147934d0aSPaolo Bonzini /* 247934d0aSPaolo Bonzini * VT82C686B south bridge support 347934d0aSPaolo Bonzini * 447934d0aSPaolo Bonzini * Copyright (c) 2008 yajin (yajin@vm-kernel.org) 547934d0aSPaolo Bonzini * Copyright (c) 2009 chenming (chenming@rdc.faw.com.cn) 647934d0aSPaolo Bonzini * Copyright (c) 2010 Huacai Chen (zltjiangshi@gmail.com) 747934d0aSPaolo Bonzini * This code is licensed under the GNU GPL v2. 847934d0aSPaolo Bonzini * 947934d0aSPaolo Bonzini * Contributions after 2012-01-13 are licensed under the terms of the 1047934d0aSPaolo Bonzini * GNU GPL, version 2 or (at your option) any later version. 1147934d0aSPaolo Bonzini */ 1247934d0aSPaolo Bonzini 1347934d0aSPaolo Bonzini #include "hw/hw.h" 1447934d0aSPaolo Bonzini #include "hw/i386/pc.h" 1547934d0aSPaolo Bonzini #include "hw/isa/vt82c686.h" 1647934d0aSPaolo Bonzini #include "hw/i2c/i2c.h" 1747934d0aSPaolo Bonzini #include "hw/i2c/smbus.h" 1847934d0aSPaolo Bonzini #include "hw/pci/pci.h" 1947934d0aSPaolo Bonzini #include "hw/isa/isa.h" 2047934d0aSPaolo Bonzini #include "hw/sysbus.h" 2147934d0aSPaolo Bonzini #include "hw/mips/mips.h" 2247934d0aSPaolo Bonzini #include "hw/isa/apm.h" 2347934d0aSPaolo Bonzini #include "hw/acpi/acpi.h" 2447934d0aSPaolo Bonzini #include "hw/i2c/pm_smbus.h" 2547934d0aSPaolo Bonzini #include "sysemu/sysemu.h" 2647934d0aSPaolo Bonzini #include "qemu/timer.h" 2747934d0aSPaolo Bonzini #include "exec/address-spaces.h" 2847934d0aSPaolo Bonzini 2947934d0aSPaolo Bonzini //#define DEBUG_VT82C686B 3047934d0aSPaolo Bonzini 3147934d0aSPaolo Bonzini #ifdef DEBUG_VT82C686B 3247934d0aSPaolo Bonzini #define DPRINTF(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__) 3347934d0aSPaolo Bonzini #else 3447934d0aSPaolo Bonzini #define DPRINTF(fmt, ...) 3547934d0aSPaolo Bonzini #endif 3647934d0aSPaolo Bonzini 3747934d0aSPaolo Bonzini typedef struct SuperIOConfig 3847934d0aSPaolo Bonzini { 3947934d0aSPaolo Bonzini uint8_t config[0xff]; 4047934d0aSPaolo Bonzini uint8_t index; 4147934d0aSPaolo Bonzini uint8_t data; 4247934d0aSPaolo Bonzini } SuperIOConfig; 4347934d0aSPaolo Bonzini 4447934d0aSPaolo Bonzini typedef struct VT82C686BState { 4547934d0aSPaolo Bonzini PCIDevice dev; 46bcc37e24SJan Kiszka MemoryRegion superio; 4747934d0aSPaolo Bonzini SuperIOConfig superio_conf; 4847934d0aSPaolo Bonzini } VT82C686BState; 4947934d0aSPaolo Bonzini 50bcc37e24SJan Kiszka static void superio_ioport_writeb(void *opaque, hwaddr addr, uint64_t data, 51bcc37e24SJan Kiszka unsigned size) 5247934d0aSPaolo Bonzini { 5347934d0aSPaolo Bonzini int can_write; 5447934d0aSPaolo Bonzini SuperIOConfig *superio_conf = opaque; 5547934d0aSPaolo Bonzini 5647934d0aSPaolo Bonzini DPRINTF("superio_ioport_writeb address 0x%x val 0x%x\n", addr, data); 5747934d0aSPaolo Bonzini if (addr == 0x3f0) { 5847934d0aSPaolo Bonzini superio_conf->index = data & 0xff; 5947934d0aSPaolo Bonzini } else { 6047934d0aSPaolo Bonzini /* 0x3f1 */ 6147934d0aSPaolo Bonzini switch (superio_conf->index) { 6247934d0aSPaolo Bonzini case 0x00 ... 0xdf: 6347934d0aSPaolo Bonzini case 0xe4: 6447934d0aSPaolo Bonzini case 0xe5: 6547934d0aSPaolo Bonzini case 0xe9 ... 0xed: 6647934d0aSPaolo Bonzini case 0xf3: 6747934d0aSPaolo Bonzini case 0xf5: 6847934d0aSPaolo Bonzini case 0xf7: 6947934d0aSPaolo Bonzini case 0xf9 ... 0xfb: 7047934d0aSPaolo Bonzini case 0xfd ... 0xff: 7147934d0aSPaolo Bonzini can_write = 0; 7247934d0aSPaolo Bonzini break; 7347934d0aSPaolo Bonzini default: 7447934d0aSPaolo Bonzini can_write = 1; 7547934d0aSPaolo Bonzini 7647934d0aSPaolo Bonzini if (can_write) { 7747934d0aSPaolo Bonzini switch (superio_conf->index) { 7847934d0aSPaolo Bonzini case 0xe7: 7947934d0aSPaolo Bonzini if ((data & 0xff) != 0xfe) { 8047934d0aSPaolo Bonzini DPRINTF("chage uart 1 base. unsupported yet\n"); 8147934d0aSPaolo Bonzini } 8247934d0aSPaolo Bonzini break; 8347934d0aSPaolo Bonzini case 0xe8: 8447934d0aSPaolo Bonzini if ((data & 0xff) != 0xbe) { 8547934d0aSPaolo Bonzini DPRINTF("chage uart 2 base. unsupported yet\n"); 8647934d0aSPaolo Bonzini } 8747934d0aSPaolo Bonzini break; 8847934d0aSPaolo Bonzini 8947934d0aSPaolo Bonzini default: 9047934d0aSPaolo Bonzini superio_conf->config[superio_conf->index] = data & 0xff; 9147934d0aSPaolo Bonzini } 9247934d0aSPaolo Bonzini } 9347934d0aSPaolo Bonzini } 9447934d0aSPaolo Bonzini superio_conf->config[superio_conf->index] = data & 0xff; 9547934d0aSPaolo Bonzini } 9647934d0aSPaolo Bonzini } 9747934d0aSPaolo Bonzini 98bcc37e24SJan Kiszka static uint64_t superio_ioport_readb(void *opaque, hwaddr addr, unsigned size) 9947934d0aSPaolo Bonzini { 10047934d0aSPaolo Bonzini SuperIOConfig *superio_conf = opaque; 10147934d0aSPaolo Bonzini 10247934d0aSPaolo Bonzini DPRINTF("superio_ioport_readb address 0x%x\n", addr); 10347934d0aSPaolo Bonzini return (superio_conf->config[superio_conf->index]); 10447934d0aSPaolo Bonzini } 10547934d0aSPaolo Bonzini 106bcc37e24SJan Kiszka static const MemoryRegionOps superio_ops = { 107bcc37e24SJan Kiszka .read = superio_ioport_readb, 108bcc37e24SJan Kiszka .write = superio_ioport_writeb, 109bcc37e24SJan Kiszka .endianness = DEVICE_NATIVE_ENDIAN, 110bcc37e24SJan Kiszka .impl = { 111bcc37e24SJan Kiszka .min_access_size = 1, 112bcc37e24SJan Kiszka .max_access_size = 1, 113bcc37e24SJan Kiszka }, 114bcc37e24SJan Kiszka }; 115bcc37e24SJan Kiszka 11647934d0aSPaolo Bonzini static void vt82c686b_reset(void * opaque) 11747934d0aSPaolo Bonzini { 11847934d0aSPaolo Bonzini PCIDevice *d = opaque; 11947934d0aSPaolo Bonzini uint8_t *pci_conf = d->config; 12047934d0aSPaolo Bonzini VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); 12147934d0aSPaolo Bonzini 12247934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); 12347934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | 12447934d0aSPaolo Bonzini PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); 12547934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); 12647934d0aSPaolo Bonzini 12747934d0aSPaolo Bonzini pci_conf[0x48] = 0x01; /* Miscellaneous Control 3 */ 12847934d0aSPaolo Bonzini pci_conf[0x4a] = 0x04; /* IDE interrupt Routing */ 12947934d0aSPaolo Bonzini pci_conf[0x4f] = 0x03; /* DMA/Master Mem Access Control 3 */ 13047934d0aSPaolo Bonzini pci_conf[0x50] = 0x2d; /* PnP DMA Request Control */ 13147934d0aSPaolo Bonzini pci_conf[0x59] = 0x04; 13247934d0aSPaolo Bonzini pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/ 13347934d0aSPaolo Bonzini pci_conf[0x5f] = 0x04; 13447934d0aSPaolo Bonzini pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */ 13547934d0aSPaolo Bonzini 13647934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe0] = 0x3c; 13747934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe2] = 0x03; 13847934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe3] = 0xfc; 13947934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe6] = 0xde; 14047934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe7] = 0xfe; 14147934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe8] = 0xbe; 14247934d0aSPaolo Bonzini } 14347934d0aSPaolo Bonzini 14447934d0aSPaolo Bonzini /* write config pci function0 registers. PCI-ISA bridge */ 14547934d0aSPaolo Bonzini static void vt82c686b_write_config(PCIDevice * d, uint32_t address, 14647934d0aSPaolo Bonzini uint32_t val, int len) 14747934d0aSPaolo Bonzini { 14847934d0aSPaolo Bonzini VT82C686BState *vt686 = DO_UPCAST(VT82C686BState, dev, d); 14947934d0aSPaolo Bonzini 15047934d0aSPaolo Bonzini DPRINTF("vt82c686b_write_config address 0x%x val 0x%x len 0x%x\n", 15147934d0aSPaolo Bonzini address, val, len); 15247934d0aSPaolo Bonzini 15347934d0aSPaolo Bonzini pci_default_write_config(d, address, val, len); 15447934d0aSPaolo Bonzini if (address == 0x85) { /* enable or disable super IO configure */ 155bcc37e24SJan Kiszka memory_region_set_enabled(&vt686->superio, val & 0x2); 15647934d0aSPaolo Bonzini } 15747934d0aSPaolo Bonzini } 15847934d0aSPaolo Bonzini 15947934d0aSPaolo Bonzini #define ACPI_DBG_IO_ADDR 0xb044 16047934d0aSPaolo Bonzini 16147934d0aSPaolo Bonzini typedef struct VT686PMState { 16247934d0aSPaolo Bonzini PCIDevice dev; 16347934d0aSPaolo Bonzini MemoryRegion io; 16447934d0aSPaolo Bonzini ACPIREGS ar; 16547934d0aSPaolo Bonzini APMState apm; 16647934d0aSPaolo Bonzini PMSMBus smb; 16747934d0aSPaolo Bonzini uint32_t smb_io_base; 16847934d0aSPaolo Bonzini } VT686PMState; 16947934d0aSPaolo Bonzini 17047934d0aSPaolo Bonzini typedef struct VT686AC97State { 17147934d0aSPaolo Bonzini PCIDevice dev; 17247934d0aSPaolo Bonzini } VT686AC97State; 17347934d0aSPaolo Bonzini 17447934d0aSPaolo Bonzini typedef struct VT686MC97State { 17547934d0aSPaolo Bonzini PCIDevice dev; 17647934d0aSPaolo Bonzini } VT686MC97State; 17747934d0aSPaolo Bonzini 17847934d0aSPaolo Bonzini static void pm_update_sci(VT686PMState *s) 17947934d0aSPaolo Bonzini { 18047934d0aSPaolo Bonzini int sci_level, pmsts; 18147934d0aSPaolo Bonzini 18247934d0aSPaolo Bonzini pmsts = acpi_pm1_evt_get_sts(&s->ar); 18347934d0aSPaolo Bonzini sci_level = (((pmsts & s->ar.pm1.evt.en) & 18447934d0aSPaolo Bonzini (ACPI_BITMASK_RT_CLOCK_ENABLE | 18547934d0aSPaolo Bonzini ACPI_BITMASK_POWER_BUTTON_ENABLE | 18647934d0aSPaolo Bonzini ACPI_BITMASK_GLOBAL_LOCK_ENABLE | 18747934d0aSPaolo Bonzini ACPI_BITMASK_TIMER_ENABLE)) != 0); 18847934d0aSPaolo Bonzini qemu_set_irq(s->dev.irq[0], sci_level); 18947934d0aSPaolo Bonzini /* schedule a timer interruption if needed */ 19047934d0aSPaolo Bonzini acpi_pm_tmr_update(&s->ar, (s->ar.pm1.evt.en & ACPI_BITMASK_TIMER_ENABLE) && 19147934d0aSPaolo Bonzini !(pmsts & ACPI_BITMASK_TIMER_STATUS)); 19247934d0aSPaolo Bonzini } 19347934d0aSPaolo Bonzini 19447934d0aSPaolo Bonzini static void pm_tmr_timer(ACPIREGS *ar) 19547934d0aSPaolo Bonzini { 19647934d0aSPaolo Bonzini VT686PMState *s = container_of(ar, VT686PMState, ar); 19747934d0aSPaolo Bonzini pm_update_sci(s); 19847934d0aSPaolo Bonzini } 19947934d0aSPaolo Bonzini 20047934d0aSPaolo Bonzini static void pm_io_space_update(VT686PMState *s) 20147934d0aSPaolo Bonzini { 20247934d0aSPaolo Bonzini uint32_t pm_io_base; 20347934d0aSPaolo Bonzini 20447934d0aSPaolo Bonzini pm_io_base = pci_get_long(s->dev.config + 0x40); 20547934d0aSPaolo Bonzini pm_io_base &= 0xffc0; 20647934d0aSPaolo Bonzini 20747934d0aSPaolo Bonzini memory_region_transaction_begin(); 20847934d0aSPaolo Bonzini memory_region_set_enabled(&s->io, s->dev.config[0x80] & 1); 20947934d0aSPaolo Bonzini memory_region_set_address(&s->io, pm_io_base); 21047934d0aSPaolo Bonzini memory_region_transaction_commit(); 21147934d0aSPaolo Bonzini } 21247934d0aSPaolo Bonzini 21347934d0aSPaolo Bonzini static void pm_write_config(PCIDevice *d, 21447934d0aSPaolo Bonzini uint32_t address, uint32_t val, int len) 21547934d0aSPaolo Bonzini { 21647934d0aSPaolo Bonzini DPRINTF("pm_write_config address 0x%x val 0x%x len 0x%x\n", 21747934d0aSPaolo Bonzini address, val, len); 21847934d0aSPaolo Bonzini pci_default_write_config(d, address, val, len); 21947934d0aSPaolo Bonzini } 22047934d0aSPaolo Bonzini 22147934d0aSPaolo Bonzini static int vmstate_acpi_post_load(void *opaque, int version_id) 22247934d0aSPaolo Bonzini { 22347934d0aSPaolo Bonzini VT686PMState *s = opaque; 22447934d0aSPaolo Bonzini 22547934d0aSPaolo Bonzini pm_io_space_update(s); 22647934d0aSPaolo Bonzini return 0; 22747934d0aSPaolo Bonzini } 22847934d0aSPaolo Bonzini 22947934d0aSPaolo Bonzini static const VMStateDescription vmstate_acpi = { 23047934d0aSPaolo Bonzini .name = "vt82c686b_pm", 23147934d0aSPaolo Bonzini .version_id = 1, 23247934d0aSPaolo Bonzini .minimum_version_id = 1, 23347934d0aSPaolo Bonzini .minimum_version_id_old = 1, 23447934d0aSPaolo Bonzini .post_load = vmstate_acpi_post_load, 23547934d0aSPaolo Bonzini .fields = (VMStateField []) { 23647934d0aSPaolo Bonzini VMSTATE_PCI_DEVICE(dev, VT686PMState), 23747934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.evt.sts, VT686PMState), 23847934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.evt.en, VT686PMState), 23947934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.cnt.cnt, VT686PMState), 24047934d0aSPaolo Bonzini VMSTATE_STRUCT(apm, VT686PMState, 0, vmstate_apm, APMState), 24147934d0aSPaolo Bonzini VMSTATE_TIMER(ar.tmr.timer, VT686PMState), 24247934d0aSPaolo Bonzini VMSTATE_INT64(ar.tmr.overflow_time, VT686PMState), 24347934d0aSPaolo Bonzini VMSTATE_END_OF_LIST() 24447934d0aSPaolo Bonzini } 24547934d0aSPaolo Bonzini }; 24647934d0aSPaolo Bonzini 24747934d0aSPaolo Bonzini /* 24847934d0aSPaolo Bonzini * TODO: vt82c686b_ac97_init() and vt82c686b_mc97_init() 24947934d0aSPaolo Bonzini * just register a PCI device now, functionalities will be implemented later. 25047934d0aSPaolo Bonzini */ 25147934d0aSPaolo Bonzini 25247934d0aSPaolo Bonzini static int vt82c686b_ac97_initfn(PCIDevice *dev) 25347934d0aSPaolo Bonzini { 25447934d0aSPaolo Bonzini VT686AC97State *s = DO_UPCAST(VT686AC97State, dev, dev); 25547934d0aSPaolo Bonzini uint8_t *pci_conf = s->dev.config; 25647934d0aSPaolo Bonzini 25747934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_INVALIDATE | 25847934d0aSPaolo Bonzini PCI_COMMAND_PARITY); 25947934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_CAP_LIST | 26047934d0aSPaolo Bonzini PCI_STATUS_DEVSEL_MEDIUM); 26147934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03); 26247934d0aSPaolo Bonzini 26347934d0aSPaolo Bonzini return 0; 26447934d0aSPaolo Bonzini } 26547934d0aSPaolo Bonzini 26647934d0aSPaolo Bonzini void vt82c686b_ac97_init(PCIBus *bus, int devfn) 26747934d0aSPaolo Bonzini { 26847934d0aSPaolo Bonzini PCIDevice *dev; 26947934d0aSPaolo Bonzini 27047934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_AC97"); 27147934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 27247934d0aSPaolo Bonzini } 27347934d0aSPaolo Bonzini 27447934d0aSPaolo Bonzini static void via_ac97_class_init(ObjectClass *klass, void *data) 27547934d0aSPaolo Bonzini { 27647934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 27747934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 27847934d0aSPaolo Bonzini 27947934d0aSPaolo Bonzini k->init = vt82c686b_ac97_initfn; 28047934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 28147934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_AC97; 28247934d0aSPaolo Bonzini k->revision = 0x50; 28347934d0aSPaolo Bonzini k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; 28447934d0aSPaolo Bonzini dc->desc = "AC97"; 28547934d0aSPaolo Bonzini } 28647934d0aSPaolo Bonzini 28747934d0aSPaolo Bonzini static const TypeInfo via_ac97_info = { 28847934d0aSPaolo Bonzini .name = "VT82C686B_AC97", 28947934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 29047934d0aSPaolo Bonzini .instance_size = sizeof(VT686AC97State), 29147934d0aSPaolo Bonzini .class_init = via_ac97_class_init, 29247934d0aSPaolo Bonzini }; 29347934d0aSPaolo Bonzini 29447934d0aSPaolo Bonzini static int vt82c686b_mc97_initfn(PCIDevice *dev) 29547934d0aSPaolo Bonzini { 29647934d0aSPaolo Bonzini VT686MC97State *s = DO_UPCAST(VT686MC97State, dev, dev); 29747934d0aSPaolo Bonzini uint8_t *pci_conf = s->dev.config; 29847934d0aSPaolo Bonzini 29947934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_INVALIDATE | 30047934d0aSPaolo Bonzini PCI_COMMAND_VGA_PALETTE); 30147934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); 30247934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03); 30347934d0aSPaolo Bonzini 30447934d0aSPaolo Bonzini return 0; 30547934d0aSPaolo Bonzini } 30647934d0aSPaolo Bonzini 30747934d0aSPaolo Bonzini void vt82c686b_mc97_init(PCIBus *bus, int devfn) 30847934d0aSPaolo Bonzini { 30947934d0aSPaolo Bonzini PCIDevice *dev; 31047934d0aSPaolo Bonzini 31147934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_MC97"); 31247934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 31347934d0aSPaolo Bonzini } 31447934d0aSPaolo Bonzini 31547934d0aSPaolo Bonzini static void via_mc97_class_init(ObjectClass *klass, void *data) 31647934d0aSPaolo Bonzini { 31747934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 31847934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 31947934d0aSPaolo Bonzini 32047934d0aSPaolo Bonzini k->init = vt82c686b_mc97_initfn; 32147934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 32247934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_MC97; 32347934d0aSPaolo Bonzini k->class_id = PCI_CLASS_COMMUNICATION_OTHER; 32447934d0aSPaolo Bonzini k->revision = 0x30; 32547934d0aSPaolo Bonzini dc->desc = "MC97"; 32647934d0aSPaolo Bonzini } 32747934d0aSPaolo Bonzini 32847934d0aSPaolo Bonzini static const TypeInfo via_mc97_info = { 32947934d0aSPaolo Bonzini .name = "VT82C686B_MC97", 33047934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 33147934d0aSPaolo Bonzini .instance_size = sizeof(VT686MC97State), 33247934d0aSPaolo Bonzini .class_init = via_mc97_class_init, 33347934d0aSPaolo Bonzini }; 33447934d0aSPaolo Bonzini 33547934d0aSPaolo Bonzini /* vt82c686 pm init */ 33647934d0aSPaolo Bonzini static int vt82c686b_pm_initfn(PCIDevice *dev) 33747934d0aSPaolo Bonzini { 33847934d0aSPaolo Bonzini VT686PMState *s = DO_UPCAST(VT686PMState, dev, dev); 33947934d0aSPaolo Bonzini uint8_t *pci_conf; 34047934d0aSPaolo Bonzini 34147934d0aSPaolo Bonzini pci_conf = s->dev.config; 34247934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, 0); 34347934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_FAST_BACK | 34447934d0aSPaolo Bonzini PCI_STATUS_DEVSEL_MEDIUM); 34547934d0aSPaolo Bonzini 34647934d0aSPaolo Bonzini /* 0x48-0x4B is Power Management I/O Base */ 34747934d0aSPaolo Bonzini pci_set_long(pci_conf + 0x48, 0x00000001); 34847934d0aSPaolo Bonzini 34947934d0aSPaolo Bonzini /* SMB ports:0xeee0~0xeeef */ 35047934d0aSPaolo Bonzini s->smb_io_base =((s->smb_io_base & 0xfff0) + 0x0); 35147934d0aSPaolo Bonzini pci_conf[0x90] = s->smb_io_base | 1; 35247934d0aSPaolo Bonzini pci_conf[0x91] = s->smb_io_base >> 8; 35347934d0aSPaolo Bonzini pci_conf[0xd2] = 0x90; 35447934d0aSPaolo Bonzini pm_smbus_init(&s->dev.qdev, &s->smb); 35547934d0aSPaolo Bonzini memory_region_add_subregion(get_system_io(), s->smb_io_base, &s->smb.io); 35647934d0aSPaolo Bonzini 35747934d0aSPaolo Bonzini apm_init(dev, &s->apm, NULL, s); 35847934d0aSPaolo Bonzini 359*2c9b15caSPaolo Bonzini memory_region_init(&s->io, NULL, "vt82c686-pm", 64); 36047934d0aSPaolo Bonzini memory_region_set_enabled(&s->io, false); 36147934d0aSPaolo Bonzini memory_region_add_subregion(get_system_io(), 0, &s->io); 36247934d0aSPaolo Bonzini 36347934d0aSPaolo Bonzini acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io); 36447934d0aSPaolo Bonzini acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io); 36547934d0aSPaolo Bonzini acpi_pm1_cnt_init(&s->ar, &s->io, 2); 36647934d0aSPaolo Bonzini 36747934d0aSPaolo Bonzini return 0; 36847934d0aSPaolo Bonzini } 36947934d0aSPaolo Bonzini 37047934d0aSPaolo Bonzini i2c_bus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, 37147934d0aSPaolo Bonzini qemu_irq sci_irq) 37247934d0aSPaolo Bonzini { 37347934d0aSPaolo Bonzini PCIDevice *dev; 37447934d0aSPaolo Bonzini VT686PMState *s; 37547934d0aSPaolo Bonzini 37647934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_PM"); 37747934d0aSPaolo Bonzini qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base); 37847934d0aSPaolo Bonzini 37947934d0aSPaolo Bonzini s = DO_UPCAST(VT686PMState, dev, dev); 38047934d0aSPaolo Bonzini 38147934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 38247934d0aSPaolo Bonzini 38347934d0aSPaolo Bonzini return s->smb.smbus; 38447934d0aSPaolo Bonzini } 38547934d0aSPaolo Bonzini 38647934d0aSPaolo Bonzini static Property via_pm_properties[] = { 38747934d0aSPaolo Bonzini DEFINE_PROP_UINT32("smb_io_base", VT686PMState, smb_io_base, 0), 38847934d0aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 38947934d0aSPaolo Bonzini }; 39047934d0aSPaolo Bonzini 39147934d0aSPaolo Bonzini static void via_pm_class_init(ObjectClass *klass, void *data) 39247934d0aSPaolo Bonzini { 39347934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 39447934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 39547934d0aSPaolo Bonzini 39647934d0aSPaolo Bonzini k->init = vt82c686b_pm_initfn; 39747934d0aSPaolo Bonzini k->config_write = pm_write_config; 39847934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 39947934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_ACPI; 40047934d0aSPaolo Bonzini k->class_id = PCI_CLASS_BRIDGE_OTHER; 40147934d0aSPaolo Bonzini k->revision = 0x40; 40247934d0aSPaolo Bonzini dc->desc = "PM"; 40347934d0aSPaolo Bonzini dc->vmsd = &vmstate_acpi; 40447934d0aSPaolo Bonzini dc->props = via_pm_properties; 40547934d0aSPaolo Bonzini } 40647934d0aSPaolo Bonzini 40747934d0aSPaolo Bonzini static const TypeInfo via_pm_info = { 40847934d0aSPaolo Bonzini .name = "VT82C686B_PM", 40947934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 41047934d0aSPaolo Bonzini .instance_size = sizeof(VT686PMState), 41147934d0aSPaolo Bonzini .class_init = via_pm_class_init, 41247934d0aSPaolo Bonzini }; 41347934d0aSPaolo Bonzini 41447934d0aSPaolo Bonzini static const VMStateDescription vmstate_via = { 41547934d0aSPaolo Bonzini .name = "vt82c686b", 41647934d0aSPaolo Bonzini .version_id = 1, 41747934d0aSPaolo Bonzini .minimum_version_id = 1, 41847934d0aSPaolo Bonzini .minimum_version_id_old = 1, 41947934d0aSPaolo Bonzini .fields = (VMStateField []) { 42047934d0aSPaolo Bonzini VMSTATE_PCI_DEVICE(dev, VT82C686BState), 42147934d0aSPaolo Bonzini VMSTATE_END_OF_LIST() 42247934d0aSPaolo Bonzini } 42347934d0aSPaolo Bonzini }; 42447934d0aSPaolo Bonzini 42547934d0aSPaolo Bonzini /* init the PCI-to-ISA bridge */ 42647934d0aSPaolo Bonzini static int vt82c686b_initfn(PCIDevice *d) 42747934d0aSPaolo Bonzini { 428bcc37e24SJan Kiszka VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); 42947934d0aSPaolo Bonzini uint8_t *pci_conf; 430bcc37e24SJan Kiszka ISABus *isa_bus; 43147934d0aSPaolo Bonzini uint8_t *wmask; 43247934d0aSPaolo Bonzini int i; 43347934d0aSPaolo Bonzini 434bcc37e24SJan Kiszka isa_bus = isa_bus_new(&d->qdev, pci_address_space_io(d)); 43547934d0aSPaolo Bonzini 43647934d0aSPaolo Bonzini pci_conf = d->config; 43747934d0aSPaolo Bonzini pci_config_set_prog_interface(pci_conf, 0x0); 43847934d0aSPaolo Bonzini 43947934d0aSPaolo Bonzini wmask = d->wmask; 44047934d0aSPaolo Bonzini for (i = 0x00; i < 0xff; i++) { 44147934d0aSPaolo Bonzini if (i<=0x03 || (i>=0x08 && i<=0x3f)) { 44247934d0aSPaolo Bonzini wmask[i] = 0x00; 44347934d0aSPaolo Bonzini } 44447934d0aSPaolo Bonzini } 44547934d0aSPaolo Bonzini 446*2c9b15caSPaolo Bonzini memory_region_init_io(&vt82c->superio, NULL, &superio_ops, 447*2c9b15caSPaolo Bonzini &vt82c->superio_conf, "superio", 2); 448bcc37e24SJan Kiszka memory_region_set_enabled(&vt82c->superio, false); 449bcc37e24SJan Kiszka /* The floppy also uses 0x3f0 and 0x3f1. 450bcc37e24SJan Kiszka * But we do not emulate a floppy, so just set it here. */ 451bcc37e24SJan Kiszka memory_region_add_subregion(isa_bus->address_space_io, 0x3f0, 452bcc37e24SJan Kiszka &vt82c->superio); 453bcc37e24SJan Kiszka 45447934d0aSPaolo Bonzini qemu_register_reset(vt82c686b_reset, d); 45547934d0aSPaolo Bonzini 45647934d0aSPaolo Bonzini return 0; 45747934d0aSPaolo Bonzini } 45847934d0aSPaolo Bonzini 45947934d0aSPaolo Bonzini ISABus *vt82c686b_init(PCIBus *bus, int devfn) 46047934d0aSPaolo Bonzini { 46147934d0aSPaolo Bonzini PCIDevice *d; 46247934d0aSPaolo Bonzini 46347934d0aSPaolo Bonzini d = pci_create_simple_multifunction(bus, devfn, true, "VT82C686B"); 46447934d0aSPaolo Bonzini 4652ae0e48dSAndreas Färber return ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0")); 46647934d0aSPaolo Bonzini } 46747934d0aSPaolo Bonzini 46847934d0aSPaolo Bonzini static void via_class_init(ObjectClass *klass, void *data) 46947934d0aSPaolo Bonzini { 47047934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 47147934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 47247934d0aSPaolo Bonzini 47347934d0aSPaolo Bonzini k->init = vt82c686b_initfn; 47447934d0aSPaolo Bonzini k->config_write = vt82c686b_write_config; 47547934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 47647934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE; 47747934d0aSPaolo Bonzini k->class_id = PCI_CLASS_BRIDGE_ISA; 47847934d0aSPaolo Bonzini k->revision = 0x40; 47947934d0aSPaolo Bonzini dc->desc = "ISA bridge"; 48047934d0aSPaolo Bonzini dc->no_user = 1; 48147934d0aSPaolo Bonzini dc->vmsd = &vmstate_via; 48247934d0aSPaolo Bonzini } 48347934d0aSPaolo Bonzini 48447934d0aSPaolo Bonzini static const TypeInfo via_info = { 48547934d0aSPaolo Bonzini .name = "VT82C686B", 48647934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 48747934d0aSPaolo Bonzini .instance_size = sizeof(VT82C686BState), 48847934d0aSPaolo Bonzini .class_init = via_class_init, 48947934d0aSPaolo Bonzini }; 49047934d0aSPaolo Bonzini 49147934d0aSPaolo Bonzini static void vt82c686b_register_types(void) 49247934d0aSPaolo Bonzini { 49347934d0aSPaolo Bonzini type_register_static(&via_ac97_info); 49447934d0aSPaolo Bonzini type_register_static(&via_mc97_info); 49547934d0aSPaolo Bonzini type_register_static(&via_pm_info); 49647934d0aSPaolo Bonzini type_register_static(&via_info); 49747934d0aSPaolo Bonzini } 49847934d0aSPaolo Bonzini 49947934d0aSPaolo Bonzini type_init(vt82c686b_register_types) 500