io_init.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1992 - 1997, 2000-2006 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <linux/slab.h>
  9. #include <linux/export.h>
  10. #include <asm/sn/types.h>
  11. #include <asm/sn/addrs.h>
  12. #include <asm/sn/io.h>
  13. #include <asm/sn/module.h>
  14. #include <asm/sn/intr.h>
  15. #include <asm/sn/pcibus_provider_defs.h>
  16. #include <asm/sn/pcidev.h>
  17. #include <asm/sn/sn_sal.h>
  18. #include "xtalk/hubdev.h"
  19. /*
  20. * The code in this file will only be executed when running with
  21. * a PROM that does _not_ have base ACPI IO support.
  22. * (i.e., SN_ACPI_BASE_SUPPORT() == 0)
  23. */
  24. static int max_segment_number; /* Default highest segment number */
  25. static int max_pcibus_number = 255; /* Default highest pci bus number */
  26. /*
  27. * Retrieve the hub device info structure for the given nasid.
  28. */
  29. static inline u64 sal_get_hubdev_info(u64 handle, u64 address)
  30. {
  31. struct ia64_sal_retval ret_stuff;
  32. ret_stuff.status = 0;
  33. ret_stuff.v0 = 0;
  34. SAL_CALL_NOLOCK(ret_stuff,
  35. (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
  36. (u64) handle, (u64) address, 0, 0, 0, 0, 0);
  37. return ret_stuff.v0;
  38. }
  39. /*
  40. * Retrieve the pci bus information given the bus number.
  41. */
  42. static inline u64 sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
  43. {
  44. struct ia64_sal_retval ret_stuff;
  45. ret_stuff.status = 0;
  46. ret_stuff.v0 = 0;
  47. SAL_CALL_NOLOCK(ret_stuff,
  48. (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
  49. (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
  50. return ret_stuff.v0;
  51. }
  52. /*
  53. * Retrieve the pci device information given the bus and device|function number.
  54. */
  55. static inline u64
  56. sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
  57. u64 sn_irq_info)
  58. {
  59. struct ia64_sal_retval ret_stuff;
  60. ret_stuff.status = 0;
  61. ret_stuff.v0 = 0;
  62. SAL_CALL_NOLOCK(ret_stuff,
  63. (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
  64. (u64) segment, (u64) bus_number, (u64) devfn,
  65. (u64) pci_dev,
  66. sn_irq_info, 0, 0);
  67. return ret_stuff.v0;
  68. }
  69. /*
  70. * sn_fixup_ionodes() - This routine initializes the HUB data structure for
  71. * each node in the system. This function is only
  72. * executed when running with a non-ACPI capable PROM.
  73. */
  74. static void __init sn_fixup_ionodes(void)
  75. {
  76. struct hubdev_info *hubdev;
  77. u64 status;
  78. u64 nasid;
  79. int i;
  80. extern void sn_common_hubdev_init(struct hubdev_info *);
  81. /*
  82. * Get SGI Specific HUB chipset information.
  83. * Inform Prom that this kernel can support domain bus numbering.
  84. */
  85. for (i = 0; i < num_cnodes; i++) {
  86. hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
  87. nasid = cnodeid_to_nasid(i);
  88. hubdev->max_segment_number = 0xffffffff;
  89. hubdev->max_pcibus_number = 0xff;
  90. status = sal_get_hubdev_info(nasid, (u64) __pa(hubdev));
  91. if (status)
  92. continue;
  93. /* Save the largest Domain and pcibus numbers found. */
  94. if (hubdev->max_segment_number) {
  95. /*
  96. * Dealing with a Prom that supports segments.
  97. */
  98. max_segment_number = hubdev->max_segment_number;
  99. max_pcibus_number = hubdev->max_pcibus_number;
  100. }
  101. sn_common_hubdev_init(hubdev);
  102. }
  103. }
  104. /*
  105. * sn_pci_legacy_window_fixup - Setup PCI resources for
  106. * legacy IO and MEM space. This needs to
  107. * be done here, as the PROM does not have
  108. * ACPI support defining the root buses
  109. * and their resources (_CRS),
  110. */
  111. static void
  112. sn_legacy_pci_window_fixup(struct resource *res,
  113. u64 legacy_io, u64 legacy_mem)
  114. {
  115. res[0].name = "legacy_io";
  116. res[0].flags = IORESOURCE_IO;
  117. res[0].start = legacy_io;
  118. res[0].end = res[0].start + 0xffff;
  119. res[0].parent = &ioport_resource;
  120. res[1].name = "legacy_mem";
  121. res[1].flags = IORESOURCE_MEM;
  122. res[1].start = legacy_mem;
  123. res[1].end = res[1].start + (1024 * 1024) - 1;
  124. res[1].parent = &iomem_resource;
  125. }
  126. /*
  127. * sn_io_slot_fixup() - We are not running with an ACPI capable PROM,
  128. * and need to convert the pci_dev->resource
  129. * 'start' and 'end' addresses to mapped addresses,
  130. * and setup the pci_controller->window array entries.
  131. */
  132. void
  133. sn_io_slot_fixup(struct pci_dev *dev)
  134. {
  135. int idx;
  136. unsigned long addr, end, size, start;
  137. struct pcidev_info *pcidev_info;
  138. struct sn_irq_info *sn_irq_info;
  139. int status;
  140. pcidev_info = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
  141. if (!pcidev_info)
  142. panic("%s: Unable to alloc memory for pcidev_info", __func__);
  143. sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  144. if (!sn_irq_info)
  145. panic("%s: Unable to alloc memory for sn_irq_info", __func__);
  146. /* Call to retrieve pci device information needed by kernel. */
  147. status = sal_get_pcidev_info((u64) pci_domain_nr(dev),
  148. (u64) dev->bus->number,
  149. dev->devfn,
  150. (u64) __pa(pcidev_info),
  151. (u64) __pa(sn_irq_info));
  152. BUG_ON(status); /* Cannot get platform pci device information */
  153. /* Copy over PIO Mapped Addresses */
  154. for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
  155. if (!pcidev_info->pdi_pio_mapped_addr[idx]) {
  156. continue;
  157. }
  158. start = dev->resource[idx].start;
  159. end = dev->resource[idx].end;
  160. size = end - start;
  161. if (size == 0) {
  162. continue;
  163. }
  164. addr = pcidev_info->pdi_pio_mapped_addr[idx];
  165. addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  166. dev->resource[idx].start = addr;
  167. dev->resource[idx].end = addr + size;
  168. /*
  169. * if it's already in the device structure, remove it before
  170. * inserting
  171. */
  172. if (dev->resource[idx].parent && dev->resource[idx].parent->child)
  173. release_resource(&dev->resource[idx]);
  174. if (dev->resource[idx].flags & IORESOURCE_IO)
  175. insert_resource(&ioport_resource, &dev->resource[idx]);
  176. else
  177. insert_resource(&iomem_resource, &dev->resource[idx]);
  178. /*
  179. * If ROM, set the actual ROM image size, and mark as
  180. * shadowed in PROM.
  181. */
  182. if (idx == PCI_ROM_RESOURCE) {
  183. size_t image_size;
  184. void __iomem *rom;
  185. rom = ioremap(pci_resource_start(dev, PCI_ROM_RESOURCE),
  186. size + 1);
  187. image_size = pci_get_rom_size(dev, rom, size + 1);
  188. dev->resource[PCI_ROM_RESOURCE].end =
  189. dev->resource[PCI_ROM_RESOURCE].start +
  190. image_size - 1;
  191. dev->resource[PCI_ROM_RESOURCE].flags |=
  192. IORESOURCE_ROM_BIOS_COPY;
  193. }
  194. }
  195. sn_pci_fixup_slot(dev, pcidev_info, sn_irq_info);
  196. }
  197. EXPORT_SYMBOL(sn_io_slot_fixup);
  198. /*
  199. * sn_pci_controller_fixup() - This routine sets up a bus's resources
  200. * consistent with the Linux PCI abstraction layer.
  201. */
  202. static void __init
  203. sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
  204. {
  205. s64 status = 0;
  206. struct pci_controller *controller;
  207. struct pcibus_bussoft *prom_bussoft_ptr;
  208. struct resource *res;
  209. LIST_HEAD(resources);
  210. status = sal_get_pcibus_info((u64) segment, (u64) busnum,
  211. (u64) ia64_tpa(&prom_bussoft_ptr));
  212. if (status > 0)
  213. return; /*bus # does not exist */
  214. prom_bussoft_ptr = __va(prom_bussoft_ptr);
  215. controller = kzalloc(sizeof(*controller), GFP_KERNEL);
  216. BUG_ON(!controller);
  217. controller->segment = segment;
  218. res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
  219. BUG_ON(!res);
  220. /*
  221. * Temporarily save the prom_bussoft_ptr for use by sn_bus_fixup().
  222. * (platform_data will be overwritten later in sn_common_bus_fixup())
  223. */
  224. controller->platform_data = prom_bussoft_ptr;
  225. sn_legacy_pci_window_fixup(res,
  226. prom_bussoft_ptr->bs_legacy_io,
  227. prom_bussoft_ptr->bs_legacy_mem);
  228. pci_add_resource_offset(&resources, &res[0],
  229. prom_bussoft_ptr->bs_legacy_io);
  230. pci_add_resource_offset(&resources, &res[1],
  231. prom_bussoft_ptr->bs_legacy_mem);
  232. bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, controller,
  233. &resources);
  234. if (bus == NULL) {
  235. kfree(res);
  236. kfree(controller);
  237. }
  238. }
  239. /*
  240. * sn_bus_fixup
  241. */
  242. void
  243. sn_bus_fixup(struct pci_bus *bus)
  244. {
  245. struct pci_dev *pci_dev = NULL;
  246. struct pcibus_bussoft *prom_bussoft_ptr;
  247. if (!bus->parent) { /* If root bus */
  248. prom_bussoft_ptr = PCI_CONTROLLER(bus)->platform_data;
  249. if (prom_bussoft_ptr == NULL) {
  250. printk(KERN_ERR
  251. "sn_bus_fixup: 0x%04x:0x%02x Unable to "
  252. "obtain prom_bussoft_ptr\n",
  253. pci_domain_nr(bus), bus->number);
  254. return;
  255. }
  256. sn_common_bus_fixup(bus, prom_bussoft_ptr);
  257. }
  258. list_for_each_entry(pci_dev, &bus->devices, bus_list) {
  259. sn_io_slot_fixup(pci_dev);
  260. }
  261. }
  262. /*
  263. * sn_io_init - PROM does not have ACPI support to define nodes or root buses,
  264. * so we need to do things the hard way, including initiating the
  265. * bus scanning ourselves.
  266. */
  267. void __init sn_io_init(void)
  268. {
  269. int i, j;
  270. sn_fixup_ionodes();
  271. /* busses are not known yet ... */
  272. for (i = 0; i <= max_segment_number; i++)
  273. for (j = 0; j <= max_pcibus_number; j++)
  274. sn_pci_controller_fixup(i, j, NULL);
  275. }