# HG changeset patch
# User Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
# Node ID 374b41b4f227a5a9e29e70a889a0226bd43db8d5
# Parent 30abfbe6e047859c7ef8884e27594bd41ea45028
[LINUX][XEN] introduce arch specific GNTTAB routines
They are ifdef'ed CONFIG_PPC_XEN now, but the intention is to make
them "official" arch interfaces and eventually remove the ifdefs from
this file completely.
Signed-off-by: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
---
drivers/xen/core/gnttab.c | 85 ++++++++++++++++++++++++++++++++++++++--------
include/xen/gnttab.h | 6 ++-
2 files changed, 76 insertions(+), 15 deletions(-)
diff -r 30abfbe6e047 -r 374b41b4f227 drivers/xen/core/gnttab.c
--- a/drivers/xen/core/gnttab.c Sun Oct 08 12:34:23 2006 -0400
+++ b/drivers/xen/core/gnttab.c Sun Oct 08 12:38:48 2006 -0400
@@ -31,7 +31,6 @@
* IN THE SOFTWARE.
*/
-#include <linux/config.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/mm.h>
@@ -41,6 +40,8 @@
#include <asm/pgtable.h>
#include <asm/uaccess.h>
#include <asm/synch_bitops.h>
+#include <asm/io.h>
+#include <xen/interface/memory.h>
/* External tools reserve first few grant table entries. */
#define NR_RESERVED_ENTRIES 8
@@ -48,6 +49,10 @@
#define NR_GRANT_ENTRIES \
(NR_GRANT_FRAMES * PAGE_SIZE / sizeof(struct grant_entry))
#define GNTTAB_LIST_END (NR_GRANT_ENTRIES + 1)
+
+extern void *arch_gnttab_map(unsigned long *frames);
+extern int arch_gnttab_suspend(void *shared);
+extern unsigned long alloc_empty_foreign_map_page_range(unsigned long pages);
static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
static int gnttab_free_count;
@@ -169,7 +174,7 @@ int gnttab_end_foreign_access_ref(grant_
printk(KERN_ALERT "WARNING: g.e. still in use!\n");
return 0;
}
- } while ((nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) !=
+ } while ((nflags = synch_cmpxchg_subword(&shared[ref].flags, flags, 0))
!=
flags);
return 1;
@@ -224,7 +229,7 @@ unsigned long gnttab_end_foreign_transfe
* reference and return failure (== 0).
*/
while (!((flags = shared[ref].flags) & GTF_transfer_committed)) {
- if (synch_cmpxchg(&shared[ref].flags, flags, 0) == flags)
+ if (synch_cmpxchg_subword(&shared[ref].flags, flags, 0) ==
flags)
return 0;
cpu_relax();
}
@@ -350,7 +355,9 @@ void gnttab_cancel_free_callback(struct
}
EXPORT_SYMBOL_GPL(gnttab_cancel_free_callback);
-#ifdef CONFIG_P2M
+#ifdef CONFIG_XEN
+#ifndef CONFIG_PPC_XEN
+#ifndef __ia64__
static int map_pte_fn(pte_t *pte, struct page *pmd_page,
unsigned long addr, void *data)
{
@@ -369,13 +376,14 @@ static int unmap_pte_fn(pte_t *pte, stru
return 0;
}
#endif
+#endif /* CONFIG_PPC_XEN */
int gnttab_resume(void)
{
struct gnttab_setup_table setup;
unsigned long frames[NR_GRANT_FRAMES];
int rc;
-#ifdef CONFIG_P2M
+#ifndef __ia64__
void *pframes = frames;
struct vm_struct *area;
#endif
@@ -390,7 +398,14 @@ int gnttab_resume(void)
BUG_ON(rc || setup.status);
-#ifdef CONFIG_P2M
+#ifdef CONFIG_PPC_XEN
+ if (shared == NULL) {
+ (void)pframes;
+ (void)area;
+ shared = arch_gnttab_map(frames);
+ }
+#else
+#ifndef(__ia64__)
if (shared == NULL) {
area = get_vm_area(PAGE_SIZE * NR_GRANT_FRAMES, VM_IOREMAP);
BUG_ON(area == NULL);
@@ -404,23 +419,63 @@ int gnttab_resume(void)
shared = __va(frames[0] << PAGE_SHIFT);
printk("grant table at %p\n", shared);
#endif
-
+#endif
return 0;
}
int gnttab_suspend(void)
{
-
-#ifdef CONFIG_P2M
+#ifdef CONFIG_PPC_XEN
+ return arch_gnttab_suspend(shared);
+#else
+#if !defined(__ia64__)
apply_to_page_range(&init_mm, (unsigned long)shared,
PAGE_SIZE * NR_GRANT_FRAMES,
unmap_pte_fn, NULL);
#endif
-
- return 0;
-}
-
-static int __init gnttab_init(void)
+#endif
+ return 0;
+}
+
+#else /* !CONFIG_XEN */
+
+#include <platform-pci.h>
+
+int gnttab_resume(void)
+{
+ unsigned long frames;
+ struct xen_add_to_physmap xatp;
+ unsigned int i;
+
+ frames = alloc_xen_mmio(PAGE_SIZE * NR_GRANT_FRAMES);
+
+ for (i = 0; i < NR_GRANT_FRAMES; i++) {
+ xatp.domid = DOMID_SELF;
+ xatp.idx = i;
+ xatp.space = XENMAPSPACE_grant_table;
+ xatp.gpfn = (frames >> PAGE_SHIFT) + i;
+ if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
+ BUG();
+ }
+
+ shared = ioremap(frames, PAGE_SIZE * NR_GRANT_FRAMES);
+ if (shared == NULL) {
+ printk("error to ioremap gnttab share frames\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int gnttab_suspend(void)
+{
+ iounmap(shared);
+ return 0;
+}
+
+#endif /* !CONFIG_XEN */
+
+int __init gnttab_init(void)
{
int i;
@@ -439,4 +494,6 @@ static int __init gnttab_init(void)
return 0;
}
+#ifdef CONFIG_XEN
core_initcall(gnttab_init);
+#endif
diff -r 30abfbe6e047 -r 374b41b4f227 include/xen/gnttab.h
--- a/include/xen/gnttab.h Sun Oct 08 12:34:23 2006 -0400
+++ b/include/xen/gnttab.h Sun Oct 08 12:38:48 2006 -0400
@@ -111,7 +111,7 @@ void gnttab_grant_foreign_transfer_ref(g
#ifdef __ia64__
#define gnttab_map_vaddr(map) __va(map.dev_bus_addr)
#else
-#define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
+#define gnttab_map_vaddr(map) ((void *)(map.host_addr))
#endif
int gnttab_suspend(void);
@@ -123,8 +123,10 @@ gnttab_set_map_op(struct gnttab_map_gran
{
if (flags & GNTMAP_contains_pte)
map->host_addr = addr;
+#ifndef CONFIG_PPC_XEN
else if (xen_feature(XENFEAT_auto_translated_physmap))
map->host_addr = __pa(addr);
+#endif
else
map->host_addr = addr;
@@ -139,8 +141,10 @@ gnttab_set_unmap_op(struct gnttab_unmap_
{
if (flags & GNTMAP_contains_pte)
unmap->host_addr = addr;
+#ifndef CONFIG_PPC_XEN
else if (xen_feature(XENFEAT_auto_translated_physmap))
unmap->host_addr = __pa(addr);
+#endif
else
unmap->host_addr = addr;
_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel
|