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 | |
| 25 | #include "hw.h" |
| 26 | #include "pc.h" |
| 27 | #include "pci.h" |
| 28 | #include "isa.h" |
| 29 | #include "sysbus.h" |
| 30 | |
| 31 | PCIDevice *piix4_dev; |
| 32 | |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 33 | typedef struct PIIX4State { |
| 34 | PCIDevice dev; |
| 35 | } PIIX4State; |
| 36 | |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 37 | static void piix4_reset(void *opaque) |
| 38 | { |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 39 | PIIX4State *d = opaque; |
| 40 | uint8_t *pci_conf = d->dev.config; |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 41 | |
| 42 | pci_conf[0x04] = 0x07; // master, memory and I/O |
| 43 | pci_conf[0x05] = 0x00; |
| 44 | pci_conf[0x06] = 0x00; |
| 45 | pci_conf[0x07] = 0x02; // PCI_status_devsel_medium |
| 46 | pci_conf[0x4c] = 0x4d; |
| 47 | pci_conf[0x4e] = 0x03; |
| 48 | pci_conf[0x4f] = 0x00; |
| 49 | pci_conf[0x60] = 0x0a; // PCI A -> IRQ 10 |
| 50 | pci_conf[0x61] = 0x0a; // PCI B -> IRQ 10 |
| 51 | pci_conf[0x62] = 0x0b; // PCI C -> IRQ 11 |
| 52 | pci_conf[0x63] = 0x0b; // PCI D -> IRQ 11 |
| 53 | pci_conf[0x69] = 0x02; |
| 54 | pci_conf[0x70] = 0x80; |
| 55 | pci_conf[0x76] = 0x0c; |
| 56 | pci_conf[0x77] = 0x0c; |
| 57 | pci_conf[0x78] = 0x02; |
| 58 | pci_conf[0x79] = 0x00; |
| 59 | pci_conf[0x80] = 0x00; |
| 60 | pci_conf[0x82] = 0x00; |
| 61 | pci_conf[0xa0] = 0x08; |
| 62 | pci_conf[0xa2] = 0x00; |
| 63 | pci_conf[0xa3] = 0x00; |
| 64 | pci_conf[0xa4] = 0x00; |
| 65 | pci_conf[0xa5] = 0x00; |
| 66 | pci_conf[0xa6] = 0x00; |
| 67 | pci_conf[0xa7] = 0x00; |
| 68 | pci_conf[0xa8] = 0x0f; |
| 69 | pci_conf[0xaa] = 0x00; |
| 70 | pci_conf[0xab] = 0x00; |
| 71 | pci_conf[0xac] = 0x00; |
| 72 | pci_conf[0xae] = 0x00; |
| 73 | } |
| 74 | |
Juan Quintela | 9039d78 | 2010-12-02 16:59:33 +0100 | [diff] [blame] | 75 | static const VMStateDescription vmstate_piix4 = { |
| 76 | .name = "PIIX4", |
| 77 | .version_id = 2, |
| 78 | .minimum_version_id = 2, |
| 79 | .minimum_version_id_old = 2, |
| 80 | .fields = (VMStateField[]) { |
| 81 | VMSTATE_PCI_DEVICE(dev, PIIX4State), |
| 82 | VMSTATE_END_OF_LIST() |
| 83 | } |
| 84 | }; |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 85 | |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 86 | static int piix4_initfn(PCIDevice *dev) |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 87 | { |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 88 | PIIX4State *d = DO_UPCAST(PIIX4State, dev, dev); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 89 | |
Richard Henderson | c2d0d01 | 2011-08-10 15:28:11 -0700 | [diff] [blame] | 90 | isa_bus_new(&d->dev.qdev, pci_address_space_io(dev)); |
Juan Quintela | 1fc7cee | 2010-12-02 16:26:56 +0100 | [diff] [blame] | 91 | piix4_dev = &d->dev; |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 92 | qemu_register_reset(piix4_reset, d); |
| 93 | return 0; |
| 94 | } |
| 95 | |
Hervé Poussineau | 142e978 | 2011-12-15 22:09:58 +0100 | [diff] [blame] | 96 | int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn) |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 97 | { |
| 98 | PCIDevice *d; |
| 99 | |
Isaku Yamahata | fecb93c | 2010-06-23 16:15:31 +0900 | [diff] [blame] | 100 | d = pci_create_simple_multifunction(bus, devfn, true, "PIIX4"); |
Hervé Poussineau | 142e978 | 2011-12-15 22:09:58 +0100 | [diff] [blame] | 101 | *isa_bus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&d->qdev, "isa.0")); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 102 | return d->devfn; |
| 103 | } |
| 104 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 105 | static void piix4_class_init(ObjectClass *klass, void *data) |
| 106 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 107 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 108 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 109 | |
| 110 | k->no_hotplug = 1; |
| 111 | k->init = piix4_initfn; |
| 112 | k->vendor_id = PCI_VENDOR_ID_INTEL; |
| 113 | k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0; |
| 114 | k->class_id = PCI_CLASS_BRIDGE_ISA; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 115 | dc->desc = "ISA bridge"; |
| 116 | dc->no_user = 1; |
| 117 | dc->vmsd = &vmstate_piix4; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 118 | } |
| 119 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 120 | static TypeInfo piix4_info = { |
| 121 | .name = "PIIX4", |
| 122 | .parent = TYPE_PCI_DEVICE, |
| 123 | .instance_size = sizeof(PIIX4State), |
| 124 | .class_init = piix4_class_init, |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 125 | }; |
| 126 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 127 | static void piix4_register_types(void) |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 128 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 129 | type_register_static(&piix4_info); |
Juan Quintela | 823e675 | 2009-08-28 15:28:13 +0200 | [diff] [blame] | 130 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 131 | |
| 132 | type_init(piix4_register_types) |