# HG changeset patch
# User Alex Williamson <alex.williamson@xxxxxx>
# Date 1181702630 21600
# Node ID 5917bb91bf09a5b3c1ba8c65237cbfb5ac175a86
# Parent 2c15ed1d75fbf302d89bade0079ba580eb54023b
# Parent a44649e59d1fd42ac14cf3114336ba8d47e47296
Merge with linux-2.6.18-xen.hg (staging)
---
arch/i386/Kconfig | 1
arch/ia64/pci/pci.c | 28 ++
arch/x86_64/Makefile | 2
arch/x86_64/kernel/head-xen.S | 10
arch/x86_64/kernel/setup64-xen.c | 4
arch/x86_64/kernel/vsyscall-xen.c | 12
arch/x86_64/mm/init-xen.c | 49 ---
drivers/xen/Kconfig | 18 +
drivers/xen/pciback/Makefile | 1
drivers/xen/pciback/controller.c | 404 ++++++++++++++++++++++++++++++
drivers/xen/pcifront/pci_op.c | 120 ++++++++
drivers/xen/privcmd/privcmd.c | 2
include/asm-x86_64/mach-xen/asm/pgalloc.h | 4
include/asm-x86_64/mach-xen/asm/pgtable.h | 3
include/xen/pcifront.h | 26 +
15 files changed, 608 insertions(+), 76 deletions(-)
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/i386/Kconfig
--- a/arch/i386/Kconfig Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/i386/Kconfig Tue Jun 12 20:43:50 2007 -0600
@@ -431,7 +431,6 @@ config MICROCODE
config X86_MSR
tristate "/dev/cpu/*/msr - Model-specific register support"
- depends on !X86_XEN
help
This device gives privileged processes access to the x86
Model-Specific Registers (MSRs). It is a character device with
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/ia64/pci/pci.c
--- a/arch/ia64/pci/pci.c Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/ia64/pci/pci.c Tue Jun 12 20:43:50 2007 -0600
@@ -839,3 +839,31 @@ int pci_vector_resources(int last, int n
return count;
}
+
+#ifdef CONFIG_XEN
+void __devinit xen_add_resource(struct pci_controller *controller,
+ unsigned int domain, unsigned int bus,
+ struct acpi_resource *resource)
+{
+ struct pci_root_info info;
+ char *name;
+
+ name = kmalloc(16, GFP_KERNEL);
+ if (!name)
+ return;
+
+ sprintf(name, "PCI Bus %04x:%02x", domain, bus);
+ info.controller = controller;
+ info.name = name;
+
+ add_window(resource, &info);
+}
+EXPORT_SYMBOL(xen_add_resource);
+
+void __devinit xen_pcibios_setup_root_windows(struct pci_bus *bus,
+ struct pci_controller *controller)
+{
+ pcibios_setup_root_windows(bus, controller);
+}
+EXPORT_SYMBOL(xen_pcibios_setup_root_windows);
+#endif
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/x86_64/Makefile
--- a/arch/x86_64/Makefile Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/x86_64/Makefile Tue Jun 12 20:43:50 2007 -0600
@@ -81,7 +81,7 @@ ifdef CONFIG_XEN
ifdef CONFIG_XEN
CPPFLAGS := -Iinclude$(if $(KBUILD_SRC),2)/asm/mach-xen $(CPPFLAGS)
head-y := arch/x86_64/kernel/head-xen.o arch/x86_64/kernel/head64-xen.o
arch/x86_64/kernel/init_task.o
-LDFLAGS_vmlinux := -e _start
+LDFLAGS_vmlinux := -e startup_64
boot := arch/i386/boot-xen
.PHONY: vmlinuz
#Default target when executing "make"
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/x86_64/kernel/head-xen.S
--- a/arch/x86_64/kernel/head-xen.S Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/x86_64/kernel/head-xen.S Tue Jun 12 20:43:50 2007 -0600
@@ -27,11 +27,8 @@
.section .bootstrap.text, "ax", @progbits
.code64
-#define VIRT_ENTRY_OFFSET 0x0
-.org VIRT_ENTRY_OFFSET
.globl startup_64
startup_64:
-ENTRY(_start)
movq $(init_thread_union+THREAD_SIZE-8),%rsp
/* rsi is pointer to startup info structure.
@@ -53,15 +50,14 @@ NEXT_PAGE(init_level4_pgt)
NEXT_PAGE(init_level4_pgt)
/* This gets initialized in x86_64_start_kernel */
.fill 512,8,0
-
+NEXT_PAGE(init_level4_user_pgt)
/*
* We update two pgd entries to make kernel and user pgd consistent
* at pgd_populate(). It can be used for kernel modules. So we place
* this page here for those cases to avoid memory corruption.
- * We also use this page to establish the initiali mapping for
+ * We also use this page to establish the initial mapping for the
* vsyscall area.
*/
-NEXT_PAGE(init_level4_user_pgt)
.fill 512,8,0
NEXT_PAGE(level3_kernel_pgt)
@@ -175,7 +171,7 @@ ENTRY(empty_zero_page)
.ascii ",ELF_PADDR_OFFSET=0x"
utoh __START_KERNEL_map
.ascii ",VIRT_ENTRY=0x"
- utoh (__START_KERNEL_map + __PHYSICAL_START + VIRT_ENTRY_OFFSET)
+ utoh (__START_KERNEL_map + __PHYSICAL_START)
.ascii ",HYPERCALL_PAGE=0x"
utoh (phys_hypercall_page >> PAGE_SHIFT)
.ascii ",FEATURES=writable_page_tables"
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/x86_64/kernel/setup64-xen.c
--- a/arch/x86_64/kernel/setup64-xen.c Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/x86_64/kernel/setup64-xen.c Tue Jun 12 20:43:50 2007 -0600
@@ -128,8 +128,8 @@ void __init setup_per_cpu_areas(void)
#ifdef CONFIG_XEN
static void switch_pt(void)
{
- xen_pt_switch(__pa(init_level4_pgt));
- xen_new_user_pt(__pa(init_level4_user_pgt));
+ xen_pt_switch(__pa_symbol(init_level4_pgt));
+ xen_new_user_pt(__pa_symbol(__user_pgd(init_level4_pgt)));
}
void __cpuinit cpu_gdt_init(struct desc_ptr *gdt_descr)
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/x86_64/kernel/vsyscall-xen.c
--- a/arch/x86_64/kernel/vsyscall-xen.c Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/x86_64/kernel/vsyscall-xen.c Tue Jun 12 20:43:50 2007 -0600
@@ -208,17 +208,6 @@ static void __init map_vsyscall(void)
__set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_page0, PAGE_KERNEL_VSYSCALL);
}
-#ifdef CONFIG_XEN
-static void __init map_vsyscall_user(void)
-{
- extern void __set_fixmap_user(enum fixed_addresses, unsigned long,
pgprot_t);
- extern char __vsyscall_0;
- unsigned long physaddr_page0 = __pa_symbol(&__vsyscall_0);
-
- __set_fixmap_user(VSYSCALL_FIRST_PAGE, physaddr_page0,
PAGE_KERNEL_VSYSCALL);
-}
-#endif
-
static int __init vsyscall_init(void)
{
BUG_ON(((unsigned long) &vgettimeofday !=
@@ -227,7 +216,6 @@ static int __init vsyscall_init(void)
BUG_ON((VSYSCALL_ADDR(0) != __fix_to_virt(VSYSCALL_FIRST_PAGE)));
map_vsyscall();
#ifdef CONFIG_XEN
- map_vsyscall_user();
sysctl_vsyscall = 0; /* disable vgettimeofay() */
#endif
#ifdef CONFIG_SYSCTL
diff -r 2c15ed1d75fb -r 5917bb91bf09 arch/x86_64/mm/init-xen.c
--- a/arch/x86_64/mm/init-xen.c Tue Jun 12 16:33:57 2007 -0600
+++ b/arch/x86_64/mm/init-xen.c Tue Jun 12 20:43:50 2007 -0600
@@ -227,14 +227,8 @@ static __init void *spp_getpage(void)
return ptr;
}
-#define pgd_offset_u(address) (pgd_t *)(init_level4_user_pgt +
pgd_index(address))
-
-static inline pud_t *pud_offset_u(unsigned long address)
-{
- pud_t *pud = level3_user_pgt;
-
- return pud + pud_index(address);
-}
+#define pgd_offset_u(address) (__user_pgd(init_level4_pgt) +
pgd_index(address))
+#define pud_offset_u(address) (level3_user_pgt + pud_index(address))
static __init void set_pte_phys(unsigned long vaddr,
unsigned long phys, pgprot_t prot, int user_mode)
@@ -337,9 +331,6 @@ static __init void set_pte_phys_ma(unsig
__flush_tlb_one(vaddr);
}
-#define SET_FIXMAP_KERNEL 0
-#define SET_FIXMAP_USER 1
-
/* NOTE: this is meant to be run only at boot */
void __init
__set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
@@ -352,28 +343,13 @@ __set_fixmap (enum fixed_addresses idx,
}
switch (idx) {
case VSYSCALL_LAST_PAGE ... VSYSCALL_FIRST_PAGE:
- set_pte_phys(address, phys, prot, SET_FIXMAP_KERNEL);
+ set_pte_phys(address, phys, prot, 0);
+ set_pte_phys(address, phys, prot, 1);
break;
default:
set_pte_phys_ma(address, phys, prot);
break;
}
-}
-
-/*
- * This only supports vsyscall area.
- */
-void __init
-__set_fixmap_user (enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
-{
- unsigned long address = __fix_to_virt(idx);
-
- if (idx >= __end_of_fixed_addresses) {
- printk("Invalid __set_fixmap\n");
- return;
- }
-
- set_pte_phys(address, phys, prot, SET_FIXMAP_USER);
}
unsigned long __initdata table_start, table_end;
@@ -579,13 +555,15 @@ void __init xen_init_pt(void)
init_level4_pgt[pgd_index(__START_KERNEL_map)] =
__pgd(__pa_symbol(level3_kernel_pgt) | _PAGE_TABLE);
level3_kernel_pgt[pud_index(__START_KERNEL_map)] =
- __pud(__pa_symbol(level2_kernel_pgt) |
- _KERNPG_TABLE);
- memcpy((void *)level2_kernel_pgt, page, PAGE_SIZE);
+ __pud(__pa_symbol(level2_kernel_pgt) | _PAGE_TABLE);
+ memcpy(level2_kernel_pgt, page, PAGE_SIZE);
+
+ __user_pgd(init_level4_pgt)[pgd_index(VSYSCALL_START)] =
+ __pgd(__pa_symbol(level3_user_pgt) | _PAGE_TABLE);
early_make_page_readonly(init_level4_pgt,
XENFEAT_writable_page_tables);
- early_make_page_readonly(init_level4_user_pgt,
+ early_make_page_readonly(__user_pgd(init_level4_pgt),
XENFEAT_writable_page_tables);
early_make_page_readonly(level3_kernel_pgt,
XENFEAT_writable_page_tables);
@@ -596,11 +574,8 @@ void __init xen_init_pt(void)
if (!xen_feature(XENFEAT_writable_page_tables)) {
xen_pgd_pin(__pa_symbol(init_level4_pgt));
- xen_pgd_pin(__pa_symbol(init_level4_user_pgt));
- }
-
- set_pgd((pgd_t *)(init_level4_user_pgt + 511),
- mk_kernel_pgd(__pa_symbol(level3_user_pgt)));
+ xen_pgd_pin(__pa_symbol(__user_pgd(init_level4_pgt)));
+ }
}
static void __init extend_init_mapping(unsigned long tables_space)
diff -r 2c15ed1d75fb -r 5917bb91bf09 drivers/xen/Kconfig
--- a/drivers/xen/Kconfig Tue Jun 12 16:33:57 2007 -0600
+++ b/drivers/xen/Kconfig Tue Jun 12 20:43:50 2007 -0600
@@ -109,7 +109,8 @@ choice
choice
prompt "PCI Backend Mode"
depends on XEN_PCIDEV_BACKEND
- default XEN_PCIDEV_BACKEND_VPCI
+ default XEN_PCIDEV_BACKEND_VPCI if !IA64
+ default XEN_PCIDEV_BACKEND_CONTROLLER if IA64
config XEN_PCIDEV_BACKEND_VPCI
bool "Virtual PCI"
@@ -138,6 +139,21 @@ config XEN_PCIDEV_BACKEND_SLOT
For example, a device at 03:05.2 will be re-assigned to 00:00.0. A
second device at 02:1a.1 will be re-assigned to 00:01.0.
+config XEN_PCIDEV_BACKEND_CONTROLLER
+ bool "Controller"
+ depends on IA64
+ ---help---
+ This PCI backend virtualizes the PCI bus topology by providing a
+ virtual bus per PCI root device. Devices which are physically under
+ the same root bus will appear on the same virtual bus. For systems
+ with complex I/O addressing, this is the only backend which supports
+ extended I/O port spaces and MMIO translation offsets. This backend
+ also supports slot virtualization. For example, a device at
+ 0000:01:02.1 will be re-assigned to 0000:00:00.0. A second device
+ at 0000:02:05.0 (behind a P2P bridge on bus 0000:01) will be
+ re-assigned to 0000:00:01.0. A third device at 0000:16:05.0 (under
+ a different PCI root bus) will be re-assigned to 0000:01:00.0.
+
endchoice
config XEN_PCIDEV_BE_DEBUG
diff -r 2c15ed1d75fb -r 5917bb91bf09 drivers/xen/pciback/Makefile
--- a/drivers/xen/pciback/Makefile Tue Jun 12 16:33:57 2007 -0600
+++ b/drivers/xen/pciback/Makefile Tue Jun 12 20:43:50 2007 -0600
@@ -9,6 +9,7 @@ pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI
pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o
pciback-$(CONFIG_XEN_PCIDEV_BACKEND_SLOT) += slot.o
pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o
+pciback-$(CONFIG_XEN_PCIDEV_BACKEND_CONTROLLER) += controller.o
ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
diff -r 2c15ed1d75fb -r 5917bb91bf09 drivers/xen/pciback/controller.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/xen/pciback/controller.c Tue Jun 12 20:43:50 2007 -0600
@@ -0,0 +1,404 @@
+/*
+ * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
+ * Alex Williamson <alex.williamson@xxxxxx>
+ *
+ * PCI "Controller" Backend - virtualize PCI bus topology based on PCI
+ * controllers. Devices under the same PCI controller are exposed on the
+ * same virtual domain:bus. Within a bus, device slots are virtualized
+ * to compact the bus.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+#include <linux/acpi.h>
+#include <linux/list.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include "pciback.h"
+
+#define PCI_MAX_BUSSES 255
+#define PCI_MAX_SLOTS 32
+
+struct controller_dev_entry {
+ struct list_head list;
+ struct pci_dev *dev;
+ unsigned int devfn;
+};
+
+struct controller_list_entry {
+ struct list_head list;
+ struct pci_controller *controller;
+ unsigned int domain;
+ unsigned int bus;
+ unsigned int next_devfn;
+ struct list_head dev_list;
+};
+
+struct controller_dev_data {
+ struct list_head list;
+ unsigned int next_domain;
+ unsigned int next_bus;
+ spinlock_t lock;
+};
+
+struct walk_info {
+ struct pciback_device *pdev;
+ int resource_count;
+ int root_num;
+};
+
+struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev,
+ unsigned int domain, unsigned int bus,
+ unsigned int devfn)
+{
+ struct controller_dev_data *dev_data = pdev->pci_dev_data;
+ struct controller_dev_entry *dev_entry;
+ struct controller_list_entry *cntrl_entry;
+ struct pci_dev *dev = NULL;
+ unsigned long flags;
+
+ spin_lock_irqsave(&dev_data->lock, flags);
+
+ list_for_each_entry(cntrl_entry, &dev_data->list, list) {
+ if (cntrl_entry->domain != domain ||
+ cntrl_entry->bus != bus)
+ continue;
+
+ list_for_each_entry(dev_entry, &cntrl_entry->dev_list, list) {
+ if (devfn == dev_entry->devfn) {
+ dev = dev_entry->dev;
+ goto found;
+ }
+ }
+ }
+found:
+ spin_unlock_irqrestore(&dev_data->lock, flags);
+
+ return dev;
+}
+
+int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev)
+{
+ struct controller_dev_data *dev_data = pdev->pci_dev_data;
+ struct controller_dev_entry *dev_entry;
+ struct controller_list_entry *cntrl_entry;
+ struct pci_controller *dev_controller = PCI_CONTROLLER(dev);
+ unsigned long flags;
+ int ret = 0, found = 0;
+
+ spin_lock_irqsave(&dev_data->lock, flags);
+
+ /* Look to see if we already have a domain:bus for this controller */
+ list_for_each_entry(cntrl_entry, &dev_data->list, list) {
+ if (cntrl_entry->controller == dev_controller) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found) {
+ cntrl_entry = kmalloc(sizeof(*cntrl_entry), GFP_ATOMIC);
+ if (!cntrl_entry) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ cntrl_entry->controller = dev_controller;
+ cntrl_entry->next_devfn = PCI_DEVFN(0, 0);
+
+ cntrl_entry->domain = dev_data->next_domain;
+ cntrl_entry->bus = dev_data->next_bus++;
+ if (dev_data->next_bus > PCI_MAX_BUSSES) {
+ dev_data->next_domain++;
+ dev_data->next_bus = 0;
+ }
+
+ INIT_LIST_HEAD(&cntrl_entry->dev_list);
+
+ list_add_tail(&cntrl_entry->list, &dev_data->list);
+ }
+
+ if (PCI_SLOT(cntrl_entry->next_devfn) > PCI_MAX_SLOTS) {
+ /*
+ * While it seems unlikely, this can actually happen if
+ * a controller has P2P bridges under it.
+ */
+ xenbus_dev_fatal(pdev->xdev, -ENOSPC, "Virtual bus %04x:%02x "
+ "is full, no room to export %04x:%02x:%02x.%x",
+ cntrl_entry->domain, cntrl_entry->bus,
+ pci_domain_nr(dev->bus), dev->bus->number,
+ PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
+ ret = -ENOSPC;
+ goto out;
+ }
+
+ dev_entry = kmalloc(sizeof(*dev_entry), GFP_ATOMIC);
+ if (!dev_entry) {
+ if (list_empty(&cntrl_entry->dev_list)) {
+ list_del(&cntrl_entry->list);
+ kfree(cntrl_entry);
+ }
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ dev_entry->dev = dev;
+ dev_entry->devfn = cntrl_entry->next_devfn;
+
+ list_add_tail(&dev_entry->list, &cntrl_entry->dev_list);
+
+ cntrl_entry->next_devfn += PCI_DEVFN(1, 0);
+
+out:
+ spin_unlock_irqrestore(&dev_data->lock, flags);
+ return ret;
+}
+
+void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev)
+{
+ struct controller_dev_data *dev_data = pdev->pci_dev_data;
+ struct controller_list_entry *cntrl_entry;
+ struct controller_dev_entry *dev_entry = NULL;
+ struct pci_dev *found_dev = NULL;
+ unsigned long flags;
+
+ spin_lock_irqsave(&dev_data->lock, flags);
+
+ list_for_each_entry(cntrl_entry, &dev_data->list, list) {
+ if (cntrl_entry->controller != PCI_CONTROLLER(dev))
+ continue;
+
+ list_for_each_entry(dev_entry, &cntrl_entry->dev_list, list) {
+ if (dev_entry->dev == dev) {
+ found_dev = dev_entry->dev;
+ break;
+ }
+ }
+ }
+
+ if (!found_dev) {
+ spin_unlock_irqrestore(&dev_data->lock, flags);
+ return;
+ }
+
+ list_del(&dev_entry->list);
+ kfree(dev_entry);
+
+ if (list_empty(&cntrl_entry->dev_list)) {
+ list_del(&cntrl_entry->list);
+ kfree(cntrl_entry);
+ }
+
+ spin_unlock_irqrestore(&dev_data->lock, flags);
+ pcistub_put_pci_dev(found_dev);
+}
+
+int pciback_init_devices(struct pciback_device *pdev)
+{
+ struct controller_dev_data *dev_data;
+
+ dev_data = kmalloc(sizeof(*dev_data), GFP_KERNEL);
+ if (!dev_data)
+ return -ENOMEM;
+
+ spin_lock_init(&dev_data->lock);
+
+ INIT_LIST_HEAD(&dev_data->list);
+
+ /* Starting domain:bus numbers */
+ dev_data->next_domain = 0;
+ dev_data->next_bus = 0;
+
+ pdev->pci_dev_data = dev_data;
+
+ return 0;
+}
+
+static acpi_status write_xenbus_resource(struct acpi_resource *res, void *data)
+{
+ struct walk_info *info = data;
+ struct acpi_resource_address64 addr;
+ acpi_status status;
+ int i, len, err;
+ char str[32], tmp[3];
+ unsigned char *ptr, *buf;
+
+ status = acpi_resource_to_address64(res, &addr);
+
+ /* Do we care about this range? Let's check. */
+ if (!ACPI_SUCCESS(status) ||
+ !(addr.resource_type == ACPI_MEMORY_RANGE ||
+ addr.resource_type == ACPI_IO_RANGE) ||
+ !addr.address_length || addr.producer_consumer != ACPI_PRODUCER)
+ return AE_OK;
+
+ /*
+ * Furthermore, we really only care to tell the guest about
+ * address ranges that require address translation of some sort.
+ */
+ if (!(addr.resource_type == ACPI_MEMORY_RANGE &&
+ addr.info.mem.translation) &&
+ !(addr.resource_type == ACPI_IO_RANGE &&
+ addr.info.io.translation))
+ return AE_OK;
+
+ /* Store the resource in xenbus for the guest */
+ len = snprintf(str, sizeof(str), "root-%d-resource-%d",
+ info->root_num, info->resource_count);
+ if (unlikely(len >= (sizeof(str) - 1)))
+ return AE_OK;
+
+ buf = kzalloc((sizeof(*res) * 2) + 1, GFP_KERNEL);
+ if (!buf)
+ return AE_OK;
+
+ /* Clean out resource_source */
+ res->data.address64.resource_source.index = 0xFF;
+ res->data.address64.resource_source.string_length = 0;
+ res->data.address64.resource_source.string_ptr = NULL;
+
+ ptr = (unsigned char *)res;
+
+ /* Turn the acpi_resource into an ASCII byte stream */
+ for (i = 0; i < sizeof(*res); i++) {
+ snprintf(tmp, sizeof(tmp), "%02x", ptr[i]);
+ strncat(buf, tmp, 2);
+ }
+
+ err = xenbus_printf(XBT_NIL, info->pdev->xdev->nodename,
+ str, "%s", buf);
+
+ if (!err)
+ info->resource_count++;
+
+ kfree(buf);
+
+ return AE_OK;
+}
+
+int pciback_publish_pci_roots(struct pciback_device *pdev,
+ publish_pci_root_cb publish_root_cb)
+{
+ struct controller_dev_data *dev_data = pdev->pci_dev_data;
+ struct controller_list_entry *cntrl_entry;
+ int i, root_num, len, err = 0;
+ unsigned int domain, bus;
+ char str[64];
+ struct walk_info info;
+
+ spin_lock(&dev_data->lock);
+
+ list_for_each_entry(cntrl_entry, &dev_data->list, list) {
+ /* First publish all the domain:bus info */
+ err = publish_root_cb(pdev, cntrl_entry->domain,
+ cntrl_entry->bus);
+ if (err)
+ goto out;
+
+ /*
+ * Now figure out which root-%d this belongs to
+ * so we can associate resources with it.
+ */
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
+ "root_num", "%d", &root_num);
+
+ if (err != 1)
+ goto out;
+
+ for (i = 0; i < root_num; i++) {
+ len = snprintf(str, sizeof(str), "root-%d", i);
+ if (unlikely(len >= (sizeof(str) - 1))) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
+ str, "%x:%x", &domain, &bus);
+ if (err != 2)
+ goto out;
+
+ /* Is this the one we just published? */
+ if (domain == cntrl_entry->domain &&
+ bus == cntrl_entry->bus)
+ break;
+ }
+
+ if (i == root_num)
+ goto out;
+
+ info.pdev = pdev;
+ info.resource_count = 0;
+ info.root_num = i;
+
+ /* Let ACPI do the heavy lifting on decoding resources */
+ acpi_walk_resources(cntrl_entry->controller->acpi_handle,
+ METHOD_NAME__CRS, write_xenbus_resource,
+ &info);
+
+ /* No resouces. OK. On to the next one */
+ if (!info.resource_count)
+ continue;
+
+ /* Store the number of resources we wrote for this root-%d */
+ len = snprintf(str, sizeof(str), "root-%d-resources", i);
+ if (unlikely(len >= (sizeof(str) - 1))) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
+ "%d", info.resource_count);
+ if (err)
+ goto out;
+ }
+
+ /* Finally, write some magic to synchronize with the guest. */
+ len = snprintf(str, sizeof(str), "root-resource-magic");
+ if (unlikely(len >= (sizeof(str) - 1))) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
+ "%lx", (sizeof(struct acpi_resource) * 2) + 1);
+
+out:
+ spin_unlock(&dev_data->lock);
+
+ return err;
+}
+
+void pciback_release_devices(struct pciback_device *pdev)
+{
+ struct controller_dev_data *dev_data = pdev->pci_dev_data;
+ struct controller_list_entry *cntrl_entry, *c;
+ struct controller_dev_entry *dev_entry, *d;
+
+ list_for_each_entry_safe(cntrl_entry, c, &dev_data->list, list) {
+ list_for_each_entry_safe(dev_entry, d,
+ &cntrl_entry->dev_list, list) {
+ list_del(&dev_entry->list);
+ pcistub_put_pci_dev(dev_entry->dev);
+ kfree(dev_entry);
+ }
+ list_del(&cntrl_entry->list);
+ kfree(cntrl_entry);
+ }
+
+ kfree(dev_data);
+ pdev->pci_dev_data = NULL;
+}
diff -r 2c15ed1d75fb -r 5917bb91bf09 drivers/xen/pcifront/pci_op.c
--- a/drivers/xen/pcifront/pci_op.c Tue Jun 12 16:33:57 2007 -0600
+++ b/drivers/xen/pcifront/pci_op.c Tue Jun 12 20:43:50 2007 -0600
@@ -14,6 +14,122 @@
static int verbose_request = 0;
module_param(verbose_request, int, 0644);
+
+#ifdef __ia64__
+static void pcifront_init_sd(struct pcifront_sd *sd,
+ unsigned int domain, unsigned int bus,
+ struct pcifront_device *pdev)
+{
+ int err, i, j, k, len, root_num, res_count;
+ struct acpi_resource res;
+ unsigned int d, b, byte;
+ unsigned long magic;
+ char str[64], tmp[3];
+ unsigned char *buf, *bufp;
+ u8 *ptr;
+
+ memset(sd, 0, sizeof(*sd));
+
+ sd->segment = domain;
+ sd->node = -1; /* Revisit for NUMA */
+ sd->platform_data = pdev;
+
+ /* Look for resources for this controller in xenbus. */
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, "root_num",
+ "%d", &root_num);
+ if (err != 1)
+ return;
+
+ for (i = 0; i < root_num; i++) {
+ len = snprintf(str, sizeof(str), "root-%d", i);
+ if (unlikely(len >= (sizeof(str) - 1)))
+ return;
+
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend,
+ str, "%x:%x", &d, &b);
+ if (err != 2)
+ return;
+
+ if (d == domain && b == bus)
+ break;
+ }
+
+ if (i == root_num)
+ return;
+
+ len = snprintf(str, sizeof(str), "root-resource-magic");
+
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend,
+ str, "%lx", &magic);
+
+ if (err != 1)
+ return; /* No resources, nothing to do */
+
+ if (magic != (sizeof(res) * 2) + 1) {
+ printk(KERN_WARNING "pcifront: resource magic mismatch\n");
+ return;
+ }
+
+ len = snprintf(str, sizeof(str), "root-%d-resources", i);
+ if (unlikely(len >= (sizeof(str) - 1)))
+ return;
+
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend,
+ str, "%d", &res_count);
+
+ if (err != 1)
+ return; /* No resources, nothing to do */
+
+ sd->window = kzalloc(sizeof(*sd->window) * res_count, GFP_KERNEL);
+ if (!sd->window)
+ return;
+
+ /* magic is also the size of the byte stream in xenbus */
+ buf = kmalloc(magic, GFP_KERNEL);
+ if (!buf) {
+ kfree(sd->window);
+ sd->window = NULL;
+ return;
+ }
+
+ /* Read the resources out of xenbus */
+ for (j = 0; j < res_count; j++) {
+ memset(&res, 0, sizeof(res));
+ memset(buf, 0, magic);
+
+ len = snprintf(str, sizeof(str), "root-%d-resource-%d", i, j);
+ if (unlikely(len >= (sizeof(str) - 1)))
+ return;
+
+ err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str,
+ "%s", buf);
+ if (err != 1) {
+ printk(KERN_WARNING "pcifront: error reading "
+ "resource %d on bus %04x:%02x\n",
+ j, domain, bus);
+ continue;
+ }
+
+ bufp = buf;
+ ptr = (u8 *)&res;
+ memset(tmp, 0, sizeof(tmp));
+
+ /* Copy ASCII byte stream into structure */
+ for (k = 0; k < magic - 1; k += 2) {
+ memcpy(tmp, bufp, 2);
+ bufp += 2;
+
+ sscanf(tmp, "%02x", &byte);
+ *ptr = byte;
+ ptr++;
+ }
+
+ xen_add_resource(sd, domain, bus, &res);
+ sd->windows++;
+ }
+ kfree(buf);
+}
+#endif
static int errno_to_pcibios_err(int errno)
{
@@ -207,7 +323,7 @@ int pcifront_scan_root(struct pcifront_d
err = -ENOMEM;
goto err_out;
}
- pcifront_init_sd(sd, domain, pdev);
+ pcifront_init_sd(sd, domain, bus, pdev);
b = pci_scan_bus_parented(&pdev->xdev->dev, bus,
&pcifront_bus_ops, sd);
@@ -217,6 +333,8 @@ int pcifront_scan_root(struct pcifront_d
err = -ENOMEM;
goto err_out;
}
+
+ pcifront_setup_root_resources(b, sd);
bus_entry->bus = b;
list_add(&bus_entry->list, &pdev->root_buses);
diff -r 2c15ed1d75fb -r 5917bb91bf09 drivers/xen/privcmd/privcmd.c
--- a/drivers/xen/privcmd/privcmd.c Tue Jun 12 16:33:57 2007 -0600
+++ b/drivers/xen/privcmd/privcmd.c Tue Jun 12 20:43:50 2007 -0600
@@ -229,9 +229,11 @@ static struct vm_operations_struct privc
static int privcmd_mmap(struct file * file, struct vm_area_struct * vma)
{
+#ifndef __powerpc__ /* PowerPC has a trick to safely do this. */
/* Unsupported for auto-translate guests. */
if (xen_feature(XENFEAT_auto_translated_physmap))
return -ENOSYS;
+#endif
/* DONTCOPY is essential for Xen as copy_page_range is broken. */
vma->vm_flags |= VM_RESERVED | VM_IO | VM_DONTCOPY;
diff -r 2c15ed1d75fb -r 5917bb91bf09 include/asm-x86_64/mach-xen/asm/pgalloc.h
--- a/include/asm-x86_64/mach-xen/asm/pgalloc.h Tue Jun 12 16:33:57 2007 -0600
+++ b/include/asm-x86_64/mach-xen/asm/pgalloc.h Tue Jun 12 20:43:50 2007 -0600
@@ -146,8 +146,8 @@ static inline pgd_t *pgd_alloc(struct mm
/*
* Set level3_user_pgt for vsyscall area
*/
- set_pgd(__user_pgd(pgd) + pgd_index(VSYSCALL_START),
- __pgd(__pa_symbol(level3_user_pgt) | _PAGE_TABLE));
+ __user_pgd(pgd)[pgd_index(VSYSCALL_START)] =
+ __pgd(__pa_symbol(level3_user_pgt) | _PAGE_TABLE);
return pgd;
}
diff -r 2c15ed1d75fb -r 5917bb91bf09 include/asm-x86_64/mach-xen/asm/pgtable.h
--- a/include/asm-x86_64/mach-xen/asm/pgtable.h Tue Jun 12 16:33:57 2007 -0600
+++ b/include/asm-x86_64/mach-xen/asm/pgtable.h Tue Jun 12 20:43:50 2007 -0600
@@ -15,7 +15,6 @@
#include <asm/hypervisor.h>
extern pud_t level3_user_pgt[512];
-extern pud_t init_level4_user_pgt[];
extern void xen_init_pt(void);
@@ -395,7 +394,7 @@ static inline int pmd_large(pmd_t pte) {
#define pgd_page(pgd) ((unsigned long) __va(pgd_val(pgd) & PTE_MASK))
#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
#define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
-#define pgd_offset_k(address) (pgd_t *)(init_level4_pgt + pgd_index(address))
+#define pgd_offset_k(address) (init_level4_pgt + pgd_index(address))
#define pgd_present(pgd) (__pgd_val(pgd) & _PAGE_PRESENT)
#define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
diff -r 2c15ed1d75fb -r 5917bb91bf09 include/xen/pcifront.h
--- a/include/xen/pcifront.h Tue Jun 12 16:33:57 2007 -0600
+++ b/include/xen/pcifront.h Tue Jun 12 20:43:50 2007 -0600
@@ -26,7 +26,8 @@ pcifront_get_pdev(struct pcifront_sd *sd
return sd->pdev;
}
-static inline void pcifront_init_sd(struct pcifront_sd *sd, int domain,
+static inline void pcifront_init_sd(struct pcifront_sd *sd,
+ unsigned int domain, unsigned int bus,
struct pcifront_device *pdev)
{
sd->domain = domain;
@@ -45,10 +46,21 @@ static inline int pci_proc_domain(struct
}
#endif /* CONFIG_PCI_DOMAINS */
+static inline void pcifront_setup_root_resources(struct pci_bus *bus,
+ struct pcifront_sd *sd)
+{
+}
+
#else /* __ia64__ */
+#include <linux/acpi.h>
#include <asm/pci.h>
#define pcifront_sd pci_controller
+
+extern void xen_add_resource(struct pci_controller *, unsigned int,
+ unsigned int, struct acpi_resource *);
+extern void xen_pcibios_setup_root_windows(struct pci_bus *,
+ struct pci_controller *);
static inline struct pcifront_device *
pcifront_get_pdev(struct pcifront_sd *sd)
@@ -56,16 +68,10 @@ pcifront_get_pdev(struct pcifront_sd *sd
return (struct pcifront_device *)sd->platform_data;
}
-static inline void pcifront_init_sd(struct pcifront_sd *sd, int domain,
- struct pcifront_device *pdev)
+static inline void pcifront_setup_root_resources(struct pci_bus *bus,
+ struct pcifront_sd *sd)
{
- sd->segment = domain;
- sd->acpi_handle = NULL;
- sd->iommu = NULL;
- sd->node = -1;
- sd->windows = 0;
- sd->window = NULL;
- sd->platform_data = pdev;
+ xen_pcibios_setup_root_windows(bus, sd);
}
#endif /* __ia64__ */
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|