This patch moves the common code for traversing through the PGD, PTE
tables in userspace virtual address translation and vmalloc address translation
to a new routine. This will help us to make changes to the common code
at a single place. This will be used for board based definitions for address
translation
Signed-off-by: Suzuki K. Poulose <suzuki(a)in.ibm.com>
---
ppc.c | 184 +++++++++++++++++++++++------------------------------------------
1 files changed, 65 insertions(+), 119 deletions(-)
diff --git a/ppc.c b/ppc.c
index a9068c2..3834e7f 100755
--- a/ppc.c
+++ b/ppc.c
@@ -259,6 +259,69 @@ ppc_dump_machdep_table(ulong arg)
fprintf(fp, " machspec: %lx\n", (ulong)machdep->machspec);
}
+static int
+ppc_pgd_vtop(ulong *pgd, ulong vaddr, physaddr_t *paddr, int verbose)
+{
+ ulong *page_dir;
+ ulong *page_middle;
+ ulong *page_table;
+ ulong pgd_pte;
+ ulong pte;
+
+ if (verbose)
+ fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd);
+
+ page_dir = pgd + (vaddr >> PGDIR_SHIFT);
+
+ FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE());
+ pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir));
+
+ if (verbose)
+ fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte);
+
+ if (!pgd_pte)
+ goto no_page;
+
+ page_middle = (ulong *)pgd_pte;
+
+ if (machdep->flags & CPU_BOOKE)
+ page_table = page_middle + (BTOP(vaddr) & (PTRS_PER_PTE - 1));
+ else {
+ page_table = (ulong *)((pgd_pte & (ulong)machdep->pagemask) +
machdep->kvbase);
+ page_table += ((ulong)BTOP(vaddr) & (PTRS_PER_PTE-1));
+ }
+
+ if (verbose)
+ fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle,
+ (ulong)page_table);
+
+ FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE());
+ pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table));
+
+ if (verbose)
+ fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte);
+
+ if (!(pte & _PAGE_PRESENT)) {
+ if (pte && verbose) {
+ fprintf(fp, "\n");
+ ppc_translate_pte(pte, 0, 0);
+ }
+ goto no_page;
+ }
+
+ if (verbose) {
+ fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(pte));
+ ppc_translate_pte(pte, 0, 0);
+ }
+
+ *paddr = PAGEBASE(pte) + PAGEOFFSET(vaddr);
+
+ return TRUE;
+
+no_page:
+ return FALSE;
+
+}
/*
* Translates a user virtual address to its physical address. cmd_vtop()
@@ -275,11 +338,6 @@ ppc_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr,
int verbose)
{
ulong mm, active_mm;
ulong *pgd;
- ulong *page_dir;
- ulong *page_middle;
- ulong *page_table;
- ulong pgd_pte;
- ulong pte;
if (!tc)
error(FATAL, "current context invalid\n");
@@ -315,62 +373,7 @@ ppc_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr,
int verbose)
FAULT_ON_ERROR);
}
- if (verbose)
- fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd);
-
- page_dir = pgd + (vaddr >> PGDIR_SHIFT);
-
- FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE());
- pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir));
-
- if (verbose)
- fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte);
-
- if (!pgd_pte)
- goto no_upage;
-
- page_middle = (ulong *)pgd_pte;
-
- if (machdep->flags & CPU_BOOKE)
- page_table = page_middle + (BTOP(vaddr) & (PTRS_PER_PTE - 1));
- else {
- page_table = (ulong *)((pgd_pte & (ulong)machdep->pagemask) +
machdep->kvbase);
- page_table += ((ulong)BTOP(vaddr) & (PTRS_PER_PTE-1));
- }
-
- if (verbose)
- fprintf(fp, " PMD: %lx => %lx\n",(ulong)page_middle,
- (ulong)page_table);
-
- FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE());
- pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table));
-
- if (verbose)
- fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte);
-
- if (!(pte & _PAGE_PRESENT)) {
- *paddr = pte;
- if (pte && verbose) {
- fprintf(fp, "\n");
- ppc_translate_pte(pte, 0, 0);
- }
- goto no_upage;
- }
-
- if (!pte)
- goto no_upage;
-
- *paddr = PAGEBASE(pte) + PAGEOFFSET(vaddr);
-
- if (verbose) {
- fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(pte));
- ppc_translate_pte(pte, 0, 0);
- }
-
- return TRUE;
-
-no_upage:
- return FALSE;
+ return ppc_pgd_vtop(pgd, vaddr, paddr, verbose);
}
/*
@@ -382,11 +385,6 @@ static int
ppc_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
{
ulong *pgd;
- ulong *page_dir;
- ulong *page_middle;
- ulong *page_table;
- ulong pgd_pte;
- ulong pte;
if (!IS_KVADDR(kvaddr))
return FALSE;
@@ -403,59 +401,7 @@ ppc_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr,
int verbose)
}
pgd = (ulong *)vt->kernel_pgd[0];
-
- if (verbose)
- fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd);
-
- page_dir = pgd + (kvaddr >> PGDIR_SHIFT);
-
- FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE());
- pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir));
-
- if (verbose)
- fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte);
-
- if (!pgd_pte)
- goto no_kpage;
-
- page_middle = (ulong *)pgd_pte;
-
- if (machdep->flags & CPU_BOOKE)
- page_table = page_middle + (BTOP(kvaddr) & (PTRS_PER_PTE - 1));
- else {
- page_table = (ulong *)((pgd_pte & (ulong)machdep->pagemask) +
machdep->kvbase);
- page_table += ((ulong)BTOP(kvaddr) & (PTRS_PER_PTE-1));
- }
-
- if (verbose)
- fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle,
- (ulong)page_table);
-
- FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE());
- pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table));
-
- if (verbose)
- fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte);
-
- if (!(pte & _PAGE_PRESENT)) {
- if (pte && verbose) {
- fprintf(fp, "\n");
- ppc_translate_pte(pte, 0, 0);
- }
- goto no_kpage;
- }
-
- if (verbose) {
- fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(pte));
- ppc_translate_pte(pte, 0, 0);
- }
-
- *paddr = PAGEBASE(pte) + PAGEOFFSET(kvaddr);
-
- return TRUE;
-
-no_kpage:
- return FALSE;
+ return ppc_pgd_vtop(pgd, kvaddr, paddr, verbose);
}
/*