2
0

dec.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * QEMU DEC 21154 PCI bridge
  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 "dec.h"
  26. #include "hw/sysbus.h"
  27. #include "hw/pci/pci.h"
  28. #include "hw/pci/pci_host.h"
  29. #include "hw/pci/pci_bridge.h"
  30. #include "hw/pci/pci_bus.h"
  31. /* debug DEC */
  32. //#define DEBUG_DEC
  33. #ifdef DEBUG_DEC
  34. #define DEC_DPRINTF(fmt, ...) \
  35. do { printf("DEC: " fmt , ## __VA_ARGS__); } while (0)
  36. #else
  37. #define DEC_DPRINTF(fmt, ...)
  38. #endif
  39. #define DEC_21154(obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)
  40. typedef struct DECState {
  41. PCIHostState parent_obj;
  42. } DECState;
  43. static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
  44. {
  45. return irq_num;
  46. }
  47. static int dec_pci_bridge_initfn(PCIDevice *pci_dev)
  48. {
  49. return pci_bridge_initfn(pci_dev, TYPE_PCI_BUS);
  50. }
  51. static void dec_21154_pci_bridge_class_init(ObjectClass *klass, void *data)
  52. {
  53. DeviceClass *dc = DEVICE_CLASS(klass);
  54. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  55. k->init = dec_pci_bridge_initfn;
  56. k->exit = pci_bridge_exitfn;
  57. k->vendor_id = PCI_VENDOR_ID_DEC;
  58. k->device_id = PCI_DEVICE_ID_DEC_21154;
  59. k->config_write = pci_bridge_write_config;
  60. k->is_bridge = 1;
  61. dc->desc = "DEC 21154 PCI-PCI bridge";
  62. dc->reset = pci_bridge_reset;
  63. dc->vmsd = &vmstate_pci_device;
  64. }
  65. static const TypeInfo dec_21154_pci_bridge_info = {
  66. .name = "dec-21154-p2p-bridge",
  67. .parent = TYPE_PCI_BRIDGE,
  68. .instance_size = sizeof(PCIBridge),
  69. .class_init = dec_21154_pci_bridge_class_init,
  70. };
  71. PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
  72. {
  73. PCIDevice *dev;
  74. PCIBridge *br;
  75. dev = pci_create_multifunction(parent_bus, devfn, false,
  76. "dec-21154-p2p-bridge");
  77. br = PCI_BRIDGE(dev);
  78. pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
  79. qdev_init_nofail(&dev->qdev);
  80. return pci_bridge_get_sec_bus(br);
  81. }
  82. static int pci_dec_21154_device_init(SysBusDevice *dev)
  83. {
  84. PCIHostState *phb;
  85. phb = PCI_HOST_BRIDGE(dev);
  86. memory_region_init_io(&phb->conf_mem, OBJECT(dev), &pci_host_conf_le_ops,
  87. dev, "pci-conf-idx", 0x1000);
  88. memory_region_init_io(&phb->data_mem, OBJECT(dev), &pci_host_data_le_ops,
  89. dev, "pci-data-idx", 0x1000);
  90. sysbus_init_mmio(dev, &phb->conf_mem);
  91. sysbus_init_mmio(dev, &phb->data_mem);
  92. return 0;
  93. }
  94. static int dec_21154_pci_host_init(PCIDevice *d)
  95. {
  96. /* PCI2PCI bridge same values as PearPC - check this */
  97. return 0;
  98. }
  99. static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
  100. {
  101. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  102. DeviceClass *dc = DEVICE_CLASS(klass);
  103. k->init = dec_21154_pci_host_init;
  104. k->vendor_id = PCI_VENDOR_ID_DEC;
  105. k->device_id = PCI_DEVICE_ID_DEC_21154;
  106. k->revision = 0x02;
  107. k->class_id = PCI_CLASS_BRIDGE_PCI;
  108. k->is_bridge = 1;
  109. /*
  110. * PCI-facing part of the host bridge, not usable without the
  111. * host-facing part, which can't be device_add'ed, yet.
  112. */
  113. dc->cannot_instantiate_with_device_add_yet = true;
  114. }
  115. static const TypeInfo dec_21154_pci_host_info = {
  116. .name = "dec-21154",
  117. .parent = TYPE_PCI_DEVICE,
  118. .instance_size = sizeof(PCIDevice),
  119. .class_init = dec_21154_pci_host_class_init,
  120. };
  121. static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
  122. {
  123. SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
  124. sdc->init = pci_dec_21154_device_init;
  125. }
  126. static const TypeInfo pci_dec_21154_device_info = {
  127. .name = TYPE_DEC_21154,
  128. .parent = TYPE_PCI_HOST_BRIDGE,
  129. .instance_size = sizeof(DECState),
  130. .class_init = pci_dec_21154_device_class_init,
  131. };
  132. static void dec_register_types(void)
  133. {
  134. type_register_static(&pci_dec_21154_device_info);
  135. type_register_static(&dec_21154_pci_host_info);
  136. type_register_static(&dec_21154_pci_bridge_info);
  137. }
  138. type_init(dec_register_types)