ppc/pnv: LPC fixes and add nice PNOR image
Subsystems (2)
Nicholas Piggin
reviewercover ppc/pnv: LPC fixes and add nice PNOR image
Here a few fixes and improvements I gathered looking at firmware errors. One is LPC transaction error response, another is problems addressing the PNOR (skiboot has a bug here too I need to fix), and another is the lack of a nice properly formatted default PNOR image.
Thanks,
Nick
Nicholas Piggin (6):
ppc/pnv: Support LPC host controller irqs other than serirqs ppc/pnv: raise no-response errors if an LPC transaction fails ppc/pnv: Implement LPC FW address space IDSEL ppc/pnv: Move PNOR to offset 0 in the ISA FW space ppc/pnv: Add a PNOR address and size sanity checks ppc/pnv: Add a default formatted PNOR image
MAINTAINERS | 1 + docs/system/ppc/powernv.rst | 7 +++ include/hw/ppc/pnv_pnor.h | 6 ++- hw/ppc/pnv.c | 16 ++++++- hw/ppc/pnv_bmc.c | 28 ++++++++++++ hw/ppc/pnv_lpc.c | 89 ++++++++++++++++++++---------------- pc-bios/README | 13 ++++++ pc-bios/meson.build | 1 + pc-bios/pnv-pnor.bin | Bin 0 -> 139264 bytes 9 files changed, 119 insertions(+), 42 deletions(-) create mode 100644 pc-bios/pnv-pnor.bin
Signature · 1 line
2.47.1
Nicholas Piggin
reviewerPATCH 1/6 ppc/pnv: Support LPC host controller irqs other than serirqs
The LPC model has only supported serirqs (ISA device IRQs), however there are internal sources that can raise other interrupts. Update the device to handle these interrupt sources.
--- hw/ppc/pnv_lpc.c | 64 +++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 33 deletions(-)
hw/ppc/pnv_lpc.c +31 -33
@@ -456,46 +456,18 @@ static void pnv_lpc_eval_irqs(PnvLpcController *lpc) {uint32_t active_irqs =0 ; -if (lpc->lpc_hc_irqstat &PPC_BITMASK32 (16 ,31 )) { -qemu_log_mask (LOG_UNIMP ,"LPC HC Unimplemented irqs in IRQSTAT: " -"0x%08" PRIx32"\n" , lpc->lpc_hc_irqstat); - } - -if (lpc->lpc_hc_irqser_ctrl &LPC_HC_IRQSER_EN ) { - active_irqs = lpc->lpc_hc_irqstat & lpc->lpc_hc_irqmask; + active_irqs = lpc->lpc_hc_irqstat & lpc->lpc_hc_irqmask; +if (!(lpc->lpc_hc_irqser_ctrl &LPC_HC_IRQSER_EN )) { + active_irqs &= ~LPC_HC_IRQ_SERIRQ_ALL ; }/* Reflect the interrupt */ -if (!lpc->psi_has_serirq) { -/* -* POWER8 ORs all irqs together (also with LPCHC internal interrupt -* sources) and outputs a single line that raises the PSI LPCHC irq -* which then latches an OPB IRQ status register that sends the irq -* to PSI. -* -* We don't honor the polarity register, it's pointless and unused -* anyway -*/ -if (active_irqs) { - lpc->opb_irq_input |=OPB_MASTER_IRQ_LPC ; - }else { - lpc->opb_irq_input &= ~OPB_MASTER_IRQ_LPC ; - } - -/* Update OPB internal latch */ - lpc->opb_irq_stat |= lpc->opb_irq_input & lpc->opb_irq_mask; - -qemu_set_irq (lpc->psi_irq_lpchc, lpc->opb_irq_stat !=0 ); - }else { +if (lpc->psi_has_serirq) {/* -* POWER9 and POWER10 have routing fields in OPB master registers that +* POWER9 and later have routing fields in OPB master registers that * send LPC irqs to 4 output lines that raise the PSI SERIRQ irqs. * These don't appear to get latched into an OPB register like the * LPCHC irqs. -* -* POWER9 LPC controller internal irqs still go via the OPB -* and LPCHC PSI irqs like P8, but we have no such internal sources -* modelled yet. */ bool serirq_out[4 ] = { false, false, false, false };int irq;
@@ -510,7 +482,33 @@ static void pnv_lpc_eval_irqs(PnvLpcController *lpc)qemu_set_irq (lpc->psi_irq_serirq[1 ], serirq_out[1 ]);qemu_set_irq (lpc->psi_irq_serirq[2 ], serirq_out[2 ]);qemu_set_irq (lpc->psi_irq_serirq[3 ], serirq_out[3 ]); + +/* +* POWER9 and later LPC controller internal irqs still go via the OPB +* and LPCHC PSI irqs like P8, so take the SERIRQs out and continue. +*/ + active_irqs &= ~LPC_HC_IRQ_SERIRQ_ALL ; + } + +/* +* POWER8 ORs all irqs together (also with LPCHC internal interrupt +* sources) and outputs a single line that raises the PSI LPCHC irq +* which then latches an OPB IRQ status register that sends the irq +* to PSI. +* +* We don't honor the polarity register, it's pointless and unused +* anyway +*/ +if (active_irqs) { + lpc->opb_irq_input |=OPB_MASTER_IRQ_LPC ; + }else { + lpc->opb_irq_input &= ~OPB_MASTER_IRQ_LPC ; } + +/* Update OPB internal latch */ + lpc->opb_irq_stat |= lpc->opb_irq_input & lpc->opb_irq_mask; + +qemu_set_irq (lpc->psi_irq_lpchc, lpc->opb_irq_stat !=0 ); }static uint64_t lpc_hc_read (void *opaque,hwaddr addr,unsigned size)
Signature · 1 line
2.47.1
Nicholas Piggin
reviewerPATCH 2/6 ppc/pnv: raise no-response errors if an LPC transaction fails
In reply to Nicholas PigginIf nothing responds to an LPC access, the LPC host controller should set an IRQSTAT error. Model this behaviour.
skiboot uses this error to "probe" LPC accesses, among other things to determine if a SuperIO chip is present. After this change it recognizes there is no SuperIO present and does not keep trying to access it.
--- hw/ppc/pnv_lpc.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/ppc/pnv_lpc.c +10 -0
@@ -353,6 +353,8 @@ static const MemoryRegionOps pnv_lpc_xscom_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static void pnv_lpc_opb_noresponse (PnvLpcController *lpc); +static uint64_t pnv_lpc_mmio_read (void *opaque,hwaddr addr,unsigned size) {PnvLpcController *lpc =PNV_LPC (opaque);
@@ -376,6 +378,7 @@ static uint64_t pnv_lpc_mmio_read(void *opaque, hwaddr addr, unsigned size) }if (result !=MEMTX_OK ) { +pnv_lpc_opb_noresponse (lpc);qemu_log_mask (LOG_GUEST_ERROR ,"OPB read failed at @0x%" HWADDR_PRIx"\n" , addr); }
@@ -406,6 +409,7 @@ static void pnv_lpc_mmio_write(void *opaque, hwaddr addr, }if (result !=MEMTX_OK ) { +pnv_lpc_opb_noresponse (lpc);qemu_log_mask (LOG_GUEST_ERROR ,"OPB write failed at @0x%" HWADDR_PRIx"\n" , addr); }
@@ -511,6 +515,12 @@ static void pnv_lpc_eval_irqs(PnvLpcController *lpc)qemu_set_irq (lpc->psi_irq_lpchc, lpc->opb_irq_stat !=0 ); } +static void pnv_lpc_opb_noresponse (PnvLpcController *lpc) +{ + lpc->lpc_hc_irqstat |=LPC_HC_IRQ_SYNC_NORESP_ERR ; +pnv_lpc_eval_irqs (lpc); +} +static uint64_t lpc_hc_read (void *opaque,hwaddr addr,unsigned size) {PnvLpcController *lpc = opaque;
Signature · 1 line
2.47.1
Nicholas Piggin
reviewerPATCH 3/6 ppc/pnv: Implement LPC FW address space IDSEL
In reply to Nicholas PigginLPC FW address space is a 256MB (28-bit) region to one of 16-devices that are selected with the IDSEL register. Implement this by making the ISA FW address space 4GB, and move the 256MB OPB alias within that space according to IDSEL.
--- hw/ppc/pnv_lpc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
hw/ppc/pnv_lpc.c +9 -6
@@ -85,7 +85,7 @@ enum {#define ISA_IO_SIZE 0x00010000#define ISA_MEM_SIZE 0x10000000 -#define ISA_FW_SIZE 0x10000000 +#define ISA_FW_SIZE 0x100000000#define LPC_IO_OPB_ADDR 0xd0010000#define LPC_IO_OPB_SIZE 0x00010000#define LPC_MEM_OPB_ADDR 0xe0000000
@@ -561,10 +561,13 @@ static void lpc_hc_write(void *opaque, hwaddr addr, uint64_t val,switch (addr) {case LPC_HC_FW_SEG_IDSEL : -/* XXX Actually figure out how that works as this impact -* memory regions/aliases +/* +* ISA FW "devices" are modeled as 16x256MB windows into a +* 4GB LPC FW address space. */ + val &=0xf ;/* Selects device 0-15 */ lpc->lpc_hc_fw_seg_idsel = val; +memory_region_set_alias_offset (&lpc->opb_isa_fw, val *LPC_FW_OPB_SIZE );break ;case LPC_HC_FW_RD_ACC_SIZE : lpc->lpc_hc_fw_rd_acc_size = val;
@@ -798,9 +801,9 @@ static void pnv_lpc_realize(DeviceState *dev, Error **errp)memory_region_init (&lpc->opb_mr,OBJECT (dev),"lpc-opb" ,0x100000000ull );address_space_init (&lpc->opb_as, &lpc->opb_mr,"lpc-opb" ); -/* Create ISA IO and Mem space regions which are the root of -* the ISA bus (ie, ISA address spaces). We don't create a -* separate one for FW which we alias to memory. +/* +* Create ISA IO, Mem, and FW space regions which are the root of +* the ISA bus (ie, ISA address spaces). */ memory_region_init (&lpc->isa_io,OBJECT (dev),"isa-io" ,ISA_IO_SIZE );memory_region_init (&lpc->isa_mem,OBJECT (dev),"isa-mem" ,ISA_MEM_SIZE );
Signature · 1 line
2.47.1
Nicholas Piggin
reviewerPATCH 4/6 ppc/pnv: Move PNOR to offset 0 in the ISA FW space
In reply to Nicholas Pigginskiboot has a bug that does not handle ISA FW access correctly for IDSEL devices > 0, and the current PNOR default address and size puts 64MB in device 0 and 64MB in device 1, which causes skiboot to hit this bug and breaks PNOR accesses.
Move the PNOR address down to 0 for now, so a 256MB PNOR can be accessed via device 0.
--- include/hw/ppc/pnv_pnor.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/hw/ppc/pnv_pnor.h +4 -2
@@ -13,9 +13,11 @@#include "hw/sysbus.h" /* -* PNOR offset on the LPC FW address space +* PNOR offset on the LPC FW address space. For now this should be 0 because +* skiboot 7.1 has a bug where IDSEL > 0 (LPC FW address > 256MB) access is +* not performed correctly. */ -#define PNOR_SPI_OFFSET 0x0c000000UL +#define PNOR_SPI_OFFSET 0x00000000UL#define TYPE_PNV_PNOR "pnv-pnor"OBJECT_DECLARE_SIMPLE_TYPE (PnvPnor,PNV_PNOR )
Signature · 1 line
2.47.1
Nicholas Piggin
reviewerPATCH 5/6 ppc/pnv: Add a PNOR address and size sanity checks
In reply to Nicholas PigginThe BMC HIOMAP PNOR access protocol has certain limits on PNOR addresses and sizes. Add some sanity checks for these so we don't get strange behaviour.
--- hw/ppc/pnv_bmc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
hw/ppc/pnv_bmc.c +28 -0
@@ -251,10 +251,38 @@ static const IPMINetfn hiomap_netfn = {void pnv_bmc_set_pnor (IPMIBmc *bmc,PnvPnor *pnor) { +uint32_t pnor_size = pnor->size; +uint32_t pnor_addr =PNOR_SPI_OFFSET ; +if (!pnv_bmc_is_simulator (bmc)) {return ; } +/* +* The HIOMAP protocol uses block units and 16-bit addressing. +* Prevent overflow or misalign. +*/ +if (pnor_addr >=1U << (BLOCK_SHIFT +16 )) { +warn_report ("PNOR address is larger than 2^%d, disabling PNOR" , +BLOCK_SHIFT +16 ); +return ; + } +if (pnor_addr & ((1U <<BLOCK_SHIFT ) -1 )) { +warn_report ("PNOR address is not aligned to 2^%d, disabling PNOR" , +BLOCK_SHIFT ); +return ; + } +if (pnor_size >1U << (BLOCK_SHIFT +16 )) { +warn_report ("PNOR size is larger than 2^%d, disabling PNOR" , +BLOCK_SHIFT +16 ); +return ; + } +if (pnor_size & ((1U <<BLOCK_SHIFT ) -1 )) { +warn_report ("PNOR size is not aligned to 2^%d, disabling PNOR" , +BLOCK_SHIFT ); +return ; + } +object_ref (OBJECT (pnor));object_property_add_const_link (OBJECT (bmc),"pnor" ,OBJECT (pnor));
Signature · 1 line
2.47.1
Nicholas Piggin
reviewerPATCH 6/6 ppc/pnv: Add a default formatted PNOR image
In reply to Nicholas PigginThe default PNOR image is erased and not recognised by skiboot, so NVRAM gets disabled. This change adds a tiny pnor file that is a proper FFS image with a formatted NVRAM partition. This is recognised by skiboot and will persist across machine reboots.
--- MAINTAINERS | 1 + docs/system/ppc/powernv.rst | 7 +++++++ hw/ppc/pnv.c | 16 +++++++++++++++- pc-bios/README | 13 +++++++++++++ pc-bios/meson.build | 1 + pc-bios/pnv-pnor.bin | Bin 0 -> 139264 bytes 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 pc-bios/pnv-pnor.bin
MAINTAINERS +1 -0
@@ -1531,6 +1531,7 @@ F: include/hw/ppc/pnv* F: include/hw/pci-host/pnv* F: include/hw/ssi/pnv_spi* F: pc-bios/skiboot.lid +F: pc-bios/pnv-pnor.bin F: tests/qtest/pnv* F: tests/functional/test_ppc64_powernv.py
docs/system/ppc/powernv.rst +7 -0
@@ -195,6 +195,13 @@ Use a MTD drive to add a PNOR to the machine, and get a NVRAM : -drive file=./witherspoon.pnor,format=raw,if=mtd +If no mtd drive is provided, the powernv platform will create a default +PNOR device using a tiny formatted PNOR in pc-bios/pnv-pnor.bin opened +read-only (PNOR changes will be persistent across reboots but not across +invocations of QEMU). If no defaults are used, an erased 128MB PNOR is +provided (which skiboot will probably not recognize since it is not +formatted). + Maintainer contact information ------------------------------
hw/ppc/pnv.c +15 -1
@@ -64,6 +64,8 @@#define FW_LOAD_ADDR 0x0#define FW_MAX_SIZE (16 * MiB) +#define PNOR_FILE_NAME "pnv-pnor.bin" +#define KERNEL_LOAD_ADDR 0x20000000#define KERNEL_MAX_SIZE (128 * MiB)#define INITRD_LOAD_ADDR 0x28000000
@@ -942,7 +944,7 @@ static void pnv_init(MachineState *machine)uint64_t chip_ram_start =0 ;int i;char *chip_typename; -DriveInfo *pnor =drive_get (IF_MTD ,0 ,0 ); +DriveInfo *pnor;DeviceState *dev;if (kvm_enabled ()) {
@@ -989,6 +991,18 @@ static void pnv_init(MachineState *machine)* Create our simple PNOR device */ dev =qdev_new (TYPE_PNV_PNOR ); + pnor =drive_get (IF_MTD ,0 ,0 ); +if (!pnor &&defaults_enabled ()) { + fw_filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,PNOR_FILE_NAME ); +if (!fw_filename) { +warn_report ("Could not find PNOR '%s'" ,PNOR_FILE_NAME ); + }else { +QemuOpts *opts; + opts =drive_add (IF_MTD ,-1 , fw_filename,"format=raw,readonly=on" ); + pnor =drive_new (opts,IF_MTD , &error_fatal); +g_free (fw_filename); + } + }if (pnor) {qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (pnor)); }
pc-bios/README +13 -0
@@ -43,6 +43,19 @@ run an hypervisor OS or simply a host OS on the "baremetal" platform, also known as the PowerNV (Non-Virtualized) platform. +- pnv-pnor.bin is a non-volatile RAM image used by PowerNV, which stores + NVRAM BIOS settings among other things. This image was created with the + following command (the ffspart tool can be found in the skiboot source tree): + + ffspart -s 0x1000 -c 34 -i pnv-pnor.in -p pnv-pnor.bin + + Where pnv-pnor.in contains the two lines (no leading whitespace): + + NVRAM,0x01000,0x00020000,,,/dev/zero + VERSION,0x21000,0x00001000,,,/dev/zero + + skiboot is then booted once to format the NVRAM partition. + - QemuMacDrivers (https://github.com/ozbenh/QemuMacDrivers) is a project to provide virtualised drivers for PPC MacOS guests.
pc-bios/meson.build +1 -0
@@ -70,6 +70,7 @@ blobs = [ 's390-ccw.img', 'slof.bin', 'skiboot.lid', + 'pnv-pnor.bin', 'palcode-clipper', 'u-boot.e500', 'u-boot-sam460-20100605.bin',
pc-bios/pnv-pnor.bin new file binary +0 -0
Signature · 1 line
2.47.1