Skip to content

Commit 4d70b69

Browse files
Ram Paimpe
authored andcommitted
powerpc: helper functions to initialize AMR, IAMR and UAMOR registers
Introduce helper functions that can initialize the bits in the AMR, IAMR and UAMOR register; the bits that correspond to the given pkey. Reviewed-by: Thiago Jung Bauermann <[email protected]> Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 1b4037d commit 4d70b69

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

arch/powerpc/mm/pkeys.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ bool pkey_execute_disable_supported;
1212
int pkeys_total; /* Total pkeys as per device tree */
1313
u32 initial_allocation_mask; /* Bits set for reserved keys */
1414

15+
#define AMR_BITS_PER_PKEY 2
16+
#define PKEY_REG_BITS (sizeof(u64)*8)
17+
#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey+1) * AMR_BITS_PER_PKEY))
18+
1519
int pkey_initialize(void)
1620
{
1721
int os_reserved, i;
@@ -103,3 +107,46 @@ static inline void write_uamor(u64 value)
103107
{
104108
mtspr(SPRN_UAMOR, value);
105109
}
110+
111+
static inline void init_amr(int pkey, u8 init_bits)
112+
{
113+
u64 new_amr_bits = (((u64)init_bits & 0x3UL) << pkeyshift(pkey));
114+
u64 old_amr = read_amr() & ~((u64)(0x3ul) << pkeyshift(pkey));
115+
116+
write_amr(old_amr | new_amr_bits);
117+
}
118+
119+
static inline void init_iamr(int pkey, u8 init_bits)
120+
{
121+
u64 new_iamr_bits = (((u64)init_bits & 0x1UL) << pkeyshift(pkey));
122+
u64 old_iamr = read_iamr() & ~((u64)(0x1ul) << pkeyshift(pkey));
123+
124+
write_iamr(old_iamr | new_iamr_bits);
125+
}
126+
127+
static void pkey_status_change(int pkey, bool enable)
128+
{
129+
u64 old_uamor;
130+
131+
/* Reset the AMR and IAMR bits for this key */
132+
init_amr(pkey, 0x0);
133+
init_iamr(pkey, 0x0);
134+
135+
/* Enable/disable key */
136+
old_uamor = read_uamor();
137+
if (enable)
138+
old_uamor |= (0x3ul << pkeyshift(pkey));
139+
else
140+
old_uamor &= ~(0x3ul << pkeyshift(pkey));
141+
write_uamor(old_uamor);
142+
}
143+
144+
void __arch_activate_pkey(int pkey)
145+
{
146+
pkey_status_change(pkey, true);
147+
}
148+
149+
void __arch_deactivate_pkey(int pkey)
150+
{
151+
pkey_status_change(pkey, false);
152+
}

0 commit comments

Comments
 (0)