2012-11-23 04:05:06 +01:00
|
|
|
/*
|
|
|
|
* ACPI implementation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
2012-10-30 03:11:31 +01:00
|
|
|
* Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
|
|
|
|
* VA Linux Systems Japan K.K.
|
|
|
|
* Copyright (C) 2012 Jason Baron <jbaron@redhat.com>
|
|
|
|
*
|
|
|
|
* This is based on acpi.c.
|
2012-11-23 04:05:06 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2012-10-30 03:11:31 +01:00
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2012-11-23 04:05:06 +01:00
|
|
|
*/
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
2013-07-24 17:56:10 +02:00
|
|
|
#include "qapi/visitor.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/i386/pc.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/pci/pci.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/timer.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/acpi/acpi.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/kvm.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "exec/address-spaces.h"
|
2012-11-23 04:05:06 +01:00
|
|
|
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/i386/ich9.h"
|
2014-06-02 15:25:22 +02:00
|
|
|
#include "hw/mem/pc-dimm.h"
|
2012-11-23 04:05:06 +01:00
|
|
|
|
|
|
|
//#define DEBUG
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define ICH9_DEBUG(fmt, ...) \
|
|
|
|
do { printf("%s "fmt, __func__, ## __VA_ARGS__); } while (0)
|
|
|
|
#else
|
|
|
|
#define ICH9_DEBUG(fmt, ...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void ich9_pm_update_sci_fn(ACPIREGS *regs)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = container_of(regs, ICH9LPCPMRegs, acpi_regs);
|
2013-12-13 17:22:07 +01:00
|
|
|
acpi_update_sci(&pm->acpi_regs, pm->irq);
|
2012-11-23 04:05:06 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 13:43:17 +01:00
|
|
|
static uint64_t ich9_gpe_readb(void *opaque, hwaddr addr, unsigned width)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
return acpi_gpe_ioport_readb(&pm->acpi_regs, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ich9_gpe_writeb(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned width)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
acpi_gpe_ioport_writeb(&pm->acpi_regs, addr, val);
|
2013-12-13 17:22:10 +01:00
|
|
|
acpi_update_sci(&pm->acpi_regs, pm->irq);
|
2012-11-22 13:43:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps ich9_gpe_ops = {
|
|
|
|
.read = ich9_gpe_readb,
|
|
|
|
.write = ich9_gpe_writeb,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.impl.min_access_size = 1,
|
|
|
|
.impl.max_access_size = 1,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2012-11-22 13:51:35 +01:00
|
|
|
static uint64_t ich9_smi_readl(void *opaque, hwaddr addr, unsigned width)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
switch (addr) {
|
|
|
|
case 0:
|
|
|
|
return pm->smi_en;
|
|
|
|
case 4:
|
|
|
|
return pm->smi_sts;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned width)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
switch (addr) {
|
|
|
|
case 0:
|
|
|
|
pm->smi_en = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps ich9_smi_ops = {
|
|
|
|
.read = ich9_smi_readl,
|
|
|
|
.write = ich9_smi_writel,
|
|
|
|
.valid.min_access_size = 4,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2012-11-23 04:05:06 +01:00
|
|
|
void ich9_pm_iospace_update(ICH9LPCPMRegs *pm, uint32_t pm_io_base)
|
|
|
|
{
|
|
|
|
ICH9_DEBUG("to 0x%x\n", pm_io_base);
|
|
|
|
|
|
|
|
assert((pm_io_base & ICH9_PMIO_MASK) == 0);
|
|
|
|
|
|
|
|
pm->pm_io_base = pm_io_base;
|
2012-11-22 12:08:22 +01:00
|
|
|
memory_region_transaction_begin();
|
|
|
|
memory_region_set_enabled(&pm->io, pm->pm_io_base != 0);
|
|
|
|
memory_region_set_address(&pm->io, pm->pm_io_base);
|
|
|
|
memory_region_transaction_commit();
|
2012-11-23 04:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ich9_pm_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
uint32_t pm_io_base = pm->pm_io_base;
|
|
|
|
pm->pm_io_base = 0;
|
|
|
|
ich9_pm_iospace_update(pm, pm_io_base);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VMSTATE_GPE_ARRAY(_field, _state) \
|
|
|
|
{ \
|
|
|
|
.name = (stringify(_field)), \
|
|
|
|
.version_id = 0, \
|
|
|
|
.num = ICH9_PMIO_GPE0_LEN, \
|
|
|
|
.info = &vmstate_info_uint8, \
|
|
|
|
.size = sizeof(uint8_t), \
|
|
|
|
.flags = VMS_ARRAY | VMS_POINTER, \
|
|
|
|
.offset = vmstate_offset_pointer(_state, _field, uint8_t), \
|
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:23 +02:00
|
|
|
static bool vmstate_test_use_memhp(void *opaque)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *s = opaque;
|
|
|
|
return s->acpi_memory_hotplug.is_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_memhp_state = {
|
|
|
|
.name = "ich9_pm/memhp",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.minimum_version_id_old = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_MEMORY_HOTPLUG(acpi_memory_hotplug, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-23 04:05:06 +01:00
|
|
|
const VMStateDescription vmstate_ich9_pm = {
|
|
|
|
.name = "ich9_pm",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.post_load = ich9_pm_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT16(acpi_regs.pm1.evt.sts, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_UINT16(acpi_regs.pm1.evt.en, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_UINT16(acpi_regs.pm1.cnt.cnt, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_TIMER(acpi_regs.tmr.timer, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_INT64(acpi_regs.tmr.overflow_time, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_GPE_ARRAY(acpi_regs.gpe.sts, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_GPE_ARRAY(acpi_regs.gpe.en, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_UINT32(smi_en, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_UINT32(smi_sts, ICH9LPCPMRegs),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2014-06-02 15:25:23 +02:00
|
|
|
},
|
|
|
|
.subsections = (VMStateSubsection[]) {
|
|
|
|
{
|
|
|
|
.vmsd = &vmstate_memhp_state,
|
|
|
|
.needed = vmstate_test_use_memhp,
|
|
|
|
},
|
|
|
|
VMSTATE_END_OF_LIST()
|
2012-11-23 04:05:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pm_reset(void *opaque)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
ich9_pm_iospace_update(pm, 0);
|
|
|
|
|
|
|
|
acpi_pm1_evt_reset(&pm->acpi_regs);
|
|
|
|
acpi_pm1_cnt_reset(&pm->acpi_regs);
|
|
|
|
acpi_pm_tmr_reset(&pm->acpi_regs);
|
|
|
|
acpi_gpe_reset(&pm->acpi_regs);
|
|
|
|
|
2012-11-14 21:54:07 +01:00
|
|
|
if (kvm_enabled()) {
|
|
|
|
/* Mark SMM as already inited to prevent SMM from running. KVM does not
|
|
|
|
* support SMM mode. */
|
|
|
|
pm->smi_en |= ICH9_PMIO_SMI_EN_APMC_EN;
|
|
|
|
}
|
|
|
|
|
2013-12-13 17:22:07 +01:00
|
|
|
acpi_update_sci(&pm->acpi_regs, pm->irq);
|
2012-11-23 04:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pm_powerdown_req(Notifier *n, void *opaque)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, powerdown_notifier);
|
|
|
|
|
|
|
|
acpi_pm1_evt_power_down(&pm->acpi_regs);
|
|
|
|
}
|
|
|
|
|
2012-12-11 09:42:18 +01:00
|
|
|
void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
|
2013-04-24 12:37:22 +02:00
|
|
|
qemu_irq sci_irq)
|
2012-11-23 04:05:06 +01:00
|
|
|
{
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init(&pm->io, OBJECT(lpc_pci), "ich9-pm", ICH9_PMIO_SIZE);
|
2012-11-22 12:08:22 +01:00
|
|
|
memory_region_set_enabled(&pm->io, false);
|
2012-12-11 09:42:18 +01:00
|
|
|
memory_region_add_subregion(pci_address_space_io(lpc_pci),
|
|
|
|
0, &pm->io);
|
2012-11-22 12:08:22 +01:00
|
|
|
|
2012-11-22 12:12:30 +01:00
|
|
|
acpi_pm_tmr_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);
|
2012-11-22 13:25:10 +01:00
|
|
|
acpi_pm1_evt_init(&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);
|
2013-04-02 20:41:40 +02:00
|
|
|
acpi_pm1_cnt_init(&pm->acpi_regs, &pm->io, 2);
|
2012-11-22 13:43:17 +01:00
|
|
|
|
2012-11-23 04:05:06 +01:00
|
|
|
acpi_gpe_init(&pm->acpi_regs, ICH9_PMIO_GPE0_LEN);
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&pm->io_gpe, OBJECT(lpc_pci), &ich9_gpe_ops, pm,
|
2013-06-13 12:51:48 +02:00
|
|
|
"acpi-gpe0", ICH9_PMIO_GPE0_LEN);
|
2012-11-22 13:43:17 +01:00
|
|
|
memory_region_add_subregion(&pm->io, ICH9_PMIO_GPE0_STS, &pm->io_gpe);
|
2012-11-23 04:05:06 +01:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&pm->io_smi, OBJECT(lpc_pci), &ich9_smi_ops, pm,
|
2013-06-13 12:51:48 +02:00
|
|
|
"acpi-smi", 8);
|
2012-11-22 13:51:35 +01:00
|
|
|
memory_region_add_subregion(&pm->io, ICH9_PMIO_SMI_EN, &pm->io_smi);
|
|
|
|
|
2012-11-23 04:05:06 +01:00
|
|
|
pm->irq = sci_irq;
|
|
|
|
qemu_register_reset(pm_reset, pm);
|
|
|
|
pm->powerdown_notifier.notify = pm_powerdown_req;
|
|
|
|
qemu_register_powerdown_notifier(&pm->powerdown_notifier);
|
2014-01-09 17:36:32 +01:00
|
|
|
|
2014-10-22 05:24:31 +02:00
|
|
|
acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
|
|
|
|
&pm->gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
|
2014-06-02 15:25:22 +02:00
|
|
|
|
|
|
|
if (pm->acpi_memory_hotplug.is_enabled) {
|
|
|
|
acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
|
|
|
|
&pm->acpi_memory_hotplug);
|
|
|
|
}
|
2012-11-23 04:05:06 +01:00
|
|
|
}
|
2013-07-24 17:56:10 +02:00
|
|
|
|
|
|
|
static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
|
|
|
|
void *opaque, const char *name,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ICH9LPCPMRegs *pm = opaque;
|
|
|
|
uint32_t value = pm->pm_io_base + ICH9_PMIO_GPE0_STS;
|
|
|
|
|
|
|
|
visit_type_uint32(v, &value, name, errp);
|
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:22 +02:00
|
|
|
static bool ich9_pm_get_memory_hotplug_support(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
|
|
|
|
|
|
|
|
return s->pm.acpi_memory_hotplug.is_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
|
|
|
|
|
|
|
|
s->pm.acpi_memory_hotplug.is_enabled = value;
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:56:10 +02:00
|
|
|
void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
|
|
|
|
{
|
|
|
|
static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
|
2014-06-02 15:25:22 +02:00
|
|
|
pm->acpi_memory_hotplug.is_enabled = true;
|
2013-07-24 17:56:10 +02:00
|
|
|
|
|
|
|
object_property_add_uint32_ptr(obj, ACPI_PM_PROP_PM_IO_BASE,
|
|
|
|
&pm->pm_io_base, errp);
|
|
|
|
object_property_add(obj, ACPI_PM_PROP_GPE0_BLK, "uint32",
|
|
|
|
ich9_pm_get_gpe0_blk,
|
|
|
|
NULL, NULL, pm, NULL);
|
|
|
|
object_property_add_uint32_ptr(obj, ACPI_PM_PROP_GPE0_BLK_LEN,
|
|
|
|
&gpe0_len, errp);
|
2014-06-02 15:25:22 +02:00
|
|
|
object_property_add_bool(obj, "memory-hotplug-support",
|
|
|
|
ich9_pm_get_memory_hotplug_support,
|
|
|
|
ich9_pm_set_memory_hotplug_support,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
if (pm->acpi_memory_hotplug.is_enabled &&
|
|
|
|
object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
|
|
|
|
acpi_memory_plug_cb(&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug,
|
|
|
|
dev, errp);
|
2014-10-22 05:24:26 +02:00
|
|
|
} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
|
|
|
|
acpi_cpu_plug_cb(&pm->acpi_regs, pm->irq, &pm->gpe_cpu, dev, errp);
|
2014-06-02 15:25:22 +02:00
|
|
|
} else {
|
|
|
|
error_setg(errp, "acpi: device plug request for not supported device"
|
|
|
|
" type: %s", object_get_typename(OBJECT(dev)));
|
|
|
|
}
|
2013-07-24 17:56:10 +02:00
|
|
|
}
|
2014-06-16 19:12:27 +02:00
|
|
|
|
|
|
|
void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
|
|
|
|
{
|
|
|
|
ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
|
|
|
|
|
|
|
|
acpi_memory_ospm_status(&s->pm.acpi_memory_hotplug, list);
|
|
|
|
}
|