Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 May 2012 15:36:38 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r235197 - in projects/altix2/sys: kern sys
Message-ID:  <201205091536.q49FacpR090863@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201205091536.q49FacpR090863>