Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/iommu/busdma_iommu.c
Show First 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | if (dmat->map_count != 0) { | ||||
goto out; | goto out; | ||||
} | } | ||||
while (dmat != NULL) { | while (dmat != NULL) { | ||||
parent = (struct bus_dma_tag_iommu *)dmat->common.parent; | parent = (struct bus_dma_tag_iommu *)dmat->common.parent; | ||||
if (atomic_fetchadd_int(&dmat->common.ref_count, -1) == | if (atomic_fetchadd_int(&dmat->common.ref_count, -1) == | ||||
1) { | 1) { | ||||
if (dmat == dmat->ctx->tag) | if (dmat == dmat->ctx->tag) | ||||
iommu_free_ctx(dmat->ctx); | iommu_free_ctx(dmat->ctx); | ||||
free_domain(dmat->segments, M_IOMMU_DMAMAP); | free(dmat->segments, M_IOMMU_DMAMAP); | ||||
free(dmat, M_DEVBUF); | free(dmat, M_DEVBUF); | ||||
dmat = parent; | dmat = parent; | ||||
} else | } else | ||||
dmat = NULL; | dmat = NULL; | ||||
} | } | ||||
} | } | ||||
out: | out: | ||||
CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); | CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); | ||||
Show All 20 Lines | if (map == NULL) { | ||||
*mapp = NULL; | *mapp = NULL; | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
if (tag->segments == NULL) { | if (tag->segments == NULL) { | ||||
tag->segments = malloc_domainset(sizeof(bus_dma_segment_t) * | tag->segments = malloc_domainset(sizeof(bus_dma_segment_t) * | ||||
tag->common.nsegments, M_IOMMU_DMAMAP, | tag->common.nsegments, M_IOMMU_DMAMAP, | ||||
DOMAINSET_PREF(tag->common.domain), M_NOWAIT); | DOMAINSET_PREF(tag->common.domain), M_NOWAIT); | ||||
if (tag->segments == NULL) { | if (tag->segments == NULL) { | ||||
free_domain(map, M_IOMMU_DMAMAP); | free(map, M_IOMMU_DMAMAP); | ||||
*mapp = NULL; | *mapp = NULL; | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
} | } | ||||
TAILQ_INIT(&map->map_entries); | TAILQ_INIT(&map->map_entries); | ||||
map->tag = tag; | map->tag = tag; | ||||
map->locked = true; | map->locked = true; | ||||
map->cansleep = false; | map->cansleep = false; | ||||
Show All 15 Lines | iommu_bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map1) | ||||
if (map != NULL) { | if (map != NULL) { | ||||
domain = tag->ctx->domain; | domain = tag->ctx->domain; | ||||
IOMMU_DOMAIN_LOCK(domain); | IOMMU_DOMAIN_LOCK(domain); | ||||
if (!TAILQ_EMPTY(&map->map_entries)) { | if (!TAILQ_EMPTY(&map->map_entries)) { | ||||
IOMMU_DOMAIN_UNLOCK(domain); | IOMMU_DOMAIN_UNLOCK(domain); | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
IOMMU_DOMAIN_UNLOCK(domain); | IOMMU_DOMAIN_UNLOCK(domain); | ||||
free_domain(map, M_IOMMU_DMAMAP); | free(map, M_IOMMU_DMAMAP); | ||||
} | } | ||||
tag->map_count--; | tag->map_count--; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
iommu_bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, | iommu_bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct bus_dma_tag_iommu *tag; | struct bus_dma_tag_iommu *tag; | ||||
struct bus_dmamap_iommu *map; | struct bus_dmamap_iommu *map; | ||||
tag = (struct bus_dma_tag_iommu *)dmat; | tag = (struct bus_dma_tag_iommu *)dmat; | ||||
map = (struct bus_dmamap_iommu *)map1; | map = (struct bus_dmamap_iommu *)map1; | ||||
if ((map->flags & BUS_DMAMAP_IOMMU_MALLOC) != 0) { | if ((map->flags & BUS_DMAMAP_IOMMU_MALLOC) != 0) { | ||||
free_domain(vaddr, M_DEVBUF); | free(vaddr, M_DEVBUF); | ||||
map->flags &= ~BUS_DMAMAP_IOMMU_MALLOC; | map->flags &= ~BUS_DMAMAP_IOMMU_MALLOC; | ||||
} else { | } else { | ||||
KASSERT((map->flags & BUS_DMAMAP_IOMMU_KMEM_ALLOC) != 0, | KASSERT((map->flags & BUS_DMAMAP_IOMMU_KMEM_ALLOC) != 0, | ||||
("iommu_bus_dmamem_free for non alloced map %p", map)); | ("iommu_bus_dmamem_free for non alloced map %p", map)); | ||||
kmem_free((vm_offset_t)vaddr, tag->common.maxsize); | kmem_free((vm_offset_t)vaddr, tag->common.maxsize); | ||||
map->flags &= ~BUS_DMAMAP_IOMMU_KMEM_ALLOC; | map->flags &= ~BUS_DMAMAP_IOMMU_KMEM_ALLOC; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 522 Lines • Show Last 20 Lines |