Skip to content

Commit ed56c12

Browse files
jannaumarcan
authored andcommitted
drm: apple: Align PIODMA buffers to SZ_16K
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 <[email protected]>
1 parent d1b7526 commit ed56c12

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

drivers/gpu/drm/apple/iomfb_template.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ static struct dcp_map_buf_resp dcpep_cb_map_piodma(struct apple_dcp *dcp,
279279
ret = iommu_map_sgtable(dcp->iommu_dom, memdesc->dva, map,
280280
IOMMU_READ | IOMMU_WRITE);
281281

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

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

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

358364
dma_get_sgtable(dcp->dev, &memdesc->map, memdesc->buf, memdesc->dva,
359-
memdesc->size);
365+
size);
360366
resp.dva = memdesc->dva;
361367

362368
return resp;

0 commit comments

Comments
 (0)