Skip to content

Commit

Permalink
powerpc: helper functions to initialize AMR, IAMR and UAMOR registers
Browse files Browse the repository at this point in the history
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 <bauerman@linux.vnet.ibm.com>
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Ram Pai authored and Michael Ellerman committed Jan 20, 2018
1 parent 1b4037d commit 4d70b69
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions arch/powerpc/mm/pkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ bool pkey_execute_disable_supported;
int pkeys_total; /* Total pkeys as per device tree */
u32 initial_allocation_mask; /* Bits set for reserved keys */

#define AMR_BITS_PER_PKEY 2
#define PKEY_REG_BITS (sizeof(u64)*8)
#define pkeyshift(pkey) (PKEY_REG_BITS - ((pkey+1) * AMR_BITS_PER_PKEY))

int pkey_initialize(void)
{
int os_reserved, i;
Expand Down Expand Up @@ -103,3 +107,46 @@ static inline void write_uamor(u64 value)
{
mtspr(SPRN_UAMOR, value);
}

static inline void init_amr(int pkey, u8 init_bits)
{
u64 new_amr_bits = (((u64)init_bits & 0x3UL) << pkeyshift(pkey));
u64 old_amr = read_amr() & ~((u64)(0x3ul) << pkeyshift(pkey));

write_amr(old_amr | new_amr_bits);
}

static inline void init_iamr(int pkey, u8 init_bits)
{
u64 new_iamr_bits = (((u64)init_bits & 0x1UL) << pkeyshift(pkey));
u64 old_iamr = read_iamr() & ~((u64)(0x1ul) << pkeyshift(pkey));

write_iamr(old_iamr | new_iamr_bits);
}

static void pkey_status_change(int pkey, bool enable)
{
u64 old_uamor;

/* Reset the AMR and IAMR bits for this key */
init_amr(pkey, 0x0);
init_iamr(pkey, 0x0);

/* Enable/disable key */
old_uamor = read_uamor();
if (enable)
old_uamor |= (0x3ul << pkeyshift(pkey));
else
old_uamor &= ~(0x3ul << pkeyshift(pkey));
write_uamor(old_uamor);
}

void __arch_activate_pkey(int pkey)
{
pkey_status_change(pkey, true);
}

void __arch_deactivate_pkey(int pkey)
{
pkey_status_change(pkey, false);
}

0 comments on commit 4d70b69

Please sign in to comment.