summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurora zuma automerger <aurora-zuma-automerger@google.com>2023-05-12 07:50:36 +0000
committerCopybara-Service <copybara-worker@google.com>2023-05-24 23:55:37 -0700
commitba9d2b042ab2e39d9edc327f44712cd28e960979 (patch)
tree6438bbe960b53244f83e69137bc86137375af116
parent845dc991e47ae307e1b8eb8bf76a743812df9417 (diff)
downloadzuma-ba9d2b042ab2e39d9edc327f44712cd28e960979.tar.gz
gxp: [Copybara Auto Merge] Merge branch 'zuma' into 'android14-gs-pixel-5.15'
gxp: Retrieve correct sgt for dmabuf mapping Bug: 282024556 GitOrigin-RevId: e846e1f04b32a9f755255e56feed64c2149de585 Change-Id: I8a8a805b7c00495545aed0c2361647db089fb0a1
-rw-r--r--gxp-debug-dump.c4
-rw-r--r--gxp-dmabuf.c12
-rw-r--r--gxp-dmabuf.h7
-rw-r--r--gxp-mapping.c14
-rw-r--r--gxp-mapping.h6
5 files changed, 38 insertions, 5 deletions
diff --git a/gxp-debug-dump.c b/gxp-debug-dump.c
index 53ea055..188aaf2 100644
--- a/gxp-debug-dump.c
+++ b/gxp-debug-dump.c
@@ -421,6 +421,7 @@ static int gxp_user_buffers_vmap(struct gxp_dev *gxp,
dma_addr_t daddr;
struct gxp_mapping *mapping;
void *vaddr;
+ bool is_dmabuf;
if (!vd || vd->state == GXP_VD_RELEASED) {
dev_err(gxp->dev, "Virtual device is not available for vmap\n");
@@ -442,8 +443,9 @@ static int gxp_user_buffers_vmap(struct gxp_dev *gxp,
continue;
}
+ is_dmabuf = !mapping->host_address;
/* Map the mapping into kernel space */
- vaddr = gxp_mapping_vmap(mapping);
+ vaddr = gxp_mapping_vmap(mapping, is_dmabuf);
/*
* Release the reference from searching for the mapping.
diff --git a/gxp-dmabuf.c b/gxp-dmabuf.c
index d0dcf54..7cdf19d 100644
--- a/gxp-dmabuf.c
+++ b/gxp-dmabuf.c
@@ -117,6 +117,18 @@ err_attach:
return ERR_PTR(ret);
}
+struct sg_table *gxp_dmabuf_get_sgt(struct gxp_mapping *mapping)
+{
+ struct gxp_dmabuf_mapping *dmabuf_mapping;
+
+ if (mapping->host_address)
+ /* Not a dmabuf */
+ return NULL;
+
+ dmabuf_mapping = container_of(mapping, struct gxp_dmabuf_mapping, mapping);
+ return dmabuf_mapping->sgt;
+}
+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
MODULE_IMPORT_NS(DMA_BUF);
#endif
diff --git a/gxp-dmabuf.h b/gxp-dmabuf.h
index 94b274b..c259401 100644
--- a/gxp-dmabuf.h
+++ b/gxp-dmabuf.h
@@ -29,5 +29,12 @@
struct gxp_mapping *gxp_dmabuf_map(struct gxp_dev *gxp,
struct gcip_iommu_domain *domain, int fd,
u32 flags, enum dma_data_direction dir);
+/**
+ * gxp_dmabuf_get_sgt(): Retrieve the sg table for dmabuf
+ * @mapping: The mapping corresponding to dmabuf
+ *
+ * Return: sg table on success or NULL.
+ */
+struct sg_table *gxp_dmabuf_get_sgt(struct gxp_mapping *mapping);
#endif /* __GXP_DMABUF_H__ */
diff --git a/gxp-mapping.c b/gxp-mapping.c
index 2218ace..8f71d33 100644
--- a/gxp-mapping.c
+++ b/gxp-mapping.c
@@ -16,6 +16,7 @@
#include "gxp-client.h"
#include "gxp-debug-dump.h"
#include "gxp-dma.h"
+#include "gxp-dmabuf.h"
#include "gxp-internal.h"
#include "gxp-mapping.h"
@@ -343,7 +344,7 @@ out:
return ret;
}
-void *gxp_mapping_vmap(struct gxp_mapping *mapping)
+void *gxp_mapping_vmap(struct gxp_mapping *mapping, bool is_dmabuf)
{
struct sg_table *sgt;
struct sg_page_iter sg_iter;
@@ -364,7 +365,16 @@ void *gxp_mapping_vmap(struct gxp_mapping *mapping)
goto out;
}
- sgt = &mapping->sgt;
+ if (is_dmabuf)
+ sgt = gxp_dmabuf_get_sgt(mapping);
+ else
+ sgt = &mapping->sgt;
+
+ if (!sgt) {
+ vaddr = ERR_PTR(-EINVAL);
+ goto out;
+ }
+
for_each_sg_page(sgt->sgl, &sg_iter, sgt->orig_nents, 0)
page_count++;
diff --git a/gxp-mapping.h b/gxp-mapping.h
index 24a72b5..b0f36bd 100644
--- a/gxp-mapping.h
+++ b/gxp-mapping.h
@@ -134,7 +134,8 @@ int gxp_mapping_sync(struct gxp_mapping *mapping, u32 offset, u32 size,
/**
* gxp_mapping_vmap() - Map a mapping's buffer into kernel address space
- * @mapping: Tha mapping to map into kernel space
+ * @mapping: The mapping to map into kernel space
+ * @is_dmabuf: Whether or not the mapping is for a dmabuf
*
* If the buffer is already mapped, increments a reference count and returns
* the existing virtual address instead.
@@ -144,8 +145,9 @@ int gxp_mapping_sync(struct gxp_mapping *mapping, u32 offset, u32 size,
* Return: A pointer to the mapped buffer if successful; otherwise an ERR_PTR:
* * -ENODEV: A reference to the mapping could not be obtained
* * -ENOMEM: Insufficient memory to map the buffer
+ * * -EINVAL: No valid sgt found.
*/
-void *gxp_mapping_vmap(struct gxp_mapping *mapping);
+void *gxp_mapping_vmap(struct gxp_mapping *mapping, bool is_dmabuf);
/**
* gxp_mapping_vunmap() - Unmap a mapping from kernel address space