From: Tom Rini Date: Mon, 11 Nov 2024 13:26:50 +0000 (-0600) Subject: Merge patch series "Fix IOVA allocation in Apple dart iommu after global LMB mem... X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-logo.png?a=commitdiff_plain;h=48fd7e9699f8799690196c76869d59c1e5b2e9a6;p=u-boot.git Merge patch series "Fix IOVA allocation in Apple dart iommu after global LMB mem map changes" Janne Grunau says: The changes in "Make LMB memory map global and persistent" [1] break mapping DMA memory in the USB xHCI driver when using the apple_dart iommu present on Apple silicon systems. The IOVA space used by the u-boot driver (low 4GB) and physical memory do not overlap. The physical memory on this systems starts depending on the SoC either at 0x10_0000_0000 or 0x100_0000_0000. It make no sense to manage these distinct regions in a single LMB map. In addition every device has its own iommu and IO address space so sharing a single memory map between all iommu instances is not necessary. To fix this issue restore the used subset (add, alloc and free) of the previous pointer based LMB interface with "io_" as prefix. To ensure that low level lmb functions do not use the global LMB variable reorder lib/lmb.c so that the variable is not visible. Tested with patches from my "Fix device removal order for Apple dart iommu" series [2] to fix a separate issue. The cosmetic commit has two checkpatch warnings in existing code which I ignored. [1] https://lore.kernel.org/u-boot/20240826115940.3233167-1-sughosh.ganu@linaro.org/ [2] https://lore.kernel.org/u-boot/20241031-iommu_apple_dart_ordering-v1-0-8a6877946d6b@jannau.net/ Link: https://lore.kernel.org/r/20241111-io_lmb_apple_dart_iommu-v3-0-32c05da51d72@jannau.net Signed-off-by: Tom Rini --- 48fd7e9699f8799690196c76869d59c1e5b2e9a6 diff --cc include/lmb.h index 2201d6f2b6,fa91bf17ad..f221f0cce8 --- a/include/lmb.h +++ b/include/lmb.h @@@ -156,6 -156,57 +156,57 @@@ static inline int lmb_read_check(phys_a return lmb_alloc_addr(addr, len) == addr ? 0 : -1; } + /** + * io_lmb_setup() - Initialize LMB struct - * @lmb: IO LMB to initialize ++ * @io_lmb: IO LMB to initialize + * + * Returns: 0 on success, negative error code on failure + */ + int io_lmb_setup(struct lmb *io_lmb); + + /** + * io_lmb_teardown() - Tear LMB struct down - * @lmb: IO LMB to teardown ++ * @io_lmb: IO LMB to teardown + */ + void io_lmb_teardown(struct lmb *io_lmb); + + /** + * io_lmb_add() - Add an IOVA range for allocations + * @io_lmb: LMB to add the space to + * @base: Base Address of region to add + * @size: Size of the region to add + * + * Add the IOVA space [base, base + size] to be managed by io_lmb. + * + * Returns: 0 if the region addition was successful, -1 on failure + */ + long io_lmb_add(struct lmb *io_lmb, phys_addr_t base, phys_size_t size); + + /** + * io_lmb_alloc() - Allocate specified IO memory address with specified alignment + * @io_lmb: LMB to alloc from + * @size: Size of the region requested + * @align: Required address and size alignment + * + * Allocate a region of IO memory. The base parameter is used to specify the + * base address of the requested region. + * + * Return: base IO address on success, 0 on error + */ + phys_addr_t io_lmb_alloc(struct lmb *io_lmb, phys_size_t size, ulong align); + + /** + * io_lmb_free() - Free up a region of IOVA space + * @io_lmb: LMB to return the IO address space to + * @base: Base Address of region to be freed + * @size: Size of the region to be freed + * + * Free up a region of IOVA space. + * + * Return: 0 if successful, -1 on failure + */ + long io_lmb_free(struct lmb *io_lmb, phys_addr_t base, phys_size_t size); + #endif /* __KERNEL__ */ #endif /* _LINUX_LMB_H */