ich9: add TCO interface emulation
PATCH 1/3 ich9: add TCO interface emulation
This interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
--- hw/acpi/Makefile.objs | 1 + hw/acpi/ich9.c | 36 ++++++++++ hw/acpi/tco.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++ 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, 386 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 +188 -0
188 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/3 target-i386: reserve RCRB mmio space in ACPI DSDT table
--- hw/i386/acpi-dsdt-pdrc.dsl | 46 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/q35-acpi-dsdt.dsl | 1 + tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7795 bytes 3 files changed, 47 insertions(+) create mode 100644 hw/i386/acpi-dsdt-pdrc.dsl
hw/i386/acpi-dsdt-pdrc.dsl new file +46 -0
@@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +/**************************************************************** + * PCI Device Resource Comsumption + ****************************************************************/ + +Scope(\_SB.PCI0) { + Device (PDRC) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (PDRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) + }) + + Method (_CRS, 0, Serialized) { + Return(PDRS) + } + } +} + +Scope(\_SB) { + OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000) + Field (RCRB, DWordAcc, Lock, Preserve) { + Offset(0x3000), + TCTL, 8, + , 24, + Offset(0x3400), + RTCC, 32, + HPTC, 32, + GCSR, 32, + } +}
hw/i386/q35-acpi-dsdt.dsl +1 -0
@@ -114,6 +114,7 @@ DefinitionBlock ( } } +#include "acpi-dsdt-pdrc.dsl" #include "acpi-dsdt-hpet.dsl"
tests/acpi-test-data/q35/DSDT binary +0 -0
Signature · 1 line
2.1.0
PATCH 3/3 tests: add testcase for TCO watchdog emulation
In reply to Paulo Alcantara--- tests/Makefile | 2 + tests/tco-test.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 349 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 +347 -0
347 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 9 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.
Quoted 5 lines
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.Signed-off-by Paulo Alcantara <[email protected]>
Hi,
the main issue here is lack of migration support. You need to add a new subsection to vmstate_ich9_pm that is migrated if the registers are different from the default values.
Other comments inline.
Quoted 38 lines
hw/acpi/tco.c new file +32
-0@@ -0,0 +1,188 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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-common.h" +#include "sysemu/watchdog.h" +#include "hw/i386/ich9.h" + +#include "hw/acpi/tco.h" + +//#define DEBUG + +#ifdef DEBUG
hw/acpi/tco.c line 42
Quoted 10 lines
hw/acpi/tco.c new file +10
-0+#define TCO_DEBUG (fmt, ...) \ + do { \ + fprintf(stderr, "%s "fmt, __func__, ## __VA_ARGS__); \ + } while (0) +#else +#define TCO_DEBUG (fmt, ...) do { } while (0) +#endif + +static QEMUTimer *tco_timer; +static unsigned int timeouts_no;
These must not be globals. Instead, add them to TCOIORegs.
hw/acpi/tco.c line 49
Quoted 6 lines
hw/acpi/tco.c new file +6
-0+static inline void tco_timer_reload (void ) +{ +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + +timer_del (tco_timer); +timer_mod (tco_timer, now +tco_ticks_per_sec ());
No need for del+mod. Also, these are not tco_ticks_per_sec() but rather TCO_TICK_NSEC. It can be a #define instead of a function.
For a little extra challenge, you could the base value when the timer was started inside TCOIORegs. The timer can be made to expire directly after 0.6*TCO_TMR seconds; you can use the base value and the current time to compute the value of TCO_RLD. Something like:
case TCO_RLD:
rld = tr->tco.rld;
/* base_clock is set to -1 in tco_timer_stop, reloaded in
* tco_timer_reload.
*/
if (base_clock != -1) {
elapsed = (qemu_get_clock(QEMU_CLOCK_VIRTUAL) - base_clock)
/ TCO_TICK_NSEC;
rld -= MIN(elapsed, rld);
}This makes it possible for QEMU to sleep most of the time when the guest is idle, instead of waking up every 0.6 seconds. But feel free to work on this afterwards.
hw/acpi/tco.c line 95
Quoted 3 lines
hw/acpi/tco.c new file +3
-0+void acpi_pm_tco_init (TCOIORegs *tr) +{ + *tr =TCO_IO_REGS_DEFAULTS_INIT ();
Just inline the macro definition here.
Quoted 22 lines
hw/acpi/tco.c new file +22
-0+void acpi_pm_tco_ioport_writew (TCOIORegs *tr,uint32_t addr,uint32_t val) +{ +switch (addr) { +case TCO_RLD : + timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (); + }else { + tr->tco.rld = val; + } +break ; +case TCO_DAT_IN : + tr->tco.din = val; + tr->tco.sts1 |=SW_TCO_SMI ; +ich9_generate_smi (); +break ; +case TCO_DAT_OUT : + tr->tco.dout = val; + tr->tco.sts1 |=TCO_INT_STS ; +/* TODO: cause an interrupt, as selected by the TCO_INT_SEL bits */ +break ;
hw/acpi/tco.c line 161
Quoted 10 lines
hw/acpi/tco.c new file +10
-0+case TCO1_STS : + tr->tco.sts1 = val &TCO1_STS_MASK ; +break ; +case TCO2_STS : + tr->tco.sts2 = val &TCO2_STS_MASK ; +break ; +case TCO1_CNT : + val &=TCO1_CNT_MASK ; +/* TCO_LOCK bit cannot be changed once set */ + tr->tco.cnt1 = (val & ~TCO_LOCK ) | (tr->tco.cnt1 &TCO_LOCK );
This means that TCO_LOCK is never set in tr->tco.cnt1, I think? If I'm correct, it should be covered by tests.
Quoted 119 lines
hw/acpi/tco.c new file +7
-0+if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (); + }else { +tco_timer_stop (); + } +break ;include/hw/acpi/tco.h new file +105
-0@@ -0,0 +1,139 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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. +*/ +#ifndef HW_ACPI_TCO_H +#define HW_ACPI_TCO_H + +#include "qemu/typedefs.h" +#include "qemu-common.h" + +/* TCO I/O register offsets */ +enum { +TCO_RLD =0x00 , +TCO_DAT_IN =0x02 , +TCO_DAT_OUT =0x03 , +TCO1_STS =0x04 , +TCO2_STS =0x06 , +TCO1_CNT =0x08 , +TCO2_CNT =0x0a , +TCO_MESSAGE1 =0x0c , +TCO_MESSAGE2 =0x0d , +TCO_WDCNT =0x0e , +SW_IRQ_GEN =0x10 , +TCO_TMR =0x12 , +}; + +/* TCO I/O register defaults */ +enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +/* TCO I/O register control/status bits */ +enum { +SW_TCO_SMI = (1 <<1 ), +TCO_INT_STS = (1 <<2 ), +TCO_LOCK = (1 <<12 ), +TCO_TMR_HLT = (1 <<11 ), +TCO_TIMEOUT = (1 <<3 ), +TCO_SECOND_TO_STS = (1 <<1 ), +TCO_BOOT_STS = (1 <<2 ), +}; + +/* TCO I/O registers mask bits */ +enum { +TCO_RLD_MASK =0x3ff , +TCO1_STS_MASK =0xe870 , +TCO2_STS_MASK =0xfff8 , +TCO1_CNT_MASK =0xfeff , +TCO_TMR_MASK =0x3ff , +}; + +typedef struct TCOIORegs { +struct { +uint16_t rld; +uint8_t din; +uint8_t dout; +uint16_t sts1; +uint16_t sts2; +uint16_t cnt1; +uint16_t cnt2; +uint8_t msg1; +uint8_t msg2; +uint8_t wdcnt; +uint16_t tmr; + } tco; +uint8_t sw_irq_gen; +}TCOIORegs ; + +#define TCO_IO_REGS_DEFAULTS_INIT () \ + (TCOIORegs) { \ + .tco = { \ + .rld = TCO_RLD_DEFAULT, \ + .din = TCO_DAT_IN_DEFAULT, \ + .dout = TCO_DAT_OUT_DEFAULT, \ + .sts1 = TCO1_STS_DEFAULT, \
include/hw/acpi/tco.h line 115
Quoted 10 lines
include/hw/acpi/tco.h new file +10
-0+ .sts2 = TCO2_STS_DEFAULT, \ + .cnt1 = TCO1_CNT_DEFAULT, \ + .cnt2 = TCO2_CNT_DEFAULT, \ + .msg1 = TCO_MESSAGE1_DEFAULT, \ + .msg2 = TCO_MESSAGE2_DEFAULT, \ + .wdcnt = TCO_WDCNT_DEFAULT, \ + .tmr = TCO_TMR_DEFAULT, \ + }, \ + .sw_irq_gen =SW_IRQ_GEN_DEFAULT \ + }
No need for this definition. This and the *_DEFAULT definitions as well should be in the .c file.
Quoted 11 lines
include/hw/acpi/tco.h new file +11
-0+/* tco.c */ +void acpi_pm_tco_init (TCOIORegs *tr); +uint32_t acpi_pm_tco_ioport_readw (TCOIORegs *tr,uint32_t addr); +void acpi_pm_tco_ioport_writew (TCOIORegs *tr,uint32_t addr,uint32_t val); + +/* As per ICH9 spec, the internal timer has an error of ~0.6s on every tick */ +static inline int64_t tco_ticks_per_sec (void ) +{ +return 600000000LL ; +} +
include/hw/acpi/tco.h line 137
Quoted 10 lines
include/hw/acpi/tco.h new file +10
-0+static inline int is_valid_tco_time (uint32_t val) +{ +/* values of 0 or 1 will be ignored by ICH */ +return val >1 ; +} + +static inline int can_start_tco_timer (TCOIORegs *tr) +{ +return !(tr->tco.cnt1 &TCO_TMR_HLT ) &&is_valid_tco_time (tr->tco.tmr); +}
These three inlines should be in the .c file.
Don't be discouraged by the comments. It's good work!
Paolo
Quoted 36 lines
include/hw/acpi/tco.h new file +1
-0+#endif /* HW_ACPI_TCO_H */ 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
Re: [Qemu-devel] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 3 lines · Paulo Alcantara
Signed-off-by Paulo Alcantara <[email protected]>--- hw/i386/acpi-dsdt-pdrc.dsl | 46 ++++++++++++++++++++++++++++++++++++++++++
Why pdrc and not e.g. ccr (chipset configuration registers)? I cannot find PDRC / PCI device resource consumption in the ICH9 spec.
Quoted 18 lines
hw/i386/q35-acpi-dsdt.dsl | 1 + tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7795 bytes 3 files changed, 47 insertions(+) create mode 100644 hw/i386/acpi-dsdt-pdrc.dslhw/i386/acpi-dsdt-pdrc.dsl new file +7
-0@@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful,
hw/i386/acpi-dsdt-pdrc.dsl line 17
Quoted 10 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +10
-0+ * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +/**************************************************************** + * PCI Device Resource Comsumption
"Chipset configuration registers"
hw/i386/acpi-dsdt-pdrc.dsl line 21
Quoted 4 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +4
-0+ ****************************************************************/ + +Scope(\_SB.PCI0) { + Device (PDRC) {
Device (CCR)
hw/i386/acpi-dsdt-pdrc.dsl line 25
Quoted 4 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +4
-0+ Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (PDRS, ResourceTemplate() {
Just use Name(_CRS, ResourceTemplate() { ... })
Quoted 10 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +10
-0+ Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) + }) + + Method (_CRS, 0, Serialized) { + Return(PDRS) + } + } +} + +Scope(\_SB) {
hw/i386/acpi-dsdt-pdrc.dsl line 45
Quoted 10 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +10
-0+ OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000) + Field (RCRB, DWordAcc, Lock, Preserve) { + Offset(0x3000), + TCTL, 8, + , 24, + Offset(0x3400), + RTCC, 32, + HPTC, 32, + GCSR, 32, + }
Why do you need the RCRB OperationRegion if you never access it?
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 117
Quoted 10 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +1
-0+}hw/i386/q35-acpi-dsdt.dsl +1
-0@@ -114,6 +114,7 @@ DefinitionBlock ( } } +#include "acpi-dsdt-pdrc.dsl"
Just include it in this file since it's not shared between i440FX and Q35.
Thanks,
Paolo
Quoted 14 lines
hw/i386/q35-acpi-dsdt.dsl +0
-0#include "acpi-dsdt-hpet.dsl"tests/acpi-test-data/q35/DSDT binary +0
-0
Quoted 3 lines · On Wed, 27 May 2015 13:58:57 +0200 Paolo Bonzini <[email protected]> wrote:
the main issue here is lack of migration support. You need to add a new subsection to
vmstate_ich9_pmthat is migrated if the registers are different from the default values.
Hrm - OK. I didn't even take that into account. I'll do it.
Quoted 4 lines
hw/acpi/tco.c line 42
Quoted 2 lines
hw/acpi/tco.c new file +2
-0+static QEMUTimer *tco_timer; +static unsigned int timeouts_no;These must not be globals. Instead, add them to TCOIORegs.
OK.
Quoted 10 lines
hw/acpi/tco.c line 49
Quoted 7 lines
hw/acpi/tco.c new file +6
-0+static inline void tco_timer_reload (void ) +{ +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + +timer_del (tco_timer); +timer_mod (tco_timer, now +tco_ticks_per_sec ());No need for del+mod. Also, these are not
tco_ticks_per_sec()but ratherTCO_TICK_NSEC. It can be a #define instead of a function.
OK.
Quoted 16 lines
For a little extra challenge, you could the base value when the timer was started inside TCOIORegs. The timer can be made to expire directly after 0.6*TCO_TMR seconds; you can use the base value and the current time to compute the value of
TCO_RLD. Something like:case TCO_RLD: rld = tr->tco.rld; /* base_clock is set to -1 in tco_timer_stop, reloaded in * tco_timer_reload. */ if (base_clock != -1) { elapsed = (qemu_get_clock(QEMU_CLOCK_VIRTUAL) - base_clock) / TCO_TICK_NSEC; rld -= MIN(elapsed, rld); }
Quoted 3 lines
This makes it possible for QEMU to sleep most of the time when the guest is idle, instead of waking up every 0.6 seconds. But feel free to work on this afterwards.
Nice. I liked your approach and that will definitely avoid overheard waking up on every 0.6s. No, I will work on this approach right now so I can sleep well.
Quoted 6 lines
hw/acpi/tco.c line 95
Quoted 4 lines
hw/acpi/tco.c new file +3
-0+void acpi_pm_tco_init (TCOIORegs *tr) +{ + *tr =TCO_IO_REGS_DEFAULTS_INIT ();Just inline the macro definition here.
OK.
Quoted 8 lines
Quoted 5 lines
hw/acpi/tco.c new file +4
-0+case TCO1_CNT : + val &=TCO1_CNT_MASK ; +/* TCO_LOCK bit cannot be changed once set */ + tr->tco.cnt1 = (val & ~TCO_LOCK) | (tr->tco.cnt1 &
TCO_LOCK);This means that
TCO_LOCKis never set intr->tco.cnt1, I think? If I'm correct, it should be covered by tests.
No. The TCO_LOCK bit is set in tr->tco.cnt1, but cannot be unset afterwards -- on reset, of course, it will. Maybe a test that covers setting it and then unsetting it might be interesting to have in tests/tco-test.c.
Quoted 18 lines
Quoted 7 lines
include/hw/acpi/tco.h new file +7
-0+#define TCO_IO_REGS_DEFAULTS_INIT () \ + (TCOIORegs) { \ + .tco = { \ + .rld = TCO_RLD_DEFAULT, \ + .din = TCO_DAT_IN_DEFAULT, \ + .dout = TCO_DAT_OUT_DEFAULT, \ + .sts1 = TCO1_STS_DEFAULT, \include/hw/acpi/tco.h line 115
Quoted 10 lines
include/hw/acpi/tco.h new file +10
-0+ .sts2 = TCO2_STS_DEFAULT, \ + .cnt1 = TCO1_CNT_DEFAULT, \ + .cnt2 = TCO2_CNT_DEFAULT, \ + .msg1 = TCO_MESSAGE1_DEFAULT, \ + .msg2 = TCO_MESSAGE2_DEFAULT, \ + .wdcnt = TCO_WDCNT_DEFAULT, \ + .tmr = TCO_TMR_DEFAULT, \ + }, \ + .sw_irq_gen =SW_IRQ_GEN_DEFAULT \ + }
Quoted 2 lines
No need for this definition. This and the
*_DEFAULTdefinitions as well should be in the .c file.
OK.
Quoted 16 lines
Quoted 16 lines
include/hw/acpi/tco.h new file +4
-0+/* tco.c */ +void acpi_pm_tco_init (TCOIORegs *tr); +uint32_t acpi_pm_tco_ioport_readw (TCOIORegs *tr,uint32_t addr); +void acpi_pm_tco_ioport_writew(TCOIORegs *tr, uint32_t addr,
uint32_tval); +
+/* As per ICH9 spec, the internal timer has an error of ~0.6s on every tick */ +static inlineint64_ttco_ticks_per_sec(void)include/hw/acpi/tco.h new file +8
-0+{ +return 600000000LL ; +} + +static inline int is_valid_tco_time (uint32_t val) +{ +/* values of 0 or 1 will be ignored by ICH */ +return val >1 ;
Quoted 8 lines
Quoted 6 lines
include/hw/acpi/tco.h new file +5
-0+} + +static inline int can_start_tco_timer (TCOIORegs *tr) +{ + return !(tr->tco.cnt1 & TCO_TMR_HLT) &&
is_valid_tco_time(tr->tco.tmr); +}These three inlines should be in the .c file.
OK.
Quoted 2 lines
Don't be discouraged by the comments. It's good work!
Alright. Thank you for the comments! I'll send a v2 soon.
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Re: [Qemu-devel] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paolo BonziniQuoted 10 lines · On Wed, 27 May 2015 14:03:59 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 4 lines · Paulo Alcantara
Signed-off-by Paulo Alcantara <[email protected]>--- hw/i386/acpi-dsdt-pdrc.dsl | 46++++++++++++++++++++++++++++++++++++++++++
Why pdrc and not e.g. ccr (chipset configuration registers)? I cannot find PDRC / PCI device resource consumption in the ICH9 spec.
I've found the "PDRC" name being used in ACPI DSDT table definitions on the internet for the MS legacy PNP ID "PNP0C02". However, the ICH9 does mention "Chipset Configuration registers" so it's really more meaningful to name it as "CCR" and then matching spec.
Quoted 27 lines
Quoted 27 lines
hw/i386/q35-acpi-dsdt.dsl | 1 + tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7795 bytes 3 files changed, 47 insertions(+) create mode 100644 hw/i386/acpi-dsdt-pdrc.dslhw/i386/acpi-dsdt-pdrc.dsl new file +2
-0@@ -0,0 +1,46 @@ +/* + * This program is free software; you can redistribute it and/ormodify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.hw/i386/acpi-dsdt-pdrc.dsl new file +7
-0+ + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public
Quoted 8 lines
hw/i386/acpi-dsdt-pdrc.dsl line 17
Quoted 6 lines
License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */hw/i386/acpi-dsdt-pdrc.dsl new file +3
-0+ +/**************************************************************** + * PCI Device Resource Comsumption"Chipset configuration registers"
OK.
Quoted 7 lines
hw/i386/acpi-dsdt-pdrc.dsl line 21
Quoted 5 lines
+ ****************************************************************/
hw/i386/acpi-dsdt-pdrc.dsl new file +3
-0+ +Scope(\_SB.PCI0) { + Device (PDRC) {Device (CCR)
OK.
Quoted 7 lines
hw/i386/acpi-dsdt-pdrc.dsl line 25
Quoted 5 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +4
-0+ Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (PDRS, ResourceTemplate() {Just use Name(_CRS,
ResourceTemplate(){ ... })
OK.
Quoted 15 lines
Quoted 15 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +14
-0+ Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) + }) + + Method (_CRS, 0, Serialized) { + Return(PDRS) + } + } +} + +Scope(\_SB) { + OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000) + Field (RCRB, DWordAcc, Lock, Preserve) { + Offset(0x3000), + TCTL, 8,
Quoted 8 lines
hw/i386/acpi-dsdt-pdrc.dsl line 45
Quoted 6 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +6
-0+ , 24, + Offset(0x3400), + RTCC, 32, + HPTC, 32, + GCSR, 32, + }Why do you need the RCRB OperationRegion if you never access it?
Indeed. It's not being referenced in any AML code so I'll remove it.
Quoted 10 lines
Quoted 10 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +1
-0+}hw/i386/q35-acpi-dsdt.dsl +0
-0@@ -114,6 +114,7 @@ DefinitionBlock ( } }
Quoted 4 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 117
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+#include "acpi-dsdt-pdrc.dsl"Just include it in this file since it's not shared between i440FX and Q35.
OK.
I'll send a v2 with all proposed changes.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraHi,
hw/i386/acpi-dsdt-pdrc.dsl line 36
Quoted 2 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +2
-0+Scope(\_SB) { + OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000)
Where does this address come from?
Is this a standard location suggested by intel specs? Or is the firmware free to choose it?
cheers,
Gerd
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Hi Gerd,
Quoted 4 lines · On Thu, 28 May 2015 09:13:35 +0200 Gerd Hoffmann <[email protected]> wrote:
hw/i386/acpi-dsdt-pdrc.dsl line 36
Quoted 2 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +2
-0+Scope(\_SB) { + OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000)Where does this address come from?
This address is reserved in an ACPI DSDT table for Intel Haswell in Coreboot project, Vlv2DeviceRefCodePkg package in EDK II as well as my Haswell laptop on which I can see it through dmesg :-)
Quoted 1 line
Is this a standard location suggested by intel specs?
I haven't found any Intel spec or any other document that suggests such address, but from "9.4 Memory Map" section in ICH9 spec, it seems safe to use that MMIO region for the 16KiB of chipset configuration registers.
Quoted 1 line
Or is the firmware free to choose it?
Given that, I would say so.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
PATCH v2 2/3 target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo Alcantarav1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRB
--- hw/i386/q35-acpi-dsdt.dsl | 14 ++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 2 files changed, 14 insertions(+)
hw/i386/q35-acpi-dsdt.dsl +14 -0
@@ -114,6 +114,20 @@ DefinitionBlock ( } } +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) // RCBA + }) + } +} + #include "acpi-dsdt-hpet.dsl"
tests/acpi-test-data/q35/DSDT binary +0 -0
Signature · 1 line
2.1.0
PATCH v2 1/3 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 59 ++++++++++++ hw/acpi/tco.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 10 ++ include/hw/acpi/ich9.h | 4 + include/hw/acpi/tco.h | 98 +++++++++++++++++++ include/hw/i386/ich9.h | 8 ++ 7 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +59 -0
103 lines not on this page · raw message
hw/acpi/tco.c new file +254 -0
254 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 +98 -0
98 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 v2 3/3 tests: add testcase for TCO watchdog emulation
v1 -> v2:
* some cleanup
* added test for TCO_LOCK bit
--- tests/Makefile | 2 + tests/tco-test.c | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 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 +419 -0
419 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 5 lines · Paulo Alcantara
Hi Gerd,
On Thu, 28 May 2015 09:13:35 +0200
Gerd Hoffmann <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines
hw/i386/acpi-dsdt-pdrc.dsl line 36
Quoted 2 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +2
-0+Scope(\_SB) { + OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000)Where does this address come from?
This address is reserved in an ACPI DSDT table for Intel Haswell in Coreboot project, Vlv2DeviceRefCodePkg package in EDK II as well as my Haswell laptop on which I can see it through
dmesg:-)
So it seems to be kind of standard.
Same address on my laptop btw.
Quoted 10 lines
Quoted 1 line
Is this a standard location suggested by intel specs?
I haven't found any Intel spec or any other document that suggests such address, but from "9.4 Memory Map" section in ICH9 spec, it seems safe to use that MMIO region for the 16KiB of chipset configuration registers.
Quoted 1 line
Or is the firmware free to choose it?
Given that, I would say so.
There are a few more cases where addresses programmed by the firmware and addresses in the acpi tables must match: acpi registers, pci mmconfig space for example. They are handles this way:
(1) firmware programs the hardware registers as it pleases.
(2) when the firmware fetches the acpi tables from qemu (via fw_cfg) qemu will update the tables according to the hardware programming.
So the question is whenever we better do that here too, or whenever it is fine to simply hardcore this to 0xfed1c000 everywhere ...
I tend to think hardcoding is fine in that case. coreboot, edk2 & seabios all place it at the same location, and it is highly unlikely we ever want move this to another place some day for some reason.
cheers,
Gerd
hw/acpi/tco.c line 176
Quoted 7 lines · Paulo Alcantara
hw/acpi/tco.c new file +7
-0+case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val;
Please mask out bits outside TCO_RLD_MASK here, same as you do for TCO1_STS_MASK and friends.
Quoted 2 lines
(quoted diff) +2
-0+ } + break;
[...]
Quoted 1 line
+
tr->tco.cnt1=tr->tco.cnt1&TCO_LOCK? val |TCO_LOCK: val;
Since you have to respin, you can do:
tr->tco.cnt1 = val | (tr->tco.cnt1 & TCO_LOCK);
Otherwise looks good to me.
CCing the maintainer.
Paolo
Re: [Qemu-devel] [PATCH v2 3/3] tests: add testcase for TCO watchdog emulation
In reply to Paulo AlcantaraQuoted 447 lines · Paulo Alcantara
v1 -> v2:
* some cleanup
* added test forTCO_LOCKbitSigned-off-by Paulo Alcantara <[email protected]>--- tests/Makefile | 2 + tests/tco-test.c | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 tests/tco-test.ctests/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 +409
-0@@ -0,0 +1,419 @@ +/* +* QEMU ICH9 TCO emulation tests +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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 <glib.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "libqtest.h" +#include "libqos/pci.h" +#include "libqos/pci-pc.h" +#include "hw/pci/pci_regs.h" +#include "hw/i386/ich9.h" +#include "hw/acpi/ich9.h" +#include "hw/acpi/tco.h" + +#define PM_IO_BASE_ADDR 0xb000 +#define RCBA_BASE_ADDR 0xfed1c000 + +enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +#define TCO_SECS_TO_TICKS (secs) (((secs) * 10) / 6) +#define TCO_TICKS_TO_SECS (ticks) (((ticks) * 6) / 10) + +typedef struct { +const char *args; +QPCIDevice *dev; +void *lpc_base; +void *tco_io_base; +}TestData ; + +static void test_init (TestData *d) +{ +QPCIBus *bus; +QTestState *qs; +char *s; + + s =g_strdup_printf ("-machine q35 %s" , !d->args ?"" : d->args); + qs =qtest_start (s); +qtest_irq_intercept_in (qs,"ioapic" ); +g_free (s); + + bus =qpci_init_pc (); + d->dev =qpci_device_find (bus,QPCI_DEVFN (0x1f ,0x00 )); +g_assert (d->dev !=NULL ); + +/* map PCI-to-LPC bridge interface BAR */ + d->lpc_base =qpci_iomap (d->dev,0 ,NULL ); + +qpci_device_enable (d->dev); + +g_assert (d->lpc_base !=NULL ); + +/* set ACPI PM I/O space base address */ +qpci_config_writel (d->dev, (uintptr_t )d->lpc_base +ICH9_LPC_PMBASE , +PM_IO_BASE_ADDR |0x1 ); +/* enable ACPI I/O */ +qpci_config_writeb (d->dev, (uintptr_t )d->lpc_base +ICH9_LPC_ACPI_CTRL , +0x80 ); +/* set Root Complex BAR */ +qpci_config_writel (d->dev, (uintptr_t )d->lpc_base +ICH9_LPC_RCBA , +RCBA_BASE_ADDR |0x1 ); + + d->tco_io_base = (void *)((uintptr_t )PM_IO_BASE_ADDR +0x60 ); +} + +static void stop_tco (const TestData *d) +{ +uint32_t val; + + val =qpci_io_readw (d->dev, d->tco_io_base +TCO1_CNT ); + val |=TCO_TMR_HLT ; +qpci_io_writew (d->dev, d->tco_io_base +TCO1_CNT , val); +} + +static void start_tco (const TestData *d) +{ +uint32_t val; + + val =qpci_io_readw (d->dev, d->tco_io_base +TCO1_CNT ); + val &= ~TCO_TMR_HLT ; +qpci_io_writew (d->dev, d->tco_io_base +TCO1_CNT , val); +} + +static void load_tco (const TestData *d) +{ +qpci_io_writew (d->dev, d->tco_io_base +TCO_RLD ,4 ); +} + +static void set_tco_timeout (const TestData *d,uint16_t ticks) +{ +qpci_io_writew (d->dev, d->tco_io_base +TCO_TMR , ticks); +} + +static void clear_tco_status (const TestData *d) +{ +qpci_io_writew (d->dev, d->tco_io_base +TCO1_STS ,0x0008 ); +qpci_io_writew (d->dev, d->tco_io_base +TCO2_STS ,0x0002 ); +qpci_io_writew (d->dev, d->tco_io_base +TCO2_STS ,0x0004 ); +} + +static void reset_on_second_timeout (bool enable) +{ +uint32_t val; + + val =readl (RCBA_BASE_ADDR +ICH9_LPC_RCBA_GCS ); +if (enable) { + val &= ~ICH9_LPC_RCBA_GCS_NO_REBOOT ; + }else { + val |=ICH9_LPC_RCBA_GCS_NO_REBOOT ; + } +writel (RCBA_BASE_ADDR +ICH9_LPC_RCBA_GCS , val); +} + +static void test_tco_defaults (void ) +{ +TestData d; + + d.args =NULL ; +test_init (&d); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_RLD), ==, +TCO_RLD_DEFAULT ); +/* TCO_DAT_IN & TCO_DAT_OUT */ + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_DAT_IN), ==, + (TCO_DAT_OUT_DEFAULT <<8 ) |TCO_DAT_IN_DEFAULT ); +/* TCO1_STS & TCO2_STS */ + g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_base + TCO1_STS), ==, + (TCO2_STS_DEFAULT <<16 ) |TCO1_STS_DEFAULT ); +/* TCO1_CNT & TCO2_CNT */ + g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_base + TCO1_CNT), ==, + (TCO2_CNT_DEFAULT <<16 ) |TCO1_CNT_DEFAULT ); +/* TCO_MESSAGE1 & TCO_MESSAGE2 */ + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_MESSAGE1), ==, + (TCO_MESSAGE2_DEFAULT <<8 ) |TCO_MESSAGE1_DEFAULT ); + g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_base + TCO_WDCNT), ==, +TCO_WDCNT_DEFAULT ); + g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_base + SW_IRQ_GEN), ==, +SW_IRQ_GEN_DEFAULT ); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_TMR), ==, +TCO_TMR_DEFAULT ); +qtest_end (); +} + +static void test_tco_timeout (void ) +{ +TestData d; +const uint16_t ticks =TCO_SECS_TO_TICKS (4 ); +uint32_t val; +int ret; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); +clock_step (ticks *TCO_TICK_NSEC ); + +/* test first timeout */ + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==1 ); + +/* test clearing timeout bit */ + val |=TCO_TIMEOUT ; +qpci_io_writew (d.dev, d.tco_io_base +TCO1_STS , val); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==0 ); + +/* test second timeout */ +clock_step (ticks *TCO_TICK_NSEC ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==1 ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_SECOND_TO_STS ?1 :0 ; +g_assert (ret ==1 ); + +stop_tco (&d); +qtest_end (); +} + +static void test_tco_max_timeout (void ) +{ +TestData d; +const uint16_t ticks =0xffff ; +uint32_t val; +int ret; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); +clock_step (((ticks &TCO_TMR_MASK ) -1 ) *TCO_TICK_NSEC ); + + val =qpci_io_readw (d.dev, d.tco_io_base +TCO_RLD ); + g_assert_cmpint(val & TCO_RLD_MASK, ==, 1); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==0 ); +clock_step (TCO_TICK_NSEC ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==1 ); + +stop_tco (&d); +qtest_end (); +} + +static QDict *get_watchdog_action (void ) +{ +QDict *ev =qmp ("" ); +QDict *data; +g_assert (!strcmp (qdict_get_str (ev,"event" ),"WATCHDOG" )); + + data =qdict_get_qdict (ev,"data" ); +QINCREF (data); +QDECREF (ev); +return data; +} + +static void test_tco_second_timeout_pause (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (32 ); +QDict *ad; + + td.args ="-watchdog-action pause" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td,TCO_SECS_TO_TICKS (16 )); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"pause" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_second_timeout_reset (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (16 ); +QDict *ad; + + td.args ="-watchdog-action reset" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td,TCO_SECS_TO_TICKS (16 )); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"reset" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_second_timeout_shutdown (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (128 ); +QDict *ad; + + td.args ="-watchdog-action shutdown" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td, ticks); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"shutdown" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_second_timeout_none (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (256 ); +QDict *ad; + + td.args ="-watchdog-action none" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td, ticks); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"none" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_ticks_counter (void ) +{ +TestData d; +uint16_t ticks =TCO_SECS_TO_TICKS (8 ); +uint16_t rld; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); + +do { + rld =qpci_io_readw (d.dev, d.tco_io_base +TCO_RLD ) &TCO_RLD_MASK ; + g_assert_cmpint(rld, ==, ticks); +clock_step (TCO_TICK_NSEC ); + ticks--; + }while (!(qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ) &TCO_TIMEOUT )); + +stop_tco (&d); +qtest_end (); +} + +static void test_tco_lock_bit (void ) +{ +TestData d; +uint16_t val; + + d.args =NULL ; +test_init (&d); + + val =TCO_LOCK ; +qpci_io_writew (d.dev, d.tco_io_base +TCO1_CNT , val); + val &= ~TCO_LOCK ; +qpci_io_writew (d.dev, d.tco_io_base +TCO1_CNT , val); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO1_CNT), ==, +TCO_LOCK ); +qtest_end (); +} + +int main (int argc,char **argv) +{ + (void )test_tco_ticks_counter; +g_test_init (&argc, &argv,NULL ); +qtest_add_func ("tco/defaults" , test_tco_defaults); +qtest_add_func ("tco/timeout/no_action" , test_tco_timeout);
tests/tco-test.c line 419
Quoted 10 lines
tests/tco-test.c new file +10
-0+qtest_add_func ("tco/timeout/no_action/max" , test_tco_max_timeout); +qtest_add_func ("tco/second_timeout/pause" , test_tco_second_timeout_pause); +qtest_add_func ("tco/second_timeout/reset" , test_tco_second_timeout_reset); +qtest_add_func ("tco/second_timeout/shutdown" , + test_tco_second_timeout_shutdown); +qtest_add_func ("tco/second_timeout/none" , test_tco_second_timeout_none); +qtest_add_func ("tco/counter" , test_tco_ticks_counter); +qtest_add_func ("tco/lock_bit" , test_tco_lock_bit); +return g_test_run (); +}
Looks good.
If you want, you can add a test for the reserved bits of the various registers.
Paolo
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Gerd HoffmannQuoted 37 lines · Gerd Hoffmann
Quoted 5 lines · Paulo Alcantara
Hi Gerd,
On Thu, 28 May 2015 09:13:35 +0200
Gerd Hoffmann <[email protected]> wrote:Quoted 8 lines
Quoted 4 lines
hw/i386/acpi-dsdt-pdrc.dsl line 36
Quoted 2 lines
hw/i386/acpi-dsdt-pdrc.dsl new file +2
-0+Scope(\_SB) { + OperationRegion (RCRB, SystemMemory, 0xfed1c000, 0x4000)Where does this address come from?
This address is reserved in an ACPI DSDT table for Intel Haswell in Coreboot project, Vlv2DeviceRefCodePkg package in EDK II as well as my Haswell laptop on which I can see it through
dmesg:-)So it seems to be kind of standard.
Same address on my laptop btw.Quoted 10 lines
Quoted 1 line
Is this a standard location suggested by intel specs?
I haven't found any Intel spec or any other document that suggests such address, but from "9.4 Memory Map" section in ICH9 spec, it seems safe to use that MMIO region for the 16KiB of chipset configuration registers.
Quoted 1 line
Or is the firmware free to choose it?
Given that, I would say so.
There are a few more cases where addresses programmed by the firmware and addresses in the acpi tables must match: acpi registers, pci mmconfig space for example. They are handles this way:
(1) firmware programs the hardware registers as it pleases.
(2) when the firmware fetches the acpi tables from qemu (viafw_cfg) qemu will update the tables according to the hardware programming.
Quoted 6 lines
So the question is whenever we better do that here too, or whenever it is fine to simply hardcore this to
0xfed1c000everywhere ...I tend to think hardcoding is fine in that case. coreboot, edk2 & seabios all place it at the same location, and it is highly unlikely we ever want move this to another place some day for some reason.
Thanks for the explanation. So, handling it the same way as we do for acpi regs and pci mmconfig space seems to be the proper solution, however I think it's OK to hard-code that address for now since it's being used in many places already.
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 11 lines · Paolo Bonzini
hw/acpi/tco.c line 176
Quoted 7 lines · Paulo Alcantara
hw/acpi/tco.c new file +7
-0+case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val;
Quoted 2 lines
Please mask out bits outside
TCO_RLD_MASKhere, same as you do forTCO1_STS_MASKand friends.
OK.
Quoted 5 lines
Quoted 1 line
+
tr->tco.cnt1=tr->tco.cnt1&TCO_LOCK? val |TCO_LOCK: val;Since you have to respin, you can do:
tr->tco.cnt1 = val | (tr->tco.cnt1 & TCO_LOCK);
OK.
Quoted 4 lines
Otherwise looks good to me.
CCing the maintainer.
OK. Sorry for not CCing him earlier.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 12 lines · On Mon, 1 Jun 2015 10:38:32 -0300 "Paulo Alcantara" <[email protected]> wrote:
Quoted 11 lines · Paolo Bonzini
Quoted 7 lines · Paulo Alcantara
hw/acpi/tco.c new file +7
-0+case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val;
Quoted 4 lines
Quoted 2 lines
Please mask out bits outside
TCO_RLD_MASKhere, same as you do forTCO1_STS_MASKand friends.OK.
Hrm - actually, I can't do that. Unlike TCO1_STS, TCO2_STS and TCO1_CNT registers that have some bits which are disabled by writing 1 to them -- that's why I mask them out before updating -- the TCO_RLD and TCO_TMR registers only have bits 15:10 marked as _reserved_ and I should not zero them out. Does that seem correct to you?
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
PATCH v3 2/3 target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo Alcantarav1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRB
--- hw/i386/q35-acpi-dsdt.dsl | 14 ++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 2 files changed, 14 insertions(+)
hw/i386/q35-acpi-dsdt.dsl +14 -0
@@ -114,6 +114,20 @@ DefinitionBlock ( } } +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) // RCBA + }) + } +} + #include "acpi-dsdt-hpet.dsl"
tests/acpi-test-data/q35/DSDT binary +0 -0
Signature · 1 line
2.1.0
PATCH v3 1/3 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* set SECOND_TO_STS and BOOT_STS bits in TCO2_STS instead
* improve handling of TCO_LOCK bit in TCO1_CNT register
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 59 ++++++++++++ hw/acpi/tco.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 10 ++ include/hw/acpi/ich9.h | 4 + include/hw/acpi/tco.h | 98 +++++++++++++++++++ include/hw/i386/ich9.h | 8 ++ 7 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +59 -0
103 lines not on this page · raw message
hw/acpi/tco.c new file +254 -0
254 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 +98 -0
98 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 v3 3/3 tests: add testcase for TCO watchdog emulation
v1 -> v2:
* some cleanup
* add test for TCO_LOCK bit
v2 -> v3:
* add tests for TCO control & status bits
* fix check of SECOND_TO_STS bit (it's set in TCO2_STS reg)
--- tests/Makefile | 2 + tests/tco-test.c | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 477 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 +475 -0
475 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 13 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.
Quoted 7 lines
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* setSECOND_TO_STSandBOOT_STSbits inTCO2_STSinstead
* improve handling ofTCO_LOCKbit inTCO1_CNTregister
Michael, ping? :-)
(looks like there's a lot of ICH9 changes since this patchset was sent, so you want me to rebase it against master and resend, please let me know)
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 13 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.
Quoted 7 lines
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* setSECOND_TO_STSandBOOT_STSbits inTCO2_STSinstead
* improve handling ofTCO_LOCKbit inTCO1_CNTregister
changelog must come after --- so that git am ignores it.
Quoted 2 lines
Signed-off-by Paulo Alcantara <[email protected]>
for some reason v3 was sent as reply to v2.
Don't do that please.
Quoted 129 lines
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 59 ++++++++++++ hw/acpi/tco.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 10 ++ include/hw/acpi/ich9.h | 4 + include/hw/acpi/tco.h | 98 +++++++++++++++++++ include/hw/i386/ich9.h | 8 ++ 7 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.hhw/acpi/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.ohw/acpi/ich9.c +58
-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);@@ -157,6 +188,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_tco (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return s->tco_regs.use_tco; +} + +static const VMStateDescription vmstate_tco_io_state = { + .name ="ich9_pm/tco" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_STRUCT (tco_regs, ICH9LPCPMRegs,1 , vmstate_tco_io_sts, + TCOIORegs), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_ich9_pm = { .name ="ich9_pm" , .version_id =1 ,@@ -179,6 +228,10 @@ const VMStateDescription vmstate_ich9_pm = { .vmsd = &vmstate_memhp_state, .needed = vmstate_test_use_memhp, }, + { + .vmsd = &vmstate_tco_io_state, + .needed = vmstate_test_use_tco, + }, VMSTATE_END_OF_LIST() } };@@ -230,6 +283,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/ich9.c void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) · line 418
Quoted 4 lines
hw/acpi/ich9.c +1
-0@@ -357,6 +415,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) pm->disable_s3 =0 ; pm->disable_s4 =0 ; pm->s4_val =2 ; + pm->tco_regs.use_tco = true;
Would be safer to add a property, and not to enable this for old machine types.
Quoted 84 lines
hw/acpi/ich9.c +0
-0object_property_add_uint32_ptr (obj,ACPI_PM_PROP_PM_IO_BASE , &pm->pm_io_base, errp);hw/acpi/tco.c new file +75
-0@@ -0,0 +1,254 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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-common.h" +#include "sysemu/watchdog.h" +#include "hw/i386/ich9.h" + +#include "hw/acpi/tco.h" + +//#define DEBUG + +#ifdef DEBUG +#define TCO_DEBUG (fmt, ...) \ + do { \ + fprintf(stderr, "%s "fmt, __func__, ## __VA_ARGS__); \ + } while (0) +#else +#define TCO_DEBUG (fmt, ...) do { } while (0) +#endif + +enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +static inline void tco_timer_reload (TCOIORegs *tr) +{ + tr->expire_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + ((int64_t )(tr->tco.tmr &TCO_TMR_MASK ) *TCO_TICK_NSEC ); +timer_mod (tr->tco_timer, tr->expire_time); +} + +static inline void tco_timer_stop (TCOIORegs *tr) +{ + tr->expire_time =-1 ; +} + +static void tco_timer_expired (void *opaque) +{ +TCOIORegs *tr = opaque; +ICH9LPCPMRegs *pm =container_of (tr, ICH9LPCPMRegs, tco_regs); +ICH9LPCState *lpc =container_of (pm, ICH9LPCState, pm); +uint32_t gcs =pci_get_long (lpc->chip_config +ICH9_LPC_RCBA_GCS ); + + tr->tco.rld =0 ;
hw/acpi/tco.c line 85
Quoted 10 lines
hw/acpi/tco.c new file +10
-0+ tr->tco.sts1 |=TCO_TIMEOUT ; +if (++tr->timeouts_no ==2 ) { + tr->tco.sts2 |=TCO_SECOND_TO_STS ; + tr->tco.sts2 |=TCO_BOOT_STS ; + tr->timeouts_no =0 ; + +if (!(gcs &ICH9_LPC_RCBA_GCS_NO_REBOOT )) { +watchdog_perform_action (); +tco_timer_stop (tr); +return ;
So this is a virtual clock - not running when VM is not running. Doesn't this mean if you stop VM for a while, it's almost sure to fire when you resume?
Maybe it's a useful feature, but maybe it's best to keep it off by default?
Quoted 141 lines
hw/acpi/tco.c new file +141
-0+ } + } + +if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) { +ich9_generate_smi (); + }else { +ich9_generate_nmi (); + } + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); +} + +void acpi_pm_tco_init (TCOIORegs *tr) +{ + *tr = (TCOIORegs ) { + .tco = { + .rld =TCO_RLD_DEFAULT , + .din =TCO_DAT_IN_DEFAULT , + .dout =TCO_DAT_OUT_DEFAULT , + .sts1 =TCO1_STS_DEFAULT , + .sts2 =TCO2_STS_DEFAULT , + .cnt1 =TCO1_CNT_DEFAULT , + .cnt2 =TCO2_CNT_DEFAULT , + .msg1 =TCO_MESSAGE1_DEFAULT , + .msg2 =TCO_MESSAGE2_DEFAULT , + .wdcnt =TCO_WDCNT_DEFAULT , + .tmr =TCO_TMR_DEFAULT , + }, + .sw_irq_gen =SW_IRQ_GEN_DEFAULT , + .tco_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , tco_timer_expired, tr), + .expire_time =-1 , + .timeouts_no =0 , + }; +} + +/* NOTE: values of 0 or 1 will be ignored by ICH */ +static inline int can_start_tco_timer (TCOIORegs *tr) +{ +return !(tr->tco.cnt1 &TCO_TMR_HLT ) && tr->tco.tmr >1 ; +} + +uint32_t acpi_pm_tco_ioport_readw (TCOIORegs *tr,uint32_t addr) +{ +uint16_t rld; + +switch (addr) { +case TCO_RLD : +if (tr->expire_time !=-1 ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +int64_t elapsed = (tr->expire_time - now) /TCO_TICK_NSEC ; + rld = (uint16_t )elapsed | (tr->tco.rld & ~TCO_RLD_MASK ); + }else { + rld = tr->tco.rld; + } +return rld; +case TCO_DAT_IN : +return tr->tco.din; +case TCO_DAT_OUT : +return tr->tco.dout; +case TCO1_STS : +return tr->tco.sts1; +case TCO2_STS : +return tr->tco.sts2; +case TCO1_CNT : +return tr->tco.cnt1; +case TCO2_CNT : +return tr->tco.cnt2; +case TCO_MESSAGE1 : +return tr->tco.msg1; +case TCO_MESSAGE2 : +return tr->tco.msg2; +case TCO_WDCNT : +return tr->tco.wdcnt; +case TCO_TMR : +return tr->tco.tmr; +case SW_IRQ_GEN : +return tr->sw_irq_gen; + } +return 0 ; +} + +void acpi_pm_tco_ioport_writew (TCOIORegs *tr,uint32_t addr,uint32_t val) +{ +switch (addr) { +case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val; + } +break ; +case TCO_DAT_IN : + tr->tco.din = val; + tr->tco.sts1 |=SW_TCO_SMI ; +ich9_generate_smi (); +break ; +case TCO_DAT_OUT : + tr->tco.dout = val; + tr->tco.sts1 |=TCO_INT_STS ; +/* TODO: cause an interrupt, as selected by the TCO_INT_SEL bits */ +break ; +case TCO1_STS : + tr->tco.sts1 = val &TCO1_STS_MASK ; +break ; +case TCO2_STS : + tr->tco.sts2 = val &TCO2_STS_MASK ; +break ; +case TCO1_CNT : + val &=TCO1_CNT_MASK ; +/* +* once TCO_LOCK bit is set, it can not be cleared by software. a reset +* is required to change this bit from 1 to 0 -- it defaults to 0. +*/ + tr->tco.cnt1 = val | (tr->tco.cnt1 &TCO_LOCK ); +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { +tco_timer_stop (tr); + } +break ; +case TCO2_CNT : + tr->tco.cnt2 = val; +break ; +case TCO_MESSAGE1 : + tr->tco.msg1 = val; +break ; +case TCO_MESSAGE2 : + tr->tco.msg2 = val; +break ; +case TCO_WDCNT : + tr->tco.wdcnt = val; +break ; +case TCO_TMR : + tr->tco.tmr = val; +break ; +case SW_IRQ_GEN : + tr->sw_irq_gen = val; +break ;
hw/acpi/tco.c line 236
Quoted 10 lines
hw/acpi/tco.c new file +10
-0+ } +} + +const VMStateDescription vmstate_tco_io_sts = { + .name ="tco io device status" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_BOOL (use_tco, TCOIORegs),
So this field is only migrated if it is true.
Doesn't seem to make sense.
Quoted 208 lines
hw/acpi/tco.c new file +18
-0+ VMSTATE_UINT16(tco.rld, TCOIORegs), + VMSTATE_UINT8(tco.din, TCOIORegs), + VMSTATE_UINT8(tco.dout, TCOIORegs), + VMSTATE_UINT16(tco.sts1, TCOIORegs), + VMSTATE_UINT16(tco.sts2, TCOIORegs), + VMSTATE_UINT16(tco.cnt1, TCOIORegs), + VMSTATE_UINT16(tco.cnt2, TCOIORegs), + VMSTATE_UINT8(tco.msg1, TCOIORegs), + VMSTATE_UINT8(tco.msg2, TCOIORegs), + VMSTATE_UINT8(tco.wdcnt, TCOIORegs), + VMSTATE_UINT16(tco.tmr, TCOIORegs), + VMSTATE_UINT8(sw_irq_gen, TCOIORegs), + VMSTATE_TIMER_PTR(tco_timer, TCOIORegs), + VMSTATE_INT64(expire_time, TCOIORegs), + VMSTATE_UINT8(timeouts_no, TCOIORegs), +VMSTATE_END_OF_LIST () + } +};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 +98
-0@@ -0,0 +1,98 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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. +*/ +#ifndef HW_ACPI_TCO_H +#define HW_ACPI_TCO_H + +#include "qemu/typedefs.h" +#include "qemu-common.h" + +/* As per ICH9 spec, the internal timer has an error of ~0.6s on every tick */ +#define TCO_TICK_NSEC 600000000LL + +/* TCO I/O register offsets */ +enum { +TCO_RLD =0x00 , +TCO_DAT_IN =0x02 , +TCO_DAT_OUT =0x03 , +TCO1_STS =0x04 , +TCO2_STS =0x06 , +TCO1_CNT =0x08 , +TCO2_CNT =0x0a , +TCO_MESSAGE1 =0x0c , +TCO_MESSAGE2 =0x0d , +TCO_WDCNT =0x0e , +SW_IRQ_GEN =0x10 , +TCO_TMR =0x12 , +}; + +/* TCO I/O register control/status bits */ +enum { +SW_TCO_SMI = (1 <<1 ), +TCO_INT_STS = (1 <<2 ), +TCO_LOCK = (1 <<12 ), +TCO_TMR_HLT = (1 <<11 ), +TCO_TIMEOUT = (1 <<3 ), +TCO_SECOND_TO_STS = (1 <<1 ), +TCO_BOOT_STS = (1 <<2 ), +}; + +/* TCO I/O registers mask bits */ +enum { +TCO_RLD_MASK =0x3ff , +TCO1_STS_MASK =0xe870 , +TCO2_STS_MASK =0xfff8 , +TCO1_CNT_MASK =0xfeff , +TCO_TMR_MASK =0x3ff , +}; + +typedef struct TCOIORegs { +bool use_tco; +struct { +uint16_t rld; +uint8_t din; +uint8_t dout; +uint16_t sts1; +uint16_t sts2; +uint16_t cnt1; +uint16_t cnt2; +uint8_t msg1; +uint8_t msg2; +uint8_t wdcnt; +uint16_t tmr; + } tco; +uint8_t sw_irq_gen; + +QEMUTimer *tco_timer; +int64_t expire_time; +uint8_t timeouts_no; +}TCOIORegs ; + +/* tco.c */ +void acpi_pm_tco_init (TCOIORegs *tr); +uint32_t acpi_pm_tco_ioport_readw (TCOIORegs *tr,uint32_t addr); +void acpi_pm_tco_ioport_writew (TCOIORegs *tr,uint32_t addr,uint32_t val); + +extern const VMStateDescription vmstate_tco_io_sts; + +#endif /* HW_ACPI_TCO_H */ 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 0x2Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v3 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 3 lines · Paulo Alcantara
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRB
changelog should come after ---.
An empty commit log is too terse I think.
Could you quote spec in the changelog?
Quoted 14 lines
Signed-off-by Paulo Alcantara <[email protected]>--- hw/i386/q35-acpi-dsdt.dsl | 14 ++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 2 files changed, 14 insertions(+)hw/i386/q35-acpi-dsdt.dsl +0
-0@@ -114,6 +114,20 @@ DefinitionBlock ( } }
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 126
Quoted 10 lines
hw/i386/q35-acpi-dsdt.dsl +10
-0+/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) // RCBA
Indent a bit more please.
Quoted 19 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"tests/acpi-test-data/q35/DSDT binary +0
-0Signature · 2 lines
-- 2.1.0
Re: [Qemu-devel] [PATCH v3 3/3] tests: add testcase for TCO watchdog emulation
In reply to Paulo AlcantaraQuoted 6 lines · Paulo Alcantara
v1 -> v2:
* some cleanup
* add test forTCO_LOCKbit
v2 -> v3:
* add tests for TCO control & status bits
* fix check ofSECOND_TO_STSbit (it's set inTCO2_STSreg)
Changelog after -- please.
Pls add a bit of description here.
Quoted 62 lines
Signed-off-by Paulo Alcantara <[email protected]>--- tests/Makefile | 2 + tests/tco-test.c | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 477 insertions(+) create mode 100644 tests/tco-test.ctests/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 +29
-0@@ -0,0 +1,475 @@ +/* +* QEMU ICH9 TCO emulation tests +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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 <glib.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "libqtest.h"
tests/tco-test.c line 39
Quoted 10 lines
tests/tco-test.c new file +10
-0+#include "libqos/pci.h" +#include "libqos/pci-pc.h" +#include "hw/pci/pci_regs.h" +#include "hw/i386/ich9.h" +#include "hw/acpi/ich9.h" +#include "hw/acpi/tco.h" + +#define PM_IO_BASE_ADDR 0xb000 +#define RCBA_BASE_ADDR 0xfed1c000 +
This is duplicated in DSL. Add a macro?
Quoted 438 lines
tests/tco-test.c new file +436
-0+enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +#define TCO_SECS_TO_TICKS (secs) (((secs) * 10) / 6) +#define TCO_TICKS_TO_SECS (ticks) (((ticks) * 6) / 10) + +typedef struct { +const char *args; +QPCIDevice *dev; +void *lpc_base; +void *tco_io_base; +}TestData ; + +static void test_init (TestData *d) +{ +QPCIBus *bus; +QTestState *qs; +char *s; + + s =g_strdup_printf ("-machine q35 %s" , !d->args ?"" : d->args); + qs =qtest_start (s); +qtest_irq_intercept_in (qs,"ioapic" ); +g_free (s); + + bus =qpci_init_pc (); + d->dev =qpci_device_find (bus,QPCI_DEVFN (0x1f ,0x00 )); +g_assert (d->dev !=NULL ); + +/* map PCI-to-LPC bridge interface BAR */ + d->lpc_base =qpci_iomap (d->dev,0 ,NULL ); + +qpci_device_enable (d->dev); + +g_assert (d->lpc_base !=NULL ); + +/* set ACPI PM I/O space base address */ +qpci_config_writel (d->dev, (uintptr_t )d->lpc_base +ICH9_LPC_PMBASE , +PM_IO_BASE_ADDR |0x1 ); +/* enable ACPI I/O */ +qpci_config_writeb (d->dev, (uintptr_t )d->lpc_base +ICH9_LPC_ACPI_CTRL , +0x80 ); +/* set Root Complex BAR */ +qpci_config_writel (d->dev, (uintptr_t )d->lpc_base +ICH9_LPC_RCBA , +RCBA_BASE_ADDR |0x1 ); + + d->tco_io_base = (void *)((uintptr_t )PM_IO_BASE_ADDR +0x60 ); +} + +static void stop_tco (const TestData *d) +{ +uint32_t val; + + val =qpci_io_readw (d->dev, d->tco_io_base +TCO1_CNT ); + val |=TCO_TMR_HLT ; +qpci_io_writew (d->dev, d->tco_io_base +TCO1_CNT , val); +} + +static void start_tco (const TestData *d) +{ +uint32_t val; + + val =qpci_io_readw (d->dev, d->tco_io_base +TCO1_CNT ); + val &= ~TCO_TMR_HLT ; +qpci_io_writew (d->dev, d->tco_io_base +TCO1_CNT , val); +} + +static void load_tco (const TestData *d) +{ +qpci_io_writew (d->dev, d->tco_io_base +TCO_RLD ,4 ); +} + +static void set_tco_timeout (const TestData *d,uint16_t ticks) +{ +qpci_io_writew (d->dev, d->tco_io_base +TCO_TMR , ticks); +} + +static void clear_tco_status (const TestData *d) +{ +qpci_io_writew (d->dev, d->tco_io_base +TCO1_STS ,0x0008 ); +qpci_io_writew (d->dev, d->tco_io_base +TCO2_STS ,0x0002 ); +qpci_io_writew (d->dev, d->tco_io_base +TCO2_STS ,0x0004 ); +} + +static void reset_on_second_timeout (bool enable) +{ +uint32_t val; + + val =readl (RCBA_BASE_ADDR +ICH9_LPC_RCBA_GCS ); +if (enable) { + val &= ~ICH9_LPC_RCBA_GCS_NO_REBOOT ; + }else { + val |=ICH9_LPC_RCBA_GCS_NO_REBOOT ; + } +writel (RCBA_BASE_ADDR +ICH9_LPC_RCBA_GCS , val); +} + +static void test_tco_defaults (void ) +{ +TestData d; + + d.args =NULL ; +test_init (&d); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_RLD), ==, +TCO_RLD_DEFAULT ); +/* TCO_DAT_IN & TCO_DAT_OUT */ + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_DAT_IN), ==, + (TCO_DAT_OUT_DEFAULT <<8 ) |TCO_DAT_IN_DEFAULT ); +/* TCO1_STS & TCO2_STS */ + g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_base + TCO1_STS), ==, + (TCO2_STS_DEFAULT <<16 ) |TCO1_STS_DEFAULT ); +/* TCO1_CNT & TCO2_CNT */ + g_assert_cmpint(qpci_io_readl(d.dev, d.tco_io_base + TCO1_CNT), ==, + (TCO2_CNT_DEFAULT <<16 ) |TCO1_CNT_DEFAULT ); +/* TCO_MESSAGE1 & TCO_MESSAGE2 */ + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_MESSAGE1), ==, + (TCO_MESSAGE2_DEFAULT <<8 ) |TCO_MESSAGE1_DEFAULT ); + g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_base + TCO_WDCNT), ==, +TCO_WDCNT_DEFAULT ); + g_assert_cmpint(qpci_io_readb(d.dev, d.tco_io_base + SW_IRQ_GEN), ==, +SW_IRQ_GEN_DEFAULT ); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_TMR), ==, +TCO_TMR_DEFAULT ); +qtest_end (); +} + +static void test_tco_timeout (void ) +{ +TestData d; +const uint16_t ticks =TCO_SECS_TO_TICKS (4 ); +uint32_t val; +int ret; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); +clock_step (ticks *TCO_TICK_NSEC ); + +/* test first timeout */ + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==1 ); + +/* test clearing timeout bit */ + val |=TCO_TIMEOUT ; +qpci_io_writew (d.dev, d.tco_io_base +TCO1_STS , val); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==0 ); + +/* test second timeout */ +clock_step (ticks *TCO_TICK_NSEC ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==1 ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO2_STS ); + ret = val &TCO_SECOND_TO_STS ?1 :0 ; +g_assert (ret ==1 ); + +stop_tco (&d); +qtest_end (); +} + +static void test_tco_max_timeout (void ) +{ +TestData d; +const uint16_t ticks =0xffff ; +uint32_t val; +int ret; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); +clock_step (((ticks &TCO_TMR_MASK ) -1 ) *TCO_TICK_NSEC ); + + val =qpci_io_readw (d.dev, d.tco_io_base +TCO_RLD ); + g_assert_cmpint(val & TCO_RLD_MASK, ==, 1); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==0 ); +clock_step (TCO_TICK_NSEC ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val &TCO_TIMEOUT ?1 :0 ; +g_assert (ret ==1 ); + +stop_tco (&d); +qtest_end (); +} + +static QDict *get_watchdog_action (void ) +{ +QDict *ev =qmp ("" ); +QDict *data; +g_assert (!strcmp (qdict_get_str (ev,"event" ),"WATCHDOG" )); + + data =qdict_get_qdict (ev,"data" ); +QINCREF (data); +QDECREF (ev); +return data; +} + +static void test_tco_second_timeout_pause (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (32 ); +QDict *ad; + + td.args ="-watchdog-action pause" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td,TCO_SECS_TO_TICKS (16 )); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"pause" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_second_timeout_reset (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (16 ); +QDict *ad; + + td.args ="-watchdog-action reset" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td,TCO_SECS_TO_TICKS (16 )); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"reset" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_second_timeout_shutdown (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (128 ); +QDict *ad; + + td.args ="-watchdog-action shutdown" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td, ticks); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"shutdown" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_second_timeout_none (void ) +{ +TestData td; +const uint16_t ticks =TCO_SECS_TO_TICKS (256 ); +QDict *ad; + + td.args ="-watchdog-action none" ; +test_init (&td); + +stop_tco (&td); +clear_tco_status (&td); +reset_on_second_timeout (true); +set_tco_timeout (&td, ticks); +load_tco (&td); +start_tco (&td); +clock_step (ticks *TCO_TICK_NSEC *2 ); + ad =get_watchdog_action (); +g_assert (!strcmp (qdict_get_str (ad,"action" ),"none" )); +QDECREF (ad); + +stop_tco (&td); +qtest_end (); +} + +static void test_tco_ticks_counter (void ) +{ +TestData d; +uint16_t ticks =TCO_SECS_TO_TICKS (8 ); +uint16_t rld; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); + +do { + rld =qpci_io_readw (d.dev, d.tco_io_base +TCO_RLD ) &TCO_RLD_MASK ; + g_assert_cmpint(rld, ==, ticks); +clock_step (TCO_TICK_NSEC ); + ticks--; + }while (!(qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ) &TCO_TIMEOUT )); + +stop_tco (&d); +qtest_end (); +} + +static void test_tco1_control_bits (void ) +{ +TestData d; +uint16_t val; + + d.args =NULL ; +test_init (&d); + + val =TCO_LOCK ; +qpci_io_writew (d.dev, d.tco_io_base +TCO1_CNT , val); + val &= ~TCO_LOCK ; +qpci_io_writew (d.dev, d.tco_io_base +TCO1_CNT , val); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO1_CNT), ==, +TCO_LOCK ); +qtest_end (); +} + +static void test_tco1_status_bits (void ) +{ +TestData d; +uint16_t ticks =8 ; +uint16_t val; +int ret; + + d.args =NULL ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (false); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); +clock_step (ticks *TCO_TICK_NSEC ); + +qpci_io_writeb (d.dev, d.tco_io_base +TCO_DAT_IN ,0 ); +qpci_io_writeb (d.dev, d.tco_io_base +TCO_DAT_OUT ,0 ); + val =qpci_io_readw (d.dev, d.tco_io_base +TCO1_STS ); + ret = val & (TCO_TIMEOUT |SW_TCO_SMI |TCO_INT_STS ) ?1 :0 ; +g_assert (ret ==1 ); +qpci_io_writew (d.dev, d.tco_io_base +TCO1_STS , val); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO1_STS), ==, 0); +qtest_end (); +} + +static void test_tco2_status_bits (void ) +{ +TestData d; +uint16_t ticks =8 ; +uint16_t val; +int ret; + + d.args ="-watchdog-action none" ; +test_init (&d); + +stop_tco (&d); +clear_tco_status (&d); +reset_on_second_timeout (true); +set_tco_timeout (&d, ticks); +load_tco (&d); +start_tco (&d); +clock_step (ticks *TCO_TICK_NSEC *2 ); + + val =qpci_io_readw (d.dev, d.tco_io_base +TCO2_STS ); + ret = val & (TCO_SECOND_TO_STS |TCO_BOOT_STS ) ?1 :0 ; +g_assert (ret ==1 ); +qpci_io_writew (d.dev, d.tco_io_base +TCO2_STS , val); + g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO2_STS), ==, 0); +qtest_end (); +} + +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); + +qtest_add_func ("tco/defaults" , test_tco_defaults); +qtest_add_func ("tco/timeout/no_action" , test_tco_timeout); +qtest_add_func ("tco/timeout/no_action/max" , test_tco_max_timeout); +qtest_add_func ("tco/second_timeout/pause" , test_tco_second_timeout_pause); +qtest_add_func ("tco/second_timeout/reset" , test_tco_second_timeout_reset); +qtest_add_func ("tco/second_timeout/shutdown" , + test_tco_second_timeout_shutdown); +qtest_add_func ("tco/second_timeout/none" , test_tco_second_timeout_none); +qtest_add_func ("tco/counter" , test_tco_ticks_counter); +qtest_add_func ("tco/tco1_control/bits" , test_tco1_control_bits); +qtest_add_func ("tco/tco1_status/bits" , test_tco1_status_bits); +qtest_add_func ("tco/tco2_status/bits" , test_tco2_status_bits); +return g_test_run (); +}Signature · 1 line
2.1.0
Quoted 22 lines · On Wed, 17 Jun 2015 15:27:53 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.Quoted 7 lines
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* setSECOND_TO_STSandBOOT_STSbits inTCO2_STSinstead
* improve handling ofTCO_LOCKbit inTCO1_CNTregister
Quoted 1 line
changelog must come after --- so that git am ignores it.
Ok.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Paulo Alcantara <[email protected]>for some reason v3 was sent as reply to v2.
Don't do that please.
Indeed. Sorry about that.
Quoted 134 lines
Quoted 134 lines
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 59 ++++++++++++ hw/acpi/tco.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/isa/lpc_ich9.c | 10 ++ include/hw/acpi/ich9.h | 4 + include/hw/acpi/tco.h | 98 +++++++++++++++++++ include/hw/i386/ich9.h | 8 ++ 7 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.hhw/acpi/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.otco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.ohw/acpi/ich9.c +4
-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 */
hw/acpi/ich9.c +44
-0+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);@@ -157,6 +188,24 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_tco (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return s->tco_regs.use_tco; +} + +static const VMStateDescription vmstate_tco_io_state = { + .name ="ich9_pm/tco" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_STRUCT (tco_regs, ICH9LPCPMRegs,1 , vmstate_tco_io_sts, + TCOIORegs), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_ich9_pm = { .name ="ich9_pm" ,.version_id = 1,hw/acpi/ich9.c +8
-0@@ -179,6 +228,10 @@ const VMStateDescription vmstate_ich9_pm = { .vmsd = &vmstate_memhp_state, .needed = vmstate_test_use_memhp, }, + { + .vmsd = &vmstate_tco_io_state, + .needed = vmstate_test_use_tco, + }, VMSTATE_END_OF_LIST() } };@@ -230,6 +283,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;
Quoted 8 lines
hw/acpi/ich9.c void ich9_pm_add_properties(Object *obj, · line 418
Quoted 5 lines
hw/acpi/ich9.c +1
-0@@ -357,6 +415,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) pm->disable_s3 = 0; pm->disable_s4 =0 ; pm->s4_val =2 ; + pm->tco_regs.use_tco = true;Would be safer to add a property, and not to enable this for old machine types.
This use_tco field is *really* confusing. My initial idea of using this field was to determine whether migrate TCO registers or not, but now that doesn't make sense at all. On Q35 machine type all TCO registers should be migrated and initialised.
Since this is ICH9-specific code, doesn't this mean other machine types (e.g. i440FX) wouldn't be supported? would we need to add a property to it yet?
Quoted 103 lines
Quoted 103 lines
hw/acpi/ich9.c +0
-0object_property_add_uint32_ptr (obj,ACPI_PM_PROP_PM_IO_BASE , &pm->pm_io_base, errp);hw/acpi/tco.c new file +6
-0@@ -0,0 +1,254 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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.
+ */hw/acpi/tco.c new file +50
-0+#include "qemu-common.h" +#include "sysemu/watchdog.h" +#include "hw/i386/ich9.h" + +#include "hw/acpi/tco.h" + +//#define DEBUG + +#ifdef DEBUG +#define TCO_DEBUG (fmt, ...) \ + do { \ + fprintf(stderr, "%s "fmt, __func__, ## __VA_ARGS__); \ + } while (0) +#else +#define TCO_DEBUG (fmt, ...) do { } while (0) +#endif + +enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +static inline void tco_timer_reload (TCOIORegs *tr) +{ + tr->expire_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + ((int64_t )(tr->tco.tmr &TCO_TMR_MASK ) *TCO_TICK_NSEC ); +timer_mod (tr->tco_timer, tr->expire_time); +} + +static inline void tco_timer_stop (TCOIORegs *tr) +{ + tr->expire_time =-1 ; +} + +static void tco_timer_expired (void *opaque) +{ +TCOIORegs *tr = opaque; +ICH9LPCPMRegs *pm =container_of (tr, ICH9LPCPMRegs, tco_regs); +ICH9LPCState *lpc =container_of (pm, ICH9LPCState, pm); + uint32_t gcs = pci_get_long(lpc->chip_config +
ICH9_LPC_RCBA_GCS); +hw/acpi/tco.c new file +7
-0+ tr->tco.rld =0 ; + tr->tco.sts1 |=TCO_TIMEOUT ; +if (++tr->timeouts_no ==2 ) { + tr->tco.sts2 |=TCO_SECOND_TO_STS ; + tr->tco.sts2 |=TCO_BOOT_STS ; + tr->timeouts_no =0 ; +
Quoted 8 lines
hw/acpi/tco.c line 85
Quoted 4 lines
hw/acpi/tco.c new file +4
-0+if (!(gcs &ICH9_LPC_RCBA_GCS_NO_REBOOT )) { +watchdog_perform_action (); +tco_timer_stop (tr); +return ;So this is a virtual clock - not running when VM is not running. Doesn't this mean if you stop VM for a while, it's almost sure to fire when you resume?
Yes, it will.
Quoted 3 lines
Maybe it's a useful feature, but maybe it's best to keep it off by default?
The timer is already halted by default. So you might ask me why it's halted if TCO_TMR_HLT bit is 0 by default (e.g. timer running)? It will only start counting down if someone reloads it through TCO_RLD register.
I would just keep it running when resuming VM because ICH9 spec says that it will _only_ count down in the S0 state. Although, I think it's worth mentioning that the firmware should be able to stop it (or restore its default values) while in the S3 resume path.
Quoted 153 lines
Quoted 153 lines
hw/acpi/tco.c new file +30
-0+ } + } + +if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) { +ich9_generate_smi (); + }else { +ich9_generate_nmi (); + } + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); +} + +void acpi_pm_tco_init(TCOIORegs *tr) +{ + *tr = (TCOIORegs) { + .tco = { + .rld = TCO_RLD_DEFAULT, + .din = TCO_DAT_IN_DEFAULT, + .dout = TCO_DAT_OUT_DEFAULT, + .sts1 = TCO1_STS_DEFAULT, + .sts2 = TCO2_STS_DEFAULT, + .cnt1 = TCO1_CNT_DEFAULT, + .cnt2 = TCO2_CNT_DEFAULT, + .msg1 = TCO_MESSAGE1_DEFAULT, + .msg2 = TCO_MESSAGE2_DEFAULT, + .wdcnt = TCO_WDCNT_DEFAULT, + .tmr = TCO_TMR_DEFAULT, + }, + .sw_irq_gen = SW_IRQ_GEN_DEFAULT, + .tco_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
tco_timer_expired, tr),hw/acpi/tco.c new file +20
-0+ .expire_time = -1, + .timeouts_no = 0, + }; +} + +/* NOTE: values of 0 or 1 will be ignored by ICH */ +static inline int can_start_tco_timer (TCOIORegs *tr) +{ +return !(tr->tco.cnt1 &TCO_TMR_HLT ) && tr->tco.tmr >1 ; +} + +uint32_t acpi_pm_tco_ioport_readw (TCOIORegs *tr,uint32_t addr) +{ +uint16_t rld; + +switch (addr) { +case TCO_RLD : +if (tr->expire_time !=-1 ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + int64_t elapsed = (tr->expire_time - now) /
TCO_TICK_NSEC;
+ rld = (uint16_t)elapsed | (tr->tco.rld&
~TCO_RLD_MASK);hw/acpi/tco.c new file +31
-0+ }else { + rld = tr->tco.rld; + } +return rld; +case TCO_DAT_IN : +return tr->tco.din; +case TCO_DAT_OUT : +return tr->tco.dout; +case TCO1_STS : +return tr->tco.sts1; +case TCO2_STS : +return tr->tco.sts2; +case TCO1_CNT : +return tr->tco.cnt1; +case TCO2_CNT : +return tr->tco.cnt2; +case TCO_MESSAGE1 : +return tr->tco.msg1; +case TCO_MESSAGE2 : +return tr->tco.msg2; +case TCO_WDCNT : +return tr->tco.wdcnt; +case TCO_TMR : +return tr->tco.tmr; +case SW_IRQ_GEN : +return tr->sw_irq_gen; + } +return 0 ; +} + +void acpi_pm_tco_ioport_writew(TCOIORegs *tr, uint32_t addr,
uint32_tval) +{hw/acpi/tco.c new file +19
-0+switch (addr) { +case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val; + } +break ; +case TCO_DAT_IN : + tr->tco.din = val; + tr->tco.sts1 |=SW_TCO_SMI ; +ich9_generate_smi (); +break ; +case TCO_DAT_OUT : + tr->tco.dout = val; + tr->tco.sts1 |=TCO_INT_STS ; +/* TODO: cause an interrupt, as selected by the
TCO_INT_SELbits */hw/acpi/tco.c new file +11
-0+break ; +case TCO1_STS : + tr->tco.sts1 = val &TCO1_STS_MASK ; +break ; +case TCO2_STS : + tr->tco.sts2 = val &TCO2_STS_MASK ; +break ; +case TCO1_CNT : + val &=TCO1_CNT_MASK ; +/* +* once TCO_LOCK bit is set, it can not be cleared by software. a reset
+ * is required to change this bit from 1 to 0 -- it
defaults to 0.hw/acpi/tco.c new file +32
-0+*/ + tr->tco.cnt1 = val | (tr->tco.cnt1 &TCO_LOCK ); +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { +tco_timer_stop (tr); + } +break ; +case TCO2_CNT : + tr->tco.cnt2 = val; +break ; +case TCO_MESSAGE1 : + tr->tco.msg1 = val; +break ; +case TCO_MESSAGE2 : + tr->tco.msg2 = val; +break ; +case TCO_WDCNT : + tr->tco.wdcnt = val; +break ; +case TCO_TMR : + tr->tco.tmr = val; +break ; +case SW_IRQ_GEN : + tr->sw_irq_gen = val; +break ; + } +} + +const VMStateDescription vmstate_tco_io_sts = { + .name ="tco io device status" ,
Quoted 8 lines
hw/acpi/tco.c line 236
Quoted 5 lines
hw/acpi/tco.c new file +5
-0+ .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField []) { +VMSTATE_BOOL (use_tco, TCOIORegs),So this field is only migrated if it is true.
Doesn't seem to make sense.
Yeah, indeed. I should remove this field and always migrate TCO registers on Q35 machine type.
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Re: [Qemu-devel] [PATCH v3 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Michael S. TsirkinQuoted 6 lines · On Wed, 17 Jun 2015 15:33:07 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Paulo Alcantara
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBchangelog should come after ---.
Ok.
Quoted 2 lines
An empty commit log is too terse I think.
Could you quote spec in the changelog?
Yes, sure.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Paulo Alcantara <[email protected]>--- hw/i386/q35-acpi-dsdt.dsl | 14 ++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 2 files changed, 14 insertions(+)hw/i386/q35-acpi-dsdt.dsl +0
-0@@ -114,6 +114,20 @@ DefinitionBlock ( } }
Quoted 13 lines
Quoted 11 lines
hw/i386/q35-acpi-dsdt.dsl +10
-0+/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) //RCBA
Indent a bit more please.
Ok.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Re: [Qemu-devel] [PATCH v3 3/3] tests: add testcase for TCO watchdog emulation
In reply to Michael S. TsirkinQuoted 10 lines · On Wed, 17 Jun 2015 15:37:49 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Paulo Alcantara
v1 -> v2:
* some cleanup
* add test forTCO_LOCKbit
v2 -> v3:
* add tests for TCO control & status bits
* fix check ofSECOND_TO_STSbit (it's set inTCO2_STSreg)Changelog after -- please.
Pls add a bit of description here.
Ok.
Quoted 79 lines
Quoted 79 lines
Signed-off-by Paulo Alcantara <[email protected]>--- tests/Makefile | 2 + tests/tco-test.c | 475+++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 477 insertions(+) create mode 100644
tests/tco-test.ctests/Makefile +1
-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.otests/vmxnet3-test$(EXESUF):tests/vmxnet3-test.otests/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.otests/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) diff --gita/tests/tco-test.cb/tests/tco-test.cnew file mode 100644 index 0000000..b9acf43tests/tco-test.c new file +6
-0@@ -0,0 +1,475 @@ +/* +* QEMU ICH9 TCO emulation tests +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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.
+ */tests/tco-test.c new file +10
-0+#include <glib.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "libqtest.h" +#include "libqos/pci.h" +#include "libqos/pci-pc.h" +#include "hw/pci/pci_regs.h" +#include "hw/i386/ich9.h"
Quoted 8 lines
tests/tco-test.c line 39
Quoted 6 lines
tests/tco-test.c new file +6
-0+#include "hw/acpi/ich9.h" +#include "hw/acpi/tco.h" + +#define PM_IO_BASE_ADDR 0xb000 +#define RCBA_BASE_ADDR 0xfed1c000 +This is duplicated in DSL. Add a macro?
Ok. I will add a macro for RCBA address.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
PATCH v4 2/3 target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraThis block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRB
v2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in _CRS() method declaration
* create hw/i386/ich9-cc.h for chipset configuration register values and use them in ASL
--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.h
hw/i386/q35-acpi-dsdt.dsl +16 -0
@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"
include/hw/i386/ich9-cc.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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. +*/ + +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000 +#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */
tests/acpi-test-data/q35/DSDT binary +0 -0
Signature · 1 line
2.1.0
PATCH v4 1/3 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* set SECOND_TO_STS and BOOT_STS bits in TCO2_STS instead
* improve handling of TCO_LOCK bit in TCO1_CNT register
v3 -> v4:
* fix some conflicts in hw/acpi/ich9.c after rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO support
on pc-q35-2.4 and later --- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 +++++++++- hw/acpi/tco.c | 279 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 15 ++- include/hw/acpi/ich9.h | 7 +- include/hw/acpi/tco.h | 98 +++++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 10 +- include/hw/i386/pc.h | 1 + 10 files changed, 466 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +54 -1
105 lines not on this page · raw message
hw/acpi/tco.c new file +279 -0
279 lines not on this page · raw message
hw/i386/pc_q35.c +3 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }
@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 ); }
hw/isa/lpc_ich9.c +13 -2
@@ -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] &
@@ -357,11 +367,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev); }
include/hw/acpi/ich9.h +6 -1
@@ -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_en_wmask;
@@ -54,9 +56,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;
include/hw/acpi/tco.h new file +98 -0
98 lines not on this page · raw message
include/hw/boards.h +2 -1
@@ -99,7 +99,8 @@ struct MachineClass { no_floppy:1, no_cdrom:1, no_sdcard:1, - has_dynamic_sysbus:1; + has_dynamic_sysbus:1, + no_tco:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
include/hw/i386/ich9.h +9 -1
@@ -17,9 +17,12 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool enable_tco);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"
@@ -162,6 +165,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
@@ -186,7 +191,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
include/hw/i386/pc.h +1 -0
@@ -89,6 +89,7 @@ typedef struct PcPciInfo {#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len" +#define ACPI_PM_PROP_TCO_ENABLED "enable_tco"struct PcGuestInfo {bool isapc_ram_fw;
Signature · 1 line
2.1.0
PATCH v4 3/3 tests: add testcase for TCO watchdog emulation
This patch adds a testcase that covers the following:
1) TCO default values
2) first and second TCO timeout
3) watch and validate ticks counter through TCO_RLD register
4) maximum supported TCO timeout (0x3ff)
5) watchdog actions (pause/reset/shutdown/none) upon second TCO timeout
6) set and get of TCO control and status bits
---
v1 -> v2:
* some cleanup
* add test for TCO_LOCK bit
v2 -> v3:
* add tests for TCO control & status bits
* fix check of SECOND_TO_STS bit (it's set in TCO2_STS reg)
v3 -> v4:
* add more description to commit log
* use RCBA_BASE_ADDR macro defintion from hw/i386/ich9-cc.h instead
--- tests/Makefile | 2 + tests/tco-test.c | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 477 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)
@@ -367,6 +368,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 +475 -0
475 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 18 lines · Paulo Alcantara
hw/acpi/tco.c new file +12
-0@@ -0,0 +1,279 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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: +*
hw/acpi/tco.c line 22
Quoted 10 lines
hw/acpi/tco.c new file +10
-0+* 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.
Please make new original code GPLv2+. If you have copied from another file, then you should follow that file's licensing, but in that case you should also acknowledge the original copyright.
Quoted 1 line
hw/acpi/tco.c new file +1
-0+*/
Re: [Qemu-devel] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 8 lines · Paulo Alcantara
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>
Just to make sure, the device is in fact only functional if it's enabled using the property, correct?
In that case please add it conditionally to the SSDT instead.
Quoted 95 lines
---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +31
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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. +*/ + +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000 +#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ tests/acpi-test-data/q35/DSDT binary +0
-0Signature · 2 lines
-- 2.1.0
Quoted 9 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.
Quoted 5 lines
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.Signed-off-by Paulo Alcantara <[email protected]>
Given that support is known to be partial, would it make sense to keep it disabled by default for 2.4?
This way in 2.5 we won't need to add more flags to stay bug compatible.
Quoted 711 lines
---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonziniv2 -> v3:
* setSECOND_TO_STSandBOOT_STSbits inTCO2_STSinstead
* improve handling ofTCO_LOCKbit inTCO1_CNTregisterv3 -> v4:
* fix some conflicts inhw/acpi/ich9.cafter rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO supporton pc-q35-2.4 and later --- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 +++++++++- hw/acpi/tco.c | 279 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 15 ++- include/hw/acpi/ich9.h | 7 +- include/hw/acpi/tco.h | 98 +++++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 10 +- include/hw/i386/pc.h | 1 + 10 files changed, 466 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.hhw/acpi/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.ohw/acpi/ich9.c +54
-1@@ -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,16 @@ static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val, unsigned width) {ICH9LPCPMRegs *pm = opaque; +TCOIORegs *tr = &pm->tco_regs; +uint64_t tco_en; +switch (addr) {case 0 : + tco_en = pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ; +/* once TCO_LOCK bit is set, TCO_EN bit cannot be overwritten */ +if (tr->tco.cnt1 &TCO_LOCK ) { + val = (val & ~ICH9_PMIO_SMI_EN_TCO_EN ) | tco_en; + } pm->smi_en &= ~pm->smi_en_wmask; pm->smi_en |= (val & pm->smi_en_wmask);break ;@@ -159,6 +168,25 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_tco (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return s->enable_tco; +} + +static const VMStateDescription vmstate_tco_io_state = { + .name ="ich9_pm/tco" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_tco, + .fields = (VMStateField []) { +VMSTATE_STRUCT (tco_regs, ICH9LPCPMRegs,1 , vmstate_tco_io_sts, + TCOIORegs), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_ich9_pm = { .name ="ich9_pm" , .version_id =1 ,@@ -179,6 +207,10 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state,NULL + }, + .subsections = (const VMStateDescription *[]) { + &vmstate_tco_io_state, +NULL } };@@ -209,7 +241,7 @@ static void pm_powerdown_req(Notifier *n, void *opaque)acpi_pm1_evt_power_down (&pm->acpi_regs); } -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq) {memory_region_init (&pm->io,OBJECT (lpc_pci),"ich9-pm" ,ICH9_PMIO_SIZE );@@ -231,6 +263,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); + pm->enable_tco = enable_tco; +if (pm->enable_tco) { +acpi_pm_tco_init (&pm->tco_regs, &pm->io); + } + pm->irq = sci_irq;qemu_register_reset (pm_reset, pm); pm->powerdown_notifier.notify = pm_powerdown_req;@@ -351,6 +388,18 @@ out:error_propagate (errp, local_err); } +static bool ich9_pm_get_enable_tco (Object *obj,Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); +return s->pm.enable_tco; +} + +static void ich9_pm_set_enable_tco (Object *obj,bool value,Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); + s->pm.enable_tco = value; +} +void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm,Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ;@@ -382,6 +431,10 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) ich9_pm_get_s4_val, ich9_pm_set_s4_val, NULL, pm, NULL); +object_property_add_bool (obj,ACPI_PM_PROP_TCO_ENABLED , + ich9_pm_get_enable_tco, + ich9_pm_set_enable_tco, +NULL ); }void ich9_pm_device_plug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp)hw/acpi/tco.c new file +279
-0@@ -0,0 +1,279 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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-common.h" +#include "sysemu/watchdog.h" +#include "hw/i386/ich9.h" + +#include "hw/acpi/tco.h" + +//#define DEBUG + +#ifdef DEBUG +#define TCO_DEBUG (fmt, ...) \ + do { \ + fprintf(stderr, "%s "fmt, __func__, ## __VA_ARGS__); \ + } while (0) +#else +#define TCO_DEBUG (fmt, ...) do { } while (0) +#endif + +enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +static inline void tco_timer_reload (TCOIORegs *tr) +{ + tr->expire_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + ((int64_t )(tr->tco.tmr &TCO_TMR_MASK ) *TCO_TICK_NSEC ); +timer_mod (tr->tco_timer, tr->expire_time); +} + +static inline void tco_timer_stop (TCOIORegs *tr) +{ + tr->expire_time =-1 ; +} + +static void tco_timer_expired (void *opaque) +{ +TCOIORegs *tr = opaque; +ICH9LPCPMRegs *pm =container_of (tr, ICH9LPCPMRegs, tco_regs); +ICH9LPCState *lpc =container_of (pm, ICH9LPCState, pm); +uint32_t gcs =pci_get_long (lpc->chip_config +ICH9_LPC_RCBA_GCS ); + + tr->tco.rld =0 ; + tr->tco.sts1 |=TCO_TIMEOUT ; +if (++tr->timeouts_no ==2 ) { + tr->tco.sts2 |=TCO_SECOND_TO_STS ; + tr->tco.sts2 |=TCO_BOOT_STS ; + tr->timeouts_no =0 ; + +if (!(gcs &ICH9_LPC_RCBA_GCS_NO_REBOOT )) { +watchdog_perform_action (); +tco_timer_stop (tr); +return ; + } + } + +if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) { +ich9_generate_smi (); + }else { +ich9_generate_nmi (); + } + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); +} + +/* NOTE: values of 0 or 1 will be ignored by ICH */ +static inline int can_start_tco_timer (TCOIORegs *tr) +{ +return !(tr->tco.cnt1 &TCO_TMR_HLT ) && tr->tco.tmr >1 ; +} + +static uint32_t tco_ioport_readw (TCOIORegs *tr,uint32_t addr) +{ +uint16_t rld; + +switch (addr) { +case TCO_RLD : +if (tr->expire_time !=-1 ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +int64_t elapsed = (tr->expire_time - now) /TCO_TICK_NSEC ; + rld = (uint16_t )elapsed | (tr->tco.rld & ~TCO_RLD_MASK ); + }else { + rld = tr->tco.rld; + } +return rld; +case TCO_DAT_IN : +return tr->tco.din; +case TCO_DAT_OUT : +return tr->tco.dout; +case TCO1_STS : +return tr->tco.sts1; +case TCO2_STS : +return tr->tco.sts2; +case TCO1_CNT : +return tr->tco.cnt1; +case TCO2_CNT : +return tr->tco.cnt2; +case TCO_MESSAGE1 : +return tr->tco.msg1; +case TCO_MESSAGE2 : +return tr->tco.msg2; +case TCO_WDCNT : +return tr->tco.wdcnt; +case TCO_TMR : +return tr->tco.tmr; +case SW_IRQ_GEN : +return tr->sw_irq_gen; + } +return 0 ; +} + +static void tco_ioport_writew (TCOIORegs *tr,uint32_t addr,uint32_t val) +{ +switch (addr) { +case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val; + } +break ; +case TCO_DAT_IN : + tr->tco.din = val; + tr->tco.sts1 |=SW_TCO_SMI ; +ich9_generate_smi (); +break ; +case TCO_DAT_OUT : + tr->tco.dout = val; + tr->tco.sts1 |=TCO_INT_STS ; +/* TODO: cause an interrupt, as selected by the TCO_INT_SEL bits */ +break ; +case TCO1_STS : + tr->tco.sts1 = val &TCO1_STS_MASK ; +break ; +case TCO2_STS : + tr->tco.sts2 = val &TCO2_STS_MASK ; +break ; +case TCO1_CNT : + val &=TCO1_CNT_MASK ; +/* +* once TCO_LOCK bit is set, it can not be cleared by software. a reset +* is required to change this bit from 1 to 0 -- it defaults to 0. +*/ + tr->tco.cnt1 = val | (tr->tco.cnt1 &TCO_LOCK ); +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { +tco_timer_stop (tr); + } +break ; +case TCO2_CNT : + tr->tco.cnt2 = val; +break ; +case TCO_MESSAGE1 : + tr->tco.msg1 = val; +break ; +case TCO_MESSAGE2 : + tr->tco.msg2 = val; +break ; +case TCO_WDCNT : + tr->tco.wdcnt = val; +break ; +case TCO_TMR : + tr->tco.tmr = val; +break ; +case SW_IRQ_GEN : + tr->sw_irq_gen = val; +break ; + } +} + +static uint64_t tco_io_readw (void *opaque,hwaddr addr,unsigned width) +{ +TCOIORegs *tr = opaque; +return tco_ioport_readw (tr, addr); +} + +static void tco_io_writew (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +TCOIORegs *tr = opaque; +tco_ioport_writew (tr, addr, val); +} + +static const MemoryRegionOps tco_io_ops = { + .read = tco_io_readw, + .write = tco_io_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 acpi_pm_tco_init (TCOIORegs *tr,MemoryRegion *parent) +{ + *tr = (TCOIORegs ) { + .tco = { + .rld =TCO_RLD_DEFAULT , + .din =TCO_DAT_IN_DEFAULT , + .dout =TCO_DAT_OUT_DEFAULT , + .sts1 =TCO1_STS_DEFAULT , + .sts2 =TCO2_STS_DEFAULT , + .cnt1 =TCO1_CNT_DEFAULT , + .cnt2 =TCO2_CNT_DEFAULT , + .msg1 =TCO_MESSAGE1_DEFAULT , + .msg2 =TCO_MESSAGE2_DEFAULT , + .wdcnt =TCO_WDCNT_DEFAULT , + .tmr =TCO_TMR_DEFAULT , + }, + .sw_irq_gen =SW_IRQ_GEN_DEFAULT , + .tco_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , tco_timer_expired, tr), + .expire_time =-1 , + .timeouts_no =0 , + }; +memory_region_init_io (&tr->io,memory_region_owner (parent), + &tco_io_ops, tr,"sm-tco" ,ICH9_PMIO_TCO_LEN ); +memory_region_add_subregion (parent,ICH9_PMIO_TCO_RLD , &tr->io); +} + +const VMStateDescription vmstate_tco_io_sts = { + .name ="tco io device status" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT16 (tco.rld, TCOIORegs), +VMSTATE_UINT8 (tco.din, TCOIORegs), +VMSTATE_UINT8 (tco.dout, TCOIORegs), +VMSTATE_UINT16 (tco.sts1, TCOIORegs), +VMSTATE_UINT16 (tco.sts2, TCOIORegs), +VMSTATE_UINT16 (tco.cnt1, TCOIORegs), +VMSTATE_UINT16 (tco.cnt2, TCOIORegs), +VMSTATE_UINT8 (tco.msg1, TCOIORegs), +VMSTATE_UINT8 (tco.msg2, TCOIORegs), +VMSTATE_UINT8 (tco.wdcnt, TCOIORegs), +VMSTATE_UINT16 (tco.tmr, TCOIORegs), +VMSTATE_UINT8 (sw_irq_gen, TCOIORegs), +VMSTATE_TIMER_PTR (tco_timer, TCOIORegs), +VMSTATE_INT64 (expire_time, TCOIORegs), +VMSTATE_UINT8 (timeouts_no, TCOIORegs), +VMSTATE_END_OF_LIST () + } +};hw/i386/pc_q35.c +3
-1@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 ); }hw/isa/lpc_ich9.c +13
-2@@ -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] &@@ -357,11 +367,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev); }include/hw/acpi/ich9.h +6
-1@@ -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_en_wmask;@@ -54,9 +56,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;include/hw/acpi/tco.h new file +98
-0@@ -0,0 +1,98 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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. +*/ +#ifndef HW_ACPI_TCO_H +#define HW_ACPI_TCO_H + +#include "qemu/typedefs.h" +#include "qemu-common.h" + +/* As per ICH9 spec, the internal timer has an error of ~0.6s on every tick */ +#define TCO_TICK_NSEC 600000000LL + +/* TCO I/O register offsets */ +enum { +TCO_RLD =0x00 , +TCO_DAT_IN =0x02 , +TCO_DAT_OUT =0x03 , +TCO1_STS =0x04 , +TCO2_STS =0x06 , +TCO1_CNT =0x08 , +TCO2_CNT =0x0a , +TCO_MESSAGE1 =0x0c , +TCO_MESSAGE2 =0x0d , +TCO_WDCNT =0x0e , +SW_IRQ_GEN =0x10 , +TCO_TMR =0x12 , +}; + +/* TCO I/O register control/status bits */ +enum { +SW_TCO_SMI =1 <<1 , +TCO_INT_STS =1 <<2 , +TCO_LOCK =1 <<12 , +TCO_TMR_HLT =1 <<11 , +TCO_TIMEOUT =1 <<3 , +TCO_SECOND_TO_STS =1 <<1 , +TCO_BOOT_STS =1 <<2 , +}; + +/* TCO I/O registers mask bits */ +enum { +TCO_RLD_MASK =0x3ff , +TCO1_STS_MASK =0xe870 , +TCO2_STS_MASK =0xfff8 , +TCO1_CNT_MASK =0xfeff , +TCO_TMR_MASK =0x3ff , +}; + +typedef struct TCOIORegs { +bool use_tco; +struct { +uint16_t rld; +uint8_t din; +uint8_t dout; +uint16_t sts1; +uint16_t sts2; +uint16_t cnt1; +uint16_t cnt2; +uint8_t msg1; +uint8_t msg2; +uint8_t wdcnt; +uint16_t tmr; + } tco; +uint8_t sw_irq_gen; + +QEMUTimer *tco_timer; +int64_t expire_time; +uint8_t timeouts_no; + +MemoryRegion io; +}TCOIORegs ; + +/* tco.c */ +void acpi_pm_tco_init (TCOIORegs *tr,MemoryRegion *parent); + +extern const VMStateDescription vmstate_tco_io_sts; + +#endif /* HW_ACPI_TCO_H */ include/hw/boards.h +2
-1@@ -99,7 +99,8 @@ struct MachineClass { no_floppy:1, no_cdrom:1, no_sdcard:1, - has_dynamic_sysbus:1; + has_dynamic_sysbus:1, + no_tco:1;int is_default;const char *default_machine_opts;const char *default_boot_order;include/hw/i386/ich9.h +9
-1@@ -17,9 +17,12 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool enable_tco);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"@@ -162,6 +165,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@@ -186,7 +191,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 0x2include/hw/i386/pc.h +1
-0@@ -89,6 +89,7 @@ typedef struct PcPciInfo {#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len" +#define ACPI_PM_PROP_TCO_ENABLED "enable_tco"struct PcGuestInfo {bool isapc_ram_fw;Signature · 1 line
2.1.0
Quoted 2 lines · Michael S. Tsirkin
Given that support is known to be partial, would it make sense to keep it disabled by default for 2.4?
What is partial about it? In fact, considering that q35 behavior is still experimental it makes no sense to even make it conditional. We discussed this on IRC and I was hoping to hear you reply "sorry, I was wrong". Instead, I get this.
Michael, I'm seriously getting annoyed by this behavior. Stop scaring away contributors.
Paolo
Quoted 1 line
This way in 2.5 we won't need to add more flags to stay bug compatible.
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Michael S. Tsirkin
Given that support is known to be partial, would it make sense to keep it disabled by default for 2.4?
What is partial about it?
Ow, looks like I didn't send out the response to the patch itself. Will do.
Quoted 2 lines
In fact, considering that q35 behavior is
still experimental it makes no sense to even make it conditional.
I agree to this, though an option to disable seems useful for debugging, so I'm glad that Paulo implemented it. It's probably not strictly required to disable for old machine types, but why not.
Quoted 8 lines
We
discussed this on IRC and I was hoping to hear you reply "sorry, I was wrong". Instead, I get this.Michael, I'm seriously getting annoyed by this behavior. Stop scaring away contributors.
Paolo
Doing my best here, but I do think we need to be careful about merging things at this stage to avoid delaying the release.
Quoted 1 line
Quoted 1 line
This way in 2.5 we won't need to add more flags to stay bug compatible.
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Paulo Alcantara
hw/acpi/tco.c new file +6
-0@@ -0,0 +1,279 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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,
Quoted 8 lines
Quoted 4 lines
ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.Please make new original code GPLv2+. If you have copied from another file, then you should follow that file's licensing, but in that case you should also acknowledge the original copyright.
OK.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 35 lines · Paulo Alcantara
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 34 lines
+/*
+ * QEMU ICH9 TCO emulation
+ *
+ * Copyright (c) 2015 Paulo Alcantara <[email protected]>
+ *
+ * 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.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Please make new original code GPLv2+. If you have copied from another file, then you should follow that file's licensing, but in that case you should also acknowledge the original copyright.
OK.
Why? The only "forbidden" license for new code is GPLv2.
If you want to make things more permissive, that's accepted.
Paolo
Quoted 23 lines · Michael S. Tsirkin
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Michael S. Tsirkin
Given that support is known to be partial, would it make sense to keep it disabled by default for 2.4?
What is partial about it?
Ow, looks like I didn't send out the response to the patch itself. Will do.
Quoted 2 lines
In fact, considering that q35 behavior is
still experimental it makes no sense to even make it conditional.I agree to this, though an option to disable seems useful for debugging, so I'm glad that Paulo implemented it. It's probably not strictly required to disable for old machine types, but why not.
Quoted 4 lines
We
discussed this on IRC and I was hoping to hear you reply "sorry, I was wrong". Instead, I get this.
Quoted 10 lines
Quoted 4 lines
Michael, I'm seriously getting annoyed by this behavior. Stop scaring away contributors.
Paolo
Doing my best here, but I do think we need to be careful about merging things at this stage to avoid delaying the release.
Quoted 2 lines
Quoted 1 line
This way in 2.5 we won't need to add more flags to stay bug
compatible.
Hi Michael,
I have seen no use other than watchdog functionality of TCO. The reason I wrote it was because I was working on an internal project that needed TCO to generate SMI so that my registered SW SMI handler in firmware would get executed. If, at that time, I had it supported on QEMU that would certainly have saved a lot of time instead testing it on bare hardware :-)
Given that, I think it's OK for me to enable it by default on pc-q35-2.4 and later.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 44 lines · Paulo Alcantara
Quoted 23 lines · Michael S. Tsirkin
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Michael S. Tsirkin
Given that support is known to be partial, would it make sense to keep it disabled by default for 2.4?
What is partial about it?
Ow, looks like I didn't send out the response to the patch itself. Will do.
Quoted 2 lines
In fact, considering that q35 behavior is
still experimental it makes no sense to even make it conditional.I agree to this, though an option to disable seems useful for debugging, so I'm glad that Paulo implemented it. It's probably not strictly required to disable for old machine types, but why not.
Quoted 4 lines
We
discussed this on IRC and I was hoping to hear you reply "sorry, I was wrong". Instead, I get this.Quoted 10 lines
Quoted 4 lines
Michael, I'm seriously getting annoyed by this behavior. Stop scaring away contributors.
Paolo
Doing my best here, but I do think we need to be careful about merging things at this stage to avoid delaying the release.
Quoted 2 lines
Quoted 1 line
This way in 2.5 we won't need to add more flags to stay bug
compatible.
Hi Michael,
I have seen no use other than watchdog functionality of TCO. The reason I wrote it was because I was working on an internal project that needed TCO to generate SMI so that my registered SW SMI handler in firmware would get executed. If, at that time, I had it supported on QEMU that would certainly have saved a lot of time instead testing it on bare hardware :-)
Quoted 6 lines
Given that, I think it's OK for me to enable it by default on pc-q35-2.4 and later.
Thanks,
Paulo
OK. Do you agree to move the ACPI bits to the SSDT, making it conditional on device being enabled?
Quoted 3 lines
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 41 lines · Paolo Bonzini
Quoted 38 lines · Paulo Alcantara
Quoted 38 lines
Quoted 38 lines
Quoted 26 lines
Quoted 26 lines
+/*
+ * QEMU ICH9 TCO emulation
+ *
+ * Copyright (c) 2015 Paulo Alcantara <[email protected]>
+ *
+ * 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 EVENTQuoted 8 lines
Quoted 8 lines
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.Please make new original code GPLv2+. If you have copied from another file, then you should follow that file's licensing, but in that case you should also acknowledge the original copyright.
Quoted 7 lines
Quoted 1 line
OK.
Why? The only "forbidden" license for new code is GPLv2.
If you want to make things more permissive, that's accepted.
Paolo
Because it's a pain if I need to move code between files with different licenses. MIT is GPL compatible but mixing licenses at random is still not a good idea.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Michael S. TsirkinQuoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Paulo Alcantara
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
Quoted 7 lines
Quoted 3 lines
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>Just to make sure, the device is in fact only functional if it's enabled using the property, correct?
In that case please add it conditionally to the SSDT instead.
No need to add it conditionally in SSDT. In fact, what this patch does is just reserving the MMIO region but the firmware and OS is free to set RCBA to whatever address it wants. For instance, the OVMF is currently setting RCBA to that address already so, if running on pc-q35-2.3 (or older), the TCO will not work either since it was not initialised (enable_tco == false).
In order to test Linux's iTCO_wdt kernel module I had to patch SeaBIOS (patch still pending, BTW) and OVMF to set RCBA BAR -- neither affected by this DSDT's change -- because the module requires RCRB to access GCS_NO_REBOOT bit flag to decide whether or not reboot the system on second TCO timeout. Otherwise the module won't be loaded up and no "/dev/watchdog" interface.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 2 lines · Michael S. Tsirkin
OK. Do you agree to move the ACPI bits to the SSDT, making it conditional on device being enabled?
Again, no. The chipset configuration registers range is always defined by the chipset, even if the TCO is not in use. It would have to be conditional on whether the RCBA is programmed by the firmware, not on whether the TCO watchdog is enabled. That's a very different patch, and it's independent of DSDT vs. SSDT.
You have to draw a line between required work and nice-to-haves that the maintainer can do himself. Otherwise, the possibilities are:
1) the contributor is scared away, and we lose a valuable feature
2) the contributor does it, but then keeps all remaining contributions in house because the first one was such a hell to go through.
Paolo
Quoted 3 lines · Michael S. Tsirkin
Because it's a pain if I need to move code between files with different licenses. MIT is GPL compatible but mixing licenses at random is still not a good idea.
This is a non-problem. How often does it happen that code is moved between files (as opposed to extracted to a new file)?
Besides, the rule you want is not enforceable because Fabrice Bellard explicitly wanted TCG-related files to be BSD.
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 3 lines · Michael S. Tsirkin
Because it's a pain if I need to move code between files with different licenses. MIT is GPL compatible but mixing licenses at random is still not a good idea.
Quoted 7 lines
This is a non-problem. How often does it happen that code is moved between files (as opposed to extracted to a new file)?
Besides, the rule you want is not enforceable because Fabrice Bellard explicitly wanted TCG-related files to be BSD.
Paolo
It's not a big deal, but it's preferable if possible. Paulo do you have a problem switching to GPLv2+?
Signature · 1 line
MST
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Paolo Bonzini
Quoted 37 lines · Paulo Alcantara
Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 36 lines
+/*
+ * QEMU ICH9 TCO emulation
+ *
+ * Copyright (c) 2015 Paulo Alcantara <[email protected]>
+ *
+ * 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.Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Please make new original code GPLv2+. If you have copied from another file, then you should follow that file's licensing, but in that case you should also acknowledge the original copyright.
OK.
Why? The only "forbidden" license for new code is GPLv2.
Quoted 7 lines
Quoted 3 lines
If you want to make things more permissive, that's accepted.
Paolo
Because it's a pain if I need to move code between files with different licenses. MIT is GPL compatible but mixing licenses at random is still not a good idea.
Seconded. New code should be GPLv2+ unless you have a really good reason for something else.
Keeping the original license in a derivative work is a really good reason (assuming it's compatible to GPLv2; if it's not, we can't use the derivative work anyway).
LGPLv2+ license for code meant to be linked into differently licensed other projects may be a good reason.
Other reasons exist.
Whatever your reason is, you need to explain it.
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Paolo Bonzini
Quoted 1 line · Michael S. Tsirkin
Because it's a pain if I need to move code between files with
different
Quoted 1 line
licenses. MIT is GPL compatible but mixing licenses at random is
still
Quoted 1 line
not a good idea.
This is a non-problem. How often does it happen that code is moved between files (as opposed to extracted to a new file)?
Quoted 7 lines
Quoted 4 lines
Besides, the rule you want is not enforceable because Fabrice Bellard explicitly wanted TCG-related files to be BSD.
Paolo
It's not a big deal, but it's preferable if possible. Paulo do you have a problem switching to GPLv2+?
Hi Michael,
No, I really don't. If it's really preferable and brings advantage to the project, then I see no problem at all.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Quoted 662 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonziniv2 -> v3:
* setSECOND_TO_STSandBOOT_STSbits inTCO2_STSinstead
* improve handling ofTCO_LOCKbit inTCO1_CNTregisterv3 -> v4:
* fix some conflicts inhw/acpi/ich9.cafter rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO supporton pc-q35-2.4 and later --- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 +++++++++- hw/acpi/tco.c | 279 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 15 ++- include/hw/acpi/ich9.h | 7 +- include/hw/acpi/tco.h | 98 +++++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 10 +- include/hw/i386/pc.h | 1 + 10 files changed, 466 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.hhw/acpi/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.ohw/acpi/ich9.c +9
-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,16 @@ static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val, unsigned width) {ICH9LPCPMRegs *pm = opaque; +TCOIORegs *tr = &pm->tco_regs; +uint64_t tco_en; +switch (addr) {case 0 : + tco_en = pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ; +/* once TCO_LOCK bit is set, TCO_EN bit cannot be overwritten */ +if (tr->tco.cnt1 &TCO_LOCK ) { + val = (val & ~ICH9_PMIO_SMI_EN_TCO_EN ) | tco_en; + } pm->smi_en &= ~pm->smi_en_wmask; pm->smi_en |= (val & pm->smi_en_wmask);break;hw/acpi/ich9.c +19
-0@@ -159,6 +168,25 @@ static const VMStateDescription vmstate_memhp_state = { } }; +static bool vmstate_test_use_tco (void *opaque) +{ +ICH9LPCPMRegs *s = opaque; +return s->enable_tco; +} + +static const VMStateDescription vmstate_tco_io_state = { + .name ="ich9_pm/tco" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .needed = vmstate_test_use_tco, + .fields = (VMStateField []) { +VMSTATE_STRUCT (tco_regs, ICH9LPCPMRegs,1 , vmstate_tco_io_sts, + TCOIORegs), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_ich9_pm = { .name ="ich9_pm" ,.version_id = 1,hw/acpi/ich9.c +5
-1@@ -179,6 +207,10 @@ const VMStateDescription vmstate_ich9_pm = { .subsections = (const VMStateDescription*[]) { &vmstate_memhp_state,NULL + }, + .subsections = (const VMStateDescription *[]) { + &vmstate_tco_io_state, +NULL } };@@ -209,7 +241,7 @@ static void pm_powerdown_req(Notifier *n, void *opaque)acpi_pm1_evt_power_down (&pm->acpi_regs); } -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq) {memory_region_init(&pm->io, OBJECT(lpc_pci), "ich9-pm",
ICH9_PMIO_SIZE);hw/acpi/ich9.c +5
-0@@ -231,6 +263,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); + pm->enable_tco = enable_tco; +if (pm->enable_tco) { +acpi_pm_tco_init (&pm->tco_regs, &pm->io); + } + pm->irq = sci_irq;qemu_register_reset (pm_reset, pm);pm->powerdown_notifier.notify = pm_powerdown_req;hw/acpi/ich9.c +16
-0@@ -351,6 +388,18 @@ out:error_propagate (errp, local_err); } +static bool ich9_pm_get_enable_tco (Object *obj,Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); +return s->pm.enable_tco; +} + +static void ich9_pm_set_enable_tco (Object *obj,bool value,Error **errp) +{ +ICH9LPCState *s =ICH9_LPC_DEVICE (obj); + s->pm.enable_tco = value; +} +void ich9_pm_add_properties (Object *obj,ICH9LPCPMRegs *pm,Error **errp) {static const uint32_t gpe0_len =ICH9_PMIO_GPE0_LEN ;@@ -382,6 +431,10 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp) ich9_pm_get_s4_val, ich9_pm_set_s4_val, NULL, pm, NULL); +object_property_add_bool (obj,ACPI_PM_PROP_TCO_ENABLED , + ich9_pm_get_enable_tco, + ich9_pm_set_enable_tco, +NULL ); }void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error
**errp)hw/acpi/tco.c new file +6
-0@@ -0,0 +1,279 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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.
+ */hw/acpi/tco.c new file +141
-0+#include "qemu-common.h" +#include "sysemu/watchdog.h" +#include "hw/i386/ich9.h" + +#include "hw/acpi/tco.h" + +//#define DEBUG + +#ifdef DEBUG +#define TCO_DEBUG (fmt, ...) \ + do { \ + fprintf(stderr, "%s "fmt, __func__, ## __VA_ARGS__); \ + } while (0) +#else +#define TCO_DEBUG (fmt, ...) do { } while (0) +#endif + +enum { +TCO_RLD_DEFAULT =0x0000 , +TCO_DAT_IN_DEFAULT =0x00 , +TCO_DAT_OUT_DEFAULT =0x00 , +TCO1_STS_DEFAULT =0x0000 , +TCO2_STS_DEFAULT =0x0000 , +TCO1_CNT_DEFAULT =0x0000 , +TCO2_CNT_DEFAULT =0x0008 , +TCO_MESSAGE1_DEFAULT =0x00 , +TCO_MESSAGE2_DEFAULT =0x00 , +TCO_WDCNT_DEFAULT =0x00 , +TCO_TMR_DEFAULT =0x0004 , +SW_IRQ_GEN_DEFAULT =0x03 , +}; + +static inline void tco_timer_reload (TCOIORegs *tr) +{ + tr->expire_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + ((int64_t )(tr->tco.tmr &TCO_TMR_MASK ) *TCO_TICK_NSEC ); +timer_mod (tr->tco_timer, tr->expire_time); +} + +static inline void tco_timer_stop (TCOIORegs *tr) +{ + tr->expire_time =-1 ; +} + +static void tco_timer_expired (void *opaque) +{ +TCOIORegs *tr = opaque; +ICH9LPCPMRegs *pm =container_of (tr, ICH9LPCPMRegs, tco_regs); +ICH9LPCState *lpc =container_of (pm, ICH9LPCState, pm); +uint32_t gcs =pci_get_long (lpc->chip_config +ICH9_LPC_RCBA_GCS ); + + tr->tco.rld =0 ; + tr->tco.sts1 |=TCO_TIMEOUT ; +if (++tr->timeouts_no ==2 ) { + tr->tco.sts2 |=TCO_SECOND_TO_STS ; + tr->tco.sts2 |=TCO_BOOT_STS ; + tr->timeouts_no =0 ; + +if (!(gcs &ICH9_LPC_RCBA_GCS_NO_REBOOT )) { +watchdog_perform_action (); +tco_timer_stop (tr); +return ; + } + } + +if (pm->smi_en &ICH9_PMIO_SMI_EN_TCO_EN ) { +ich9_generate_smi (); + }else { +ich9_generate_nmi (); + } + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); +} + +/* NOTE: values of 0 or 1 will be ignored by ICH */ +static inline int can_start_tco_timer (TCOIORegs *tr) +{ +return !(tr->tco.cnt1 &TCO_TMR_HLT ) && tr->tco.tmr >1 ; +} + +static uint32_t tco_ioport_readw (TCOIORegs *tr,uint32_t addr) +{ +uint16_t rld; + +switch (addr) { +case TCO_RLD : +if (tr->expire_time !=-1 ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +int64_t elapsed = (tr->expire_time - now) /TCO_TICK_NSEC ; + rld = (uint16_t )elapsed | (tr->tco.rld & ~TCO_RLD_MASK ); + }else { + rld = tr->tco.rld; + } +return rld; +case TCO_DAT_IN : +return tr->tco.din; +case TCO_DAT_OUT : +return tr->tco.dout; +case TCO1_STS : +return tr->tco.sts1; +case TCO2_STS : +return tr->tco.sts2; +case TCO1_CNT : +return tr->tco.cnt1; +case TCO2_CNT : +return tr->tco.cnt2; +case TCO_MESSAGE1 : +return tr->tco.msg1; +case TCO_MESSAGE2 : +return tr->tco.msg2; +case TCO_WDCNT : +return tr->tco.wdcnt; +case TCO_TMR : +return tr->tco.tmr; +case SW_IRQ_GEN : +return tr->sw_irq_gen; + } +return 0 ; +} + +static void tco_ioport_writew (TCOIORegs *tr,uint32_t addr,uint32_t val) +{ +switch (addr) { +case TCO_RLD : + tr->timeouts_no =0 ; +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { + tr->tco.rld = val; + } +break ; +case TCO_DAT_IN : + tr->tco.din = val; + tr->tco.sts1 |=SW_TCO_SMI ; +ich9_generate_smi (); +break ; +case TCO_DAT_OUT : + tr->tco.dout = val; + tr->tco.sts1 |=TCO_INT_STS ; +/* TODO: cause an interrupt, as selected by the TCO_INT_SEL bits */
hw/acpi/tco.c new file +11
-0+break ; +case TCO1_STS : + tr->tco.sts1 = val &TCO1_STS_MASK ; +break ; +case TCO2_STS : + tr->tco.sts2 = val &TCO2_STS_MASK ; +break ; +case TCO1_CNT : + val &=TCO1_CNT_MASK ; +/* +* once TCO_LOCK bit is set, it can not be cleared by software. a reset
+ * is required to change this bit from 1 to 0 -- it defaults to
0.hw/acpi/tco.c new file +71
-0+*/ + tr->tco.cnt1 = val | (tr->tco.cnt1 &TCO_LOCK ); +if (can_start_tco_timer (tr)) { + tr->tco.rld = tr->tco.tmr; +tco_timer_reload (tr); + }else { +tco_timer_stop (tr); + } +break ; +case TCO2_CNT : + tr->tco.cnt2 = val; +break ; +case TCO_MESSAGE1 : + tr->tco.msg1 = val; +break ; +case TCO_MESSAGE2 : + tr->tco.msg2 = val; +break ; +case TCO_WDCNT : + tr->tco.wdcnt = val; +break ; +case TCO_TMR : + tr->tco.tmr = val; +break ; +case SW_IRQ_GEN : + tr->sw_irq_gen = val; +break ; + } +} + +static uint64_t tco_io_readw (void *opaque,hwaddr addr,unsigned width) +{ +TCOIORegs *tr = opaque; +return tco_ioport_readw (tr, addr); +} + +static void tco_io_writew (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +TCOIORegs *tr = opaque; +tco_ioport_writew (tr, addr, val); +} + +static const MemoryRegionOps tco_io_ops = { + .read = tco_io_readw, + .write = tco_io_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 acpi_pm_tco_init(TCOIORegs *tr, MemoryRegion *parent) +{ + *tr = (TCOIORegs) { + .tco = { + .rld = TCO_RLD_DEFAULT, + .din = TCO_DAT_IN_DEFAULT, + .dout = TCO_DAT_OUT_DEFAULT, + .sts1 = TCO1_STS_DEFAULT, + .sts2 = TCO2_STS_DEFAULT, + .cnt1 = TCO1_CNT_DEFAULT, + .cnt2 = TCO2_CNT_DEFAULT, + .msg1 = TCO_MESSAGE1_DEFAULT, + .msg2 = TCO_MESSAGE2_DEFAULT, + .wdcnt = TCO_WDCNT_DEFAULT, + .tmr = TCO_TMR_DEFAULT, + }, + .sw_irq_gen = SW_IRQ_GEN_DEFAULT, + .tco_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
tco_timer_expired, tr),hw/acpi/tco.c new file +32
-0+ .expire_time = -1, + .timeouts_no = 0, + }; +memory_region_init_io (&tr->io,memory_region_owner (parent), + &tco_io_ops, tr,"sm-tco" ,ICH9_PMIO_TCO_LEN ); +memory_region_add_subregion (parent,ICH9_PMIO_TCO_RLD , &tr->io); +} + +const VMStateDescription vmstate_tco_io_sts = { + .name ="tco io device status" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT16 (tco.rld, TCOIORegs), +VMSTATE_UINT8 (tco.din, TCOIORegs), +VMSTATE_UINT8 (tco.dout, TCOIORegs), +VMSTATE_UINT16 (tco.sts1, TCOIORegs), +VMSTATE_UINT16 (tco.sts2, TCOIORegs), +VMSTATE_UINT16 (tco.cnt1, TCOIORegs), +VMSTATE_UINT16 (tco.cnt2, TCOIORegs), +VMSTATE_UINT8 (tco.msg1, TCOIORegs), +VMSTATE_UINT8 (tco.msg2, TCOIORegs), +VMSTATE_UINT8 (tco.wdcnt, TCOIORegs), +VMSTATE_UINT16 (tco.tmr, TCOIORegs), +VMSTATE_UINT8 (sw_irq_gen, TCOIORegs), +VMSTATE_TIMER_PTR (tco_timer, TCOIORegs), +VMSTATE_INT64 (expire_time, TCOIORegs), +VMSTATE_UINT8 (timeouts_no, TCOIORegs), +VMSTATE_END_OF_LIST () + } +};hw/i386/pc_q35.c +1
-1@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport !=ON_OFF_AUTO_ON ), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
hw/i386/pc_q35.c +2
-0@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 );}
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] &hw/isa/lpc_ich9.c +3
-2@@ -357,11 +367,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc, 0)); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev);}
include/hw/acpi/ich9.h +6
-1@@ -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_en_wmask;@@ -54,9 +56,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;include/hw/acpi/tco.h new file +6
-0@@ -0,0 +1,98 @@ +/* +* QEMU ICH9 TCO emulation +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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/hw/acpi/tco.h new file +7
-0+#ifndef HW_ACPI_TCO_H +#define HW_ACPI_TCO_H + +#include "qemu/typedefs.h" +#include "qemu-common.h" + +/* As per ICH9 spec, the internal timer has an error of ~0.6s on every tick */
include/hw/acpi/tco.h new file +30
-0+#define TCO_TICK_NSEC 600000000LL + +/* TCO I/O register offsets */ +enum { +TCO_RLD =0x00 , +TCO_DAT_IN =0x02 , +TCO_DAT_OUT =0x03 , +TCO1_STS =0x04 , +TCO2_STS =0x06 , +TCO1_CNT =0x08 , +TCO2_CNT =0x0a , +TCO_MESSAGE1 =0x0c , +TCO_MESSAGE2 =0x0d , +TCO_WDCNT =0x0e , +SW_IRQ_GEN =0x10 , +TCO_TMR =0x12 , +}; + +/* TCO I/O register control/status bits */ +enum { +SW_TCO_SMI =1 <<1 , +TCO_INT_STS =1 <<2 , +TCO_LOCK =1 <<12 , +TCO_TMR_HLT =1 <<11 , +TCO_TIMEOUT =1 <<3 , +TCO_SECOND_TO_STS =1 <<1 , +TCO_BOOT_STS =1 <<2 , +}; + +/* TCO I/O registers mask bits */
include/hw/acpi/tco.h line 70
Quoted 10 lines
include/hw/acpi/tco.h new file +10
-0+enum { +TCO_RLD_MASK =0x3ff , +TCO1_STS_MASK =0xe870 , +TCO2_STS_MASK =0xfff8 , +TCO1_CNT_MASK =0xfeff , +TCO_TMR_MASK =0x3ff , +}; + +typedef struct TCOIORegs { + bool use_tco;
This field is no longer used and should be removed. When I get home I'll send a v5 with this fix and the license stuff. Thank you all for reviewing it. That's really appreciable.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
PATCH v5 2/3 target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraThis block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRB
v2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in _CRS() method declaration
* create hw/i386/ich9-cc.h for chipset configuration register values and use them in ASL
v4 -> v5:
* prefix macros in ich9-cc.h with "ICH9_" for better readability and make use of them in CCR device definition
--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.h
hw/i386/q35-acpi-dsdt.dsl +16 -0
@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"
include/hw/i386/ich9-cc.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */
tests/acpi-test-data/q35/DSDT binary +0 -0
Signature · 1 line
2.1.0
PATCH v5 1/3 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* set SECOND_TO_STS and BOOT_STS bits in TCO2_STS instead
* improve handling of TCO_LOCK bit in TCO1_CNT register
v3 -> v4:
* fix some conflicts in hw/acpi/ich9.c after rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO support
on pc-q35-2.4 and later
v4 -> v5:
* remove unused field (use_tco) in TCOIORegs structure
* move license to GPLv2+
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 ++++++++++- hw/acpi/tco.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 15 ++- include/hw/acpi/ich9.h | 7 +- include/hw/acpi/tco.h | 82 +++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 10 +- include/hw/i386/pc.h | 1 + 10 files changed, 435 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +54 -1
105 lines not on this page · raw message
hw/acpi/tco.c new file +264 -0
264 lines not on this page · raw message
hw/i386/pc_q35.c +3 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }
@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 ); }
hw/isa/lpc_ich9.c +13 -2
@@ -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] &
@@ -357,11 +367,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev); }
include/hw/acpi/ich9.h +6 -1
@@ -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_en_wmask;
@@ -54,9 +56,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;
include/hw/acpi/tco.h new file +82 -0
82 lines not on this page · raw message
include/hw/boards.h +2 -1
@@ -99,7 +99,8 @@ struct MachineClass { no_floppy:1, no_cdrom:1, no_sdcard:1, - has_dynamic_sysbus:1; + has_dynamic_sysbus:1, + no_tco:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
include/hw/i386/ich9.h +9 -1
@@ -17,9 +17,12 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool enable_tco);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"
@@ -162,6 +165,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
@@ -186,7 +191,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
include/hw/i386/pc.h +1 -0
@@ -89,6 +89,7 @@ typedef struct PcPciInfo {#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len" +#define ACPI_PM_PROP_TCO_ENABLED "enable_tco"struct PcGuestInfo {bool isapc_ram_fw;
Signature · 1 line
2.1.0
PATCH v5 3/3 tests: add testcase for TCO watchdog emulation
This patch adds a testcase that covers the following:
1) TCO default values
2) first and second TCO timeout
3) watch and validate ticks counter through TCO_RLD register
4) maximum supported TCO timeout (0x3ff)
5) watchdog actions (pause/reset/shutdown/none) upon second TCO timeout
6) set and get of TCO control and status bits
---
v1 -> v2:
* some cleanup
* add test for TCO_LOCK bit
v2 -> v3:
* add tests for TCO control & status bits
* fix check of SECOND_TO_STS bit (it's set in TCO2_STS reg)
v3 -> v4:
* add more description to commit log
* use RCBA_BASE_ADDR macro defintion from hw/i386/ich9-cc.h instead
v4 -> v5:
* use modified macros (now prefixed with ICH9_) from ich9-cc.h
* move license to GPLv2+
--- tests/Makefile | 2 + tests/tco-test.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+) create mode 100644 tests/tco-test.c
tests/Makefile +2 -0
@@ -152,6 +152,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)
@@ -370,6 +371,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 +460 -0
460 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 9 lines · Paulo Alcantara
This interface provides some registers within a 32-byte range and can be acessed 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 -- if
TCO_ENbit is set -- on every timeout. IfNO_REBOOTbit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout ifTCO_RLDregister wasn't previously written to prevent timeout.
Quoted 5 lines
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (
NMI2SMI_ENbit), system intruder detection, etc. are not implemented yet.Signed-off-by Paulo Alcantara <[email protected]>
One useful feature to implement could be ability to set the NO_REBOOT strapping pin to 1. And maybe it's even a better default - will have to experiment with this feature some more.
Does not have to block this patchset, can be done by a patch on top.
Signature · 1 line
MST
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 32 lines · On Sun, 21 Jun 2015 21:37:02 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +0
-0
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 123
Quoted 10 lines
hw/i386/q35-acpi-dsdt.dsl +7
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) {
I'd name it something like: TCOW
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 124
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_HID, EISAID("PNP0C02"))
PNP0C02 not in ACPI spec, pls use PNP0A06 like we do in other places for reserving IO space.
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 125
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_UID, 1)
s/1/"TCO watchdog resources"/
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 3 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)
since this values are dynamically programmed by BIOS
it's incorrect to put them here statically.
Take RCBA_BASE_ADDR from respective ICH9 register,
which should be programmed by BIOS before ACPI tables are read by it.
Also like Michael suggested create this device dynamically in build_ssdt(), for example look at "if (misc->applesmc_io_base) {" block in hw/i386/acpi-build.c and add this device only if it's present (i.e. for version from which it's supported)
Quoted 31 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +18
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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
include/hw/i386/ich9-cc.h line 28
Quoted 10 lines
include/hw/i386/ich9-cc.h new file +10
-0+* 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. +*/ + +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000
where does this value come from?
Quoted 13 lines
include/hw/i386/ich9-cc.h new file +3
-0+#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ tests/acpi-test-data/q35/DSDT binary +0
-0
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 47 lines · Igor Mammedov
Quoted 32 lines · On Sun, 21 Jun 2015 21:37:02 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +0
-0hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 123
Quoted 10 lines
hw/i386/q35-acpi-dsdt.dsl +7
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) {I'd name it something like: TCOW
Quoted 6 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 124
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_HID, EISAID("PNP0C02"))PNP0C02 not in ACPI spec, pls use PNP0A06 like we do in other places for reserving IO space.
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 125
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_UID, 1)s/1/"TCO watchdog resources"/
I think we switched all UID values to integers, you can look it up in git history. Let's keep this consistent?
Quoted 69 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 3 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)since this values are dynamically programmed by BIOS
it's incorrect to put them here statically.
TakeRCBA_BASE_ADDRfrom respective ICH9 register,
which should be programmed by BIOS before ACPI tables are read by it.Also like Michael suggested create this device dynamically in
build_ssdt(), for example look at "if (misc->applesmc_io_base) {" block inhw/i386/acpi-build.cand add this device only if it's present (i.e. for version from which it's supported)Quoted 31 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +18
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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 include/hw/i386/ich9-cc.h line 28
Quoted 10 lines
include/hw/i386/ich9-cc.h new file +10
-0+* 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. +*/ + +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000where does this value come from?
Quoted 13 lines
include/hw/i386/ich9-cc.h new file +3
-0+#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ tests/acpi-test-data/q35/DSDT binary +0
-0
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Igor Mammedov----- Original Message -----
Quoted 44 lines
From: "Igor Mammedov" <[email protected]>
To: "Paulo Alcantara" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Tuesday, June 23, 2015 12:38:59 PM
Subject: Re: [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT tableQuoted 35 lines · On Sun, 21 Jun 2015 21:37:02 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +0
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } }
Quoted 8 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 123
Quoted 7 lines
hw/i386/q35-acpi-dsdt.dsl +7
-0+#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) {I'd name it something like: TCOW
Guys, can you *please* read the reviews to v1/2/3 and even to v4 itself?!?!?
Paolo
Quoted 89 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 124
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_HID, EISAID("PNP0C02"))PNP0C02 not in ACPI spec, pls use PNP0A06 like we do in other places for reserving IO space.
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 125
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_UID, 1)s/1/"TCO watchdog resources"/
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 3 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)since this values are dynamically programmed by BIOS
it's incorrect to put them here statically.
TakeRCBA_BASE_ADDRfrom respective ICH9 register,
which should be programmed by BIOS before ACPI tables are read by it.Also like Michael suggested create this device dynamically in
build_ssdt(), for example look at "if (misc->applesmc_io_base) {" block inhw/i386/acpi-build.cand add this device only if it's present (i.e. for version from which it's supported)Quoted 46 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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/hw/i386/ich9-cc.h line 28
Quoted 5 lines
include/hw/i386/ich9-cc.h new file +5
-0+ +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000where does this value come from?
Quoted 15 lines
include/hw/i386/ich9-cc.h new file +3
-0+#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ tests/acpi-test-data/q35/DSDT +0
-0index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644
GIT binary patch
delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Igor Mammedov----- Original Message -----
Quoted 53 lines
From: "Igor Mammedov" <[email protected]>
To: "Paulo Alcantara" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Tuesday, June 23, 2015 12:38:59 PM
Subject: Re: [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT tableQuoted 32 lines · On Sun, 21 Jun 2015 21:37:02 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +0
-0hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 123
Quoted 10 lines
hw/i386/q35-acpi-dsdt.dsl +7
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) {I'd name it something like: TCOW
Quoted 3 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 124
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_HID, EISAID("PNP0C02"))PNP0C02 not in ACPI spec, pls use PNP0A06 like we do in other places for reserving IO space.
The ACPI spec says "Note: Plug and Play IDs that are not defined by the ACPI specification are defined and described in the following document [URL]" where PNP0C02 is the "General ID for reserving resources required by Plug and Play system board registers (not specific to a particular device)".
PNP0A06 is the "ACPI bus", whatever that means.
Paolo
Quoted 85 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 125
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_UID, 1)s/1/"TCO watchdog resources"/
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 3 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)since this values are dynamically programmed by BIOS
it's incorrect to put them here statically.
TakeRCBA_BASE_ADDRfrom respective ICH9 register,
which should be programmed by BIOS before ACPI tables are read by it.Also like Michael suggested create this device dynamically in
build_ssdt(), for example look at "if (misc->applesmc_io_base) {" block inhw/i386/acpi-build.cand add this device only if it's present (i.e. for version from which it's supported)Quoted 46 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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/hw/i386/ich9-cc.h line 28
Quoted 5 lines
include/hw/i386/ich9-cc.h new file +5
-0+ +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000where does this value come from?
Quoted 15 lines
include/hw/i386/ich9-cc.h new file +3
-0+#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ tests/acpi-test-data/q35/DSDT +0
-0index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644
GIT binary patch
delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Igor MammedovQuoted 9 lines · Igor Mammedov
Quoted 1 line
+ Name (
_UID, 1)s/1/"TCO watchdog resources"/
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 3 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)since this values are dynamically programmed by BIOS
it's incorrect to put them here statically.
TakeRCBA_BASE_ADDRfrom respective ICH9 register,
which should be programmed by BIOS before ACPI tables are read by it.
Hmm this is true, isn't it?
static void ich9_lpc_rcba_update(ICH9LPCState *lpc, uint32_t rbca_old)
{
uint32_t rbca = pci_get_long(lpc->d.config + ICH9_LPC_RCBA);
if (rbca_old & ICH9_LPC_RCBA_EN) {
memory_region_del_subregion(get_system_memory(), &lpc->rbca_mem);
}
if (rbca & ICH9_LPC_RCBA_EN) {
memory_region_add_subregion_overlap(get_system_memory(),
rbca & ICH9_LPC_RCBA_BA_MASK,
&lpc->rbca_mem, 1);
}
}So the RBCA base must come from device config,
and in particular, this means it must be in the
SSDT since the DSDT is static.
We already have aml_memory32_fixed, e.g.
if (misc->tpm_version != TPM_VERSION_UNSPEC) {
dev = aml_device("ISA.TPM");
aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C31")));
aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
crs = aml_resource_template();
aml_append(crs, aml_memory32_fixed(TPM_TIS_ADDR_BASE,
TPM_TIS_ADDR_SIZE, AML_READ_WRITE));
aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ));
aml_append(dev, aml_name_decl("_CRS", crs));
aml_append(scope, dev);
}so it won't be hard to do.
Signature · 1 line
MST
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Michael S. TsirkinQuoted 51 lines · On Tue, 23 Jun 2015 12:58:13 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 50 lines · Igor Mammedov
Quoted 34 lines · On Sun, 21 Jun 2015 21:37:02 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register
values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +0
-0@@ -114,6 +114,22 @@ DefinitionBlock ( }hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 124
Quoted 10 lines
hw/i386/q35-acpi-dsdt.dsl +7
-0} +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) {I'd name it something like: TCOW
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_HID, EISAID("PNP0C02"))
Quoted 8 lines
Quoted 5 lines
PNP0C02 not in ACPI spec, pls use PNP0A06 like we do in other places for reserving IO space.
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 125
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_UID, 1)s/1/"TCO watchdog resources"/
I think we switched all UID values to integers, you can look it up in git history. Let's keep this consistent?
in ssdt for container devices we use strings which says what container is for.
so using description string is consistent with what we are doing now.
With numbers it's easy to create UID collision, which makes some Windows versions BSOD.
as side effect:
It makes container device self describing if one looks in device-manager.
Quoted 83 lines
Quoted 83 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 4 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)since this values are dynamically programmed by BIOS it's incorrect to put them here statically.
TakeRCBA_BASE_ADDRfrom respective ICH9 register, which should be programmed by BIOS before ACPI tables are read by it.Also like Michael suggested create this device dynamically in
build_ssdt(), for example look at "if (misc->applesmc_io_base) {" block inhw/i386/acpi-build.cand add this device only if it's present (i.e. for version from which it's supported)Quoted 48 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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/hw/i386/ich9-cc.h line 28
Quoted 5 lines
include/hw/i386/ich9-cc.h new file +5
-0+ +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000where does this value come from?
Quoted 13 lines
include/hw/i386/ich9-cc.h new file +3
-0+#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [SeaBIOS] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 67 lines · Igor Mammedov
Quoted 51 lines · On Tue, 23 Jun 2015 12:58:13 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 50 lines · Igor Mammedov
Quoted 34 lines · On Sun, 21 Jun 2015 21:37:02 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register
values and use them in ASL--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 31 +++++++++++++++++++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 47 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +0
-0@@ -114,6 +114,22 @@ DefinitionBlock ( }hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 124
Quoted 10 lines
hw/i386/q35-acpi-dsdt.dsl +7
-0} +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) {I'd name it something like: TCOW
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_HID, EISAID("PNP0C02"))Quoted 8 lines
Quoted 5 lines
PNP0C02 not in ACPI spec, pls use PNP0A06 like we do in other places for reserving IO space.
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 125
Quoted 1 line
hw/i386/q35-acpi-dsdt.dsl +1
-0+ Name (_UID, 1)s/1/"TCO watchdog resources"/
I think we switched all UID values to integers, you can look it up in git history. Let's keep this consistent?
in ssdt for container devices we use strings which says what container is for.
so using description string is consistent with what we are doing now.
Quoted 6 lines
With numbers it's easy to create UID collision, which makes some Windows versions BSOD.
as side effect:
It makes container device self describing if one looks in device-manager.
But see
commit c96d9286a6d70452e5fa4f1e3f840715e325be95
i386/acpi-build: more traditional _UID and _HID for PXB root buses
ARM also seems to have #s as UIDs for CPUs.
I don't think I'll block this patch on this issue, we can tweak the UID later easily.
Quoted 83 lines
Quoted 83 lines
Quoted 83 lines
hw/i386/q35-acpi-dsdt.dsl DefinitionBlock ( · line 128
Quoted 4 lines
hw/i386/q35-acpi-dsdt.dsl +3
-0+ + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, RCBA_BASE_ADDR, RCRB_SIZE)since this values are dynamically programmed by BIOS it's incorrect to put them here statically.
TakeRCBA_BASE_ADDRfrom respective ICH9 register, which should be programmed by BIOS before ACPI tables are read by it.Also like Michael suggested create this device dynamically in
build_ssdt(), for example look at "if (misc->applesmc_io_base) {" block inhw/i386/acpi-build.cand add this device only if it's present (i.e. for version from which it's supported)Quoted 48 lines
hw/i386/q35-acpi-dsdt.dsl +4
-0+ }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,31 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* 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/hw/i386/ich9-cc.h line 28
Quoted 5 lines
include/hw/i386/ich9-cc.h new file +5
-0+ +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define RCBA_BASE_ADDR 0xfed1c000where does this value come from?
Quoted 13 lines
include/hw/i386/ich9-cc.h new file +3
-0+#define RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [SeaBIOS] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 6 lines · On Mon, 22 Jun 2015 20:10:28 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Do we really need to describe this block in ASL? PCI0 bus _CRS doesn't include 0xfed1c000 address and stops at 0xfec00000 (w32.end - end of 32-bit PCI window), so adding a device that consumes not provided by parent bus resources probably is not correct.
Taking in account that address is beyond of dynamically used PCI memory resources, I'd just drop patch.
If the goal of it to make sure that it provides resource conflict check then Windows wasn't doing a good job with PNP0C02 used, that's why we ended up with PNP0A06 (between PNP0C02, PNP0A06, ACPI0004) for this task in cases of absence of a defined device HID. And it should be moved out of PCI0 bus scope anyway.
Quoted 85 lines
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASLv4 -> v5:
* prefix macros inich9-cc.hwith "ICH9_" for better readability and make use of them in CCR device definition--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */include/hw/i386/ich9-cc.h new file +7
-0+#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [SeaBIOS] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraOn Mon, 22 Jun 2015 20:10:28 -0300
Paulo Alcantara <[email protected]> wrote:
Also I've stumbled upon
http://download.intel.com/design/chipsets/applnots/29227301.pdf
don't we need to implement WDDT ACPI table as well?
Quoted 91 lines
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASLv4 -> v5:
* prefix macros inich9-cc.hwith "ICH9_" for better readability and make use of them in CCR device definition--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */include/hw/i386/ich9-cc.h new file +7
-0+#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [SeaBIOS] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 6 lines · Igor Mammedov
On Mon, 22 Jun 2015 20:10:28 -0300
Paulo Alcantara <[email protected]> wrote:Also I've stumbled upon
http://download.intel.com/design/chipsets/applnots/29227301.pdf
don't we need to implement WDDT ACPI table as well?
Maybe but linux does not seem to care.
Signature · 1 line
MST
Re: [Qemu-devel] [SeaBIOS] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 9 lines · On Tue, 23 Jun 2015 17:06:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
On Mon, 22 Jun 2015 20:10:28 -0300
Paulo Alcantara <[email protected]> wrote:Also I've stumbled upon
http://download.intel.com/design/chipsets/applnots/29227301.pdf
don't we need to implement WDDT ACPI table as well?Maybe but linux does not seem to care.
What about Windows?
Re: [Qemu-devel] [SeaBIOS] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 7 lines · Igor Mammedov
Quoted 4 lines · On Tue, 23 Jun 2015 17:06:46 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Igor Mammedov
On Mon, 22 Jun 2015 20:10:28 -0300
Paulo Alcantara <[email protected]> wrote:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Also I've stumbled upon
http://download.intel.com/design/chipsets/applnots/29227301.pdf
don't we need to implement WDDT ACPI table as well?Maybe but linux does not seem to care.
What about Windows?
Needs testing - I tried existing guests and they do not touch TCO but maybe a new install will. Possibly windows does not touch TCO since there's no WDDT ACPI table, but it's not a regression so does not have to block this patchset.
Signature · 1 line
MST
Re: [Qemu-devel] [SeaBIOS] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Igor MammedovQuoted 15 lines · Igor Mammedov
Quoted 6 lines · On Mon, 22 Jun 2015 20:10:28 -0300 Paulo Alcantara <[email protected]> wrote:
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Do we really need to describe this block in ASL? PCI0 bus
_CRSdoesn't include0xfed1c000address and stops at0xfec00000(w32.end - end of 32-bit PCI window), so adding a device that consumes not provided by parent bus resources probably is not correct.
Quoted 8 lines
Taking in account that address is beyond of dynamically used PCI memory resources, I'd just drop patch.
If the goal of it to make sure that it provides resource conflict check then Windows wasn't doing a good job with PNP0C02 used, that's why we ended up with PNP0A06 (between PNP0C02, PNP0A06, ACPI0004) for this task in cases of absence of a defined device HID. And it should be moved out of PCI0 bus scope anyway.
Paulo, does some guest need this patch (2/3)?
Quoted 85 lines
Quoted 85 lines
Signed-off-by Paulo Alcantara <[email protected]>---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASLv4 -> v5:
* prefix macros inich9-cc.hwith "ICH9_" for better readability and make use of them in CCR device definition--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */include/hw/i386/ich9-cc.h new file +7
-0+#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzs
Re: [Qemu-devel] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
In reply to Paulo AlcantaraQuoted 8 lines · Paulo Alcantara
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>
Can you confirm things just work for you if you drop this patch from the series?
Quoted 83 lines
---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register values and use them in ASLv4 -> v5:
* prefix macros inich9-cc.hwith "ICH9_" for better readability and make use of them in CCR device definition--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +15
-0@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ tests/acpi-test-data/q35/DSDT binary +0
-0Signature · 2 lines
-- 2.1.0
Re: [Qemu-devel] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 6 lines · On Wed, 24 Jun 2015 17:11:26 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Paulo Alcantara
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
Quoted 6 lines
Quoted 3 lines
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>Can you confirm things just work for you if you drop this patch from the series?
Hi Michael,
Yes, everything works. I still see no point of adding it to SSDT because OVMF is already setting RCBA to that fixed address and so SeaBIOS once my patch is applied. Therefore, there is no no such thing like "dynamically programmed by BIOS" either. Although, my host and probably yours define the same address in DSDT.
Given that UEFI and a BIOS implementations are using the same fixed address, this patch was done in a hope of not letting the ACPI-aware OS using the same address for another BAR or something else thus avoiding conflicts.
Please, let me know if I'm missing something here. If you want, I can send v6 with this patch removed completely.
(BTW, sorry for the delay. It's holiday here in Brazil and, you know, real life happens sometimes :-) )
Thanks,
Paulo
Quoted 87 lines
Quoted 86 lines
---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register
values and use them in ASLv4 -> v5:
* prefix macros inich9-cc.hwith "ICH9_" for better readability
and make use of them in CCR device definition--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */include/hw/i386/ich9-cc.h new file +7
-0+#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzsSignature · 1 line
2.1.0
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Re: [Qemu-devel] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table
Quoted 24 lines · Paulo Alcantara
Quoted 6 lines · On Wed, 24 Jun 2015 17:11:26 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Paulo Alcantara
This block is mapped into memory space, using the Root Complex Base Address (RCBA) register of the PCI-to-LPC bridge. Accesses in this space must be limited to 32-(DW) bit quantities. Burst accesses are not allowed.
Quoted 6 lines
Quoted 3 lines
All Chipset Configuration Registers are located in this 16KiB space.
Signed-off-by Paulo Alcantara <[email protected]>Can you confirm things just work for you if you drop this patch from the series?
Hi Michael,
Yes, everything works. I still see no point of adding it to SSDT because OVMF is already setting RCBA to that fixed address and so SeaBIOS once my patch is applied. Therefore, there is no no such thing like "dynamically programmed by BIOS" either. Although, my host and probably yours define the same address in DSDT.
Quoted 4 lines
Given that UEFI and a BIOS implementations are using the same fixed address, this patch was done in a hope of not letting the ACPI-aware OS using the same address for another BAR or something else thus avoiding conflicts.
But does PCI root CRS cover this range? If not - an ACPI aware OS can't assign PCI BARs in this range really.
Quoted 9 lines
Please, let me know if I'm missing something here. If you want, I can send v6 with this patch removed completely.
(BTW, sorry for the delay. It's holiday here in Brazil and, you know, real life happens sometimes :-) )
Thanks,
Paulo
No rush, we have a couple of days until the hard freeze still
Quoted 93 lines
Quoted 87 lines
Quoted 86 lines
---
v1 -> v2:
* s/PDRC/CCR/ for clarity and match ICH9 spec
* remove unnecessary OperationRegion for RCRBv2 -> v3: (no changes)
v3 -> v4:
* quote RCRB description from ICH9 spec to commit log
* fix indentation issue in_CRS()method declaration
* createhw/i386/ich9-cc.hfor chipset configuration register
values and use them in ASLv4 -> v5:
* prefix macros inich9-cc.hwith "ICH9_" for better readability
and make use of them in CCR device definition--- hw/i386/q35-acpi-dsdt.dsl | 16 ++++++++++++++++ include/hw/i386/ich9-cc.h | 15 +++++++++++++++ tests/acpi-test-data/q35/DSDT | Bin 7666 -> 7723 bytes 3 files changed, 31 insertions(+) create mode 100644 include/hw/i386/ich9-cc.hhw/i386/q35-acpi-dsdt.dsl +16
-0@@ -114,6 +114,22 @@ DefinitionBlock ( } } +#include "hw/i386/ich9-cc.h" + +/**************************************************************** + * Chipset Configuration Registers + ****************************************************************/ +Scope(\_SB.PCI0) { + Device (CCR) { + Name (_HID, EISAID("PNP0C02")) + Name (_UID, 1) + + Name (_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, ICH9_RCBA_BASE_ADDR, ICH9_RCRB_SIZE) + }) + } +} + #include "acpi-dsdt-hpet.dsl"include/hw/i386/ich9-cc.h new file +6
-0@@ -0,0 +1,15 @@ +/* +* QEMU ICH9 Chipset Configuration Registers +* +* Copyright (c) 2015 Paulo Alcantara <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */include/hw/i386/ich9-cc.h new file +7
-0+#ifndef HW_ICH9_CC_H +#define HW_ICH9_CC_H + +#define ICH9_RCBA_BASE_ADDR 0xfed1c000 +#define ICH9_RCRB_SIZE 0x00004000 + +#endif /* HW_ICH9_CC_H */ (quoted diff) +0
-0b/tests/acpi-test-data/q35/DSDT index
4723e5954dccb00995ccaf521b7daf6bf15cf1d4..f3bda7b54ea6d669b1498d9380e7781207fb6e49100644 GIT binary patch delta 81 zcmexlz1oJ$CD<iITaJN&F>xbTJfnq$UVN}qe1Nm3L3ERjvvW{9N4$rp3y<Rk9wv_X lP)>|j(F#wU_n7HzBWz<Mur0y|1mf)FjO*Z&S3140RVI6(s-wdelta 24
gcmZ2&^U0daCD<k8lPm)R<DrdQ@r;`nF?PxT0Bl$YHUIzsSignature · 1 line
2.1.0Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
PATCH v6 1/2 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* set SECOND_TO_STS and BOOT_STS bits in TCO2_STS instead
* improve handling of TCO_LOCK bit in TCO1_CNT register
v3 -> v4:
* fix some conflicts in hw/acpi/ich9.c after rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO support
on pc-q35-2.4 and later
v4 -> v5:
* remove unused field (use_tco) in TCOIORegs structure
* move license to GPLv2+
v5 -> v6:
* remove "io_tco" field from ICH9LPCPMRegs structure since it's no longer used
* set ICH9_CC_GCS_NO_REBOOT bit by default in ICH9's LPC initialisation
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 ++++++++++- hw/acpi/tco.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 16 ++- include/hw/acpi/ich9.h | 6 +- include/hw/acpi/tco.h | 82 +++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 11 ++- include/hw/i386/pc.h | 1 + 10 files changed, 436 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +54 -1
105 lines not on this page · raw message
hw/acpi/tco.c new file +264 -0
264 lines not on this page · raw message
hw/i386/pc_q35.c +3 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }
@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 ); }
hw/isa/lpc_ich9.c +14 -2
@@ -138,6 +138,7 @@ static void ich9_cc_reset(ICH9LPCState *lpc)pci_set_long (c +ICH9_CC_D27IR ,ICH9_CC_DIR_DEFAULT );pci_set_long (c +ICH9_CC_D26IR ,ICH9_CC_DIR_DEFAULT );pci_set_long (c +ICH9_CC_D25IR ,ICH9_CC_DIR_DEFAULT ); +pci_set_long (c +ICH9_CC_GCS ,ICH9_CC_GCS_DEFAULT );ich9_cc_update (lpc); }
@@ -313,6 +314,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] &
@@ -357,11 +368,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev); }
include/hw/acpi/ich9.h +5 -1
@@ -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 { /*
@@ -54,9 +55,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;
include/hw/acpi/tco.h new file +82 -0
82 lines not on this page · raw message
include/hw/boards.h +2 -1
@@ -99,7 +99,8 @@ struct MachineClass { no_floppy:1, no_cdrom:1, no_sdcard:1, - has_dynamic_sysbus:1; + has_dynamic_sysbus:1, + no_tco:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
include/hw/i386/ich9.h +10 -1
@@ -17,9 +17,12 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool enable_tco);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"
@@ -90,6 +93,9 @@ Object *ich9_lpc_find(void);#define ICH9_CC_DIR_MASK 0x7#define ICH9_CC_OIC 0x31FF#define ICH9_CC_OIC_AEN 0x1 +#define ICH9_CC_GCS 0x3410 +#define ICH9_CC_GCS_DEFAULT 0x00000020 +#define ICH9_CC_GCS_NO_REBOOT (1 << 5)/* D28:F[0-5] */ #define ICH9_PCIE_DEV 28
@@ -186,7 +192,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
include/hw/i386/pc.h +1 -0
@@ -89,6 +89,7 @@ typedef struct PcPciInfo {#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len" +#define ACPI_PM_PROP_TCO_ENABLED "enable_tco"struct PcGuestInfo {bool isapc_ram_fw;
Signature · 1 line
2.1.0
PATCH v6 2/2 tests: add testcase for TCO watchdog emulation
This patch adds a testcase that covers the following:
1) TCO default values
2) first and second TCO timeout
3) watch and validate ticks counter through TCO_RLD register
4) maximum supported TCO timeout (0x3ff)
5) watchdog actions (pause/reset/shutdown/none) upon second TCO timeout
6) set and get of TCO control and status bits
---
v1 -> v2:
* some cleanup
* add test for TCO_LOCK bit
v2 -> v3:
* add tests for TCO control & status bits
* fix check of SECOND_TO_STS bit (it's set in TCO2_STS reg)
v3 -> v4:
* add more description to commit log
* use RCBA_BASE_ADDR macro defintion from hw/i386/ich9-cc.h instead
v4 -> v5:
* use modified macros (now prefixed with ICH9_) from ich9-cc.h
* move license to GPLv2+
v5 -> v6:
* remove include of "hw/i386/ich9-cc.h" since it's no longer exist
--- tests/Makefile | 2 + tests/tco-test.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+) create mode 100644 tests/tco-test.c
tests/Makefile +2 -0
@@ -152,6 +152,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)
@@ -370,6 +371,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 +460 -0
460 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v7 1/3 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* set SECOND_TO_STS and BOOT_STS bits in TCO2_STS instead
* improve handling of TCO_LOCK bit in TCO1_CNT register
v3 -> v4:
* fix some conflicts in hw/acpi/ich9.c after rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO support
on pc-q35-2.4 and later
v4 -> v5:
* remove unused field (use_tco) in TCOIORegs structure
* move license to GPLv2+
v5 -> v6:
* remove "io_tco" field from ICH9LPCPMRegs structure since it's no longer used
* set ICH9_CC_GCS_NO_REBOOT bit by default in ICH9's LPC initialisation
v6 -> v7: (no changes)
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 ++++++++++- hw/acpi/tco.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 16 ++- include/hw/acpi/ich9.h | 6 +- include/hw/acpi/tco.h | 82 +++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 11 ++- include/hw/i386/pc.h | 1 + 10 files changed, 436 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +54 -1
105 lines not on this page · raw message
hw/acpi/tco.c new file +264 -0
264 lines not on this page · raw message
hw/i386/pc_q35.c +3 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }
@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 ); }
hw/isa/lpc_ich9.c +14 -2
@@ -138,6 +138,7 @@ static void ich9_cc_reset(ICH9LPCState *lpc)pci_set_long (c +ICH9_CC_D27IR ,ICH9_CC_DIR_DEFAULT );pci_set_long (c +ICH9_CC_D26IR ,ICH9_CC_DIR_DEFAULT );pci_set_long (c +ICH9_CC_D25IR ,ICH9_CC_DIR_DEFAULT ); +pci_set_long (c +ICH9_CC_GCS ,ICH9_CC_GCS_DEFAULT );ich9_cc_update (lpc); }
@@ -313,6 +314,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] &
@@ -357,11 +368,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev); }
include/hw/acpi/ich9.h +5 -1
@@ -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 { /*
@@ -54,9 +55,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;
include/hw/acpi/tco.h new file +82 -0
82 lines not on this page · raw message
include/hw/boards.h +2 -1
@@ -99,7 +99,8 @@ struct MachineClass { no_floppy:1, no_cdrom:1, no_sdcard:1, - has_dynamic_sysbus:1; + has_dynamic_sysbus:1, + no_tco:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
include/hw/i386/ich9.h +10 -1
@@ -17,9 +17,12 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool enable_tco);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"
@@ -90,6 +93,9 @@ Object *ich9_lpc_find(void);#define ICH9_CC_DIR_MASK 0x7#define ICH9_CC_OIC 0x31FF#define ICH9_CC_OIC_AEN 0x1 +#define ICH9_CC_GCS 0x3410 +#define ICH9_CC_GCS_DEFAULT 0x00000020 +#define ICH9_CC_GCS_NO_REBOOT (1 << 5)/* D28:F[0-5] */ #define ICH9_PCIE_DEV 28
@@ -186,7 +192,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
include/hw/i386/pc.h +1 -0
@@ -89,6 +89,7 @@ typedef struct PcPciInfo {#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len" +#define ACPI_PM_PROP_TCO_ENABLED "enable_tco"struct PcGuestInfo {bool isapc_ram_fw;
Signature · 1 line
2.1.0
PATCH v7 2/3 tests: add testcase for TCO watchdog emulation
This patch adds a testcase that covers the following:
1) TCO default values
2) first and second TCO timeout
3) watch and validate ticks counter through TCO_RLD register
4) maximum supported TCO timeout (0x3ff)
5) watchdog actions (pause/reset/shutdown/none) upon second TCO timeout
6) set and get of TCO control and status bits
---
v1 -> v2:
* some cleanup
* add test for TCO_LOCK bit
v2 -> v3:
* add tests for TCO control & status bits
* fix check of SECOND_TO_STS bit (it's set in TCO2_STS reg)
v3 -> v4:
* add more description to commit log
* use RCBA_BASE_ADDR macro defintion from hw/i386/ich9-cc.h instead
v4 -> v5:
* use modified macros (now prefixed with ICH9_) from ich9-cc.h
* move license to GPLv2+
v5 -> v6:
* remove include of "hw/i386/ich9-cc.h" since it's no longer exist
v6 -> v7: (no changes)
--- tests/Makefile | 2 + tests/tco-test.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+) create mode 100644 tests/tco-test.c
tests/Makefile +2 -0
@@ -152,6 +152,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)
@@ -370,6 +371,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 +460 -0
460 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v7 3/3 ich9: implement strap SPKR pin logic
In reply to Paulo AlcantaraIf the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the NO_REBOOT bit (CC: offset 0x3410:bit 5).
The NO_REBOOT bit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".
This patch implements the logic where hardware has ability to set SPKR pin through a property named "pin-spkr" and it's sampled low by default.
--- hw/acpi/tco.c | 3 ++- hw/isa/lpc_ich9.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/i386/ich9.h | 11 +++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-)
hw/acpi/tco.c +2 -1
@@ -64,7 +64,8 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if ((lpc->pin_strap.spkr &ICH9_PS_SPKR_PIN_LOW ) && + !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;
hw/isa/lpc_ich9.c +38 -0
@@ -575,11 +575,49 @@ static void ich9_lpc_get_sci_int(Object *obj, Visitor *v,visit_type_uint32 (v, &value, name, errp); } +static void ich9_lpc_get_spkr_pin (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +ICH9LPCState *lpc = opaque; +uint8_t value = lpc->pin_strap.spkr; + +visit_type_uint8 (v, &value, name, errp); +} + +static void ich9_lpc_set_spkr_pin (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +ICH9LPCState *lpc = opaque; +Error *local_err =NULL ; +uint8_t value; +uint32_t *gcs; + +visit_type_uint8 (v, &value, name, &local_err); +if (local_err) { + goto out; + } + value &=ICH9_PS_SPKR_PIN_MASK ; +if (value &ICH9_PS_SPKR_PIN_HIGH ) { + gcs = (uint32_t *)&lpc->chip_config[ICH9_CC_GCS ]; + *gcs |=ICH9_CC_GCS_NO_REBOOT ; + } + lpc->pin_strap.spkr = value; +out: +error_propagate (errp, local_err); +} +static void ich9_lpc_add_properties (ICH9LPCState *lpc) {static const uint8_t acpi_enable_cmd =ICH9_APM_ACPI_ENABLE ;static const uint8_t acpi_disable_cmd =ICH9_APM_ACPI_DISABLE ; + lpc->pin_strap.spkr =ICH9_PS_SPKR_PIN_DEFAULT ; +object_property_add (OBJECT (lpc),"pin-spkr" ,"uint8" , + ich9_lpc_get_spkr_pin, + ich9_lpc_set_spkr_pin, +NULL , lpc,NULL );object_property_add (OBJECT (lpc),ACPI_PM_PROP_SCI_INT ,"uint32" , ich9_lpc_get_sci_int,NULL ,NULL ,NULL ,NULL );
include/hw/i386/ich9.h +11 -0
@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +uint8_t spkr; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];
@@ -72,6 +77,12 @@ Object *ich9_lpc_find(void);#define Q35_MASK (bit, ms_bit, ls_bit) \ ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1))) +/* ICH9: Pin Straps */ +#define ICH9_PS_SPKR_PIN_LOW 0x01 +#define ICH9_PS_SPKR_PIN_HIGH 0x02 +#define ICH9_PS_SPKR_PIN_MASK 0x03 +#define ICH9_PS_SPKR_PIN_DEFAULT ICH9_PS_SPKR_PIN_LOW +/* ICH9: Chipset Configuration Registers */ #define ICH9_CC_ADDR_MASK (ICH9_CC_SIZE - 1)
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v7 3/3] ich9: implement strap SPKR pin logic
Quoted 11 lines · Paulo Alcantara
If the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the
NO_REBOOTbit (CC: offset 0x3410:bit 5).The
NO_REBOOTbit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".This patch implements the logic where hardware has ability to set SPKR pin through a property named "pin-spkr"
I would call it "noreboot" and not pin-spkr since that's what it does in the end.
Quoted 1 line
and it's sampled low by default.
I think sample high is a safer default.
Quoted 66 lines
Signed-off-by Paulo Alcantara <[email protected]>--- hw/acpi/tco.c | 3 ++- hw/isa/lpc_ich9.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/i386/ich9.h | 11 +++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-)hw/acpi/tco.c +2
-1@@ -64,7 +64,8 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if ((lpc->pin_strap.spkr &ICH9_PS_SPKR_PIN_LOW ) && + !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;hw/isa/lpc_ich9.c +33
-0@@ -575,11 +575,49 @@ static void ich9_lpc_get_sci_int(Object *obj, Visitor *v,visit_type_uint32 (v, &value, name, errp); } +static void ich9_lpc_get_spkr_pin (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +ICH9LPCState *lpc = opaque; +uint8_t value = lpc->pin_strap.spkr; + +visit_type_uint8 (v, &value, name, errp); +} + +static void ich9_lpc_set_spkr_pin (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +ICH9LPCState *lpc = opaque; +Error *local_err =NULL ; +uint8_t value; +uint32_t *gcs; + +visit_type_uint8 (v, &value, name, &local_err); +if (local_err) { + goto out; + } + value &=ICH9_PS_SPKR_PIN_MASK ; +if (value &ICH9_PS_SPKR_PIN_HIGH ) { + gcs = (uint32_t *)&lpc->chip_config[ICH9_CC_GCS ]; + *gcs |=ICH9_CC_GCS_NO_REBOOT ; + } + lpc->pin_strap.spkr = value; +out: +error_propagate (errp, local_err); +} +static void ich9_lpc_add_properties (ICH9LPCState *lpc) {static const uint8_t acpi_enable_cmd =ICH9_APM_ACPI_ENABLE ;
hw/isa/lpc_ich9.c static void ich9_lpc_get_sci_int(Object *obj, Visitor *v, · line 623
Quoted 10 lines
hw/isa/lpc_ich9.c +5
-0static const uint8_t acpi_disable_cmd =ICH9_APM_ACPI_DISABLE ; + lpc->pin_strap.spkr =ICH9_PS_SPKR_PIN_DEFAULT ; +object_property_add (OBJECT (lpc),"pin-spkr" ,"uint8" , + ich9_lpc_get_spkr_pin, + ich9_lpc_set_spkr_pin, +NULL , lpc,NULL );object_property_add (OBJECT (lpc),ACPI_PM_PROP_SCI_INT ,"uint32" , ich9_lpc_get_sci_int,NULL ,NULL ,NULL ,NULL );
BTW it's easier to add simple properties in dc->props then you don't need all the error propagate code etc.
Quoted 17 lines
include/hw/i386/ich9.h +5
-0@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +uint8_t spkr; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];
include/hw/i386/ich9.h Object *ich9_lpc_find(void); · line 85
Quoted 9 lines
include/hw/i386/ich9.h +6
-0@@ -72,6 +77,12 @@ Object *ich9_lpc_find(void);#define Q35_MASK (bit, ms_bit, ls_bit) \ ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1))) +/* ICH9: Pin Straps */ +#define ICH9_PS_SPKR_PIN_LOW 0x01 +#define ICH9_PS_SPKR_PIN_HIGH 0x02 +#define ICH9_PS_SPKR_PIN_MASK 0x03 +#define ICH9_PS_SPKR_PIN_DEFAULT ICH9_PS_SPKR_PIN_LOW +
The interface seems a bit inconvenient to me. Why not make it a simple boolean property?
Quoted 5 lines
include/hw/i386/ich9.h +0
-0/* ICH9: Chipset Configuration Registers */ #define ICH9_CC_ADDR_MASK (ICH9_CC_SIZE - 1)Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v7 3/3] ich9: implement strap SPKR pin logic
Quoted 10 lines · On Sun, 28 Jun 2015 10:37:58 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 9 lines · Paulo Alcantara
If the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the
NO_REBOOTbit (CC: offset 0x3410:bit 5).The
NO_REBOOTbit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".
Quoted 5 lines
Quoted 2 lines
This patch implements the logic where hardware has ability to set SPKR pin through a property named "pin-spkr"
I would call it "noreboot" and not pin-spkr since that's what it does in the end.
Right. That's also more user intuitive, indeed.
Quoted 4 lines
Quoted 2 lines
and it's sampled low by default.
I think sample high is a safer default.
OK. I'll default it to high.
Quoted 70 lines
Quoted 70 lines
Signed-off-by Paulo Alcantara <[email protected]>--- hw/acpi/tco.c | 3 ++- hw/isa/lpc_ich9.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/i386/ich9.h | 11 +++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-)hw/acpi/tco.c +2
-1@@ -64,7 +64,8 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if ((lpc->pin_strap.spkr &ICH9_PS_SPKR_PIN_LOW ) && + !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;hw/isa/lpc_ich9.c +34
-0@@ -575,11 +575,49 @@ static void ich9_lpc_get_sci_int(Object *obj, Visitor *v,visit_type_uint32 (v, &value, name, errp); } +static void ich9_lpc_get_spkr_pin (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +ICH9LPCState *lpc = opaque; +uint8_t value = lpc->pin_strap.spkr; + +visit_type_uint8 (v, &value, name, errp); +} + +static void ich9_lpc_set_spkr_pin (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +ICH9LPCState *lpc = opaque; +Error *local_err =NULL ; +uint8_t value; +uint32_t *gcs; + +visit_type_uint8 (v, &value, name, &local_err); +if (local_err) { + goto out; + } + value &=ICH9_PS_SPKR_PIN_MASK ; +if (value &ICH9_PS_SPKR_PIN_HIGH ) { + gcs = (uint32_t *)&lpc->chip_config[ICH9_CC_GCS ]; + *gcs |=ICH9_CC_GCS_NO_REBOOT ; + } + lpc->pin_strap.spkr = value; +out: +error_propagate (errp, local_err); +} +static void ich9_lpc_add_properties (ICH9LPCState *lpc) {static const uint8_t acpi_enable_cmd =ICH9_APM_ACPI_ENABLE ;static const uint8_t acpi_disable_cmd =ICH9_APM_ACPI_DISABLE ; + lpc->pin_strap.spkr =ICH9_PS_SPKR_PIN_DEFAULT ;
Quoted 10 lines
hw/isa/lpc_ich9.c static void ich9_lpc_get_sci_int(Object *obj, Visitor *v, · line 623
Quoted 7 lines
hw/isa/lpc_ich9.c +4
-0+object_property_add (OBJECT (lpc),"pin-spkr" ,"uint8" , + ich9_lpc_get_spkr_pin, + ich9_lpc_set_spkr_pin, +NULL , lpc,NULL );object_property_add (OBJECT (lpc),ACPI_PM_PROP_SCI_INT ,"uint32" , ich9_lpc_get_sci_int,NULL ,NULL ,NULL ,NULL );BTW it's easier to add simple properties in
dc->propsthen you don't need all the error propagate code etc.
Hrm - good to know. I'll take a look at it. Thanks.
Quoted 23 lines
Quoted 23 lines
include/hw/i386/ich9.h +6
-0@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +uint8_t spkr; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];@@ -72,6 +77,12 @@ Object *ich9_lpc_find(void);#define Q35_MASK (bit, ms_bit, ls_bit) \ ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1))) +/* ICH9: Pin Straps */
Quoted 8 lines
include/hw/i386/ich9.h Object *ich9_lpc_find(void); · line 85
Quoted 5 lines
include/hw/i386/ich9.h +5
-0+#define ICH9_PS_SPKR_PIN_LOW 0x01 +#define ICH9_PS_SPKR_PIN_HIGH 0x02 +#define ICH9_PS_SPKR_PIN_MASK 0x03 +#define ICH9_PS_SPKR_PIN_DEFAULT ICH9_PS_SPKR_PIN_LOW +The interface seems a bit inconvenient to me. Why not make it a simple boolean property?
No real reason, actually. Since it has no more than 2 states (high and low), a boolean property would be appropriate. I'll make it boolean.
Thanks,
Paulo
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
PATCH v8 1/3 ich9: add TCO interface emulation
In reply to Paulo AlcantaraThis interface provides some registers within a 32-byte range and can be acessed 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 -- if TCO_EN bit is set -- on every timeout. If NO_REBOOT bit is not set in GCS (General Control and Status register), the system will be resetted upon second timeout if TCO_RLD register wasn't previously written to prevent timeout.
This patch adds support to TCO watchdog logic and few other features like mapping NMIs to SMIs (NMI2SMI_EN bit), system intruder detection, etc. are not implemented yet.
---
v1 -> v2:
* add migration support for TCO I/O device state
* wake up only when total time expired instead of every 0.6s
* some cleanup suggested by Paolo Bonzini
v2 -> v3:
* set SECOND_TO_STS and BOOT_STS bits in TCO2_STS instead
* improve handling of TCO_LOCK bit in TCO1_CNT register
v3 -> v4:
* fix some conflicts in hw/acpi/ich9.c after rebasing against master
* remove meaningless "use_tco" field from TCOIORegs structure
* add a object property named "enable_tco" and only enable TCO support
on pc-q35-2.4 and later
v4 -> v5:
* remove unused field (use_tco) in TCOIORegs structure
* move license to GPLv2+
v5 -> v6:
* remove "io_tco" field from ICH9LPCPMRegs structure since it's no longer used
* set ICH9_CC_GCS_NO_REBOOT bit by default in ICH9's LPC initialisation
v6 -> v7: (no changes)
--- hw/acpi/Makefile.objs | 2 +- hw/acpi/ich9.c | 55 ++++++++++- hw/acpi/tco.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_q35.c | 4 +- hw/isa/lpc_ich9.c | 16 ++- include/hw/acpi/ich9.h | 6 +- include/hw/acpi/tco.h | 82 +++++++++++++++ include/hw/boards.h | 3 +- include/hw/i386/ich9.h | 11 ++- include/hw/i386/pc.h | 1 + 10 files changed, 436 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/tco.c create mode 100644 include/hw/acpi/tco.h
hw/acpi/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o ich9.o pcihp.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/ich9.c +54 -1
105 lines not on this page · raw message
hw/acpi/tco.c new file +264 -0
264 lines not on this page · raw message
hw/i386/pc_q35.c +3 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !mc->no_tco);/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
@@ -393,6 +393,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->default_machine_opts ="firmware=bios-256k.bin" ; m->default_display ="std" ; m->no_floppy =1 ; + m->no_tco =0 ; m->alias ="q35" ; }
@@ -404,6 +405,7 @@ static void pc_q35_2_3_machine_options(MachineClass *m) {pc_q35_2_4_machine_options (m); m->no_floppy =0 ; + m->no_tco =1 ; m->alias =NULL ;SET_MACHINE_COMPAT (m,PC_COMPAT_2_3 ); }
hw/isa/lpc_ich9.c +14 -2
@@ -138,6 +138,7 @@ static void ich9_cc_reset(ICH9LPCState *lpc)pci_set_long (c +ICH9_CC_D27IR ,ICH9_CC_DIR_DEFAULT );pci_set_long (c +ICH9_CC_D26IR ,ICH9_CC_DIR_DEFAULT );pci_set_long (c +ICH9_CC_D25IR ,ICH9_CC_DIR_DEFAULT ); +pci_set_long (c +ICH9_CC_GCS ,ICH9_CC_GCS_DEFAULT );ich9_cc_update (lpc); }
@@ -313,6 +314,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] &
@@ -357,11 +368,12 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool enable_tco) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); +ich9_pm_init (lpc_pci, &lpc->pm, enable_tco, +qemu_allocate_irq (ich9_set_sci, lpc,0 ));ich9_lpc_reset (&lpc->d.qdev); }
include/hw/acpi/ich9.h +5 -1
@@ -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 { /*
@@ -54,9 +55,12 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +bool enable_tco; + +TCOIORegs tco_regs; } ICH9LPCPMRegs; -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool enable_tco,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;
include/hw/acpi/tco.h new file +82 -0
82 lines not on this page · raw message
include/hw/boards.h +2 -1
@@ -99,7 +99,8 @@ struct MachineClass { no_floppy:1, no_cdrom:1, no_sdcard:1, - has_dynamic_sysbus:1; + has_dynamic_sysbus:1, + no_tco:1;int is_default;const char *default_machine_opts;const char *default_boot_order;
include/hw/i386/ich9.h +10 -1
@@ -17,9 +17,12 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool enable_tco);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"
@@ -90,6 +93,9 @@ Object *ich9_lpc_find(void);#define ICH9_CC_DIR_MASK 0x7#define ICH9_CC_OIC 0x31FF#define ICH9_CC_OIC_AEN 0x1 +#define ICH9_CC_GCS 0x3410 +#define ICH9_CC_GCS_DEFAULT 0x00000020 +#define ICH9_CC_GCS_NO_REBOOT (1 << 5)/* D28:F[0-5] */ #define ICH9_PCIE_DEV 28
@@ -186,7 +192,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
include/hw/i386/pc.h +1 -0
@@ -89,6 +89,7 @@ typedef struct PcPciInfo {#define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"#define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"#define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len" +#define ACPI_PM_PROP_TCO_ENABLED "enable_tco"struct PcGuestInfo {bool isapc_ram_fw;
Signature · 1 line
2.1.0
PATCH v8 2/3 tests: add testcase for TCO watchdog emulation
This patch adds a testcase that covers the following:
1) TCO default values
2) first and second TCO timeout
3) watch and validate ticks counter through TCO_RLD register
4) maximum supported TCO timeout (0x3ff)
5) watchdog actions (pause/reset/shutdown/none) upon second TCO timeout
6) set and get of TCO control and status bits
---
v1 -> v2:
* some cleanup
* add test for TCO_LOCK bit
v2 -> v3:
* add tests for TCO control & status bits
* fix check of SECOND_TO_STS bit (it's set in TCO2_STS reg)
v3 -> v4:
* add more description to commit log
* use RCBA_BASE_ADDR macro defintion from hw/i386/ich9-cc.h instead
v4 -> v5:
* use modified macros (now prefixed with ICH9_) from ich9-cc.h
* move license to GPLv2+
v5 -> v6:
* remove include of "hw/i386/ich9-cc.h" since it's no longer exist
v6 -> v7: (no changes)
--- tests/Makefile | 2 + tests/tco-test.c | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+) create mode 100644 tests/tco-test.c
tests/Makefile +2 -0
@@ -152,6 +152,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)
@@ -370,6 +371,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 +460 -0
460 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v8 3/3 ich9: implement strap SPKR pin logic
In reply to Paulo AlcantaraIf the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the NO_REBOOT bit (CC: offset 0x3410:bit 5).
The NO_REBOOT bit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".
This patch implements the logic where hardware has ability to set SPKR pin through a property named "noreboot" and it's sampled high by default.
---
v7 -> v8:
* change property name to "noreboot"
* default "noreboot" property to high
* define property in dc->props
* update tco tests to support and exercise "noreboot" property
--- hw/acpi/tco.c | 2 +- hw/isa/lpc_ich9.c | 6 ++++++ include/hw/i386/ich9.h | 5 +++++ tests/tco-test.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-)
hw/acpi/tco.c +1 -1
@@ -64,7 +64,7 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if (!lpc->pin_strap.spkr_hi && !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;
hw/isa/lpc_ich9.c +6 -0
@@ -688,6 +688,11 @@ static const VMStateDescription vmstate_ich9_lpc = { } }; +static Property ich9_lpc_properties[] = { +DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_END_OF_LIST (), +}; +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -699,6 +704,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) dc->reset = ich9_lpc_reset; k->init = ich9_lpc_init; dc->vmsd = &vmstate_ich9_lpc; + dc->props = ich9_lpc_properties; k->config_write = ich9_lpc_config_write; dc->desc ="ICH9 LPC bridge" ; k->vendor_id =PCI_VENDOR_ID_INTEL ;
include/hw/i386/ich9.h +5 -0
@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +bool spkr_hi; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];
tests/tco-test.c +16 -2
@@ -42,6 +42,7 @@ enum { typedef struct { const char *args; + bool noreboot; QPCIDevice *dev; void *lpc_base; void *tco_io_base;
@@ -53,7 +54,9 @@ static void test_init(TestData *d)QTestState *qs;char *s; - s =g_strdup_printf ("-machine q35 %s" , !d->args ?"" : d->args); + s =g_strdup_printf ("-machine q35 %s %s" , + d->noreboot ?"" :"-global ICH9-LPC.noreboot=false" , + !d->args ?"" : d->args); qs =qtest_start (s);qtest_irq_intercept_in (qs,"ioapic" );g_free (s);
@@ -135,6 +138,7 @@ static void test_tco_defaults(void)TestData d; d.args =NULL ; + d.noreboot = true;test_init (&d); g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_RLD), ==,TCO_RLD_DEFAULT );
@@ -167,6 +171,7 @@ static void test_tco_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
@@ -210,6 +215,7 @@ static void test_tco_max_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
@@ -253,6 +259,7 @@ static void test_tco_second_timeout_pause(void)QDict *ad; td.args ="-watchdog-action pause" ; + td.noreboot = false;test_init (&td);stop_tco (&td);
@@ -277,6 +284,7 @@ static void test_tco_second_timeout_reset(void)QDict *ad; td.args ="-watchdog-action reset" ; + td.noreboot = false;test_init (&td);stop_tco (&td);
@@ -301,6 +309,7 @@ static void test_tco_second_timeout_shutdown(void)QDict *ad; td.args ="-watchdog-action shutdown" ; + td.noreboot = false;test_init (&td);stop_tco (&td);
@@ -325,6 +334,7 @@ static void test_tco_second_timeout_none(void)QDict *ad; td.args ="-watchdog-action none" ; + td.noreboot = false;test_init (&td);stop_tco (&td);
@@ -349,6 +359,7 @@ static void test_tco_ticks_counter(void)uint16_t rld; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
@@ -375,6 +386,7 @@ static void test_tco1_control_bits(void)uint16_t val; d.args =NULL ; + d.noreboot = true;test_init (&d); val =TCO_LOCK ;
@@ -394,6 +406,7 @@ static void test_tco1_status_bits(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
@@ -421,7 +434,8 @@ static void test_tco2_status_bits(void)uint16_t val;int ret; - d.args ="-watchdog-action none" ; + d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v8 3/3] ich9: implement strap SPKR pin logic
Quoted 5 lines · Paulo Alcantara
If the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the
NO_REBOOTbit (CC: offset 0x3410:bit 5).
Quoted 7 lines
The
NO_REBOOTbit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".This patch implements the logic where hardware has ability to set SPKR pin through a property named "noreboot" and it's sampled high by default.
I know Michael suggested this, but I think default high is a worse default. It does not allow recovering from a hard lockup where you cannot process an NMI, unlike all other watchdogs implemented by QEMU. In fact, the Linux driver fails to start if the strap is high.
My theory is that hardware manufacturers should only set the strap high if they want the firmware to have total control of the watchdog via SMIs (TCO_EN).
If it is just a matter of being late in 2.4, just delay everything to 2.5. It doesn't require any more work from Paulo, as you can just flip the default yourself without adding a new machine type (in fact I'm still not sure why machine types for Q35 are versioned, since migration is not supported...).
Paolo
Quoted 181 lines
Signed-off-by Paulo Alcantara <[email protected]>---
v7 -> v8:
* change property name to "noreboot"
* default "noreboot" property to high
* define property indc->props
* update tco tests to support and exercise "noreboot" property--- hw/acpi/tco.c | 2 +- hw/isa/lpc_ich9.c | 6 ++++++ include/hw/i386/ich9.h | 5 +++++ tests/tco-test.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-)hw/acpi/tco.c +1
-1@@ -64,7 +64,7 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if (!lpc->pin_strap.spkr_hi && !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;hw/isa/lpc_ich9.c +6
-0@@ -688,6 +688,11 @@ static const VMStateDescription vmstate_ich9_lpc = { } }; +static Property ich9_lpc_properties[] = { +DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_END_OF_LIST (), +}; +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -699,6 +704,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) dc->reset = ich9_lpc_reset; k->init = ich9_lpc_init; dc->vmsd = &vmstate_ich9_lpc; + dc->props = ich9_lpc_properties; k->config_write = ich9_lpc_config_write; dc->desc ="ICH9 LPC bridge" ; k->vendor_id =PCI_VENDOR_ID_INTEL ;include/hw/i386/ich9.h +5
-0@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +bool spkr_hi; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];tests/tco-test.c +16
-2@@ -42,6 +42,7 @@ enum { typedef struct { const char *args; + bool noreboot; QPCIDevice *dev; void *lpc_base; void *tco_io_base;@@ -53,7 +54,9 @@ static void test_init(TestData *d)QTestState *qs;char *s; - s =g_strdup_printf ("-machine q35 %s" , !d->args ?"" : d->args); + s =g_strdup_printf ("-machine q35 %s %s" , + d->noreboot ?"" :"-global ICH9-LPC.noreboot=false" , + !d->args ?"" : d->args); qs =qtest_start (s);qtest_irq_intercept_in (qs,"ioapic" );g_free (s);@@ -135,6 +138,7 @@ static void test_tco_defaults(void)TestData d; d.args =NULL ; + d.noreboot = true;test_init (&d); g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_RLD), ==,TCO_RLD_DEFAULT );@@ -167,6 +171,7 @@ static void test_tco_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -210,6 +215,7 @@ static void test_tco_max_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -253,6 +259,7 @@ static void test_tco_second_timeout_pause(void)QDict *ad; td.args ="-watchdog-action pause" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -277,6 +284,7 @@ static void test_tco_second_timeout_reset(void)QDict *ad; td.args ="-watchdog-action reset" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -301,6 +309,7 @@ static void test_tco_second_timeout_shutdown(void)QDict *ad; td.args ="-watchdog-action shutdown" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -325,6 +334,7 @@ static void test_tco_second_timeout_none(void)QDict *ad; td.args ="-watchdog-action none" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -349,6 +359,7 @@ static void test_tco_ticks_counter(void)uint16_t rld; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -375,6 +386,7 @@ static void test_tco1_control_bits(void)uint16_t val; d.args =NULL ; + d.noreboot = true;test_init (&d); val =TCO_LOCK ;@@ -394,6 +406,7 @@ static void test_tco1_status_bits(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -421,7 +434,8 @@ static void test_tco2_status_bits(void)uint16_t val;int ret; - d.args ="-watchdog-action none" ; + d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
Re: [Qemu-devel] [PATCH v8 3/3] ich9: implement strap SPKR pin logic
Quoted 25 lines · Paolo Bonzini
Quoted 5 lines · Paulo Alcantara
If the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the
NO_REBOOTbit (CC: offset 0x3410:bit 5).Quoted 7 lines
The
NO_REBOOTbit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".This patch implements the logic where hardware has ability to set SPKR pin through a property named "noreboot" and it's sampled high by default.
I know Michael suggested this, but I think default high is a worse default. It does not allow recovering from a hard lockup where you cannot process an NMI, unlike all other watchdogs implemented by QEMU. In fact, the Linux driver fails to start if the strap is high.
My theory is that hardware manufacturers should only set the strap high if they want the firmware to have total control of the watchdog via SMIs (
TCO_EN).
Quoted 7 lines
If it is just a matter of being late in 2.4, just delay everything to 2.5. It doesn't require any more work from Paulo, as you can just flip the default yourself without adding a new machine type (in fact I'm still not sure why machine types for Q35 are versioned, since migration is not supported...).
Paolo
I don't think we should defer the whole series because of the argument about the default. I've merged these patches, I you like, pls send a one-line patch on top to flip the default with some info on how it was tested, and we can discuss it separately.
Makes sense?
BTW 2.4 makes qemu versioned because ahci finally supports migration so yes, we'll have to version from now on.
Quoted 181 lines
Quoted 181 lines
Signed-off-by Paulo Alcantara <[email protected]>---
v7 -> v8:
* change property name to "noreboot"
* default "noreboot" property to high
* define property indc->props
* update tco tests to support and exercise "noreboot" property--- hw/acpi/tco.c | 2 +- hw/isa/lpc_ich9.c | 6 ++++++ include/hw/i386/ich9.h | 5 +++++ tests/tco-test.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-)hw/acpi/tco.c +1
-1@@ -64,7 +64,7 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if (!lpc->pin_strap.spkr_hi && !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;hw/isa/lpc_ich9.c +6
-0@@ -688,6 +688,11 @@ static const VMStateDescription vmstate_ich9_lpc = { } }; +static Property ich9_lpc_properties[] = { +DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_END_OF_LIST (), +}; +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -699,6 +704,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) dc->reset = ich9_lpc_reset; k->init = ich9_lpc_init; dc->vmsd = &vmstate_ich9_lpc; + dc->props = ich9_lpc_properties; k->config_write = ich9_lpc_config_write; dc->desc ="ICH9 LPC bridge" ; k->vendor_id =PCI_VENDOR_ID_INTEL ;include/hw/i386/ich9.h +5
-0@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +bool spkr_hi; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];tests/tco-test.c +16
-2@@ -42,6 +42,7 @@ enum { typedef struct { const char *args; + bool noreboot; QPCIDevice *dev; void *lpc_base; void *tco_io_base;@@ -53,7 +54,9 @@ static void test_init(TestData *d)QTestState *qs;char *s; - s =g_strdup_printf ("-machine q35 %s" , !d->args ?"" : d->args); + s =g_strdup_printf ("-machine q35 %s %s" , + d->noreboot ?"" :"-global ICH9-LPC.noreboot=false" , + !d->args ?"" : d->args); qs =qtest_start (s);qtest_irq_intercept_in (qs,"ioapic" );g_free (s);@@ -135,6 +138,7 @@ static void test_tco_defaults(void)TestData d; d.args =NULL ; + d.noreboot = true;test_init (&d); g_assert_cmpint(qpci_io_readw(d.dev, d.tco_io_base + TCO_RLD), ==,TCO_RLD_DEFAULT );@@ -167,6 +171,7 @@ static void test_tco_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -210,6 +215,7 @@ static void test_tco_max_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -253,6 +259,7 @@ static void test_tco_second_timeout_pause(void)QDict *ad; td.args ="-watchdog-action pause" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -277,6 +284,7 @@ static void test_tco_second_timeout_reset(void)QDict *ad; td.args ="-watchdog-action reset" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -301,6 +309,7 @@ static void test_tco_second_timeout_shutdown(void)QDict *ad; td.args ="-watchdog-action shutdown" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -325,6 +334,7 @@ static void test_tco_second_timeout_none(void)QDict *ad; td.args ="-watchdog-action none" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -349,6 +359,7 @@ static void test_tco_ticks_counter(void)uint16_t rld; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -375,6 +386,7 @@ static void test_tco1_control_bits(void)uint16_t val; d.args =NULL ; + d.noreboot = true;test_init (&d); val =TCO_LOCK ;@@ -394,6 +406,7 @@ static void test_tco1_status_bits(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -421,7 +434,8 @@ static void test_tco2_status_bits(void)uint16_t val;int ret; - d.args ="-watchdog-action none" ; + d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
Re: [Qemu-devel] [PATCH v8 3/3] ich9: implement strap SPKR pin logic
Quoted 6 lines · Michael S. Tsirkin
I don't think we should defer the whole series because of the argument about the default. I've merged these patches, I you like, pls send a one-line patch on top to flip the default with some info on how it was tested, and we can discuss it separately.
Makes sense?
Perfect.
Paolo
Quoted 4 lines
BTW 2.4 makes qemu versioned because ahci finally supports migration so yes, we'll have to version from now on.
Re: [Qemu-devel] [PATCH v8 3/3] ich9: implement strap SPKR pin logic
In reply to Michael S. TsirkinQuoted 14 lines · On Wed, 1 Jul 2015 15:31:31 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Paulo Alcantara
If the signal is sampled high, this indicates that the system is strapped to the "No Reboot" mode (ICH9 will disable the TCO Timer system reboot feature). The status of this strap is readable via the
NO_REBOOTbit (CC: offset 0x3410:bit 5).The
NO_REBOOTbit is set when SPKR pin on ICH9 is sampled high. This bit may be set or cleared by software if the strap is sampled low but may not override the strap when it indicates "No Reboot".
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
This patch implements the logic where hardware has ability to set SPKR pin through a property named "noreboot" and it's sampled high by default.
I know Michael suggested this, but I think default high is a worse default. It does not allow recovering from a hard lockup where you cannot process an NMI, unlike all other watchdogs implemented by QEMU. In fact, the Linux driver fails to start if the strap is high.
No, the iTCO_wdt driver won't fail to start. It actually depends on whether RCBA BAR is set. However, ICH9 will just ignore whether NO_REBOOT is set or unset when SPKR pin is high.
I think you forgot to apply my SeaBIOS patch that sets RCBA BAR so it failed to start. We should also make sure it's applied once TCO patches get upstream.
Thanks,
Paulo
Quoted 209 lines
Quoted 5 lines
My theory is that hardware manufacturers should only set the strap high if they want the firmware to have total control of the watchdog via SMIs (
TCO_EN).Quoted 7 lines
If it is just a matter of being late in 2.4, just delay everything to 2.5. It doesn't require any more work from Paulo, as you can just flip the default yourself without adding a new machine type (in fact I'm still not sure why machine types for Q35 are versioned, since migration is not supported...).
Paolo
I don't think we should defer the whole series because of the argument about the default. I've merged these patches, I you like, pls send a one-line patch on top to flip the default with some info on how it was tested, and we can discuss it separately.
Makes sense?
BTW 2.4 makes qemu versioned because ahci finally supports migration so yes, we'll have to version from now on.
Quoted 184 lines
Quoted 184 lines
Signed-off-by Paulo Alcantara <[email protected]>---
v7 -> v8:
* change property name to "noreboot"
* default "noreboot" property to high
* define property indc->props
* update tco tests to support and exercise "noreboot" property--- hw/acpi/tco.c | 2 +- hw/isa/lpc_ich9.c | 6 ++++++ include/hw/i386/ich9.h | 5 +++++ tests/tco-test.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-)hw/acpi/tco.c +1
-1@@ -64,7 +64,7 @@ static void tco_timer_expired(void *opaque) tr->tco.sts2 |=TCO_BOOT_STS ; tr->timeouts_no =0 ; -if (!(gcs &ICH9_CC_GCS_NO_REBOOT )) { +if (!lpc->pin_strap.spkr_hi && !(gcs &ICH9_CC_GCS_NO_REBOOT )) {watchdog_perform_action ();tco_timer_stop (tr);return ;hw/isa/lpc_ich9.c +5
-0@@ -688,6 +688,11 @@ static const VMStateDescription vmstate_ich9_lpc = { } }; +static Property ich9_lpc_properties[] = { +DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_END_OF_LIST (), +}; +static void ich9_lpc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc = DEVICE_CLASS(klass);hw/isa/lpc_ich9.c +1
-0@@ -699,6 +704,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data) dc->reset = ich9_lpc_reset; k->init = ich9_lpc_init; dc->vmsd = &vmstate_ich9_lpc; + dc->props = ich9_lpc_properties; k->config_write = ich9_lpc_config_write; dc->desc ="ICH9 LPC bridge" ; k->vendor_id =PCI_VENDOR_ID_INTEL ;include/hw/i386/ich9.h +5
-0@@ -46,6 +46,11 @@ typedef struct ICH9LPCState {ICH9LPCPMRegs pm;uint32_t sci_level;/* track sci level */ +/* 2.24 Pin Straps */ +struct { +bool spkr_hi; + } pin_strap; +/* 10.1 Chipset Configuration registers(Memory Space) which is pointed by RCBA */ uint8_t chip_config[ICH9_CC_SIZE ];tests/tco-test.c +4
-1@@ -42,6 +42,7 @@ enum { typedef struct { const char *args; + bool noreboot; QPCIDevice *dev; void *lpc_base; void *tco_io_base;@@ -53,7 +54,9 @@ static void test_init(TestData *d)QTestState *qs;char *s; - s =g_strdup_printf ("-machine q35 %s" , !d->args ?"" : d->args); + s =g_strdup_printf ("-machine q35 %s %s" , + d->noreboot ? "" : "-global ICH9-LPC.noreboot=false", + !d->args ?"" : d->args); qs =qtest_start (s);qtest_irq_intercept_in(qs, "ioapic"); g_free(s);tests/tco-test.c +12
-1@@ -135,6 +138,7 @@ static void test_tco_defaults(void)TestData d; d.args =NULL ; + d.noreboot = true;test_init (&d);g_assert_cmpint (qpci_io_readw (d.dev, d.tco_io_base + TCO_RLD), ==, TCO_RLD_DEFAULT);@@ -167,6 +171,7 @@ static void test_tco_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -210,6 +215,7 @@ static void test_tco_max_timeout(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -253,6 +259,7 @@ static void test_tco_second_timeout_pause(void) QDict *ad; td.args ="-watchdog-action pause" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -277,6 +284,7 @@ static void test_tco_second_timeout_reset(void) QDict *ad; td.args ="-watchdog-action reset" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -301,6 +309,7 @@ static void test_tco_second_timeout_shutdown(void) QDict *ad; td.args ="-watchdog-action shutdown" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -325,6 +334,7 @@ static void test_tco_second_timeout_none(void)QDict *ad; td.args ="-watchdog-action none" ; + td.noreboot = false;test_init (&td);stop_tco (&td);@@ -349,6 +359,7 @@ static void test_tco_ticks_counter(void)uint16_t rld; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -375,6 +386,7 @@ static void test_tco1_control_bits(void)uint16_t val; d.args =NULL ; + d.noreboot = true;test_init (&d); val =TCO_LOCK ;@@ -394,6 +406,7 @@ static void test_tco1_status_bits(void)int ret; d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);@@ -421,7 +434,8 @@ static void test_tco2_status_bits(void)uint16_t val;int ret; - d.args ="-watchdog-action none" ; + d.args =NULL ; + d.noreboot = true;test_init (&d);stop_tco (&d);
Signature · 2 lines
Paulo Alcantara, C.E.S.A.R Speaking for myself only.
Re: [Qemu-devel] [PATCH v8 3/3] ich9: implement strap SPKR pin logic
Quoted 3 lines · Paulo Alcantara
No, the
iTCO_wdtdriver won't fail to start. It actually depends on whether RCBA BAR is set. However, ICH9 will just ignore whetherNO_REBOOTis set or unset when SPKR pin is high.
This is the code I was referring to, in iTCO_wdt_start:
/* disable chipset's NO_REBOOT bit */
if (iTCO_wdt_unset_NO_REBOOT_bit()) {
spin_unlock(&iTCO_wdt_private.io_lock);
pr_err("failed to reset NO_REBOOT flag, reboot disabled by hardware/BIOS\n");
return -EIO;
}Paolo