grackle_pci.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 "hw.h"
  26. #include "ppc_mac.h"
  27. #include "pci.h"
  28. /* debug Grackle */
  29. //#define DEBUG_GRACKLE
  30. #ifdef DEBUG_GRACKLE
  31. #define GRACKLE_DPRINTF(fmt, args...) \
  32. do { printf("GRACKLE: " fmt , ##args); } while (0)
  33. #else
  34. #define GRACKLE_DPRINTF(fmt, args...)
  35. #endif
  36. typedef target_phys_addr_t pci_addr_t;
  37. #include "pci_host.h"
  38. typedef PCIHostState GrackleState;
  39. static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr,
  40. uint32_t val)
  41. {
  42. GrackleState *s = opaque;
  43. GRACKLE_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr,
  44. val);
  45. #ifdef TARGET_WORDS_BIGENDIAN
  46. val = bswap32(val);
  47. #endif
  48. s->config_reg = val;
  49. }
  50. static uint32_t pci_grackle_config_readl (void *opaque, target_phys_addr_t addr)
  51. {
  52. GrackleState *s = opaque;
  53. uint32_t val;
  54. val = s->config_reg;
  55. #ifdef TARGET_WORDS_BIGENDIAN
  56. val = bswap32(val);
  57. #endif
  58. GRACKLE_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr,
  59. val);
  60. return val;
  61. }
  62. static CPUWriteMemoryFunc *pci_grackle_config_write[] = {
  63. &pci_grackle_config_writel,
  64. &pci_grackle_config_writel,
  65. &pci_grackle_config_writel,
  66. };
  67. static CPUReadMemoryFunc *pci_grackle_config_read[] = {
  68. &pci_grackle_config_readl,
  69. &pci_grackle_config_readl,
  70. &pci_grackle_config_readl,
  71. };
  72. static CPUWriteMemoryFunc *pci_grackle_write[] = {
  73. &pci_host_data_writeb,
  74. &pci_host_data_writew,
  75. &pci_host_data_writel,
  76. };
  77. static CPUReadMemoryFunc *pci_grackle_read[] = {
  78. &pci_host_data_readb,
  79. &pci_host_data_readw,
  80. &pci_host_data_readl,
  81. };
  82. /* Don't know if this matches real hardware, but it agrees with OHW. */
  83. static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num)
  84. {
  85. return (irq_num + (pci_dev->devfn >> 3)) & 3;
  86. }
  87. static void pci_grackle_set_irq(qemu_irq *pic, int irq_num, int level)
  88. {
  89. GRACKLE_DPRINTF("set_irq num %d level %d\n", irq_num, level);
  90. qemu_set_irq(pic[irq_num + 0x15], level);
  91. }
  92. static void pci_grackle_save(QEMUFile* f, void *opaque)
  93. {
  94. PCIDevice *d = opaque;
  95. pci_device_save(d, f);
  96. }
  97. static int pci_grackle_load(QEMUFile* f, void *opaque, int version_id)
  98. {
  99. PCIDevice *d = opaque;
  100. if (version_id != 1)
  101. return -EINVAL;
  102. return pci_device_load(d, f);
  103. }
  104. static void pci_grackle_reset(void *opaque)
  105. {
  106. }
  107. PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic)
  108. {
  109. GrackleState *s;
  110. PCIDevice *d;
  111. int pci_mem_config, pci_mem_data;
  112. s = qemu_mallocz(sizeof(GrackleState));
  113. s->bus = pci_register_bus(pci_grackle_set_irq, pci_grackle_map_irq,
  114. pic, 0, 4);
  115. pci_mem_config = cpu_register_io_memory(0, pci_grackle_config_read,
  116. pci_grackle_config_write, s);
  117. pci_mem_data = cpu_register_io_memory(0, pci_grackle_read,
  118. pci_grackle_write, s);
  119. cpu_register_physical_memory(base, 0x1000, pci_mem_config);
  120. cpu_register_physical_memory(base + 0x00200000, 0x1000, pci_mem_data);
  121. d = pci_register_device(s->bus, "Grackle host bridge", sizeof(PCIDevice),
  122. 0, NULL, NULL);
  123. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_MOTOROLA);
  124. pci_config_set_device_id(d->config, PCI_DEVICE_ID_MOTOROLA_MPC106);
  125. d->config[0x08] = 0x00; // revision
  126. d->config[0x09] = 0x01;
  127. pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
  128. d->config[0x0e] = 0x00; // header_type
  129. #if 0
  130. /* PCI2PCI bridge same values as PearPC - check this */
  131. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC);
  132. pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154);
  133. d->config[0x08] = 0x02; // revision
  134. pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI);
  135. d->config[0x0e] = 0x01; // header_type
  136. d->config[0x18] = 0x0; // primary_bus
  137. d->config[0x19] = 0x1; // secondary_bus
  138. d->config[0x1a] = 0x1; // subordinate_bus
  139. d->config[0x1c] = 0x10; // io_base
  140. d->config[0x1d] = 0x20; // io_limit
  141. d->config[0x20] = 0x80; // memory_base
  142. d->config[0x21] = 0x80;
  143. d->config[0x22] = 0x90; // memory_limit
  144. d->config[0x23] = 0x80;
  145. d->config[0x24] = 0x00; // prefetchable_memory_base
  146. d->config[0x25] = 0x84;
  147. d->config[0x26] = 0x00; // prefetchable_memory_limit
  148. d->config[0x27] = 0x85;
  149. #endif
  150. register_savevm("grackle", 0, 1, pci_grackle_save, pci_grackle_load, d);
  151. qemu_register_reset(pci_grackle_reset, d);
  152. pci_grackle_reset(d);
  153. return s->bus;
  154. }