grackle.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * QEMU Grackle PCI host (heathrow OldWorld PowerMac)
  3. *
  4. * Copyright (c) 2006-2007 Fabrice Bellard
  5. * Copyright (c) 2007 Jocelyn Mayer
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. #include "qemu/osdep.h"
  26. #include "hw/qdev-properties.h"
  27. #include "hw/pci/pci_device.h"
  28. #include "hw/irq.h"
  29. #include "qapi/error.h"
  30. #include "qemu/module.h"
  31. #include "trace.h"
  32. #include "qom/object.h"
  33. #include "hw/pci-host/grackle.h"
  34. /* Don't know if this matches real hardware, but it agrees with OHW. */
  35. static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num)
  36. {
  37. return (irq_num + (pci_dev->devfn >> 3)) & 3;
  38. }
  39. static void pci_grackle_set_irq(void *opaque, int irq_num, int level)
  40. {
  41. GrackleState *s = opaque;
  42. trace_grackle_set_irq(irq_num, level);
  43. qemu_set_irq(s->irqs[irq_num], level);
  44. }
  45. static void grackle_realize(DeviceState *dev, Error **errp)
  46. {
  47. GrackleState *s = GRACKLE_PCI_HOST_BRIDGE(dev);
  48. PCIHostState *phb = PCI_HOST_BRIDGE(dev);
  49. phb->bus = pci_register_root_bus(dev, NULL,
  50. pci_grackle_set_irq,
  51. pci_grackle_map_irq,
  52. s,
  53. &s->pci_mmio,
  54. &s->pci_io,
  55. 0, 4, TYPE_PCI_BUS);
  56. pci_create_simple(phb->bus, 0, "grackle");
  57. }
  58. static void grackle_init(Object *obj)
  59. {
  60. GrackleState *s = GRACKLE_PCI_HOST_BRIDGE(obj);
  61. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  62. PCIHostState *phb = PCI_HOST_BRIDGE(obj);
  63. memory_region_init(&s->pci_mmio, OBJECT(s), "pci-mmio", 0x100000000ULL);
  64. memory_region_init_io(&s->pci_io, OBJECT(s), &unassigned_io_ops, obj,
  65. "pci-isa-mmio", 0x00200000);
  66. memory_region_init_alias(&s->pci_hole, OBJECT(s), "pci-hole", &s->pci_mmio,
  67. 0x80000000ULL, 0x7e000000ULL);
  68. memory_region_init_io(&phb->conf_mem, obj, &pci_host_conf_le_ops,
  69. DEVICE(obj), "pci-conf-idx", 0x1000);
  70. memory_region_init_io(&phb->data_mem, obj, &pci_host_data_le_ops,
  71. DEVICE(obj), "pci-data-idx", 0x1000);
  72. sysbus_init_mmio(sbd, &phb->conf_mem);
  73. sysbus_init_mmio(sbd, &phb->data_mem);
  74. sysbus_init_mmio(sbd, &s->pci_hole);
  75. sysbus_init_mmio(sbd, &s->pci_io);
  76. qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
  77. }
  78. static void grackle_pci_realize(PCIDevice *d, Error **errp)
  79. {
  80. d->config[PCI_CLASS_PROG] = 0x01;
  81. }
  82. static void grackle_pci_class_init(ObjectClass *klass, void *data)
  83. {
  84. DeviceClass *dc = DEVICE_CLASS(klass);
  85. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  86. k->realize = grackle_pci_realize;
  87. k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
  88. k->device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
  89. k->revision = 0x00;
  90. k->class_id = PCI_CLASS_BRIDGE_HOST;
  91. /*
  92. * PCI-facing part of the host bridge, not usable without the
  93. * host-facing part, which can't be device_add'ed, yet.
  94. */
  95. dc->user_creatable = false;
  96. }
  97. static const TypeInfo grackle_pci_info = {
  98. .name = "grackle",
  99. .parent = TYPE_PCI_DEVICE,
  100. .instance_size = sizeof(PCIDevice),
  101. .class_init = grackle_pci_class_init,
  102. .interfaces = (InterfaceInfo[]) {
  103. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  104. { },
  105. },
  106. };
  107. static char *grackle_ofw_unit_address(const SysBusDevice *dev)
  108. {
  109. GrackleState *s = GRACKLE_PCI_HOST_BRIDGE(dev);
  110. return g_strdup_printf("%x", s->ofw_addr);
  111. }
  112. static Property grackle_properties[] = {
  113. DEFINE_PROP_UINT32("ofw-addr", GrackleState, ofw_addr, -1),
  114. DEFINE_PROP_END_OF_LIST()
  115. };
  116. static void grackle_class_init(ObjectClass *klass, void *data)
  117. {
  118. DeviceClass *dc = DEVICE_CLASS(klass);
  119. SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
  120. dc->realize = grackle_realize;
  121. device_class_set_props(dc, grackle_properties);
  122. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  123. dc->fw_name = "pci";
  124. sbc->explicit_ofw_unit_address = grackle_ofw_unit_address;
  125. }
  126. static const TypeInfo grackle_host_info = {
  127. .name = TYPE_GRACKLE_PCI_HOST_BRIDGE,
  128. .parent = TYPE_PCI_HOST_BRIDGE,
  129. .instance_size = sizeof(GrackleState),
  130. .instance_init = grackle_init,
  131. .class_init = grackle_class_init,
  132. };
  133. static void grackle_register_types(void)
  134. {
  135. type_register_static(&grackle_pci_info);
  136. type_register_static(&grackle_host_info);
  137. }
  138. type_init(grackle_register_types)