Commit 11e88964 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch '2.6.37-rc4-pvhvm-fixes' of git://xenbits.xen.org/people/sstabellini/linux-pvhvm

* '2.6.37-rc4-pvhvm-fixes' of git://xenbits.xen.org/people/sstabellini/linux-pvhvm:
  xen: unplug the emulated devices at resume time
  xen: fix save/restore for PV on HVM guests with pirq remapping
  xen: resume the pv console for hvm guests too
  xen: fix MSI setup and teardown for PV on HVM guests
  xen: use PHYSDEVOP_get_free_pirq to implement find_unbound_pirq
parents 8338fded 512b109e
...@@ -70,6 +70,9 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi, ...@@ -70,6 +70,9 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi,
struct xen_pci_frontend_ops *xen_pci_frontend; struct xen_pci_frontend_ops *xen_pci_frontend;
EXPORT_SYMBOL_GPL(xen_pci_frontend); EXPORT_SYMBOL_GPL(xen_pci_frontend);
#define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
MSI_DATA_LEVEL_ASSERT | (3 << 8) | MSI_DATA_VECTOR(0))
static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq, static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq,
struct msi_msg *msg) struct msi_msg *msg)
{ {
...@@ -83,12 +86,7 @@ static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq, ...@@ -83,12 +86,7 @@ static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq,
MSI_ADDR_REDIRECTION_CPU | MSI_ADDR_REDIRECTION_CPU |
MSI_ADDR_DEST_ID(pirq); MSI_ADDR_DEST_ID(pirq);
msg->data = msg->data = XEN_PIRQ_MSI_DATA;
MSI_DATA_TRIGGER_EDGE |
MSI_DATA_LEVEL_ASSERT |
/* delivery mode reserved */
(3 << 8) |
MSI_DATA_VECTOR(0);
} }
static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
...@@ -98,8 +96,23 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) ...@@ -98,8 +96,23 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
struct msi_msg msg; struct msi_msg msg;
list_for_each_entry(msidesc, &dev->msi_list, list) { list_for_each_entry(msidesc, &dev->msi_list, list) {
__read_msi_msg(msidesc, &msg);
pirq = MSI_ADDR_EXT_DEST_ID(msg.address_hi) |
((msg.address_lo >> MSI_ADDR_DEST_ID_SHIFT) & 0xff);
if (xen_irq_from_pirq(pirq) >= 0 && msg.data == XEN_PIRQ_MSI_DATA) {
xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
"msi-x" : "msi", &irq, &pirq, XEN_ALLOC_IRQ);
if (irq < 0)
goto error;
ret = set_irq_msi(irq, msidesc);
if (ret < 0)
goto error_while;
printk(KERN_DEBUG "xen: msi already setup: msi --> irq=%d"
" pirq=%d\n", irq, pirq);
return 0;
}
xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ? xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
"msi-x" : "msi", &irq, &pirq); "msi-x" : "msi", &irq, &pirq, (XEN_ALLOC_IRQ | XEN_ALLOC_PIRQ));
if (irq < 0 || pirq < 0) if (irq < 0 || pirq < 0)
goto error; goto error;
printk(KERN_DEBUG "xen: msi --> irq=%d, pirq=%d\n", irq, pirq); printk(KERN_DEBUG "xen: msi --> irq=%d, pirq=%d\n", irq, pirq);
......
...@@ -68,7 +68,7 @@ static int __init check_platform_magic(void) ...@@ -68,7 +68,7 @@ static int __init check_platform_magic(void)
return 0; return 0;
} }
void __init xen_unplug_emulated_devices(void) void xen_unplug_emulated_devices(void)
{ {
int r; int r;
......
...@@ -31,6 +31,7 @@ void xen_hvm_post_suspend(int suspend_cancelled) ...@@ -31,6 +31,7 @@ void xen_hvm_post_suspend(int suspend_cancelled)
int cpu; int cpu;
xen_hvm_init_shared_info(); xen_hvm_init_shared_info();
xen_callback_vector(); xen_callback_vector();
xen_unplug_emulated_devices();
if (xen_feature(XENFEAT_hvm_safe_pvclock)) { if (xen_feature(XENFEAT_hvm_safe_pvclock)) {
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
xen_setup_runstate_info(cpu); xen_setup_runstate_info(cpu);
......
...@@ -43,7 +43,7 @@ void xen_vcpu_restore(void); ...@@ -43,7 +43,7 @@ void xen_vcpu_restore(void);
void xen_callback_vector(void); void xen_callback_vector(void);
void xen_hvm_init_shared_info(void); void xen_hvm_init_shared_info(void);
void __init xen_unplug_emulated_devices(void); void xen_unplug_emulated_devices(void);
void __init xen_build_dynamic_phys_to_machine(void); void __init xen_build_dynamic_phys_to_machine(void);
......
...@@ -105,7 +105,6 @@ struct irq_info ...@@ -105,7 +105,6 @@ struct irq_info
static struct irq_info *irq_info; static struct irq_info *irq_info;
static int *pirq_to_irq; static int *pirq_to_irq;
static int nr_pirqs;
static int *evtchn_to_irq; static int *evtchn_to_irq;
struct cpu_evtchn_s { struct cpu_evtchn_s {
...@@ -385,12 +384,17 @@ static int get_nr_hw_irqs(void) ...@@ -385,12 +384,17 @@ static int get_nr_hw_irqs(void)
return ret; return ret;
} }
/* callers of this function should make sure that PHYSDEVOP_get_nr_pirqs static int find_unbound_pirq(int type)
* succeeded otherwise nr_pirqs won't hold the right value */
static int find_unbound_pirq(void)
{ {
int i; int rc, i;
for (i = nr_pirqs-1; i >= 0; i--) { struct physdev_get_free_pirq op_get_free_pirq;
op_get_free_pirq.type = type;
rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_free_pirq, &op_get_free_pirq);
if (!rc)
return op_get_free_pirq.pirq;
for (i = 0; i < nr_irqs; i++) {
if (pirq_to_irq[i] < 0) if (pirq_to_irq[i] < 0)
return i; return i;
} }
...@@ -611,10 +615,10 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) ...@@ -611,10 +615,10 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
spin_lock(&irq_mapping_update_lock); spin_lock(&irq_mapping_update_lock);
if ((pirq > nr_pirqs) || (gsi > nr_irqs)) { if ((pirq > nr_irqs) || (gsi > nr_irqs)) {
printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n", printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n",
pirq > nr_pirqs ? "nr_pirqs" :"", pirq > nr_irqs ? "pirq" :"",
gsi > nr_irqs ? "nr_irqs" : ""); gsi > nr_irqs ? "gsi" : "");
goto out; goto out;
} }
...@@ -664,17 +668,21 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) ...@@ -664,17 +668,21 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
#include <linux/msi.h> #include <linux/msi.h>
#include "../pci/msi.h" #include "../pci/msi.h"
void xen_allocate_pirq_msi(char *name, int *irq, int *pirq) void xen_allocate_pirq_msi(char *name, int *irq, int *pirq, int alloc)
{ {
spin_lock(&irq_mapping_update_lock); spin_lock(&irq_mapping_update_lock);
*irq = find_unbound_irq(); if (alloc & XEN_ALLOC_IRQ) {
if (*irq == -1) *irq = find_unbound_irq();
goto out; if (*irq == -1)
goto out;
}
*pirq = find_unbound_pirq(); if (alloc & XEN_ALLOC_PIRQ) {
if (*pirq == -1) *pirq = find_unbound_pirq(MAP_PIRQ_TYPE_MSI);
goto out; if (*pirq == -1)
goto out;
}
set_irq_chip_and_handler_name(*irq, &xen_pirq_chip, set_irq_chip_and_handler_name(*irq, &xen_pirq_chip,
handle_level_irq, name); handle_level_irq, name);
...@@ -762,6 +770,7 @@ int xen_destroy_irq(int irq) ...@@ -762,6 +770,7 @@ int xen_destroy_irq(int irq)
printk(KERN_WARNING "unmap irq failed %d\n", rc); printk(KERN_WARNING "unmap irq failed %d\n", rc);
goto out; goto out;
} }
pirq_to_irq[info->u.pirq.pirq] = -1;
} }
irq_info[irq] = mk_unbound_info(); irq_info[irq] = mk_unbound_info();
...@@ -782,6 +791,11 @@ int xen_gsi_from_irq(unsigned irq) ...@@ -782,6 +791,11 @@ int xen_gsi_from_irq(unsigned irq)
return gsi_from_irq(irq); return gsi_from_irq(irq);
} }
int xen_irq_from_pirq(unsigned pirq)
{
return pirq_to_irq[pirq];
}
int bind_evtchn_to_irq(unsigned int evtchn) int bind_evtchn_to_irq(unsigned int evtchn)
{ {
int irq; int irq;
...@@ -1279,6 +1293,42 @@ static int retrigger_dynirq(unsigned int irq) ...@@ -1279,6 +1293,42 @@ static int retrigger_dynirq(unsigned int irq)
return ret; return ret;
} }
static void restore_cpu_pirqs(void)
{
int pirq, rc, irq, gsi;
struct physdev_map_pirq map_irq;
for (pirq = 0; pirq < nr_irqs; pirq++) {
irq = pirq_to_irq[pirq];
if (irq == -1)
continue;
/* save/restore of PT devices doesn't work, so at this point the
* only devices present are GSI based emulated devices */
gsi = gsi_from_irq(irq);
if (!gsi)
continue;
map_irq.domid = DOMID_SELF;
map_irq.type = MAP_PIRQ_TYPE_GSI;
map_irq.index = gsi;
map_irq.pirq = pirq;
rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
if (rc) {
printk(KERN_WARNING "xen map irq failed gsi=%d irq=%d pirq=%d rc=%d\n",
gsi, irq, pirq, rc);
irq_info[irq] = mk_unbound_info();
pirq_to_irq[pirq] = -1;
continue;
}
printk(KERN_DEBUG "xen: --> irq=%d, pirq=%d\n", irq, map_irq.pirq);
startup_pirq(irq);
}
}
static void restore_cpu_virqs(unsigned int cpu) static void restore_cpu_virqs(unsigned int cpu)
{ {
struct evtchn_bind_virq bind_virq; struct evtchn_bind_virq bind_virq;
...@@ -1422,6 +1472,8 @@ void xen_irq_resume(void) ...@@ -1422,6 +1472,8 @@ void xen_irq_resume(void)
unmask_evtchn(evtchn); unmask_evtchn(evtchn);
} }
restore_cpu_pirqs();
} }
static struct irq_chip xen_dynamic_chip __read_mostly = { static struct irq_chip xen_dynamic_chip __read_mostly = {
...@@ -1506,26 +1558,17 @@ void xen_callback_vector(void) {} ...@@ -1506,26 +1558,17 @@ void xen_callback_vector(void) {}
void __init xen_init_IRQ(void) void __init xen_init_IRQ(void)
{ {
int i, rc; int i;
struct physdev_nr_pirqs op_nr_pirqs;
cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s), cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s),
GFP_KERNEL); GFP_KERNEL);
irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL); irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL);
rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_nr_pirqs, &op_nr_pirqs); /* We are using nr_irqs as the maximum number of pirq available but
if (rc < 0) { * that number is actually chosen by Xen and we don't know exactly
nr_pirqs = nr_irqs; * what it is. Be careful choosing high pirq numbers. */
if (rc != -ENOSYS) pirq_to_irq = kcalloc(nr_irqs, sizeof(*pirq_to_irq), GFP_KERNEL);
printk(KERN_WARNING "PHYSDEVOP_get_nr_pirqs returned rc=%d\n", rc); for (i = 0; i < nr_irqs; i++)
} else {
if (xen_pv_domain() && !xen_initial_domain())
nr_pirqs = max((int)op_nr_pirqs.nr_pirqs, nr_irqs);
else
nr_pirqs = op_nr_pirqs.nr_pirqs;
}
pirq_to_irq = kcalloc(nr_pirqs, sizeof(*pirq_to_irq), GFP_KERNEL);
for (i = 0; i < nr_pirqs; i++)
pirq_to_irq[i] = -1; pirq_to_irq[i] = -1;
evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq),
......
...@@ -49,6 +49,7 @@ static int xen_hvm_suspend(void *data) ...@@ -49,6 +49,7 @@ static int xen_hvm_suspend(void *data)
if (!*cancelled) { if (!*cancelled) {
xen_irq_resume(); xen_irq_resume();
xen_console_resume();
xen_timer_resume(); xen_timer_resume();
} }
......
...@@ -76,7 +76,9 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name); ...@@ -76,7 +76,9 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name);
#ifdef CONFIG_PCI_MSI #ifdef CONFIG_PCI_MSI
/* Allocate an irq and a pirq to be used with MSIs. */ /* Allocate an irq and a pirq to be used with MSIs. */
void xen_allocate_pirq_msi(char *name, int *irq, int *pirq); #define XEN_ALLOC_PIRQ (1 << 0)
#define XEN_ALLOC_IRQ (1 << 1)
void xen_allocate_pirq_msi(char *name, int *irq, int *pirq, int alloc_mask);
int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type); int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type);
#endif #endif
...@@ -89,4 +91,7 @@ int xen_vector_from_irq(unsigned pirq); ...@@ -89,4 +91,7 @@ int xen_vector_from_irq(unsigned pirq);
/* Return gsi allocated to pirq */ /* Return gsi allocated to pirq */
int xen_gsi_from_irq(unsigned pirq); int xen_gsi_from_irq(unsigned pirq);
/* Return irq from pirq */
int xen_irq_from_pirq(unsigned pirq);
#endif /* _XEN_EVENTS_H */ #endif /* _XEN_EVENTS_H */
...@@ -188,6 +188,16 @@ struct physdev_nr_pirqs { ...@@ -188,6 +188,16 @@ struct physdev_nr_pirqs {
uint32_t nr_pirqs; uint32_t nr_pirqs;
}; };
/* type is MAP_PIRQ_TYPE_GSI or MAP_PIRQ_TYPE_MSI
* the hypercall returns a free pirq */
#define PHYSDEVOP_get_free_pirq 23
struct physdev_get_free_pirq {
/* IN */
int type;
/* OUT */
uint32_t pirq;
};
/* /*
* Notify that some PIRQ-bound event channels have been unmasked. * Notify that some PIRQ-bound event channels have been unmasked.
* ** This command is obsolete since interface version 0x00030202 and is ** * ** This command is obsolete since interface version 0x00030202 and is **
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment