|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] arm/mpu: Provide a constructor for pr_t type
commit a37f924e74850fa92f62cc0a37880fb9b4d7e9da
Author: Luca Fancellu <luca.fancellu@xxxxxxx>
AuthorDate: Fri May 23 07:54:06 2025 +0100
Commit: Michal Orzel <michal.orzel@xxxxxxx>
CommitDate: Fri May 30 08:46:21 2025 +0200
arm/mpu: Provide a constructor for pr_t type
Provide a function that creates a pr_t object from a memory
range and some attributes.
Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
xen/arch/arm/include/asm/mpu/mm.h | 10 ++++++
xen/arch/arm/mpu/mm.c | 68 +++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+)
diff --git a/xen/arch/arm/include/asm/mpu/mm.h
b/xen/arch/arm/include/asm/mpu/mm.h
index d7950d9b4f..a7f970b465 100644
--- a/xen/arch/arm/include/asm/mpu/mm.h
+++ b/xen/arch/arm/include/asm/mpu/mm.h
@@ -65,6 +65,16 @@ void read_protection_region(pr_t *pr_read, uint8_t sel);
/* Writes the MPU region (from @pr_write) with index @sel to the HW */
void write_protection_region(const pr_t *pr_write, uint8_t sel);
+/*
+ * Creates a pr_t structure describing a protection region.
+ *
+ * @base: base address as base of the protection region.
+ * @limit: exclusive address as limit of the protection region.
+ * @flags: memory flags for the mapping.
+ * @return: pr_t structure describing a protection region.
+ */
+pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags);
+
#endif /* __ARM_MPU_MM_H__ */
/*
diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index 9c5789cdf1..86fbe105af 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -9,6 +9,7 @@
#include <xen/types.h>
#include <asm/mpu.h>
#include <asm/mpu/mm.h>
+#include <asm/page.h>
#include <asm/sysregs.h>
struct page_info *frame_table;
@@ -155,6 +156,73 @@ void write_protection_region(const pr_t *pr_write, uint8_t
sel)
break;
}
}
+
+pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags)
+{
+ unsigned int attr_idx = PAGE_AI_MASK(flags);
+ prbar_t prbar;
+ prlar_t prlar;
+ pr_t region;
+
+ /* Build up value for PRBAR_EL2. */
+ prbar = (prbar_t) {
+ .reg = {
+ .xn_0 = 0,
+ .xn = PAGE_XN_MASK(flags),
+ .ap_0 = 0,
+ .ro = PAGE_RO_MASK(flags)
+ }};
+
+ switch ( attr_idx )
+ {
+ /*
+ * ARM ARM: Shareable, Inner Shareable, and Outer Shareable Normal memory
+ * (DDI 0487L.a B2.10.1.1.1 Note section):
+ *
+ * Because all data accesses to Non-cacheable locations are data coherent
+ * to all observers, Non-cacheable locations are always treated as Outer
+ * Shareable
+ *
+ * ARM ARM: Device memory (DDI 0487L.a B2.10.2)
+ *
+ * All of these memory types have the following properties:
+ * [...]
+ * - Data accesses to memory locations are coherent for all observers in
+ * the system, and correspondingly are treated as being Outer Shareable
+ */
+ case MT_NORMAL_NC:
+ /* Fall through */
+ case MT_DEVICE_nGnRnE:
+ /* Fall through */
+ case MT_DEVICE_nGnRE:
+ prbar.reg.sh = LPAE_SH_OUTER;
+ break;
+ default:
+ /* Xen mappings are SMP coherent */
+ prbar.reg.sh = LPAE_SH_INNER;
+ break;
+ }
+
+ /* Build up value for PRLAR_EL2. */
+ prlar = (prlar_t) {
+ .reg = {
+ .ns = 0, /* Hyp mode is in secure world */
+ .ai = attr_idx,
+ .en = 1, /* Region enabled */
+ }};
+
+ /* Build up MPU memory region. */
+ region = (pr_t) {
+ .prbar = prbar,
+ .prlar = prlar,
+ };
+
+ /* Set base address and limit address. */
+ pr_set_base(®ion, base);
+ pr_set_limit(®ion, limit);
+
+ return region;
+}
#endif /* CONFIG_ARM_64 */
void __init setup_mm(void)
--
generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |