ppc/pnv: reworking the interrupt controller
v6 cover ppc/pnv: reworking the interrupt controller
Hello,
Here is a short serie adding support for the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
The initial patches are mostly cleanups and small extensions to the XICS framework. They provide a basic container XICS object that the PowerNV machine can use to hold the ICSs and ICPs of the system. Last is the PSI HB model which handles the external interrupt.
The next step should be IPMI support which adds a BT device on the ISA bus and some device tree extensions to read sensors and FRUs. This is relatively straight forward and most of the IPMI code has been discussed already on the list. Then should come a PHB3 model to include some PCI devices. This is big and it needs a few helpers in the PCI core.
If you feel adventurous, you can grab kernel and rootfs images :
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/zImage.epapr
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/rootfs.cpio.xz
and give it a try. The full patchset is available here :
https://github.com/legoater/qemu/commits/powernv-ipmi-2.8
This is a wip branch.
Thanks,
C.
Benjamin Herrenschmidt (3):
ppc/pnv: Add cut down PSI bridge model and hookup external interrupt ppc/pnv: Add OCC model stub with interrupt support ppc/pnv: Add Naples chip support for LPC interrupts
Cédric Le Goater (7):
ppc/xics: introduce a helper to insert a new ics ppc/xics: add a xics_get_cpu_index_by_pir helper ppc/xics: add a 'realize' handler to the xics_common class ppc/xics: add a 'set_nr_servers' handler to the xics_common class ppc/pnv: add a XICS object to the PowerNV machine ppc/pnv: add MMIO regions for ICPs
ppc/pnv: link the CPUs to the machine XICS
hw/intc/xics.c | 61 +++++ hw/intc/xics_kvm.c | 30 +-- hw/intc/xics_spapr.c | 41 +--- hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 139 ++++++++++- hw/ppc/pnv_core.c | 152 +++++++++++- hw/ppc/pnv_lpc.c | 47 +++- hw/ppc/pnv_occ.c | 136 +++++++++++ hw/ppc/pnv_psi.c | 574 +++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/ppc.c | 16 ++ include/hw/ppc/pnv.h | 32 +++ include/hw/ppc/pnv_core.h | 2 + include/hw/ppc/pnv_lpc.h | 9 + include/hw/ppc/pnv_occ.h | 38 +++ include/hw/ppc/pnv_psi.h | 61 +++++ include/hw/ppc/pnv_xscom.h | 6 + include/hw/ppc/xics.h | 8 + target-ppc/cpu.h | 10 + 18 files changed, 1283 insertions(+), 81 deletions(-) create mode 100644 hw/ppc/pnv_occ.c create mode 100644 hw/ppc/pnv_psi.c create mode 100644 include/hw/ppc/pnv_occ.h create mode 100644 include/hw/ppc/pnv_psi.h
Signature · 1 line
2.7.4
PATCH v6 1/10 ppc/xics: introduce a helper to insert a new ics
Interrupt Control Sources (ICS) are now maintained under a list.
---
Changes since v5:
- used the helper in xics spapr/kvm
hw/intc/xics.c | 6 ++++++ hw/intc/xics_kvm.c | 4 +--- hw/intc/xics_spapr.c | 4 +--- include/hw/ppc/xics.h | 1 + 4 files changed, 9 insertions(+), 6 deletions(-)
hw/intc/xics.c +6 -0
@@ -151,6 +151,12 @@ static void xics_common_reset(DeviceState *d) } } +void xics_insert_ics (XICSState *xics,ICSState *ics) +{ + ics->xics = xics; +QLIST_INSERT_HEAD (&xics->ics, ics, list); +} +static void xics_prop_get_nr_irqs (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
hw/intc/xics_kvm.c +1 -3
@@ -474,13 +474,11 @@ fail:static void xics_kvm_initfn (Object *obj) { -XICSState *xics =XICS_COMMON (obj);ICSState *ics; ics =ICS_SIMPLE (object_new (TYPE_ICS_KVM ));object_property_add_child (obj,"ics" ,OBJECT (ics),NULL ); - ics->xics = xics; -QLIST_INSERT_HEAD (&xics->ics, ics, list); +xics_insert_ics (XICS_COMMON (obj), ics); }static void xics_kvm_class_init (ObjectClass *oc,void *data)
hw/intc/xics_spapr.c +1 -3
@@ -302,13 +302,11 @@ static void xics_spapr_realize(DeviceState *dev, Error **errp)static void xics_spapr_initfn (Object *obj) { -XICSState *xics =XICS_SPAPR (obj);ICSState *ics; ics =ICS_SIMPLE (object_new (TYPE_ICS_SIMPLE ));object_property_add_child (obj,"ics" ,OBJECT (ics),NULL ); - ics->xics = xics; -QLIST_INSERT_HEAD (&xics->ics, ics, list); +xics_insert_ics (XICS_COMMON (obj), ics); }static void xics_spapr_class_init (ObjectClass *oc,void *data)
include/hw/ppc/xics.h +1 -0
@@ -209,5 +209,6 @@ void ics_simple_write_xive(ICSState *ics, int nr, int server,void ics_set_irq_type (ICSState *ics,int srcno,bool lsi);ICSState *xics_find_source (XICSState *icp,int irq); +void xics_insert_ics (XICSState *xics,ICSState *ics);#endif /* XICS_H */
Signature · 1 line
2.7.4
PATCH v6 2/10 ppc/xics: add a xics_get_cpu_index_by_pir helper
In reply to Cédric Le GoaterWe will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
---
Changes since v5:
- removed the dependency on XICS. The routine now uses a loop on all CPUs of the machine like this is done in ppc_get_vcpu_by_dt_id()
hw/intc/xics.c | 11 +++++++++++ hw/ppc/ppc.c | 16 ++++++++++++++++ include/hw/ppc/xics.h | 1 + target-ppc/cpu.h | 10 ++++++++++ 4 files changed, 38 insertions(+)
hw/intc/xics.c +11 -0
@@ -49,6 +49,17 @@ int xics_get_cpu_index_by_dt_id(int cpu_dt_id)return -1 ; } +int xics_get_cpu_index_by_pir (int pir) +{ +PowerPCCPU *cpu =ppc_get_vcpu_by_pir (pir); + +if (cpu) { +return cpu->parent_obj.cpu_index; + } + +return -1 ; +} +void xics_cpu_destroy (XICSState *xics,PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);
hw/ppc/ppc.c +16 -0
@@ -1352,6 +1352,22 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id)return NULL ; } +PowerPCCPU *ppc_get_vcpu_by_pir (int pir) +{ +CPUState *cs; + +CPU_FOREACH (cs) { +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +if (env->spr_cb[SPR_PIR ].default_value == pir) { +return cpu; + } + } + +return NULL ; +} +void ppc_cpu_parse_features (const char *cpu_model) {CPUClass *cc;
include/hw/ppc/xics.h +1 -0
@@ -196,6 +196,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers,/* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id (int cpu_dt_id); +int xics_get_cpu_index_by_pir (int pir);void icp_set_cppr (ICPState *icp,uint8_t cppr);void icp_set_mfrr (ICPState *icp,uint8_t mfrr);
target-ppc/cpu.h +10 -0
@@ -2443,5 +2443,15 @@ int ppc_get_vcpu_dt_id(PowerPCCPU *cpu);*/ PowerPCCPU *ppc_get_vcpu_by_dt_id (int cpu_dt_id); +/** +* ppc_get_vcpu_by_pir_id: +* @pir: Processor Identifier Register (SPR_PIR) +* +* Searches for a CPU by @pir. +* +* Returns: a PowerPCCPU struct +*/ +PowerPCCPU *ppc_get_vcpu_by_pir (int pir); +void ppc_maybe_bswap_register (CPUPPCState *env,uint8_t *mem_buf,int len);#endif /* PPC_CPU_H */
Signature · 1 line
2.7.4
PATCH v6 3/10 ppc/xics: add a 'realize' handler to the xics_common class
In reply to Cédric Le GoaterThe xics_spapr_realize() and xics_kvm_realize() routines both realize the ICS and ICP objects the same way. We can move this part under the parent class xics_common and keep only the specificities in the child class.
---
To be noted : this patch changes a bit the call order. Realization of the ICS and ICP objects are now done before everything else.
hw/intc/xics.c | 36 ++++++++++++++++++++++++++++++++++++ hw/intc/xics_kvm.c | 26 ++------------------------ hw/intc/xics_spapr.c | 30 +----------------------------- include/hw/ppc/xics.h | 1 + 4 files changed, 40 insertions(+), 53 deletions(-)
hw/intc/xics.c +36 -0
@@ -253,6 +253,41 @@ static void xics_prop_set_nr_servers(Object *obj, Visitor *v, xsc->set_nr_servers (xics, value, errp); } +static void xics_common_realize (DeviceState *dev,Error **errp) +{ +XICSState *xics =XICS_COMMON (dev); +XICSStateClass *xsc =XICS_COMMON_GET_CLASS (xics); +ICSState *ics; +Error *error =NULL ; +int i; + +if (!xics->nr_servers) { +error_setg (errp,"Number of servers needs to be greater 0" ); +return ; + } + + QLIST_FOREACH(ics, &xics->ics, list) { +object_property_set_bool (OBJECT (ics), true,"realized" , &error); +if (error) { +error_propagate (errp, error); +return ; + } + } + +for (i =0 ; i < xics->nr_servers; i++) { +object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , + &error); +if (error) { +error_propagate (errp, error); +return ; + } + } + +if (xsc->realize) { + xsc->realize (dev, errp); + } +} +static void xics_common_initfn (Object *obj) {XICSState *xics =XICS_COMMON (obj);
@@ -271,6 +306,7 @@ static void xics_common_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc);InterruptStatsProviderClass *ic =INTERRUPT_STATS_PROVIDER_CLASS (oc); + dc->realize = xics_common_realize; dc->reset = xics_common_reset; ic->print_info = xics_common_pic_print_info; }
hw/intc/xics_kvm.c +2 -24
@@ -388,10 +388,7 @@ static void rtas_dummy(PowerPCCPU *cpu, sPAPRMachineState *spapr,static void xics_kvm_realize (DeviceState *dev,Error **errp) {KVMXICSState *xicskvm =XICS_SPAPR_KVM (dev); -XICSState *xics =XICS_COMMON (dev); -ICSState *ics; -int i, rc; -Error *error =NULL ; +int rc;struct kvm_create_device xics_create_device = { .type =KVM_DEV_TYPE_XICS , .flags =0 ,
@@ -441,24 +438,6 @@ static void xics_kvm_realize(DeviceState *dev, Error **errp) xicskvm->kernel_xics_fd = xics_create_device.fd; - QLIST_FOREACH(ics, &xics->ics, list) { -object_property_set_bool (OBJECT (ics), true,"realized" , &error); -if (error) { -error_propagate (errp, error); - goto fail; - } - } - -assert (xics->nr_servers); -for (i =0 ; i < xics->nr_servers; i++) { -object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , - &error); -if (error) { -error_propagate (errp, error); - goto fail; - } - } - kvm_kernel_irqchip = true; kvm_msi_via_irqfd_allowed = true; kvm_gsi_direct_mapping = true;
@@ -483,10 +462,9 @@ static void xics_kvm_initfn(Object *obj)static void xics_kvm_class_init (ObjectClass *oc,void *data) { -DeviceClass *dc =DEVICE_CLASS (oc);XICSStateClass *xsc =XICS_COMMON_CLASS (oc); - dc->realize = xics_kvm_realize; + xsc->realize = xics_kvm_realize; xsc->cpu_setup = xics_kvm_cpu_setup; xsc->set_nr_irqs = xics_kvm_set_nr_irqs; xsc->set_nr_servers = xics_kvm_set_nr_servers;
hw/intc/xics_spapr.c +1 -29
@@ -259,16 +259,6 @@ static void xics_spapr_set_nr_servers(XICSState *xics, uint32_t nr_servers,static void xics_spapr_realize (DeviceState *dev,Error **errp) { -XICSState *xics =XICS_SPAPR (dev); -ICSState *ics; -Error *error =NULL ; -int i; - -if (!xics->nr_servers) { -error_setg (errp,"Number of servers needs to be greater 0" ); -return ; - } -/* Registration of global state belongs into realize */ spapr_rtas_register (RTAS_IBM_SET_XIVE ,"ibm,set-xive" , rtas_set_xive);spapr_rtas_register (RTAS_IBM_GET_XIVE ,"ibm,get-xive" , rtas_get_xive);
@@ -281,23 +271,6 @@ static void xics_spapr_realize(DeviceState *dev, Error **errp)spapr_register_hypercall (H_XIRR_X , h_xirr_x);spapr_register_hypercall (H_EOI , h_eoi);spapr_register_hypercall (H_IPOLL , h_ipoll); - - QLIST_FOREACH(ics, &xics->ics, list) { -object_property_set_bool (OBJECT (ics), true,"realized" , &error); -if (error) { -error_propagate (errp, error); -return ; - } - } - -for (i =0 ; i < xics->nr_servers; i++) { -object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , - &error); -if (error) { -error_propagate (errp, error); -return ; - } - } }static void xics_spapr_initfn (Object *obj)
@@ -311,10 +284,9 @@ static void xics_spapr_initfn(Object *obj)static void xics_spapr_class_init (ObjectClass *oc,void *data) { -DeviceClass *dc =DEVICE_CLASS (oc);XICSStateClass *xsc =XICS_SPAPR_CLASS (oc); - dc->realize = xics_spapr_realize; + xsc->realize = xics_spapr_realize; xsc->set_nr_irqs = xics_spapr_set_nr_irqs; xsc->set_nr_servers = xics_spapr_set_nr_servers; }
include/hw/ppc/xics.h +1 -0
@@ -73,6 +73,7 @@ typedef struct ICSIRQState ICSIRQState;struct XICSStateClass {DeviceClass parent_class; +void (*realize)(DeviceState *dev,Error **errp);void (*cpu_setup)(XICSState *icp,PowerPCCPU *cpu);void (*set_nr_irqs)(XICSState *icp,uint32_t nr_irqs,Error **errp);void (*set_nr_servers)(XICSState *icp,uint32_t nr_servers,Error **errp);
Signature · 1 line
2.7.4
PATCH v6 4/10 ppc/xics: add a 'set_nr_servers' handler to the xics_common class
In reply to Cédric Le GoaterIt also makes the xics_common class usable as a standalone class. This will be useful for the PowerNV machine which only needs a simple container XICS object at the machine level.
It also cleans up a little more the xics_spapr class and we should soon be able to remove it. The 'set_nr_irqs' is still in the way.
--- hw/intc/xics.c | 8 ++++++++ hw/intc/xics_spapr.c | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-)
hw/intc/xics.c +8 -0
@@ -219,6 +219,12 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers, } } +static void xics_common_set_nr_servers (XICSState *xics,uint32_t nr_servers, +Error **errp) +{ +xics_set_nr_servers (xics, nr_servers,TYPE_ICP , errp); +} +static void xics_prop_get_nr_servers (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)
@@ -305,10 +311,12 @@ static void xics_common_class_init(ObjectClass *oc, void *data) {DeviceClass *dc =DEVICE_CLASS (oc);InterruptStatsProviderClass *ic =INTERRUPT_STATS_PROVIDER_CLASS (oc); +XICSStateClass *xsc =XICS_COMMON_CLASS (oc); dc->realize = xics_common_realize; dc->reset = xics_common_reset; ic->print_info = xics_common_pic_print_info; + xsc->set_nr_servers = xics_common_set_nr_servers; }static const TypeInfo xics_common_info = {
hw/intc/xics_spapr.c +0 -7
@@ -251,12 +251,6 @@ static void xics_spapr_set_nr_irqs(XICSState *xics, uint32_t nr_irqs, } } -static void xics_spapr_set_nr_servers (XICSState *xics,uint32_t nr_servers, -Error **errp) -{ -xics_set_nr_servers (xics, nr_servers,TYPE_ICP , errp); -} -static void xics_spapr_realize (DeviceState *dev,Error **errp) {/* Registration of global state belongs into realize */
@@ -288,7 +282,6 @@ static void xics_spapr_class_init(ObjectClass *oc, void *data) xsc->realize = xics_spapr_realize; xsc->set_nr_irqs = xics_spapr_set_nr_irqs; - xsc->set_nr_servers = xics_spapr_set_nr_servers; }static const TypeInfo xics_spapr_info = {
Signature · 1 line
2.7.4
PATCH v6 5/10 ppc/pnv: add a XICS object to the PowerNV machine
In reply to Cédric Le GoaterNothing more than a simple container object for the ICP and ICS. ICPs are still created by the XICS object for the moment.
---
David,
Please note the qdev_set_parent_bus(). That is how the reset should be handled. I had done that before for the Aspeed SoC machine but I had forgotten ...
hw/ppc/pnv.c | 10 ++++++++++ include/hw/ppc/pnv.h | 3 +++ 2 files changed, 13 insertions(+)
hw/ppc/pnv.c +10 -0
@@ -411,6 +411,16 @@ static void ppc_powernv_init(MachineState *machine) } } +/* Create XICS which holds all the ICPs for each thread */ +object_initialize (&pnv->xics,sizeof (pnv->xics),TYPE_XICS_COMMON ); +object_property_add_child (OBJECT (machine),"xics" ,OBJECT (&pnv->xics), + &error_fatal); +qdev_set_parent_bus (DEVICE (&pnv->xics),sysbus_get_default ()); +object_property_set_int (OBJECT (&pnv->xics), smp_cores * smp_threads, +"nr_servers" , &error_fatal); +object_property_set_bool (OBJECT (&pnv->xics), true,"realized" , + &error_fatal); +/* We need some cpu model to instantiate the PnvChip class */ if (machine->cpu_model ==NULL ) { machine->cpu_model ="POWER8" ;
include/hw/ppc/pnv.h +3 -0
@@ -22,6 +22,7 @@#include "hw/boards.h" #include "hw/sysbus.h" #include "hw/ppc/pnv_lpc.h" +#include "hw/ppc/xics.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -113,6 +114,8 @@ typedef struct PnvMachineState {PnvChip **chips;ISABus *isa_bus; + +XICSState xics; } PnvMachineState;#define PNV_FDT_ADDR 0x01000000
Signature · 1 line
2.7.4
PATCH v6 6/10 ppc/pnv: add MMIO regions for ICPs
In reply to Cédric Le GoaterThis provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
Each chip of a PowerNV machine has a global container MMIO region for all ICPs. Each thread of the chip has its own ICP MMIO subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry).
The regions also provide a mean to link with the ICPState to a CPU.
---
Changes since v5:
- moved the ICP container region to PnvChip
- moved the ICP subregions to PnvCore
- removed XICSNative
- renamed patch
Changes since v4:
- replaced the pir_table by memory subregions using an ICP.
- removed the find_icp() and cpu_setup() handlers which became useless with the memory regions.
- removed the superfluous inits done in xics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.
hw/ppc/pnv.c | 16 ++++++ hw/ppc/pnv_core.c | 140 +++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/pnv.h | 20 +++++++ include/hw/ppc/pnv_core.h | 2 + include/hw/ppc/xics.h | 5 ++ 5 files changed, 182 insertions(+), 1 deletion(-)
hw/ppc/pnv.c +16 -0
@@ -645,6 +645,15 @@ static void pnv_chip_init(Object *obj)object_property_add_child (obj,"lpc" ,OBJECT (&chip->lpc),NULL ); } +static void pnv_chip_icp_realize (PnvChip *chip,Error **errp) +{ +char *name; + + name =g_strdup_printf ("icp-%x" , chip->chip_id); +memory_region_init (&chip->icp_mmio,OBJECT (chip), name,PNV_ICP_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (chip), &chip->icp_mmio); +} +static void pnv_chip_realize (DeviceState *dev,Error **errp) {PnvChip *chip =PNV_CHIP (dev);
@@ -667,6 +676,13 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) }sysbus_mmio_map (SYS_BUS_DEVICE (chip),0 ,PNV_XSCOM_BASE (chip)); +/* Interrupt Controller */ +pnv_chip_icp_realize (chip, &error); +if (error) { +error_propagate (errp, error); +return ; + } +/* Cores */ pnv_chip_core_sanitize (chip, &error);if (error) {
hw/ppc/pnv_core.c +139 -1
165 lines not on this page · raw message
include/hw/ppc/pnv.h +20 -0
@@ -55,6 +55,7 @@ typedef struct PnvChip {MemoryRegion xscom_mmio;MemoryRegion xscom;AddressSpace xscom_as; +MemoryRegion icp_mmio;PnvLpcController lpc; } PnvChip;
@@ -128,4 +129,23 @@ typedef struct PnvMachineState {#define PNV_XSCOM_BASE (chip) \ (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) +/* +* XSCOM 0x20109CA defines the ICP BAR: +* +* 0:29 : bits 14 to 43 of address to define 1 MB region. +* 30 : 1 to enable ICP to receive loads/stores against its BAR region +* 31:63 : Constant 0 +* +* Usually defined as : +* +* 0xffffe00200000000 -> 0x0003ffff80000000 +* 0xffffe00600000000 -> 0x0003ffff80100000 +* 0xffffe02200000000 -> 0x0003ffff80800000 +* 0xffffe02600000000 -> 0x0003ffff80900000 +* +* TODO: make a macro using the chip hw id +*/ +#define PNV_ICP_BASE (chip) 0x0003ffff80000000ull +#define PNV_ICP_SIZE 0x0000000000100000ull +#endif /* _PPC_PNV_H */
include/hw/ppc/pnv_core.h +2 -0
@@ -38,6 +38,8 @@ typedef struct PnvCore {uint32_t pir;MemoryRegion xscom_regs; + +MemoryRegion *icp_mmios; } PnvCore; typedef struct PnvCoreClass {
include/hw/ppc/xics.h +5 -0
@@ -120,6 +120,11 @@ struct ICPState {bool cap_irq_xics_enabled;XICSState *xics; + +/* +* for XICSNative (not used by Linux). +*/ +uint32_t links[3 ]; };#define TYPE_ICS_BASE "ics-base"
Signature · 1 line
2.7.4
PATCH v6 7/10 ppc/pnv: link the CPUs to the machine XICS
In reply to Cédric Le GoaterThis also maps all the chip container ICP region and the threads ICP subregions. The device tree is populated accordingly.
---
Changes since v5:
- reworked to fit new model
Changes since v4:
- changed the calculation of the number of ICPs to use smp_threads
- added the mapping of the ICP subregions per thread
hw/ppc/pnv.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 12 ++++++++---- 2 files changed, 63 insertions(+), 4 deletions(-)
hw/ppc/pnv.c +55 -0
@@ -33,6 +33,7 @@#include "qemu/cutils.h" #include "qapi/visitor.h" +#include "hw/ppc/xics.h" #include "hw/ppc/pnv_xscom.h" #include "hw/isa/isa.h"
@@ -214,6 +215,47 @@ static void powernv_create_core_node(PnvChip *chip, PnvCore *pc, void *fdt) servers_prop, sizeof(servers_prop)))); } +static void powernv_populate_icp (PnvChip *chip,void *fdt,int offset, +uint32_t pir,uint32_t count) +{ +uint64_t addr; +char *name; +const char compat[] ="IBM,power8-icp\0IBM,ppc-xicp" ; +uint32_t irange[2 ], i, rsize; +uint64_t *reg; + +/* +* TODO: add multichip ICP BAR +*/ + addr =PNV_ICP_BASE (chip) | (pir <<12 ); + + irange[0 ] =cpu_to_be32 (pir); + irange[1 ] =cpu_to_be32 (count); + + rsize =sizeof (uint64_t ) *2 * count; + reg =g_malloc (rsize); +for (i =0 ; i < count; i++) { + reg[i *2 ] =cpu_to_be64 (addr | ((pir + i) *0x1000 )); + reg[i *2 +1 ] =cpu_to_be64 (0x1000 ); + } + + name =g_strdup_printf ("interrupt-controller@%" PRIX64 , addr); + offset =fdt_add_subnode (fdt, offset, name); +_FDT (offset); +g_free (name); + +_FDT ((fdt_setprop (fdt, offset,"compatible" , compat,sizeof (compat)))); +_FDT ((fdt_setprop (fdt, offset,"reg" , reg, rsize))); +_FDT ((fdt_setprop_string (fdt, offset,"device_type" , +"PowerPC-External-Interrupt-Presentation" ))); +_FDT ((fdt_setprop (fdt, offset,"interrupt-controller" ,NULL ,0 ))); +_FDT ((fdt_setprop (fdt, offset,"ibm,interrupt-server-ranges" , + irange,sizeof (irange)))); +_FDT ((fdt_setprop_cell (fdt, offset,"#interrupt-cells" ,1 ))); +_FDT ((fdt_setprop_cell (fdt, offset,"#address-cells" ,0 ))); +g_free (reg); +} +static void powernv_populate_chip (PnvChip *chip,void *fdt) {PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip);
@@ -227,6 +269,10 @@ static void powernv_populate_chip(PnvChip *chip, void *fdt)PnvCore *pnv_core =PNV_CORE (chip->cores + i * typesize);powernv_create_core_node (chip, pnv_core, fdt); + +/* Interrupt presentation controllers (ICP). One per thread. */ +powernv_populate_icp (chip, fdt,0 , pnv_core->pir, +CPU_CORE (pnv_core)->nr_threads); }if (chip->ram_size) {
@@ -682,6 +728,7 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)error_propagate (errp, error);return ; } +sysbus_mmio_map (SYS_BUS_DEVICE (chip),1 ,PNV_ICP_BASE (chip));/* Cores */ pnv_chip_core_sanitize (chip, &error);
@@ -696,6 +743,7 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) && (i < chip->nr_cores); core_hwid++) {char core_name[32 ];void *pnv_core = chip->cores + i * typesize; +int j;if (!(chip->cores_mask & (1ull << core_hwid))) {continue ;
@@ -719,6 +767,13 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)/* Each core has an XSCOM MMIO region */ pnv_xscom_add_subregion (chip,PNV_XSCOM_EX_CORE_BASE (core_hwid), &PNV_CORE (pnv_core)->xscom_regs); + +/* Each thread has a ICP MMIO region */ +for (j =0 ; j <CPU_CORE (pnv_core)->nr_threads; j++) { +memory_region_add_subregion (&chip->icp_mmio, + (pcc->core_pir (chip, core_hwid) + j) <<12 , + &PNV_CORE (pnv_core)->icp_mmios[j]); + } i++; }g_free (typename);
hw/ppc/pnv_core.c +8 -4
@@ -25,6 +25,7 @@#include "hw/ppc/pnv.h" #include "hw/ppc/pnv_core.h" #include "hw/ppc/pnv_xscom.h" +#include "hw/ppc/xics.h" static uint64_t pnv_core_icp_read (void *opaque,hwaddr addr,unsigned width) {
@@ -165,7 +166,7 @@ static void powernv_cpu_reset(void *opaque) env->msr |=MSR_HVB ;/* Hypervisor mode */ } -static void powernv_cpu_init (PowerPCCPU *cpu,Error **errp) +static void powernv_cpu_init (PowerPCCPU *cpu,XICSState *xics,Error **errp) {CPUPPCState *env = &cpu->env;int core_pir;
@@ -185,6 +186,9 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error **errp)cpu_ppc_tb_init (env,PNV_TIMEBASE_FREQ );qemu_register_reset (powernv_cpu_reset, cpu); + +/* xics_cpu_setup() assigns the CPU to the ICPState */ +xics_cpu_setup (xics, cpu); }/*
@@ -232,7 +236,7 @@ static const MemoryRegionOps pnv_core_xscom_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void pnv_core_realize_child (Object *child,Error **errp) +static void pnv_core_realize_child (Object *child,XICSState *xics,Error **errp) {Error *local_err =NULL ;CPUState *cs =CPU (child);
@@ -244,7 +248,7 @@ static void pnv_core_realize_child(Object *child, Error **errp)return ; } -powernv_cpu_init (cpu, &local_err); +powernv_cpu_init (cpu, xics, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
@@ -291,7 +295,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)for (j =0 ; j < cc->nr_threads; j++) { obj = pc->threads + j * size; -pnv_core_realize_child (obj, &local_err); +pnv_core_realize_child (obj, &pnv->xics, &local_err);if (local_err) { goto err; }
Signature · 1 line
2.7.4
PATCH v6 8/10 ppc/pnv: Add cut down PSI bridge model and hookup external interrupt
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
The PSI (Processor Service Interface) is one of the engines of the "Bridge" unit which connects the different interfaces to the Power Processor.
This adds just enough of the PSI bridge to handle various on-chip and the one external interrupt. The rest of PSI has to do with the link to the IBM FSP service processor which we don't plan to emulate (not used on OpenPower machines).
[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model
- reworked set_xive and worked around a skiboot bug
- removed the 'psi_mmio_to_xscom' mapping array ]
---
Changes since v5:
- reworked to fit new XICS model
- removed the 'psi_mmio_to_xscom' mapping array but kept the memory region handlers because they have different privileges. XSCOM can map/unmap the MMIO region.
Changes since v4:
- used the helpers for the XSCOM region
- introduced pnv->cpld_irqstate to remove a static
- reworked pnv_psi_set_xivr() to use xics_get_cpu_index_by_pir(). This is similar to rtas_set_xive but skiboot does a first initialization with empty servers so we need to check for that case.
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 33 ++- hw/ppc/pnv_psi.c | 574 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 + include/hw/ppc/pnv_psi.h | 61 +++++ include/hw/ppc/pnv_xscom.h | 3 + 6 files changed, 673 insertions(+), 7 deletions(-) create mode 100644 hw/ppc/pnv_psi.c create mode 100644 include/hw/ppc/pnv_psi.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +27 -6
@@ -354,15 +354,22 @@ static void ppc_powernv_reset(void)* have a CPLD that will collect the SerIRQ and shoot them as a * single level interrupt to the P8 chip. So let's setup a hook * for doing just that. -* -* Note: The actual interrupt input isn't emulated yet, this will -* come with the PSI bridge model. */ static void pnv_lpc_isa_irq_handler_cpld (void *opaque,int n,int level) { -/* We don't yet emulate the PSI bridge which provides the external -* interrupt, so just drop interrupts on the floor -*/ +PnvMachineState *pnv =POWERNV_MACHINE (qdev_get_machine ()); +uint32_t old_state = pnv->cpld_irqstate; +PnvChip *chip = opaque; + +if (level) { + pnv->cpld_irqstate |=1u << n; + }else { + pnv->cpld_irqstate &= ~(1u << n); + } +if (pnv->cpld_irqstate != old_state) { +pnv_psi_irq_set (&chip->psi,PSIHB_IRQ_EXTERNAL , + pnv->cpld_irqstate !=0 ); + } }static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level)
@@ -689,6 +696,9 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->lpc,sizeof (chip->lpc),TYPE_PNV_LPC );object_property_add_child (obj,"lpc" ,OBJECT (&chip->lpc),NULL ); + +object_initialize (&chip->psi,sizeof (chip->psi),TYPE_PNV_PSI ); +object_property_add_child (obj,"psi" ,OBJECT (&chip->psi),NULL ); }static void pnv_chip_icp_realize (PnvChip *chip,Error **errp)
@@ -708,6 +718,8 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)char *typename =pnv_core_typename (pcc->cpu_model);size_t typesize =object_type_get_instance_size (typename);int i, core_hwid; +MachineState *machine =MACHINE (qdev_get_machine ()); +PnvMachineState *pnv =POWERNV_MACHINE (machine);if (!object_class_by_name (typename)) {error_setg (errp,"Unable to find PowerNV CPU Core '%s'" , typename);
@@ -778,6 +790,15 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) }g_free (typename); + +/* Processor Service Interface (PSI) Host Bridge */ +object_property_set_bool (OBJECT (&chip->psi), true,"realized" , + &error_fatal); +pnv_xscom_add_subregion (chip,PNV_XSCOM_PSI_BASE , &chip->psi.xscom_regs); + +/* link in the PSI ICS */ +xics_insert_ics (&pnv->xics, &chip->psi.ics); +/* Create LPC controller */ object_property_set_bool (OBJECT (&chip->lpc), true,"realized" , &error_fatal);
hw/ppc/pnv_psi.c new file +574 -0
574 lines not on this page · raw message
include/hw/ppc/pnv.h +7 -0
@@ -23,6 +23,7 @@#include "hw/sysbus.h" #include "hw/ppc/pnv_lpc.h" #include "hw/ppc/xics.h" +#include "hw/ppc/pnv_psi.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -58,6 +59,7 @@ typedef struct PnvChip {MemoryRegion icp_mmio;PnvLpcController lpc; +PnvPsiController psi; } PnvChip; typedef struct PnvChipClass {
@@ -117,6 +119,7 @@ typedef struct PnvMachineState {ISABus *isa_bus;XICSState xics; +uint32_t cpld_irqstate; } PnvMachineState;#define PNV_FDT_ADDR 0x01000000
@@ -148,4 +151,8 @@ typedef struct PnvMachineState {#define PNV_ICP_BASE (chip) 0x0003ffff80000000ull#define PNV_ICP_SIZE 0x0000000000100000ull +#define PNV_PSIHB_BAR 0x0003fffe80000000ull +#define PNV_PSIHB_BAR_SIZE 0x0000000000100000ull + +#endif /* _PPC_PNV_H */
include/hw/ppc/pnv_psi.h new file +61 -0
61 lines not on this page · raw message
include/hw/ppc/pnv_xscom.h +3 -0
@@ -61,6 +61,9 @@ typedef struct PnvXScomInterfaceClass {#define PNV_XSCOM_LPC_BASE 0xb0020#define PNV_XSCOM_LPC_SIZE 0x4 +#define PNV_XSCOM_PSI_BASE 0x2010900 +#define PNV_XSCOM_PSI_SIZE 0x20 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 1 line
2.7.4
PATCH v6 9/10 ppc/pnv: Add OCC model stub with interrupt support
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
The OCC is an on-chip microcontroller based on a ppc405 core used for various power management tasks. It comes with a pile of additional hardware sitting on the PIB (aka XSCOM bus). At this point we don't emulate it (nor plan to do so). However there is one facility which is provided by the surrounding hardware that we do need, which is the interrupt generation facility. OPAL uses it to send itself interrupts under some circumstances and there are other uses around the corner.
So this implement just enough to support this.
[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model ]
---
Changes since v4:
- used the helpers for the XSCOM region
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 10 ++++ hw/ppc/pnv_occ.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_occ.h | 38 +++++++++++++ include/hw/ppc/pnv_xscom.h | 3 + 6 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_occ.c create mode 100644 include/hw/ppc/pnv_occ.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +10 -0
@@ -699,6 +699,11 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->psi,sizeof (chip->psi),TYPE_PNV_PSI );object_property_add_child (obj,"psi" ,OBJECT (&chip->psi),NULL ); + +object_initialize (&chip->occ,sizeof (chip->occ),TYPE_PNV_OCC ); +object_property_add_child (obj,"occ" ,OBJECT (&chip->occ),NULL ); +object_property_add_const_link (OBJECT (&chip->occ),"psi" , +OBJECT (&chip->psi), &error_abort); }static void pnv_chip_icp_realize (PnvChip *chip,Error **errp)
@@ -803,6 +808,11 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_bool (OBJECT (&chip->lpc), true,"realized" , &error_fatal);pnv_xscom_add_subregion (chip,PNV_XSCOM_LPC_BASE , &chip->lpc.xscom_regs); + +/* Create the simplified OCC model */ +object_property_set_bool (OBJECT (&chip->occ), true,"realized" , + &error_fatal); +pnv_xscom_add_subregion (chip,PNV_XSCOM_OCC_BASE , &chip->occ.xscom_regs); }static Property pnv_chip_properties[] = {
hw/ppc/pnv_occ.c new file +136 -0
136 lines not on this page · raw message
include/hw/ppc/pnv.h +2 -0
@@ -24,6 +24,7 @@#include "hw/ppc/pnv_lpc.h" #include "hw/ppc/xics.h" #include "hw/ppc/pnv_psi.h" +#include "hw/ppc/pnv_occ.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -60,6 +61,7 @@ typedef struct PnvChip {PnvLpcController lpc;PnvPsiController psi; +PnvOCC occ; } PnvChip; typedef struct PnvChipClass {
include/hw/ppc/pnv_occ.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* QEMU PowerNV Emulation of a few OCC related registers +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _PPC_PNV_OCC_H +#define _PPC_PNV_OCC_H + +#define TYPE_PNV_OCC "pnv-occ" +#define PNV_OCC (obj) OBJECT_CHECK(PnvOCC, (obj), TYPE_PNV_OCC) + +typedef struct PnvPsiController PnvPsiController ; + +typedef struct PnvOCC { +DeviceState xd; + +/* OCC Misc interrupt */ +uint64_t occmisc; + +PnvPsiController *psi; + +MemoryRegion xscom_regs; +}PnvOCC ; + +#endif /* _PPC_PNV_OCC_H */
include/hw/ppc/pnv_xscom.h +3 -0
@@ -64,6 +64,9 @@ typedef struct PnvXScomInterfaceClass {#define PNV_XSCOM_PSI_BASE 0x2010900#define PNV_XSCOM_PSI_SIZE 0x20 +#define PNV_XSCOM_OCC_BASE 0x0066000 +#define PNV_XSCOM_OCC_SIZE 0x6000 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 1 line
2.7.4
PATCH v6 10/10 ppc/pnv: Add Naples chip support for LPC interrupts
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
It adds the Naples chip which supports proper LPC interrupts via the LPC controller rather than via an external CPLD.
[clg: - updated for qemu-2.7
- ported on latest PowerNV patchset (v3) ]
---
Changes since v4:
- remove test on ISA_NUM_IRQS
hw/ppc/pnv.c | 15 ++++++++++++++- hw/ppc/pnv_lpc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/pnv_lpc.h | 9 +++++++++ 3 files changed, 68 insertions(+), 3 deletions(-)
hw/ppc/pnv.c +14 -1
@@ -374,7 +374,14 @@ static void pnv_lpc_isa_irq_handler_cpld(void *opaque, int n, int level)static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level) { -/* XXX TODO */ +PnvChip *chip = opaque; +PnvLpcController *lpc = &chip->lpc; + +/* The Naples HW latches the 1 levels, clearing is done by SW */ +if (level) { + lpc->lpc_hc_irqstat |=LPC_HC_IRQ_SERIRQ0 >> n; +pnv_lpc_eval_irqs (lpc); + } }static ISABus *pnv_isa_create (PnvChip *chip)
@@ -704,6 +711,12 @@ static void pnv_chip_init(Object *obj)object_property_add_child (obj,"occ" ,OBJECT (&chip->occ),NULL );object_property_add_const_link (OBJECT (&chip->occ),"psi" ,OBJECT (&chip->psi), &error_abort); + +/* +* The LPC controller needs PSI to generate interrupts +*/ +object_property_add_const_link (OBJECT (&chip->lpc),"psi" , +OBJECT (&chip->psi), &error_abort); }static void pnv_chip_icp_realize (PnvChip *chip,Error **errp)
hw/ppc/pnv_lpc.c +45 -2
89 lines not on this page · raw message
include/hw/ppc/pnv_lpc.h +9 -0
@@ -23,6 +23,8 @@#define PNV_LPC (obj) \ OBJECT_CHECK(PnvLpcController, (obj), TYPE_PNV_LPC) +typedef struct PnvPsiController PnvPsiController ; + typedef struct PnvLpcController { DeviceState parent;
@@ -62,6 +64,13 @@ typedef struct PnvLpcController {/* XSCOM registers */ MemoryRegion xscom_regs; + +/* PSI to generate interrupts */ + PnvPsiController *psi; } PnvLpcController; +#define LPC_HC_IRQ_SERIRQ0 0x80000000/* all bits down to ... */ + +void pnv_lpc_eval_irqs (PnvLpcController *lpc); +#endif /* _PPC_PNV_LPC_H */
Signature · 1 line
2.7.4