Skip to content

Commit

Permalink
sh: Abstract the number of page table levels
Browse files Browse the repository at this point in the history
Keep the dimensions of the page tables in a separate header file in
preparation for allowing a three level page table structure.

Signed-off-by: Matt Fleming <matt@console-pimps.org>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Matt Fleming authored and Paul Mundt committed Dec 17, 2009
1 parent 2f7bb2d commit b73c806
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 38 deletions.
24 changes: 3 additions & 21 deletions arch/sh/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include <linux/quicklist.h>
#include <asm/page.h>

#define QUICK_PGD 0 /* We preserve special mappings over free */
#define QUICK_PT 1 /* Other page table pages that are zero on free */

#include <asm/pgalloc_nopmd.h>

static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
pte_t *pte)
{
Expand All @@ -20,28 +21,9 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
}
#define pmd_pgtable(pmd) pmd_page(pmd)

static inline void pgd_ctor(void *x)
{
pgd_t *pgd = x;

memcpy(pgd + USER_PTRS_PER_PGD,
swapper_pg_dir + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
}

/*
* Allocate and free page tables.
*/
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
{
return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
quicklist_free(QUICK_PGD, NULL, pgd);
}

static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
unsigned long address)
{
Expand Down Expand Up @@ -81,7 +63,7 @@ do { \

static inline void check_pgt_cache(void)
{
quicklist_trim(QUICK_PGD, NULL, 25, 16);
__check_pgt_cache();
quicklist_trim(QUICK_PT, NULL, 25, 16);
}

Expand Down
30 changes: 30 additions & 0 deletions arch/sh/include/asm/pgalloc_nopmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef __ASM_SH_PGALLOC_NOPMD_H
#define __ASM_SH_PGALLOC_NOPMD_H

#define QUICK_PGD 0 /* We preserve special mappings over free */

static inline void pgd_ctor(void *x)
{
pgd_t *pgd = x;

memcpy(pgd + USER_PTRS_PER_PGD,
swapper_pg_dir + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
}

static inline pgd_t *pgd_alloc(struct mm_struct *mm)
{
return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
quicklist_free(QUICK_PGD, NULL, pgd);
}

static inline void __check_pgt_cache(void)
{
quicklist_trim(QUICK_PGD, NULL, 25, 16);
}

#endif /* __ASM_SH_PGALLOC_NOPMD_H */
18 changes: 1 addition & 17 deletions arch/sh/include/asm/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef __ASM_SH_PGTABLE_H
#define __ASM_SH_PGTABLE_H

#include <asm-generic/pgtable-nopmd.h>
#include <asm/pgtable_nopmd.h>
#include <asm/page.h>

#ifndef __ASSEMBLY__
Expand Down Expand Up @@ -51,28 +51,12 @@ static inline unsigned long long neff_sign_extend(unsigned long val)
#define NPHYS_SIGN (1LL << (NPHYS - 1))
#define NPHYS_MASK (-1LL << NPHYS)

/*
* traditional two-level paging structure
*/
/* PTE bits */
#if defined(CONFIG_X2TLB) || defined(CONFIG_SUPERH64)
# define PTE_MAGNITUDE 3 /* 64-bit PTEs on extended mode SH-X2 TLB */
#else
# define PTE_MAGNITUDE 2 /* 32-bit PTEs */
#endif
#define PTE_SHIFT PAGE_SHIFT
#define PTE_BITS (PTE_SHIFT - PTE_MAGNITUDE)

/* PGD bits */
#define PGDIR_SHIFT (PTE_SHIFT + PTE_BITS)
#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
#define PGDIR_MASK (~(PGDIR_SIZE-1))

/* Entries per level */
#define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE))
#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t))

#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
#define FIRST_USER_ADDRESS 0

#define PHYS_ADDR_MASK29 0x1fffffff
Expand Down
22 changes: 22 additions & 0 deletions arch/sh/include/asm/pgtable_nopmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __ASM_SH_PGTABLE_NOPMD_H
#define __ASM_SH_PGTABLE_NOPMD_H

#include <asm-generic/pgtable-nopmd.h>

/*
* traditional two-level paging structure
*/

/* PTE bits */
#define PTE_MAGNITUDE 2 /* 32-bit PTEs */

#define PTE_SHIFT PAGE_SHIFT
#define PTE_BITS (PTE_SHIFT - PTE_MAGNITUDE)

/* PGD bits */
#define PGDIR_SHIFT (PTE_SHIFT + PTE_BITS)

#define PTRS_PER_PGD (PAGE_SIZE / (1 << PTE_MAGNITUDE))
#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)

#endif /* __ASM_SH_PGTABLE_NOPMD_H */

0 comments on commit b73c806

Please sign in to comment.