ich9: add TCO interface emulation
PATCH 1/2 ich9: add TCO interface emulation
This interface is provides some registers within a 32-byte range and can be accessed through PCI-to-LPC bridge interface (PMBASE + 0x60).
It's commonly used as a watchdog timer to detect system lockups through SMIs that are generated by it (if TCO_EN bit is enabled) on every timeout and then giving the system firmware the ability to perform any action -- if NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be reseted upon second TCO timeout.
This patch focus on adding full support to TCO watchdog logic and a few features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection (TCO interrupt due to INTRUDER# signal), etc. are not implemented yet.
--- hw/acpi/Makefile.objs | 1 + hw/acpi/ich9.c | 36 +++++++++ hw/acpi/tco.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 10 +++ include/hw/acpi/ich9.h | 4 + include/hw/acpi/tco.h | 139 +++++++++++++++++++++++++++++++++++ include/hw/i386/ich9.h | 8 ++ 7 files changed, 392 insertions(+) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o +common-obj-$(CONFIG_ACPI) += tco.o common-obj-$(CONFIG_ACPI) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
hw/acpi/ich9.c +36 -0
@@ -30,6 +30,7 @@#include "qemu/timer.h" #include "sysemu/sysemu.h" #include "hw/acpi/acpi.h" +#include "hw/acpi/tco.h" #include "sysemu/kvm.h" #include "exec/address-spaces.h"
@@ -92,8 +93,15 @@ static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val, unsigned width) {ICH9LPCPMRegs *pm = opaque; +TCOIORegs *tr = &pm->tco_regs; +switch (addr) {case 0 : +/* once TCO_LOCK bit is set, TCO_EN bit cannot be overwritten */ +if (tr->tco.cnt1 &TCO_LOCK ) { + val &= ~ICH9_PMIO_SMI_EN_TCO_EN ; + val |= pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ; + } pm->smi_en = val;break ; }
@@ -107,6 +115,29 @@ static const MemoryRegionOps ich9_smi_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; +static uint64_t ich9_tco_readw (void *opaque,hwaddr addr,unsigned width) +{ +ICH9LPCPMRegs *pm = opaque; +return acpi_pm_tco_ioport_readw (&pm->tco_regs, addr); +} + +static void ich9_tco_writew (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +ICH9LPCPMRegs *pm = opaque; +acpi_pm_tco_ioport_writew (&pm->tco_regs, addr, val); +} + +static const MemoryRegionOps ich9_tco_ops = { + .read = ich9_tco_readw, + .write = ich9_tco_writew, + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =1 , + .impl.max_access_size =2 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; +void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base) {ICH9_DEBUG ("to 0x%x\n" , pm_io_base);
@@ -230,6 +261,11 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, "acpi-smi", 8);memory_region_add_subregion (&pm->io,ICH9_PMIO_SMI_EN , &pm->io_smi); +acpi_pm_tco_init (&pm->tco_regs); +memory_region_init_io (&pm->io_tco,OBJECT (lpc_pci), &ich9_tco_ops, pm, +"sm-tco" ,ICH9_PMIO_TCO_LEN ); +memory_region_add_subregion (&pm->io,ICH9_PMIO_TCO_RLD , &pm->io_tco); + pm->irq = sci_irq;qemu_register_reset (pm_reset, pm); pm->powerdown_notifier.notify = pm_powerdown_req;
hw/acpi/tco.c new file +194 -0
194 lines not on this page · raw message
hw/isa/lpc_ich9.c +10 -0
@@ -313,6 +313,16 @@ PCIINTxRoute ich9_route_intx_pin_to_irq(void *opaque, int pirq_pin)return route; } +void ich9_generate_smi (void ) +{ +cpu_interrupt (first_cpu,CPU_INTERRUPT_SMI ); +} + +void ich9_generate_nmi (void ) +{ +cpu_interrupt (first_cpu,CPU_INTERRUPT_NMI ); +} +static int ich9_lpc_sci_irq (ICH9LPCState *lpc) { switch (lpc->d.config[ICH9_LPC_ACPI_CTRL] &
include/hw/acpi/ich9.h +4 -0
@@ -25,6 +25,7 @@#include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/acpi_dev_interface.h" +#include "hw/acpi/tco.h" typedef struct ICH9LPCPMRegs { /*
@@ -37,6 +38,7 @@ typedef struct ICH9LPCPMRegs {MemoryRegion io;MemoryRegion io_gpe;MemoryRegion io_smi; +MemoryRegion io_tco;uint32_t smi_en;uint32_t smi_sts;
@@ -53,6 +55,8 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
include/hw/acpi/tco.h new file +139 -0
139 lines not on this page · raw message
include/hw/i386/ich9.h +8 -0
@@ -20,6 +20,9 @@ PCIINTxRoute ich9_route_intx_pin_to_irq(void *opaque, int pirq_pin);void ich9_lpc_pm_init (PCIDevice *pci_lpc);I2CBus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base); +void ich9_generate_smi (void ); +void ich9_generate_nmi (void ); +#define ICH9_CC_SIZE (16 * 1024)/* 16KB */ #define TYPE_ICH9_LPC_DEVICE "ICH9-LPC"
@@ -156,6 +159,8 @@ Object *ich9_lpc_find(void);#define ICH9_LPC_RCBA_BA_MASK Q35_MASK(32, 31, 14)#define ICH9_LPC_RCBA_EN 0x1#define ICH9_LPC_RCBA_DEFAULT 0x0 +#define ICH9_LPC_RCBA_GCS 0x3410 +#define ICH9_LPC_RCBA_GCS_NO_REBOOT (1 << 5)#define ICH9_LPC_PIC_NUM_PINS 16#define ICH9_LPC_IOAPIC_NUM_PINS 24
@@ -180,7 +185,10 @@ Object *ich9_lpc_find(void);#define ICH9_PMIO_GPE0_LEN 16#define ICH9_PMIO_SMI_EN 0x30#define ICH9_PMIO_SMI_EN_APMC_EN (1 << 5) +#define ICH9_PMIO_SMI_EN_TCO_EN (1 << 13)#define ICH9_PMIO_SMI_STS 0x34 +#define ICH9_PMIO_TCO_RLD 0x60 +#define ICH9_PMIO_TCO_LEN 32/* FADT ACPI_ENABLE/ACPI_DISABLE */ #define ICH9_APM_ACPI_ENABLE 0x2
Signature · 1 line
2.1.0
PATCH 2/2 tests: add testcase for TCO watchdog emulation
--- tests/Makefile | 2 + tests/tco-test.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 tests/tco-test.c
tests/Makefile +2 -0
@@ -150,6 +150,7 @@ check-qtest-i386-y += tests/i440fx-test$(EXESUF) check-qtest-i386-y += tests/fw_cfg-test$(EXESUF) check-qtest-i386-y += tests/drive_del-test$(EXESUF) check-qtest-i386-y += tests/wdt_ib700-test$(EXESUF) +check-qtest-i386-y += tests/tco-test$(EXESUF) gcov-files-i386-y += hw/watchdog/watchdog.c hw/watchdog/wdt_ib700.c check-qtest-i386-y += $(check-qtest-pci-y) gcov-files-i386-y += $(gcov-files-pci-y)
@@ -363,6 +364,7 @@ tests/eepro100-test$(EXESUF): tests/eepro100-test.o tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o tests/ne2000-test$(EXESUF): tests/ne2000-test.o tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o +tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y) tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y) tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y)
tests/tco-test.c new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.1.0