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; 4647934d0aSPaolo Bonzini SuperIOConfig superio_conf; 4747934d0aSPaolo Bonzini } VT82C686BState; 4847934d0aSPaolo Bonzini 4947934d0aSPaolo Bonzini static void superio_ioport_writeb(void *opaque, uint32_t addr, uint32_t data) 5047934d0aSPaolo Bonzini { 5147934d0aSPaolo Bonzini int can_write; 5247934d0aSPaolo Bonzini SuperIOConfig *superio_conf = opaque; 5347934d0aSPaolo Bonzini 5447934d0aSPaolo Bonzini DPRINTF("superio_ioport_writeb address 0x%x val 0x%x\n", addr, data); 5547934d0aSPaolo Bonzini if (addr == 0x3f0) { 5647934d0aSPaolo Bonzini superio_conf->index = data & 0xff; 5747934d0aSPaolo Bonzini } else { 5847934d0aSPaolo Bonzini /* 0x3f1 */ 5947934d0aSPaolo Bonzini switch (superio_conf->index) { 6047934d0aSPaolo Bonzini case 0x00 ... 0xdf: 6147934d0aSPaolo Bonzini case 0xe4: 6247934d0aSPaolo Bonzini case 0xe5: 6347934d0aSPaolo Bonzini case 0xe9 ... 0xed: 6447934d0aSPaolo Bonzini case 0xf3: 6547934d0aSPaolo Bonzini case 0xf5: 6647934d0aSPaolo Bonzini case 0xf7: 6747934d0aSPaolo Bonzini case 0xf9 ... 0xfb: 6847934d0aSPaolo Bonzini case 0xfd ... 0xff: 6947934d0aSPaolo Bonzini can_write = 0; 7047934d0aSPaolo Bonzini break; 7147934d0aSPaolo Bonzini default: 7247934d0aSPaolo Bonzini can_write = 1; 7347934d0aSPaolo Bonzini 7447934d0aSPaolo Bonzini if (can_write) { 7547934d0aSPaolo Bonzini switch (superio_conf->index) { 7647934d0aSPaolo Bonzini case 0xe7: 7747934d0aSPaolo Bonzini if ((data & 0xff) != 0xfe) { 7847934d0aSPaolo Bonzini DPRINTF("chage uart 1 base. unsupported yet\n"); 7947934d0aSPaolo Bonzini } 8047934d0aSPaolo Bonzini break; 8147934d0aSPaolo Bonzini case 0xe8: 8247934d0aSPaolo Bonzini if ((data & 0xff) != 0xbe) { 8347934d0aSPaolo Bonzini DPRINTF("chage uart 2 base. unsupported yet\n"); 8447934d0aSPaolo Bonzini } 8547934d0aSPaolo Bonzini break; 8647934d0aSPaolo Bonzini 8747934d0aSPaolo Bonzini default: 8847934d0aSPaolo Bonzini superio_conf->config[superio_conf->index] = data & 0xff; 8947934d0aSPaolo Bonzini } 9047934d0aSPaolo Bonzini } 9147934d0aSPaolo Bonzini } 9247934d0aSPaolo Bonzini superio_conf->config[superio_conf->index] = data & 0xff; 9347934d0aSPaolo Bonzini } 9447934d0aSPaolo Bonzini } 9547934d0aSPaolo Bonzini 9647934d0aSPaolo Bonzini static uint32_t superio_ioport_readb(void *opaque, uint32_t addr) 9747934d0aSPaolo Bonzini { 9847934d0aSPaolo Bonzini SuperIOConfig *superio_conf = opaque; 9947934d0aSPaolo Bonzini 10047934d0aSPaolo Bonzini DPRINTF("superio_ioport_readb address 0x%x\n", addr); 10147934d0aSPaolo Bonzini return (superio_conf->config[superio_conf->index]); 10247934d0aSPaolo Bonzini } 10347934d0aSPaolo Bonzini 10447934d0aSPaolo Bonzini static void vt82c686b_reset(void * opaque) 10547934d0aSPaolo Bonzini { 10647934d0aSPaolo Bonzini PCIDevice *d = opaque; 10747934d0aSPaolo Bonzini uint8_t *pci_conf = d->config; 10847934d0aSPaolo Bonzini VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); 10947934d0aSPaolo Bonzini 11047934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); 11147934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | 11247934d0aSPaolo Bonzini PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); 11347934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); 11447934d0aSPaolo Bonzini 11547934d0aSPaolo Bonzini pci_conf[0x48] = 0x01; /* Miscellaneous Control 3 */ 11647934d0aSPaolo Bonzini pci_conf[0x4a] = 0x04; /* IDE interrupt Routing */ 11747934d0aSPaolo Bonzini pci_conf[0x4f] = 0x03; /* DMA/Master Mem Access Control 3 */ 11847934d0aSPaolo Bonzini pci_conf[0x50] = 0x2d; /* PnP DMA Request Control */ 11947934d0aSPaolo Bonzini pci_conf[0x59] = 0x04; 12047934d0aSPaolo Bonzini pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/ 12147934d0aSPaolo Bonzini pci_conf[0x5f] = 0x04; 12247934d0aSPaolo Bonzini pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */ 12347934d0aSPaolo Bonzini 12447934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe0] = 0x3c; 12547934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe2] = 0x03; 12647934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe3] = 0xfc; 12747934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe6] = 0xde; 12847934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe7] = 0xfe; 12947934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe8] = 0xbe; 13047934d0aSPaolo Bonzini } 13147934d0aSPaolo Bonzini 13247934d0aSPaolo Bonzini /* write config pci function0 registers. PCI-ISA bridge */ 13347934d0aSPaolo Bonzini static void vt82c686b_write_config(PCIDevice * d, uint32_t address, 13447934d0aSPaolo Bonzini uint32_t val, int len) 13547934d0aSPaolo Bonzini { 13647934d0aSPaolo Bonzini VT82C686BState *vt686 = DO_UPCAST(VT82C686BState, dev, d); 13747934d0aSPaolo Bonzini 13847934d0aSPaolo Bonzini DPRINTF("vt82c686b_write_config address 0x%x val 0x%x len 0x%x\n", 13947934d0aSPaolo Bonzini address, val, len); 14047934d0aSPaolo Bonzini 14147934d0aSPaolo Bonzini pci_default_write_config(d, address, val, len); 14247934d0aSPaolo Bonzini if (address == 0x85) { /* enable or disable super IO configure */ 14347934d0aSPaolo Bonzini if (val & 0x2) { 14447934d0aSPaolo Bonzini /* floppy also uses 0x3f0 and 0x3f1. 14547934d0aSPaolo Bonzini * But we do not emulate flopy,so just set it here. */ 14647934d0aSPaolo Bonzini isa_unassign_ioport(0x3f0, 2); 14747934d0aSPaolo Bonzini register_ioport_read(0x3f0, 2, 1, superio_ioport_readb, 14847934d0aSPaolo Bonzini &vt686->superio_conf); 14947934d0aSPaolo Bonzini register_ioport_write(0x3f0, 2, 1, superio_ioport_writeb, 15047934d0aSPaolo Bonzini &vt686->superio_conf); 15147934d0aSPaolo Bonzini } else { 15247934d0aSPaolo Bonzini isa_unassign_ioport(0x3f0, 2); 15347934d0aSPaolo Bonzini } 15447934d0aSPaolo Bonzini } 15547934d0aSPaolo Bonzini } 15647934d0aSPaolo Bonzini 15747934d0aSPaolo Bonzini #define ACPI_DBG_IO_ADDR 0xb044 15847934d0aSPaolo Bonzini 15947934d0aSPaolo Bonzini typedef struct VT686PMState { 16047934d0aSPaolo Bonzini PCIDevice dev; 16147934d0aSPaolo Bonzini MemoryRegion io; 16247934d0aSPaolo Bonzini ACPIREGS ar; 16347934d0aSPaolo Bonzini APMState apm; 16447934d0aSPaolo Bonzini PMSMBus smb; 16547934d0aSPaolo Bonzini uint32_t smb_io_base; 16647934d0aSPaolo Bonzini } VT686PMState; 16747934d0aSPaolo Bonzini 16847934d0aSPaolo Bonzini typedef struct VT686AC97State { 16947934d0aSPaolo Bonzini PCIDevice dev; 17047934d0aSPaolo Bonzini } VT686AC97State; 17147934d0aSPaolo Bonzini 17247934d0aSPaolo Bonzini typedef struct VT686MC97State { 17347934d0aSPaolo Bonzini PCIDevice dev; 17447934d0aSPaolo Bonzini } VT686MC97State; 17547934d0aSPaolo Bonzini 17647934d0aSPaolo Bonzini static void pm_update_sci(VT686PMState *s) 17747934d0aSPaolo Bonzini { 17847934d0aSPaolo Bonzini int sci_level, pmsts; 17947934d0aSPaolo Bonzini 18047934d0aSPaolo Bonzini pmsts = acpi_pm1_evt_get_sts(&s->ar); 18147934d0aSPaolo Bonzini sci_level = (((pmsts & s->ar.pm1.evt.en) & 18247934d0aSPaolo Bonzini (ACPI_BITMASK_RT_CLOCK_ENABLE | 18347934d0aSPaolo Bonzini ACPI_BITMASK_POWER_BUTTON_ENABLE | 18447934d0aSPaolo Bonzini ACPI_BITMASK_GLOBAL_LOCK_ENABLE | 18547934d0aSPaolo Bonzini ACPI_BITMASK_TIMER_ENABLE)) != 0); 18647934d0aSPaolo Bonzini qemu_set_irq(s->dev.irq[0], sci_level); 18747934d0aSPaolo Bonzini /* schedule a timer interruption if needed */ 18847934d0aSPaolo Bonzini acpi_pm_tmr_update(&s->ar, (s->ar.pm1.evt.en & ACPI_BITMASK_TIMER_ENABLE) && 18947934d0aSPaolo Bonzini !(pmsts & ACPI_BITMASK_TIMER_STATUS)); 19047934d0aSPaolo Bonzini } 19147934d0aSPaolo Bonzini 19247934d0aSPaolo Bonzini static void pm_tmr_timer(ACPIREGS *ar) 19347934d0aSPaolo Bonzini { 19447934d0aSPaolo Bonzini VT686PMState *s = container_of(ar, VT686PMState, ar); 19547934d0aSPaolo Bonzini pm_update_sci(s); 19647934d0aSPaolo Bonzini } 19747934d0aSPaolo Bonzini 19847934d0aSPaolo Bonzini static void pm_io_space_update(VT686PMState *s) 19947934d0aSPaolo Bonzini { 20047934d0aSPaolo Bonzini uint32_t pm_io_base; 20147934d0aSPaolo Bonzini 20247934d0aSPaolo Bonzini pm_io_base = pci_get_long(s->dev.config + 0x40); 20347934d0aSPaolo Bonzini pm_io_base &= 0xffc0; 20447934d0aSPaolo Bonzini 20547934d0aSPaolo Bonzini memory_region_transaction_begin(); 20647934d0aSPaolo Bonzini memory_region_set_enabled(&s->io, s->dev.config[0x80] & 1); 20747934d0aSPaolo Bonzini memory_region_set_address(&s->io, pm_io_base); 20847934d0aSPaolo Bonzini memory_region_transaction_commit(); 20947934d0aSPaolo Bonzini } 21047934d0aSPaolo Bonzini 21147934d0aSPaolo Bonzini static void pm_write_config(PCIDevice *d, 21247934d0aSPaolo Bonzini uint32_t address, uint32_t val, int len) 21347934d0aSPaolo Bonzini { 21447934d0aSPaolo Bonzini DPRINTF("pm_write_config address 0x%x val 0x%x len 0x%x\n", 21547934d0aSPaolo Bonzini address, val, len); 21647934d0aSPaolo Bonzini pci_default_write_config(d, address, val, len); 21747934d0aSPaolo Bonzini } 21847934d0aSPaolo Bonzini 21947934d0aSPaolo Bonzini static int vmstate_acpi_post_load(void *opaque, int version_id) 22047934d0aSPaolo Bonzini { 22147934d0aSPaolo Bonzini VT686PMState *s = opaque; 22247934d0aSPaolo Bonzini 22347934d0aSPaolo Bonzini pm_io_space_update(s); 22447934d0aSPaolo Bonzini return 0; 22547934d0aSPaolo Bonzini } 22647934d0aSPaolo Bonzini 22747934d0aSPaolo Bonzini static const VMStateDescription vmstate_acpi = { 22847934d0aSPaolo Bonzini .name = "vt82c686b_pm", 22947934d0aSPaolo Bonzini .version_id = 1, 23047934d0aSPaolo Bonzini .minimum_version_id = 1, 23147934d0aSPaolo Bonzini .minimum_version_id_old = 1, 23247934d0aSPaolo Bonzini .post_load = vmstate_acpi_post_load, 23347934d0aSPaolo Bonzini .fields = (VMStateField []) { 23447934d0aSPaolo Bonzini VMSTATE_PCI_DEVICE(dev, VT686PMState), 23547934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.evt.sts, VT686PMState), 23647934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.evt.en, VT686PMState), 23747934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.cnt.cnt, VT686PMState), 23847934d0aSPaolo Bonzini VMSTATE_STRUCT(apm, VT686PMState, 0, vmstate_apm, APMState), 23947934d0aSPaolo Bonzini VMSTATE_TIMER(ar.tmr.timer, VT686PMState), 24047934d0aSPaolo Bonzini VMSTATE_INT64(ar.tmr.overflow_time, VT686PMState), 24147934d0aSPaolo Bonzini VMSTATE_END_OF_LIST() 24247934d0aSPaolo Bonzini } 24347934d0aSPaolo Bonzini }; 24447934d0aSPaolo Bonzini 24547934d0aSPaolo Bonzini /* 24647934d0aSPaolo Bonzini * TODO: vt82c686b_ac97_init() and vt82c686b_mc97_init() 24747934d0aSPaolo Bonzini * just register a PCI device now, functionalities will be implemented later. 24847934d0aSPaolo Bonzini */ 24947934d0aSPaolo Bonzini 25047934d0aSPaolo Bonzini static int vt82c686b_ac97_initfn(PCIDevice *dev) 25147934d0aSPaolo Bonzini { 25247934d0aSPaolo Bonzini VT686AC97State *s = DO_UPCAST(VT686AC97State, dev, dev); 25347934d0aSPaolo Bonzini uint8_t *pci_conf = s->dev.config; 25447934d0aSPaolo Bonzini 25547934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_INVALIDATE | 25647934d0aSPaolo Bonzini PCI_COMMAND_PARITY); 25747934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_CAP_LIST | 25847934d0aSPaolo Bonzini PCI_STATUS_DEVSEL_MEDIUM); 25947934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03); 26047934d0aSPaolo Bonzini 26147934d0aSPaolo Bonzini return 0; 26247934d0aSPaolo Bonzini } 26347934d0aSPaolo Bonzini 26447934d0aSPaolo Bonzini void vt82c686b_ac97_init(PCIBus *bus, int devfn) 26547934d0aSPaolo Bonzini { 26647934d0aSPaolo Bonzini PCIDevice *dev; 26747934d0aSPaolo Bonzini 26847934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_AC97"); 26947934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 27047934d0aSPaolo Bonzini } 27147934d0aSPaolo Bonzini 27247934d0aSPaolo Bonzini static void via_ac97_class_init(ObjectClass *klass, void *data) 27347934d0aSPaolo Bonzini { 27447934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 27547934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 27647934d0aSPaolo Bonzini 27747934d0aSPaolo Bonzini k->init = vt82c686b_ac97_initfn; 27847934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 27947934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_AC97; 28047934d0aSPaolo Bonzini k->revision = 0x50; 28147934d0aSPaolo Bonzini k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; 28247934d0aSPaolo Bonzini dc->desc = "AC97"; 28347934d0aSPaolo Bonzini } 28447934d0aSPaolo Bonzini 28547934d0aSPaolo Bonzini static const TypeInfo via_ac97_info = { 28647934d0aSPaolo Bonzini .name = "VT82C686B_AC97", 28747934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 28847934d0aSPaolo Bonzini .instance_size = sizeof(VT686AC97State), 28947934d0aSPaolo Bonzini .class_init = via_ac97_class_init, 29047934d0aSPaolo Bonzini }; 29147934d0aSPaolo Bonzini 29247934d0aSPaolo Bonzini static int vt82c686b_mc97_initfn(PCIDevice *dev) 29347934d0aSPaolo Bonzini { 29447934d0aSPaolo Bonzini VT686MC97State *s = DO_UPCAST(VT686MC97State, dev, dev); 29547934d0aSPaolo Bonzini uint8_t *pci_conf = s->dev.config; 29647934d0aSPaolo Bonzini 29747934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_INVALIDATE | 29847934d0aSPaolo Bonzini PCI_COMMAND_VGA_PALETTE); 29947934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); 30047934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03); 30147934d0aSPaolo Bonzini 30247934d0aSPaolo Bonzini return 0; 30347934d0aSPaolo Bonzini } 30447934d0aSPaolo Bonzini 30547934d0aSPaolo Bonzini void vt82c686b_mc97_init(PCIBus *bus, int devfn) 30647934d0aSPaolo Bonzini { 30747934d0aSPaolo Bonzini PCIDevice *dev; 30847934d0aSPaolo Bonzini 30947934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_MC97"); 31047934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 31147934d0aSPaolo Bonzini } 31247934d0aSPaolo Bonzini 31347934d0aSPaolo Bonzini static void via_mc97_class_init(ObjectClass *klass, void *data) 31447934d0aSPaolo Bonzini { 31547934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 31647934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 31747934d0aSPaolo Bonzini 31847934d0aSPaolo Bonzini k->init = vt82c686b_mc97_initfn; 31947934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 32047934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_MC97; 32147934d0aSPaolo Bonzini k->class_id = PCI_CLASS_COMMUNICATION_OTHER; 32247934d0aSPaolo Bonzini k->revision = 0x30; 32347934d0aSPaolo Bonzini dc->desc = "MC97"; 32447934d0aSPaolo Bonzini } 32547934d0aSPaolo Bonzini 32647934d0aSPaolo Bonzini static const TypeInfo via_mc97_info = { 32747934d0aSPaolo Bonzini .name = "VT82C686B_MC97", 32847934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 32947934d0aSPaolo Bonzini .instance_size = sizeof(VT686MC97State), 33047934d0aSPaolo Bonzini .class_init = via_mc97_class_init, 33147934d0aSPaolo Bonzini }; 33247934d0aSPaolo Bonzini 33347934d0aSPaolo Bonzini /* vt82c686 pm init */ 33447934d0aSPaolo Bonzini static int vt82c686b_pm_initfn(PCIDevice *dev) 33547934d0aSPaolo Bonzini { 33647934d0aSPaolo Bonzini VT686PMState *s = DO_UPCAST(VT686PMState, dev, dev); 33747934d0aSPaolo Bonzini uint8_t *pci_conf; 33847934d0aSPaolo Bonzini 33947934d0aSPaolo Bonzini pci_conf = s->dev.config; 34047934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, 0); 34147934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_FAST_BACK | 34247934d0aSPaolo Bonzini PCI_STATUS_DEVSEL_MEDIUM); 34347934d0aSPaolo Bonzini 34447934d0aSPaolo Bonzini /* 0x48-0x4B is Power Management I/O Base */ 34547934d0aSPaolo Bonzini pci_set_long(pci_conf + 0x48, 0x00000001); 34647934d0aSPaolo Bonzini 34747934d0aSPaolo Bonzini /* SMB ports:0xeee0~0xeeef */ 34847934d0aSPaolo Bonzini s->smb_io_base =((s->smb_io_base & 0xfff0) + 0x0); 34947934d0aSPaolo Bonzini pci_conf[0x90] = s->smb_io_base | 1; 35047934d0aSPaolo Bonzini pci_conf[0x91] = s->smb_io_base >> 8; 35147934d0aSPaolo Bonzini pci_conf[0xd2] = 0x90; 35247934d0aSPaolo Bonzini pm_smbus_init(&s->dev.qdev, &s->smb); 35347934d0aSPaolo Bonzini memory_region_add_subregion(get_system_io(), s->smb_io_base, &s->smb.io); 35447934d0aSPaolo Bonzini 35547934d0aSPaolo Bonzini apm_init(dev, &s->apm, NULL, s); 35647934d0aSPaolo Bonzini 35747934d0aSPaolo Bonzini memory_region_init(&s->io, "vt82c686-pm", 64); 35847934d0aSPaolo Bonzini memory_region_set_enabled(&s->io, false); 35947934d0aSPaolo Bonzini memory_region_add_subregion(get_system_io(), 0, &s->io); 36047934d0aSPaolo Bonzini 36147934d0aSPaolo Bonzini acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io); 36247934d0aSPaolo Bonzini acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io); 36347934d0aSPaolo Bonzini acpi_pm1_cnt_init(&s->ar, &s->io, 2); 36447934d0aSPaolo Bonzini 36547934d0aSPaolo Bonzini return 0; 36647934d0aSPaolo Bonzini } 36747934d0aSPaolo Bonzini 36847934d0aSPaolo Bonzini i2c_bus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, 36947934d0aSPaolo Bonzini qemu_irq sci_irq) 37047934d0aSPaolo Bonzini { 37147934d0aSPaolo Bonzini PCIDevice *dev; 37247934d0aSPaolo Bonzini VT686PMState *s; 37347934d0aSPaolo Bonzini 37447934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_PM"); 37547934d0aSPaolo Bonzini qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base); 37647934d0aSPaolo Bonzini 37747934d0aSPaolo Bonzini s = DO_UPCAST(VT686PMState, dev, dev); 37847934d0aSPaolo Bonzini 37947934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 38047934d0aSPaolo Bonzini 38147934d0aSPaolo Bonzini return s->smb.smbus; 38247934d0aSPaolo Bonzini } 38347934d0aSPaolo Bonzini 38447934d0aSPaolo Bonzini static Property via_pm_properties[] = { 38547934d0aSPaolo Bonzini DEFINE_PROP_UINT32("smb_io_base", VT686PMState, smb_io_base, 0), 38647934d0aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 38747934d0aSPaolo Bonzini }; 38847934d0aSPaolo Bonzini 38947934d0aSPaolo Bonzini static void via_pm_class_init(ObjectClass *klass, void *data) 39047934d0aSPaolo Bonzini { 39147934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 39247934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 39347934d0aSPaolo Bonzini 39447934d0aSPaolo Bonzini k->init = vt82c686b_pm_initfn; 39547934d0aSPaolo Bonzini k->config_write = pm_write_config; 39647934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 39747934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_ACPI; 39847934d0aSPaolo Bonzini k->class_id = PCI_CLASS_BRIDGE_OTHER; 39947934d0aSPaolo Bonzini k->revision = 0x40; 40047934d0aSPaolo Bonzini dc->desc = "PM"; 40147934d0aSPaolo Bonzini dc->vmsd = &vmstate_acpi; 40247934d0aSPaolo Bonzini dc->props = via_pm_properties; 40347934d0aSPaolo Bonzini } 40447934d0aSPaolo Bonzini 40547934d0aSPaolo Bonzini static const TypeInfo via_pm_info = { 40647934d0aSPaolo Bonzini .name = "VT82C686B_PM", 40747934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 40847934d0aSPaolo Bonzini .instance_size = sizeof(VT686PMState), 40947934d0aSPaolo Bonzini .class_init = via_pm_class_init, 41047934d0aSPaolo Bonzini }; 41147934d0aSPaolo Bonzini 41247934d0aSPaolo Bonzini static const VMStateDescription vmstate_via = { 41347934d0aSPaolo Bonzini .name = "vt82c686b", 41447934d0aSPaolo Bonzini .version_id = 1, 41547934d0aSPaolo Bonzini .minimum_version_id = 1, 41647934d0aSPaolo Bonzini .minimum_version_id_old = 1, 41747934d0aSPaolo Bonzini .fields = (VMStateField []) { 41847934d0aSPaolo Bonzini VMSTATE_PCI_DEVICE(dev, VT82C686BState), 41947934d0aSPaolo Bonzini VMSTATE_END_OF_LIST() 42047934d0aSPaolo Bonzini } 42147934d0aSPaolo Bonzini }; 42247934d0aSPaolo Bonzini 42347934d0aSPaolo Bonzini /* init the PCI-to-ISA bridge */ 42447934d0aSPaolo Bonzini static int vt82c686b_initfn(PCIDevice *d) 42547934d0aSPaolo Bonzini { 42647934d0aSPaolo Bonzini uint8_t *pci_conf; 42747934d0aSPaolo Bonzini uint8_t *wmask; 42847934d0aSPaolo Bonzini int i; 42947934d0aSPaolo Bonzini 43047934d0aSPaolo Bonzini isa_bus_new(&d->qdev, pci_address_space_io(d)); 43147934d0aSPaolo Bonzini 43247934d0aSPaolo Bonzini pci_conf = d->config; 43347934d0aSPaolo Bonzini pci_config_set_prog_interface(pci_conf, 0x0); 43447934d0aSPaolo Bonzini 43547934d0aSPaolo Bonzini wmask = d->wmask; 43647934d0aSPaolo Bonzini for (i = 0x00; i < 0xff; i++) { 43747934d0aSPaolo Bonzini if (i<=0x03 || (i>=0x08 && i<=0x3f)) { 43847934d0aSPaolo Bonzini wmask[i] = 0x00; 43947934d0aSPaolo Bonzini } 44047934d0aSPaolo Bonzini } 44147934d0aSPaolo Bonzini 44247934d0aSPaolo Bonzini qemu_register_reset(vt82c686b_reset, d); 44347934d0aSPaolo Bonzini 44447934d0aSPaolo Bonzini return 0; 44547934d0aSPaolo Bonzini } 44647934d0aSPaolo Bonzini 44747934d0aSPaolo Bonzini ISABus *vt82c686b_init(PCIBus *bus, int devfn) 44847934d0aSPaolo Bonzini { 44947934d0aSPaolo Bonzini PCIDevice *d; 45047934d0aSPaolo Bonzini 45147934d0aSPaolo Bonzini d = pci_create_simple_multifunction(bus, devfn, true, "VT82C686B"); 45247934d0aSPaolo Bonzini 453*2ae0e48dSAndreas Färber return ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0")); 45447934d0aSPaolo Bonzini } 45547934d0aSPaolo Bonzini 45647934d0aSPaolo Bonzini static void via_class_init(ObjectClass *klass, void *data) 45747934d0aSPaolo Bonzini { 45847934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 45947934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 46047934d0aSPaolo Bonzini 46147934d0aSPaolo Bonzini k->init = vt82c686b_initfn; 46247934d0aSPaolo Bonzini k->config_write = vt82c686b_write_config; 46347934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 46447934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE; 46547934d0aSPaolo Bonzini k->class_id = PCI_CLASS_BRIDGE_ISA; 46647934d0aSPaolo Bonzini k->revision = 0x40; 46747934d0aSPaolo Bonzini dc->desc = "ISA bridge"; 46847934d0aSPaolo Bonzini dc->no_user = 1; 46947934d0aSPaolo Bonzini dc->vmsd = &vmstate_via; 47047934d0aSPaolo Bonzini } 47147934d0aSPaolo Bonzini 47247934d0aSPaolo Bonzini static const TypeInfo via_info = { 47347934d0aSPaolo Bonzini .name = "VT82C686B", 47447934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 47547934d0aSPaolo Bonzini .instance_size = sizeof(VT82C686BState), 47647934d0aSPaolo Bonzini .class_init = via_class_init, 47747934d0aSPaolo Bonzini }; 47847934d0aSPaolo Bonzini 47947934d0aSPaolo Bonzini static void vt82c686b_register_types(void) 48047934d0aSPaolo Bonzini { 48147934d0aSPaolo Bonzini type_register_static(&via_ac97_info); 48247934d0aSPaolo Bonzini type_register_static(&via_mc97_info); 48347934d0aSPaolo Bonzini type_register_static(&via_pm_info); 48447934d0aSPaolo Bonzini type_register_static(&via_info); 48547934d0aSPaolo Bonzini } 48647934d0aSPaolo Bonzini 48747934d0aSPaolo Bonzini type_init(vt82c686b_register_types) 488