drivers/staging/media/ipu3/ipu3-dmamap.c

Source file repositories/reference/linux-study-clean/drivers/staging/media/ipu3/ipu3-dmamap.c

File Facts

System
Linux kernel
Corpus path
drivers/staging/media/ipu3/ipu3-dmamap.c
Extension
.c
Size
5682 bytes
Lines
251
Domain
Driver Families
Bucket
drivers/staging
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!PageCompound(page)) {
				split_page(page, order);
				break;
			}

			__free_pages(page, order);
		}
		if (!page) {
			imgu_dmamap_free_buffer(pages, i << PAGE_SHIFT);
			return NULL;
		}
		count -= order_size;
		while (order_size--)
			pages[i++] = page++;
	}

	return pages;
}

/**
 * imgu_dmamap_alloc - allocate and map a buffer into KVA
 * @imgu: struct device pointer
 * @map: struct to store mapping variables
 * @len: size required
 *
 * Returns:
 *  KVA on success
 *  %NULL on failure
 */
void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
			size_t len)
{
	unsigned long shift = iova_shift(&imgu->iova_domain);
	struct device *dev = &imgu->pci_dev->dev;
	size_t size = PAGE_ALIGN(len);
	int count = size >> PAGE_SHIFT;
	struct page **pages;
	dma_addr_t iovaddr;
	struct iova *iova;
	int i, rval;

	dev_dbg(dev, "%s: allocating %zu\n", __func__, size);

	iova = alloc_iova(&imgu->iova_domain, size >> shift,
			  imgu->mmu->aperture_end >> shift, 0);
	if (!iova)
		return NULL;

	pages = imgu_dmamap_alloc_buffer(size, GFP_KERNEL);
	if (!pages)
		goto out_free_iova;

	/* Call IOMMU driver to setup pgt */
	iovaddr = iova_dma_addr(&imgu->iova_domain, iova);
	for (i = 0; i < count; ++i) {
		rval = imgu_mmu_map(imgu->mmu, iovaddr,
				    page_to_phys(pages[i]), PAGE_SIZE);
		if (rval)
			goto out_unmap;

		iovaddr += PAGE_SIZE;
	}

	map->vaddr = vmap(pages, count, VM_USERMAP, PAGE_KERNEL);
	if (!map->vaddr)
		goto out_unmap;

	map->pages = pages;
	map->size = size;
	map->daddr = iova_dma_addr(&imgu->iova_domain, iova);

	dev_dbg(dev, "%s: allocated %zu @ IOVA %pad @ VA %p\n", __func__,
		size, &map->daddr, map->vaddr);

	return map->vaddr;

out_unmap:
	imgu_dmamap_free_buffer(pages, size);
	imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
		       i * PAGE_SIZE);

out_free_iova:
	__free_iova(&imgu->iova_domain, iova);

	return NULL;
}

void imgu_dmamap_unmap(struct imgu_device *imgu, struct imgu_css_map *map)
{
	struct iova *iova;

Annotation

Implementation Notes