Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Nov 2013 05:20:51 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r257839 - projects/altix2/sys/kern
Message-ID:  <201311080520.rA85Kps0030736@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Fri Nov  8 05:20:51 2013
New Revision: 257839
URL: http://svnweb.freebsd.org/changeset/base/257839

Log:
  o   Implement busdma_md_load_mbuf()
  o   The behaviour provided by bus_dmamap_load_mbuf_sg() is achieved
      by passing a NULL pointer for the callback function. Change
      existing load functions to do the same.
  o   Allow per-device busdma flags to be set using hints. A typical
      use would be for debugging and tracing on a per device basis.

Modified:
  projects/altix2/sys/kern/subr_busdma.c

Modified: projects/altix2/sys/kern/subr_busdma.c
==============================================================================
--- projects/altix2/sys/kern/subr_busdma.c	Fri Nov  8 05:11:32 2013	(r257838)
+++ projects/altix2/sys/kern/subr_busdma.c	Fri Nov  8 05:20:51 2013	(r257839)
@@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/busdma.h>
 #include <sys/ktr.h>
+#include <sys/mbuf.h>
 #include <sys/queue.h>
 #include <machine/stdarg.h>
 #include <cam/cam.h>
@@ -251,12 +252,20 @@ _busdma_data_dump(const char *func, stru
 static u_int
 _busdma_flags(const char *func, device_t dev, u_int flags)
 {
+	int res;
 
-	if (flags & BUSDMA_MD_PLATFORM_FLAGS)
+	if (flags & BUSDMA_MD_PLATFORM_FLAGS) {
 		device_printf(dev, "called %s() with invalid flags %#x\n",
 		    func, flags);
+		flags &= ~BUSDMA_MD_PLATFORM_FLAGS;
+	}
+
+	if (resource_int_value(device_get_name(dev), device_get_unit(dev),
+	    "busdma", &res) != 0)
+		res = 0;
+	flags |= res;
 
-	return (flags & ~BUSDMA_MD_PLATFORM_FLAGS);
+	return (flags);
 }
 
 static struct busdma_md_seg *
@@ -760,7 +769,8 @@ busdma_md_load_ccb(busdma_md_t md, union
 
 	ccb_h = &ccb->ccb_h;
 	if ((ccb_h->flags & CAM_DIR_MASK) == CAM_DIR_NONE) {
-		(*cb)(arg, NULL, 0);
+		if (cb != NULL)
+			(*cb)(arg, NULL, 0);
 		return (0);
 	}
 
@@ -801,8 +811,9 @@ busdma_md_load_ccb(busdma_md_t md, union
 		if (error)
 			printf("_busdma_iommu_map: error=%d\n", error);
 	}
-	(*cb)(arg, md, error);
-	return (0);
+	if (cb != NULL)
+		(*cb)(arg, md, error);
+	return (error);
 }
 
 int
@@ -825,8 +836,41 @@ busdma_md_load_linear(struct busdma_md *
 		if (error)
 			printf("_busdma_iommu_map: error=%d\n", error);
 	}
-	(*cb)(arg, md, error);
-	return (0);
+	if (cb != NULL)
+		(*cb)(arg, md, error);
+	return (error);
+}
+
+int
+busdma_md_load_mbuf(struct busdma_md *md, struct mbuf *m0,
+    busdma_callback_f cb, void *arg, u_int flags)
+{
+	struct mbuf *m;
+	int error;
+
+	CTR6(KTR_BUSDMA, "%s: md=%p, m0=%p, cb=%p, arg=%p, flags=%#x",
+	    __func__, md, m0, cb, arg, flags);
+
+	flags = _busdma_flags(__func__, md->md_tag->dt_device, flags);
+
+	if (md == NULL || m0 == NULL)
+		return (EINVAL);
+
+	error = 0;
+	for (m = m0; m != NULL && error == 0; m = m->m_next) {
+		if (m->m_len == 0)
+			continue;
+		error = _busdma_md_load(md, NULL, (uintptr_t)(m->m_data),
+		    m->m_len);
+	}
+	if (!error) {
+		error = _busdma_iommu_map(md->md_tag->dt_device, md);
+		if (error)
+			printf("_busdma_iommu_map: error=%d\n", error);
+	}
+	if (cb != NULL)
+		(*cb)(arg, md, error);
+	return (error);
 }
 
 int
@@ -841,8 +885,9 @@ busdma_md_load_phys(struct busdma_md *md
 	flags = _busdma_flags(__func__, md->md_tag->dt_device, flags);
 
 	panic(__func__);
-	(*cb)(arg, md, ENOSYS);
-	return (0);
+	if (cb != NULL)
+		(*cb)(arg, md, ENOSYS);
+	return (ENOSYS);
 }
 
 int
@@ -856,8 +901,9 @@ busdma_md_load_uio(struct busdma_md *md,
 	flags = _busdma_flags(__func__, md->md_tag->dt_device, flags);
 
 	panic(__func__);
-	(*cb)(arg, md, ENOSYS);
-	return (0);
+	if (cb != NULL)
+		(*cb)(arg, md, ENOSYS);
+	return (ENOSYS);
 }
 
 int



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