From owner-svn-src-head@FreeBSD.ORG Fri Jun 12 14:53:57 2015 Return-Path: Delivered-To: svn-src-head@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F1E48D49; Fri, 12 Jun 2015 14:53:56 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D34BD12C; Fri, 12 Jun 2015 14:53:56 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5CEruER039309; Fri, 12 Jun 2015 14:53:56 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5CEruuA039308; Fri, 12 Jun 2015 14:53:56 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201506121453.t5CEruuA039308@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Fri, 12 Jun 2015 14:53:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284322 - head/tools/bus_space X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Jun 2015 14:53:57 -0000 Author: marcel Date: Fri Jun 12 14:53:56 2015 New Revision: 284322 URL: https://svnweb.freebsd.org/changeset/base/284322 Log: Free the segment objects properly. Modified: head/tools/bus_space/busdma.c Modified: head/tools/bus_space/busdma.c ============================================================================== --- head/tools/bus_space/busdma.c Fri Jun 12 14:30:27 2015 (r284321) +++ head/tools/bus_space/busdma.c Fri Jun 12 14:53:56 2015 (r284322) @@ -273,17 +273,15 @@ bd_mem_alloc(int tid, u_int flags) tag->refcnt++; md->key = ioc.result; + /* XXX we need to support multiple segments */ assert(ioc.u.mem.phys_nsegs == 1); - pseg = obj_alloc(OBJ_TYPE_SEG); - pseg->refcnt = 1; - pseg->parent = md; - pseg->u.seg.address = ioc.u.mem.phys_addr; - pseg->u.seg.size = tag->u.tag.maxsz; - md->u.md.seg[BUSDMA_MD_PHYS] = pseg; - md->u.md.nsegs[BUSDMA_MD_PHYS] = ioc.u.mem.phys_nsegs; - assert(ioc.u.mem.bus_nsegs == 1); + + bseg = pseg = vseg = NULL; + bseg = obj_alloc(OBJ_TYPE_SEG); + if (bseg == NULL) + goto fail; bseg->refcnt = 1; bseg->parent = md; bseg->u.seg.address = ioc.u.mem.bus_addr; @@ -291,33 +289,71 @@ bd_mem_alloc(int tid, u_int flags) md->u.md.seg[BUSDMA_MD_BUS] = bseg; md->u.md.nsegs[BUSDMA_MD_BUS] = ioc.u.mem.bus_nsegs; + pseg = obj_alloc(OBJ_TYPE_SEG); + if (pseg == NULL) + goto fail; + pseg->refcnt = 1; + pseg->parent = md; + pseg->u.seg.address = ioc.u.mem.phys_addr; + pseg->u.seg.size = tag->u.tag.maxsz; + md->u.md.seg[BUSDMA_MD_PHYS] = pseg; + md->u.md.nsegs[BUSDMA_MD_PHYS] = ioc.u.mem.phys_nsegs; + vseg = obj_alloc(OBJ_TYPE_SEG); + if (vseg == NULL) + goto fail; vseg->refcnt = 1; vseg->parent = md; vseg->u.seg.address = (uintptr_t)mmap(NULL, pseg->u.seg.size, PROT_READ | PROT_WRITE, MAP_NOCORE | MAP_SHARED, md->fd, pseg->u.seg.address); + if (vseg->u.seg.address == (uintptr_t)MAP_FAILED) + goto fail; vseg->u.seg.size = pseg->u.seg.size; md->u.md.seg[BUSDMA_MD_VIRT] = vseg; md->u.md.nsegs[BUSDMA_MD_VIRT] = 1; return (md->oid); + + fail: + if (vseg != NULL) + obj_free(vseg); + if (pseg != NULL) + obj_free(pseg); + if (bseg != NULL) + obj_free(bseg); + memset(&ioc, 0, sizeof(ioc)); + ioc.request = PROTO_IOC_BUSDMA_MEM_FREE; + ioc.key = md->key; + ioctl(md->fd, PROTO_IOC_BUSDMA, &ioc); + md->parent->refcnt--; + obj_free(md); + return (-1); } int bd_mem_free(int mdid) { struct proto_ioc_busdma ioc; - struct obj *md, *seg; + struct obj *md, *seg, *seg0; md = obj_lookup(mdid, OBJ_TYPE_MD); if (md == NULL) return (errno); - for (seg = md->u.md.seg[BUSDMA_MD_VIRT]; - seg != NULL; - seg = seg->u.seg.next) + for (seg = md->u.md.seg[BUSDMA_MD_VIRT]; seg != NULL; seg = seg0) { munmap((void *)seg->u.seg.address, seg->u.seg.size); + seg0 = seg->u.seg.next; + obj_free(seg); + } + for (seg = md->u.md.seg[BUSDMA_MD_PHYS]; seg != NULL; seg = seg0) { + seg0 = seg->u.seg.next; + obj_free(seg); + } + for (seg = md->u.md.seg[BUSDMA_MD_BUS]; seg != NULL; seg = seg0) { + seg0 = seg->u.seg.next; + obj_free(seg); + } memset(&ioc, 0, sizeof(ioc)); ioc.request = PROTO_IOC_BUSDMA_MEM_FREE; ioc.key = md->key;