piix4.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include "hw.h"
  25. #include "pc.h"
  26. #include "pci/pci.h"
  27. #include "isa.h"
  28. #include "sysbus.h"
  29. PCIDevice *piix4_dev;
  30. typedef struct PIIX4State {
  31. PCIDevice dev;
  32. } PIIX4State;
  33. static void piix4_reset(void *opaque)
  34. {
  35. PIIX4State *d = opaque;
  36. uint8_t *pci_conf = d->dev.config;
  37. pci_conf[0x04] = 0x07; // master, memory and I/O
  38. pci_conf[0x05] = 0x00;
  39. pci_conf[0x06] = 0x00;
  40. pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
  41. pci_conf[0x4c] = 0x4d;
  42. pci_conf[0x4e] = 0x03;
  43. pci_conf[0x4f] = 0x00;
  44. pci_conf[0x60] = 0x0a; // PCI A -> IRQ 10
  45. pci_conf[0x61] = 0x0a; // PCI B -> IRQ 10
  46. pci_conf[0x62] = 0x0b; // PCI C -> IRQ 11
  47. pci_conf[0x63] = 0x0b; // PCI D -> IRQ 11
  48. pci_conf[0x69] = 0x02;
  49. pci_conf[0x70] = 0x80;
  50. pci_conf[0x76] = 0x0c;
  51. pci_conf[0x77] = 0x0c;
  52. pci_conf[0x78] = 0x02;
  53. pci_conf[0x79] = 0x00;
  54. pci_conf[0x80] = 0x00;
  55. pci_conf[0x82] = 0x00;
  56. pci_conf[0xa0] = 0x08;
  57. pci_conf[0xa2] = 0x00;
  58. pci_conf[0xa3] = 0x00;
  59. pci_conf[0xa4] = 0x00;
  60. pci_conf[0xa5] = 0x00;
  61. pci_conf[0xa6] = 0x00;
  62. pci_conf[0xa7] = 0x00;
  63. pci_conf[0xa8] = 0x0f;
  64. pci_conf[0xaa] = 0x00;
  65. pci_conf[0xab] = 0x00;
  66. pci_conf[0xac] = 0x00;
  67. pci_conf[0xae] = 0x00;
  68. }
  69. static const VMStateDescription vmstate_piix4 = {
  70. .name = "PIIX4",
  71. .version_id = 2,
  72. .minimum_version_id = 2,
  73. .minimum_version_id_old = 2,
  74. .fields = (VMStateField[]) {
  75. VMSTATE_PCI_DEVICE(dev, PIIX4State),
  76. VMSTATE_END_OF_LIST()
  77. }
  78. };
  79. static int piix4_initfn(PCIDevice *dev)
  80. {
  81. PIIX4State *d = DO_UPCAST(PIIX4State, dev, dev);
  82. isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
  83. piix4_dev = &d->dev;
  84. qemu_register_reset(piix4_reset, d);
  85. return 0;
  86. }
  87. int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
  88. {
  89. PCIDevice *d;
  90. d = pci_create_simple_multifunction(bus, devfn, true, "PIIX4");
  91. *isa_bus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&d->qdev, "isa.0"));
  92. return d->devfn;
  93. }
  94. static void piix4_class_init(ObjectClass *klass, void *data)
  95. {
  96. DeviceClass *dc = DEVICE_CLASS(klass);
  97. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  98. k->no_hotplug = 1;
  99. k->init = piix4_initfn;
  100. k->vendor_id = PCI_VENDOR_ID_INTEL;
  101. k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
  102. k->class_id = PCI_CLASS_BRIDGE_ISA;
  103. dc->desc = "ISA bridge";
  104. dc->no_user = 1;
  105. dc->vmsd = &vmstate_piix4;
  106. }
  107. static const TypeInfo piix4_info = {
  108. .name = "PIIX4",
  109. .parent = TYPE_PCI_DEVICE,
  110. .instance_size = sizeof(PIIX4State),
  111. .class_init = piix4_class_init,
  112. };
  113. static void piix4_register_types(void)
  114. {
  115. type_register_static(&piix4_info);
  116. }
  117. type_init(piix4_register_types)