Deleted Added
full compact
busdma_bounce.c (302408) busdma_bounce.c (318976)
1/*-
2 * Copyright (c) 1997, 1998 Justin T. Gibbs.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997, 1998 Justin T. Gibbs.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/11/sys/x86/x86/busdma_bounce.c 298044 2016-04-15 09:21:50Z royger $");
28__FBSDID("$FreeBSD: stable/11/sys/x86/x86/busdma_bounce.c 318976 2017-05-27 07:47:52Z hselasky $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/bus.h>
34#include <sys/interrupt.h>
35#include <sys/kernel.h>
36#include <sys/ktr.h>

--- 354 unchanged lines hidden (view full) ---

391 }
392 if (flags & BUS_DMA_ZERO)
393 mflags |= M_ZERO;
394 if (flags & BUS_DMA_NOCACHE)
395 attr = VM_MEMATTR_UNCACHEABLE;
396 else
397 attr = VM_MEMATTR_DEFAULT;
398
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/bus.h>
34#include <sys/interrupt.h>
35#include <sys/kernel.h>
36#include <sys/ktr.h>

--- 354 unchanged lines hidden (view full) ---

391 }
392 if (flags & BUS_DMA_ZERO)
393 mflags |= M_ZERO;
394 if (flags & BUS_DMA_NOCACHE)
395 attr = VM_MEMATTR_UNCACHEABLE;
396 else
397 attr = VM_MEMATTR_DEFAULT;
398
399 /*
400 * XXX:
401 * (dmat->alignment <= dmat->maxsize) is just a quick hack; the exact
402 * alignment guarantees of malloc need to be nailed down, and the
403 * code below should be rewritten to take that into account.
399 /*
400 * Allocate the buffer from the malloc(9) allocator if...
401 * - It's small enough to fit into a single power of two sized bucket.
402 * - The alignment is less than or equal to the maximum size
403 * - The low address requirement is fulfilled.
404 * else allocate non-contiguous pages if...
405 * - The page count that could get allocated doesn't exceed
406 * nsegments also when the maximum segment size is less
407 * than PAGE_SIZE.
408 * - The alignment constraint isn't larger than a page boundary.
409 * - There are no boundary-crossing constraints.
410 * else allocate a block of contiguous pages because one or more of the
411 * constraints is something that only the contig allocator can fulfill.
404 *
412 *
405 * In the meantime, we'll warn the user if malloc gets it wrong.
413 * NOTE: The (dmat->common.alignment <= dmat->maxsize) check
414 * below is just a quick hack. The exact alignment guarantees
415 * of malloc(9) need to be nailed down, and the code below
416 * should be rewritten to take that into account.
417 *
418 * In the meantime warn the user if malloc gets it wrong.
406 */
407 if ((dmat->common.maxsize <= PAGE_SIZE) &&
408 (dmat->common.alignment <= dmat->common.maxsize) &&
409 dmat->common.lowaddr >= ptoa((vm_paddr_t)Maxmem) &&
410 attr == VM_MEMATTR_DEFAULT) {
411 *vaddr = malloc(dmat->common.maxsize, M_DEVBUF, mflags);
419 */
420 if ((dmat->common.maxsize <= PAGE_SIZE) &&
421 (dmat->common.alignment <= dmat->common.maxsize) &&
422 dmat->common.lowaddr >= ptoa((vm_paddr_t)Maxmem) &&
423 attr == VM_MEMATTR_DEFAULT) {
424 *vaddr = malloc(dmat->common.maxsize, M_DEVBUF, mflags);
412 } else if (dmat->common.nsegments >= btoc(dmat->common.maxsize) &&
425 } else if (dmat->common.nsegments >=
426 howmany(dmat->common.maxsize, MIN(dmat->common.maxsegsz, PAGE_SIZE)) &&
413 dmat->common.alignment <= PAGE_SIZE &&
427 dmat->common.alignment <= PAGE_SIZE &&
414 (dmat->common.boundary == 0 ||
415 dmat->common.boundary >= dmat->common.lowaddr)) {
428 (dmat->common.boundary % PAGE_SIZE) == 0) {
416 /* Page-based multi-segment allocations allowed */
417 *vaddr = (void *)kmem_alloc_attr(kernel_arena,
418 dmat->common.maxsize, mflags, 0ul, dmat->common.lowaddr,
419 attr);
420 dmat->bounce_flags |= BUS_DMA_KMEM_ALLOC;
421 } else {
422 *vaddr = (void *)kmem_alloc_contig(kernel_arena,
423 dmat->common.maxsize, mflags, 0ul, dmat->common.lowaddr,

--- 843 unchanged lines hidden ---
429 /* Page-based multi-segment allocations allowed */
430 *vaddr = (void *)kmem_alloc_attr(kernel_arena,
431 dmat->common.maxsize, mflags, 0ul, dmat->common.lowaddr,
432 attr);
433 dmat->bounce_flags |= BUS_DMA_KMEM_ALLOC;
434 } else {
435 *vaddr = (void *)kmem_alloc_contig(kernel_arena,
436 dmat->common.maxsize, mflags, 0ul, dmat->common.lowaddr,

--- 843 unchanged lines hidden ---