3 files changed, 43 insertions(+), 28 deletions(-)
xen/arch/powerpc/memory.c | 1
xen/arch/powerpc/mm.c | 56 ++++++++++++++++++++++++++----------------
xen/include/asm-powerpc/mm.h | 14 +++++-----
# HG changeset patch
# User Ryan Harper <ryanh@xxxxxxxxxx>
# Date 1172103252 21600
# Node ID 82803360d949f547abfd7601177ecd836e492e36
# Parent 33f05ec503bfabccd119f06b30037b618f8d05b9
[PATCH] xen: add machine_to_phys table for ppc
Signed-off-by: Ryan Harper <ryanh@xxxxxxxxxx>
ediff -r a9398ae1c634 xen/arch/powerpc/memory.c
diff -r 33f05ec503bf -r 82803360d949 xen/arch/powerpc/memory.c
--- a/xen/arch/powerpc/memory.c Wed Feb 21 18:14:12 2007 -0600
+++ b/xen/arch/powerpc/memory.c Wed Feb 21 18:14:12 2007 -0600
@@ -176,6 +176,7 @@ void memory_init(module_t *mod, int mcou
DBG("total_pages: 0x%016lx\n", total_pages);
init_frametable();
+ init_machine_to_phys_table();
numa_initmem_init(0, max_page);
diff -r 33f05ec503bf -r 82803360d949 xen/arch/powerpc/mm.c
--- a/xen/arch/powerpc/mm.c Wed Feb 21 18:14:12 2007 -0600
+++ b/xen/arch/powerpc/mm.c Wed Feb 21 18:14:12 2007 -0600
@@ -43,6 +43,9 @@ unsigned long max_page;
unsigned long max_page;
unsigned long total_pages;
+/* machine to phys mapping to used by all domains */
+unsigned long *machine_phys_mapping;
+
void __init init_frametable(void)
{
unsigned long p;
@@ -58,6 +61,25 @@ void __init init_frametable(void)
frame_table = (struct page_info *)(p << PAGE_SHIFT);
for (i = 0; i < nr_pages; i += 1)
clear_page((void *)((p + i) << PAGE_SHIFT));
+}
+
+/* array of pfns, indexed by mfn */
+void __init init_machine_to_phys_table(void)
+{
+ unsigned long p;
+ unsigned long nr_pages;
+ int i;
+
+ nr_pages = PFN_UP(max_page * sizeof(unsigned long));
+
+ p = alloc_boot_pages(nr_pages, 1);
+ if (p == 0)
+ panic("Not enough memory for machine phys mapping table\n");
+
+ machine_phys_mapping = (unsigned long *)(p << PAGE_SHIFT);
+ for (i = 0; i < nr_pages; i += 1)
+ clear_page((void *)((p + i) << PAGE_SHIFT));
+
}
void share_xen_page_with_guest(
@@ -489,10 +511,12 @@ ulong pfn2mfn(struct domain *d, ulong pf
/* mfn_to_pfn */
unsigned long mfn_to_gmfn(struct domain *d, unsigned long mfn)
{
- ulong cur_pfn;
+ struct page_info *pg = mfn_to_page(mfn);
ulong gnttab_mfn;
- ulong rma_mfn;
- uint ext_nrpages = (1 << cpu_extent_order());
+
+ /* is this our mfn? */
+ if ( page_get_owner(pg) != d )
+ return INVALID_M2P_ENTRY;
/* grant? */
gnttab_mfn = gnttab_shared_mfn(d, d->grant_table, 0);
@@ -503,22 +527,8 @@ unsigned long mfn_to_gmfn(struct domain
if (d->is_privileged && cpu_io_mfn(mfn))
return mfn;
- rma_mfn = page_to_mfn(d->arch.rma_page);
- if (mfn >= rma_mfn &&
- mfn < (rma_mfn + (1 << d->arch.rma_order)))
- return mfn - rma_mfn;
-
- /* check extents (cpu-defined contiguous chunks after RMA) */
- cur_pfn = 1UL << d->arch.rma_order; /* start looking after RMA */
- for ( ; cur_pfn < d->max_pages; cur_pfn += ext_nrpages )
- {
- uint b_mfn = d->arch.p2m[cur_pfn];
- uint e_mfn = b_mfn + ext_nrpages;
-
- if (mfn >= b_mfn && mfn < e_mfn)
- return cur_pfn + (mfn - b_mfn);
- }
- return INVALID_M2P_ENTRY;
+ /* check m2p table */
+ return get_gpfn_from_mfn(mfn);
}
void guest_physmap_add_page(
@@ -543,8 +553,10 @@ void guest_physmap_add_page(
printk("Ack! PFN aliased. pfn%lx, old mfn=%lx, new mfn=%lx\n",
gpfn, d->arch.p2m[gpfn], mfn);
- /* pfn and mfn ok, map it */
+ /* pfn and mfn ok, map p2m */
d->arch.p2m[gpfn] = mfn;
+ /* map m2p */
+ set_gpfn_from_mfn(mfn, gpfn);
}
void guest_physmap_remove_page(
@@ -562,8 +574,10 @@ void guest_physmap_remove_page(
return;
}
- /* pfn and mfn ok, unmap it */
+ /* pfn and mfn ok, unmap p2m */
d->arch.p2m[gpfn] = INVALID_MFN;
+ /* unmap m2p */
+ set_gpfn_from_mfn(mfn, INVALID_M2P_ENTRY);
}
void shadow_drop_references(
diff -r 33f05ec503bf -r 82803360d949 xen/include/asm-powerpc/mm.h
--- a/xen/include/asm-powerpc/mm.h Wed Feb 21 18:14:12 2007 -0600
+++ b/xen/include/asm-powerpc/mm.h Wed Feb 21 18:14:12 2007 -0600
@@ -145,6 +145,7 @@ extern unsigned long max_page;
extern unsigned long max_page;
extern unsigned long total_pages;
void init_frametable(void);
+void init_machine_to_phys_table(void);
void free_rma_check(struct page_info *page);
static inline void put_page(struct page_info *page)
@@ -226,14 +227,13 @@ typedef struct {
} vm_assist_info_t;
extern vm_assist_info_t vm_assist_info[];
-
-/* hope that accesses to this will fail spectacularly */
-#undef machine_to_phys_mapping
+extern unsigned long *machine_phys_mapping;
+#define machine_to_phys_mapping (machine_phys_mapping)
#define INVALID_M2P_ENTRY (~0UL)
-
-/* do nothing, its all calculated */
-#define set_gpfn_from_mfn(mfn, pfn) do { } while (0)
-#define get_gpfn_from_mfn(mfn) (mfn)
+#define VALID_M2P(_e) (!((_e) & (1UL<<(BITS_PER_LONG-1))))
+
+#define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
+#define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)])
extern unsigned long mfn_to_gmfn(struct domain *d, unsigned long mfn);
_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel
|