Updated pseries patches
cover Updated pseries patches
Hi Alex,
Here are the two patches from my last pseries batch which didn't go in, updated to incorporate comments from the list.
PATCH 1/2 pseries: Add support for level interrupts to XICS
The pseries "xics" interrupt controller, like most interrupt controllers can support both message (i.e. edge sensitive) interrupts and level sensitive interrupts, but it needs to know which are which.
When I implemented the xics emulation for qemu, the only devices we supported were the PAPR virtual IO devices. These devices only use message interrupts, so they were the only ones I implemented in xics.
Since then, however, we have added support for PCI devices, which use level sensitive interrupts. It turns out the message interrupt logic still actually works most of the time for these, but there are circumstances where we can lost interrupts due to the incorrect interrupt logic.
This patch, therefore, implements the correct xics level-sensitive interrupt logic. The type of the interrupt is set when a device allocates a new xics interrupt.
--- hw/spapr.c | 5 +- hw/spapr.h | 13 +++++- hw/spapr_pci.c | 2 +- hw/spapr_vio.c | 2 +- hw/xics.c | 125 +++++++++++++++++++++++++++++++++++++++++-------------- hw/xics.h | 8 +++- 6 files changed, 117 insertions(+), 38 deletions(-)
hw/spapr.c +3 -2
@@ -83,7 +83,8 @@sPAPREnvironment *spapr; -qemu_irq spapr_allocate_irq (uint32_t hint,uint32_t *irq_num) +qemu_irq spapr_allocate_irq (uint32_t hint,uint32_t *irq_num, +enum xics_irq_type type) {uint32_t irq;qemu_irq qirq;
@@ -95,7 +96,7 @@ qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num) irq = spapr->next_irq++; } - qirq =xics_find_qirq (spapr->icp, irq); + qirq =xics_assign_irq (spapr->icp, irq, type);if (!qirq) {return NULL ; }
hw/spapr.h +12 -1
@@ -286,7 +286,18 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);target_ulong spapr_hypercall (CPUState *env,target_ulong opcode,target_ulong *args); -qemu_irq spapr_allocate_irq (uint32_t hint,uint32_t *irq_num); +qemu_irq spapr_allocate_irq (uint32_t hint,uint32_t *irq_num, +enum xics_irq_type type); + +static inline qemu_irq spapr_allocate_msi (uint32_t hint,uint32_t *irq_num) +{ +return spapr_allocate_irq (hint, irq_num,XICS_MSI ); +} + +static inline qemu_irq spapr_allocate_lsi (uint32_t hint,uint32_t *irq_num) +{ +return spapr_allocate_irq (hint, irq_num,XICS_LSI ); +}static inline uint32_t rtas_ld (target_ulong phys,int n) {
hw/spapr_pci.c +1 -1
@@ -171,7 +171,7 @@ static int spapr_phb_init(SysBusDevice *s)qemu_irq qirq;uint32_t num; - qirq =spapr_allocate_irq (0 , &num); + qirq =spapr_allocate_lsi (0 , &num);if (!qirq) {return -1 ; }
hw/spapr_vio.c +1 -1
@@ -670,7 +670,7 @@ static int spapr_vio_busdev_init(DeviceState *qdev) dev->qdev.id = id; } - dev->qirq =spapr_allocate_irq (dev->vio_irq_num, &dev->vio_irq_num); + dev->qirq =spapr_allocate_msi (dev->vio_irq_num, &dev->vio_irq_num);if (!dev->qirq) {return -1 ; }
hw/xics.c +93 -32
204 lines not on this page · raw message
hw/xics.h +7 -1
@@ -31,7 +31,13 @@struct icp_state ; -qemu_irq xics_find_qirq (struct icp_state *icp,int irq); +enum xics_irq_type { +XICS_MSI ,/* Message-signalled (edge) interrupt */ +XICS_LSI ,/* Level-signalled interrupt */ +}; + +qemu_irq xics_assign_irq (struct icp_state *icp,int irq, +enum xics_irq_type type);struct icp_state *xics_system_init (int nr_irqs);
Signature · 1 line
1.7.9.1
Alexander Graf
AppliedRe: [Qemu-devel] [PATCH 1/2] pseries: Add support for level interrupts to XICS
Quoted 14 lines · David Gibson
The pseries "xics" interrupt controller, like most interrupt controllers can support both message (i.e. edge sensitive) interrupts and level sensitive interrupts, but it needs to know which are which.
When I implemented the xics emulation for qemu, the only devices we supported were the PAPR virtual IO devices. These devices only use message interrupts, so they were the only ones I implemented in xics.
Since then, however, we have added support for PCI devices, which use level sensitive interrupts. It turns out the message interrupt logic still actually works most of the time for these, but there are circumstances where we can lost interrupts due to the incorrect interrupt logic.
Quoted 5 lines
This patch, therefore, implements the correct xics level-sensitive interrupt logic. The type of the interrupt is set when a device allocates a new xics interrupt.
Signed-off-by David Gibson <[email protected]>
Thanks, applied to ppc-next.
Alex
PATCH 2/2 pseries: Configure PCI bridge using properties
In reply to David GibsonCurrently, the function spapr_create_phb() uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.
Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from spapr_create_phb() to spapr_phb_init().
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
--- hw/spapr.c | 2 +- hw/spapr_pci.c | 148 ++++++++++++++++++++++++++++++-------------------------- hw/spapr_pci.h | 5 +- 3 files changed, 83 insertions(+), 72 deletions(-)
hw/spapr.c +1 -1
@@ -630,7 +630,7 @@ static void ppc_spapr_init(ram_addr_t ram_size, }/* Set up PCI */ -spapr_create_phb (spapr,"pci" ,SPAPR_PCI_BUID , +spapr_create_phb (spapr,SPAPR_PCI_BUID ,SPAPR_PCI_MEM_WIN_ADDR ,SPAPR_PCI_MEM_WIN_SIZE ,SPAPR_PCI_IO_WIN_ADDR );
hw/spapr_pci.c +80 -68
196 lines not on this page · raw message
hw/spapr_pci.h +2 -3
@@ -35,7 +35,7 @@ typedef struct sPAPRPHBState {uint64_t buid;MemoryRegion memspace, iospace; -target_phys_addr_t mem_win_addr, io_win_addr; +target_phys_addr_t mem_win_addr, mem_win_size, io_win_addr, io_win_size;MemoryRegion memwindow, iowindow;struct {
@@ -49,8 +49,7 @@ typedef struct sPAPRPHBState {#define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL#define SPAPR_PCI_IO_WIN_SIZE 0x10000 -void spapr_create_phb (sPAPREnvironment *spapr, -const char *busname,uint64_t buid, +void spapr_create_phb (sPAPREnvironment *spapr,uint64_t buid,uint64_t mem_win_addr,uint64_t mem_win_size,uint64_t io_win_addr);
Signature · 1 line
1.7.9.1
Re: [Qemu-devel] [PATCH 2/2] pseries: Configure PCI bridge using properties
Quoted 11 lines · David Gibson
Currently, the function
spapr_create_phb()uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from
spapr_create_phb()tospapr_phb_init().
Quoted 6 lines
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by David Gibson <[email protected]>
Andreas, could you please (n)ack this version?
Alex
Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] pseries: Configure PCI bridge using properties
Quoted 14 lines · Alexander Graf
Quoted 11 lines · David Gibson
Currently, the function
spapr_create_phb()uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from
spapr_create_phb()tospapr_phb_init().
Quoted 8 lines
Quoted 6 lines
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by David Gibson <[email protected]>Andreas, could you please (n)ack this version?
Actually, can you review and merge this updated version instead. Turns out that libvirt and some other tools assume that there will be a PCI bus named simply "pci", which is no longer true with the patch above (we call each bus "pci@XXXXXX" to match the guest's device tree). The revised version calls the default bus simply "pci" to work around libvirt's PC centrism, and allows manually added extra busses to be named explicitly with a property, defaulting to "pci@XXXXX".
Quoted 1 line
From
c2ce4ad7c4e36ea79d34cfa3305f4b027492474eMon Sep 17 00:00:00 2001
From: David Gibson <[email protected]>
Date: Tue, 13 Mar 2012 14:13:26 +1100
Subject: [PATCH] pseries: Configure PCI bridge using properties
Currently, the function spapr_create_phb() uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.
Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from spapr_create_phb() to spapr_phb_init().
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
--- hw/spapr_pci.c | 166 +++++++++++++++++++++++++++++++------------------------- hw/spapr_pci.h | 4 +- 2 files changed, 94 insertions(+), 76 deletions(-)
hw/spapr_pci.c +91 -75
@@ -161,49 +161,6 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)qemu_set_irq (phb->lsi_table[irq_num].qirq, level); } -static int spapr_phb_init (SysBusDevice *s) -{ -sPAPRPHBState *phb =FROM_SYSBUS (sPAPRPHBState, s); -int i; - -/* Initialize the LSI table */ -for (i =0 ; i <SPAPR_PCI_NUM_LSI ; i++) { -qemu_irq qirq; -uint32_t num; - - qirq =spapr_allocate_lsi (0 , &num); -if (!qirq) { -return -1 ; - } - - phb->lsi_table[i].dt_irq = num; - phb->lsi_table[i].qirq = qirq; - } - -return 0 ; -} - -static void spapr_phb_class_init (ObjectClass *klass,void *data) -{ -SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); - - sdc->init = spapr_phb_init; -} - -static TypeInfo spapr_phb_info = { - .name ="spapr-pci-host-bridge" , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (sPAPRPHBState), - .class_init = spapr_phb_class_init, -}; - -static void spapr_register_types (void ) -{ -type_register_static (&spapr_phb_info); -} - -type_init (spapr_register_types) -static uint64_t spapr_io_read (void *opaque,target_phys_addr_t addr,unsigned size) {
@@ -241,35 +198,29 @@ static const MemoryRegionOps spapr_io_ops = { .write = spapr_io_write }; -void spapr_create_phb (sPAPREnvironment *spapr, -const char *busname,uint64_t buid, -uint64_t mem_win_addr,uint64_t mem_win_size, -uint64_t io_win_addr) +/* +* PHB PCI device +*/ +static int spapr_phb_init (SysBusDevice *s) { -DeviceState *dev; -SysBusDevice *s; -sPAPRPHBState *phb; +sPAPRPHBState *phb =FROM_SYSBUS (sPAPRPHBState, s); +char *namebuf; +int i;PCIBus *bus; -char namebuf[strlen (busname)+11 ]; - dev =qdev_create (NULL ,"spapr-pci-host-bridge" ); -qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); - phb =FROM_SYSBUS (sPAPRPHBState, s); + phb->dtbusname =g_strdup_printf ("pci@%" PRIx64, phb->buid); + namebuf =alloca (strlen (phb->dtbusname) +32 ); - phb->mem_win_addr = mem_win_addr; - -sprintf (namebuf,"%s-mem" , busname); +/* Initialize memory regions */ +sprintf (namebuf,"%s.mmio" , phb->dtbusname);memory_region_init (&phb->memspace, namebuf,INT64_MAX ); -sprintf (namebuf,"%s-memwindow" , busname); +sprintf (namebuf,"%s.mmio-alias" , phb->dtbusname);memory_region_init_alias (&phb->memwindow, namebuf, &phb->memspace, -SPAPR_PCI_MEM_WIN_BUS_OFFSET , mem_win_size); -memory_region_add_subregion (get_system_memory (), mem_win_addr, +SPAPR_PCI_MEM_WIN_BUS_OFFSET , phb->mem_win_size); +memory_region_add_subregion (get_system_memory (), phb->mem_win_addr, &phb->memwindow); - phb->io_win_addr = io_win_addr; -/* On ppc, we only have MMIO no specific IO space from the CPU * perspective. In theory we ought to be able to embed the PCI IO * memory region direction in the system memory space. However,
@@ -278,33 +229,92 @@ void spapr_create_phb(sPAPREnvironment *spapr,* system io address space. This hack to bounce things via * system_io works around the problem until all the users of * old_portion are updated */ -sprintf (namebuf,"%s-io" , busname); +sprintf (namebuf,"%s.io" , phb->dtbusname);memory_region_init (&phb->iospace, namebuf,SPAPR_PCI_IO_WIN_SIZE );/* FIXME: fix to support multiple PHBs */ memory_region_add_subregion (get_system_io (),0 , &phb->iospace); -sprintf (namebuf,"%s-iowindow" , busname); +sprintf (namebuf,"%s.io-alias" , phb->dtbusname);memory_region_init_io (&phb->iowindow, &spapr_io_ops, phb, namebuf,SPAPR_PCI_IO_WIN_SIZE ); -memory_region_add_subregion (get_system_memory (), io_win_addr, +memory_region_add_subregion (get_system_memory (), phb->io_win_addr, &phb->iowindow); - phb->host_state.bus = bus =pci_register_bus (&phb->busdev.qdev, busname, - pci_spapr_set_irq, - pci_spapr_map_irq, - phb, - &phb->memspace, &phb->iospace, -PCI_DEVFN (0 ,0 ), -SPAPR_PCI_NUM_LSI ); + bus =pci_register_bus (&phb->busdev.qdev, + phb->busname ? phb->busname : phb->dtbusname, + pci_spapr_set_irq, pci_spapr_map_irq, phb, + &phb->memspace, &phb->iospace, +PCI_DEVFN (0 ,0 ),SPAPR_PCI_NUM_LSI ); + phb->host_state.bus = bus; + +QLIST_INSERT_HEAD (&spapr->phbs, phb, list); + +/* Initialize the LSI table */ +for (i =0 ; i <SPAPR_PCI_NUM_LSI ; i++) { +qemu_irq qirq; +uint32_t num; + + qirq =spapr_allocate_lsi (0 , &num); +if (!qirq) { +return -1 ; + } + + phb->lsi_table[i].dt_irq = num; + phb->lsi_table[i].qirq = qirq; + } + +return 0 ; +} + +static Property spapr_phb_properties[] = { +DEFINE_PROP_HEX64 ("buid" , sPAPRPHBState, buid,0 ), +DEFINE_PROP_STRING ("busname" , sPAPRPHBState, busname), +DEFINE_PROP_HEX64 ("mem_win_addr" , sPAPRPHBState, mem_win_addr,0 ), +DEFINE_PROP_HEX64 ("mem_win_size" , sPAPRPHBState, mem_win_size,0x20000000 ), +DEFINE_PROP_HEX64 ("io_win_addr" , sPAPRPHBState, io_win_addr,0 ), +DEFINE_PROP_HEX64 ("io_win_size" , sPAPRPHBState, io_win_size,0x10000 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_phb_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + sdc->init = spapr_phb_init; + dc->props = spapr_phb_properties;spapr_rtas_register ("read-pci-config" , rtas_read_pci_config);spapr_rtas_register ("write-pci-config" , rtas_write_pci_config);spapr_rtas_register ("ibm,read-pci-config" , rtas_ibm_read_pci_config);spapr_rtas_register ("ibm,write-pci-config" , rtas_ibm_write_pci_config); +} -QLIST_INSERT_HEAD (&spapr->phbs, phb, list); +static TypeInfo spapr_phb_info = { + .name ="spapr-pci-host-bridge" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRPHBState), + .class_init = spapr_phb_class_init, +}; + +void spapr_create_phb (sPAPREnvironment *spapr, +const char *busname,uint64_t buid, +uint64_t mem_win_addr,uint64_t mem_win_size, +uint64_t io_win_addr) +{ +DeviceState *dev; + + dev =qdev_create (NULL , spapr_phb_info.name); -/* pci_bus_set_mem_base(bus, mem_va_start - SPAPR_PCI_MEM_BAR_START); */ +if (busname) { +qdev_prop_set_string (dev,"busname" ,g_strdup (busname)); + } +qdev_prop_set_uint64 (dev,"buid" , buid); +qdev_prop_set_uint64 (dev,"mem_win_addr" , mem_win_addr); +qdev_prop_set_uint64 (dev,"mem_win_size" , mem_win_size); +qdev_prop_set_uint64 (dev,"io_win_addr" , io_win_addr); + +qdev_init_nofail (dev); }/* Macros to operate with address in OF binding to PCI */
@@ -396,3 +406,9 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,return 0 ; } + +static void register_types (void ) +{ +type_register_static (&spapr_phb_info); +} +type_init (register_types)
hw/spapr_pci.h +3 -1
@@ -33,9 +33,11 @@ typedef struct sPAPRPHBState {PCIHostState host_state;uint64_t buid; +char *busname; +char *dtbusname;MemoryRegion memspace, iospace; -target_phys_addr_t mem_win_addr, io_win_addr; +target_phys_addr_t mem_win_addr, mem_win_size, io_win_addr, io_win_size;MemoryRegion memwindow, iowindow;struct {
Signature · 9 lines
1.7.9.1 -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Andreas Färber
Reviewed-byRe: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] pseries: Configure PCI bridge using properties
Am 13.03.2012 04:50, schrieb David Gibson:
Quoted 24 lines · Alexander Graf
Quoted 14 lines · David Gibson
Quoted 12 lines
Currently, the function
spapr_create_phb()uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from
spapr_create_phb()tospapr_phb_init().Quoted 8 lines
Quoted 6 lines
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by David Gibson <[email protected]>Andreas, could you please (n)ack this version?
Quoted 7 lines
Actually, can you review and merge this updated version instead. Turns out that libvirt and some other tools assume that there will be a PCI bus named simply "pci", which is no longer true with the patch above (we call each bus "pci@XXXXXX" to match the guest's device tree). The revised version calls the default bus simply "pci" to work around libvirt's PC centrism, and allows manually added extra busses to be named explicitly with a property, defaulting to "pci@XXXXX".
I was happy with David's improvements but didn't feel comfortable acking the overall patch.
One minor improvement in case this gets gespun:
* spapr_phb_info could be made static const (was/is static)
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Alexander Graf
AppliedRe: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] pseries: Configure PCI bridge using properties
In reply to David GibsonQuoted 48 lines · David Gibson
Quoted 14 lines · Alexander Graf
Quoted 11 lines · David Gibson
Currently, the function
spapr_create_phb()uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from
spapr_create_phb()tospapr_phb_init().Quoted 8 lines
Quoted 6 lines
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by David Gibson <[email protected]>Andreas, could you please (n)ack this version?
Actually, can you review and merge this updated version instead. Turns out that libvirt and some other tools assume that there will be a PCI bus named simply "pci", which is no longer true with the patch above (we call each bus "pci@XXXXXX" to match the guest's device tree). The revised version calls the default bus simply "pci" to work around libvirt's PC centrism, and allows manually added extra busses to be named explicitly with a property, defaulting to "pci@XXXXX".
From
c2ce4ad7c4e36ea79d34cfa3305f4b027492474eMon Sep 17 00:00:00 2001
From: David Gibson <[email protected]>
Date: Tue, 13 Mar 2012 14:13:26 +1100
Subject: [PATCH] pseries: Configure PCI bridge using propertiesCurrently, the function
spapr_create_phb()uses its parameters to initialize the correct memory windows for the new PCI Host Bridge (PHB). This is not the way things are supposed to be done with qdevs, and means you can't create extra PHBs easily using -device.Since pSeries machines can and do have many PHBs with various configurations, this is a real limitation, not just a theoretical. This patch, therefore, alters the PHB initialization code to use qdev properties to set these parameters of the new bridge, moving most of the code from
spapr_create_phb()tospapr_phb_init().
Quoted 6 lines
While we're at it, we change the naming of each PCI bus and its associated memory regions to be less arbitrary and make it easier to relate the guest and qemu views of memory to each other.
Signed-off-by Alexey Kardashevskiy <[email protected]>Signed-off-by David Gibson <[email protected]>
Thanks, applied to ppc-next.
Alex