ppc/pnv: booting the kernel and reaching user space
v5 cover ppc/pnv: booting the kernel and reaching user space
Hello,
Here is the latest version of the ppc/pnv platform patchset. PowerNV (as Non-Virtualized) is the "baremetal" platform using the OPAL firmware. It runs Linux on IBM and Open Power systems and it can be used as an hypervisor OS, to run KVM guests, or simply as a host OS. The goal here is to add support for the baremetal platform and possibly later also for the KVM PR guests but not for HV guests.
In v5, all the comments from v4 should have been addressed. Most of the differences are cleanups suggested by David but there a couple of important changes :
- an addition of a new firmware to qemu : skiboot 5.3.7.
- a rework of the native Interrupt Presentation Controller model which now uses memory subregions instead of a hash table.
- a removal of the Power9 LPC Controller. This is still in the plans but the models need a little more work.
The initial patches provide a minimal platform with some RAM to load the ROMs : firmware, kernel and initrd. The device tree is built with what is available at reset time. Then, comes the PnvChip object acting as a container for other devices required to run a system. The cores are added to each chip with some restrictions on the number and the ids. Next is the XSCOM model, the sideband bus which gives controls to all the units in the POWER8 chip, the LPC controller for the console, the native interrupt controller and the PSI HB model to handle the external interrupt.
The next step should be IPMI support which adds a BT device on the ISA bus and some device tree extensions to read sensors and FRUs. This is relatively straight forward and most of the IPMI code has been discussed already on the list. Then should come a PHB3 model to include some PCI devices. This is big and it needs a few helpers in the PCI core.
If you feel adventurous, you can grab kernel and rootfs images :
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/zImage.epapr
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/rootfs.cpio.xz
and give it a try. The full patchset is available here :
https://github.com/legoater/qemu/commits/powernv-ipmi-2.8
This is a wip branch, which I stabilize when the qemu version, on which it is based, is released.
Thanks,
C.
Benjamin Herrenschmidt (5):
ppc/pnv: add skeleton PowerNV platform
ppc/pnv: add a LPC controller
ppc/pnv: Add cut down PSI bridge model and hookup external interrupt ppc/pnv: Add OCC model stub with interrupt support ppc/pnv: Add Naples chip support for LPC interrupts
Cédric Le Goater (12):
ppc: add skiboot firmware for the pnv platform ppc/pnv: add a PnvChip object
ppc/pnv: add a core mask to PnvChip ppc/pnv: add a PIR handler to PnvChip ppc/pnv: add a PnvCore object
ppc/pnv: add XSCOM infrastructure ppc/pnv: add XSCOM handlers to PnvCore ppc/pnv: add a ISA bus
ppc/xics: Add "native" XICS subclass ppc/pnv: add a XICS native to each PowerNV chip ppc/xics: add a xics_get_cpu_index_by_pir helper ppc/xics: introduce a helper to insert a new ics
.gitmodules | 3 + MAINTAINERS | 1 + Makefile | 2 +- default-configs/ppc64-softmmu.mak | 4 +- hw/intc/Makefile.objs | 1 + hw/intc/xics.c | 6 + hw/intc/xics_native.c | 323 ++++++++++++++ hw/ppc/Makefile.objs | 2 + hw/ppc/pnv.c | 888 ++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 248 +++++++++++ hw/ppc/pnv_lpc.c | 514 ++++++++++++++++++++++ hw/ppc/pnv_occ.c | 135 ++++++ hw/ppc/pnv_psi.c | 615 ++++++++++++++++++++++++++ hw/ppc/pnv_xscom.c | 277 ++++++++++++ include/hw/ppc/pnv.h | 159 +++++++ include/hw/ppc/pnv_core.h | 50 +++ include/hw/ppc/pnv_lpc.h | 76 ++++ include/hw/ppc/pnv_occ.h | 38 ++ include/hw/ppc/pnv_psi.h | 64 +++ include/hw/ppc/pnv_xscom.h | 84 ++++ include/hw/ppc/xics.h | 26 ++ pc-bios/README | 5 + pc-bios/skiboot.lid | Bin 0 -> 983893 bytes roms/Makefile | 8 +- roms/skiboot | 1 + 25 files changed, 3527 insertions(+), 3 deletions(-) create mode 100644 hw/intc/xics_native.c create mode 100644 hw/ppc/pnv.c create mode 100644 hw/ppc/pnv_core.c create mode 100644 hw/ppc/pnv_lpc.c create mode 100644 hw/ppc/pnv_occ.c create mode 100644 hw/ppc/pnv_psi.c create mode 100644 hw/ppc/pnv_xscom.c create mode 100644 include/hw/ppc/pnv.h create mode 100644 include/hw/ppc/pnv_core.h create mode 100644 include/hw/ppc/pnv_lpc.h create mode 100644 include/hw/ppc/pnv_occ.h create mode 100644 include/hw/ppc/pnv_psi.h create mode 100644 include/hw/ppc/pnv_xscom.h create mode 100644 pc-bios/skiboot.lid create mode 160000 roms/skiboot
Signature · 1 line
2.7.4
PATCH v5 1/17 ppc: add skiboot firmware for the pnv platform
This is the initial image of skiboot 5.3.7 (commit 762d0082) for the PowerPC PowerNV (Non-Virtualized) platform. Built from submodule.
--- .gitmodules | 3 +++ MAINTAINERS | 1 + Makefile | 2 +- pc-bios/README | 5 +++++ pc-bios/skiboot.lid | Bin 0 -> 983893 bytes roms/Makefile | 8 +++++++- roms/skiboot | 1 + 7 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 pc-bios/skiboot.lid create mode 160000 roms/skiboot
.gitmodules +3 -0
@@ -31,3 +31,6 @@ [submodule "roms/u-boot"] path = roms/u-boot url = git://git.qemu-project.org/u-boot.git +[submodule "roms/skiboot"] + path = roms/skiboot + url = git://git.qemu.org/skiboot.git
MAINTAINERS +1 -0
@@ -656,6 +656,7 @@ F: include/hw/*/xics* F: pc-bios/spapr-rtas/* F: pc-bios/spapr-rtas.bin F: pc-bios/slof.bin +F: pc-bios/skiboot.lid F: docs/specs/ppc-spapr-hcalls.txt F: docs/specs/ppc-spapr-hotplug.txt F: tests/spapr*
Makefile +1 -1
@@ -421,7 +421,7 @@ qemu-icon.bmp qemu_logo_no_text.svg \ bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \ multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \ s390-ccw.img \ -spapr-rtas.bin slof.bin \ +spapr-rtas.bin slof.bin skiboot.lid \ palcode-clipper \ u-boot.e500 else
pc-bios/README +5 -0
@@ -42,3 +42,8 @@ it was compiled using the qemu-ppce500 target. A git mirror is available at: git://git.qemu-project.org/u-boot.git The hash used to compile the current version is: 2072e72 + +- Skiboot (https://github.com/open-power/skiboot/) is an OPAL + (OpenPower Abstraction Layer) firmware for OpenPOWER systems. It can + run an hypervisor OS or simply a host OS on the "baremetal" + platform, also known as the PowerNV (Non-Virtualized) platform.
pc-bios/skiboot.lid new file binary +0 -0
roms/Makefile +7 -1
@@ -63,6 +63,7 @@ default: @echo " efirom -- update nic roms (bios+efi, this needs" @echo " the EfiRom utility from edk2 / tianocore)" @echo " slof -- update slof.bin" + @echo " skiboot -- update skiboot.lid" @echo " u-boot.e500 -- update u-boot.e500" bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
@@ -103,7 +104,7 @@ build-lgplvgabios: $(MAKE) -C vgabios $(vgabios_targets) -.PHONY: sgabios +.PHONY: sgabios skiboot sgabios: $(MAKE) -C sgabios cp sgabios/sgabios.bin ../pc-bios
@@ -146,6 +147,10 @@ u-boot.e500: $(powerpc_cross_prefix)strip u-boot/build.e500/u-boot -o \ ../pc-bios/u-boot.e500 +skiboot: + $(MAKE) -C skiboot CROSS=$(powerpc64_cross_prefix) + cp skiboot/skiboot.lid ../pc-bios/skiboot.lid + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C vgabios clean
@@ -155,3 +160,4 @@ clean: $(MAKE) -C ipxe/src veryclean $(MAKE) -C SLOF clean rm -rf u-boot/build.e500 + $(MAKE) -C skiboot clean
roms/skiboot new file +1 -0
@@ -0,0 +1 @@ +Subproject commit 762d0082f18e4fb921a2d44a1051b02d8b0f6381
Signature · 1 line
2.7.4
PATCH v5 2/17 ppc/pnv: add skeleton PowerNV platform
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
The goal is to emulate a PowerNV system at the level of the skiboot firmware, which loads the OS and provides some runtime services. Power Systems have a lower firmware (HostBoot) that does low level system initialization, like DRAM training. This is beyond the scope of what qemu will address in a PowerNV guest.
No devices yet, not even an interrupt controller. Just to get started, some RAM to load the skiboot firmware, the kernel and initrd. The device tree is fully created in the machine reset op.
[clg: - updated for qemu-2.7
- replaced fprintf by error_report
- used a common definition of _FDT macro
- removed VMStateDescription as migration is not yet supported
- added IBM Copyright statements
- reworked kernel_filename handling
- merged PnvSystem and sPowerNVMachineState
- removed PHANDLE_XICP
- added ppc_create_page_sizes_prop helper
- removed nmi support
- removed kvm support
- updated powernv machine to version 2.8
- removed chips and cpus, They will be provided in another patches
- added a machine reset routine to initialize the device tree (also)
- french has a squelette and english a skeleton.
- improved commit log.
- reworked prototypes parameters
- added a check on the ram size (thanks to Michael Ellerman)
- fixed chip-id cell
- changed MAX_CPUS to 2048
- simplified memory node creation to one node only
- removed machine version
- rewrote the device tree creation with the fdt "rw" routines
- s/sPowerNVMachineState/PnvMachineState/
- etc.]
---
Changes since v4:
- modified ppc_powernv_init() to use a 'MachineState *' and replaced the use of the global 'ram_size' by 'machine->ram_size'. The result is cleaner.
Changes since v3:
- fixed printf format for hwaddr
- used fdt_pack() before writing the tree in memory
- removed the requirement on having a kernel loaded as running with just a firmware is fine. We will need to discuss the inclusion of the file skiboot.lid under qemu.
Changes since v2:
- some more copyright header cleanups
- remove fdt_addr field from PnvMachineState
Changes since v1:
- changed MAX_CPUS to 2048
- simplified memory node creation to one node only
- removed machine version
- rewrote the device tree creation with the fdt "rw" routines
- s/sPowerNVMachineState/PnvMachineState/
- block_default_type is back to IF_IDE because of the AHCI device
default-configs/ppc64-softmmu.mak | 1 + hw/ppc/Makefile.objs | 2 + hw/ppc/pnv.c | 226 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 38 +++++++ 4 files changed, 267 insertions(+) create mode 100644 hw/ppc/pnv.c create mode 100644 include/hw/ppc/pnv.h
default-configs/ppc64-softmmu.mak +1 -0
@@ -39,6 +39,7 @@ CONFIG_I8259=y CONFIG_XILINX=y CONFIG_XILINX_ETHLITE=y CONFIG_PSERIES=y +CONFIG_POWERNV=y CONFIG_PREP=y CONFIG_MAC=y CONFIG_E500=y
hw/ppc/Makefile.objs +2 -0
@@ -5,6 +5,8 @@ obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o +# IBM PowerNV +obj-$(CONFIG_POWERNV) += pnv.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c new file +226 -0
226 lines not on this page · raw message
include/hw/ppc/pnv.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* QEMU PowerPC PowerNV various definitions +* +* Copyright (c) 2014-2016 BenH, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _PPC_PNV_H +#define _PPC_PNV_H + +#include "hw/boards.h" + +#define TYPE_POWERNV_MACHINE MACHINE_TYPE_NAME("powernv") +#define POWERNV_MACHINE (obj) \ + OBJECT_CHECK(PnvMachineState, (obj), TYPE_POWERNV_MACHINE) + +typedef struct PnvMachineState { +/*< private >*/ +MachineState parent_obj; + +uint32_t initrd_base; +long initrd_size; +}PnvMachineState ; + +#define PNV_FDT_ADDR 0x01000000 + +#endif /* _PPC_PNV_H */
Signature · 1 line
2.7.4
PATCH v5 3/17 ppc/pnv: add a PnvChip object
In reply to Cédric Le GoaterThis is is an abstraction of a POWER8 chip which is a set of cores plus other 'units', like the pervasive unit, the interrupt controller, the memory controller, the on-chip microcontroller, etc. The whole can be seen as a socket. It depends on a cpu model and its characteristics:
max cores and specific inits are defined in a PnvChipClass.
We start with an near empty PnvChip with only a few cpu constants which we will grow in the subsequent patches with the controllers required to run the system.
The Chip CFAM (Common FRU Access Module) ID gives the model of the chip and its version number. It is generally the first thing firmwares fetch, available at XSCOM PCB address 0xf000f, to start initialization.
---
Changes since v4:
- changed 'num-chip' to be a class property of the powernv machine. Modified the accessors to more generic ones using Visitor.
- introduced two new properties 'ram-start' and 'ram-size' to hold the definitions of the RAM per chip. This change was motivated by the use of machine->ram_disk in the previous patch but it also prepares ground for the support of multiple chips.
Changes since v3:
- removed PnvChipPower* types
- removed realize ops of PnvChip
- replaced scanf by qemu_strtoul
Changes since v2:
- forced a POWER8 cpu model if none is specified and check that a PnvChip type exist for it
- did some renaming to be consistent with the cpu model names
- added POWER9 chip
- removed empty realize op
- renamed atribute chip_f000f in chip_cfam_id
- used error_fatal instead of error_abort when setting the chip properties
- introduced a powernv_populate_chip() routine
Changes since v1:
- introduced a PnvChipClass depending on the cpu model. It also provides some chip constants used by devices, like the cpu model hw id (f000f), a enum type (not sure this is useful yet), a custom realize ops for customization.
- the num-chips property can be configured on the command line.
hw/ppc/pnv.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/pnv.h | 63 +++++++++++++++ 2 files changed, 271 insertions(+), 5 deletions(-)
hw/ppc/pnv.c +208 -5
@@ -30,6 +30,7 @@#include "hw/loader.h" #include "exec/address-spaces.h" #include "qemu/cutils.h" +#include "qapi/visitor.h" #include <libfdt.h>
@@ -74,6 +75,14 @@ static void powernv_populate_memory_node(void *fdt, int chip_id, hwaddr start,_FDT ((fdt_setprop_cell (fdt, off,"ibm,chip-id" , chip_id))); } +static void powernv_populate_chip (PnvChip *chip,void *fdt) +{ +if (chip->ram_size) { +powernv_populate_memory_node (fdt, chip->chip_id, chip->ram_start, + chip->ram_size); + } +} +static void *powernv_create_fdt (MachineState *machine) {const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;
@@ -81,6 +90,7 @@ static void *powernv_create_fdt(MachineState *machine)void *fdt;char *buf;int off; +int i; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));
@@ -116,11 +126,10 @@ static void *powernv_create_fdt(MachineState *machine) &end_prop, sizeof(end_prop)))); } -/* TODO: put all the memory in one node on chip 0 until we find a -* way to specify different ranges for each chip -*/ -powernv_populate_memory_node (fdt,0 ,0 , machine->ram_size); - +/* Populate device tree for each chip */ +for (i =0 ; i < pnv->num_chips; i++) { +powernv_populate_chip (pnv->chips[i], fdt); + }return fdt; }
@@ -145,6 +154,8 @@ static void ppc_powernv_init(MachineState *machine)MemoryRegion *ram;char *fw_filename;long fw_size; +int i; +char *chip_typename;/* allocate RAM */ if (machine->ram_size < (1 *G_BYTE )) {
@@ -194,6 +205,190 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); } } + +/* We need some cpu model to instantiate the PnvChip class */ +if (machine->cpu_model ==NULL ) { + machine->cpu_model ="POWER8" ; + } + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); +if (!object_class_by_name (chip_typename)) { +error_report ("qemu: invalid CPU model '%s' for %s machine" , + machine->cpu_model,MACHINE_GET_CLASS (machine)->name); +exit (1 ); + } + + pnv->chips = g_new0(PnvChip *, pnv->num_chips); +for (i =0 ; i < pnv->num_chips; i++) { +char chip_name[32 ]; +Object *chip =object_new (chip_typename); + + pnv->chips[i] =PNV_CHIP (chip); + +/* TODO: put all the memory in one node on chip 0 until we find a +* way to specify different ranges for each chip +*/ +if (i ==0 ) { +object_property_set_int (chip, machine->ram_size,"ram-size" , + &error_fatal); + } + +snprintf (chip_name,sizeof (chip_name),"chip[%d]" ,PNV_CHIP_HWID (i)); +object_property_add_child (OBJECT (pnv), chip_name, chip, &error_fatal); +object_property_set_int (chip,PNV_CHIP_HWID (i),"chip-id" , + &error_fatal); +object_property_set_bool (chip, true,"realized" , &error_fatal); + } +g_free (chip_typename); +} + +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->cpu_model ="POWER8E" ; + k->chip_type =PNV_CHIP_POWER8E ; + k->chip_cfam_id =0x221ef04980000000ull ;/* P8 Murano DD2.1 */ + dc->desc ="PowerNV Chip POWER8E" ; +} + +static const TypeInfo pnv_chip_power8e_info = { + .name =TYPE_PNV_CHIP_POWER8E , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChip), + .class_init = pnv_chip_power8e_class_init, +}; + +static void pnv_chip_power8_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->cpu_model ="POWER8" ; + k->chip_type =PNV_CHIP_POWER8 ; + k->chip_cfam_id =0x220ea04980000000ull ;/* P8 Venice DD2.0 */ + dc->desc ="PowerNV Chip POWER8" ; +} + +static const TypeInfo pnv_chip_power8_info = { + .name =TYPE_PNV_CHIP_POWER8 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChip), + .class_init = pnv_chip_power8_class_init, +}; + +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_POWER8NVL ; + k->chip_cfam_id =0x120d304980000000ull ;/* P8 Naples DD1.0 */ + dc->desc ="PowerNV Chip POWER8NVL" ; +} + +static const TypeInfo pnv_chip_power8nvl_info = { + .name =TYPE_PNV_CHIP_POWER8NVL , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChip), + .class_init = pnv_chip_power8nvl_class_init, +}; + +static void pnv_chip_power9_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->cpu_model ="POWER9" ; + k->chip_type =PNV_CHIP_POWER9 ; + k->chip_cfam_id =0x100d104980000000ull ;/* P9 Nimbus DD1.0 */ + dc->desc ="PowerNV Chip POWER9" ; +} + +static const TypeInfo pnv_chip_power9_info = { + .name =TYPE_PNV_CHIP_POWER9 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChip), + .class_init = pnv_chip_power9_class_init, +}; + +static void pnv_chip_realize (DeviceState *dev,Error **errp) +{ +/* left purposely empty */ +} + +static Property pnv_chip_properties[] = { +DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,0 ), +DEFINE_PROP_UINT64 ("ram-start" , PnvChip, ram_start,0 ), +DEFINE_PROP_UINT64 ("ram-size" , PnvChip, ram_size,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pnv_chip_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = pnv_chip_realize; + dc->props = pnv_chip_properties; + dc->desc ="PowerNV Chip" ; +} + +static const TypeInfo pnv_chip_info = { + .name =TYPE_PNV_CHIP , + .parent =TYPE_SYS_BUS_DEVICE , + .class_init = pnv_chip_class_init, + .class_size =sizeof (PnvChipClass), + .abstract = true, +}; + +static void pnv_get_num_chips (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +visit_type_uint32 (v, name, &POWERNV_MACHINE (obj)->num_chips, errp); +} + +static void pnv_set_num_chips (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); +uint32_t num_chips; +Error *local_err =NULL ; + +visit_type_uint32 (v, name, &num_chips, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* +* TODO: should we decide on how many chips we can create based +* on #cores and Venice vs. Murano vs. Naples chip type etc..., +*/ +if (!is_power_of_2 (num_chips) || num_chips >4 ) { +error_setg (errp,"invalid number of chips: '%d'" , num_chips); +return ; + } + + pnv->num_chips = num_chips; +} + +static void powernv_machine_initfn (Object *obj) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); + pnv->num_chips =1 ; +} + +static void powernv_machine_class_props_init (ObjectClass *oc) +{ +object_class_property_add (oc,"num-chips" ,"uint32_t" , + pnv_get_num_chips, pnv_set_num_chips, +NULL ,NULL ,NULL ); +object_class_property_set_description (oc,"num-chips" , +"Specifies the number of processor chips" , +NULL ); }static void powernv_machine_class_init (ObjectClass *oc,void *data)
@@ -209,18 +404,26 @@ static void powernv_machine_class_init(ObjectClass *oc, void *data) mc->no_parallel =1 ; mc->default_boot_order =NULL ; mc->default_ram_size =1 *G_BYTE ; + +powernv_machine_class_props_init (oc); }static const TypeInfo powernv_machine_info = { .name =TYPE_POWERNV_MACHINE , .parent =TYPE_MACHINE , .instance_size =sizeof (PnvMachineState), + .instance_init = powernv_machine_initfn, .class_init = powernv_machine_class_init, };static void powernv_machine_register_types (void ) {type_register_static (&powernv_machine_info); +type_register_static (&pnv_chip_info); +type_register_static (&pnv_chip_power8e_info); +type_register_static (&pnv_chip_power8_info); +type_register_static (&pnv_chip_power8nvl_info); +type_register_static (&pnv_chip_power9_info); }type_init (powernv_machine_register_types)
include/hw/ppc/pnv.h +63 -0
75 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v5 4/17 ppc/pnv: add a core mask to PnvChip
In reply to Cédric Le GoaterThis will be used to build real HW ids for the cores and enforce some limits on the available cores per chip.
---
Changes since v4 :
- removed setting of 'cores-mask' property. -global can be used to alter the default setting.
Changes since v3 :
- reworked pnv_chip_core_sanitize() to return errors and to check the maximum of cores against the instance cores_mask
Changes since v2 :
- added POWER9 support
- removed cores_max
- introduces a pnv_chip_core_sanitize() helper to check the core ids_mask and the maximum number of cores
hw/ppc/pnv.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/pnv.h | 4 +++ 2 files changed, 76 insertions(+), 1 deletion(-)
hw/ppc/pnv.c +72 -1
@@ -238,11 +238,38 @@ static void ppc_powernv_init(MachineState *machine)object_property_add_child (OBJECT (pnv), chip_name, chip, &error_fatal);object_property_set_int (chip,PNV_CHIP_HWID (i),"chip-id" , &error_fatal); +object_property_set_int (chip, smp_cores,"nr-cores" , &error_fatal);object_property_set_bool (chip, true,"realized" , &error_fatal); }g_free (chip_typename); } +/* Allowed core identifiers on a POWER8 Processor Chip : +* +* <EX0 reserved> +* EX1 - Venice only +* EX2 - Venice only +* EX3 - Venice only +* EX4 +* EX5 +* EX6 +* <EX7,8 reserved> <reserved> +* EX9 - Venice only +* EX10 - Venice only +* EX11 - Venice only +* EX12 +* EX13 +* EX14 +* <EX15 reserved> +*/ +#define POWER8E_CORE_MASK (0x7070ull) +#define POWER8_CORE_MASK (0x7e7eull) + +/* +* POWER9 has 24 cores, ids starting at 0x20 +*/ +#define POWER9_CORE_MASK (0xffffff00000000ull) +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -251,6 +278,7 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8E" ; k->chip_type =PNV_CHIP_POWER8E ; k->chip_cfam_id =0x221ef04980000000ull ;/* P8 Murano DD2.1 */ + k->cores_mask =POWER8E_CORE_MASK ; dc->desc ="PowerNV Chip POWER8E" ; }
@@ -269,6 +297,7 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8" ; k->chip_type =PNV_CHIP_POWER8 ; k->chip_cfam_id =0x220ea04980000000ull ;/* P8 Venice DD2.0 */ + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8" ; }
@@ -287,6 +316,7 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8NVL" ; k->chip_type =PNV_CHIP_POWER8NVL ; k->chip_cfam_id =0x120d304980000000ull ;/* P8 Naples DD1.0 */ + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8NVL" ; }
@@ -305,6 +335,7 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER9" ; k->chip_type =PNV_CHIP_POWER9 ; k->chip_cfam_id =0x100d104980000000ull ;/* P9 Nimbus DD1.0 */ + k->cores_mask =POWER9_CORE_MASK ; dc->desc ="PowerNV Chip POWER9" ; }
@@ -315,15 +346,55 @@ static const TypeInfo pnv_chip_power9_info = { .class_init = pnv_chip_power9_class_init, }; +static void pnv_chip_core_sanitize (PnvChip *chip,Error **errp) +{ +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +int cores_max; + +/* +* No custom mask for this chip, let's use the default one from * +* the chip class +*/ +if (!chip->cores_mask) { + chip->cores_mask = pcc->cores_mask; + } + +/* filter alien core ids ! some are reserved */ +if ((chip->cores_mask & pcc->cores_mask) != chip->cores_mask) { +error_setg (errp,"warning: invalid core mask for chip Ox%" PRIx64" !" , + chip->cores_mask); +return ; + } + chip->cores_mask &= pcc->cores_mask; + +/* now that we have a sane layout, let check the number of cores */ + cores_max =hweight_long (chip->cores_mask); +if (chip->nr_cores > cores_max) { +error_setg (errp,"warning: too many cores for chip ! Limit is %d" , + cores_max); +return ; + } +} +static void pnv_chip_realize (DeviceState *dev,Error **errp) { -/* left purposely empty */ +PnvChip *chip =PNV_CHIP (dev); +Error *error =NULL ; + +/* Early checks on the core settings */ +pnv_chip_core_sanitize (chip, &error); +if (error) { +error_propagate (errp, error); +return ; + } }static Property pnv_chip_properties[] = {DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,0 ),DEFINE_PROP_UINT64 ("ram-start" , PnvChip, ram_start,0 ),DEFINE_PROP_UINT64 ("ram-size" , PnvChip, ram_size,0 ), +DEFINE_PROP_UINT32 ("nr-cores" , PnvChip, nr_cores,1 ), +DEFINE_PROP_UINT64 ("cores-mask" , PnvChip, cores_mask,0x0 ),DEFINE_PROP_END_OF_LIST (), };
include/hw/ppc/pnv.h +4 -0
@@ -44,6 +44,9 @@ typedef struct PnvChip {uint32_t chip_id;uint64_t ram_start;uint64_t ram_size; + +uint32_t nr_cores; +uint64_t cores_mask; } PnvChip; typedef struct PnvChipClass {
@@ -54,6 +57,7 @@ typedef struct PnvChipClass {const char *cpu_model;PnvChipType chip_type;uint64_t chip_cfam_id; +uint64_t cores_mask; } PnvChipClass;#define TYPE_PNV_CHIP_POWER8E TYPE_PNV_CHIP "-POWER8E"
Signature · 1 line
2.7.4
PATCH v5 5/17 ppc/pnv: add a PIR handler to PnvChip
In reply to Cédric Le GoaterThe Processor Identification Register (PIR) is a register that holds a processor identifier which is used for bus transactions (XSCOM) and for processor differentiation in multiprocessor systems. It also used in the interrupt vector entries (IVE) to identify the thread serving the interrupts.
P9 and P8 have some differences in the CPU PIR encoding.
---
Changes since v3 :
- added a couple more comments on the bits definition
hw/ppc/pnv.c | 30 ++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 ++ 2 files changed, 32 insertions(+)
hw/ppc/pnv.c +30 -0
@@ -244,6 +244,32 @@ static void ppc_powernv_init(MachineState *machine)g_free (chip_typename); } +/* +* 0:21 Reserved - Read as zeros +* 22:24 Chip ID +* 25:28 Core number +* 29:31 Thread ID +*/ +static uint32_t pnv_chip_core_pir_p8 (PnvChip *chip,uint32_t core_id) +{ +return (chip->chip_id <<7 ) | (core_id <<3 ); +} + +/* +* 0:48 Reserved - Read as zeroes +* 49:52 Node ID +* 53:55 Chip ID +* 56 Reserved - Read as zero +* 57:61 Core number +* 62:63 Thread ID +* +* We only care about the lower bits. uint32_t is fine for the moment. +*/ +static uint32_t pnv_chip_core_pir_p9 (PnvChip *chip,uint32_t core_id) +{ +return (chip->chip_id <<8 ) | (core_id <<2 ); +} +/* Allowed core identifiers on a POWER8 Processor Chip : * * <EX0 reserved>
@@ -279,6 +305,7 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->chip_type =PNV_CHIP_POWER8E ; k->chip_cfam_id =0x221ef04980000000ull ;/* P8 Murano DD2.1 */ k->cores_mask =POWER8E_CORE_MASK ; + k->core_pir = pnv_chip_core_pir_p8; dc->desc ="PowerNV Chip POWER8E" ; }
@@ -298,6 +325,7 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->chip_type =PNV_CHIP_POWER8 ; k->chip_cfam_id =0x220ea04980000000ull ;/* P8 Venice DD2.0 */ k->cores_mask =POWER8_CORE_MASK ; + k->core_pir = pnv_chip_core_pir_p8; dc->desc ="PowerNV Chip POWER8" ; }
@@ -317,6 +345,7 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->chip_type =PNV_CHIP_POWER8NVL ; k->chip_cfam_id =0x120d304980000000ull ;/* P8 Naples DD1.0 */ k->cores_mask =POWER8_CORE_MASK ; + k->core_pir = pnv_chip_core_pir_p8; dc->desc ="PowerNV Chip POWER8NVL" ; }
@@ -336,6 +365,7 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) k->chip_type =PNV_CHIP_POWER9 ; k->chip_cfam_id =0x100d104980000000ull ;/* P9 Nimbus DD1.0 */ k->cores_mask =POWER9_CORE_MASK ; + k->core_pir = pnv_chip_core_pir_p9; dc->desc ="PowerNV Chip POWER9" ; }
include/hw/ppc/pnv.h +2 -0
@@ -58,6 +58,8 @@ typedef struct PnvChipClass {PnvChipType chip_type;uint64_t chip_cfam_id;uint64_t cores_mask; + +uint32_t (*core_pir)(PnvChip *chip,uint32_t core_id); } PnvChipClass;#define TYPE_PNV_CHIP_POWER8E TYPE_PNV_CHIP "-POWER8E"
Signature · 1 line
2.7.4
PATCH v5 6/17 ppc/pnv: add a PnvCore object
In reply to Cédric Le GoaterThis is largy inspired by sPAPRCPUCore with some simplification, no hotplug for instance. A set of PnvCore objects is added to the PnvChip and the device tree is populated looping on these cores.
Real HW cpu ids are now generated depending on the chip cpu model, the chip id and a core mask. The id is propagated to the CPU object, using properties, to set the SPR_PIR (Processor Identification Register)
---
I did not introduce a single table to construct both the chip types and the corresponding core types yet. Keeping the idea for later as there might be other types to construct with P9 support.
Changes since v4:
- initialized SPR_PIR from init routine
- removed SPR_HIOR setting. This is a 970 register.
- removed extra reset
Changes since v3:
- removed the usage of cpu_index
- removed the setting of the msr_mask
Changes since v2:
- added P9 support
- used error_fatal instead of error_abort when setting the chip properties
- replaced num_cores by nr_cores
- removed gservers properties that were unused on powernv.
- used a 'void *' instead of a 'PnvCore *' to hold core Objects of potentially different size.
- qom: linked the core Objects to the chip
- moved device tree creation under powernv_populate_chip()
- added a 'pir' property' for ease of use
Changes since v1:
- changed name to PnvCore
- changed PnvChip core array type to a 'PnvCore *cores'
- introduced real cpu hw ids using a core mask from the chip
- reworked powernv_create_core_node() which populates the device tree
- added missing "ibm,pa-features" property
- smp_cpus representing threads, used smp_cores instead to create the cores in the chip.
- removed the use of ppc_get_vcpu_dt_id()
- added "POWER8E" and "POWER8NVL" cpu models to exercice the PnvChipClass
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 189 +++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/pnv_core.c | 182 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_core.h | 48 ++++++++++++ 5 files changed, 421 insertions(+), 2 deletions(-) create mode 100644 hw/ppc/pnv_core.c create mode 100644 include/hw/ppc/pnv_core.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_core.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +188 -1
219 lines not on this page · raw message
hw/ppc/pnv_core.c new file +182 -0
182 lines not on this page · raw message
include/hw/ppc/pnv.h +2 -0
@@ -47,6 +47,7 @@ typedef struct PnvChip {uint32_t nr_cores;uint64_t cores_mask; +void *cores; } PnvChip; typedef struct PnvChipClass {
@@ -103,5 +104,6 @@ typedef struct PnvMachineState { } PnvMachineState;#define PNV_FDT_ADDR 0x01000000 +#define PNV_TIMEBASE_FREQ 512000000ULL#endif /* _PPC_PNV_H */
include/hw/ppc/pnv_core.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v5 7/17 ppc/pnv: add XSCOM infrastructure
In reply to Cédric Le GoaterOn a real POWER8 system, the Pervasive Interconnect Bus (PIB) serves as a backbone to connect different units of the system. The host firmware connects to the PIB through a bridge unit, the Alter-Display-Unit (ADU), which gives him access to all the chiplets on the PCB network (Pervasive Connect Bus), the PIB acting as the root of this network.
XSCOM (serial communication) is the interface to the sideband bus provided by the POWER8 pervasive unit to read and write to chiplets resources. This is needed by the host firmware, OPAL and to a lesser extent, Linux. This is among others how the PCI Host bridges get configured at boot or how the LPC bus is accessed.
To represent the ADU of a real system, we introduce a specific AddressSpace to dispatch XSCOM accesses to the targeted chiplets. The translation of an XSCOM address into a PCB register address is slightly different between the P9 and the P8. This is handled before the dispatch using a 8byte alignment for all.
To customize the device tree, a QOM InterfaceClass, PnvXScomInterface, is provided with a populate() handler. The chip populates the device tree by simply looping on its children. Therefore, each model needing custom nodes should not forget to declare itself as a child at instantiation time.
Based on previous work done by :
Benjamin Herrenschmidt <[email protected]>
---
Changes since v4:
- added helpers to initialize and map the chiplet XSCOM regions in the XSCOM address space. This is to hide the '<< 3' shift.
Changes since v3:
- reworked the model to dispatch addresses to the memory regions using pcb_addr << 3, which is a no-op for the P9. The benefit is that all the address translation work can be done before dispatch and the conversion handlers in the chip and in the xscom interface are gone.
- removed the proxy PnnXscom object and extended the PnvChip object with an address space for XSCOM and its associated memory region.
- changed the read/write handlers in the address space to use address_space_stq() and address_space_ldq()
- introduced 'fake' default read/write handlers to handle 'core' registers. We can add a real device model when more work needs to be done under these.
- fixed an issue with the monitor doing read/write in the XSCOM address space. When under the monitor, we don't have a cpu to update the HMER SPR. That might need more work in the long term.
- introduced a xscom base field to hold the xscom base address as it is different on P9
- renamed the devnode() handler to populate()
Changes since v2:
- QOMified the model.
- all mappings in main memory space are now gathered in pnv_chip_realize() as done on other architectures.
- removed XScomBus. The parenthood is established through the QOM model
- replaced the XScomDevice with an InterfaceClass : PnvXScomInterface.
- introduced an XSCOM address space to dispatch accesses to the chiplets
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 25 ++++ hw/ppc/pnv_xscom.c | 277 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 15 +++ include/hw/ppc/pnv_xscom.h | 56 +++++++++ 5 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_xscom.c create mode 100644 include/hw/ppc/pnv_xscom.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_core.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +25 -0
@@ -33,6 +33,8 @@#include "qemu/cutils.h" #include "qapi/visitor.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_MAX_SIZE 0x00100000
@@ -219,6 +221,8 @@ static void powernv_populate_chip(PnvChip *chip, void *fdt)size_t typesize =object_type_get_instance_size (typename);int i; +pnv_xscom_populate (chip, fdt,0 ); +for (i =0 ; i < chip->nr_cores; i++) {PnvCore *pnv_core =PNV_CORE (chip->cores + i * typesize);
@@ -455,6 +459,7 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x221ef04980000000ull ;/* P8 Murano DD2.1 */ k->cores_mask =POWER8E_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p8; + k->xscom_base =0x003fc0000000000ull ; dc->desc ="PowerNV Chip POWER8E" ; }
@@ -475,6 +480,7 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x220ea04980000000ull ;/* P8 Venice DD2.0 */ k->cores_mask =POWER8_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p8; + k->xscom_base =0x003fc0000000000ull ; dc->desc ="PowerNV Chip POWER8" ; }
@@ -495,6 +501,7 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x120d304980000000ull ;/* P8 Naples DD1.0 */ k->cores_mask =POWER8_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p8; + k->xscom_base =0x003fc0000000000ull ; dc->desc ="PowerNV Chip POWER8NVL" ; }
@@ -515,6 +522,7 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x100d104980000000ull ;/* P9 Nimbus DD1.0 */ k->cores_mask =POWER9_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p9; + k->xscom_base =0x00603fc00000000ull ; dc->desc ="PowerNV Chip POWER9" ; }
@@ -555,6 +563,14 @@ static void pnv_chip_core_sanitize(PnvChip *chip, Error **errp) } } +static void pnv_chip_init (Object *obj) +{ +PnvChip *chip =PNV_CHIP (obj); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + chip->xscom_base = pcc->xscom_base; +} +static void pnv_chip_realize (DeviceState *dev,Error **errp) {PnvChip *chip =PNV_CHIP (dev);
@@ -569,6 +585,14 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)return ; } +/* XSCOM bridge */ +pnv_xscom_realize (chip, &error); +if (error) { +error_propagate (errp, error); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (chip),0 ,PNV_XSCOM_BASE (chip)); +/* Cores */ pnv_chip_core_sanitize (chip, &error);if (error) {
@@ -628,6 +652,7 @@ static const TypeInfo pnv_chip_info = { .name = TYPE_PNV_CHIP, .parent = TYPE_SYS_BUS_DEVICE, .class_init = pnv_chip_class_init, + .instance_init = pnv_chip_init, .class_size = sizeof(PnvChipClass), .abstract = true, };
hw/ppc/pnv_xscom.c new file +277 -0
277 lines not on this page · raw message
include/hw/ppc/pnv.h +15 -0
@@ -21,6 +21,7 @@#include "hw/boards.h" #include "hw/sysbus.h" +#include "hw/ppc/pnv_xscom.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -48,6 +49,11 @@ typedef struct PnvChip {uint32_t nr_cores;uint64_t cores_mask;void *cores; + +hwaddr xscom_base; +MemoryRegion xscom_mmio; +MemoryRegion xscom; +AddressSpace xscom_as; } PnvChip; typedef struct PnvChipClass {
@@ -60,6 +66,8 @@ typedef struct PnvChipClass {uint64_t chip_cfam_id;uint64_t cores_mask; +hwaddr xscom_base; +uint32_t (*core_pir)(PnvChip *chip,uint32_t core_id); } PnvChipClass;
@@ -106,4 +114,11 @@ typedef struct PnvMachineState {#define PNV_FDT_ADDR 0x01000000#define PNV_TIMEBASE_FREQ 512000000ULL +/* +* POWER8 MMIO base addresses +*/ +#define PNV_XSCOM_SIZE 0x800000000ull +#define PNV_XSCOM_BASE (chip) \ + (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) +#endif /* _PPC_PNV_H */
include/hw/ppc/pnv_xscom.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 07/17] ppc/pnv: add XSCOM infrastructure
Quoted 25 lines · Cédric Le Goater
On a real POWER8 system, the Pervasive Interconnect Bus (PIB) serves as a backbone to connect different units of the system. The host firmware connects to the PIB through a bridge unit, the Alter-Display-Unit (ADU), which gives him access to all the chiplets on the PCB network (Pervasive Connect Bus), the PIB acting as the root of this network.
XSCOM (serial communication) is the interface to the sideband bus provided by the POWER8 pervasive unit to read and write to chiplets resources. This is needed by the host firmware, OPAL and to a lesser extent, Linux. This is among others how the PCI Host bridges get configured at boot or how the LPC bus is accessed.
To represent the ADU of a real system, we introduce a specific AddressSpace to dispatch XSCOM accesses to the targeted chiplets. The translation of an XSCOM address into a PCB register address is slightly different between the P9 and the P8. This is handled before the dispatch using a 8byte alignment for all.
To customize the device tree, a QOM InterfaceClass, PnvXScomInterface, is provided with a
populate()handler. The chip populates the device tree by simply looping on its children. Therefore, each model needing custom nodes should not forget to declare itself as a child at instantiation time.
Quoted 4 lines
Based on previous work done by :
Benjamin Herrenschmidt <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Looks like xscom_complete() is still using current_cpu, which I've mentioned before. Apart from that;
Quoted 193 lines
---
Changes since v4:
- added helpers to initialize and map the chiplet XSCOM regions in the XSCOM address space. This is to hide the '<< 3' shift.
Changes since v3:
- reworked the model to dispatch addresses to the memory regions using
pcb_addr<< 3, which is a no-op for the P9. The benefit is that all the address translation work can be done before dispatch and the conversion handlers in the chip and in the xscom interface are gone.- removed the proxy PnnXscom object and extended the PnvChip object with an address space for XSCOM and its associated memory region.
- changed the read/write handlers in the address space to use
address_space_stq()andaddress_space_ldq()- introduced 'fake' default read/write handlers to handle 'core' registers. We can add a real device model when more work needs to be done under these.
- fixed an issue with the monitor doing read/write in the XSCOM address space. When under the monitor, we don't have a cpu to update the HMER SPR. That might need more work in the long term.
- introduced a xscom base field to hold the xscom base address as it is different on P9
- renamed the
devnode()handler topopulate()Changes since v2:
- QOMified the model.
- all mappings in main memory space are now gathered in
pnv_chip_realize()as done on other architectures.- removed XScomBus. The parenthood is established through the QOM model
- replaced the XScomDevice with an InterfaceClass : PnvXScomInterface.
- introduced an XSCOM address space to dispatch accesses to the chipletshw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 25 ++++ hw/ppc/pnv_xscom.c | 277 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 15 +++ include/hw/ppc/pnv_xscom.h | 56 +++++++++ 5 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_xscom.c create mode 100644 include/hw/ppc/pnv_xscom.hhw/ppc/Makefile.objs +1
-1@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_core.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/pnv.c +25
-0@@ -33,6 +33,8 @@#include "qemu/cutils.h" #include "qapi/visitor.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_MAX_SIZE 0x00100000@@ -219,6 +221,8 @@ static void powernv_populate_chip(PnvChip *chip, void *fdt)size_t typesize =object_type_get_instance_size (typename);int i; +pnv_xscom_populate (chip, fdt,0 ); +for (i =0 ; i < chip->nr_cores; i++) {PnvCore *pnv_core =PNV_CORE (chip->cores + i * typesize);@@ -455,6 +459,7 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x221ef04980000000ull ;/* P8 Murano DD2.1 */ k->cores_mask =POWER8E_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p8; + k->xscom_base =0x003fc0000000000ull ; dc->desc ="PowerNV Chip POWER8E" ; }@@ -475,6 +480,7 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x220ea04980000000ull ;/* P8 Venice DD2.0 */ k->cores_mask =POWER8_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p8; + k->xscom_base =0x003fc0000000000ull ; dc->desc ="PowerNV Chip POWER8" ; }@@ -495,6 +501,7 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x120d304980000000ull ;/* P8 Naples DD1.0 */ k->cores_mask =POWER8_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p8; + k->xscom_base =0x003fc0000000000ull ; dc->desc ="PowerNV Chip POWER8NVL" ; }@@ -515,6 +522,7 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) k->chip_cfam_id =0x100d104980000000ull ;/* P9 Nimbus DD1.0 */ k->cores_mask =POWER9_CORE_MASK ; k->core_pir = pnv_chip_core_pir_p9; + k->xscom_base =0x00603fc00000000ull ; dc->desc ="PowerNV Chip POWER9" ; }@@ -555,6 +563,14 @@ static void pnv_chip_core_sanitize(PnvChip *chip, Error **errp) } } +static void pnv_chip_init (Object *obj) +{ +PnvChip *chip =PNV_CHIP (obj); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + chip->xscom_base = pcc->xscom_base; +} +static void pnv_chip_realize (DeviceState *dev,Error **errp) {PnvChip *chip =PNV_CHIP (dev);@@ -569,6 +585,14 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)return ; } +/* XSCOM bridge */ +pnv_xscom_realize (chip, &error); +if (error) { +error_propagate (errp, error); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (chip),0 ,PNV_XSCOM_BASE (chip)); +/* Cores */ pnv_chip_core_sanitize (chip, &error);if (error) {@@ -628,6 +652,7 @@ static const TypeInfo pnv_chip_info = { .name = TYPE_PNV_CHIP, .parent = TYPE_SYS_BUS_DEVICE, .class_init = pnv_chip_class_init, + .instance_init = pnv_chip_init, .class_size = sizeof(PnvChipClass), .abstract = true, };hw/ppc/pnv_xscom.c new file +25
-0@@ -0,0 +1,277 @@ +/* +* QEMU PowerPC PowerNV XSCOM bus +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "sysemu/kvm.h" +#include "target-ppc/cpu.h" +#include "hw/sysbus.h"
hw/ppc/pnv_xscom.c line 35
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+ +#include "hw/ppc/fdt.h" +#include "hw/ppc/pnv_xscom.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xscom_complete (uint64_t hmer_bits) +{ +CPUState *cs = current_cpu;
I still think this should take a cpu parameter, moving the current_cpu invocation to the callers.
Quoted 349 lines
hw/ppc/pnv_xscom.c new file +242
-0+ +/* +* TODO: When the read/write comes from the monitor, we do not +* have a cpu. +*/ +if (cs) { +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +/* +* TODO: Need a CPU helper to set HMER, also handle generation +* of HMIs +*/ +cpu_synchronize_state (cs); + env->spr[SPR_HMER ] |= hmer_bits; + } +} + +static uint32_t pnv_xscom_pcba (PnvChip *chip,uint64_t addr) +{ +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + addr &= (PNV_XSCOM_SIZE -1 ); +if (pcc->chip_type ==PNV_CHIP_POWER9 ) { +return addr >>3 ; + }else { +return ((addr >>4 ) & ~0xfull ) | ((addr >>3 ) &0xf ); + } +} + +static uint64_t xscom_read_default (PnvChip *chip,uint32_t pcba) +{ +switch (pcba) { +case 0xf000f : +return PNV_CHIP_GET_CLASS (chip)->chip_cfam_id; +case 0x1010c00 :/* PIBAM FIR */ +case 0x1010c03 :/* PIBAM FIR MASK */ +case 0x2020007 :/* ADU stuff */ +case 0x2020009 :/* ADU stuff */ +case 0x202000f :/* ADU stuff */ +return 0 ; +case 0x2013f00 :/* PBA stuff */ +case 0x2013f01 :/* PBA stuff */ +case 0x2013f02 :/* PBA stuff */ +case 0x2013f03 :/* PBA stuff */ +case 0x2013f04 :/* PBA stuff */ +case 0x2013f05 :/* PBA stuff */ +case 0x2013f06 :/* PBA stuff */ +case 0x2013f07 :/* PBA stuff */ +return 0 ; +case 0x2013028 :/* CAPP stuff */ +case 0x201302a :/* CAPP stuff */ +case 0x2013801 :/* CAPP stuff */ +case 0x2013802 :/* CAPP stuff */ +return 0 ; +default : +return -1 ; + } +} + +static bool xscom_write_default (PnvChip *chip,uint32_t pcba,uint64_t val) +{ +/* We ignore writes to these */ +switch (pcba) { +case 0xf000f :/* chip id is RO */ +case 0x1010c00 :/* PIBAM FIR */ +case 0x1010c01 :/* PIBAM FIR */ +case 0x1010c02 :/* PIBAM FIR */ +case 0x1010c03 :/* PIBAM FIR MASK */ +case 0x1010c04 :/* PIBAM FIR MASK */ +case 0x1010c05 :/* PIBAM FIR MASK */ +case 0x2020007 :/* ADU stuff */ +case 0x2020009 :/* ADU stuff */ +case 0x202000f :/* ADU stuff */ +return true; +default : +return false; + } +} + +static uint64_t xscom_read (void *opaque,hwaddr addr,unsigned width) +{ +PnvChip *chip = opaque; +uint32_t pcba =pnv_xscom_pcba (chip, addr); +uint64_t val =0 ; +MemTxResult result; + +/* Handle some SCOMs here before dispatch */ + val =xscom_read_default (chip, pcba); +if (val !=-1 ) { + goto complete; + } + + val =address_space_ldq (&chip->xscom_as, pcba <<3 ,MEMTXATTRS_UNSPECIFIED , + &result); +if (result !=MEMTX_OK ) { +qemu_log_mask (LOG_GUEST_ERROR ,"XSCOM read failed at @0x%" + HWADDR_PRIx" pcba=0x%08x\n" , addr, pcba); +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return 0 ; + } + +complete: +xscom_complete (HMER_XSCOM_DONE ); +return val; +} + +static void xscom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +PnvChip *chip = opaque; +uint32_t pcba =pnv_xscom_pcba (chip, addr); +MemTxResult result; + +/* Handle some SCOMs here before dispatch */ +if (xscom_write_default (chip, pcba, val)) { + goto complete; + } + +address_space_stq (&chip->xscom_as, pcba <<3 , val,MEMTXATTRS_UNSPECIFIED , + &result); +if (result !=MEMTX_OK ) { +qemu_log_mask (LOG_GUEST_ERROR ,"XSCOM write failed at @0x%" + HWADDR_PRIx" pcba=0x%08x data=0x%" PRIx64"\n" , + addr, pcba, val); +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return ; + } + +complete: +xscom_complete (HMER_XSCOM_DONE ); +} + +const MemoryRegionOps pnv_xscom_ops = { + .read = xscom_read, + .write = xscom_write, + .valid.min_access_size =8 , + .valid.max_access_size =8 , + .impl.min_access_size =8 , + .impl.max_access_size =8 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +void pnv_xscom_realize (PnvChip *chip,Error **errp) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (chip); +char *name; + + name =g_strdup_printf ("xscom-%x" , chip->chip_id); +memory_region_init_io (&chip->xscom_mmio,OBJECT (chip), &pnv_xscom_ops, + chip, name,PNV_XSCOM_SIZE ); +sysbus_init_mmio (sbd, &chip->xscom_mmio); + +memory_region_init (&chip->xscom,OBJECT (chip), name,PNV_XSCOM_SIZE ); +address_space_init (&chip->xscom_as, &chip->xscom, name); +g_free (name); +} + +static const TypeInfo pnv_xscom_interface_info = { + .name =TYPE_PNV_XSCOM_INTERFACE , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PnvXScomInterfaceClass), +}; + +static void pnv_xscom_register_types (void ) +{ +type_register_static (&pnv_xscom_interface_info); +} + +type_init (pnv_xscom_register_types) + +typedef struct ForeachPopulateArgs { +void *fdt; +int xscom_offset; +} ForeachPopulateArgs; + +static int xscom_populate_child (Object *child,void *opaque) +{ +if (object_dynamic_cast (child,TYPE_PNV_XSCOM_INTERFACE )) { +ForeachPopulateArgs *args = opaque; +PnvXScomInterface *xd =PNV_XSCOM_INTERFACE (child); +PnvXScomInterfaceClass *xc =PNV_XSCOM_INTERFACE_GET_CLASS (xd); + +if (xc->populate) { +_FDT ((xc->populate (xd, args->fdt, args->xscom_offset))); + } + } +return 0 ; +} + +static const char compat_p8[] ="ibm,power8-xscom\0ibm,xscom" ; +static const char compat_p9[] ="ibm,power9-xscom\0ibm,xscom" ; + +int pnv_xscom_populate (PnvChip *chip,void *fdt,int root_offset) +{ +uint64_t reg[] = {cpu_to_be64 (PNV_XSCOM_BASE (chip)), +cpu_to_be64 (PNV_XSCOM_SIZE ) }; +int xscom_offset; +ForeachPopulateArgs args; +char *name; +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + name =g_strdup_printf ("xscom@%" PRIx64,be64_to_cpu (reg[0 ])); + xscom_offset =fdt_add_subnode (fdt, root_offset, name); +_FDT (xscom_offset); +g_free (name); +_FDT ((fdt_setprop_cell (fdt, xscom_offset,"ibm,chip-id" , chip->chip_id))); +_FDT ((fdt_setprop_cell (fdt, xscom_offset,"#address-cells" ,1 ))); +_FDT ((fdt_setprop_cell (fdt, xscom_offset,"#size-cells" ,1 ))); +_FDT ((fdt_setprop (fdt, xscom_offset,"reg" , reg,sizeof (reg)))); + +if (pcc->chip_type ==PNV_CHIP_POWER9 ) { +_FDT ((fdt_setprop (fdt, xscom_offset,"compatible" , compat_p9, +sizeof (compat_p9)))); + }else { +_FDT ((fdt_setprop (fdt, xscom_offset,"compatible" , compat_p8, +sizeof (compat_p8)))); + } + +_FDT ((fdt_setprop (fdt, xscom_offset,"scom-controller" ,NULL ,0 ))); + + args.fdt = fdt; + args.xscom_offset = xscom_offset; + +object_child_foreach (OBJECT (chip), xscom_populate_child, &args); +return 0 ; +} + +void pnv_xscom_add_subregion (PnvChip *chip,hwaddr offset,MemoryRegion *mr) +{ +memory_region_add_subregion (&chip->xscom, offset <<3 , mr); +} + +void pnv_xscom_region_init (MemoryRegion *mr, +struct Object *owner, +const MemoryRegionOps *ops, +void *opaque, +const char *name, +uint64_t size) +{ +memory_region_init_io (mr, owner, ops, opaque, name, size <<3 ); +}include/hw/ppc/pnv.h +15
-0@@ -21,6 +21,7 @@#include "hw/boards.h" #include "hw/sysbus.h" +#include "hw/ppc/pnv_xscom.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)@@ -48,6 +49,11 @@ typedef struct PnvChip {uint32_t nr_cores;uint64_t cores_mask;void *cores; + +hwaddr xscom_base; +MemoryRegion xscom_mmio; +MemoryRegion xscom; +AddressSpace xscom_as; } PnvChip; typedef struct PnvChipClass {@@ -60,6 +66,8 @@ typedef struct PnvChipClass {uint64_t chip_cfam_id;uint64_t cores_mask; +hwaddr xscom_base; +uint32_t (*core_pir)(PnvChip *chip,uint32_t core_id); } PnvChipClass;@@ -106,4 +114,11 @@ typedef struct PnvMachineState {#define PNV_FDT_ADDR 0x01000000#define PNV_TIMEBASE_FREQ 512000000ULL +/* +* POWER8 MMIO base addresses +*/ +#define PNV_XSCOM_SIZE 0x800000000ull +#define PNV_XSCOM_BASE (chip) \ + (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) +#endif /* _PPC_PNV_H */ include/hw/ppc/pnv_xscom.h new file +56
-0@@ -0,0 +1,56 @@ +/* +* QEMU PowerPC PowerNV XSCOM bus definitions +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _PPC_PNV_XSCOM_H +#define _PPC_PNV_XSCOM_H + +#include "qom/object.h" + +typedef struct PnvChip PnvChip ; + +typedef struct PnvXScomInterface { +Object parent; +}PnvXScomInterface ; + +#define TYPE_PNV_XSCOM_INTERFACE "pnv-xscom-interface" +#define PNV_XSCOM_INTERFACE (obj) \ + OBJECT_CHECK(PnvXScomInterface, (obj), TYPE_PNV_XSCOM_INTERFACE) +#define PNV_XSCOM_INTERFACE_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvXScomInterfaceClass, (klass), \ + TYPE_PNV_XSCOM_INTERFACE) +#define PNV_XSCOM_INTERFACE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvXScomInterfaceClass, (obj), TYPE_PNV_XSCOM_INTERFACE) + +typedef struct PnvXScomInterfaceClass { +InterfaceClass parent; +int (*populate)(PnvXScomInterface *dev,void *fdt,int offset); +}PnvXScomInterfaceClass ; + +extern void pnv_xscom_realize (PnvChip *chip,Error **errp); +extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset); + +extern void pnv_xscom_add_subregion (PnvChip *chip,hwaddr offset, +MemoryRegion *mr); +extern void pnv_xscom_region_init (MemoryRegion *mr, +struct Object *owner, +const MemoryRegionOps *ops, +void *opaque, +const char *name, +uint64_t size); + +#endif /* _PPC_PNV_XSCOM_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 v5 07/17] ppc/pnv: add XSCOM infrastructure
Quoted 26 lines · David Gibson
Quoted 25 lines · Cédric Le Goater
On a real POWER8 system, the Pervasive Interconnect Bus (PIB) serves as a backbone to connect different units of the system. The host firmware connects to the PIB through a bridge unit, the Alter-Display-Unit (ADU), which gives him access to all the chiplets on the PCB network (Pervasive Connect Bus), the PIB acting as the root of this network.
XSCOM (serial communication) is the interface to the sideband bus provided by the POWER8 pervasive unit to read and write to chiplets resources. This is needed by the host firmware, OPAL and to a lesser extent, Linux. This is among others how the PCI Host bridges get configured at boot or how the LPC bus is accessed.
To represent the ADU of a real system, we introduce a specific AddressSpace to dispatch XSCOM accesses to the targeted chiplets. The translation of an XSCOM address into a PCB register address is slightly different between the P9 and the P8. This is handled before the dispatch using a 8byte alignment for all.
To customize the device tree, a QOM InterfaceClass, PnvXScomInterface, is provided with a
populate()handler. The chip populates the device tree by simply looping on its children. Therefore, each model needing custom nodes should not forget to declare itself as a child at instantiation time.
Quoted 7 lines
Quoted 4 lines
Based on previous work done by :
Benjamin Herrenschmidt <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>Looks like
xscom_complete()is still usingcurrent_cpu, which I've mentioned before. Apart from that;
gasp. I forgot :/ Thanks for doing it.
C.
PATCH v5 8/17 ppc/pnv: add XSCOM handlers to PnvCore
In reply to Cédric Le GoaterNow that we are using real HW ids for the cores in PowerNV chips, we can route the XSCOM accesses to them. We just need to attach a specific XSCOM memory region to each core in the appropriate window for the core number.
To start with, let's install the DTS (Digital Thermal Sensor) handlers which should return 38°C for each core.
---
Changes since v4:
- used the helpers for the XSCOM region
Changes since v3:
- moved to new XSCOM model
- kept the write op on the XSCOM memory region for later use
Changes since v2:
- added a XSCOM memory region to handle access to the EX core registers
- extended the PnvCore object with a XSCOM_INTERFACE so that we can use pnv_xscom_pcba() and pnv_xscom_addr() to handle XSCOM address translation.
hw/ppc/pnv.c | 4 ++++ hw/ppc/pnv_core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_core.h | 2 ++ include/hw/ppc/pnv_xscom.h | 19 ++++++++++++++++++ 4 files changed, 75 insertions(+)
hw/ppc/pnv.c +4 -0
@@ -625,6 +625,10 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_bool (OBJECT (pnv_core), true,"realized" , &error_fatal);object_unref (OBJECT (pnv_core)); + +/* Each core has an XSCOM MMIO region */ +pnv_xscom_add_subregion (chip,PNV_XSCOM_EX_CORE_BASE (core_hwid), + &PNV_CORE (pnv_core)->xscom_regs); i++; }g_free (typename);
hw/ppc/pnv_core.c +50 -0
68 lines not on this page · raw message
include/hw/ppc/pnv_core.h +2 -0
@@ -36,6 +36,8 @@ typedef struct PnvCore {/*< public >*/ void *threads;uint32_t pir; + +MemoryRegion xscom_regs; } PnvCore; typedef struct PnvCoreClass {
include/hw/ppc/pnv_xscom.h +19 -0
@@ -41,6 +41,25 @@ typedef struct PnvXScomInterfaceClass {int (*populate)(PnvXScomInterface *dev,void *fdt,int offset); } PnvXScomInterfaceClass; +/* +* Layout of the XSCOM PCB addresses of EX core 1 +* +* GPIO 0x1100xxxx +* SCOM 0x1101xxxx +* OHA 0x1102xxxx +* CLOCK CTL 0x1103xxxx +* FIR 0x1104xxxx +* THERM 0x1105xxxx +* <reserved> 0x1106xxxx +* .. +* 0x110Exxxx +* PCB SLAVE 0x110Fxxxx +*/ + +#define PNV_XSCOM_EX_BASE 0x10000000 +#define PNV_XSCOM_EX_CORE_BASE (i) (PNV_XSCOM_EX_BASE | (((uint64_t)i) << 24)) +#define PNV_XSCOM_EX_CORE_SIZE 0x100000 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 08/17] ppc/pnv: add XSCOM handlers to PnvCore
Quoted 9 lines · Cédric Le Goater
Now that we are using real HW ids for the cores in PowerNV chips, we can route the XSCOM accesses to them. We just need to attach a specific XSCOM memory region to each core in the appropriate window for the core number.
To start with, let's install the DTS (Digital Thermal Sensor) handlers which should return 38°C for each core.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 158 lines
---
Changes since v4:
- used the helpers for the XSCOM region
Changes since v3:
- moved to new XSCOM model
- kept the write op on the XSCOM memory region for later useChanges since v2:
- added a XSCOM memory region to handle access to the EX core registers
- extended the PnvCore object with aXSCOM_INTERFACEso that we can usepnv_xscom_pcba()andpnv_xscom_addr()to handle XSCOM address translation.hw/ppc/pnv.c | 4 ++++ hw/ppc/pnv_core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_core.h | 2 ++ include/hw/ppc/pnv_xscom.h | 19 ++++++++++++++++++ 4 files changed, 75 insertions(+)hw/ppc/pnv.c +4
-0@@ -625,6 +625,10 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_bool (OBJECT (pnv_core), true,"realized" , &error_fatal);object_unref (OBJECT (pnv_core)); + +/* Each core has an XSCOM MMIO region */ +pnv_xscom_add_subregion (chip,PNV_XSCOM_EX_CORE_BASE (core_hwid), + &PNV_CORE (pnv_core)->xscom_regs); i++; }g_free (typename);hw/ppc/pnv_core.c +50
-0@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "sysemu/sysemu.h" #include "qapi/error.h" +#include "qemu/log.h" #include "target-ppc/cpu.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" @@ -63,6 +64,51 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error **errp)qemu_register_reset (powernv_cpu_reset, cpu); } +/* +* These values are read by the PowerNV HW monitors under Linux +*/ +#define PNV_XSCOM_EX_DTS_RESULT0 0x50000 +#define PNV_XSCOM_EX_DTS_RESULT1 0x50001 + +static uint64_t pnv_core_xscom_read (void *opaque,hwaddr addr, +unsigned int width) +{ +uint32_t offset = addr >>3 ; +uint64_t val =0 ; + +/* The result should be 38 C */ +switch (offset) { +case PNV_XSCOM_EX_DTS_RESULT0 : + val =0x26f024f023f0000ull ; +break ; +case PNV_XSCOM_EX_DTS_RESULT1 : + val =0x24f000000000000ull ; +break ; +default : +qemu_log_mask (LOG_UNIMP ,"Warning: reading reg=0x%" HWADDR_PRIx, + addr); + } + +return val; +} + +static void pnv_core_xscom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned int width) +{ +qemu_log_mask (LOG_UNIMP ,"Warning: writing to reg=0x%" HWADDR_PRIx, + addr); +} + +static const MemoryRegionOps pnv_core_xscom_ops = { + .read = pnv_core_xscom_read, + .write = pnv_core_xscom_write, + .valid.min_access_size =8 , + .valid.max_access_size =8 , + .impl.min_access_size =8 , + .impl.max_access_size =8 , + .endianness =DEVICE_BIG_ENDIAN , +}; +static void pnv_core_realize_child (Object *child,Error **errp) {Error *local_err =NULL ;@@ -118,6 +164,10 @@ static void pnv_core_realize(DeviceState *dev, Error **errp) goto err; } } + +snprintf (name,sizeof (name),"xscom-core.%d" , cc->core_id); +pnv_xscom_region_init (&pc->xscom_regs,OBJECT (dev), &pnv_core_xscom_ops, + pc, name,PNV_XSCOM_EX_CORE_SIZE );return ; err:include/hw/ppc/pnv_core.h +2
-0@@ -36,6 +36,8 @@ typedef struct PnvCore {/*< public >*/ void *threads;uint32_t pir; + +MemoryRegion xscom_regs; } PnvCore; typedef struct PnvCoreClass {include/hw/ppc/pnv_xscom.h +19
-0@@ -41,6 +41,25 @@ typedef struct PnvXScomInterfaceClass {int (*populate)(PnvXScomInterface *dev,void *fdt,int offset); } PnvXScomInterfaceClass; +/* +* Layout of the XSCOM PCB addresses of EX core 1 +* +* GPIO 0x1100xxxx +* SCOM 0x1101xxxx +* OHA 0x1102xxxx +* CLOCK CTL 0x1103xxxx +* FIR 0x1104xxxx +* THERM 0x1105xxxx +* <reserved> 0x1106xxxx +* .. +* 0x110Exxxx +* PCB SLAVE 0x110Fxxxx +*/ + +#define PNV_XSCOM_EX_BASE 0x10000000 +#define PNV_XSCOM_EX_CORE_BASE (i) (PNV_XSCOM_EX_BASE | (((uint64_t)i) << 24)) +#define PNV_XSCOM_EX_CORE_SIZE 0x100000 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
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
PATCH v5 9/17 ppc/pnv: add a LPC controller
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
The LPC (Low Pin Count) interface on a POWER8 is made accessible to the system through the ADU (XSCOM interface). This interface is part of set of units connected together via a local OPB (On-Chip Peripheral Bus) which act as a bridge between the ADU and the off chip LPC endpoints, like external flash modules.
The most important units of this OPB are :
- OPB Master: contains the ADU slave logic, a set of internal registers and the logic to control the OPB.
- LPCHC (LPC HOST Controller): which implements a OPB Slave, a set of internal registers and the LPC HOST Controller to control the LPC interface.
Four address spaces are provided to the ADU :
- LPC Bus Firmware Memory
- LPC Bus Memory
- LPC Bus I/O (ISA bus)
- and the registers for the OPB Master and the LPC Host Controller
On POWER8, an intermediate hop is necessary to reach the OPB, through a unit called the ECCB. OPB commands are simply mangled in ECCB write commands.
On POWER9, the OPB master address space can be accessed via MMIO. The logic is same but the code will be simpler as the XSCOM and ECCB hops are not necessary anymore.
This version of the LPC controller model doesn't yet implement support for the SerIRQ deserializer present in the Naples version of the chip though some preliminary work is there.
[clg: - updated for qemu-2.7
- ported on latest PowerNV patchset
- changed the XSCOM interface to fit new model
- QOMified the model
- moved the ISA hunks in another patch
- removed printf logging
- added a couple of UNIMP logging
- rewrote commit log ]
---
Todo:
- rework the address_space read/write ops as they should be shared with the P9 support.
Changes since v4:
- used the helpers for the XSCOM region
Changes since v3:
- rewrote commit log
- fixed appendprop
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 8 + hw/ppc/pnv_lpc.c | 471 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 3 + include/hw/ppc/pnv_lpc.h | 67 +++++++ include/hw/ppc/pnv_xscom.h | 3 + 6 files changed, 553 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_lpc.c create mode 100644 include/hw/ppc/pnv_lpc.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +8 -0
@@ -569,6 +569,9 @@ static void pnv_chip_init(Object *obj)PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); chip->xscom_base = pcc->xscom_base; + +object_initialize (&chip->lpc,sizeof (chip->lpc),TYPE_PNV_LPC ); +object_property_add_child (obj,"lpc" ,OBJECT (&chip->lpc),NULL ); }static void pnv_chip_realize (DeviceState *dev,Error **errp)
@@ -632,6 +635,11 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) i++; }g_free (typename); + +/* Create LPC controller */ +object_property_set_bool (OBJECT (&chip->lpc), true,"realized" , + &error_fatal); +pnv_xscom_add_subregion (chip,PNV_XSCOM_LPC_BASE , &chip->lpc.xscom_regs); }static Property pnv_chip_properties[] = {
hw/ppc/pnv_lpc.c new file +471 -0
471 lines not on this page · raw message
include/hw/ppc/pnv.h +3 -0
@@ -22,6 +22,7 @@#include "hw/boards.h" #include "hw/sysbus.h" #include "hw/ppc/pnv_xscom.h" +#include "hw/ppc/pnv_lpc.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -54,6 +55,8 @@ typedef struct PnvChip {MemoryRegion xscom_mmio;MemoryRegion xscom;AddressSpace xscom_as; + +PnvLpcController lpc; } PnvChip; typedef struct PnvChipClass {
include/hw/ppc/pnv_lpc.h new file +67 -0
67 lines not on this page · raw message
include/hw/ppc/pnv_xscom.h +3 -0
@@ -60,6 +60,9 @@ typedef struct PnvXScomInterfaceClass {#define PNV_XSCOM_EX_CORE_BASE (i) (PNV_XSCOM_EX_BASE | (((uint64_t)i) << 24))#define PNV_XSCOM_EX_CORE_SIZE 0x100000 +#define PNV_XSCOM_LPC_BASE 0xb0020 +#define PNV_XSCOM_LPC_SIZE 0x4 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 1 line
2.7.4
PATCH v5 10/17 ppc/pnv: add a ISA bus
In reply to Cédric Le GoaterAs Qemu only supports a single instance of the ISA bus, we use the LPC controller of chip 0 to create one and plug in a couple of useful devices, like an UART and RTC. An IPMI BT device, which is also an ISA device, can be defined on the command line to connect an external BMC. That is for later.
The PowerNV machine now has a console. Skiboot should load a kernel and jump into it but execution will stop quite early because we lack a model for the native XICS controller for the moment :
[ 0.000000] NR_IRQS:512 nr_irqs:512 16
[ 0.000000] XICS: Cannot find a Presentation Controller !
[ 0.000000] ------------[ cut here ]------------
[ 0.000000] WARNING: at arch/powerpc/platforms/powernv/setup.c:81
...
[ 0.000000] NIP [c00000000079d65c] pnv_init_IRQ+0x30/0x44You can still do a few things under xmon.
Based on previous work from :
Benjamin Herrenschmidt <[email protected]>
---
Changes since v4:
- changed the (empty) irq handlers to use a PnvChip as argument
hw/ppc/pnv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 ++ 2 files changed, 67 insertions(+)
hw/ppc/pnv.c +65 -0
@@ -35,6 +35,10 @@#include "hw/ppc/pnv_xscom.h" +#include "hw/isa/isa.h" +#include "hw/char/serial.h" +#include "hw/timer/mc146818rtc.h" +#include <libfdt.h> #define FDT_MAX_SIZE 0x00100000
@@ -301,6 +305,58 @@ static void ppc_powernv_reset(void)cpu_physical_memory_write (PNV_FDT_ADDR , fdt,fdt_totalsize (fdt)); } +/* If we don't use the built-in LPC interrupt deserializer, we need +* to provide a set of qirqs for the ISA bus or things will go bad. +* +* Most machines using pre-Naples chips (without said deserializer) +* have a CPLD that will collect the SerIRQ and shoot them as a +* single level interrupt to the P8 chip. So let's setup a hook +* for doing just that. +* +* Note: The actual interrupt input isn't emulated yet, this will +* come with the PSI bridge model. +*/ +static void pnv_lpc_isa_irq_handler_cpld (void *opaque,int n,int level) +{ +/* We don't yet emulate the PSI bridge which provides the external +* interrupt, so just drop interrupts on the floor +*/ +} + +static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level) +{ +/* XXX TODO */ +} + +static ISABus *pnv_isa_create (PnvChip *chip) +{ +PnvLpcController *lpc = &chip->lpc; +ISABus *isa_bus; +qemu_irq *irqs; +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + +/* let isa_bus_new() create its own bridge on SysBus otherwise +* devices speficied on the command line won't find the bus and +* will fail to create. +*/ + isa_bus =isa_bus_new (NULL , &lpc->isa_mem, &lpc->isa_io, + &error_fatal); + +/* Not all variants have a working serial irq decoder. If not, +* handling of LPC interrupts becomes a platform issue (some +* platforms have a CPLD to do it). +*/ +if (pcc->chip_type ==PNV_CHIP_POWER8NVL ) { + irqs =qemu_allocate_irqs (pnv_lpc_isa_irq_handler, chip,ISA_NUM_IRQS ); + }else { + irqs =qemu_allocate_irqs (pnv_lpc_isa_irq_handler_cpld, chip, +ISA_NUM_IRQS ); + } + +isa_bus_irqs (isa_bus, irqs); +return isa_bus; +} +static void ppc_powernv_init (MachineState *machine) {PnvMachineState *pnv =POWERNV_MACHINE (machine);
@@ -395,6 +451,15 @@ static void ppc_powernv_init(MachineState *machine)object_property_set_bool (chip, true,"realized" , &error_fatal); }g_free (chip_typename); + +/* Instantiate ISA bus on chip 0 */ + pnv->isa_bus =pnv_isa_create (pnv->chips[0 ]); + +/* Create serial port */ +serial_hds_isa_init (pnv->isa_bus,MAX_SERIAL_PORTS ); + +/* Create an RTC ISA device too */ +rtc_init (pnv->isa_bus,2000 ,NULL ); }/*
include/hw/ppc/pnv.h +2 -0
@@ -112,6 +112,8 @@ typedef struct PnvMachineState {uint32_t num_chips;PnvChip **chips; + +ISABus *isa_bus; } PnvMachineState;#define PNV_FDT_ADDR 0x01000000
Signature · 1 line
2.7.4
PATCH v5 11/17 ppc/xics: Add "native" XICS subclass
In reply to Cédric Le GoaterThis provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
---
Changes since v4:
- replaced the pir_table by memory subregions using an ICP.
- removed the find_icp() and cpu_setup() handlers which became useless with the memory regions.
- removed the superfluous inits done in xics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.
default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.c
default-configs/ppc64-softmmu.mak +2 -1
@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=y
hw/intc/Makefile.objs +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.o
hw/intc/xics_native.c new file +304 -0
304 lines not on this page · raw message
include/hw/ppc/pnv.h +19 -0
@@ -126,4 +126,23 @@ typedef struct PnvMachineState {#define PNV_XSCOM_BASE (chip) \ (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) +/* +* XSCOM 0x20109CA defines the ICP BAR: +* +* 0:29 : bits 14 to 43 of address to define 1 MB region. +* 30 : 1 to enable ICP to receive loads/stores against its BAR region +* 31:63 : Constant 0 +* +* Usually defined as : +* +* 0xffffe00200000000 -> 0x0003ffff80000000 +* 0xffffe00600000000 -> 0x0003ffff80100000 +* 0xffffe02200000000 -> 0x0003ffff80800000 +* 0xffffe02600000000 -> 0x0003ffff80900000 +* +* TODO: make a macro using the chip hw id +*/ +#define PNV_XICS_BASE 0x0003ffff80000000ull +#define PNV_XICS_SIZE 0x0000000000100000ull +#endif /* _PPC_PNV_H */
include/hw/ppc/xics.h +24 -0
@@ -119,8 +119,27 @@ struct ICPState {bool cap_irq_xics_enabled;XICSState *xics; + +/* +* for XICSNative (not used by Linux). +*/ +uint32_t links[3 ]; }; +#define TYPE_XICS_NATIVE "xics-native" +#define XICS_NATIVE (obj) OBJECT_CHECK(XICSNative, (obj), TYPE_XICS_NATIVE) +#define XICS_NATIVE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XICSStateClass, (klass), TYPE_XICS_NATIVE) +#define XICS_NATIVE_GET_CLASS (obj) \ + OBJECT_CLASS_CHECK(XICSStateClass, (obj), TYPE_XICS_NATIVE) + +typedef struct XICSNative { +XICSState parent_obj; + +MemoryRegion icp_mmio; +MemoryRegion *icp_mmios; +}XICSNative ; +#define TYPE_ICS_BASE "ics-base"#define ICS_BASE (obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_BASE)
@@ -209,4 +228,9 @@ void ics_set_irq_type(ICSState *ics, int srcno, bool lsi);ICSState *xics_find_source (XICSState *icp,int irq); +typedef struct PnvChip PnvChip ; + +void xics_native_populate_icp (PnvChip *chip,void *fdt,int offset, +uint32_t base,uint32_t count); +#endif /* XICS_H */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 95 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_tableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +34
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h>
hw/intc/xics_native.c line 44
Quoted 10 lines
hw/intc/xics_native.c new file +10
-0+ +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +} + +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}
I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should. If it was, device_reset should be called without these shenannigans.
Quoted 175 lines
hw/intc/xics_native.c new file +175
-0+ +static uint64_t xics_native_read (void *opaque,hwaddr addr,unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); +uint64_t val =0xffffffff ; + +switch (addr &0xffc ) { +case 0 :/* poll */ + val =icp_ipoll (icp,NULL ); +if (byte0) { + val >>=24 ; + }else if (width !=4 ) { + goto bad_access; + } +break ; +case 4 :/* xirr */ +if (byte0) { + val =icp_ipoll (icp,NULL ) >>24 ; + }else if (width ==4 ) { + val =icp_accept (icp); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { + val = icp->mfrr; + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + val = icp->links[0 ]; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + val = icp->links[1 ]; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + val = icp->links[2 ]; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } + +return val; +} + +static void xics_native_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); + +switch (addr &0xffc ) { +case 4 :/* xirr */ +if (byte0) { +icp_set_cppr (icp, val); + }else if (width ==4 ) { +icp_eoi (icp, val); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { +icp_set_mfrr (icp, val); + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + icp->links[0 ] = val; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + icp->links[1 ] = val; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + icp->links[2 ] = val; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } +} + +static const MemoryRegionOps xics_native_ops = { + .read = xics_native_read, + .write = xics_native_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static uint64_t xics_native_default_read (void *opaque,hwaddr addr, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +return 0xffffffffffffffffull ; +} + +static void xics_native_default_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +} + +static const MemoryRegionOps xics_native_default_ops = { + .read = xics_native_default_read, + .write = xics_native_default_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static void xics_native_set_nr_servers (XICSState *xics,uint32_t nr_servers, +Error **errp) +{ +xics_set_nr_servers (xics, nr_servers,TYPE_ICP , errp); +} + +static void xics_native_realize (DeviceState *dev,Error **errp) +{ +XICSState *xics =XICS_COMMON (dev); +XICSNative *xicsn =XICS_NATIVE (dev); +Error *error =NULL ; +int i; + +if (!xics->nr_servers) { +error_setg (errp,"Number of servers needs to be greater than 0" ); +return ; + } + +for (i =0 ; i < xics->nr_servers; i++) { +object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , + &error); +if (error) { +error_propagate (errp, error); +return ; + } + } +
hw/intc/xics_native.c line 229
Quoted 10 lines
hw/intc/xics_native.c new file +10
-0+/* +* Initialize the container region for the ICPs and the subregion +* for each cpu. The mmapping will be done at the board level +* depending on the pir of the core. +* +* TODO: build a name with the chip id +*/ +memory_region_init_io (&xicsn->icp_mmio,OBJECT (dev), + &xics_native_default_ops, xicsn,"icp-0" , +PNV_XICS_SIZE );
I don't think you should need these native ops. I believe you can construct a memory region as a "pure" container, then just put the populated regions inside it.
Quoted 145 lines
hw/intc/xics_native.c new file +75
-0+sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xicsn->icp_mmio); + + xicsn->icp_mmios =g_new0 (MemoryRegion, xics->nr_servers); +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +memory_region_init_io (&xicsn->icp_mmios[i],OBJECT (dev), + &xics_native_ops, icp,"icp-0" ,0x1000 ); + } +} + +static void xics_native_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +XICSStateClass *xsc =XICS_NATIVE_CLASS (oc); + + dc->realize = xics_native_realize; + xsc->set_nr_servers = xics_native_set_nr_servers; +} + +static const TypeInfo xics_native_info = { + .name =TYPE_XICS_NATIVE , + .parent =TYPE_XICS_COMMON , + .instance_size =sizeof (XICSNative), + .class_size =sizeof (XICSStateClass), + .class_init = xics_native_class_init, + .instance_init = xics_native_initfn, +}; + +static void xics_native_register_types (void ) +{ +type_register_static (&xics_native_info); +} + +type_init (xics_native_register_types) + +void xics_native_populate_icp(PnvChip *chip, void *fdt, int offset, +uint32_t pir,uint32_t count) +{ +uint64_t addr; +char *name; +const char compat[] ="IBM,power8-icp\0IBM,ppc-xicp" ; +uint32_t irange[2 ], i, rsize; +uint64_t *reg; + +/* +* TODO: add multichip ICP BAR +*/ + addr =PNV_XICS_BASE | (pir <<12 ); + + irange[0 ] =cpu_to_be32 (pir); + irange[1 ] =cpu_to_be32 (count); + + rsize =sizeof (uint64_t ) *2 * count; + reg =g_malloc (rsize); +for (i =0 ; i < count; i++) { + reg[i *2 ] =cpu_to_be64 (addr | ((pir + i) *0x1000 )); + reg[i *2 +1 ] =cpu_to_be64 (0x1000 ); + } + + name =g_strdup_printf ("interrupt-controller@%" PRIX64 , addr); + offset =fdt_add_subnode (fdt, offset, name); +_FDT (offset); +g_free (name); + +_FDT ((fdt_setprop (fdt, offset,"compatible" , compat,sizeof (compat)))); +_FDT ((fdt_setprop (fdt, offset,"reg" , reg, rsize))); +_FDT ((fdt_setprop_string (fdt, offset,"device_type" , +"PowerPC-External-Interrupt-Presentation" ))); +_FDT ((fdt_setprop (fdt, offset,"interrupt-controller" ,NULL ,0 ))); +_FDT ((fdt_setprop (fdt, offset,"ibm,interrupt-server-ranges" , + irange,sizeof (irange)))); +_FDT ((fdt_setprop_cell (fdt, offset,"#interrupt-cells" ,1 ))); +_FDT ((fdt_setprop_cell (fdt, offset,"#address-cells" ,0 ))); +g_free (reg); +}include/hw/ppc/pnv.h +19
-0@@ -126,4 +126,23 @@ typedef struct PnvMachineState {#define PNV_XSCOM_BASE (chip) \ (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) +/* +* XSCOM 0x20109CA defines the ICP BAR: +* +* 0:29 : bits 14 to 43 of address to define 1 MB region. +* 30 : 1 to enable ICP to receive loads/stores against its BAR region +* 31:63 : Constant 0 +* +* Usually defined as : +* +* 0xffffe00200000000 -> 0x0003ffff80000000 +* 0xffffe00600000000 -> 0x0003ffff80100000 +* 0xffffe02200000000 -> 0x0003ffff80800000 +* 0xffffe02600000000 -> 0x0003ffff80900000 +* +* TODO: make a macro using the chip hw id +*/ +#define PNV_XICS_BASE 0x0003ffff80000000ull +#define PNV_XICS_SIZE 0x0000000000100000ull +#endif /* _PPC_PNV_H */ include/hw/ppc/xics.h +24
-0@@ -119,8 +119,27 @@ struct ICPState {bool cap_irq_xics_enabled;XICSState *xics; + +/* +* for XICSNative (not used by Linux). +*/ +uint32_t links[3 ]; }; +#define TYPE_XICS_NATIVE "xics-native" +#define XICS_NATIVE (obj) OBJECT_CHECK(XICSNative, (obj), TYPE_XICS_NATIVE) +#define XICS_NATIVE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XICSStateClass, (klass), TYPE_XICS_NATIVE) +#define XICS_NATIVE_GET_CLASS (obj) \ + OBJECT_CLASS_CHECK(XICSStateClass, (obj), TYPE_XICS_NATIVE) + +typedef struct XICSNative { +XICSState parent_obj; + +MemoryRegion icp_mmio; +MemoryRegion *icp_mmios; +}XICSNative ; +#define TYPE_ICS_BASE "ics-base"#define ICS_BASE (obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_BASE)@@ -209,4 +228,9 @@ void ics_set_irq_type(ICSState *ics, int srcno, bool lsi);ICSState *xics_find_source (XICSState *icp,int irq); +typedef struct PnvChip PnvChip ; + +void xics_native_populate_icp (PnvChip *chip,void *fdt,int offset, +uint32_t base,uint32_t count); +#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 v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 101 lines · David Gibson
Quoted 100 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_tableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +39
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +}
Quoted 8 lines
hw/intc/xics_native.c line 44
Quoted 5 lines
hw/intc/xics_native.c new file +5
-0+ +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should.
Well, it has sysbus mmio region, but it is not created with qdev_create(...) so it is not under sysbus and the reset does not get called. That is my understanding of the problem.
May be we shouldn't be using a sysbus mmio region ?
Quoted 1 line
If it was,
device_resetshould be called without these shenannigans.
yes.
Quoted 181 lines
Quoted 181 lines
hw/intc/xics_native.c new file +181
-0+ +static uint64_t xics_native_read (void *opaque,hwaddr addr,unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); +uint64_t val =0xffffffff ; + +switch (addr &0xffc ) { +case 0 :/* poll */ + val =icp_ipoll (icp,NULL ); +if (byte0) { + val >>=24 ; + }else if (width !=4 ) { + goto bad_access; + } +break ; +case 4 :/* xirr */ +if (byte0) { + val =icp_ipoll (icp,NULL ) >>24 ; + }else if (width ==4 ) { + val =icp_accept (icp); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { + val = icp->mfrr; + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + val = icp->links[0 ]; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + val = icp->links[1 ]; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + val = icp->links[2 ]; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } + +return val; +} + +static void xics_native_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); + +switch (addr &0xffc ) { +case 4 :/* xirr */ +if (byte0) { +icp_set_cppr (icp, val); + }else if (width ==4 ) { +icp_eoi (icp, val); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { +icp_set_mfrr (icp, val); + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + icp->links[0 ] = val; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + icp->links[1 ] = val; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + icp->links[2 ] = val; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } +} + +static const MemoryRegionOps xics_native_ops = { + .read = xics_native_read, + .write = xics_native_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static uint64_t xics_native_default_read (void *opaque,hwaddr addr, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +return 0xffffffffffffffffull ; +} + +static void xics_native_default_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +} + +static const MemoryRegionOps xics_native_default_ops = { + .read = xics_native_default_read, + .write = xics_native_default_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static void xics_native_set_nr_servers (XICSState *xics,uint32_t nr_servers, +Error **errp) +{ +xics_set_nr_servers (xics, nr_servers,TYPE_ICP , errp); +} + +static void xics_native_realize (DeviceState *dev,Error **errp) +{ +XICSState *xics =XICS_COMMON (dev); +XICSNative *xicsn =XICS_NATIVE (dev); +Error *error =NULL ; +int i; + +if (!xics->nr_servers) { +error_setg (errp,"Number of servers needs to be greater than 0" ); +return ; + } + +for (i =0 ; i < xics->nr_servers; i++) { +object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , + &error); +if (error) { +error_propagate (errp, error); +return ; + } + } + +/* +* Initialize the container region for the ICPs and the subregion +* for each cpu. The mmapping will be done at the board level +* depending on the pir of the core. +* +* TODO: build a name with the chip id
Quoted 8 lines
hw/intc/xics_native.c line 229
Quoted 4 lines
hw/intc/xics_native.c new file +4
-0+*/ +memory_region_init_io (&xicsn->icp_mmio,OBJECT (dev), + &xics_native_default_ops, xicsn,"icp-0" , +PNV_XICS_SIZE );I don't think you should need these native ops. I believe you can construct a memory region as a "pure" container, then just put the populated regions inside it.
It is a way to track bogus read/writes the guest shouldn't be doing but it is not that important. I can remove it.
Thanks
C.
Quoted 146 lines
Quoted 145 lines
hw/intc/xics_native.c new file +75
-0+sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xicsn->icp_mmio); + + xicsn->icp_mmios =g_new0 (MemoryRegion, xics->nr_servers); +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +memory_region_init_io (&xicsn->icp_mmios[i],OBJECT (dev), + &xics_native_ops, icp,"icp-0" ,0x1000 ); + } +} + +static void xics_native_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +XICSStateClass *xsc =XICS_NATIVE_CLASS (oc); + + dc->realize = xics_native_realize; + xsc->set_nr_servers = xics_native_set_nr_servers; +} + +static const TypeInfo xics_native_info = { + .name =TYPE_XICS_NATIVE , + .parent =TYPE_XICS_COMMON , + .instance_size =sizeof (XICSNative), + .class_size =sizeof (XICSStateClass), + .class_init = xics_native_class_init, + .instance_init = xics_native_initfn, +}; + +static void xics_native_register_types (void ) +{ +type_register_static (&xics_native_info); +} + +type_init (xics_native_register_types) + +void xics_native_populate_icp(PnvChip *chip, void *fdt, int offset, +uint32_t pir,uint32_t count) +{ +uint64_t addr; +char *name; +const char compat[] ="IBM,power8-icp\0IBM,ppc-xicp" ; +uint32_t irange[2 ], i, rsize; +uint64_t *reg; + +/* +* TODO: add multichip ICP BAR +*/ + addr =PNV_XICS_BASE | (pir <<12 ); + + irange[0 ] =cpu_to_be32 (pir); + irange[1 ] =cpu_to_be32 (count); + + rsize =sizeof (uint64_t ) *2 * count; + reg =g_malloc (rsize); +for (i =0 ; i < count; i++) { + reg[i *2 ] =cpu_to_be64 (addr | ((pir + i) *0x1000 )); + reg[i *2 +1 ] =cpu_to_be64 (0x1000 ); + } + + name =g_strdup_printf ("interrupt-controller@%" PRIX64 , addr); + offset =fdt_add_subnode (fdt, offset, name); +_FDT (offset); +g_free (name); + +_FDT ((fdt_setprop (fdt, offset,"compatible" , compat,sizeof (compat)))); +_FDT ((fdt_setprop (fdt, offset,"reg" , reg, rsize))); +_FDT ((fdt_setprop_string (fdt, offset,"device_type" , +"PowerPC-External-Interrupt-Presentation" ))); +_FDT ((fdt_setprop (fdt, offset,"interrupt-controller" ,NULL ,0 ))); +_FDT ((fdt_setprop (fdt, offset,"ibm,interrupt-server-ranges" , + irange,sizeof (irange)))); +_FDT ((fdt_setprop_cell (fdt, offset,"#interrupt-cells" ,1 ))); +_FDT ((fdt_setprop_cell (fdt, offset,"#address-cells" ,0 ))); +g_free (reg); +}include/hw/ppc/pnv.h +19
-0@@ -126,4 +126,23 @@ typedef struct PnvMachineState {#define PNV_XSCOM_BASE (chip) \ (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) +/* +* XSCOM 0x20109CA defines the ICP BAR: +* +* 0:29 : bits 14 to 43 of address to define 1 MB region. +* 30 : 1 to enable ICP to receive loads/stores against its BAR region +* 31:63 : Constant 0 +* +* Usually defined as : +* +* 0xffffe00200000000 -> 0x0003ffff80000000 +* 0xffffe00600000000 -> 0x0003ffff80100000 +* 0xffffe02200000000 -> 0x0003ffff80800000 +* 0xffffe02600000000 -> 0x0003ffff80900000 +* +* TODO: make a macro using the chip hw id +*/ +#define PNV_XICS_BASE 0x0003ffff80000000ull +#define PNV_XICS_SIZE 0x0000000000100000ull +#endif /* _PPC_PNV_H */ include/hw/ppc/xics.h +24
-0@@ -119,8 +119,27 @@ struct ICPState {bool cap_irq_xics_enabled;XICSState *xics; + +/* +* for XICSNative (not used by Linux). +*/ +uint32_t links[3 ]; }; +#define TYPE_XICS_NATIVE "xics-native" +#define XICS_NATIVE (obj) OBJECT_CHECK(XICSNative, (obj), TYPE_XICS_NATIVE) +#define XICS_NATIVE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XICSStateClass, (klass), TYPE_XICS_NATIVE) +#define XICS_NATIVE_GET_CLASS (obj) \ + OBJECT_CLASS_CHECK(XICSStateClass, (obj), TYPE_XICS_NATIVE) + +typedef struct XICSNative { +XICSState parent_obj; + +MemoryRegion icp_mmio; +MemoryRegion *icp_mmios; +}XICSNative ; +#define TYPE_ICS_BASE "ics-base"#define ICS_BASE (obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_BASE)@@ -209,4 +228,9 @@ void ics_set_irq_type(ICSState *ics, int srcno, bool lsi);ICSState *xics_find_source (XICSState *icp,int irq); +typedef struct PnvChip PnvChip ; + +void xics_native_populate_icp (PnvChip *chip,void *fdt,int offset, +uint32_t base,uint32_t count); +#endif /* XICS_H */
Re: [Qemu-devel] [PATCH v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 111 lines · Cédric Le Goater
Quoted 101 lines · David Gibson
Quoted 100 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_tableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +39
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +}Quoted 8 lines
hw/intc/xics_native.c line 44
Quoted 5 lines
hw/intc/xics_native.c new file +5
-0+ +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should.
Quoted 5 lines
Well, it has sysbus mmio region, but it is not created with
qdev_create(...)so it is not under sysbus and the reset does not get called. That is my understanding of the problem.May be we shouldn't be using a sysbus mmio region ?
Yeah, maybe not. We don't really fit the sysbus model well.
I do kind of wonder if the xics object should be an mmio device at all, or if just the individual ICPs should be. But that might make for more trouble.
Quoted 195 lines
Quoted 1 line
If it was,
device_resetshould be called without these shenannigans.yes.
Quoted 181 lines
Quoted 181 lines
hw/intc/xics_native.c new file +181
-0+ +static uint64_t xics_native_read (void *opaque,hwaddr addr,unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); +uint64_t val =0xffffffff ; + +switch (addr &0xffc ) { +case 0 :/* poll */ + val =icp_ipoll (icp,NULL ); +if (byte0) { + val >>=24 ; + }else if (width !=4 ) { + goto bad_access; + } +break ; +case 4 :/* xirr */ +if (byte0) { + val =icp_ipoll (icp,NULL ) >>24 ; + }else if (width ==4 ) { + val =icp_accept (icp); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { + val = icp->mfrr; + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + val = icp->links[0 ]; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + val = icp->links[1 ]; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + val = icp->links[2 ]; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } + +return val; +} + +static void xics_native_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); + +switch (addr &0xffc ) { +case 4 :/* xirr */ +if (byte0) { +icp_set_cppr (icp, val); + }else if (width ==4 ) { +icp_eoi (icp, val); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { +icp_set_mfrr (icp, val); + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + icp->links[0 ] = val; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + icp->links[1 ] = val; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + icp->links[2 ] = val; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } +} + +static const MemoryRegionOps xics_native_ops = { + .read = xics_native_read, + .write = xics_native_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static uint64_t xics_native_default_read (void *opaque,hwaddr addr, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +return 0xffffffffffffffffull ; +} + +static void xics_native_default_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +} + +static const MemoryRegionOps xics_native_default_ops = { + .read = xics_native_default_read, + .write = xics_native_default_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static void xics_native_set_nr_servers (XICSState *xics,uint32_t nr_servers, +Error **errp) +{ +xics_set_nr_servers (xics, nr_servers,TYPE_ICP , errp); +} + +static void xics_native_realize (DeviceState *dev,Error **errp) +{ +XICSState *xics =XICS_COMMON (dev); +XICSNative *xicsn =XICS_NATIVE (dev); +Error *error =NULL ; +int i; + +if (!xics->nr_servers) { +error_setg (errp,"Number of servers needs to be greater than 0" ); +return ; + } + +for (i =0 ; i < xics->nr_servers; i++) { +object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , + &error); +if (error) { +error_propagate (errp, error); +return ; + } + } + +/* +* Initialize the container region for the ICPs and the subregion +* for each cpu. The mmapping will be done at the board level +* depending on the pir of the core. +* +* TODO: build a name with the chip id Quoted 8 lines
hw/intc/xics_native.c line 229
Quoted 4 lines
hw/intc/xics_native.c new file +4
-0+*/ +memory_region_init_io (&xicsn->icp_mmio,OBJECT (dev), + &xics_native_default_ops, xicsn,"icp-0" , +PNV_XICS_SIZE );I don't think you should need these native ops. I believe you can construct a memory region as a "pure" container, then just put the populated regions inside it.
Quoted 2 lines
It is a way to track bogus read/writes the guest shouldn't be doing but it is not that important. I can remove it.
Right. I don't recall exactly what will happen if you don't populate this at all, but I think you should eventually arrive at the global fallback handler which should give you a similar effect.
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 v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 116 lines · David Gibson
Quoted 115 lines · Cédric Le Goater
Quoted 101 lines · David Gibson
Quoted 100 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_ableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +39
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +}Quoted 8 lines
hw/intc/xics_native.c line 44
Quoted 5 lines
hw/intc/xics_native.c new file +5
-0+ +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should.
Well, it has sysbus mmio region, but it is not created with
qdev_create(...)so it is not under sysbus and the reset does not get called. That is my understanding of the problem.
Quoted 7 lines
Quoted 1 line
May be we shouldn't be using a sysbus mmio region ?
Yeah, maybe not. We don't really fit the sysbus model well.
I do kind of wonder if the xics object should be an mmio device at all, or if just the individual ICPs should be. But that might make for more trouble.
A cleanup brings another :) It is true that xics native does not have any controls. It is just a container to hold the array of ICPs and so each of these could well be a child object of PnvCore. Well, of a PnvThread but we don't have that today.
I am going to move the container region to PnvChip to start with and if I can the ICP regions to PnvCore. When we realize the PnvCore, we have the xics, but I need to find a way to grab the ICPState from it. I might need to use the cpu_index for that or could I change xics_cpu_setup() to return an 'ICPState *' ?
I would prefer the ICP to be a PnvCore/Thread child object but that is too early I think.
So if that comes well together, we will get rid of XICSNative and we will use a XICSState for its ICP array.
Quoted 202 lines
Quoted 195 lines
Quoted 1 line
If it was,
device_resetshould be called without these shenannigans.yes.
Quoted 181 lines
Quoted 181 lines
hw/intc/xics_native.c new file +181
-0+ +static uint64_t xics_native_read (void *opaque,hwaddr addr,unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); +uint64_t val =0xffffffff ; + +switch (addr &0xffc ) { +case 0 :/* poll */ + val =icp_ipoll (icp,NULL ); +if (byte0) { + val >>=24 ; + }else if (width !=4 ) { + goto bad_access; + } +break ; +case 4 :/* xirr */ +if (byte0) { + val =icp_ipoll (icp,NULL ) >>24 ; + }else if (width ==4 ) { + val =icp_accept (icp); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { + val = icp->mfrr; + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + val = icp->links[0 ]; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + val = icp->links[1 ]; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + val = icp->links[2 ]; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } + +return val; +} + +static void xics_native_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +ICPState *icp = opaque; +bool byte0 = (width ==1 && (addr &0x3 ) ==0 ); + +switch (addr &0xffc ) { +case 4 :/* xirr */ +if (byte0) { +icp_set_cppr (icp, val); + }else if (width ==4 ) { +icp_eoi (icp, val); + }else { + goto bad_access; + } +break ; +case 12 : +if (byte0) { +icp_set_mfrr (icp, val); + }else { + goto bad_access; + } +break ; +case 16 : +if (width ==4 ) { + icp->links[0 ] = val; + }else { + goto bad_access; + } +break ; +case 20 : +if (width ==4 ) { + icp->links[1 ] = val; + }else { + goto bad_access; + } +break ; +case 24 : +if (width ==4 ) { + icp->links[2 ] = val; + }else { + goto bad_access; + } +break ; +default : +bad_access: +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); + } +} + +static const MemoryRegionOps xics_native_ops = { + .read = xics_native_read, + .write = xics_native_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static uint64_t xics_native_default_read (void *opaque,hwaddr addr, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +return 0xffffffffffffffffull ; +} + +static void xics_native_default_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"XICS: Bad ICP access 0x%" + HWADDR_PRIx"/%d\n" , addr, width); +} + +static const MemoryRegionOps xics_native_default_ops = { + .read = xics_native_default_read, + .write = xics_native_default_write, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =4 , + .endianness =DEVICE_BIG_ENDIAN , +}; + +static void xics_native_set_nr_servers (XICSState *xics,uint32_t nr_servers, +Error **errp) +{ +xics_set_nr_servers (xics, nr_servers,TYPE_ICP , errp); +} + +static void xics_native_realize (DeviceState *dev,Error **errp) +{ +XICSState *xics =XICS_COMMON (dev); +XICSNative *xicsn =XICS_NATIVE (dev); +Error *error =NULL ; +int i; + +if (!xics->nr_servers) { +error_setg (errp,"Number of servers needs to be greater than 0" ); +return ; + } + +for (i =0 ; i < xics->nr_servers; i++) { +object_property_set_bool (OBJECT (&xics->ss[i]), true,"realized" , + &error); +if (error) { +error_propagate (errp, error); +return ; + } + } + +/* +* Initialize the container region for the ICPs and the subregion +* for each cpu. The mmapping will be done at the board level +* depending on the pir of the core. +* +* TODO: build a name with the chip id Quoted 8 lines
hw/intc/xics_native.c line 229
Quoted 4 lines
hw/intc/xics_native.c new file +4
-0+*/ +memory_region_init_io (&xicsn->icp_mmio,OBJECT (dev), + &xics_native_default_ops, xicsn,"icp-0" , +PNV_XICS_SIZE );I don't think you should need these native ops. I believe you can construct a memory region as a "pure" container, then just put the populated regions inside it.
Quoted 2 lines
It is a way to track bogus read/writes the guest shouldn't be doing but it is not that important. I can remove it.
Right. I don't recall exactly what will happen if you don't populate this at all, but I think you should eventually arrive at the global fallback handler which should give you a similar effect.
Re: [Qemu-devel] [PATCH v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 121 lines · Cédric Le Goater
Quoted 120 lines · David Gibson
Quoted 111 lines · Cédric Le Goater
Quoted 101 lines · David Gibson
Quoted 100 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_ableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +39
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +}Quoted 8 lines
hw/intc/xics_native.c line 44
Quoted 5 lines
hw/intc/xics_native.c new file +5
-0+ +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should.
Quoted 5 lines
Well, it has sysbus mmio region, but it is not created with
qdev_create(...)so it is not under sysbus and the reset does not get called. That is my understanding of the problem.May be we shouldn't be using a sysbus mmio region ?
Yeah, maybe not. We don't really fit the sysbus model well.
Quoted 8 lines
Quoted 3 lines
I do kind of wonder if the xics object should be an mmio device at all, or if just the individual ICPs should be. But that might make for more trouble.
A cleanup brings another :) It is true that xics native does not have any controls. It is just a container to hold the array of ICPs and so each of these could well be a child object of PnvCore. Well, of a PnvThread but we don't have that today.
Ok.
Quoted 8 lines
I am going to move the container region to PnvChip to start with and if I can the ICP regions to PnvCore. When we realize the PnvCore, we have the xics, but I need to find a way to grab the ICPState from it. I might need to use the
cpu_indexfor that or could I changexics_cpu_setup()to return an 'ICPState *' ?I would prefer the ICP to be a PnvCore/Thread child object but that is too early I think.
Right, that makes sense.
Quoted 2 lines
So if that comes well together, we will get rid of XICSNative and we will use a XICSState for its ICP array.
So, I just had a thought about this that I think might work, though it would require cleaning up the existing stuff in spapr before extending for powernv:
Abolish the (overall) XICS as a fully realized object, and instead make it a QOM interface, which is implemented by the machine. ICPs and ICSes remain real devices, which (as now) would have a link back to the XICS interface object.
The XICS interface would provide server-number-to-ICP-pointer and irq-number-to-ICS-pointer callbacks. That puts the "fabric" logic - how the IPCs and ICSes find each other back in the machine, which I think is where it belongs. Obviously we could still provide xics_system_init() or similar helpers to make it easier for the machines to implement the xics interface.
The overall XICS has no migrated state, which means that change shouldn't fundamentally break things. There might be issues with the qom paths of ICS or ICP changing, we'd have to check 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 v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 147 lines · David Gibson
Quoted 121 lines · Cédric Le Goater
Quoted 120 lines · David Gibson
Quoted 111 lines · Cédric Le Goater
Quoted 101 lines · David Gibson
Quoted 100 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_ableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +39
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +}Quoted 8 lines
hw/intc/xics_native.c line 44
Quoted 5 lines
hw/intc/xics_native.c new file +5
-0+ +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should.
Quoted 5 lines
Well, it has sysbus mmio region, but it is not created with
qdev_create(...)so it is not under sysbus and the reset does not get called. That is my understanding of the problem.May be we shouldn't be using a sysbus mmio region ?
Yeah, maybe not. We don't really fit the sysbus model well.
Quoted 8 lines
Quoted 3 lines
I do kind of wonder if the xics object should be an mmio device at all, or if just the individual ICPs should be. But that might make for more trouble.
A cleanup brings another :) It is true that xics native does not have any controls. It is just a container to hold the array of ICPs and so each of these could well be a child object of PnvCore. Well, of a PnvThread but we don't have that today.
Ok.
Quoted 8 lines
I am going to move the container region to PnvChip to start with and if I can the ICP regions to PnvCore. When we realize the PnvCore, we have the xics, but I need to find a way to grab the ICPState from it. I might need to use the
cpu_indexfor that or could I changexics_cpu_setup()to return an 'ICPState *' ?I would prefer the ICP to be a PnvCore/Thread child object but that is too early I think.
Right, that makes sense.
Quoted 2 lines
So if that comes well together, we will get rid of XICSNative and we will use a XICSState for its ICP array.
Quoted 8 lines
So, I just had a thought about this that I think might work, though it would require cleaning up the existing stuff in spapr before extending for powernv:
Abolish the (overall) XICS as a fully realized object, and instead make it a QOM interface, which is implemented by the machine. ICPs and ICSes remain real devices, which (as now) would have a link back to the XICS interface object.
OK. I will take a look at that for 2.9.
Here is the current status for pnv. XICSNative is gone. The ICP container region is under the chip and the ICP-per-thread subregions under PnvCore. The machine uses a XICS_COMMON object to hold the array of ICPs and the list of ICS. The result is much better but I had to modify a few things in xics to be able to instantiate a XICS_COMMON object :
* add a new ops to XICSStateClass :
void (*realize)(DeviceState *dev, Error **errp)
to clean up xics_kvm_realize() and xics_spapr_realize() which are doing the same thing. That's a good cleanup going in the direction you are talking about. So maybe I could send for 2.8
* add a xics_common_set_nr_servers() routine to create the ICPs when a XICS_COMMON object is instantiated. That is more a work around. That business around the "nr_irqs" and "nr_servers" properties is confusing, we should clean it up.
So if you think this is worth 2.8, I can send a couple of patches. Else I can start by some xics cleanups and aim 2.9
Quoted 6 lines
The XICS interface would provide server-number-to-ICP-pointer and irq-number-to-ICS-pointer callbacks. That puts the "fabric" logic - how the IPCs and ICSes find each other back in the machine, which I think is where it belongs. Obviously we could still provide
xics_system_init()or similar helpers to make it easier for the machines to implement the xics interface.
Rough comments and questions :
* ICS :
They don't belong to XICS but we do need to maintain a list as we have a few loops on the ICSs. Should we maintain the list under the machine ?
* ICP :
The server-number-to-ICP-pointer handler should cover most of the needs. If we can use the Core object to hold the ICP, that would be even better. It whould greatly simplify cpu_setup() which is here just for KVM_CAP_IRQ_XICS and the list of cpus would provide the array.
ICP reset would be handled at the Core level
xics_common_pic_print_info() would be a machine handler.
I am not sure what to do with ics_simple_post_load().
C.
Quoted 5 lines
The overall XICS has no migrated state, which means that change shouldn't fundamentally break things. There might be issues with the qom paths of ICS or ICP changing, we'd have to check that.
Re: [Qemu-devel] [PATCH v5 11/17] ppc/xics: Add "native" XICS subclass
Quoted 165 lines · Cédric Le Goater
Quoted 147 lines · David Gibson
Quoted 121 lines · Cédric Le Goater
Quoted 120 lines · David Gibson
Quoted 111 lines · Cédric Le Goater
Quoted 101 lines · David Gibson
Quoted 100 lines · Cédric Le Goater
This provides access to the MMIO based Interrupt Presentation Controllers (ICP) as found on a POWER8 system.
A new XICSNative class is introduced to hold the MMIO region of the ICPs. Each thread of the system has a subregion, indexed by its PIR number, holding a XIVE (External Interrupt Vector Entry). This provides a mean to make the link with the ICPState of the CPU.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- replaced the
pir_ableby memory subregions using an ICP.
- removed thefind_icp()andcpu_setup()handlers which became useless with the memory regions.
- removed the superfluous inits done inxics_native_initfn. This is covered in the parent class init.
- took ownership of the patch.default-configs/ppc64-softmmu.mak | 3 +- hw/intc/Makefile.objs | 1 + hw/intc/xics_native.c | 304 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 19 +++ include/hw/ppc/xics.h | 24 +++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 hw/intc/xics_native.cdefault-configs/ppc64-softmmu.mak +2
-1@@ -48,8 +48,9 @@ CONFIG_PLATFORM_BUS=y CONFIG_ETSEC=y CONFIG_LIBDECNUMBER=y # For pSeries -CONFIG_XICS=$(CONFIG_PSERIES) +CONFIG_XICS=$(or $(CONFIG_PSERIES),$(CONFIG_POWERNV)) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) +CONFIG_XICS_NATIVE=$(CONFIG_POWERNV) CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o +obj-$(CONFIG_XICS_NATIVE) += xics_native.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/xics_native.c new file +39
-0@@ -0,0 +1,304 @@ +/* +* QEMU PowerPC PowerNV machine model +* +* Native version of ICS/ICP +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/xics.h" +#include "hw/ppc/pnv.h" + +#include <libfdt.h> + +static void xics_native_reset (void *opaque) +{ +device_reset (DEVICE (opaque)); +}Quoted 8 lines
hw/intc/xics_native.c line 44
Quoted 5 lines
hw/intc/xics_native.c new file +5
-0+ +static void xics_native_initfn (Object *obj) +{ +qemu_register_reset (xics_native_reset, obj); +}I think we need to investigate why the xics native is not showing up on the SysBus. As a "raw" MMIO device, it really should.
Quoted 5 lines
Well, it has sysbus mmio region, but it is not created with
qdev_create(...)so it is not under sysbus and the reset does not get called. That is my understanding of the problem.May be we shouldn't be using a sysbus mmio region ?
Yeah, maybe not. We don't really fit the sysbus model well.
Quoted 8 lines
Quoted 3 lines
I do kind of wonder if the xics object should be an mmio device at all, or if just the individual ICPs should be. But that might make for more trouble.
A cleanup brings another :) It is true that xics native does not have any controls. It is just a container to hold the array of ICPs and so each of these could well be a child object of PnvCore. Well, of a PnvThread but we don't have that today.
Ok.
Quoted 8 lines
I am going to move the container region to PnvChip to start with and if I can the ICP regions to PnvCore. When we realize the PnvCore, we have the xics, but I need to find a way to grab the ICPState from it. I might need to use the
cpu_indexfor that or could I changexics_cpu_setup()to return an 'ICPState *' ?I would prefer the ICP to be a PnvCore/Thread child object but that is too early I think.
Right, that makes sense.
Quoted 2 lines
So if that comes well together, we will get rid of XICSNative and we will use a XICSState for its ICP array.
Quoted 8 lines
So, I just had a thought about this that I think might work, though it would require cleaning up the existing stuff in spapr before extending for powernv:
Abolish the (overall) XICS as a fully realized object, and instead make it a QOM interface, which is implemented by the machine. ICPs and ICSes remain real devices, which (as now) would have a link back to the XICS interface object.
OK. I will take a look at that for 2.9.
Here is the current status for pnv. XICSNative is gone. The ICP container region is under the chip and the ICP-per-thread subregions under PnvCore. The machine uses a
XICS_COMMONobject to hold the array of ICPs and the list of ICS. The result is much better but I had to modify a few things in xics to be able to instantiate aXICS_COMMONobject :
Quoted 7 lines
* add a new ops to XICSStateClass :
void (*realize)(DeviceState *dev, Error **errp)
to clean up
xics_kvm_realize()andxics_spapr_realize()which are doing the same thing. That's a good cleanup going in the direction you are talking about. So maybe I could send for 2.8
Sounds likely. Please send it and I'll give it a look and see if I think it's suitable as a late addition to 2.8.
Quoted 4 lines
* add a
xics_common_set_nr_servers()routine to create the ICPs when aXICS_COMMONobject is instantiated. That is more a work around. That business around the "nr_irqs" and "nr_servers" properties is confusing, we should clean it up.
Yeah, it's a bit clunky. The nr_irqs really only makes sense for the spapr case where there's a single ICS.
Quoted 2 lines
So if you think this is worth 2.8, I can send a couple of patches. Else I can start by some xics cleanups and aim 2.9
I think it's at least worth a look to see how invasive it is.
Quoted 7 lines
Quoted 6 lines
The XICS interface would provide server-number-to-ICP-pointer and irq-number-to-ICS-pointer callbacks. That puts the "fabric" logic - how the IPCs and ICSes find each other back in the machine, which I think is where it belongs. Obviously we could still provide
xics_system_init()or similar helpers to make it easier for the machines to implement the xics interface.
Quoted 7 lines
Rough comments and questions :
* ICS :
They don't belong to XICS but we do need to maintain a list as we have a few loops on the ICSs. Should we maintain the list under the machine ?
So, the XICS interface type would need some method to traverse all the ICSes. It would be up to the XICS interface implementor (the machine in this, and probably all, cases) to decide how it does that. spapr would just go to the single known ICS instance. powernv could maintain a list, or alternatively it could use its existing list of chips to find all the possible ICS instances.
Quoted 7 lines
* ICP :
The server-number-to-ICP-pointer handler should cover most of the needs. If we can use the Core object to hold the ICP, that would be even better. It whould greatly simplify
cpu_setup()which is here just forKVM_CAP_IRQ_XICSand the list of cpus would provide the array.
Sure. I don't think whether the ICP is in the core or the chip has much bearing on the XICS interface, only what the machine would need to do exactly to locate the right ICP instance. The machine knows how the PIRs are allocated, so it should be able to parse the server number and work out both chip and core.
Quoted 3 lines
ICP reset would be handled at the Core level
xics_common_pic_print_info()would be a machine handler.
Actually, I think you have a couple of options there. IIRC the interrupt stats provider interface works so that the monitor commands will iterate through all objects supporting the interface.
So, you could make the machine respond and give a global view of the XICS, presumably using a helper function from the XICS code. Alternatively, you could make each ICS support the interface and provide a view of just its piece of the interrupt state (I think it's the ICSes not the ICPs that are relevant for this information, but I could be wrong).
Quoted 1 line
I am not sure what to do with
ics_simple_post_load().
So, ics_simple_post_load() is actually already a bit broken. It relies on the fact that the ICP state is restored before the ICS state, without really enforcing that. There was a bug somewhat related to this recently with interrupts being lost across migration sometimes - the interrupt controller variables were restored, but we didn't correctly recalculate the state of the output line to interrupt the CPU.
This callback is essentially about restoring some cached state across the whole XICS subsystem from the state within the individual ICS and ICP devices - in particular the state of the (logical) output lines. So really, this would belong better in the machine - obviously we'd want a helper in the xics code that any machine implementing the XICS interface could use.
Quoted 10 lines
C.
Quoted 5 lines
The overall XICS has no migrated state, which means that change shouldn't fundamentally break things. There might be issues with the qom paths of ICS or ICP changing, we'd have to check 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
PATCH v5 12/17 ppc/pnv: add a XICS native to each PowerNV chip
In reply to Cédric Le GoaterIt also links the XICS object to each core as it is needed to do the CPU setup and the ICP MMIO windows are memory mapped for each thread.
---
Changes since v4:
- changed the calculation of the number of ICPs to use smp_threads
- added the mapping of the ICP subregions per thread
hw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 24 ++++++++++++++++++++---- include/hw/ppc/pnv.h | 2 ++ 3 files changed, 49 insertions(+), 4 deletions(-)
hw/ppc/pnv.c +27 -0
@@ -33,6 +33,7 @@#include "qemu/cutils.h" #include "qapi/visitor.h" +#include "hw/ppc/xics.h" #include "hw/ppc/pnv_xscom.h" #include "hw/isa/isa.h"
@@ -231,6 +232,9 @@ static void powernv_populate_chip(PnvChip *chip, void *fdt)PnvCore *pnv_core =PNV_CORE (chip->cores + i * typesize);powernv_create_core_node (chip, pnv_core, fdt); + +/* Interrupt presentation controllers (ICP). One per thread. */ +xics_native_populate_icp (chip, fdt,0 , pnv_core->pir, smp_threads); }if (chip->ram_size) {
@@ -637,6 +641,9 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->lpc,sizeof (chip->lpc),TYPE_PNV_LPC );object_property_add_child (obj,"lpc" ,OBJECT (&chip->lpc),NULL ); + +object_initialize (&chip->xics,sizeof (chip->xics),TYPE_XICS_NATIVE ); +object_property_add_child (obj,"xics" ,OBJECT (&chip->xics),NULL ); }static void pnv_chip_realize (DeviceState *dev,Error **errp)
@@ -668,12 +675,23 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)return ; } +/* +* Interrupt Controller. To be created before the cores because +* each thread will fetch its ICP in the XICS +*/ +object_property_set_int (OBJECT (&chip->xics), chip->nr_cores * smp_threads, +"nr_servers" , &error_fatal); +object_property_set_bool (OBJECT (&chip->xics), true,"realized" , + &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (&chip->xics),0 ,PNV_XICS_BASE ); + chip->cores =g_malloc0 (typesize * chip->nr_cores);for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->nr_cores); core_hwid++) {char core_name[32 ];void *pnv_core = chip->cores + i * typesize; +int j;if (!(chip->cores_mask & (1ull << core_hwid))) {continue ;
@@ -690,6 +708,8 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_int (OBJECT (pnv_core), pcc->core_pir (chip, core_hwid),"pir" , &error_fatal); +object_property_add_const_link (OBJECT (pnv_core),"xics" , +OBJECT (&chip->xics), &error_fatal);object_property_set_bool (OBJECT (pnv_core), true,"realized" , &error_fatal);object_unref (OBJECT (pnv_core));
@@ -697,6 +717,13 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)/* Each core has an XSCOM MMIO region */ pnv_xscom_add_subregion (chip,PNV_XSCOM_EX_CORE_BASE (core_hwid), &PNV_CORE (pnv_core)->xscom_regs); + +/* Each thread as region for its ICP */ +for (j =0 ; j < smp_threads; j++) { +memory_region_add_subregion (&chip->xics.icp_mmio, + pcc->core_pir (chip, core_hwid) <<12 , + &chip->xics.icp_mmios[i]); + } i++; }g_free (typename);
hw/ppc/pnv_core.c +20 -4
@@ -24,6 +24,7 @@#include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" #include "hw/ppc/pnv_core.h" +#include "hw/ppc/xics.h" static void powernv_cpu_reset (void *opaque) {
@@ -42,7 +43,7 @@ static void powernv_cpu_reset(void *opaque) env->msr |=MSR_HVB ;/* Hypervisor mode */ } -static void powernv_cpu_init (PowerPCCPU *cpu,Error **errp) +static void powernv_cpu_init (PowerPCCPU *cpu,XICSState *xics,Error **errp) {CPUPPCState *env = &cpu->env;int core_pir;
@@ -62,6 +63,11 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error **errp)cpu_ppc_tb_init (env,PNV_TIMEBASE_FREQ );qemu_register_reset (powernv_cpu_reset, cpu); + +/* +* xics_cpu_setup() assigns the CPU to the ICP in XICS +*/ +xics_cpu_setup (xics, cpu); }/*
@@ -109,7 +115,7 @@ static const MemoryRegionOps pnv_core_xscom_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void pnv_core_realize_child (Object *child,Error **errp) +static void pnv_core_realize_child (Object *child,XICSState *xics,Error **errp) {Error *local_err =NULL ;CPUState *cs =CPU (child);
@@ -121,7 +127,7 @@ static void pnv_core_realize_child(Object *child, Error **errp)return ; } -powernv_cpu_init (cpu, &local_err); +powernv_cpu_init (cpu, xics, &local_err);if (local_err) {error_propagate (errp, local_err);return ;
@@ -139,6 +145,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)void *obj;int i, j;char name[32 ]; +XICSState *xics; pc->threads =g_malloc0 (size * cc->nr_threads);for (i =0 ; i < cc->nr_threads; i++) {
@@ -156,10 +163,19 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)object_unref (obj); } +/* get XICS object from chip */ + obj =object_property_get_link (OBJECT (dev),"xics" , &local_err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (local_err)); +return ; + } + xics =XICS_COMMON (obj); +for (j =0 ; j < cc->nr_threads; j++) { obj = pc->threads + j * size; -pnv_core_realize_child (obj, &local_err); +pnv_core_realize_child (obj, xics, &local_err);if (local_err) { goto err; }
include/hw/ppc/pnv.h +2 -0
@@ -23,6 +23,7 @@#include "hw/sysbus.h" #include "hw/ppc/pnv_xscom.h" #include "hw/ppc/pnv_lpc.h" +#include "hw/ppc/xics.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -57,6 +58,7 @@ typedef struct PnvChip {AddressSpace xscom_as;PnvLpcController lpc; +XICSNative xics; } PnvChip; typedef struct PnvChipClass {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 12/17] ppc/pnv: add a XICS native to each PowerNV chip
Quoted 82 lines · Cédric Le Goater
It also links the XICS object to each core as it is needed to do the CPU setup and the ICP MMIO windows are memory mapped for each thread.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- changed the calculation of the number of ICPs to use
smp_threads
- added the mapping of the ICP subregions per threadhw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 24 ++++++++++++++++++++---- include/hw/ppc/pnv.h | 2 ++ 3 files changed, 49 insertions(+), 4 deletions(-)hw/ppc/pnv.c +20
-0@@ -33,6 +33,7 @@#include "qemu/cutils.h" #include "qapi/visitor.h" +#include "hw/ppc/xics.h" #include "hw/ppc/pnv_xscom.h" #include "hw/isa/isa.h" @@ -231,6 +232,9 @@ static void powernv_populate_chip(PnvChip *chip, void *fdt)PnvCore *pnv_core =PNV_CORE (chip->cores + i * typesize);powernv_create_core_node (chip, pnv_core, fdt); + +/* Interrupt presentation controllers (ICP). One per thread. */ +xics_native_populate_icp (chip, fdt,0 , pnv_core->pir, smp_threads); }if (chip->ram_size) {@@ -637,6 +641,9 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->lpc,sizeof (chip->lpc),TYPE_PNV_LPC );object_property_add_child (obj,"lpc" ,OBJECT (&chip->lpc),NULL ); + +object_initialize (&chip->xics,sizeof (chip->xics),TYPE_XICS_NATIVE ); +object_property_add_child (obj,"xics" ,OBJECT (&chip->xics),NULL ); }static void pnv_chip_realize (DeviceState *dev,Error **errp)@@ -668,12 +675,23 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)return ; } +/* +* Interrupt Controller. To be created before the cores because +* each thread will fetch its ICP in the XICS +*/ +object_property_set_int (OBJECT (&chip->xics), chip->nr_cores * smp_threads, +"nr_servers" , &error_fatal); +object_property_set_bool (OBJECT (&chip->xics), true,"realized" , + &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (&chip->xics),0 ,PNV_XICS_BASE ); + chip->cores =g_malloc0 (typesize * chip->nr_cores);for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->nr_cores); core_hwid++) {char core_name[32 ];void *pnv_core = chip->cores + i * typesize; +int j;if (!(chip->cores_mask & (1ull << core_hwid))) {continue ;@@ -690,6 +708,8 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_int (OBJECT (pnv_core), pcc->core_pir (chip, core_hwid),"pir" , &error_fatal); +object_property_add_const_link (OBJECT (pnv_core),"xics" , +OBJECT (&chip->xics), &error_fatal);object_property_set_bool (OBJECT (pnv_core), true,"realized" , &error_fatal);object_unref (OBJECT (pnv_core));
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 724
Quoted 8 lines
hw/ppc/pnv.c +5
-0@@ -697,6 +717,13 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)/* Each core has an XSCOM MMIO region */ pnv_xscom_add_subregion (chip,PNV_XSCOM_EX_CORE_BASE (core_hwid), &PNV_CORE (pnv_core)->xscom_regs); + +/* Each thread as region for its ICP */ +for (j =0 ; j < smp_threads; j++) { + memory_region_add_subregion(&chip->xics.icp_mmio, + pcc->core_pir(chip, core_hwid) << 12,
Pffut ... This should be :
(pcc->core_pir(chip, core_hwid) + j) << 12,
but as smp_threads=1, it has no consequences for the moment. Tell me how you would prefer me to fix this.
Thanks,
C.
Quoted 106 lines
hw/ppc/pnv.c +2
-0+ &chip->xics.icp_mmios[i]); + } i++; }g_free (typename);hw/ppc/pnv_core.c +20
-4@@ -24,6 +24,7 @@#include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" #include "hw/ppc/pnv_core.h" +#include "hw/ppc/xics.h" static void powernv_cpu_reset (void *opaque) {@@ -42,7 +43,7 @@ static void powernv_cpu_reset(void *opaque) env->msr |=MSR_HVB ;/* Hypervisor mode */ } -static void powernv_cpu_init (PowerPCCPU *cpu,Error **errp) +static void powernv_cpu_init (PowerPCCPU *cpu,XICSState *xics,Error **errp) {CPUPPCState *env = &cpu->env;int core_pir;@@ -62,6 +63,11 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error **errp)cpu_ppc_tb_init (env,PNV_TIMEBASE_FREQ );qemu_register_reset (powernv_cpu_reset, cpu); + +/* +* xics_cpu_setup() assigns the CPU to the ICP in XICS +*/ +xics_cpu_setup (xics, cpu); }/* @@ -109,7 +115,7 @@ static const MemoryRegionOps pnv_core_xscom_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void pnv_core_realize_child (Object *child,Error **errp) +static void pnv_core_realize_child (Object *child,XICSState *xics,Error **errp) {Error *local_err =NULL ;CPUState *cs =CPU (child);@@ -121,7 +127,7 @@ static void pnv_core_realize_child(Object *child, Error **errp)return ; } -powernv_cpu_init (cpu, &local_err); +powernv_cpu_init (cpu, xics, &local_err);if (local_err) {error_propagate (errp, local_err);return ;@@ -139,6 +145,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)void *obj;int i, j;char name[32 ]; +XICSState *xics; pc->threads =g_malloc0 (size * cc->nr_threads);for (i =0 ; i < cc->nr_threads; i++) {@@ -156,10 +163,19 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)object_unref (obj); } +/* get XICS object from chip */ + obj =object_property_get_link (OBJECT (dev),"xics" , &local_err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (local_err)); +return ; + } + xics =XICS_COMMON (obj); +for (j =0 ; j < cc->nr_threads; j++) { obj = pc->threads + j * size; -pnv_core_realize_child (obj, &local_err); +pnv_core_realize_child (obj, xics, &local_err);if (local_err) { goto err; }include/hw/ppc/pnv.h +2
-0@@ -23,6 +23,7 @@#include "hw/sysbus.h" #include "hw/ppc/pnv_xscom.h" #include "hw/ppc/pnv_lpc.h" +#include "hw/ppc/xics.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)@@ -57,6 +58,7 @@ typedef struct PnvChip {AddressSpace xscom_as;PnvLpcController lpc; +XICSNative xics; } PnvChip; typedef struct PnvChipClass {
Re: [Qemu-devel] [PATCH v5 12/17] ppc/pnv: add a XICS native to each PowerNV chip
Quoted 94 lines · Cédric Le Goater
Quoted 82 lines · Cédric Le Goater
It also links the XICS object to each core as it is needed to do the CPU setup and the ICP MMIO windows are memory mapped for each thread.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v4:
- changed the calculation of the number of ICPs to use
smp_threads
- added the mapping of the ICP subregions per threadhw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 24 ++++++++++++++++++++---- include/hw/ppc/pnv.h | 2 ++ 3 files changed, 49 insertions(+), 4 deletions(-)hw/ppc/pnv.c +20
-0@@ -33,6 +33,7 @@#include "qemu/cutils.h" #include "qapi/visitor.h" +#include "hw/ppc/xics.h" #include "hw/ppc/pnv_xscom.h" #include "hw/isa/isa.h" @@ -231,6 +232,9 @@ static void powernv_populate_chip(PnvChip *chip, void *fdt)PnvCore *pnv_core =PNV_CORE (chip->cores + i * typesize);powernv_create_core_node (chip, pnv_core, fdt); + +/* Interrupt presentation controllers (ICP). One per thread. */ +xics_native_populate_icp (chip, fdt,0 , pnv_core->pir, smp_threads); }if (chip->ram_size) {@@ -637,6 +641,9 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->lpc,sizeof (chip->lpc),TYPE_PNV_LPC );object_property_add_child (obj,"lpc" ,OBJECT (&chip->lpc),NULL ); + +object_initialize (&chip->xics,sizeof (chip->xics),TYPE_XICS_NATIVE ); +object_property_add_child (obj,"xics" ,OBJECT (&chip->xics),NULL ); }static void pnv_chip_realize (DeviceState *dev,Error **errp)@@ -668,12 +675,23 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)return ; } +/* +* Interrupt Controller. To be created before the cores because +* each thread will fetch its ICP in the XICS +*/ +object_property_set_int (OBJECT (&chip->xics), chip->nr_cores * smp_threads, +"nr_servers" , &error_fatal); +object_property_set_bool (OBJECT (&chip->xics), true,"realized" , + &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (&chip->xics),0 ,PNV_XICS_BASE ); + chip->cores =g_malloc0 (typesize * chip->nr_cores);for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->nr_cores); core_hwid++) {char core_name[32 ];void *pnv_core = chip->cores + i * typesize; +int j;if (!(chip->cores_mask & (1ull << core_hwid))) {continue ;@@ -690,6 +708,8 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_int (OBJECT (pnv_core), pcc->core_pir (chip, core_hwid),"pir" , &error_fatal); +object_property_add_const_link (OBJECT (pnv_core),"xics" , +OBJECT (&chip->xics), &error_fatal);object_property_set_bool (OBJECT (pnv_core), true,"realized" , &error_fatal);object_unref (OBJECT (pnv_core));hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 724
Quoted 8 lines
hw/ppc/pnv.c +5
-0@@ -697,6 +717,13 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)/* Each core has an XSCOM MMIO region */ pnv_xscom_add_subregion (chip,PNV_XSCOM_EX_CORE_BASE (core_hwid), &PNV_CORE (pnv_core)->xscom_regs); + +/* Each thread as region for its ICP */ +for (j =0 ; j < smp_threads; j++) { + memory_region_add_subregion(&chip->xics.icp_mmio, + pcc->core_pir(chip, core_hwid) << 12,Pffut ... This should be :
Quoted 4 lines
(pcc->core_pir(chip, core_hwid) + j) << 12,but as smp_threads=1, it has no consequences for the moment. Tell me how you would prefer me to fix this.
I think I have enough comments on the previous patch that a respin of patches 11+ will make sense, so just fix it then.
Quoted 113 lines
Thanks,
C.
Quoted 106 lines
hw/ppc/pnv.c +2
-0+ &chip->xics.icp_mmios[i]); + } i++; }g_free (typename);hw/ppc/pnv_core.c +20
-4@@ -24,6 +24,7 @@#include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" #include "hw/ppc/pnv_core.h" +#include "hw/ppc/xics.h" static void powernv_cpu_reset (void *opaque) {@@ -42,7 +43,7 @@ static void powernv_cpu_reset(void *opaque) env->msr |=MSR_HVB ;/* Hypervisor mode */ } -static void powernv_cpu_init (PowerPCCPU *cpu,Error **errp) +static void powernv_cpu_init (PowerPCCPU *cpu,XICSState *xics,Error **errp) {CPUPPCState *env = &cpu->env;int core_pir;@@ -62,6 +63,11 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error **errp)cpu_ppc_tb_init (env,PNV_TIMEBASE_FREQ );qemu_register_reset (powernv_cpu_reset, cpu); + +/* +* xics_cpu_setup() assigns the CPU to the ICP in XICS +*/ +xics_cpu_setup (xics, cpu); }/* @@ -109,7 +115,7 @@ static const MemoryRegionOps pnv_core_xscom_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static void pnv_core_realize_child (Object *child,Error **errp) +static void pnv_core_realize_child (Object *child,XICSState *xics,Error **errp) {Error *local_err =NULL ;CPUState *cs =CPU (child);@@ -121,7 +127,7 @@ static void pnv_core_realize_child(Object *child, Error **errp)return ; } -powernv_cpu_init (cpu, &local_err); +powernv_cpu_init (cpu, xics, &local_err);if (local_err) {error_propagate (errp, local_err);return ;@@ -139,6 +145,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)void *obj;int i, j;char name[32 ]; +XICSState *xics; pc->threads =g_malloc0 (size * cc->nr_threads);for (i =0 ; i < cc->nr_threads; i++) {@@ -156,10 +163,19 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)object_unref (obj); } +/* get XICS object from chip */ + obj =object_property_get_link (OBJECT (dev),"xics" , &local_err); +if (!obj) { +error_setg (errp,"%s: required link 'xics' not found: %s" , + __func__,error_get_pretty (local_err)); +return ; + } + xics =XICS_COMMON (obj); +for (j =0 ; j < cc->nr_threads; j++) { obj = pc->threads + j * size; -pnv_core_realize_child (obj, &local_err); +pnv_core_realize_child (obj, xics, &local_err);if (local_err) { goto err; }include/hw/ppc/pnv.h +2
-0@@ -23,6 +23,7 @@#include "hw/sysbus.h" #include "hw/ppc/pnv_xscom.h" #include "hw/ppc/pnv_lpc.h" +#include "hw/ppc/xics.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)@@ -57,6 +58,7 @@ typedef struct PnvChip {AddressSpace xscom_as;PnvLpcController lpc; +XICSNative xics; } PnvChip; typedef struct PnvChipClass {
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
PATCH v5 13/17 ppc/xics: add a xics_get_cpu_index_by_pir helper
In reply to Cédric Le GoaterWe will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
--- hw/intc/xics_native.c | 19 +++++++++++++++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 20 insertions(+)
hw/intc/xics_native.c +19 -0
@@ -33,6 +33,25 @@#include <libfdt.h> +int xics_get_cpu_index_by_pir (XICSState *xics,int pir) +{ +int i; + +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +if (icp->cs) { +PowerPCCPU *cpu =POWERPC_CPU (icp->cs); +CPUPPCState *env = &cpu->env; + +if (env->spr_cb[SPR_PIR ].default_value == pir) { +return i; + } + } + } + +return -1 ; +} +static void xics_native_reset (void *opaque) {device_reset (DEVICE (opaque));
include/hw/ppc/xics.h +1 -0
@@ -214,6 +214,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers,/* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id (int cpu_dt_id); +int xics_get_cpu_index_by_pir (XICSState *xics,int pir);void icp_set_cppr (ICPState *icp,uint8_t cppr);void icp_set_mfrr (ICPState *icp,uint8_t mfrr);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 13/17] ppc/xics: add a xics_get_cpu_index_by_pir helper
Quoted 4 lines · Cédric Le Goater
We will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
Signed-off-by Cédric Le Goater <[email protected]>
Looks correct as far as it goes, but I wonder if this would be more generally useful as a machine level function that searches the cpu objects by PIR, returning a pointer. From that to the cpu_index is then trivial.
Quoted 47 lines
--- hw/intc/xics_native.c | 19 +++++++++++++++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 20 insertions(+)hw/intc/xics_native.c +19
-0@@ -33,6 +33,25 @@#include <libfdt.h> +int xics_get_cpu_index_by_pir (XICSState *xics,int pir) +{ +int i; + +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +if (icp->cs) { +PowerPCCPU *cpu =POWERPC_CPU (icp->cs); +CPUPPCState *env = &cpu->env; + +if (env->spr_cb[SPR_PIR ].default_value == pir) { +return i; + } + } + } + +return -1 ; +} +static void xics_native_reset (void *opaque) {device_reset (DEVICE (opaque));include/hw/ppc/xics.h +1
-0@@ -214,6 +214,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers,/* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id (int cpu_dt_id); +int xics_get_cpu_index_by_pir (XICSState *xics,int pir);void icp_set_cppr (ICPState *icp,uint8_t cppr);void icp_set_mfrr (ICPState *icp,uint8_t mfrr);
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 v5 13/17] ppc/xics: add a xics_get_cpu_index_by_pir helper
Quoted 10 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
We will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
Signed-off-by Cédric Le Goater <[email protected]>Looks correct as far as it goes, but I wonder if this would be more generally useful as a machine level function that searches the cpu objects by PIR, returning a pointer. From that to the
cpu_indexis then trivial.
Well I guess so. The XICSState argument reduces the scope in case of multichip but as this routine is used to initialize the xive registers, it does not need to be fast.
So you rather have, something like:
PowerPCCPU *ppc_get_vcpu_by_pir(int pir);
similar to :
PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id);
Thanks,
C.
Quoted 48 lines
Quoted 47 lines
--- hw/intc/xics_native.c | 19 +++++++++++++++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 20 insertions(+)hw/intc/xics_native.c +19
-0@@ -33,6 +33,25 @@#include <libfdt.h> +int xics_get_cpu_index_by_pir (XICSState *xics,int pir) +{ +int i; + +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +if (icp->cs) { +PowerPCCPU *cpu =POWERPC_CPU (icp->cs); +CPUPPCState *env = &cpu->env; + +if (env->spr_cb[SPR_PIR ].default_value == pir) { +return i; + } + } + } + +return -1 ; +} +static void xics_native_reset (void *opaque) {device_reset (DEVICE (opaque));include/hw/ppc/xics.h +1
-0@@ -214,6 +214,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers,/* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id (int cpu_dt_id); +int xics_get_cpu_index_by_pir (XICSState *xics,int pir);void icp_set_cppr (ICPState *icp,uint8_t cppr);void icp_set_mfrr (ICPState *icp,uint8_t mfrr);
Re: [Qemu-devel] [PATCH v5 13/17] ppc/xics: add a xics_get_cpu_index_by_pir helper
Quoted 7 lines · Cédric Le Goater
Quoted 6 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
We will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 8 lines
Quoted 4 lines
Looks correct as far as it goes, but I wonder if this would be more generally useful as a machine level function that searches the cpu objects by PIR, returning a pointer. From that to the
cpu_indexis then trivial.Well I guess so. The XICSState argument reduces the scope in case of multichip but as this routine is used to initialize the xive registers, it does not need to be fast.
Ahh.. I was thinking of the top-level xics object as global, rather than per-chip.
Except.. does having it per-chip work anyway? The server numbers are globally unique, aren't they? What happens if you put a server number from one chip as the target for an ICE on another chip?
The xics object is a bit weird, in that it doesn't represent a real device in a sense, but is rather something to co-ordinate global addressing between ICS and ICP units. Well, I suppose in that sense it represent the interrupt propagation fabric.
Quoted 62 lines
So you rather have, something like:
PowerPCCPU *ppc_get_vcpu_by_pir(int pir);similar to :
PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id);Thanks,
C.
Quoted 48 lines
Quoted 47 lines
--- hw/intc/xics_native.c | 19 +++++++++++++++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 20 insertions(+)hw/intc/xics_native.c +19
-0@@ -33,6 +33,25 @@#include <libfdt.h> +int xics_get_cpu_index_by_pir (XICSState *xics,int pir) +{ +int i; + +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +if (icp->cs) { +PowerPCCPU *cpu =POWERPC_CPU (icp->cs); +CPUPPCState *env = &cpu->env; + +if (env->spr_cb[SPR_PIR ].default_value == pir) { +return i; + } + } + } + +return -1 ; +} +static void xics_native_reset (void *opaque) {device_reset (DEVICE (opaque));include/hw/ppc/xics.h +1
-0@@ -214,6 +214,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers,/* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id (int cpu_dt_id); +int xics_get_cpu_index_by_pir (XICSState *xics,int pir);void icp_set_cppr (ICPState *icp,uint8_t cppr);void icp_set_mfrr (ICPState *icp,uint8_t mfrr);
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 v5 13/17] ppc/xics: add a xics_get_cpu_index_by_pir helper
Quoted 13 lines · David Gibson
Quoted 12 lines · Cédric Le Goater
Quoted 10 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
We will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
Signed-off-by Cédric Le Goater <[email protected]>Looks correct as far as it goes, but I wonder if this would be more generally useful as a machine level function that searches the cpu objects by PIR, returning a pointer. From that to the
cpu_indexis then trivial.
Quoted 6 lines
Quoted 3 lines
Well I guess so. The XICSState argument reduces the scope in case of multichip but as this routine is used to initialize the xive registers, it does not need to be fast.
Ahh.. I was thinking of the top-level xics object as global, rather than per-chip.
well, the ICP MMIO region address is linked to the chip but that is all for the moment.
Quoted 2 lines
Except.. does having it per-chip work anyway? The server numbers are globally unique, aren't they?
yes.
Quoted 2 lines
What happens if you put a server number from one chip as the target for an ICE on another chip?
we have the chip number, so we could route ? I haven't gone that far in the modeling though. It might be overly complex to do for the purpose.
Quoted 4 lines
The xics object is a bit weird, in that it doesn't represent a real device in a sense, but is rather something to co-ordinate global addressing between ICS and ICP units. Well, I suppose in that sense it represent the interrupt propagation fabric.
yes. See my other email. I think we can get rid of it and simply use a XICSState which links together the ICPs and the ICS of the system. but, let's keep it at the chip level for the moment, it is correct, and see if we need to move it upwards when we work on multichip.
Thanks,
C.
Quoted 63 lines
Quoted 62 lines
So you rather have, something like:
PowerPCCPU *ppc_get_vcpu_by_pir(int pir);similar to :
PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id);Thanks,
C.
Quoted 48 lines
Quoted 47 lines
--- hw/intc/xics_native.c | 19 +++++++++++++++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 20 insertions(+)hw/intc/xics_native.c +19
-0@@ -33,6 +33,25 @@#include <libfdt.h> +int xics_get_cpu_index_by_pir (XICSState *xics,int pir) +{ +int i; + +for (i =0 ; i < xics->nr_servers; i++) { +ICPState *icp = &xics->ss[i]; +if (icp->cs) { +PowerPCCPU *cpu =POWERPC_CPU (icp->cs); +CPUPPCState *env = &cpu->env; + +if (env->spr_cb[SPR_PIR ].default_value == pir) { +return i; + } + } + } + +return -1 ; +} +static void xics_native_reset (void *opaque) {device_reset (DEVICE (opaque));include/hw/ppc/xics.h +1
-0@@ -214,6 +214,7 @@ void xics_set_nr_servers(XICSState *xics, uint32_t nr_servers,/* Internal XICS interfaces */ int xics_get_cpu_index_by_dt_id (int cpu_dt_id); +int xics_get_cpu_index_by_pir (XICSState *xics,int pir);void icp_set_cppr (ICPState *icp,uint8_t cppr);void icp_set_mfrr (ICPState *icp,uint8_t mfrr);
Re: [Qemu-devel] [PATCH v5 13/17] ppc/xics: add a xics_get_cpu_index_by_pir helper
Quoted 27 lines · Cédric Le Goater
Quoted 13 lines · David Gibson
Quoted 12 lines · Cédric Le Goater
Quoted 10 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
We will need this helper to translate the server number of the XIVE (which is a PIR) into an ICPState index number (which is a cpu index).
Signed-off-by Cédric Le Goater <[email protected]>Looks correct as far as it goes, but I wonder if this would be more generally useful as a machine level function that searches the cpu objects by PIR, returning a pointer. From that to the
cpu_indexis then trivial.Quoted 6 lines
Quoted 3 lines
Well I guess so. The XICSState argument reduces the scope in case of multichip but as this routine is used to initialize the xive registers, it does not need to be fast.
Ahh.. I was thinking of the top-level xics object as global, rather than per-chip.
well, the ICP MMIO region address is linked to the chip but that is all for the moment.
Quoted 2 lines
Except.. does having it per-chip work anyway? The server numbers are globally unique, aren't they?
Quoted 7 lines
yes.
Quoted 2 lines
What happens if you put a server number from one chip as the target for an ICE on another chip?
we have the chip number, so we could route ? I haven't gone that far in the modeling though. It might be overly complex to do for the purpose.
Right.. yeah, trying to route between XICS objects sounds like a nightmare. Really the whole notion of the XICS overall object is that it represents the whole irq propagation fabric - so it knows about all the ICPS and all the ICSes and handles the routing between them.
So making the XICS object per-chip I think is a mistake which will just lead to pain down the track. See my other mail for a new suggestion on how to handle this.
Quoted 9 lines
Quoted 4 lines
The xics object is a bit weird, in that it doesn't represent a real device in a sense, but is rather something to co-ordinate global addressing between ICS and ICP units. Well, I suppose in that sense it represent the interrupt propagation fabric.
yes. See my other email. I think we can get rid of it and simply use a XICSState which links together the ICPs and the ICS of the system. but, let's keep it at the chip level for the moment, it is correct, and see if we need to move it upwards when we work on multichip.
No, I disagree. I think moving the XICs up a layer will only create pain later for little benefit now.
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
PATCH v5 14/17 ppc/xics: introduce a helper to insert a new ics
In reply to Cédric Le GoaterInterrupt Control Sources (ICS) are now maintained under a list.
--- hw/intc/xics.c | 6 ++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 7 insertions(+)
hw/intc/xics.c +6 -0
@@ -151,6 +151,12 @@ static void xics_common_reset(DeviceState *d) } } +void xics_insert_ics (XICSState *xics,ICSState *ics) +{ + ics->xics = xics; +QLIST_INSERT_HEAD (&xics->ics, ics, list); +} +static void xics_prop_get_nr_irqs (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
include/hw/ppc/xics.h +1 -0
@@ -228,6 +228,7 @@ void ics_simple_write_xive(ICSState *ics, int nr, int server,void ics_set_irq_type (ICSState *ics,int srcno,bool lsi);ICSState *xics_find_source (XICSState *icp,int irq); +void xics_insert_ics (XICSState *xics,ICSState *ics);typedef struct PnvChip PnvChip ;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 14/17] ppc/xics: introduce a helper to insert a new ics
Quoted 3 lines · Cédric Le Goater
Interrupt Control Sources (ICS) are now maintained under a list.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 34 lines
--- hw/intc/xics.c | 6 ++++++ include/hw/ppc/xics.h | 1 + 2 files changed, 7 insertions(+)hw/intc/xics.c +6
-0@@ -151,6 +151,12 @@ static void xics_common_reset(DeviceState *d) } } +void xics_insert_ics (XICSState *xics,ICSState *ics) +{ + ics->xics = xics; +QLIST_INSERT_HEAD (&xics->ics, ics, list); +} +static void xics_prop_get_nr_irqs (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {include/hw/ppc/xics.h +1
-0@@ -228,6 +228,7 @@ void ics_simple_write_xive(ICSState *ics, int nr, int server,void ics_set_irq_type (ICSState *ics,int srcno,bool lsi);ICSState *xics_find_source (XICSState *icp,int irq); +void xics_insert_ics (XICSState *xics,ICSState *ics);typedef struct PnvChip PnvChip ;
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
PATCH v5 15/17 ppc/pnv: Add cut down PSI bridge model and hookup external interrupt
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
The PSI (Processor Service Interface) is one of the engines of the "Bridge" unit which connects the different interfaces to the Power Processor.
This adds just enough of the PSI bridge to handle various on-chip and the one external interrupt. The rest of PSI has to do with the link to the IBM FSP service processor which we don't plan to emulate (not used on OpenPower machines).
[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model
- reworked set_xive ]
---
When skiboot initializes PSIHB, it fills the xives with server=0, prio=0xff, which is fine, but for some reason the last two xive settings reach the qemu MMIO region with a bogus value :
pnv_psi_mmio_write: MMIO write 0x30 val 0x000000ff00000000 pnv_psi_mmio_write: MMIO write 0x60 val 0x000000ff20000000 pnv_psi_mmio_write: MMIO write 0x68 val 0x000000ff40000000 pnv_psi_mmio_write: MMIO write 0x70 val 0x000000ff60000000 pnv_psi_mmio_write: MMIO write 0x78 val 0xffffffff80000000 pnv_psi_mmio_write: MMIO write 0x80 val 0xffffffffa0000000
It looks like a badly initialized temp variable in the call stack. The memory regions look fine, maybe in stdcix ? For the moment, I have added a logging error to catch non zero values as the guest should not do that in any case.
Changes since v4:
- used the helpers for the XSCOM region
- introduced pnv->cpld_irqstate to remove a static
- reworked pnv_psi_set_xivr() to use xics_get_cpu_index_by_pir(). This is similar to rtas_set_xive but skiboot does a first initialization with empty servers so we need to check for that case.
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 31 ++- hw/ppc/pnv_psi.c | 615 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 + include/hw/ppc/pnv_psi.h | 64 +++++ include/hw/ppc/pnv_xscom.h | 3 + 6 files changed, 715 insertions(+), 7 deletions(-) create mode 100644 hw/ppc/pnv_psi.c create mode 100644 include/hw/ppc/pnv_psi.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +25 -6
@@ -316,15 +316,22 @@ static void ppc_powernv_reset(void)* have a CPLD that will collect the SerIRQ and shoot them as a * single level interrupt to the P8 chip. So let's setup a hook * for doing just that. -* -* Note: The actual interrupt input isn't emulated yet, this will -* come with the PSI bridge model. */ static void pnv_lpc_isa_irq_handler_cpld (void *opaque,int n,int level) { -/* We don't yet emulate the PSI bridge which provides the external -* interrupt, so just drop interrupts on the floor -*/ +PnvMachineState *pnv =POWERNV_MACHINE (qdev_get_machine ()); +uint32_t old_state = pnv->cpld_irqstate; +PnvChip *chip = opaque; + +if (level) { + pnv->cpld_irqstate |=1u << n; + }else { + pnv->cpld_irqstate &= ~(1u << n); + } +if (pnv->cpld_irqstate != old_state) { +pnv_psi_irq_set (&chip->psi,PSIHB_IRQ_EXTERNAL , + pnv->cpld_irqstate !=0 ); + } }static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level)
@@ -644,6 +651,9 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->xics,sizeof (chip->xics),TYPE_XICS_NATIVE );object_property_add_child (obj,"xics" ,OBJECT (&chip->xics),NULL ); + +object_initialize (&chip->psi,sizeof (chip->psi),TYPE_PNV_PSI ); +object_property_add_child (obj,"psi" ,OBJECT (&chip->psi),NULL ); }static void pnv_chip_realize (DeviceState *dev,Error **errp)
@@ -728,6 +738,15 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) }g_free (typename); + +/* Processor Service Interface (PSI) Host Bridge */ +object_property_set_bool (OBJECT (&chip->psi), true,"realized" , + &error_fatal); +pnv_xscom_add_subregion (chip,PNV_XSCOM_PSI_BASE , &chip->psi.xscom_regs); + +/* link in the PSI ICS */ +xics_insert_ics (XICS_COMMON (&chip->xics), &chip->psi.ics); +/* Create LPC controller */ object_property_set_bool (OBJECT (&chip->lpc), true,"realized" , &error_fatal);
hw/ppc/pnv_psi.c new file +615 -0
615 lines not on this page · raw message
include/hw/ppc/pnv.h +7 -0
@@ -24,6 +24,7 @@#include "hw/ppc/pnv_xscom.h" #include "hw/ppc/pnv_lpc.h" #include "hw/ppc/xics.h" +#include "hw/ppc/pnv_psi.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -59,6 +60,7 @@ typedef struct PnvChip {PnvLpcController lpc;XICSNative xics; +PnvPsiController psi; } PnvChip; typedef struct PnvChipClass {
@@ -116,6 +118,7 @@ typedef struct PnvMachineState {PnvChip **chips;ISABus *isa_bus; +uint32_t cpld_irqstate; } PnvMachineState;#define PNV_FDT_ADDR 0x01000000
@@ -147,4 +150,8 @@ typedef struct PnvMachineState {#define PNV_XICS_BASE 0x0003ffff80000000ull#define PNV_XICS_SIZE 0x0000000000100000ull +#define PNV_PSIHB_BAR 0x0003fffe80000000ull +#define PNV_PSIHB_BAR_SIZE 0x0000000000100000ull + +#endif /* _PPC_PNV_H */
include/hw/ppc/pnv_psi.h new file +64 -0
64 lines not on this page · raw message
include/hw/ppc/pnv_xscom.h +3 -0
@@ -63,6 +63,9 @@ typedef struct PnvXScomInterfaceClass {#define PNV_XSCOM_LPC_BASE 0xb0020#define PNV_XSCOM_LPC_SIZE 0x4 +#define PNV_XSCOM_PSI_BASE 0x2010900 +#define PNV_XSCOM_PSI_SIZE 0x20 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 15/17] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt
Quoted 30 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
The PSI (Processor Service Interface) is one of the engines of the "Bridge" unit which connects the different interfaces to the Power Processor.
This adds just enough of the PSI bridge to handle various on-chip and the one external interrupt. The rest of PSI has to do with the link to the IBM FSP service processor which we don't plan to emulate (not used on OpenPower machines).
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model
- reworkedset_xive]Signed-off-by Cédric Le Goater <[email protected]>---
When skiboot initializes PSIHB, it fills the xives with server=0, prio=0xff, which is fine, but for some reason the last two xive settings reach the qemu MMIO region with a bogus value :
pnv_psi_mmio_write: MMIO write 0x30 val 0x000000ff00000000 pnv_psi_mmio_write: MMIO write 0x60 val 0x000000ff20000000 pnv_psi_mmio_write: MMIO write 0x68 val 0x000000ff40000000 pnv_psi_mmio_write: MMIO write 0x70 val 0x000000ff60000000 pnv_psi_mmio_write: MMIO write 0x78 val 0xffffffff80000000 pnv_psi_mmio_write: MMIO write 0x80 val 0xffffffffa0000000
Quoted 4 lines
It looks like a badly initialized temp variable in the call stack. The memory regions look fine, maybe in stdcix ? For the moment, I have added a logging error to catch non zero values as the guest should not do that in any case.
Just to clarify, I think you're saying that you believe this to be a skiboot (guest side) bug rather than a qemu bug. Is that right?
Quoted 196 lines
Changes since v4:
- used the helpers for the XSCOM region
- introducedpnv->cpld_irqstateto remove a static
- reworkedpnv_psi_set_xivr()to usexics_get_cpu_index_by_pir(). This is similar tortas_set_xivebut skiboot does a first initialization with empty servers so we need to check for that case.hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 31 ++- hw/ppc/pnv_psi.c | 615 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 + include/hw/ppc/pnv_psi.h | 64 +++++ include/hw/ppc/pnv_xscom.h | 3 + 6 files changed, 715 insertions(+), 7 deletions(-) create mode 100644 hw/ppc/pnv_psi.c create mode 100644 include/hw/ppc/pnv_psi.hhw/ppc/Makefile.objs +1
-1@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/pnv.c +25
-6@@ -316,15 +316,22 @@ static void ppc_powernv_reset(void)* have a CPLD that will collect the SerIRQ and shoot them as a * single level interrupt to the P8 chip. So let's setup a hook * for doing just that. -* -* Note: The actual interrupt input isn't emulated yet, this will -* come with the PSI bridge model. */ static void pnv_lpc_isa_irq_handler_cpld (void *opaque,int n,int level) { -/* We don't yet emulate the PSI bridge which provides the external -* interrupt, so just drop interrupts on the floor -*/ +PnvMachineState *pnv =POWERNV_MACHINE (qdev_get_machine ()); +uint32_t old_state = pnv->cpld_irqstate; +PnvChip *chip = opaque; + +if (level) { + pnv->cpld_irqstate |=1u << n; + }else { + pnv->cpld_irqstate &= ~(1u << n); + } +if (pnv->cpld_irqstate != old_state) { +pnv_psi_irq_set (&chip->psi,PSIHB_IRQ_EXTERNAL , + pnv->cpld_irqstate !=0 ); + } }static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level)@@ -644,6 +651,9 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->xics,sizeof (chip->xics),TYPE_XICS_NATIVE );object_property_add_child (obj,"xics" ,OBJECT (&chip->xics),NULL ); + +object_initialize (&chip->psi,sizeof (chip->psi),TYPE_PNV_PSI ); +object_property_add_child (obj,"psi" ,OBJECT (&chip->psi),NULL ); }static void pnv_chip_realize (DeviceState *dev,Error **errp)@@ -728,6 +738,15 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) }g_free (typename); + +/* Processor Service Interface (PSI) Host Bridge */ +object_property_set_bool (OBJECT (&chip->psi), true,"realized" , + &error_fatal); +pnv_xscom_add_subregion (chip,PNV_XSCOM_PSI_BASE , &chip->psi.xscom_regs); + +/* link in the PSI ICS */ +xics_insert_ics (XICS_COMMON (&chip->xics), &chip->psi.ics); +/* Create LPC controller */ object_property_set_bool (OBJECT (&chip->lpc), true,"realized" , &error_fatal);hw/ppc/pnv_psi.c new file +97
-0@@ -0,0 +1,615 @@ +/* +* QEMU PowerNV PowerPC PSI interface +* +* Copyright (c) 2016, IBM Corporation +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "hw/hw.h" +#include "target-ppc/cpu.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#include "exec/address-spaces.h" + +#include "hw/ppc/fdt.h" +#include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_psi.h" + +#include <libfdt.h> + +#define PSIHB_XSCOM_FIR_RW 0x00 +#define PSIHB_XSCOM_FIR_AND 0x01 +#define PSIHB_XSCOM_FIR_OR 0x02 +#define PSIHB_XSCOM_FIRMASK_RW 0x03 +#define PSIHB_XSCOM_FIRMASK_AND 0x04 +#define PSIHB_XSCOM_FIRMASK_OR 0x05 +#define PSIHB_XSCOM_FIRACT0 0x06 +#define PSIHB_XSCOM_FIRACT1 0x07 +#define PSIHB_XSCOM_BAR 0x0a +#define PSIHB_BAR_EN 0x0000000000000001ull +#define PSIHB_XSCOM_FSPBAR 0x0b +#define PSIHB_XSCOM_CR 0x0e +#define PSIHB_CR_FSP_CMD_ENABLE 0x8000000000000000ull +#define PSIHB_CR_FSP_MMIO_ENABLE 0x4000000000000000ull +#define PSIHB_CR_FSP_IRQ_ENABLE 0x1000000000000000ull +#define PSIHB_CR_FSP_ERR_RSP_ENABLE 0x0800000000000000ull +#define PSIHB_CR_PSI_LINK_ENABLE 0x0400000000000000ull +#define PSIHB_CR_FSP_RESET 0x0200000000000000ull +#define PSIHB_CR_PSIHB_RESET 0x0100000000000000ull +#define PSIHB_CR_PSI_IRQ 0x0000800000000000ull +#define PSIHB_CR_FSP_IRQ 0x0000400000000000ull +#define PSIHB_CR_FSP_LINK_ACTIVE 0x0000200000000000ull +/* and more ... */ +#define PSIHB_XSCOM_SEMR 0x0f +#define PSIHB_XSCOM_XIVR_PSI 0x10 +#define PSIHB_XIVR_SERVER_SH 40 +#define PSIHB_XIVR_SERVER_MSK (0xffffull << PSIHB_XIVR_SERVER_SH) +#define PSIHB_XIVR_PRIO_SH 32 +#define PSIHB_XIVR_PRIO_MSK (0xffull << PSIHB_XIVR_PRIO_SH) +#define PSIHB_XIVR_SRC_SH 29 +#define PSIHB_XIVR_SRC_MSK (0x7ull << PSIHB_XIVR_SRC_SH) +#define PSIHB_XIVR_PENDING 0x01000000ull +#define PSIHB_XSCOM_SCR 0x12 +#define PSIHB_XSCOM_CCR 0x13 +#define PSIHB_XSCOM_DMA_UPADD 0x14 +#define PSIHB_XSCOM_IRQ_STAT 0x15 +#define PSIHB_IRQ_STAT_OCC 0x0000001000000000ull +#define PSIHB_IRQ_STAT_FSI 0x0000000800000000ull +#define PSIHB_IRQ_STAT_LPCI2C 0x0000000400000000ull +#define PSIHB_IRQ_STAT_LOCERR 0x0000000200000000ull +#define PSIHB_IRQ_STAT_EXT 0x0000000100000000ull +#define PSIHB_XSCOM_XIVR_OCC 0x16 +#define PSIHB_XSCOM_XIVR_FSI 0x17 +#define PSIHB_XSCOM_XIVR_LPCI2C 0x18 +#define PSIHB_XSCOM_XIVR_LOCERR 0x19 +#define PSIHB_XSCOM_XIVR_EXT 0x1a +#define PSIHB_XSCOM_IRSN 0x1b +#define PSIHB_IRSN_COMP_SH 45 +#define PSIHB_IRSN_COMP_MSK (0x7ffffull << PSIHB_IRSN_COMP_SH) +#define PSIHB_IRSN_IRQ_MUX 0x0000000800000000ull +#define PSIHB_IRSN_IRQ_RESET 0x0000000400000000ull +#define PSIHB_IRSN_DOWNSTREAM_EN 0x0000000200000000ull +#define PSIHB_IRSN_UPSTREAM_EN 0x0000000100000000ull +#define PSIHB_IRSN_COMPMASK_SH 13 +#define PSIHB_IRSN_COMPMASK_MSK (0x7ffffull << PSIHB_IRSN_COMPMASK_SH) + +#define PSIHB_MMIO_BAR 0x00 +#define PSIHB_MMIO_FSPBAR 0x08 +#define PSIHB_MMIO_CR 0x20 +#define PSIHB_MMIO_SEMR 0x28 +#define PSIHB_MMIO_XIVR_PSI 0x30 +#define PSIHB_MMIO_SCR 0x40 +#define PSIHB_MMIO_CCR 0x48 +#define PSIHB_MMIO_DMA_UPADD 0x50
hw/ppc/pnv_psi.c line 107
Quoted 10 lines
hw/ppc/pnv_psi.c new file +10
-0+#define PSIHB_MMIO_IRQ_STAT 0x58 +#define PSIHB_MMIO_XIVR_OCC 0x60 +#define PSIHB_MMIO_XIVR_FSI 0x68 +#define PSIHB_MMIO_XIVR_LPCI2C 0x70 +#define PSIHB_MMIO_XIVR_LOCERR 0x78 +#define PSIHB_MMIO_XIVR_EXT 0x80 +#define PSIHB_MMIO_IRSN 0x88 +#define PSIHB_MMIO_MAX 0x100 + +static const uint32_t psi_mmio_to_xscom[PSIHB_MMIO_MAX /8 ] = {
AFAICT, this table lookup works out as:
xscom_addr = (mmio_addr / 8) + 0xa
Which makes an actual table seem like overkill.
And in fact, since you have a /8 here, and the *8 in the xscom address space encoding, I suspect you could just alias the same IO region into both SCOM and MMIO address spaces to avoid having two dispatchers.
Quoted 629 lines
hw/ppc/pnv_psi.c new file +508
-0+ [PSIHB_MMIO_BAR / 8] = PSIHB_XSCOM_BAR, + [PSIHB_MMIO_FSPBAR / 8] = PSIHB_XSCOM_FSPBAR, + [PSIHB_MMIO_CR / 8] = PSIHB_XSCOM_CR, + [PSIHB_MMIO_SCR / 8] = PSIHB_XSCOM_SCR, + [PSIHB_MMIO_CCR / 8] = PSIHB_XSCOM_CCR, + [PSIHB_MMIO_SEMR / 8] = PSIHB_XSCOM_SEMR, + [PSIHB_MMIO_XIVR_PSI / 8] = PSIHB_XSCOM_XIVR_PSI, + [PSIHB_MMIO_XIVR_OCC / 8] = PSIHB_XSCOM_XIVR_OCC, + [PSIHB_MMIO_XIVR_FSI / 8] = PSIHB_XSCOM_XIVR_FSI, + [PSIHB_MMIO_XIVR_LPCI2C / 8] = PSIHB_XSCOM_XIVR_LPCI2C, + [PSIHB_MMIO_XIVR_LOCERR / 8] = PSIHB_XSCOM_XIVR_LOCERR, + [PSIHB_MMIO_XIVR_EXT / 8] = PSIHB_XSCOM_XIVR_EXT, + [PSIHB_MMIO_IRQ_STAT / 8] = PSIHB_XSCOM_IRQ_STAT, + [PSIHB_MMIO_DMA_UPADD / 8] = PSIHB_XSCOM_DMA_UPADD, + [PSIHB_MMIO_IRSN / 8] = PSIHB_XSCOM_IRSN, +}; + +static void pnv_psi_set_bar (PnvPsiController *psi,uint64_t bar) +{ +MemoryRegion *sysmem =get_system_memory (); +uint64_t old = psi->regs[PSIHB_XSCOM_BAR ]; + + psi->regs[PSIHB_XSCOM_BAR ] = bar &0x0003fffffff00001 ; + +/* Update MR, always remove it first */ +if (old &PSIHB_BAR_EN ) { +memory_region_del_subregion (sysmem, &psi->regs_mr); + } +/* Then add it back if needed */ +if (bar &PSIHB_BAR_EN ) { +uint64_t addr = bar &0x0003fffffff00000 ; +memory_region_add_subregion (sysmem, addr, &psi->regs_mr); + } +} + +static void pnv_psi_update_fsp_mr (PnvPsiController *psi) +{ +/* XXX Update FSP MR if/when we support FSP BAR */ +} + +static void pnv_psi_set_cr (PnvPsiController *psi,uint64_t cr) +{ +uint64_t old = psi->regs[PSIHB_XSCOM_CR ]; + + psi->regs[PSIHB_XSCOM_CR ] = cr &0x0003ffff00000000 ; + +/* Check some bit changes */ +if ((old ^ psi->regs[PSIHB_XSCOM_CR ]) &PSIHB_CR_FSP_MMIO_ENABLE ) { +pnv_psi_update_fsp_mr (psi); + } +} + +static void pnv_psi_set_irsn (PnvPsiController *psi,uint64_t val) +{ +uint32_t offset; +ICSState *ics = &psi->ics; + +/* In this model we ignore the up/down enable bits for now +* as SW doesn't use them (other than setting them at boot). +* We ignore IRQ_MUX, its meaning isn't clear and we don't use +* it and finally we ignore reset (XXX fix that ?) +*/ + psi->regs[PSIHB_XSCOM_IRSN ] = val & (PSIHB_IRSN_COMP_MSK | +PSIHB_IRSN_IRQ_MUX | +PSIHB_IRSN_DOWNSTREAM_EN | +PSIHB_IRSN_DOWNSTREAM_EN | +PSIHB_IRSN_DOWNSTREAM_EN ); + +/* We ignore the compare mask as well, our ICS emulation is too +* simplistic to make any use if it, and we extract the offset +* from the compare value +*/ + offset = (val &PSIHB_IRSN_COMP_MSK ) >>PSIHB_IRSN_COMP_SH ; + ics->offset = offset; +} + +static bool pnv_psi_irq_bits (PnvPsiController *psi,PnvPsiIrq irq, +uint32_t *out_xivr_reg, +uint32_t *out_stat_reg, +uint64_t *out_stat_bit) +{ +switch (irq) { +case PSIHB_IRQ_PSI : + *out_xivr_reg =PSIHB_XSCOM_XIVR_PSI ; + *out_stat_reg =PSIHB_XSCOM_CR ; + *out_stat_bit =PSIHB_CR_PSI_IRQ ; +break ; +case PSIHB_IRQ_FSP : + *out_xivr_reg =PSIHB_XSCOM_XIVR_PSI ; + *out_stat_reg =PSIHB_XSCOM_CR ; + *out_stat_bit =PSIHB_CR_FSP_IRQ ; +break ; +case PSIHB_IRQ_OCC : + *out_xivr_reg =PSIHB_XSCOM_XIVR_OCC ; + *out_stat_reg =PSIHB_XSCOM_IRQ_STAT ; + *out_stat_bit =PSIHB_IRQ_STAT_OCC ; +break ; +case PSIHB_IRQ_FSI : + *out_xivr_reg =PSIHB_XSCOM_XIVR_FSI ; + *out_stat_reg =PSIHB_XSCOM_IRQ_STAT ; + *out_stat_bit =PSIHB_IRQ_STAT_FSI ; +break ; +case PSIHB_IRQ_LPC_I2C : + *out_xivr_reg =PSIHB_XSCOM_XIVR_LPCI2C ; + *out_stat_reg =PSIHB_XSCOM_IRQ_STAT ; + *out_stat_bit =PSIHB_IRQ_STAT_LPCI2C ; +break ; +case PSIHB_IRQ_LOCAL_ERR : + *out_xivr_reg =PSIHB_XSCOM_XIVR_LOCERR ; + *out_stat_reg =PSIHB_XSCOM_IRQ_STAT ; + *out_stat_bit =PSIHB_IRQ_STAT_LOCERR ; +break ; +case PSIHB_IRQ_EXTERNAL : + *out_xivr_reg =PSIHB_XSCOM_XIVR_EXT ; + *out_stat_reg =PSIHB_XSCOM_IRQ_STAT ; + *out_stat_bit =PSIHB_IRQ_STAT_EXT ; +break ; +default : +return false; + } +return true; +} + +void pnv_psi_irq_set (PnvPsiController *psi,PnvPsiIrq irq,bool state) +{ +ICSState *ics = &psi->ics; +uint32_t xivr_reg; +uint32_t stat_reg; +uint64_t stat_bit; +uint32_t src; +bool masked; + +if (!pnv_psi_irq_bits (psi, irq, &xivr_reg, &stat_reg, &stat_bit)) { +qemu_log_mask (LOG_GUEST_ERROR ,"PSI: Unsupported irq %d\n" , irq); +return ; + } + + src = (psi->regs[xivr_reg] &PSIHB_XIVR_SRC_MSK ) >>PSIHB_XIVR_SRC_SH ; + masked = (psi->regs[xivr_reg] &PSIHB_XIVR_PRIO_MSK ) ==PSIHB_XIVR_PRIO_MSK ; +if (state) { + psi->regs[stat_reg] |= stat_bit; +/* XXX optimization: check mask here. That means re-evaluating +* when unmasking, thus TODO +*/ +qemu_irq_raise (ics->qirqs[src]); + }else { + psi->regs[stat_reg] &= ~stat_bit; + +/* FSP and PSI are muxed so don't lower if either still set */ +if (stat_reg !=PSIHB_XSCOM_CR || + !(psi->regs[stat_reg] & (PSIHB_CR_PSI_IRQ |PSIHB_CR_FSP_IRQ ))) { +qemu_irq_lower (ics->qirqs[src]); + }else { + state = true; + } + } + +/* XXX Note about the emulation of the pending bit: This isn't +* entirely correct. The pending bit should be cleared when the +* EOI has been received. However, we don't have callbacks on +* EOI (especially not under KVM) so no way to emulate that +* properly, so instead we just set that bit as the logical +* "output" of the XIVR (ie pending & !masked) +* XXX TODO: Also update it on set_xivr +*/ +if (state && !masked) { + psi->regs[xivr_reg] |=PSIHB_XIVR_PENDING ; + }else { + psi->regs[xivr_reg] &= ~PSIHB_XIVR_PENDING ; + } +} + +static void pnv_psi_set_xivr (PnvPsiController *psi,uint32_t reg,uint64_t val) +{ +ICSState *ics = &psi->ics; +uint16_t server; +uint8_t prio; +uint8_t src; +int icp_index; + + psi->regs[reg] = (psi->regs[reg] &PSIHB_XIVR_PENDING ) | + (val & (PSIHB_XIVR_SERVER_MSK | +PSIHB_XIVR_PRIO_MSK | +PSIHB_XIVR_SRC_MSK )); + val = psi->regs[reg]; + server = (val &PSIHB_XIVR_SERVER_MSK ) >>PSIHB_XIVR_SERVER_SH ; + prio = (val &PSIHB_XIVR_PRIO_MSK ) >>PSIHB_XIVR_PRIO_SH ; + src = (val &PSIHB_XIVR_SRC_MSK ) >>PSIHB_XIVR_SRC_SH ; +if (src >PSIHB_IRQ_EXTERNAL ) { +/* XXX Generate error ? */ +return ; + } + +/* +* Linux fills the irq xivr with the hw processor id plus the +* link bits. shift back to get something valid. +*/ + server >>=2 ; + +/* +* When skiboot initializes PSIHB, it fills the xives with +* server=0, prio=0xff, but we don't have a CPU with a pir=0. So +* skip that case. +*/ +if (prio !=0xff ) { + icp_index =xics_get_cpu_index_by_pir (ics->xics, server); +assert (icp_index !=-1 ); + }else { +if (server) { +qemu_log_mask (LOG_GUEST_ERROR ,"PSI: bogus server %d for IRQ %d\n" , + server, src); + } + icp_index = server; + } + +/* Now because of source remapping, weird things can happen +* if you change the source number dynamically, our simple ICS +* doesn't deal with remapping. So we just poke a different +* ICS entry based on what source number was written. This will +* do for now but a more accurate implementation would instead +* use a fixed server/prio and a remapper of the generated irq. +*/ +ics_simple_write_xive (ics, src, icp_index, prio, prio); +} + +static bool pnv_psi_reg_read (PnvPsiController *psi,uint32_t offset, +uint64_t *out_val,bool mmio) +{ +switch (offset) { +case PSIHB_XSCOM_FIR_RW : +case PSIHB_XSCOM_FIRACT0 : +case PSIHB_XSCOM_FIRACT1 : +case PSIHB_XSCOM_BAR : +case PSIHB_XSCOM_FSPBAR : +case PSIHB_XSCOM_CR : +case PSIHB_XSCOM_XIVR_PSI : +case PSIHB_XSCOM_XIVR_OCC : +case PSIHB_XSCOM_XIVR_FSI : +case PSIHB_XSCOM_XIVR_LPCI2C : +case PSIHB_XSCOM_XIVR_LOCERR : +case PSIHB_XSCOM_XIVR_EXT : +case PSIHB_XSCOM_IRQ_STAT : +case PSIHB_XSCOM_SEMR : +case PSIHB_XSCOM_DMA_UPADD : +case PSIHB_XSCOM_IRSN : + *out_val = psi->regs[offset]; +return true; + } +return false; +} + +static bool pnv_psi_reg_write (PnvPsiController *psi,uint32_t offset, +uint64_t val,bool mmio) +{ +switch (offset) { +case PSIHB_XSCOM_FIR_RW : +case PSIHB_XSCOM_FIRACT0 : +case PSIHB_XSCOM_FIRACT1 : +case PSIHB_XSCOM_SEMR : +case PSIHB_XSCOM_DMA_UPADD : + psi->regs[offset] = val; +return true; +case PSIHB_XSCOM_FIR_OR : + psi->regs[PSIHB_XSCOM_FIR_RW ] |= val; +return true; +case PSIHB_XSCOM_FIR_AND : + psi->regs[PSIHB_XSCOM_FIR_RW ] &= val; +return true; +case PSIHB_XSCOM_BAR : +/* Only XSCOM can write this one */ +if (!mmio) { +pnv_psi_set_bar (psi, val); + } +return true; +case PSIHB_XSCOM_FSPBAR : + psi->regs[PSIHB_XSCOM_BAR ] = val &0x0003ffff00000000 ; +pnv_psi_update_fsp_mr (psi); +return true; +case PSIHB_XSCOM_CR : +pnv_psi_set_cr (psi, val); +return true; +case PSIHB_XSCOM_SCR : +pnv_psi_set_cr (psi, psi->regs[PSIHB_XSCOM_CR ] | val); +return true; +case PSIHB_XSCOM_CCR : +pnv_psi_set_cr (psi, psi->regs[PSIHB_XSCOM_CR ] & ~val); +return true; +case PSIHB_XSCOM_XIVR_PSI : +case PSIHB_XSCOM_XIVR_OCC : +case PSIHB_XSCOM_XIVR_FSI : +case PSIHB_XSCOM_XIVR_LPCI2C : +case PSIHB_XSCOM_XIVR_LOCERR : +case PSIHB_XSCOM_XIVR_EXT : +pnv_psi_set_xivr (psi, offset, val); +return true; +case PSIHB_XSCOM_IRQ_STAT : +/* Read only, should we generate an error ? */ +return true; +case PSIHB_XSCOM_IRSN : +pnv_psi_set_irsn (psi, val); +return true; + } +return false; +} + +static uint64_t pnv_psi_mmio_read (void *opaque,hwaddr addr,unsigned size) +{ +PnvPsiController *psi = opaque; +uint32_t xscom_off; +uint64_t val; + +if (size !=8 ) { + goto fail; + } + + addr &= (PNV_PSIHB_BAR_SIZE -1 ); + +if (addr >=PSIHB_MMIO_MAX ) { + goto fail; + } + xscom_off = psi_mmio_to_xscom[addr /8 ]; +if (xscom_off ==0 ) { + goto fail; + } +if (pnv_psi_reg_read (psi, xscom_off, &val, true)) { +return val; + } + fail: +return 0xffffffffffffffffull ; +} + +static void pnv_psi_mmio_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +PnvPsiController *psi = opaque; +uint32_t xscom_off; + +if (size !=8 ) { +return ; + } + + addr &= (PNV_PSIHB_BAR_SIZE -1 ); + +if (addr >=PSIHB_MMIO_MAX ) { +return ; + } + xscom_off = psi_mmio_to_xscom[addr /8 ]; +if (xscom_off ==0 ) { +return ; + } +pnv_psi_reg_write (psi, xscom_off, val, true); +} + +static const MemoryRegionOps psi_mmio_ops = { + .read = pnv_psi_mmio_read, + .write = pnv_psi_mmio_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +static uint64_t pnv_psi_xscom_read (void *opaque,hwaddr addr,unsigned size) +{ +PnvPsiController *psi =PNV_PSI (opaque); +uint32_t offset = addr >>3 ; +uint64_t val =0 ; + +pnv_psi_reg_read (psi, offset, &val, false); + +return val; +} + +static void pnv_psi_xscom_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +PnvPsiController *psi =PNV_PSI (opaque); +uint32_t offset = addr >>3 ; + +pnv_psi_reg_write (psi, offset, val, false); +} + +static const MemoryRegionOps pnv_psi_xscom_ops = { + .read = pnv_psi_xscom_read, + .write = pnv_psi_xscom_write, + .valid.min_access_size =8 , + .valid.max_access_size =8 , + .impl.min_access_size =8 , + .impl.max_access_size =8 , + .endianness =DEVICE_BIG_ENDIAN , +}; + + +static void pnv_psi_init (Object *obj) +{ +PnvPsiController *psi =PNV_PSI (obj); + +object_initialize (&psi->ics,sizeof (psi->ics),TYPE_ICS_SIMPLE ); +object_property_add_child (obj,"ics-psi" ,OBJECT (&psi->ics),NULL ); +} + +static void pnv_psi_realize (DeviceState *dev,Error **errp) +{ +PnvPsiController *psi =PNV_PSI (dev); +ICSState *ics = &psi->ics; +Error *error =NULL ; +unsigned int i; + +/* Initialize MMIO region */ +memory_region_init_io (&psi->regs_mr,OBJECT (dev), &psi_mmio_ops, psi, +"psihb" ,PNV_PSIHB_BAR_SIZE ); + +/* Default BAR. Use object properties ? */ +pnv_psi_set_bar (psi,PNV_PSIHB_BAR |PSIHB_BAR_EN ); + +/* Default sources in XIVR */ + psi->regs[PSIHB_XSCOM_XIVR_PSI ] =PSIHB_XIVR_PRIO_MSK | + (0ull <<PSIHB_XIVR_SRC_SH ); + psi->regs[PSIHB_XSCOM_XIVR_OCC ] =PSIHB_XIVR_PRIO_MSK | + (1ull <<PSIHB_XIVR_SRC_SH ); + psi->regs[PSIHB_XSCOM_XIVR_FSI ] =PSIHB_XIVR_PRIO_MSK | + (2ull <<PSIHB_XIVR_SRC_SH ); + psi->regs[PSIHB_XSCOM_XIVR_LPCI2C ] =PSIHB_XIVR_PRIO_MSK | + (3ull <<PSIHB_XIVR_SRC_SH ); + psi->regs[PSIHB_XSCOM_XIVR_LOCERR ] =PSIHB_XIVR_PRIO_MSK | + (4ull <<PSIHB_XIVR_SRC_SH ); + psi->regs[PSIHB_XSCOM_XIVR_EXT ] =PSIHB_XIVR_PRIO_MSK | + (5ull <<PSIHB_XIVR_SRC_SH ); + +/* +* PSI interrupt control source +* FIXME: nr_irqs should a property +*/ + ics->nr_irqs =PSI_NUM_INTERRUPTS ; +object_property_set_bool (OBJECT (ics), true,"realized" , &error); +if (error) { +error_propagate (errp, error); +return ; + } + +for (i =0 ; i < ics->nr_irqs; i++) { +ics_set_irq_type (ics, i, true); + } + +/* XScom region for PSI registers */ +pnv_xscom_region_init (&psi->xscom_regs,OBJECT (dev), &pnv_psi_xscom_ops, + psi,"xscom-psi" ,PNV_XSCOM_PSI_SIZE ); +} + +static int pnv_psi_populate (PnvXScomInterface *dev,void *fdt,int xscom_offset) +{ +const char compat[] ="ibm,power8-psihb-x\0ibm,psihb-x" ; +char *name; +int offset; +uint32_t lpc_pcba =PNV_XSCOM_PSI_BASE ; +uint32_t reg[] = { +cpu_to_be32 (lpc_pcba), +cpu_to_be32 (PNV_XSCOM_PSI_SIZE ) + }; + + name =g_strdup_printf ("psihb@%x" , lpc_pcba); + offset =fdt_add_subnode (fdt, xscom_offset, name); +_FDT (offset); +g_free (name); + +_FDT ((fdt_setprop (fdt, offset,"reg" , reg,sizeof (reg)))); + +_FDT ((fdt_setprop_cell (fdt, offset,"#address-cells" ,2 ))); +_FDT ((fdt_setprop_cell (fdt, offset,"#size-cells" ,1 ))); +_FDT ((fdt_setprop (fdt, offset,"compatible" , compat, +sizeof (compat)))); +return 0 ; +} + + +static void pnv_psi_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvXScomInterfaceClass *xdc =PNV_XSCOM_INTERFACE_CLASS (klass); + + xdc->populate = pnv_psi_populate; + + dc->realize = pnv_psi_realize; +} + +static const TypeInfo pnv_psi_info = { + .name =TYPE_PNV_PSI , + .parent =TYPE_DEVICE , + .instance_size =sizeof (PnvPsiController), + .instance_init = pnv_psi_init, + .class_init = pnv_psi_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PNV_XSCOM_INTERFACE }, + { } + } +}; + +static void pnv_psi_register_types (void ) +{ +type_register_static (&pnv_psi_info); +} + +type_init (pnv_psi_register_types)include/hw/ppc/pnv.h +7
-0@@ -24,6 +24,7 @@#include "hw/ppc/pnv_xscom.h" #include "hw/ppc/pnv_lpc.h" #include "hw/ppc/xics.h" +#include "hw/ppc/pnv_psi.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)@@ -59,6 +60,7 @@ typedef struct PnvChip {PnvLpcController lpc;XICSNative xics; +PnvPsiController psi; } PnvChip; typedef struct PnvChipClass {@@ -116,6 +118,7 @@ typedef struct PnvMachineState {PnvChip **chips;ISABus *isa_bus; +uint32_t cpld_irqstate; } PnvMachineState;#define PNV_FDT_ADDR 0x01000000@@ -147,4 +150,8 @@ typedef struct PnvMachineState {#define PNV_XICS_BASE 0x0003ffff80000000ull#define PNV_XICS_SIZE 0x0000000000100000ull +#define PNV_PSIHB_BAR 0x0003fffe80000000ull +#define PNV_PSIHB_BAR_SIZE 0x0000000000100000ull + +#endif /* _PPC_PNV_H */ include/hw/ppc/pnv_psi.h new file +64
-0@@ -0,0 +1,64 @@ +/* +* QEMU PowerPC PowerNV PSI controller +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _PPC_PNV_PSI_H +#define _PPC_PNV_PSI_H + +#include "hw/ppc/pnv_xscom.h" +#include "hw/ppc/pnv_psi.h" + +#define TYPE_PNV_PSI "pnv-psi" +#define PNV_PSI (obj) \ + OBJECT_CHECK(PnvPsiController, (obj), TYPE_PNV_PSI) + +#define PSIHB_XSCOM_MAX 0x20 + +typedef struct XICSState XICSState ; + +typedef struct PnvPsiController { +DeviceState parent; + +MemoryRegion regs_mr; + +/* FSP region not supported */ +/* MemoryRegion fsp_mr; */ + +/* Interrupt generation */ +ICSState ics; + +/* Registers */ +uint64_t regs[PSIHB_XSCOM_MAX ]; + +MemoryRegion xscom_regs; +}PnvPsiController ; + +typedef enum PnvPsiIrq { +PSIHB_IRQ_PSI ,/* internal use only */ +PSIHB_IRQ_FSP ,/* internal use only */ +PSIHB_IRQ_OCC , +PSIHB_IRQ_FSI , +PSIHB_IRQ_LPC_I2C , +PSIHB_IRQ_LOCAL_ERR , +PSIHB_IRQ_EXTERNAL , +}PnvPsiIrq ; + +#define PSI_NUM_INTERRUPTS 6 + +extern void pnv_psi_irq_set (PnvPsiController *psi,PnvPsiIrq irq,bool state); + +#endif /* _PPC_PNV_PSI_H */ include/hw/ppc/pnv_xscom.h +3
-0@@ -63,6 +63,9 @@ typedef struct PnvXScomInterfaceClass {#define PNV_XSCOM_LPC_BASE 0xb0020#define PNV_XSCOM_LPC_SIZE 0x4 +#define PNV_XSCOM_PSI_BASE 0x2010900 +#define PNV_XSCOM_PSI_SIZE 0x20 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 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 v5 15/17] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt
Quoted 31 lines · David Gibson
Quoted 30 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
The PSI (Processor Service Interface) is one of the engines of the "Bridge" unit which connects the different interfaces to the Power Processor.
This adds just enough of the PSI bridge to handle various on-chip and the one external interrupt. The rest of PSI has to do with the link to the IBM FSP service processor which we don't plan to emulate (not used on OpenPower machines).
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model
- reworkedset_xive]Signed-off-by Cédric Le Goater <[email protected]>---
When skiboot initializes PSIHB, it fills the xives with server=0, prio=0xff, which is fine, but for some reason the last two xive settings reach the qemu MMIO region with a bogus value :
pnv_psi_mmio_write: MMIO write 0x30 val 0x000000ff00000000 pnv_psi_mmio_write: MMIO write 0x60 val 0x000000ff20000000 pnv_psi_mmio_write: MMIO write 0x68 val 0x000000ff40000000 pnv_psi_mmio_write: MMIO write 0x70 val 0x000000ff60000000 pnv_psi_mmio_write: MMIO write 0x78 val 0xffffffff80000000 pnv_psi_mmio_write: MMIO write 0x80 val 0xffffffffa0000000
Quoted 7 lines
Quoted 4 lines
It looks like a badly initialized temp variable in the call stack. The memory regions look fine, maybe in stdcix ? For the moment, I have added a logging error to catch non zero values as the guest should not do that in any case.
Just to clarify, I think you're saying that you believe this to be a skiboot (guest side) bug rather than a qemu bug. Is that right?
Yes. I just found why. The P8_IRQ_PSI_* values in skiboot need to be unsigned because they are shifted left of 29 bits :
... #define P8_IRQ_PSI_LOCAL_ERR 4 #define P8_IRQ_PSI_EXTERNAL 5 /* Used for UART */ ... out_be64(psi->regs + PSIHB_XIVR_LOCAL_ERR, (0xffull << 32) | (P8_IRQ_PSI_LOCAL_ERR << 29)); out_be64(psi->regs + PSIHB_XIVR_HOST_ERR, (0xffull << 32) | (P8_IRQ_PSI_EXTERNAL << 29));
I will send a skiboot patch but we need to keep the code as it is.
Thanks
C.
Re: [Qemu-devel] [PATCH v5 15/17] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt
Quoted 53 lines · Cédric Le Goater
Quoted 31 lines · David Gibson
Quoted 30 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
The PSI (Processor Service Interface) is one of the engines of the "Bridge" unit which connects the different interfaces to the Power Processor.
This adds just enough of the PSI bridge to handle various on-chip and the one external interrupt. The rest of PSI has to do with the link to the IBM FSP service processor which we don't plan to emulate (not used on OpenPower machines).
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model
- reworkedset_xive]Signed-off-by Cédric Le Goater <[email protected]>---
When skiboot initializes PSIHB, it fills the xives with server=0, prio=0xff, which is fine, but for some reason the last two xive settings reach the qemu MMIO region with a bogus value :
pnv_psi_mmio_write: MMIO write 0x30 val 0x000000ff00000000 pnv_psi_mmio_write: MMIO write 0x60 val 0x000000ff20000000 pnv_psi_mmio_write: MMIO write 0x68 val 0x000000ff40000000 pnv_psi_mmio_write: MMIO write 0x70 val 0x000000ff60000000 pnv_psi_mmio_write: MMIO write 0x78 val 0xffffffff80000000 pnv_psi_mmio_write: MMIO write 0x80 val 0xffffffffa0000000Quoted 7 lines
Quoted 4 lines
It looks like a badly initialized temp variable in the call stack. The memory regions look fine, maybe in stdcix ? For the moment, I have added a logging error to catch non zero values as the guest should not do that in any case.
Just to clarify, I think you're saying that you believe this to be a skiboot (guest side) bug rather than a qemu bug. Is that right?
Yes. I just found why. The P8_IRQ_PSI_* values in skiboot need to be unsigned because they are shifted left of 29 bits :
... #define P8_IRQ_PSI_LOCAL_ERR 4 #define P8_IRQ_PSI_EXTERNAL 5 /* Used for UART */ ... out_be64(psi->regs + PSIHB_XIVR_LOCAL_ERR, (0xffull << 32) | (P8_IRQ_PSI_LOCAL_ERR << 29)); out_be64(psi->regs + PSIHB_XIVR_HOST_ERR, (0xffull << 32) | (P8_IRQ_PSI_EXTERNAL << 29));
Quoted 1 line
I will send a skiboot patch but we need to keep the code as it is.
Sure. Seems like the hardware ignores those high bits, so we probably should too.
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 v5 15/17] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt
In reply to David GibsonQuoted 21 lines
Quoted 9 lines
hw/ppc/pnv_psi.c new file +8
-0+#define PSIHB_MMIO_BAR 0x00 +#define PSIHB_MMIO_FSPBAR 0x08 +#define PSIHB_MMIO_CR 0x20 +#define PSIHB_MMIO_SEMR 0x28 +#define PSIHB_MMIO_XIVR_PSI 0x30 +#define PSIHB_MMIO_SCR 0x40 +#define PSIHB_MMIO_CCR 0x48 +#define PSIHB_MMIO_DMA_UPADD 0x50hw/ppc/pnv_psi.c line 107
Quoted 10 lines
hw/ppc/pnv_psi.c new file +10
-0+#define PSIHB_MMIO_IRQ_STAT 0x58 +#define PSIHB_MMIO_XIVR_OCC 0x60 +#define PSIHB_MMIO_XIVR_FSI 0x68 +#define PSIHB_MMIO_XIVR_LPCI2C 0x70 +#define PSIHB_MMIO_XIVR_LOCERR 0x78 +#define PSIHB_MMIO_XIVR_EXT 0x80 +#define PSIHB_MMIO_IRSN 0x88 +#define PSIHB_MMIO_MAX 0x100 + +static const uint32_t psi_mmio_to_xscom[PSIHB_MMIO_MAX /8 ] = {AFAICT, this table lookup works out as:
Quoted 8 lines
xscom_addr = (mmio_addr / 8) + 0xaWhich makes an actual table seem like overkill.
And in fact, since you have a /8 here, and the *8 in the xscom address space encoding, I suspect you could just alias the same IO region into both SCOM and MMIO address spaces to avoid having two dispatchers.
yes. I think this is possible. I will work on it.
Thanks,
C.
PATCH v5 16/17 ppc/pnv: Add OCC model stub with interrupt support
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
The OCC is an on-chip microcontroller based on a ppc405 core used for various power management tasks. It comes with a pile of additional hardware sitting on the PIB (aka XSCOM bus). At this point we don't emulate it (nor plan to do so). However there is one facility which is provided by the surrounding hardware that we do need, which is the interrupt generation facility. OPAL uses it to send itself interrupts under some circumstances and there are other uses around the corner.
So this implement just enough to support this.
[clg: - updated for qemu-2.7
- changed the XSCOM interface to fit new model
- QOMified the model ]
---
Changes since v4:
- used the helpers for the XSCOM region
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 10 ++++ hw/ppc/pnv_occ.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_occ.h | 38 +++++++++++++ include/hw/ppc/pnv_xscom.h | 3 + 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_occ.c create mode 100644 include/hw/ppc/pnv_occ.h
hw/ppc/Makefile.objs +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o # IBM PowerNV -obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +10 -0
@@ -654,6 +654,11 @@ static void pnv_chip_init(Object *obj)object_initialize (&chip->psi,sizeof (chip->psi),TYPE_PNV_PSI );object_property_add_child (obj,"psi" ,OBJECT (&chip->psi),NULL ); + +object_initialize (&chip->occ,sizeof (chip->occ),TYPE_PNV_OCC ); +object_property_add_child (obj,"occ" ,OBJECT (&chip->occ),NULL ); +object_property_add_const_link (OBJECT (&chip->occ),"psi" , +OBJECT (&chip->psi), &error_abort); }static void pnv_chip_realize (DeviceState *dev,Error **errp)
@@ -751,6 +756,11 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)object_property_set_bool (OBJECT (&chip->lpc), true,"realized" , &error_fatal);pnv_xscom_add_subregion (chip,PNV_XSCOM_LPC_BASE , &chip->lpc.xscom_regs); + +/* Create the simplified OCC model */ +object_property_set_bool (OBJECT (&chip->occ), true,"realized" , + &error_fatal); +pnv_xscom_add_subregion (chip,PNV_XSCOM_OCC_BASE , &chip->occ.xscom_regs); }static Property pnv_chip_properties[] = {
hw/ppc/pnv_occ.c new file +135 -0
135 lines not on this page · raw message
include/hw/ppc/pnv.h +2 -0
@@ -25,6 +25,7 @@#include "hw/ppc/pnv_lpc.h" #include "hw/ppc/xics.h" #include "hw/ppc/pnv_psi.h" +#include "hw/ppc/pnv_occ.h" #define TYPE_PNV_CHIP "powernv-chip"#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
@@ -61,6 +62,7 @@ typedef struct PnvChip {PnvLpcController lpc;XICSNative xics;PnvPsiController psi; +PnvOCC occ; } PnvChip; typedef struct PnvChipClass {
include/hw/ppc/pnv_occ.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* QEMU PowerNV Emulation of a few OCC related registers +* +* Copyright (c) 2016, IBM Corporation. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _PPC_PNV_OCC_H +#define _PPC_PNV_OCC_H + +#define TYPE_PNV_OCC "pnv-occ" +#define PNV_OCC (obj) OBJECT_CHECK(PnvOCC, (obj), TYPE_PNV_OCC) + +typedef struct PnvPsiController PnvPsiController ; + +typedef struct PnvOCC { +DeviceState xd; + +/* OCC Misc interrupt */ +uint64_t occmisc; + +PnvPsiController *psi; + +MemoryRegion xscom_regs; +}PnvOCC ; + +#endif /* _PPC_PNV_OCC_H */
include/hw/ppc/pnv_xscom.h +3 -0
@@ -66,6 +66,9 @@ typedef struct PnvXScomInterfaceClass {#define PNV_XSCOM_PSI_BASE 0x2010900#define PNV_XSCOM_PSI_SIZE 0x20 +#define PNV_XSCOM_OCC_BASE 0x0066000 +#define PNV_XSCOM_OCC_SIZE 0x6000 +extern void pnv_xscom_realize (PnvChip *chip,Error **errp);extern int pnv_xscom_populate (PnvChip *chip,void *fdt,int offset);
Signature · 1 line
2.7.4
PATCH v5 17/17 ppc/pnv: Add Naples chip support for LPC interrupts
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
It adds the Naples chip which supports proper LPC interrupts via the LPC controller rather than via an external CPLD.
[clg: - updated for qemu-2.7
- ported on latest PowerNV patchset (v3) ]
---
Changes since v4:
- remove test on ISA_NUM_IRQS
hw/ppc/pnv.c | 15 ++++++++++++++- hw/ppc/pnv_lpc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/pnv_lpc.h | 9 +++++++++ 3 files changed, 68 insertions(+), 3 deletions(-)
hw/ppc/pnv.c +14 -1
@@ -336,7 +336,14 @@ static void pnv_lpc_isa_irq_handler_cpld(void *opaque, int n, int level)static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level) { -/* XXX TODO */ +PnvChip *chip = opaque; +PnvLpcController *lpc = &chip->lpc; + +/* The Naples HW latches the 1 levels, clearing is done by SW */ +if (level) { + lpc->lpc_hc_irqstat |=LPC_HC_IRQ_SERIRQ0 >> n; +pnv_lpc_eval_irqs (lpc); + } }static ISABus *pnv_isa_create (PnvChip *chip)
@@ -659,6 +666,12 @@ static void pnv_chip_init(Object *obj)object_property_add_child (obj,"occ" ,OBJECT (&chip->occ),NULL );object_property_add_const_link (OBJECT (&chip->occ),"psi" ,OBJECT (&chip->psi), &error_abort); + +/* +* The LPC controller needs PSI to generate interrupts +*/ +object_property_add_const_link (OBJECT (&chip->lpc),"psi" , +OBJECT (&chip->psi), &error_abort); }static void pnv_chip_realize (DeviceState *dev,Error **errp)
hw/ppc/pnv_lpc.c +45 -2
89 lines not on this page · raw message
include/hw/ppc/pnv_lpc.h +9 -0
@@ -23,6 +23,8 @@#define PNV_LPC (obj) \ OBJECT_CHECK(PnvLpcController, (obj), TYPE_PNV_LPC) +typedef struct PnvPsiController PnvPsiController ; + typedef struct PnvLpcController { DeviceState parent;
@@ -62,6 +64,13 @@ typedef struct PnvLpcController {/* XSCOM registers */ MemoryRegion xscom_regs; + +/* PSI to generate interrupts */ + PnvPsiController *psi; } PnvLpcController; +#define LPC_HC_IRQ_SERIRQ0 0x80000000/* all bits down to ... */ + +void pnv_lpc_eval_irqs (PnvLpcController *lpc); +#endif /* _PPC_PNV_LPC_H */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v5 17/17] ppc/pnv: Add Naples chip support for LPC interrupts
Quoted 9 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
It adds the Naples chip which supports proper LPC interrupts via the LPC controller rather than via an external CPLD.
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: - updated for qemu-2.7
- ported on latest PowerNV patchset (v3) ]Signed-off-by Cédric Le Goater <[email protected]>
Quoted 169 lines
---
Changes since v4:
- remove test on
ISA_NUM_IRQShw/ppc/pnv.c | 15 ++++++++++++++- hw/ppc/pnv_lpc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- include/hw/ppc/pnv_lpc.h | 9 +++++++++ 3 files changed, 68 insertions(+), 3 deletions(-)hw/ppc/pnv.c +14
-1@@ -336,7 +336,14 @@ static void pnv_lpc_isa_irq_handler_cpld(void *opaque, int n, int level)static void pnv_lpc_isa_irq_handler (void *opaque,int n,int level) { -/* XXX TODO */ +PnvChip *chip = opaque; +PnvLpcController *lpc = &chip->lpc; + +/* The Naples HW latches the 1 levels, clearing is done by SW */ +if (level) { + lpc->lpc_hc_irqstat |=LPC_HC_IRQ_SERIRQ0 >> n; +pnv_lpc_eval_irqs (lpc); + } }static ISABus *pnv_isa_create (PnvChip *chip)@@ -659,6 +666,12 @@ static void pnv_chip_init(Object *obj)object_property_add_child (obj,"occ" ,OBJECT (&chip->occ),NULL );object_property_add_const_link (OBJECT (&chip->occ),"psi" ,OBJECT (&chip->psi), &error_abort); + +/* +* The LPC controller needs PSI to generate interrupts +*/ +object_property_add_const_link (OBJECT (&chip->lpc),"psi" , +OBJECT (&chip->psi), &error_abort); }static void pnv_chip_realize (DeviceState *dev,Error **errp)hw/ppc/pnv_lpc.c +45
-2@@ -249,6 +249,34 @@ static const MemoryRegionOps pnv_lpc_xscom_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +void pnv_lpc_eval_irqs (PnvLpcController *lpc) +{ +bool lpc_to_opb_irq = false; + +/* Update LPC controller to OPB line */ +if (lpc->lpc_hc_irqser_ctrl &LPC_HC_IRQSER_EN ) { +uint32_t irqs; + + irqs = lpc->lpc_hc_irqstat & lpc->lpc_hc_irqmask; + lpc_to_opb_irq = (irqs !=0 ); + } + +/* We don't honor the polarity register, it's pointless and unused +* anyway +*/ +if (lpc_to_opb_irq) { + lpc->opb_irq_input |=OPB_MASTER_IRQ_LPC ; + }else { + lpc->opb_irq_input &= ~OPB_MASTER_IRQ_LPC ; + } + +/* Update OPB internal latch */ + lpc->opb_irq_stat |= lpc->opb_irq_input & lpc->opb_irq_mask; + +/* Reflect the interrupt */ +pnv_psi_irq_set (lpc->psi,PSIHB_IRQ_LPC_I2C , lpc->opb_irq_stat !=0 ); +} +static uint64_t lpc_hc_read (void *opaque,hwaddr addr,unsigned size) {PnvLpcController *lpc = opaque;@@ -299,12 +327,15 @@ static void lpc_hc_write(void *opaque, hwaddr addr, uint64_t val,break ;case LPC_HC_IRQSER_CTRL : lpc->lpc_hc_irqser_ctrl = val; +pnv_lpc_eval_irqs (lpc);break ;case LPC_HC_IRQMASK : lpc->lpc_hc_irqmask = val; +pnv_lpc_eval_irqs (lpc);break ;case LPC_HC_IRQSTAT : lpc->lpc_hc_irqstat &= ~val; +pnv_lpc_eval_irqs (lpc);break ;case LPC_HC_ERROR_ADDRESS :break ;@@ -362,14 +393,15 @@ static void opb_master_write(void *opaque, hwaddr addr,switch (addr) {case OPB_MASTER_LS_IRQ_STAT : lpc->opb_irq_stat &= ~val; +pnv_lpc_eval_irqs (lpc);break ;case OPB_MASTER_LS_IRQ_MASK : -/* XXX Filter out reserved bits */ lpc->opb_irq_mask = val; +pnv_lpc_eval_irqs (lpc);break ;case OPB_MASTER_LS_IRQ_POL : -/* XXX Filter out reserved bits */ lpc->opb_irq_pol = val; +pnv_lpc_eval_irqs (lpc);break ;case OPB_MASTER_LS_IRQ_INPUT :/* Read only */ @@ -397,6 +429,8 @@ static const MemoryRegionOps opb_master_ops = {static void pnv_lpc_realize (DeviceState *dev,Error **errp) {PnvLpcController *lpc =PNV_LPC (dev); +Object *obj; +Error *error =NULL ;/* Reg inits */ lpc->lpc_hc_fw_rd_acc_size =LPC_HC_FW_RD_4B ;@@ -440,6 +474,15 @@ static void pnv_lpc_realize(DeviceState *dev, Error **errp)pnv_xscom_region_init (&lpc->xscom_regs,OBJECT (dev), &pnv_lpc_xscom_ops, lpc,"xscom-lpc" ,PNV_XSCOM_LPC_SIZE ); + +/* get PSI object from chip */ + obj =object_property_get_link (OBJECT (dev),"psi" , &error); +if (!obj) { +error_setg (errp,"%s: required link 'psi' not found: %s" , + __func__,error_get_pretty (error)); +return ; + } + lpc->psi =PNV_PSI (obj); }static void pnv_lpc_class_init (ObjectClass *klass,void *data)include/hw/ppc/pnv_lpc.h +9
-0@@ -23,6 +23,8 @@#define PNV_LPC (obj) \ OBJECT_CHECK(PnvLpcController, (obj), TYPE_PNV_LPC) +typedef struct PnvPsiController PnvPsiController ; + typedef struct PnvLpcController { DeviceState parent;@@ -62,6 +64,13 @@ typedef struct PnvLpcController {/* XSCOM registers */ MemoryRegion xscom_regs; + +/* PSI to generate interrupts */ + PnvPsiController *psi; } PnvLpcController; +#define LPC_HC_IRQ_SERIRQ0 0x80000000/* all bits down to ... */ + +void pnv_lpc_eval_irqs (PnvLpcController *lpc); +#endif /* _PPC_PNV_LPC_H */
Signature · 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
Quoted 31 lines · Cédric Le Goater
Hello,
Here is the latest version of the ppc/pnv platform patchset. PowerNV (as Non-Virtualized) is the "baremetal" platform using the OPAL firmware. It runs Linux on IBM and Open Power systems and it can be used as an hypervisor OS, to run KVM guests, or simply as a host OS. The goal here is to add support for the baremetal platform and possibly later also for the KVM PR guests but not for HV guests.
In v5, all the comments from v4 should have been addressed. Most of the differences are cleanups suggested by David but there a couple of important changes :
- an addition of a new firmware to qemu : skiboot 5.3.7.
- a rework of the native Interrupt Presentation Controller model which now uses memory subregions instead of a hash table.
- a removal of the Power9 LPC Controller. This is still in the plans but the models need a little more work.The initial patches provide a minimal platform with some RAM to load the ROMs : firmware, kernel and initrd. The device tree is built with what is available at reset time. Then, comes the PnvChip object acting as a container for other devices required to run a system. The cores are added to each chip with some restrictions on the number and the ids. Next is the XSCOM model, the sideband bus which gives controls to all the units in the POWER8 chip, the LPC controller for the console, the native interrupt controller and the PSI HB model to handle the external interrupt.
Quoted 6 lines
The next step should be IPMI support which adds a BT device on the ISA bus and some device tree extensions to read sensors and FRUs. This is relatively straight forward and most of the IPMI code has been discussed already on the list. Then should come a PHB3 model to include some PCI devices. This is big and it needs a few helpers in the PCI core.
I've merged 1-6 into ppc-for-2.8. The rest I'm still reviewing.
Quoted 80 lines
If you feel adventurous, you can grab kernel and rootfs images :
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/zImage.epapr
https://openpower.xyz/job/openpower-op-build/distro=ubuntu,target=palmetto/lastSuccessfulBuild/artifact/images/rootfs.cpio.xzand give it a try. The full patchset is available here :
https://github.com/legoater/qemu/commits/powernv-ipmi-2.8
This is a wip branch, which I stabilize when the qemu version, on which it is based, is released.
Thanks,
C.
Benjamin Herrenschmidt (5):
ppc/pnv: add skeleton PowerNV platform
ppc/pnv: add a LPC controller
ppc/pnv: Add cut down PSI bridge model and hookup external interrupt ppc/pnv: Add OCC model stub with interrupt support ppc/pnv: Add Naples chip support for LPC interruptsCédric Le Goater (12):
ppc: add skiboot firmware for the pnv platform ppc/pnv: add a PnvChip object
ppc/pnv: add a core mask to PnvChip ppc/pnv: add a PIR handler to PnvChip ppc/pnv: add a PnvCore object
ppc/pnv: add XSCOM infrastructure ppc/pnv: add XSCOM handlers to PnvCore ppc/pnv: add a ISA bus
ppc/xics: Add "native" XICS subclass ppc/pnv: add a XICS native to each PowerNV chip ppc/xics: add axics_get_cpu_index_by_pirhelper ppc/xics: introduce a helper to insert a new ics.gitmodules | 3 + MAINTAINERS | 1 + Makefile | 2 +- default-configs/ppc64-softmmu.mak | 4 +- hw/intc/Makefile.objs | 1 + hw/intc/xics.c | 6 + hw/intc/xics_native.c | 323 ++++++++++++++ hw/ppc/Makefile.objs | 2 + hw/ppc/pnv.c | 888 ++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 248 +++++++++++ hw/ppc/pnv_lpc.c | 514 ++++++++++++++++++++++ hw/ppc/pnv_occ.c | 135 ++++++ hw/ppc/pnv_psi.c | 615 ++++++++++++++++++++++++++ hw/ppc/pnv_xscom.c | 277 ++++++++++++ include/hw/ppc/pnv.h | 159 +++++++ include/hw/ppc/pnv_core.h | 50 +++ include/hw/ppc/pnv_lpc.h | 76 ++++ include/hw/ppc/pnv_occ.h | 38 ++ include/hw/ppc/pnv_psi.h | 64 +++ include/hw/ppc/pnv_xscom.h | 84 ++++ include/hw/ppc/xics.h | 26 ++ pc-bios/README | 5 + pc-bios/skiboot.lid | Bin 0 -> 983893 bytes roms/Makefile | 8 +- roms/skiboot | 1 + 25 files changed, 3527 insertions(+), 3 deletions(-) create mode 100644 hw/intc/xics_native.c create mode 100644 hw/ppc/pnv.c create mode 100644 hw/ppc/pnv_core.c create mode 100644 hw/ppc/pnv_lpc.c create mode 100644 hw/ppc/pnv_occ.c create mode 100644 hw/ppc/pnv_psi.c create mode 100644 hw/ppc/pnv_xscom.c create mode 100644 include/hw/ppc/pnv.h create mode 100644 include/hw/ppc/pnv_core.h create mode 100644 include/hw/ppc/pnv_lpc.h create mode 100644 include/hw/ppc/pnv_occ.h create mode 100644 include/hw/ppc/pnv_psi.h create mode 100644 include/hw/ppc/pnv_xscom.h create mode 100644 pc-bios/skiboot.lid create mode 160000 roms/skiboot
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
Quoted 32 lines · David Gibson
Quoted 31 lines · Cédric Le Goater
Hello,
Here is the latest version of the ppc/pnv platform patchset. PowerNV (as Non-Virtualized) is the "baremetal" platform using the OPAL firmware. It runs Linux on IBM and Open Power systems and it can be used as an hypervisor OS, to run KVM guests, or simply as a host OS. The goal here is to add support for the baremetal platform and possibly later also for the KVM PR guests but not for HV guests.
In v5, all the comments from v4 should have been addressed. Most of the differences are cleanups suggested by David but there a couple of important changes :
- an addition of a new firmware to qemu : skiboot 5.3.7.
- a rework of the native Interrupt Presentation Controller model which now uses memory subregions instead of a hash table.
- a removal of the Power9 LPC Controller. This is still in the plans but the models need a little more work.The initial patches provide a minimal platform with some RAM to load the ROMs : firmware, kernel and initrd. The device tree is built with what is available at reset time. Then, comes the PnvChip object acting as a container for other devices required to run a system. The cores are added to each chip with some restrictions on the number and the ids. Next is the XSCOM model, the sideband bus which gives controls to all the units in the POWER8 chip, the LPC controller for the console, the native interrupt controller and the PSI HB model to handle the external interrupt.
Quoted 8 lines
Quoted 6 lines
The next step should be IPMI support which adds a BT device on the ISA bus and some device tree extensions to read sensors and FRUs. This is relatively straight forward and most of the IPMI code has been discussed already on the list. Then should come a PHB3 model to include some PCI devices. This is big and it needs a few helpers in the PCI core.
I've merged 1-6 into ppc-for-2.8. The rest I'm still reviewing.
I've now merged 7-10 into ppc-for-2.8, making the change I requested to xscom_complete() along the way. Still looking at the rest.
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