| /* |
| * Copyright 2017, Data61 |
| * Commonwealth Scientific and Industrial Research Organisation (CSIRO) |
| * ABN 41 687 119 230. |
| * |
| * This software may be distributed and modified according to the terms of |
| * the BSD 2-Clause license. Note that NO WARRANTY is provided. |
| * See "LICENSE_BSD2.txt" for details. |
| * |
| * @TAG(DATA61_BSD) |
| */ |
| |
| #pragma once |
| |
| #include <autoconf.h> |
| #include <sel4utils/gen_config.h> |
| |
| #if defined(CONFIG_IOMMU) |
| |
| #include <sel4/sel4.h> |
| #include <vka/vka.h> |
| #include <vspace/vspace.h> |
| #include <platsupport/io.h> |
| |
| /** |
| * Creates an implementation of a dma manager that is designed to work only in the presence of an IOMMU |
| * Due to its reliance on malloc for actually allocating memory blocks, and because malloc'ed memory is |
| * assumed to be cached, it only supports cached allocations. The basic operation of this allocator is to |
| * malloc block of memory, find the frame capabilities, duplicate and map these into the appropriate |
| * iospaces. It is the responsibility of the user to ensure that whatever frames are used in mapping |
| * the malloc region are of a size that the hardware will accept being mapped into the IOMMU |
| * @param vka Allocation interface used for allocated cslots and any required paging structures for the iospace. |
| * This interface will be copied |
| * @param vspace Virtual memory manager that needs to contain any mappings used to back malloc. |
| * This interface will be copied |
| * @param dma_man Pointer to dma manager struct that will be filled out |
| * @param num_iospaces Number of iospaces we wish allocations from this dma manager to be valid in |
| * @param iospaces Pointer to list of cptrs representing the iospaces to map into |
| * @return 0 on success |
| */ |
| int sel4utils_make_iommu_dma_alloc(vka_t *vka, vspace_t *vspace, ps_dma_man_t *dma_man, unsigned int num_iospaces, |
| seL4_CPtr *iospaces); |
| |
| /** |
| * Variant of ps_dma_alloc that allows the caller to allocate memory in their address space for use |
| * as the dma buffer. This function takes a description of a region of (virtual) memory, and maps |
| * the frames that back the region into the dma manager's iospace such that the iovaddr of each frame |
| * corresponds to its vaddr. |
| * |
| * The intended use case for this function is in environments without a dynamic heap (that is, where |
| * malloc is not backed by a vspace). The dma_man argument must be a pointer to a dma manager that |
| * was created using sel4utils_make_iommu_dma_alloc. The vspace argument to sel4utils_make_iommu_dma_alloc |
| * must be able to resolve vaddrs within the specified buffer to frame caps with its get_cap function. |
| * |
| * This function takes a cookie rather than a dma manager to allow it to be used in the implementation |
| * of a ps_dma_alloc_fn_t. |
| * |
| * @param dma_cookie The cookie of a dma manager initialised with sel4utils_make_iommu_dma_alloc. |
| * @param vaddr A pointer to a region of memory to use as the dma buffer. The vspace given to |
| * sel4utils_make_iommu_dma_alloc to initialise dma_man must be able to resolve |
| * addresses in this buffer to frame caps with its get_cap function. |
| * @param size The size of the region of memory pointed to by vaddr. |
| * @return 0 on success |
| */ |
| int sel4utils_iommu_dma_alloc_iospace(void *dma_cookie, void *vaddr, size_t size); |
| #endif /* CONFIG_IOMMU */ |