MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bus_dmamap_create

Function bus_dmamap_create

freebsd/mips/mips/busdma_machdep.c:547–622  ·  view source on GitHub ↗

* Allocate a handle for mapping from kva/uva/physical * address space into bus device space. */

Source from the content-addressed store, hash-verified

545 * address space into bus device space.
546 */
547int
548bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
549{
550 bus_dmamap_t newmap;
551 int error = 0;
552
553 if (dmat->segments == NULL) {
554 dmat->segments = (bus_dma_segment_t *)malloc(
555 sizeof(bus_dma_segment_t) * dmat->nsegments, M_BUSDMA,
556 M_NOWAIT);
557 if (dmat->segments == NULL) {
558 CTR3(KTR_BUSDMA, "%s: tag %p error %d",
559 __func__, dmat, ENOMEM);
560 return (ENOMEM);
561 }
562 }
563
564 newmap = _busdma_alloc_dmamap(dmat);
565 if (newmap == NULL) {
566 CTR3(KTR_BUSDMA, "%s: tag %p error %d", __func__, dmat, ENOMEM);
567 return (ENOMEM);
568 }
569 *mapp = newmap;
570
571 /*
572 * Bouncing might be required if the driver asks for an active
573 * exclusion region, a data alignment that is stricter than 1, and/or
574 * an active address boundary.
575 */
576 if (dmat->flags & BUS_DMA_COULD_BOUNCE) {
577 /* Must bounce */
578 struct bounce_zone *bz;
579 int maxpages;
580
581 if (dmat->bounce_zone == NULL) {
582 if ((error = alloc_bounce_zone(dmat)) != 0) {
583 _busdma_free_dmamap(newmap);
584 *mapp = NULL;
585 return (error);
586 }
587 }
588 bz = dmat->bounce_zone;
589
590 /* Initialize the new map */
591 STAILQ_INIT(&((*mapp)->bpages));
592
593 /*
594 * Attempt to add pages to our pool on a per-instance
595 * basis up to a sane limit.
596 */
597 maxpages = MAX_BPAGES;
598 if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0
599 || (bz->map_count > 0 && bz->total_bpages < maxpages)) {
600 int pages;
601
602 pages = MAX(atop(dmat->maxsize), 1);
603 pages = MIN(maxpages - bz->total_bpages, pages);
604 pages = MAX(pages, 1);

Callers 3

jz4780_mmc_setup_dmaFunction · 0.50
arge_dma_allocFunction · 0.50
are_dma_allocFunction · 0.50

Calls 5

mallocFunction · 0.85
_busdma_alloc_dmamapFunction · 0.85
_busdma_free_dmamapFunction · 0.85
alloc_bounce_zoneFunction · 0.70
alloc_bounce_pagesFunction · 0.70

Tested by

no test coverage detected