From owner-svn-src-stable-7@FreeBSD.ORG Sun Dec 13 15:12:41 2009 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 19AF9106566C; Sun, 13 Dec 2009 15:12:41 +0000 (UTC) (envelope-from rnoland@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0789E8FC08; Sun, 13 Dec 2009 15:12:41 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBDFCemp089916; Sun, 13 Dec 2009 15:12:40 GMT (envelope-from rnoland@svn.freebsd.org) Received: (from rnoland@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBDFCekX089914; Sun, 13 Dec 2009 15:12:40 GMT (envelope-from rnoland@svn.freebsd.org) Message-Id: <200912131512.nBDFCekX089914@svn.freebsd.org> From: Robert Noland Date: Sun, 13 Dec 2009 15:12:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200477 - stable/7/sys/dev/drm X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Dec 2009 15:12:41 -0000 Author: rnoland Date: Sun Dec 13 15:12:40 2009 New Revision: 200477 URL: http://svn.freebsd.org/changeset/base/200477 Log: MFC r198694,r198697 Some general cleanup of scatter/gather memory allocation - We don't need to check malloc return values with M_WAITOK - remove variables that we don't really need - cleanup the error paths by just calling drm_sg_cleanup() - fix drm_sg_cleanup() to be safe to call at any time Modified: stable/7/sys/dev/drm/drm_scatter.c Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/dev/drm/drm_scatter.c ============================================================================== --- stable/7/sys/dev/drm/drm_scatter.c Sun Dec 13 15:08:25 2009 (r200476) +++ stable/7/sys/dev/drm/drm_scatter.c Sun Dec 13 15:12:40 2009 (r200477) @@ -47,79 +47,50 @@ drm_sg_alloc(struct drm_device *dev, str { struct drm_sg_mem *entry; struct drm_dma_handle *dmah; - unsigned long pages; int ret; if (dev->sg) return EINVAL; entry = malloc(sizeof(*entry), DRM_MEM_SGLISTS, M_WAITOK | M_ZERO); - if (!entry) - return ENOMEM; - - pages = round_page(request->size) / PAGE_SIZE; - DRM_DEBUG("sg size=%ld pages=%ld\n", request->size, pages); - - entry->pages = pages; - - entry->busaddr = malloc(pages * sizeof(*entry->busaddr), DRM_MEM_PAGES, - M_WAITOK | M_ZERO); - if (!entry->busaddr) { - free(entry, DRM_MEM_SGLISTS); - return ENOMEM; - } + entry->pages = round_page(request->size) / PAGE_SIZE; + DRM_DEBUG("sg size=%ld pages=%d\n", request->size, entry->pages); + entry->busaddr = malloc(entry->pages * sizeof(*entry->busaddr), + DRM_MEM_PAGES, M_WAITOK | M_ZERO); dmah = malloc(sizeof(struct drm_dma_handle), DRM_MEM_DMA, - M_ZERO | M_NOWAIT); - if (dmah == NULL) { - free(entry->busaddr, DRM_MEM_PAGES); - free(entry, DRM_MEM_SGLISTS); - return ENOMEM; - } + M_WAITOK | M_ZERO); + entry->dmah = dmah; ret = bus_dma_tag_create(NULL, PAGE_SIZE, 0, /* tag, align, boundary */ BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */ NULL, NULL, /* filtfunc, filtfuncargs */ - request->size, pages, /* maxsize, nsegs */ + request->size, entry->pages, /* maxsize, nsegs */ PAGE_SIZE, 0, /* maxsegsize, flags */ NULL, NULL, /* lockfunc, lockfuncargs */ &dmah->tag); if (ret != 0) { - free(dmah, DRM_MEM_DMA); - free(entry->busaddr, DRM_MEM_PAGES); - free(entry, DRM_MEM_SGLISTS); + drm_sg_cleanup(entry); return ENOMEM; } ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr, BUS_DMA_WAITOK | BUS_DMA_ZERO | BUS_DMA_NOCACHE, &dmah->map); if (ret != 0) { - bus_dma_tag_destroy(dmah->tag); - free(dmah, DRM_MEM_DMA); - free(entry->busaddr, DRM_MEM_PAGES); - free(entry, DRM_MEM_SGLISTS); + drm_sg_cleanup(entry); return ENOMEM; } + entry->handle = (unsigned long)dmah->vaddr; + entry->virtual = dmah->vaddr; + ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr, request->size, drm_sg_alloc_cb, entry, BUS_DMA_NOWAIT); if (ret != 0) { - bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); - bus_dma_tag_destroy(dmah->tag); - free(dmah, DRM_MEM_DMA); - free(entry->busaddr, DRM_MEM_PAGES); - free(entry, DRM_MEM_SGLISTS); + drm_sg_cleanup(entry); return ENOMEM; } - entry->dmah = dmah; - entry->handle = (unsigned long)dmah->vaddr; - - DRM_DEBUG("sg alloc handle = %08lx\n", entry->handle); - - entry->virtual = (void *)entry->handle; - request->handle = entry->handle; - DRM_LOCK(); if (dev->sg) { DRM_UNLOCK(); @@ -129,6 +100,11 @@ drm_sg_alloc(struct drm_device *dev, str dev->sg = entry; DRM_UNLOCK(); + DRM_DEBUG("handle=%08lx, kva=%p, contents=%08lx\n", entry->handle, + entry->virtual, *(unsigned long *)entry->virtual); + + request->handle = entry->handle; + return 0; } @@ -143,6 +119,8 @@ drm_sg_alloc_cb(void *arg, bus_dma_segme for(i = 0 ; i < nsegs ; i++) { entry->busaddr[i] = segs[i].ds_addr; + DRM_DEBUG("segment %d @ 0x%016lx\n", i, + (unsigned long)segs[i].ds_addr); } } @@ -162,9 +140,12 @@ drm_sg_cleanup(struct drm_sg_mem *entry) { struct drm_dma_handle *dmah = entry->dmah; - bus_dmamap_unload(dmah->tag, dmah->map); - bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); - bus_dma_tag_destroy(dmah->tag); + if (dmah->map != NULL) + bus_dmamap_unload(dmah->tag, dmah->map); + if (dmah->vaddr != NULL) + bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); + if (dmah->tag != NULL) + bus_dma_tag_destroy(dmah->tag); free(dmah, DRM_MEM_DMA); free(entry->busaddr, DRM_MEM_PAGES); free(entry, DRM_MEM_SGLISTS);