Skip to content

Commit

Permalink
iommu/io-pgtable: Add DART subpage protection support
Browse files Browse the repository at this point in the history
DART allows to only expose a subpage to the device. While this is an
optional feature on the M1 DARTs the new ones present on the Pro/Max
models require this field in every PTE.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
Signed-off-by: Janne Grunau <j@jannau.net>
Reviewed-by: Rob Herring <robh@kernel.org>
Acked-by: Hector Martin <marcan@marcan.st>
Link: https://lore.kernel.org/r/20220916094152.87137-4-j@jannau.net
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Sven Peter authored and Joerg Roedel committed Sep 26, 2022
1 parent 745ef10 commit d8fe365
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/iommu/io-pgtable-dart.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define pr_fmt(fmt) "dart io-pgtable: " fmt

#include <linux/atomic.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/io-pgtable.h>
#include <linux/kernel.h>
Expand All @@ -40,6 +41,9 @@
#define DART_PTES_PER_TABLE(d) \
(DART_GRANULE(d) >> ilog2(sizeof(dart_iopte)))

#define APPLE_DART_PTE_SUBPAGE_START GENMASK_ULL(63, 52)
#define APPLE_DART_PTE_SUBPAGE_END GENMASK_ULL(51, 40)

#define APPLE_DART1_PADDR_MASK GENMASK_ULL(35, 12)

/* Apple DART1 protection bits */
Expand Down Expand Up @@ -107,6 +111,10 @@ static int dart_init_pte(struct dart_io_pgtable *data,
return -EEXIST;
}

/* subpage protection: always allow access to the entire page */
pte |= FIELD_PREP(APPLE_DART_PTE_SUBPAGE_START, 0);
pte |= FIELD_PREP(APPLE_DART_PTE_SUBPAGE_END, 0xfff);

pte |= APPLE_DART1_PTE_PROT_SP_DIS;
pte |= APPLE_DART_PTE_VALID;

Expand Down

0 comments on commit d8fe365

Please sign in to comment.