ppc/pnv: add a minimal platform
v2 cover ppc/pnv: add a minimal platform
Hello,
Here is a new version to address the comments from v1 plus a couple of improvements, the most important being :
- PnvChip now has PnvChipClass depending on the cpu model
- the device tree uses the fdt "rw" routines
- the XSCOM bus makes its first appearance.
- the cores now use real HW ids ! 'cpu_dt_id' is dead, long live 'cpu_index'
The patchset is organised the same way, the initial patch provides a minimal platform with some RAM to load ROMs, firmware, kernel, 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. First of these is XSCOM, the sideband bus which gives controls to all the units in the POWER8 chip and then the cores.
Last is a little fix to dump the cpus from the monitor.
The PowerNV platform provides just enough support to be run under qemu, so that you can check the qom tree, dump the device tree from ram, show the cpus, etc. It still lacks quite a few controllers to be useful.
The next major task is XICS as it does not support real HW ids for the cpus. There are some initial patches and hacks for that in my dev branch. If you feel adventurous, you can give it a try here :
https://github.com/legoater/qemu/commits/powernv-ipmi-2.8
Just add on the command line :
-smp cores=8
Thanks,
C.
Benjamin Herrenschmidt (2):
ppc/pnv: add skeleton PowerNV platform
ppc/pnv: Add XSCOM infrastructure
Cédric Le Goater (5):
ppc/pnv: add a PnvChip object
ppc/pnv: add a core mask to PnvChip ppc/pnv: add a PnvCore object
ppc/pnv: add a XScomDevice to PnvCore
monitor: fix crash for platforms without a CPU 0
default-configs/ppc64-softmmu.mak | 1 + hw/ppc/Makefile.objs | 2 + hw/ppc/pnv.c | 649 ++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 237 ++++++++++++++ hw/ppc/pnv_xscom.c | 408 ++++++++++++++++++++++++ include/hw/ppc/pnv.h | 119 +++++++ include/hw/ppc/pnv_core.h | 60 ++++ include/hw/ppc/pnv_xscom.h | 75 +++++ monitor.c | 2 +- 9 files changed, 1552 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv.c create mode 100644 hw/ppc/pnv_core.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_xscom.h
Signature · 1 line
2.7.4
PATCH v2 1/7 ppc/pnv: add skeleton PowerNV platform
From: 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 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 | 244 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 37 ++++++ 4 files changed, 284 insertions(+) create mode 100644 hw/ppc/pnv.c create mode 100644 include/hw/ppc/pnv.h
default-configs/ppc64-softmmu.mak +1 -0
@@ -40,6 +40,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 +244 -0
244 lines not on this page · raw message
include/hw/ppc/pnv.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* QEMU 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; +hwaddr fdt_addr; +}PnvMachineState ; + +#endif /* _PPC_PNV_H */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 1/7] ppc/pnv: add skeleton PowerNV platform
Quoted 107 lines · On Wed, 31 Aug 2016 18:34:09 +0200 Cédric Le Goater <[email protected]> wrote:
From: 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.
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: - updated for qemu-2.7
- replaced fprintf byerror_report
- used a common definition of_FDTmacro
- removed VMStateDescription as migration is not yet supported
- added IBM Copyright statements
- reworkedkernel_filenamehandling
- merged PnvSystem and sPowerNVMachineState
- removedPHANDLE_XICP
- addedppc_create_page_sizes_prophelper
- 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
- changedMAX_CPUSto 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.
]Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v1:
- changed
MAX_CPUSto 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_typeis back toIF_IDEbecause of the AHCI devicedefault-configs/ppc64-softmmu.mak | 1 + hw/ppc/Makefile.objs | 2 + hw/ppc/pnv.c | 244 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 37 ++++++ 4 files changed, 284 insertions(+) create mode 100644 hw/ppc/pnv.c create mode 100644 include/hw/ppc/pnv.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -40,6 +40,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=yhw/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 endifhw/ppc/pnv.c new file +17
-0@@ -0,0 +1,244 @@ +/* +* QEMU PowerPC PowerNV model +* +* Copyright (c) 2004-2007 Fabrice Bellard +* Copyright (c) 2007 Jocelyn Mayer +* Copyright (c) 2010 David Gibson, IBM Corporation. +* Copyright (c) 2014-2016 BenH, IBM Corporation. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software.
hw/ppc/pnv.c line 27
Quoted 10 lines
hw/ppc/pnv.c new file +10
-0+* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +*/
This file is a new contribution to QEMU. According to the LICENSE file, it should be released under GPL version 2 or later. If Ben agrees, probably better to have the same text as in include/hw/ppc/pnv.h below.
Quoted 22 lines
[...]
include/hw/ppc/pnv.h new file +18
-0@@ -0,0 +1,37 @@ +/* +* QEMU 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/>. +*/
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 1/7] ppc/pnv: add skeleton PowerNV platform
Quoted 28 lines
Quoted 19 lines
+/*
+ * QEMU PowerPC PowerNV model
+ *
+ * Copyright (c) 2004-2007 Fabrice Bellard
+ * Copyright (c) 2007 Jocelyn Mayer
+ * Copyright (c) 2010 David Gibson, IBM Corporation.
+ * Copyright (c) 2014-2016 BenH, IBM Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORQuoted 8 lines
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
Quoted 3 lines
This file is a new contribution to QEMU. According to the LICENSE file, it should be released under GPL version 2 or later. If Ben agrees, probably better to have the same text as in
include/hw/ppc/pnv.hbelow.
Yes. These copyright headers came from the spapr.c, the file on which pnv.c was originally based. pnv.c has nearly been completely rewritten since.
Ben,
Is that OK with you ?
Cheers,
C.
Quoted 22 lines
Quoted 22 lines
[...]
include/hw/ppc/pnv.h new file +18
-0@@ -0,0 +1,37 @@ +/* +* QEMU 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/>. +*/
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 1/7] ppc/pnv: add skeleton PowerNV platform
Quoted 6 lines · Cédric Le Goater
Quoted 1 line
This file is a new contribution to QEMU. According to the LICENSE
file, it should
Quoted 1 line
be released under GPL version 2 or later. If Ben agrees, probably
better to have
Quoted 1 line
the same text as in
include/hw/ppc/pnv.hbelow.
Quoted 7 lines
Yes. These copyright headers came from the
spapr.c, the file on whichpnv.cwas originally based.pnv.chas nearly been completely rewritten since.Ben,
Is that OK with you ?
Sure.
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 1/7] ppc/pnv: add skeleton PowerNV platform
In reply to Cédric Le GoaterQuoted 234 lines · Cédric Le Goater
From: 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.
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: - updated for qemu-2.7
- replaced fprintf byerror_report
- used a common definition of_FDTmacro
- removed VMStateDescription as migration is not yet supported
- added IBM Copyright statements
- reworkedkernel_filenamehandling
- merged PnvSystem and sPowerNVMachineState
- removedPHANDLE_XICP
- addedppc_create_page_sizes_prophelper
- 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
- changedMAX_CPUSto 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.
]Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v1:
- changed
MAX_CPUSto 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_typeis back toIF_IDEbecause of the AHCI devicedefault-configs/ppc64-softmmu.mak | 1 + hw/ppc/Makefile.objs | 2 + hw/ppc/pnv.c | 244 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 37 ++++++ 4 files changed, 284 insertions(+) create mode 100644 hw/ppc/pnv.c create mode 100644 include/hw/ppc/pnv.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -40,6 +40,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=yhw/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 endifhw/ppc/pnv.c new file +144
-0@@ -0,0 +1,244 @@ +/* +* QEMU PowerPC PowerNV model +* +* Copyright (c) 2004-2007 Fabrice Bellard +* Copyright (c) 2007 Jocelyn Mayer +* Copyright (c) 2010 David Gibson, IBM Corporation. +* Copyright (c) 2014-2016 BenH, IBM Corporation. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "sysemu/sysemu.h" +#include "sysemu/numa.h" +#include "hw/hw.h" +#include "target-ppc/cpu.h" +#include "qemu/log.h" +#include "hw/ppc/fdt.h" +#include "hw/ppc/ppc.h" +#include "hw/ppc/pnv.h" +#include "hw/loader.h" +#include "exec/address-spaces.h" +#include "qemu/cutils.h" + +#include <libfdt.h> + +#define FDT_ADDR 0x01000000 +#define FDT_MAX_SIZE 0x00100000 + +#define FW_FILE_NAME "skiboot.lid" +#define FW_LOAD_ADDR 0x0 +#define FW_MAX_SIZE 0x00400000 + +#define KERNEL_LOAD_ADDR 0x20000000 +#define INITRD_LOAD_ADDR 0x40000000 + +/* +* On Power Systems E880, the max cpus (threads) should be : +* 4 * 4 sockets * 12 cores * 8 threads = 1536 +* Let's make it 2^11 +*/ +#define MAX_CPUS 2048 + +static void powernv_populate_memory_node (void *fdt,int chip_id,hwaddr start, +hwaddr size) +{ +char *mem_name; +uint64_t mem_reg_property[2 ]; +int off; + + mem_reg_property[0 ] =cpu_to_be64 (start); + mem_reg_property[1 ] =cpu_to_be64 (size); + + mem_name =g_strdup_printf ("memory@" TARGET_FMT_lx, start); + off =fdt_add_subnode (fdt,0 , mem_name); +g_free (mem_name); + +_FDT ((fdt_setprop_string (fdt, off,"device_type" ,"memory" ))); +_FDT ((fdt_setprop (fdt, off,"reg" , mem_reg_property, +sizeof (mem_reg_property)))); +_FDT ((fdt_setprop_cell (fdt, off,"ibm,chip-id" , chip_id))); +} + + +/* +* Memory nodes are created by hostboot, one for each range of memory +* that has a different "affinity". In practice, it means one range +* per chip. +*/ +static int powernv_populate_memory (void *fdt) +{ +int chip_id =0 ; +hwaddr chip_ramsize = ram_size; +hwaddr chip_start =0 ; + +/* Only one chip for the moment */ +powernv_populate_memory_node (fdt, chip_id, chip_start, chip_ramsize); + +return 0 ; +} + +static void *powernv_create_fdt (PnvMachineState *pnv, +const char *kernel_cmdline) +{ +void *fdt; +char *buf; +const char plat_compat[] ="qemu,powernv\0ibm,powernv" ; +int off; + + fdt =g_malloc0 (FDT_MAX_SIZE ); +_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE ))); + +/* Root node */ +_FDT ((fdt_setprop_cell (fdt,0 ,"#address-cells" ,0x2 ))); +_FDT ((fdt_setprop_cell (fdt,0 ,"#size-cells" ,0x2 ))); +_FDT ((fdt_setprop_string (fdt,0 ,"model" , +"IBM PowerNV (emulated by qemu)" ))); +_FDT ((fdt_setprop (fdt,0 ,"compatible" , plat_compat, +sizeof (plat_compat)))); + + buf =g_strdup_printf (UUID_FMT , qemu_uuid[0 ], qemu_uuid[1 ], + qemu_uuid[2 ], qemu_uuid[3 ], qemu_uuid[4 ], + qemu_uuid[5 ], qemu_uuid[6 ], qemu_uuid[7 ], + qemu_uuid[8 ], qemu_uuid[9 ], qemu_uuid[10 ], + qemu_uuid[11 ], qemu_uuid[12 ], qemu_uuid[13 ], + qemu_uuid[14 ], qemu_uuid[15 ]); +_FDT ((fdt_setprop_string (fdt,0 ,"vm,uuid" , buf))); +g_free (buf); + + off =fdt_add_subnode (fdt,0 ,"chosen" ); +if (kernel_cmdline) { +_FDT ((fdt_setprop_string (fdt, off,"bootargs" , kernel_cmdline))); + } + +if (pnv->initrd_size) { +uint32_t start_prop =cpu_to_be32 (pnv->initrd_base); +uint32_t end_prop =cpu_to_be32 (pnv->initrd_base + pnv->initrd_size); + +_FDT ((fdt_setprop (fdt, off,"linux,initrd-start" , + &start_prop,sizeof (start_prop)))); +_FDT ((fdt_setprop (fdt, off,"linux,initrd-end" , + &end_prop,sizeof (end_prop)))); + } + +/* Memory */ +powernv_populate_memory (fdt); +
hw/ppc/pnv.c line 154
Quoted 10 lines
hw/ppc/pnv.c new file +10
-0+return fdt; +} + +static void ppc_powernv_reset (void ) +{ +MachineState *machine =MACHINE (qdev_get_machine ()); +PnvMachineState *pnv =POWERNV_MACHINE (machine); +void *fdt; + + pnv->fdt_addr =FDT_ADDR ;
Not sure there's any point to pnv->fdt_addr, since it will always have the value FDT_ADDR. Only worth changing if you're doing a respin for other reasons though.
Quoted 133 lines
hw/ppc/pnv.c new file +90
-0+ +qemu_devices_reset (); + + fdt =powernv_create_fdt (pnv, machine->kernel_cmdline); + +cpu_physical_memory_write (pnv->fdt_addr, fdt,fdt_totalsize (fdt)); +} + +static void ppc_powernv_init (MachineState *machine) +{ +PnvMachineState *pnv =POWERNV_MACHINE (machine); +ram_addr_t ram_size = machine->ram_size; +MemoryRegion *ram; +char *fw_filename; +long fw_size; +long kernel_size; + +/* allocate RAM */ +if (ram_size < (1 *G_BYTE )) { +error_report ("Warning: skiboot may not work with < 1GB of RAM" ); + } + + ram =g_new (MemoryRegion,1 ); +memory_region_allocate_system_memory (ram,NULL ,"ppc_powernv.ram" , + ram_size); +memory_region_add_subregion (get_system_memory (),0 , ram); + +/* load skiboot firmware */ +if (bios_name ==NULL ) { + bios_name =FW_FILE_NAME ; + } + + fw_filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); + + fw_size =load_image_targphys (fw_filename,FW_LOAD_ADDR ,FW_MAX_SIZE ); +if (fw_size <0 ) { +hw_error ("qemu: could not load OPAL '%s'\n" , fw_filename); +exit (1 ); + } +g_free (fw_filename); + +/* load kernel */ + kernel_size =load_image_targphys (machine->kernel_filename, +KERNEL_LOAD_ADDR ,0x2000000 ); +if (kernel_size <0 ) { +hw_error ("qemu: could not load kernel'%s'\n" , machine->kernel_filename); +exit (1 ); + } + +/* load initrd */ +if (machine->initrd_filename) { + pnv->initrd_base =INITRD_LOAD_ADDR ; + pnv->initrd_size =load_image_targphys (machine->initrd_filename, + pnv->initrd_base,0x10000000 );/* 128MB max */ +if (pnv->initrd_size <0 ) { +error_report ("qemu: could not load initial ram disk '%s'" , + machine->initrd_filename); +exit (1 ); + } + } +} + +static void powernv_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="IBM PowerNV (Non-Virtualized)" ; + mc->init = ppc_powernv_init; + mc->reset = ppc_powernv_reset; + mc->max_cpus =MAX_CPUS ; + mc->block_default_type =IF_IDE ;/* Pnv provides a AHCI device for +* storage */ + mc->no_parallel =1 ; + mc->default_boot_order =NULL ; + mc->default_ram_size =1 *G_BYTE ; +} + +static const TypeInfo powernv_machine_info = { + .name =TYPE_POWERNV_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (PnvMachineState), + .class_init = powernv_machine_class_init, +}; + +static void powernv_machine_register_types (void ) +{ +type_register_static (&powernv_machine_info); +} + +type_init (powernv_machine_register_types)include/hw/ppc/pnv.h new file +37
-0@@ -0,0 +1,37 @@ +/* +* QEMU 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; +hwaddr fdt_addr; +}PnvMachineState ; + +#endif /* _PPC_PNV_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 v2 1/7] ppc/pnv: add skeleton PowerNV platform
Quoted 11 lines
hw/ppc/pnv.c line 154
Quoted 7 lines
hw/ppc/pnv.c new file +7
-0+static void ppc_powernv_reset (void ) +{ +MachineState *machine =MACHINE (qdev_get_machine ()); +PnvMachineState *pnv =POWERNV_MACHINE (machine); +void *fdt; + + pnv->fdt_addr =FDT_ADDR ;Not sure there's any point to
pnv->fdt_addr, since it will always have the valueFDT_ADDR. Only worth changing if you're doing a respin for other reasons though.
Yes, you are probably right. I will take a look.
I have a new version with some basic core and xscom support for P9, booting up to the interrupt setting in skiboot. So I was already planning for v3.
Thanks,
C.
PATCH v2 2/7 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, specific init 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.
---
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.
Maybe this object deserves its own file hw/ppc/pnv_chip.c ?
hw/ppc/pnv.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 71 ++++++++++++++++++++++++ 2 files changed, 225 insertions(+)
hw/ppc/pnv.c +154 -0
@@ -168,6 +168,8 @@ static void ppc_powernv_init(MachineState *machine)char *fw_filename;long fw_size;long kernel_size; +int i; +char *chip_typename;/* allocate RAM */ if (ram_size < (1 *G_BYTE )) {
@@ -212,6 +214,153 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); } } + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); + + pnv->chips = g_new0(PnvChip *, pnv->num_chips); +for (i =0 ; i < pnv->num_chips; i++) { +Object *chip =object_new (chip_typename); +object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_bool (chip, true,"realized" , &error_abort); + pnv->chips[i] =PNV_CHIP (chip); + } +g_free (chip_typename); +} + +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8nvl_realize; + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_P8NVL ; + k->chip_f000f =0x120d304980000000ull ; + dc->desc ="PowerNV Chip POWER8NVL" ; +} + +static const TypeInfo pnv_chip_power8nvl_info = { + .name =TYPE_PNV_CHIP_POWER8NVL , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8NVL), + .class_init = pnv_chip_power8nvl_class_init, +}; + +static void pnv_chip_power8_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8_realize; + k->cpu_model ="POWER8" ; + k->chip_type =PNV_CHIP_P8 ; + k->chip_f000f =0x220ea04980000000ull ; + dc->desc ="PowerNV Chip POWER8" ; +} + +static const TypeInfo pnv_chip_power8_info = { + .name =TYPE_PNV_CHIP_POWER8 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8), + .class_init = pnv_chip_power8_class_init, +}; + +static void pnv_chip_power8e_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8e_realize; + k->cpu_model ="POWER8E" ; + k->chip_type =PNV_CHIP_P8E ; + k->chip_f000f =0x221ef04980000000ull ; + dc->desc ="PowerNV Chip POWER8E" ; +} + +static const TypeInfo pnv_chip_power8e_info = { + .name =TYPE_PNV_CHIP_POWER8E , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8e), + .class_init = pnv_chip_power8e_class_init, +}; + +static void pnv_chip_realize (DeviceState *dev,Error **errp) +{ +PnvChip *chip =PNV_CHIP (dev); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + pcc->realize (chip, errp); +} + +static Property pnv_chip_properties[] = { +DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,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 char *pnv_get_num_chips (Object *obj,Error **errp) +{ +return g_strdup_printf ("%d" ,POWERNV_MACHINE (obj)->num_chips); +} + +static void pnv_set_num_chips (Object *obj,const char *value,Error **errp) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); +int num_chips; + +if (sscanf (value,"%d" , &num_chips) !=1 ) { +error_setg (errp,"invalid num_chips property: '%s'" , value); + } + +/* +* FIXME: should we decide on how many chips we can create based +* on #cores and Venice vs. Murano vs. Naples chip type etc..., +*/ + pnv->num_chips = num_chips; +} + +static void powernv_machine_initfn (Object *obj) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); + pnv->num_chips =1 ; + +object_property_add_str (obj,"num-chips" , pnv_get_num_chips, + pnv_set_num_chips,NULL ); +object_property_set_description (obj,"num-chips" , +"Specifies the number of processor chips" , +NULL ); }static void powernv_machine_class_init (ObjectClass *oc,void *data)
@@ -233,12 +382,17 @@ 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_init (powernv_machine_register_types)
include/hw/ppc/pnv.h +71 -0
83 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 41 lines · On Wed, 31 Aug 2016 18:34:10 +0200 Cédric Le Goater <[email protected]> wrote:
This 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, specific init 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.
Signed-off-by Cédric Le Goater <[email protected]>---
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.Maybe this object deserves its own file
hw/ppc/pnv_chip.c?hw/ppc/pnv.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 71 ++++++++++++++++++++++++ 2 files changed, 225 insertions(+)hw/ppc/pnv.c +2
-0@@ -168,6 +168,8 @@ static void ppc_powernv_init(MachineState *machine)char *fw_filename;long fw_size;long kernel_size; +int i; +char *chip_typename;/* allocate RAM */ if (ram_size < (1 *G_BYTE )) {
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 220
Quoted 7 lines
hw/ppc/pnv.c +4
-0@@ -212,6 +214,153 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); } } + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); +
You should check that the CPU model is supported by this machine (with object_class_by_name()) and error out if it is not, or...
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 223
Quoted 3 lines
hw/ppc/pnv.c +3
-0+ pnv->chips = g_new0(PnvChip *, pnv->num_chips); +for (i =0 ; i < pnv->num_chips; i++) { +Object *chip =object_new (chip_typename);
... this call to object_new() will abort.
Quoted 195 lines
hw/ppc/pnv.c +145
-0+object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_bool (chip, true,"realized" , &error_abort); + pnv->chips[i] =PNV_CHIP (chip); + } +g_free (chip_typename); +} + +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8nvl_realize; + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_P8NVL ; + k->chip_f000f =0x120d304980000000ull ; + dc->desc ="PowerNV Chip POWER8NVL" ; +} + +static const TypeInfo pnv_chip_power8nvl_info = { + .name =TYPE_PNV_CHIP_POWER8NVL , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8NVL), + .class_init = pnv_chip_power8nvl_class_init, +}; + +static void pnv_chip_power8_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8_realize; + k->cpu_model ="POWER8" ; + k->chip_type =PNV_CHIP_P8 ; + k->chip_f000f =0x220ea04980000000ull ; + dc->desc ="PowerNV Chip POWER8" ; +} + +static const TypeInfo pnv_chip_power8_info = { + .name =TYPE_PNV_CHIP_POWER8 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8), + .class_init = pnv_chip_power8_class_init, +}; + +static void pnv_chip_power8e_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8e_realize; + k->cpu_model ="POWER8E" ; + k->chip_type =PNV_CHIP_P8E ; + k->chip_f000f =0x221ef04980000000ull ; + dc->desc ="PowerNV Chip POWER8E" ; +} + +static const TypeInfo pnv_chip_power8e_info = { + .name =TYPE_PNV_CHIP_POWER8E , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8e), + .class_init = pnv_chip_power8e_class_init, +}; + +static void pnv_chip_realize (DeviceState *dev,Error **errp) +{ +PnvChip *chip =PNV_CHIP (dev); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + pcc->realize (chip, errp); +} + +static Property pnv_chip_properties[] = { +DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,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 char *pnv_get_num_chips (Object *obj,Error **errp) +{ +return g_strdup_printf ("%d" ,POWERNV_MACHINE (obj)->num_chips); +} + +static void pnv_set_num_chips (Object *obj,const char *value,Error **errp) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); +int num_chips; + +if (sscanf (value,"%d" , &num_chips) !=1 ) { +error_setg (errp,"invalid num_chips property: '%s'" , value); + } + +/* +* FIXME: should we decide on how many chips we can create based +* on #cores and Venice vs. Murano vs. Naples chip type etc..., +*/ + pnv->num_chips = num_chips; +} + +static void powernv_machine_initfn (Object *obj) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); + pnv->num_chips =1 ; + +object_property_add_str (obj,"num-chips" , pnv_get_num_chips, + pnv_set_num_chips,NULL ); +object_property_set_description (obj,"num-chips" , +"Specifies the number of processor chips" , +NULL ); }static void powernv_machine_class_init (ObjectClass *oc,void *data)@@ -233,12 +382,17 @@ 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_init (powernv_machine_register_types)include/hw/ppc/pnv.h +26
-0@@ -20,6 +20,74 @@#define _PPC_PNV_H#include "hw/boards.h" +#include "hw/sysbus.h" + +#define TYPE_PNV_CHIP "powernv-chip" +#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP) +#define PNV_CHIP_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvChipClass, (klass), TYPE_PNV_CHIP) +#define PNV_CHIP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvChipClass, (obj), TYPE_PNV_CHIP) + +typedef enum PnvChipType { +PNV_CHIP_P8E ,/* AKA Murano (default) */ +PNV_CHIP_P8 ,/* AKA Venice */ +PNV_CHIP_P8NVL ,/* AKA Naples */ +}PnvChipType ; + +typedef struct PnvChip { +/*< private >*/ +SysBusDevice parent_obj; + +/*< public >*/ +uint32_t chip_id; +}PnvChip ; + +typedef struct PnvChipClass { + /*< private >*/ + SysBusDeviceClass parent_class;
include/hw/ppc/pnv.h line 58
Quoted 10 lines
include/hw/ppc/pnv.h +10
-0+/*< public >*/ +const char *cpu_model; +PnvChipType chip_type; +uint64_t chip_f000f; + +void (*realize)(PnvChip *dev,Error **errp); +} PnvChipClass; + +#define TYPE_PNV_CHIP "powernv-chip" +
This macro is already defined above.
include/hw/ppc/pnv.h line 59
Quoted 1 line
include/hw/ppc/pnv.h +1
-0+#define TYPE_PNV_CHIP_POWER8E "powernv-chip-POWER8E"
What about this ?
#define TYPE_PNV_CHIP_POWER8E TYPE_PNV_CHIP "-POWER8E"
include/hw/ppc/pnv.h line 65
Quoted 6 lines
include/hw/ppc/pnv.h +6
-0+#define PNV_CHIP_POWER8E (obj) \ + OBJECT_CHECK(PnvChipPower8e, (obj), TYPE_PNV_CHIP_POWER8E) + +typedef struct PnvChipPower8e { +PnvChip pnv_chip; +}PnvChipPower8e ;
Why Power8e here and...
Quoted 6 lines
include/hw/ppc/pnv.h +6
-0+ +#define TYPE_PNV_CHIP_POWER8 "powernv-chip-POWER8" +#define PNV_CHIP_POWER8 (obj) \ + OBJECT_CHECK(PnvChipPower8, (obj), TYPE_PNV_CHIP_POWER8) + +typedef struct PnvChipPower8 {
include/hw/ppc/pnv.h line 81
Quoted 10 lines
include/hw/ppc/pnv.h +10
-0+PnvChip pnv_chip; +} PnvChipPower8; + +#define TYPE_PNV_CHIP_POWER8NVL "powernv-chip-POWER8NVL" +#define PNV_CHIP_POWER8NVL (obj) \ + OBJECT_CHECK(PnvChipPower8NVL, (obj), TYPE_PNV_CHIP_POWER8NVL) + +typedef struct PnvChipPower8NVL { +PnvChip pnv_chip; +}PnvChipPower8NVL ;
... Power8NVL there ?
Quoted 22 lines
include/hw/ppc/pnv.h +12
-0+ +/* +* This generates a HW chip id depending on an index: +* +* 0x0, 0x1, 0x10, 0x11, 0x20, 0x21, ... +* +* Is this correct ? +*/ +#define CHIP_HWID (i) ((((i) & 0x3e) << 3) | ((i) & 0x1))#define TYPE_POWERNV_MACHINE MACHINE_TYPE_NAME("powernv")#define POWERNV_MACHINE (obj) \@@ -32,6 +100,9 @@ typedef struct PnvMachineState {uint32_t initrd_base;long initrd_size;hwaddr fdt_addr; + +uint32_t num_chips; + PnvChip **chips; } PnvMachineState;#endif /* _PPC_PNV_H */
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 270 lines · Greg Kurz
Quoted 41 lines · On Wed, 31 Aug 2016 18:34:10 +0200 Cédric Le Goater <[email protected]> wrote:
This 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, specific init 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.
Signed-off-by Cédric Le Goater <[email protected]>---
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.Maybe this object deserves its own file
hw/ppc/pnv_chip.c?hw/ppc/pnv.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 71 ++++++++++++++++++++++++ 2 files changed, 225 insertions(+)hw/ppc/pnv.c +2
-0@@ -168,6 +168,8 @@ static void ppc_powernv_init(MachineState *machine)char *fw_filename;long fw_size;long kernel_size; +int i; +char *chip_typename;/* allocate RAM */ if (ram_size < (1 *G_BYTE )) {hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 220
Quoted 7 lines
hw/ppc/pnv.c +4
-0@@ -212,6 +214,153 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); } } + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); +You should check that the CPU model is supported by this machine (with
object_class_by_name()) and error out if it is not, or...hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 223
Quoted 3 lines
hw/ppc/pnv.c +3
-0+ pnv->chips = g_new0(PnvChip *, pnv->num_chips); +for (i =0 ; i < pnv->num_chips; i++) { +Object *chip =object_new (chip_typename);... this call to
object_new()will abort.Quoted 195 lines
hw/ppc/pnv.c +145
-0+object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_bool (chip, true,"realized" , &error_abort); + pnv->chips[i] =PNV_CHIP (chip); + } +g_free (chip_typename); +} + +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8nvl_realize; + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_P8NVL ; + k->chip_f000f =0x120d304980000000ull ; + dc->desc ="PowerNV Chip POWER8NVL" ; +} + +static const TypeInfo pnv_chip_power8nvl_info = { + .name =TYPE_PNV_CHIP_POWER8NVL , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8NVL), + .class_init = pnv_chip_power8nvl_class_init, +}; + +static void pnv_chip_power8_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8_realize; + k->cpu_model ="POWER8" ; + k->chip_type =PNV_CHIP_P8 ; + k->chip_f000f =0x220ea04980000000ull ; + dc->desc ="PowerNV Chip POWER8" ; +} + +static const TypeInfo pnv_chip_power8_info = { + .name =TYPE_PNV_CHIP_POWER8 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8), + .class_init = pnv_chip_power8_class_init, +}; + +static void pnv_chip_power8e_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8e_realize; + k->cpu_model ="POWER8E" ; + k->chip_type =PNV_CHIP_P8E ; + k->chip_f000f =0x221ef04980000000ull ; + dc->desc ="PowerNV Chip POWER8E" ; +} + +static const TypeInfo pnv_chip_power8e_info = { + .name =TYPE_PNV_CHIP_POWER8E , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8e), + .class_init = pnv_chip_power8e_class_init, +}; + +static void pnv_chip_realize (DeviceState *dev,Error **errp) +{ +PnvChip *chip =PNV_CHIP (dev); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + pcc->realize (chip, errp); +} + +static Property pnv_chip_properties[] = { +DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,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 char *pnv_get_num_chips (Object *obj,Error **errp) +{ +return g_strdup_printf ("%d" ,POWERNV_MACHINE (obj)->num_chips); +} + +static void pnv_set_num_chips (Object *obj,const char *value,Error **errp) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); +int num_chips; + +if (sscanf (value,"%d" , &num_chips) !=1 ) { +error_setg (errp,"invalid num_chips property: '%s'" , value); + } + +/* +* FIXME: should we decide on how many chips we can create based +* on #cores and Venice vs. Murano vs. Naples chip type etc..., +*/ + pnv->num_chips = num_chips; +} + +static void powernv_machine_initfn (Object *obj) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); + pnv->num_chips =1 ; + +object_property_add_str (obj,"num-chips" , pnv_get_num_chips, + pnv_set_num_chips,NULL ); +object_property_set_description (obj,"num-chips" , +"Specifies the number of processor chips" , +NULL ); }static void powernv_machine_class_init (ObjectClass *oc,void *data)@@ -233,12 +382,17 @@ 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_init (powernv_machine_register_types)include/hw/ppc/pnv.h +26
-0@@ -20,6 +20,74 @@#define _PPC_PNV_H#include "hw/boards.h" +#include "hw/sysbus.h" + +#define TYPE_PNV_CHIP "powernv-chip" +#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP) +#define PNV_CHIP_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvChipClass, (klass), TYPE_PNV_CHIP) +#define PNV_CHIP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvChipClass, (obj), TYPE_PNV_CHIP) + +typedef enum PnvChipType { +PNV_CHIP_P8E ,/* AKA Murano (default) */ +PNV_CHIP_P8 ,/* AKA Venice */ +PNV_CHIP_P8NVL ,/* AKA Naples */ +}PnvChipType ; + +typedef struct PnvChip { +/*< private >*/ +SysBusDevice parent_obj; + +/*< public >*/ +uint32_t chip_id; +}PnvChip ; + +typedef struct PnvChipClass { + /*< private >*/ + SysBusDeviceClass parent_class;include/hw/ppc/pnv.h line 58
Quoted 10 lines
include/hw/ppc/pnv.h +10
-0+/*< public >*/ +const char *cpu_model; +PnvChipType chip_type; +uint64_t chip_f000f; + +void (*realize)(PnvChip *dev,Error **errp); +} PnvChipClass; + +#define TYPE_PNV_CHIP "powernv-chip" +This macro is already defined above.
Quoted 5 lines
include/hw/ppc/pnv.h line 59
Quoted 1 line
include/hw/ppc/pnv.h +1
-0+#define TYPE_PNV_CHIP_POWER8E "powernv-chip-POWER8E"What about this ?
#define
TYPE_PNV_CHIP_POWER8ETYPE_PNV_CHIP"-POWER8E"
I thought of doing that and forgot :)
Quoted 8 lines
include/hw/ppc/pnv.h line 65
Quoted 6 lines
include/hw/ppc/pnv.h +6
-0+#define PNV_CHIP_POWER8E (obj) \ + OBJECT_CHECK(PnvChipPower8e, (obj), TYPE_PNV_CHIP_POWER8E) + +typedef struct PnvChipPower8e { +PnvChip pnv_chip; +}PnvChipPower8e ;Why Power8e here and...
yes. I will change the names to be in sync with the cpu names and will probably do the same with enum PnvChipType.
Thanks,
C.
Quoted 42 lines
Quoted 6 lines
include/hw/ppc/pnv.h +6
-0+ +#define TYPE_PNV_CHIP_POWER8 "powernv-chip-POWER8" +#define PNV_CHIP_POWER8 (obj) \ + OBJECT_CHECK(PnvChipPower8, (obj), TYPE_PNV_CHIP_POWER8) + +typedef struct PnvChipPower8 {include/hw/ppc/pnv.h line 81
Quoted 10 lines
include/hw/ppc/pnv.h +10
-0+PnvChip pnv_chip; +} PnvChipPower8; + +#define TYPE_PNV_CHIP_POWER8NVL "powernv-chip-POWER8NVL" +#define PNV_CHIP_POWER8NVL (obj) \ + OBJECT_CHECK(PnvChipPower8NVL, (obj), TYPE_PNV_CHIP_POWER8NVL) + +typedef struct PnvChipPower8NVL { +PnvChip pnv_chip; +}PnvChipPower8NVL ;... Power8NVL there ?
Quoted 22 lines
include/hw/ppc/pnv.h +12
-0+ +/* +* This generates a HW chip id depending on an index: +* +* 0x0, 0x1, 0x10, 0x11, 0x20, 0x21, ... +* +* Is this correct ? +*/ +#define CHIP_HWID (i) ((((i) & 0x3e) << 3) | ((i) & 0x1))#define TYPE_POWERNV_MACHINE MACHINE_TYPE_NAME("powernv")#define POWERNV_MACHINE (obj) \@@ -32,6 +100,9 @@ typedef struct PnvMachineState {uint32_t initrd_base;long initrd_size;hwaddr fdt_addr; + +uint32_t num_chips; + PnvChip **chips; } PnvMachineState;#endif /* _PPC_PNV_H */
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
In reply to Cédric Le GoaterQuoted 43 lines · Cédric Le Goater
This 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, specific init 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.
Signed-off-by Cédric Le Goater <[email protected]>---
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.Maybe this object deserves its own file
hw/ppc/pnv_chip.c?hw/ppc/pnv.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 71 ++++++++++++++++++++++++ 2 files changed, 225 insertions(+)hw/ppc/pnv.c +2
-0@@ -168,6 +168,8 @@ static void ppc_powernv_init(MachineState *machine)char *fw_filename;long fw_size;long kernel_size; +int i; +char *chip_typename;/* allocate RAM */ if (ram_size < (1 *G_BYTE )) {@@ -212,6 +214,153 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); }
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 225
Quoted 10 lines
hw/ppc/pnv.c +9
-0} + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); + + pnv->chips = g_new0(PnvChip *, pnv->num_chips); +for (i =0 ; i < pnv->num_chips; i++) { +Object *chip =object_new (chip_typename); +object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_bool (chip, true,"realized" , &error_abort);
I'm guessing these could fail due to bad user supplied parameters, not just internal bugs. In which case this should be &error_fatal rather than &error_abort.
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 234
Quoted 9 lines
hw/ppc/pnv.c +9
-0+ pnv->chips[i] =PNV_CHIP (chip); + } +g_free (chip_typename); +} + +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) +{ + ; +}
I don't think you should need to define an empty realize function. Or is this just a placeholder for things future patches will add?
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 243
Quoted 9 lines
hw/ppc/pnv.c +9
-0+ +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8nvl_realize; + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_P8NVL ;
With the new chip class per cpu class, does this chip_type field serve any purpose any more?
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 244
Quoted 1 line
hw/ppc/pnv.c +1
-0+ k->chip_f000f =0x120d304980000000ull ;
A comment somewhere explaining what this cryptic value is would be nice.
Quoted 16 lines
hw/ppc/pnv.c +16
-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 (PnvChipPower8NVL), + .class_init = pnv_chip_power8nvl_class_init, +}; + +static void pnv_chip_power8_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8_class_init (ObjectClass *klass,void *data)
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 270
Quoted 10 lines
hw/ppc/pnv.c +10
-0+{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8_realize; + k->cpu_model ="POWER8" ; + k->chip_type =PNV_CHIP_P8 ; + k->chip_f000f =0x220ea04980000000ull ; + dc->desc ="PowerNV Chip POWER8" ; +}
It might be worth using some macros to compactify the definition of each of the chip variants.
Quoted 203 lines
hw/ppc/pnv.c +98
-0+ +static const TypeInfo pnv_chip_power8_info = { + .name =TYPE_PNV_CHIP_POWER8 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8), + .class_init = pnv_chip_power8_class_init, +}; + +static void pnv_chip_power8e_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8e_realize; + k->cpu_model ="POWER8E" ; + k->chip_type =PNV_CHIP_P8E ; + k->chip_f000f =0x221ef04980000000ull ; + dc->desc ="PowerNV Chip POWER8E" ; +} + +static const TypeInfo pnv_chip_power8e_info = { + .name =TYPE_PNV_CHIP_POWER8E , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8e), + .class_init = pnv_chip_power8e_class_init, +}; + +static void pnv_chip_realize (DeviceState *dev,Error **errp) +{ +PnvChip *chip =PNV_CHIP (dev); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + pcc->realize (chip, errp); +} + +static Property pnv_chip_properties[] = { +DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,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 char *pnv_get_num_chips (Object *obj,Error **errp) +{ +return g_strdup_printf ("%d" ,POWERNV_MACHINE (obj)->num_chips); +} + +static void pnv_set_num_chips (Object *obj,const char *value,Error **errp) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); +int num_chips; + +if (sscanf (value,"%d" , &num_chips) !=1 ) { +error_setg (errp,"invalid num_chips property: '%s'" , value); + } + +/* +* FIXME: should we decide on how many chips we can create based +* on #cores and Venice vs. Murano vs. Naples chip type etc..., +*/ + pnv->num_chips = num_chips; +} + +static void powernv_machine_initfn (Object *obj) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); + pnv->num_chips =1 ; + +object_property_add_str (obj,"num-chips" , pnv_get_num_chips, + pnv_set_num_chips,NULL ); +object_property_set_description (obj,"num-chips" , +"Specifies the number of processor chips" , +NULL ); }static void powernv_machine_class_init (ObjectClass *oc,void *data)@@ -233,12 +382,17 @@ 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_init (powernv_machine_register_types)include/hw/ppc/pnv.h +71
-0@@ -20,6 +20,74 @@#define _PPC_PNV_H#include "hw/boards.h" +#include "hw/sysbus.h" + +#define TYPE_PNV_CHIP "powernv-chip" +#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP) +#define PNV_CHIP_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvChipClass, (klass), TYPE_PNV_CHIP) +#define PNV_CHIP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvChipClass, (obj), TYPE_PNV_CHIP) + +typedef enum PnvChipType { +PNV_CHIP_P8E ,/* AKA Murano (default) */ +PNV_CHIP_P8 ,/* AKA Venice */ +PNV_CHIP_P8NVL ,/* AKA Naples */ +}PnvChipType ; + +typedef struct PnvChip { +/*< private >*/ +SysBusDevice parent_obj; + +/*< public >*/ +uint32_t chip_id; +}PnvChip ; + +typedef struct PnvChipClass { +/*< private >*/ +SysBusDeviceClass parent_class; +/*< public >*/ +const char *cpu_model; +PnvChipType chip_type; +uint64_t chip_f000f; + +void (*realize)(PnvChip *dev,Error **errp); +}PnvChipClass ; + +#define TYPE_PNV_CHIP "powernv-chip" + +#define TYPE_PNV_CHIP_POWER8E "powernv-chip-POWER8E" +#define PNV_CHIP_POWER8E (obj) \ + OBJECT_CHECK(PnvChipPower8e, (obj), TYPE_PNV_CHIP_POWER8E) + +typedef struct PnvChipPower8e { +PnvChip pnv_chip; +}PnvChipPower8e ; + +#define TYPE_PNV_CHIP_POWER8 "powernv-chip-POWER8" +#define PNV_CHIP_POWER8 (obj) \ + OBJECT_CHECK(PnvChipPower8, (obj), TYPE_PNV_CHIP_POWER8) + +typedef struct PnvChipPower8 { +PnvChip pnv_chip; +}PnvChipPower8 ; + +#define TYPE_PNV_CHIP_POWER8NVL "powernv-chip-POWER8NVL" +#define PNV_CHIP_POWER8NVL (obj) \ + OBJECT_CHECK(PnvChipPower8NVL, (obj), TYPE_PNV_CHIP_POWER8NVL) + +typedef struct PnvChipPower8NVL { +PnvChip pnv_chip; +}PnvChipPower8NVL ; + +/* +* This generates a HW chip id depending on an index: +* +* 0x0, 0x1, 0x10, 0x11, 0x20, 0x21, ... +* +* Is this correct ? +*/ +#define CHIP_HWID (i) ((((i) & 0x3e) << 3) | ((i) & 0x1))#define TYPE_POWERNV_MACHINE MACHINE_TYPE_NAME("powernv")#define POWERNV_MACHINE (obj) \@@ -32,6 +100,9 @@ typedef struct PnvMachineState {uint32_t initrd_base;long initrd_size;hwaddr fdt_addr; + +uint32_t num_chips; + PnvChip **chips; } PnvMachineState;#endif /* _PPC_PNV_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 v2 2/7] ppc/pnv: add a PnvChip object
Quoted 9 lines · David Gibson
With the new chip class per cpu class, does this
chip_typefield serve
any purpose any more?Quoted 1 line
+
k->chip_f000f=0x120d304980000000ull;A comment somewhere explaining what this cryptic value is would be nice.
It's snapshot from an actual chip ;-) Some of the fields we know about such as the actual chip "type" and DD version but some are obscure even to us :-)
Cheers,
Ben.
`
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · David Gibson
With the new chip class per cpu class, does this
chip_typefield serve
any purpose any more?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+
k->chip_f000f=0x120d304980000000ull;A comment somewhere explaining what this cryptic value is would be nice.
It's snapshot from an actual chip ;-) Some of the fields we know about such as the actual chip "type" and DD version but some are obscure even to us :-)
yeah. I have not found a clear definition of all the bits.
I will try to make a macro with what I can collect from the specs and the code.
Cheers,
C.
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 4 lines · Cédric Le Goater
yeah. I have not found a clear definition of all the bits.
I will try to make a macro with what I can collect from the specs and the code.
It's the CFAM stuff, there's some doco internally but nothing releasable publicly...
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
yeah. I have not found a clear definition of all the bits.
I will try to make a macro with what I can collect from the specs and the code.
It's the CFAM stuff, there's some doco internally but nothing releasable publicly...
Right...
My point is that I want a name (and/or coment) saying what the relevance of this value is to qemu. Why do we need this cryptic value sitting here?
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 v2 2/7] ppc/pnv: add a PnvChip object
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
yeah. I have not found a clear definition of all the bits.
I will try to make a macro with what I can collect from the specs and the code.
Quoted 8 lines
Quoted 2 lines
It's the CFAM stuff, there's some doco internally but nothing releasable publicly...
Right...
My point is that I want a name (and/or coment) saying what the relevance of this value is to qemu. Why do we need this cryptic value sitting here?
OK. I will add that. It is mostly important for the FW to identify the chip model. PVR is for the CPU.
Thanks,
C.
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
In reply to Benjamin HerrenschmidtQuoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · David Gibson
With the new chip class per cpu class, does this
chip_typefield serve
any purpose any more?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+
k->chip_f000f=0x120d304980000000ull;A comment somewhere explaining what this cryptic value is would be nice.
It's snapshot from an actual chip ;-) Some of the fields we know about such as the actual chip "type" and DD version but some are obscure even to us :-)
Sorry, I actually meant what does "chip_f000f" mean, rather than what does the value inside there mean.
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 v2 2/7] ppc/pnv: add a PnvChip object
Quoted 12 lines · David Gibson
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · David Gibson
With the new chip class per cpu class, does this
chip_typefield serve
any purpose any more?Quoted 1 line
+
k->chip_f000f=0x120d304980000000ull;A comment somewhere explaining what this cryptic value is would be nice.
Quoted 6 lines
Quoted 3 lines
It's snapshot from an actual chip ;-) Some of the fields we know about such as the actual chip "type" and DD version but some are obscure even to us :-)
Sorry, I actually meant what does "
chip_f000f" mean, rather than what does the value inside there mean.
f000f is the xscom address of the register containing this CFAM chip id. I will add a chip_cfam_id attribute to the chip object. I guess it makes more sense.
Other chips (like the Centaur) have such an ID.
C.
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 17 lines · Cédric Le Goater
Quoted 16 lines · David Gibson
Quoted 14 lines · Benjamin Herrenschmidt
Quoted 9 lines · David Gibson
With the new chip class per cpu class, does this
chip_typefield serve
any purpose any more?Quoted 1 line
+
k->chip_f000f=0x120d304980000000ull;A comment somewhere explaining what this cryptic value is would be nice.
It's snapshot from an actual chip ;-) Some of the fields we know about such as the actual chip "type" and DD version but some are obscure even to us :-)
Quoted 8 lines
Quoted 2 lines
Sorry, I actually meant what does "
chip_f000f" mean, rather than what does the value inside there mean.f000f is the xscom address of the register containing this CFAM chip id. I will add a
chip_cfam_idattribute to the chip object. I guess it makes more sense.Other chips (like the Centaur) have such an ID.
Ok.
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 v2 2/7] ppc/pnv: add a PnvChip object
In reply to David GibsonQuoted 50 lines · David Gibson
Quoted 49 lines · Cédric Le Goater
This 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, specific init 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.
Signed-off-by Cédric Le Goater <[email protected]>---
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.Maybe this object deserves its own file
hw/ppc/pnv_chip.c?hw/ppc/pnv.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 71 ++++++++++++++++++++++++ 2 files changed, 225 insertions(+)hw/ppc/pnv.c +7
-0@@ -168,6 +168,8 @@ static void ppc_powernv_init(MachineState *machine)char *fw_filename;long fw_size;long kernel_size; +int i; +char *chip_typename;/* allocate RAM */ if (ram_size < (1 *G_BYTE )) {@@ -212,6 +214,153 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); } } + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); + + pnv->chips = g_new0(PnvChip *, pnv->num_chips);
Quoted 8 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 225
Quoted 4 lines
hw/ppc/pnv.c +4
-0+for (i =0 ; i < pnv->num_chips; i++) { +Object *chip =object_new (chip_typename); +object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_bool (chip, true,"realized" , &error_abort);I'm guessing these could fail due to bad user supplied parameters, not just internal bugs. In which case this should be
&error_fatalrather than&error_abort.
yes.
Quoted 13 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 234
Quoted 10 lines
hw/ppc/pnv.c +9
-0+ pnv->chips[i] =PNV_CHIP (chip); + } +g_free (chip_typename); +} + +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) +{ + ; +}I don't think you should need to define an empty realize function. Or is this just a placeholder for things future patches will add?
yes that was the plan but maybe this is a little early. chip_type proved to be useful enough for the moment in the full patchset I maintain.
P9 will use a xive object when available and not a xics. I think this is when the real big difference will show up. So I should make realize() optional.
Quoted 4 lines
Quoted 4 lines
hw/ppc/pnv.c +4
-0+ +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass);
Quoted 8 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 243
Quoted 5 lines
hw/ppc/pnv.c +5
-0+PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8nvl_realize; + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_P8NVL ;With the new chip class per cpu class, does this
chip_typefield serve any purpose any more?
It does look a bit redundant, I agree. But it is useful for xscom address translation (P9 is a little different), for xscom devices in general, for core id to pir conversion. It also does for lpc_irq support, which applies to P8NVL (and upper I suppose).
Let's keep it for the moment as it serves its purpose, which is to handle small differences without too much cost. If this is going too far, I will propose a set of ops per chip type.
Quoted 3 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 244
Quoted 1 line
hw/ppc/pnv.c +1
-0+ k->chip_f000f =0x120d304980000000ull ;A comment somewhere explaining what this cryptic value is would be nice.
yeah. I will make a macro of it with the bits I know about :/
Quoted 21 lines
Quoted 21 lines
hw/ppc/pnv.c +21
-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 (PnvChipPower8NVL), + .class_init = pnv_chip_power8nvl_class_init, +}; + +static void pnv_chip_power8_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8_realize;
Quoted 8 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 270
Quoted 5 lines
hw/ppc/pnv.c +5
-0+ k->cpu_model ="POWER8" ; + k->chip_type =PNV_CHIP_P8 ; + k->chip_f000f =0x220ea04980000000ull ; + dc->desc ="PowerNV Chip POWER8" ; +}It might be worth using some macros to compactify the definition of each of the chip variants.
yes. we have four of them now. It is time do so.
Thanks,
C.
Quoted 204 lines
Quoted 203 lines
hw/ppc/pnv.c +98
-0+ +static const TypeInfo pnv_chip_power8_info = { + .name =TYPE_PNV_CHIP_POWER8 , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8), + .class_init = pnv_chip_power8_class_init, +}; + +static void pnv_chip_power8e_realize (PnvChip *chip,Error **errp) +{ + ; +} + +static void pnv_chip_power8e_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8e_realize; + k->cpu_model ="POWER8E" ; + k->chip_type =PNV_CHIP_P8E ; + k->chip_f000f =0x221ef04980000000ull ; + dc->desc ="PowerNV Chip POWER8E" ; +} + +static const TypeInfo pnv_chip_power8e_info = { + .name =TYPE_PNV_CHIP_POWER8E , + .parent =TYPE_PNV_CHIP , + .instance_size =sizeof (PnvChipPower8e), + .class_init = pnv_chip_power8e_class_init, +}; + +static void pnv_chip_realize (DeviceState *dev,Error **errp) +{ +PnvChip *chip =PNV_CHIP (dev); +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + pcc->realize (chip, errp); +} + +static Property pnv_chip_properties[] = { +DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,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 char *pnv_get_num_chips (Object *obj,Error **errp) +{ +return g_strdup_printf ("%d" ,POWERNV_MACHINE (obj)->num_chips); +} + +static void pnv_set_num_chips (Object *obj,const char *value,Error **errp) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); +int num_chips; + +if (sscanf (value,"%d" , &num_chips) !=1 ) { +error_setg (errp,"invalid num_chips property: '%s'" , value); + } + +/* +* FIXME: should we decide on how many chips we can create based +* on #cores and Venice vs. Murano vs. Naples chip type etc..., +*/ + pnv->num_chips = num_chips; +} + +static void powernv_machine_initfn (Object *obj) +{ +PnvMachineState *pnv =POWERNV_MACHINE (obj); + pnv->num_chips =1 ; + +object_property_add_str (obj,"num-chips" , pnv_get_num_chips, + pnv_set_num_chips,NULL ); +object_property_set_description (obj,"num-chips" , +"Specifies the number of processor chips" , +NULL ); }static void powernv_machine_class_init (ObjectClass *oc,void *data)@@ -233,12 +382,17 @@ 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_init (powernv_machine_register_types)include/hw/ppc/pnv.h +71
-0@@ -20,6 +20,74 @@#define _PPC_PNV_H#include "hw/boards.h" +#include "hw/sysbus.h" + +#define TYPE_PNV_CHIP "powernv-chip" +#define PNV_CHIP (obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP) +#define PNV_CHIP_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvChipClass, (klass), TYPE_PNV_CHIP) +#define PNV_CHIP_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvChipClass, (obj), TYPE_PNV_CHIP) + +typedef enum PnvChipType { +PNV_CHIP_P8E ,/* AKA Murano (default) */ +PNV_CHIP_P8 ,/* AKA Venice */ +PNV_CHIP_P8NVL ,/* AKA Naples */ +}PnvChipType ; + +typedef struct PnvChip { +/*< private >*/ +SysBusDevice parent_obj; + +/*< public >*/ +uint32_t chip_id; +}PnvChip ; + +typedef struct PnvChipClass { +/*< private >*/ +SysBusDeviceClass parent_class; +/*< public >*/ +const char *cpu_model; +PnvChipType chip_type; +uint64_t chip_f000f; + +void (*realize)(PnvChip *dev,Error **errp); +}PnvChipClass ; + +#define TYPE_PNV_CHIP "powernv-chip" + +#define TYPE_PNV_CHIP_POWER8E "powernv-chip-POWER8E" +#define PNV_CHIP_POWER8E (obj) \ + OBJECT_CHECK(PnvChipPower8e, (obj), TYPE_PNV_CHIP_POWER8E) + +typedef struct PnvChipPower8e { +PnvChip pnv_chip; +}PnvChipPower8e ; + +#define TYPE_PNV_CHIP_POWER8 "powernv-chip-POWER8" +#define PNV_CHIP_POWER8 (obj) \ + OBJECT_CHECK(PnvChipPower8, (obj), TYPE_PNV_CHIP_POWER8) + +typedef struct PnvChipPower8 { +PnvChip pnv_chip; +}PnvChipPower8 ; + +#define TYPE_PNV_CHIP_POWER8NVL "powernv-chip-POWER8NVL" +#define PNV_CHIP_POWER8NVL (obj) \ + OBJECT_CHECK(PnvChipPower8NVL, (obj), TYPE_PNV_CHIP_POWER8NVL) + +typedef struct PnvChipPower8NVL { +PnvChip pnv_chip; +}PnvChipPower8NVL ; + +/* +* This generates a HW chip id depending on an index: +* +* 0x0, 0x1, 0x10, 0x11, 0x20, 0x21, ... +* +* Is this correct ? +*/ +#define CHIP_HWID (i) ((((i) & 0x3e) << 3) | ((i) & 0x1))#define TYPE_POWERNV_MACHINE MACHINE_TYPE_NAME("powernv")#define POWERNV_MACHINE (obj) \@@ -32,6 +100,9 @@ typedef struct PnvMachineState {uint32_t initrd_base;long initrd_size;hwaddr fdt_addr; + +uint32_t num_chips; + PnvChip **chips; } PnvMachineState;#endif /* _PPC_PNV_H */
Re: [Qemu-devel] [PATCH v2 2/7] ppc/pnv: add a PnvChip object
Quoted 97 lines · Cédric Le Goater
Quoted 50 lines · David Gibson
Quoted 49 lines · Cédric Le Goater
This 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, specific init 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.
Signed-off-by Cédric Le Goater <[email protected]>---
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.Maybe this object deserves its own file
hw/ppc/pnv_chip.c?hw/ppc/pnv.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 71 ++++++++++++++++++++++++ 2 files changed, 225 insertions(+)hw/ppc/pnv.c +7
-0@@ -168,6 +168,8 @@ static void ppc_powernv_init(MachineState *machine)char *fw_filename;long fw_size;long kernel_size; +int i; +char *chip_typename;/* allocate RAM */ if (ram_size < (1 *G_BYTE )) {@@ -212,6 +214,153 @@ static void ppc_powernv_init(MachineState *machine)exit (1 ); } } + +/* Create the processor chips */ + chip_typename =g_strdup_printf (TYPE_PNV_CHIP "-%s" , machine->cpu_model); + + pnv->chips = g_new0(PnvChip *, pnv->num_chips);Quoted 8 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 225
Quoted 4 lines
hw/ppc/pnv.c +4
-0+for (i =0 ; i < pnv->num_chips; i++) { +Object *chip =object_new (chip_typename); +object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_bool (chip, true,"realized" , &error_abort);I'm guessing these could fail due to bad user supplied parameters, not just internal bugs. In which case this should be
&error_fatalrather than&error_abort.yes.
Quoted 13 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 234
Quoted 10 lines
hw/ppc/pnv.c +9
-0+ pnv->chips[i] =PNV_CHIP (chip); + } +g_free (chip_typename); +} + +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) +{ + ; +}I don't think you should need to define an empty realize function. Or is this just a placeholder for things future patches will add?
yes that was the plan but maybe this is a little early.
chip_typeproved to be useful enough for the moment in the full patchset I maintain.P9 will use a xive object when available and not a xics. I think this is when the real big difference will show up. So I should make
realize()optional.Quoted 4 lines
Quoted 4 lines
hw/ppc/pnv.c +4
-0+ +static void pnv_chip_power8nvl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass);Quoted 8 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 243
Quoted 5 lines
hw/ppc/pnv.c +5
-0+PnvChipClass *k =PNV_CHIP_CLASS (klass); + + k->realize = pnv_chip_power8nvl_realize; + k->cpu_model ="POWER8NVL" ; + k->chip_type =PNV_CHIP_P8NVL ;With the new chip class per cpu class, does this
chip_typefield serve any purpose any more?
Quoted 8 lines
It does look a bit redundant, I agree. But it is useful for xscom address translation (P9 is a little different), for xscom devices in general, for core id to pir conversion. It also does for
lpc_irqsupport, which applies to P8NVL (and upper I suppose).Let's keep it for the moment as it serves its purpose, which is to handle small differences without too much cost. If this is going too far, I will propose a set of ops per chip type.
Ok, fair enough.
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 v2 3/7 ppc/pnv: Add XSCOM infrastructure
In reply to Cédric Le GoaterFrom: Benjamin Herrenschmidt <[email protected]>
XSCOM is an interface to a sideband bus provided by the POWER8 chip pervasive unit, which gives access to a number of facilities in the chip that are needed by the OPAL firmware 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.
This provides a simple bus and device type for devices sitting on XSCOM along with some facilities to optionally generate corresponding device-tree nodes
[clg: updated for qemu-2.7
ported on new sPowerNVMachineState which was merged with PnvSystem removed TRACE_XSCOM
fixed checkpatch errors
replaced assert with error_setg in xscom_realize() reworked xscom_create
introduced the use of the chip_class for chip model contants ]
---
They were some discussions on whether we should use a qemu address_space instead of the xscom ranges defined in this patch. I gave it try, it is possible but it brings extra unnecessary calls and complexity. I think the current solution is better.
hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 11 ++ hw/ppc/pnv_xscom.c | 408 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_xscom.h | 75 +++++++++ 5 files changed, 497 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 +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endif
hw/ppc/pnv.c +11 -0
@@ -39,6 +39,8 @@#include "exec/address-spaces.h" #include "qemu/cutils.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_ADDR 0x01000000
@@ -103,6 +105,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,char *buf;const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off; +int i; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));
@@ -142,6 +145,11 @@ static void *powernv_create_fdt(PnvMachineState *pnv,/* Memory */ powernv_populate_memory (fdt); +/* Populate XSCOM for each chip */ +for (i =0 ; i < pnv->num_chips; i++) { +xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); + } +return fdt; }
@@ -305,6 +313,9 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +/* Set up XSCOM bus */ + chip->xscom =xscom_create (chip); + pcc->realize (chip, errp); }
hw/ppc/pnv_xscom.c new file +408 -0
408 lines not on this page · raw message
include/hw/ppc/pnv.h +2 -0
@@ -35,12 +35,14 @@ typedef enum PnvChipType {PNV_CHIP_P8NVL ,/* AKA Naples */ } PnvChipType; +typedef struct XScomBus XScomBus ;typedef struct PnvChip {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ uint32_t chip_id; +XScomBus *xscom; }PnvChip ; typedef struct PnvChipClass {
include/hw/ppc/pnv_xscom.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 73 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
XSCOM is an interface to a sideband bus provided by the POWER8 chip pervasive unit, which gives access to a number of facilities in the chip that are needed by the OPAL firmware 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.
This provides a simple bus and device type for devices sitting on XSCOM along with some facilities to optionally generate corresponding device-tree nodes
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: updated for qemu-2.7
ported on new sPowerNVMachineState which was merged with PnvSystem removedTRACE_XSCOM
fixed checkpatch errors
replaced assert witherror_setginxscom_realize()reworkedxscom_create
introduced the use of thechip_classfor chip model contants ]Signed-off-by Cédric Le Goater <[email protected]>---
They were some discussions on whether we should use a qemu
address_spaceinstead of the xscom ranges defined in this patch. I gave it try, it is possible but it brings extra unnecessary calls and complexity. I think the current solution is better.hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 11 ++ hw/ppc/pnv_xscom.c | 408 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_xscom.h | 75 +++++++++ 5 files changed, 497 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 +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/pnv.c +3
-0@@ -39,6 +39,8 @@#include "exec/address-spaces.h" #include "qemu/cutils.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_ADDR 0x01000000@@ -103,6 +105,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,char *buf;const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off; +int i; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));
hw/ppc/pnv.c static void *powernv_create_fdt(PnvMachineState *pnv, · line 151
Quoted 7 lines
hw/ppc/pnv.c +4
-0@@ -142,6 +145,11 @@ static void *powernv_create_fdt(PnvMachineState *pnv,/* Memory */ powernv_populate_memory (fdt); +/* Populate XSCOM for each chip */ +for (i =0 ; i < pnv->num_chips; i++) { +xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); + }
There will be a bunch of per-chip things in the fdt - I suggest a common function to do all the fdt creation for a single chip. Since you've moved to using the fdt_rw functions exclusively, you don't have the sequence constraints that would have made that awkward previously.
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 317
Quoted 9 lines
hw/ppc/pnv.c +2
-0return fdt; }@@ -305,6 +313,9 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +/* Set up XSCOM bus */ + chip->xscom =xscom_create (chip);
So, this creates the xscom as a new device object, unfortunately doing that from another object's realize() violations QOM lifetime rules as I understand them. I think - I have to admit I'm pretty confused on this topic myself.
You could construct the scom from chip init, then realize it from chip realize, but I think using object_new() (via qdev_create()) from another object's init also breaks the rules. You are however allowed to allocate the scom state statically within the chip and use object_initialize() instead, AIUI.
Alternatively.. it might be simpler to just drop the SCOM as a separate device. I think you could just hang the scom bus directly off the chip object. IIUC the scom is basically the only chip-level control mechanism, so this does make a certain amount of sense.
Quoted 58 lines
hw/ppc/pnv.c +0
-0pcc->realize (chip, errp); }hw/ppc/pnv_xscom.c new file +49
-0@@ -0,0 +1,408 @@ + +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson, IBM Corporation <[email protected]> +* Based on the s390 virtio bus code: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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/>. +*/ + +/* TODO: Add some infrastructure for "random stuff" and FIRs that +* various units might want to deal with without creating actual +* XSCOM devices. +* +* For example, HB LPC XSCOM in the PIBAM +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/hw.h" +#include "sysemu/sysemu.h" +#include "hw/boards.h" +#include "monitor/monitor.h" +#include "hw/loader.h" +#include "elf.h" +#include "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "sysemu/device_tree.h" +#include "hw/ppc/fdt.h" + +#include "hw/ppc/pnv_xscom.h" + +#include <libfdt.h> + +#define TYPE_XSCOM "xscom" +#define XSCOM (obj) OBJECT_CHECK(XScomState, (obj), TYPE_XSCOM) + +#define XSCOM_SIZE 0x800000000ull
hw/ppc/pnv_xscom.c line 59
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+#define XSCOM_BASE (chip) (0x3fc0000000000ull + ((uint64_t)(chip)) * XSCOM_SIZE) + + +typedef struct XScomState { + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + + MemoryRegion mem; + int32_t chip_id;
Merging scom and chip would avoid the duplication of this field too.
Quoted 32 lines
hw/ppc/pnv_xscom.c new file +32
-0+PnvChipClass *chip_class; +XScomBus *bus; +} XScomState; + +static uint32_t xscom_to_pcb_addr (uint64_t addr) +{ + addr &= (XSCOM_SIZE -1 ); +return ((addr >>4 ) & ~0xfull ) | ((addr >>3 ) &0xf ); +} + +static void xscom_complete (uint64_t hmer_bits) +{ +CPUState *cs = current_cpu; +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +cpu_synchronize_state (cs); + env->spr[SPR_HMER ] |= hmer_bits; + +/* XXX Need a CPU helper to set HMER, also handle gneeration +* of HMIs +*/ +} + +static XScomDevice *xscom_find_target (XScomState *s,uint32_t pcb_addr, +uint32_t *range) +{ +BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd);
hw/ppc/pnv_xscom.c line 101
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+unsigned int i; + +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) > pcb_addr) { + *range = i; +return xd; + } + } + }
Hmm.. you could set up a SCOM local address space using the infrastructure in memory.c, rather than doing your own dispatch.
Quoted 192 lines
hw/ppc/pnv_xscom.c new file +192
-0+return NULL ; +} + +static bool xscom_dispatch_read (XScomState *s,uint32_t pcb_addr, +uint64_t *out_val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->read) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->read (xd, range, offset, out_val); +} + +static bool xscom_dispatch_write (XScomState *s,uint32_t pcb_addr,uint64_t val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->write) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->write (xd, range, offset, val); +} + +static uint64_t xscom_read (void *opaque,hwaddr addr,unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); +uint64_t val; + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +case 0xf000f : + val = s->chip_class->chip_f000f; +break ; +case 0x1010c00 :/* PIBAM FIR */ +case 0x1010c03 :/* PIBAM FIR MASK */ +case 0x2020007 :/* ADU stuff */ +case 0x2020009 :/* ADU stuff */ +case 0x202000f :/* ADU stuff */ + val =0 ; +break ; +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 */ + val =0 ; +break ; +default : +if (!xscom_dispatch_read (s, pcba, &val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return 0 ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +return val; +} + +static void xscom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +/* We ignore writes to these */ +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 */ +break ; +default : +if (!xscom_dispatch_write (s, pcba, val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +} + +static const MemoryRegionOps 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 , +}; + +static int xscom_init (SysBusDevice *dev) +{ +XScomState *s =XSCOM (dev); + + s->chip_id =-1 ; +return 0 ; +} + +static void xscom_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +XScomState *s =XSCOM (dev); +char *name; + +if (s->chip_id <0 ) { +error_setg (errp,"invalid chip id '%d'" , s->chip_id); +return ; + } + name =g_strdup_printf ("xscom-%x" , s->chip_id); +memory_region_init_io (&s->mem,OBJECT (s), &xscom_ops, s, name,XSCOM_SIZE ); +sysbus_init_mmio (sbd, &s->mem); +sysbus_mmio_map (sbd,0 ,XSCOM_BASE (s->chip_id)); +} + +static Property xscom_properties[] = { +DEFINE_PROP_INT32 ("chip_id" , XScomState, chip_id,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void xscom_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = xscom_properties; + dc->realize = xscom_realize; + k->init = xscom_init; +} + +static const TypeInfo xscom_info = { + .name =TYPE_XSCOM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XScomState), + .class_init = xscom_class_init, +}; + +static void xscom_bus_class_init (ObjectClass *klass,void *data) +{ +} + +static const TypeInfo xscom_bus_info = { + .name =TYPE_XSCOM_BUS , + .parent =TYPE_BUS , + .class_init = xscom_bus_class_init, + .instance_size =sizeof (XScomBus), +}; + +XScomBus *xscom_create (PnvChip *chip) +{ +DeviceState *dev; +XScomState *xdev; +BusState *qbus; +XScomBus *xb; +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + dev =qdev_create (NULL ,TYPE_XSCOM ); +qdev_prop_set_uint32 (dev,"chip_id" , chip->chip_id); +qdev_init_nofail (dev); + +/* Create bus on bridge device */ + qbus =qbus_create (TYPE_XSCOM_BUS , dev,"xscom" );
hw/ppc/pnv_xscom.c line 303
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+ xb =DO_UPCAST (XScomBus, bus, qbus); + xb->chip_id = chip->chip_id; + xdev =XSCOM (dev); + xdev->bus = xb; + xdev->chip_class = pcc; + +return xb; +} + +int xscom_populate_fdt (XScomBus *xb,void *fdt,int root_offset)
What is the root_offset parameter for, since it is always 0?
hw/ppc/pnv_xscom.c line 313
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+{ +BusChild *bc; +char *name; +const char compat[] ="ibm,power8-xscom\0ibm,xscom" ; +uint64_t reg[] = {cpu_to_be64 (XSCOM_BASE (xb->chip_id)), +cpu_to_be64 (XSCOM_SIZE ) }; +int xscom_offset; + + name =g_strdup_printf ("xscom@%llx" , (unsigned long long ) +be64_to_cpu (reg[0 ]));
Nit: in qemu the PRIx64 etc. macros are usually preferred to (unsigned long long) casts of this type.
Quoted 26 lines
hw/ppc/pnv_xscom.c new file +26
-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" , xb->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)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"compatible" , compat, +sizeof (compat)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"scom-controller" ,NULL ,0 ))); + + QTAILQ_FOREACH(bc, &xb->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xd); +uint32_t reg[MAX_XSCOM_RANGES *2 ]; +unsigned int i, sz =0 ; +void *cp, *p; +int child_offset; + +/* Some XSCOM slaves may not be represented in the DT */ +if (!xc->dt_name) { +continue ; + } + name =g_strdup_printf ("%s@%x" , xc->dt_name, xd->ranges[0 ].addr); + child_offset =fdt_add_subnode (fdt, xscom_offset, name);
hw/ppc/pnv_xscom.c line 349
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+_FDT (child_offset); +g_free (name); +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].size ==0 ) { +break ; + } + reg[sz++] =cpu_to_be32 (xd->ranges[i].addr); + reg[sz++] =cpu_to_be32 (xd->ranges[i].size); + } +_FDT ((fdt_setprop (fdt, child_offset,"reg" , reg, sz *4 )));
Use of fdt_appendprop() might make this a little neater.
Quoted 9 lines
hw/ppc/pnv_xscom.c new file +9
-0+if (xc->devnode) { +_FDT ((xc->devnode (xd, fdt, child_offset))); + } +#define MAX_COMPATIBLE_PROP 1024 + cp = p =g_malloc0 (MAX_COMPATIBLE_PROP ); + i =0 ; +while ((p - cp) <MAX_COMPATIBLE_PROP ) { +int l; +if (xc->dt_compatible[i] ==NULL ) {
hw/ppc/pnv_xscom.c line 368
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+break ; + } + l =strlen (xc->dt_compatible[i]); +if (l >= (MAX_COMPATIBLE_PROP - i)) { +break ; + } +strcpy (p, xc->dt_compatible[i++]); + p += l +1 ; + } +_FDT ((fdt_setprop (fdt, child_offset,"compatible" , cp, p - cp)));
Might it be easier to just require the individual scom device to set the compatible property from its ->devnode callback? That way it can just
const char compat = "foo\0bar\0baz"; fdt_setprop(..., compat, sizeof(compat));
and avoid this fiddling around with arrays.
Quoted 140 lines
hw/ppc/pnv_xscom.c new file +40
-0+ } + +return 0 ; +} + +static int xscom_qdev_init (DeviceState *qdev) +{ +XScomDevice *xdev = (XScomDevice *)qdev; +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xdev); + +if (xc->init) { +return xc->init (xdev); + } +return 0 ; +} + +static void xscom_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *k =DEVICE_CLASS (klass); + k->init = xscom_qdev_init; + k->bus_type =TYPE_XSCOM_BUS ; +} + +static const TypeInfo xscom_dev_info = { + .name =TYPE_XSCOM_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (XScomDevice), + .abstract = true, + .class_size =sizeof (XScomDeviceClass), + .class_init = xscom_device_class_init, +}; + +static void xscom_register_types (void ) +{ +type_register_static (&xscom_info); +type_register_static (&xscom_bus_info); +type_register_static (&xscom_dev_info); +} + +type_init (xscom_register_types)include/hw/ppc/pnv.h +2
-0@@ -35,12 +35,14 @@ typedef enum PnvChipType {PNV_CHIP_P8NVL ,/* AKA Naples */ } PnvChipType; +typedef struct XScomBus XScomBus ;typedef struct PnvChip {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ uint32_t chip_id; +XScomBus *xscom; }PnvChip ; typedef struct PnvChipClass {include/hw/ppc/pnv_xscom.h new file +75
-0@@ -0,0 +1,75 @@ +#ifndef _HW_XSCOM_H +#define _HW_XSCOM_H +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson <[email protected]>, IBM Corp. +* Based on the s390 virtio bus definitions: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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 <hw/ppc/pnv.h> + +#define TYPE_XSCOM_DEVICE "xscom-device" +#define XSCOM_DEVICE (obj) \ + OBJECT_CHECK(XScomDevice, (obj), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XScomDeviceClass, (klass), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(XScomDeviceClass, (obj), TYPE_XSCOM_DEVICE) + +#define TYPE_XSCOM_BUS "xscom-bus" +#define XSCOM_BUS (obj) OBJECT_CHECK(XScomBus, (obj), TYPE_XSCOM_BUS) + +typedef struct XScomDevice XScomDevice ; +typedef struct XScomBus XScomBus ; + +typedef struct XScomDeviceClass { +DeviceClass parent_class; + +const char *dt_name; +const char **dt_compatible; +int (*init)(XScomDevice *dev); +int (*devnode)(XScomDevice *dev,void *fdt,int offset); + +/* Actual XScom accesses */ +bool (*read)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t *out_val); +bool (*write)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t val); +}XScomDeviceClass ; + +typedef struct XScomRange { +uint32_t addr; +uint32_t size; +}XScomRange ; + +struct XScomDevice { +DeviceState qdev; +#define MAX_XSCOM_RANGES 4 +struct XScomRange ranges[MAX_XSCOM_RANGES ]; +}; + +struct XScomBus { +BusState bus; +uint32_t chip_id; +}; + +extern XScomBus *xscom_create (PnvChip *chip); +extern int xscom_populate_fdt (XScomBus *xscom,void *fdt,int offset); + + +#endif /* _HW_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 v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 15 lines · David Gibson
Quoted 1 line
+static XScomDevice *xscom_find_target(XScomState *s,
uint32_t
pcb_addr,hw/ppc/pnv_xscom.c
Quoted 12 lines
+
uint32_t*range)hw/ppc/pnv_xscom.c new file +11
-0+{ + BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { + DeviceState *qd = bc->child; + XScomDevice *xd = XSCOM_DEVICE(qd); + unsigned int i; + + for (i = 0; i < MAX_XSCOM_RANGES; i++) { + if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) >
pcb_addr) {
Quoted 8 lines
Quoted 5 lines
+ *range = i;
+ return xd;
+ }
+ }
+ }Hmm.. you could set up a SCOM local address space using the infrastructure in
memory.c, rather than doing your own dispatch.
There are pros and cons to this approach. The memory.c stuff comes with quite a lot of baggage, not all of it very shinny to be honest ;-) I still *hate* how it forces upon us a whole 128-bit integer arithmetic library just so that it can represent 1_0000_0000_0000_0000 ...
It would be make more sense to use inclusive start/end instead and stick to 64-bits.
That being said, we could do that. We'd have to shift the XSCOM addresses left by 3 since each address is an 8 bytes reigster and forbid non-8-bytes accesses.
Ben.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 21 lines · David Gibson
Quoted 1 line
+static XScomDevice *xscom_find_target(XScomState *s,
uint32_t
pcb_addr,hw/ppc/pnv_xscom.c
Quoted 12 lines
+
uint32_t*range)hw/ppc/pnv_xscom.c new file +11
-0+{ + BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { + DeviceState *qd = bc->child; + XScomDevice *xd = XSCOM_DEVICE(qd); + unsigned int i; + + for (i = 0; i < MAX_XSCOM_RANGES; i++) { + if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) >
pcb_addr) {Quoted 5 lines
+ *range = i;
+ return xd;
+ }
+ }
+ }
Quoted 7 lines
Quoted 2 lines
Hmm.. you could set up a SCOM local address space using the infrastructure in
memory.c, rather than doing your own dispatch.There are pros and cons to this approach. The
memory.cstuff comes with quite a lot of baggage, not all of it very shinny to be honest ;-) I still *hate* how it forces upon us a whole 128-bit integer arithmetic library just so that it can represent 1_0000_0000_0000_0000 ...
Ugh, yeah. I tried to argue against this when it first came in, but was overruled.
Quoted 6 lines
It would be make more sense to use inclusive start/end instead and stick to 64-bits.
That being said, we could do that. We'd have to shift the XSCOM addresses left by 3 since each address is an 8 bytes reigster and forbid non-8-bytes accesses.
Ok. I'm not particularly fussed either way.
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 v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 34 lines · David Gibson
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 21 lines · David Gibson
Quoted 1 line
+static XScomDevice *xscom_find_target(XScomState *s,
uint32_t
pcb_addr,hw/ppc/pnv_xscom.c
Quoted 12 lines
hw/ppc/pnv_xscom.c new file +12
-0+ uint32_t *range) +{ + BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { + DeviceState *qd = bc->child; + XScomDevice *xd = XSCOM_DEVICE(qd); + unsigned int i; + + for (i = 0; i < MAX_XSCOM_RANGES; i++) { + if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) >
pcb_addr) {Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+ *range = i; +return xd; + } + } + }Quoted 7 lines
Quoted 2 lines
Hmm.. you could set up a SCOM local address space using the infrastructure in
memory.c, rather than doing your own dispatch.There are pros and cons to this approach. The
memory.cstuff comes with quite a lot of baggage, not all of it very shinny to be honest ;-) I still *hate* how it forces upon us a whole 128-bit integer arithmetic library just so that it can represent 1_0000_0000_0000_0000 ...Ugh, yeah. I tried to argue against this when it first came in, but was overruled.
Quoted 8 lines
Quoted 6 lines
It would be make more sense to use inclusive start/end instead and stick to 64-bits.
That being said, we could do that. We'd have to shift the XSCOM addresses left by 3 since each address is an 8 bytes reigster and forbid non-8-bytes accesses.
Ok. I'm not particularly fussed either way.
The change does seem too invasive. I can give it a try in next version.
When a memory region is triggered, the impacted device will have to convert the address with xscom_to_pcb_addr(). There is some dependency on the chip model because the translation is different. That would be an extra op in the xscom device model I guess.
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
Thanks,
C.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 8 lines · Cédric Le Goater
The change does seem too invasive. I can give it a try in next version.
When a memory region is triggered, the impacted device will have to convert the address with
xscom_to_pcb_addr(). There is some dependency on the chip model because the translation is different. That would be an extra op in the xscom device model I guess.
No. If you split the XSCOM bus from the MMIO -> XSCOM bridge (the ADU) then the conversion only happens in the former. You don't directly route the MMIOs over ! You intercept the MMIOs and use use the address_space_rw to "generate" the XSCOM accesses on the other side, like I do for the LPC bus.
We need that anyway because of the way XSCOMs can manipulate the HMER etc...
Quoted 3 lines
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 9 lines · Benjamin Herrenschmidt
d be an extra op in the xscom device model I guess.
No. If you split the XSCOM bus from the MMIO -> XSCOM bridge (the ADU)
then the conversion only happens in the former. You don't directly route the MMIOs over ! You intercept the MMIOs and use use theaddress_space_rwto "generate" the XSCOM accesses on the other side, like I do for the LPC bus.
Quoted 7 lines
We need that anyway because of the way XSCOMs can manipulate the HMER etc...
Quoted 4 lines
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
In fact, if you do the above, you no longer need a XSCOM device...
A number of "devices" can exist below a chip, all they need to have XSCOMs is to register memory regions that are child of that chip's xscom_region.
For device-tree, well, we could have a generic interface that anything that can populate DT has and iterate through them. Or make a "chiplet" class or something.
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
d be an extra op in the xscom device model I guess.
No. If you split the XSCOM bus from the MMIO -> XSCOM bridge (the ADU)
then the conversion only happens in the former. You don't directly route the MMIOs over ! You intercept the MMIOs and use use theaddress_space_rwto "generate" the XSCOM accesses on the other side, like I do for the LPC bus.Quoted 7 lines
We need that anyway because of the way XSCOMs can manipulate the HMER etc...
Quoted 4 lines
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
Quoted 5 lines
In fact, if you do the above, you no longer need a XSCOM device...
A number of "devices" can exist below a chip, all they need to have XSCOMs is to register memory regions that are child of that chip's
xscom_region.
yes. To hack my way through again, I have added a memory region under the XScomDevice, but we should have a list like the ranges[] because of the PHB3 PCBQs.
Quoted 3 lines
For device-tree, well, we could have a generic interface that anything that can populate DT has and iterate through them. Or make a "chiplet" class or something.
yes, something like the XScomDeviceClass, which serves well the purpose anyhow.
Thanks,
C.
Quoted 3 lines
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 4 lines · Cédric Le Goater
yes. To hack my way through again, I have added a memory region under the XScomDevice, but we should have a list like the ranges[] because of the PHB3 PCBQs.
You have the parent region in the chip. Then each device can create and attach memory regions below if it feels like it. No need to have a generic XScomDevice with a fixed list of regions I think. I mean, you can ... but you don't have to.
Quoted 6 lines
Quoted 3 lines
For device-tree, well, we could have a generic interface that anything that can populate DT has and iterate through them. Or make a "chiplet" class or something.
yes, something like the XScomDeviceClass, which serves well the purpose anyhow.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to Benjamin HerrenschmidtQuoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · Cédric Le Goater
The change does seem too invasive. I can give it a try in next version.
When a memory region is triggered, the impacted device will have to convert the address with
xscom_to_pcb_addr(). There is some dependency on the chip model because the translation is different. That would be an extra op in the xscom device model I guess.
Quoted 5 lines
No. If you split the XSCOM bus from the MMIO -> XSCOM bridge (the ADU) then the conversion only happens in the former. You don't directly route the MMIOs over ! You intercept the MMIOs and use use the
address_space_rwto "generate" the XSCOM accesses on the other side, like I do for the LPC bus.
Oh.. wait.. that is what I had in mind, I think I misinterpreted something one of you said.
Quoted 9 lines
We need that anyway because of the way XSCOMs can manipulate the HMER etc...
Quoted 3 lines
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
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 v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to Benjamin HerrenschmidtQuoted 10 lines · Benjamin Herrenschmidt
Quoted 8 lines · Cédric Le Goater
The change does seem too invasive. I can give it a try in next version.
When a memory region is triggered, the impacted device will have to convert the address with
xscom_to_pcb_addr(). There is some dependency on the chip model because the translation is different. That would be an extra op in the xscom device model I guess.
Quoted 5 lines
No. If you split the XSCOM bus from the MMIO -> XSCOM bridge (the ADU) then the conversion only happens in the former. You don't directly route the MMIOs over ! You intercept the MMIOs and use use the
address_space_rwto "generate" the XSCOM accesses on the other side, like I do for the LPC bus.
Yes. That is what I have been experimenting with. The mmio read/write ops and the current xscom read/write ops are quite compatible so It did cost too much to do so :
+static uint64_t pnv_lpc_xscom_mr_read(void *opaque, hwaddr addr, unsigned size) +{
+ XScomDevice *xd = XSCOM_DEVICE(opaque);
+ uint64_t val = 0;
+
+ pnv_lpc_xscom_read(xd, 0, xscom_to_pcb_addr(xd->chip_type, addr), &val);
+ return val;
+}
+
+static void pnv_lpc_xscom_mr_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+ XScomDevice *xd = XSCOM_DEVICE(opaque);
+ pnv_lpc_xscom_write(xd, 0, xscom_to_pcb_addr(xd->chip_type, addr), val);
+}
+
+static const MemoryRegionOps lpc_xscom_mr_ops = {
+ .read = pnv_lpc_xscom_mr_read,
+ .write = pnv_lpc_xscom_mr_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_lpc_realize(DeviceState *dev, Error **errp)
{
PnvLpcController *lpc = PNV_LPC_CONTROLLER(dev);+ XScomBus *bus = XSCOM_BUS(qdev_get_parent_bus(dev));
/* LPC XSCOM address is fixed */
+ memory_region_init_io(&lpc->xd.xscom_mr, OBJECT(dev), &lpc_xscom_mr_ops,
+ lpc, "lpc-xscom", 4 * 8);
+ memory_region_add_subregion(bus->xscom_mr, 0xb00200, &lpc->xd.xscom_mr);
+
lpc->xd.ranges[0].addr = 0xb0020;
lpc->xd.ranges[0].size = 4;To hack my way through, I have put the address space and the backend region under the XscomBus, bc it's easy to capture from the device. So that might be a reason to keep this bus/device model.
The xscom_to_pcb_addr() translation should probably done at the upper level, at the bridge/ADU level. I think that is what you are asking for above.
As for the mapping, I don't think it should be here. It should be done at the chip/bus level which controls the address space, but not in the devices.
Quoted 2 lines
We need that anyway because of the way XSCOMs can manipulate the HMER etc...
ah. Another thing I need to look at !
Thanks,
C.
Quoted 5 lines
Quoted 3 lines
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 17 lines · Cédric Le Goater
+staticuint64_tpnv_lpc_xscom_mr_read(void *opaque, hwaddr addr, unsigned size)(quoted diff) +5
-0+{ + XScomDevice *xd = XSCOM_DEVICE(opaque); + uint64_t val = 0; + + pnv_lpc_xscom_read(xd, 0, xscom_to_pcb_addr(xd->chip_type,addr), &val);
+ return val;(quoted diff) +7
-0+} + +static void pnv_lpc_xscom_mr_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + XScomDevice *xd = XSCOM_DEVICE(opaque); + pnv_lpc_xscom_write(xd, 0, xscom_to_pcb_addr(xd->chip_type,
Quoted 3 lines
addr), val);
+}
I don't understand. That's not at all why I suggested or I'm missing something.
What I suggest is that you have a memory region per-chip (which is NOT hooked onto the main address space) which represents the PCB space. Calling xscom_region. Hook it up to its own address_space.
Thus, the various devices (LPC, OCC, etc...) all just register a sub- region of that address space using the PCB addresses directly (well, shifted left by 3 because it's 8 bytes registers but that's it).
The XSCOM "controller" AKA ADU is the one doing the bridge. It registers an MMIO region in the main address space (SysBusDevice ?) and from the MMIO accessors, it does the address mangling, and use address_space_rw() to trigger accesses onto that chip's xscom_region.
Ben.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 16 lines · Benjamin Herrenschmidt
Quoted 15 lines · Cédric Le Goater
+static
uint64_tpnv_lpc_xscom_mr_read(void *opaque, hwaddr addr, unsigned size)(quoted diff) +5
-0+{ + XScomDevice *xd = XSCOM_DEVICE(opaque); + uint64_t val = 0; + + pnv_lpc_xscom_read(xd, 0, xscom_to_pcb_addr(xd->chip_type,addr), &val);
(quoted diff) +6
-0+ return val; +} + +static void pnv_lpc_xscom_mr_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{
Quoted 8 lines
Quoted 5 lines
(quoted diff) +2
-0+ XScomDevice *xd = XSCOM_DEVICE(opaque); + pnv_lpc_xscom_write(xd, 0, xscom_to_pcb_addr(xd->chip_type,addr), val);
+}I don't understand. That's not at all why I suggested or I'm missing something.
This was a preliminary hack on the full powernv tree to study the question. I made the two options cohabitate in the same qemu to see what were the issues and possible solutions.
The result is very much what you describe below. I need to start from the beginning now, and not the end, to make something cleaner.
Quoted 4 lines
What I suggest is that you have a memory region per-chip (which is NOT hooked onto the main address space) which represents the PCB space. Calling
xscom_region. Hook it up to its ownaddress_space.
Quoted 8 lines
Thus, the various devices (LPC, OCC, etc...) all just register a sub- region of that address space using the PCB addresses directly (well, shifted left by 3 because it's 8 bytes registers but that's it).
The XSCOM "controller" AKA ADU is the one doing the bridge. It registers an MMIO region in the main address space (SysBusDevice ?) and from the MMIO accessors, it does the address mangling, and use
address_space_rw()to trigger accesses onto that chip'sxscom_region.
yes. this is what your XSCOM bridge does already.
name = g_strdup_printf("xscom-%x", s->chip_id);
memory_region_init_io(&s->mem, OBJECT(s), &xscom_ops, s, name, XSCOM_SIZE);
sysbus_init_mmio(sbd, &s->mem);
sysbus_mmio_map(sbd, 0, XSCOM_BASE(s->chip_id));Thanks,
C.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to Cédric Le GoaterQuoted 45 lines · Cédric Le Goater
Quoted 34 lines · David Gibson
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 21 lines · David Gibson
Quoted 1 line
+static XScomDevice *xscom_find_target(XScomState *s,
uint32_t
pcb_addr,hw/ppc/pnv_xscom.c
Quoted 12 lines
hw/ppc/pnv_xscom.c new file +12
-0+ uint32_t *range) +{ + BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { + DeviceState *qd = bc->child; + XScomDevice *xd = XSCOM_DEVICE(qd); + unsigned int i; + + for (i = 0; i < MAX_XSCOM_RANGES; i++) { + if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) >
pcb_addr) {Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+ *range = i; +return xd; + } + } + }Quoted 7 lines
Quoted 2 lines
Hmm.. you could set up a SCOM local address space using the infrastructure in
memory.c, rather than doing your own dispatch.There are pros and cons to this approach. The
memory.cstuff comes with quite a lot of baggage, not all of it very shinny to be honest ;-) I still *hate* how it forces upon us a whole 128-bit integer arithmetic library just so that it can represent 1_0000_0000_0000_0000 ...Ugh, yeah. I tried to argue against this when it first came in, but was overruled.
Quoted 8 lines
Quoted 6 lines
It would be make more sense to use inclusive start/end instead and stick to 64-bits.
That being said, we could do that. We'd have to shift the XSCOM addresses left by 3 since each address is an 8 bytes reigster and forbid non-8-bytes accesses.
Ok. I'm not particularly fussed either way.
Quoted 7 lines
The change does seem too invasive. I can give it a try in next version.
When a memory region is triggered, the impacted device will have to convert the address with
xscom_to_pcb_addr(). There is some dependency on the chip model because the translation is different. That would be an extra op in the xscom device model I guess.
Actually, I was still thinking of having an MR for the scom interface unit, which does the xscom_to_pcb_addr() then re-issues the access in the PCB address space.
But your suggestion might work too.
Quoted 8 lines
Also, the main purpose of the XscomBus is to loop on the devices to populate the device tree. I am wondering if we could just use a simple list under the chip for that purpose.
Thanks,
C.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to David GibsonQuoted 77 lines · David Gibson
Quoted 76 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
XSCOM is an interface to a sideband bus provided by the POWER8 chip pervasive unit, which gives access to a number of facilities in the chip that are needed by the OPAL firmware 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.
This provides a simple bus and device type for devices sitting on XSCOM along with some facilities to optionally generate corresponding device-tree nodes
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: updated for qemu-2.7
ported on new sPowerNVMachineState which was merged with PnvSystem removedTRACE_XSCOM
fixed checkpatch errors
replaced assert witherror_setginxscom_realize()reworkedxscom_create
introduced the use of thechip_classfor chip model contants ]Signed-off-by Cédric Le Goater <[email protected]>---
They were some discussions on whether we should use a qemu
address_spaceinstead of the xscom ranges defined in this patch. I gave it try, it is possible but it brings extra unnecessary calls and complexity. I think the current solution is better.hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 11 ++ hw/ppc/pnv_xscom.c | 408 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_xscom.h | 75 +++++++++ 5 files changed, 497 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 +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/pnv.c +3
-0@@ -39,6 +39,8 @@#include "exec/address-spaces.h" #include "qemu/cutils.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_ADDR 0x01000000@@ -103,6 +105,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,char *buf;const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off; +int i; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -142,6 +145,11 @@ static void *powernv_create_fdt(PnvMachineState *pnv,/* Memory */ powernv_populate_memory (fdt);
Quoted 9 lines
hw/ppc/pnv.c static void *powernv_create_fdt(PnvMachineState *pnv, · line 151
Quoted 4 lines
hw/ppc/pnv.c +4
-0+/* Populate XSCOM for each chip */ +for (i =0 ; i < pnv->num_chips; i++) { +xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); + }There will be a bunch of per-chip things in the fdt - I suggest a common function to do all the fdt creation for a single chip. Since you've moved to using the
fdt_rwfunctions exclusively, you don't have the sequence constraints that would have made that awkward previously.
ok.
Quoted 21 lines
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 317
Quoted 9 lines
hw/ppc/pnv.c +2
-0return fdt; }@@ -305,6 +313,9 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +/* Set up XSCOM bus */ + chip->xscom =xscom_create (chip);So, this creates the xscom as a new device object, unfortunately doing that from another object's
realize()violations QOM lifetime rules as I understand them. I think - I have to admit I'm pretty confused on this topic myself.You could construct the scom from chip init, then realize it from chip realize, but I think using
object_new()(viaqdev_create()) from another object's init also breaks the rules. You are however allowed to allocate the scom state statically within the chip and useobject_initialize()instead, AIUI.
Quoted 4 lines
Alternatively.. it might be simpler to just drop the SCOM as a separate device. I think you could just hang the scom bus directly off the chip object. IIUC the scom is basically the only chip-level control mechanism, so this does make a certain amount of sense.
yes. I am exposing more and more stuff of the chip object under the xscom object so we should merge them. I agree. We will still need some XScomDevice of some sort.
Quoted 62 lines
Quoted 62 lines
hw/ppc/pnv.c +0
-0pcc->realize (chip, errp); }hw/ppc/pnv_xscom.c new file +53
-0@@ -0,0 +1,408 @@ + +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson, IBM Corporation <[email protected]> +* Based on the s390 virtio bus code: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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/>. +*/ + +/* TODO: Add some infrastructure for "random stuff" and FIRs that +* various units might want to deal with without creating actual +* XSCOM devices. +* +* For example, HB LPC XSCOM in the PIBAM +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/hw.h" +#include "sysemu/sysemu.h" +#include "hw/boards.h" +#include "monitor/monitor.h" +#include "hw/loader.h" +#include "elf.h" +#include "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "sysemu/device_tree.h" +#include "hw/ppc/fdt.h" + +#include "hw/ppc/pnv_xscom.h" + +#include <libfdt.h> + +#define TYPE_XSCOM "xscom" +#define XSCOM (obj) OBJECT_CHECK(XScomState, (obj), TYPE_XSCOM) + +#define XSCOM_SIZE 0x800000000ull +#define XSCOM_BASE (chip) (0x3fc0000000000ull + ((uint64_t)(chip)) * XSCOM_SIZE) + + +typedef struct XScomState {
Quoted 8 lines
hw/ppc/pnv_xscom.c line 59
Quoted 6 lines
hw/ppc/pnv_xscom.c new file +6
-0+/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion mem; +int32_t chip_id;Merging scom and chip would avoid the duplication of this field too.
yes.
Quoted 37 lines
Quoted 37 lines
hw/ppc/pnv_xscom.c new file +37
-0+PnvChipClass *chip_class; +XScomBus *bus; +} XScomState; + +static uint32_t xscom_to_pcb_addr (uint64_t addr) +{ + addr &= (XSCOM_SIZE -1 ); +return ((addr >>4 ) & ~0xfull ) | ((addr >>3 ) &0xf ); +} + +static void xscom_complete (uint64_t hmer_bits) +{ +CPUState *cs = current_cpu; +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +cpu_synchronize_state (cs); + env->spr[SPR_HMER ] |= hmer_bits; + +/* XXX Need a CPU helper to set HMER, also handle gneeration +* of HMIs +*/ +} + +static XScomDevice *xscom_find_target (XScomState *s,uint32_t pcb_addr, +uint32_t *range) +{ +BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +unsigned int i; + +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) > pcb_addr) {
Quoted 8 lines
hw/ppc/pnv_xscom.c line 101
Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+ *range = i; +return xd; + } + } + }Hmm.. you could set up a SCOM local address space using the infrastructure in
memory.c, rather than doing your own dispatch.
I need to study this option a little deeper.
Quoted 197 lines
Quoted 197 lines
hw/ppc/pnv_xscom.c new file +196
-0+return NULL ; +} + +static bool xscom_dispatch_read (XScomState *s,uint32_t pcb_addr, +uint64_t *out_val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->read) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->read (xd, range, offset, out_val); +} + +static bool xscom_dispatch_write (XScomState *s,uint32_t pcb_addr,uint64_t val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->write) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->write (xd, range, offset, val); +} + +static uint64_t xscom_read (void *opaque,hwaddr addr,unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); +uint64_t val; + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +case 0xf000f : + val = s->chip_class->chip_f000f; +break ; +case 0x1010c00 :/* PIBAM FIR */ +case 0x1010c03 :/* PIBAM FIR MASK */ +case 0x2020007 :/* ADU stuff */ +case 0x2020009 :/* ADU stuff */ +case 0x202000f :/* ADU stuff */ + val =0 ; +break ; +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 */ + val =0 ; +break ; +default : +if (!xscom_dispatch_read (s, pcba, &val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return 0 ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +return val; +} + +static void xscom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +/* We ignore writes to these */ +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 */ +break ; +default : +if (!xscom_dispatch_write (s, pcba, val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +} + +static const MemoryRegionOps 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 , +}; + +static int xscom_init (SysBusDevice *dev) +{ +XScomState *s =XSCOM (dev); + + s->chip_id =-1 ; +return 0 ; +} + +static void xscom_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +XScomState *s =XSCOM (dev); +char *name; + +if (s->chip_id <0 ) { +error_setg (errp,"invalid chip id '%d'" , s->chip_id); +return ; + } + name =g_strdup_printf ("xscom-%x" , s->chip_id); +memory_region_init_io (&s->mem,OBJECT (s), &xscom_ops, s, name,XSCOM_SIZE ); +sysbus_init_mmio (sbd, &s->mem); +sysbus_mmio_map (sbd,0 ,XSCOM_BASE (s->chip_id)); +} + +static Property xscom_properties[] = { +DEFINE_PROP_INT32 ("chip_id" , XScomState, chip_id,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void xscom_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = xscom_properties; + dc->realize = xscom_realize; + k->init = xscom_init; +} + +static const TypeInfo xscom_info = { + .name =TYPE_XSCOM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XScomState), + .class_init = xscom_class_init, +}; + +static void xscom_bus_class_init (ObjectClass *klass,void *data) +{ +} + +static const TypeInfo xscom_bus_info = { + .name =TYPE_XSCOM_BUS , + .parent =TYPE_BUS , + .class_init = xscom_bus_class_init, + .instance_size =sizeof (XScomBus), +}; + +XScomBus *xscom_create (PnvChip *chip) +{ +DeviceState *dev; +XScomState *xdev; +BusState *qbus; +XScomBus *xb; +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + dev =qdev_create (NULL ,TYPE_XSCOM ); +qdev_prop_set_uint32 (dev,"chip_id" , chip->chip_id); +qdev_init_nofail (dev); + +/* Create bus on bridge device */ + qbus =qbus_create (TYPE_XSCOM_BUS , dev,"xscom" ); + xb =DO_UPCAST (XScomBus, bus, qbus); + xb->chip_id = chip->chip_id; + xdev =XSCOM (dev); + xdev->bus = xb;
Quoted 8 lines
hw/ppc/pnv_xscom.c line 303
Quoted 6 lines
hw/ppc/pnv_xscom.c new file +6
-0+ xdev->chip_class = pcc; + +return xb; +} + +int xscom_populate_fdt (XScomBus *xb,void *fdt,int root_offset)What is the
root_offsetparameter for, since it is always 0?
yes ...
Quoted 5 lines
Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+{ +BusChild *bc; +char *name; +const char compat[] ="ibm,power8-xscom\0ibm,xscom" ; +uint64_t reg[] = {cpu_to_be64 (XSCOM_BASE (xb->chip_id)),
Quoted 8 lines
hw/ppc/pnv_xscom.c line 313
Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+ cpu_to_be64(XSCOM_SIZE) }; +int xscom_offset; + + name =g_strdup_printf ("xscom@%llx" , (unsigned long long ) +be64_to_cpu (reg[0 ]));Nit: in qemu the PRIx64 etc. macros are usually preferred to (unsigned long long) casts of this type.
sure.
Quoted 30 lines
Quoted 30 lines
hw/ppc/pnv_xscom.c new file +30
-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" , xb->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)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"compatible" , compat, +sizeof (compat)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"scom-controller" ,NULL ,0 ))); + + QTAILQ_FOREACH(bc, &xb->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xd); +uint32_t reg[MAX_XSCOM_RANGES *2 ]; +unsigned int i, sz =0 ; +void *cp, *p; +int child_offset; + +/* Some XSCOM slaves may not be represented in the DT */ +if (!xc->dt_name) { +continue ; + } + name =g_strdup_printf ("%s@%x" , xc->dt_name, xd->ranges[0 ].addr); + child_offset =fdt_add_subnode (fdt, xscom_offset, name); +_FDT (child_offset); +g_free (name); +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].size ==0 ) {
Quoted 8 lines
hw/ppc/pnv_xscom.c line 349
Quoted 6 lines
hw/ppc/pnv_xscom.c new file +6
-0+break ; + } + reg[sz++] =cpu_to_be32 (xd->ranges[i].addr); + reg[sz++] =cpu_to_be32 (xd->ranges[i].size); + } +_FDT ((fdt_setprop (fdt, child_offset,"reg" , reg, sz *4 )));Use of
fdt_appendprop()might make this a little neater.
ok.
Quoted 20 lines
Quoted 9 lines
hw/ppc/pnv_xscom.c new file +9
-0+if (xc->devnode) { +_FDT ((xc->devnode (xd, fdt, child_offset))); + } +#define MAX_COMPATIBLE_PROP 1024 + cp = p =g_malloc0 (MAX_COMPATIBLE_PROP ); + i =0 ; +while ((p - cp) <MAX_COMPATIBLE_PROP ) { +int l; +if (xc->dt_compatible[i] ==NULL ) {hw/ppc/pnv_xscom.c line 368
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+break ; + } + l =strlen (xc->dt_compatible[i]); +if (l >= (MAX_COMPATIBLE_PROP - i)) { +break ; + } +strcpy (p, xc->dt_compatible[i++]); + p += l +1 ; + } +_FDT ((fdt_setprop (fdt, child_offset,"compatible" , cp, p - cp)));
Quoted 7 lines
Might it be easier to just require the individual scom device to set the compatible property from its ->devnode callback? That way it can just
const char compat = "foo\0bar\0baz"; fdt_setprop(..., compat, sizeof(compat));and avoid this fiddling around with arrays.
Yes. xscom_populate_fdt() will shrink quite a bit. This is a good idea.
Thanks,
C.
Quoted 141 lines
Quoted 140 lines
hw/ppc/pnv_xscom.c new file +40
-0+ } + +return 0 ; +} + +static int xscom_qdev_init (DeviceState *qdev) +{ +XScomDevice *xdev = (XScomDevice *)qdev; +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xdev); + +if (xc->init) { +return xc->init (xdev); + } +return 0 ; +} + +static void xscom_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *k =DEVICE_CLASS (klass); + k->init = xscom_qdev_init; + k->bus_type =TYPE_XSCOM_BUS ; +} + +static const TypeInfo xscom_dev_info = { + .name =TYPE_XSCOM_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (XScomDevice), + .abstract = true, + .class_size =sizeof (XScomDeviceClass), + .class_init = xscom_device_class_init, +}; + +static void xscom_register_types (void ) +{ +type_register_static (&xscom_info); +type_register_static (&xscom_bus_info); +type_register_static (&xscom_dev_info); +} + +type_init (xscom_register_types)include/hw/ppc/pnv.h +2
-0@@ -35,12 +35,14 @@ typedef enum PnvChipType {PNV_CHIP_P8NVL ,/* AKA Naples */ } PnvChipType; +typedef struct XScomBus XScomBus ;typedef struct PnvChip {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ uint32_t chip_id; +XScomBus *xscom; }PnvChip ; typedef struct PnvChipClass {include/hw/ppc/pnv_xscom.h new file +75
-0@@ -0,0 +1,75 @@ +#ifndef _HW_XSCOM_H +#define _HW_XSCOM_H +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson <[email protected]>, IBM Corp. +* Based on the s390 virtio bus definitions: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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 <hw/ppc/pnv.h> + +#define TYPE_XSCOM_DEVICE "xscom-device" +#define XSCOM_DEVICE (obj) \ + OBJECT_CHECK(XScomDevice, (obj), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XScomDeviceClass, (klass), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(XScomDeviceClass, (obj), TYPE_XSCOM_DEVICE) + +#define TYPE_XSCOM_BUS "xscom-bus" +#define XSCOM_BUS (obj) OBJECT_CHECK(XScomBus, (obj), TYPE_XSCOM_BUS) + +typedef struct XScomDevice XScomDevice ; +typedef struct XScomBus XScomBus ; + +typedef struct XScomDeviceClass { +DeviceClass parent_class; + +const char *dt_name; +const char **dt_compatible; +int (*init)(XScomDevice *dev); +int (*devnode)(XScomDevice *dev,void *fdt,int offset); + +/* Actual XScom accesses */ +bool (*read)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t *out_val); +bool (*write)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t val); +}XScomDeviceClass ; + +typedef struct XScomRange { +uint32_t addr; +uint32_t size; +}XScomRange ; + +struct XScomDevice { +DeviceState qdev; +#define MAX_XSCOM_RANGES 4 +struct XScomRange ranges[MAX_XSCOM_RANGES ]; +}; + +struct XScomBus { +BusState bus; +uint32_t chip_id; +}; + +extern XScomBus *xscom_create (PnvChip *chip); +extern int xscom_populate_fdt (XScomBus *xscom,void *fdt,int offset); + + +#endif /* _HW_XSCOM_H */
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 9 lines · Cédric Le Goater
Quoted 3 lines
Alternatively.. it might be simpler to just drop the SCOM as a separate device. I think you could just hang the scom bus directly off the chip object. IIUC the scom is basically the only chip-
level
Quoted 1 line
control mechanism, so this does make a certain amount of sense.
yes. I am exposing more and more stuff of the chip object under the xscom object so we should merge them. I agree. We will still need some XScomDevice of some sort.
What you can do is split it this way which matches the HW:
- The chip object is the XSCOM parent, it owns the XSCOM bus, and expose functions (methods) to read/write XSCOMs. WE could rename XSCOM to "PIB" or "PCB" which is the real name of the bus ;-) But that might confuse things more than help .
- A separate ADU object on each chip that is a SysDevice and does the MMIO bridge to XSCOM. It decodes the MMIO range for that chip and calls the above accessors.
That makes it easy to generate XSCOMs using different mechanisms if we wish to do so, which could come in handy, such as monitor commands, or if we ever do cosimulation with a separate BMC, a simulated FSI, all by just calling the first object's methods.
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 9 lines · Cédric Le Goater
Quoted 3 lines
Alternatively.. it might be simpler to just drop the SCOM as a separate device. I think you could just hang the scom bus directly off the chip object. IIUC the scom is basically the only chip-
level
Quoted 1 line
control mechanism, so this does make a certain amount of sense.
yes. I am exposing more and more stuff of the chip object under the xscom object so we should merge them. I agree. We will still need some XScomDevice of some sort.
What you can do is split it this way which matches the HW:
- The chip object is the XSCOM parent, it owns the XSCOM bus, and expose functions (methods) to read/write XSCOMs. WE could rename XSCOM to "PIB" or "PCB" which is the real name of the bus ;-) But that might confuse things more than help .
Quoted 8 lines
- A separate ADU object on each chip that is a SysDevice and does the MMIO bridge to XSCOM. It decodes the MMIO range for that chip and calls the above accessors.
That makes it easy to generate XSCOMs using different mechanisms if we wish to do so, which could come in handy, such as monitor commands, or if we ever do cosimulation with a separate BMC, a simulated FSI, all by just calling the first object's methods.
Not what I had in mind - I still was thinking of having the xscom access unit do the translation and re-issue into the pcb bus address space.
But sounds like this other approach could have some advantages.
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 v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to Benjamin HerrenschmidtQuoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · Cédric Le Goater
Quoted 3 lines
Alternatively.. it might be simpler to just drop the SCOM as a separate device. I think you could just hang the scom bus directly off the chip object. IIUC the scom is basically the only chip-
level
Quoted 1 line
control mechanism, so this does make a certain amount of sense.
yes. I am exposing more and more stuff of the chip object under the xscom object so we should merge them. I agree. We will still need some XScomDevice of some sort.
Quoted 6 lines
What you can do is split it this way which matches the HW:
- The chip object is the XSCOM parent, it owns the XSCOM bus,
and expose functions (methods) to read/write XSCOMs. WE could rename XSCOM to "PIB" or "PCB" which is the real name of the bus ;-) But that might confuse things more than help .
Well, "Pervasive" should be mentioned somewhere, it is central to PowerPC architecture. I will add a comment for the "PIB" (Pervasive Interconnect Bus) aka XSCOM bus
Quoted 3 lines
- A separate ADU object on each chip that is a SysDevice and does the
MMIO bridge to XSCOM. It decodes the MMIO range for that chip and calls the above accessors.
ok. So the ADU is the address space holder.
Quoted 2 lines
That makes it easy to generate XSCOMs using different mechanisms if we wish to do so, which could come in handy, such as monitor commands,
yes, that will be helpful to trigger some behavior from the command line.
Quoted 2 lines
or if we ever do cosimulation with a separate BMC, a simulated FSI, all by just calling the first object's methods.
The cosimulation is not a long term goal, for the ipmi-bt part. But yes, having a more complete model would be excellent.
Cheers,
C.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to Cédric Le GoaterQuoted 239 lines · Cédric Le Goater
Quoted 77 lines · David Gibson
Quoted 76 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
XSCOM is an interface to a sideband bus provided by the POWER8 chip pervasive unit, which gives access to a number of facilities in the chip that are needed by the OPAL firmware 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.
This provides a simple bus and device type for devices sitting on XSCOM along with some facilities to optionally generate corresponding device-tree nodes
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: updated for qemu-2.7
ported on new sPowerNVMachineState which was merged with PnvSystem removedTRACE_XSCOM
fixed checkpatch errors
replaced assert witherror_setginxscom_realize()reworkedxscom_create
introduced the use of thechip_classfor chip model contants ]Signed-off-by Cédric Le Goater <[email protected]>---
They were some discussions on whether we should use a qemu
address_spaceinstead of the xscom ranges defined in this patch. I gave it try, it is possible but it brings extra unnecessary calls and complexity. I think the current solution is better.hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 11 ++ hw/ppc/pnv_xscom.c | 408 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_xscom.h | 75 +++++++++ 5 files changed, 497 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 +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/pnv.c +3
-0@@ -39,6 +39,8 @@#include "exec/address-spaces.h" #include "qemu/cutils.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_ADDR 0x01000000@@ -103,6 +105,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,char *buf;const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off; +int i; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -142,6 +145,11 @@ static void *powernv_create_fdt(PnvMachineState *pnv,/* Memory */ powernv_populate_memory (fdt);Quoted 9 lines
hw/ppc/pnv.c static void *powernv_create_fdt(PnvMachineState *pnv, · line 151
Quoted 4 lines
hw/ppc/pnv.c +4
-0+/* Populate XSCOM for each chip */ +for (i =0 ; i < pnv->num_chips; i++) { +xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); + }There will be a bunch of per-chip things in the fdt - I suggest a common function to do all the fdt creation for a single chip. Since you've moved to using the
fdt_rwfunctions exclusively, you don't have the sequence constraints that would have made that awkward previously.ok.
Quoted 21 lines
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 317
Quoted 9 lines
hw/ppc/pnv.c +2
-0return fdt; }@@ -305,6 +313,9 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +/* Set up XSCOM bus */ + chip->xscom =xscom_create (chip);So, this creates the xscom as a new device object, unfortunately doing that from another object's
realize()violations QOM lifetime rules as I understand them. I think - I have to admit I'm pretty confused on this topic myself.You could construct the scom from chip init, then realize it from chip realize, but I think using
object_new()(viaqdev_create()) from another object's init also breaks the rules. You are however allowed to allocate the scom state statically within the chip and useobject_initialize()instead, AIUI.Quoted 4 lines
Alternatively.. it might be simpler to just drop the SCOM as a separate device. I think you could just hang the scom bus directly off the chip object. IIUC the scom is basically the only chip-level control mechanism, so this does make a certain amount of sense.
yes. I am exposing more and more stuff of the chip object under the xscom object so we should merge them. I agree. We will still need some XScomDevice of some sort.
Quoted 62 lines
Quoted 62 lines
hw/ppc/pnv.c +0
-0pcc->realize (chip, errp); }hw/ppc/pnv_xscom.c new file +53
-0@@ -0,0 +1,408 @@ + +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson, IBM Corporation <[email protected]> +* Based on the s390 virtio bus code: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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/>. +*/ + +/* TODO: Add some infrastructure for "random stuff" and FIRs that +* various units might want to deal with without creating actual +* XSCOM devices. +* +* For example, HB LPC XSCOM in the PIBAM +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/hw.h" +#include "sysemu/sysemu.h" +#include "hw/boards.h" +#include "monitor/monitor.h" +#include "hw/loader.h" +#include "elf.h" +#include "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "sysemu/device_tree.h" +#include "hw/ppc/fdt.h" + +#include "hw/ppc/pnv_xscom.h" + +#include <libfdt.h> + +#define TYPE_XSCOM "xscom" +#define XSCOM (obj) OBJECT_CHECK(XScomState, (obj), TYPE_XSCOM) + +#define XSCOM_SIZE 0x800000000ull +#define XSCOM_BASE (chip) (0x3fc0000000000ull + ((uint64_t)(chip)) * XSCOM_SIZE) + + +typedef struct XScomState {Quoted 8 lines
hw/ppc/pnv_xscom.c line 59
Quoted 6 lines
hw/ppc/pnv_xscom.c new file +6
-0+/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion mem; +int32_t chip_id;Merging scom and chip would avoid the duplication of this field too.
yes.
Quoted 37 lines
Quoted 37 lines
hw/ppc/pnv_xscom.c new file +37
-0+PnvChipClass *chip_class; +XScomBus *bus; +} XScomState; + +static uint32_t xscom_to_pcb_addr (uint64_t addr) +{ + addr &= (XSCOM_SIZE -1 ); +return ((addr >>4 ) & ~0xfull ) | ((addr >>3 ) &0xf ); +} + +static void xscom_complete (uint64_t hmer_bits) +{ +CPUState *cs = current_cpu; +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +cpu_synchronize_state (cs); + env->spr[SPR_HMER ] |= hmer_bits; + +/* XXX Need a CPU helper to set HMER, also handle gneeration +* of HMIs +*/ +} + +static XScomDevice *xscom_find_target (XScomState *s,uint32_t pcb_addr, +uint32_t *range) +{ +BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +unsigned int i; + +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) > pcb_addr) {Quoted 8 lines
hw/ppc/pnv_xscom.c line 101
Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+ *range = i; +return xd; + } + } + }Hmm.. you could set up a SCOM local address space using the infrastructure in
memory.c, rather than doing your own dispatch.
Quoted 1 line
I need to study this option a little deeper.
So.. something I realized a bit later.
The obvious way of changing XScomDevice to a QOM interface isn't really compatible with using the address space infrastructure. You'd have read/write methods in the interface, and since that's not the same interface as an MR you'd need to do your own address decode / dispatch as you do above.
That does suggest an alternative approach though. You could remove XScomDevice entirely from QOM existence, and just expose the xscom address space globally, much like address_space_memory. The individual devices could just register their own subregions within it.
I'm not sure if the latter is a good idea, though.
Quoted 442 lines
Quoted 198 lines
Quoted 198 lines
hw/ppc/pnv_xscom.c new file +196
-0+return NULL ; +} + +static bool xscom_dispatch_read (XScomState *s,uint32_t pcb_addr, +uint64_t *out_val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->read) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->read (xd, range, offset, out_val); +} + +static bool xscom_dispatch_write (XScomState *s,uint32_t pcb_addr,uint64_t val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->write) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->write (xd, range, offset, val); +} + +static uint64_t xscom_read (void *opaque,hwaddr addr,unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); +uint64_t val; + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +case 0xf000f : + val = s->chip_class->chip_f000f; +break ; +case 0x1010c00 :/* PIBAM FIR */ +case 0x1010c03 :/* PIBAM FIR MASK */ +case 0x2020007 :/* ADU stuff */ +case 0x2020009 :/* ADU stuff */ +case 0x202000f :/* ADU stuff */ + val =0 ; +break ; +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 */ + val =0 ; +break ; +default : +if (!xscom_dispatch_read (s, pcba, &val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return 0 ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +return val; +} + +static void xscom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +/* We ignore writes to these */ +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 */ +break ; +default : +if (!xscom_dispatch_write (s, pcba, val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +} + +static const MemoryRegionOps 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 , +}; + +static int xscom_init (SysBusDevice *dev) +{ +XScomState *s =XSCOM (dev); + + s->chip_id =-1 ; +return 0 ; +} + +static void xscom_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +XScomState *s =XSCOM (dev); +char *name; + +if (s->chip_id <0 ) { +error_setg (errp,"invalid chip id '%d'" , s->chip_id); +return ; + } + name =g_strdup_printf ("xscom-%x" , s->chip_id); +memory_region_init_io (&s->mem,OBJECT (s), &xscom_ops, s, name,XSCOM_SIZE ); +sysbus_init_mmio (sbd, &s->mem); +sysbus_mmio_map (sbd,0 ,XSCOM_BASE (s->chip_id)); +} + +static Property xscom_properties[] = { +DEFINE_PROP_INT32 ("chip_id" , XScomState, chip_id,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void xscom_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = xscom_properties; + dc->realize = xscom_realize; + k->init = xscom_init; +} + +static const TypeInfo xscom_info = { + .name =TYPE_XSCOM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XScomState), + .class_init = xscom_class_init, +}; + +static void xscom_bus_class_init (ObjectClass *klass,void *data) +{ +} + +static const TypeInfo xscom_bus_info = { + .name =TYPE_XSCOM_BUS , + .parent =TYPE_BUS , + .class_init = xscom_bus_class_init, + .instance_size =sizeof (XScomBus), +}; + +XScomBus *xscom_create (PnvChip *chip) +{ +DeviceState *dev; +XScomState *xdev; +BusState *qbus; +XScomBus *xb; +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + dev =qdev_create (NULL ,TYPE_XSCOM ); +qdev_prop_set_uint32 (dev,"chip_id" , chip->chip_id); +qdev_init_nofail (dev); + +/* Create bus on bridge device */ + qbus =qbus_create (TYPE_XSCOM_BUS , dev,"xscom" ); + xb =DO_UPCAST (XScomBus, bus, qbus); + xb->chip_id = chip->chip_id; + xdev =XSCOM (dev); + xdev->bus = xb;Quoted 8 lines
hw/ppc/pnv_xscom.c line 303
Quoted 6 lines
hw/ppc/pnv_xscom.c new file +6
-0+ xdev->chip_class = pcc; + +return xb; +} + +int xscom_populate_fdt (XScomBus *xb,void *fdt,int root_offset)What is the
root_offsetparameter for, since it is always 0?yes ...
Quoted 5 lines
Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+{ +BusChild *bc; +char *name; +const char compat[] ="ibm,power8-xscom\0ibm,xscom" ; +uint64_t reg[] = {cpu_to_be64 (XSCOM_BASE (xb->chip_id)),Quoted 8 lines
hw/ppc/pnv_xscom.c line 313
Quoted 5 lines
hw/ppc/pnv_xscom.c new file +5
-0+ cpu_to_be64(XSCOM_SIZE) }; +int xscom_offset; + + name =g_strdup_printf ("xscom@%llx" , (unsigned long long ) +be64_to_cpu (reg[0 ]));Nit: in qemu the PRIx64 etc. macros are usually preferred to (unsigned long long) casts of this type.
sure.
Quoted 30 lines
Quoted 30 lines
hw/ppc/pnv_xscom.c new file +30
-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" , xb->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)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"compatible" , compat, +sizeof (compat)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"scom-controller" ,NULL ,0 ))); + + QTAILQ_FOREACH(bc, &xb->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xd); +uint32_t reg[MAX_XSCOM_RANGES *2 ]; +unsigned int i, sz =0 ; +void *cp, *p; +int child_offset; + +/* Some XSCOM slaves may not be represented in the DT */ +if (!xc->dt_name) { +continue ; + } + name =g_strdup_printf ("%s@%x" , xc->dt_name, xd->ranges[0 ].addr); + child_offset =fdt_add_subnode (fdt, xscom_offset, name); +_FDT (child_offset); +g_free (name); +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].size ==0 ) {Quoted 8 lines
hw/ppc/pnv_xscom.c line 349
Quoted 6 lines
hw/ppc/pnv_xscom.c new file +6
-0+break ; + } + reg[sz++] =cpu_to_be32 (xd->ranges[i].addr); + reg[sz++] =cpu_to_be32 (xd->ranges[i].size); + } +_FDT ((fdt_setprop (fdt, child_offset,"reg" , reg, sz *4 )));Use of
fdt_appendprop()might make this a little neater.ok.
Quoted 20 lines
Quoted 9 lines
hw/ppc/pnv_xscom.c new file +9
-0+if (xc->devnode) { +_FDT ((xc->devnode (xd, fdt, child_offset))); + } +#define MAX_COMPATIBLE_PROP 1024 + cp = p =g_malloc0 (MAX_COMPATIBLE_PROP ); + i =0 ; +while ((p - cp) <MAX_COMPATIBLE_PROP ) { +int l; +if (xc->dt_compatible[i] ==NULL ) {hw/ppc/pnv_xscom.c line 368
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+break ; + } + l =strlen (xc->dt_compatible[i]); +if (l >= (MAX_COMPATIBLE_PROP - i)) { +break ; + } +strcpy (p, xc->dt_compatible[i++]); + p += l +1 ; + } +_FDT ((fdt_setprop (fdt, child_offset,"compatible" , cp, p - cp)));Quoted 7 lines
Might it be easier to just require the individual scom device to set the compatible property from its ->devnode callback? That way it can just
const char compat = "foo\0bar\0baz"; fdt_setprop(..., compat, sizeof(compat));and avoid this fiddling around with arrays.
Yes.
xscom_populate_fdt()will shrink quite a bit. This is a good idea.Thanks,
C.
Quoted 141 lines
Quoted 140 lines
hw/ppc/pnv_xscom.c new file +40
-0+ } + +return 0 ; +} + +static int xscom_qdev_init (DeviceState *qdev) +{ +XScomDevice *xdev = (XScomDevice *)qdev; +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xdev); + +if (xc->init) { +return xc->init (xdev); + } +return 0 ; +} + +static void xscom_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *k =DEVICE_CLASS (klass); + k->init = xscom_qdev_init; + k->bus_type =TYPE_XSCOM_BUS ; +} + +static const TypeInfo xscom_dev_info = { + .name =TYPE_XSCOM_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (XScomDevice), + .abstract = true, + .class_size =sizeof (XScomDeviceClass), + .class_init = xscom_device_class_init, +}; + +static void xscom_register_types (void ) +{ +type_register_static (&xscom_info); +type_register_static (&xscom_bus_info); +type_register_static (&xscom_dev_info); +} + +type_init (xscom_register_types)include/hw/ppc/pnv.h +2
-0@@ -35,12 +35,14 @@ typedef enum PnvChipType {PNV_CHIP_P8NVL ,/* AKA Naples */ } PnvChipType; +typedef struct XScomBus XScomBus ;typedef struct PnvChip {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ uint32_t chip_id; +XScomBus *xscom; }PnvChip ; typedef struct PnvChipClass {include/hw/ppc/pnv_xscom.h new file +75
-0@@ -0,0 +1,75 @@ +#ifndef _HW_XSCOM_H +#define _HW_XSCOM_H +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson <[email protected]>, IBM Corp. +* Based on the s390 virtio bus definitions: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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 <hw/ppc/pnv.h> + +#define TYPE_XSCOM_DEVICE "xscom-device" +#define XSCOM_DEVICE (obj) \ + OBJECT_CHECK(XScomDevice, (obj), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XScomDeviceClass, (klass), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(XScomDeviceClass, (obj), TYPE_XSCOM_DEVICE) + +#define TYPE_XSCOM_BUS "xscom-bus" +#define XSCOM_BUS (obj) OBJECT_CHECK(XScomBus, (obj), TYPE_XSCOM_BUS) + +typedef struct XScomDevice XScomDevice ; +typedef struct XScomBus XScomBus ; + +typedef struct XScomDeviceClass { +DeviceClass parent_class; + +const char *dt_name; +const char **dt_compatible; +int (*init)(XScomDevice *dev); +int (*devnode)(XScomDevice *dev,void *fdt,int offset); + +/* Actual XScom accesses */ +bool (*read)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t *out_val); +bool (*write)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t val); +}XScomDeviceClass ; + +typedef struct XScomRange { +uint32_t addr; +uint32_t size; +}XScomRange ; + +struct XScomDevice { +DeviceState qdev; +#define MAX_XSCOM_RANGES 4 +struct XScomRange ranges[MAX_XSCOM_RANGES ]; +}; + +struct XScomBus { +BusState bus; +uint32_t chip_id; +}; + +extern XScomBus *xscom_create (PnvChip *chip); +extern int xscom_populate_fdt (XScomBus *xscom,void *fdt,int offset); + + +#endif /* _HW_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 v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 8 lines · David Gibson
That does suggest an alternative approach though. You could remove XScomDevice entirely from QOM existence, and just expose the xscom address space globally, much like address_space_memory. The individual devices could just register their own subregions within it.
I'm not sure if the latter is a good idea, though.
Not globally, per chip.
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 8 lines · David Gibson
That does suggest an alternative approach though. You could remove XScomDevice entirely from QOM existence, and just expose the xscom address space globally, much like address_space_memory. The individual devices could just register their own subregions within it.
I'm not sure if the latter is a good idea, though.
Not globally, per chip.
Right, that's probably better. Not immediately sure how the scomdevice would get hold of its chip's scom AS, but we can probably figure out something.
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 v2 3/7] ppc/pnv: Add XSCOM infrastructure
Quoted 3 lines · David Gibson
Right, that's probably better. Not immediately sure how the scomdevice would get hold of its chip's scom AS, but we can probably figure out something.
Passed at instanciation ?
Cheers,
Ben.
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
In reply to Cédric Le GoaterQuoted 452 lines · Cédric Le Goater
From: Benjamin Herrenschmidt <[email protected]>
XSCOM is an interface to a sideband bus provided by the POWER8 chip pervasive unit, which gives access to a number of facilities in the chip that are needed by the OPAL firmware 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.
This provides a simple bus and device type for devices sitting on XSCOM along with some facilities to optionally generate corresponding device-tree nodes
Signed-off-by Benjamin Herrenschmidt <[email protected]>[clg: updated for qemu-2.7
ported on new sPowerNVMachineState which was merged with PnvSystem removedTRACE_XSCOM
fixed checkpatch errors
replaced assert witherror_setginxscom_realize()reworkedxscom_create
introduced the use of thechip_classfor chip model contants ]Signed-off-by Cédric Le Goater <[email protected]>---
They were some discussions on whether we should use a qemu
address_spaceinstead of the xscom ranges defined in this patch. I gave it try, it is possible but it brings extra unnecessary calls and complexity. I think the current solution is better.hw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 11 ++ hw/ppc/pnv_xscom.c | 408 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 + include/hw/ppc/pnv_xscom.h | 75 +++++++++ 5 files changed, 497 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 +obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) obj-y += spapr_pci_vfio.o endifhw/ppc/pnv.c +11
-0@@ -39,6 +39,8 @@#include "exec/address-spaces.h" #include "qemu/cutils.h" +#include "hw/ppc/pnv_xscom.h" +#include <libfdt.h> #define FDT_ADDR 0x01000000@@ -103,6 +105,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,char *buf;const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off; +int i; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -142,6 +145,11 @@ static void *powernv_create_fdt(PnvMachineState *pnv,/* Memory */ powernv_populate_memory (fdt); +/* Populate XSCOM for each chip */ +for (i =0 ; i < pnv->num_chips; i++) { +xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); + } +return fdt; }@@ -305,6 +313,9 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +/* Set up XSCOM bus */ + chip->xscom =xscom_create (chip); + pcc->realize (chip, errp); }hw/ppc/pnv_xscom.c new file +352
-0@@ -0,0 +1,408 @@ + +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson, IBM Corporation <[email protected]> +* Based on the s390 virtio bus code: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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/>. +*/ + +/* TODO: Add some infrastructure for "random stuff" and FIRs that +* various units might want to deal with without creating actual +* XSCOM devices. +* +* For example, HB LPC XSCOM in the PIBAM +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/hw.h" +#include "sysemu/sysemu.h" +#include "hw/boards.h" +#include "monitor/monitor.h" +#include "hw/loader.h" +#include "elf.h" +#include "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "sysemu/device_tree.h" +#include "hw/ppc/fdt.h" + +#include "hw/ppc/pnv_xscom.h" + +#include <libfdt.h> + +#define TYPE_XSCOM "xscom" +#define XSCOM (obj) OBJECT_CHECK(XScomState, (obj), TYPE_XSCOM) + +#define XSCOM_SIZE 0x800000000ull +#define XSCOM_BASE (chip) (0x3fc0000000000ull + ((uint64_t)(chip)) * XSCOM_SIZE) + + +typedef struct XScomState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion mem; +int32_t chip_id; +PnvChipClass *chip_class; +XScomBus *bus; +}XScomState ; + +static uint32_t xscom_to_pcb_addr (uint64_t addr) +{ + addr &= (XSCOM_SIZE -1 ); +return ((addr >>4 ) & ~0xfull ) | ((addr >>3 ) &0xf ); +} + +static void xscom_complete (uint64_t hmer_bits) +{ +CPUState *cs = current_cpu; +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +cpu_synchronize_state (cs); + env->spr[SPR_HMER ] |= hmer_bits; + +/* XXX Need a CPU helper to set HMER, also handle gneeration +* of HMIs +*/ +} + +static XScomDevice *xscom_find_target (XScomState *s,uint32_t pcb_addr, +uint32_t *range) +{ +BusChild *bc; + + QTAILQ_FOREACH(bc, &s->bus->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +unsigned int i; + +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].addr <= pcb_addr && + (xd->ranges[i].addr + xd->ranges[i].size) > pcb_addr) { + *range = i; +return xd; + } + } + } +return NULL ; +} + +static bool xscom_dispatch_read (XScomState *s,uint32_t pcb_addr, +uint64_t *out_val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->read) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->read (xd, range, offset, out_val); +} + +static bool xscom_dispatch_write (XScomState *s,uint32_t pcb_addr,uint64_t val) +{ +uint32_t range, offset; +struct XScomDevice *xd =xscom_find_target (s, pcb_addr, &range); +XScomDeviceClass *xc; + +if (!xd) { +return false; + } + xc =XSCOM_DEVICE_GET_CLASS (xd); +if (!xc->write) { +return false; + } + offset = pcb_addr - xd->ranges[range].addr; +return xc->write (xd, range, offset, val); +} + +static uint64_t xscom_read (void *opaque,hwaddr addr,unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); +uint64_t val; + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +case 0xf000f : + val = s->chip_class->chip_f000f; +break ; +case 0x1010c00 :/* PIBAM FIR */ +case 0x1010c03 :/* PIBAM FIR MASK */ +case 0x2020007 :/* ADU stuff */ +case 0x2020009 :/* ADU stuff */ +case 0x202000f :/* ADU stuff */ + val =0 ; +break ; +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 */ + val =0 ; +break ; +default : +if (!xscom_dispatch_read (s, pcba, &val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return 0 ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +return val; +} + +static void xscom_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +XScomState *s = opaque; +uint32_t pcba =xscom_to_pcb_addr (addr); + +assert (width ==8 ); + +/* Handle some SCOMs here before dispatch */ +switch (pcba) { +/* We ignore writes to these */ +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 */ +break ; +default : +if (!xscom_dispatch_write (s, pcba, val)) { +xscom_complete (HMER_XSCOM_FAIL |HMER_XSCOM_DONE ); +return ; + } + } + +xscom_complete (HMER_XSCOM_DONE ); +} + +static const MemoryRegionOps 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 , +}; + +static int xscom_init (SysBusDevice *dev) +{ +XScomState *s =XSCOM (dev); + + s->chip_id =-1 ; +return 0 ; +} + +static void xscom_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +XScomState *s =XSCOM (dev); +char *name; + +if (s->chip_id <0 ) { +error_setg (errp,"invalid chip id '%d'" , s->chip_id); +return ; + } + name =g_strdup_printf ("xscom-%x" , s->chip_id); +memory_region_init_io (&s->mem,OBJECT (s), &xscom_ops, s, name,XSCOM_SIZE ); +sysbus_init_mmio (sbd, &s->mem); +sysbus_mmio_map (sbd,0 ,XSCOM_BASE (s->chip_id)); +} + +static Property xscom_properties[] = { +DEFINE_PROP_INT32 ("chip_id" , XScomState, chip_id,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void xscom_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = xscom_properties; + dc->realize = xscom_realize; + k->init = xscom_init; +} + +static const TypeInfo xscom_info = { + .name =TYPE_XSCOM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XScomState), + .class_init = xscom_class_init, +}; + +static void xscom_bus_class_init (ObjectClass *klass,void *data) +{ +} + +static const TypeInfo xscom_bus_info = { + .name =TYPE_XSCOM_BUS , + .parent =TYPE_BUS , + .class_init = xscom_bus_class_init, + .instance_size =sizeof (XScomBus), +}; + +XScomBus *xscom_create (PnvChip *chip) +{ +DeviceState *dev; +XScomState *xdev; +BusState *qbus; +XScomBus *xb; +PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); + + dev =qdev_create (NULL ,TYPE_XSCOM ); +qdev_prop_set_uint32 (dev,"chip_id" , chip->chip_id); +qdev_init_nofail (dev); + +/* Create bus on bridge device */ + qbus =qbus_create (TYPE_XSCOM_BUS , dev,"xscom" ); + xb =DO_UPCAST (XScomBus, bus, qbus); + xb->chip_id = chip->chip_id; + xdev =XSCOM (dev); + xdev->bus = xb; + xdev->chip_class = pcc; + +return xb; +} + +int xscom_populate_fdt (XScomBus *xb,void *fdt,int root_offset) +{ +BusChild *bc; +char *name; +const char compat[] ="ibm,power8-xscom\0ibm,xscom" ; +uint64_t reg[] = {cpu_to_be64 (XSCOM_BASE (xb->chip_id)), +cpu_to_be64 (XSCOM_SIZE ) }; +int xscom_offset; + + name =g_strdup_printf ("xscom@%llx" , (unsigned long long ) +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" , xb->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)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"compatible" , compat, +sizeof (compat)))); +_FDT ((fdt_setprop (fdt, xscom_offset,"scom-controller" ,NULL ,0 ))); + + QTAILQ_FOREACH(bc, &xb->bus.children, sibling) { +DeviceState *qd = bc->child; +XScomDevice *xd =XSCOM_DEVICE (qd); +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xd); +uint32_t reg[MAX_XSCOM_RANGES *2 ]; +unsigned int i, sz =0 ; +void *cp, *p; +int child_offset; + +/* Some XSCOM slaves may not be represented in the DT */ +if (!xc->dt_name) { +continue ; + } + name =g_strdup_printf ("%s@%x" , xc->dt_name, xd->ranges[0 ].addr); + child_offset =fdt_add_subnode (fdt, xscom_offset, name); +_FDT (child_offset); +g_free (name); +for (i =0 ; i <MAX_XSCOM_RANGES ; i++) { +if (xd->ranges[i].size ==0 ) { +break ; + } + reg[sz++] =cpu_to_be32 (xd->ranges[i].addr); + reg[sz++] =cpu_to_be32 (xd->ranges[i].size); + } +_FDT ((fdt_setprop (fdt, child_offset,"reg" , reg, sz *4 ))); +if (xc->devnode) { +_FDT ((xc->devnode (xd, fdt, child_offset))); + }
hw/ppc/pnv_xscom.c line 362
Quoted 10 lines
hw/ppc/pnv_xscom.c new file +10
-0+#define MAX_COMPATIBLE_PROP 1024 + cp = p =g_malloc0 (MAX_COMPATIBLE_PROP ); + i =0 ; +while ((p - cp) <MAX_COMPATIBLE_PROP ) { +int l; +if (xc->dt_compatible[i] ==NULL ) { +break ; + } + l =strlen (xc->dt_compatible[i]); +if (l >= (MAX_COMPATIBLE_PROP - i)) {
The use of 'i' above doesn't look right. Should the check be more like this?
if ((l + 1) >= (MAX_COMPATIBLE_PROP - (p - cp))) {Quoted 149 lines
hw/ppc/pnv_xscom.c new file +46
-0+break ; + } +strcpy (p, xc->dt_compatible[i++]); + p += l +1 ; + } +_FDT ((fdt_setprop (fdt, child_offset,"compatible" , cp, p - cp))); + } + +return 0 ; +} + +static int xscom_qdev_init (DeviceState *qdev) +{ +XScomDevice *xdev = (XScomDevice *)qdev; +XScomDeviceClass *xc =XSCOM_DEVICE_GET_CLASS (xdev); + +if (xc->init) { +return xc->init (xdev); + } +return 0 ; +} + +static void xscom_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *k =DEVICE_CLASS (klass); + k->init = xscom_qdev_init; + k->bus_type =TYPE_XSCOM_BUS ; +} + +static const TypeInfo xscom_dev_info = { + .name =TYPE_XSCOM_DEVICE , + .parent =TYPE_DEVICE , + .instance_size =sizeof (XScomDevice), + .abstract = true, + .class_size =sizeof (XScomDeviceClass), + .class_init = xscom_device_class_init, +}; + +static void xscom_register_types (void ) +{ +type_register_static (&xscom_info); +type_register_static (&xscom_bus_info); +type_register_static (&xscom_dev_info); +} + +type_init (xscom_register_types)include/hw/ppc/pnv.h +2
-0@@ -35,12 +35,14 @@ typedef enum PnvChipType {PNV_CHIP_P8NVL ,/* AKA Naples */ } PnvChipType; +typedef struct XScomBus XScomBus ;typedef struct PnvChip {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ uint32_t chip_id; +XScomBus *xscom; }PnvChip ; typedef struct PnvChipClass {include/hw/ppc/pnv_xscom.h new file +75
-0@@ -0,0 +1,75 @@ +#ifndef _HW_XSCOM_H +#define _HW_XSCOM_H +/* +* QEMU PowerNV XSCOM bus definitions +* +* Copyright (c) 2010 David Gibson <[email protected]>, IBM Corp. +* Based on the s390 virtio bus definitions: +* Copyright (c) 2009 Alexander Graf <[email protected]> +* +* 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 <hw/ppc/pnv.h> + +#define TYPE_XSCOM_DEVICE "xscom-device" +#define XSCOM_DEVICE (obj) \ + OBJECT_CHECK(XScomDevice, (obj), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_CLASS (klass) \ + OBJECT_CLASS_CHECK(XScomDeviceClass, (klass), TYPE_XSCOM_DEVICE) +#define XSCOM_DEVICE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(XScomDeviceClass, (obj), TYPE_XSCOM_DEVICE) + +#define TYPE_XSCOM_BUS "xscom-bus" +#define XSCOM_BUS (obj) OBJECT_CHECK(XScomBus, (obj), TYPE_XSCOM_BUS) + +typedef struct XScomDevice XScomDevice ; +typedef struct XScomBus XScomBus ; + +typedef struct XScomDeviceClass { +DeviceClass parent_class; + +const char *dt_name; +const char **dt_compatible; +int (*init)(XScomDevice *dev); +int (*devnode)(XScomDevice *dev,void *fdt,int offset); + +/* Actual XScom accesses */ +bool (*read)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t *out_val); +bool (*write)(XScomDevice *dev,uint32_t range,uint32_t offset, +uint64_t val); +}XScomDeviceClass ; + +typedef struct XScomRange { +uint32_t addr; +uint32_t size; +}XScomRange ; + +struct XScomDevice { +DeviceState qdev; +#define MAX_XSCOM_RANGES 4 +struct XScomRange ranges[MAX_XSCOM_RANGES ]; +}; + +struct XScomBus { +BusState bus; +uint32_t chip_id; +}; + +extern XScomBus *xscom_create (PnvChip *chip); +extern int xscom_populate_fdt (XScomBus *xscom,void *fdt,int offset); + + +#endif /* _HW_XSCOM_H */ Signature · 1 line
2.7.4
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 3/7] ppc/pnv: Add XSCOM infrastructure
Hello Sam,
Quoted 12 lines
hw/ppc/pnv_xscom.c line 362
Quoted 11 lines
hw/ppc/pnv_xscom.c new file +11
-0+ } +#define MAX_COMPATIBLE_PROP 1024 + cp = p =g_malloc0 (MAX_COMPATIBLE_PROP ); + i =0 ; +while ((p - cp) <MAX_COMPATIBLE_PROP ) { +int l; +if (xc->dt_compatible[i] ==NULL ) { +break ; + } + l =strlen (xc->dt_compatible[i]); +if (l >= (MAX_COMPATIBLE_PROP - i)) {
Quoted 2 lines
The use of 'i' above doesn't look right. Should the check be more like this?
if ((l + 1) >= (MAX_COMPATIBLE_PROP - (p - cp))) {
David just proposed to move the compatible property setting in the devnode op of the device, and so all this code should disappear at the same time.
Thanks,
C.
Quoted 11 lines
Quoted 11 lines
hw/ppc/pnv_xscom.c new file +11
-0+break ; + } +strcpy (p, xc->dt_compatible[i++]); + p += l +1 ; + } +_FDT ((fdt_setprop (fdt, child_offset,"compatible" , cp, p - cp))); + } + +return 0 ; +} +
PATCH v2 4/7 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.
--- hw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 ++ 2 files changed, 29 insertions(+)
hw/ppc/pnv.c +27 -0
@@ -236,6 +236,27 @@ static void ppc_powernv_init(MachineState *machine)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 (~0xffff8f8f) +#define POWER8_CORE_MASK (~0xffff8181) +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) { ;
@@ -250,6 +271,8 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8NVL" ; k->chip_type =PNV_CHIP_P8NVL ; k->chip_f000f =0x120d304980000000ull ; + k->cores_max =12 ; + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8NVL" ; }
@@ -274,6 +297,8 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8" ; k->chip_type =PNV_CHIP_P8 ; k->chip_f000f =0x220ea04980000000ull ; + k->cores_max =12 ; + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8" ; }
@@ -298,6 +323,8 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8E" ; k->chip_type =PNV_CHIP_P8E ; k->chip_f000f =0x221ef04980000000ull ; + k->cores_max =6 ; + k->cores_mask =POWER8E_CORE_MASK ; dc->desc ="PowerNV Chip POWER8E" ; }
include/hw/ppc/pnv.h +2 -0
@@ -49,6 +49,8 @@ typedef struct PnvChipClass {/*< private >*/ SysBusDeviceClass parent_class;/*< public >*/ +uint32_t cores_max; +uint32_t cores_mask;const char *cpu_model;PnvChipType chip_type;uint64_t chip_f000f;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 4/7] ppc/pnv: add a core mask to PnvChip
Quoted 73 lines · Cédric Le Goater
This will be used to build real HW ids for the cores and enforce some limits on the available cores per chip.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 ++ 2 files changed, 29 insertions(+)hw/ppc/pnv.c +27
-0@@ -236,6 +236,27 @@ static void ppc_powernv_init(MachineState *machine)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 (~0xffff8f8f) +#define POWER8_CORE_MASK (~0xffff8181) +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) { ;@@ -250,6 +271,8 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8NVL" ; k->chip_type =PNV_CHIP_P8NVL ; k->chip_f000f =0x120d304980000000ull ; + k->cores_max =12 ; + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8NVL" ; }@@ -274,6 +297,8 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8" ; k->chip_type =PNV_CHIP_P8 ; k->chip_f000f =0x220ea04980000000ull ; + k->cores_max =12 ; + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8" ; }@@ -298,6 +323,8 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8E" ; k->chip_type =PNV_CHIP_P8E ; k->chip_f000f =0x221ef04980000000ull ; + k->cores_max =6 ; + k->cores_mask =POWER8E_CORE_MASK ; dc->desc ="PowerNV Chip POWER8E" ; }include/hw/ppc/pnv.h +0
-0
include/hw/ppc/pnv.h typedef struct PnvChipClass { · line 53
Quoted 5 lines
include/hw/ppc/pnv.h +2
-0@@ -49,6 +49,8 @@ typedef struct PnvChipClass {/*< private >*/ SysBusDeviceClass parent_class;/*< public >*/ +uint32_t cores_max; +uint32_t cores_mask;
This 'cores_mask' attribute needs to be a uint64_t for POWER9. The core chiplet ids are in the range : [ 0x20 - 0x37 ]
I will change that in the next version and include a PnvChipPower9 class as the cpu_model was merged in David's branch.
Cheers,
C.
Re: [Qemu-devel] [PATCH v2 4/7] ppc/pnv: add a core mask to PnvChip
In reply to Cédric Le GoaterQuoted 42 lines · Cédric Le Goater
This will be used to build real HW ids for the cores and enforce some limits on the available cores per chip.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 ++ 2 files changed, 29 insertions(+)hw/ppc/pnv.c +21
-0@@ -236,6 +236,27 @@ static void ppc_powernv_init(MachineState *machine)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 (~0xffff8f8f) +#define POWER8_CORE_MASK (~0xffff8181) +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) { ;
hw/ppc/pnv.c static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) · line 274
Quoted 4 lines
hw/ppc/pnv.c +1
-0@@ -250,6 +271,8 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8NVL" ; k->chip_type =PNV_CHIP_P8NVL ; k->chip_f000f =0x120d304980000000ull ; + k->cores_max =12 ;
Is it worth having this cores_max field, since AFAICT you can calculate it as hweight(~cores_mask)?
Quoted 35 lines
hw/ppc/pnv.c +5
-0+ k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8NVL" ; }@@ -274,6 +297,8 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8" ; k->chip_type =PNV_CHIP_P8 ; k->chip_f000f =0x220ea04980000000ull ; + k->cores_max =12 ; + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8" ; }@@ -298,6 +323,8 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8E" ; k->chip_type =PNV_CHIP_P8E ; k->chip_f000f =0x221ef04980000000ull ; + k->cores_max =6 ; + k->cores_mask =POWER8E_CORE_MASK ; dc->desc ="PowerNV Chip POWER8E" ; }include/hw/ppc/pnv.h +2
-0@@ -49,6 +49,8 @@ typedef struct PnvChipClass {/*< private >*/ SysBusDeviceClass parent_class;/*< public >*/ +uint32_t cores_max; +uint32_t cores_mask;const char *cpu_model;PnvChipType chip_type;uint64_t chip_f000f;
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 v2 4/7] ppc/pnv: add a core mask to PnvChip
Quoted 42 lines · David Gibson
Quoted 41 lines · Cédric Le Goater
This will be used to build real HW ids for the cores and enforce some limits on the available cores per chip.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv.c | 27 +++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 2 ++ 2 files changed, 29 insertions(+)hw/ppc/pnv.c +21
-0@@ -236,6 +236,27 @@ static void ppc_powernv_init(MachineState *machine)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 (~0xffff8f8f) +#define POWER8_CORE_MASK (~0xffff8181) +static void pnv_chip_power8nvl_realize (PnvChip *chip,Error **errp) { ;
Quoted 8 lines
hw/ppc/pnv.c static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) · line 274
Quoted 5 lines
hw/ppc/pnv.c +1
-0@@ -250,6 +271,8 @@ static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8NVL" ; k->chip_type =PNV_CHIP_P8NVL ; k->chip_f000f =0x120d304980000000ull ; + k->cores_max =12 ;Is it worth having this
cores_maxfield, since AFAICT you can calculate it ashweight(~cores_mask)?
Sure. I looked for it and missed it.
Here is a slightly improved version from Brian Kernighan :
unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; c++)
{
v &= v - 1; // clear the least significant bit set
}Thanks,
C.
Quoted 36 lines
Quoted 35 lines
hw/ppc/pnv.c +5
-0+ k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8NVL" ; }@@ -274,6 +297,8 @@ static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8" ; k->chip_type =PNV_CHIP_P8 ; k->chip_f000f =0x220ea04980000000ull ; + k->cores_max =12 ; + k->cores_mask =POWER8_CORE_MASK ; dc->desc ="PowerNV Chip POWER8" ; }@@ -298,6 +323,8 @@ static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) k->cpu_model ="POWER8E" ; k->chip_type =PNV_CHIP_P8E ; k->chip_f000f =0x221ef04980000000ull ; + k->cores_max =6 ; + k->cores_mask =POWER8E_CORE_MASK ; dc->desc ="PowerNV Chip POWER8E" ; }include/hw/ppc/pnv.h +2
-0@@ -49,6 +49,8 @@ typedef struct PnvChipClass {/*< private >*/ SysBusDeviceClass parent_class;/*< public >*/ +uint32_t cores_max; +uint32_t cores_mask;const char *cpu_model;PnvChipType chip_type;uint64_t chip_f000f;
Re: [Qemu-devel] [PATCH v2 4/7] ppc/pnv: add a core mask to PnvChip
Quoted 7 lines · Cédric Le Goater
Quoted 2 lines
Is it worth having this
cores_maxfield, since AFAICT you can calculate it ashweight(~cores_mask)?Sure. I looked for it and missed it.
Here is a slightly improved version from Brian Kernighan :
Quoted 7 lines
unsigned int v; // count the number of bits set in v unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; c++)
{
v &= v - 1; // clear the least significant bit set }
Use the accessor (ie, hweight). The compiler might turn it into a popcnt instruction of some sort if the CPU has one :-)
Ben.
PATCH v2 5/7 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. But the differences are small and the objects could possibly be merged.
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. This id is stored in CPUState->cpu_index and in PnvCore->core_id and it is used to populate the device tree.
---
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 | 204 ++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 170 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 ++ include/hw/ppc/pnv_core.h | 47 +++++++++++ 5 files changed, 429 insertions(+), 1 deletion(-) 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 pnv_xscom.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 +204 -0
253 lines not on this page · raw message
hw/ppc/pnv_core.c new file +170 -0
170 lines not on this page · raw message
include/hw/ppc/pnv.h +7 -0
@@ -36,6 +36,7 @@ typedef enum PnvChipType { } PnvChipType;typedef struct XScomBus XScomBus ; +typedef struct PnvCore PnvCore ; typedef struct PnvChip { /*< private >*/ SysBusDevice parent_obj;
@@ -43,6 +44,10 @@ typedef struct PnvChip {/*< public >*/ uint32_t chip_id;XScomBus *xscom; + +uint32_t num_cores; +uint32_t cores_mask; +PnvCore *cores; } PnvChip; typedef struct PnvChipClass {
@@ -109,4 +114,6 @@ typedef struct PnvMachineState { PnvChip **chips; } PnvMachineState; +#define PNV_TIMEBASE_FREQ 512000000ULL +#endif /* _PPC_PNV_H */
include/hw/ppc/pnv_core.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 5/7] ppc/pnv: add a PnvCore object
Quoted 178 lines · Cédric Le Goater
This is largy inspired by sPAPRCPUCore with some simplification, no hotplug for instance. But the differences are small and the objects could possibly be merged.
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. This id is stored in
CPUState->cpu_indexand inPnvCore->core_idand it is used to populate the device tree.Signed-off-by Cédric Le Goater <[email protected]>---
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
- reworkedpowernv_create_core_node()which populates the device tree
- added missing "ibm,pa-features" property
-smp_cpusrepresenting threads, usedsmp_coresinstead to create the cores in the chip.
- removed the use ofppc_get_vcpu_dt_id()
- added "POWER8E" and "POWER8NVL" cpu models to exercice the PnvChipClasshw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 170 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 ++ include/hw/ppc/pnv_core.h | 47 +++++++++++ 5 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_core.c create mode 100644 include/hw/ppc/pnv_core.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 +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 +114
-0@@ -35,6 +35,7 @@#include "hw/ppc/fdt.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_core.h" #include "hw/loader.h" #include "exec/address-spaces.h" #include "qemu/cutils.h" @@ -98,6 +99,136 @@ static int powernv_populate_memory(void *fdt)return 0 ; } +/* +* The PowerNV cores (and threads) need to use real HW ids and not an +* incremental index like it has been done on other platforms. This HW +* id is called a PIR and is used in the device tree, in the XSCOM +* communication to address cores, in the interrupt servers. +*/ +static void powernv_create_core_node (PnvCore *pc,void *fdt, +int cpus_offset,int chip_id) +{ +CPUCore *core =CPU_CORE (pc); +CPUState *cs =CPU (DEVICE (pc->threads)); +DeviceClass *dc =DEVICE_GET_CLASS (cs); +PowerPCCPU *cpu =POWERPC_CPU (cs); +int smt_threads =ppc_get_compat_smt_threads (cpu); +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cs); +uint32_t servers_prop[smt_threads]; +uint32_t gservers_prop[smt_threads *2 ]; +int i; +uint32_t segs[] = {cpu_to_be32 (28 ),cpu_to_be32 (40 ), +0xffffffff ,0xffffffff }; +uint32_t tbfreq =PNV_TIMEBASE_FREQ ; +uint32_t cpufreq =1000000000 ; +uint32_t page_sizes_prop[64 ]; +size_t page_sizes_prop_size; +const uint8_t pa_features[] = {24 ,0 , +0xf6 ,0x3f ,0xc7 ,0xc0 ,0x80 ,0xf0 , +0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x00 , +0x80 ,0x00 ,0x80 ,0x00 ,0x80 ,0x00 }; +int offset; +char *nodename; + + nodename =g_strdup_printf ("%s@%x" , dc->fw_name, core->core_id); + offset =fdt_add_subnode (fdt, cpus_offset, nodename); +_FDT (offset); +g_free (nodename); + +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,chip-id" , chip_id))); + +_FDT ((fdt_setprop_cell (fdt, offset,"reg" , core->core_id))); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,pir" , core->core_id))); +_FDT ((fdt_setprop_string (fdt, offset,"device_type" ,"cpu" ))); + +_FDT ((fdt_setprop_cell (fdt, offset,"cpu-version" , env->spr[SPR_PVR ]))); +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-block-size" , + env->dcache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-line-size" , + env->dcache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-block-size" , + env->icache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-line-size" , + env->icache_line_size))); + +if (pcc->l1_dcache_size) { +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-size" , + pcc->l1_dcache_size))); + }else { +error_report ("Warning: Unknown L1 dcache size for cpu" ); + } +if (pcc->l1_icache_size) { +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-size" , + pcc->l1_icache_size))); + }else { +error_report ("Warning: Unknown L1 icache size for cpu" ); + } + +_FDT ((fdt_setprop_cell (fdt, offset,"timebase-frequency" , tbfreq))); +_FDT ((fdt_setprop_cell (fdt, offset,"clock-frequency" , cpufreq))); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,slb-size" , env->slb_nr))); +_FDT ((fdt_setprop_string (fdt, offset,"status" ,"okay" ))); +_FDT ((fdt_setprop (fdt, offset,"64-bit" ,NULL ,0 ))); + +if (env->spr_cb[SPR_PURR ].oea_read) { +_FDT ((fdt_setprop (fdt, offset,"ibm,purr" ,NULL ,0 ))); + } + +if (env->mmu_model &POWERPC_MMU_1TSEG ) { +_FDT ((fdt_setprop (fdt, offset,"ibm,processor-segment-sizes" , + segs,sizeof (segs)))); + } + +/* Advertise VMX/VSX (vector extensions) if available +* 0 / no property == no vector extensions +* 1 == VMX / Altivec available +* 2 == VSX available */ +if (env->insns_flags &PPC_ALTIVEC ) { +uint32_t vmx = (env->insns_flags2 &PPC2_VSX ) ?2 :1 ; + +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,vmx" , vmx))); + } + +/* Advertise DFP (Decimal Floating Point) if available +* 0 / no property == no DFP +* 1 == DFP available */ +if (env->insns_flags2 &PPC2_DFP ) { +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,dfp" ,1 ))); + } + + page_sizes_prop_size =ppc_create_page_sizes_prop (env, page_sizes_prop, +sizeof (page_sizes_prop)); +if (page_sizes_prop_size) { +_FDT ((fdt_setprop (fdt, offset,"ibm,segment-page-sizes" , + page_sizes_prop, page_sizes_prop_size))); + } + +_FDT ((fdt_setprop (fdt, offset,"ibm,pa-features" , + pa_features,sizeof (pa_features)))); + +if (cpu->cpu_version) { +_FDT ((fdt_setprop_cell (fdt, offset,"cpu-version" , cpu->cpu_version))); + } +
hw/ppc/pnv.c static int powernv_populate_memory(void *fdt) · line 224
Quoted 10 lines
hw/ppc/pnv.c +10
-0+/* Build interrupt servers and gservers properties */ +for (i =0 ; i < smt_threads; i++) { + servers_prop[i] =cpu_to_be32 (core->core_id + i); +/* Hack, direct the group queues back to cpu 0 +* +* FIXME: check that we still need this hack with real HW +* ids. Probably not. +*/ + gservers_prop[i *2 ] =cpu_to_be32 (core->core_id + i); + gservers_prop[i *2 +1 ] =0 ;
I'm not sure the group servers concept even makes sense in the case of powernv. In powernv, doesn't the guest control the "real" xics, including the link registers, and therefore can configure its own groups, rather than being limited to what firmware has set up as for PAPR?
Quoted 42 lines
hw/ppc/pnv.c +24
-0+ } +_FDT ((fdt_setprop (fdt, offset,"ibm,ppc-interrupt-server#s" , + servers_prop,sizeof (servers_prop)))); +_FDT ((fdt_setprop (fdt, offset,"ibm,ppc-interrupt-gserver#s" , + gservers_prop,sizeof (gservers_prop)))); +} +static void *powernv_create_fdt (PnvMachineState *pnv,const char *kernel_cmdline) {@@ -106,6 +237,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off;int i; +int cpus_offset; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -150,6 +282,22 @@ static void *powernv_create_fdt(PnvMachineState *pnv,xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); } +/* cpus */ + cpus_offset =fdt_add_subnode (fdt,0 ,"cpus" ); +_FDT (cpus_offset); +_FDT ((fdt_setprop_cell (fdt, cpus_offset,"#address-cells" ,0x1 ))); +_FDT ((fdt_setprop_cell (fdt, cpus_offset,"#size-cells" ,0x0 ))); + +for (i =0 ; i < pnv->num_chips; i++) { +PnvChip *chip = pnv->chips[i]; +int j; + +for (j =0 ; j < chip->num_cores; j++) { +powernv_create_core_node (&chip->cores[j], fdt, cpus_offset, + chip->chip_id); + } + } +return fdt; }
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 381
Quoted 4 lines
hw/ppc/pnv.c +1
-0@@ -230,6 +378,11 @@ static void ppc_powernv_init(MachineState *machine)for (i =0 ; i < pnv->num_chips; i++) {Object *chip =object_new (chip_typename);object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_int (chip, smp_cores,"num-cores" , &error_abort);
This should probably be &error_fatal, again.
Quoted 40 lines
hw/ppc/pnv.c +25
-0+/* +* We could set a custom cores_mask for the chip here. +*/ +object_property_set_bool (chip, true,"realized" , &error_abort); pnv->chips[i] =PNV_CHIP (chip); }@@ -335,19 +488,70 @@ static const TypeInfo pnv_chip_power8e_info = { .class_init = pnv_chip_power8e_class_init, }; +/* +* This is different for POWER9 so we might need a ops in the chip to +* calculate the core pirs +*/ +#define P8_PIR (chip_id, core_id) (((chip_id) << 7) | ((core_id) << 3)) +static void pnv_chip_realize (DeviceState *dev,Error **errp) {PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +char *typename =pnv_core_typename (pcc->cpu_model); +size_t typesize =object_type_get_instance_size (typename); +int i, core_hwid; + +if (!object_class_by_name (typename)) { +error_setg (errp,"Unable to find PowerNV CPU Core '%s'" , typename); +return ; + }/* Set up XSCOM bus */ chip->xscom =xscom_create (chip); +if (chip->num_cores > pcc->cores_max) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: too many cores for chip ! " +"Limiting to %d\n" , __func__, pcc->cores_max); + chip->num_cores = pcc->cores_max; + } + + chip->cores =g_new0 (PnvCore, chip->num_cores);
hw/ppc/pnv.c static const TypeInfo pnv_chip_power8e_info = { · line 529
Quoted 10 lines
hw/ppc/pnv.c +10
-0+ +/* 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; + } + +for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) + && (i < chip->num_cores); core_hwid++) { +PnvCore *pnv_core = &chip->cores[i];
Unfortunately, as with spapr core creating its threads you'll need some fancier pointer manipulation to handle the possibility of subtypes of PnvCore with a different instance size. That doesn't happen now, but it can in theory.
Quoted 14 lines
hw/ppc/pnv.c +14
-0+ +if (!(chip->cores_mask & (1 << core_hwid))) { +continue ; + } + +object_initialize (pnv_core, typesize, typename); +object_property_set_int (OBJECT (pnv_core), smp_threads,"nr-threads" , + &error_fatal); +object_property_set_int (OBJECT (pnv_core), +P8_PIR (chip->chip_id, core_hwid), +CPU_CORE_PROP_CORE_ID , &error_fatal); +object_property_set_bool (OBJECT (pnv_core), true,"realized" , + &error_fatal); +object_unref (OBJECT (pnv_core));
hw/ppc/pnv.c static const TypeInfo pnv_chip_power8e_info = { · line 553
Quoted 10 lines
hw/ppc/pnv.c +5
-0+ i++; + } +g_free (typename); + pcc->realize (chip, errp); }static Property pnv_chip_properties[] = {DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,0 ), +DEFINE_PROP_UINT32 ("num-cores" , PnvChip, num_cores,1 ),
I suggest renaming this to "nr-cores" to match "nr-threads" inside the core object.
Quoted 37 lines
hw/ppc/pnv.c +1
-0+DEFINE_PROP_UINT32 ("cores-mask" , PnvChip, cores_mask,0x0 ), DEFINE_PROP_END_OF_LIST(), };hw/ppc/pnv_core.c new file +27
-0@@ -0,0 +1,170 @@ +/* +* QEMU PowerPC PowerNV CPU Core model +* +* Copyright (c) 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 "sysemu/sysemu.h" +#include "qapi/error.h" +#include "target-ppc/cpu.h" +#include "hw/ppc/ppc.h" +#include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_core.h" + +static void powernv_cpu_reset (void *opaque)
hw/ppc/pnv_core.c line 37
Quoted 10 lines
hw/ppc/pnv_core.c new file +10
-0+{ +PowerPCCPU *cpu = opaque; +CPUState *cs =CPU (cpu); +CPUPPCState *env = &cpu->env; +MachineState *machine =MACHINE (qdev_get_machine ()); +PnvMachineState *pnv =POWERNV_MACHINE (machine); + +cpu_reset (cs); + + env->spr[SPR_PIR ] = cs->cpu_index;
This can't work. Your PIR values aren't contiguous, but cpu_index values must be (until you get hotplug).
hw/ppc/pnv_core.c line 39
Quoted 2 lines
hw/ppc/pnv_core.c new file +2
-0+ env->spr[SPR_HIOR ] =0 ; + env->gpr[3 ] = pnv->fdt_addr;
Is the fdt address injected for all CPUs, or only the boot CPU?
Quoted 214 lines
hw/ppc/pnv_core.c new file +131
-0+ env->nip =0x10 ; + env->msr |=MSR_HVB ; +} + +static void powernv_cpu_init (PowerPCCPU *cpu,Error **errp) +{ +CPUPPCState *env = &cpu->env; + +/* Set time-base frequency to 512 MHz */ +cpu_ppc_tb_init (env,PNV_TIMEBASE_FREQ ); + +/* MSR[IP] doesn't exist nowadays */ + env->msr_mask &= ~(1 <<6 ); + +qemu_register_reset (powernv_cpu_reset, cpu); +powernv_cpu_reset (cpu); +} + +static void pnv_core_realize_child (Object *child,Error **errp) +{ +Error *local_err =NULL ; +CPUState *cs =CPU (child); +PowerPCCPU *cpu =POWERPC_CPU (cs); + +object_property_set_bool (child, true,"realized" , &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +powernv_cpu_init (cpu, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } +} + +static void pnv_core_realize (DeviceState *dev,Error **errp) +{ +PnvCore *pc =PNV_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (OBJECT (dev)); +PnvCoreClass *pcc =PNV_CORE_GET_CLASS (OBJECT (dev)); +const char *typename =object_class_get_name (pcc->cpu_oc); +size_t size =object_type_get_instance_size (typename); +Error *local_err =NULL ; +void *obj; +int i, j; + + pc->threads =g_malloc0 (size * cc->nr_threads); +for (i =0 ; i < cc->nr_threads; i++) { +char id[32 ]; +CPUState *cs; + + obj = pc->threads + i * size; + +object_initialize (obj, size, typename); + cs =CPU (obj); + cs->cpu_index = cc->core_id + i; +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (pc), id, obj, &local_err); +if (local_err) { + goto err; + } +object_unref (obj); + } + +for (j =0 ; j < cc->nr_threads; j++) { + obj = pc->threads + j * size; + +pnv_core_realize_child (obj, &local_err); +if (local_err) { + goto err; + } + } +return ; + +err: +while (--i >=0 ) { + obj = pc->threads + i * size; +object_unparent (obj); + } +g_free (pc->threads); +error_propagate (errp, local_err); +} + +/* +* Grow this list or merge with SPAPRCoreInfo which is very similar +*/ +static const char *pnv_core_models[] = {"POWER8E" ,"POWER8" ,"POWER8NVL" }; + +static void pnv_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +PnvCoreClass *pcc =PNV_CORE_CLASS (oc); + + dc->realize = pnv_core_realize; + pcc->cpu_oc =cpu_class_by_name (TYPE_POWERPC_CPU , data); +} + +static const TypeInfo pnv_core_info = { + .name =TYPE_PNV_CORE , + .parent =TYPE_CPU_CORE , + .instance_size =sizeof (PnvCore), + .class_size =sizeof (PnvCoreClass), + .abstract = true, +}; + +static void pnv_core_register_types (void ) +{ +int i ; + +type_register_static (&pnv_core_info); +for (i =0 ; i <ARRAY_SIZE (pnv_core_models); ++i) { +TypeInfo ti = { + .parent =TYPE_PNV_CORE , + .instance_size =sizeof (PnvCore), + .class_init = pnv_core_class_init, + .class_data = (void *) pnv_core_models[i], + }; + ti.name =pnv_core_typename (pnv_core_models[i]); +type_register (&ti); +g_free ((void *)ti.name); + } +} + +type_init (pnv_core_register_types) + +char *pnv_core_typename(const char *model) +{ +return g_strdup_printf (TYPE_PNV_CORE "-%s" , model); +}include/hw/ppc/pnv.h +7
-0@@ -36,6 +36,7 @@ typedef enum PnvChipType { } PnvChipType;typedef struct XScomBus XScomBus ; +typedef struct PnvCore PnvCore ; typedef struct PnvChip { /*< private >*/ SysBusDevice parent_obj;@@ -43,6 +44,10 @@ typedef struct PnvChip {/*< public >*/ uint32_t chip_id;XScomBus *xscom; + +uint32_t num_cores; +uint32_t cores_mask; +PnvCore *cores; } PnvChip; typedef struct PnvChipClass {@@ -109,4 +114,6 @@ typedef struct PnvMachineState { PnvChip **chips; } PnvMachineState; +#define PNV_TIMEBASE_FREQ 512000000ULL +#endif /* _PPC_PNV_H */ include/hw/ppc/pnv_core.h new file +47
-0@@ -0,0 +1,47 @@ +/* +* QEMU PowerPC PowerNV CPU Core model +* +* 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_CORE_H +#define _PPC_PNV_CORE_H + +#include "hw/cpu/core.h" + +#define TYPE_PNV_CORE "powernv-cpu-core" +#define PNV_CORE (obj) \ + OBJECT_CHECK(PnvCore, (obj), TYPE_PNV_CORE) +#define PNV_CORE_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvCoreClass, (klass), TYPE_PNV_CORE) +#define PNV_CORE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvCoreClass, (obj), TYPE_PNV_CORE) + +typedef struct PnvCore { +/*< private >*/ +CPUCore parent_obj; + +/*< public >*/ +void *threads; +}PnvCore ; + +typedef struct PnvCoreClass { +DeviceClass parent_class; +ObjectClass *cpu_oc; +}PnvCoreClass ; + +extern char *pnv_core_typename (const char *model); + +#endif /* _PPC_PNV_CORE_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 v2 5/7] ppc/pnv: add a PnvCore object
Quoted 187 lines · David Gibson
Quoted 186 lines · Cédric Le Goater
This is largy inspired by sPAPRCPUCore with some simplification, no hotplug for instance. But the differences are small and the objects could possibly be merged.
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. This id is stored in
CPUState->cpu_indexand inPnvCore->core_idand it is used to populate the device tree.Signed-off-by Cédric Le Goater <[email protected]>---
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
- reworkedpowernv_create_core_node()which populates the device tree
- added missing "ibm,pa-features" property
-smp_cpusrepresenting threads, usedsmp_coresinstead to create the cores in the chip.
- removed the use ofppc_get_vcpu_dt_id()
- added "POWER8E" and "POWER8NVL" cpu models to exercice the PnvChipClasshw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 170 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 ++ include/hw/ppc/pnv_core.h | 47 +++++++++++ 5 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_core.c create mode 100644 include/hw/ppc/pnv_core.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 +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 +122
-0@@ -35,6 +35,7 @@#include "hw/ppc/fdt.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_core.h" #include "hw/loader.h" #include "exec/address-spaces.h" #include "qemu/cutils.h" @@ -98,6 +99,136 @@ static int powernv_populate_memory(void *fdt)return 0 ; } +/* +* The PowerNV cores (and threads) need to use real HW ids and not an +* incremental index like it has been done on other platforms. This HW +* id is called a PIR and is used in the device tree, in the XSCOM +* communication to address cores, in the interrupt servers. +*/ +static void powernv_create_core_node (PnvCore *pc,void *fdt, +int cpus_offset,int chip_id) +{ +CPUCore *core =CPU_CORE (pc); +CPUState *cs =CPU (DEVICE (pc->threads)); +DeviceClass *dc =DEVICE_GET_CLASS (cs); +PowerPCCPU *cpu =POWERPC_CPU (cs); +int smt_threads =ppc_get_compat_smt_threads (cpu); +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cs); +uint32_t servers_prop[smt_threads]; +uint32_t gservers_prop[smt_threads *2 ]; +int i; +uint32_t segs[] = {cpu_to_be32 (28 ),cpu_to_be32 (40 ), +0xffffffff ,0xffffffff }; +uint32_t tbfreq =PNV_TIMEBASE_FREQ ; +uint32_t cpufreq =1000000000 ; +uint32_t page_sizes_prop[64 ]; +size_t page_sizes_prop_size; +const uint8_t pa_features[] = {24 ,0 , +0xf6 ,0x3f ,0xc7 ,0xc0 ,0x80 ,0xf0 , +0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x00 , +0x80 ,0x00 ,0x80 ,0x00 ,0x80 ,0x00 }; +int offset; +char *nodename; + + nodename =g_strdup_printf ("%s@%x" , dc->fw_name, core->core_id); + offset =fdt_add_subnode (fdt, cpus_offset, nodename); +_FDT (offset); +g_free (nodename); + +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,chip-id" , chip_id))); + +_FDT ((fdt_setprop_cell (fdt, offset,"reg" , core->core_id))); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,pir" , core->core_id))); +_FDT ((fdt_setprop_string (fdt, offset,"device_type" ,"cpu" ))); + +_FDT ((fdt_setprop_cell (fdt, offset,"cpu-version" , env->spr[SPR_PVR ]))); +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-block-size" , + env->dcache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-line-size" , + env->dcache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-block-size" , + env->icache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-line-size" , + env->icache_line_size))); + +if (pcc->l1_dcache_size) { +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-size" , + pcc->l1_dcache_size))); + }else { +error_report ("Warning: Unknown L1 dcache size for cpu" ); + } +if (pcc->l1_icache_size) { +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-size" , + pcc->l1_icache_size))); + }else { +error_report ("Warning: Unknown L1 icache size for cpu" ); + } + +_FDT ((fdt_setprop_cell (fdt, offset,"timebase-frequency" , tbfreq))); +_FDT ((fdt_setprop_cell (fdt, offset,"clock-frequency" , cpufreq))); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,slb-size" , env->slb_nr))); +_FDT ((fdt_setprop_string (fdt, offset,"status" ,"okay" ))); +_FDT ((fdt_setprop (fdt, offset,"64-bit" ,NULL ,0 ))); + +if (env->spr_cb[SPR_PURR ].oea_read) { +_FDT ((fdt_setprop (fdt, offset,"ibm,purr" ,NULL ,0 ))); + } + +if (env->mmu_model &POWERPC_MMU_1TSEG ) { +_FDT ((fdt_setprop (fdt, offset,"ibm,processor-segment-sizes" , + segs,sizeof (segs)))); + } + +/* Advertise VMX/VSX (vector extensions) if available +* 0 / no property == no vector extensions +* 1 == VMX / Altivec available +* 2 == VSX available */ +if (env->insns_flags &PPC_ALTIVEC ) { +uint32_t vmx = (env->insns_flags2 &PPC2_VSX ) ?2 :1 ; + +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,vmx" , vmx))); + } + +/* Advertise DFP (Decimal Floating Point) if available +* 0 / no property == no DFP +* 1 == DFP available */ +if (env->insns_flags2 &PPC2_DFP ) { +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,dfp" ,1 ))); + } + + page_sizes_prop_size =ppc_create_page_sizes_prop (env, page_sizes_prop, +sizeof (page_sizes_prop)); +if (page_sizes_prop_size) { +_FDT ((fdt_setprop (fdt, offset,"ibm,segment-page-sizes" , + page_sizes_prop, page_sizes_prop_size))); + } + +_FDT ((fdt_setprop (fdt, offset,"ibm,pa-features" , + pa_features,sizeof (pa_features)))); + +if (cpu->cpu_version) { +_FDT ((fdt_setprop_cell (fdt, offset,"cpu-version" , cpu->cpu_version))); + } + +/* Build interrupt servers and gservers properties */ +for (i =0 ; i < smt_threads; i++) { + servers_prop[i] =cpu_to_be32 (core->core_id + i); +/* Hack, direct the group queues back to cpu 0 +* +* FIXME: check that we still need this hack with real HW +* ids. Probably not. +*/
Quoted 8 lines
hw/ppc/pnv.c static int powernv_populate_memory(void *fdt) · line 224
Quoted 2 lines
hw/ppc/pnv.c +2
-0+ gservers_prop[i *2 ] =cpu_to_be32 (core->core_id + i); + gservers_prop[i *2 +1 ] =0 ;I'm not sure the group servers concept even makes sense in the case of powernv. In powernv, doesn't the guest control the "real" xics, including the link registers, and therefore can configure its own groups, rather than being limited to what firmware has set up as for PAPR?
yes. we can remove this property.
Quoted 41 lines
Quoted 41 lines
hw/ppc/pnv.c +24
-0+ } +_FDT ((fdt_setprop (fdt, offset,"ibm,ppc-interrupt-server#s" , + servers_prop,sizeof (servers_prop)))); +_FDT ((fdt_setprop (fdt, offset,"ibm,ppc-interrupt-gserver#s" , + gservers_prop,sizeof (gservers_prop)))); +} +static void *powernv_create_fdt (PnvMachineState *pnv,const char *kernel_cmdline) {@@ -106,6 +237,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off;int i; +int cpus_offset; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -150,6 +282,22 @@ static void *powernv_create_fdt(PnvMachineState *pnv,xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); } +/* cpus */ + cpus_offset =fdt_add_subnode (fdt,0 ,"cpus" ); +_FDT (cpus_offset); +_FDT ((fdt_setprop_cell (fdt, cpus_offset,"#address-cells" ,0x1 ))); +_FDT ((fdt_setprop_cell (fdt, cpus_offset,"#size-cells" ,0x0 ))); + +for (i =0 ; i < pnv->num_chips; i++) { +PnvChip *chip = pnv->chips[i]; +int j; + +for (j =0 ; j < chip->num_cores; j++) { +powernv_create_core_node (&chip->cores[j], fdt, cpus_offset, + chip->chip_id); + } + } +return fdt; }
Quoted 7 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 381
Quoted 5 lines
hw/ppc/pnv.c +1
-0@@ -230,6 +378,11 @@ static void ppc_powernv_init(MachineState *machine)for (i =0 ; i < pnv->num_chips; i++) {Object *chip =object_new (chip_typename);object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_int (chip, smp_cores,"num-cores" , &error_abort);This should probably be
&error_fatal, again.
ok.
Quoted 48 lines
Quoted 48 lines
hw/ppc/pnv.c +33
-0+/* +* We could set a custom cores_mask for the chip here. +*/ +object_property_set_bool (chip, true,"realized" , &error_abort); pnv->chips[i] =PNV_CHIP (chip); }@@ -335,19 +488,70 @@ static const TypeInfo pnv_chip_power8e_info = { .class_init = pnv_chip_power8e_class_init, }; +/* +* This is different for POWER9 so we might need a ops in the chip to +* calculate the core pirs +*/ +#define P8_PIR (chip_id, core_id) (((chip_id) << 7) | ((core_id) << 3)) +static void pnv_chip_realize (DeviceState *dev,Error **errp) {PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +char *typename =pnv_core_typename (pcc->cpu_model); +size_t typesize =object_type_get_instance_size (typename); +int i, core_hwid; + +if (!object_class_by_name (typename)) { +error_setg (errp,"Unable to find PowerNV CPU Core '%s'" , typename); +return ; + }/* Set up XSCOM bus */ chip->xscom =xscom_create (chip); +if (chip->num_cores > pcc->cores_max) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: too many cores for chip ! " +"Limiting to %d\n" , __func__, pcc->cores_max); + chip->num_cores = pcc->cores_max; + } + + chip->cores =g_new0 (PnvCore, chip->num_cores); + +/* 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; + } + + for (i = 0, core_hwid = 0; (core_hwid < sizeof(chip->cores_mask) * 8)
Quoted 8 lines
hw/ppc/pnv.c static const TypeInfo pnv_chip_power8e_info = { · line 529
Quoted 2 lines
hw/ppc/pnv.c +2
-0+ && (i < chip->num_cores); core_hwid++) { +PnvCore *pnv_core = &chip->cores[i];Unfortunately, as with spapr core creating its threads you'll need some fancier pointer manipulation to handle the possibility of subtypes of PnvCore with a different instance size. That doesn't happen now, but it can in theory.
Yes. This is a reason why I preferred to have a Object **cores. I will fix that.
I don't really like that :
void *obj = chip->cores + i * size;
It does not feel "object-oriented".
Quoted 21 lines
Quoted 21 lines
hw/ppc/pnv.c +18
-0+ +if (!(chip->cores_mask & (1 << core_hwid))) { +continue ; + } + +object_initialize (pnv_core, typesize, typename); +object_property_set_int (OBJECT (pnv_core), smp_threads,"nr-threads" , + &error_fatal); +object_property_set_int (OBJECT (pnv_core), +P8_PIR (chip->chip_id, core_hwid), +CPU_CORE_PROP_CORE_ID , &error_fatal); +object_property_set_bool (OBJECT (pnv_core), true,"realized" , + &error_fatal); +object_unref (OBJECT (pnv_core)); + i++; + } +g_free (typename); + pcc->realize (chip, errp); }
Quoted 6 lines
hw/ppc/pnv.c static const TypeInfo pnv_chip_power8e_info = { · line 553
Quoted 3 lines
hw/ppc/pnv.c +1
-0static Property pnv_chip_properties[] = {DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,0 ), +DEFINE_PROP_UINT32 ("num-cores" , PnvChip, num_cores,1 ),I suggest renaming this to "nr-cores" to match "nr-threads" inside the core object.
ok. fine for me.
Quoted 42 lines
Quoted 42 lines
hw/ppc/pnv.c +1
-0+DEFINE_PROP_UINT32 ("cores-mask" , PnvChip, cores_mask,0x0 ), DEFINE_PROP_END_OF_LIST(), };hw/ppc/pnv_core.c new file +32
-0@@ -0,0 +1,170 @@ +/* +* QEMU PowerPC PowerNV CPU Core model +* +* Copyright (c) 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 "sysemu/sysemu.h" +#include "qapi/error.h" +#include "target-ppc/cpu.h" +#include "hw/ppc/ppc.h" +#include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_core.h" + +static void powernv_cpu_reset (void *opaque) +{ +PowerPCCPU *cpu = opaque; +CPUState *cs =CPU (cpu); +CPUPPCState *env = &cpu->env; +MachineState *machine =MACHINE (qdev_get_machine ());
Quoted 8 lines
hw/ppc/pnv_core.c line 37
Quoted 5 lines
hw/ppc/pnv_core.c new file +5
-0+PnvMachineState *pnv =POWERNV_MACHINE (machine); + +cpu_reset (cs); + + env->spr[SPR_PIR ] = cs->cpu_index;This can't work. Your PIR values aren't contiguous, but
cpu_indexvalues must be (until you get hotplug).
cpu_index are not contiguous indeed. They are assigned in pnv_core_realize()
cs->cpu_index = cc->core_id + i;
For this to work, we need the four xics patches Nikunj is working on plus some helper routines to assign and find an icp depending on cs and not an index anymore.
I will revive the thread with an extra patch.
Quoted 4 lines
hw/ppc/pnv_core.c line 39
Quoted 2 lines
hw/ppc/pnv_core.c new file +2
-0+ env->spr[SPR_HIOR ] =0 ; + env->gpr[3 ] = pnv->fdt_addr;Is the fdt address injected for all CPUs, or only the boot CPU?
skiboot will just pick just any boot cpu. My understanding is that all need to have the flat device tree address in r3.
Thanks,
C.
Quoted 215 lines
Quoted 214 lines
hw/ppc/pnv_core.c new file +131
-0+ env->nip =0x10 ; + env->msr |=MSR_HVB ; +} + +static void powernv_cpu_init (PowerPCCPU *cpu,Error **errp) +{ +CPUPPCState *env = &cpu->env; + +/* Set time-base frequency to 512 MHz */ +cpu_ppc_tb_init (env,PNV_TIMEBASE_FREQ ); + +/* MSR[IP] doesn't exist nowadays */ + env->msr_mask &= ~(1 <<6 ); + +qemu_register_reset (powernv_cpu_reset, cpu); +powernv_cpu_reset (cpu); +} + +static void pnv_core_realize_child (Object *child,Error **errp) +{ +Error *local_err =NULL ; +CPUState *cs =CPU (child); +PowerPCCPU *cpu =POWERPC_CPU (cs); + +object_property_set_bool (child, true,"realized" , &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +powernv_cpu_init (cpu, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } +} + +static void pnv_core_realize (DeviceState *dev,Error **errp) +{ +PnvCore *pc =PNV_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (OBJECT (dev)); +PnvCoreClass *pcc =PNV_CORE_GET_CLASS (OBJECT (dev)); +const char *typename =object_class_get_name (pcc->cpu_oc); +size_t size =object_type_get_instance_size (typename); +Error *local_err =NULL ; +void *obj; +int i, j; + + pc->threads =g_malloc0 (size * cc->nr_threads); +for (i =0 ; i < cc->nr_threads; i++) { +char id[32 ]; +CPUState *cs; + + obj = pc->threads + i * size; + +object_initialize (obj, size, typename); + cs =CPU (obj); + cs->cpu_index = cc->core_id + i; +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (pc), id, obj, &local_err); +if (local_err) { + goto err; + } +object_unref (obj); + } + +for (j =0 ; j < cc->nr_threads; j++) { + obj = pc->threads + j * size; + +pnv_core_realize_child (obj, &local_err); +if (local_err) { + goto err; + } + } +return ; + +err: +while (--i >=0 ) { + obj = pc->threads + i * size; +object_unparent (obj); + } +g_free (pc->threads); +error_propagate (errp, local_err); +} + +/* +* Grow this list or merge with SPAPRCoreInfo which is very similar +*/ +static const char *pnv_core_models[] = {"POWER8E" ,"POWER8" ,"POWER8NVL" }; + +static void pnv_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +PnvCoreClass *pcc =PNV_CORE_CLASS (oc); + + dc->realize = pnv_core_realize; + pcc->cpu_oc =cpu_class_by_name (TYPE_POWERPC_CPU , data); +} + +static const TypeInfo pnv_core_info = { + .name =TYPE_PNV_CORE , + .parent =TYPE_CPU_CORE , + .instance_size =sizeof (PnvCore), + .class_size =sizeof (PnvCoreClass), + .abstract = true, +}; + +static void pnv_core_register_types (void ) +{ +int i ; + +type_register_static (&pnv_core_info); +for (i =0 ; i <ARRAY_SIZE (pnv_core_models); ++i) { +TypeInfo ti = { + .parent =TYPE_PNV_CORE , + .instance_size =sizeof (PnvCore), + .class_init = pnv_core_class_init, + .class_data = (void *) pnv_core_models[i], + }; + ti.name =pnv_core_typename (pnv_core_models[i]); +type_register (&ti); +g_free ((void *)ti.name); + } +} + +type_init (pnv_core_register_types) + +char *pnv_core_typename(const char *model) +{ +return g_strdup_printf (TYPE_PNV_CORE "-%s" , model); +}include/hw/ppc/pnv.h +7
-0@@ -36,6 +36,7 @@ typedef enum PnvChipType { } PnvChipType;typedef struct XScomBus XScomBus ; +typedef struct PnvCore PnvCore ; typedef struct PnvChip { /*< private >*/ SysBusDevice parent_obj;@@ -43,6 +44,10 @@ typedef struct PnvChip {/*< public >*/ uint32_t chip_id;XScomBus *xscom; + +uint32_t num_cores; +uint32_t cores_mask; +PnvCore *cores; } PnvChip; typedef struct PnvChipClass {@@ -109,4 +114,6 @@ typedef struct PnvMachineState { PnvChip **chips; } PnvMachineState; +#define PNV_TIMEBASE_FREQ 512000000ULL +#endif /* _PPC_PNV_H */ include/hw/ppc/pnv_core.h new file +47
-0@@ -0,0 +1,47 @@ +/* +* QEMU PowerPC PowerNV CPU Core model +* +* 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_CORE_H +#define _PPC_PNV_CORE_H + +#include "hw/cpu/core.h" + +#define TYPE_PNV_CORE "powernv-cpu-core" +#define PNV_CORE (obj) \ + OBJECT_CHECK(PnvCore, (obj), TYPE_PNV_CORE) +#define PNV_CORE_CLASS (klass) \ + OBJECT_CLASS_CHECK(PnvCoreClass, (klass), TYPE_PNV_CORE) +#define PNV_CORE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PnvCoreClass, (obj), TYPE_PNV_CORE) + +typedef struct PnvCore { +/*< private >*/ +CPUCore parent_obj; + +/*< public >*/ +void *threads; +}PnvCore ; + +typedef struct PnvCoreClass { +DeviceClass parent_class; +ObjectClass *cpu_oc; +}PnvCoreClass ; + +extern char *pnv_core_typename (const char *model); + +#endif /* _PPC_PNV_CORE_H */
Re: [Qemu-devel] [PATCH v2 5/7] ppc/pnv: add a PnvCore object
Quoted 307 lines · Cédric Le Goater
Quoted 187 lines · David Gibson
Quoted 186 lines · Cédric Le Goater
This is largy inspired by sPAPRCPUCore with some simplification, no hotplug for instance. But the differences are small and the objects could possibly be merged.
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. This id is stored in
CPUState->cpu_indexand inPnvCore->core_idand it is used to populate the device tree.Signed-off-by Cédric Le Goater <[email protected]>---
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
- reworkedpowernv_create_core_node()which populates the device tree
- added missing "ibm,pa-features" property
-smp_cpusrepresenting threads, usedsmp_coresinstead to create the cores in the chip.
- removed the use ofppc_get_vcpu_dt_id()
- added "POWER8E" and "POWER8NVL" cpu models to exercice the PnvChipClasshw/ppc/Makefile.objs | 2 +- hw/ppc/pnv.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/pnv_core.c | 170 ++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv.h | 7 ++ include/hw/ppc/pnv_core.h | 47 +++++++++++ 5 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/pnv_core.c create mode 100644 include/hw/ppc/pnv_core.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 +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 +122
-0@@ -35,6 +35,7 @@#include "hw/ppc/fdt.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_core.h" #include "hw/loader.h" #include "exec/address-spaces.h" #include "qemu/cutils.h" @@ -98,6 +99,136 @@ static int powernv_populate_memory(void *fdt)return 0 ; } +/* +* The PowerNV cores (and threads) need to use real HW ids and not an +* incremental index like it has been done on other platforms. This HW +* id is called a PIR and is used in the device tree, in the XSCOM +* communication to address cores, in the interrupt servers. +*/ +static void powernv_create_core_node (PnvCore *pc,void *fdt, +int cpus_offset,int chip_id) +{ +CPUCore *core =CPU_CORE (pc); +CPUState *cs =CPU (DEVICE (pc->threads)); +DeviceClass *dc =DEVICE_GET_CLASS (cs); +PowerPCCPU *cpu =POWERPC_CPU (cs); +int smt_threads =ppc_get_compat_smt_threads (cpu); +CPUPPCState *env = &cpu->env; +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cs); +uint32_t servers_prop[smt_threads]; +uint32_t gservers_prop[smt_threads *2 ]; +int i; +uint32_t segs[] = {cpu_to_be32 (28 ),cpu_to_be32 (40 ), +0xffffffff ,0xffffffff }; +uint32_t tbfreq =PNV_TIMEBASE_FREQ ; +uint32_t cpufreq =1000000000 ; +uint32_t page_sizes_prop[64 ]; +size_t page_sizes_prop_size; +const uint8_t pa_features[] = {24 ,0 , +0xf6 ,0x3f ,0xc7 ,0xc0 ,0x80 ,0xf0 , +0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x00 , +0x80 ,0x00 ,0x80 ,0x00 ,0x80 ,0x00 }; +int offset; +char *nodename; + + nodename =g_strdup_printf ("%s@%x" , dc->fw_name, core->core_id); + offset =fdt_add_subnode (fdt, cpus_offset, nodename); +_FDT (offset); +g_free (nodename); + +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,chip-id" , chip_id))); + +_FDT ((fdt_setprop_cell (fdt, offset,"reg" , core->core_id))); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,pir" , core->core_id))); +_FDT ((fdt_setprop_string (fdt, offset,"device_type" ,"cpu" ))); + +_FDT ((fdt_setprop_cell (fdt, offset,"cpu-version" , env->spr[SPR_PVR ]))); +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-block-size" , + env->dcache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-line-size" , + env->dcache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-block-size" , + env->icache_line_size))); +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-line-size" , + env->icache_line_size))); + +if (pcc->l1_dcache_size) { +_FDT ((fdt_setprop_cell (fdt, offset,"d-cache-size" , + pcc->l1_dcache_size))); + }else { +error_report ("Warning: Unknown L1 dcache size for cpu" ); + } +if (pcc->l1_icache_size) { +_FDT ((fdt_setprop_cell (fdt, offset,"i-cache-size" , + pcc->l1_icache_size))); + }else { +error_report ("Warning: Unknown L1 icache size for cpu" ); + } + +_FDT ((fdt_setprop_cell (fdt, offset,"timebase-frequency" , tbfreq))); +_FDT ((fdt_setprop_cell (fdt, offset,"clock-frequency" , cpufreq))); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,slb-size" , env->slb_nr))); +_FDT ((fdt_setprop_string (fdt, offset,"status" ,"okay" ))); +_FDT ((fdt_setprop (fdt, offset,"64-bit" ,NULL ,0 ))); + +if (env->spr_cb[SPR_PURR ].oea_read) { +_FDT ((fdt_setprop (fdt, offset,"ibm,purr" ,NULL ,0 ))); + } + +if (env->mmu_model &POWERPC_MMU_1TSEG ) { +_FDT ((fdt_setprop (fdt, offset,"ibm,processor-segment-sizes" , + segs,sizeof (segs)))); + } + +/* Advertise VMX/VSX (vector extensions) if available +* 0 / no property == no vector extensions +* 1 == VMX / Altivec available +* 2 == VSX available */ +if (env->insns_flags &PPC_ALTIVEC ) { +uint32_t vmx = (env->insns_flags2 &PPC2_VSX ) ?2 :1 ; + +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,vmx" , vmx))); + } + +/* Advertise DFP (Decimal Floating Point) if available +* 0 / no property == no DFP +* 1 == DFP available */ +if (env->insns_flags2 &PPC2_DFP ) { +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,dfp" ,1 ))); + } + + page_sizes_prop_size =ppc_create_page_sizes_prop (env, page_sizes_prop, +sizeof (page_sizes_prop)); +if (page_sizes_prop_size) { +_FDT ((fdt_setprop (fdt, offset,"ibm,segment-page-sizes" , + page_sizes_prop, page_sizes_prop_size))); + } + +_FDT ((fdt_setprop (fdt, offset,"ibm,pa-features" , + pa_features,sizeof (pa_features)))); + +if (cpu->cpu_version) { +_FDT ((fdt_setprop_cell (fdt, offset,"cpu-version" , cpu->cpu_version))); + } + +/* Build interrupt servers and gservers properties */ +for (i =0 ; i < smt_threads; i++) { + servers_prop[i] =cpu_to_be32 (core->core_id + i); +/* Hack, direct the group queues back to cpu 0 +* +* FIXME: check that we still need this hack with real HW +* ids. Probably not. +*/ Quoted 8 lines
hw/ppc/pnv.c static int powernv_populate_memory(void *fdt) · line 224
Quoted 2 lines
hw/ppc/pnv.c +2
-0+ gservers_prop[i *2 ] =cpu_to_be32 (core->core_id + i); + gservers_prop[i *2 +1 ] =0 ;I'm not sure the group servers concept even makes sense in the case of powernv. In powernv, doesn't the guest control the "real" xics, including the link registers, and therefore can configure its own groups, rather than being limited to what firmware has set up as for PAPR?
yes. we can remove this property.
Quoted 41 lines
Quoted 41 lines
hw/ppc/pnv.c +24
-0+ } +_FDT ((fdt_setprop (fdt, offset,"ibm,ppc-interrupt-server#s" , + servers_prop,sizeof (servers_prop)))); +_FDT ((fdt_setprop (fdt, offset,"ibm,ppc-interrupt-gserver#s" , + gservers_prop,sizeof (gservers_prop)))); +} +static void *powernv_create_fdt (PnvMachineState *pnv,const char *kernel_cmdline) {@@ -106,6 +237,7 @@ static void *powernv_create_fdt(PnvMachineState *pnv,const char plat_compat[] ="qemu,powernv\0ibm,powernv" ;int off;int i; +int cpus_offset; fdt =g_malloc0 (FDT_MAX_SIZE );_FDT ((fdt_create_empty_tree (fdt,FDT_MAX_SIZE )));@@ -150,6 +282,22 @@ static void *powernv_create_fdt(PnvMachineState *pnv,xscom_populate_fdt (pnv->chips[i]->xscom, fdt,0 ); } +/* cpus */ + cpus_offset =fdt_add_subnode (fdt,0 ,"cpus" ); +_FDT (cpus_offset); +_FDT ((fdt_setprop_cell (fdt, cpus_offset,"#address-cells" ,0x1 ))); +_FDT ((fdt_setprop_cell (fdt, cpus_offset,"#size-cells" ,0x0 ))); + +for (i =0 ; i < pnv->num_chips; i++) { +PnvChip *chip = pnv->chips[i]; +int j; + +for (j =0 ; j < chip->num_cores; j++) { +powernv_create_core_node (&chip->cores[j], fdt, cpus_offset, + chip->chip_id); + } + } +return fdt; }Quoted 7 lines
hw/ppc/pnv.c static void ppc_powernv_init(MachineState *machine) · line 381
Quoted 5 lines
hw/ppc/pnv.c +1
-0@@ -230,6 +378,11 @@ static void ppc_powernv_init(MachineState *machine)for (i =0 ; i < pnv->num_chips; i++) {Object *chip =object_new (chip_typename);object_property_set_int (chip,CHIP_HWID (i),"chip-id" , &error_abort); +object_property_set_int (chip, smp_cores,"num-cores" , &error_abort);This should probably be
&error_fatal, again.ok.
Quoted 48 lines
Quoted 48 lines
hw/ppc/pnv.c +33
-0+/* +* We could set a custom cores_mask for the chip here. +*/ +object_property_set_bool (chip, true,"realized" , &error_abort); pnv->chips[i] =PNV_CHIP (chip); }@@ -335,19 +488,70 @@ static const TypeInfo pnv_chip_power8e_info = { .class_init = pnv_chip_power8e_class_init, }; +/* +* This is different for POWER9 so we might need a ops in the chip to +* calculate the core pirs +*/ +#define P8_PIR (chip_id, core_id) (((chip_id) << 7) | ((core_id) << 3)) +static void pnv_chip_realize (DeviceState *dev,Error **errp) {PnvChip *chip =PNV_CHIP (dev);PnvChipClass *pcc =PNV_CHIP_GET_CLASS (chip); +char *typename =pnv_core_typename (pcc->cpu_model); +size_t typesize =object_type_get_instance_size (typename); +int i, core_hwid; + +if (!object_class_by_name (typename)) { +error_setg (errp,"Unable to find PowerNV CPU Core '%s'" , typename); +return ; + }/* Set up XSCOM bus */ chip->xscom =xscom_create (chip); +if (chip->num_cores > pcc->cores_max) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: too many cores for chip ! " +"Limiting to %d\n" , __func__, pcc->cores_max); + chip->num_cores = pcc->cores_max; + } + + chip->cores =g_new0 (PnvCore, chip->num_cores); + +/* 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; + } + + for (i = 0, core_hwid = 0; (core_hwid < sizeof(chip->cores_mask) * 8)Quoted 8 lines
hw/ppc/pnv.c static const TypeInfo pnv_chip_power8e_info = { · line 529
Quoted 2 lines
hw/ppc/pnv.c +2
-0+ && (i < chip->num_cores); core_hwid++) { +PnvCore *pnv_core = &chip->cores[i];Unfortunately, as with spapr core creating its threads you'll need some fancier pointer manipulation to handle the possibility of subtypes of PnvCore with a different instance size. That doesn't happen now, but it can in theory.
Quoted 8 lines
Yes. This is a reason why I preferred to have a Object **cores. I will fix that.
I don't really like that :
void *obj = chip->cores + i * size;It does not feel "object-oriented".
Yeah, it's pretty clunky, but it's what we have for now.
Quoted 81 lines
Quoted 21 lines
Quoted 21 lines
hw/ppc/pnv.c +18
-0+ +if (!(chip->cores_mask & (1 << core_hwid))) { +continue ; + } + +object_initialize (pnv_core, typesize, typename); +object_property_set_int (OBJECT (pnv_core), smp_threads,"nr-threads" , + &error_fatal); +object_property_set_int (OBJECT (pnv_core), +P8_PIR (chip->chip_id, core_hwid), +CPU_CORE_PROP_CORE_ID , &error_fatal); +object_property_set_bool (OBJECT (pnv_core), true,"realized" , + &error_fatal); +object_unref (OBJECT (pnv_core)); + i++; + } +g_free (typename); + pcc->realize (chip, errp); }Quoted 6 lines
hw/ppc/pnv.c static const TypeInfo pnv_chip_power8e_info = { · line 553
Quoted 3 lines
hw/ppc/pnv.c +1
-0static Property pnv_chip_properties[] = {DEFINE_PROP_UINT32 ("chip-id" , PnvChip, chip_id,0 ), +DEFINE_PROP_UINT32 ("num-cores" , PnvChip, num_cores,1 ),I suggest renaming this to "nr-cores" to match "nr-threads" inside the core object.
ok. fine for me.
Quoted 42 lines
Quoted 42 lines
hw/ppc/pnv.c +1
-0+DEFINE_PROP_UINT32 ("cores-mask" , PnvChip, cores_mask,0x0 ), DEFINE_PROP_END_OF_LIST(), };hw/ppc/pnv_core.c new file +32
-0@@ -0,0 +1,170 @@ +/* +* QEMU PowerPC PowerNV CPU Core model +* +* Copyright (c) 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 "sysemu/sysemu.h" +#include "qapi/error.h" +#include "target-ppc/cpu.h" +#include "hw/ppc/ppc.h" +#include "hw/ppc/pnv.h" +#include "hw/ppc/pnv_core.h" + +static void powernv_cpu_reset (void *opaque) +{ +PowerPCCPU *cpu = opaque; +CPUState *cs =CPU (cpu); +CPUPPCState *env = &cpu->env; +MachineState *machine =MACHINE (qdev_get_machine ());Quoted 8 lines
hw/ppc/pnv_core.c line 37
Quoted 5 lines
hw/ppc/pnv_core.c new file +5
-0+PnvMachineState *pnv =POWERNV_MACHINE (machine); + +cpu_reset (cs); + + env->spr[SPR_PIR ] = cs->cpu_index;This can't work. Your PIR values aren't contiguous, but
cpu_indexvalues must be (until you get hotplug).
Quoted 7 lines
cpu_indexare not contiguous indeed. They are assigned inpnv_core_realize()cs->cpu_index = cc->core_id + i;For this to work, we need the four xics patches Nikunj is working on plus some helper routines to assign and find an icp depending on cs and not an index anymore.
That's not the only problem with cpu_index being non-contiguous. Maybe we'll get to a point where that's possible but for the forseeable future, the cpu_index will need to be contiguous (as long as all possible cpus are present, anyway).
For now you should, if possible, derive the non-contiguous platform ids from the contiguous cpu_index when you need them.
Quoted 9 lines
I will revive the thread with an extra patch.
Quoted 4 lines
hw/ppc/pnv_core.c line 39
Quoted 2 lines
hw/ppc/pnv_core.c new file +2
-0+ env->spr[SPR_HIOR ] =0 ; + env->gpr[3 ] = pnv->fdt_addr;Is the fdt address injected for all CPUs, or only the boot CPU?
skiboot will just pick just any boot cpu. My understanding is that all need to have the flat device tree address in r3.
Ok.
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 v2 6/7 ppc/pnv: add a XScomDevice 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 XScomDevice to each core with the associated ranges in the XSCOM address space.
To start with, let's install the DTS (Digital Thermal Sensor) handlers which are easy to handle.
--- hw/ppc/pnv.c | 9 +++++++ hw/ppc/pnv_core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_core.h | 13 +++++++++ 3 files changed, 89 insertions(+)
hw/ppc/pnv.c +9 -0
@@ -527,6 +527,7 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->num_cores); core_hwid++) {PnvCore *pnv_core = &chip->cores[i]; +DeviceState *qdev;if (!(chip->cores_mask & (1 << core_hwid))) {continue ;
@@ -542,6 +543,14 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) &error_fatal);object_unref (OBJECT (pnv_core)); i++; + +/* Attach the core to its XSCOM bus */ + qdev =qdev_create (&chip->xscom->bus,TYPE_PNV_CORE_XSCOM ); +qdev_prop_set_uint32 (qdev,"core-pir" , +P8_PIR (chip->chip_id, core_hwid)); +qdev_init_nofail (qdev); + + pnv_core->xd =PNV_CORE_XSCOM (qdev); }g_free (typename);
hw/ppc/pnv_core.c +67 -0
84 lines not on this page · raw message
include/hw/ppc/pnv_core.h +13 -0
@@ -20,6 +20,18 @@#define _PPC_PNV_CORE_H#include "hw/cpu/core.h" +#include "hw/ppc/pnv_xscom.h" + +#define TYPE_PNV_CORE_XSCOM "powernv-cpu-core-xscom" +#define PNV_CORE_XSCOM (obj) \ + OBJECT_CHECK(PnvCoreXScom, (obj), TYPE_PNV_CORE_XSCOM) + +typedef struct PnvCoreXScom { +XScomDevice xd; +uint32_t core_pir; +}PnvCoreXScom ; + +#define P8_PIR2COREID (pir) (((pir) >> 3) & 0xf)#define TYPE_PNV_CORE "powernv-cpu-core"#define PNV_CORE (obj) \
@@ -35,6 +47,7 @@ typedef struct PnvCore {/*< public >*/ void *threads; +PnvCoreXScom *xd; } PnvCore; typedef struct PnvCoreClass {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 6/7] ppc/pnv: add a XScomDevice to PnvCore
Quoted 28 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 XScomDevice to each core with the associated ranges in the XSCOM address space.
To start with, let's install the DTS (Digital Thermal Sensor) handlers which are easy to handle.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv.c | 9 +++++++ hw/ppc/pnv_core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_core.h | 13 +++++++++ 3 files changed, 89 insertions(+)hw/ppc/pnv.c +1
-0@@ -527,6 +527,7 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->num_cores); core_hwid++) {PnvCore *pnv_core = &chip->cores[i]; +DeviceState *qdev;if (!(chip->cores_mask & (1 << core_hwid))) {continue ;
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 548
Quoted 6 lines
hw/ppc/pnv.c +3
-0@@ -542,6 +543,14 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) &error_fatal);object_unref (OBJECT (pnv_core)); i++; + +/* Attach the core to its XSCOM bus */ + qdev =qdev_create (&chip->xscom->bus,TYPE_PNV_CORE_XSCOM );
Again, I think this breaks QOM lifetime rules.
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 551
Quoted 3 lines
hw/ppc/pnv.c +3
-0+qdev_prop_set_uint32 (qdev,"core-pir" , +P8_PIR (chip->chip_id, core_hwid)); +qdev_init_nofail (qdev);
qdev_init_nofail() - which will abort on failure - shouldn't be used in a realize() function, which has a way to gracefully report errors.
So, in terms of the lifetime thing. I think one permitted solution is to embed the scom device state in the core device state and use object_initialize().
Alternatively, since SCOM is by its nature a sideband bus, I wonder if it would make sense to have ScomDevice be a QOM interface, rather than a full QOM class. That way the core device itself (and other devices with SCOM control) could present the SCOM device interface and be placed directly on the SCOM bus without having to introduce an extra object. It will probably make accessing the object innards in response to SCOM requests more straightforward as well.
I'm not entirely sure if sharing just an interface will be sufficient for devices under a bus, but it's worth investigating.
Quoted 29 lines
hw/ppc/pnv.c +2
-0+ + pnv_core->xd =PNV_CORE_XSCOM (qdev); }g_free (typename);hw/ppc/pnv_core.c +8
-0@@ -18,7 +18,9 @@*/ #include "qemu/osdep.h" #include "sysemu/sysemu.h" +#include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/log.h" #include "target-ppc/cpu.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" @@ -144,10 +146,75 @@ static const TypeInfo pnv_core_info = { .abstract = true, }; + +#define DTS_RESULT0 0x50000 +#define DTS_RESULT1 0x50001 + +static bool pnv_core_xscom_read (XScomDevice *dev,uint32_t range, +uint32_t offset,uint64_t *out_val)
hw/ppc/pnv_core.c static const TypeInfo pnv_core_info = { · line 164
Quoted 10 lines
hw/ppc/pnv_core.c +10
-0+{ +switch (offset) { +case DTS_RESULT0 : + *out_val =0x26f024f023f0000ull ; +break ; +case DTS_RESULT1 : + *out_val =0x24f000000000000ull ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"Warning: reading reg=0x%08x" , offset);
Can't you just return false here and let the caller handle the error reporting?
Quoted 87 lines
hw/ppc/pnv_core.c +49
-0+ } + +return true; +} + +static bool pnv_core_xscom_write (XScomDevice *dev,uint32_t range, +uint32_t offset,uint64_t val) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"Warning: writing to reg=0x%08x" , offset); +return true; +} + +#define EX_XSCOM_BASE 0x10000000 +#define EX_XSCOM_SIZE 0x100000 + +static void pnv_core_xscom_realize (DeviceState *dev,Error **errp) +{ +XScomDevice *xd =XSCOM_DEVICE (dev); +PnvCoreXScom *pnv_xd =PNV_CORE_XSCOM (dev); + + xd->ranges[0 ].addr =EX_XSCOM_BASE |P8_PIR2COREID (pnv_xd->core_pir) <<24 ; + xd->ranges[0 ].size =EX_XSCOM_SIZE ; +} + +static Property pnv_core_xscom_properties[] = { +DEFINE_PROP_UINT32 ("core-pir" , PnvCoreXScom, core_pir,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pnv_core_xscom_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +XScomDeviceClass *xdc =XSCOM_DEVICE_CLASS (klass); + + xdc->read = pnv_core_xscom_read; + xdc->write = pnv_core_xscom_write; + + dc->realize = pnv_core_xscom_realize; + dc->props = pnv_core_xscom_properties; +} + +static const TypeInfo pnv_core_xscom_type_info = { + .name =TYPE_PNV_CORE_XSCOM , + .parent =TYPE_XSCOM_DEVICE , + .instance_size =sizeof (PnvCoreXScom), + .class_init = pnv_core_xscom_class_init, +}; +static void pnv_core_register_types (void ) {int i ; +type_register_static (&pnv_core_xscom_type_info);type_register_static (&pnv_core_info);for (i =0 ; i <ARRAY_SIZE (pnv_core_models); ++i) { TypeInfo ti = {include/hw/ppc/pnv_core.h +13
-0@@ -20,6 +20,18 @@#define _PPC_PNV_CORE_H#include "hw/cpu/core.h" +#include "hw/ppc/pnv_xscom.h" + +#define TYPE_PNV_CORE_XSCOM "powernv-cpu-core-xscom" +#define PNV_CORE_XSCOM (obj) \ + OBJECT_CHECK(PnvCoreXScom, (obj), TYPE_PNV_CORE_XSCOM) + +typedef struct PnvCoreXScom { +XScomDevice xd; +uint32_t core_pir; +}PnvCoreXScom ; + +#define P8_PIR2COREID (pir) (((pir) >> 3) & 0xf)#define TYPE_PNV_CORE "powernv-cpu-core"#define PNV_CORE (obj) \@@ -35,6 +47,7 @@ typedef struct PnvCore {/*< public >*/ void *threads; +PnvCoreXScom *xd; } PnvCore; typedef struct PnvCoreClass {
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 v2 6/7] ppc/pnv: add a XScomDevice to PnvCore
Quoted 38 lines · David Gibson
Quoted 28 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 XScomDevice to each core with the associated ranges in the XSCOM address space.
To start with, let's install the DTS (Digital Thermal Sensor) handlers which are easy to handle.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv.c | 9 +++++++ hw/ppc/pnv_core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_core.h | 13 +++++++++ 3 files changed, 89 insertions(+)hw/ppc/pnv.c +1
-0@@ -527,6 +527,7 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->num_cores); core_hwid++) {PnvCore *pnv_core = &chip->cores[i]; +DeviceState *qdev;if (!(chip->cores_mask & (1 << core_hwid))) {continue ;hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 548
Quoted 6 lines
hw/ppc/pnv.c +3
-0@@ -542,6 +543,14 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) &error_fatal);object_unref (OBJECT (pnv_core)); i++; + +/* Attach the core to its XSCOM bus */ + qdev =qdev_create (&chip->xscom->bus,TYPE_PNV_CORE_XSCOM );Again, I think this breaks QOM lifetime rules.
Quoted 6 lines
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 551
Quoted 3 lines
hw/ppc/pnv.c +3
-0+qdev_prop_set_uint32 (qdev,"core-pir" , +P8_PIR (chip->chip_id, core_hwid)); +qdev_init_nofail (qdev);
qdev_init_nofail()- which will abort on failure - shouldn't be used in arealize()function, which has a way to gracefully report errors.
yes. I kind of knew that was ugly but the main purpose of the patch is the use of scom. So I took the quick and dirty path :)
we should do what you propose below:
Quoted 3 lines
So, in terms of the lifetime thing. I think one permitted solution is to embed the scom device state in the core device state and use
object_initialize().
yes.
Quoted 6 lines
Alternatively, since SCOM is by its nature a sideband bus, I wonder if it would make sense to have ScomDevice be a QOM interface, rather than a full QOM class. That way the core device itself (and other devices with SCOM control) could present the SCOM device interface and be placed directly on the SCOM bus without having to introduce an extra object.
what you are proposing is to have a PnvCore inherit from CPUCore and XScomDevice ? I tried that and did not find a way for multi-inheritance. But yes, we would get rid of the extra object. At the same time, that extra object represents the xscom interface unit in a chiplet which exists on real HW.
Quoted 2 lines
It will probably make accessing the object innards in response to SCOM requests more straightforward as well.
The address space is probably the best approach. I have some experimental patches which look pretty good :
address-space: xscom-0
0000000000000000-00000007ffffffff (prio 0, RW): xscom-0
0000000000b00200-0000000000b0021f (prio 0, RW): lpc-xscom
0000000120000000-00000001207fffff (prio 0, RW): core-20-xscom
0000000121000000-00000001217fffff (prio 0, RW): core-21-xscom
0000000122000000-00000001227fffff (prio 0, RW): core-22-xscom
0000000123000000-00000001237fffff (prio 0, RW): core-23-xscom
0000000124000000-00000001247fffff (prio 0, RW): core-24-xscom
0000000125000000-00000001257fffff (prio 0, RW): core-25-xscom
0000000126000000-00000001267fffff (prio 0, RW): core-26-xscom
....Quoted 2 lines
I'm not entirely sure if sharing just an interface will be sufficient for devices under a bus, but it's worth investigating.
yes. I need to step back a bit and look how I could rework the patchset to QOMify the whole. This is really qdev oriented and there are a couple of places where fixes are needed. I am seeing that better now.
The address space should be investigated also.
Quoted 33 lines
Quoted 33 lines
hw/ppc/pnv.c +2
-0+ + pnv_core->xd =PNV_CORE_XSCOM (qdev); }g_free (typename);hw/ppc/pnv_core.c +12
-0@@ -18,7 +18,9 @@*/ #include "qemu/osdep.h" #include "sysemu/sysemu.h" +#include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/log.h" #include "target-ppc/cpu.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" @@ -144,10 +146,75 @@ static const TypeInfo pnv_core_info = { .abstract = true, }; + +#define DTS_RESULT0 0x50000 +#define DTS_RESULT1 0x50001 + +static bool pnv_core_xscom_read (XScomDevice *dev,uint32_t range, +uint32_t offset,uint64_t *out_val) +{ +switch (offset) { +case DTS_RESULT0 : + *out_val =0x26f024f023f0000ull ;
Quoted 8 lines
hw/ppc/pnv_core.c static const TypeInfo pnv_core_info = { · line 164
Quoted 6 lines
hw/ppc/pnv_core.c +6
-0+break ; +case DTS_RESULT1 : + *out_val =0x24f000000000000ull ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"Warning: reading reg=0x%08x" , offset);Can't you just return false here and let the caller handle the error reporting?
yes.
Thanks,
C.
Quoted 88 lines
Quoted 87 lines
hw/ppc/pnv_core.c +49
-0+ } + +return true; +} + +static bool pnv_core_xscom_write (XScomDevice *dev,uint32_t range, +uint32_t offset,uint64_t val) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"Warning: writing to reg=0x%08x" , offset); +return true; +} + +#define EX_XSCOM_BASE 0x10000000 +#define EX_XSCOM_SIZE 0x100000 + +static void pnv_core_xscom_realize (DeviceState *dev,Error **errp) +{ +XScomDevice *xd =XSCOM_DEVICE (dev); +PnvCoreXScom *pnv_xd =PNV_CORE_XSCOM (dev); + + xd->ranges[0 ].addr =EX_XSCOM_BASE |P8_PIR2COREID (pnv_xd->core_pir) <<24 ; + xd->ranges[0 ].size =EX_XSCOM_SIZE ; +} + +static Property pnv_core_xscom_properties[] = { +DEFINE_PROP_UINT32 ("core-pir" , PnvCoreXScom, core_pir,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pnv_core_xscom_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +XScomDeviceClass *xdc =XSCOM_DEVICE_CLASS (klass); + + xdc->read = pnv_core_xscom_read; + xdc->write = pnv_core_xscom_write; + + dc->realize = pnv_core_xscom_realize; + dc->props = pnv_core_xscom_properties; +} + +static const TypeInfo pnv_core_xscom_type_info = { + .name =TYPE_PNV_CORE_XSCOM , + .parent =TYPE_XSCOM_DEVICE , + .instance_size =sizeof (PnvCoreXScom), + .class_init = pnv_core_xscom_class_init, +}; +static void pnv_core_register_types (void ) {int i ; +type_register_static (&pnv_core_xscom_type_info);type_register_static (&pnv_core_info);for (i =0 ; i <ARRAY_SIZE (pnv_core_models); ++i) { TypeInfo ti = {include/hw/ppc/pnv_core.h +13
-0@@ -20,6 +20,18 @@#define _PPC_PNV_CORE_H#include "hw/cpu/core.h" +#include "hw/ppc/pnv_xscom.h" + +#define TYPE_PNV_CORE_XSCOM "powernv-cpu-core-xscom" +#define PNV_CORE_XSCOM (obj) \ + OBJECT_CHECK(PnvCoreXScom, (obj), TYPE_PNV_CORE_XSCOM) + +typedef struct PnvCoreXScom { +XScomDevice xd; +uint32_t core_pir; +}PnvCoreXScom ; + +#define P8_PIR2COREID (pir) (((pir) >> 3) & 0xf)#define TYPE_PNV_CORE "powernv-cpu-core"#define PNV_CORE (obj) \@@ -35,6 +47,7 @@ typedef struct PnvCore {/*< public >*/ void *threads; +PnvCoreXScom *xd; } PnvCore; typedef struct PnvCoreClass {
Re: [Qemu-devel] [PATCH v2 6/7] ppc/pnv: add a XScomDevice to PnvCore
Quoted 64 lines · Cédric Le Goater
Quoted 38 lines · David Gibson
Quoted 28 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 XScomDevice to each core with the associated ranges in the XSCOM address space.
To start with, let's install the DTS (Digital Thermal Sensor) handlers which are easy to handle.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ppc/pnv.c | 9 +++++++ hw/ppc/pnv_core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_core.h | 13 +++++++++ 3 files changed, 89 insertions(+)hw/ppc/pnv.c +1
-0@@ -527,6 +527,7 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp)for (i =0 , core_hwid =0 ; (core_hwid <sizeof (chip->cores_mask) *8 ) && (i < chip->num_cores); core_hwid++) {PnvCore *pnv_core = &chip->cores[i]; +DeviceState *qdev;if (!(chip->cores_mask & (1 << core_hwid))) {continue ;hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 548
Quoted 6 lines
hw/ppc/pnv.c +3
-0@@ -542,6 +543,14 @@ static void pnv_chip_realize(DeviceState *dev, Error **errp) &error_fatal);object_unref (OBJECT (pnv_core)); i++; + +/* Attach the core to its XSCOM bus */ + qdev =qdev_create (&chip->xscom->bus,TYPE_PNV_CORE_XSCOM );Again, I think this breaks QOM lifetime rules.
Quoted 6 lines
hw/ppc/pnv.c static void pnv_chip_realize(DeviceState *dev, Error **errp) · line 551
Quoted 3 lines
hw/ppc/pnv.c +3
-0+qdev_prop_set_uint32 (qdev,"core-pir" , +P8_PIR (chip->chip_id, core_hwid)); +qdev_init_nofail (qdev);
qdev_init_nofail()- which will abort on failure - shouldn't be used in arealize()function, which has a way to gracefully report errors.yes. I kind of knew that was ugly but the main purpose of the patch is the use of scom. So I took the quick and dirty path :)
we should do what you propose below:
Quoted 3 lines
So, in terms of the lifetime thing. I think one permitted solution is to embed the scom device state in the core device state and use
object_initialize().yes.
Quoted 6 lines
Alternatively, since SCOM is by its nature a sideband bus, I wonder if it would make sense to have ScomDevice be a QOM interface, rather than a full QOM class. That way the core device itself (and other devices with SCOM control) could present the SCOM device interface and be placed directly on the SCOM bus without having to introduce an extra object.
Quoted 2 lines
what you are proposing is to have a PnvCore inherit from CPUCore and XScomDevice ? I tried that and did not find a way for multi-inheritance.
QOM supports multiple interface inheritance, but not multiple direct inheritance. That's why youd need to change XScomDevice from a class to an interface, as I propose in a different mail. Not sure if that will cause other problems with the qbus infrastructure. Have a look at say, 'HotplugHandler' for an example of a QOM interface.
Quoted 169 lines
But yes, we would get rid of the extra object. At the same time, that extra object represents the xscom interface unit in a chiplet which exists on real HW.
Quoted 2 lines
It will probably make accessing the object innards in response to SCOM requests more straightforward as well.
The address space is probably the best approach. I have some experimental patches which look pretty good :
address-space: xscom-0
0000000000000000-00000007ffffffff (prio 0, RW): xscom-00000000000b00200-0000000000b0021f (prio 0, RW): lpc-xscom 0000000120000000-00000001207fffff (prio 0, RW): core-20-xscom 0000000121000000-00000001217fffff (prio 0, RW): core-21-xscom 0000000122000000-00000001227fffff (prio 0, RW): core-22-xscom 0000000123000000-00000001237fffff (prio 0, RW): core-23-xscom 0000000124000000-00000001247fffff (prio 0, RW): core-24-xscom 0000000125000000-00000001257fffff (prio 0, RW): core-25-xscom 0000000126000000-00000001267fffff (prio 0, RW): core-26-xscom ....Quoted 2 lines
I'm not entirely sure if sharing just an interface will be sufficient for devices under a bus, but it's worth investigating.
yes. I need to step back a bit and look how I could rework the patchset to QOMify the whole. This is really qdev oriented and there are a couple of places where fixes are needed. I am seeing that better now.
The address space should be investigated also.
Quoted 33 lines
Quoted 33 lines
hw/ppc/pnv.c +2
-0+ + pnv_core->xd =PNV_CORE_XSCOM (qdev); }g_free (typename);hw/ppc/pnv_core.c +12
-0@@ -18,7 +18,9 @@*/ #include "qemu/osdep.h" #include "sysemu/sysemu.h" +#include "qemu/error-report.h" #include "qapi/error.h" +#include "qemu/log.h" #include "target-ppc/cpu.h" #include "hw/ppc/ppc.h" #include "hw/ppc/pnv.h" @@ -144,10 +146,75 @@ static const TypeInfo pnv_core_info = { .abstract = true, }; + +#define DTS_RESULT0 0x50000 +#define DTS_RESULT1 0x50001 + +static bool pnv_core_xscom_read (XScomDevice *dev,uint32_t range, +uint32_t offset,uint64_t *out_val) +{ +switch (offset) { +case DTS_RESULT0 : + *out_val =0x26f024f023f0000ull ;Quoted 8 lines
hw/ppc/pnv_core.c static const TypeInfo pnv_core_info = { · line 164
Quoted 6 lines
hw/ppc/pnv_core.c +6
-0+break ; +case DTS_RESULT1 : + *out_val =0x24f000000000000ull ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"Warning: reading reg=0x%08x" , offset);Can't you just return false here and let the caller handle the error reporting?
yes.
Thanks,
C.
Quoted 88 lines
Quoted 87 lines
hw/ppc/pnv_core.c +49
-0+ } + +return true; +} + +static bool pnv_core_xscom_write (XScomDevice *dev,uint32_t range, +uint32_t offset,uint64_t val) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"Warning: writing to reg=0x%08x" , offset); +return true; +} + +#define EX_XSCOM_BASE 0x10000000 +#define EX_XSCOM_SIZE 0x100000 + +static void pnv_core_xscom_realize (DeviceState *dev,Error **errp) +{ +XScomDevice *xd =XSCOM_DEVICE (dev); +PnvCoreXScom *pnv_xd =PNV_CORE_XSCOM (dev); + + xd->ranges[0 ].addr =EX_XSCOM_BASE |P8_PIR2COREID (pnv_xd->core_pir) <<24 ; + xd->ranges[0 ].size =EX_XSCOM_SIZE ; +} + +static Property pnv_core_xscom_properties[] = { +DEFINE_PROP_UINT32 ("core-pir" , PnvCoreXScom, core_pir,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pnv_core_xscom_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +XScomDeviceClass *xdc =XSCOM_DEVICE_CLASS (klass); + + xdc->read = pnv_core_xscom_read; + xdc->write = pnv_core_xscom_write; + + dc->realize = pnv_core_xscom_realize; + dc->props = pnv_core_xscom_properties; +} + +static const TypeInfo pnv_core_xscom_type_info = { + .name =TYPE_PNV_CORE_XSCOM , + .parent =TYPE_XSCOM_DEVICE , + .instance_size =sizeof (PnvCoreXScom), + .class_init = pnv_core_xscom_class_init, +}; +static void pnv_core_register_types (void ) {int i ; +type_register_static (&pnv_core_xscom_type_info);type_register_static (&pnv_core_info);for (i =0 ; i <ARRAY_SIZE (pnv_core_models); ++i) { TypeInfo ti = {include/hw/ppc/pnv_core.h +13
-0@@ -20,6 +20,18 @@#define _PPC_PNV_CORE_H#include "hw/cpu/core.h" +#include "hw/ppc/pnv_xscom.h" + +#define TYPE_PNV_CORE_XSCOM "powernv-cpu-core-xscom" +#define PNV_CORE_XSCOM (obj) \ + OBJECT_CHECK(PnvCoreXScom, (obj), TYPE_PNV_CORE_XSCOM) + +typedef struct PnvCoreXScom { +XScomDevice xd; +uint32_t core_pir; +}PnvCoreXScom ; + +#define P8_PIR2COREID (pir) (((pir) >> 3) & 0xf)#define TYPE_PNV_CORE "powernv-cpu-core"#define PNV_CORE (obj) \@@ -35,6 +47,7 @@ typedef struct PnvCore {/*< public >*/ void *threads; +PnvCoreXScom *xd; } PnvCore; typedef struct PnvCoreClass {
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 v2 7/7 monitor: fix crash for platforms without a CPU 0
In reply to Cédric Le GoaterOn PowerNV, CPU ids start at 0x8 or 0x20, we don't have a CPU 0 anymore. So let's use the first_cpu index to initialize the monitor.
---
So that you can dump the cpu list with the monitor :
(qemu) info cpus * CPU #8: nip=0x0000000000000010 thread_id=7742 CPU #16: nip=0x0000000000000010 thread_id=7740 CPU #24: nip=0x0000000000000010 thread_id=7740 CPU #32: nip=0x0000000000000010 thread_id=7740 CPU #40: nip=0x0000000000000010 thread_id=7740 CPU #48: nip=0x0000000000000010 thread_id=7740 CPU #72: nip=0x0000000000000010 thread_id=7740 CPU #80: nip=0x0000000000000010 thread_id=7740 CPU #136: nip=0x0000000000000010 thread_id=7740 CPU #144: nip=0x0000000000000010 thread_id=7740 CPU #152: nip=0x0000000000000010 thread_id=7740 CPU #160: nip=0x0000000000000010 thread_id=7740 CPU #168: nip=0x0000000000000010 thread_id=7740 CPU #176: nip=0x0000000000000010 thread_id=7740 CPU #200: nip=0x0000000000000010 thread_id=7740 CPU #208: nip=0x0000000000000010 thread_id=7740
monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
monitor.c +1 -1
@@ -1027,7 +1027,7 @@ int monitor_set_cpu(int cpu_index)CPUState *mon_get_cpu (void ) {if (!cur_mon->mon_cpu) { -monitor_set_cpu (0 ); +monitor_set_cpu (first_cpu->cpu_index); }cpu_synchronize_state (cur_mon->mon_cpu);return cur_mon->mon_cpu;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 7/7] monitor: fix crash for platforms without a CPU 0
Quoted 4 lines · Cédric Le Goater
On PowerNV, CPU ids start at
0x8or0x20, we don't have a CPU 0 anymore. So let's use thefirst_cpuindex to initialize the monitor.Signed-off-by Cédric Le Goater <[email protected]>
So we need a patch like this - amongst other fixes - in order to allow unplug of cpu 0. I'm not really sure whether to push it ahead now, or gather it up with other no-cpu-0 fixes and send them as a batch.
Quoted 38 lines
---
So that you can dump the cpu list with the monitor :
(qemu) info cpus * CPU #8: nip=0x0000000000000010 thread_id=7742 CPU #16: nip=0x0000000000000010 thread_id=7740 CPU #24: nip=0x0000000000000010 thread_id=7740 CPU #32: nip=0x0000000000000010 thread_id=7740 CPU #40: nip=0x0000000000000010 thread_id=7740 CPU #48: nip=0x0000000000000010 thread_id=7740 CPU #72: nip=0x0000000000000010 thread_id=7740 CPU #80: nip=0x0000000000000010 thread_id=7740 CPU #136: nip=0x0000000000000010 thread_id=7740 CPU #144: nip=0x0000000000000010 thread_id=7740 CPU #152: nip=0x0000000000000010 thread_id=7740 CPU #160: nip=0x0000000000000010 thread_id=7740 CPU #168: nip=0x0000000000000010 thread_id=7740 CPU #176: nip=0x0000000000000010 thread_id=7740 CPU #200: nip=0x0000000000000010 thread_id=7740 CPU #208: nip=0x0000000000000010 thread_id=7740monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)monitor.c +1
-1@@ -1027,7 +1027,7 @@ int monitor_set_cpu(int cpu_index)CPUState *mon_get_cpu (void ) {if (!cur_mon->mon_cpu) { -monitor_set_cpu (0 ); +monitor_set_cpu (first_cpu->cpu_index); }cpu_synchronize_state (cur_mon->mon_cpu);return cur_mon->mon_cpu;
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 v2 7/7] monitor: fix crash for platforms without a CPU 0
Quoted 9 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
On PowerNV, CPU ids start at
0x8or0x20, we don't have a CPU 0 anymore. So let's use thefirst_cpuindex to initialize the monitor.Signed-off-by Cédric Le Goater <[email protected]>So we need a patch like this - amongst other fixes - in order to allow unplug of cpu 0. I'm not really sure whether to push it ahead now, or gather it up with other no-cpu-0 fixes and send them as a batch.
I think we could send it now as it removes an assumption on the cpu number.
C.
Quoted 40 lines
Quoted 39 lines
---
So that you can dump the cpu list with the monitor :
(qemu) info cpus * CPU #8: nip=0x0000000000000010 thread_id=7742 CPU #16: nip=0x0000000000000010 thread_id=7740 CPU #24: nip=0x0000000000000010 thread_id=7740 CPU #32: nip=0x0000000000000010 thread_id=7740 CPU #40: nip=0x0000000000000010 thread_id=7740 CPU #48: nip=0x0000000000000010 thread_id=7740 CPU #72: nip=0x0000000000000010 thread_id=7740 CPU #80: nip=0x0000000000000010 thread_id=7740 CPU #136: nip=0x0000000000000010 thread_id=7740 CPU #144: nip=0x0000000000000010 thread_id=7740 CPU #152: nip=0x0000000000000010 thread_id=7740 CPU #160: nip=0x0000000000000010 thread_id=7740 CPU #168: nip=0x0000000000000010 thread_id=7740 CPU #176: nip=0x0000000000000010 thread_id=7740 CPU #200: nip=0x0000000000000010 thread_id=7740 CPU #208: nip=0x0000000000000010 thread_id=7740monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)monitor.c +1
-1@@ -1027,7 +1027,7 @@ int monitor_set_cpu(int cpu_index)CPUState *mon_get_cpu (void ) {if (!cur_mon->mon_cpu) { -monitor_set_cpu (0 ); +monitor_set_cpu (first_cpu->cpu_index); }cpu_synchronize_state (cur_mon->mon_cpu);return cur_mon->mon_cpu;
Re: [Qemu-devel] [PATCH v2 7/7] monitor: fix crash for platforms without a CPU 0
Quoted 5 lines · Cédric Le Goater
Quoted 4 lines · David Gibson
Quoted 3 lines · Cédric Le Goater
On PowerNV, CPU ids start at
0x8or0x20, we don't have a CPU 0 anymore. So let's use thefirst_cpuindex to initialize the monitor.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>So we need a patch like this - amongst other fixes - in order to allow unplug of cpu 0. I'm not really sure whether to push it ahead now, or gather it up with other no-cpu-0 fixes and send them as a batch.
I think we could send it now as it removes an assumption on the cpu number.
True enough. I'll try to queue it once I've sorted out my first 2.8 pull request with the existing backlog.
Quoted 45 lines
C.
Quoted 40 lines
Quoted 39 lines
---
So that you can dump the cpu list with the monitor :
(qemu) info cpus * CPU #8: nip=0x0000000000000010 thread_id=7742 CPU #16: nip=0x0000000000000010 thread_id=7740 CPU #24: nip=0x0000000000000010 thread_id=7740 CPU #32: nip=0x0000000000000010 thread_id=7740 CPU #40: nip=0x0000000000000010 thread_id=7740 CPU #48: nip=0x0000000000000010 thread_id=7740 CPU #72: nip=0x0000000000000010 thread_id=7740 CPU #80: nip=0x0000000000000010 thread_id=7740 CPU #136: nip=0x0000000000000010 thread_id=7740 CPU #144: nip=0x0000000000000010 thread_id=7740 CPU #152: nip=0x0000000000000010 thread_id=7740 CPU #160: nip=0x0000000000000010 thread_id=7740 CPU #168: nip=0x0000000000000010 thread_id=7740 CPU #176: nip=0x0000000000000010 thread_id=7740 CPU #200: nip=0x0000000000000010 thread_id=7740 CPU #208: nip=0x0000000000000010 thread_id=7740monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)monitor.c +1
-1@@ -1027,7 +1027,7 @@ int monitor_set_cpu(int cpu_index)CPUState *mon_get_cpu (void ) {if (!cur_mon->mon_cpu) { -monitor_set_cpu (0 ); +monitor_set_cpu (first_cpu->cpu_index); }cpu_synchronize_state (cur_mon->mon_cpu);return cur_mon->mon_cpu;
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