2009-04-25 16:56:19 +04:00
|
|
|
/*
|
|
|
|
* Virtual hardware watchdog.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* 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
|
2009-07-17 00:47:01 +04:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2009-04-25 16:56:19 +04:00
|
|
|
*
|
|
|
|
* By Richard W.M. Jones (rjones@redhat.com).
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:30 +03:00
|
|
|
#include "qemu/osdep.h"
|
2009-04-25 16:56:19 +04:00
|
|
|
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "sysemu/watchdog.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
/*#define I6300ESB_DEBUG 1*/
|
|
|
|
|
|
|
|
#ifdef I6300ESB_DEBUG
|
|
|
|
#define i6300esb_debug(fs,...) \
|
|
|
|
fprintf(stderr,"i6300esb: %s: "fs,__func__,##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define i6300esb_debug(fs,...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* PCI configuration registers */
|
|
|
|
#define ESB_CONFIG_REG 0x60 /* Config register */
|
|
|
|
#define ESB_LOCK_REG 0x68 /* WDT lock register */
|
|
|
|
|
|
|
|
/* Memory mapped registers (offset from base address) */
|
|
|
|
#define ESB_TIMER1_REG 0x00 /* Timer1 value after each reset */
|
|
|
|
#define ESB_TIMER2_REG 0x04 /* Timer2 value after each reset */
|
|
|
|
#define ESB_GINTSR_REG 0x08 /* General Interrupt Status Register */
|
|
|
|
#define ESB_RELOAD_REG 0x0c /* Reload register */
|
|
|
|
|
|
|
|
/* Lock register bits */
|
|
|
|
#define ESB_WDT_FUNC (0x01 << 2) /* Watchdog functionality */
|
|
|
|
#define ESB_WDT_ENABLE (0x01 << 1) /* Enable WDT */
|
|
|
|
#define ESB_WDT_LOCK (0x01 << 0) /* Lock (nowayout) */
|
|
|
|
|
|
|
|
/* Config register bits */
|
|
|
|
#define ESB_WDT_REBOOT (0x01 << 5) /* Enable reboot on timeout */
|
|
|
|
#define ESB_WDT_FREQ (0x01 << 2) /* Decrement frequency */
|
|
|
|
#define ESB_WDT_INTTYPE (0x11 << 0) /* Interrupt type on timer1 timeout */
|
|
|
|
|
|
|
|
/* Reload register bits */
|
|
|
|
#define ESB_WDT_RELOAD (0x01 << 8) /* prevent timeout */
|
|
|
|
|
|
|
|
/* Magic constants */
|
|
|
|
#define ESB_UNLOCK1 0x80 /* Step 1 to unlock reset registers */
|
|
|
|
#define ESB_UNLOCK2 0x86 /* Step 2 to unlock reset registers */
|
|
|
|
|
|
|
|
/* Device state. */
|
|
|
|
struct I6300State {
|
2009-08-21 12:31:33 +04:00
|
|
|
PCIDevice dev;
|
2011-08-08 17:09:20 +04:00
|
|
|
MemoryRegion io_mem;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
int reboot_enabled; /* "Reboot" on timer expiry. The real action
|
|
|
|
* performed depends on the -watchdog-action
|
|
|
|
* param passed on QEMU command line.
|
|
|
|
*/
|
|
|
|
int clock_scale; /* Clock scale. */
|
|
|
|
#define CLOCK_SCALE_1KHZ 0
|
|
|
|
#define CLOCK_SCALE_1MHZ 1
|
|
|
|
|
|
|
|
int int_type; /* Interrupt type generated. */
|
|
|
|
#define INT_TYPE_IRQ 0 /* APIC 1, INT 10 */
|
|
|
|
#define INT_TYPE_SMI 2
|
|
|
|
#define INT_TYPE_DISABLED 3
|
|
|
|
|
|
|
|
int free_run; /* If true, reload timer on expiry. */
|
|
|
|
int locked; /* If true, enabled field cannot be changed. */
|
|
|
|
int enabled; /* If true, watchdog is enabled. */
|
|
|
|
|
|
|
|
QEMUTimer *timer; /* The actual watchdog timer. */
|
|
|
|
|
|
|
|
uint32_t timer1_preload; /* Values preloaded into timer1, timer2. */
|
|
|
|
uint32_t timer2_preload;
|
|
|
|
int stage; /* Stage (1 or 2). */
|
|
|
|
|
|
|
|
int unlock_state; /* Guest writes 0x80, 0x86 to unlock the
|
|
|
|
* registers, and we transition through
|
|
|
|
* states 0 -> 1 -> 2 when this happens.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int previous_reboot_flag; /* If the watchdog caused the previous
|
|
|
|
* reboot, this flag will be set.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-13 03:43:25 +03:00
|
|
|
#define TYPE_WATCHDOG_I6300ESB_DEVICE "i6300esb"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(I6300State, WATCHDOG_I6300ESB_DEVICE)
|
2015-05-13 03:43:25 +03:00
|
|
|
|
2009-04-25 16:56:19 +04:00
|
|
|
/* This function is called when the watchdog has either been enabled
|
|
|
|
* (hence it starts counting down) or has been keep-alived.
|
|
|
|
*/
|
|
|
|
static void i6300esb_restart_timer(I6300State *d, int stage)
|
|
|
|
{
|
|
|
|
int64_t timeout;
|
|
|
|
|
|
|
|
if (!d->enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->stage = stage;
|
|
|
|
|
|
|
|
if (d->stage <= 1)
|
|
|
|
timeout = d->timer1_preload;
|
|
|
|
else
|
|
|
|
timeout = d->timer2_preload;
|
|
|
|
|
|
|
|
if (d->clock_scale == CLOCK_SCALE_1KHZ)
|
|
|
|
timeout <<= 15;
|
|
|
|
else
|
|
|
|
timeout <<= 5;
|
|
|
|
|
2015-08-24 20:29:45 +03:00
|
|
|
/* Get the timeout in nanoseconds. */
|
|
|
|
|
|
|
|
timeout = timeout * 30; /* on a PCI bus, 1 tick is 30 ns*/
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout);
|
|
|
|
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_mod(d->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timeout);
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is called when the guest disables the watchdog. */
|
|
|
|
static void i6300esb_disable_timer(I6300State *d)
|
|
|
|
{
|
|
|
|
i6300esb_debug("timer disabled\n");
|
|
|
|
|
2013-08-21 19:03:08 +04:00
|
|
|
timer_del(d->timer);
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-08 17:59:55 +03:00
|
|
|
static void i6300esb_reset(DeviceState *dev)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
2011-12-04 22:22:06 +04:00
|
|
|
PCIDevice *pdev = PCI_DEVICE(dev);
|
2015-05-13 03:43:25 +03:00
|
|
|
I6300State *d = WATCHDOG_I6300ESB_DEVICE(pdev);
|
2010-12-08 17:59:55 +03:00
|
|
|
|
|
|
|
i6300esb_debug("I6300State = %p\n", d);
|
|
|
|
|
2009-04-25 16:56:19 +04:00
|
|
|
i6300esb_disable_timer(d);
|
2010-12-08 17:59:55 +03:00
|
|
|
|
2010-09-24 19:08:06 +04:00
|
|
|
/* NB: Don't change d->previous_reboot_flag in this function. */
|
|
|
|
|
2010-12-08 17:59:55 +03:00
|
|
|
d->reboot_enabled = 1;
|
|
|
|
d->clock_scale = CLOCK_SCALE_1KHZ;
|
|
|
|
d->int_type = INT_TYPE_IRQ;
|
|
|
|
d->free_run = 0;
|
|
|
|
d->locked = 0;
|
|
|
|
d->enabled = 0;
|
|
|
|
d->timer1_preload = 0xfffff;
|
|
|
|
d->timer2_preload = 0xfffff;
|
|
|
|
d->stage = 1;
|
|
|
|
d->unlock_state = 0;
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is called when the watchdog expires. Note that
|
|
|
|
* the hardware has two timers, and so expiry happens in two stages.
|
|
|
|
* If d->stage == 1 then we perform the first stage action (usually,
|
|
|
|
* sending an interrupt) and then restart the timer again for the
|
|
|
|
* second stage. If the second stage expires then the watchdog
|
|
|
|
* really has run out.
|
|
|
|
*/
|
|
|
|
static void i6300esb_timer_expired(void *vp)
|
|
|
|
{
|
2009-10-15 00:58:14 +04:00
|
|
|
I6300State *d = vp;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
i6300esb_debug("stage %d\n", d->stage);
|
|
|
|
|
|
|
|
if (d->stage == 1) {
|
|
|
|
/* What to do at the end of stage 1? */
|
|
|
|
switch (d->int_type) {
|
|
|
|
case INT_TYPE_IRQ:
|
|
|
|
fprintf(stderr, "i6300esb_timer_expired: I would send APIC 1 INT 10 here if I knew how (XXX)\n");
|
|
|
|
break;
|
|
|
|
case INT_TYPE_SMI:
|
|
|
|
fprintf(stderr, "i6300esb_timer_expired: I would send SMI here if I knew how (XXX)\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the second stage. */
|
|
|
|
i6300esb_restart_timer(d, 2);
|
|
|
|
} else {
|
|
|
|
/* Second stage expired, reboot for real. */
|
|
|
|
if (d->reboot_enabled) {
|
|
|
|
d->previous_reboot_flag = 1;
|
|
|
|
watchdog_perform_action(); /* This reboots, exits, etc */
|
2019-05-28 19:40:20 +03:00
|
|
|
i6300esb_reset(DEVICE(d));
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* In "free running mode" we start stage 1 again. */
|
|
|
|
if (d->free_run)
|
|
|
|
i6300esb_restart_timer(d, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i6300esb_config_write(PCIDevice *dev, uint32_t addr,
|
|
|
|
uint32_t data, int len)
|
|
|
|
{
|
2015-05-13 03:43:25 +03:00
|
|
|
I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
|
2009-04-25 16:56:19 +04:00
|
|
|
int old;
|
|
|
|
|
|
|
|
i6300esb_debug("addr = %x, data = %x, len = %d\n", addr, data, len);
|
|
|
|
|
|
|
|
if (addr == ESB_CONFIG_REG && len == 2) {
|
|
|
|
d->reboot_enabled = (data & ESB_WDT_REBOOT) == 0;
|
|
|
|
d->clock_scale =
|
|
|
|
(data & ESB_WDT_FREQ) != 0 ? CLOCK_SCALE_1MHZ : CLOCK_SCALE_1KHZ;
|
|
|
|
d->int_type = (data & ESB_WDT_INTTYPE);
|
|
|
|
} else if (addr == ESB_LOCK_REG && len == 1) {
|
|
|
|
if (!d->locked) {
|
|
|
|
d->locked = (data & ESB_WDT_LOCK) != 0;
|
|
|
|
d->free_run = (data & ESB_WDT_FUNC) != 0;
|
|
|
|
old = d->enabled;
|
|
|
|
d->enabled = (data & ESB_WDT_ENABLE) != 0;
|
|
|
|
if (!old && d->enabled) /* Enabled transitioned from 0 -> 1 */
|
|
|
|
i6300esb_restart_timer(d, 1);
|
|
|
|
else if (!d->enabled)
|
|
|
|
i6300esb_disable_timer(d);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pci_default_write_config(dev, addr, data, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t i6300esb_config_read(PCIDevice *dev, uint32_t addr, int len)
|
|
|
|
{
|
2015-05-13 03:43:25 +03:00
|
|
|
I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
|
2009-04-25 16:56:19 +04:00
|
|
|
uint32_t data;
|
|
|
|
|
|
|
|
i6300esb_debug ("addr = %x, len = %d\n", addr, len);
|
|
|
|
|
|
|
|
if (addr == ESB_CONFIG_REG && len == 2) {
|
|
|
|
data =
|
|
|
|
(d->reboot_enabled ? 0 : ESB_WDT_REBOOT) |
|
|
|
|
(d->clock_scale == CLOCK_SCALE_1MHZ ? ESB_WDT_FREQ : 0) |
|
|
|
|
d->int_type;
|
|
|
|
return data;
|
|
|
|
} else if (addr == ESB_LOCK_REG && len == 1) {
|
|
|
|
data =
|
|
|
|
(d->free_run ? ESB_WDT_FUNC : 0) |
|
|
|
|
(d->locked ? ESB_WDT_LOCK : 0) |
|
|
|
|
(d->enabled ? ESB_WDT_ENABLE : 0);
|
|
|
|
return data;
|
|
|
|
} else {
|
|
|
|
return pci_default_read_config(dev, addr, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t i6300esb_mem_readb(void *vp, hwaddr addr)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
|
|
|
i6300esb_debug ("addr = %x\n", (int) addr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t i6300esb_mem_readw(void *vp, hwaddr addr)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
|
|
|
uint32_t data = 0;
|
2009-10-15 00:58:14 +04:00
|
|
|
I6300State *d = vp;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
i6300esb_debug("addr = %x\n", (int) addr);
|
|
|
|
|
|
|
|
if (addr == 0xc) {
|
|
|
|
/* The previous reboot flag is really bit 9, but there is
|
|
|
|
* a bug in the Linux driver where it thinks it's bit 12.
|
|
|
|
* Set both.
|
|
|
|
*/
|
|
|
|
data = d->previous_reboot_flag ? 0x1200 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint32_t i6300esb_mem_readl(void *vp, hwaddr addr)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
|
|
|
i6300esb_debug("addr = %x\n", (int) addr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void i6300esb_mem_writeb(void *vp, hwaddr addr, uint32_t val)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
2009-10-15 00:58:14 +04:00
|
|
|
I6300State *d = vp;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
i6300esb_debug("addr = %x, val = %x\n", (int) addr, val);
|
|
|
|
|
|
|
|
if (addr == 0xc && val == 0x80)
|
|
|
|
d->unlock_state = 1;
|
|
|
|
else if (addr == 0xc && val == 0x86 && d->unlock_state == 1)
|
|
|
|
d->unlock_state = 2;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void i6300esb_mem_writew(void *vp, hwaddr addr, uint32_t val)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
2009-10-15 00:58:14 +04:00
|
|
|
I6300State *d = vp;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
i6300esb_debug("addr = %x, val = %x\n", (int) addr, val);
|
|
|
|
|
|
|
|
if (addr == 0xc && val == 0x80)
|
|
|
|
d->unlock_state = 1;
|
|
|
|
else if (addr == 0xc && val == 0x86 && d->unlock_state == 1)
|
|
|
|
d->unlock_state = 2;
|
|
|
|
else {
|
|
|
|
if (d->unlock_state == 2) {
|
|
|
|
if (addr == 0xc) {
|
|
|
|
if ((val & 0x100) != 0)
|
|
|
|
/* This is the "ping" from the userspace watchdog in
|
|
|
|
* the guest ...
|
|
|
|
*/
|
|
|
|
i6300esb_restart_timer(d, 1);
|
|
|
|
|
|
|
|
/* Setting bit 9 resets the previous reboot flag.
|
|
|
|
* There's a bug in the Linux driver where it sets
|
|
|
|
* bit 12 instead.
|
|
|
|
*/
|
|
|
|
if ((val & 0x200) != 0 || (val & 0x1000) != 0) {
|
|
|
|
d->previous_reboot_flag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->unlock_state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void i6300esb_mem_writel(void *vp, hwaddr addr, uint32_t val)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
2009-10-15 00:58:14 +04:00
|
|
|
I6300State *d = vp;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
|
|
|
i6300esb_debug ("addr = %x, val = %x\n", (int) addr, val);
|
|
|
|
|
|
|
|
if (addr == 0xc && val == 0x80)
|
|
|
|
d->unlock_state = 1;
|
|
|
|
else if (addr == 0xc && val == 0x86 && d->unlock_state == 1)
|
|
|
|
d->unlock_state = 2;
|
|
|
|
else {
|
|
|
|
if (d->unlock_state == 2) {
|
|
|
|
if (addr == 0)
|
|
|
|
d->timer1_preload = val & 0xfffff;
|
|
|
|
else if (addr == 4)
|
|
|
|
d->timer2_preload = val & 0xfffff;
|
|
|
|
|
|
|
|
d->unlock_state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 16:57:13 +03:00
|
|
|
static uint64_t i6300esb_mem_readfn(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return i6300esb_mem_readb(opaque, addr);
|
|
|
|
case 2:
|
|
|
|
return i6300esb_mem_readw(opaque, addr);
|
|
|
|
case 4:
|
|
|
|
return i6300esb_mem_readl(opaque, addr);
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i6300esb_mem_writefn(void *opaque, hwaddr addr,
|
|
|
|
uint64_t value, unsigned size)
|
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
i6300esb_mem_writeb(opaque, addr, value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
i6300esb_mem_writew(opaque, addr, value);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
i6300esb_mem_writel(opaque, addr, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 17:09:20 +04:00
|
|
|
static const MemoryRegionOps i6300esb_ops = {
|
2018-06-15 16:57:13 +03:00
|
|
|
.read = i6300esb_mem_readfn,
|
|
|
|
.write = i6300esb_mem_writefn,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
2015-03-23 04:51:47 +03:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-08 17:09:20 +04:00
|
|
|
};
|
|
|
|
|
2009-10-15 00:47:04 +04:00
|
|
|
static const VMStateDescription vmstate_i6300esb = {
|
|
|
|
.name = "i6300esb_wdt",
|
2013-05-22 20:32:51 +04:00
|
|
|
/* With this VMSD's introduction, version_id/minimum_version_id were
|
|
|
|
* erroneously set to sizeof(I6300State), causing a somewhat random
|
|
|
|
* version_id to be set for every build. This eventually broke
|
|
|
|
* migration.
|
|
|
|
*
|
2014-04-16 17:32:32 +04:00
|
|
|
* To correct this without breaking old->new migration for older
|
|
|
|
* versions of QEMU, we've set version_id to a value high enough
|
|
|
|
* to exceed all past values of sizeof(I6300State) across various
|
|
|
|
* build environments, and have reset minimum_version_id to 1,
|
|
|
|
* since this VMSD has never changed and thus can accept all past
|
|
|
|
* versions.
|
2013-05-22 20:32:51 +04:00
|
|
|
*
|
|
|
|
* For future changes we can treat these values as we normally would.
|
|
|
|
*/
|
|
|
|
.version_id = 10000,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-10-15 00:47:04 +04:00
|
|
|
VMSTATE_PCI_DEVICE(dev, I6300State),
|
|
|
|
VMSTATE_INT32(reboot_enabled, I6300State),
|
|
|
|
VMSTATE_INT32(clock_scale, I6300State),
|
|
|
|
VMSTATE_INT32(int_type, I6300State),
|
|
|
|
VMSTATE_INT32(free_run, I6300State),
|
|
|
|
VMSTATE_INT32(locked, I6300State),
|
|
|
|
VMSTATE_INT32(enabled, I6300State),
|
2015-01-08 12:18:59 +03:00
|
|
|
VMSTATE_TIMER_PTR(timer, I6300State),
|
2009-10-15 00:47:04 +04:00
|
|
|
VMSTATE_UINT32(timer1_preload, I6300State),
|
|
|
|
VMSTATE_UINT32(timer2_preload, I6300State),
|
|
|
|
VMSTATE_INT32(stage, I6300State),
|
|
|
|
VMSTATE_INT32(unlock_state, I6300State),
|
|
|
|
VMSTATE_INT32(previous_reboot_flag, I6300State),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2009-04-25 16:56:19 +04:00
|
|
|
|
2015-01-19 17:52:30 +03:00
|
|
|
static void i6300esb_realize(PCIDevice *dev, Error **errp)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
2015-05-13 03:43:25 +03:00
|
|
|
I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
|
2009-04-25 16:56:19 +04:00
|
|
|
|
2010-12-08 17:59:55 +03:00
|
|
|
i6300esb_debug("I6300State = %p\n", d);
|
|
|
|
|
2013-08-21 19:03:08 +04:00
|
|
|
d->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, i6300esb_timer_expired, d);
|
2010-09-24 19:08:06 +04:00
|
|
|
d->previous_reboot_flag = 0;
|
2009-04-25 16:56:19 +04:00
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&d->io_mem, OBJECT(d), &i6300esb_ops, d,
|
|
|
|
"i6300esb", 0x10);
|
2011-08-08 17:09:31 +04:00
|
|
|
pci_register_bar(&d->dev, 0, 0, &d->io_mem);
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
|
|
|
|
2016-11-29 04:49:04 +03:00
|
|
|
static void i6300esb_exit(PCIDevice *dev)
|
|
|
|
{
|
|
|
|
I6300State *d = WATCHDOG_I6300ESB_DEVICE(dev);
|
|
|
|
|
|
|
|
timer_del(d->timer);
|
|
|
|
timer_free(d->timer);
|
|
|
|
}
|
|
|
|
|
2009-04-25 16:56:19 +04:00
|
|
|
static WatchdogTimerModel model = {
|
|
|
|
.wdt_name = "i6300esb",
|
|
|
|
.wdt_description = "Intel 6300ESB",
|
|
|
|
};
|
|
|
|
|
2011-12-04 22:22:06 +04:00
|
|
|
static void i6300esb_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 22:22:06 +04:00
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->config_read = i6300esb_config_read;
|
|
|
|
k->config_write = i6300esb_config_write;
|
2015-01-19 17:52:30 +03:00
|
|
|
k->realize = i6300esb_realize;
|
2016-11-29 04:49:04 +03:00
|
|
|
k->exit = i6300esb_exit;
|
2011-12-04 22:22:06 +04:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_INTEL;
|
|
|
|
k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
|
|
|
|
k->class_id = PCI_CLASS_SYSTEM_OTHER;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->reset = i6300esb_reset;
|
|
|
|
dc->vmsd = &vmstate_i6300esb;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2011-12-04 22:22:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo i6300esb_info = {
|
2015-05-13 03:43:25 +03:00
|
|
|
.name = TYPE_WATCHDOG_I6300ESB_DEVICE,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(I6300State),
|
|
|
|
.class_init = i6300esb_class_init,
|
2017-09-27 22:56:34 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2009-08-21 12:31:34 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void i6300esb_register_types(void)
|
2009-04-25 16:56:19 +04:00
|
|
|
{
|
|
|
|
watchdog_add_model(&model);
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&i6300esb_info);
|
2009-04-25 16:56:19 +04:00
|
|
|
}
|
2009-08-21 12:31:34 +04:00
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(i6300esb_register_types)
|