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 { 399feb8adeSPaolo Bonzini uint8_t config[0x100]; 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 SuperIOConfig *superio_conf = opaque; 5447934d0aSPaolo Bonzini 5547934d0aSPaolo Bonzini DPRINTF("superio_ioport_writeb address 0x%x val 0x%x\n", addr, data); 5647934d0aSPaolo Bonzini if (addr == 0x3f0) { 5747934d0aSPaolo Bonzini superio_conf->index = data & 0xff; 5847934d0aSPaolo Bonzini } else { 59b196d969Szhanghailiang bool can_write = true; 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: 71b196d969Szhanghailiang can_write = false; 7247934d0aSPaolo Bonzini break; 7347934d0aSPaolo Bonzini case 0xe7: 7447934d0aSPaolo Bonzini if ((data & 0xff) != 0xfe) { 75b196d969Szhanghailiang DPRINTF("change uart 1 base. unsupported yet\n"); 76b196d969Szhanghailiang can_write = false; 7747934d0aSPaolo Bonzini } 7847934d0aSPaolo Bonzini break; 7947934d0aSPaolo Bonzini case 0xe8: 8047934d0aSPaolo Bonzini if ((data & 0xff) != 0xbe) { 81b196d969Szhanghailiang DPRINTF("change uart 2 base. unsupported yet\n"); 82b196d969Szhanghailiang can_write = false; 8347934d0aSPaolo Bonzini } 8447934d0aSPaolo Bonzini break; 8547934d0aSPaolo Bonzini default: 86b196d969Szhanghailiang break; 87b196d969Szhanghailiang 88b196d969Szhanghailiang } 89b196d969Szhanghailiang if (can_write) { 9047934d0aSPaolo Bonzini superio_conf->config[superio_conf->index] = data & 0xff; 9147934d0aSPaolo Bonzini } 9247934d0aSPaolo Bonzini } 9347934d0aSPaolo Bonzini } 9447934d0aSPaolo Bonzini 95bcc37e24SJan Kiszka static uint64_t superio_ioport_readb(void *opaque, hwaddr addr, unsigned size) 9647934d0aSPaolo Bonzini { 9747934d0aSPaolo Bonzini SuperIOConfig *superio_conf = opaque; 9847934d0aSPaolo Bonzini 9947934d0aSPaolo Bonzini DPRINTF("superio_ioport_readb address 0x%x\n", addr); 10047934d0aSPaolo Bonzini return (superio_conf->config[superio_conf->index]); 10147934d0aSPaolo Bonzini } 10247934d0aSPaolo Bonzini 103bcc37e24SJan Kiszka static const MemoryRegionOps superio_ops = { 104bcc37e24SJan Kiszka .read = superio_ioport_readb, 105bcc37e24SJan Kiszka .write = superio_ioport_writeb, 106bcc37e24SJan Kiszka .endianness = DEVICE_NATIVE_ENDIAN, 107bcc37e24SJan Kiszka .impl = { 108bcc37e24SJan Kiszka .min_access_size = 1, 109bcc37e24SJan Kiszka .max_access_size = 1, 110bcc37e24SJan Kiszka }, 111bcc37e24SJan Kiszka }; 112bcc37e24SJan Kiszka 11347934d0aSPaolo Bonzini static void vt82c686b_reset(void * opaque) 11447934d0aSPaolo Bonzini { 11547934d0aSPaolo Bonzini PCIDevice *d = opaque; 11647934d0aSPaolo Bonzini uint8_t *pci_conf = d->config; 11747934d0aSPaolo Bonzini VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); 11847934d0aSPaolo Bonzini 11947934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); 12047934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | 12147934d0aSPaolo Bonzini PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); 12247934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); 12347934d0aSPaolo Bonzini 12447934d0aSPaolo Bonzini pci_conf[0x48] = 0x01; /* Miscellaneous Control 3 */ 12547934d0aSPaolo Bonzini pci_conf[0x4a] = 0x04; /* IDE interrupt Routing */ 12647934d0aSPaolo Bonzini pci_conf[0x4f] = 0x03; /* DMA/Master Mem Access Control 3 */ 12747934d0aSPaolo Bonzini pci_conf[0x50] = 0x2d; /* PnP DMA Request Control */ 12847934d0aSPaolo Bonzini pci_conf[0x59] = 0x04; 12947934d0aSPaolo Bonzini pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/ 13047934d0aSPaolo Bonzini pci_conf[0x5f] = 0x04; 13147934d0aSPaolo Bonzini pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */ 13247934d0aSPaolo Bonzini 13347934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe0] = 0x3c; 13447934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe2] = 0x03; 13547934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe3] = 0xfc; 13647934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe6] = 0xde; 13747934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe7] = 0xfe; 13847934d0aSPaolo Bonzini vt82c->superio_conf.config[0xe8] = 0xbe; 13947934d0aSPaolo Bonzini } 14047934d0aSPaolo Bonzini 14147934d0aSPaolo Bonzini /* write config pci function0 registers. PCI-ISA bridge */ 14247934d0aSPaolo Bonzini static void vt82c686b_write_config(PCIDevice * d, uint32_t address, 14347934d0aSPaolo Bonzini uint32_t val, int len) 14447934d0aSPaolo Bonzini { 14547934d0aSPaolo Bonzini VT82C686BState *vt686 = DO_UPCAST(VT82C686BState, dev, d); 14647934d0aSPaolo Bonzini 14747934d0aSPaolo Bonzini DPRINTF("vt82c686b_write_config address 0x%x val 0x%x len 0x%x\n", 14847934d0aSPaolo Bonzini address, val, len); 14947934d0aSPaolo Bonzini 15047934d0aSPaolo Bonzini pci_default_write_config(d, address, val, len); 15147934d0aSPaolo Bonzini if (address == 0x85) { /* enable or disable super IO configure */ 152bcc37e24SJan Kiszka memory_region_set_enabled(&vt686->superio, val & 0x2); 15347934d0aSPaolo Bonzini } 15447934d0aSPaolo Bonzini } 15547934d0aSPaolo Bonzini 15647934d0aSPaolo Bonzini #define ACPI_DBG_IO_ADDR 0xb044 15747934d0aSPaolo Bonzini 15847934d0aSPaolo Bonzini typedef struct VT686PMState { 15947934d0aSPaolo Bonzini PCIDevice dev; 16047934d0aSPaolo Bonzini MemoryRegion io; 16147934d0aSPaolo Bonzini ACPIREGS ar; 16247934d0aSPaolo Bonzini APMState apm; 16347934d0aSPaolo Bonzini PMSMBus smb; 16447934d0aSPaolo Bonzini uint32_t smb_io_base; 16547934d0aSPaolo Bonzini } VT686PMState; 16647934d0aSPaolo Bonzini 16747934d0aSPaolo Bonzini typedef struct VT686AC97State { 16847934d0aSPaolo Bonzini PCIDevice dev; 16947934d0aSPaolo Bonzini } VT686AC97State; 17047934d0aSPaolo Bonzini 17147934d0aSPaolo Bonzini typedef struct VT686MC97State { 17247934d0aSPaolo Bonzini PCIDevice dev; 17347934d0aSPaolo Bonzini } VT686MC97State; 17447934d0aSPaolo Bonzini 17547934d0aSPaolo Bonzini static void pm_update_sci(VT686PMState *s) 17647934d0aSPaolo Bonzini { 17747934d0aSPaolo Bonzini int sci_level, pmsts; 17847934d0aSPaolo Bonzini 17947934d0aSPaolo Bonzini pmsts = acpi_pm1_evt_get_sts(&s->ar); 18047934d0aSPaolo Bonzini sci_level = (((pmsts & s->ar.pm1.evt.en) & 18147934d0aSPaolo Bonzini (ACPI_BITMASK_RT_CLOCK_ENABLE | 18247934d0aSPaolo Bonzini ACPI_BITMASK_POWER_BUTTON_ENABLE | 18347934d0aSPaolo Bonzini ACPI_BITMASK_GLOBAL_LOCK_ENABLE | 18447934d0aSPaolo Bonzini ACPI_BITMASK_TIMER_ENABLE)) != 0); 1859e64f8a3SMarcel Apfelbaum pci_set_irq(&s->dev, sci_level); 18647934d0aSPaolo Bonzini /* schedule a timer interruption if needed */ 18747934d0aSPaolo Bonzini acpi_pm_tmr_update(&s->ar, (s->ar.pm1.evt.en & ACPI_BITMASK_TIMER_ENABLE) && 18847934d0aSPaolo Bonzini !(pmsts & ACPI_BITMASK_TIMER_STATUS)); 18947934d0aSPaolo Bonzini } 19047934d0aSPaolo Bonzini 19147934d0aSPaolo Bonzini static void pm_tmr_timer(ACPIREGS *ar) 19247934d0aSPaolo Bonzini { 19347934d0aSPaolo Bonzini VT686PMState *s = container_of(ar, VT686PMState, ar); 19447934d0aSPaolo Bonzini pm_update_sci(s); 19547934d0aSPaolo Bonzini } 19647934d0aSPaolo Bonzini 19747934d0aSPaolo Bonzini static void pm_io_space_update(VT686PMState *s) 19847934d0aSPaolo Bonzini { 19947934d0aSPaolo Bonzini uint32_t pm_io_base; 20047934d0aSPaolo Bonzini 20147934d0aSPaolo Bonzini pm_io_base = pci_get_long(s->dev.config + 0x40); 20247934d0aSPaolo Bonzini pm_io_base &= 0xffc0; 20347934d0aSPaolo Bonzini 20447934d0aSPaolo Bonzini memory_region_transaction_begin(); 20547934d0aSPaolo Bonzini memory_region_set_enabled(&s->io, s->dev.config[0x80] & 1); 20647934d0aSPaolo Bonzini memory_region_set_address(&s->io, pm_io_base); 20747934d0aSPaolo Bonzini memory_region_transaction_commit(); 20847934d0aSPaolo Bonzini } 20947934d0aSPaolo Bonzini 21047934d0aSPaolo Bonzini static void pm_write_config(PCIDevice *d, 21147934d0aSPaolo Bonzini uint32_t address, uint32_t val, int len) 21247934d0aSPaolo Bonzini { 21347934d0aSPaolo Bonzini DPRINTF("pm_write_config address 0x%x val 0x%x len 0x%x\n", 21447934d0aSPaolo Bonzini address, val, len); 21547934d0aSPaolo Bonzini pci_default_write_config(d, address, val, len); 21647934d0aSPaolo Bonzini } 21747934d0aSPaolo Bonzini 21847934d0aSPaolo Bonzini static int vmstate_acpi_post_load(void *opaque, int version_id) 21947934d0aSPaolo Bonzini { 22047934d0aSPaolo Bonzini VT686PMState *s = opaque; 22147934d0aSPaolo Bonzini 22247934d0aSPaolo Bonzini pm_io_space_update(s); 22347934d0aSPaolo Bonzini return 0; 22447934d0aSPaolo Bonzini } 22547934d0aSPaolo Bonzini 22647934d0aSPaolo Bonzini static const VMStateDescription vmstate_acpi = { 22747934d0aSPaolo Bonzini .name = "vt82c686b_pm", 22847934d0aSPaolo Bonzini .version_id = 1, 22947934d0aSPaolo Bonzini .minimum_version_id = 1, 23047934d0aSPaolo Bonzini .post_load = vmstate_acpi_post_load, 23147934d0aSPaolo Bonzini .fields = (VMStateField[]) { 23247934d0aSPaolo Bonzini VMSTATE_PCI_DEVICE(dev, VT686PMState), 23347934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.evt.sts, VT686PMState), 23447934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.evt.en, VT686PMState), 23547934d0aSPaolo Bonzini VMSTATE_UINT16(ar.pm1.cnt.cnt, VT686PMState), 23647934d0aSPaolo Bonzini VMSTATE_STRUCT(apm, VT686PMState, 0, vmstate_apm, APMState), 237e720677eSPaolo Bonzini VMSTATE_TIMER_PTR(ar.tmr.timer, VT686PMState), 23847934d0aSPaolo Bonzini VMSTATE_INT64(ar.tmr.overflow_time, VT686PMState), 23947934d0aSPaolo Bonzini VMSTATE_END_OF_LIST() 24047934d0aSPaolo Bonzini } 24147934d0aSPaolo Bonzini }; 24247934d0aSPaolo Bonzini 24347934d0aSPaolo Bonzini /* 24447934d0aSPaolo Bonzini * TODO: vt82c686b_ac97_init() and vt82c686b_mc97_init() 24547934d0aSPaolo Bonzini * just register a PCI device now, functionalities will be implemented later. 24647934d0aSPaolo Bonzini */ 24747934d0aSPaolo Bonzini 24847934d0aSPaolo Bonzini static int vt82c686b_ac97_initfn(PCIDevice *dev) 24947934d0aSPaolo Bonzini { 25047934d0aSPaolo Bonzini VT686AC97State *s = DO_UPCAST(VT686AC97State, dev, dev); 25147934d0aSPaolo Bonzini uint8_t *pci_conf = s->dev.config; 25247934d0aSPaolo Bonzini 25347934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_INVALIDATE | 25447934d0aSPaolo Bonzini PCI_COMMAND_PARITY); 25547934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_CAP_LIST | 25647934d0aSPaolo Bonzini PCI_STATUS_DEVSEL_MEDIUM); 25747934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03); 25847934d0aSPaolo Bonzini 25947934d0aSPaolo Bonzini return 0; 26047934d0aSPaolo Bonzini } 26147934d0aSPaolo Bonzini 26247934d0aSPaolo Bonzini void vt82c686b_ac97_init(PCIBus *bus, int devfn) 26347934d0aSPaolo Bonzini { 26447934d0aSPaolo Bonzini PCIDevice *dev; 26547934d0aSPaolo Bonzini 26647934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_AC97"); 26747934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 26847934d0aSPaolo Bonzini } 26947934d0aSPaolo Bonzini 27047934d0aSPaolo Bonzini static void via_ac97_class_init(ObjectClass *klass, void *data) 27147934d0aSPaolo Bonzini { 27247934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 27347934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 27447934d0aSPaolo Bonzini 27547934d0aSPaolo Bonzini k->init = vt82c686b_ac97_initfn; 27647934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 27747934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_AC97; 27847934d0aSPaolo Bonzini k->revision = 0x50; 27947934d0aSPaolo Bonzini k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO; 280125ee0edSMarcel Apfelbaum set_bit(DEVICE_CATEGORY_SOUND, dc->categories); 28147934d0aSPaolo Bonzini dc->desc = "AC97"; 28247934d0aSPaolo Bonzini } 28347934d0aSPaolo Bonzini 28447934d0aSPaolo Bonzini static const TypeInfo via_ac97_info = { 28547934d0aSPaolo Bonzini .name = "VT82C686B_AC97", 28647934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 28747934d0aSPaolo Bonzini .instance_size = sizeof(VT686AC97State), 28847934d0aSPaolo Bonzini .class_init = via_ac97_class_init, 28947934d0aSPaolo Bonzini }; 29047934d0aSPaolo Bonzini 29147934d0aSPaolo Bonzini static int vt82c686b_mc97_initfn(PCIDevice *dev) 29247934d0aSPaolo Bonzini { 29347934d0aSPaolo Bonzini VT686MC97State *s = DO_UPCAST(VT686MC97State, dev, dev); 29447934d0aSPaolo Bonzini uint8_t *pci_conf = s->dev.config; 29547934d0aSPaolo Bonzini 29647934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_INVALIDATE | 29747934d0aSPaolo Bonzini PCI_COMMAND_VGA_PALETTE); 29847934d0aSPaolo Bonzini pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); 29947934d0aSPaolo Bonzini pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03); 30047934d0aSPaolo Bonzini 30147934d0aSPaolo Bonzini return 0; 30247934d0aSPaolo Bonzini } 30347934d0aSPaolo Bonzini 30447934d0aSPaolo Bonzini void vt82c686b_mc97_init(PCIBus *bus, int devfn) 30547934d0aSPaolo Bonzini { 30647934d0aSPaolo Bonzini PCIDevice *dev; 30747934d0aSPaolo Bonzini 30847934d0aSPaolo Bonzini dev = pci_create(bus, devfn, "VT82C686B_MC97"); 30947934d0aSPaolo Bonzini qdev_init_nofail(&dev->qdev); 31047934d0aSPaolo Bonzini } 31147934d0aSPaolo Bonzini 31247934d0aSPaolo Bonzini static void via_mc97_class_init(ObjectClass *klass, void *data) 31347934d0aSPaolo Bonzini { 31447934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 31547934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 31647934d0aSPaolo Bonzini 31747934d0aSPaolo Bonzini k->init = vt82c686b_mc97_initfn; 31847934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 31947934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_MC97; 32047934d0aSPaolo Bonzini k->class_id = PCI_CLASS_COMMUNICATION_OTHER; 32147934d0aSPaolo Bonzini k->revision = 0x30; 322125ee0edSMarcel Apfelbaum set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); 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 3571437c94bSPaolo Bonzini memory_region_init(&s->io, OBJECT(dev), "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 368a5c82852SAndreas Färber I2CBus *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; 402125ee0edSMarcel Apfelbaum set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); 40347934d0aSPaolo Bonzini dc->props = via_pm_properties; 40447934d0aSPaolo Bonzini } 40547934d0aSPaolo Bonzini 40647934d0aSPaolo Bonzini static const TypeInfo via_pm_info = { 40747934d0aSPaolo Bonzini .name = "VT82C686B_PM", 40847934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 40947934d0aSPaolo Bonzini .instance_size = sizeof(VT686PMState), 41047934d0aSPaolo Bonzini .class_init = via_pm_class_init, 41147934d0aSPaolo Bonzini }; 41247934d0aSPaolo Bonzini 41347934d0aSPaolo Bonzini static const VMStateDescription vmstate_via = { 41447934d0aSPaolo Bonzini .name = "vt82c686b", 41547934d0aSPaolo Bonzini .version_id = 1, 41647934d0aSPaolo Bonzini .minimum_version_id = 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 { 426bcc37e24SJan Kiszka VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); 42747934d0aSPaolo Bonzini uint8_t *pci_conf; 428bcc37e24SJan Kiszka ISABus *isa_bus; 42947934d0aSPaolo Bonzini uint8_t *wmask; 43047934d0aSPaolo Bonzini int i; 43147934d0aSPaolo Bonzini 432*bb2ed009SHervé Poussineau isa_bus = isa_bus_new(DEVICE(d), get_system_memory(), 433*bb2ed009SHervé Poussineau pci_address_space_io(d)); 43447934d0aSPaolo Bonzini 43547934d0aSPaolo Bonzini pci_conf = d->config; 43647934d0aSPaolo Bonzini pci_config_set_prog_interface(pci_conf, 0x0); 43747934d0aSPaolo Bonzini 43847934d0aSPaolo Bonzini wmask = d->wmask; 43947934d0aSPaolo Bonzini for (i = 0x00; i < 0xff; i++) { 44047934d0aSPaolo Bonzini if (i<=0x03 || (i>=0x08 && i<=0x3f)) { 44147934d0aSPaolo Bonzini wmask[i] = 0x00; 44247934d0aSPaolo Bonzini } 44347934d0aSPaolo Bonzini } 44447934d0aSPaolo Bonzini 445db10ca90SPaolo Bonzini memory_region_init_io(&vt82c->superio, OBJECT(d), &superio_ops, 4462c9b15caSPaolo Bonzini &vt82c->superio_conf, "superio", 2); 447bcc37e24SJan Kiszka memory_region_set_enabled(&vt82c->superio, false); 448bcc37e24SJan Kiszka /* The floppy also uses 0x3f0 and 0x3f1. 449bcc37e24SJan Kiszka * But we do not emulate a floppy, so just set it here. */ 450bcc37e24SJan Kiszka memory_region_add_subregion(isa_bus->address_space_io, 0x3f0, 451bcc37e24SJan Kiszka &vt82c->superio); 452bcc37e24SJan Kiszka 45347934d0aSPaolo Bonzini qemu_register_reset(vt82c686b_reset, d); 45447934d0aSPaolo Bonzini 45547934d0aSPaolo Bonzini return 0; 45647934d0aSPaolo Bonzini } 45747934d0aSPaolo Bonzini 45847934d0aSPaolo Bonzini ISABus *vt82c686b_init(PCIBus *bus, int devfn) 45947934d0aSPaolo Bonzini { 46047934d0aSPaolo Bonzini PCIDevice *d; 46147934d0aSPaolo Bonzini 46247934d0aSPaolo Bonzini d = pci_create_simple_multifunction(bus, devfn, true, "VT82C686B"); 46347934d0aSPaolo Bonzini 4642ae0e48dSAndreas Färber return ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0")); 46547934d0aSPaolo Bonzini } 46647934d0aSPaolo Bonzini 46747934d0aSPaolo Bonzini static void via_class_init(ObjectClass *klass, void *data) 46847934d0aSPaolo Bonzini { 46947934d0aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 47047934d0aSPaolo Bonzini PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 47147934d0aSPaolo Bonzini 47247934d0aSPaolo Bonzini k->init = vt82c686b_initfn; 47347934d0aSPaolo Bonzini k->config_write = vt82c686b_write_config; 47447934d0aSPaolo Bonzini k->vendor_id = PCI_VENDOR_ID_VIA; 47547934d0aSPaolo Bonzini k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE; 47647934d0aSPaolo Bonzini k->class_id = PCI_CLASS_BRIDGE_ISA; 47747934d0aSPaolo Bonzini k->revision = 0x40; 47847934d0aSPaolo Bonzini dc->desc = "ISA bridge"; 47947934d0aSPaolo Bonzini dc->vmsd = &vmstate_via; 48004916ee9SMarkus Armbruster /* 48104916ee9SMarkus Armbruster * Reason: part of VIA VT82C686 southbridge, needs to be wired up, 48204916ee9SMarkus Armbruster * e.g. by mips_fulong2e_init() 48304916ee9SMarkus Armbruster */ 48404916ee9SMarkus Armbruster dc->cannot_instantiate_with_device_add_yet = true; 48547934d0aSPaolo Bonzini } 48647934d0aSPaolo Bonzini 48747934d0aSPaolo Bonzini static const TypeInfo via_info = { 48847934d0aSPaolo Bonzini .name = "VT82C686B", 48947934d0aSPaolo Bonzini .parent = TYPE_PCI_DEVICE, 49047934d0aSPaolo Bonzini .instance_size = sizeof(VT82C686BState), 49147934d0aSPaolo Bonzini .class_init = via_class_init, 49247934d0aSPaolo Bonzini }; 49347934d0aSPaolo Bonzini 49447934d0aSPaolo Bonzini static void vt82c686b_register_types(void) 49547934d0aSPaolo Bonzini { 49647934d0aSPaolo Bonzini type_register_static(&via_ac97_info); 49747934d0aSPaolo Bonzini type_register_static(&via_mc97_info); 49847934d0aSPaolo Bonzini type_register_static(&via_pm_info); 49947934d0aSPaolo Bonzini type_register_static(&via_info); 50047934d0aSPaolo Bonzini } 50147934d0aSPaolo Bonzini 50247934d0aSPaolo Bonzini type_init(vt82c686b_register_types) 503