spapr: Guest exploitation of the XIVE interrupt controller (POWER9)
cover spapr: Guest exploitation of the XIVE interrupt controller (POWER9)
Hello,
On a POWER9 sPAPR machine, the Client Architecture Support (CAS) negotiation process determines whether the guest operates with an interrupt controller using the XICS legacy model, as found on POWER8, or in XIVE exploitation mode, the newer POWER9 interrupt model. XIVE is a complex interrupt controller introducing a large number of new features, for virtualization in particular. Here is a brief overview for the sPAPR platform which only requires a small subset of these functions.
XIVE uses a set of internal tables to redirect exceptions from interrupt sources to the CPU. Each interrupt source has a 2-bit state machine, the Event State Buffer (ESB), that allows events to be triggered. If the event is let through, XIVE looks up in the Interrupt Virtualization Entry (IVE) table for the Event Queue Descriptor defined for the source. Each Event Queue Descriptor defines a notification path to a CPU and an in-memory queue in which will be recorded an event identifier for the OS to pull.
This patchset is the first non-RFC proposal to add XIVE support in a POWER9 sPAPR machine. It should addressed the comments made on the previous RFCs, the most important points being :
- use a single IRQ allocator for the machine,
- remove any relation with the XICS model,
- get rid of 'nr_servers' under the XIVE object.
The high level ideas of the current design are :
- move all IRQ allocation code under the machine to make sure that the allocated IRQ numbers are kept in sync between XICS and XIVE. This is necessary for the devices which allocate IRQs and populate the device tree before the machine is even started.
- introduce a persistent XIVE object under the sPAPR machine and let the CAS negotiation process decide whether it should be used or not. Use the 'ov5_cas' attribute for this purpose.
- introduce a persistent XIVE interrupt presenter under the sPAPR core and switch ICP after CAS. Each core has now two ICPs, one active through the 'intc' pointer and another one among its children ready to be used if the guest requires it.
- move the XIVE EQs under the cores to simplify the XIVE model
- allocate the CPU IPIs at the beginning of the IRQ number space to be compatible with XICS (which starts at 4096) and also to simplify the model. This means that the XIVE model covers the whole IRQ number space. There are no offset like in XICS splitting the IRQ number space.
The patchset first begins with cleanups and code movements in the XICS model and in the sPAPR machine to prepare ground for the integration of the XIVE model. Some could be merged directly.
It continues with patches introducing new models or XIVE :
- sPAPRXive holding the internal tables and the MMIO regions used by the XIVE controller.
- sPAPRXiveICP object acting the XIVE interrupt presenter
and describing the notification process and the interrupt delivery to the CPU.
It finishes with the integration of sPAPRXive object under the sPAPR machine, the introducion of the new XIVE hcalls, the new device tree layout, and the necessary adjustments to support the CAS negotiation.
Migration is addressed, CPU hotplug, and support for older machines and QEMU versions also.
Code is here:
https://github.com/legoater/qemu/commits/xive
Caveats :
- KVM support : not addressed yet
The guest needs to be run with kernel_irqchip=off on a POWER9 system.
- LSI : hardly tested.
Thanks,
C.
Tests :
- make check on each patch
- migration :
qemu-2.12 (pseries-2.12) <-> qemu-2.12 (pseries-2.12)
qemu-2.12 (pseries-2.10) <-> qemu-2.12 (pseries-2.10)
qemu-2.10 (pseries-2.10) <-> qemu-2.12 (pseries-2.10)Cédric Le Goater (25):
ppc/xics: introduce an icp_create() helper
ppc/xics: assign of the CPU 'intc' pointer under the core
spapr: introduce a spapr_icp_create() helper
spapr: move the IRQ allocation routines under the machine
spapr: introduce a spapr_irq_set() helper
spapr: introduce a spapr_irq_get_qirq() helper
migration: add VMSTATE_STRUCT_VARRAY_UINT32_ALLOC
spapr: introduce a skeleton for the XIVE interrupt controller
spapr: introduce handlers for XIVE interrupt sources
spapr: add MMIO handlers for the XIVE interrupt sources
spapr: describe the XIVE interrupt source flags
spapr: introduce a XIVE interrupt presenter model
spapr: introduce the XIVE Event Queues
spapr: push the XIVE EQ data in OS event queue
spapr: notify the CPU when the XIVE interrupt priority is more
privileged
spapr: add support for the SET_OS_PENDING command (XIVE)
spapr: add a sPAPRXive object to the machine
spapr: allocate IRQ numbers for the XIVE interrupt mode
spapr: add hcalls support for the XIVE interrupt mode
spapr: add device tree support for the XIVE interrupt mode
spapr: introduce a helper to map the XIVE memory regions
spapr: add XIVE support to spapr_irq_get_qirq()
spapr: toggle the ICP depending on the selected interrupt mode
spapr: add support to dump XIVE information
spapr: advertise XIVE exploitation mode in CAS
default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 964 ++++++++++++++++++++++++++++++++++++++ hw/intc/spapr_xive_hcall.c | 949 +++++++++++++++++++++++++++++++++++++ hw/intc/trace-events | 4 - hw/intc/xics.c | 35 +- hw/intc/xics_spapr.c | 114 ----- hw/intc/xive-internal.h | 189 ++++++++ hw/ppc/pnv_core.c | 10 +- hw/ppc/spapr.c | 286 ++++++++++- hw/ppc/spapr_cpu_core.c | 44 +- hw/ppc/spapr_events.c | 16 +- hw/ppc/spapr_hcall.c | 6 + hw/ppc/spapr_pci.c | 10 +- hw/ppc/spapr_vio.c | 2 +- hw/ppc/trace-events | 4 + include/hw/pci-host/spapr.h | 2 +- include/hw/ppc/spapr.h | 27 +- include/hw/ppc/spapr_cpu_core.h | 1 + include/hw/ppc/spapr_vio.h | 2 +- include/hw/ppc/spapr_xive.h | 89 ++++ include/hw/ppc/xics.h | 8 +- include/migration/vmstate.h | 10 + 23 files changed, 2592 insertions(+), 182 deletions(-) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/spapr_xive_hcall.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.h
Signature · 1 line
2.13.6
PATCH 1/25 ppc/xics: introduce an icp_create() helper
The sPAPR and the PowerNV core objects create the interrupt presenter object of the CPUs in a very similar way. Let's provide a common routine in which we use the presenter 'type' as a child identifier.
--- hw/intc/xics.c | 22 ++++++++++++++++++++++ hw/ppc/pnv_core.c | 10 +--------- hw/ppc/spapr_cpu_core.c | 13 ++----------- include/hw/ppc/xics.h | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-)
hw/intc/xics.c +22 -0
@@ -384,6 +384,28 @@ static const TypeInfo icp_info = { .class_size = sizeof(ICPStateClass), }; +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi,Error **errp) +{ +Object *child =OBJECT (cs); +Error *local_err =NULL ; +Object *obj; + + obj =object_new (type); +object_property_add_child (child, type, obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), + &error_abort); +object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); + obj =NULL ; + } + +return obj; +} +/* * ICS: Source layer */
hw/ppc/pnv_core.c +1 -9
@@ -126,7 +126,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {
@@ -134,13 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (child,"icp" , obj,NULL ); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
@@ -148,7 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)powernv_cpu_init (cpu, &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }
hw/ppc/spapr_cpu_core.c +2 -11
@@ -111,7 +111,6 @@ static void spapr_cpu_core_realize_child(Object *child,Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {
@@ -123,21 +122,13 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - obj =object_new (spapr->icp_type); -object_property_add_child (child,"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (spapr), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { - goto free_icp; + goto error; }return ; -free_icp: -object_unparent (obj); error:error_propagate (errp, local_err); }
include/hw/ppc/xics.h +3 -0
@@ -212,4 +212,7 @@ typedef struct sPAPRMachineState sPAPRMachineState;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp);void xics_spapr_init (sPAPRMachineState *spapr); +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi, +Error **errp); +#endif /* XICS_H */
Signature · 1 line
2.13.6
PATCH 2/25 ppc/xics: assign of the CPU 'intc' pointer under the core
In reply to Cédric Le GoaterThe 'intc' pointer of the CPU references the interrupt presenter in the XICS interrupt mode. When the XIVE interrupt mode is available and activated, the machine will need to reassign this pointer to reflect the change.
Moving this assignment under the realize routine of the CPU will ease the process when the interrupt mode is toggled.
--- hw/intc/xics.c | 1 - hw/ppc/pnv_core.c | 2 +- hw/ppc/spapr_cpu_core.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)
hw/intc/xics.c +0 -1
@@ -334,7 +334,6 @@ static void icp_realize(DeviceState *dev, Error **errp) } cpu =POWERPC_CPU (obj); - cpu->intc =OBJECT (icp); icp->cs =CPU (obj); env = &cpu->env;
hw/ppc/pnv_core.c +1 -1
@@ -133,7 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } -icp_create (cs,TYPE_PNV_ICP , xi, &local_err); + cpu->intc =icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
hw/ppc/spapr_cpu_core.c +1 -1
@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } -icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { goto error; }
Signature · 1 line
2.13.6
PATCH 3/25 spapr: introduce a spapr_icp_create() helper
In reply to Cédric Le GoaterOn sPAPR, the creation of the interrupt presenter depends on some of the machine attributes. When the XIVE interrupt mode is available, this will get more complex. So provide a machine-level helper to isolate the process and hide the details to the sPAPR core realize function.
--- hw/ppc/spapr.c | 14 ++++++++++++++ hw/ppc/spapr_cpu_core.c | 2 +- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +14 -0
@@ -3556,6 +3556,20 @@ static ICPState *spapr_icp_get(XICSFabric *xi, int vcpu_id)return cpu ?ICP (cpu->intc) :NULL ; } +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); +if (local_err) { +error_propagate (errp, local_err); +return NULL ; + } + +return obj; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {
hw/ppc/spapr_cpu_core.c +1 -1
@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =spapr_icp_create (spapr, cs, &local_err);if (local_err) { goto error; }
include/hw/ppc/spapr.h +2 -0
@@ -707,4 +707,6 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);int spapr_vcpu_id (PowerPCCPU *cpu);PowerPCCPU *spapr_find_cpu (int vcpu_id); +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +#endif /* HW_SPAPR_H */
Signature · 1 line
2.13.6
PATCH 4/25 spapr: move the IRQ allocation routines under the machine
In reply to Cédric Le GoaterAlso change the prototype to use a sPAPRMachineState and prefix them with spapr_irq_. It will let us synchronise the IRQ allocation with the XIVE interrupt mode when available.
--- hw/intc/trace-events | 4 -- hw/intc/xics_spapr.c | 114 ------------------------------------------------- hw/ppc/spapr.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 4 +- hw/ppc/spapr_pci.c | 8 ++-- hw/ppc/spapr_vio.c | 2 +- hw/ppc/trace-events | 4 ++ include/hw/ppc/spapr.h | 6 +++ include/hw/ppc/xics.h | 4 -- 9 files changed, 131 insertions(+), 129 deletions(-)
hw/intc/trace-events +0 -4
@@ -64,10 +64,6 @@ xics_ics_simple_set_irq_lsi(int srcno, int nr) "set_irq_lsi: srcno %d [irq 0x%x] xics_ics_simple_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_xive: irq 0x%x [src %d] server 0x%x prio 0x%x" xics_ics_simple_reject(int nr, int srcno) "reject irq 0x%x [src %d]" xics_ics_simple_eoi(int nr) "ics_eoi: irq 0x%x" -xics_alloc(int irq) "irq %d" -xics_alloc_block(int first, int num, bool lsi, int align) "first irq %d, %d irqs, lsi=%d, alignnum %d" -xics_ics_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs" -xics_ics_free_warn(int src, int irq) "Source#%d, irq %d is already free" # hw/intc/s390_flic_kvm.c flic_create_device(int err) "flic: create device failed %d"
hw/intc/xics_spapr.c +0 -114
120 lines not on this page · raw message
hw/ppc/spapr.c +114 -0
120 lines not on this page · raw message
hw/ppc/spapr_events.c +2 -2
@@ -718,7 +718,7 @@ void spapr_events_init(sPAPRMachineState *spapr) spapr->event_sources =spapr_event_sources_new ();spapr_event_sources_register (spapr->event_sources,EVENT_CLASS_EPOW , -spapr_ics_alloc (spapr->ics,0 , false, +spapr_irq_alloc (spapr,0 , false, &error_fatal));/* NOTE: if machine supports modern/dedicated hotplug event source,
@@ -731,7 +731,7 @@ void spapr_events_init(sPAPRMachineState *spapr)*/ if (spapr->use_hotplug_event_source) {spapr_event_sources_register (spapr->event_sources,EVENT_CLASS_HOT_PLUG , -spapr_ics_alloc (spapr->ics,0 , false, +spapr_irq_alloc (spapr,0 , false, &error_fatal)); }
hw/ppc/spapr_pci.c +4 -4
@@ -314,7 +314,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,return ; } -spapr_ics_free (spapr->ics, msi->first_irq, msi->num); +spapr_irq_free (spapr, msi->first_irq, msi->num);if (msi_present (pdev)) {spapr_msi_setmsg (pdev,0 , false,0 ,0 ); }
@@ -352,7 +352,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr, }/* Allocate MSIs */ - irq =spapr_ics_alloc_block (spapr->ics, req_num, false, + irq =spapr_irq_alloc_block (spapr, req_num, false, ret_intr_type ==RTAS_TYPE_MSI , &err);if (err) { error_reportf_err(err, "Can't allocate MSIs for device %x: ",
@@ -363,7 +363,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,/* Release previous MSIs */ if (msi) { -spapr_ics_free (spapr->ics, msi->first_irq, msi->num); +spapr_irq_free (spapr, msi->first_irq, msi->num);g_hash_table_remove (phb->msi, &config_addr); }
@@ -1675,7 +1675,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)uint32_t irq;Error *local_err =NULL ; - irq =spapr_ics_alloc_block (spapr->ics,1 , true, false, &local_err); + irq =spapr_irq_alloc_block (spapr,1 , true, false, &local_err);if (local_err) {error_propagate (errp, local_err);error_prepend (errp,"can't allocate LSIs: " );
hw/ppc/spapr_vio.c +1 -1
@@ -454,7 +454,7 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp) dev->qdev.id = id; } - dev->irq =spapr_ics_alloc (spapr->ics, dev->irq, false, &local_err); + dev->irq =spapr_irq_alloc (spapr, dev->irq, false, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
hw/ppc/trace-events +4 -0
@@ -12,6 +12,10 @@ spapr_pci_msi_retry(unsigned config_addr, unsigned req_num, unsigned max_irqs) " # hw/ppc/spapr.c spapr_cas_failed(unsigned long n) "DT diff buffer is too small: %ld bytes" spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes" +spapr_irq_alloc(int irq) "irq %d" +spapr_irq_alloc_block(int first, int num, bool lsi, int align) "first irq %d, %d irqs, lsi=%d, alignnum %d" +spapr_irq_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs" +spapr_irq_free_warn(int src, int irq) "Source#%d, irq %d is already free" # hw/ppc/spapr_hcall.c spapr_cas_pvr_try(uint32_t pvr) "0x%x"
include/hw/ppc/spapr.h +6 -0
@@ -709,4 +709,10 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id);Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi, +Error **errp); +int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi, +bool align,Error **errp); +void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num); +#endif /* HW_SPAPR_H */
include/hw/ppc/xics.h +0 -4
@@ -181,10 +181,6 @@ typedef struct XICSFabricClass {#define XICS_IRQS_SPAPR 1024 -int spapr_ics_alloc (ICSState *ics,int irq_hint,bool lsi,Error **errp); -int spapr_ics_alloc_block (ICSState *ics,int num,bool lsi,bool align, -Error **errp); -void spapr_ics_free (ICSState *ics,int irq,int num);void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);
Signature · 1 line
2.13.6
PATCH 5/25 spapr: introduce a spapr_irq_set() helper
In reply to Cédric Le GoaterIt will make synchronisation easier with the XIVE interrupt mode when available. The 'irq' parameter refers to the global IRQ number space.
--- hw/ppc/spapr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +8 -3
@@ -3594,6 +3594,11 @@ static int ics_find_free_block(ICSState *ics, int num, int alignnum)return -1 ; } +static void spapr_irq_set (sPAPRMachineState *spapr,int irq,bool lsi) +{ +ics_set_irq_type (spapr->ics, irq - spapr->ics->offset, lsi); +} +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi,Error **errp) {
@@ -3618,7 +3623,7 @@ int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi, irq += ics->offset; } -ics_set_irq_type (ics, irq - ics->offset, lsi); +spapr_irq_set (spapr, irq, lsi);trace_spapr_irq_alloc (irq);return irq;
@@ -3657,10 +3662,10 @@ int spapr_irq_alloc_block(sPAPRMachineState *spapr, int num, bool lsi,return -1 ; } + first += ics->offset;for (i = first; i < first + num; ++i) { -ics_set_irq_type (ics, i, lsi); +spapr_irq_set (spapr, i, lsi); } - first += ics->offset;trace_spapr_irq_alloc_block (first, num, lsi, align);
Signature · 1 line
2.13.6
PATCH 7/25 migration: add VMSTATE_STRUCT_VARRAY_UINT32_ALLOC
In reply to Cédric Le Goater--- include/migration/vmstate.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/migration/vmstate.h +10 -0
@@ -560,6 +560,16 @@ extern const VMStateInfo vmstate_info_qtailq; .offset = vmstate_offset_pointer(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (_field, _state, _field_num, _version, _vmsd, _type) {\ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .vmsd = &(_vmsd), \ + .num_offset = vmstate_offset_value(_state, _field_num, uint32_t), \ + .size = sizeof(_type), \ + .flags = VMS_STRUCT|VMS_VARRAY_UINT32|VMS_ALLOC|VMS_POINTER, \ + .offset = vmstate_offset_pointer(_state, _field, _type), \ +} +#define VMSTATE_STATIC_BUFFER (_field, _state, _version, _test, _start, _size) { \ .name = (stringify(_field)), \ .version_id = (_version), \
Signature · 1 line
2.13.6
PATCH 6/25 spapr: introduce a spapr_irq_get_qirq() helper
In reply to Cédric Le Goaterxics_get_qirq() is only used by the sPAPR machine. Let's move it there and change its name to reflect its scope. It will be useful for XIVE support which will use its own set of qirqs.
--- hw/intc/xics.c | 12 ------------ hw/ppc/spapr.c | 11 +++++++++++ hw/ppc/spapr_events.c | 12 +++++------- hw/ppc/spapr_pci.c | 2 +- include/hw/pci-host/spapr.h | 2 +- include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_vio.h | 2 +- include/hw/ppc/xics.h | 1 - 8 files changed, 20 insertions(+), 23 deletions(-)
hw/intc/xics.c +0 -12
@@ -714,18 +714,6 @@ static const TypeInfo xics_fabric_info = {/* * Exported functions */ -qemu_irq xics_get_qirq (XICSFabric *xi,int irq) -{ -XICSFabricClass *xic =XICS_FABRIC_GET_CLASS (xi); -ICSState *ics = xic->ics_get (xi, irq); - -if (ics) { -return ics->qirqs[irq - ics->offset]; - } - -return NULL ; -} -ICPState *xics_icp_get (XICSFabric *xi,int server) {XICSFabricClass *xic =XICS_FABRIC_GET_CLASS (xi);
hw/ppc/spapr.c +11 -0
@@ -3689,6 +3689,17 @@ void spapr_irq_free(sPAPRMachineState *spapr, int irq, int num) } } +qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq) +{ +ICSState *ics = spapr->ics; + +if (ics_valid_irq (ics, irq)) { +return ics->qirqs[irq - ics->offset]; + } + +return NULL ; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {
hw/ppc/spapr_events.c +5 -7
@@ -472,9 +472,8 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)rtas_event_log_queue (spapr, entry); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), -rtas_event_log_to_irq (spapr, -RTAS_LOG_TYPE_EPOW ))); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, +rtas_event_log_to_irq (spapr,RTAS_LOG_TYPE_EPOW ))); } static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
@@ -556,9 +555,8 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,rtas_event_log_queue (spapr, entry); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), -rtas_event_log_to_irq (spapr, -RTAS_LOG_TYPE_HOTPLUG ))); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, +rtas_event_log_to_irq (spapr,RTAS_LOG_TYPE_HOTPLUG ))); }void spapr_hotplug_req_add_by_index (sPAPRDRConnector *drc)
@@ -678,7 +676,7 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMachineState *spapr,spapr_event_sources_get_source (spapr->event_sources, i);g_assert (source->enabled); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), source->irq)); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, source->irq)); } }
hw/ppc/spapr_pci.c +1 -1
@@ -723,7 +723,7 @@ static void spapr_msi_write(void *opaque, hwaddr addr,trace_spapr_pci_msi_write (addr, data, irq); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), irq)); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, irq)); }static const MemoryRegionOps spapr_msi_ops = {
include/hw/pci-host/spapr.h +1 -1
@@ -108,7 +108,7 @@ static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); -return xics_get_qirq (XICS_FABRIC (spapr), phb->lsi_table[pin].irq); +return spapr_irq_get_qirq (spapr, phb->lsi_table[pin].irq); }PCIHostState *spapr_create_phb (sPAPRMachineState *spapr,int index);
include/hw/ppc/spapr.h +1 -0
@@ -714,5 +714,6 @@ int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi,int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi,bool align,Error **errp);void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num); +qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq);#endif /* HW_SPAPR_H */
include/hw/ppc/spapr_vio.h +1 -1
@@ -87,7 +87,7 @@ static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); -return xics_get_qirq (XICS_FABRIC (spapr), dev->irq); +return spapr_irq_get_qirq (spapr, dev->irq); } static inline bool spapr_vio_dma_valid(VIOsPAPRDevice *dev, uint64_t taddr,
include/hw/ppc/xics.h +0 -1
@@ -183,7 +183,6 @@ typedef struct XICSFabricClass {void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle); -qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server);/* Internal XICS interfaces */
Signature · 1 line
2.13.6
PATCH 8/25 spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterThe XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.h
default-configs/ppc64-softmmu.mak +1 -0
@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=y
hw/intc/Makefile.objs +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.o
hw/intc/spapr_xive.c new file +165 -0
165 lines not on this page · raw message
hw/intc/xive-internal.h new file +50 -0
50 lines not on this page · raw message
include/hw/ppc/spapr_xive.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 9/25 spapr: introduce handlers for XIVE interrupt sources
In reply to Cédric Le GoaterThese are very similar to the XICS handlers in a simpler form. They make use of a status array for the LSI interrupts. The spapr_xive_irq() routine in charge of triggering the CPU interrupt line will be filled later on.
--- hw/intc/spapr_xive.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/spapr_xive.h | 14 +++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-)
hw/intc/spapr_xive.c +53 -2
@@ -26,6 +26,47 @@#include "xive-internal.h" +static void spapr_xive_irq (sPAPRXive *xive,int lisn) +{ + +} + +/* +* XIVE Interrupt Source +*/ +static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val) +{ +if (val) { +spapr_xive_irq (xive, lisn); + } +} + +static void spapr_xive_source_set_irq_lsi (sPAPRXive *xive,int lisn,int val) +{ +if (val) { + xive->status[lisn] |=XIVE_STATUS_ASSERTED ; + }else { + xive->status[lisn] &= ~XIVE_STATUS_ASSERTED ; + } + +if (xive->status[lisn] &XIVE_STATUS_ASSERTED && + !(xive->status[lisn] &XIVE_STATUS_SENT )) { + xive->status[lisn] |=XIVE_STATUS_SENT ; +spapr_xive_irq (xive, lisn); + } +} + +static void spapr_xive_source_set_irq (void *opaque,int lisn,int val) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); + +if (spapr_xive_irq_is_lsi (xive, lisn)) { +spapr_xive_source_set_irq_lsi (xive, lisn, val); + }else { +spapr_xive_source_set_irq_msi (xive, lisn, val); + } +} +/* * Main XIVE object */
@@ -41,7 +82,8 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)continue ; } -monitor_printf (mon," %4x %s %08x %08x\n" , i, +monitor_printf (mon," %4x %s %s %08x %08x\n" , i, +spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w));
@@ -53,6 +95,8 @@ void spapr_xive_reset(void *dev)sPAPRXive *xive =SPAPR_XIVE (dev);int i; +/* Do not clear IRQs status */ +/* Mask all valid IVEs in the IRQ number space. */ for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i];
@@ -71,6 +115,11 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)return ; } +/* QEMU IRQs */ + xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, + xive->nr_irqs); + xive->status =g_malloc0 (xive->nr_irqs); +/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));
@@ -102,6 +151,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL), VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), + VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs),VMSTATE_END_OF_LIST () }, };
@@ -140,7 +190,7 @@ XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn)return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; } -bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi) {XiveIVE *ive =spapr_xive_get_ive (xive, lisn);
@@ -149,6 +199,7 @@ bool spapr_xive_irq_set(sPAPRXive *xive, uint32_t lisn) } ive->w |=IVE_VALID ; + xive->status[lisn] |= lsi ?XIVE_STATUS_LSI :0 ;return true; }
include/hw/ppc/spapr_xive.h +13 -1
@@ -33,11 +33,23 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +#define XIVE_STATUS_LSI 0x1 +#define XIVE_STATUS_ASSERTED 0x2 +#define XIVE_STATUS_SENT 0x4 +uint8_t *status; +/* XIVE internal tables */ XiveIVE *ivt; }; -bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn) +{ +return xive->status[lisn] &XIVE_STATUS_LSI ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);
Signature · 1 line
2.13.6
PATCH 10/25 spapr: add MMIO handlers for the XIVE interrupt sources
In reply to Cédric Le GoaterEach interrupt source is associated with a two bit state machine called an Event State Buffer (ESB). The bits are named "P" (pending) and "Q" (queued) and can be controlled by MMIO. It is used to trigger events. See code for more details on the states and transitions.
The MMIO space for the ESB translation is 512GB large on baremetal (powernv) systems and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map a sub memory region for the provisionned IRQ numbers and to use the mapping address of chip 0 on a real system. The OS will get the address of the MMIO page of the ESB entry associated with an IRQ using the H_INT_GET_SOURCE_INFO hcall.
--- hw/intc/spapr_xive.c | 268 +++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr_xive.h | 8 ++ 2 files changed, 275 insertions(+), 1 deletion(-)
hw/intc/spapr_xive.c +267 -1
@@ -32,6 +32,216 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn) }/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_GET 0x800 +#define XIVE_ESB_SET_PQ_00 0xc00 +#define XIVE_ESB_SET_PQ_01 0xd00 +#define XIVE_ESB_SET_PQ_10 0xe00 +#define XIVE_ESB_SET_PQ_11 0xf00 + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ +static void spapr_xive_source_eoi (sPAPRXive *xive,uint32_t lisn) +{ +if (spapr_xive_irq_is_lsi (xive, lisn)) { + xive->status[lisn] &= ~XIVE_STATUS_SENT ; + } +} + +/* TODO: handle second page +* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +uint64_t ret =-1 ; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); + goto out; + } + +switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn); + +/* return TRUE or FALSE depending on PQ value */ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +out: +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +bool notify = false; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return ; + } + +switch (offset) { +case 0 : +/* TODO: should we trigger even if the IVE is masked ? */ + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +if (notify && !(ive->w &IVE_MASKED )) { +qemu_irq_pulse (xive->qirqs[lisn]); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +/* * XIVE Interrupt Source */ static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val)
@@ -70,6 +280,33 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)/* * Main XIVE object */ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ + +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset, +unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" [%u]\n" , + __func__, offset, size); +return 0 ; +} + +static void spapr_xive_esb_default_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" <- 0x%" PRIx64" [%u]\n" , + __func__, offset, value, size); +} + +static const MemoryRegionOps spapr_xive_esb_default_ops = { + .read = spapr_xive_esb_default_read, + .write = spapr_xive_esb_default_write, + .endianness =DEVICE_BIG_ENDIAN , +};void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {
@@ -77,14 +314,19 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %s %c%c %08x %08x\n" , i,spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }
@@ -104,6 +346,9 @@ void spapr_xive_reset(void *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)
@@ -123,6 +368,26 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); +/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. That's the full window but we will only map the +* subregions in use. */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + xive->esb_shift =ESB_SHIFT ; + +/* Install default memory region handlers to log bogus access */ +memory_region_init_io (&xive->esb_mr,NULL , &spapr_xive_esb_default_ops, +NULL ,"xive.esb.full" ,VC_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_mr); + +/* Install the ESB memory region in the overall one */ +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), &spapr_xive_esb_ops, + xive,"xive.esb" , + (1ull << xive->esb_shift) * xive->nr_irqs); +memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem); +qemu_register_reset (spapr_xive_reset, dev); }
@@ -152,6 +417,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };
include/hw/ppc/spapr_xive.h +8 -0
@@ -42,6 +42,14 @@ struct sPAPRXive {/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size; + +/* ESB memory region */ +uint32_t esb_shift; +hwaddr esb_base; +MemoryRegion esb_mr; +MemoryRegion esb_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)
Signature · 1 line
2.13.6
PATCH 11/25 spapr: describe the XIVE interrupt source flags
In reply to Cédric Le GoaterThe XIVE interrupt sources can have different characteristics depending on their nature and the HW level in use. The sPAPR specs provide a set of flags to describe them :
- XIVE_SRC_H_INT_ESB the Event State Buffers are controlled with a specific hcall H_INT_ESB and not with MMIO
- XIVE_SRC_LSI LSI or MSI source (ICSIRQState level) - XIVE_SRC_TRIGGER the full function page supports trigger - XIVE_SRC_STORE_EOI EOI can be done with a store.
Our QEMU emulation of XIVE for the sPAPR machine gathers all sources under a same model and provides a common source with the XIVE_SRC_TRIGGER type. So, the above list is mostly informative apart from the XIVE_SRC_LSI flag which will be deduced from the XIVE_STATUS_LSI flag.
The OS retrieves this information on the source with the H_INT_GET_SOURCE_INFO hcall.
--- hw/intc/spapr_xive.c | 4 ++++ include/hw/ppc/spapr_xive.h | 7 +++++++ 2 files changed, 11 insertions(+)
hw/intc/spapr_xive.c +4 -0
@@ -368,6 +368,10 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); +/* All sources are emulated under the XIVE object and share the +* same characteristic */ + xive->flags =XIVE_SRC_TRIGGER ; +/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); xive->sbe =g_malloc0 (xive->sbe_size);
include/hw/ppc/spapr_xive.h +7 -0
@@ -40,6 +40,13 @@ struct sPAPRXive {#define XIVE_STATUS_SENT 0x4uint8_t *status; +/* Interrupt source flags */ +#define XIVE_SRC_H_INT_ESB (1ull << (63 - 60)) +#define XIVE_SRC_LSI (1ull << (63 - 61)) +#define XIVE_SRC_TRIGGER (1ull << (63 - 62)) +#define XIVE_SRC_STORE_EOI (1ull << (63 - 63)) +uint32_t flags; +/* XIVE internal tables */ XiveIVE *ivt;uint8_t *sbe;
Signature · 1 line
2.13.6
PATCH 12/25 spapr: introduce a XIVE interrupt presenter model
In reply to Cédric Le GoaterThe XIVE interrupt presenter exposes a set of rings, also called Thread Interrupt Management Areas (TIMA), to handle priority management and interrupt acknowledgment among other things. There is one ring per level of privilege, four in all. The one we are interested in for the sPAPR machine is the OS ring.
The TIMA is mapped at the same address for each CPU. 'current_cpu' is used to retrieve the targeted interrupt presenter object holding the cache data of the registers the model use.
--- hw/intc/spapr_xive.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 89 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 371 insertions(+)
hw/intc/spapr_xive.c +271 -0
@@ -23,9 +23,166 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h" #include "xive-internal.h" +struct sPAPRXiveICP { +DeviceState parent_obj; + +CPUState *cs; +uint8_t tima[TM_RING_COUNT *0x10 ]; +uint8_t *tima_os; +qemu_irq output; +}; + +static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp) +{ +return 0 ; +} + +static void spapr_xive_icp_set_cppr (sPAPRXiveICP *icp,uint8_t cppr) +{ +if (cppr >XIVE_PRIORITY_MAX ) { + cppr =0xff ; + } + + icp->tima_os[TM_CPPR ] = cppr; +} + +/* +* Thread Interrupt Management Area MMIO +*/ +static uint64_t spapr_xive_tm_read_special (sPAPRXiveICP *icp,hwaddr offset, +unsigned size) +{ +uint64_t ret =-1 ; + +if (offset ==TM_SPC_ACK_OS_REG && size ==2 ) { + ret =spapr_xive_icp_accept (icp); + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA read @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + +return ret; +} + +static uint64_t spapr_xive_tm_read (void *opaque,hwaddr offset,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu); +sPAPRXiveICP *icp =SPAPR_XIVE_ICP (cpu->intc); +uint64_t ret =-1 ; +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +return spapr_xive_tm_read_special (icp, offset, size); + } + +if ((offset &0xf0 ) ==TM_QW1_OS ) { +switch (size) { +case 1 : +case 2 : +case 4 : +case 8 : +if (QEMU_IS_ALIGNED (offset, size)) { + ret =0 ; +for (i =0 ; i < size; i++) { + ret |= icp->tima[offset + i] << (8 * i); + } + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"XIVE: invalid TIMA read alignment @%" + HWADDR_PRIx" size %d\n" , offset, size); + } +break ; +default : +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: does handle non-OS TIMA ring @%" + HWADDR_PRIx"\n" , offset); + } + +return ret; +} + +static bool spapr_xive_tm_is_readonly (uint8_t offset) +{ +/* Let's be optimistic and prepare ground for HV mode support */ +switch (offset) { +case TM_QW1_OS +TM_CPPR : +return false; +default : +return true; + } +} + +static void spapr_xive_tm_write_special (sPAPRXiveICP *icp,hwaddr offset, +uint64_t value,unsigned size) +{ +/* TODO: support TM_SPC_SET_OS_PENDING */ + +/* TODO: support TM_SPC_ACK_OS_EL */ +} + +static void spapr_xive_tm_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu); +sPAPRXiveICP *icp =SPAPR_XIVE_ICP (cpu->intc); +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +spapr_xive_tm_write_special (icp, offset, value, size); +return ; + } + +if ((offset &0xf0 ) ==TM_QW1_OS ) { +switch (size) { +case 1 : +if (offset ==TM_QW1_OS +TM_CPPR ) { +spapr_xive_icp_set_cppr (icp, value &0xff ); + } +break ; +case 4 : +case 8 : +if (QEMU_IS_ALIGNED (offset, size)) { +for (i =0 ; i < size; i++) { +if (!spapr_xive_tm_is_readonly (offset + i)) { + icp->tima[offset + i] = (value >> (8 * i)) &0xff ; + } + } + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA write @%" + HWADDR_PRIx" size %d\n" , offset, size); + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA write @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: does handle non-OS TIMA ring @%" + HWADDR_PRIx"\n" , offset); + } +} + + +static const MemoryRegionOps spapr_xive_tm_ops = { + .read = spapr_xive_tm_read, + .write = spapr_xive_tm_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =1 , + .max_access_size =8 , + }, +}; +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {
@@ -287,6 +444,11 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)#define VC_BAR_SIZE 0x08000000000ull#define ESB_SHIFT 16/* One 64k page. OPAL has two */ +/* Thread Interrupt Management Area MMIO */ +#define TM_BAR_DEFAULT 0x30203180000ull +#define TM_SHIFT 16 +#define TM_BAR_SIZE (TM_RING_COUNT * (1 << TM_SHIFT)) +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset,unsigned size) {
@@ -392,6 +554,14 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp) (1ull << xive->esb_shift) * xive->nr_irqs);memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem); +/* TM BAR. Same address for each chip */ + xive->tm_base = (P9_MMIO_BASE |TM_BAR_DEFAULT ); + xive->tm_shift =TM_SHIFT ; + +memory_region_init_io (&xive->tm_iomem,OBJECT (xive), &spapr_xive_tm_ops, + xive,"xive.tm" ,TM_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->tm_iomem); +qemu_register_reset (spapr_xive_reset, dev); }
@@ -448,9 +618,110 @@ static const TypeInfo spapr_xive_info = { .class_init = spapr_xive_class_init, }; +void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon) +{ +int cpu_index = xicp->cs ? xicp->cs->cpu_index :-1 ; + +monitor_printf (mon,"CPU %d CPPR=%02x IPB=%02x PIPR=%02x NSR=%02x\n" , + cpu_index, xicp->tima_os[TM_CPPR ], xicp->tima_os[TM_IPB ], + xicp->tima_os[TM_PIPR ], xicp->tima_os[TM_NSR ]); +} + +static void spapr_xive_icp_reset (void *dev) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev); + +memset (xicp->tima,0 ,sizeof (xicp->tima)); +} + +static void spapr_xive_icp_realize (DeviceState *dev,Error **errp) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev); +PowerPCCPU *cpu; +CPUPPCState *env; +Object *obj; +Error *err =NULL ; + + obj =object_property_get_link (OBJECT (dev),ICP_PROP_CPU , &err); +if (!obj) { +error_propagate (errp, err); +error_prepend (errp,"required link '" ICP_PROP_CPU "' not found: " ); +return ; + } + + cpu =POWERPC_CPU (obj); + xicp->cs =CPU (obj); + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + xicp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + xicp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XIVE interrupt controller does not support " +"this CPU bus model" ); +return ; + } + +qemu_register_reset (spapr_xive_icp_reset, dev); +} + +static void spapr_xive_icp_unrealize (DeviceState *dev,Error **errp) +{ +qemu_unregister_reset (spapr_xive_icp_reset, dev); +} + +static void spapr_xive_icp_init (Object *obj) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (obj); + + xicp->tima_os = &xicp->tima[TM_QW1_OS ]; +} + +static bool vmstate_spapr_xive_icp_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive_icp = { + .name =TYPE_SPAPR_XIVE_ICP , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_icp_needed, + .fields = (VMStateField []) { +VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_END_OF_LIST () + }, +}; + +static void spapr_xive_icp_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_icp_realize; + dc->unrealize = spapr_xive_icp_unrealize; + dc->desc ="sPAPR XIVE Interrupt Presenter" ; + dc->vmsd = &vmstate_spapr_xive_icp; +} + +static const TypeInfo xive_icp_info = { + .name =TYPE_SPAPR_XIVE_ICP , + .parent =TYPE_DEVICE , + .instance_size =sizeof (sPAPRXiveICP), + .instance_init = spapr_xive_icp_init, + .class_init = spapr_xive_icp_class_init, +}; +static void spapr_xive_register_types (void ) {type_register_static (&spapr_xive_info); +type_register_static (&xive_icp_info); }type_init (spapr_xive_register_types)
hw/intc/xive-internal.h +89 -0
101 lines not on this page · raw message
include/hw/ppc/spapr_xive.h +11 -0
@@ -23,10 +23,15 @@typedef struct sPAPRXive sPAPRXive ;typedef struct XiveIVE XiveIVE ; +typedef struct sPAPRXiveICP sPAPRXiveICP ;#define TYPE_SPAPR_XIVE "spapr-xive"#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) +#define TYPE_SPAPR_XIVE_ICP "spapr-xive-icp" +#define SPAPR_XIVE_ICP (obj) \ + OBJECT_CHECK(sPAPRXiveICP, (obj), TYPE_SPAPR_XIVE_ICP) +struct sPAPRXive {SysBusDevice parent;
@@ -57,6 +62,11 @@ struct sPAPRXive {hwaddr esb_base;MemoryRegion esb_mr;MemoryRegion esb_iomem; + +/* TIMA memory region */ +uint32_t tm_shift; +hwaddr tm_base; +MemoryRegion tm_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)
@@ -67,5 +77,6 @@ static inline bool spapr_xive_irq_is_lsi(sPAPRXive *xive, int lisn)bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); +void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon);#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH 13/25 spapr: introduce the XIVE Event Queues
In reply to Cédric Le GoaterThe Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is one of the internal tables the XIVE interrupt controller uses to redirect exception from event sources to CPU threads.
The EQD specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which server (VPD in XIVE terminology) to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
There is one XiveEQ per priority and the model chooses to store them under the Xive Interrupt presenter model. It will be retrieved, just like for XICS, through the 'intc' object pointer of the CPU.
The EQ indexing follows a simple pattern:
(server << 3) | (priority & 0x7)
--- hw/intc/spapr_xive.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+)
hw/intc/spapr_xive.c +56 -0
@@ -23,6 +23,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h"
@@ -34,6 +35,8 @@ struct sPAPRXiveICP {uint8_t tima[TM_RING_COUNT *0x10 ];uint8_t *tima_os;qemu_irq output; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp)
@@ -183,6 +186,13 @@ static const MemoryRegionOps spapr_xive_tm_ops = { }, }; +static sPAPRXiveICP *spapr_xive_icp_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {
@@ -632,6 +642,8 @@ static void spapr_xive_icp_reset(void *dev)sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev);memset (xicp->tima,0 ,sizeof (xicp->tima)); + +memset (xicp->eqt,0 ,sizeof (xicp->eqt)); }static void spapr_xive_icp_realize (DeviceState *dev,Error **errp)
@@ -683,6 +695,23 @@ static void spapr_xive_icp_init(Object *obj) xicp->tima_os = &xicp->tima[TM_QW1_OS ]; } +static const VMStateDescription vmstate_spapr_xive_icp_eq = { + .name =TYPE_SPAPR_XIVE_ICP "/eq" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ), +VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_icp_needed (void *opaque) {/* TODO check machine XIVE support */
@@ -696,6 +725,8 @@ static const VMStateDescription vmstate_spapr_xive_icp = { .needed = vmstate_spapr_xive_icp_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveICP, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_icp_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };
@@ -755,3 +786,28 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) ive->w &= ~IVE_VALID ;return true; } + +/* +* Use a simple indexing for the EQs. +*/ +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t eq_idx) +{ +int priority = eq_idx &0x7 ; +sPAPRXiveICP *xicp =spapr_xive_icp_get (xive, eq_idx >>3 ); + +return xicp ? &xicp->eqt[priority] :NULL ; +} + +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server, +uint8_t priority,uint32_t *out_eq_idx) +{ +if (priority >XIVE_PRIORITY_MAX ) { +return false; + } + +if (out_eq_idx) { + *out_eq_idx = (server <<3 ) | (priority &0x7 ); + } + +return true; +}
hw/intc/xive-internal.h +50 -0
59 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 14/25 spapr: push the XIVE EQ data in OS event queue
In reply to Cédric Le GoaterIf a triggered event is let through, the Event Queue data defined in the associated IVE is pushed in the in-memory event queue. The latter is a circular buffer provided by the OS using the H_INT_SET_QUEUE_CONFIG hcall, one per server and priority couple. It is composed of Event Queue entries which are 4 bytes long, the first bit being a 'generation' bit and the 31 following bits the EQ Data field.
The EQ Data field provides a way to set an invariant logical event source number for an IRQ. It is set with the H_INT_SET_SOURCE_CONFIG hcall.
--- hw/intc/spapr_xive.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
hw/intc/spapr_xive.c +67 -0
@@ -193,9 +193,76 @@ static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server)return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; } +static void spapr_xive_eq_push (XiveEQ *eq,uint32_t data) +{ +uint64_t qaddr_base = (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; +uint32_t qsize =GETFIELD (EQ_W0_QSIZE , eq->w0); +uint32_t qindex =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); +uint32_t qgen =GETFIELD (EQ_W1_GENERATION , eq->w1); + +uint64_t qaddr = qaddr_base + (qindex <<2 ); +uint32_t qdata =cpu_to_be32 ((qgen <<31 ) | (data &0x7fffffff )); +uint32_t qentries =1 << (qsize +10 ); + +if (dma_memory_write (&address_space_memory, qaddr, &qdata,sizeof (qdata))) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to write EQ data @0x%" + HWADDR_PRIx"\n" , __func__, qaddr); +return ; + } + + qindex = (qindex +1 ) % qentries; +if (qindex ==0 ) { + qgen ^=1 ; + eq->w1 =SETFIELD (EQ_W1_GENERATION , eq->w1, qgen); + } + eq->w1 =SETFIELD (EQ_W1_PAGE_OFF , eq->w1, qindex); +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) { +XiveIVE *ive; +XiveEQ *eq; +uint32_t eq_idx; +uint8_t priority; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return ; + } +if (ive->w &IVE_MASKED ) { +return ; + } + +/* Find our XiveEQ */ + eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); + eq =spapr_xive_get_eq (xive, eq_idx); +if (!eq) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No EQ for LISN %d\n" , lisn); +return ; + } + +if (eq->w0 &EQ_W0_ENQUEUE ) { +spapr_xive_eq_push (eq,GETFIELD (IVE_EQ_DATA , ive->w)); + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: !ENQUEUE not implemented\n" ); + } + +if (!(eq->w0 &EQ_W0_UCOND_NOTIFY )) { +qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); + } + +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { + priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7); + +/* The EQ is masked. Can this happen ? */ +if (priority ==0xff ) { +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); + } }/*
Signature · 1 line
2.13.6
PATCH 15/25 spapr: notify the CPU when the XIVE interrupt priority is more privileged
In reply to Cédric Le GoaterThe Pending Interrupt Priority Register (PIPR) contains the priority of the most favored pending notification. It is calculated from the Interrupt Pending Buffer (IPB) which indicates a pending interrupt at the priority corresponding to the bit number.
If the PIPR is more favored (1) than the Current Processor Priority Register (CPPR), the CPU interrupt line is raised and the EO bit of the Notification Source Register is updated to notify the presence of an exception for the O/S. The check needs to be done whenever the PIPR or the CPPR is changed.
Then, the O/S Exception is raised and the O/S acknowledges the interrupt with a special read in the TIMA. If the EO bit of the Notification Source Register (NSR) is set (and it should), the Current Processor Priority Register (CPPR) takes the value of the Pending Interrupt Priority Register (PIPR). The bit number in the Interrupt Pending Buffer (IPB) corresponding to the priority of the pending interrupt is reseted and so is the EO bit of the NSR.
(1) numerically less than
--- hw/intc/spapr_xive.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)
hw/intc/spapr_xive.c +76 -1
@@ -39,9 +39,63 @@ struct sPAPRXiveICP {XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; }; +/* Convert a priority number to an Interrupt Pending Buffer (IPB) +* register, which indicates a pending interrupt at the priority +* corresponding to the bit number +*/ +static uint8_t priority_to_ipb (uint8_t priority) +{ +return priority >XIVE_PRIORITY_MAX ? +0 :1 << (XIVE_PRIORITY_MAX - priority); +} + +/* Convert an Interrupt Pending Buffer (IPB) register to a Pending +* Interrupt Priority Register (PIPR), which contains the priority of +* the most favored pending notification. +* +* TODO: +* +* PIPR is clamped to CPPR. So the value in the PIPR is: +* +* v = leftmost_bit_of(ipb) (or 0xff); +* pipr = v < cppr ? v : cppr; +* +* Ben says: "which means it's never actually 0xff ... surprise !". +* But, the CPPR can be set to 0xFF ... I am confused ... +*/ +static uint8_t ipb_to_pipr (uint8_t ibp) +{ +return ibp ?clz32 ((uint32_t )ibp <<24 ) :0xff ; +} +static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp) { -return 0 ; +uint8_t nsr = icp->tima_os[TM_NSR ]; + +qemu_irq_lower (icp->output); + +if (icp->tima_os[TM_NSR ] &TM_QW1_NSR_EO ) { +uint8_t cppr = icp->tima_os[TM_PIPR ]; + + icp->tima_os[TM_CPPR ] = cppr; + +/* Reset the pending buffer bit */ + icp->tima_os[TM_IPB ] &= ~priority_to_ipb (cppr); + icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); + +/* Drop Exception bit for OS */ + icp->tima_os[TM_NSR ] &= ~TM_QW1_NSR_EO ; + } + +return (nsr <<8 ) | icp->tima_os[TM_CPPR ]; +} + +static void spapr_xive_icp_notify (sPAPRXiveICP *icp) +{ +if (icp->tima_os[TM_PIPR ] < icp->tima_os[TM_CPPR ]) { + icp->tima_os[TM_NSR ] |=TM_QW1_NSR_EO ; +qemu_irq_raise (icp->output); + } }static void spapr_xive_icp_set_cppr (sPAPRXiveICP *icp,uint8_t cppr)
@@ -51,6 +105,9 @@ static void spapr_xive_icp_set_cppr(sPAPRXiveICP *icp, uint8_t cppr) } icp->tima_os[TM_CPPR ] = cppr; + +/* CPPR has changed, inform the ICP which might raise an exception */ +spapr_xive_icp_notify (icp); }/*
@@ -224,6 +281,8 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)XiveEQ *eq;uint32_t eq_idx;uint8_t priority; +uint32_t server; +sPAPRXiveICP *icp; ive =spapr_xive_get_ive (xive, lisn);if (!ive || !(ive->w &IVE_VALID )) {
@@ -253,6 +312,13 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); } + server =GETFIELD (EQ_W6_NVT_INDEX , eq->w6); + icp =spapr_xive_icp_get (xive, server); +if (!icp) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No ICP for server %d\n" , server); +return ; + } +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7);
@@ -260,9 +326,18 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)if (priority ==0xff ) {g_assert_not_reached (); } + +/* Update the IPB (Interrupt Pending Buffer) with the priority +* of the new notification and inform the ICP, which will +* decide to raise the exception, or not, depending the CPPR. +*/ + icp->tima_os[TM_IPB ] |=priority_to_ipb (priority); + icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); }else {qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); } + +spapr_xive_icp_notify (icp); }/*
Signature · 1 line
2.13.6
PATCH 16/25 spapr: add support for the SET_OS_PENDING command (XIVE)
In reply to Cédric Le GoaterAdjusting the Interrupt Pending Buffer for the O/S would allow a CPU to process event queues of other priorities during one physical interrupt cycle. This is not currently used by the XIVE support for sPAPR in Linux but it is by the hypervisor.
Quoted 1 line
From Ben :
It's a way to avoid the SW replay on EOI.
IE, assume you have 2 interrupts in the queue. You take the exception, ack the first one, process it etc... Then you EOI, the HW won't send a second notification. You need to look at the queue and continue consuming until it's empty.
Today Linux checks the queue on EOI and use a SW mechanism to synthesize a new pseudo-external interrupt.
This MMIO command would allow the OS to instead set back the corresponding priority bit to 1 in the IPB and cause the HW to re-emit the interrupt instead of SW.
Linux doesn't use this today because DD1 didn't support it for the HV level, but other OSes might and we also might use it when we do groups, thus allowing redistribution.
--- hw/intc/spapr_xive.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
hw/intc/spapr_xive.c +8 -1
@@ -181,7 +181,14 @@ static bool spapr_xive_tm_is_readonly(uint8_t offset)static void spapr_xive_tm_write_special (sPAPRXiveICP *icp,hwaddr offset,uint64_t value,unsigned size) { -/* TODO: support TM_SPC_SET_OS_PENDING */ +if (offset ==TM_SPC_SET_OS_PENDING && size ==1 ) { + icp->tima_os[TM_IPB ] |=priority_to_ipb (value &0xff ); + icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); +spapr_xive_icp_notify (icp); + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA write @%" + HWADDR_PRIx" size %d\n" , offset, size); + }/* TODO: support TM_SPC_ACK_OS_EL */ }
Signature · 1 line
2.13.6
PATCH 17/25 spapr: add a sPAPRXive object to the machine
In reply to Cédric Le GoaterThe XIVE object is designed to be always available, so it is created unconditionally on newer machines. Depending on the configuration and the guest capabilities, the CAS negotiation process will decide which interrupt model to use, legacy or XIVE.
The XIVE model makes use of the full range of the IRQ number space because the IRQ numbers for the CPU IPIs are allocated in the range below XICS_IRQ_BASE, which is unused by XICS.
--- hw/ppc/spapr.c | 34 ++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ 2 files changed, 36 insertions(+)
hw/ppc/spapr.c +34 -0
@@ -56,6 +56,7 @@#include "hw/ppc/spapr_vio.h" #include "hw/pci-host/spapr.h" #include "hw/ppc/xics.h" +#include "hw/ppc/spapr_xive.h" #include "hw/pci/msi.h" #include "hw/pci/pci.h"
@@ -204,6 +205,29 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) } } +static sPAPRXive *spapr_xive_create (sPAPRMachineState *spapr,int nr_irqs, +Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =object_new (TYPE_SPAPR_XIVE ); +object_property_add_child (OBJECT (spapr),"xive" , obj, &error_abort); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + } +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } + +return SPAPR_XIVE (obj); +error: +error_propagate (errp, local_err); +return NULL ; +} +static int spapr_fixup_cpu_smt_dt (void *fdt,int offset,PowerPCCPU *cpu,int smt_threads) {
@@ -2360,6 +2384,16 @@ static void ppc_spapr_init(MachineState *machine)/* Set up Interrupt Controller before we create the VCPUs */ xics_system_init (machine,XICS_IRQS_SPAPR , &error_fatal); +/* We don't have KVM support yet, so check for irqchip=on */ +if (kvm_enabled () &&machine_kernel_irqchip_required (machine)) { +error_report ("kernel_irqchip requested. no XIVE support" ); + }else { +/* XIVE uses the full range of IRQ numbers. The CPU IPIs will +* use the range below XICS_IRQ_BASE, which is unused by XICS. */ + spapr->xive =spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , + &error_fatal); + } +/* Set up containers for ibm,client-architecture-support negotiated options */ spapr->ov5 =spapr_ovec_new ();
include/hw/ppc/spapr.h +2 -0
@@ -14,6 +14,7 @@ struct sPAPRNVRAM;typedef struct sPAPREventLogEntry sPAPREventLogEntry ;typedef struct sPAPREventSource sPAPREventSource ;typedef struct sPAPRPendingHPT sPAPRPendingHPT ; +typedef struct sPAPRXive sPAPRXive ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL#define SPAPR_ENTRY_POINT 0x100
@@ -127,6 +128,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +sPAPRXive *xive; };#define H_SUCCESS 0
Signature · 1 line
2.13.6
PATCH 18/25 spapr: allocate IRQ numbers for the XIVE interrupt mode
In reply to Cédric Le GoaterThe IRQ numbers for the IPIs are allocated at the bottom of the IRQ number space to preserve compatibility with XICS which only uses IRQ numbers above 4096.
Also make sure that the allocated IRQ numbers are kept in sync between XICS and XIVE.
--- hw/ppc/spapr.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/ppc/spapr.c +7 -0
@@ -2392,6 +2392,11 @@ static void ppc_spapr_init(MachineState *machine)* use the range below XICS_IRQ_BASE, which is unused by XICS. */ spapr->xive =spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , &error_fatal); + +/* Allocate the first IRQ numbers for the XIVE IPIs */ +for (i =0 ; i <xics_max_server_number (); ++i) { +spapr_xive_irq_set (spapr->xive, i, false); + } }/* Set up containers for ibm,client-architecture-support negotiated options
@@ -3631,6 +3636,7 @@ static int ics_find_free_block(ICSState *ics, int num, int alignnum)static void spapr_irq_set (sPAPRMachineState *spapr,int irq,bool lsi) {ics_set_irq_type (spapr->ics, irq - spapr->ics->offset, lsi); +spapr_xive_irq_set (spapr->xive, irq, lsi); } int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi,
@@ -3721,6 +3727,7 @@ void spapr_irq_free(sPAPRMachineState *spapr, int irq, int num)memset (&ics->irqs[i],0 ,sizeof (ICSIRQState)); } } +spapr_xive_irq_unset (spapr->xive, irq); }qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq)
Signature · 1 line
2.13.6
PATCH 20/25 spapr: add device tree support for the XIVE interrupt mode
In reply to Cédric Le GoaterThe XIVE interface for the guest is described in the device tree under the "interrupt-controller" node. A couple of new properties are specific to XIVE :
- "reg"
contains the base address and size of the thread interrupt managnement areas (TIMA), also called rings, for the User level and for the Guest OS level. Only the Guest OS level is taken into account today.
- "ibm,xive-eq-sizes"
the size of the event queues. One cell per size supported, contains log2 of size, in ascending order.
- "ibm,xive-lisn-ranges"
the interrupt numbers ranges assigned to the guest. These are allocated using a simple bitmap.
and also under the root node :
- "ibm,plat-res-int-priorities"
contains a list of priorities that the hypervisor has reserved for its own use. Simulate ranges as defined by the PowerVM Hypervisor.
When the XIVE interrupt mode is activated after the CAS negotiation, the machine will perform a reboot to rebuild the device tree.
--- hw/intc/spapr_xive_hcall.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 7 ++++++- hw/ppc/spapr_hcall.c | 6 ++++++ include/hw/ppc/spapr_xive.h | 2 ++ 4 files changed, 64 insertions(+), 1 deletion(-)
hw/intc/spapr_xive_hcall.c +50 -0
@@ -883,3 +883,53 @@ void spapr_xive_hcall_init(sPAPRMachineState *spapr)spapr_register_hypercall (H_INT_SYNC , h_int_sync);spapr_register_hypercall (H_INT_RESET , h_int_reset); } + +void spapr_xive_populate (sPAPRMachineState *spapr,int nr_servers, +void *fdt,uint32_t phandle) +{ +sPAPRXive *xive = spapr->xive; +int node; +uint64_t timas[2 *2 ]; +uint32_t lisn_ranges[] = { +cpu_to_be32 (0 ), +cpu_to_be32 (nr_servers), + }; +uint32_t eq_sizes[] = { +cpu_to_be32 (12 ),/* 4K */ +cpu_to_be32 (16 ),/* 64K */ +cpu_to_be32 (21 ),/* 2M */ +cpu_to_be32 (24 ),/* 16M */ + }; +uint32_t plat_res_int_priorities[ARRAY_SIZE (reserved_priorities)]; +int i; + +for (i =0 ; i <ARRAY_SIZE (plat_res_int_priorities); i++) { + plat_res_int_priorities[i] =cpu_to_be32 (reserved_priorities[i]); + } + +/* Thread Interrupt Management Areas : User and OS */ +for (i =0 ; i <2 ; i++) { + timas[i *2 ] =cpu_to_be64 (xive->tm_base + i * (1 << xive->tm_shift)); + timas[i *2 +1 ] =cpu_to_be64 (1 << xive->tm_shift); + } + +_FDT (node =fdt_add_subnode (fdt,0 ,"interrupt-controller" )); + +_FDT (fdt_setprop_string (fdt, node,"name" ,"interrupt-controller" )); +_FDT (fdt_setprop_string (fdt, node,"device_type" ,"power-ivpe" )); +_FDT (fdt_setprop (fdt, node,"reg" , timas,sizeof (timas))); + +_FDT (fdt_setprop_string (fdt, node,"compatible" ,"ibm,power-ivpe" )); +_FDT (fdt_setprop (fdt, node,"ibm,xive-eq-sizes" , eq_sizes, +sizeof (eq_sizes))); +_FDT (fdt_setprop (fdt, node,"ibm,xive-lisn-ranges" , lisn_ranges, +sizeof (lisn_ranges))); + +/* For SLOF */ +_FDT (fdt_setprop_cell (fdt, node,"linux,phandle" , phandle)); +_FDT (fdt_setprop_cell (fdt, node,"phandle" , phandle)); + +/* top properties */ +_FDT (fdt_setprop (fdt,0 ,"ibm,plat-res-int-priorities" , + plat_res_int_priorities,sizeof (plat_res_int_priorities))); +}
hw/ppc/spapr.c +6 -1
@@ -1127,7 +1127,12 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (xics_max_server_number (), fdt,PHANDLE_XICP ); +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_dt_xics (xics_max_server_number (), fdt,PHANDLE_XICP ); + }else { +/* Populate device tree for XIVE */ +spapr_xive_populate (spapr,xics_max_server_number (), fdt,PHANDLE_XICP ); + } ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {
hw/ppc/spapr_hcall.c +6 -0
@@ -1646,6 +1646,12 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, (spapr_h_cas_compose_response (spapr, args[1 ], args[2 ], ov5_updates) !=0 ); } + +/* We need to rebuild the device tree for XIVE, generate a reset */ +if (!spapr->cas_reboot) { + spapr->cas_reboot =spapr_ovec_test (ov5_updates,OV5_XIVE_EXPLOIT ); + } +spapr_ovec_cleanup (ov5_updates);if (spapr->cas_reboot) {
include/hw/ppc/spapr_xive.h +2 -0
@@ -82,5 +82,7 @@ void spapr_xive_icp_pic_print_info(sPAPRXiveICP *xicp, Monitor *mon);typedef struct sPAPRMachineState sPAPRMachineState ;void spapr_xive_hcall_init (sPAPRMachineState *spapr); +void spapr_xive_populate (sPAPRMachineState *spapr,int nr_servers,void *fdt, +uint32_t phandle);#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH 19/25 spapr: add hcalls support for the XIVE interrupt mode
In reply to Cédric Le GoaterA set of Hypervisor's call are used to configure the interrupt sources and the event/notification queues of the guest:
- H_INT_GET_SOURCE_INFO
used to obtain the address of the MMIO page of the Event State Buffer (PQ bits) entry associated with the source.
- H_INT_SET_SOURCE_CONFIG
assigns a source to a "target".
- H_INT_GET_SOURCE_CONFIG
determines to which "target" and "priority" is assigned to a source
- H_INT_GET_QUEUE_INFO
returns the address of the notification management page associated with the specified "target" and "priority".
- H_INT_SET_QUEUE_CONFIG
sets or resets the event queue for a given "target" and "priority". It is also used to set the notification config associated with the queue, only unconditional notification for the moment. Reset is performed with a queue size of 0 and queueing is disabled in that case.
- H_INT_GET_QUEUE_CONFIG
returns the queue settings for a given "target" and "priority".
- H_INT_RESET
resets all of the partition's interrupt exploitation structures to their initial state, losing all configuration set via the hcalls H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
- H_INT_SYNC
issue a synchronisation on a source to make sure sure all notifications have reached their queue.
Calls that still need to be addressed :
H_INT_SET_OS_REPORTING_LINE
H_INT_GET_OS_REPORTING_LINE
See the code for more documentation on each hcall.
--- hw/intc/Makefile.objs | 2 +- hw/intc/spapr_xive_hcall.c | 885 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 2 + include/hw/ppc/spapr.h | 15 +- include/hw/ppc/spapr_xive.h | 4 + 5 files changed, 906 insertions(+), 2 deletions(-) create mode 100644 hw/intc/spapr_xive_hcall.c
hw/intc/Makefile.objs +1 -1
@@ -35,7 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o -obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o spapr_xive_hcall.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.o
hw/intc/spapr_xive_hcall.c new file +885 -0
885 lines not on this page · raw message
hw/ppc/spapr.c +2 -0
@@ -222,6 +222,8 @@ static sPAPRXive *spapr_xive_create(sPAPRMachineState *spapr, int nr_irqs, goto error; } +spapr_xive_hcall_init (spapr); +return SPAPR_XIVE (obj); error:error_propagate (errp, local_err);
include/hw/ppc/spapr.h +14 -1
@@ -387,7 +387,20 @@ struct sPAPRMachineState {#define H_INVALIDATE_PID 0x378#define H_REGISTER_PROC_TBL 0x37C#define H_SIGNAL_SYS_RESET 0x380 -#define MAX_HCALL_OPCODE H_SIGNAL_SYS_RESET + +#define H_INT_GET_SOURCE_INFO 0x3A8 +#define H_INT_SET_SOURCE_CONFIG 0x3AC +#define H_INT_GET_SOURCE_CONFIG 0x3B0 +#define H_INT_GET_QUEUE_INFO 0x3B4 +#define H_INT_SET_QUEUE_CONFIG 0x3B8 +#define H_INT_GET_QUEUE_CONFIG 0x3BC +#define H_INT_SET_OS_REPORTING_LINE 0x3C0 +#define H_INT_GET_OS_REPORTING_LINE 0x3C4 +#define H_INT_ESB 0x3C8 +#define H_INT_SYNC 0x3CC +#define H_INT_RESET 0x3D0 + +#define MAX_HCALL_OPCODE H_INT_RESET/* The hcalls above are standardized in PAPR and implemented by pHyp * as well.
include/hw/ppc/spapr_xive.h +4 -0
@@ -79,4 +79,8 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon); +typedef struct sPAPRMachineState sPAPRMachineState ; + +void spapr_xive_hcall_init (sPAPRMachineState *spapr); +#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH 21/25 spapr: introduce a helper to map the XIVE memory regions
In reply to Cédric Le GoaterWhen the XIVE interrupt mode is activated, the machine needs to expose to the guest the MMIO regions use by the controller :
- Event State Buffer (ESB)
- Thread Interrupt Management Area (TIMA)
Migration will also need to reflect the current interrupt mode in use.
--- hw/intc/spapr_xive_hcall.c | 14 ++++++++++++++ hw/ppc/spapr.c | 5 +++++ include/hw/ppc/spapr_xive.h | 1 + 3 files changed, 20 insertions(+)
hw/intc/spapr_xive_hcall.c +14 -0
@@ -933,3 +933,17 @@ void spapr_xive_populate(sPAPRMachineState *spapr, int nr_servers,_FDT (fdt_setprop (fdt,0 ,"ibm,plat-res-int-priorities" , plat_res_int_priorities,sizeof (plat_res_int_priorities))); } + +void spapr_xive_mmio_map (sPAPRMachineState *spapr) +{ +sPAPRXive *xive = spapr->xive; + +/* ESBs */ +sysbus_mmio_map (SYS_BUS_DEVICE (xive),0 , xive->esb_base); + +/* Thread Management Interrupt Areas */ +/* TODO: Only map the OS TIMA for the moment. Mapping the whole +* region needs some rework in the handlers */ +sysbus_mmio_map (SYS_BUS_DEVICE (xive),1 , + xive->tm_base + (1 << xive->tm_shift)); +}
hw/ppc/spapr.c +5 -0
@@ -1132,6 +1132,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr, }else {/* Populate device tree for XIVE */ spapr_xive_populate (spapr,xics_max_server_number (), fdt,PHANDLE_XICP ); +spapr_xive_mmio_map (spapr); } ret =spapr_populate_memory (spapr, fdt);
@@ -1613,6 +1614,10 @@ static int spapr_post_load(void *opaque, int version_id) } } +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_mmio_map (spapr); + } +return err; }
include/hw/ppc/spapr_xive.h +1 -0
@@ -84,5 +84,6 @@ typedef struct sPAPRMachineState sPAPRMachineState;void spapr_xive_hcall_init (sPAPRMachineState *spapr);void spapr_xive_populate (sPAPRMachineState *spapr,int nr_servers,void *fdt,uint32_t phandle); +void spapr_xive_mmio_map (sPAPRMachineState *spapr);#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH 22/25 spapr: add XIVE support to spapr_irq_get_qirq()
In reply to Cédric Le GoaterThe XIVE object has its own set of qirqs which is to be used when the XIVE interrupt mode is activated.
--- hw/ppc/spapr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +6 -2
@@ -3746,8 +3746,12 @@ qemu_irq spapr_irq_get_qirq(sPAPRMachineState *spapr, int irq) {ICSState *ics = spapr->ics; -if (ics_valid_irq (ics, irq)) { -return ics->qirqs[irq - ics->offset]; +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return spapr->xive->qirqs[irq]; + }else { +if (ics_valid_irq (ics, irq)) { +return ics->qirqs[irq - ics->offset]; + } }return NULL ;
Signature · 1 line
2.13.6
PATCH 23/25 spapr: toggle the ICP depending on the selected interrupt mode
In reply to Cédric Le GoaterEach interrupt mode has its own specific interrupt presenter object, that we store under the CPU object, one for XICS and one for XIVE. The active presenter, corresponding to the current interrupt mode, is simply selected with a lookup on the children of the CPU.
Migration and CPU hotplug also need to reflect the current interrupt mode in use.
--- hw/ppc/spapr.c | 21 ++++++++++++++++++++- hw/ppc/spapr_cpu_core.c | 31 +++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 1 + 3 files changed, 52 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +20 -1
@@ -1128,8 +1128,10 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,/* /interrupt controller */ if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_cpu_core_set_icp (spapr->icp_type);spapr_dt_xics (xics_max_server_number (), fdt,PHANDLE_XICP ); }else { +spapr_cpu_core_set_icp (TYPE_SPAPR_XIVE_ICP );/* Populate device tree for XIVE */ spapr_xive_populate (spapr,xics_max_server_number (), fdt,PHANDLE_XICP );spapr_xive_mmio_map (spapr);
@@ -1615,6 +1617,7 @@ static int spapr_post_load(void *opaque, int version_id) }if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_cpu_core_set_icp (TYPE_SPAPR_XIVE_ICP );spapr_xive_mmio_map (spapr); }
@@ -3610,7 +3613,7 @@ static ICPState *spapr_icp_get(XICSFabric *xi, int vcpu_id)Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp) {Error *local_err =NULL ; -Object *obj; +Object *obj, *obj_xive; obj =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) {
@@ -3618,6 +3621,22 @@ Object *spapr_icp_create(sPAPRMachineState *spapr, CPUState *cs, Error **errp)return NULL ; } +/* Add a XIVE interrupt presenter. The machine will switch the CPU +* ICP depending on the interrupt model negotiated at CAS time. +*/ + obj_xive =icp_create (cs,TYPE_SPAPR_XIVE_ICP ,XICS_FABRIC (spapr), + &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); +return NULL ; + } + +/* when hotplugged, the CPU should have the correct ICP */ +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return obj_xive; + } +return obj; }
hw/ppc/spapr_cpu_core.c +31 -0
@@ -257,3 +257,34 @@ static const TypeInfo spapr_cpu_core_type_infos[] = { };DEFINE_TYPES (spapr_cpu_core_type_infos) + +typedef struct ForeachFindICPArgs { +const char *icp_type; +Object *icp; +} ForeachFindICPArgs; + +static int spapr_cpu_core_find_icp (Object *child,void *opaque) +{ +ForeachFindICPArgs *args = opaque; + +if (object_dynamic_cast (child, args->icp_type)) { + args->icp = child; + } + +return args->icp !=NULL ; +} + +void spapr_cpu_core_set_icp (const char *icp_type) +{ +CPUState *cs; + +CPU_FOREACH (cs) { +ForeachFindICPArgs args = { icp_type,NULL }; +PowerPCCPU *cpu =POWERPC_CPU (cs); + +object_child_foreach (OBJECT (cs), spapr_cpu_core_find_icp, &args); +g_assert (args.icp); + + cpu->intc = args.icp; + } +}
include/hw/ppc/spapr_cpu_core.h +1 -0
@@ -38,4 +38,5 @@ typedef struct sPAPRCPUCoreClass { } sPAPRCPUCoreClass;const char *spapr_get_cpu_core_type (const char *cpu_type); +void spapr_cpu_core_set_icp (const char *icp_type);#endif
Signature · 1 line
2.13.6
PATCH 24/25 spapr: add support to dump XIVE information
In reply to Cédric Le GoaterModify the InterruptStatsProvider output to reflect the interrupt mode currently in use by the machine.
--- hw/ppc/spapr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +10 -2
@@ -3785,10 +3785,18 @@ static void spapr_pic_print_info(InterruptStatsProvider *obj,CPU_FOREACH (cs) {PowerPCCPU *cpu =POWERPC_CPU (cs); -icp_pic_print_info (ICP (cpu->intc), mon); +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_icp_pic_print_info (SPAPR_XIVE_ICP (cpu->intc), mon); + }else { +icp_pic_print_info (ICP (cpu->intc), mon); + } } -ics_pic_print_info (spapr->ics, mon); +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_pic_print_info (spapr->xive, mon); + }else { +ics_pic_print_info (spapr->ics, mon); + } }int spapr_vcpu_id (PowerPCCPU *cpu)
Signature · 1 line
2.13.6
PATCH 25/25 spapr: advertise XIVE exploitation mode in CAS
In reply to Cédric Le GoaterWe introduce a 'xive_exploitation' boolean at the machine level to enable the XIVE interrupt mode for newer machines and to disable it on older ones.
The XIVE interrupt mode can still be forced on the command line with a machine option. That might be a bit dangerous. To be discussed.
--- hw/intc/spapr_xive.c | 10 ++++++---- hw/ppc/spapr.c | 52 +++++++++++++++++++++++++++++++++++++++++++++----- include/hw/ppc/spapr.h | 1 + 3 files changed, 54 insertions(+), 9 deletions(-)
hw/intc/spapr_xive.c +6 -4
@@ -736,8 +736,9 @@ static const VMStateDescription vmstate_spapr_xive_ive = {static bool vmstate_spapr_xive_needed (void *opaque) { -/* TODO check machine XIVE support */ -return true; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +return spapr->xive_exploitation; }static const VMStateDescription vmstate_spapr_xive = {
@@ -863,8 +864,9 @@ static const VMStateDescription vmstate_spapr_xive_icp_eq = {static bool vmstate_spapr_xive_icp_needed (void *opaque) { -/* TODO check machine XIVE support */ -return true; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +return spapr->xive_exploitation; }static const VMStateDescription vmstate_spapr_xive_icp = {
hw/ppc/spapr.c +47 -5
96 lines not on this page · raw message
include/hw/ppc/spapr.h +1 -0
@@ -129,6 +129,7 @@ struct sPAPRMachineState {const char *icp_type;sPAPRXive *xive; +bool xive_exploitation; };#define H_SUCCESS 0
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH 13/25] spapr: introduce the XIVE Event Queues
In reply to Cédric Le GoaterQuoted 4 lines · Cédric Le Goater
The Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is one of the internal tables the XIVE interrupt controller uses to redirect exception from event sources to CPU threads.
Keep in mind tha we want to only expose to the guest priorities 0..6 as priority 7 will not be available with KVM on DD2.0 chips.
Quoted 190 lines
The EQD specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which server (VPD in XIVE terminology) to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
There is one XiveEQ per priority and the model chooses to store them under the Xive Interrupt presenter model. It will be retrieved, just like for XICS, through the 'intc' object pointer of the CPU.
The EQ indexing follows a simple pattern:
(server << 3) | (priority & 0x7)Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+)hw/intc/spapr_xive.c +56
-0@@ -23,6 +23,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h" @@ -34,6 +35,8 @@ struct sPAPRXiveICP {uint8_t tima[TM_RING_COUNT *0x10 ];uint8_t *tima_os;qemu_irq output; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp)@@ -183,6 +186,13 @@ static const MemoryRegionOps spapr_xive_tm_ops = { }, }; +static sPAPRXiveICP *spapr_xive_icp_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -632,6 +642,8 @@ static void spapr_xive_icp_reset(void *dev)sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev);memset (xicp->tima,0 ,sizeof (xicp->tima)); + +memset (xicp->eqt,0 ,sizeof (xicp->eqt)); }static void spapr_xive_icp_realize (DeviceState *dev,Error **errp)@@ -683,6 +695,23 @@ static void spapr_xive_icp_init(Object *obj) xicp->tima_os = &xicp->tima[TM_QW1_OS ]; } +static const VMStateDescription vmstate_spapr_xive_icp_eq = { + .name =TYPE_SPAPR_XIVE_ICP "/eq" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ), +VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_icp_needed (void *opaque) {/* TODO check machine XIVE support */ @@ -696,6 +725,8 @@ static const VMStateDescription vmstate_spapr_xive_icp = { .needed = vmstate_spapr_xive_icp_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveICP, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_icp_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };@@ -755,3 +786,28 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) ive->w &= ~IVE_VALID ;return true; } + +/* +* Use a simple indexing for the EQs. +*/ +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t eq_idx) +{ +int priority = eq_idx &0x7 ; +sPAPRXiveICP *xicp =spapr_xive_icp_get (xive, eq_idx >>3 ); + +return xicp ? &xicp->eqt[priority] :NULL ; +} + +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server, +uint8_t priority,uint32_t *out_eq_idx) +{ +if (priority >XIVE_PRIORITY_MAX ) { +return false; + } + +if (out_eq_idx) { + *out_eq_idx = (server <<3 ) | (priority &0x7 ); + } + +return true; +}hw/intc/xive-internal.h +50
-0@@ -131,9 +131,59 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +/* EQ */ +typedef struct XiveEQ { +uint32_t w0; +#define EQ_W0_VALID PPC_BIT32(0) +#define EQ_W0_ENQUEUE PPC_BIT32(1) +#define EQ_W0_UCOND_NOTIFY PPC_BIT32(2) +#define EQ_W0_BACKLOG PPC_BIT32(3) +#define EQ_W0_PRECL_ESC_CTL PPC_BIT32(4) +#define EQ_W0_ESCALATE_CTL PPC_BIT32(5) +#define EQ_W0_END_OF_INTR PPC_BIT32(6) +#define EQ_W0_QSIZE PPC_BITMASK32(12, 15) +#define EQ_W0_SW0 PPC_BIT32(16) +#define EQ_W0_FIRMWARE EQ_W0_SW0/* Owned by FW */ +#define EQ_QSIZE_4K 0 +#define EQ_QSIZE_64K 4 +#define EQ_W0_HWDEP PPC_BITMASK32(24, 31) +uint32_t w1; +#define EQ_W1_ESn PPC_BITMASK32(0, 1) +#define EQ_W1_ESn_P PPC_BIT32(0) +#define EQ_W1_ESn_Q PPC_BIT32(1) +#define EQ_W1_ESe PPC_BITMASK32(2, 3) +#define EQ_W1_ESe_P PPC_BIT32(2) +#define EQ_W1_ESe_Q PPC_BIT32(3) +#define EQ_W1_GENERATION PPC_BIT32(9) +#define EQ_W1_PAGE_OFF PPC_BITMASK32(10, 31) +uint32_t w2; +#define EQ_W2_MIGRATION_REG PPC_BITMASK32(0, 3) +#define EQ_W2_OP_DESC_HI PPC_BITMASK32(4, 31) +uint32_t w3; +#define EQ_W3_OP_DESC_LO PPC_BITMASK32(0, 31) +uint32_t w4; +#define EQ_W4_ESC_EQ_BLOCK PPC_BITMASK32(4, 7) +#define EQ_W4_ESC_EQ_INDEX PPC_BITMASK32(8, 31) +uint32_t w5; +#define EQ_W5_ESC_EQ_DATA PPC_BITMASK32(1, 31) +uint32_t w6; +#define EQ_W6_FORMAT_BIT PPC_BIT32(8) +#define EQ_W6_NVT_BLOCK PPC_BITMASK32(9, 12) +#define EQ_W6_NVT_INDEX PPC_BITMASK32(13, 31) +uint32_t w7; +#define EQ_W7_F0_IGNORE PPC_BIT32(0) +#define EQ_W7_F0_BLK_GROUPING PPC_BIT32(1) +#define EQ_W7_F0_PRIORITY PPC_BITMASK32(8, 15) +#define EQ_W7_F1_WAKEZ PPC_BIT32(0) +#define EQ_W7_F1_LOG_SERVER_ID PPC_BITMASK32(1, 31) +}XiveEQ ; +#define XIVE_PRIORITY_MAX 7void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t idx); +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server,uint8_t prio, +uint32_t *out_eq_idx);#endif /* _INTC_XIVE_INTERNAL_H */
Re: [Qemu-devel] [PATCH 02/25] ppc/xics: assign of the CPU 'intc' pointer under the core
In reply to Cédric Le GoaterQuoted 9 lines · Cédric Le Goater
The 'intc' pointer of the CPU references the interrupt presenter in the XICS interrupt mode. When the XIVE interrupt mode is available and activated, the machine will need to reassign this pointer to reflect the change.
Moving this assignment under the realize routine of the CPU will ease the process when the interrupt mode is toggled.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 44 lines
--- hw/intc/xics.c | 1 - hw/ppc/pnv_core.c | 2 +- hw/ppc/spapr_cpu_core.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)hw/intc/xics.c +0
-1@@ -334,7 +334,6 @@ static void icp_realize(DeviceState *dev, Error **errp) } cpu =POWERPC_CPU (obj); - cpu->intc =OBJECT (icp); icp->cs =CPU (obj); env = &cpu->env;hw/ppc/pnv_core.c +1
-1@@ -133,7 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } -icp_create (cs,TYPE_PNV_ICP , xi, &local_err); + cpu->intc =icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;hw/ppc/spapr_cpu_core.c +1
-1@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } -icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { goto error; }
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 01/25] ppc/xics: introduce an icp_create() helper
In reply to Cédric Le GoaterQuoted 5 lines · Cédric Le Goater
The sPAPR and the PowerNV core objects create the interrupt presenter object of the CPUs in a very similar way. Let's provide a common routine in which we use the presenter 'type' as a child identifier.
Signed-off-by Cédric Le Goater <[email protected]>
One tiny nit.., apart from that
Quoted 12 lines
--- hw/intc/xics.c | 22 ++++++++++++++++++++++ hw/ppc/pnv_core.c | 10 +--------- hw/ppc/spapr_cpu_core.c | 13 ++----------- include/hw/ppc/xics.h | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-)hw/intc/xics.c +0
-0
hw/intc/xics.c static const TypeInfo icp_info = { · line 389
Quoted 6 lines
hw/intc/xics.c +3
-0@@ -384,6 +384,28 @@ static const TypeInfo icp_info = { .class_size = sizeof(ICPStateClass), }; +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi,Error **errp) +{ +Object *child =OBJECT (cs);
In the original context 'child' made sense, since it was the child object of the core. Here, it's misleading, since it's the parent of the xics link. It's only used in a couple of places, so I suggest you just opencode OBJECT(cs) in each place.
Quoted 105 lines
hw/intc/xics.c +19
-0+Error *local_err =NULL ; +Object *obj; + + obj =object_new (type); +object_property_add_child (child, type, obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), + &error_abort); +object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); + obj =NULL ; + } + +return obj; +} +/* * ICS: Source layer */ hw/ppc/pnv_core.c +1
-9@@ -126,7 +126,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -134,13 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (child,"icp" , obj,NULL ); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;@@ -148,7 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)powernv_cpu_init (cpu, &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }hw/ppc/spapr_cpu_core.c +2
-11@@ -111,7 +111,6 @@ static void spapr_cpu_core_realize_child(Object *child,Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -123,21 +122,13 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - obj =object_new (spapr->icp_type); -object_property_add_child (child,"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (spapr), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { - goto free_icp; + goto error; }return ; -free_icp: -object_unparent (obj); error:error_propagate (errp, local_err); }include/hw/ppc/xics.h +3
-0@@ -212,4 +212,7 @@ typedef struct sPAPRMachineState sPAPRMachineState;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp);void xics_spapr_init (sPAPRMachineState *spapr); +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi, +Error **errp); +#endif /* XICS_H */
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 05/25] spapr: introduce a spapr_irq_set() helper
In reply to Cédric Le GoaterQuoted 4 lines · Cédric Le Goater
It will make synchronisation easier with the XIVE interrupt mode when available. The 'irq' parameter refers to the global IRQ number space.
Signed-off-by Cédric Le Goater <[email protected]>
s/spapr_irq_set/spapr_irq_set_lsi/
otherwise the name doesn't tell you what it sets.
With that change,
Quoted 42 lines
--- hw/ppc/spapr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)hw/ppc/spapr.c +8
-3@@ -3594,6 +3594,11 @@ static int ics_find_free_block(ICSState *ics, int num, int alignnum)return -1 ; } +static void spapr_irq_set (sPAPRMachineState *spapr,int irq,bool lsi) +{ +ics_set_irq_type (spapr->ics, irq - spapr->ics->offset, lsi); +} +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi,Error **errp) {@@ -3618,7 +3623,7 @@ int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi, irq += ics->offset; } -ics_set_irq_type (ics, irq - ics->offset, lsi); +spapr_irq_set (spapr, irq, lsi);trace_spapr_irq_alloc (irq);return irq;@@ -3657,10 +3662,10 @@ int spapr_irq_alloc_block(sPAPRMachineState *spapr, int num, bool lsi,return -1 ; } + first += ics->offset;for (i = first; i < first + num; ++i) { -ics_set_irq_type (ics, i, lsi); +spapr_irq_set (spapr, i, lsi); } - first += ics->offset;trace_spapr_irq_alloc_block (first, num, lsi, align);
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 06/25] spapr: introduce a spapr_irq_get_qirq() helper
In reply to Cédric Le GoaterQuoted 5 lines · Cédric Le Goater
xics_get_qirq()is only used by the sPAPR machine. Let's move it there and change its name to reflect its scope. It will be useful for XIVE support which will use its own set of qirqs.Signed-off-by Cédric Le Goater <[email protected]>
s/spapr_irq_get_qirq/spapr_qirq/
for brevity
With that change
Quoted 155 lines
--- hw/intc/xics.c | 12 ------------ hw/ppc/spapr.c | 11 +++++++++++ hw/ppc/spapr_events.c | 12 +++++------- hw/ppc/spapr_pci.c | 2 +- include/hw/pci-host/spapr.h | 2 +- include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_vio.h | 2 +- include/hw/ppc/xics.h | 1 - 8 files changed, 20 insertions(+), 23 deletions(-)hw/intc/xics.c +0
-12@@ -714,18 +714,6 @@ static const TypeInfo xics_fabric_info = {/* * Exported functions */ -qemu_irq xics_get_qirq (XICSFabric *xi,int irq) -{ -XICSFabricClass *xic =XICS_FABRIC_GET_CLASS (xi); -ICSState *ics = xic->ics_get (xi, irq); - -if (ics) { -return ics->qirqs[irq - ics->offset]; - } - -return NULL ; -} -ICPState *xics_icp_get (XICSFabric *xi,int server) {XICSFabricClass *xic =XICS_FABRIC_GET_CLASS (xi);hw/ppc/spapr.c +11
-0@@ -3689,6 +3689,17 @@ void spapr_irq_free(sPAPRMachineState *spapr, int irq, int num) } } +qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq) +{ +ICSState *ics = spapr->ics; + +if (ics_valid_irq (ics, irq)) { +return ics->qirqs[irq - ics->offset]; + } + +return NULL ; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_events.c +5
-7@@ -472,9 +472,8 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)rtas_event_log_queue (spapr, entry); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), -rtas_event_log_to_irq (spapr, -RTAS_LOG_TYPE_EPOW ))); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, +rtas_event_log_to_irq (spapr,RTAS_LOG_TYPE_EPOW ))); } static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,@@ -556,9 +555,8 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,rtas_event_log_queue (spapr, entry); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), -rtas_event_log_to_irq (spapr, -RTAS_LOG_TYPE_HOTPLUG ))); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, +rtas_event_log_to_irq (spapr,RTAS_LOG_TYPE_HOTPLUG ))); }void spapr_hotplug_req_add_by_index (sPAPRDRConnector *drc)@@ -678,7 +676,7 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMachineState *spapr,spapr_event_sources_get_source (spapr->event_sources, i);g_assert (source->enabled); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), source->irq)); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, source->irq)); } }hw/ppc/spapr_pci.c +1
-1@@ -723,7 +723,7 @@ static void spapr_msi_write(void *opaque, hwaddr addr,trace_spapr_pci_msi_write (addr, data, irq); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), irq)); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, irq)); }static const MemoryRegionOps spapr_msi_ops = {include/hw/pci-host/spapr.h +1
-1@@ -108,7 +108,7 @@ static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); -return xics_get_qirq (XICS_FABRIC (spapr), phb->lsi_table[pin].irq); +return spapr_irq_get_qirq (spapr, phb->lsi_table[pin].irq); }PCIHostState *spapr_create_phb (sPAPRMachineState *spapr,int index);include/hw/ppc/spapr.h +1
-0@@ -714,5 +714,6 @@ int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi,int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi,bool align,Error **errp);void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num); +qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq);#endif /* HW_SPAPR_H */ include/hw/ppc/spapr_vio.h +1
-1@@ -87,7 +87,7 @@ static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); -return xics_get_qirq (XICS_FABRIC (spapr), dev->irq); +return spapr_irq_get_qirq (spapr, dev->irq); } static inline bool spapr_vio_dma_valid(VIOsPAPRDevice *dev, uint64_t taddr,include/hw/ppc/xics.h +0
-1@@ -183,7 +183,6 @@ typedef struct XICSFabricClass {void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle); -qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server);/* Internal XICS interfaces */
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 04/25] spapr: move the IRQ allocation routines under the machine
In reply to Cédric Le GoaterQuoted 5 lines · Cédric Le Goater
Also change the prototype to use a sPAPRMachineState and prefix them with
spapr_irq_. It will let us synchronise the IRQ allocation with the XIVE interrupt mode when available.Signed-off-by Cédric Le Goater <[email protected]>
Quoted 397 lines
--- hw/intc/trace-events | 4 -- hw/intc/xics_spapr.c | 114 ------------------------------------------------- hw/ppc/spapr.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 4 +- hw/ppc/spapr_pci.c | 8 ++-- hw/ppc/spapr_vio.c | 2 +- hw/ppc/trace-events | 4 ++ include/hw/ppc/spapr.h | 6 +++ include/hw/ppc/xics.h | 4 -- 9 files changed, 131 insertions(+), 129 deletions(-)hw/intc/trace-events +0
-4@@ -64,10 +64,6 @@ xics_ics_simple_set_irq_lsi(int srcno, int nr) "set_irq_lsi: srcno %d [irq 0x%x] xics_ics_simple_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_xive: irq 0x%x [src %d] server 0x%x prio 0x%x" xics_ics_simple_reject(int nr, int srcno) "reject irq 0x%x [src %d]" xics_ics_simple_eoi(int nr) "ics_eoi: irq 0x%x" -xics_alloc(int irq) "irq %d" -xics_alloc_block(int first, int num, bool lsi, int align) "first irq %d, %d irqs, lsi=%d, alignnum %d" -xics_ics_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs" -xics_ics_free_warn(int src, int irq) "Source#%d, irq %d is already free" # hw/intc/s390_flic_kvm.c flic_create_device(int err) "flic: create device failed %d"hw/intc/xics_spapr.c +0
-114@@ -245,120 +245,6 @@ void xics_spapr_init(sPAPRMachineState *spapr)spapr_register_hypercall (H_IPOLL , h_ipoll); } -#define ICS_IRQ_FREE (ics, srcno) \ - (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_MASK))) - -static int ics_find_free_block (ICSState *ics,int num,int alignnum) -{ -int first, i; - -for (first =0 ; first < ics->nr_irqs; first += alignnum) { -if (num > (ics->nr_irqs - first)) { -return -1 ; - } -for (i = first; i < first + num; ++i) { -if (!ICS_IRQ_FREE (ics, i)) { -break ; - } - } -if (i == (first + num)) { -return first; - } - } - -return -1 ; -} - -int spapr_ics_alloc (ICSState *ics,int irq_hint,bool lsi,Error **errp) -{ -int irq; - -if (!ics) { -return -1 ; - } -if (irq_hint) { -if (!ICS_IRQ_FREE (ics, irq_hint - ics->offset)) { -error_setg (errp,"can't allocate IRQ %d: already in use" , irq_hint); -return -1 ; - } - irq = irq_hint; - }else { - irq =ics_find_free_block (ics,1 ,1 ); -if (irq <0 ) { -error_setg (errp,"can't allocate IRQ: no IRQ left" ); -return -1 ; - } - irq += ics->offset; - } - -ics_set_irq_type (ics, irq - ics->offset, lsi); -trace_xics_alloc (irq); - -return irq; -} - -/* -* Allocate block of consecutive IRQs, and return the number of the first IRQ in -* the block. If align==true, aligns the first IRQ number to num. -*/ -int spapr_ics_alloc_block (ICSState *ics,int num,bool lsi, -bool align,Error **errp) -{ -int i, first =-1 ; - -if (!ics) { -return -1 ; - } - -/* -* MSIMesage::data is used for storing VIRQ so -* it has to be aligned to num to support multiple -* MSI vectors. MSI-X is not affected by this. -* The hint is used for the first IRQ, the rest should -* be allocated continuously. -*/ -if (align) { -assert ((num ==1 ) || (num ==2 ) || (num ==4 ) || - (num ==8 ) || (num ==16 ) || (num ==32 )); - first =ics_find_free_block (ics, num, num); - }else { - first =ics_find_free_block (ics, num,1 ); - } -if (first <0 ) { -error_setg (errp,"can't find a free %d-IRQ block" , num); -return -1 ; - } - -for (i = first; i < first + num; ++i) { -ics_set_irq_type (ics, i, lsi); - } - first += ics->offset; - -trace_xics_alloc_block (first, num, lsi, align); - -return first; -} - -static void ics_free (ICSState *ics,int srcno,int num) -{ -int i; - -for (i = srcno; i < srcno + num; ++i) { -if (ICS_IRQ_FREE (ics, i)) { -trace_xics_ics_free_warn (0 , i + ics->offset); - } -memset (&ics->irqs[i],0 ,sizeof (ICSIRQState)); - } -} - -void spapr_ics_free (ICSState *ics,int irq,int num) -{ -if (ics_valid_irq (ics, irq)) { -trace_xics_ics_free (0 , irq, num); -ics_free (ics, irq - ics->offset, num); - } -} -void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle) {uint32_t interrupt_server_ranges_prop[] = {hw/ppc/spapr.c +114
-0@@ -3570,6 +3570,120 @@ Object *spapr_icp_create(sPAPRMachineState *spapr, CPUState *cs, Error **errp)return obj; } +#define ICS_IRQ_FREE (ics, srcno) \ + (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_MASK))) + +static int ics_find_free_block (ICSState *ics,int num,int alignnum) +{ +int first, i; + +for (first =0 ; first < ics->nr_irqs; first += alignnum) { +if (num > (ics->nr_irqs - first)) { +return -1 ; + } +for (i = first; i < first + num; ++i) { +if (!ICS_IRQ_FREE (ics, i)) { +break ; + } + } +if (i == (first + num)) { +return first; + } + } + +return -1 ; +} + +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi, +Error **errp) +{ +ICSState *ics = spapr->ics; +int irq; + +if (!ics) { +return -1 ; + } +if (irq_hint) { +if (!ICS_IRQ_FREE (ics, irq_hint - ics->offset)) { +error_setg (errp,"can't allocate IRQ %d: already in use" , irq_hint); +return -1 ; + } + irq = irq_hint; + }else { + irq =ics_find_free_block (ics,1 ,1 ); +if (irq <0 ) { +error_setg (errp,"can't allocate IRQ: no IRQ left" ); +return -1 ; + } + irq += ics->offset; + } + +ics_set_irq_type (ics, irq - ics->offset, lsi); +trace_spapr_irq_alloc (irq); + +return irq; +} + +/* +* Allocate block of consecutive IRQs, and return the number of the first IRQ in +* the block. If align==true, aligns the first IRQ number to num. +*/ +int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi, +bool align,Error **errp) +{ +ICSState *ics = spapr->ics; +int i, first =-1 ; + +if (!ics) { +return -1 ; + } + +/* +* MSIMesage::data is used for storing VIRQ so +* it has to be aligned to num to support multiple +* MSI vectors. MSI-X is not affected by this. +* The hint is used for the first IRQ, the rest should +* be allocated continuously. +*/ +if (align) { +assert ((num ==1 ) || (num ==2 ) || (num ==4 ) || + (num ==8 ) || (num ==16 ) || (num ==32 )); + first =ics_find_free_block (ics, num, num); + }else { + first =ics_find_free_block (ics, num,1 ); + } +if (first <0 ) { +error_setg (errp,"can't find a free %d-IRQ block" , num); +return -1 ; + } + +for (i = first; i < first + num; ++i) { +ics_set_irq_type (ics, i, lsi); + } + first += ics->offset; + +trace_spapr_irq_alloc_block (first, num, lsi, align); + +return first; +} + +void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num) +{ +ICSState *ics = spapr->ics; +int srcno = irq - ics->offset; +int i; + +if (ics_valid_irq (ics, irq)) { +trace_spapr_irq_free (0 , irq, num); +for (i = srcno; i < srcno + num; ++i) { +if (ICS_IRQ_FREE (ics, i)) { +trace_spapr_irq_free_warn (0 , i + ics->offset); + } +memset (&ics->irqs[i],0 ,sizeof (ICSIRQState)); + } + } +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_events.c +2
-2@@ -718,7 +718,7 @@ void spapr_events_init(sPAPRMachineState *spapr) spapr->event_sources =spapr_event_sources_new ();spapr_event_sources_register (spapr->event_sources,EVENT_CLASS_EPOW , -spapr_ics_alloc (spapr->ics,0 , false, +spapr_irq_alloc (spapr,0 , false, &error_fatal));/* NOTE: if machine supports modern/dedicated hotplug event source, @@ -731,7 +731,7 @@ void spapr_events_init(sPAPRMachineState *spapr)*/ if (spapr->use_hotplug_event_source) {spapr_event_sources_register (spapr->event_sources,EVENT_CLASS_HOT_PLUG , -spapr_ics_alloc (spapr->ics,0 , false, +spapr_irq_alloc (spapr,0 , false, &error_fatal)); }hw/ppc/spapr_pci.c +4
-4@@ -314,7 +314,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,return ; } -spapr_ics_free (spapr->ics, msi->first_irq, msi->num); +spapr_irq_free (spapr, msi->first_irq, msi->num);if (msi_present (pdev)) {spapr_msi_setmsg (pdev,0 , false,0 ,0 ); }@@ -352,7 +352,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr, }/* Allocate MSIs */ - irq =spapr_ics_alloc_block (spapr->ics, req_num, false, + irq =spapr_irq_alloc_block (spapr, req_num, false, ret_intr_type ==RTAS_TYPE_MSI , &err);if (err) { error_reportf_err(err, "Can't allocate MSIs for device %x: ",@@ -363,7 +363,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,/* Release previous MSIs */ if (msi) { -spapr_ics_free (spapr->ics, msi->first_irq, msi->num); +spapr_irq_free (spapr, msi->first_irq, msi->num);g_hash_table_remove (phb->msi, &config_addr); }@@ -1675,7 +1675,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)uint32_t irq;Error *local_err =NULL ; - irq =spapr_ics_alloc_block (spapr->ics,1 , true, false, &local_err); + irq =spapr_irq_alloc_block (spapr,1 , true, false, &local_err);if (local_err) {error_propagate (errp, local_err);error_prepend (errp,"can't allocate LSIs: " );hw/ppc/spapr_vio.c +1
-1@@ -454,7 +454,7 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp) dev->qdev.id = id; } - dev->irq =spapr_ics_alloc (spapr->ics, dev->irq, false, &local_err); + dev->irq =spapr_irq_alloc (spapr, dev->irq, false, &local_err);if (local_err) {error_propagate (errp, local_err);return ;hw/ppc/trace-events +4
-0@@ -12,6 +12,10 @@ spapr_pci_msi_retry(unsigned config_addr, unsigned req_num, unsigned max_irqs) " # hw/ppc/spapr.c spapr_cas_failed(unsigned long n) "DT diff buffer is too small: %ld bytes" spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes" +spapr_irq_alloc(int irq) "irq %d" +spapr_irq_alloc_block(int first, int num, bool lsi, int align) "first irq %d, %d irqs, lsi=%d, alignnum %d" +spapr_irq_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs" +spapr_irq_free_warn(int src, int irq) "Source#%d, irq %d is already free" # hw/ppc/spapr_hcall.c spapr_cas_pvr_try(uint32_t pvr) "0x%x"include/hw/ppc/spapr.h +6
-0@@ -709,4 +709,10 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id);Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi, +Error **errp); +int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi, +bool align,Error **errp); +void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num); +#endif /* HW_SPAPR_H */ include/hw/ppc/xics.h +0
-4@@ -181,10 +181,6 @@ typedef struct XICSFabricClass {#define XICS_IRQS_SPAPR 1024 -int spapr_ics_alloc (ICSState *ics,int irq_hint,bool lsi,Error **errp); -int spapr_ics_alloc_block (ICSState *ics,int num,bool lsi,bool align, -Error **errp); -void spapr_ics_free (ICSState *ics,int irq,int num);void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 01/25] ppc/xics: introduce an icp_create() helper
In reply to David GibsonQuoted 26 lines · David Gibson
Quoted 5 lines · Cédric Le Goater
The sPAPR and the PowerNV core objects create the interrupt presenter object of the CPUs in a very similar way. Let's provide a common routine in which we use the presenter 'type' as a child identifier.
Signed-off-by Cédric Le Goater <[email protected]>One tiny nit.., apart from that
Reviewed-by David Gibson <[email protected]>Quoted 15 lines
--- hw/intc/xics.c | 22 ++++++++++++++++++++++ hw/ppc/pnv_core.c | 10 +--------- hw/ppc/spapr_cpu_core.c | 13 ++----------- include/hw/ppc/xics.h | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-)hw/intc/xics.c +0
-0@@ -384,6 +384,28 @@ static const TypeInfo icp_info = { .class_size = sizeof(ICPStateClass), };
Quoted 8 lines
hw/intc/xics.c static const TypeInfo icp_info = { · line 389
Quoted 3 lines
hw/intc/xics.c +3
-0+Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi,Error **errp) +{ +Object *child =OBJECT (cs);In the original context 'child' made sense, since it was the child object of the core. Here, it's misleading, since it's the parent of the xics link. It's only used in a couple of places, so I suggest you just opencode OBJECT(cs) in each place.
yes. That was a left over from the copy-paste.
Thanks,
C.
Quoted 106 lines
Quoted 105 lines
hw/intc/xics.c +19
-0+Error *local_err =NULL ; +Object *obj; + + obj =object_new (type); +object_property_add_child (child, type, obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), + &error_abort); +object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); + obj =NULL ; + } + +return obj; +} +/* * ICS: Source layer */ hw/ppc/pnv_core.c +1
-9@@ -126,7 +126,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -134,13 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (child,"icp" , obj,NULL ); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;@@ -148,7 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)powernv_cpu_init (cpu, &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }hw/ppc/spapr_cpu_core.c +2
-11@@ -111,7 +111,6 @@ static void spapr_cpu_core_realize_child(Object *child,Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -123,21 +122,13 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - obj =object_new (spapr->icp_type); -object_property_add_child (child,"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (spapr), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { - goto free_icp; + goto error; }return ; -free_icp: -object_unparent (obj); error:error_propagate (errp, local_err); }include/hw/ppc/xics.h +3
-0@@ -212,4 +212,7 @@ typedef struct sPAPRMachineState sPAPRMachineState;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp);void xics_spapr_init (sPAPRMachineState *spapr); +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi, +Error **errp); +#endif /* XICS_H */
Re: [Qemu-devel] [PATCH 06/25] spapr: introduce a spapr_irq_get_qirq() helper
In reply to David GibsonQuoted 10 lines · David Gibson
Quoted 5 lines · Cédric Le Goater
xics_get_qirq()is only used by the sPAPR machine. Let's move it there and change its name to reflect its scope. It will be useful for XIVE support which will use its own set of qirqs.Signed-off-by Cédric Le Goater <[email protected]>s/spapr_irq_get_qirq/spapr_qirq/
for brevity
Sure.
Quoted 3 lines
With that change
Reviewed-by David Gibson <[email protected]>
Thanks,
C.
Quoted 156 lines
Quoted 155 lines
--- hw/intc/xics.c | 12 ------------ hw/ppc/spapr.c | 11 +++++++++++ hw/ppc/spapr_events.c | 12 +++++------- hw/ppc/spapr_pci.c | 2 +- include/hw/pci-host/spapr.h | 2 +- include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_vio.h | 2 +- include/hw/ppc/xics.h | 1 - 8 files changed, 20 insertions(+), 23 deletions(-)hw/intc/xics.c +0
-12@@ -714,18 +714,6 @@ static const TypeInfo xics_fabric_info = {/* * Exported functions */ -qemu_irq xics_get_qirq (XICSFabric *xi,int irq) -{ -XICSFabricClass *xic =XICS_FABRIC_GET_CLASS (xi); -ICSState *ics = xic->ics_get (xi, irq); - -if (ics) { -return ics->qirqs[irq - ics->offset]; - } - -return NULL ; -} -ICPState *xics_icp_get (XICSFabric *xi,int server) {XICSFabricClass *xic =XICS_FABRIC_GET_CLASS (xi);hw/ppc/spapr.c +11
-0@@ -3689,6 +3689,17 @@ void spapr_irq_free(sPAPRMachineState *spapr, int irq, int num) } } +qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq) +{ +ICSState *ics = spapr->ics; + +if (ics_valid_irq (ics, irq)) { +return ics->qirqs[irq - ics->offset]; + } + +return NULL ; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_events.c +5
-7@@ -472,9 +472,8 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)rtas_event_log_queue (spapr, entry); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), -rtas_event_log_to_irq (spapr, -RTAS_LOG_TYPE_EPOW ))); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, +rtas_event_log_to_irq (spapr,RTAS_LOG_TYPE_EPOW ))); } static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,@@ -556,9 +555,8 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,rtas_event_log_queue (spapr, entry); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), -rtas_event_log_to_irq (spapr, -RTAS_LOG_TYPE_HOTPLUG ))); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, +rtas_event_log_to_irq (spapr,RTAS_LOG_TYPE_HOTPLUG ))); }void spapr_hotplug_req_add_by_index (sPAPRDRConnector *drc)@@ -678,7 +676,7 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMachineState *spapr,spapr_event_sources_get_source (spapr->event_sources, i);g_assert (source->enabled); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), source->irq)); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, source->irq)); } }hw/ppc/spapr_pci.c +1
-1@@ -723,7 +723,7 @@ static void spapr_msi_write(void *opaque, hwaddr addr,trace_spapr_pci_msi_write (addr, data, irq); -qemu_irq_pulse (xics_get_qirq (XICS_FABRIC (spapr), irq)); +qemu_irq_pulse (spapr_irq_get_qirq (spapr, irq)); }static const MemoryRegionOps spapr_msi_ops = {include/hw/pci-host/spapr.h +1
-1@@ -108,7 +108,7 @@ static inline qemu_irq spapr_phb_lsi_qirq(struct sPAPRPHBState *phb, int pin) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); -return xics_get_qirq (XICS_FABRIC (spapr), phb->lsi_table[pin].irq); +return spapr_irq_get_qirq (spapr, phb->lsi_table[pin].irq); }PCIHostState *spapr_create_phb (sPAPRMachineState *spapr,int index);include/hw/ppc/spapr.h +1
-0@@ -714,5 +714,6 @@ int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi,int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi,bool align,Error **errp);void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num); +qemu_irq spapr_irq_get_qirq (sPAPRMachineState *spapr,int irq);#endif /* HW_SPAPR_H */ include/hw/ppc/spapr_vio.h +1
-1@@ -87,7 +87,7 @@ static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev) {sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); -return xics_get_qirq (XICS_FABRIC (spapr), dev->irq); +return spapr_irq_get_qirq (spapr, dev->irq); } static inline bool spapr_vio_dma_valid(VIOsPAPRDevice *dev, uint64_t taddr,include/hw/ppc/xics.h +0
-1@@ -183,7 +183,6 @@ typedef struct XICSFabricClass {void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle); -qemu_irq xics_get_qirq (XICSFabric *xi,int irq);ICPState *xics_icp_get (XICSFabric *xi,int server);/* Internal XICS interfaces */
Re: [Qemu-devel] [PATCH 13/25] spapr: introduce the XIVE Event Queues
In reply to Benjamin HerrenschmidtQuoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
The Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is one of the internal tables the XIVE interrupt controller uses to redirect exception from event sources to CPU threads.
Keep in mind tha we want to only expose to the guest priorities 0..6 as priority 7 will not be available with KVM on DD2.0 chips.
The hcall patch 19 introduces the "ibm,plat-res-int-priorities" property. The priority ranges reserved by the hypervisor are the following :
static const uint32_t reserved_priorities[] = {
7, /* start */
0xf8, /* count */
};So The Linux driver is expected to choose priority 6. The priority validity is then checked in each hcall returning H_P4/H_P3 in case of failure.
But it is true that we scale the arrays with :
#define XIVE_PRIORITY_MAX 7
Do you want QEMU to completely remove prio 7 ?
C.
Quoted 190 lines
Quoted 190 lines
The EQD specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which server (VPD in XIVE terminology) to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
There is one XiveEQ per priority and the model chooses to store them under the Xive Interrupt presenter model. It will be retrieved, just like for XICS, through the 'intc' object pointer of the CPU.
The EQ indexing follows a simple pattern:
(server << 3) | (priority & 0x7)Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+)hw/intc/spapr_xive.c +56
-0@@ -23,6 +23,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h" @@ -34,6 +35,8 @@ struct sPAPRXiveICP {uint8_t tima[TM_RING_COUNT *0x10 ];uint8_t *tima_os;qemu_irq output; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp)@@ -183,6 +186,13 @@ static const MemoryRegionOps spapr_xive_tm_ops = { }, }; +static sPAPRXiveICP *spapr_xive_icp_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -632,6 +642,8 @@ static void spapr_xive_icp_reset(void *dev)sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev);memset (xicp->tima,0 ,sizeof (xicp->tima)); + +memset (xicp->eqt,0 ,sizeof (xicp->eqt)); }static void spapr_xive_icp_realize (DeviceState *dev,Error **errp)@@ -683,6 +695,23 @@ static void spapr_xive_icp_init(Object *obj) xicp->tima_os = &xicp->tima[TM_QW1_OS ]; } +static const VMStateDescription vmstate_spapr_xive_icp_eq = { + .name =TYPE_SPAPR_XIVE_ICP "/eq" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ), +VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_icp_needed (void *opaque) {/* TODO check machine XIVE support */ @@ -696,6 +725,8 @@ static const VMStateDescription vmstate_spapr_xive_icp = { .needed = vmstate_spapr_xive_icp_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveICP, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_icp_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };@@ -755,3 +786,28 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) ive->w &= ~IVE_VALID ;return true; } + +/* +* Use a simple indexing for the EQs. +*/ +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t eq_idx) +{ +int priority = eq_idx &0x7 ; +sPAPRXiveICP *xicp =spapr_xive_icp_get (xive, eq_idx >>3 ); + +return xicp ? &xicp->eqt[priority] :NULL ; +} + +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server, +uint8_t priority,uint32_t *out_eq_idx) +{ +if (priority >XIVE_PRIORITY_MAX ) { +return false; + } + +if (out_eq_idx) { + *out_eq_idx = (server <<3 ) | (priority &0x7 ); + } + +return true; +}hw/intc/xive-internal.h +50
-0@@ -131,9 +131,59 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +/* EQ */ +typedef struct XiveEQ { +uint32_t w0; +#define EQ_W0_VALID PPC_BIT32(0) +#define EQ_W0_ENQUEUE PPC_BIT32(1) +#define EQ_W0_UCOND_NOTIFY PPC_BIT32(2) +#define EQ_W0_BACKLOG PPC_BIT32(3) +#define EQ_W0_PRECL_ESC_CTL PPC_BIT32(4) +#define EQ_W0_ESCALATE_CTL PPC_BIT32(5) +#define EQ_W0_END_OF_INTR PPC_BIT32(6) +#define EQ_W0_QSIZE PPC_BITMASK32(12, 15) +#define EQ_W0_SW0 PPC_BIT32(16) +#define EQ_W0_FIRMWARE EQ_W0_SW0/* Owned by FW */ +#define EQ_QSIZE_4K 0 +#define EQ_QSIZE_64K 4 +#define EQ_W0_HWDEP PPC_BITMASK32(24, 31) +uint32_t w1; +#define EQ_W1_ESn PPC_BITMASK32(0, 1) +#define EQ_W1_ESn_P PPC_BIT32(0) +#define EQ_W1_ESn_Q PPC_BIT32(1) +#define EQ_W1_ESe PPC_BITMASK32(2, 3) +#define EQ_W1_ESe_P PPC_BIT32(2) +#define EQ_W1_ESe_Q PPC_BIT32(3) +#define EQ_W1_GENERATION PPC_BIT32(9) +#define EQ_W1_PAGE_OFF PPC_BITMASK32(10, 31) +uint32_t w2; +#define EQ_W2_MIGRATION_REG PPC_BITMASK32(0, 3) +#define EQ_W2_OP_DESC_HI PPC_BITMASK32(4, 31) +uint32_t w3; +#define EQ_W3_OP_DESC_LO PPC_BITMASK32(0, 31) +uint32_t w4; +#define EQ_W4_ESC_EQ_BLOCK PPC_BITMASK32(4, 7) +#define EQ_W4_ESC_EQ_INDEX PPC_BITMASK32(8, 31) +uint32_t w5; +#define EQ_W5_ESC_EQ_DATA PPC_BITMASK32(1, 31) +uint32_t w6; +#define EQ_W6_FORMAT_BIT PPC_BIT32(8) +#define EQ_W6_NVT_BLOCK PPC_BITMASK32(9, 12) +#define EQ_W6_NVT_INDEX PPC_BITMASK32(13, 31) +uint32_t w7; +#define EQ_W7_F0_IGNORE PPC_BIT32(0) +#define EQ_W7_F0_BLK_GROUPING PPC_BIT32(1) +#define EQ_W7_F0_PRIORITY PPC_BITMASK32(8, 15) +#define EQ_W7_F1_WAKEZ PPC_BIT32(0) +#define EQ_W7_F1_LOG_SERVER_ID PPC_BITMASK32(1, 31) +}XiveEQ ; +#define XIVE_PRIORITY_MAX 7void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t idx); +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server,uint8_t prio, +uint32_t *out_eq_idx);#endif /* _INTC_XIVE_INTERNAL_H */
Re: [Qemu-devel] [PATCH 05/25] spapr: introduce a spapr_irq_set() helper
In reply to David GibsonQuoted 9 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
It will make synchronisation easier with the XIVE interrupt mode when available. The 'irq' parameter refers to the global IRQ number space.
Signed-off-by Cédric Le Goater <[email protected]>s/spapr_irq_set/spapr_irq_set_lsi/
otherwise the name doesn't tell you what it sets.
That is when it gets confusing. This routine does two things :
- it allocates the IRQ number
- it sets the type of the allocated IRQ number, LSI or MSI.
because both information are held under the same flag :
ics->irqs[srcno].flags
But the main purpose of this routine is to do the allocation, so that is why I changed the name.
Now that you have the explanations and that you rather still have the prefix '_lsi', please tell me. In any case, I will add a comment on what the routine is doing.
Thanks,
C.
Quoted 47 lines
With that change,
Reviewed-by David Gibson <[email protected]>Quoted 42 lines
--- hw/ppc/spapr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)hw/ppc/spapr.c +8
-3@@ -3594,6 +3594,11 @@ static int ics_find_free_block(ICSState *ics, int num, int alignnum)return -1 ; } +static void spapr_irq_set (sPAPRMachineState *spapr,int irq,bool lsi) +{ +ics_set_irq_type (spapr->ics, irq - spapr->ics->offset, lsi); +} +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi,Error **errp) {@@ -3618,7 +3623,7 @@ int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi, irq += ics->offset; } -ics_set_irq_type (ics, irq - ics->offset, lsi); +spapr_irq_set (spapr, irq, lsi);trace_spapr_irq_alloc (irq);return irq;@@ -3657,10 +3662,10 @@ int spapr_irq_alloc_block(sPAPRMachineState *spapr, int num, bool lsi,return -1 ; } + first += ics->offset;for (i = first; i < first + num; ++i) { -ics_set_irq_type (ics, i, lsi); +spapr_irq_set (spapr, i, lsi); } - first += ics->offset;trace_spapr_irq_alloc_block (first, num, lsi, align);
Re: [Qemu-devel] [Qemu-ppc] [PATCH 01/25] ppc/xics: introduce an icp_create() helper
In reply to Cédric Le GoaterQuoted 6 lines · On Thu, 23 Nov 2017 14:29:31 +0100 Cédric Le Goater <[email protected]> wrote:
The sPAPR and the PowerNV core objects create the interrupt presenter object of the CPUs in a very similar way. Let's provide a common routine in which we use the presenter 'type' as a child identifier.
Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 122 lines
hw/intc/xics.c | 22 ++++++++++++++++++++++ hw/ppc/pnv_core.c | 10 +--------- hw/ppc/spapr_cpu_core.c | 13 ++----------- include/hw/ppc/xics.h | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-)hw/intc/xics.c +22
-0@@ -384,6 +384,28 @@ static const TypeInfo icp_info = { .class_size = sizeof(ICPStateClass), }; +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi,Error **errp) +{ +Object *child =OBJECT (cs); +Error *local_err =NULL ; +Object *obj; + + obj =object_new (type); +object_property_add_child (child, type, obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), + &error_abort); +object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); + obj =NULL ; + } + +return obj; +} +/* * ICS: Source layer */ hw/ppc/pnv_core.c +1
-9@@ -126,7 +126,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -134,13 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (child,"icp" , obj,NULL ); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;@@ -148,7 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)powernv_cpu_init (cpu, &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }hw/ppc/spapr_cpu_core.c +2
-11@@ -111,7 +111,6 @@ static void spapr_cpu_core_realize_child(Object *child,Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -123,21 +122,13 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - obj =object_new (spapr->icp_type); -object_property_add_child (child,"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (spapr), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { - goto free_icp; + goto error; }return ; -free_icp: -object_unparent (obj); error:error_propagate (errp, local_err); }include/hw/ppc/xics.h +3
-0@@ -212,4 +212,7 @@ typedef struct sPAPRMachineState sPAPRMachineState;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp);void xics_spapr_init (sPAPRMachineState *spapr); +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi, +Error **errp); +#endif /* XICS_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH 02/25] ppc/xics: assign of the CPU 'intc' pointer under the core
In reply to Cédric Le GoaterQuoted 8 lines · On Thu, 23 Nov 2017 14:29:32 +0100 Cédric Le Goater <[email protected]> wrote:
The 'intc' pointer of the CPU references the interrupt presenter in the XICS interrupt mode. When the XIVE interrupt mode is available and activated, the machine will need to reassign this pointer to reflect the change.
Moving this assignment under the realize routine of the CPU will ease the process when the interrupt mode is toggled.
No surprise since this was violating CPU internals actually :)
Quoted 2 lines
Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 43 lines
hw/intc/xics.c | 1 - hw/ppc/pnv_core.c | 2 +- hw/ppc/spapr_cpu_core.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)hw/intc/xics.c +0
-1@@ -334,7 +334,6 @@ static void icp_realize(DeviceState *dev, Error **errp) } cpu =POWERPC_CPU (obj); - cpu->intc =OBJECT (icp); icp->cs =CPU (obj); env = &cpu->env;hw/ppc/pnv_core.c +1
-1@@ -133,7 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } -icp_create (cs,TYPE_PNV_ICP , xi, &local_err); + cpu->intc =icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;hw/ppc/spapr_cpu_core.c +1
-1@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } -icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { goto error; }
Re: [Qemu-devel] [Qemu-ppc] [PATCH 01/25] ppc/xics: introduce an icp_create() helper
In reply to David GibsonQuoted 26 lines · On Fri, 24 Nov 2017 13:51:00 +1100 David Gibson <[email protected]>…
Quoted 5 lines · Cédric Le Goater
The sPAPR and the PowerNV core objects create the interrupt presenter object of the CPUs in a very similar way. Let's provide a common routine in which we use the presenter 'type' as a child identifier.
Signed-off-by Cédric Le Goater <[email protected]>One tiny nit.., apart from that
Reviewed-by David Gibson <[email protected]>Quoted 15 lines
--- hw/intc/xics.c | 22 ++++++++++++++++++++++ hw/ppc/pnv_core.c | 10 +--------- hw/ppc/spapr_cpu_core.c | 13 ++----------- include/hw/ppc/xics.h | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-)hw/intc/xics.c +0
-0@@ -384,6 +384,28 @@ static const TypeInfo icp_info = { .class_size = sizeof(ICPStateClass), };
Quoted 7 lines
hw/intc/xics.c static const TypeInfo icp_info = { · line 389
Quoted 3 lines
hw/intc/xics.c +3
-0+Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi,Error **errp) +{ +Object *child =OBJECT (cs);In the original context 'child' made sense, since it was the child object of the core. Here, it's misleading, since it's the parent of the xics link. It's only used in a couple of places, so I suggest you
Oops yes :)
Quoted 2 lines
just opencode OBJECT(cs) in each place.
or rename child to owner, as it is done with DRCs and TCE tables.
Quoted 106 lines
Quoted 105 lines
hw/intc/xics.c +19
-0+Error *local_err =NULL ; +Object *obj; + + obj =object_new (type); +object_property_add_child (child, type, obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), + &error_abort); +object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); + obj =NULL ; + } + +return obj; +} +/* * ICS: Source layer */ hw/ppc/pnv_core.c +1
-9@@ -126,7 +126,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -134,13 +133,7 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)return ; } - obj =object_new (TYPE_PNV_ICP ); -object_property_add_child (child,"icp" , obj,NULL ); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (xi), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs,TYPE_PNV_ICP , xi, &local_err);if (local_err) {error_propagate (errp, local_err);return ;@@ -148,7 +141,6 @@ static void pnv_core_realize_child(Object *child, XICSFabric *xi, Error **errp)powernv_cpu_init (cpu, &local_err);if (local_err) { -object_unparent (obj);error_propagate (errp, local_err);return ; }hw/ppc/spapr_cpu_core.c +2
-11@@ -111,7 +111,6 @@ static void spapr_cpu_core_realize_child(Object *child,Error *local_err =NULL ;CPUState *cs =CPU (child);PowerPCCPU *cpu =POWERPC_CPU (cs); -Object *obj;object_property_set_bool (child, true,"realized" , &local_err);if (local_err) {@@ -123,21 +122,13 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - obj =object_new (spapr->icp_type); -object_property_add_child (child,"icp" , obj, &error_abort); -object_unref (obj); -object_property_add_const_link (obj,ICP_PROP_XICS ,OBJECT (spapr), - &error_abort); -object_property_add_const_link (obj,ICP_PROP_CPU , child, &error_abort); -object_property_set_bool (obj, true,"realized" , &local_err); +icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err);if (local_err) { - goto free_icp; + goto error; }return ; -free_icp: -object_unparent (obj); error:error_propagate (errp, local_err); }include/hw/ppc/xics.h +3
-0@@ -212,4 +212,7 @@ typedef struct sPAPRMachineState sPAPRMachineState;int xics_kvm_init (sPAPRMachineState *spapr,Error **errp);void xics_spapr_init (sPAPRMachineState *spapr); +Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi, +Error **errp); +#endif /* XICS_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH 03/25] spapr: introduce a spapr_icp_create() helper
In reply to Cédric Le GoaterQuoted 6 lines · On Thu, 23 Nov 2017 14:29:33 +0100 Cédric Le Goater <[email protected]> wrote:
On sPAPR, the creation of the interrupt presenter depends on some of the machine attributes. When the XIVE interrupt mode is available, this will get more complex. So provide a machine-level helper to isolate the process and hide the details to the sPAPR core realize function.
Not sure it makes sense to introduce this helper that early in the series... what about folding it in patch 23 where it is really needed ?
Quoted 56 lines
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/spapr.c | 14 ++++++++++++++ hw/ppc/spapr_cpu_core.c | 2 +- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)hw/ppc/spapr.c +14
-0@@ -3556,6 +3556,20 @@ static ICPState *spapr_icp_get(XICSFabric *xi, int vcpu_id)return cpu ?ICP (cpu->intc) :NULL ; } +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); +if (local_err) { +error_propagate (errp, local_err); +return NULL ; + } + +return obj; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_cpu_core.c +1
-1@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =spapr_icp_create (spapr, cs, &local_err);if (local_err) { goto error; }include/hw/ppc/spapr.h +2
-0@@ -707,4 +707,6 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);int spapr_vcpu_id (PowerPCCPU *cpu);PowerPCCPU *spapr_find_cpu (int vcpu_id); +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +#endif /* HW_SPAPR_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH 03/25] spapr: introduce a spapr_icp_create() helper
Quoted 10 lines · Greg Kurz
Quoted 6 lines · On Thu, 23 Nov 2017 14:29:33 +0100 Cédric Le Goater <[email protected]> wrote:
On sPAPR, the creation of the interrupt presenter depends on some of the machine attributes. When the XIVE interrupt mode is available, this will get more complex. So provide a machine-level helper to isolate the process and hide the details to the sPAPR core realize function.
Quoted 2 lines
Not sure it makes sense to introduce this helper that early in the series... what about folding it in patch 23 where it is really needed ?
It does 'icp_type' and the 'xics_fabric' which are machine concepts around the sPAPR interrupt controller model.
But yes, it could come before patch 23. May be not folded, though.
C.
Quoted 57 lines
Quoted 56 lines
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/spapr.c | 14 ++++++++++++++ hw/ppc/spapr_cpu_core.c | 2 +- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)hw/ppc/spapr.c +14
-0@@ -3556,6 +3556,20 @@ static ICPState *spapr_icp_get(XICSFabric *xi, int vcpu_id)return cpu ?ICP (cpu->intc) :NULL ; } +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); +if (local_err) { +error_propagate (errp, local_err); +return NULL ; + } + +return obj; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_cpu_core.c +1
-1@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =spapr_icp_create (spapr, cs, &local_err);if (local_err) { goto error; }include/hw/ppc/spapr.h +2
-0@@ -707,4 +707,6 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);int spapr_vcpu_id (PowerPCCPU *cpu);PowerPCCPU *spapr_find_cpu (int vcpu_id); +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +#endif /* HW_SPAPR_H */
Re: [Qemu-devel] [PATCH 13/25] spapr: introduce the XIVE Event Queues
In reply to Cédric Le GoaterQuoted 9 lines · Cédric Le Goater
So The Linux driver is expected to choose priority 6. The priority validity is then checked in each hcall returning H_P4/H_P3 in case of failure.
But it is true that we scale the arrays with :
#define XIVE_PRIORITY_MAX 7Do you want QEMU to completely remove prio 7 ?
I'd like qemu to be consistent, at least make sure it errors out if the OS tries to configue prio 7 or route an irq to it.
Cheers,
Ben.
Re: [Qemu-devel] [Qemu-ppc] [PATCH 01/25] ppc/xics: introduce an icp_create() helper
In reply to Greg KurzQuoted 37 lines · Greg Kurz
Quoted 26 lines · On Fri, 24 Nov 2017 13:51:00 +1100 David Gibson <[email protected]>…
Quoted 5 lines · Cédric Le Goater
The sPAPR and the PowerNV core objects create the interrupt presenter object of the CPUs in a very similar way. Let's provide a common routine in which we use the presenter 'type' as a child identifier.
Signed-off-by Cédric Le Goater <[email protected]>One tiny nit.., apart from that
Reviewed-by David Gibson <[email protected]>Quoted 15 lines
--- hw/intc/xics.c | 22 ++++++++++++++++++++++ hw/ppc/pnv_core.c | 10 +--------- hw/ppc/spapr_cpu_core.c | 13 ++----------- include/hw/ppc/xics.h | 3 +++ 4 files changed, 28 insertions(+), 20 deletions(-)hw/intc/xics.c +0
-0@@ -384,6 +384,28 @@ static const TypeInfo icp_info = { .class_size = sizeof(ICPStateClass), };Quoted 7 lines
hw/intc/xics.c static const TypeInfo icp_info = { · line 389
Quoted 3 lines
hw/intc/xics.c +3
-0+Object *icp_create (CPUState *cs,const char *type,XICSFabric *xi,Error **errp) +{ +Object *child =OBJECT (cs);In the original context 'child' made sense, since it was the child object of the core. Here, it's misleading, since it's the parent of the xics link. It's only used in a couple of places, so I suggest you
Quoted 6 lines
Oops yes :)
Quoted 2 lines
just opencode OBJECT(cs) in each place.
or rename child to owner, as it is done with DRCs and TCE tables.
Sure. Either's fine by me.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 11/25] spapr: describe the XIVE interrupt source flags
In reply to Cédric Le GoaterQuoted 29 lines · Cédric Le Goater
The XIVE interrupt sources can have different characteristics depending on their nature and the HW level in use. The sPAPR specs provide a set of flags to describe them :
-
XIVE_SRC_H_INT_ESBthe Event State Buffers are controlled with a specific hcallH_INT_ESBand not with MMIO- XIVE_SRC_LSI LSI or MSI source (ICSIRQState level) - XIVE_SRC_TRIGGER the full function page supports trigger - XIVE_SRC_STORE_EOI EOI can be done with a store.Our QEMU emulation of XIVE for the sPAPR machine gathers all sources under a same model and provides a common source with the
XIVE_SRC_TRIGGERtype. So, the above list is mostly informative apart from theXIVE_SRC_LSIflag which will be deduced from theXIVE_STATUS_LSIflag.The OS retrieves this information on the source with the
H_INT_GET_SOURCE_INFOhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 4 ++++ include/hw/ppc/spapr_xive.h | 7 +++++++ 2 files changed, 11 insertions(+)hw/intc/spapr_xive.c +0
-0
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 373
Quoted 6 lines
hw/intc/spapr_xive.c +3
-0@@ -368,6 +368,10 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); +/* All sources are emulated under the XIVE object and share the +* same characteristic */ + xive->flags =XIVE_SRC_TRIGGER ;
You never actually use this field. And since it always has the same value, is there a point to storing it?
Quoted 22 lines
hw/intc/spapr_xive.c +1
-0+/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); xive->sbe =g_malloc0 (xive->sbe_size);include/hw/ppc/spapr_xive.h +7
-0@@ -40,6 +40,13 @@ struct sPAPRXive {#define XIVE_STATUS_SENT 0x4uint8_t *status; +/* Interrupt source flags */ +#define XIVE_SRC_H_INT_ESB (1ull << (63 - 60)) +#define XIVE_SRC_LSI (1ull << (63 - 61)) +#define XIVE_SRC_TRIGGER (1ull << (63 - 62)) +#define XIVE_SRC_STORE_EOI (1ull << (63 - 63)) +uint32_t flags; +/* XIVE internal tables */ XiveIVE *ivt;uint8_t *sbe;
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 197 lines · Cédric Le Goater
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +143
-0@@ -0,0 +1,165 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); + +qemu_register_reset (spapr_xive_reset, dev); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn)
hw/intc/spapr_xive.c line 153
Quoted 10 lines
hw/intc/spapr_xive.c new file +10
-0+{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +}
As I said in another comment, I don't like the name: sets what, exactly?
It's not really clear to me what the VALID bit means. Why would an irq within the allocated range be invalid?
Quoted 118 lines
hw/intc/spapr_xive.c new file +12
-0+ +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* QEMU PowerPC XIVE model +* +* Copyright 2016,2017 IBM Corporation. +* +* 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. +*/ +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define PPC_BIT (bit) (0x8000000000000000UL >> (bit)) +#define PPC_BIT32 (bit) (0x80000000UL >> (bit)) +#define PPC_BIT8 (bit) (0x80UL >> (bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ + PPC_BIT32(bs)) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +void spapr_xive_reset (void *dev); +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 157 lines · Cédric Le Goater
Each interrupt source is associated with a two bit state machine called an Event State Buffer (ESB). The bits are named "P" (pending) and "Q" (queued) and can be controlled by MMIO. It is used to trigger events. See code for more details on the states and transitions.
The MMIO space for the ESB translation is 512GB large on baremetal (powernv) systems and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map a sub memory region for the provisionned IRQ numbers and to use the mapping address of chip 0 on a real system. The OS will get the address of the MMIO page of the ESB entry associated with an IRQ using the
H_INT_GET_SOURCE_INFOhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 268 +++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr_xive.h | 8 ++ 2 files changed, 275 insertions(+), 1 deletion(-)hw/intc/spapr_xive.c +131
-0@@ -32,6 +32,216 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn) }/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_GET 0x800 +#define XIVE_ESB_SET_PQ_00 0xc00 +#define XIVE_ESB_SET_PQ_01 0xd00 +#define XIVE_ESB_SET_PQ_10 0xe00 +#define XIVE_ESB_SET_PQ_11 0xf00 + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ +static void spapr_xive_source_eoi (sPAPRXive *xive,uint32_t lisn) +{ +if (spapr_xive_irq_is_lsi (xive, lisn)) { + xive->status[lisn] &= ~XIVE_STATUS_SENT ; + } +} + +/* TODO: handle second page +* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +uint64_t ret =-1 ;
hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); + goto out; + } + +switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);
Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the STATUS_SENT bit from the PQ bits?
Quoted 91 lines
hw/intc/spapr_xive.c +84
-0+/* return TRUE or FALSE depending on PQ value */ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +out: +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +bool notify = false; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return ; + } + +switch (offset) { +case 0 : +/* TODO: should we trigger even if the IVE is masked ? */ + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +if (notify && !(ive->w &IVE_MASKED )) { +qemu_irq_pulse (xive->qirqs[lisn]); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +/* * XIVE Interrupt Source */ static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val)@@ -70,6 +280,33 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)/* * Main XIVE object */ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ + +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset, +unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" [%u]\n" , + __func__, offset, size); +return 0 ; +} + +static void spapr_xive_esb_default_write(void *opaque, hwaddr offset,
hw/intc/spapr_xive.c static void spapr_xive_source_set_irq(void *opaque, int lisn, int val) · line 308
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ uint64_t value, unsigned size) +{ + qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx " <- 0x%" PRIx64 " [%u]\n", + __func__, offset, value, size); +} + +static const MemoryRegionOps spapr_xive_esb_default_ops = { + .read = spapr_xive_esb_default_read, + .write = spapr_xive_esb_default_write, + .endianness =DEVICE_BIG_ENDIAN ,
I think you should at least have a valid access size field here.
Quoted 37 lines
hw/intc/spapr_xive.c +10
-1+};void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {@@ -77,14 +314,19 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %s %c%c %08x %08x\n" , i,spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }@@ -104,6 +346,9 @@ void spapr_xive_reset(void *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)@@ -123,6 +368,26 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 378
Quoted 10 lines
hw/intc/spapr_xive.c +8
-0xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); +/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. That's the full window but we will only map the +* subregions in use. */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + xive->esb_shift =ESB_SHIFT ;
Any point to having this as a variable, if it's always the same size?
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 389
Quoted 11 lines
hw/intc/spapr_xive.c +11
-0+ +/* Install default memory region handlers to log bogus access */ +memory_region_init_io (&xive->esb_mr,NULL , &spapr_xive_esb_default_ops, +NULL ,"xive.esb.full" ,VC_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_mr); + +/* Install the ESB memory region in the overall one */ +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), &spapr_xive_esb_ops, + xive,"xive.esb" , + (1ull << xive->esb_shift) * xive->nr_irqs); +memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem);
Is there a benegit to to having these nested regions, rather than just validating the lisn in the read/write functions?
Quoted 16 lines
hw/intc/spapr_xive.c +1
-0qemu_register_reset (spapr_xive_reset, dev); }@@ -152,6 +417,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };include/hw/ppc/spapr_xive.h +0
-0
include/hw/ppc/spapr_xive.h struct sPAPRXive { · line 46
Quoted 5 lines
include/hw/ppc/spapr_xive.h +2
-0@@ -42,6 +42,14 @@ struct sPAPRXive {/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size;
sbe_size is derivable from nr_irqs, so I don't think there's a point to storing it separately .
Quoted 9 lines
include/hw/ppc/spapr_xive.h +6
-0+ +/* ESB memory region */ +uint32_t esb_shift; +hwaddr esb_base; +MemoryRegion esb_mr; +MemoryRegion esb_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 09/25] spapr: introduce handlers for XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 5 lines · Cédric Le Goater
These are very similar to the XICS handlers in a simpler form. They make use of a status array for the LSI interrupts. The
spapr_xive_irq()routine in charge of triggering the CPU interrupt line will be filled later on.Signed-off-by Cédric Le Goater <[email protected]>
Is the status word you add here architected as part of the XIVE spec, or purely internal / implementation specific?
Quoted 106 lines
--- hw/intc/spapr_xive.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/spapr_xive.h | 14 +++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-)hw/intc/spapr_xive.c +52
-2@@ -26,6 +26,47 @@#include "xive-internal.h" +static void spapr_xive_irq (sPAPRXive *xive,int lisn) +{ + +} + +/* +* XIVE Interrupt Source +*/ +static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val) +{ +if (val) { +spapr_xive_irq (xive, lisn); + } +} + +static void spapr_xive_source_set_irq_lsi (sPAPRXive *xive,int lisn,int val) +{ +if (val) { + xive->status[lisn] |=XIVE_STATUS_ASSERTED ; + }else { + xive->status[lisn] &= ~XIVE_STATUS_ASSERTED ; + } + +if (xive->status[lisn] &XIVE_STATUS_ASSERTED && + !(xive->status[lisn] &XIVE_STATUS_SENT )) { + xive->status[lisn] |=XIVE_STATUS_SENT ; +spapr_xive_irq (xive, lisn); + } +} + +static void spapr_xive_source_set_irq (void *opaque,int lisn,int val) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); + +if (spapr_xive_irq_is_lsi (xive, lisn)) { +spapr_xive_source_set_irq_lsi (xive, lisn, val); + }else { +spapr_xive_source_set_irq_msi (xive, lisn, val); + } +} +/* * Main XIVE object */ @@ -41,7 +82,8 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)continue ; } -monitor_printf (mon," %4x %s %08x %08x\n" , i, +monitor_printf (mon," %4x %s %s %08x %08x\n" , i, +spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w));@@ -53,6 +95,8 @@ void spapr_xive_reset(void *dev)sPAPRXive *xive =SPAPR_XIVE (dev);int i; +/* Do not clear IRQs status */ +/* Mask all valid IVEs in the IRQ number space. */ for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i];@@ -71,6 +115,11 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)return ; } +/* QEMU IRQs */ + xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, + xive->nr_irqs); + xive->status =g_malloc0 (xive->nr_irqs); +/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));@@ -102,6 +151,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL), VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), + VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs),VMSTATE_END_OF_LIST () }, };@@ -140,7 +190,7 @@ XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn)return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; } -bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi) {XiveIVE *ive =spapr_xive_get_ive (xive, lisn);
hw/intc/spapr_xive.c bool spapr_xive_irq_set(sPAPRXive *xive, uint32_t lisn) · line 202
Quoted 4 lines
hw/intc/spapr_xive.c +1
-0@@ -149,6 +199,7 @@ bool spapr_xive_irq_set(sPAPRXive *xive, uint32_t lisn) } ive->w |=IVE_VALID ; + xive->status[lisn] |= lsi ?XIVE_STATUS_LSI :0 ;
How does a hardware XIVE know which irqs are LSI and which are MSI?
Quoted 32 lines
hw/intc/spapr_xive.c +0
-0return true; }include/hw/ppc/spapr_xive.h +13
-1@@ -33,11 +33,23 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +#define XIVE_STATUS_LSI 0x1 +#define XIVE_STATUS_ASSERTED 0x2 +#define XIVE_STATUS_SENT 0x4 +uint8_t *status; +/* XIVE internal tables */ XiveIVE *ivt; }; -bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn) +{ +return xive->status[lisn] &XIVE_STATUS_LSI ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 202 lines · David Gibson
Quoted 201 lines · Cédric Le Goater
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +147
-0@@ -0,0 +1,165 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); + +qemu_register_reset (spapr_xive_reset, dev); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) {
Quoted 8 lines
hw/intc/spapr_xive.c line 153
Quoted 6 lines
hw/intc/spapr_xive.c new file +6
-0+return false; + } + + ive->w |=IVE_VALID ; +return true; +}As I said in another comment, I don't like the name: sets what, exactly?
may be spapr_xive_irq_alloc() would be better ? I guess so.
Quoted 3 lines
It's not really clear to me what the VALID bit means. Why would an irq within the allocated range be invalid?
'enable' might be better a better choice but that is how the specs refer to this bit.
It it used by the HW to let through or stop the notification process immediately when a trigger is performed on the ESB MMIOs.
Thanks,
C.
Quoted 120 lines
Quoted 119 lines
hw/intc/spapr_xive.c new file +12
-0+ +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* QEMU PowerPC XIVE model +* +* Copyright 2016,2017 IBM Corporation. +* +* 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. +*/ +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define PPC_BIT (bit) (0x8000000000000000UL >> (bit)) +#define PPC_BIT32 (bit) (0x80000000UL >> (bit)) +#define PPC_BIT8 (bit) (0x80UL >> (bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ + PPC_BIT32(bs)) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +void spapr_xive_reset (void *dev); +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Greg Kurz
Reviewed-byRe: [Qemu-devel] [Qemu-ppc] [PATCH 03/25] spapr: introduce a spapr_icp_create() helper
In reply to Cédric Le GoaterQuoted 11 lines · On Fri, 24 Nov 2017 12:26:21 +0000 Cédric Le Goater <[email protected]> wrote:
Quoted 10 lines · Greg Kurz
Quoted 6 lines · On Thu, 23 Nov 2017 14:29:33 +0100 Cédric Le Goater <[email protected]> wrote:
On sPAPR, the creation of the interrupt presenter depends on some of the machine attributes. When the XIVE interrupt mode is available, this will get more complex. So provide a machine-level helper to isolate the process and hide the details to the sPAPR core realize function.
Quoted 6 lines
Quoted 2 lines
Not sure it makes sense to introduce this helper that early in the series... what about folding it in patch 23 where it is really needed ?
It does '
icp_type' and the 'xics_fabric' which are machine concepts around the sPAPR interrupt controller model.
Oh yes you're right, I guess I was looking at this from the perspective of my PHB hotplug series :)
Hence,
Quoted 64 lines
But yes, it could come before patch 23. May be not folded, though.
C.
Quoted 57 lines
Quoted 56 lines
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/spapr.c | 14 ++++++++++++++ hw/ppc/spapr_cpu_core.c | 2 +- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)hw/ppc/spapr.c +14
-0@@ -3556,6 +3556,20 @@ static ICPState *spapr_icp_get(XICSFabric *xi, int vcpu_id)return cpu ?ICP (cpu->intc) :NULL ; } +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); +if (local_err) { +error_propagate (errp, local_err); +return NULL ; + } + +return obj; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_cpu_core.c +1
-1@@ -122,7 +122,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - cpu->intc =icp_create (cs, spapr->icp_type,XICS_FABRIC (spapr), &local_err); + cpu->intc =spapr_icp_create (spapr, cs, &local_err);if (local_err) { goto error; }include/hw/ppc/spapr.h +2
-0@@ -707,4 +707,6 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);int spapr_vcpu_id (PowerPCCPU *cpu);PowerPCCPU *spapr_find_cpu (int vcpu_id); +Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +#endif /* HW_SPAPR_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH 04/25] spapr: move the IRQ allocation routines under the machine
In reply to Cédric Le GoaterQuoted 6 lines · On Thu, 23 Nov 2017 14:29:34 +0100 Cédric Le Goater <[email protected]> wrote:
Also change the prototype to use a sPAPRMachineState and prefix them with
spapr_irq_. It will let us synchronise the IRQ allocation with the XIVE interrupt mode when available.Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 396 lines
hw/intc/trace-events | 4 -- hw/intc/xics_spapr.c | 114 ------------------------------------------------- hw/ppc/spapr.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 4 +- hw/ppc/spapr_pci.c | 8 ++-- hw/ppc/spapr_vio.c | 2 +- hw/ppc/trace-events | 4 ++ include/hw/ppc/spapr.h | 6 +++ include/hw/ppc/xics.h | 4 -- 9 files changed, 131 insertions(+), 129 deletions(-)hw/intc/trace-events +0
-4@@ -64,10 +64,6 @@ xics_ics_simple_set_irq_lsi(int srcno, int nr) "set_irq_lsi: srcno %d [irq 0x%x] xics_ics_simple_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_xive: irq 0x%x [src %d] server 0x%x prio 0x%x" xics_ics_simple_reject(int nr, int srcno) "reject irq 0x%x [src %d]" xics_ics_simple_eoi(int nr) "ics_eoi: irq 0x%x" -xics_alloc(int irq) "irq %d" -xics_alloc_block(int first, int num, bool lsi, int align) "first irq %d, %d irqs, lsi=%d, alignnum %d" -xics_ics_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs" -xics_ics_free_warn(int src, int irq) "Source#%d, irq %d is already free" # hw/intc/s390_flic_kvm.c flic_create_device(int err) "flic: create device failed %d"hw/intc/xics_spapr.c +0
-114@@ -245,120 +245,6 @@ void xics_spapr_init(sPAPRMachineState *spapr)spapr_register_hypercall (H_IPOLL , h_ipoll); } -#define ICS_IRQ_FREE (ics, srcno) \ - (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_MASK))) - -static int ics_find_free_block (ICSState *ics,int num,int alignnum) -{ -int first, i; - -for (first =0 ; first < ics->nr_irqs; first += alignnum) { -if (num > (ics->nr_irqs - first)) { -return -1 ; - } -for (i = first; i < first + num; ++i) { -if (!ICS_IRQ_FREE (ics, i)) { -break ; - } - } -if (i == (first + num)) { -return first; - } - } - -return -1 ; -} - -int spapr_ics_alloc (ICSState *ics,int irq_hint,bool lsi,Error **errp) -{ -int irq; - -if (!ics) { -return -1 ; - } -if (irq_hint) { -if (!ICS_IRQ_FREE (ics, irq_hint - ics->offset)) { -error_setg (errp,"can't allocate IRQ %d: already in use" , irq_hint); -return -1 ; - } - irq = irq_hint; - }else { - irq =ics_find_free_block (ics,1 ,1 ); -if (irq <0 ) { -error_setg (errp,"can't allocate IRQ: no IRQ left" ); -return -1 ; - } - irq += ics->offset; - } - -ics_set_irq_type (ics, irq - ics->offset, lsi); -trace_xics_alloc (irq); - -return irq; -} - -/* -* Allocate block of consecutive IRQs, and return the number of the first IRQ in -* the block. If align==true, aligns the first IRQ number to num. -*/ -int spapr_ics_alloc_block (ICSState *ics,int num,bool lsi, -bool align,Error **errp) -{ -int i, first =-1 ; - -if (!ics) { -return -1 ; - } - -/* -* MSIMesage::data is used for storing VIRQ so -* it has to be aligned to num to support multiple -* MSI vectors. MSI-X is not affected by this. -* The hint is used for the first IRQ, the rest should -* be allocated continuously. -*/ -if (align) { -assert ((num ==1 ) || (num ==2 ) || (num ==4 ) || - (num ==8 ) || (num ==16 ) || (num ==32 )); - first =ics_find_free_block (ics, num, num); - }else { - first =ics_find_free_block (ics, num,1 ); - } -if (first <0 ) { -error_setg (errp,"can't find a free %d-IRQ block" , num); -return -1 ; - } - -for (i = first; i < first + num; ++i) { -ics_set_irq_type (ics, i, lsi); - } - first += ics->offset; - -trace_xics_alloc_block (first, num, lsi, align); - -return first; -} - -static void ics_free (ICSState *ics,int srcno,int num) -{ -int i; - -for (i = srcno; i < srcno + num; ++i) { -if (ICS_IRQ_FREE (ics, i)) { -trace_xics_ics_free_warn (0 , i + ics->offset); - } -memset (&ics->irqs[i],0 ,sizeof (ICSIRQState)); - } -} - -void spapr_ics_free (ICSState *ics,int irq,int num) -{ -if (ics_valid_irq (ics, irq)) { -trace_xics_ics_free (0 , irq, num); -ics_free (ics, irq - ics->offset, num); - } -} -void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle) {uint32_t interrupt_server_ranges_prop[] = {hw/ppc/spapr.c +114
-0@@ -3570,6 +3570,120 @@ Object *spapr_icp_create(sPAPRMachineState *spapr, CPUState *cs, Error **errp)return obj; } +#define ICS_IRQ_FREE (ics, srcno) \ + (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_MASK))) + +static int ics_find_free_block (ICSState *ics,int num,int alignnum) +{ +int first, i; + +for (first =0 ; first < ics->nr_irqs; first += alignnum) { +if (num > (ics->nr_irqs - first)) { +return -1 ; + } +for (i = first; i < first + num; ++i) { +if (!ICS_IRQ_FREE (ics, i)) { +break ; + } + } +if (i == (first + num)) { +return first; + } + } + +return -1 ; +} + +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi, +Error **errp) +{ +ICSState *ics = spapr->ics; +int irq; + +if (!ics) { +return -1 ; + } +if (irq_hint) { +if (!ICS_IRQ_FREE (ics, irq_hint - ics->offset)) { +error_setg (errp,"can't allocate IRQ %d: already in use" , irq_hint); +return -1 ; + } + irq = irq_hint; + }else { + irq =ics_find_free_block (ics,1 ,1 ); +if (irq <0 ) { +error_setg (errp,"can't allocate IRQ: no IRQ left" ); +return -1 ; + } + irq += ics->offset; + } + +ics_set_irq_type (ics, irq - ics->offset, lsi); +trace_spapr_irq_alloc (irq); + +return irq; +} + +/* +* Allocate block of consecutive IRQs, and return the number of the first IRQ in +* the block. If align==true, aligns the first IRQ number to num. +*/ +int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi, +bool align,Error **errp) +{ +ICSState *ics = spapr->ics; +int i, first =-1 ; + +if (!ics) { +return -1 ; + } + +/* +* MSIMesage::data is used for storing VIRQ so +* it has to be aligned to num to support multiple +* MSI vectors. MSI-X is not affected by this. +* The hint is used for the first IRQ, the rest should +* be allocated continuously. +*/ +if (align) { +assert ((num ==1 ) || (num ==2 ) || (num ==4 ) || + (num ==8 ) || (num ==16 ) || (num ==32 )); + first =ics_find_free_block (ics, num, num); + }else { + first =ics_find_free_block (ics, num,1 ); + } +if (first <0 ) { +error_setg (errp,"can't find a free %d-IRQ block" , num); +return -1 ; + } + +for (i = first; i < first + num; ++i) { +ics_set_irq_type (ics, i, lsi); + } + first += ics->offset; + +trace_spapr_irq_alloc_block (first, num, lsi, align); + +return first; +} + +void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num) +{ +ICSState *ics = spapr->ics; +int srcno = irq - ics->offset; +int i; + +if (ics_valid_irq (ics, irq)) { +trace_spapr_irq_free (0 , irq, num); +for (i = srcno; i < srcno + num; ++i) { +if (ICS_IRQ_FREE (ics, i)) { +trace_spapr_irq_free_warn (0 , i + ics->offset); + } +memset (&ics->irqs[i],0 ,sizeof (ICSIRQState)); + } + } +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {hw/ppc/spapr_events.c +2
-2@@ -718,7 +718,7 @@ void spapr_events_init(sPAPRMachineState *spapr) spapr->event_sources =spapr_event_sources_new ();spapr_event_sources_register (spapr->event_sources,EVENT_CLASS_EPOW , -spapr_ics_alloc (spapr->ics,0 , false, +spapr_irq_alloc (spapr,0 , false, &error_fatal));/* NOTE: if machine supports modern/dedicated hotplug event source, @@ -731,7 +731,7 @@ void spapr_events_init(sPAPRMachineState *spapr)*/ if (spapr->use_hotplug_event_source) {spapr_event_sources_register (spapr->event_sources,EVENT_CLASS_HOT_PLUG , -spapr_ics_alloc (spapr->ics,0 , false, +spapr_irq_alloc (spapr,0 , false, &error_fatal)); }hw/ppc/spapr_pci.c +4
-4@@ -314,7 +314,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,return ; } -spapr_ics_free (spapr->ics, msi->first_irq, msi->num); +spapr_irq_free (spapr, msi->first_irq, msi->num);if (msi_present (pdev)) {spapr_msi_setmsg (pdev,0 , false,0 ,0 ); }@@ -352,7 +352,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr, }/* Allocate MSIs */ - irq =spapr_ics_alloc_block (spapr->ics, req_num, false, + irq =spapr_irq_alloc_block (spapr, req_num, false, ret_intr_type ==RTAS_TYPE_MSI , &err);if (err) { error_reportf_err(err, "Can't allocate MSIs for device %x: ",@@ -363,7 +363,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,/* Release previous MSIs */ if (msi) { -spapr_ics_free (spapr->ics, msi->first_irq, msi->num); +spapr_irq_free (spapr, msi->first_irq, msi->num);g_hash_table_remove (phb->msi, &config_addr); }@@ -1675,7 +1675,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)uint32_t irq;Error *local_err =NULL ; - irq =spapr_ics_alloc_block (spapr->ics,1 , true, false, &local_err); + irq =spapr_irq_alloc_block (spapr,1 , true, false, &local_err);if (local_err) {error_propagate (errp, local_err);error_prepend (errp,"can't allocate LSIs: " );hw/ppc/spapr_vio.c +1
-1@@ -454,7 +454,7 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp) dev->qdev.id = id; } - dev->irq =spapr_ics_alloc (spapr->ics, dev->irq, false, &local_err); + dev->irq =spapr_irq_alloc (spapr, dev->irq, false, &local_err);if (local_err) {error_propagate (errp, local_err);return ;hw/ppc/trace-events +4
-0@@ -12,6 +12,10 @@ spapr_pci_msi_retry(unsigned config_addr, unsigned req_num, unsigned max_irqs) " # hw/ppc/spapr.c spapr_cas_failed(unsigned long n) "DT diff buffer is too small: %ld bytes" spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes" +spapr_irq_alloc(int irq) "irq %d" +spapr_irq_alloc_block(int first, int num, bool lsi, int align) "first irq %d, %d irqs, lsi=%d, alignnum %d" +spapr_irq_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs" +spapr_irq_free_warn(int src, int irq) "Source#%d, irq %d is already free" # hw/ppc/spapr_hcall.c spapr_cas_pvr_try(uint32_t pvr) "0x%x"include/hw/ppc/spapr.h +6
-0@@ -709,4 +709,10 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id);Object *spapr_icp_create (sPAPRMachineState *spapr,CPUState *cs,Error **errp); +int spapr_irq_alloc (sPAPRMachineState *spapr,int irq_hint,bool lsi, +Error **errp); +int spapr_irq_alloc_block (sPAPRMachineState *spapr,int num,bool lsi, +bool align,Error **errp); +void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num); +#endif /* HW_SPAPR_H */ include/hw/ppc/xics.h +0
-4@@ -181,10 +181,6 @@ typedef struct XICSFabricClass {#define XICS_IRQS_SPAPR 1024 -int spapr_ics_alloc (ICSState *ics,int irq_hint,bool lsi,Error **errp); -int spapr_ics_alloc_block (ICSState *ics,int num,bool lsi,bool align, -Error **errp); -void spapr_ics_free (ICSState *ics,int irq,int num);void spapr_dt_xics (int nr_servers,void *fdt,uint32_t phandle);qemu_irq xics_get_qirq (XICSFabric *xi,int irq);
Re: [Qemu-devel] [PATCH 09/25] spapr: introduce handlers for XIVE interrupt sources
In reply to David GibsonQuoted 9 lines · David Gibson
Quoted 5 lines · Cédric Le Goater
These are very similar to the XICS handlers in a simpler form. They make use of a status array for the LSI interrupts. The
spapr_xive_irq()routine in charge of triggering the CPU interrupt line will be filled later on.Signed-off-by Cédric Le Goater <[email protected]>Is the status word you add here architected as part of the XIVE spec, or purely internal / implementation specific?
this is the model.
Quoted 106 lines
Quoted 106 lines
--- hw/intc/spapr_xive.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/spapr_xive.h | 14 +++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-)hw/intc/spapr_xive.c +52
-2@@ -26,6 +26,47 @@#include "xive-internal.h" +static void spapr_xive_irq (sPAPRXive *xive,int lisn) +{ + +} + +/* +* XIVE Interrupt Source +*/ +static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val) +{ +if (val) { +spapr_xive_irq (xive, lisn); + } +} + +static void spapr_xive_source_set_irq_lsi (sPAPRXive *xive,int lisn,int val) +{ +if (val) { + xive->status[lisn] |=XIVE_STATUS_ASSERTED ; + }else { + xive->status[lisn] &= ~XIVE_STATUS_ASSERTED ; + } + +if (xive->status[lisn] &XIVE_STATUS_ASSERTED && + !(xive->status[lisn] &XIVE_STATUS_SENT )) { + xive->status[lisn] |=XIVE_STATUS_SENT ; +spapr_xive_irq (xive, lisn); + } +} + +static void spapr_xive_source_set_irq (void *opaque,int lisn,int val) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); + +if (spapr_xive_irq_is_lsi (xive, lisn)) { +spapr_xive_source_set_irq_lsi (xive, lisn, val); + }else { +spapr_xive_source_set_irq_msi (xive, lisn, val); + } +} +/* * Main XIVE object */ @@ -41,7 +82,8 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)continue ; } -monitor_printf (mon," %4x %s %08x %08x\n" , i, +monitor_printf (mon," %4x %s %s %08x %08x\n" , i, +spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w));@@ -53,6 +95,8 @@ void spapr_xive_reset(void *dev)sPAPRXive *xive =SPAPR_XIVE (dev);int i; +/* Do not clear IRQs status */ +/* Mask all valid IVEs in the IRQ number space. */ for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i];@@ -71,6 +115,11 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)return ; } +/* QEMU IRQs */ + xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, + xive->nr_irqs); + xive->status =g_malloc0 (xive->nr_irqs); +/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));@@ -102,6 +151,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL), VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), + VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs),VMSTATE_END_OF_LIST () }, };@@ -140,7 +190,7 @@ XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn)return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; } -bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi) {XiveIVE *ive =spapr_xive_get_ive (xive, lisn);
Quoted 7 lines
hw/intc/spapr_xive.c bool spapr_xive_irq_set(sPAPRXive *xive, uint32_t lisn) · line 202
Quoted 5 lines
hw/intc/spapr_xive.c +1
-0@@ -149,6 +199,7 @@ bool spapr_xive_irq_set(sPAPRXive *xive, uint32_t lisn) } ive->w |=IVE_VALID ; + xive->status[lisn] |= lsi ?XIVE_STATUS_LSI :0 ;How does a hardware XIVE know which irqs are LSI and which are MSI?
AFAICT, it doesn't. LSI events are configured as the other XIVE interrupts. The level is converted in the P bit and the Q bit should always be zero. So I should be able to simplify the proposed model which still is mimicking XICS ... I will take a look at it.
There are a sort of special degenerated LSIs but these are for bringup.
Thanks,
C.
Quoted 33 lines
Quoted 32 lines
hw/intc/spapr_xive.c +0
-0return true; }include/hw/ppc/spapr_xive.h +13
-1@@ -33,11 +33,23 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +#define XIVE_STATUS_LSI 0x1 +#define XIVE_STATUS_ASSERTED 0x2 +#define XIVE_STATUS_SENT 0x4 +uint8_t *status; +/* XIVE internal tables */ XiveIVE *ivt; }; -bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn) +{ +return xive->status[lisn] &XIVE_STATUS_LSI ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);
Re: [Qemu-devel] [PATCH 11/25] spapr: describe the XIVE interrupt source flags
In reply to David GibsonQuoted 33 lines · David Gibson
Quoted 32 lines · Cédric Le Goater
The XIVE interrupt sources can have different characteristics depending on their nature and the HW level in use. The sPAPR specs provide a set of flags to describe them :
-
XIVE_SRC_H_INT_ESBthe Event State Buffers are controlled with a specific hcallH_INT_ESBand not with MMIO- XIVE_SRC_LSI LSI or MSI source (ICSIRQState level) - XIVE_SRC_TRIGGER the full function page supports trigger - XIVE_SRC_STORE_EOI EOI can be done with a store.Our QEMU emulation of XIVE for the sPAPR machine gathers all sources under a same model and provides a common source with the
XIVE_SRC_TRIGGERtype. So, the above list is mostly informative apart from theXIVE_SRC_LSIflag which will be deduced from theXIVE_STATUS_LSIflag.The OS retrieves this information on the source with the
H_INT_GET_SOURCE_INFOhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 4 ++++ include/hw/ppc/spapr_xive.h | 7 +++++++ 2 files changed, 11 insertions(+)hw/intc/spapr_xive.c +0
-0@@ -368,6 +368,10 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));
Quoted 6 lines
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 373
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+/* All sources are emulated under the XIVE object and share the +* same characteristic */ + xive->flags =XIVE_SRC_TRIGGER ;You never actually use this field. And since it always has the same value, is there a point to storing it?
yep. not much. This is a left over.
I will keep the defines and move the value to the XIVE hcall layer where it is used.
Thanks,
C.
Quoted 23 lines
Quoted 22 lines
hw/intc/spapr_xive.c +1
-0+/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); xive->sbe =g_malloc0 (xive->sbe_size);include/hw/ppc/spapr_xive.h +7
-0@@ -40,6 +40,13 @@ struct sPAPRXive {#define XIVE_STATUS_SENT 0x4uint8_t *status; +/* Interrupt source flags */ +#define XIVE_SRC_H_INT_ESB (1ull << (63 - 60)) +#define XIVE_SRC_LSI (1ull << (63 - 61)) +#define XIVE_SRC_TRIGGER (1ull << (63 - 62)) +#define XIVE_SRC_STORE_EOI (1ull << (63 - 63)) +uint32_t flags; +/* XIVE internal tables */ XiveIVE *ivt;uint8_t *sbe;
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to David GibsonQuoted 172 lines · David Gibson
Quoted 157 lines · Cédric Le Goater
Each interrupt source is associated with a two bit state machine called an Event State Buffer (ESB). The bits are named "P" (pending) and "Q" (queued) and can be controlled by MMIO. It is used to trigger events. See code for more details on the states and transitions.
The MMIO space for the ESB translation is 512GB large on baremetal (powernv) systems and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map a sub memory region for the provisionned IRQ numbers and to use the mapping address of chip 0 on a real system. The OS will get the address of the MMIO page of the ESB entry associated with an IRQ using the
H_INT_GET_SOURCE_INFOhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 268 +++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr_xive.h | 8 ++ 2 files changed, 275 insertions(+), 1 deletion(-)hw/intc/spapr_xive.c +131
-0@@ -32,6 +32,216 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn) }/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_GET 0x800 +#define XIVE_ESB_SET_PQ_00 0xc00 +#define XIVE_ESB_SET_PQ_01 0xd00 +#define XIVE_ESB_SET_PQ_10 0xe00 +#define XIVE_ESB_SET_PQ_11 0xf00 + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ +static void spapr_xive_source_eoi (sPAPRXive *xive,uint32_t lisn) +{ +if (spapr_xive_irq_is_lsi (xive, lisn)) { + xive->status[lisn] &= ~XIVE_STATUS_SENT ; + } +} + +/* TODO: handle second page +* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +uint64_t ret =-1 ;hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); + goto out; + } + +switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
Quoted 2 lines
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?
Yes. I should.
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
Quoted 95 lines
Quoted 95 lines
hw/intc/spapr_xive.c +88
-0+/* return TRUE or FALSE depending on PQ value */ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +out: +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +bool notify = false; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return ; + } + +switch (offset) { +case 0 : +/* TODO: should we trigger even if the IVE is masked ? */ + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +if (notify && !(ive->w &IVE_MASKED )) { +qemu_irq_pulse (xive->qirqs[lisn]); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +/* * XIVE Interrupt Source */ static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val)@@ -70,6 +280,33 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)/* * Main XIVE object */ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ + +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset, +unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" [%u]\n" , + __func__, offset, size); +return 0 ; +} + +static void spapr_xive_esb_default_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" <- 0x%" PRIx64" [%u]\n" , + __func__, offset, value, size);
Quoted 8 lines
hw/intc/spapr_xive.c static void spapr_xive_source_set_irq(void *opaque, int lisn, int val) · line 308
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+} + +static const MemoryRegionOps spapr_xive_esb_default_ops = { + .read = spapr_xive_esb_default_read, + .write = spapr_xive_esb_default_write, + .endianness =DEVICE_BIG_ENDIAN ,I think you should at least have a valid access size field here.
yes.
Quoted 39 lines
Quoted 39 lines
hw/intc/spapr_xive.c +10
-1+};void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {@@ -77,14 +314,19 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %s %c%c %08x %08x\n" , i,spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }@@ -104,6 +346,9 @@ void spapr_xive_reset(void *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)@@ -123,6 +368,26 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));
Quoted 10 lines
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 378
Quoted 8 lines
hw/intc/spapr_xive.c +8
-0+/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. That's the full window but we will only map the +* subregions in use. */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + xive->esb_shift =ESB_SHIFT ;Any point to having this as a variable, if it's always the same size?
Well, it is related to the page size and we could have a HW configuration with two pages, with one specific page for trigger. But we don't need to model this, yet.
The 'esb_shift' field is used in different places. I would rather keep it.
Quoted 6 lines
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+ +/* Install default memory region handlers to log bogus access */ +memory_region_init_io (&xive->esb_mr,NULL , &spapr_xive_esb_default_ops, +NULL ,"xive.esb.full" ,VC_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_mr); +
Quoted 8 lines
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 389
Quoted 5 lines
hw/intc/spapr_xive.c +5
-0+/* Install the ESB memory region in the overall one */ +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), &spapr_xive_esb_ops, + xive,"xive.esb" , + (1ull << xive->esb_shift) * xive->nr_irqs); +memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem);Is there a benegit to to having these nested regions, rather than just validating the lisn in the read/write functions?
No. this was to represent the full ESB space of the system but we can reduce it to one region. This is not a problem I think.
Quoted 17 lines
Quoted 17 lines
hw/intc/spapr_xive.c +1
-0qemu_register_reset (spapr_xive_reset, dev); }@@ -152,6 +417,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };include/hw/ppc/spapr_xive.h +0
-0@@ -42,6 +42,14 @@ struct sPAPRXive {
Quoted 7 lines
include/hw/ppc/spapr_xive.h struct sPAPRXive { · line 46
Quoted 4 lines
include/hw/ppc/spapr_xive.h +2
-0/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size;
sbe_sizeis derivable fromnr_irqs, so I don't think there's a point to storing it separately .
I needed the value for the vmstate macros.
Thanks,
C.
Quoted 10 lines
Quoted 9 lines
include/hw/ppc/spapr_xive.h +6
-0+ +/* ESB memory region */ +uint32_t esb_shift; +hwaddr esb_base; +MemoryRegion esb_mr; +MemoryRegion esb_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
Quoted 173 lines · Cédric Le Goater
Quoted 172 lines · David Gibson
Quoted 157 lines · Cédric Le Goater
Each interrupt source is associated with a two bit state machine called an Event State Buffer (ESB). The bits are named "P" (pending) and "Q" (queued) and can be controlled by MMIO. It is used to trigger events. See code for more details on the states and transitions.
The MMIO space for the ESB translation is 512GB large on baremetal (powernv) systems and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map a sub memory region for the provisionned IRQ numbers and to use the mapping address of chip 0 on a real system. The OS will get the address of the MMIO page of the ESB entry associated with an IRQ using the
H_INT_GET_SOURCE_INFOhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 268 +++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr_xive.h | 8 ++ 2 files changed, 275 insertions(+), 1 deletion(-)hw/intc/spapr_xive.c +131
-0@@ -32,6 +32,216 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn) }/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_GET 0x800 +#define XIVE_ESB_SET_PQ_00 0xc00 +#define XIVE_ESB_SET_PQ_01 0xd00 +#define XIVE_ESB_SET_PQ_10 0xe00 +#define XIVE_ESB_SET_PQ_11 0xf00 + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ +static void spapr_xive_source_eoi (sPAPRXive *xive,uint32_t lisn) +{ +if (spapr_xive_irq_is_lsi (xive, lisn)) { + xive->status[lisn] &= ~XIVE_STATUS_SENT ; + } +} + +/* TODO: handle second page +* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +uint64_t ret =-1 ;hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); + goto out; + } + +switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
Quoted 7 lines
Quoted 2 lines
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?Yes. I should.
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Quoted 156 lines
Quoted 95 lines
Quoted 95 lines
hw/intc/spapr_xive.c +88
-0+/* return TRUE or FALSE depending on PQ value */ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +out: +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >> xive->esb_shift; +XiveIVE *ive; +bool notify = false; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return ; + } + +switch (offset) { +case 0 : +/* TODO: should we trigger even if the IVE is masked ? */ + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +if (notify && !(ive->w &IVE_MASKED )) { +qemu_irq_pulse (xive->qirqs[lisn]); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +/* * XIVE Interrupt Source */ static void spapr_xive_source_set_irq_msi (sPAPRXive *xive,int lisn,int val)@@ -70,6 +280,33 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)/* * Main XIVE object */ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ + +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset, +unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" [%u]\n" , + __func__, offset, size); +return 0 ; +} + +static void spapr_xive_esb_default_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" <- 0x%" PRIx64" [%u]\n" , + __func__, offset, value, size);Quoted 8 lines
hw/intc/spapr_xive.c static void spapr_xive_source_set_irq(void *opaque, int lisn, int val) · line 308
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+} + +static const MemoryRegionOps spapr_xive_esb_default_ops = { + .read = spapr_xive_esb_default_read, + .write = spapr_xive_esb_default_write, + .endianness =DEVICE_BIG_ENDIAN ,I think you should at least have a valid access size field here.
yes.
Quoted 39 lines
Quoted 39 lines
hw/intc/spapr_xive.c +10
-1+};void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {@@ -77,14 +314,19 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %s %c%c %08x %08x\n" , i,spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }@@ -104,6 +346,9 @@ void spapr_xive_reset(void *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)@@ -123,6 +368,26 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));Quoted 10 lines
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 378
Quoted 8 lines
hw/intc/spapr_xive.c +8
-0+/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. That's the full window but we will only map the +* subregions in use. */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + xive->esb_shift =ESB_SHIFT ;Any point to having this as a variable, if it's always the same size?
Quoted 6 lines
Well, it is related to the page size and we could have a HW configuration with two pages, with one specific page for trigger. But we don't need to model this, yet.
The '
esb_shift' field is used in different places. I would rather keep it.
Hm, ok.
Quoted 43 lines
Quoted 6 lines
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+ +/* Install default memory region handlers to log bogus access */ +memory_region_init_io (&xive->esb_mr,NULL , &spapr_xive_esb_default_ops, +NULL ,"xive.esb.full" ,VC_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_mr); +Quoted 8 lines
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 389
Quoted 5 lines
hw/intc/spapr_xive.c +5
-0+/* Install the ESB memory region in the overall one */ +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), &spapr_xive_esb_ops, + xive,"xive.esb" , + (1ull << xive->esb_shift) * xive->nr_irqs); +memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem);Is there a benegit to to having these nested regions, rather than just validating the lisn in the read/write functions?
No. this was to represent the full ESB space of the system but we can reduce it to one region. This is not a problem I think.
Quoted 17 lines
Quoted 17 lines
hw/intc/spapr_xive.c +1
-0qemu_register_reset (spapr_xive_reset, dev); }@@ -152,6 +417,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_STRUCT_VARRAY_UINT32_ALLOC(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), VMSTATE_VBUFFER_UINT32(status, sPAPRXive, 1, NULL, nr_irqs), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };include/hw/ppc/spapr_xive.h +0
-0@@ -42,6 +42,14 @@ struct sPAPRXive {Quoted 7 lines
include/hw/ppc/spapr_xive.h struct sPAPRXive { · line 46
Quoted 4 lines
include/hw/ppc/spapr_xive.h +2
-0/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size;
sbe_sizeis derivable fromnr_irqs, so I don't think there's a point to storing it separately .
Quoted 1 line
I needed the value for the vmstate macros.
Ah, right.
Quoted 17 lines
Thanks,
C.
Quoted 10 lines
Quoted 9 lines
include/hw/ppc/spapr_xive.h +6
-0+ +/* ESB memory region */ +uint32_t esb_shift; +hwaddr esb_base; +MemoryRegion esb_mr; +MemoryRegion esb_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 212 lines · Cédric Le Goater
Quoted 202 lines · David Gibson
Quoted 201 lines · Cédric Le Goater
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +147
-0@@ -0,0 +1,165 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE)); + +qemu_register_reset (spapr_xive_reset, dev); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) {Quoted 8 lines
hw/intc/spapr_xive.c line 153
Quoted 6 lines
hw/intc/spapr_xive.c new file +6
-0+return false; + } + + ive->w |=IVE_VALID ; +return true; +}As I said in another comment, I don't like the name: sets what, exactly?
Quoted 1 line
may be
spapr_xive_irq_alloc()would be better ? I guess so.
Or enable/disable.
Quoted 5 lines
Quoted 2 lines
It's not really clear to me what the VALID bit means. Why would an irq within the allocated range be invalid?
'enable' might be better a better choice but that is how the specs refer to this bit.
Right, definitely the VALID name for the bit constant, if that's what's in the specs. But it still might be better to use enable/disable for the functions to change it since that's clearer.
Unless there's something else we might want to do with the irq that could also be called enable/disable.
Quoted 2 lines
It it used by the HW to let through or stop the notification process immediately when a trigger is performed on the ESB MMIOs.
Ok, so the concept does exist in hardware.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 12/25] spapr: introduce a XIVE interrupt presenter model
In reply to Cédric Le GoaterQuoted 22 lines · Cédric Le Goater
The XIVE interrupt presenter exposes a set of rings, also called Thread Interrupt Management Areas (TIMA), to handle priority management and interrupt acknowledgment among other things. There is one ring per level of privilege, four in all. The one we are interested in for the sPAPR machine is the OS ring.
The TIMA is mapped at the same address for each CPU. '
current_cpu' is used to retrieve the targeted interrupt presenter object holding the cache data of the registers the model use.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 89 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 371 insertions(+)hw/intc/spapr_xive.c +0
-0
hw/intc/spapr_xive.c line 30
Quoted 8 lines
hw/intc/spapr_xive.c +2
-0@@ -23,9 +23,166 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h" #include "xive-internal.h" +struct sPAPRXiveICP {
I'd really prefer to avoid calling anything in xive "icp" to avoid confusion with xics.
hw/intc/spapr_xive.c line 34
Quoted 4 lines
hw/intc/spapr_xive.c +4
-0+DeviceState parent_obj; + +CPUState *cs; +uint8_t tima[TM_RING_COUNT *0x10 ];
What does the 0x10 represent? #define for clarity, maybe.
Do we need to model the whole range as memory, or just the relevant pieces with read/write meaning?
Quoted 29 lines
hw/intc/spapr_xive.c +29
-0+uint8_t *tima_os; +qemu_irq output; +}; + +static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp) +{ +return 0 ; +} + +static void spapr_xive_icp_set_cppr (sPAPRXiveICP *icp,uint8_t cppr) +{ +if (cppr >XIVE_PRIORITY_MAX ) { + cppr =0xff ; + } + + icp->tima_os[TM_CPPR ] = cppr; +} + +/* +* Thread Interrupt Management Area MMIO +*/ +static uint64_t spapr_xive_tm_read_special (sPAPRXiveICP *icp,hwaddr offset, +unsigned size) +{ +uint64_t ret =-1 ; + +if (offset ==TM_SPC_ACK_OS_REG && size ==2 ) { + ret =spapr_xive_icp_accept (icp); + }else {
hw/intc/spapr_xive.c line 73
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA read @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + +return ret; +} + +static uint64_t spapr_xive_tm_read (void *opaque,hwaddr offset,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu);
So, strictly speaking this could be handled by setting each of the CPUs address spaces separately, to something with their own TIMA superimposed on address_space_memory. What you have might be more practical though.
Quoted 5 lines
hw/intc/spapr_xive.c +5
-0+sPAPRXiveICP *icp =SPAPR_XIVE_ICP (cpu->intc); +uint64_t ret =-1 ; +int i; + +if (offset >=TM_SPC_ACK_EBB ) {
hw/intc/spapr_xive.c line 88
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+return spapr_xive_tm_read_special (icp, offset, size); + } + +if ((offset &0xf0 ) ==TM_QW1_OS ) { +switch (size) { +case 1 : +case 2 : +case 4 : +case 8 : +if (QEMU_IS_ALIGNED (offset, size)) {
Hm, the MR subsystem doesn't already split unaligned accesses?
Quoted 69 lines
hw/intc/spapr_xive.c +69
-0+ ret =0 ; +for (i =0 ; i < size; i++) { + ret |= icp->tima[offset + i] << (8 * i); + } + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"XIVE: invalid TIMA read alignment @%" + HWADDR_PRIx" size %d\n" , offset, size); + } +break ; +default : +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: does handle non-OS TIMA ring @%" + HWADDR_PRIx"\n" , offset); + } + +return ret; +} + +static bool spapr_xive_tm_is_readonly (uint8_t offset) +{ +/* Let's be optimistic and prepare ground for HV mode support */ +switch (offset) { +case TM_QW1_OS +TM_CPPR : +return false; +default : +return true; + } +} + +static void spapr_xive_tm_write_special (sPAPRXiveICP *icp,hwaddr offset, +uint64_t value,unsigned size) +{ +/* TODO: support TM_SPC_SET_OS_PENDING */ + +/* TODO: support TM_SPC_ACK_OS_EL */ +} + +static void spapr_xive_tm_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu); +sPAPRXiveICP *icp =SPAPR_XIVE_ICP (cpu->intc); +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +spapr_xive_tm_write_special (icp, offset, value, size); +return ; + } + +if ((offset &0xf0 ) ==TM_QW1_OS ) { +switch (size) { +case 1 : +if (offset ==TM_QW1_OS +TM_CPPR ) { +spapr_xive_icp_set_cppr (icp, value &0xff ); + } +break ; +case 4 : +case 8 : +if (QEMU_IS_ALIGNED (offset, size)) { +for (i =0 ; i < size; i++) { +if (!spapr_xive_tm_is_readonly (offset + i)) { + icp->tima[offset + i] = (value >> (8 * i)) &0xff ; + } + } + }else { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid TIMA write @%"
hw/intc/spapr_xive.c line 167
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ HWADDR_PRIx" size %d\n", offset, size); + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA write @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: does handle non-OS TIMA ring @%" + HWADDR_PRIx"\n" , offset);
The many qemu_log()s worry me a little. They're not ratelimited, so the guest could in principle chew through the host's log space.
IIUC these are very unlikely to be hit in practice, so maybe tracepoints would be more suitable.
Quoted 34 lines
hw/intc/spapr_xive.c +23
-0+ } +} + + +static const MemoryRegionOps spapr_xive_tm_ops = { + .read = spapr_xive_tm_read, + .write = spapr_xive_tm_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =1 , + .max_access_size =8 , + }, +}; +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -287,6 +444,11 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)#define VC_BAR_SIZE 0x08000000000ull#define ESB_SHIFT 16/* One 64k page. OPAL has two */ +/* Thread Interrupt Management Area MMIO */ +#define TM_BAR_DEFAULT 0x30203180000ull +#define TM_SHIFT 16 +#define TM_BAR_SIZE (TM_RING_COUNT * (1 << TM_SHIFT)) +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset,unsigned size) {
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 559
Quoted 6 lines
hw/intc/spapr_xive.c +3
-0@@ -392,6 +554,14 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp) (1ull << xive->esb_shift) * xive->nr_irqs);memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem); +/* TM BAR. Same address for each chip */ + xive->tm_base = (P9_MMIO_BASE |TM_BAR_DEFAULT ); + xive->tm_shift =TM_SHIFT ;
Any reason for this to be a variable?
Quoted 45 lines
hw/intc/spapr_xive.c +38
-0+ +memory_region_init_io (&xive->tm_iomem,OBJECT (xive), &spapr_xive_tm_ops, + xive,"xive.tm" ,TM_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->tm_iomem); +qemu_register_reset (spapr_xive_reset, dev); }@@ -448,9 +618,110 @@ static const TypeInfo spapr_xive_info = { .class_init = spapr_xive_class_init, }; +void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon) +{ +int cpu_index = xicp->cs ? xicp->cs->cpu_index :-1 ; + +monitor_printf (mon,"CPU %d CPPR=%02x IPB=%02x PIPR=%02x NSR=%02x\n" , + cpu_index, xicp->tima_os[TM_CPPR ], xicp->tima_os[TM_IPB ], + xicp->tima_os[TM_PIPR ], xicp->tima_os[TM_NSR ]); +} + +static void spapr_xive_icp_reset (void *dev) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev); + +memset (xicp->tima,0 ,sizeof (xicp->tima)); +} + +static void spapr_xive_icp_realize (DeviceState *dev,Error **errp) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev); +PowerPCCPU *cpu; +CPUPPCState *env; +Object *obj; +Error *err =NULL ; + + obj =object_property_get_link (OBJECT (dev),ICP_PROP_CPU , &err); +if (!obj) { +error_propagate (errp, err); +error_prepend (errp,"required link '" ICP_PROP_CPU "' not found: " ); +return ; + } + + cpu =POWERPC_CPU (obj); + xicp->cs =CPU (obj);
hw/intc/spapr_xive.c static const TypeInfo spapr_xive_info = { · line 663
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + xicp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + xicp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ;
I really don't think we need to implement XIVE for 970.
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ +default : +error_setg (errp,"XIVE interrupt controller does not support " +"this CPU bus model" ); +return ; + } + +qemu_register_reset (spapr_xive_icp_reset, dev); +} +
hw/intc/spapr_xive.c static const TypeInfo spapr_xive_info = { · line 683
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+static void spapr_xive_icp_unrealize (DeviceState *dev,Error **errp) +{ +qemu_unregister_reset (spapr_xive_icp_reset, dev); +} + +static void spapr_xive_icp_init (Object *obj) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (obj); + + xicp->tima_os = &xicp->tima[TM_QW1_OS ];
This is a fixed offset, so why store it as a pointer. For the PAPR guest case, do we even need to model the other rings?
Quoted 49 lines
hw/intc/spapr_xive.c +38
-0+} + +static bool vmstate_spapr_xive_icp_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive_icp = { + .name =TYPE_SPAPR_XIVE_ICP , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_icp_needed, + .fields = (VMStateField []) { +VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_END_OF_LIST () + }, +}; + +static void spapr_xive_icp_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_icp_realize; + dc->unrealize = spapr_xive_icp_unrealize; + dc->desc ="sPAPR XIVE Interrupt Presenter" ; + dc->vmsd = &vmstate_spapr_xive_icp; +} + +static const TypeInfo xive_icp_info = { + .name =TYPE_SPAPR_XIVE_ICP , + .parent =TYPE_DEVICE , + .instance_size =sizeof (sPAPRXiveICP), + .instance_init = spapr_xive_icp_init, + .class_init = spapr_xive_icp_class_init, +}; +static void spapr_xive_register_types (void ) {type_register_static (&spapr_xive_info); +type_register_static (&xive_icp_info); }type_init (spapr_xive_register_types)hw/intc/xive-internal.h +0
-0
hw/intc/xive-internal.h line 28
Quoted 5 lines
hw/intc/xive-internal.h +2
-0@@ -24,6 +24,93 @@#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ PPC_BIT32(bs)) +/* +* Thread Management (aka "TM") registers
Because "TM" didn't stand for enough things already :/.
Quoted 136 lines
hw/intc/xive-internal.h +87
-0+*/ + +/* Number of Thread Management Interrupt Areas */ +#define TM_RING_COUNT 4 + +/* TM register offsets */ +#define TM_QW0_USER 0x000/* All rings */ +#define TM_QW1_OS 0x010/* Ring 0..2 */ +#define TM_QW2_HV_POOL 0x020/* Ring 0..1 */ +#define TM_QW3_HV_PHYS 0x030/* Ring 0..1 */ + +/* Byte offsets inside a QW QW0 QW1 QW2 QW3 */ +#define TM_NSR 0x0/* + + - + */ +#define TM_CPPR 0x1/* - + - + */ +#define TM_IPB 0x2/* - + + + */ +#define TM_LSMFB 0x3/* - + + + */ +#define TM_ACK_CNT 0x4/* - + - - */ +#define TM_INC 0x5/* - + - + */ +#define TM_AGE 0x6/* - + - + */ +#define TM_PIPR 0x7/* - + - + */ + +#define TM_WORD0 0x0 +#define TM_WORD1 0x4 + +/* +* QW word 2 contains the valid bit at the top and other fields +* depending on the QW. +*/ +#define TM_WORD2 0x8 +#define TM_QW0W2_VU PPC_BIT32(0) +#define TM_QW0W2_LOGIC_SERV PPC_BITMASK32(1, 31)/* XX 2,31 ? */ +#define TM_QW1W2_VO PPC_BIT32(0) +#define TM_QW1W2_OS_CAM PPC_BITMASK32(8, 31) +#define TM_QW2W2_VP PPC_BIT32(0) +#define TM_QW2W2_POOL_CAM PPC_BITMASK32(8, 31) +#define TM_QW3W2_VT PPC_BIT32(0) +#define TM_QW3W2_LP PPC_BIT32(6) +#define TM_QW3W2_LE PPC_BIT32(7) +#define TM_QW3W2_T PPC_BIT32(31) + +/* +* In addition to normal loads to "peek" and writes (only when invalid) +* using 4 and 8 bytes accesses, the above registers support these +* "special" byte operations: +* +* - Byte load from QW0[NSR] - User level NSR (EBB) +* - Byte store to QW0[NSR] - User level NSR (EBB) +* - Byte load/store to QW1[CPPR] and QW3[CPPR] - CPPR access +* - Byte load from QW3[TM_WORD2] - Read VT||00000||LP||LE on thrd 0 +* otherwise VT||0000000 +* - Byte store to QW3[TM_WORD2] - Set VT bit (and LP/LE if present) +* +* Then we have all these "special" CI ops at these offset that trigger +* all sorts of side effects: +*/ +#define TM_SPC_ACK_EBB 0x800/* Load8 ack EBB to reg*/ +#define TM_SPC_ACK_OS_REG 0x810/* Load16 ack OS irq to reg */ +#define TM_SPC_PUSH_USR_CTX 0x808/* Store32 Push/Validate user context */ +#define TM_SPC_PULL_USR_CTX 0x808/* Load32 Pull/Invalidate user +* context */ +#define TM_SPC_SET_OS_PENDING 0x812/* Store8 Set OS irq pending bit */ +#define TM_SPC_PULL_OS_CTX 0x818/* Load32/Load64 Pull/Invalidate OS +* context to reg */ +#define TM_SPC_PULL_POOL_CTX 0x828/* Load32/Load64 Pull/Invalidate Pool +* context to reg*/ +#define TM_SPC_ACK_HV_REG 0x830/* Load16 ack HV irq to reg */ +#define TM_SPC_PULL_USR_CTX_OL 0xc08/* Store8 Pull/Inval usr ctx to odd +* line */ +#define TM_SPC_ACK_OS_EL 0xc10/* Store8 ack OS irq to even line */ +#define TM_SPC_ACK_HV_POOL_EL 0xc20/* Store8 ack HV evt pool to even +* line */ +#define TM_SPC_ACK_HV_EL 0xc30/* Store8 ack HV irq to even line */ +/* XXX more... */ + +/* NSR fields for the various QW ack types */ +#define TM_QW0_NSR_EB PPC_BIT8(0) +#define TM_QW1_NSR_EO PPC_BIT8(0) +#define TM_QW3_NSR_HE PPC_BITMASK8(0, 1) +#define TM_QW3_NSR_HE_NONE 0 +#define TM_QW3_NSR_HE_POOL 1 +#define TM_QW3_NSR_HE_PHYS 2 +#define TM_QW3_NSR_HE_LSI 3 +#define TM_QW3_NSR_I PPC_BIT8(2) +#define TM_QW3_NSR_GRP_LVL PPC_BIT8(3, 7) +/* IVE/EAS * * One per interrupt source. Targets that interrupt to a given EQ @@ -44,6 +131,8 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +#define XIVE_PRIORITY_MAX 7 +void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn);include/hw/ppc/spapr_xive.h +11
-0@@ -23,10 +23,15 @@typedef struct sPAPRXive sPAPRXive ;typedef struct XiveIVE XiveIVE ; +typedef struct sPAPRXiveICP sPAPRXiveICP ;#define TYPE_SPAPR_XIVE "spapr-xive"#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) +#define TYPE_SPAPR_XIVE_ICP "spapr-xive-icp" +#define SPAPR_XIVE_ICP (obj) \ + OBJECT_CHECK(sPAPRXiveICP, (obj), TYPE_SPAPR_XIVE_ICP) +struct sPAPRXive {SysBusDevice parent;@@ -57,6 +62,11 @@ struct sPAPRXive {hwaddr esb_base;MemoryRegion esb_mr;MemoryRegion esb_iomem; + +/* TIMA memory region */ +uint32_t tm_shift; +hwaddr tm_base; +MemoryRegion tm_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)@@ -67,5 +77,6 @@ static inline bool spapr_xive_irq_is_lsi(sPAPRXive *xive, int lisn)bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); +void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon);#endif /* PPC_SPAPR_XIVE_H */
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 12/25] spapr: introduce a XIVE interrupt presenter model
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
The XIVE interrupt presenter exposes a set of rings, also called Thread Interrupt Management Areas (TIMA), to handle priority management and interrupt acknowledgment among other things. There is one ring per level of privilege, four in all. The one we are interested in for the sPAPR machine is the OS ring.
The TIMA is mapped at the same address for each CPU. '
current_cpu' is used to retrieve the targeted interrupt presenter object holding the cache data of the registers the model use.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 89 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 371 insertions(+)hw/intc/spapr_xive.c +1
-0@@ -23,9 +23,166 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h"
Quoted 6 lines
hw/intc/spapr_xive.c line 30
Quoted 3 lines
hw/intc/spapr_xive.c +1
-0#include "xive-internal.h" +struct sPAPRXiveICP {I'd really prefer to avoid calling anything in xive "icp" to avoid confusion with xics.
OK.
The specs refers to the whole as an IVPE : Interrupt Virtualization Presentation Engine. In our model, we use the TIMA cached values of the OS ring and the qemu_irq for the CPU line.
Would 'sPAPRXivePresenter' be fine ?
Quoted 6 lines
hw/intc/spapr_xive.c line 34
Quoted 4 lines
hw/intc/spapr_xive.c +4
-0+DeviceState parent_obj; + +CPUState *cs; +uint8_t tima[TM_RING_COUNT *0x10 ];What does the
0x10represent? #define for clarity, maybe.
yes.
Quoted 2 lines
Do we need to model the whole range as memory, or just the relevant pieces with read/write meaning?
Yes. we could limit the TIMA and MMIO region to what sPAPR only needs :
the OS ring.
Quoted 36 lines
Quoted 36 lines
hw/intc/spapr_xive.c +35
-0+uint8_t *tima_os; +qemu_irq output; +}; + +static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp) +{ +return 0 ; +} + +static void spapr_xive_icp_set_cppr (sPAPRXiveICP *icp,uint8_t cppr) +{ +if (cppr >XIVE_PRIORITY_MAX ) { + cppr =0xff ; + } + + icp->tima_os[TM_CPPR ] = cppr; +} + +/* +* Thread Interrupt Management Area MMIO +*/ +static uint64_t spapr_xive_tm_read_special (sPAPRXiveICP *icp,hwaddr offset, +unsigned size) +{ +uint64_t ret =-1 ; + +if (offset ==TM_SPC_ACK_OS_REG && size ==2 ) { + ret =spapr_xive_icp_accept (icp); + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA read @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + +return ret; +}
Quoted 8 lines
hw/intc/spapr_xive.c line 73
Quoted 4 lines
hw/intc/spapr_xive.c +4
-0+ +static uint64_t spapr_xive_tm_read (void *opaque,hwaddr offset,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu);So, strictly speaking this could be handled by setting each of the CPUs address spaces separately, to something with their own TIMA superimposed on
address_space_memory.
Ah. I didn't know we could do that.
Quoted 1 line
What you have might be more practical though.
well, you will see at the end of the patchset how cpu->intc is assigned.
Quoted 9 lines
Quoted 9 lines
hw/intc/spapr_xive.c +9
-0+sPAPRXiveICP *icp =SPAPR_XIVE_ICP (cpu->intc); +uint64_t ret =-1 ; +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +return spapr_xive_tm_read_special (icp, offset, size); + } + +if ((offset &0xf0 ) ==TM_QW1_OS ) {
Quoted 8 lines
hw/intc/spapr_xive.c line 88
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+switch (size) { +case 1 : +case 2 : +case 4 : +case 8 : +if (QEMU_IS_ALIGNED (offset, size)) {Hm, the MR subsystem doesn't already split unaligned accesses?
euh. yes, I might be doing a little too much.
Quoted 83 lines
Quoted 69 lines
hw/intc/spapr_xive.c +69
-0+ ret =0 ; +for (i =0 ; i < size; i++) { + ret |= icp->tima[offset + i] << (8 * i); + } + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"XIVE: invalid TIMA read alignment @%" + HWADDR_PRIx" size %d\n" , offset, size); + } +break ; +default : +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: does handle non-OS TIMA ring @%" + HWADDR_PRIx"\n" , offset); + } + +return ret; +} + +static bool spapr_xive_tm_is_readonly (uint8_t offset) +{ +/* Let's be optimistic and prepare ground for HV mode support */ +switch (offset) { +case TM_QW1_OS +TM_CPPR : +return false; +default : +return true; + } +} + +static void spapr_xive_tm_write_special (sPAPRXiveICP *icp,hwaddr offset, +uint64_t value,unsigned size) +{ +/* TODO: support TM_SPC_SET_OS_PENDING */ + +/* TODO: support TM_SPC_ACK_OS_EL */ +} + +static void spapr_xive_tm_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu); +sPAPRXiveICP *icp =SPAPR_XIVE_ICP (cpu->intc); +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +spapr_xive_tm_write_special (icp, offset, value, size); +return ; + } + +if ((offset &0xf0 ) ==TM_QW1_OS ) { +switch (size) { +case 1 : +if (offset ==TM_QW1_OS +TM_CPPR ) { +spapr_xive_icp_set_cppr (icp, value &0xff ); + } +break ; +case 4 : +case 8 : +if (QEMU_IS_ALIGNED (offset, size)) { +for (i =0 ; i < size; i++) { +if (!spapr_xive_tm_is_readonly (offset + i)) { + icp->tima[offset + i] = (value >> (8 * i)) &0xff ; + } + } + }else { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid TIMA write @%"hw/intc/spapr_xive.c line 167
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ HWADDR_PRIx" size %d\n", offset, size); + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA write @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: does handle non-OS TIMA ring @%" + HWADDR_PRIx"\n" , offset);The many qemu_log()s worry me a little. They're not ratelimited, so the guest could in principle chew through the host's log space.
Quoted 2 lines
IIUC these are very unlikely to be hit in practice, so maybe tracepoints would be more suitable.
ok.
Quoted 37 lines
Quoted 37 lines
hw/intc/spapr_xive.c +23
-0+ } +} + + +static const MemoryRegionOps spapr_xive_tm_ops = { + .read = spapr_xive_tm_read, + .write = spapr_xive_tm_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =1 , + .max_access_size =8 , + }, +}; +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -287,6 +444,11 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)#define VC_BAR_SIZE 0x08000000000ull#define ESB_SHIFT 16/* One 64k page. OPAL has two */ +/* Thread Interrupt Management Area MMIO */ +#define TM_BAR_DEFAULT 0x30203180000ull +#define TM_SHIFT 16 +#define TM_BAR_SIZE (TM_RING_COUNT * (1 << TM_SHIFT)) +static uint64_t spapr_xive_esb_default_read (void *p,hwaddr offset,unsigned size) {@@ -392,6 +554,14 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp) (1ull << xive->esb_shift) * xive->nr_irqs);memory_region_add_subregion (&xive->esb_mr,0 , &xive->esb_iomem);
Quoted 5 lines
hw/intc/spapr_xive.c static void spapr_xive_realize(DeviceState *dev, Error **errp) · line 559
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+/* TM BAR. Same address for each chip */ + xive->tm_base = (P9_MMIO_BASE |TM_BAR_DEFAULT ); + xive->tm_shift =TM_SHIFT ;Any reason for this to be a variable?
no, we could just use TM_SHIFT. I will look into it.
Quoted 49 lines
Quoted 49 lines
hw/intc/spapr_xive.c +42
-0+ +memory_region_init_io (&xive->tm_iomem,OBJECT (xive), &spapr_xive_tm_ops, + xive,"xive.tm" ,TM_BAR_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->tm_iomem); +qemu_register_reset (spapr_xive_reset, dev); }@@ -448,9 +618,110 @@ static const TypeInfo spapr_xive_info = { .class_init = spapr_xive_class_init, }; +void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon) +{ +int cpu_index = xicp->cs ? xicp->cs->cpu_index :-1 ; + +monitor_printf (mon,"CPU %d CPPR=%02x IPB=%02x PIPR=%02x NSR=%02x\n" , + cpu_index, xicp->tima_os[TM_CPPR ], xicp->tima_os[TM_IPB ], + xicp->tima_os[TM_PIPR ], xicp->tima_os[TM_NSR ]); +} + +static void spapr_xive_icp_reset (void *dev) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev); + +memset (xicp->tima,0 ,sizeof (xicp->tima)); +} + +static void spapr_xive_icp_realize (DeviceState *dev,Error **errp) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev); +PowerPCCPU *cpu; +CPUPPCState *env; +Object *obj; +Error *err =NULL ; + + obj =object_property_get_link (OBJECT (dev),ICP_PROP_CPU , &err); +if (!obj) { +error_propagate (errp, err); +error_prepend (errp,"required link '" ICP_PROP_CPU "' not found: " ); +return ; + } + + cpu =POWERPC_CPU (obj); + xicp->cs =CPU (obj); + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 :
Quoted 8 lines
hw/intc/spapr_xive.c static const TypeInfo spapr_xive_info = { · line 663
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+ xicp->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +case PPC_FLAGS_INPUT_970 : + xicp->output = env->irq_inputs[PPC970_INPUT_INT ]; +break ;I really don't think we need to implement XIVE for 970.
Indeed. This is a left over from a copy/paste of the ICPState realize routine.
Quoted 15 lines
Quoted 15 lines
hw/intc/spapr_xive.c +15
-0+ +default : +error_setg (errp,"XIVE interrupt controller does not support " +"this CPU bus model" ); +return ; + } + +qemu_register_reset (spapr_xive_icp_reset, dev); +} + +static void spapr_xive_icp_unrealize (DeviceState *dev,Error **errp) +{ +qemu_unregister_reset (spapr_xive_icp_reset, dev); +} +
Quoted 8 lines
hw/intc/spapr_xive.c static const TypeInfo spapr_xive_info = { · line 683
Quoted 5 lines
hw/intc/spapr_xive.c +5
-0+static void spapr_xive_icp_init (Object *obj) +{ +sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (obj); + + xicp->tima_os = &xicp->tima[TM_QW1_OS ];This is a fixed offset, so why store it as a pointer. For the PAPR guest case, do we even need to model the other rings?
No we don't. I will simplify.
Thanks,
C.
Quoted 195 lines
Quoted 50 lines
hw/intc/spapr_xive.c +38
-0+} + +static bool vmstate_spapr_xive_icp_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive_icp = { + .name =TYPE_SPAPR_XIVE_ICP , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_icp_needed, + .fields = (VMStateField []) { +VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_END_OF_LIST () + }, +}; + +static void spapr_xive_icp_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_icp_realize; + dc->unrealize = spapr_xive_icp_unrealize; + dc->desc ="sPAPR XIVE Interrupt Presenter" ; + dc->vmsd = &vmstate_spapr_xive_icp; +} + +static const TypeInfo xive_icp_info = { + .name =TYPE_SPAPR_XIVE_ICP , + .parent =TYPE_DEVICE , + .instance_size =sizeof (sPAPRXiveICP), + .instance_init = spapr_xive_icp_init, + .class_init = spapr_xive_icp_class_init, +}; +static void spapr_xive_register_types (void ) {type_register_static (&spapr_xive_info); +type_register_static (&xive_icp_info); }type_init (spapr_xive_register_types)hw/intc/xive-internal.h +0
-0hw/intc/xive-internal.h line 28
Quoted 5 lines
hw/intc/xive-internal.h +2
-0@@ -24,6 +24,93 @@#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ PPC_BIT32(bs)) +/* +* Thread Management (aka "TM") registers Because "TM" didn't stand for enough things already :/.
Quoted 136 lines
hw/intc/xive-internal.h +87
-0+*/ + +/* Number of Thread Management Interrupt Areas */ +#define TM_RING_COUNT 4 + +/* TM register offsets */ +#define TM_QW0_USER 0x000/* All rings */ +#define TM_QW1_OS 0x010/* Ring 0..2 */ +#define TM_QW2_HV_POOL 0x020/* Ring 0..1 */ +#define TM_QW3_HV_PHYS 0x030/* Ring 0..1 */ + +/* Byte offsets inside a QW QW0 QW1 QW2 QW3 */ +#define TM_NSR 0x0/* + + - + */ +#define TM_CPPR 0x1/* - + - + */ +#define TM_IPB 0x2/* - + + + */ +#define TM_LSMFB 0x3/* - + + + */ +#define TM_ACK_CNT 0x4/* - + - - */ +#define TM_INC 0x5/* - + - + */ +#define TM_AGE 0x6/* - + - + */ +#define TM_PIPR 0x7/* - + - + */ + +#define TM_WORD0 0x0 +#define TM_WORD1 0x4 + +/* +* QW word 2 contains the valid bit at the top and other fields +* depending on the QW. +*/ +#define TM_WORD2 0x8 +#define TM_QW0W2_VU PPC_BIT32(0) +#define TM_QW0W2_LOGIC_SERV PPC_BITMASK32(1, 31)/* XX 2,31 ? */ +#define TM_QW1W2_VO PPC_BIT32(0) +#define TM_QW1W2_OS_CAM PPC_BITMASK32(8, 31) +#define TM_QW2W2_VP PPC_BIT32(0) +#define TM_QW2W2_POOL_CAM PPC_BITMASK32(8, 31) +#define TM_QW3W2_VT PPC_BIT32(0) +#define TM_QW3W2_LP PPC_BIT32(6) +#define TM_QW3W2_LE PPC_BIT32(7) +#define TM_QW3W2_T PPC_BIT32(31) + +/* +* In addition to normal loads to "peek" and writes (only when invalid) +* using 4 and 8 bytes accesses, the above registers support these +* "special" byte operations: +* +* - Byte load from QW0[NSR] - User level NSR (EBB) +* - Byte store to QW0[NSR] - User level NSR (EBB) +* - Byte load/store to QW1[CPPR] and QW3[CPPR] - CPPR access +* - Byte load from QW3[TM_WORD2] - Read VT||00000||LP||LE on thrd 0 +* otherwise VT||0000000 +* - Byte store to QW3[TM_WORD2] - Set VT bit (and LP/LE if present) +* +* Then we have all these "special" CI ops at these offset that trigger +* all sorts of side effects: +*/ +#define TM_SPC_ACK_EBB 0x800/* Load8 ack EBB to reg*/ +#define TM_SPC_ACK_OS_REG 0x810/* Load16 ack OS irq to reg */ +#define TM_SPC_PUSH_USR_CTX 0x808/* Store32 Push/Validate user context */ +#define TM_SPC_PULL_USR_CTX 0x808/* Load32 Pull/Invalidate user +* context */ +#define TM_SPC_SET_OS_PENDING 0x812/* Store8 Set OS irq pending bit */ +#define TM_SPC_PULL_OS_CTX 0x818/* Load32/Load64 Pull/Invalidate OS +* context to reg */ +#define TM_SPC_PULL_POOL_CTX 0x828/* Load32/Load64 Pull/Invalidate Pool +* context to reg*/ +#define TM_SPC_ACK_HV_REG 0x830/* Load16 ack HV irq to reg */ +#define TM_SPC_PULL_USR_CTX_OL 0xc08/* Store8 Pull/Inval usr ctx to odd +* line */ +#define TM_SPC_ACK_OS_EL 0xc10/* Store8 ack OS irq to even line */ +#define TM_SPC_ACK_HV_POOL_EL 0xc20/* Store8 ack HV evt pool to even +* line */ +#define TM_SPC_ACK_HV_EL 0xc30/* Store8 ack HV irq to even line */ +/* XXX more... */ + +/* NSR fields for the various QW ack types */ +#define TM_QW0_NSR_EB PPC_BIT8(0) +#define TM_QW1_NSR_EO PPC_BIT8(0) +#define TM_QW3_NSR_HE PPC_BITMASK8(0, 1) +#define TM_QW3_NSR_HE_NONE 0 +#define TM_QW3_NSR_HE_POOL 1 +#define TM_QW3_NSR_HE_PHYS 2 +#define TM_QW3_NSR_HE_LSI 3 +#define TM_QW3_NSR_I PPC_BIT8(2) +#define TM_QW3_NSR_GRP_LVL PPC_BIT8(3, 7) +/* IVE/EAS * * One per interrupt source. Targets that interrupt to a given EQ @@ -44,6 +131,8 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +#define XIVE_PRIORITY_MAX 7 +void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn);include/hw/ppc/spapr_xive.h +11
-0@@ -23,10 +23,15 @@typedef struct sPAPRXive sPAPRXive ;typedef struct XiveIVE XiveIVE ; +typedef struct sPAPRXiveICP sPAPRXiveICP ;#define TYPE_SPAPR_XIVE "spapr-xive"#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) +#define TYPE_SPAPR_XIVE_ICP "spapr-xive-icp" +#define SPAPR_XIVE_ICP (obj) \ + OBJECT_CHECK(sPAPRXiveICP, (obj), TYPE_SPAPR_XIVE_ICP) +struct sPAPRXive {SysBusDevice parent;@@ -57,6 +62,11 @@ struct sPAPRXive {hwaddr esb_base;MemoryRegion esb_mr;MemoryRegion esb_iomem; + +/* TIMA memory region */ +uint32_t tm_shift; +hwaddr tm_base; +MemoryRegion tm_iomem; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)@@ -67,5 +77,6 @@ static inline bool spapr_xive_irq_is_lsi(sPAPRXive *xive, int lisn)bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); +void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon);#endif /* PPC_SPAPR_XIVE_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 54 lines · On Thu, 23 Nov 2017 14:29:38 +0100 Cédric Le Goater <[email protected]> wrote:
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +0
-0
hw/intc/spapr_xive.c line 7
Quoted 7 lines
hw/intc/spapr_xive.c new file +7
-0@@ -0,0 +1,165 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as
version 2 or (at your option) any later version.
Quoted 58 lines
hw/intc/spapr_xive.c new file +58
-0+* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp)
hw/intc/spapr_xive.c line 75
Quoted 10 lines
hw/intc/spapr_xive.c new file +10
-0+{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));
Even if it isn't documented, AFAIK current recommended practice is to do:
xive->ivt = g_new0(XiveIVE, xive->nr_irqs);
hw/intc/spapr_xive.c line 77
Quoted 2 lines
hw/intc/spapr_xive.c new file +2
-0+ +qemu_register_reset (spapr_xive_reset, dev);
Shouldn't you set dc->reset in spapr_xive_class_init() instead ?
Quoted 17 lines
hw/intc/spapr_xive.c new file +17
-0+} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +}
hw/intc/spapr_xive.c line 104
Quoted 10 lines
hw/intc/spapr_xive.c new file +10
-0+ +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE),
Hmm... this array is allocated at realize and this will cause the migration code to re-allocate it again with the same size, and leak memory IIUC.
Quoted 167 lines
hw/intc/spapr_xive.c new file +61
-0+VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* QEMU PowerPC XIVE model +* +* Copyright 2016,2017 IBM Corporation. +* +* 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. +*/ +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define PPC_BIT (bit) (0x8000000000000000UL >> (bit)) +#define PPC_BIT32 (bit) (0x80000000UL >> (bit)) +#define PPC_BIT8 (bit) (0x80UL >> (bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ + PPC_BIT32(bs)) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +void spapr_xive_reset (void *dev); +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 58 lines · Greg Kurz
Quoted 55 lines · On Thu, 23 Nov 2017 14:29:38 +0100 Cédric Le Goater <[email protected]> wrote:
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +1
-0@@ -0,0 +1,165 @@ +/*
Quoted 8 lines
hw/intc/spapr_xive.c line 7
Quoted 6 lines
hw/intc/spapr_xive.c new file +6
-0+* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as version 2 or (at your option) any later version.
yep. I will shorten the headers at the same time.
Quoted 72 lines
Quoted 59 lines
hw/intc/spapr_xive.c new file +58
-0+* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp)hw/intc/spapr_xive.c line 75
Quoted 10 lines
hw/intc/spapr_xive.c new file +10
-0+{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));Even if it isn't documented, AFAIK current recommended practice is to do:
Quoted 1 line
xive->ivt = g_new0(XiveIVE, xive->nr_irqs);
OK.
Quoted 4 lines
hw/intc/spapr_xive.c line 77
Quoted 2 lines
hw/intc/spapr_xive.c new file +2
-0+ +qemu_register_reset (spapr_xive_reset, dev);Shouldn't you set
dc->resetinspapr_xive_class_init()instead ?
qemu_register_reset() is a more general API. What is the best practice ?
Quoted 23 lines
Quoted 23 lines
hw/intc/spapr_xive.c new file +23
-0+} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed,
Quoted 8 lines
hw/intc/spapr_xive.c line 104
Quoted 4 lines
hw/intc/spapr_xive.c new file +4
-0+ .fields = (VMStateField[]) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE),Hmm... this array is allocated at realize and this will cause the migration code to re-allocate it again with the same size, and leak memory IIUC.
I thought so but something was going wrong on the receive side (memory corruption detected by valgrind). I did not find why yet.
Thanks,
C.
Quoted 168 lines
Quoted 167 lines
hw/intc/spapr_xive.c new file +61
-0+VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* QEMU PowerPC XIVE model +* +* Copyright 2016,2017 IBM Corporation. +* +* 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. +*/ +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define PPC_BIT (bit) (0x8000000000000000UL >> (bit)) +#define PPC_BIT32 (bit) (0x80000000UL >> (bit)) +#define PPC_BIT8 (bit) (0x80UL >> (bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ + PPC_BIT32(bs)) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +void spapr_xive_reset (void *dev); +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to David GibsonQuoted 10 lines
Quoted 10 lines
Quoted 9 lines
hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?
Quoted 6 lines
Quoted 4 lines
Yes. I should.
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Perfect. The current model is working but I will see how I can improve it to use the PQ bits instead.
I also found a couple of issues on the way.
We do need the "#interrupt-cells" and "interrupt-controller" properties. They are missing from the XIVE sPAPR specs but there is no other way to find the parent controller for the LSIs ... I have re-asked the pHyp team to include them in the specs and fixed the QEMU model.
Linux thinks the interrupt type is an "edge" and not a "level" one :
(initramfs) cat /proc/interrupts
CPU0
16: 0 XIVE-IPI 0 Edge IPI 17: 14 XIVE-IRQ 4100 Edge enp0s0 18: 0 XIVE-IRQ 4097 Edge RAS_HOTPLUG 19: 0 XIVE-IRQ 4096 Edge RAS_EPOW 20: 20 XIVE-IRQ 4098 Edge hvc_console
and XIVE complains :
[ 8.319970] xive: Interrupt 17 (HW 0x1004) type mismatch, Linux says Edge, FW says Level
I am digging this one.
Thanks.
C.
Re: [Qemu-devel] [Qemu-ppc] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 68 lines · On Wed, 29 Nov 2017 14:46:56 +0100 Cédric Le Goater <[email protected]> wrote:
Quoted 57 lines · Greg Kurz
Quoted 55 lines · Cédric Le Goater
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +1
-0@@ -0,0 +1,165 @@ +/* Quoted 8 lines
hw/intc/spapr_xive.c line 7
Quoted 6 lines
hw/intc/spapr_xive.c new file +6
-0+* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as version 2 or (at your option) any later version.
Quoted 2 lines
yep. I will shorten the headers at the same time.
Yeah, I found a really short one from Peter in include/hw/arm/armv7m.h:
/*
* ARMv7M CPU object
*
* Copyright (c) 2017 Linaro Ltd
* Written by Peter Maydell <[email protected]> *
* This code is licensed under the GPL version 2 or later. */
Quoted 76 lines
Quoted 72 lines
Quoted 59 lines
hw/intc/spapr_xive.c new file +58
-0+* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp)hw/intc/spapr_xive.c line 75
Quoted 10 lines
hw/intc/spapr_xive.c new file +10
-0+{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));Even if it isn't documented, AFAIK current recommended practice is to do:
Quoted 1 line
xive->ivt = g_new0(XiveIVE, xive->nr_irqs);OK.
Quoted 8 lines
Quoted 4 lines
hw/intc/spapr_xive.c line 77
Quoted 2 lines
hw/intc/spapr_xive.c new file +2
-0+ +qemu_register_reset (spapr_xive_reset, dev);Shouldn't you set
dc->resetinspapr_xive_class_init()instead ?
qemu_register_reset()is a more general API. What is the best practice ?
I'm no expert but this is a sysbus device, right ? So I'd expect it to be connected to some bus (sysbus_get_default() ?) and to get reset when the parent bus is reset...
Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
hw/intc/spapr_xive.c new file +23
-0+} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed,Quoted 8 lines
hw/intc/spapr_xive.c line 104
Quoted 4 lines
hw/intc/spapr_xive.c new file +4
-0+ .fields = (VMStateField[]) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE),Hmm... this array is allocated at realize and this will cause the migration code to re-allocate it again with the same size, and leak memory IIUC.
Quoted 3 lines
I thought so but something was going wrong on the receive side (memory corruption detected by valgrind). I did not find why yet.
Have you tried VMSTATE_STRUCT_VARRAY_POINTER_UINT32() ?
Quoted 173 lines
Thanks,
C.
Quoted 168 lines
Quoted 167 lines
hw/intc/spapr_xive.c new file +61
-0+VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* QEMU PowerPC XIVE model +* +* Copyright 2016,2017 IBM Corporation. +* +* 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. +*/ +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define PPC_BIT (bit) (0x8000000000000000UL >> (bit)) +#define PPC_BIT32 (bit) (0x80000000UL >> (bit)) +#define PPC_BIT8 (bit) (0x80UL >> (bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ + PPC_BIT32(bs)) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +void spapr_xive_reset (void *dev); +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_set (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_unset (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 12 lines · Cédric Le Goater
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?Yes. I should.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Perfect. The current model is working but I will see how I can improve it to use the PQ bits instead.
Using the PQ bits is simplifying the model but we still have to maintain an array to store the IRQ type.
There are 3 unused bits in the IVE descriptor, bits[1-3]:
#define IVE_VALID PPC_BIT(0) #define IVE_EQ_BLOCK PPC_BITMASK(4, 7) /* Destination EQ block# */ #define IVE_EQ_INDEX PPC_BITMASK(8, 31) /* Destination EQ index */ #define IVE_MASKED PPC_BIT(32) /* Masked */ #define IVE_EQ_DATA PPC_BITMASK(33, 63) /* Data written to the EQ */
We could hijack one of them to store the LSI type and get rid of the type array. Would you object to that ?
C.
Re: [Qemu-devel] [Qemu-ppc] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Greg KurzQuoted 14 lines
Quoted 14 lines
Quoted 13 lines
hw/intc/spapr_xive.c line 104
Quoted 9 lines
hw/intc/spapr_xive.c new file +9
-0+static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32_ALLOC (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE),Hmm... this array is allocated at realize and this will cause the migration code to re-allocate it again with the same size, and leak memory IIUC.
Quoted 5 lines
Quoted 3 lines
I thought so but something was going wrong on the receive side (memory corruption detected by valgrind). I did not find why yet.
Have you tried
VMSTATE_STRUCT_VARRAY_POINTER_UINT32()?
yes. tcg/intel only though.
C.
Re: [Qemu-devel] [PATCH 12/25] spapr: introduce a XIVE interrupt presenter model
In reply to Cédric Le GoaterQuoted 36 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
The XIVE interrupt presenter exposes a set of rings, also called Thread Interrupt Management Areas (TIMA), to handle priority management and interrupt acknowledgment among other things. There is one ring per level of privilege, four in all. The one we are interested in for the sPAPR machine is the OS ring.
The TIMA is mapped at the same address for each CPU. '
current_cpu' is used to retrieve the targeted interrupt presenter object holding the cache data of the registers the model use.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 89 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 371 insertions(+)hw/intc/spapr_xive.c +1
-0@@ -23,9 +23,166 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h" Quoted 6 lines
hw/intc/spapr_xive.c line 30
Quoted 3 lines
hw/intc/spapr_xive.c +1
-0#include "xive-internal.h" +struct sPAPRXiveICP {I'd really prefer to avoid calling anything in xive "icp" to avoid confusion with xics.
Quoted 7 lines
OK.
The specs refers to the whole as an IVPE : Interrupt Virtualization Presentation Engine. In our model, we use the TIMA cached values of the OS ring and the
qemu_irqfor the CPU line.Would 'sPAPRXivePresenter' be fine ?
That'd be ok. Or call if sPAPRIVPE. Or even call it TIMA. I'd be fine with any of those.
[snip]
Quoted 9 lines
Quoted 7 lines
hw/intc/spapr_xive.c line 73
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+static uint64_t spapr_xive_tm_read (void *opaque,hwaddr offset,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu);So, strictly speaking this could be handled by setting each of the CPUs address spaces separately, to something with their own TIMA superimposed on
address_space_memory.Ah. I didn't know we could do that.
I think that should work from having seen the code before. I haven't actually attempted it..
Quoted 4 lines
Quoted 1 line
What you have might be more practical though.
well, you will see at the end of the patchset how
cpu->intcis assigned.
[snip]
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Greg KurzQuoted 129 lines · Greg Kurz
Quoted 54 lines · On Thu, 23 Nov 2017 14:29:38 +0100 Cédric Le Goater <[email protected]> wrote:
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +0
-0hw/intc/spapr_xive.c line 7
Quoted 7 lines
hw/intc/spapr_xive.c new file +7
-0@@ -0,0 +1,165 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as version 2 or (at your option) any later version.
Quoted 62 lines
hw/intc/spapr_xive.c new file +62
-0+* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) {
Quoted 8 lines
hw/intc/spapr_xive.c line 75
Quoted 6 lines
hw/intc/spapr_xive.c new file +6
-0+error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));Even if it isn't documented, AFAIK current recommended practice is to do:
Yeah, that's a good idea - protects against integer overflows if nothing else.
Quoted 6 lines
xive->ivt = g_new0(XiveIVE, xive->nr_irqs);hw/intc/spapr_xive.c line 77
Quoted 2 lines
hw/intc/spapr_xive.c new file +2
-0+ +qemu_register_reset (spapr_xive_reset, dev);Shouldn't you set
dc->resetinspapr_xive_class_init()instead ?
Yeah, that.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 26 lines · Cédric Le Goater
Quoted 12 lines · Cédric Le Goater
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?Yes. I should.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Perfect. The current model is working but I will see how I can improve it to use the PQ bits instead.
Using the PQ bits is simplifying the model but we still have to maintain an array to store the IRQ type.
There are 3 unused bits in the IVE descriptor, bits[1-3]:
Quoted 8 lines
#define IVE_VALID PPC_BIT(0) #define IVE_EQ_BLOCK PPC_BITMASK(4, 7) /* Destination EQ block# */ #define IVE_EQ_INDEX PPC_BITMASK(8, 31) /* Destination EQ index */ #define IVE_MASKED PPC_BIT(32) /* Masked */ #define IVE_EQ_DATA PPC_BITMASK(33, 63) /* Data written to the EQ */We could hijack one of them to store the LSI type and get rid of the type array. Would you object to that ?
Hrm. These IVE bits are architected, aren't they? In which case I'd be wary of stealing a reserved bit in case of future extensions.
I'm wondering if we want another word / structure for storing non-architected, implementation specific flags or info.
How does this work at the hardware level? Presumbly the actual hardware components don't communicate with the XIVE to request edge or level. So how does it know? Specific ranges for LSIs? If that we should probably do the same.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 20 lines · Cédric Le Goater
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?Quoted 6 lines
Quoted 4 lines
Yes. I should.
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Perfect. The current model is working but I will see how I can improve it to use the PQ bits instead.
Quoted 7 lines
I also found a couple of issues on the way.
We do need the "#interrupt-cells" and "interrupt-controller" properties. They are missing from the XIVE sPAPR specs but there is no other way to find the parent controller for the LSIs ... I have re-asked the pHyp team to include them in the specs and fixed the QEMU model.
Told ya so :).
Quoted 1 line
Linux thinks the interrupt type is an "edge" and not a "level" one :
Right "edge" and message interrupts work basically the same way.
Quoted 18 lines
(initramfs) cat
/proc/interrupts
CPU016: 0 XIVE-IPI 0 Edge IPI 17: 14 XIVE-IRQ 4100 Edge enp0s0 18: 0 XIVE-IRQ 4097 Edge RAS_HOTPLUG 19: 0 XIVE-IRQ 4096 Edge RAS_EPOW 20: 20 XIVE-IRQ 4098 Edge hvc_consoleand XIVE complains :
[ 8.319970] xive: Interrupt 17 (HW 0x1004) type mismatch, Linux says Edge, FW says LevelI am digging this one.
Thanks.
C.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 13/25] spapr: introduce the XIVE Event Queues
In reply to Cédric Le GoaterQuoted 10 lines · Cédric Le Goater
The Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is one of the internal tables the XIVE interrupt controller uses to redirect exception from event sources to CPU threads.
The EQD specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which server (VPD in XIVE terminology) to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
Just to clarify my understanding a server / VPD in XIVE would typically correspond to a cpu - either real or virtual, yes?
Quoted 65 lines
There is one XiveEQ per priority and the model chooses to store them under the Xive Interrupt presenter model. It will be retrieved, just like for XICS, through the 'intc' object pointer of the CPU.
The EQ indexing follows a simple pattern:
(server << 3) | (priority & 0x7)Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+)hw/intc/spapr_xive.c +15
-0@@ -23,6 +23,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h" @@ -34,6 +35,8 @@ struct sPAPRXiveICP {uint8_t tima[TM_RING_COUNT *0x10 ];uint8_t *tima_os;qemu_irq output; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp)@@ -183,6 +186,13 @@ static const MemoryRegionOps spapr_xive_tm_ops = { }, }; +static sPAPRXiveICP *spapr_xive_icp_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -632,6 +642,8 @@ static void spapr_xive_icp_reset(void *dev)sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev);memset (xicp->tima,0 ,sizeof (xicp->tima)); + +memset (xicp->eqt,0 ,sizeof (xicp->eqt)); }static void spapr_xive_icp_realize (DeviceState *dev,Error **errp)@@ -683,6 +695,23 @@ static void spapr_xive_icp_init(Object *obj) xicp->tima_os = &xicp->tima[TM_QW1_OS ]; } +static const VMStateDescription vmstate_spapr_xive_icp_eq = { + .name =TYPE_SPAPR_XIVE_ICP "/eq" , + .version_id =1 ,
hw/intc/spapr_xive.c static void spapr_xive_icp_init(Object *obj) · line 710
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ .minimum_version_id = 1, + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ),
Wow. Super descriptive field names there, but I guess that's not your fault.
Quoted 17 lines
hw/intc/spapr_xive.c +6
-0+VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_icp_needed (void *opaque) {/* TODO check machine XIVE support */ @@ -696,6 +725,8 @@ static const VMStateDescription vmstate_spapr_xive_icp = { .needed = vmstate_spapr_xive_icp_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveICP, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_icp_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };
hw/intc/spapr_xive.c bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) · line 791
Quoted 6 lines
hw/intc/spapr_xive.c +3
-0@@ -755,3 +786,28 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) ive->w &= ~IVE_VALID ;return true; } + +/* +* Use a simple indexing for the EQs.
Is this server+priority encoding architected anywhere? Otherwise, why not use separate parameters?
Quoted 86 lines
hw/intc/spapr_xive.c +22
-0+*/ +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t eq_idx) +{ +int priority = eq_idx &0x7 ; +sPAPRXiveICP *xicp =spapr_xive_icp_get (xive, eq_idx >>3 ); + +return xicp ? &xicp->eqt[priority] :NULL ; +} + +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server, +uint8_t priority,uint32_t *out_eq_idx) +{ +if (priority >XIVE_PRIORITY_MAX ) { +return false; + } + +if (out_eq_idx) { + *out_eq_idx = (server <<3 ) | (priority &0x7 ); + } + +return true; +}hw/intc/xive-internal.h +50
-0@@ -131,9 +131,59 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +/* EQ */ +typedef struct XiveEQ { +uint32_t w0; +#define EQ_W0_VALID PPC_BIT32(0) +#define EQ_W0_ENQUEUE PPC_BIT32(1) +#define EQ_W0_UCOND_NOTIFY PPC_BIT32(2) +#define EQ_W0_BACKLOG PPC_BIT32(3) +#define EQ_W0_PRECL_ESC_CTL PPC_BIT32(4) +#define EQ_W0_ESCALATE_CTL PPC_BIT32(5) +#define EQ_W0_END_OF_INTR PPC_BIT32(6) +#define EQ_W0_QSIZE PPC_BITMASK32(12, 15) +#define EQ_W0_SW0 PPC_BIT32(16) +#define EQ_W0_FIRMWARE EQ_W0_SW0/* Owned by FW */ +#define EQ_QSIZE_4K 0 +#define EQ_QSIZE_64K 4 +#define EQ_W0_HWDEP PPC_BITMASK32(24, 31) +uint32_t w1; +#define EQ_W1_ESn PPC_BITMASK32(0, 1) +#define EQ_W1_ESn_P PPC_BIT32(0) +#define EQ_W1_ESn_Q PPC_BIT32(1) +#define EQ_W1_ESe PPC_BITMASK32(2, 3) +#define EQ_W1_ESe_P PPC_BIT32(2) +#define EQ_W1_ESe_Q PPC_BIT32(3) +#define EQ_W1_GENERATION PPC_BIT32(9) +#define EQ_W1_PAGE_OFF PPC_BITMASK32(10, 31) +uint32_t w2; +#define EQ_W2_MIGRATION_REG PPC_BITMASK32(0, 3) +#define EQ_W2_OP_DESC_HI PPC_BITMASK32(4, 31) +uint32_t w3; +#define EQ_W3_OP_DESC_LO PPC_BITMASK32(0, 31) +uint32_t w4; +#define EQ_W4_ESC_EQ_BLOCK PPC_BITMASK32(4, 7) +#define EQ_W4_ESC_EQ_INDEX PPC_BITMASK32(8, 31) +uint32_t w5; +#define EQ_W5_ESC_EQ_DATA PPC_BITMASK32(1, 31) +uint32_t w6; +#define EQ_W6_FORMAT_BIT PPC_BIT32(8) +#define EQ_W6_NVT_BLOCK PPC_BITMASK32(9, 12) +#define EQ_W6_NVT_INDEX PPC_BITMASK32(13, 31) +uint32_t w7; +#define EQ_W7_F0_IGNORE PPC_BIT32(0) +#define EQ_W7_F0_BLK_GROUPING PPC_BIT32(1) +#define EQ_W7_F0_PRIORITY PPC_BITMASK32(8, 15) +#define EQ_W7_F1_WAKEZ PPC_BIT32(0) +#define EQ_W7_F1_LOG_SERVER_ID PPC_BITMASK32(1, 31) +}XiveEQ ; +#define XIVE_PRIORITY_MAX 7void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t idx); +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server,uint8_t prio, +uint32_t *out_eq_idx);#endif /* _INTC_XIVE_INTERNAL_H */
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 14/25] spapr: push the XIVE EQ data in OS event queue
In reply to Cédric Le GoaterQuoted 25 lines · Cédric Le Goater
If a triggered event is let through, the Event Queue data defined in the associated IVE is pushed in the in-memory event queue. The latter is a circular buffer provided by the OS using the
H_INT_SET_QUEUE_CONFIGhcall, one per server and priority couple. It is composed of Event Queue entries which are 4 bytes long, the first bit being a 'generation' bit and the 31 following bits the EQ Data field.The EQ Data field provides a way to set an invariant logical event source number for an IRQ. It is set with the
H_INT_SET_SOURCE_CONFIGhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)hw/intc/spapr_xive.c +2
-0@@ -193,9 +193,76 @@ static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server)return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; } +static void spapr_xive_eq_push (XiveEQ *eq,uint32_t data) +{
hw/intc/spapr_xive.c static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server) · line 207
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+uint64_t qaddr_base = (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; +uint32_t qsize =GETFIELD (EQ_W0_QSIZE , eq->w0); +uint32_t qindex =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); +uint32_t qgen =GETFIELD (EQ_W1_GENERATION , eq->w1); + +uint64_t qaddr = qaddr_base + (qindex <<2 ); +uint32_t qdata =cpu_to_be32 ((qgen <<31 ) | (data &0x7fffffff )); +uint32_t qentries =1 << (qsize +10 ); + +if (dma_memory_write (&address_space_memory, qaddr, &qdata,sizeof (qdata))) {
This suggests that uint32_t data contains guest endian data, which it generally shouldn't. Better to use stl_be_dma() (or whatever is appropriate for the endianness of the data field.
Quoted 13 lines
hw/intc/spapr_xive.c +13
-0+qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to write EQ data @0x%" + HWADDR_PRIx"\n" , __func__, qaddr); +return ; + } + + qindex = (qindex +1 ) % qentries; +if (qindex ==0 ) { + qgen ^=1 ; + eq->w1 =SETFIELD (EQ_W1_GENERATION , eq->w1, qgen); + } + eq->w1 =SETFIELD (EQ_W1_PAGE_OFF , eq->w1, qindex); +} +
hw/intc/spapr_xive.c static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server) · line 230
Quoted 10 lines
hw/intc/spapr_xive.c +8
-0static void spapr_xive_irq (sPAPRXive *xive,int lisn) { +XiveIVE *ive; +XiveEQ *eq; +uint32_t eq_idx; +uint8_t priority; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn);
As mentioned on other patches, I'm a little concerned by these guest-triggerable logs. I guess the LOG_GUEST_ERROR mask will save us, though.
Quoted 38 lines
hw/intc/spapr_xive.c +34
-0+return ; + } +if (ive->w &IVE_MASKED ) { +return ; + } + +/* Find our XiveEQ */ + eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); + eq =spapr_xive_get_eq (xive, eq_idx); +if (!eq) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No EQ for LISN %d\n" , lisn); +return ; + } + +if (eq->w0 &EQ_W0_ENQUEUE ) { +spapr_xive_eq_push (eq,GETFIELD (IVE_EQ_DATA , ive->w)); + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: !ENQUEUE not implemented\n" ); + } + +if (!(eq->w0 &EQ_W0_UCOND_NOTIFY )) { +qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); + } + +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { + priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7); + +/* The EQ is masked. Can this happen ? */ +if (priority ==0xff ) { +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); + } }/*
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH 08/25] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 146 lines · Cédric Le Goater
Quoted 58 lines · Greg Kurz
Quoted 55 lines · On Thu, 23 Nov 2017 14:29:38 +0100 Cédric Le Goater <[email protected]> wrote:
The XIVE interrupt controller uses a set of tables to redirect exception from event sources to CPU threads. The Interrupt Virtualization Entry (IVE) table, also known as Event Assignment Structure (EAS), is one them.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
The IVE stores Event Queue data associated with a source. The lookups are performed when the source is configured or when an event is triggered.
Signed-off-by Cédric Le Goater <[email protected]>--- default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 ++++++++++++ include/hw/ppc/spapr_xive.h | 44 ++++++++++ 5 files changed, 261 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +1
-0@@ -0,0 +1,165 @@ +/* Quoted 8 lines
hw/intc/spapr_xive.c line 7
Quoted 6 lines
hw/intc/spapr_xive.c new file +6
-0+* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as version 2 or (at your option) any later version.
yep. I will shorten the headers at the same time.
Quoted 72 lines
Quoted 59 lines
hw/intc/spapr_xive.c new file +58
-0+* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +void spapr_xive_reset (void *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp)hw/intc/spapr_xive.c line 75
Quoted 10 lines
hw/intc/spapr_xive.c new file +10
-0+{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_malloc0 (xive->nr_irqs *sizeof (XiveIVE));Even if it isn't documented, AFAIK current recommended practice is to do:
Quoted 1 line
xive->ivt = g_new0(XiveIVE, xive->nr_irqs);OK.
Quoted 7 lines
Quoted 4 lines
hw/intc/spapr_xive.c line 77
Quoted 2 lines
hw/intc/spapr_xive.c new file +2
-0+ +qemu_register_reset (spapr_xive_reset, dev);Shouldn't you set
dc->resetinspapr_xive_class_init()instead ?
qemu_register_reset()is a more general API. What is the best practice ?
Usually dc->reset for those cases where it can be used - which is basically anything sitting on a qbus.
There can be exceptions (e.g. the stuff I did for DRCs, because they sometimes had a bus and sometimes didn't), but AFAICT this isn't one.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 15/25] spapr: notify the CPU when the XIVE interrupt priority is more privileged
In reply to Cédric Le GoaterQuoted 32 lines · Cédric Le Goater
The Pending Interrupt Priority Register (PIPR) contains the priority of the most favored pending notification. It is calculated from the Interrupt Pending Buffer (IPB) which indicates a pending interrupt at the priority corresponding to the bit number.
If the PIPR is more favored (1) than the Current Processor Priority Register (CPPR), the CPU interrupt line is raised and the EO bit of the Notification Source Register is updated to notify the presence of an exception for the O/S. The check needs to be done whenever the PIPR or the CPPR is changed.
Then, the O/S Exception is raised and the O/S acknowledges the interrupt with a special read in the TIMA. If the EO bit of the Notification Source Register (NSR) is set (and it should), the Current Processor Priority Register (CPPR) takes the value of the Pending Interrupt Priority Register (PIPR). The bit number in the Interrupt Pending Buffer (IPB) corresponding to the priority of the pending interrupt is reseted and so is the EO bit of the NSR.
(1) numerically less than
Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)hw/intc/spapr_xive.c +0
-0@@ -39,9 +39,63 @@ struct sPAPRXiveICP {XiveEQ eqt[XIVE_PRIORITY_MAX +1 ];
hw/intc/spapr_xive.c struct sPAPRXiveICP { · line 49
Quoted 10 lines
hw/intc/spapr_xive.c +8
-0}; +/* Convert a priority number to an Interrupt Pending Buffer (IPB) +* register, which indicates a pending interrupt at the priority +* corresponding to the bit number +*/ +static uint8_t priority_to_ipb (uint8_t priority) +{ +return priority >XIVE_PRIORITY_MAX ? +0 :1 << (XIVE_PRIORITY_MAX - priority);
Does handling out of bounds values here make sense, or should you just assert() they're not passed in?
Quoted 5 lines
hw/intc/spapr_xive.c +5
-0+} + +/* Convert an Interrupt Pending Buffer (IPB) register to a Pending +* Interrupt Priority Register (PIPR), which contains the priority of +* the most favored pending notification.
hw/intc/spapr_xive.c struct sPAPRXiveICP { · line 64
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+* +* TODO: +* +* PIPR is clamped to CPPR. So the value in the PIPR is: +* +* v = leftmost_bit_of(ipb) (or 0xff); +* pipr = v < cppr ? v : cppr; +* +* Ben says: "which means it's never actually 0xff ... surprise !". +* But, the CPPR can be set to 0xFF ... I am confused ...
A resolution to this would be nice..
Quoted 10 lines
hw/intc/spapr_xive.c +7
-1+*/ +static uint8_t ipb_to_pipr (uint8_t ibp) +{ +return ibp ?clz32 ((uint32_t )ibp <<24 ) :0xff ; +} +static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp) { -return 0 ; +uint8_t nsr = icp->tima_os[TM_NSR ];
hw/intc/spapr_xive.c struct sPAPRXiveICP { · line 83
Quoted 10 lines
hw/intc/spapr_xive.c +10
-0+ +qemu_irq_lower (icp->output); + +if (icp->tima_os[TM_NSR ] &TM_QW1_NSR_EO ) { +uint8_t cppr = icp->tima_os[TM_PIPR ]; + + icp->tima_os[TM_CPPR ] = cppr; + +/* Reset the pending buffer bit */ + icp->tima_os[TM_IPB ] &= ~priority_to_ipb (cppr);
What if multiple irqs of the same priority were queued?
Quoted 70 lines
hw/intc/spapr_xive.c +36
-0+ icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); + +/* Drop Exception bit for OS */ + icp->tima_os[TM_NSR ] &= ~TM_QW1_NSR_EO ; + } + +return (nsr <<8 ) | icp->tima_os[TM_CPPR ]; +} + +static void spapr_xive_icp_notify (sPAPRXiveICP *icp) +{ +if (icp->tima_os[TM_PIPR ] < icp->tima_os[TM_CPPR ]) { + icp->tima_os[TM_NSR ] |=TM_QW1_NSR_EO ; +qemu_irq_raise (icp->output); + } }static void spapr_xive_icp_set_cppr (sPAPRXiveICP *icp,uint8_t cppr)@@ -51,6 +105,9 @@ static void spapr_xive_icp_set_cppr(sPAPRXiveICP *icp, uint8_t cppr) } icp->tima_os[TM_CPPR ] = cppr; + +/* CPPR has changed, inform the ICP which might raise an exception */ +spapr_xive_icp_notify (icp); }/* @@ -224,6 +281,8 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)XiveEQ *eq;uint32_t eq_idx;uint8_t priority; +uint32_t server; +sPAPRXiveICP *icp; ive =spapr_xive_get_ive (xive, lisn);if (!ive || !(ive->w &IVE_VALID )) {@@ -253,6 +312,13 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); } + server =GETFIELD (EQ_W6_NVT_INDEX , eq->w6); + icp =spapr_xive_icp_get (xive, server); +if (!icp) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No ICP for server %d\n" , server); +return ; + } +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7);@@ -260,9 +326,18 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)if (priority ==0xff ) {g_assert_not_reached (); } + +/* Update the IPB (Interrupt Pending Buffer) with the priority +* of the new notification and inform the ICP, which will +* decide to raise the exception, or not, depending the CPPR. +*/ + icp->tima_os[TM_IPB ] |=priority_to_ipb (priority); + icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); }else {qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); } + +spapr_xive_icp_notify (icp); }/*
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 17/25] spapr: add a sPAPRXive object to the machine
In reply to Cédric Le GoaterQuoted 2 lines · Cédric Le Goater
The XIVE object is designed to be always available, so it is created unconditionally on newer machines.
There doesn't actually seem to be anything dependent on machine version here.
Quoted 7 lines
Depending on the configuration and
the guest capabilities, the CAS negotiation process will decide which interrupt model to use, legacy or XIVE.The XIVE model makes use of the full range of the IRQ number space because the IRQ numbers for the CPU IPIs are allocated in the range below
XICS_IRQ_BASE, which is unused by XICS.
Ok. And I take it 4096 is enough space for the XIVE IPIs for the forseeable future?
Quoted 50 lines
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/spapr.c | 34 ++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ 2 files changed, 36 insertions(+)hw/ppc/spapr.c +24
-0@@ -56,6 +56,7 @@#include "hw/ppc/spapr_vio.h" #include "hw/pci-host/spapr.h" #include "hw/ppc/xics.h" +#include "hw/ppc/spapr_xive.h" #include "hw/pci/msi.h" #include "hw/pci/pci.h" @@ -204,6 +205,29 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) } } +static sPAPRXive *spapr_xive_create (sPAPRMachineState *spapr,int nr_irqs, +Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =object_new (TYPE_SPAPR_XIVE ); +object_property_add_child (OBJECT (spapr),"xive" , obj, &error_abort); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + } +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } + +return SPAPR_XIVE (obj); +error: +error_propagate (errp, local_err); +return NULL ; +} +static int spapr_fixup_cpu_smt_dt (void *fdt,int offset,PowerPCCPU *cpu,int smt_threads) {
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 2389
Quoted 6 lines
hw/ppc/spapr.c +3
-0@@ -2360,6 +2384,16 @@ static void ppc_spapr_init(MachineState *machine)/* Set up Interrupt Controller before we create the VCPUs */ xics_system_init (machine,XICS_IRQS_SPAPR , &error_fatal); +/* We don't have KVM support yet, so check for irqchip=on */ +if (kvm_enabled () &&machine_kernel_irqchip_required (machine)) { +error_report ("kernel_irqchip requested. no XIVE support" );
I think you want an actual exit(1) here, no? error_report() will print an error but keep going.
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 2394
Quoted 5 lines
hw/ppc/spapr.c +5
-0+ }else { +/* XIVE uses the full range of IRQ numbers. The CPU IPIs will +* use the range below XICS_IRQ_BASE, which is unused by XICS. */ + spapr->xive =spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , + &error_fatal);
XICS_IRQ_BASE == 4096, and XICS_IRQS_SPAPR (which we should rename at some point) == 1024.
So we have a total irq space of 5k, which is a bit odd. I'd be ok with rounding it out to 8k for newer machines if that's useful. Sparse allocations in there might make life easier for getting consistent irq numbers without an "allocator" per se (because we can use different regions for VIO, PCI intx, MSI, etc. etc.).
Quoted 25 lines
hw/ppc/spapr.c +2
-0+ } +/* Set up containers for ibm,client-architecture-support negotiated options */ spapr->ov5 =spapr_ovec_new ();include/hw/ppc/spapr.h +2
-0@@ -14,6 +14,7 @@ struct sPAPRNVRAM;typedef struct sPAPREventLogEntry sPAPREventLogEntry ;typedef struct sPAPREventSource sPAPREventSource ;typedef struct sPAPRPendingHPT sPAPRPendingHPT ; +typedef struct sPAPRXive sPAPRXive ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL#define SPAPR_ENTRY_POINT 0x100@@ -127,6 +128,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +sPAPRXive *xive; };#define H_SUCCESS 0
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 12/25] spapr: introduce a XIVE interrupt presenter model
In reply to David GibsonQuoted 39 lines · David Gibson
Quoted 38 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
The XIVE interrupt presenter exposes a set of rings, also called Thread Interrupt Management Areas (TIMA), to handle priority management and interrupt acknowledgment among other things. There is one ring per level of privilege, four in all. The one we are interested in for the sPAPR machine is the OS ring.
The TIMA is mapped at the same address for each CPU. '
current_cpu' is used to retrieve the targeted interrupt presenter object holding the cache data of the registers the model use.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 89 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 371 insertions(+)hw/intc/spapr_xive.c +1
-0@@ -23,9 +23,166 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h" Quoted 6 lines
hw/intc/spapr_xive.c line 30
Quoted 3 lines
hw/intc/spapr_xive.c +1
-0#include "xive-internal.h" +struct sPAPRXiveICP {I'd really prefer to avoid calling anything in xive "icp" to avoid confusion with xics.
OK.
Quoted 8 lines
Quoted 5 lines
The specs refers to the whole as an IVPE : Interrupt Virtualization Presentation Engine. In our model, we use the TIMA cached values of the OS ring and the
qemu_irqfor the CPU line.Would 'sPAPRXivePresenter' be fine ?
That'd be ok. Or call if sPAPRIVPE. Or even call it TIMA. I'd be fine with any of those.
In this model, I am making a lot of shortcuts in the XIVE concepts (which I don't master completely yet ...)
The IVPE is the part of the overall controller doing the interrupt presentation.
The TIMA refers to the MMIO region in which the thread interrupt management is done.
The XIVE structure that contains the 'virtual processor' interrupt state is the NVT: Notification Virtual Target. An index to an NVT is stored in the EQs to do the routing. I did not introduce the NVT in sPAPRXive because it's rather big, 128 bytes, and we don't need much of it (NSR, CPPR, PIPR, IPB) but we could use a shorten one.
So I think sPAPRXiveNVT, or sPAPRXiveVP (VP for virtual processor) would be better names.
We will need more of the NVT structure to support the hcalls doing the set and the get of the address of the Reporting Cache line (H_INT_{S,G}ET_OS_REPORTING_LINE). We can extend it when time comes.
C.
Re: [Qemu-devel] [PATCH 13/25] spapr: introduce the XIVE Event Queues
In reply to David GibsonQuoted 6 lines · David Gibson
Quoted 5 lines · Cédric Le Goater
The Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is one of the internal tables the XIVE interrupt controller uses to redirect exception from event sources to CPU threads.
Quoted 8 lines
Quoted 5 lines
The EQD specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which server (VPD in XIVE terminology) to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
Just to clarify my understanding a server / VPD in XIVE would typically correspond to a cpu - either real or virtual, yes?
yes. VP for "virtual processor" and VPD for "virtual processor descriptor" which contains the XIVE interrupt state of the VP when not dispatched. It is still described in some documentation as an NVT : Notification Virtual Target.
XIVE concepts were renamed at some time but the old name perdured. I am still struggling my way through all the names.
Quoted 62 lines
Quoted 62 lines
There is one XiveEQ per priority and the model chooses to store them under the Xive Interrupt presenter model. It will be retrieved, just like for XICS, through the 'intc' object pointer of the CPU.
The EQ indexing follows a simple pattern:
(server << 3) | (priority & 0x7)Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+)hw/intc/spapr_xive.c +12
-0@@ -23,6 +23,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h" @@ -34,6 +35,8 @@ struct sPAPRXiveICP {uint8_t tima[TM_RING_COUNT *0x10 ];uint8_t *tima_os;qemu_irq output; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp)@@ -183,6 +186,13 @@ static const MemoryRegionOps spapr_xive_tm_ops = { }, }; +static sPAPRXiveICP *spapr_xive_icp_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -632,6 +642,8 @@ static void spapr_xive_icp_reset(void *dev)sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev);memset (xicp->tima,0 ,sizeof (xicp->tima)); + +memset (xicp->eqt,0 ,sizeof (xicp->eqt)); }static void spapr_xive_icp_realize (DeviceState *dev,Error **errp)@@ -683,6 +695,23 @@ static void spapr_xive_icp_init(Object *obj) xicp->tima_os = &xicp->tima[TM_QW1_OS ]; }
Quoted 15 lines
hw/intc/spapr_xive.c static void spapr_xive_icp_init(Object *obj) · line 710
Quoted 13 lines
hw/intc/spapr_xive.c +13
-0+static const VMStateDescription vmstate_spapr_xive_icp_eq = { + .name =TYPE_SPAPR_XIVE_ICP "/eq" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ),Wow. Super descriptive field names there, but I guess that's not your fault.
The defines in the "xive-internal.h" give a better view ...
Quoted 17 lines
Quoted 17 lines
hw/intc/spapr_xive.c +6
-0+VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_icp_needed (void *opaque) {/* TODO check machine XIVE support */ @@ -696,6 +725,8 @@ static const VMStateDescription vmstate_spapr_xive_icp = { .needed = vmstate_spapr_xive_icp_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveICP, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_icp_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };@@ -755,3 +786,28 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn)
Quoted 8 lines
hw/intc/spapr_xive.c bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) · line 791
Quoted 6 lines
hw/intc/spapr_xive.c +3
-0ive->w &= ~IVE_VALID ;return true; } + +/* +* Use a simple indexing for the EQs. Is this server+priority encoding architected anywhere?
no. This is a model shortcut.
Quoted 1 line
Otherwise, why not use separate parameters?
yes. spapr_xive_get_eq() could use separate parameters and it would shorten the some of the hcalls.
The result is stored in a single field of the IVE, EQ_INDEX. So I will still need mangle/demangle routines but these could be simple macros. I will look at it.
Quoted 87 lines
Quoted 86 lines
hw/intc/spapr_xive.c +22
-0+*/ +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t eq_idx) +{ +int priority = eq_idx &0x7 ; +sPAPRXiveICP *xicp =spapr_xive_icp_get (xive, eq_idx >>3 ); + +return xicp ? &xicp->eqt[priority] :NULL ; +} + +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server, +uint8_t priority,uint32_t *out_eq_idx) +{ +if (priority >XIVE_PRIORITY_MAX ) { +return false; + } + +if (out_eq_idx) { + *out_eq_idx = (server <<3 ) | (priority &0x7 ); + } + +return true; +}hw/intc/xive-internal.h +50
-0@@ -131,9 +131,59 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +/* EQ */ +typedef struct XiveEQ { +uint32_t w0; +#define EQ_W0_VALID PPC_BIT32(0) +#define EQ_W0_ENQUEUE PPC_BIT32(1) +#define EQ_W0_UCOND_NOTIFY PPC_BIT32(2) +#define EQ_W0_BACKLOG PPC_BIT32(3) +#define EQ_W0_PRECL_ESC_CTL PPC_BIT32(4) +#define EQ_W0_ESCALATE_CTL PPC_BIT32(5) +#define EQ_W0_END_OF_INTR PPC_BIT32(6) +#define EQ_W0_QSIZE PPC_BITMASK32(12, 15) +#define EQ_W0_SW0 PPC_BIT32(16) +#define EQ_W0_FIRMWARE EQ_W0_SW0/* Owned by FW */ +#define EQ_QSIZE_4K 0 +#define EQ_QSIZE_64K 4 +#define EQ_W0_HWDEP PPC_BITMASK32(24, 31) +uint32_t w1; +#define EQ_W1_ESn PPC_BITMASK32(0, 1) +#define EQ_W1_ESn_P PPC_BIT32(0) +#define EQ_W1_ESn_Q PPC_BIT32(1) +#define EQ_W1_ESe PPC_BITMASK32(2, 3) +#define EQ_W1_ESe_P PPC_BIT32(2) +#define EQ_W1_ESe_Q PPC_BIT32(3) +#define EQ_W1_GENERATION PPC_BIT32(9) +#define EQ_W1_PAGE_OFF PPC_BITMASK32(10, 31) +uint32_t w2; +#define EQ_W2_MIGRATION_REG PPC_BITMASK32(0, 3) +#define EQ_W2_OP_DESC_HI PPC_BITMASK32(4, 31) +uint32_t w3; +#define EQ_W3_OP_DESC_LO PPC_BITMASK32(0, 31) +uint32_t w4; +#define EQ_W4_ESC_EQ_BLOCK PPC_BITMASK32(4, 7) +#define EQ_W4_ESC_EQ_INDEX PPC_BITMASK32(8, 31) +uint32_t w5; +#define EQ_W5_ESC_EQ_DATA PPC_BITMASK32(1, 31) +uint32_t w6; +#define EQ_W6_FORMAT_BIT PPC_BIT32(8) +#define EQ_W6_NVT_BLOCK PPC_BITMASK32(9, 12) +#define EQ_W6_NVT_INDEX PPC_BITMASK32(13, 31) +uint32_t w7; +#define EQ_W7_F0_IGNORE PPC_BIT32(0) +#define EQ_W7_F0_BLK_GROUPING PPC_BIT32(1) +#define EQ_W7_F0_PRIORITY PPC_BITMASK32(8, 15) +#define EQ_W7_F1_WAKEZ PPC_BIT32(0) +#define EQ_W7_F1_LOG_SERVER_ID PPC_BITMASK32(1, 31) +}XiveEQ ; +#define XIVE_PRIORITY_MAX 7void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t idx); +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server,uint8_t prio, +uint32_t *out_eq_idx);#endif /* _INTC_XIVE_INTERNAL_H */
Re: [Qemu-devel] [PATCH 14/25] spapr: push the XIVE EQ data in OS event queue
In reply to David GibsonQuoted 24 lines · David Gibson
Quoted 23 lines · Cédric Le Goater
If a triggered event is let through, the Event Queue data defined in the associated IVE is pushed in the in-memory event queue. The latter is a circular buffer provided by the OS using the
H_INT_SET_QUEUE_CONFIGhcall, one per server and priority couple. It is composed of Event Queue entries which are 4 bytes long, the first bit being a 'generation' bit and the 31 following bits the EQ Data field.The EQ Data field provides a way to set an invariant logical event source number for an IRQ. It is set with the
H_INT_SET_SOURCE_CONFIGhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)hw/intc/spapr_xive.c +0
-0@@ -193,9 +193,76 @@ static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server)return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; }
Quoted 16 lines
hw/intc/spapr_xive.c static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server) · line 207
Quoted 12 lines
hw/intc/spapr_xive.c +12
-0+static void spapr_xive_eq_push (XiveEQ *eq,uint32_t data) +{ +uint64_t qaddr_base = (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; +uint32_t qsize =GETFIELD (EQ_W0_QSIZE , eq->w0); +uint32_t qindex =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); +uint32_t qgen =GETFIELD (EQ_W1_GENERATION , eq->w1); + +uint64_t qaddr = qaddr_base + (qindex <<2 ); +uint32_t qdata =cpu_to_be32 ((qgen <<31 ) | (data &0x7fffffff )); +uint32_t qentries =1 << (qsize +10 ); + +if (dma_memory_write (&address_space_memory, qaddr, &qdata,sizeof (qdata))) {This suggests that
uint32_tdata contains guest endian data, which it generally shouldn't. Better to usestl_be_dma()(or whatever is appropriate for the endianness of the data field.
There are no requirement on the endianness of the data field and it is just stored in the IVE in the hcall H_INT_SET_SOURCE_CONFIG. So the guest can pass whatever it likes.
Quoted 19 lines
Quoted 19 lines
hw/intc/spapr_xive.c +17
-0+qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to write EQ data @0x%" + HWADDR_PRIx"\n" , __func__, qaddr); +return ; + } + + qindex = (qindex +1 ) % qentries; +if (qindex ==0 ) { + qgen ^=1 ; + eq->w1 =SETFIELD (EQ_W1_GENERATION , eq->w1, qgen); + } + eq->w1 =SETFIELD (EQ_W1_PAGE_OFF , eq->w1, qindex); +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) { +XiveIVE *ive; +XiveEQ *eq; +uint32_t eq_idx; +uint8_t priority;
Quoted 8 lines
hw/intc/spapr_xive.c static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server) · line 230
Quoted 4 lines
hw/intc/spapr_xive.c +4
-0+ + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn);As mentioned on other patches, I'm a little concerned by these guest-triggerable logs. I guess the
LOG_GUEST_ERRORmask will save us, though.
I want to track 'invalid' interrupts but I haven't seen these show up in my tests. I agree there are a little too much and some could just be asserts.
Thanks,
C.
Quoted 40 lines
Quoted 39 lines
hw/intc/spapr_xive.c +34
-0+return ; + } +if (ive->w &IVE_MASKED ) { +return ; + } + +/* Find our XiveEQ */ + eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); + eq =spapr_xive_get_eq (xive, eq_idx); +if (!eq) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No EQ for LISN %d\n" , lisn); +return ; + } + +if (eq->w0 &EQ_W0_ENQUEUE ) { +spapr_xive_eq_push (eq,GETFIELD (IVE_EQ_DATA , ive->w)); + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: !ENQUEUE not implemented\n" ); + } + +if (!(eq->w0 &EQ_W0_UCOND_NOTIFY )) { +qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); + } + +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { + priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7); + +/* The EQ is masked. Can this happen ? */ +if (priority ==0xff ) { +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); + } }/*
Re: [Qemu-devel] [PATCH 17/25] spapr: add a sPAPRXive object to the machine
In reply to David GibsonQuoted 6 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
The XIVE object is designed to be always available, so it is created unconditionally on newer machines.
There doesn't actually seem to be anything dependent on machine version here.
No. I thought that was too early in the patchset. This is handled in the last patch with a 'xive_exploitation' bool which is set to false on older machines.
But, nevertheless, the XIVE objects are always created even if not used. Something to discuss.
Quoted 10 lines
Quoted 7 lines
Depending on the configuration and
the guest capabilities, the CAS negotiation process will decide which interrupt model to use, legacy or XIVE.The XIVE model makes use of the full range of the IRQ number space because the IRQ numbers for the CPU IPIs are allocated in the range below
XICS_IRQ_BASE, which is unused by XICS.Ok. And I take it 4096 is enough space for the XIVE IPIs for the forseeable future?
The biggest real system I am aware of as 16 sockets, 192 cores, SMT8. That's 1536 cpus. pseries has a max_cpus of 1024.
Quoted 52 lines
Quoted 52 lines
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/spapr.c | 34 ++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ 2 files changed, 36 insertions(+)hw/ppc/spapr.c +24
-0@@ -56,6 +56,7 @@#include "hw/ppc/spapr_vio.h" #include "hw/pci-host/spapr.h" #include "hw/ppc/xics.h" +#include "hw/ppc/spapr_xive.h" #include "hw/pci/msi.h" #include "hw/pci/pci.h" @@ -204,6 +205,29 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) } } +static sPAPRXive *spapr_xive_create (sPAPRMachineState *spapr,int nr_irqs, +Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =object_new (TYPE_SPAPR_XIVE ); +object_property_add_child (OBJECT (spapr),"xive" , obj, &error_abort); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + } +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } + +return SPAPR_XIVE (obj); +error: +error_propagate (errp, local_err); +return NULL ; +} +static int spapr_fixup_cpu_smt_dt (void *fdt,int offset,PowerPCCPU *cpu,int smt_threads) {@@ -2360,6 +2384,16 @@ static void ppc_spapr_init(MachineState *machine)/* Set up Interrupt Controller before we create the VCPUs */ xics_system_init (machine,XICS_IRQS_SPAPR , &error_fatal);
Quoted 6 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 2389
Quoted 3 lines
hw/ppc/spapr.c +3
-0+/* We don't have KVM support yet, so check for irqchip=on */ +if (kvm_enabled () &&machine_kernel_irqchip_required (machine)) { +error_report ("kernel_irqchip requested. no XIVE support" );I think you want an actual exit(1) here, no?
error_report()will print an error but keep going.
yes. Today, it coredumps. I am not sure why. I will add an exit().
Quoted 7 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 2394
Quoted 6 lines
hw/ppc/spapr.c +5
-0+ }else { +/* XIVE uses the full range of IRQ numbers. The CPU IPIs will +* use the range below XICS_IRQ_BASE, which is unused by XICS. */ + spapr->xive =spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , + &error_fatal);
Quoted 8 lines
XICS_IRQ_BASE== 4096, andXICS_IRQS_SPAPR(which we should rename at some point) == 1024.So we have a total irq space of 5k, which is a bit odd. I'd be ok with rounding it out to 8k for newer machines if that's useful. Sparse allocations in there might make life easier for getting consistent irq numbers without an "allocator" per se (because we can use different regions for VIO, PCI intx, MSI, etc. etc.).
I will start another thread on that topic.
Thanks,
C.
Quoted 27 lines
Quoted 26 lines
hw/ppc/spapr.c +2
-0+ } +/* Set up containers for ibm,client-architecture-support negotiated options */ spapr->ov5 =spapr_ovec_new ();include/hw/ppc/spapr.h +2
-0@@ -14,6 +14,7 @@ struct sPAPRNVRAM;typedef struct sPAPREventLogEntry sPAPREventLogEntry ;typedef struct sPAPREventSource sPAPREventSource ;typedef struct sPAPRPendingHPT sPAPRPendingHPT ; +typedef struct sPAPRXive sPAPRXive ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL#define SPAPR_ENTRY_POINT 0x100@@ -127,6 +128,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +sPAPRXive *xive; };#define H_SUCCESS 0
Re: [Qemu-devel] [PATCH 17/25] spapr: add a sPAPRXive object to the machine
In reply to David GibsonQuoted 8 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 2394
Quoted 5 lines
hw/ppc/spapr.c +5
-0+ }else { +/* XIVE uses the full range of IRQ numbers. The CPU IPIs will +* use the range below XICS_IRQ_BASE, which is unused by XICS. */ + spapr->xive =spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , + &error_fatal);
XICS_IRQ_BASE== 4096, andXICS_IRQS_SPAPR(which we should rename at some point) == 1024.
BTW, why XICS_IRQ_BASE == 4096 ? I could not find a reason for this offset.
Quoted 2 lines
So we have a total irq space of 5k, which is a bit odd. I'd be ok with rounding it out to 8k for newer machines if that's useful.
ok. and using a machine class value to maintain compatibility. That would be useful if we allocate more PHBs.
Quoted 3 lines
Sparse allocations in there might make life easier for getting consistent irq numbers without an "allocator" per se (because we can use different regions for VIO, PCI intx, MSI, etc. etc.).
So, do you think we should modify the IRQ allocator routines to be able to segment the IRQ number space and let devices specify the range they want to use ?
That would be useful for the PHB LSIs. The starting IRQ for the PHB could be aligned on some value depending on the PHB index, first would come the LSI interrupts and then the MSIs which are allocated later on by the guest. We would have predictable values.
Thanks,
C.
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to David GibsonQuoted 23 lines · David Gibson
Quoted 22 lines · Cédric Le Goater
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
hw/intc/spapr_xive.c static void spapr_xive_irq(sPAPRXive *xive, int lisn) · line 175
Quoted 3 lines
hw/intc/spapr_xive.c +3
-0+switch (offset) { +case 0 : +spapr_xive_source_eoi (xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?Quoted 6 lines
Quoted 4 lines
Yes. I should.
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Perfect. The current model is working but I will see how I can improve it to use the PQ bits instead.
I also found a couple of issues on the way.
Quoted 7 lines
Quoted 5 lines
We do need the "#interrupt-cells" and "interrupt-controller" properties. They are missing from the XIVE sPAPR specs but there is no other way to find the parent controller for the LSIs ... I have re-asked the pHyp team to include them in the specs and fixed the QEMU model.
Told ya so :).
I believed you ! I just needed a test case :)
C.
Re: [Qemu-devel] [PATCH 10/25] spapr: add MMIO handlers for the XIVE interrupt sources
In reply to David GibsonQuoted 33 lines · David Gibson
Quoted 32 lines · Cédric Le Goater
Quoted 12 lines · Cédric Le Goater
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ switch (offset) { + case 0: + spapr_xive_source_eoi(xive, lisn);Hrm. I don't love that you're dealing with clearing that LSI bit here, but setting it at a different level.
The state machines are doing my head in a bit, is there any way you could derive the
STATUS_SENTbit from the PQ bits?Yes. I should.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I am also lacking a guest driver to exercise these LSIs so I didn't pay a lot of attention to level interrupts. Any idea ?
How about an old-school emulated PCI device? Maybe rtl8139?
Perfect. The current model is working but I will see how I can improve it to use the PQ bits instead.
Using the PQ bits is simplifying the model but we still have to maintain an array to store the IRQ type.
There are 3 unused bits in the IVE descriptor, bits[1-3]:
#define IVE_VALID PPC_BIT(0) #define IVE_EQ_BLOCK PPC_BITMASK(4, 7) /* Destination EQ block# */ #define IVE_EQ_INDEX PPC_BITMASK(8, 31) /* Destination EQ index */ #define IVE_MASKED PPC_BIT(32) /* Masked */ #define IVE_EQ_DATA PPC_BITMASK(33, 63) /* Data written to the EQ */
Quoted 4 lines
Quoted 2 lines
We could hijack one of them to store the LSI type and get rid of the type array. Would you object to that ?
Hrm. These IVE bits are architected, aren't they?
Yes and unused.
Quoted 5 lines
In which case I'd
be wary of stealing a reserved bit in case of future extensions.I'm wondering if we want another word / structure for storing non-architected, implementation specific flags or info.
That's what is done with the status array. As migration will put pressure on future changes, may be, we should go for an extra word for these model non-architected needs.
Quoted 3 lines
How does this work at the hardware level? Presumbly the actual hardware components don't communicate with the XIVE to request edge or level.
No.
Quoted 1 line
So how does it know? Specific ranges for LSIs?
When OPAL allocates interrupt numbers for a device, it records their type to handle the EOI a little differently for LSIs. For sPAPR, it is really the same, the hcall H_INT_GET_SOURCE_INFO gives the interrupt type to the guest and the EOI is handled with a specific load. A part from that, the LSI interrupts follow the same path as the MSI.
The device controller must have some extra logic to handle the level for these interrupts but I am no expert in the domain.
Quoted 1 line
If that we should probably do the same.
Modeling the LSI level with the PQ bits looks fine. We just need to store the IRQ type information somewhere under the XIVE object. We can keep it in a byte array or a bitmap to reduce the size. But if we foresee additional state to store, we might want to use the byte array directly.
Thanks,
C.
Re: [Qemu-devel] [PATCH 15/25] spapr: notify the CPU when the XIVE interrupt priority is more privileged
In reply to David GibsonQuoted 35 lines · David Gibson
Quoted 34 lines · Cédric Le Goater
The Pending Interrupt Priority Register (PIPR) contains the priority of the most favored pending notification. It is calculated from the Interrupt Pending Buffer (IPB) which indicates a pending interrupt at the priority corresponding to the bit number.
If the PIPR is more favored (1) than the Current Processor Priority Register (CPPR), the CPU interrupt line is raised and the EO bit of the Notification Source Register is updated to notify the presence of an exception for the O/S. The check needs to be done whenever the PIPR or the CPPR is changed.
Then, the O/S Exception is raised and the O/S acknowledges the interrupt with a special read in the TIMA. If the EO bit of the Notification Source Register (NSR) is set (and it should), the Current Processor Priority Register (CPPR) takes the value of the Pending Interrupt Priority Register (PIPR). The bit number in the Interrupt Pending Buffer (IPB) corresponding to the priority of the pending interrupt is reseted and so is the EO bit of the NSR.
(1) numerically less than
Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-)hw/intc/spapr_xive.c +0
-0@@ -39,9 +39,63 @@ struct sPAPRXiveICP {XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };
Quoted 11 lines
hw/intc/spapr_xive.c struct sPAPRXiveICP { · line 49
Quoted 8 lines
hw/intc/spapr_xive.c +8
-0+/* Convert a priority number to an Interrupt Pending Buffer (IPB) +* register, which indicates a pending interrupt at the priority +* corresponding to the bit number +*/ +static uint8_t priority_to_ipb (uint8_t priority) +{ +return priority >XIVE_PRIORITY_MAX ? +0 :1 << (XIVE_PRIORITY_MAX - priority);Does handling out of bounds values here make sense, or should you just
assert()they're not passed in?
Looking at the code, I think we could assert, yes. I need to check the SET_OS_PENDING command first.
Quoted 9 lines
Quoted 9 lines
hw/intc/spapr_xive.c +9
-0+} + +/* Convert an Interrupt Pending Buffer (IPB) register to a Pending +* Interrupt Priority Register (PIPR), which contains the priority of +* the most favored pending notification. +* +* TODO: +* +* PIPR is clamped to CPPR. So the value in the PIPR is:
Quoted 8 lines
hw/intc/spapr_xive.c struct sPAPRXiveICP { · line 64
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+* +* v = leftmost_bit_of(ipb) (or 0xff); +* pipr = v < cppr ? v : cppr; +* +* Ben says: "which means it's never actually 0xff ... surprise !". +* But, the CPPR can be set to 0xFF ... I am confused ... A resolution to this would be nice..
That's on my TODO list. Not a big issue.
Quoted 14 lines
Quoted 14 lines
hw/intc/spapr_xive.c +11
-1+*/ +static uint8_t ipb_to_pipr (uint8_t ibp) +{ +return ibp ?clz32 ((uint32_t )ibp <<24 ) :0xff ; +} +static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp) { -return 0 ; +uint8_t nsr = icp->tima_os[TM_NSR ]; + +qemu_irq_lower (icp->output); + +if (icp->tima_os[TM_NSR ] &TM_QW1_NSR_EO ) {
Quoted 8 lines
hw/intc/spapr_xive.c struct sPAPRXiveICP { · line 83
Quoted 6 lines
hw/intc/spapr_xive.c +6
-0+uint8_t cppr = icp->tima_os[TM_PIPR ]; + + icp->tima_os[TM_CPPR ] = cppr; + +/* Reset the pending buffer bit */ + icp->tima_os[TM_IPB ] &= ~priority_to_ipb (cppr);What if multiple irqs of the same priority were queued?
When an interrupt is EOI'ed, the queue is scanned to check for any pending interrupts. If so, a replay is forced with a call to force_external_irq_replay()
C.
Quoted 72 lines
Quoted 71 lines
hw/intc/spapr_xive.c +36
-0+ icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); + +/* Drop Exception bit for OS */ + icp->tima_os[TM_NSR ] &= ~TM_QW1_NSR_EO ; + } + +return (nsr <<8 ) | icp->tima_os[TM_CPPR ]; +} + +static void spapr_xive_icp_notify (sPAPRXiveICP *icp) +{ +if (icp->tima_os[TM_PIPR ] < icp->tima_os[TM_CPPR ]) { + icp->tima_os[TM_NSR ] |=TM_QW1_NSR_EO ; +qemu_irq_raise (icp->output); + } }static void spapr_xive_icp_set_cppr (sPAPRXiveICP *icp,uint8_t cppr)@@ -51,6 +105,9 @@ static void spapr_xive_icp_set_cppr(sPAPRXiveICP *icp, uint8_t cppr) } icp->tima_os[TM_CPPR ] = cppr; + +/* CPPR has changed, inform the ICP which might raise an exception */ +spapr_xive_icp_notify (icp); }/* @@ -224,6 +281,8 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)XiveEQ *eq;uint32_t eq_idx;uint8_t priority; +uint32_t server; +sPAPRXiveICP *icp; ive =spapr_xive_get_ive (xive, lisn);if (!ive || !(ive->w &IVE_VALID )) {@@ -253,6 +312,13 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); } + server =GETFIELD (EQ_W6_NVT_INDEX , eq->w6); + icp =spapr_xive_icp_get (xive, server); +if (!icp) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No ICP for server %d\n" , server); +return ; + } +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7);@@ -260,9 +326,18 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)if (priority ==0xff ) {g_assert_not_reached (); } + +/* Update the IPB (Interrupt Pending Buffer) with the priority +* of the new notification and inform the ICP, which will +* decide to raise the exception, or not, depending the CPPR. +*/ + icp->tima_os[TM_IPB ] |=priority_to_ipb (priority); + icp->tima_os[TM_PIPR ] =ipb_to_pipr (icp->tima_os[TM_IPB ]); }else {qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); } + +spapr_xive_icp_notify (icp); }/*
Re: [Qemu-devel] [PATCH 12/25] spapr: introduce a XIVE interrupt presenter model
In reply to Cédric Le GoaterQuoted 58 lines · Cédric Le Goater
Quoted 39 lines · David Gibson
Quoted 38 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
The XIVE interrupt presenter exposes a set of rings, also called Thread Interrupt Management Areas (TIMA), to handle priority management and interrupt acknowledgment among other things. There is one ring per level of privilege, four in all. The one we are interested in for the sPAPR machine is the OS ring.
The TIMA is mapped at the same address for each CPU. '
current_cpu' is used to retrieve the targeted interrupt presenter object holding the cache data of the registers the model use.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 271 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 89 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 371 insertions(+)hw/intc/spapr_xive.c +1
-0@@ -23,9 +23,166 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h" Quoted 6 lines
hw/intc/spapr_xive.c line 30
Quoted 3 lines
hw/intc/spapr_xive.c +1
-0#include "xive-internal.h" +struct sPAPRXiveICP {I'd really prefer to avoid calling anything in xive "icp" to avoid confusion with xics.
OK.
Quoted 8 lines
Quoted 5 lines
The specs refers to the whole as an IVPE : Interrupt Virtualization Presentation Engine. In our model, we use the TIMA cached values of the OS ring and the
qemu_irqfor the CPU line.Would 'sPAPRXivePresenter' be fine ?
That'd be ok. Or call if sPAPRIVPE. Or even call it TIMA. I'd be fine with any of those.
In this model, I am making a lot of shortcuts in the XIVE concepts (which I don't master completely yet ...)
The IVPE is the part of the overall controller doing the interrupt presentation.
The TIMA refers to the MMIO region in which the thread interrupt management is done.
Quoted 8 lines
The XIVE structure that contains the 'virtual processor' interrupt state is the NVT: Notification Virtual Target. An index to an NVT is stored in the EQs to do the routing. I did not introduce the NVT in sPAPRXive because it's rather big, 128 bytes, and we don't need much of it (NSR, CPPR, PIPR, IPB) but we could use a shorten one.
So I think sPAPRXiveNVT, or sPAPRXiveVP (VP for virtual processor) would be better names.
Ok. I prefer sPAPRXiveNVT of these two.
Quoted 8 lines
We will need more of the NVT structure to support the hcalls doing the set and the get of the address of the Reporting Cache line (H_INT_{S,G}ET_OS_REPORTING_LINE). We can extend it when time comes.
C.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 17/25] spapr: add a sPAPRXive object to the machine
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
Quoted 8 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 2394
Quoted 5 lines
hw/ppc/spapr.c +5
-0+ }else { +/* XIVE uses the full range of IRQ numbers. The CPU IPIs will +* use the range below XICS_IRQ_BASE, which is unused by XICS. */ + spapr->xive =spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , + &error_fatal);
XICS_IRQ_BASE== 4096, andXICS_IRQS_SPAPR(which we should rename at some point) == 1024.BTW, why
XICS_IRQ_BASE== 4096 ? I could not find a reason for this offset.
It's basically arbitrary. Possible I copied the value used in practice on a PowerVM system of the time, but I don't recall for sure.
Quoted 6 lines
Quoted 2 lines
So we have a total irq space of 5k, which is a bit odd. I'd be ok with rounding it out to 8k for newer machines if that's useful.
ok. and using a machine class value to maintain compatibility. That would be useful if we allocate more PHBs.
Quoted 7 lines
Quoted 3 lines
Sparse allocations in there might make life easier for getting consistent irq numbers without an "allocator" per se (because we can use different regions for VIO, PCI intx, MSI, etc. etc.).
So, do you think we should modify the IRQ allocator routines to be able to segment the IRQ number space and let devices specify the range they want to use ?
No, I'm suggesting *eliminating* the IRQ allocator routines (except for backwards compat) and having devices "just know" their irq numbers based on their own device number and the portion of the overall irq space they're supposed to live in.
PCI MSI is an exception, obviously, it will need some sort of runtime allocation.
Quoted 9 lines
That would be useful for the PHB LSIs. The starting IRQ for the PHB could be aligned on some value depending on the PHB index, first would come the LSI interrupts and then the MSIs which are allocated later on by the guest. We would have predictable values.
Thanks,
C.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 17/25] spapr: add a sPAPRXive object to the machine
In reply to Cédric Le GoaterQuoted 8 lines · Cédric Le Goater
Quoted 6 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
The XIVE object is designed to be always available, so it is created unconditionally on newer machines.
There doesn't actually seem to be anything dependent on machine version here.
Quoted 6 lines
No. I thought that was too early in the patchset. This is handled in the last patch with a '
xive_exploitation' bool which is set to false on older machines.But, nevertheless, the XIVE objects are always created even if not used. Something to discuss.
That'll definitely break backwards migration, since the destination won't understand the (unused but still present) xive state it receives. So xives can only be created on new machine types. I'm ok (at least tentatively) with always creating them on the newer machine types, regardless of whether the guest ends up exploiting it or not.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Depending on the configuration and
the guest capabilities, the CAS negotiation process will decide which interrupt model to use, legacy or XIVE.The XIVE model makes use of the full range of the IRQ number space because the IRQ numbers for the CPU IPIs are allocated in the range below
XICS_IRQ_BASE, which is unused by XICS.
Quoted 5 lines
Quoted 2 lines
Ok. And I take it 4096 is enough space for the XIVE IPIs for the forseeable future?
The biggest real system I am aware of as 16 sockets, 192 cores, SMT8. That's 1536 cpus. pseries has a
max_cpusof 1024.
Ok, so we can go to double the current system size, but not 4x. Not sure if that seems adequate or not. Still it's a relatively minor detail.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 14/25] spapr: push the XIVE EQ data in OS event queue
In reply to Cédric Le GoaterQuoted 42 lines · Cédric Le Goater
Quoted 24 lines · David Gibson
Quoted 23 lines · Cédric Le Goater
If a triggered event is let through, the Event Queue data defined in the associated IVE is pushed in the in-memory event queue. The latter is a circular buffer provided by the OS using the
H_INT_SET_QUEUE_CONFIGhcall, one per server and priority couple. It is composed of Event Queue entries which are 4 bytes long, the first bit being a 'generation' bit and the 31 following bits the EQ Data field.The EQ Data field provides a way to set an invariant logical event source number for an IRQ. It is set with the
H_INT_SET_SOURCE_CONFIGhcall.Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)hw/intc/spapr_xive.c +0
-0@@ -193,9 +193,76 @@ static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server)return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; }Quoted 16 lines
hw/intc/spapr_xive.c static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server) · line 207
Quoted 12 lines
hw/intc/spapr_xive.c +12
-0+static void spapr_xive_eq_push (XiveEQ *eq,uint32_t data) +{ +uint64_t qaddr_base = (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; +uint32_t qsize =GETFIELD (EQ_W0_QSIZE , eq->w0); +uint32_t qindex =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); +uint32_t qgen =GETFIELD (EQ_W1_GENERATION , eq->w1); + +uint64_t qaddr = qaddr_base + (qindex <<2 ); +uint32_t qdata =cpu_to_be32 ((qgen <<31 ) | (data &0x7fffffff )); +uint32_t qentries =1 << (qsize +10 ); + +if (dma_memory_write (&address_space_memory, qaddr, &qdata,sizeof (qdata))) {This suggests that
uint32_tdata contains guest endian data, which it generally shouldn't. Better to usestl_be_dma()(or whatever is appropriate for the endianness of the data field.
Quoted 3 lines
There are no requirement on the endianness of the data field and it is just stored in the IVE in the hcall
H_INT_SET_SOURCE_CONFIG. So the guest can pass whatever it likes.
Hm, ok. Guest endian (or at least, not definitively host-endian) data in a plain uint32_t makes me uncomfortable. Could we use char data[4] instead, to make it clear it's a byte-ordered buffer, rather than a number as far as the XIVE is concerned.
Hm.. except that doesn't quite work, because the hardware must define which end that generation bit ends up in...
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
hw/intc/spapr_xive.c +17
-0+qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to write EQ data @0x%" + HWADDR_PRIx"\n" , __func__, qaddr); +return ; + } + + qindex = (qindex +1 ) % qentries; +if (qindex ==0 ) { + qgen ^=1 ; + eq->w1 =SETFIELD (EQ_W1_GENERATION , eq->w1, qgen); + } + eq->w1 =SETFIELD (EQ_W1_PAGE_OFF , eq->w1, qindex); +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) { +XiveIVE *ive; +XiveEQ *eq; +uint32_t eq_idx; +uint8_t priority;Quoted 8 lines
hw/intc/spapr_xive.c static sPAPRXiveICP *spapr_xive_icp_get(sPAPRXive *xive, int server) · line 230
Quoted 4 lines
hw/intc/spapr_xive.c +4
-0+ + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn);As mentioned on other patches, I'm a little concerned by these guest-triggerable logs. I guess the
LOG_GUEST_ERRORmask will save us, though.
Quoted 3 lines
I want to track 'invalid' interrupts but I haven't seen these show up in my tests. I agree there are a little too much and some could just be asserts.
Uh.. I don't think many can be assert()s. assert() is only appropriate if it being tripped definitely indicates a bug in qemu. Nearly all these qemu_log()s I've seen can be tripped by the guest doing something bad, which absolutely should not assert() qemu.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 12/25] spapr: introduce a XIVE interrupt presenter model
In reply to David GibsonQuoted 18 lines
Quoted 18 lines
Quoted 2 lines
That'd be ok. Or call if sPAPRIVPE. Or even call it TIMA. I'd be fine with any of those.
In this model, I am making a lot of shortcuts in the XIVE concepts (which I don't master completely yet ...)
The IVPE is the part of the overall controller doing the interrupt presentation.
The TIMA refers to the MMIO region in which the thread interrupt management is done.
The XIVE structure that contains the 'virtual processor' interrupt state is the NVT: Notification Virtual Target. An index to an NVT is stored in the EQs to do the routing. I did not introduce the NVT in sPAPRXive because it's rather big, 128 bytes, and we don't need much of it (NSR, CPPR, PIPR, IPB) but we could use a shorten one.
Quoted 4 lines
Quoted 2 lines
So I think sPAPRXiveNVT, or sPAPRXiveVP (VP for virtual processor) would be better names.
Ok. I prefer sPAPRXiveNVT of these two.
Fine. Also what about the location of the files. They are under hw/intc/ but shouldn't we consider moving them under hw/spapr/ ?
Thanks,
C.
Re: [Qemu-devel] [PATCH 13/25] spapr: introduce the XIVE Event Queues
In reply to Cédric Le GoaterQuoted 133 lines · Cédric Le Goater
Quoted 6 lines · David Gibson
Quoted 5 lines · Cédric Le Goater
The Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is one of the internal tables the XIVE interrupt controller uses to redirect exception from event sources to CPU threads.
Quoted 8 lines
Quoted 5 lines
The EQD specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which server (VPD in XIVE terminology) to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
Just to clarify my understanding a server / VPD in XIVE would typically correspond to a cpu - either real or virtual, yes?
yes. VP for "virtual processor" and VPD for "virtual processor descriptor" which contains the XIVE interrupt state of the VP when not dispatched. It is still described in some documentation as an NVT : Notification Virtual Target.
XIVE concepts were renamed at some time but the old name perdured. I am still struggling my way through all the names.
Quoted 62 lines
Quoted 62 lines
There is one XiveEQ per priority and the model chooses to store them under the Xive Interrupt presenter model. It will be retrieved, just like for XICS, through the 'intc' object pointer of the CPU.
The EQ indexing follows a simple pattern:
(server << 3) | (priority & 0x7)Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/spapr_xive.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+)hw/intc/spapr_xive.c +12
-0@@ -23,6 +23,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h" @@ -34,6 +35,8 @@ struct sPAPRXiveICP {uint8_t tima[TM_RING_COUNT *0x10 ];uint8_t *tima_os;qemu_irq output; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_icp_accept (sPAPRXiveICP *icp)@@ -183,6 +186,13 @@ static const MemoryRegionOps spapr_xive_tm_ops = { }, }; +static sPAPRXiveICP *spapr_xive_icp_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_ICP (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {@@ -632,6 +642,8 @@ static void spapr_xive_icp_reset(void *dev)sPAPRXiveICP *xicp =SPAPR_XIVE_ICP (dev);memset (xicp->tima,0 ,sizeof (xicp->tima)); + +memset (xicp->eqt,0 ,sizeof (xicp->eqt)); }static void spapr_xive_icp_realize (DeviceState *dev,Error **errp)@@ -683,6 +695,23 @@ static void spapr_xive_icp_init(Object *obj) xicp->tima_os = &xicp->tima[TM_QW1_OS ]; }Quoted 15 lines
hw/intc/spapr_xive.c static void spapr_xive_icp_init(Object *obj) · line 710
Quoted 13 lines
hw/intc/spapr_xive.c +13
-0+static const VMStateDescription vmstate_spapr_xive_icp_eq = { + .name =TYPE_SPAPR_XIVE_ICP "/eq" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ),Wow. Super descriptive field names there, but I guess that's not your fault.
The defines in the "
xive-internal.h" give a better view ...Quoted 17 lines
Quoted 17 lines
hw/intc/spapr_xive.c +6
-0+VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_icp_needed (void *opaque) {/* TODO check machine XIVE support */ @@ -696,6 +725,8 @@ static const VMStateDescription vmstate_spapr_xive_icp = { .needed = vmstate_spapr_xive_icp_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (tima, sPAPRXiveICP), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveICP, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_icp_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };@@ -755,3 +786,28 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn)Quoted 8 lines
hw/intc/spapr_xive.c bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn) · line 791
Quoted 6 lines
hw/intc/spapr_xive.c +3
-0ive->w &= ~IVE_VALID ;return true; } + +/* +* Use a simple indexing for the EQs. Is this server+priority encoding architected anywhere?
no. This is a model shortcut.
Quoted 8 lines
Quoted 1 line
Otherwise, why not use separate parameters?
yes.
spapr_xive_get_eq()could use separate parameters and it would shorten the some of the hcalls.The result is stored in a single field of the IVE,
EQ_INDEX. So I will still need mangle/demangle routines but these could be simple macros. I will look at it.
Hm, ok. So it's architected in the sense that you're using the encoding from the EQ_INDEX field throughout. That's could be a reasonable choice, I can't really tell yet.
On the other hand, it might be easier to read if we use server and priority as separate parameters until the point we actually encode into the EQ_INDEX field.
Quoted 89 lines
Quoted 88 lines
Quoted 87 lines
hw/intc/spapr_xive.c +22
-0+*/ +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t eq_idx) +{ +int priority = eq_idx &0x7 ; +sPAPRXiveICP *xicp =spapr_xive_icp_get (xive, eq_idx >>3 ); + +return xicp ? &xicp->eqt[priority] :NULL ; +} + +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server, +uint8_t priority,uint32_t *out_eq_idx) +{ +if (priority >XIVE_PRIORITY_MAX ) { +return false; + } + +if (out_eq_idx) { + *out_eq_idx = (server <<3 ) | (priority &0x7 ); + } + +return true; +}hw/intc/xive-internal.h +50
-0@@ -131,9 +131,59 @@ typedef struct XiveIVE {#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ } XiveIVE; +/* EQ */ +typedef struct XiveEQ { +uint32_t w0; +#define EQ_W0_VALID PPC_BIT32(0) +#define EQ_W0_ENQUEUE PPC_BIT32(1) +#define EQ_W0_UCOND_NOTIFY PPC_BIT32(2) +#define EQ_W0_BACKLOG PPC_BIT32(3) +#define EQ_W0_PRECL_ESC_CTL PPC_BIT32(4) +#define EQ_W0_ESCALATE_CTL PPC_BIT32(5) +#define EQ_W0_END_OF_INTR PPC_BIT32(6) +#define EQ_W0_QSIZE PPC_BITMASK32(12, 15) +#define EQ_W0_SW0 PPC_BIT32(16) +#define EQ_W0_FIRMWARE EQ_W0_SW0/* Owned by FW */ +#define EQ_QSIZE_4K 0 +#define EQ_QSIZE_64K 4 +#define EQ_W0_HWDEP PPC_BITMASK32(24, 31) +uint32_t w1; +#define EQ_W1_ESn PPC_BITMASK32(0, 1) +#define EQ_W1_ESn_P PPC_BIT32(0) +#define EQ_W1_ESn_Q PPC_BIT32(1) +#define EQ_W1_ESe PPC_BITMASK32(2, 3) +#define EQ_W1_ESe_P PPC_BIT32(2) +#define EQ_W1_ESe_Q PPC_BIT32(3) +#define EQ_W1_GENERATION PPC_BIT32(9) +#define EQ_W1_PAGE_OFF PPC_BITMASK32(10, 31) +uint32_t w2; +#define EQ_W2_MIGRATION_REG PPC_BITMASK32(0, 3) +#define EQ_W2_OP_DESC_HI PPC_BITMASK32(4, 31) +uint32_t w3; +#define EQ_W3_OP_DESC_LO PPC_BITMASK32(0, 31) +uint32_t w4; +#define EQ_W4_ESC_EQ_BLOCK PPC_BITMASK32(4, 7) +#define EQ_W4_ESC_EQ_INDEX PPC_BITMASK32(8, 31) +uint32_t w5; +#define EQ_W5_ESC_EQ_DATA PPC_BITMASK32(1, 31) +uint32_t w6; +#define EQ_W6_FORMAT_BIT PPC_BIT32(8) +#define EQ_W6_NVT_BLOCK PPC_BITMASK32(9, 12) +#define EQ_W6_NVT_INDEX PPC_BITMASK32(13, 31) +uint32_t w7; +#define EQ_W7_F0_IGNORE PPC_BIT32(0) +#define EQ_W7_F0_BLK_GROUPING PPC_BIT32(1) +#define EQ_W7_F0_PRIORITY PPC_BITMASK32(8, 15) +#define EQ_W7_F1_WAKEZ PPC_BIT32(0) +#define EQ_W7_F1_LOG_SERVER_ID PPC_BITMASK32(1, 31) +}XiveEQ ; +#define XIVE_PRIORITY_MAX 7void spapr_xive_reset (void *dev);XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t idx); +bool spapr_xive_eq_for_server (sPAPRXive *xive,uint32_t server,uint8_t prio, +uint32_t *out_eq_idx);#endif /* _INTC_XIVE_INTERNAL_H */
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH 19/25] spapr: add hcalls support for the XIVE interrupt mode
In reply to Cédric Le GoaterQuoted 123 lines · Cédric Le Goater
A set of Hypervisor's call are used to configure the interrupt sources and the event/notification queues of the guest:
-
H_INT_GET_SOURCE_INFOused to obtain the address of the MMIO page of the Event State Buffer (PQ bits) entry associated with the source.
-
H_INT_SET_SOURCE_CONFIGassigns a source to a "target".
-
H_INT_GET_SOURCE_CONFIGdetermines to which "target" and "priority" is assigned to a source
-
H_INT_GET_QUEUE_INFOreturns the address of the notification management page associated with the specified "target" and "priority".
-
H_INT_SET_QUEUE_CONFIGsets or resets the event queue for a given "target" and "priority". It is also used to set the notification config associated with the queue, only unconditional notification for the moment. Reset is performed with a queue size of 0 and queueing is disabled in that case.
-
H_INT_GET_QUEUE_CONFIGreturns the queue settings for a given "target" and "priority".
-
H_INT_RESETresets all of the partition's interrupt exploitation structures to their initial state, losing all configuration set via the hcalls
H_INT_SET_SOURCE_CONFIGandH_INT_SET_QUEUE_CONFIG.-
H_INT_SYNCissue a synchronisation on a source to make sure sure all notifications have reached their queue.
Calls that still need to be addressed :
H_INT_SET_OS_REPORTING_LINE
H_INT_GET_OS_REPORTING_LINESee the code for more documentation on each hcall.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/intc/Makefile.objs | 2 +- hw/intc/spapr_xive_hcall.c | 885 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 2 + include/hw/ppc/spapr.h | 15 +- include/hw/ppc/spapr_xive.h | 4 + 5 files changed, 906 insertions(+), 2 deletions(-) create mode 100644 hw/intc/spapr_xive_hcall.chw/intc/Makefile.objs +1
-1@@ -35,7 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o -obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o spapr_xive_hcall.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive_hcall.c new file +43
-0@@ -0,0 +1,885 @@ +/* +* QEMU PowerPC sPAPR XIVE model +* +* Copyright (c) 2017, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* 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, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/ppc/spapr.h" +#include "hw/ppc/spapr_xive.h" +#include "hw/ppc/fdt.h" +#include "monitor/monitor.h" + +#include "xive-internal.h" + +/* Priority ranges reserved by the hypervisor. The Linux driver is +* expected to choose priority 6. +*/ +static const uint32_t reserved_priorities[] = { +7 ,/* start */ +0xf8 ,/* count */ +}; + +static bool priority_is_valid (uint32_t priority) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (reserved_priorities) /2 ; i++) { +uint32_t base = reserved_priorities[2 * i]; +uint32_t count = reserved_priorities[2 * i +1 ];
hw/intc/spapr_xive_hcall.c line 53
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+ +if (priority >= base && priority < base + count) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: priority %d is reserved\n" , + __func__, priority); +return false; + } + } + +return true; +}
This seems like overkill. Aren't there only 0..7 levels supported in hardware, in which case a one byte bitmap will suffice to store the reserved levels.
To check my understanding again, if you're running this with KVM, the host kernel and qemu will need to agree on which are the reserved levels, yes?
Quoted 33 lines
hw/intc/spapr_xive_hcall.c new file +33
-0+ +/* +* The H_INT_GET_SOURCE_INFO hcall() is used to obtain the logical +* real address of the MMIO page through which the Event State Buffer +* entry associated with the value of the "lisn" parameter is managed. +* +* Parameters: +* Input +* - "flags" +* Bits 0-63 reserved +* - "lisn" is per "interrupts", "interrupt-map", or +* "ibm,xive-lisn-ranges" properties, or as returned by the +* ibm,query-interrupt-source-number RTAS call, or as returned +* by the H_ALLOCATE_VAS_WINDOW hcall +* +* Output +* - R4: "flags" +* Bits 0-59: Reserved +* Bit 60: H_INT_ESB must be used for Event State Buffer +* management +* Bit 61: 1 == LSI 0 == MSI +* Bit 62: the full function page supports trigger +* Bit 63: Store EOI Supported +* - R5: Logical Real address of full function Event State Buffer +* management page, -1 if ESB hcall flag is set to 1. +* - R6: Logical Real Address of trigger only Event State Buffer +* management page or -1. +* - R7: Power of 2 page size for the ESB management pages returned in +* R5 and R6. +*/ +static target_ulong h_int_get_source_info(PowerPCCPU *cpu, + sPAPRMachineState *spapr, + target_ulong opcode,
hw/intc/spapr_xive_hcall.c line 96
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+ target_ulong *args) +{ +sPAPRXive *xive = spapr->xive; +XiveIVE *ive; +target_ulong flags = args[0 ]; +target_ulong lisn = args[1 ]; +uint64_t mmio_base; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ;
Is H_FUNCTION required by the PAPR ACRs here? Usually we only use H_FUNCTION if the hypercall doesn't exist at all, and if unavailable for other reasons use H_AUTHORITY or something.
Quoted 7 lines
hw/intc/spapr_xive_hcall.c new file +7
-0+ } + +if (flags) { +return H_PARAMETER ; + } + +/*
hw/intc/spapr_xive_hcall.c line 113
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + + ive =spapr_xive_get_ive (spapr->xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +return H_P2 ; + } + + mmio_base = (uint64_t )xive->esb_base + (1ull << xive->esb_shift) * lisn;
Hrm.. why was xive->esb_base not already a u64?
Quoted 9 lines
hw/intc/spapr_xive_hcall.c new file +9
-0+ args[0 ] =0 ; +if (spapr_xive_irq_is_lsi (xive, lisn)) { + args[0 ] |=XIVE_SRC_LSI ; + } +if (xive->flags &XIVE_SRC_TRIGGER ) { + args[0 ] |=XIVE_SRC_TRIGGER ; + } + +if (xive->flags &XIVE_SRC_H_INT_ESB ) {
hw/intc/spapr_xive_hcall.c line 133
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+ args[1 ] =-1 ;/* never used in QEMU */ + args[2 ] =-1 ; + }else { + args[1 ] = mmio_base; +if (xive->flags &XIVE_SRC_TRIGGER ) { + args[2 ] =-1 ;/* No specific trigger page */ + }else { + args[2 ] =-1 ;/* TODO: support for specific trigger page */ + } + }
What does the availability of SRC_TRIGGER (and INT_ESB) depend on? If it varies with host capabilities, that's going to be real pain for migration.
Quoted 35 lines
hw/intc/spapr_xive_hcall.c new file +35
-0+ + args[3 ] = xive->esb_shift; + +return H_SUCCESS ; +} + +/* +* The H_INT_SET_SOURCE_CONFIG hcall() is used to assign a Logical +* Interrupt Source to a target. The Logical Interrupt Source is +* designated with the "lisn" parameter and the target is designated +* with the "target" and "priority" parameters. Upon return from the +* hcall(), no additional interrupts will be directed to the old EQ. +* +* TODO: The old EQ should be investigated for interrupts that +* occurred prior to or during the hcall(). +* +* Parameters: +* Input: +* - "flags" +* Bits 0-61: Reserved +* Bit 62: set the "eisn" in the EA +* Bit 63: masks the interrupt source in the hardware interrupt +* control structure. An interrupt masked by this mechanism will +* be dropped, but it's source state bits will still be +* set. There is no race-free way of unmasking and restoring the +* source. Thus this should only be used in interrupts that are +* also masked at the source, and only in cases where the +* interrupt is not meant to be used for a large amount of time +* because no valid target exists for it for example +* - "lisn" is per "interrupts", "interrupt-map", or +* "ibm,xive-lisn-ranges" properties, or as returned by the +* ibm,query-interrupt-source-number RTAS call, or as returned by +* the H_ALLOCATE_VAS_WINDOW hcall +* - "target" is per "ibm,ppc-interrupt-server#s" or +* "ibm,ppc-interrupt-gserver#s"
hw/intc/spapr_xive_hcall.c line 178
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+* - "priority" is a valid priority not in +* "ibm,plat-res-int-priorities" +* - "eisn" is the guest EISN associated with the "lisn" +* +* Output: +* - None +*/ + +#define XIVE_SRC_SET_EISN (1ull << (63 - 62)) +#define XIVE_SRC_MASK (1ull << (63 - 63))
Aren't there already a bunch of macros you have for defining things in terms of IBM bit numbers, so you can avoid open coding (63 - whatever).
Quoted 45 lines
hw/intc/spapr_xive_hcall.c new file +45
-0+ +static target_ulong h_int_set_source_config (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +XiveIVE *ive; +uint64_t new_ive; +target_ulong flags = args[0 ]; +target_ulong lisn = args[1 ]; +target_ulong target = args[2 ]; +target_ulong priority = args[3 ]; +target_ulong eisn = args[4 ]; +uint32_t eq_idx; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags & ~(XIVE_SRC_SET_EISN |XIVE_SRC_MASK )) { +return H_PARAMETER ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + + ive =spapr_xive_get_ive (spapr->xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +return H_P2 ; + } + +/* priority 0xff is used to reset the IVE */ +if (priority ==0xff ) { + new_ive =IVE_VALID |IVE_MASKED ; + goto out; + } + + new_ive = ive->w; + +if (flags &XIVE_SRC_MASK ) { + new_ive = ive->w |IVE_MASKED ; + }else { + new_ive = ive->w & ~IVE_MASKED ;
hw/intc/spapr_xive_hcall.c line 233
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+ } + +if (!priority_is_valid (priority)) { +return H_P4 ; + } + +/* TODO: If the partition thread count is greater than the +* hardware thread count, validate the "target" has a +* corresponding hardware thread else return H_NOT_AVAILABLE. +*/
What's this about? I thought the point of XIVE was you could set up target queues for your vcpus regardless of mapping to physical cpus.
Quoted 287 lines
hw/intc/spapr_xive_hcall.c new file +287
-0+/* Validate that "target" is part of the list of threads allocated +* to the partition. For that, find the EQ corresponding to the +* target. +*/ +if (!spapr_xive_eq_for_server (spapr->xive, target, priority, &eq_idx)) { +return H_P3 ; + } + + new_ive =SETFIELD (IVE_EQ_BLOCK , new_ive,0ul ); + new_ive =SETFIELD (IVE_EQ_INDEX , new_ive, eq_idx); + +if (flags &XIVE_SRC_SET_EISN ) { + new_ive =SETFIELD (IVE_EQ_DATA , new_ive, eisn); + } + +out: +/* TODO: handle syncs ? */ + +/* And update */ + ive->w = new_ive; + +return H_SUCCESS ; +} + +/* +* The H_INT_GET_SOURCE_CONFIG hcall() is used to determine to which +* target/priority pair is assigned to the specified Logical Interrupt +* Source. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-63 Reserved +* - "lisn" is per "interrupts", "interrupt-map", or +* "ibm,xive-lisn-ranges" properties, or as returned by the +* ibm,query-interrupt-source-number RTAS call, or as +* returned by the H_ALLOCATE_VAS_WINDOW hcall +* +* Output: +* - R4: Target to which the specified Logical Interrupt Source is +* assigned +* - R5: Priority to which the specified Logical Interrupt Source is +* assigned +* - R6: EISN for the specified Logical Interrupt Source (this will be +* equivalent to the LISN if not changed by H_INT_SET_SOURCE_CONFIG) +*/ +static target_ulong h_int_get_source_config (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; +target_ulong lisn = args[1 ]; +XiveIVE *ive; +XiveEQ *eq; +uint32_t eq_idx; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags) { +return H_PARAMETER ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + + ive =spapr_xive_get_ive (spapr->xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +return H_P2 ; + } + + eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); + eq =spapr_xive_get_eq (spapr->xive, eq_idx); +if (!eq) { +return H_HARDWARE ; + } + + args[0 ] =GETFIELD (EQ_W6_NVT_INDEX , eq->w6); + +if (ive->w &IVE_MASKED ) { + args[1 ] =0xff ; + }else { + args[1 ] =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7); + } + + args[2 ] =GETFIELD (IVE_EQ_DATA , ive->w); + +return H_SUCCESS ; +} + +/* +* The H_INT_GET_QUEUE_INFO hcall() is used to get the logical real +* address of the notification management page associated with the +* specified target and priority. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-63 Reserved +* - "target" is per "ibm,ppc-interrupt-server#s" or +* "ibm,ppc-interrupt-gserver#s" +* - "priority" is a valid priority not in +* "ibm,plat-res-int-priorities" +* +* Output: +* - R4: Logical real address of notification page +* - R5: Power of 2 page size of the notification page +*/ +static target_ulong h_int_get_queue_info (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; +target_ulong target = args[1 ]; +target_ulong priority = args[2 ]; +uint32_t eq_idx; +XiveEQ *eq; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags) { +return H_PARAMETER ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + +if (!priority_is_valid (priority)) { +return H_P3 ; + } + +/* Validate that "target" is part of the list of threads allocated +* to the partition. For that, find the EQ corresponding to the +* target. +*/ +if (!spapr_xive_eq_for_server (spapr->xive, target, priority, &eq_idx)) { +return H_P2 ; + } + +/* TODO: If the partition thread count is greater than the +* hardware thread count, validate the "target" has a +* corresponding hardware thread else return H_NOT_AVAILABLE. +*/ + + eq =spapr_xive_get_eq (spapr->xive, eq_idx); +if (!eq) { +return H_HARDWARE ; + } + + args[0 ] =-1 ;/* TODO: return ESn page */ +if (eq->w0 &EQ_W0_ENQUEUE ) { + args[1 ] =GETFIELD (EQ_W0_QSIZE , eq->w0) +12 ; + }else { + args[1 ] =0 ; + } + +return H_SUCCESS ; +} + +/* +* The H_INT_SET_QUEUE_CONFIG hcall() is used to set or reset a EQ for +* a given "target" and "priority". It is also used to set the +* notification config associated with the EQ. An EQ size of 0 is +* used to reset the EQ config for a given target and priority. If +* resetting the EQ config, the END associated with the given "target" +* and "priority" will be changed to disable queueing. +* +* Upon return from the hcall(), no additional interrupts will be +* directed to the old EQ (if one was set). The old EQ (if one was +* set) should be investigated for interrupts that occurred prior to +* or during the hcall(). +* +* Parameters: +* Input: +* - "flags" +* Bits 0-62: Reserved +* Bit 63: Unconditional Notify (n) per the XIVE spec +* - "target" is per "ibm,ppc-interrupt-server#s" or +* "ibm,ppc-interrupt-gserver#s" +* - "priority" is a valid priority not in +* "ibm,plat-res-int-priorities" +* - "eventQueue": The logical real address of the start of the EQ +* - "eventQueueSize": The power of 2 EQ size per "ibm,xive-eq-sizes" +* +* Output: +* - None +*/ + +#define XIVE_EQ_ALWAYS_NOTIFY (1ull << (63 - 63)) + +static target_ulong h_int_set_queue_config (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; +target_ulong target = args[1 ]; +target_ulong priority = args[2 ]; +target_ulong qpage = args[3 ]; +target_ulong qsize = args[4 ]; +uint32_t eq_idx; +XiveEQ *old_eq; +XiveEQ eq; +uint32_t qdata; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags & ~XIVE_EQ_ALWAYS_NOTIFY ) { +return H_PARAMETER ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + +if (!priority_is_valid (priority)) { +return H_P3 ; + } + +/* Validate that "target" is part of the list of threads allocated +* to the partition. For that, find the EQ corresponding to the +* target. +*/ +if (!spapr_xive_eq_for_server (spapr->xive, target, priority, &eq_idx)) { +return H_P2 ; + } + +/* TODO: If the partition thread count is greater than the +* hardware thread count, validate the "target" has a +* corresponding hardware thread else return H_NOT_AVAILABLE. +*/ + + old_eq =spapr_xive_get_eq (spapr->xive, eq_idx); +if (!old_eq) { +return H_HARDWARE ; + } + + eq = *old_eq; + +switch (qsize) { +case 12 : +case 16 : +case 21 : +case 24 : + eq.w3 = ((uint64_t )qpage) &0xffffffff ; + eq.w2 = (((uint64_t )qpage)) >>32 &0x0fffffff ; + eq.w0 |=EQ_W0_ENQUEUE ; + eq.w0 =SETFIELD (EQ_W0_QSIZE , eq.w0, qsize -12 ); +break ; +case 0 : +/* reset queue and disable queueing */ + eq.w2 = eq.w3 =0 ; + eq.w0 &= ~EQ_W0_ENQUEUE ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid EQ size %" PRIx64"\n" , + __func__, qsize); +return H_P5 ; + } + +if (qsize) { +/* +* Let's validate the EQ address with a read of the first EQ +* entry. We could also check that the full queue has been +* zeroed by the OS. +*/ +if (address_space_read (&address_space_memory, qpage, +MEMTXATTRS_UNSPECIFIED , + (uint8_t *) &qdata,sizeof (qdata))) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to read EQ data @0x%" + HWADDR_PRIx"\n" , __func__, qpage); +return H_P4 ; + } + } +
hw/intc/spapr_xive_hcall.c line 531
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+/* Ensure the priority and target are correctly set (they will not +* be right after allocation) +*/ + eq.w6 =SETFIELD (EQ_W6_NVT_BLOCK ,0ul ,0ul ) | +SETFIELD (EQ_W6_NVT_INDEX ,0ul , target); + eq.w7 =SETFIELD (EQ_W7_F0_PRIORITY ,0ul , priority); + +/* TODO: depends on notitification page (ESn) from H_INT_GET_QUEUE_INFO */ +if (flags &XIVE_EQ_ALWAYS_NOTIFY ) { + eq.w0 |=EQ_W0_UCOND_NOTIFY ;
Do you need to also clear if the flag is not set? AFAICT eq.w0 is inherited from teh old queue and enver reset from scratch.
hw/intc/spapr_xive_hcall.c line 544
Quoted 13 lines
hw/intc/spapr_xive_hcall.c new file +13
-0+ } + +/* The generation bit for the EQ starts at 1 and The EQ page +* offset counter starts at 0. +*/ + eq.w1 =EQ_W1_GENERATION |SETFIELD (EQ_W1_PAGE_OFF ,0ul ,0ul ); + eq.w0 |=EQ_W0_VALID ; + +/* TODO: issue syncs required to ensure all in-flight interrupts +* are complete on the old EQ */ + +/* Update EQ */ + *old_eq = eq;
Hrm. The BQL probably saves you, but in general do you need to make sure the ENQUEUE bit is set after updating everything else?
Quoted 82 lines
hw/intc/spapr_xive_hcall.c new file +82
-0+ +return H_SUCCESS ; +} + +/* +* The H_INT_GET_QUEUE_CONFIG hcall() is used to get a EQ for a given +* target and priority. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-62: Reserved +* Bit 63: Debug: Return debug data +* - "target" is per "ibm,ppc-interrupt-server#s" or +* "ibm,ppc-interrupt-gserver#s" +* - "priority" is a valid priority not in +* "ibm,plat-res-int-priorities" +* +* Output: +* - R4: "flags": +* Bits 0-62: Reserved +* Bit 63: The value of Unconditional Notify (n) per the XIVE spec +* - R5: The logical real address of the start of the EQ +* - R6: The power of 2 EQ size per "ibm,xive-eq-sizes" +* - R7: The value of Event Queue Offset Counter per XIVE spec +* if "Debug" = 1, else 0 +* +*/ + +#define XIVE_EQ_DEBUG (1ull << (63 - 63)) + +static target_ulong h_int_get_queue_config (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; +target_ulong target = args[1 ]; +target_ulong priority = args[2 ]; +uint32_t eq_idx; +XiveEQ *eq; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags & ~XIVE_EQ_DEBUG ) { +return H_PARAMETER ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + +if (!priority_is_valid (priority)) { +return H_P3 ; + } + +/* Validate that "target" is part of the list of threads allocated +* to the partition. For that, find the EQ corresponding to the +* target. +*/ +if (!spapr_xive_eq_for_server (spapr->xive, target, priority, &eq_idx)) { +return H_P2 ; + } + +/* TODO: If the partition thread count is greater than the +* hardware thread count, validate the "target" has a +* corresponding hardware thread else return H_NOT_AVAILABLE. +*/ + + eq =spapr_xive_get_eq (spapr->xive, eq_idx); +if (!eq) { +return H_HARDWARE ; + } + + args[0 ] =0 ; +if (eq->w0 &EQ_W0_UCOND_NOTIFY ) { + args[0 ] |=XIVE_EQ_ALWAYS_NOTIFY ; + } +
hw/intc/spapr_xive_hcall.c line 636
Quoted 10 lines
hw/intc/spapr_xive_hcall.c new file +10
-0+if (eq->w0 &EQ_W0_ENQUEUE ) { + args[1 ] = + (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; + args[2 ] =GETFIELD (EQ_W0_QSIZE , eq->w0) +12 ; + }else { + args[1 ] =0 ; + args[2 ] =0 ; + } + +/* TODO: do we need any locking on the EQ ? */
Probably not if you're designating it as protected by the BQL.
Quoted 301 lines
hw/intc/spapr_xive_hcall.c new file +249
-0+if (flags &XIVE_EQ_DEBUG ) { +/* Load the event queue generation number into the return flags */ + args[0 ] |=GETFIELD (EQ_W1_GENERATION , eq->w1); + +/* Load R7 with the event queue offset counter */ + args[3 ] =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); + } + +return H_SUCCESS ; +} + +/* +* The H_INT_SET_OS_REPORTING_LINE hcall() is used to set the +* reporting cache line pair for the calling thread. The reporting +* cache lines will contain the OS interrupt context when the OS +* issues a CI store byte to @TIMA+0xC10 to acknowledge the OS +* interrupt. The reporting cache lines can be reset by inputting -1 +* in "reportingLine". Issuing the CI store byte without reporting +* cache lines registered will result in the data not being accessible +* to the OS. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-63: Reserved +* - "reportingLine": The logical real address of the reporting cache +* line pair +* +* Output: +* - None +*/ +static target_ulong h_int_set_os_reporting_line (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + +/* TODO: H_INT_SET_OS_REPORTING_LINE */ +return H_FUNCTION ; +} + +/* +* The H_INT_GET_OS_REPORTING_LINE hcall() is used to get the logical +* real address of the reporting cache line pair set for the input +* "target". If no reporting cache line pair has been set, -1 is +* returned. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-63: Reserved +* - "target" is per "ibm,ppc-interrupt-server#s" or +* "ibm,ppc-interrupt-gserver#s" +* - "reportingLine": The logical real address of the reporting cache +* line pair +* +* Output: +* - R4: The logical real address of the reporting line if set, else -1 +*/ +static target_ulong h_int_get_os_reporting_line (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + +/* TODO: H_INT_GET_OS_REPORTING_LINE */ +return H_FUNCTION ; +} + +/* +* The H_INT_ESB hcall() is used to issue a load or store to the ESB +* page for the input "lisn". This hcall is only supported for LISNs +* that have the ESB hcall flag set to 1 when returned from hcall() +* H_INT_GET_SOURCE_INFO. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-62: Reserved +* bit 63: Store: Store=1, store operation, else load operation +* - "lisn" is per "interrupts", "interrupt-map", or +* "ibm,xive-lisn-ranges" properties, or as returned by the +* ibm,query-interrupt-source-number RTAS call, or as +* returned by the H_ALLOCATE_VAS_WINDOW hcall +* - "esbOffset" is the offset into the ESB page for the load or store operation +* - "storeData" is the data to write for a store operation +* +* Output: +* - R4: R4: The value of the load if load operation, else -1 +*/ + +#define XIVE_ESB_STORE (1ull << (63 - 63)) + +static target_ulong h_int_esb (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +sPAPRXive *xive = spapr->xive; +XiveIVE *ive; +target_ulong flags = args[0 ]; +target_ulong lisn = args[1 ]; +target_ulong offset = args[2 ]; +target_ulong data = args[3 ]; +uint64_t esb_base; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags & ~XIVE_ESB_STORE ) { +return H_PARAMETER ; + } + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +return H_P2 ; + } + +if (offset > (1ull << xive->esb_shift)) { +return H_P3 ; + } + + esb_base = (uint64_t )xive->esb_base + (1ull << xive->esb_shift) * lisn; + esb_base += offset; + +if (dma_memory_rw (&address_space_memory, esb_base, &data,8 , + (flags &XIVE_ESB_STORE ))) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to rw data @0x%" + HWADDR_PRIx"\n" , __func__, esb_base); +return H_HARDWARE ; + } + args[0 ] = (flags &XIVE_ESB_STORE ) ?-1 : data; +return H_SUCCESS ; +} + +/* +* The H_INT_SYNC hcall() is used to issue hardware syncs that will +* ensure any in flight events for the input lisn are in the event +* queue. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-63: Reserved +* - "lisn" is per "interrupts", "interrupt-map", or +* "ibm,xive-lisn-ranges" properties, or as returned by the +* ibm,query-interrupt-source-number RTAS call, or as +* returned by the H_ALLOCATE_VAS_WINDOW hcall +* +* Output: +* - None +*/ +static target_ulong h_int_sync (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +XiveIVE *ive; +target_ulong flags = args[0 ]; +target_ulong lisn = args[1 ]; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags) { +return H_PARAMETER ; + } + + ive =spapr_xive_get_ive (spapr->xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +return H_P2 ; + } + +/* +* H_STATE should be returned if a H_INT_RESET is in progress. +* This is not needed when running the emulation under QEMU +*/ + +/* This is not real hardware. Nothing to be done */ +return H_SUCCESS ; +} + +/* +* The H_INT_RESET hcall() is used to reset all of the partition's +* interrupt exploitation structures to their initial state. This +* means losing all previously set interrupt state set via +* H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG. +* +* Parameters: +* Input: +* - "flags" +* Bits 0-63: Reserved +* +* Output: +* - None +*/ +static target_ulong h_int_reset (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong flags = args[0 ]; + +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return H_FUNCTION ; + } + +if (flags) { +return H_PARAMETER ; + } + +spapr_xive_reset (spapr->xive); +return H_SUCCESS ; +} + +void spapr_xive_hcall_init (sPAPRMachineState *spapr) +{ +spapr_register_hypercall (H_INT_GET_SOURCE_INFO , h_int_get_source_info); +spapr_register_hypercall (H_INT_SET_SOURCE_CONFIG , h_int_set_source_config); +spapr_register_hypercall (H_INT_GET_SOURCE_CONFIG , h_int_get_source_config); +spapr_register_hypercall (H_INT_GET_QUEUE_INFO , h_int_get_queue_info); +spapr_register_hypercall (H_INT_SET_QUEUE_CONFIG , h_int_set_queue_config); +spapr_register_hypercall (H_INT_GET_QUEUE_CONFIG , h_int_get_queue_config); +spapr_register_hypercall (H_INT_SET_OS_REPORTING_LINE , + h_int_set_os_reporting_line); +spapr_register_hypercall (H_INT_GET_OS_REPORTING_LINE , + h_int_get_os_reporting_line); +spapr_register_hypercall (H_INT_ESB , h_int_esb); +spapr_register_hypercall (H_INT_SYNC , h_int_sync); +spapr_register_hypercall (H_INT_RESET , h_int_reset); +}hw/ppc/spapr.c +2
-0@@ -222,6 +222,8 @@ static sPAPRXive *spapr_xive_create(sPAPRMachineState *spapr, int nr_irqs, goto error; } +spapr_xive_hcall_init (spapr); +return SPAPR_XIVE (obj); error:error_propagate (errp, local_err);include/hw/ppc/spapr.h +14
-1@@ -387,7 +387,20 @@ struct sPAPRMachineState {#define H_INVALIDATE_PID 0x378#define H_REGISTER_PROC_TBL 0x37C#define H_SIGNAL_SYS_RESET 0x380 -#define MAX_HCALL_OPCODE H_SIGNAL_SYS_RESET + +#define H_INT_GET_SOURCE_INFO 0x3A8 +#define H_INT_SET_SOURCE_CONFIG 0x3AC +#define H_INT_GET_SOURCE_CONFIG 0x3B0 +#define H_INT_GET_QUEUE_INFO 0x3B4 +#define H_INT_SET_QUEUE_CONFIG 0x3B8 +#define H_INT_GET_QUEUE_CONFIG 0x3BC +#define H_INT_SET_OS_REPORTING_LINE 0x3C0 +#define H_INT_GET_OS_REPORTING_LINE 0x3C4 +#define H_INT_ESB 0x3C8 +#define H_INT_SYNC 0x3CC +#define H_INT_RESET 0x3D0 + +#define MAX_HCALL_OPCODE H_INT_RESET/* The hcalls above are standardized in PAPR and implemented by pHyp * as well. include/hw/ppc/spapr_xive.h +4
-0@@ -79,4 +79,8 @@ bool spapr_xive_irq_unset(sPAPRXive *xive, uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);void spapr_xive_icp_pic_print_info (sPAPRXiveICP *xicp,Monitor *mon); +typedef struct sPAPRMachineState sPAPRMachineState ; + +void spapr_xive_hcall_init (sPAPRMachineState *spapr); +#endif /* PPC_SPAPR_XIVE_H */
Signature · 4 lines
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