2
0

uninorth.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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 "qemu/osdep.h"
  25. #include "hw/irq.h"
  26. #include "hw/ppc/mac.h"
  27. #include "hw/qdev-properties.h"
  28. #include "qemu/module.h"
  29. #include "hw/pci/pci.h"
  30. #include "hw/pci/pci_host.h"
  31. #include "hw/pci-host/uninorth.h"
  32. #include "trace.h"
  33. static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e };
  34. static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
  35. {
  36. return (irq_num + (pci_dev->devfn >> 3)) & 3;
  37. }
  38. static void pci_unin_set_irq(void *opaque, int irq_num, int level)
  39. {
  40. UNINHostState *s = opaque;
  41. trace_unin_set_irq(unin_irq_line[irq_num], level);
  42. qemu_set_irq(s->irqs[irq_num], level);
  43. }
  44. static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)
  45. {
  46. uint32_t retval;
  47. if (reg & (1u << 31)) {
  48. /* XXX OpenBIOS compatibility hack */
  49. retval = reg | (addr & 3);
  50. } else if (reg & 1) {
  51. /* CFA1 style */
  52. retval = (reg & ~7u) | (addr & 7);
  53. } else {
  54. uint32_t slot, func;
  55. /* Grab CFA0 style values */
  56. slot = ctz32(reg & 0xfffff800);
  57. if (slot == 32) {
  58. slot = -1; /* XXX: should this be 0? */
  59. }
  60. func = (reg >> 8) & 7;
  61. /* ... and then convert them to x86 format */
  62. /* config pointer */
  63. retval = (reg & (0xff - 7)) | (addr & 7);
  64. /* slot */
  65. retval |= slot << 11;
  66. /* fn */
  67. retval |= func << 8;
  68. }
  69. trace_unin_get_config_reg(reg, addr, retval);
  70. return retval;
  71. }
  72. static void unin_data_write(void *opaque, hwaddr addr,
  73. uint64_t val, unsigned len)
  74. {
  75. UNINHostState *s = opaque;
  76. PCIHostState *phb = PCI_HOST_BRIDGE(s);
  77. trace_unin_data_write(addr, len, val);
  78. pci_data_write(phb->bus,
  79. unin_get_config_reg(phb->config_reg, addr),
  80. val, len);
  81. }
  82. static uint64_t unin_data_read(void *opaque, hwaddr addr,
  83. unsigned len)
  84. {
  85. UNINHostState *s = opaque;
  86. PCIHostState *phb = PCI_HOST_BRIDGE(s);
  87. uint32_t val;
  88. val = pci_data_read(phb->bus,
  89. unin_get_config_reg(phb->config_reg, addr),
  90. len);
  91. trace_unin_data_read(addr, len, val);
  92. return val;
  93. }
  94. static const MemoryRegionOps unin_data_ops = {
  95. .read = unin_data_read,
  96. .write = unin_data_write,
  97. .endianness = DEVICE_LITTLE_ENDIAN,
  98. };
  99. static void pci_unin_init_irqs(UNINHostState *s)
  100. {
  101. int i;
  102. for (i = 0; i < ARRAY_SIZE(s->irqs); i++) {
  103. s->irqs[i] = qdev_get_gpio_in(DEVICE(s->pic), unin_irq_line[i]);
  104. }
  105. }
  106. static char *pci_unin_main_ofw_unit_address(const SysBusDevice *dev)
  107. {
  108. UNINHostState *s = UNI_NORTH_PCI_HOST_BRIDGE(dev);
  109. return g_strdup_printf("%x", s->ofw_addr);
  110. }
  111. static void pci_unin_main_realize(DeviceState *dev, Error **errp)
  112. {
  113. UNINHostState *s = UNI_NORTH_PCI_HOST_BRIDGE(dev);
  114. PCIHostState *h = PCI_HOST_BRIDGE(dev);
  115. h->bus = pci_register_root_bus(dev, NULL,
  116. pci_unin_set_irq, pci_unin_map_irq,
  117. s,
  118. &s->pci_mmio,
  119. &s->pci_io,
  120. PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
  121. pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-pci");
  122. pci_unin_init_irqs(s);
  123. /* DEC 21154 bridge */
  124. #if 0
  125. /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */
  126. pci_create_simple(h->bus, PCI_DEVFN(12, 0), "dec-21154");
  127. #endif
  128. }
  129. static void pci_unin_main_init(Object *obj)
  130. {
  131. UNINHostState *s = UNI_NORTH_PCI_HOST_BRIDGE(obj);
  132. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  133. PCIHostState *h = PCI_HOST_BRIDGE(obj);
  134. /* Use values found on a real PowerMac */
  135. /* Uninorth main bus */
  136. memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
  137. obj, "unin-pci-conf-idx", 0x1000);
  138. memory_region_init_io(&h->data_mem, OBJECT(h), &unin_data_ops, obj,
  139. "unin-pci-conf-data", 0x1000);
  140. memory_region_init(&s->pci_mmio, OBJECT(s), "unin-pci-mmio",
  141. 0x100000000ULL);
  142. memory_region_init_io(&s->pci_io, OBJECT(s), &unassigned_io_ops, obj,
  143. "unin-pci-isa-mmio", 0x00800000);
  144. memory_region_init_alias(&s->pci_hole, OBJECT(s),
  145. "unin-pci-hole", &s->pci_mmio,
  146. 0x80000000ULL, 0x10000000ULL);
  147. object_property_add_link(obj, "pic", TYPE_OPENPIC,
  148. (Object **) &s->pic,
  149. qdev_prop_allow_set_link_before_realize,
  150. 0, NULL);
  151. sysbus_init_mmio(sbd, &h->conf_mem);
  152. sysbus_init_mmio(sbd, &h->data_mem);
  153. sysbus_init_mmio(sbd, &s->pci_hole);
  154. sysbus_init_mmio(sbd, &s->pci_io);
  155. }
  156. static void pci_u3_agp_realize(DeviceState *dev, Error **errp)
  157. {
  158. UNINHostState *s = U3_AGP_HOST_BRIDGE(dev);
  159. PCIHostState *h = PCI_HOST_BRIDGE(dev);
  160. h->bus = pci_register_root_bus(dev, NULL,
  161. pci_unin_set_irq, pci_unin_map_irq,
  162. s,
  163. &s->pci_mmio,
  164. &s->pci_io,
  165. PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
  166. pci_create_simple(h->bus, PCI_DEVFN(11, 0), "u3-agp");
  167. pci_unin_init_irqs(s);
  168. }
  169. static void pci_u3_agp_init(Object *obj)
  170. {
  171. UNINHostState *s = U3_AGP_HOST_BRIDGE(obj);
  172. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  173. PCIHostState *h = PCI_HOST_BRIDGE(obj);
  174. /* Uninorth U3 AGP bus */
  175. memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
  176. obj, "unin-pci-conf-idx", 0x1000);
  177. memory_region_init_io(&h->data_mem, OBJECT(h), &unin_data_ops, obj,
  178. "unin-pci-conf-data", 0x1000);
  179. memory_region_init(&s->pci_mmio, OBJECT(s), "unin-pci-mmio",
  180. 0x100000000ULL);
  181. memory_region_init_io(&s->pci_io, OBJECT(s), &unassigned_io_ops, obj,
  182. "unin-pci-isa-mmio", 0x00800000);
  183. memory_region_init_alias(&s->pci_hole, OBJECT(s),
  184. "unin-pci-hole", &s->pci_mmio,
  185. 0x80000000ULL, 0x70000000ULL);
  186. object_property_add_link(obj, "pic", TYPE_OPENPIC,
  187. (Object **) &s->pic,
  188. qdev_prop_allow_set_link_before_realize,
  189. 0, NULL);
  190. sysbus_init_mmio(sbd, &h->conf_mem);
  191. sysbus_init_mmio(sbd, &h->data_mem);
  192. sysbus_init_mmio(sbd, &s->pci_hole);
  193. sysbus_init_mmio(sbd, &s->pci_io);
  194. }
  195. static void pci_unin_agp_realize(DeviceState *dev, Error **errp)
  196. {
  197. UNINHostState *s = UNI_NORTH_AGP_HOST_BRIDGE(dev);
  198. PCIHostState *h = PCI_HOST_BRIDGE(dev);
  199. h->bus = pci_register_root_bus(dev, NULL,
  200. pci_unin_set_irq, pci_unin_map_irq,
  201. s,
  202. &s->pci_mmio,
  203. &s->pci_io,
  204. PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
  205. pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-agp");
  206. pci_unin_init_irqs(s);
  207. }
  208. static void pci_unin_agp_init(Object *obj)
  209. {
  210. UNINHostState *s = UNI_NORTH_AGP_HOST_BRIDGE(obj);
  211. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  212. PCIHostState *h = PCI_HOST_BRIDGE(obj);
  213. /* Uninorth AGP bus */
  214. memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
  215. obj, "unin-agp-conf-idx", 0x1000);
  216. memory_region_init_io(&h->data_mem, OBJECT(h), &pci_host_data_le_ops,
  217. obj, "unin-agp-conf-data", 0x1000);
  218. object_property_add_link(obj, "pic", TYPE_OPENPIC,
  219. (Object **) &s->pic,
  220. qdev_prop_allow_set_link_before_realize,
  221. 0, NULL);
  222. sysbus_init_mmio(sbd, &h->conf_mem);
  223. sysbus_init_mmio(sbd, &h->data_mem);
  224. }
  225. static void pci_unin_internal_realize(DeviceState *dev, Error **errp)
  226. {
  227. UNINHostState *s = UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(dev);
  228. PCIHostState *h = PCI_HOST_BRIDGE(dev);
  229. h->bus = pci_register_root_bus(dev, NULL,
  230. pci_unin_set_irq, pci_unin_map_irq,
  231. s,
  232. &s->pci_mmio,
  233. &s->pci_io,
  234. PCI_DEVFN(14, 0), 4, TYPE_PCI_BUS);
  235. pci_create_simple(h->bus, PCI_DEVFN(14, 0), "uni-north-internal-pci");
  236. pci_unin_init_irqs(s);
  237. }
  238. static void pci_unin_internal_init(Object *obj)
  239. {
  240. UNINHostState *s = UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(obj);
  241. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  242. PCIHostState *h = PCI_HOST_BRIDGE(obj);
  243. /* Uninorth internal bus */
  244. memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops,
  245. obj, "unin-pci-conf-idx", 0x1000);
  246. memory_region_init_io(&h->data_mem, OBJECT(h), &pci_host_data_le_ops,
  247. obj, "unin-pci-conf-data", 0x1000);
  248. object_property_add_link(obj, "pic", TYPE_OPENPIC,
  249. (Object **) &s->pic,
  250. qdev_prop_allow_set_link_before_realize,
  251. 0, NULL);
  252. sysbus_init_mmio(sbd, &h->conf_mem);
  253. sysbus_init_mmio(sbd, &h->data_mem);
  254. }
  255. static void unin_main_pci_host_realize(PCIDevice *d, Error **errp)
  256. {
  257. /* cache_line_size */
  258. d->config[0x0C] = 0x08;
  259. /* latency_timer */
  260. d->config[0x0D] = 0x10;
  261. /* capabilities_pointer */
  262. d->config[0x34] = 0x00;
  263. /*
  264. * Set kMacRISCPCIAddressSelect (0x48) register to indicate PCI
  265. * memory space with base 0x80000000, size 0x10000000 for Apple's
  266. * AppleMacRiscPCI driver
  267. */
  268. d->config[0x48] = 0x0;
  269. d->config[0x49] = 0x0;
  270. d->config[0x4a] = 0x0;
  271. d->config[0x4b] = 0x1;
  272. }
  273. static void unin_agp_pci_host_realize(PCIDevice *d, Error **errp)
  274. {
  275. /* cache_line_size */
  276. d->config[0x0C] = 0x08;
  277. /* latency_timer */
  278. d->config[0x0D] = 0x10;
  279. /* capabilities_pointer
  280. d->config[0x34] = 0x80; */
  281. }
  282. static void u3_agp_pci_host_realize(PCIDevice *d, Error **errp)
  283. {
  284. /* cache line size */
  285. d->config[0x0C] = 0x08;
  286. /* latency timer */
  287. d->config[0x0D] = 0x10;
  288. }
  289. static void unin_internal_pci_host_realize(PCIDevice *d, Error **errp)
  290. {
  291. /* cache_line_size */
  292. d->config[0x0C] = 0x08;
  293. /* latency_timer */
  294. d->config[0x0D] = 0x10;
  295. /* capabilities_pointer */
  296. d->config[0x34] = 0x00;
  297. }
  298. static void unin_main_pci_host_class_init(ObjectClass *klass, void *data)
  299. {
  300. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  301. DeviceClass *dc = DEVICE_CLASS(klass);
  302. k->realize = unin_main_pci_host_realize;
  303. k->vendor_id = PCI_VENDOR_ID_APPLE;
  304. k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI;
  305. k->revision = 0x00;
  306. k->class_id = PCI_CLASS_BRIDGE_HOST;
  307. /*
  308. * PCI-facing part of the host bridge, not usable without the
  309. * host-facing part, which can't be device_add'ed, yet.
  310. */
  311. dc->user_creatable = false;
  312. }
  313. static const TypeInfo unin_main_pci_host_info = {
  314. .name = "uni-north-pci",
  315. .parent = TYPE_PCI_DEVICE,
  316. .instance_size = sizeof(PCIDevice),
  317. .class_init = unin_main_pci_host_class_init,
  318. .interfaces = (InterfaceInfo[]) {
  319. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  320. { },
  321. },
  322. };
  323. static void u3_agp_pci_host_class_init(ObjectClass *klass, void *data)
  324. {
  325. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  326. DeviceClass *dc = DEVICE_CLASS(klass);
  327. k->realize = u3_agp_pci_host_realize;
  328. k->vendor_id = PCI_VENDOR_ID_APPLE;
  329. k->device_id = PCI_DEVICE_ID_APPLE_U3_AGP;
  330. k->revision = 0x00;
  331. k->class_id = PCI_CLASS_BRIDGE_HOST;
  332. /*
  333. * PCI-facing part of the host bridge, not usable without the
  334. * host-facing part, which can't be device_add'ed, yet.
  335. */
  336. dc->user_creatable = false;
  337. }
  338. static const TypeInfo u3_agp_pci_host_info = {
  339. .name = "u3-agp",
  340. .parent = TYPE_PCI_DEVICE,
  341. .instance_size = sizeof(PCIDevice),
  342. .class_init = u3_agp_pci_host_class_init,
  343. .interfaces = (InterfaceInfo[]) {
  344. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  345. { },
  346. },
  347. };
  348. static void unin_agp_pci_host_class_init(ObjectClass *klass, void *data)
  349. {
  350. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  351. DeviceClass *dc = DEVICE_CLASS(klass);
  352. k->realize = unin_agp_pci_host_realize;
  353. k->vendor_id = PCI_VENDOR_ID_APPLE;
  354. k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP;
  355. k->revision = 0x00;
  356. k->class_id = PCI_CLASS_BRIDGE_HOST;
  357. /*
  358. * PCI-facing part of the host bridge, not usable without the
  359. * host-facing part, which can't be device_add'ed, yet.
  360. */
  361. dc->user_creatable = false;
  362. }
  363. static const TypeInfo unin_agp_pci_host_info = {
  364. .name = "uni-north-agp",
  365. .parent = TYPE_PCI_DEVICE,
  366. .instance_size = sizeof(PCIDevice),
  367. .class_init = unin_agp_pci_host_class_init,
  368. .interfaces = (InterfaceInfo[]) {
  369. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  370. { },
  371. },
  372. };
  373. static void unin_internal_pci_host_class_init(ObjectClass *klass, void *data)
  374. {
  375. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  376. DeviceClass *dc = DEVICE_CLASS(klass);
  377. k->realize = unin_internal_pci_host_realize;
  378. k->vendor_id = PCI_VENDOR_ID_APPLE;
  379. k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI;
  380. k->revision = 0x00;
  381. k->class_id = PCI_CLASS_BRIDGE_HOST;
  382. /*
  383. * PCI-facing part of the host bridge, not usable without the
  384. * host-facing part, which can't be device_add'ed, yet.
  385. */
  386. dc->user_creatable = false;
  387. }
  388. static const TypeInfo unin_internal_pci_host_info = {
  389. .name = "uni-north-internal-pci",
  390. .parent = TYPE_PCI_DEVICE,
  391. .instance_size = sizeof(PCIDevice),
  392. .class_init = unin_internal_pci_host_class_init,
  393. .interfaces = (InterfaceInfo[]) {
  394. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  395. { },
  396. },
  397. };
  398. static Property pci_unin_main_pci_host_props[] = {
  399. DEFINE_PROP_UINT32("ofw-addr", UNINHostState, ofw_addr, -1),
  400. DEFINE_PROP_END_OF_LIST()
  401. };
  402. static void pci_unin_main_class_init(ObjectClass *klass, void *data)
  403. {
  404. DeviceClass *dc = DEVICE_CLASS(klass);
  405. SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
  406. dc->realize = pci_unin_main_realize;
  407. dc->props = pci_unin_main_pci_host_props;
  408. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  409. dc->fw_name = "pci";
  410. sbc->explicit_ofw_unit_address = pci_unin_main_ofw_unit_address;
  411. }
  412. static const TypeInfo pci_unin_main_info = {
  413. .name = TYPE_UNI_NORTH_PCI_HOST_BRIDGE,
  414. .parent = TYPE_PCI_HOST_BRIDGE,
  415. .instance_size = sizeof(UNINHostState),
  416. .instance_init = pci_unin_main_init,
  417. .class_init = pci_unin_main_class_init,
  418. };
  419. static void pci_u3_agp_class_init(ObjectClass *klass, void *data)
  420. {
  421. DeviceClass *dc = DEVICE_CLASS(klass);
  422. dc->realize = pci_u3_agp_realize;
  423. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  424. }
  425. static const TypeInfo pci_u3_agp_info = {
  426. .name = TYPE_U3_AGP_HOST_BRIDGE,
  427. .parent = TYPE_PCI_HOST_BRIDGE,
  428. .instance_size = sizeof(UNINHostState),
  429. .instance_init = pci_u3_agp_init,
  430. .class_init = pci_u3_agp_class_init,
  431. };
  432. static void pci_unin_agp_class_init(ObjectClass *klass, void *data)
  433. {
  434. DeviceClass *dc = DEVICE_CLASS(klass);
  435. dc->realize = pci_unin_agp_realize;
  436. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  437. }
  438. static const TypeInfo pci_unin_agp_info = {
  439. .name = TYPE_UNI_NORTH_AGP_HOST_BRIDGE,
  440. .parent = TYPE_PCI_HOST_BRIDGE,
  441. .instance_size = sizeof(UNINHostState),
  442. .instance_init = pci_unin_agp_init,
  443. .class_init = pci_unin_agp_class_init,
  444. };
  445. static void pci_unin_internal_class_init(ObjectClass *klass, void *data)
  446. {
  447. DeviceClass *dc = DEVICE_CLASS(klass);
  448. dc->realize = pci_unin_internal_realize;
  449. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  450. }
  451. static const TypeInfo pci_unin_internal_info = {
  452. .name = TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE,
  453. .parent = TYPE_PCI_HOST_BRIDGE,
  454. .instance_size = sizeof(UNINHostState),
  455. .instance_init = pci_unin_internal_init,
  456. .class_init = pci_unin_internal_class_init,
  457. };
  458. /* UniN device */
  459. static void unin_write(void *opaque, hwaddr addr, uint64_t value,
  460. unsigned size)
  461. {
  462. trace_unin_write(addr, value);
  463. }
  464. static uint64_t unin_read(void *opaque, hwaddr addr, unsigned size)
  465. {
  466. uint32_t value;
  467. switch (addr) {
  468. case 0:
  469. value = UNINORTH_VERSION_10A;
  470. break;
  471. default:
  472. value = 0;
  473. }
  474. trace_unin_read(addr, value);
  475. return value;
  476. }
  477. static const MemoryRegionOps unin_ops = {
  478. .read = unin_read,
  479. .write = unin_write,
  480. .endianness = DEVICE_BIG_ENDIAN,
  481. };
  482. static void unin_init(Object *obj)
  483. {
  484. UNINState *s = UNI_NORTH(obj);
  485. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  486. memory_region_init_io(&s->mem, obj, &unin_ops, s, "unin", 0x1000);
  487. sysbus_init_mmio(sbd, &s->mem);
  488. }
  489. static void unin_class_init(ObjectClass *klass, void *data)
  490. {
  491. DeviceClass *dc = DEVICE_CLASS(klass);
  492. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  493. }
  494. static const TypeInfo unin_info = {
  495. .name = TYPE_UNI_NORTH,
  496. .parent = TYPE_SYS_BUS_DEVICE,
  497. .instance_size = sizeof(UNINState),
  498. .instance_init = unin_init,
  499. .class_init = unin_class_init,
  500. };
  501. static void unin_register_types(void)
  502. {
  503. type_register_static(&unin_main_pci_host_info);
  504. type_register_static(&u3_agp_pci_host_info);
  505. type_register_static(&unin_agp_pci_host_info);
  506. type_register_static(&unin_internal_pci_host_info);
  507. type_register_static(&pci_unin_main_info);
  508. type_register_static(&pci_u3_agp_info);
  509. type_register_static(&pci_unin_agp_info);
  510. type_register_static(&pci_unin_internal_info);
  511. type_register_static(&unin_info);
  512. }
  513. type_init(unin_register_types)