From owner-svn-src-projects@FreeBSD.ORG Wed May 9 15:36:38 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 66681106564A; Wed, 9 May 2012 15:36:38 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 51FB58FC17; Wed, 9 May 2012 15:36:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q49FacP3090866; Wed, 9 May 2012 15:36:38 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q49FacpR090863; Wed, 9 May 2012 15:36:38 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201205091536.q49FacpR090863@svn.freebsd.org> From: Marcel Moolenaar Date: Wed, 9 May 2012 15:36:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r235197 - in projects/altix2/sys: kern sys X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2012 15:36:38 -0000 Author: marcel Date: Wed May 9 15:36:37 2012 New Revision: 235197 URL: http://svn.freebsd.org/changeset/base/235197 Log: o Use M_NOWAIT instead of M_WAITOK. It's assumed. This is a good area for control by a flag. o Add busdma_mem_get_seg_addr() and busdma_mem_get_seg_busaddr() so that drivers can obtain address information about a segment. To be added are busdma_mem_get_seg_paddr() and busdma_mem_get_seg_size(). XXX: I assume allocations for 1 segment only. The linked list approach is probably not how I want to productize. Modified: projects/altix2/sys/kern/subr_busdma.c projects/altix2/sys/sys/busdma.h Modified: projects/altix2/sys/kern/subr_busdma.c ============================================================================== --- projects/altix2/sys/kern/subr_busdma.c Wed May 9 15:25:58 2012 (r235196) +++ projects/altix2/sys/kern/subr_busdma.c Wed May 9 15:36:37 2012 (r235197) @@ -55,10 +55,10 @@ struct busdma_tag { struct busdma_seg { TAILQ_ENTRY(busdma_seg) ds_chain; + bus_addr_t ds_baddr; + vm_paddr_t ds_paddr; vm_offset_t ds_vaddr; vm_size_t ds_size; - vm_paddr_t ds_paddr; - bus_addr_t ds_baddr; }; struct busdma_mem { @@ -156,6 +156,18 @@ _busdma_tag_make(device_t dev, struct bu return (0); } +static struct busdma_seg * +_busdma_mem_get_seg(struct busdma_mem *mem, u_int idx) +{ + struct busdma_seg *seg; + + if (idx >= mem->dm_nsegs) + return (NULL); + + seg = TAILQ_FIRST(&mem->dm_seg); + return (seg); +} + int busdma_tag_create(device_t dev, bus_addr_t maxaddr, bus_addr_t align, bus_addr_t bndry, bus_size_t maxsz, u_int nsegs, bus_size_t maxsegsz, @@ -209,13 +221,13 @@ busdma_mem_alloc(struct busdma_tag *tag, struct busdma_seg *seg; vm_size_t maxsz; - mem = malloc(sizeof(*mem), M_BUSDMA_MEM, M_WAITOK | M_ZERO); + mem = malloc(sizeof(*mem), M_BUSDMA_MEM, M_NOWAIT | M_ZERO); mem->dm_tag = tag; TAILQ_INIT(&mem->dm_seg); maxsz = tag->dt_maxsz; while (maxsz > 0 && mem->dm_nsegs < tag->dt_nsegs) { - seg = malloc(sizeof(*seg), M_BUSDMA_SEG, M_WAITOK | M_ZERO); + seg = malloc(sizeof(*seg), M_BUSDMA_SEG, M_NOWAIT | M_ZERO); TAILQ_INSERT_TAIL(&mem->dm_seg, seg, ds_chain); seg->ds_size = MIN(maxsz, tag->dt_maxsegsz); seg->ds_vaddr = kmem_alloc_contig(kernel_map, seg->ds_size, 0, @@ -226,6 +238,7 @@ busdma_mem_alloc(struct busdma_tag *tag, goto fail; } seg->ds_paddr = pmap_kextract(seg->ds_vaddr); + seg->ds_baddr = seg->ds_paddr; maxsz -= seg->ds_size; mem->dm_nsegs++; } @@ -246,3 +259,21 @@ busdma_mem_alloc(struct busdma_tag *tag, free(mem, M_BUSDMA_MEM); return (ENOMEM); } + +vm_offset_t +busdma_mem_get_seg_addr(struct busdma_mem *mem, u_int idx) +{ + struct busdma_seg *seg; + + seg = _busdma_mem_get_seg(mem, idx); + return ((seg != NULL) ? seg->ds_vaddr : 0); +} + +bus_addr_t +busdma_mem_get_seg_busaddr(struct busdma_mem *mem, u_int idx) +{ + struct busdma_seg *seg; + + seg = _busdma_mem_get_seg(mem, idx); + return ((seg != NULL) ? seg->ds_baddr : 0); +} Modified: projects/altix2/sys/sys/busdma.h ============================================================================== --- projects/altix2/sys/sys/busdma.h Wed May 9 15:25:58 2012 (r235196) +++ projects/altix2/sys/sys/busdma.h Wed May 9 15:36:37 2012 (r235197) @@ -83,4 +83,22 @@ int busdma_tag_derive(busdma_tag_t tag, */ int busdma_mem_alloc(busdma_tag_t tag, u_int flags, busdma_mem_t *mem_p); +/* + * busdma_mem_get_seg_addr + * returns: kernel virtual address of the specified segment. + * arguments: + * mem the DMA memory allocated or mapped. + * idx the segment index, starting at 0. + */ +vm_offset_t busdma_mem_get_seg_addr(busdma_mem_t tag, u_int idx); + +/* + * busdma_mem_get_seg_busaddr + * returns: (virtual) bus address of the specified segment. + * arguments: + * mem the BMA memory allocated to mapped. + * idx the segment index, starting at 0. + */ +bus_addr_t busdma_mem_get_seg_busaddr(busdma_mem_t mem, u_int idx); + #endif /* _SYS_BUSDMA_H_ */