Skip to content

Commit 52f325f

Browse files
rmurphy-armwilldeacon
authored andcommitted
iommu/io-pgtable-arm: Correct Mali attributes
Whilst Midgard's MEMATTR follows a similar principle to the VMSA MAIR, the actual attribute values differ, so although it currently appears to work to some degree, we probably shouldn't be using our standard stage 1 MAIR for that. Instead, generate a reasonable MEMATTR with attribute values borrowed from the kbase driver; at this point we'll be overriding or ignoring pretty much all of the LPAE config, so just implement these Mali details in a dedicated allocator instead of pretending to subclass the standard VMSA format. Fixes: d08d42d ("iommu: io-pgtable: Add ARM Mali midgard MMU page table format") Tested-by: Neil Armstrong <[email protected]> Reviewed-by: Steven Price <[email protected]> Reviewed-by: Rob Herring <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 6db7bfb commit 52f325f

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

drivers/iommu/io-pgtable-arm.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@
166166
#define ARM_MALI_LPAE_TTBR_READ_INNER BIT(2)
167167
#define ARM_MALI_LPAE_TTBR_SHARE_OUTER BIT(4)
168168

169+
#define ARM_MALI_LPAE_MEMATTR_IMP_DEF 0x88ULL
170+
#define ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC 0x8DULL
171+
169172
/* IOPTE accessors */
170173
#define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d))
171174

@@ -1015,27 +1018,51 @@ arm_32_lpae_alloc_pgtable_s2(struct io_pgtable_cfg *cfg, void *cookie)
10151018
static struct io_pgtable *
10161019
arm_mali_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
10171020
{
1018-
struct io_pgtable *iop;
1021+
struct arm_lpae_io_pgtable *data;
1022+
1023+
/* No quirks for Mali (hopefully) */
1024+
if (cfg->quirks)
1025+
return NULL;
10191026

10201027
if (cfg->ias != 48 || cfg->oas > 40)
10211028
return NULL;
10221029

10231030
cfg->pgsize_bitmap &= (SZ_4K | SZ_2M | SZ_1G);
1024-
iop = arm_64_lpae_alloc_pgtable_s1(cfg, cookie);
1025-
if (iop) {
1026-
u64 mair, ttbr;
10271031

1028-
/* Copy values as union fields overlap */
1029-
mair = cfg->arm_lpae_s1_cfg.mair[0];
1030-
ttbr = cfg->arm_lpae_s1_cfg.ttbr[0];
1032+
data = arm_lpae_alloc_pgtable(cfg);
1033+
if (!data)
1034+
return NULL;
10311035

1032-
cfg->arm_mali_lpae_cfg.memattr = mair;
1033-
cfg->arm_mali_lpae_cfg.transtab = ttbr |
1034-
ARM_MALI_LPAE_TTBR_READ_INNER |
1035-
ARM_MALI_LPAE_TTBR_ADRMODE_TABLE;
1036-
}
1036+
/*
1037+
* MEMATTR: Mali has no actual notion of a non-cacheable type, so the
1038+
* best we can do is mimic the out-of-tree driver and hope that the
1039+
* "implementation-defined caching policy" is good enough. Similarly,
1040+
* we'll use it for the sake of a valid attribute for our 'device'
1041+
* index, although callers should never request that in practice.
1042+
*/
1043+
cfg->arm_mali_lpae_cfg.memattr =
1044+
(ARM_MALI_LPAE_MEMATTR_IMP_DEF
1045+
<< ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_NC)) |
1046+
(ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC
1047+
<< ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_CACHE)) |
1048+
(ARM_MALI_LPAE_MEMATTR_IMP_DEF
1049+
<< ARM_LPAE_MAIR_ATTR_SHIFT(ARM_LPAE_MAIR_ATTR_IDX_DEV));
10371050

1038-
return iop;
1051+
data->pgd = __arm_lpae_alloc_pages(data->pgd_size, GFP_KERNEL, cfg);
1052+
if (!data->pgd)
1053+
goto out_free_data;
1054+
1055+
/* Ensure the empty pgd is visible before TRANSTAB can be written */
1056+
wmb();
1057+
1058+
cfg->arm_mali_lpae_cfg.transtab = virt_to_phys(data->pgd) |
1059+
ARM_MALI_LPAE_TTBR_READ_INNER |
1060+
ARM_MALI_LPAE_TTBR_ADRMODE_TABLE;
1061+
return &data->iop;
1062+
1063+
out_free_data:
1064+
kfree(data);
1065+
return NULL;
10391066
}
10401067

10411068
struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns = {

0 commit comments

Comments
 (0)