diff options
author | Aurora zuma automerger <aurora-zuma-automerger@google.com> | 2023-02-22 11:47:36 +0000 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-15 00:28:12 -0700 |
commit | 34d8eaa82855b989b41a6b728694c1727f091397 (patch) | |
tree | ae2a0bdbe476c4ce12acc5f09fb1b6c63836de76 | |
parent | 7d833613c6706f5fd9c0eec66685ee44b0a664b4 (diff) | |
download | zuma-34d8eaa82855b989b41a6b728694c1727f091397.tar.gz |
gxp: [Copybara Auto Merge] Merge branch 'zuma' into 'android14-gs-pixel-5.15'
gxp: adopt gcip-iommu.h (custom IOVA allocator)
Bug: 243479562
Revert "gcip: temporary disable gcip-iommu"
GCIP_MAIN_REV_ID: d70d238952509edd0cd1126632341a61edf35dbf
GitOrigin-RevId: 115a93fff1d80027513a8b05e15bdcfa9eb6b53b
Change-Id: I8995a5d166f8832791d0f0fecfc546b1a9a3786f
-rw-r--r-- | gcip-kernel-driver/drivers/gcip/Makefile | 1 | ||||
-rw-r--r-- | gxp-dma-iommu.c | 121 | ||||
-rw-r--r-- | gxp-dma.h | 49 | ||||
-rw-r--r-- | gxp-dmabuf.c | 2 | ||||
-rw-r--r-- | gxp-dmabuf.h | 2 | ||||
-rw-r--r-- | gxp-domain-pool.c | 55 | ||||
-rw-r--r-- | gxp-domain-pool.h | 14 | ||||
-rw-r--r-- | gxp-internal.h | 8 | ||||
-rw-r--r-- | gxp-mapping.c | 2 | ||||
-rw-r--r-- | gxp-mapping.h | 4 | ||||
-rw-r--r-- | gxp-vd.c | 8 | ||||
-rw-r--r-- | gxp-vd.h | 2 |
12 files changed, 124 insertions, 144 deletions
diff --git a/gcip-kernel-driver/drivers/gcip/Makefile b/gcip-kernel-driver/drivers/gcip/Makefile index 7de0874..7af6c7e 100644 --- a/gcip-kernel-driver/drivers/gcip/Makefile +++ b/gcip-kernel-driver/drivers/gcip/Makefile @@ -11,6 +11,7 @@ gcip-objs := gcip-alloc-helper.o \ gcip-domain-pool.o \ gcip-firmware.o \ gcip-image-config.o \ + gcip-iommu.o \ gcip-kci.o \ gcip-mailbox.o \ gcip-mem-pool.o \ diff --git a/gxp-dma-iommu.c b/gxp-dma-iommu.c index 3312bb1..d78bc1a 100644 --- a/gxp-dma-iommu.c +++ b/gxp-dma-iommu.c @@ -13,6 +13,8 @@ #include <linux/scatterlist.h> #include <linux/slab.h> +#include <gcip/gcip-iommu.h> + #include "gxp-config.h" #include "gxp-dma.h" #include "gxp-firmware.h" /* gxp_core_boot */ @@ -27,7 +29,7 @@ struct gxp_dma_iommu_manager { struct gxp_dma_manager dma_mgr; - struct gxp_iommu_domain *default_domain; + struct gcip_iommu_domain *default_domain; struct gxp_ssmt ssmt; }; @@ -67,14 +69,6 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent, } } -static int map_flags_to_iommu_prot(enum dma_data_direction dir, - unsigned long attrs, u32 gxp_dma_flags) -{ - bool coherent = gxp_dma_flags & GXP_MAP_COHERENT ? 1 : 0; - - return dma_info_to_prot(dir, coherent, attrs); -} - static int gxp_dma_ssmt_program(struct gxp_dev *gxp, struct iommu_domain *domain, uint core_list) { @@ -179,37 +173,32 @@ static void gxp_unmap_csrs(struct gxp_dev *gxp, struct iommu_domain *domain, /* gxp-dma.h Interface */ uint gxp_iommu_aux_get_pasid(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain) + struct gcip_iommu_domain *gdomain) { return iommu_aux_get_pasid(gdomain->domain, gxp->dev); } -struct gxp_iommu_domain *gxp_iommu_get_domain_for_dev(struct gxp_dev *gxp) +struct gcip_iommu_domain *gxp_iommu_get_domain_for_dev(struct gxp_dev *gxp) { - struct gxp_iommu_domain *gdomain = gxp->default_domain; + struct gcip_iommu_domain *gdomain = gxp->default_domain; if (IS_ERR_OR_NULL(gdomain)) { - gdomain = devm_kzalloc(gxp->dev, sizeof(*gdomain), GFP_KERNEL); - if (!gdomain) - return ERR_PTR(-ENOMEM); - gdomain->domain = iommu_get_domain_for_dev(gxp->dev); - if (!gdomain->domain) { - devm_kfree(gxp->dev, gdomain); - return ERR_PTR(-ENOMEM); - } + gdomain = gcip_iommu_get_domain_for_dev(gxp->dev); + if (IS_ERR_OR_NULL(gdomain)) + return gdomain; gxp->default_domain = gdomain; } return gdomain; } -int gxp_iommu_map(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +int gxp_iommu_map(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { return iommu_map(gdomain->domain, iova, paddr, size, prot); } -void gxp_iommu_unmap(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +void gxp_iommu_unmap(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, unsigned long iova, size_t size) { iommu_unmap(gdomain->domain, iova, size); @@ -255,15 +244,6 @@ int gxp_dma_init(struct gxp_dev *gxp) goto err_unreg_fault_handler; } -#if IS_ENABLED(CONFIG_ANDROID) - /* Enable best fit algorithm to minimize fragmentation */ - ret = iommu_dma_enable_best_fit_algo(gxp->dev); - if (ret) - dev_warn(gxp->dev, - "Failed to enable best-fit IOVA allocator (%d)\n", - ret); -#endif - gxp->dma_mgr = &(mgr->dma_mgr); return 0; @@ -298,7 +278,7 @@ void gxp_dma_init_default_resources(struct gxp_dev *gxp) } int gxp_dma_domain_attach_device(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, uint core_list) { int ret; @@ -312,14 +292,14 @@ out: } void gxp_dma_domain_detach_device(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain) + struct gcip_iommu_domain *gdomain) { iommu_aux_detach_device(gdomain->domain, gxp->dev); } int gxp_dma_map_core_resources(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, uint core_list, - u8 slice_index) + struct gcip_iommu_domain *gdomain, + uint core_list, u8 slice_index) { int ret; uint i; @@ -376,7 +356,7 @@ err: } void gxp_dma_unmap_core_resources(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, uint core_list) { uint i; @@ -476,7 +456,7 @@ static inline struct sg_table *alloc_sgt_for_buffer(void *ptr, size_t size, #if (IS_ENABLED(CONFIG_GXP_TEST) || IS_ENABLED(CONFIG_ANDROID)) && \ !IS_ENABLED(CONFIG_GXP_GEM5) int gxp_dma_map_tpu_buffer(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, uint core_list, + struct gcip_iommu_domain *gdomain, uint core_list, struct edgetpu_ext_mailbox_info *mbx_info) { uint orig_core_list = core_list; @@ -520,7 +500,7 @@ error: } void gxp_dma_unmap_tpu_buffer(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct gxp_tpu_mbx_desc mbx_desc) { uint core_list = mbx_desc.phys_core_list; @@ -541,7 +521,7 @@ void gxp_dma_unmap_tpu_buffer(struct gxp_dev *gxp, int gxp_dma_map_allocated_coherent_buffer(struct gxp_dev *gxp, struct gxp_coherent_buf *buf, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, uint gxp_dma_flags) { struct gxp_dma_iommu_manager *mgr = container_of( @@ -578,7 +558,7 @@ int gxp_dma_map_allocated_coherent_buffer(struct gxp_dev *gxp, } int gxp_dma_alloc_coherent_buf(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, size_t size, + struct gcip_iommu_domain *gdomain, size_t size, gfp_t flag, uint gxp_dma_flags, struct gxp_coherent_buf *buffer) { @@ -616,7 +596,7 @@ int gxp_dma_alloc_coherent_buf(struct gxp_dev *gxp, } void gxp_dma_unmap_allocated_coherent_buffer(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct gxp_coherent_buf *buf) { if (buf->size != iommu_unmap(gdomain->domain, buf->dma_addr, buf->size)) @@ -624,7 +604,7 @@ void gxp_dma_unmap_allocated_coherent_buffer(struct gxp_dev *gxp, } void gxp_dma_free_coherent_buf(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct gxp_coherent_buf *buf) { if (gdomain != NULL) @@ -632,65 +612,58 @@ void gxp_dma_free_coherent_buf(struct gxp_dev *gxp, dma_free_coherent(gxp->dev, buf->size, buf->vaddr, buf->dma_addr); } -int gxp_dma_map_sg(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +int gxp_dma_map_sg(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, struct scatterlist *sg, int nents, enum dma_data_direction direction, unsigned long attrs, uint gxp_dma_flags) { - int nents_mapped; - dma_addr_t daddr; - int prot = map_flags_to_iommu_prot(direction, attrs, gxp_dma_flags); - ssize_t size_mapped; + int i, nents_mapped; + ssize_t size_mapped = 0; + struct scatterlist *s; + u64 gcip_map_flags = GCIP_MAP_FLAGS_DMA_DIRECTION_TO_FLAGS(direction) | + GCIP_MAP_FLAGS_DMA_ATTR_TO_FLAGS(attrs); +#ifdef GXP_IS_DMA_COHERENT + bool coherent = gxp_dma_flags & GXP_MAP_COHERENT ? true : false; + + gcip_map_flags |= GCIP_MAP_FLAGS_DMA_COHERENT_TO_FLAGS(coherent); +#endif trace_gxp_dma_map_sg_start(nents); - nents_mapped = dma_map_sg_attrs(gxp->dev, sg, nents, direction, attrs); + nents_mapped = + gcip_iommu_domain_map_sg(gdomain, sg, nents, gcip_map_flags); if (!nents_mapped) - return 0; - - daddr = sg_dma_address(sg); - - /* - * In Linux 5.15 and beyond, `iommu_map_sg()` returns a - * `ssize_t` to encode errors that earlier versions throw out. - * Explicitly cast here for backwards compatibility. - */ - size_mapped = - (ssize_t)iommu_map_sg(gdomain->domain, daddr, sg, nents, prot); - if (size_mapped <= 0) - goto err; + goto out; + for_each_sg (sg, s, nents_mapped, i) + size_mapped += sg_dma_len(s); +out: trace_gxp_dma_map_sg_end(nents_mapped, size_mapped); return nents_mapped; - -err: - dma_unmap_sg_attrs(gxp->dev, sg, nents, direction, attrs); - return 0; } -void gxp_dma_unmap_sg(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +void gxp_dma_unmap_sg(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, struct scatterlist *sg, int nents, enum dma_data_direction direction, unsigned long attrs) { struct scatterlist *s; int i; size_t size = 0; + u64 gcip_map_flags = GCIP_MAP_FLAGS_DMA_DIRECTION_TO_FLAGS(direction) | + GCIP_MAP_FLAGS_DMA_ATTR_TO_FLAGS(attrs); trace_gxp_dma_unmap_sg_start(nents); for_each_sg (sg, s, nents, i) size += sg_dma_len(s); - if (!iommu_unmap(gdomain->domain, sg_dma_address(sg), size)) - dev_warn(gxp->dev, "Failed to unmap sg\n"); - - dma_unmap_sg_attrs(gxp->dev, sg, nents, direction, attrs); + gcip_iommu_domain_unmap_sg(gdomain, sg, nents, gcip_map_flags); trace_gxp_dma_unmap_sg_end(size); } -int gxp_dma_map_iova_sgt(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +int gxp_dma_map_iova_sgt(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, dma_addr_t iova, struct sg_table *sgt, int prot) { ssize_t size_mapped; @@ -711,7 +684,7 @@ int gxp_dma_map_iova_sgt(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, } void gxp_dma_unmap_iova_sgt(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, dma_addr_t iova, + struct gcip_iommu_domain *gdomain, dma_addr_t iova, struct sg_table *sgt) { struct scatterlist *s; @@ -741,7 +714,7 @@ void gxp_dma_sync_sg_for_device(struct gxp_dev *gxp, struct scatterlist *sg, struct sg_table * gxp_dma_map_dmabuf_attachment(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct dma_buf_attachment *attachment, enum dma_data_direction direction) { @@ -786,7 +759,7 @@ err: } void gxp_dma_unmap_dmabuf_attachment(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct dma_buf_attachment *attachment, struct sg_table *sgt, enum dma_data_direction direction) @@ -17,12 +17,9 @@ #include <soc/google/tpu-ext.h> #endif -#include "gxp-internal.h" +#include <gcip/gcip-iommu.h> -struct gxp_iommu_domain { - struct iommu_domain *domain; - uint ctx_id; -}; +#include "gxp-internal.h" struct gxp_coherent_buf { void *vaddr; /* kernel VA, no allocation if NULL */ @@ -59,7 +56,7 @@ struct gxp_dma_manager { * * Return: 0 on success or negative value indicating error */ -int gxp_iommu_map(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +int gxp_iommu_map(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); /** @@ -67,7 +64,7 @@ int gxp_iommu_map(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, * @gxp: The GXP device * @gdomain: The IOMMU domain to revert mappings in. */ -void gxp_iommu_unmap(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +void gxp_iommu_unmap(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, unsigned long iova, size_t size); /** @@ -98,7 +95,7 @@ void gxp_dma_exit(struct gxp_dev *gxp); * Caller ensures a BLOCK wakelock is hold for the iommu attaching. */ int gxp_dma_domain_attach_device(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, uint core_list); /** @@ -109,7 +106,7 @@ int gxp_dma_domain_attach_device(struct gxp_dev *gxp, * Caller ensures a BLOCK wakelock is hold for the iommu detaching. */ void gxp_dma_domain_detach_device(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain); + struct gcip_iommu_domain *gdomain); /** * gxp_dma_init_default_resources() - Set the various buffers/registers with @@ -142,8 +139,8 @@ void gxp_dma_init_default_resources(struct gxp_dev *gxp); * * -EIO - Failed to create one or more of the mappings */ int gxp_dma_map_core_resources(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, uint core_list, - u8 slice_index); + struct gcip_iommu_domain *gdomain, + uint core_list, u8 slice_index); /** * gxp_dma_unmap_core_resources() - Unmap the IOVAs mapped by @@ -156,7 +153,7 @@ int gxp_dma_map_core_resources(struct gxp_dev *gxp, * locations in their IOVA space. This function releases all those mappings. */ void gxp_dma_unmap_core_resources(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, uint core_list); #if (IS_ENABLED(CONFIG_GXP_TEST) || IS_ENABLED(CONFIG_ANDROID)) && \ @@ -173,7 +170,7 @@ void gxp_dma_unmap_core_resources(struct gxp_dev *gxp, * * -EIO - Failed to create the mappings */ int gxp_dma_map_tpu_buffer(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, uint core_list, + struct gcip_iommu_domain *gdomain, uint core_list, struct edgetpu_ext_mailbox_info *mbx_info); /** @@ -183,7 +180,7 @@ int gxp_dma_map_tpu_buffer(struct gxp_dev *gxp, * @mbx_desc: Structure holding info for already mapped TPU-DSP mailboxes. */ void gxp_dma_unmap_tpu_buffer(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct gxp_tpu_mbx_desc mbx_desc); #endif // (CONFIG_GXP_TEST || CONFIG_ANDROID) && !CONFIG_GXP_GEM5 @@ -198,7 +195,7 @@ void gxp_dma_unmap_tpu_buffer(struct gxp_dev *gxp, */ int gxp_dma_map_allocated_coherent_buffer(struct gxp_dev *gxp, struct gxp_coherent_buf *buf, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, uint gxp_dma_flags); /** * gxp_dma_unmap_allocated_coherent_buffer() - Unmap a coherent buffer @@ -207,7 +204,7 @@ int gxp_dma_map_allocated_coherent_buffer(struct gxp_dev *gxp, * @buf: The coherent buffer */ void gxp_dma_unmap_allocated_coherent_buffer(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct gxp_coherent_buf *buf); /** * gxp_dma_alloc_coherent() - Allocate and map a coherent buffer for a GXP core @@ -225,7 +222,7 @@ void gxp_dma_unmap_allocated_coherent_buffer(struct gxp_dev *gxp, * Note: Allocated buffers size may be larger than the requested size. */ int gxp_dma_alloc_coherent_buf(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, size_t size, + struct gcip_iommu_domain *gdomain, size_t size, gfp_t flag, uint gxp_dma_flags, struct gxp_coherent_buf *buffer); /** @@ -242,7 +239,7 @@ int gxp_dma_alloc_coherent_buf(struct gxp_dev *gxp, * buffer but not do any unmapping. */ void gxp_dma_free_coherent_buf(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct gxp_coherent_buf *buf); /** @@ -257,7 +254,7 @@ void gxp_dma_free_coherent_buf(struct gxp_dev *gxp, * * Return: The number of scatter-gather entries mapped to */ -int gxp_dma_map_sg(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +int gxp_dma_map_sg(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, struct scatterlist *sg, int nents, enum dma_data_direction direction, unsigned long attrs, uint gxp_dma_flags); @@ -271,7 +268,7 @@ int gxp_dma_map_sg(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, * @direction: DMA direction; Same as passed to `gxp_dma_map_sg()` * @attrs: The same set of flags used by the base DMA API */ -void gxp_dma_unmap_sg(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +void gxp_dma_unmap_sg(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, struct scatterlist *sg, int nents, enum dma_data_direction direction, unsigned long attrs); @@ -285,7 +282,7 @@ void gxp_dma_unmap_sg(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, * * Return: 0 on success. Negative errno otherwise. */ -int gxp_dma_map_iova_sgt(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, +int gxp_dma_map_iova_sgt(struct gxp_dev *gxp, struct gcip_iommu_domain *gdomain, dma_addr_t iova, struct sg_table *sgt, int prot); /** * gxp_dma_unmap_iova_sgt() - Revert gxp_dma_map_iova_sgt() @@ -296,7 +293,7 @@ int gxp_dma_map_iova_sgt(struct gxp_dev *gxp, struct gxp_iommu_domain *gdomain, * `gxp_dma_map_iova_sgt()` */ void gxp_dma_unmap_iova_sgt(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, dma_addr_t iova, + struct gcip_iommu_domain *gdomain, dma_addr_t iova, struct sg_table *sgt); /** @@ -331,7 +328,7 @@ void gxp_dma_sync_sg_for_device(struct gxp_dev *gxp, struct scatterlist *sg, */ struct sg_table * gxp_dma_map_dmabuf_attachment(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct dma_buf_attachment *attachment, enum dma_data_direction direction); @@ -346,7 +343,7 @@ gxp_dma_map_dmabuf_attachment(struct gxp_dev *gxp, * @direction: DMA direction */ void gxp_dma_unmap_dmabuf_attachment(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain, + struct gcip_iommu_domain *gdomain, struct dma_buf_attachment *attachment, struct sg_table *sgt, enum dma_data_direction direction); @@ -356,7 +353,7 @@ void gxp_dma_unmap_dmabuf_attachment(struct gxp_dev *gxp, * * Return: Domain embedding default IOMMU domain information. */ -struct gxp_iommu_domain *gxp_iommu_get_domain_for_dev(struct gxp_dev *gxp); +struct gcip_iommu_domain *gxp_iommu_get_domain_for_dev(struct gxp_dev *gxp); /** * gxp_iommu_aux_get_pasid() - Get PASID corresponding to gdomain @@ -366,7 +363,7 @@ struct gxp_iommu_domain *gxp_iommu_get_domain_for_dev(struct gxp_dev *gxp); * Return: PASID of the passed domain */ uint gxp_iommu_aux_get_pasid(struct gxp_dev *gxp, - struct gxp_iommu_domain *gdomain); + struct gcip_iommu_domain *gdomain); /** * gxp_iommu_setup_shareability() - Set shareability to enable IO-Coherency. diff --git a/gxp-dmabuf.c b/gxp-dmabuf.c index 92c419d..a152e67 100644 --- a/gxp-dmabuf.c +++ b/gxp-dmabuf.c @@ -51,7 +51,7 @@ static void destroy_dmabuf_mapping(struct gxp_mapping *mapping) } struct gxp_mapping *gxp_dmabuf_map(struct gxp_dev *gxp, - struct gxp_iommu_domain *domain, int fd, + struct gcip_iommu_domain *domain, int fd, u32 flags, enum dma_data_direction dir) { struct dma_buf *dmabuf; diff --git a/gxp-dmabuf.h b/gxp-dmabuf.h index 8e1e056..94b274b 100644 --- a/gxp-dmabuf.h +++ b/gxp-dmabuf.h @@ -27,7 +27,7 @@ * mapping of the dma-buf. Returns ERR_PTR on failure. */ struct gxp_mapping *gxp_dmabuf_map(struct gxp_dev *gxp, - struct gxp_iommu_domain *domain, int fd, + struct gcip_iommu_domain *domain, int fd, u32 flags, enum dma_data_direction dir); #endif /* __GXP_DMABUF_H__ */ diff --git a/gxp-domain-pool.c b/gxp-domain-pool.c index a0f9ead..2f6167b 100644 --- a/gxp-domain-pool.c +++ b/gxp-domain-pool.c @@ -6,22 +6,41 @@ */ #include <linux/iommu.h> +#include <linux/moduleparam.h> #include <linux/slab.h> -#include <gcip/gcip-domain-pool.h> +#include <gcip/gcip-iommu.h> #include "gxp-dma.h" #include "gxp-domain-pool.h" -int gxp_domain_pool_init(struct gxp_dev *gxp, struct gcip_domain_pool *pool, - unsigned int size) +/* If true, enable GCIP custom IOVA allocator. */ +static bool gxp_gcip_dma_window_enable = true; +module_param_named(gcip_dma_window_enable, gxp_gcip_dma_window_enable, bool, + 0660); + +/* + * See enum gcip_iommu_domain_type. + * Default(0) = utilizing iova_domain + */ +static int gxp_gcip_iommu_domain_type; +module_param_named(gcip_iommu_domain_type, gxp_gcip_iommu_domain_type, int, + 0660); + +int gxp_domain_pool_init(struct gxp_dev *gxp, + struct gcip_iommu_domain_pool *pool, unsigned int size) { - int ret = gcip_domain_pool_init(gxp->dev, pool, size); + int ret = gcip_iommu_domain_pool_init(pool, gxp->dev, 0, 0, SZ_4K, size, + gxp_gcip_iommu_domain_type); __maybe_unused int i; if (ret) return ret; + if (!gxp_gcip_dma_window_enable) + gcip_iommu_domain_pool_enable_legacy_mode(pool); + gcip_iommu_domain_pool_enable_best_fit_algo(pool); + #if IS_ENABLED(CONFIG_GXP_GEM5) for (i = 0; i < size; i++) { struct iommu_domain *domain = pool->array[i]; @@ -47,33 +66,25 @@ int gxp_domain_pool_init(struct gxp_dev *gxp, struct gcip_domain_pool *pool, return 0; } -struct gxp_iommu_domain *gxp_domain_pool_alloc(struct gcip_domain_pool *pool) +struct gcip_iommu_domain * +gxp_domain_pool_alloc(struct gcip_iommu_domain_pool *pool) { - struct iommu_domain *domain = gcip_domain_pool_alloc(pool); - struct gxp_iommu_domain *gdomain; + struct gcip_iommu_domain *gdomain = + gcip_iommu_domain_pool_alloc_domain(pool); - if (!domain) + if (IS_ERR_OR_NULL(gdomain)) return NULL; - gdomain = kmalloc(sizeof(*gdomain), GFP_KERNEL); - if (!gdomain) { - gcip_domain_pool_free(pool, domain); - return NULL; - } - - gdomain->domain = domain; - return gdomain; } -void gxp_domain_pool_free(struct gcip_domain_pool *pool, - struct gxp_iommu_domain *gdomain) +void gxp_domain_pool_free(struct gcip_iommu_domain_pool *pool, + struct gcip_iommu_domain *gdomain) { - gcip_domain_pool_free(pool, gdomain->domain); - kfree(gdomain); + gcip_iommu_domain_pool_free_domain(pool, gdomain); } -void gxp_domain_pool_destroy(struct gcip_domain_pool *pool) +void gxp_domain_pool_destroy(struct gcip_iommu_domain_pool *pool) { - gcip_domain_pool_destroy(pool); + gcip_iommu_domain_pool_destroy(pool); } diff --git a/gxp-domain-pool.h b/gxp-domain-pool.h index ad2d38a..8b2cc67 100644 --- a/gxp-domain-pool.h +++ b/gxp-domain-pool.h @@ -8,7 +8,7 @@ #ifndef __GXP_DOMAIN_POOL_H__ #define __GXP_DOMAIN_POOL_H__ -#include <gcip/gcip-domain-pool.h> +#include <gcip/gcip-iommu.h> #include "gxp-dma.h" @@ -22,19 +22,21 @@ * * returns 0 on success or negative error value. */ -int gxp_domain_pool_init(struct gxp_dev *gxp, struct gcip_domain_pool *pool, +int gxp_domain_pool_init(struct gxp_dev *gxp, + struct gcip_iommu_domain_pool *pool, unsigned int size); /* * Allocates a domain from the pool * returns NULL on error. */ -struct gxp_iommu_domain *gxp_domain_pool_alloc(struct gcip_domain_pool *pool); +struct gcip_iommu_domain * +gxp_domain_pool_alloc(struct gcip_iommu_domain_pool *pool); /* Releases a domain from the pool. */ -void gxp_domain_pool_free(struct gcip_domain_pool *pool, - struct gxp_iommu_domain *gdomain); +void gxp_domain_pool_free(struct gcip_iommu_domain_pool *pool, + struct gcip_iommu_domain *gdomain); /* Cleans up all resources used by the domain pool. */ -void gxp_domain_pool_destroy(struct gcip_domain_pool *pool); +void gxp_domain_pool_destroy(struct gcip_iommu_domain_pool *pool); #endif /* __GXP_DOMAIN_POOL_H__ */ diff --git a/gxp-internal.h b/gxp-internal.h index e00401b..c1a5bf0 100644 --- a/gxp-internal.h +++ b/gxp-internal.h @@ -59,7 +59,8 @@ struct gxp_tpu_dev { }; /* Forward declarations from submodules */ -struct gcip_domain_pool; +struct gcip_iommu_domain_pool; +struct gcip_iommu_domain; struct gxp_client; struct gxp_mailbox_manager; struct gxp_debug_dump_manager; @@ -70,7 +71,6 @@ struct gxp_core_telemetry_manager; struct gxp_thermal_manager; struct gxp_usage_stats; struct gxp_power_states; -struct gxp_iommu_domain; struct gxp_dev { struct device *dev; /* platform bus device */ @@ -111,7 +111,7 @@ struct gxp_dev { struct gxp_fw_data_manager *data_mgr; struct gxp_tpu_dev tpu_dev; struct gxp_core_telemetry_manager *core_telemetry_mgr; - struct gxp_iommu_domain *default_domain; + struct gcip_iommu_domain *default_domain; struct gcip_thermal *thermal; /* * Pointer to GSA device for firmware authentication. @@ -119,7 +119,7 @@ struct gxp_dev { */ struct device *gsa_dev; u32 memory_per_core; - struct gcip_domain_pool *domain_pool; + struct gcip_iommu_domain_pool *domain_pool; struct list_head client_list; struct mutex client_list_lock; /* Pointer and mutex of secure virtual device */ diff --git a/gxp-mapping.c b/gxp-mapping.c index 1a89b1c..2218ace 100644 --- a/gxp-mapping.c +++ b/gxp-mapping.c @@ -91,7 +91,7 @@ static void destroy_mapping(struct gxp_mapping *mapping) } struct gxp_mapping *gxp_mapping_create(struct gxp_dev *gxp, - struct gxp_iommu_domain *domain, + struct gcip_iommu_domain *domain, u64 user_address, size_t size, u32 flags, enum dma_data_direction dir) { diff --git a/gxp-mapping.h b/gxp-mapping.h index 8d970ef..24a72b5 100644 --- a/gxp-mapping.h +++ b/gxp-mapping.h @@ -37,7 +37,7 @@ struct gxp_mapping { */ u64 host_address; struct gxp_dev *gxp; - struct gxp_iommu_domain *domain; + struct gcip_iommu_domain *domain; /* * `device_address` and `size` are the base address and size of the * user buffer a mapping represents. @@ -96,7 +96,7 @@ void gxp_mapping_iova_log(struct gxp_client *client, struct gxp_mapping *map, * to map the buffer for the device. */ struct gxp_mapping *gxp_mapping_create(struct gxp_dev *gxp, - struct gxp_iommu_domain *domain, + struct gcip_iommu_domain *domain, u64 user_address, size_t size, u32 flags, enum dma_data_direction dir); @@ -345,19 +345,15 @@ static void unmap_fw_image_config(struct gxp_dev *gxp, static int map_fw_image(struct gxp_dev *gxp, struct gxp_virtual_device *vd) { - struct gxp_iommu_domain *gdomain = vd->domain; - /* Maps all FW regions together. */ - return gxp_iommu_map(gxp, gdomain, gxp->fwbufs[0].daddr, + return gxp_iommu_map(gxp, vd->domain, gxp->fwbufs[0].daddr, gxp->fwbufs[0].paddr, gxp->fwbufs[0].size * GXP_NUM_CORES, IOMMU_READ); } static void unmap_fw_image(struct gxp_dev *gxp, struct gxp_virtual_device *vd) { - struct gxp_iommu_domain *gdomain = vd->domain; - - gxp_iommu_unmap(gxp, gdomain, gxp->fwbufs[0].daddr, + gxp_iommu_unmap(gxp, vd->domain, gxp->fwbufs[0].daddr, gxp->fwbufs[0].size * GXP_NUM_CORES); } @@ -70,7 +70,7 @@ struct gxp_virtual_device { struct gxp_dev *gxp; uint num_cores; void *fw_app; - struct gxp_iommu_domain *domain; + struct gcip_iommu_domain *domain; struct mailbox_resp_queue *mailbox_resp_queues; struct rb_root mappings_root; struct rw_semaphore mappings_semaphore; |