summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2010-09-15 17:11:15 +0000
committermarius <marius@FreeBSD.org>2010-09-15 17:11:15 +0000
commit2e2ae916fe6328ed40b3fd7aa646611897ed3fa4 (patch)
tree661b47cd21ea6e084ee18ddb9f8d0b26a2c12cb0 /sys
parent4643dcbb25fa9cc1999708862a8a0b1b59e5615a (diff)
downloadFreeBSD-src-2e2ae916fe6328ed40b3fd7aa646611897ed3fa4.zip
FreeBSD-src-2e2ae916fe6328ed40b3fd7aa646611897ed3fa4.tar.gz
Sync with other platforms:
- make dflt_lock() always panic, - add kludge to use contigmalloc() when the alignment is larger than the size and print a diagnostic when we didn't satisfy the alignment.
Diffstat (limited to 'sys')
-rw-r--r--sys/sparc64/sparc64/bus_machdep.c26
-rw-r--r--sys/sun4v/sun4v/bus_machdep.c26
2 files changed, 34 insertions, 18 deletions
diff --git a/sys/sparc64/sparc64/bus_machdep.c b/sys/sparc64/sparc64/bus_machdep.c
index 0bf9b2e..5f5d2a4 100644
--- a/sys/sparc64/sparc64/bus_machdep.c
+++ b/sys/sparc64/sparc64/bus_machdep.c
@@ -182,11 +182,8 @@ busdma_lock_mutex(void *arg, bus_dma_lock_op_t op)
static void
dflt_lock(void *arg, bus_dma_lock_op_t op)
{
-#ifdef INVARIANTS
+
panic("driver error: busdma dflt_lock called");
-#else
- printf("DRIVER_ERROR: busdma dflt_lock called\n");
-#endif
}
/*
@@ -631,9 +628,18 @@ nexus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
if (flags & BUS_DMA_ZERO)
mflags |= M_ZERO;
- if ((dmat->dt_maxsize <= PAGE_SIZE)) {
+ /*
+ * XXX:
+ * (dmat->dt_alignment < dmat->dt_maxsize) is just a quick hack; the
+ * exact alignment guarantees of malloc need to be nailed down, and
+ * the code below should be rewritten to take that into account.
+ *
+ * In the meantime, we'll warn the user if malloc gets it wrong.
+ */
+ if (dmat->dt_maxsize <= PAGE_SIZE &&
+ dmat->dt_alignment < dmat->dt_maxsize)
*vaddr = malloc(dmat->dt_maxsize, M_DEVBUF, mflags);
- } else {
+ else {
/*
* XXX use contigmalloc until it is merged into this
* facility and handles multi-seg allocations. Nobody
@@ -646,6 +652,8 @@ nexus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
}
if (*vaddr == NULL)
return (ENOMEM);
+ if ((uintptr_t)*vaddr % dmat->dt_alignment)
+ printf("%s: failed to align memory properly.\n", __func__);
return (0);
}
@@ -657,11 +665,11 @@ static void
nexus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
{
- if ((dmat->dt_maxsize <= PAGE_SIZE))
+ if (dmat->dt_maxsize <= PAGE_SIZE &&
+ dmat->dt_alignment < dmat->dt_maxsize)
free(vaddr, M_DEVBUF);
- else {
+ else
contigfree(vaddr, dmat->dt_maxsize, M_DEVBUF);
- }
}
struct bus_dma_methods nexus_dma_methods = {
diff --git a/sys/sun4v/sun4v/bus_machdep.c b/sys/sun4v/sun4v/bus_machdep.c
index 1282b0e..7246f5f 100644
--- a/sys/sun4v/sun4v/bus_machdep.c
+++ b/sys/sun4v/sun4v/bus_machdep.c
@@ -181,11 +181,8 @@ busdma_lock_mutex(void *arg, bus_dma_lock_op_t op)
static void
dflt_lock(void *arg, bus_dma_lock_op_t op)
{
-#ifdef INVARIANTS
+
panic("driver error: busdma dflt_lock called");
-#else
- printf("DRIVER_ERROR: busdma dflt_lock called\n");
-#endif
}
/*
@@ -647,9 +644,18 @@ nexus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
if (flags & BUS_DMA_ZERO)
mflags |= M_ZERO;
- if ((dmat->dt_maxsize <= PAGE_SIZE)) {
+ /*
+ * XXX:
+ * (dmat->dt_alignment < dmat->dt_maxsize) is just a quick hack; the
+ * exact alignment guarantees of malloc need to be nailed down, and
+ * the code below should be rewritten to take that into account.
+ *
+ * In the meantime, we'll warn the user if malloc gets it wrong.
+ */
+ if (dmat->dt_maxsize <= PAGE_SIZE &&
+ dmat->dt_alignment < dmat->dt_maxsize)
*vaddr = malloc(dmat->dt_maxsize, M_DEVBUF, mflags);
- } else {
+ else {
/*
* XXX use contigmalloc until it is merged into this
* facility and handles multi-seg allocations. Nobody
@@ -662,6 +668,8 @@ nexus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
}
if (*vaddr == NULL)
return (ENOMEM);
+ if ((uintptr_t)*vaddr % dmat->dt_alignment)
+ printf("%s: failed to align memory properly.\n", __func__);
return (0);
}
@@ -673,11 +681,11 @@ static void
nexus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
{
- if ((dmat->dt_maxsize <= PAGE_SIZE))
+ if (dmat->dt_maxsize <= PAGE_SIZE &&
+ dmat->dt_alignment < dmat->dt_maxsize)
free(vaddr, M_DEVBUF);
- else {
+ else
contigfree(vaddr, dmat->dt_maxsize, M_DEVBUF);
- }
}
struct bus_dma_methods nexus_dma_methods = {
OpenPOWER on IntegriCloud