Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU PIIX4 PCI Bridge Emulation |
| 3 | * |
| 4 | * Copyright (c) 2006 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | |
Peter Maydell | b6a0aa0 | 2016-01-26 18:17:03 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 26 | #include "hw/hw.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 27 | #include "hw/i386/pc.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 28 | #include "hw/pci/pci.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 29 | #include "hw/isa/isa.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 30 | #include "hw/sysbus.h" |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 31 | |
| 32 | PCIDevice *piix4_dev; |
| 33 | |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 34 | typedef struct PIIX4State { |
| 35 | PCIDevice dev; |
| 36 | } PIIX4State; |
| 37 | |
Gonglei | acff3e4 | 2015-05-13 08:43:24 +0800 | [diff] [blame] | 38 | #define TYPE_PIIX4_PCI_DEVICE "PIIX4" |
| 39 | #define PIIX4_PCI_DEVICE(obj) \ |
| 40 | OBJECT_CHECK(PIIX4State, (obj), TYPE_PIIX4_PCI_DEVICE) |
| 41 | |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 42 | static void piix4_reset(void *opaque) |
| 43 | { |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 44 | PIIX4State *d = opaque; |
| 45 | uint8_t *pci_conf = d->dev.config; |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 46 | |
| 47 | pci_conf[0x04] = 0x07; // master, memory and I/O |
| 48 | pci_conf[0x05] = 0x00; |
| 49 | pci_conf[0x06] = 0x00; |
| 50 | pci_conf[0x07] = 0x02; // PCI_status_devsel_medium |
| 51 | pci_conf[0x4c] = 0x4d; |
| 52 | pci_conf[0x4e] = 0x03; |
| 53 | pci_conf[0x4f] = 0x00; |
| 54 | pci_conf[0x60] = 0x0a; // PCI A -> IRQ 10 |
| 55 | pci_conf[0x61] = 0x0a; // PCI B -> IRQ 10 |
| 56 | pci_conf[0x62] = 0x0b; // PCI C -> IRQ 11 |
| 57 | pci_conf[0x63] = 0x0b; // PCI D -> IRQ 11 |
| 58 | pci_conf[0x69] = 0x02; |
| 59 | pci_conf[0x70] = 0x80; |
| 60 | pci_conf[0x76] = 0x0c; |
| 61 | pci_conf[0x77] = 0x0c; |
| 62 | pci_conf[0x78] = 0x02; |
| 63 | pci_conf[0x79] = 0x00; |
| 64 | pci_conf[0x80] = 0x00; |
| 65 | pci_conf[0x82] = 0x00; |
| 66 | pci_conf[0xa0] = 0x08; |
| 67 | pci_conf[0xa2] = 0x00; |
| 68 | pci_conf[0xa3] = 0x00; |
| 69 | pci_conf[0xa4] = 0x00; |
| 70 | pci_conf[0xa5] = 0x00; |
| 71 | pci_conf[0xa6] = 0x00; |
| 72 | pci_conf[0xa7] = 0x00; |
| 73 | pci_conf[0xa8] = 0x0f; |
| 74 | pci_conf[0xaa] = 0x00; |
| 75 | pci_conf[0xab] = 0x00; |
| 76 | pci_conf[0xac] = 0x00; |
| 77 | pci_conf[0xae] = 0x00; |
| 78 | } |
| 79 | |
Juan Quintela | 9039d78 | 2010-12-02 16:59:33 +0100 | [diff] [blame] | 80 | static const VMStateDescription vmstate_piix4 = { |
| 81 | .name = "PIIX4", |
| 82 | .version_id = 2, |
| 83 | .minimum_version_id = 2, |
Juan Quintela | d49805a | 2014-04-16 15:32:32 +0200 | [diff] [blame] | 84 | .fields = (VMStateField[]) { |
Juan Quintela | 9039d78 | 2010-12-02 16:59:33 +0100 | [diff] [blame] | 85 | VMSTATE_PCI_DEVICE(dev, PIIX4State), |
| 86 | VMSTATE_END_OF_LIST() |
| 87 | } |
| 88 | }; |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 89 | |
Markus Armbruster | 9af21db | 2015-01-19 15:52:30 +0100 | [diff] [blame] | 90 | static void piix4_realize(PCIDevice *dev, Error **errp) |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 91 | { |
Gonglei | acff3e4 | 2015-05-13 08:43:24 +0800 | [diff] [blame] | 92 | PIIX4State *d = PIIX4_PCI_DEVICE(dev); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 93 | |
Markus Armbruster | d10e543 | 2015-12-17 17:35:18 +0100 | [diff] [blame] | 94 | if (!isa_bus_new(DEVICE(d), pci_address_space(dev), |
| 95 | pci_address_space_io(dev), errp)) { |
| 96 | return; |
| 97 | } |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 98 | piix4_dev = &d->dev; |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 99 | qemu_register_reset(piix4_reset, d); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Hervé Poussineau | 142e978 | 2011-12-15 22:09:58 +0100 | [diff] [blame] | 102 | int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn) |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 103 | { |
| 104 | PCIDevice *d; |
| 105 | |
Isaku Yamahata | fecb93c | 2010-06-23 16:15:31 +0900 | [diff] [blame] | 106 | d = pci_create_simple_multifunction(bus, devfn, true, "PIIX4"); |
Andreas Färber | 2ae0e48 | 2013-06-07 14:11:07 +0200 | [diff] [blame] | 107 | *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0")); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 108 | return d->devfn; |
| 109 | } |
| 110 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 111 | static void piix4_class_init(ObjectClass *klass, void *data) |
| 112 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 113 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 114 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 115 | |
Markus Armbruster | 9af21db | 2015-01-19 15:52:30 +0100 | [diff] [blame] | 116 | k->realize = piix4_realize; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 117 | k->vendor_id = PCI_VENDOR_ID_INTEL; |
| 118 | k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0; |
| 119 | k->class_id = PCI_CLASS_BRIDGE_ISA; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 120 | dc->desc = "ISA bridge"; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 121 | dc->vmsd = &vmstate_piix4; |
Markus Armbruster | 81aab2f | 2013-11-28 17:27:00 +0100 | [diff] [blame] | 122 | /* |
| 123 | * Reason: part of PIIX4 southbridge, needs to be wired up, |
| 124 | * e.g. by mips_malta_init() |
| 125 | */ |
Eduardo Habkost | e90f2a8 | 2017-05-03 17:35:44 -0300 | [diff] [blame] | 126 | dc->user_creatable = false; |
Igor Mammedov | 2897ae0 | 2014-02-05 16:36:48 +0100 | [diff] [blame] | 127 | dc->hotpluggable = false; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 128 | } |
| 129 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 130 | static const TypeInfo piix4_info = { |
Gonglei | acff3e4 | 2015-05-13 08:43:24 +0800 | [diff] [blame] | 131 | .name = TYPE_PIIX4_PCI_DEVICE, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 132 | .parent = TYPE_PCI_DEVICE, |
| 133 | .instance_size = sizeof(PIIX4State), |
| 134 | .class_init = piix4_class_init, |
Eduardo Habkost | fd3b02c | 2017-09-27 16:56:34 -0300 | [diff] [blame] | 135 | .interfaces = (InterfaceInfo[]) { |
| 136 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, |
| 137 | { }, |
| 138 | }, |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 139 | }; |
| 140 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 141 | static void piix4_register_types(void) |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 142 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 143 | type_register_static(&piix4_info); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 144 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 145 | |
| 146 | type_init(piix4_register_types) |