unin_pci.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * QEMU Uninorth PCI host (for all Mac99 and newer machines)
  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 "ppc_mac.h"
  26. #include "pci.h"
  27. /* debug UniNorth */
  28. //#define DEBUG_UNIN
  29. #ifdef DEBUG_UNIN
  30. #define UNIN_DPRINTF(fmt, args...) \
  31. do { printf("UNIN: " fmt , ##args); } while (0)
  32. #else
  33. #define UNIN_DPRINTF(fmt, args...)
  34. #endif
  35. typedef target_phys_addr_t pci_addr_t;
  36. #include "pci_host.h"
  37. typedef PCIHostState UNINState;
  38. static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr,
  39. uint32_t val)
  40. {
  41. UNINState *s = opaque;
  42. UNIN_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr, val);
  43. #ifdef TARGET_WORDS_BIGENDIAN
  44. val = bswap32(val);
  45. #endif
  46. s->config_reg = val;
  47. }
  48. static uint32_t pci_unin_main_config_readl (void *opaque,
  49. target_phys_addr_t addr)
  50. {
  51. UNINState *s = opaque;
  52. uint32_t val;
  53. val = s->config_reg;
  54. #ifdef TARGET_WORDS_BIGENDIAN
  55. val = bswap32(val);
  56. #endif
  57. UNIN_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, val);
  58. return val;
  59. }
  60. static CPUWriteMemoryFunc *pci_unin_main_config_write[] = {
  61. &pci_unin_main_config_writel,
  62. &pci_unin_main_config_writel,
  63. &pci_unin_main_config_writel,
  64. };
  65. static CPUReadMemoryFunc *pci_unin_main_config_read[] = {
  66. &pci_unin_main_config_readl,
  67. &pci_unin_main_config_readl,
  68. &pci_unin_main_config_readl,
  69. };
  70. static CPUWriteMemoryFunc *pci_unin_main_write[] = {
  71. &pci_host_data_writeb,
  72. &pci_host_data_writew,
  73. &pci_host_data_writel,
  74. };
  75. static CPUReadMemoryFunc *pci_unin_main_read[] = {
  76. &pci_host_data_readb,
  77. &pci_host_data_readw,
  78. &pci_host_data_readl,
  79. };
  80. #if 0
  81. static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr,
  82. uint32_t val)
  83. {
  84. UNINState *s = opaque;
  85. #ifdef TARGET_WORDS_BIGENDIAN
  86. val = bswap32(val);
  87. #endif
  88. s->config_reg = 0x80000000 | (val & ~0x00000001);
  89. }
  90. static uint32_t pci_unin_config_readl (void *opaque,
  91. target_phys_addr_t addr)
  92. {
  93. UNINState *s = opaque;
  94. uint32_t val;
  95. val = (s->config_reg | 0x00000001) & ~0x80000000;
  96. #ifdef TARGET_WORDS_BIGENDIAN
  97. val = bswap32(val);
  98. #endif
  99. return val;
  100. }
  101. static CPUWriteMemoryFunc *pci_unin_config_write[] = {
  102. &pci_unin_config_writel,
  103. &pci_unin_config_writel,
  104. &pci_unin_config_writel,
  105. };
  106. static CPUReadMemoryFunc *pci_unin_config_read[] = {
  107. &pci_unin_config_readl,
  108. &pci_unin_config_readl,
  109. &pci_unin_config_readl,
  110. };
  111. static CPUWriteMemoryFunc *pci_unin_write[] = {
  112. &pci_host_pci_writeb,
  113. &pci_host_pci_writew,
  114. &pci_host_pci_writel,
  115. };
  116. static CPUReadMemoryFunc *pci_unin_read[] = {
  117. &pci_host_pci_readb,
  118. &pci_host_pci_readw,
  119. &pci_host_pci_readl,
  120. };
  121. #endif
  122. /* Don't know if this matches real hardware, but it agrees with OHW. */
  123. static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
  124. {
  125. return (irq_num + (pci_dev->devfn >> 3)) & 3;
  126. }
  127. static void pci_unin_set_irq(qemu_irq *pic, int irq_num, int level)
  128. {
  129. qemu_set_irq(pic[irq_num + 8], level);
  130. }
  131. static void pci_unin_save(QEMUFile* f, void *opaque)
  132. {
  133. PCIDevice *d = opaque;
  134. pci_device_save(d, f);
  135. }
  136. static int pci_unin_load(QEMUFile* f, void *opaque, int version_id)
  137. {
  138. PCIDevice *d = opaque;
  139. if (version_id != 1)
  140. return -EINVAL;
  141. return pci_device_load(d, f);
  142. }
  143. static void pci_unin_reset(void *opaque)
  144. {
  145. }
  146. PCIBus *pci_pmac_init(qemu_irq *pic)
  147. {
  148. UNINState *s;
  149. PCIDevice *d;
  150. int pci_mem_config, pci_mem_data;
  151. /* Use values found on a real PowerMac */
  152. /* Uninorth main bus */
  153. s = qemu_mallocz(sizeof(UNINState));
  154. s->bus = pci_register_bus(pci_unin_set_irq, pci_unin_map_irq,
  155. pic, 11 << 3, 4);
  156. pci_mem_config = cpu_register_io_memory(0, pci_unin_main_config_read,
  157. pci_unin_main_config_write, s);
  158. pci_mem_data = cpu_register_io_memory(0, pci_unin_main_read,
  159. pci_unin_main_write, s);
  160. cpu_register_physical_memory(0xf2800000, 0x1000, pci_mem_config);
  161. cpu_register_physical_memory(0xf2c00000, 0x1000, pci_mem_data);
  162. d = pci_register_device(s->bus, "Uni-north main", sizeof(PCIDevice),
  163. 11 << 3, NULL, NULL);
  164. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
  165. pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_PCI);
  166. d->config[0x08] = 0x00; // revision
  167. pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
  168. d->config[0x0C] = 0x08; // cache_line_size
  169. d->config[0x0D] = 0x10; // latency_timer
  170. d->config[0x0E] = 0x00; // header_type
  171. d->config[0x34] = 0x00; // capabilities_pointer
  172. #if 0 // XXX: not activated as PPC BIOS doesn't handle multiple buses properly
  173. /* pci-to-pci bridge */
  174. d = pci_register_device("Uni-north bridge", sizeof(PCIDevice), 0, 13 << 3,
  175. NULL, NULL);
  176. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_DEC);
  177. pci_config_set_device_id(d->config, PCI_DEVICE_ID_DEC_21154);
  178. d->config[0x08] = 0x05; // revision
  179. pci_config_set_class(d->config, PCI_CLASS_BRIDGE_PCI);
  180. d->config[0x0C] = 0x08; // cache_line_size
  181. d->config[0x0D] = 0x20; // latency_timer
  182. d->config[0x0E] = 0x01; // header_type
  183. d->config[0x18] = 0x01; // primary_bus
  184. d->config[0x19] = 0x02; // secondary_bus
  185. d->config[0x1A] = 0x02; // subordinate_bus
  186. d->config[0x1B] = 0x20; // secondary_latency_timer
  187. d->config[0x1C] = 0x11; // io_base
  188. d->config[0x1D] = 0x01; // io_limit
  189. d->config[0x20] = 0x00; // memory_base
  190. d->config[0x21] = 0x80;
  191. d->config[0x22] = 0x00; // memory_limit
  192. d->config[0x23] = 0x80;
  193. d->config[0x24] = 0x01; // prefetchable_memory_base
  194. d->config[0x25] = 0x80;
  195. d->config[0x26] = 0xF1; // prefectchable_memory_limit
  196. d->config[0x27] = 0x7F;
  197. // d->config[0x34] = 0xdc // capabilities_pointer
  198. #endif
  199. #if 0 // XXX: not needed for now
  200. /* Uninorth AGP bus */
  201. s = &pci_bridge[1];
  202. pci_mem_config = cpu_register_io_memory(0, pci_unin_config_read,
  203. pci_unin_config_write, s);
  204. pci_mem_data = cpu_register_io_memory(0, pci_unin_read,
  205. pci_unin_write, s);
  206. cpu_register_physical_memory(0xf0800000, 0x1000, pci_mem_config);
  207. cpu_register_physical_memory(0xf0c00000, 0x1000, pci_mem_data);
  208. d = pci_register_device("Uni-north AGP", sizeof(PCIDevice), 0, 11 << 3,
  209. NULL, NULL);
  210. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
  211. pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_AGP);
  212. d->config[0x08] = 0x00; // revision
  213. pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
  214. d->config[0x0C] = 0x08; // cache_line_size
  215. d->config[0x0D] = 0x10; // latency_timer
  216. d->config[0x0E] = 0x00; // header_type
  217. // d->config[0x34] = 0x80; // capabilities_pointer
  218. #endif
  219. #if 0 // XXX: not needed for now
  220. /* Uninorth internal bus */
  221. s = &pci_bridge[2];
  222. pci_mem_config = cpu_register_io_memory(0, pci_unin_config_read,
  223. pci_unin_config_write, s);
  224. pci_mem_data = cpu_register_io_memory(0, pci_unin_read,
  225. pci_unin_write, s);
  226. cpu_register_physical_memory(0xf4800000, 0x1000, pci_mem_config);
  227. cpu_register_physical_memory(0xf4c00000, 0x1000, pci_mem_data);
  228. d = pci_register_device("Uni-north internal", sizeof(PCIDevice),
  229. 3, 11 << 3, NULL, NULL);
  230. pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
  231. pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_I_PCI);
  232. d->config[0x08] = 0x00; // revision
  233. pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
  234. d->config[0x0C] = 0x08; // cache_line_size
  235. d->config[0x0D] = 0x10; // latency_timer
  236. d->config[0x0E] = 0x00; // header_type
  237. d->config[0x34] = 0x00; // capabilities_pointer
  238. #endif
  239. register_savevm("uninorth", 0, 1, pci_unin_save, pci_unin_load, d);
  240. qemu_register_reset(pci_unin_reset, d);
  241. pci_unin_reset(d);
  242. return s->bus;
  243. }