2011-03-15 16:08:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright IBM Corp. 2011
|
|
|
|
* Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
|
|
|
|
*/
|
2012-11-02 11:56:43 +00:00
|
|
|
#include <linux/hugetlb.h>
|
2011-03-15 16:08:22 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
2011-10-30 14:17:13 +00:00
|
|
|
#include <asm/cacheflush.h>
|
2011-03-15 16:08:22 +00:00
|
|
|
#include <asm/pgtable.h>
|
2012-11-02 11:56:43 +00:00
|
|
|
#include <asm/page.h>
|
|
|
|
|
|
|
|
void storage_key_init_range(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
unsigned long boundary, function, size;
|
|
|
|
|
|
|
|
while (start < end) {
|
|
|
|
if (MACHINE_HAS_EDAT2) {
|
|
|
|
/* set storage keys for a 2GB frame */
|
|
|
|
function = 0x22000 | PAGE_DEFAULT_KEY;
|
|
|
|
size = 1UL << 31;
|
|
|
|
boundary = (start + size) & ~(size - 1);
|
|
|
|
if (boundary <= end) {
|
|
|
|
do {
|
|
|
|
start = pfmf(function, start);
|
|
|
|
} while (start < boundary);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (MACHINE_HAS_EDAT1) {
|
|
|
|
/* set storage keys for a 1MB frame */
|
|
|
|
function = 0x21000 | PAGE_DEFAULT_KEY;
|
|
|
|
size = 1UL << 20;
|
|
|
|
boundary = (start + size) & ~(size - 1);
|
|
|
|
if (boundary <= end) {
|
|
|
|
do {
|
|
|
|
start = pfmf(function, start);
|
|
|
|
} while (start < boundary);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page_set_storage_key(start, PAGE_DEFAULT_KEY, 0);
|
|
|
|
start += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
2011-03-15 16:08:22 +00:00
|
|
|
|
2012-10-01 14:18:46 +00:00
|
|
|
static pte_t *walk_page_table(unsigned long addr)
|
|
|
|
{
|
|
|
|
pgd_t *pgdp;
|
|
|
|
pud_t *pudp;
|
|
|
|
pmd_t *pmdp;
|
|
|
|
pte_t *ptep;
|
|
|
|
|
|
|
|
pgdp = pgd_offset_k(addr);
|
|
|
|
if (pgd_none(*pgdp))
|
|
|
|
return NULL;
|
|
|
|
pudp = pud_offset(pgdp, addr);
|
2012-10-08 07:18:26 +00:00
|
|
|
if (pud_none(*pudp) || pud_large(*pudp))
|
2012-10-01 14:18:46 +00:00
|
|
|
return NULL;
|
|
|
|
pmdp = pmd_offset(pudp, addr);
|
|
|
|
if (pmd_none(*pmdp) || pmd_large(*pmdp))
|
|
|
|
return NULL;
|
|
|
|
ptep = pte_offset_kernel(pmdp, addr);
|
|
|
|
if (pte_none(*ptep))
|
|
|
|
return NULL;
|
|
|
|
return ptep;
|
|
|
|
}
|
|
|
|
|
2011-03-15 16:08:22 +00:00
|
|
|
static void change_page_attr(unsigned long addr, int numpages,
|
|
|
|
pte_t (*set) (pte_t))
|
|
|
|
{
|
|
|
|
pte_t *ptep, pte;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numpages; i++) {
|
2012-10-01 14:18:46 +00:00
|
|
|
ptep = walk_page_table(addr);
|
|
|
|
if (WARN_ON_ONCE(!ptep))
|
|
|
|
break;
|
2011-03-15 16:08:22 +00:00
|
|
|
pte = *ptep;
|
|
|
|
pte = set(pte);
|
2011-05-23 08:24:40 +00:00
|
|
|
__ptep_ipte(addr, ptep);
|
2011-03-15 16:08:22 +00:00
|
|
|
*ptep = pte;
|
2011-04-20 08:15:32 +00:00
|
|
|
addr += PAGE_SIZE;
|
2011-03-15 16:08:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_memory_ro(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
change_page_attr(addr, numpages, pte_wrprotect);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_memory_rw(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
change_page_attr(addr, numpages, pte_mkwrite);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not possible */
|
|
|
|
int set_memory_nx(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-19 22:55:26 +00:00
|
|
|
|
|
|
|
int set_memory_x(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-02 12:28:48 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_PAGEALLOC
|
|
|
|
void kernel_map_pages(struct page *page, int numpages, int enable)
|
|
|
|
{
|
|
|
|
unsigned long address;
|
|
|
|
pgd_t *pgd;
|
|
|
|
pud_t *pud;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numpages; i++) {
|
|
|
|
address = page_to_phys(page + i);
|
|
|
|
pgd = pgd_offset_k(address);
|
|
|
|
pud = pud_offset(pgd, address);
|
|
|
|
pmd = pmd_offset(pud, address);
|
|
|
|
pte = pte_offset_kernel(pmd, address);
|
|
|
|
if (!enable) {
|
|
|
|
__ptep_ipte(address, pte);
|
|
|
|
pte_val(*pte) = _PAGE_TYPE_EMPTY;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*pte = mk_pte_phys(address, __pgprot(_PAGE_TYPE_RW));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_HIBERNATION
|
|
|
|
bool kernel_page_present(struct page *page)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
addr = page_to_phys(page);
|
|
|
|
asm volatile(
|
|
|
|
" lra %1,0(%1)\n"
|
|
|
|
" ipm %0\n"
|
|
|
|
" srl %0,28"
|
|
|
|
: "=d" (cc), "+a" (addr) : : "cc");
|
|
|
|
return cc == 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HIBERNATION */
|
|
|
|
|
|
|
|
#endif /* CONFIG_DEBUG_PAGEALLOC */
|