io_init.c 8.5 KB

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