]>
Commit | Line | Data |
---|---|---|
edf79e66 HC |
1 | /* |
2 | * VT82C686B south bridge support | |
3 | * | |
4 | * Copyright (c) 2008 yajin (yajin@vm-kernel.org) | |
5 | * Copyright (c) 2009 chenming (chenming@rdc.faw.com.cn) | |
6 | * Copyright (c) 2010 Huacai Chen (zltjiangshi@gmail.com) | |
7 | * This code is licensed under the GNU GPL v2. | |
6b620ca3 PB |
8 | * |
9 | * Contributions after 2012-01-13 are licensed under the terms of the | |
10 | * GNU GPL, version 2 or (at your option) any later version. | |
edf79e66 HC |
11 | */ |
12 | ||
0430891c | 13 | #include "qemu/osdep.h" |
0d09e41a | 14 | #include "hw/isa/vt82c686.h" |
83c9f4ca | 15 | #include "hw/pci/pci.h" |
a27bd6c7 | 16 | #include "hw/qdev-properties.h" |
0d09e41a | 17 | #include "hw/isa/isa.h" |
98cf824b | 18 | #include "hw/isa/superio.h" |
3dc31cb8 BZ |
19 | #include "hw/intc/i8259.h" |
20 | #include "hw/irq.h" | |
21 | #include "hw/dma/i8257.h" | |
22 | #include "hw/timer/i8254.h" | |
23 | #include "hw/rtc/mc146818rtc.h" | |
d6454270 | 24 | #include "migration/vmstate.h" |
0d09e41a PB |
25 | #include "hw/isa/apm.h" |
26 | #include "hw/acpi/acpi.h" | |
27 | #include "hw/i2c/pm_smbus.h" | |
9307d06d | 28 | #include "qapi/error.h" |
2c4c556e | 29 | #include "qemu/log.h" |
0b8fa32f | 30 | #include "qemu/module.h" |
911629e6 | 31 | #include "qemu/range.h" |
1de7afc9 | 32 | #include "qemu/timer.h" |
022c62cb | 33 | #include "exec/address-spaces.h" |
ff413a1f | 34 | #include "trace.h" |
edf79e66 | 35 | |
e1a69736 BZ |
36 | #define TYPE_VIA_PM "via-pm" |
37 | OBJECT_DECLARE_SIMPLE_TYPE(ViaPMState, VIA_PM) | |
edf79e66 | 38 | |
e1a69736 | 39 | struct ViaPMState { |
edf79e66 | 40 | PCIDevice dev; |
a2902821 | 41 | MemoryRegion io; |
355bf2e5 | 42 | ACPIREGS ar; |
edf79e66 | 43 | APMState apm; |
edf79e66 | 44 | PMSMBus smb; |
db1015e9 | 45 | }; |
edf79e66 | 46 | |
e1a69736 | 47 | static void pm_io_space_update(ViaPMState *s) |
edf79e66 | 48 | { |
3ab1eea6 | 49 | uint32_t pmbase = pci_get_long(s->dev.config + 0x48) & 0xff80UL; |
edf79e66 | 50 | |
a2902821 | 51 | memory_region_transaction_begin(); |
3ab1eea6 BZ |
52 | memory_region_set_address(&s->io, pmbase); |
53 | memory_region_set_enabled(&s->io, s->dev.config[0x41] & BIT(7)); | |
a2902821 | 54 | memory_region_transaction_commit(); |
edf79e66 HC |
55 | } |
56 | ||
e1a69736 | 57 | static void smb_io_space_update(ViaPMState *s) |
911629e6 BZ |
58 | { |
59 | uint32_t smbase = pci_get_long(s->dev.config + 0x90) & 0xfff0UL; | |
60 | ||
61 | memory_region_transaction_begin(); | |
62 | memory_region_set_address(&s->smb.io, smbase); | |
63 | memory_region_set_enabled(&s->smb.io, s->dev.config[0xd2] & BIT(0)); | |
64 | memory_region_transaction_commit(); | |
65 | } | |
66 | ||
edf79e66 HC |
67 | static int vmstate_acpi_post_load(void *opaque, int version_id) |
68 | { | |
e1a69736 | 69 | ViaPMState *s = opaque; |
edf79e66 HC |
70 | |
71 | pm_io_space_update(s); | |
911629e6 | 72 | smb_io_space_update(s); |
edf79e66 HC |
73 | return 0; |
74 | } | |
75 | ||
76 | static const VMStateDescription vmstate_acpi = { | |
77 | .name = "vt82c686b_pm", | |
78 | .version_id = 1, | |
79 | .minimum_version_id = 1, | |
edf79e66 | 80 | .post_load = vmstate_acpi_post_load, |
d49805ae | 81 | .fields = (VMStateField[]) { |
e1a69736 BZ |
82 | VMSTATE_PCI_DEVICE(dev, ViaPMState), |
83 | VMSTATE_UINT16(ar.pm1.evt.sts, ViaPMState), | |
84 | VMSTATE_UINT16(ar.pm1.evt.en, ViaPMState), | |
85 | VMSTATE_UINT16(ar.pm1.cnt.cnt, ViaPMState), | |
86 | VMSTATE_STRUCT(apm, ViaPMState, 0, vmstate_apm, APMState), | |
87 | VMSTATE_TIMER_PTR(ar.tmr.timer, ViaPMState), | |
88 | VMSTATE_INT64(ar.tmr.overflow_time, ViaPMState), | |
edf79e66 HC |
89 | VMSTATE_END_OF_LIST() |
90 | } | |
91 | }; | |
92 | ||
94349bff BZ |
93 | static void pm_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len) |
94 | { | |
e1a69736 | 95 | ViaPMState *s = VIA_PM(d); |
911629e6 | 96 | |
94349bff BZ |
97 | trace_via_pm_write(addr, val, len); |
98 | pci_default_write_config(d, addr, val, len); | |
3ab1eea6 BZ |
99 | if (ranges_overlap(addr, len, 0x48, 4)) { |
100 | uint32_t v = pci_get_long(s->dev.config + 0x48); | |
101 | pci_set_long(s->dev.config + 0x48, (v & 0xff80UL) | 1); | |
102 | } | |
103 | if (range_covers_byte(addr, len, 0x41)) { | |
104 | pm_io_space_update(s); | |
105 | } | |
911629e6 BZ |
106 | if (ranges_overlap(addr, len, 0x90, 4)) { |
107 | uint32_t v = pci_get_long(s->dev.config + 0x90); | |
108 | pci_set_long(s->dev.config + 0x90, (v & 0xfff0UL) | 1); | |
109 | } | |
110 | if (range_covers_byte(addr, len, 0xd2)) { | |
111 | s->dev.config[0xd2] &= 0xf; | |
112 | smb_io_space_update(s); | |
113 | } | |
94349bff BZ |
114 | } |
115 | ||
35e360ed BZ |
116 | static void pm_io_write(void *op, hwaddr addr, uint64_t data, unsigned size) |
117 | { | |
118 | trace_via_pm_io_write(addr, data, size); | |
119 | } | |
120 | ||
121 | static uint64_t pm_io_read(void *op, hwaddr addr, unsigned size) | |
122 | { | |
123 | trace_via_pm_io_read(addr, 0, size); | |
124 | return 0; | |
125 | } | |
126 | ||
127 | static const MemoryRegionOps pm_io_ops = { | |
128 | .read = pm_io_read, | |
129 | .write = pm_io_write, | |
130 | .endianness = DEVICE_NATIVE_ENDIAN, | |
131 | .impl = { | |
132 | .min_access_size = 1, | |
133 | .max_access_size = 1, | |
134 | }, | |
135 | }; | |
136 | ||
e1a69736 | 137 | static void pm_update_sci(ViaPMState *s) |
94349bff BZ |
138 | { |
139 | int sci_level, pmsts; | |
140 | ||
141 | pmsts = acpi_pm1_evt_get_sts(&s->ar); | |
142 | sci_level = (((pmsts & s->ar.pm1.evt.en) & | |
143 | (ACPI_BITMASK_RT_CLOCK_ENABLE | | |
144 | ACPI_BITMASK_POWER_BUTTON_ENABLE | | |
145 | ACPI_BITMASK_GLOBAL_LOCK_ENABLE | | |
146 | ACPI_BITMASK_TIMER_ENABLE)) != 0); | |
0fae92a3 IY |
147 | if (pci_get_byte(s->dev.config + PCI_INTERRUPT_PIN)) { |
148 | /* | |
149 | * FIXME: | |
150 | * Fix device model that realizes this PM device and remove | |
151 | * this work around. | |
152 | * The device model should wire SCI and setup | |
153 | * PCI_INTERRUPT_PIN properly. | |
154 | * If PIN# = 0(interrupt pin isn't used), don't raise SCI as | |
155 | * work around. | |
156 | */ | |
157 | pci_set_irq(&s->dev, sci_level); | |
158 | } | |
94349bff BZ |
159 | /* schedule a timer interruption if needed */ |
160 | acpi_pm_tmr_update(&s->ar, (s->ar.pm1.evt.en & ACPI_BITMASK_TIMER_ENABLE) && | |
161 | !(pmsts & ACPI_BITMASK_TIMER_STATUS)); | |
162 | } | |
163 | ||
164 | static void pm_tmr_timer(ACPIREGS *ar) | |
165 | { | |
e1a69736 | 166 | ViaPMState *s = container_of(ar, ViaPMState, ar); |
94349bff BZ |
167 | pm_update_sci(s); |
168 | } | |
169 | ||
e1a69736 | 170 | static void via_pm_reset(DeviceState *d) |
911629e6 | 171 | { |
e1a69736 | 172 | ViaPMState *s = VIA_PM(d); |
911629e6 | 173 | |
9af8e529 BZ |
174 | memset(s->dev.config + PCI_CONFIG_HEADER_SIZE, 0, |
175 | PCI_CONFIG_SPACE_SIZE - PCI_CONFIG_HEADER_SIZE); | |
176 | /* Power Management IO base */ | |
177 | pci_set_long(s->dev.config + 0x48, 1); | |
911629e6 BZ |
178 | /* SMBus IO base */ |
179 | pci_set_long(s->dev.config + 0x90, 1); | |
911629e6 | 180 | |
44421c60 IY |
181 | acpi_pm1_evt_reset(&s->ar); |
182 | acpi_pm1_cnt_reset(&s->ar); | |
183 | acpi_pm_tmr_reset(&s->ar); | |
184 | pm_update_sci(s); | |
185 | ||
3ab1eea6 | 186 | pm_io_space_update(s); |
911629e6 BZ |
187 | smb_io_space_update(s); |
188 | } | |
189 | ||
e1a69736 | 190 | static void via_pm_realize(PCIDevice *dev, Error **errp) |
edf79e66 | 191 | { |
e1a69736 | 192 | ViaPMState *s = VIA_PM(dev); |
edf79e66 | 193 | |
3ab1eea6 | 194 | pci_set_word(dev->config + PCI_STATUS, PCI_STATUS_FAST_BACK | |
edf79e66 HC |
195 | PCI_STATUS_DEVSEL_MEDIUM); |
196 | ||
a30c34d2 | 197 | pm_smbus_init(DEVICE(s), &s->smb, false); |
911629e6 BZ |
198 | memory_region_add_subregion(pci_address_space_io(dev), 0, &s->smb.io); |
199 | memory_region_set_enabled(&s->smb.io, false); | |
edf79e66 | 200 | |
42d8a3cf | 201 | apm_init(dev, &s->apm, NULL, s); |
edf79e66 | 202 | |
e1a69736 | 203 | memory_region_init_io(&s->io, OBJECT(dev), &pm_io_ops, s, "via-pm", 128); |
35e360ed | 204 | memory_region_add_subregion(pci_address_space_io(dev), 0, &s->io); |
a2902821 | 205 | memory_region_set_enabled(&s->io, false); |
edf79e66 | 206 | |
77d58b1e | 207 | acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io); |
b5a7c024 | 208 | acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io); |
6be8cf56 | 209 | acpi_pm1_cnt_init(&s->ar, &s->io, false, false, 2, false); |
edf79e66 HC |
210 | } |
211 | ||
e1a69736 BZ |
212 | typedef struct via_pm_init_info { |
213 | uint16_t device_id; | |
214 | } ViaPMInitInfo; | |
215 | ||
40021f08 AL |
216 | static void via_pm_class_init(ObjectClass *klass, void *data) |
217 | { | |
39bffca2 | 218 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 | 219 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
e1a69736 | 220 | ViaPMInitInfo *info = data; |
40021f08 | 221 | |
e1a69736 | 222 | k->realize = via_pm_realize; |
40021f08 AL |
223 | k->config_write = pm_write_config; |
224 | k->vendor_id = PCI_VENDOR_ID_VIA; | |
e1a69736 | 225 | k->device_id = info->device_id; |
40021f08 AL |
226 | k->class_id = PCI_CLASS_BRIDGE_OTHER; |
227 | k->revision = 0x40; | |
e1a69736 | 228 | dc->reset = via_pm_reset; |
084bf4b4 BZ |
229 | /* Reason: part of VIA south bridge, does not exist stand alone */ |
230 | dc->user_creatable = false; | |
39bffca2 | 231 | dc->vmsd = &vmstate_acpi; |
40021f08 AL |
232 | } |
233 | ||
8c43a6f0 | 234 | static const TypeInfo via_pm_info = { |
e1a69736 | 235 | .name = TYPE_VIA_PM, |
39bffca2 | 236 | .parent = TYPE_PCI_DEVICE, |
e1a69736 BZ |
237 | .instance_size = sizeof(ViaPMState), |
238 | .abstract = true, | |
fd3b02c8 EH |
239 | .interfaces = (InterfaceInfo[]) { |
240 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | |
241 | { }, | |
242 | }, | |
edf79e66 HC |
243 | }; |
244 | ||
e1a69736 BZ |
245 | static const ViaPMInitInfo vt82c686b_pm_init_info = { |
246 | .device_id = PCI_DEVICE_ID_VIA_82C686B_PM, | |
247 | }; | |
248 | ||
249 | static const TypeInfo vt82c686b_pm_info = { | |
250 | .name = TYPE_VT82C686B_PM, | |
251 | .parent = TYPE_VIA_PM, | |
252 | .class_init = via_pm_class_init, | |
253 | .class_data = (void *)&vt82c686b_pm_init_info, | |
254 | }; | |
255 | ||
256 | static const ViaPMInitInfo vt8231_pm_init_info = { | |
257 | .device_id = PCI_DEVICE_ID_VIA_8231_PM, | |
258 | }; | |
259 | ||
260 | static const TypeInfo vt8231_pm_info = { | |
261 | .name = TYPE_VT8231_PM, | |
262 | .parent = TYPE_VIA_PM, | |
263 | .class_init = via_pm_class_init, | |
264 | .class_data = (void *)&vt8231_pm_init_info, | |
265 | }; | |
266 | ||
94349bff | 267 | |
f028c2de BZ |
268 | #define TYPE_VIA_SUPERIO "via-superio" |
269 | OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO) | |
270 | ||
271 | struct ViaSuperIOState { | |
272 | ISASuperIODevice superio; | |
94349bff | 273 | uint8_t regs[0x100]; |
f028c2de | 274 | const MemoryRegionOps *io_ops; |
94349bff | 275 | MemoryRegion io; |
f028c2de BZ |
276 | }; |
277 | ||
278 | static inline void via_superio_io_enable(ViaSuperIOState *s, bool enable) | |
279 | { | |
280 | memory_region_set_enabled(&s->io, enable); | |
281 | } | |
282 | ||
283 | static void via_superio_realize(DeviceState *d, Error **errp) | |
284 | { | |
285 | ViaSuperIOState *s = VIA_SUPERIO(d); | |
286 | ISASuperIOClass *ic = ISA_SUPERIO_GET_CLASS(s); | |
287 | Error *local_err = NULL; | |
288 | ||
289 | assert(s->io_ops); | |
290 | ic->parent_realize(d, &local_err); | |
291 | if (local_err) { | |
292 | error_propagate(errp, local_err); | |
293 | return; | |
294 | } | |
295 | memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", 2); | |
296 | memory_region_set_enabled(&s->io, false); | |
297 | /* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway */ | |
298 | memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0, | |
299 | &s->io); | |
300 | } | |
301 | ||
302 | static uint64_t via_superio_cfg_read(void *opaque, hwaddr addr, unsigned size) | |
303 | { | |
304 | ViaSuperIOState *sc = opaque; | |
305 | uint8_t idx = sc->regs[0]; | |
306 | uint8_t val = sc->regs[idx]; | |
307 | ||
308 | if (addr == 0) { | |
309 | return idx; | |
310 | } | |
311 | if (addr == 1 && idx == 0) { | |
312 | val = 0; /* reading reg 0 where we store index value */ | |
313 | } | |
314 | trace_via_superio_read(idx, val); | |
315 | return val; | |
316 | } | |
317 | ||
318 | static void via_superio_class_init(ObjectClass *klass, void *data) | |
319 | { | |
320 | DeviceClass *dc = DEVICE_CLASS(klass); | |
321 | ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass); | |
322 | ||
323 | sc->parent_realize = dc->realize; | |
324 | dc->realize = via_superio_realize; | |
325 | } | |
326 | ||
327 | static const TypeInfo via_superio_info = { | |
328 | .name = TYPE_VIA_SUPERIO, | |
329 | .parent = TYPE_ISA_SUPERIO, | |
330 | .instance_size = sizeof(ViaSuperIOState), | |
331 | .class_size = sizeof(ISASuperIOClass), | |
332 | .class_init = via_superio_class_init, | |
333 | .abstract = true, | |
334 | }; | |
335 | ||
336 | #define TYPE_VT82C686B_SUPERIO "vt82c686b-superio" | |
94349bff | 337 | |
f028c2de BZ |
338 | static void vt82c686b_superio_cfg_write(void *opaque, hwaddr addr, |
339 | uint64_t data, unsigned size) | |
94349bff | 340 | { |
f028c2de | 341 | ViaSuperIOState *sc = opaque; |
c953bf71 | 342 | uint8_t idx = sc->regs[0]; |
94349bff | 343 | |
cc2b4550 BZ |
344 | if (addr == 0) { /* config index register */ |
345 | sc->regs[0] = data; | |
2b98dca9 BZ |
346 | return; |
347 | } | |
cc2b4550 BZ |
348 | |
349 | /* config data register */ | |
350 | trace_via_superio_write(idx, data); | |
2b98dca9 BZ |
351 | switch (idx) { |
352 | case 0x00 ... 0xdf: | |
353 | case 0xe4: | |
354 | case 0xe5: | |
355 | case 0xe9 ... 0xed: | |
356 | case 0xf3: | |
357 | case 0xf5: | |
358 | case 0xf7: | |
359 | case 0xf9 ... 0xfb: | |
360 | case 0xfd ... 0xff: | |
b7741b77 BZ |
361 | /* ignore write to read only registers */ |
362 | return; | |
2b98dca9 BZ |
363 | /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */ |
364 | default: | |
2c4c556e BZ |
365 | qemu_log_mask(LOG_UNIMP, |
366 | "via_superio_cfg: unimplemented register 0x%x\n", idx); | |
2b98dca9 BZ |
367 | break; |
368 | } | |
cc2b4550 | 369 | sc->regs[idx] = data; |
94349bff BZ |
370 | } |
371 | ||
f028c2de BZ |
372 | static const MemoryRegionOps vt82c686b_superio_cfg_ops = { |
373 | .read = via_superio_cfg_read, | |
374 | .write = vt82c686b_superio_cfg_write, | |
94349bff BZ |
375 | .endianness = DEVICE_NATIVE_ENDIAN, |
376 | .impl = { | |
377 | .min_access_size = 1, | |
378 | .max_access_size = 1, | |
379 | }, | |
380 | }; | |
381 | ||
f028c2de BZ |
382 | static void vt82c686b_superio_reset(DeviceState *dev) |
383 | { | |
384 | ViaSuperIOState *s = VIA_SUPERIO(dev); | |
385 | ||
386 | memset(s->regs, 0, sizeof(s->regs)); | |
387 | /* Device ID */ | |
388 | vt82c686b_superio_cfg_write(s, 0, 0xe0, 1); | |
389 | vt82c686b_superio_cfg_write(s, 1, 0x3c, 1); | |
390 | /* Function select - all disabled */ | |
391 | vt82c686b_superio_cfg_write(s, 0, 0xe2, 1); | |
392 | vt82c686b_superio_cfg_write(s, 1, 0x03, 1); | |
393 | /* Floppy ctrl base addr 0x3f0-7 */ | |
394 | vt82c686b_superio_cfg_write(s, 0, 0xe3, 1); | |
395 | vt82c686b_superio_cfg_write(s, 1, 0xfc, 1); | |
396 | /* Parallel port base addr 0x378-f */ | |
397 | vt82c686b_superio_cfg_write(s, 0, 0xe6, 1); | |
398 | vt82c686b_superio_cfg_write(s, 1, 0xde, 1); | |
399 | /* Serial port 1 base addr 0x3f8-f */ | |
400 | vt82c686b_superio_cfg_write(s, 0, 0xe7, 1); | |
401 | vt82c686b_superio_cfg_write(s, 1, 0xfe, 1); | |
402 | /* Serial port 2 base addr 0x2f8-f */ | |
403 | vt82c686b_superio_cfg_write(s, 0, 0xe8, 1); | |
404 | vt82c686b_superio_cfg_write(s, 1, 0xbe, 1); | |
405 | ||
406 | vt82c686b_superio_cfg_write(s, 0, 0, 1); | |
407 | } | |
408 | ||
409 | static void vt82c686b_superio_init(Object *obj) | |
410 | { | |
411 | VIA_SUPERIO(obj)->io_ops = &vt82c686b_superio_cfg_ops; | |
412 | } | |
413 | ||
414 | static void vt82c686b_superio_class_init(ObjectClass *klass, void *data) | |
415 | { | |
416 | DeviceClass *dc = DEVICE_CLASS(klass); | |
417 | ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass); | |
418 | ||
419 | dc->reset = vt82c686b_superio_reset; | |
420 | sc->serial.count = 2; | |
421 | sc->parallel.count = 1; | |
422 | sc->ide.count = 0; /* emulated by via-ide */ | |
423 | sc->floppy.count = 1; | |
424 | } | |
425 | ||
426 | static const TypeInfo vt82c686b_superio_info = { | |
427 | .name = TYPE_VT82C686B_SUPERIO, | |
428 | .parent = TYPE_VIA_SUPERIO, | |
429 | .instance_size = sizeof(ViaSuperIOState), | |
430 | .instance_init = vt82c686b_superio_init, | |
431 | .class_size = sizeof(ISASuperIOClass), | |
432 | .class_init = vt82c686b_superio_class_init, | |
433 | }; | |
434 | ||
94349bff | 435 | |
ab74864f BZ |
436 | #define TYPE_VT8231_SUPERIO "vt8231-superio" |
437 | ||
438 | static void vt8231_superio_cfg_write(void *opaque, hwaddr addr, | |
439 | uint64_t data, unsigned size) | |
440 | { | |
441 | ViaSuperIOState *sc = opaque; | |
442 | uint8_t idx = sc->regs[0]; | |
443 | ||
444 | if (addr == 0) { /* config index register */ | |
445 | sc->regs[0] = data; | |
446 | return; | |
447 | } | |
448 | ||
449 | /* config data register */ | |
450 | trace_via_superio_write(idx, data); | |
451 | switch (idx) { | |
452 | case 0x00 ... 0xdf: | |
453 | case 0xe7 ... 0xef: | |
454 | case 0xf0 ... 0xf1: | |
455 | case 0xf5: | |
456 | case 0xf8: | |
457 | case 0xfd: | |
458 | /* ignore write to read only registers */ | |
459 | return; | |
460 | default: | |
461 | qemu_log_mask(LOG_UNIMP, | |
462 | "via_superio_cfg: unimplemented register 0x%x\n", idx); | |
463 | break; | |
464 | } | |
465 | sc->regs[idx] = data; | |
466 | } | |
467 | ||
468 | static const MemoryRegionOps vt8231_superio_cfg_ops = { | |
469 | .read = via_superio_cfg_read, | |
470 | .write = vt8231_superio_cfg_write, | |
471 | .endianness = DEVICE_NATIVE_ENDIAN, | |
472 | .impl = { | |
473 | .min_access_size = 1, | |
474 | .max_access_size = 1, | |
475 | }, | |
476 | }; | |
477 | ||
478 | static void vt8231_superio_reset(DeviceState *dev) | |
479 | { | |
480 | ViaSuperIOState *s = VIA_SUPERIO(dev); | |
481 | ||
482 | memset(s->regs, 0, sizeof(s->regs)); | |
483 | /* Device ID */ | |
484 | s->regs[0xf0] = 0x3c; | |
485 | /* Device revision */ | |
486 | s->regs[0xf1] = 0x01; | |
487 | /* Function select - all disabled */ | |
488 | vt8231_superio_cfg_write(s, 0, 0xf2, 1); | |
489 | vt8231_superio_cfg_write(s, 1, 0x03, 1); | |
490 | /* Serial port base addr */ | |
491 | vt8231_superio_cfg_write(s, 0, 0xf4, 1); | |
492 | vt8231_superio_cfg_write(s, 1, 0xfe, 1); | |
493 | /* Parallel port base addr */ | |
494 | vt8231_superio_cfg_write(s, 0, 0xf6, 1); | |
495 | vt8231_superio_cfg_write(s, 1, 0xde, 1); | |
496 | /* Floppy ctrl base addr */ | |
497 | vt8231_superio_cfg_write(s, 0, 0xf7, 1); | |
498 | vt8231_superio_cfg_write(s, 1, 0xfc, 1); | |
499 | ||
500 | vt8231_superio_cfg_write(s, 0, 0, 1); | |
501 | } | |
502 | ||
503 | static void vt8231_superio_init(Object *obj) | |
504 | { | |
505 | VIA_SUPERIO(obj)->io_ops = &vt8231_superio_cfg_ops; | |
506 | } | |
507 | ||
508 | static uint16_t vt8231_superio_serial_iobase(ISASuperIODevice *sio, | |
509 | uint8_t index) | |
510 | { | |
511 | return 0x2f8; /* FIXME: This should be settable via registers f2-f4 */ | |
512 | } | |
513 | ||
514 | static void vt8231_superio_class_init(ObjectClass *klass, void *data) | |
515 | { | |
516 | DeviceClass *dc = DEVICE_CLASS(klass); | |
517 | ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass); | |
518 | ||
519 | dc->reset = vt8231_superio_reset; | |
520 | sc->serial.count = 1; | |
521 | sc->serial.get_iobase = vt8231_superio_serial_iobase; | |
522 | sc->parallel.count = 1; | |
523 | sc->ide.count = 0; /* emulated by via-ide */ | |
524 | sc->floppy.count = 1; | |
525 | } | |
526 | ||
527 | static const TypeInfo vt8231_superio_info = { | |
528 | .name = TYPE_VT8231_SUPERIO, | |
529 | .parent = TYPE_VIA_SUPERIO, | |
530 | .instance_size = sizeof(ViaSuperIOState), | |
531 | .instance_init = vt8231_superio_init, | |
532 | .class_size = sizeof(ISASuperIOClass), | |
533 | .class_init = vt8231_superio_class_init, | |
534 | }; | |
535 | ||
536 | ||
2e84e107 BZ |
537 | #define TYPE_VIA_ISA "via-isa" |
538 | OBJECT_DECLARE_SIMPLE_TYPE(ViaISAState, VIA_ISA) | |
94349bff | 539 | |
2e84e107 | 540 | struct ViaISAState { |
94349bff | 541 | PCIDevice dev; |
3dc31cb8 | 542 | qemu_irq cpu_intr; |
f028c2de | 543 | ViaSuperIOState *via_sio; |
94349bff BZ |
544 | }; |
545 | ||
2e84e107 BZ |
546 | static const VMStateDescription vmstate_via = { |
547 | .name = "via-isa", | |
548 | .version_id = 1, | |
549 | .minimum_version_id = 1, | |
550 | .fields = (VMStateField[]) { | |
551 | VMSTATE_PCI_DEVICE(dev, ViaISAState), | |
552 | VMSTATE_END_OF_LIST() | |
553 | } | |
554 | }; | |
555 | ||
556 | static const TypeInfo via_isa_info = { | |
557 | .name = TYPE_VIA_ISA, | |
558 | .parent = TYPE_PCI_DEVICE, | |
559 | .instance_size = sizeof(ViaISAState), | |
560 | .abstract = true, | |
561 | .interfaces = (InterfaceInfo[]) { | |
562 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | |
563 | { }, | |
564 | }, | |
565 | }; | |
566 | ||
3dc31cb8 BZ |
567 | static void via_isa_request_i8259_irq(void *opaque, int irq, int level) |
568 | { | |
2e84e107 | 569 | ViaISAState *s = opaque; |
3dc31cb8 BZ |
570 | qemu_set_irq(s->cpu_intr, level); |
571 | } | |
572 | ||
2e84e107 BZ |
573 | /* TYPE_VT82C686B_ISA */ |
574 | ||
94349bff BZ |
575 | static void vt82c686b_write_config(PCIDevice *d, uint32_t addr, |
576 | uint32_t val, int len) | |
577 | { | |
2e84e107 | 578 | ViaISAState *s = VIA_ISA(d); |
94349bff BZ |
579 | |
580 | trace_via_isa_write(addr, val, len); | |
581 | pci_default_write_config(d, addr, val, len); | |
582 | if (addr == 0x85) { | |
583 | /* BIT(1): enable or disable superio config io ports */ | |
f028c2de | 584 | via_superio_io_enable(s->via_sio, val & BIT(1)); |
94349bff BZ |
585 | } |
586 | } | |
587 | ||
94349bff BZ |
588 | static void vt82c686b_isa_reset(DeviceState *dev) |
589 | { | |
2e84e107 | 590 | ViaISAState *s = VIA_ISA(dev); |
94349bff BZ |
591 | uint8_t *pci_conf = s->dev.config; |
592 | ||
593 | pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0); | |
594 | pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | | |
595 | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); | |
596 | pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); | |
597 | ||
598 | pci_conf[0x48] = 0x01; /* Miscellaneous Control 3 */ | |
599 | pci_conf[0x4a] = 0x04; /* IDE interrupt Routing */ | |
600 | pci_conf[0x4f] = 0x03; /* DMA/Master Mem Access Control 3 */ | |
601 | pci_conf[0x50] = 0x2d; /* PnP DMA Request Control */ | |
602 | pci_conf[0x59] = 0x04; | |
603 | pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/ | |
604 | pci_conf[0x5f] = 0x04; | |
605 | pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */ | |
94349bff BZ |
606 | } |
607 | ||
9af21dbe | 608 | static void vt82c686b_realize(PCIDevice *d, Error **errp) |
edf79e66 | 609 | { |
2e84e107 | 610 | ViaISAState *s = VIA_ISA(d); |
9859ad1c | 611 | DeviceState *dev = DEVICE(d); |
bcc37e24 | 612 | ISABus *isa_bus; |
3dc31cb8 | 613 | qemu_irq *isa_irq; |
edf79e66 HC |
614 | int i; |
615 | ||
3dc31cb8 BZ |
616 | qdev_init_gpio_out(dev, &s->cpu_intr, 1); |
617 | isa_irq = qemu_allocate_irqs(via_isa_request_i8259_irq, s, 1); | |
9859ad1c BZ |
618 | isa_bus = isa_bus_new(dev, get_system_memory(), pci_address_space_io(d), |
619 | &error_fatal); | |
3dc31cb8 BZ |
620 | isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq)); |
621 | i8254_pit_init(isa_bus, 0x40, 0, NULL); | |
622 | i8257_dma_init(isa_bus, 0); | |
f028c2de BZ |
623 | s->via_sio = VIA_SUPERIO(isa_create_simple(isa_bus, |
624 | TYPE_VT82C686B_SUPERIO)); | |
3dc31cb8 | 625 | mc146818_rtc_init(isa_bus, 2000, NULL); |
edf79e66 | 626 | |
9859ad1c BZ |
627 | for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) { |
628 | if (i < PCI_COMMAND || i >= PCI_REVISION_ID) { | |
629 | d->wmask[i] = 0; | |
f3db354c | 630 | } |
edf79e66 | 631 | } |
edf79e66 HC |
632 | } |
633 | ||
2e84e107 | 634 | static void vt82c686b_class_init(ObjectClass *klass, void *data) |
40021f08 | 635 | { |
39bffca2 | 636 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
637 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
638 | ||
9af21dbe | 639 | k->realize = vt82c686b_realize; |
40021f08 AL |
640 | k->config_write = vt82c686b_write_config; |
641 | k->vendor_id = PCI_VENDOR_ID_VIA; | |
2e84e107 | 642 | k->device_id = PCI_DEVICE_ID_VIA_82C686B_ISA; |
40021f08 AL |
643 | k->class_id = PCI_CLASS_BRIDGE_ISA; |
644 | k->revision = 0x40; | |
9dc1a769 | 645 | dc->reset = vt82c686b_isa_reset; |
39bffca2 | 646 | dc->desc = "ISA bridge"; |
39bffca2 | 647 | dc->vmsd = &vmstate_via; |
2e84e107 | 648 | /* Reason: part of VIA VT82C686 southbridge, needs to be wired up */ |
e90f2a8c | 649 | dc->user_creatable = false; |
40021f08 AL |
650 | } |
651 | ||
2e84e107 | 652 | static const TypeInfo vt82c686b_isa_info = { |
0f798461 | 653 | .name = TYPE_VT82C686B_ISA, |
2e84e107 BZ |
654 | .parent = TYPE_VIA_ISA, |
655 | .instance_size = sizeof(ViaISAState), | |
656 | .class_init = vt82c686b_class_init, | |
edf79e66 HC |
657 | }; |
658 | ||
94349bff | 659 | |
83f7d43a | 660 | static void vt82c686b_register_types(void) |
edf79e66 | 661 | { |
83f7d43a | 662 | type_register_static(&via_pm_info); |
e1a69736 BZ |
663 | type_register_static(&vt82c686b_pm_info); |
664 | type_register_static(&vt8231_pm_info); | |
94349bff | 665 | type_register_static(&via_superio_info); |
f028c2de | 666 | type_register_static(&vt82c686b_superio_info); |
ab74864f | 667 | type_register_static(&vt8231_superio_info); |
2e84e107 BZ |
668 | type_register_static(&via_isa_info); |
669 | type_register_static(&vt82c686b_isa_info); | |
edf79e66 | 670 | } |
83f7d43a AF |
671 | |
672 | type_init(vt82c686b_register_types) |