Skip to content

Commit

Permalink
drm: apple: Align PIODMA buffers to SZ_16K
Browse files Browse the repository at this point in the history
The iommu scatter table/list mapping can only map full iommu page size
extents. Just align the actual the allocation to the iommu page size.
This could be handled differently using DARTs subpage protection but
there's no easy way to integrate that.

Signed-off-by: Janne Grunau <j@jannau.net>
  • Loading branch information
jannau authored and herrnst committed Aug 31, 2023
1 parent 990ce54 commit 99f02a0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions drivers/gpu/drm/apple/iomfb_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ static struct dcp_map_buf_resp dcpep_cb_map_piodma(struct apple_dcp *dcp,
ret = iommu_map_sgtable(dcp->iommu_dom, memdesc->dva, map,
IOMMU_READ | IOMMU_WRITE);

if (ret != memdesc->size) {
/* HACK: expect size to be 16K aligned since the iommu API only maps
* full pages
*/
if (ret < 0 || ret != ALIGN(memdesc->size, SZ_16K)) {
dev_err(dcp->dev, "iommu_map_sgtable() returned %zd instead of expected buffer size of %zu\n", ret, memdesc->size);
goto reject;
}
Expand Down Expand Up @@ -334,6 +337,7 @@ dcpep_cb_allocate_buffer(struct apple_dcp *dcp,
{
struct dcp_allocate_buffer_resp resp = { 0 };
struct dcp_mem_descriptor *memdesc;
size_t size;
u32 id;

resp.dva_size = ALIGN(req->size, 4096);
Expand All @@ -352,11 +356,13 @@ dcpep_cb_allocate_buffer(struct apple_dcp *dcp,
memdesc = &dcp->memdesc[id];

memdesc->size = resp.dva_size;
memdesc->buf = dma_alloc_coherent(dcp->dev, memdesc->size,
/* HACK: align size to 16K since the iommu API only maps full pages */
size = ALIGN(resp.dva_size, SZ_16K);
memdesc->buf = dma_alloc_coherent(dcp->dev, size,
&memdesc->dva, GFP_KERNEL);

dma_get_sgtable(dcp->dev, &memdesc->map, memdesc->buf, memdesc->dva,
memdesc->size);
size);
resp.dva = memdesc->dva;

return resp;
Expand Down

0 comments on commit 99f02a0

Please sign in to comment.