io_init.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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-2004 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <linux/bootmem.h>
  9. #include <linux/nodemask.h>
  10. #include <asm/sn/types.h>
  11. #include <asm/sn/sn_sal.h>
  12. #include <asm/sn/addrs.h>
  13. #include <asm/sn/pcibus_provider_defs.h>
  14. #include <asm/sn/pcidev.h>
  15. #include "pci/pcibr_provider.h"
  16. #include "xtalk/xwidgetdev.h"
  17. #include <asm/sn/geo.h>
  18. #include "xtalk/hubdev.h"
  19. #include <asm/sn/io.h>
  20. #include <asm/sn/simulator.h>
  21. #include <asm/sn/tioca_provider.h>
  22. char master_baseio_wid;
  23. nasid_t master_nasid = INVALID_NASID; /* Partition Master */
  24. struct slab_info {
  25. struct hubdev_info hubdev;
  26. };
  27. struct brick {
  28. moduleid_t id; /* Module ID of this module */
  29. struct slab_info slab_info[MAX_SLABS + 1];
  30. };
  31. int sn_ioif_inited = 0; /* SN I/O infrastructure initialized? */
  32. struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
  33. /*
  34. * Hooks and struct for unsupported pci providers
  35. */
  36. static dma_addr_t
  37. sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size)
  38. {
  39. return 0;
  40. }
  41. static void
  42. sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
  43. {
  44. return;
  45. }
  46. static void *
  47. sn_default_pci_bus_fixup(struct pcibus_bussoft *soft)
  48. {
  49. return NULL;
  50. }
  51. static struct sn_pcibus_provider sn_pci_default_provider = {
  52. .dma_map = sn_default_pci_map,
  53. .dma_map_consistent = sn_default_pci_map,
  54. .dma_unmap = sn_default_pci_unmap,
  55. .bus_fixup = sn_default_pci_bus_fixup,
  56. };
  57. /*
  58. * Retrieve the DMA Flush List given nasid. This list is needed
  59. * to implement the WAR - Flush DMA data on PIO Reads.
  60. */
  61. static inline uint64_t
  62. sal_get_widget_dmaflush_list(u64 nasid, u64 widget_num, u64 address)
  63. {
  64. struct ia64_sal_retval ret_stuff;
  65. ret_stuff.status = 0;
  66. ret_stuff.v0 = 0;
  67. SAL_CALL_NOLOCK(ret_stuff,
  68. (u64) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
  69. (u64) nasid, (u64) widget_num, (u64) address, 0, 0, 0,
  70. 0);
  71. return ret_stuff.v0;
  72. }
  73. /*
  74. * Retrieve the hub device info structure for the given nasid.
  75. */
  76. static inline uint64_t sal_get_hubdev_info(u64 handle, u64 address)
  77. {
  78. struct ia64_sal_retval ret_stuff;
  79. ret_stuff.status = 0;
  80. ret_stuff.v0 = 0;
  81. SAL_CALL_NOLOCK(ret_stuff,
  82. (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
  83. (u64) handle, (u64) address, 0, 0, 0, 0, 0);
  84. return ret_stuff.v0;
  85. }
  86. /*
  87. * Retrieve the pci bus information given the bus number.
  88. */
  89. static inline uint64_t sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
  90. {
  91. struct ia64_sal_retval ret_stuff;
  92. ret_stuff.status = 0;
  93. ret_stuff.v0 = 0;
  94. SAL_CALL_NOLOCK(ret_stuff,
  95. (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
  96. (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
  97. return ret_stuff.v0;
  98. }
  99. /*
  100. * Retrieve the pci device information given the bus and device|function number.
  101. */
  102. static inline uint64_t
  103. sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
  104. u64 sn_irq_info)
  105. {
  106. struct ia64_sal_retval ret_stuff;
  107. ret_stuff.status = 0;
  108. ret_stuff.v0 = 0;
  109. SAL_CALL_NOLOCK(ret_stuff,
  110. (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
  111. (u64) segment, (u64) bus_number, (u64) devfn,
  112. (u64) pci_dev,
  113. sn_irq_info, 0, 0);
  114. return ret_stuff.v0;
  115. }
  116. /*
  117. * sn_alloc_pci_sysdata() - This routine allocates a pci controller
  118. * which is expected as the pci_dev and pci_bus sysdata by the Linux
  119. * PCI infrastructure.
  120. */
  121. static inline struct pci_controller *sn_alloc_pci_sysdata(void)
  122. {
  123. struct pci_controller *pci_sysdata;
  124. pci_sysdata = kmalloc(sizeof(*pci_sysdata), GFP_KERNEL);
  125. if (!pci_sysdata)
  126. BUG();
  127. memset(pci_sysdata, 0, sizeof(*pci_sysdata));
  128. return pci_sysdata;
  129. }
  130. /*
  131. * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
  132. * each node in the system.
  133. */
  134. static void sn_fixup_ionodes(void)
  135. {
  136. struct sn_flush_device_list *sn_flush_device_list;
  137. struct hubdev_info *hubdev;
  138. uint64_t status;
  139. uint64_t nasid;
  140. int i, widget;
  141. for (i = 0; i < numionodes; i++) {
  142. hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
  143. nasid = cnodeid_to_nasid(i);
  144. status = sal_get_hubdev_info(nasid, (uint64_t) __pa(hubdev));
  145. if (status)
  146. continue;
  147. /* Attach the error interrupt handlers */
  148. if (nasid & 1)
  149. ice_error_init(hubdev);
  150. else
  151. hub_error_init(hubdev);
  152. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
  153. hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
  154. if (!hubdev->hdi_flush_nasid_list.widget_p)
  155. continue;
  156. hubdev->hdi_flush_nasid_list.widget_p =
  157. kmalloc((HUB_WIDGET_ID_MAX + 1) *
  158. sizeof(struct sn_flush_device_list *), GFP_KERNEL);
  159. memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
  160. (HUB_WIDGET_ID_MAX + 1) *
  161. sizeof(struct sn_flush_device_list *));
  162. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
  163. sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
  164. sizeof(struct
  165. sn_flush_device_list),
  166. GFP_KERNEL);
  167. memset(sn_flush_device_list, 0x0,
  168. DEV_PER_WIDGET *
  169. sizeof(struct sn_flush_device_list));
  170. status =
  171. sal_get_widget_dmaflush_list(nasid, widget,
  172. (uint64_t)
  173. __pa
  174. (sn_flush_device_list));
  175. if (status) {
  176. kfree(sn_flush_device_list);
  177. continue;
  178. }
  179. hubdev->hdi_flush_nasid_list.widget_p[widget] =
  180. sn_flush_device_list;
  181. }
  182. }
  183. }
  184. /*
  185. * sn_pci_fixup_slot() - This routine sets up a slot's resources
  186. * consistent with the Linux PCI abstraction layer. Resources acquired
  187. * from our PCI provider include PIO maps to BAR space and interrupt
  188. * objects.
  189. */
  190. static void sn_pci_fixup_slot(struct pci_dev *dev)
  191. {
  192. int idx;
  193. int segment = 0;
  194. uint64_t size;
  195. struct sn_irq_info *sn_irq_info;
  196. struct pci_dev *host_pci_dev;
  197. int status = 0;
  198. struct pcibus_bussoft *bs;
  199. dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
  200. if (SN_PCIDEV_INFO(dev) <= 0)
  201. BUG(); /* Cannot afford to run out of memory */
  202. memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
  203. sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  204. if (sn_irq_info <= 0)
  205. BUG(); /* Cannot afford to run out of memory */
  206. memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
  207. /* Call to retrieve pci device information needed by kernel. */
  208. status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
  209. dev->devfn,
  210. (u64) __pa(SN_PCIDEV_INFO(dev)),
  211. (u64) __pa(sn_irq_info));
  212. if (status)
  213. BUG(); /* Cannot get platform pci device information information */
  214. /* Copy over PIO Mapped Addresses */
  215. for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
  216. unsigned long start, end, addr;
  217. if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
  218. continue;
  219. start = dev->resource[idx].start;
  220. end = dev->resource[idx].end;
  221. size = end - start;
  222. addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
  223. addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  224. dev->resource[idx].start = addr;
  225. dev->resource[idx].end = addr + size;
  226. if (dev->resource[idx].flags & IORESOURCE_IO)
  227. dev->resource[idx].parent = &ioport_resource;
  228. else
  229. dev->resource[idx].parent = &iomem_resource;
  230. }
  231. /* set up host bus linkages */
  232. bs = SN_PCIBUS_BUSSOFT(dev->bus);
  233. host_pci_dev =
  234. pci_find_slot(SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32,
  235. SN_PCIDEV_INFO(dev)->
  236. pdi_slot_host_handle & 0xffffffff);
  237. SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
  238. SN_PCIDEV_INFO(host_pci_dev);
  239. SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
  240. SN_PCIDEV_INFO(dev)->pdi_pcibus_info = bs;
  241. if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
  242. SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
  243. } else {
  244. SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
  245. }
  246. /* Only set up IRQ stuff if this device has a host bus context */
  247. if (bs && sn_irq_info->irq_irq) {
  248. SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
  249. dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
  250. sn_irq_fixup(dev, sn_irq_info);
  251. }
  252. }
  253. /*
  254. * sn_pci_controller_fixup() - This routine sets up a bus's resources
  255. * consistent with the Linux PCI abstraction layer.
  256. */
  257. static void sn_pci_controller_fixup(int segment, int busnum)
  258. {
  259. int status = 0;
  260. int nasid, cnode;
  261. struct pci_bus *bus;
  262. struct pci_controller *controller;
  263. struct pcibus_bussoft *prom_bussoft_ptr;
  264. struct hubdev_info *hubdev_info;
  265. void *provider_soft;
  266. struct sn_pcibus_provider *provider;
  267. status =
  268. sal_get_pcibus_info((u64) segment, (u64) busnum,
  269. (u64) ia64_tpa(&prom_bussoft_ptr));
  270. if (status > 0) {
  271. return; /* bus # does not exist */
  272. }
  273. prom_bussoft_ptr = __va(prom_bussoft_ptr);
  274. controller = sn_alloc_pci_sysdata();
  275. /* controller non-zero is BUG'd in sn_alloc_pci_sysdata */
  276. bus = pci_scan_bus(busnum, &pci_root_ops, controller);
  277. if (bus == NULL) {
  278. return; /* error, or bus already scanned */
  279. }
  280. /*
  281. * Per-provider fixup. Copies the contents from prom to local
  282. * area and links SN_PCIBUS_BUSSOFT().
  283. */
  284. if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES) {
  285. return; /* unsupported asic type */
  286. }
  287. provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
  288. if (provider == NULL) {
  289. return; /* no provider registerd for this asic */
  290. }
  291. provider_soft = NULL;
  292. if (provider->bus_fixup) {
  293. provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr);
  294. }
  295. if (provider_soft == NULL) {
  296. return; /* fixup failed or not applicable */
  297. }
  298. /*
  299. * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
  300. * after this point.
  301. */
  302. bus->sysdata = controller;
  303. PCI_CONTROLLER(bus)->platform_data = provider_soft;
  304. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
  305. cnode = nasid_to_cnodeid(nasid);
  306. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  307. SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
  308. &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
  309. }
  310. /*
  311. * Ugly hack to get PCI setup until we have a proper ACPI namespace.
  312. */
  313. #define PCI_BUSES_TO_SCAN 256
  314. static int __init sn_pci_init(void)
  315. {
  316. int i = 0;
  317. struct pci_dev *pci_dev = NULL;
  318. extern void sn_init_cpei_timer(void);
  319. #ifdef CONFIG_PROC_FS
  320. extern void register_sn_procfs(void);
  321. #endif
  322. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
  323. return 0;
  324. /*
  325. * prime sn_pci_provider[]. Individial provider init routines will
  326. * override their respective default entries.
  327. */
  328. for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
  329. sn_pci_provider[i] = &sn_pci_default_provider;
  330. pcibr_init_provider();
  331. tioca_init_provider();
  332. /*
  333. * This is needed to avoid bounce limit checks in the blk layer
  334. */
  335. ia64_max_iommu_merge_mask = ~PAGE_MASK;
  336. sn_fixup_ionodes();
  337. sn_irq = kmalloc(sizeof(struct sn_irq_info *) * NR_IRQS, GFP_KERNEL);
  338. if (sn_irq <= 0)
  339. BUG(); /* Canno afford to run out of memory. */
  340. memset(sn_irq, 0, sizeof(struct sn_irq_info *) * NR_IRQS);
  341. sn_init_cpei_timer();
  342. #ifdef CONFIG_PROC_FS
  343. register_sn_procfs();
  344. #endif
  345. for (i = 0; i < PCI_BUSES_TO_SCAN; i++) {
  346. sn_pci_controller_fixup(0, i);
  347. }
  348. /*
  349. * Generic Linux PCI Layer has created the pci_bus and pci_dev
  350. * structures - time for us to add our SN PLatform specific
  351. * information.
  352. */
  353. while ((pci_dev =
  354. pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
  355. sn_pci_fixup_slot(pci_dev);
  356. }
  357. sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
  358. return 0;
  359. }
  360. /*
  361. * hubdev_init_node() - Creates the HUB data structure and link them to it's
  362. * own NODE specific data area.
  363. */
  364. void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
  365. {
  366. struct hubdev_info *hubdev_info;
  367. if (node >= num_online_nodes()) /* Headless/memless IO nodes */
  368. hubdev_info =
  369. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
  370. sizeof(struct
  371. hubdev_info));
  372. else
  373. hubdev_info =
  374. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
  375. sizeof(struct
  376. hubdev_info));
  377. npda->pdinfo = (void *)hubdev_info;
  378. }
  379. geoid_t
  380. cnodeid_get_geoid(cnodeid_t cnode)
  381. {
  382. struct hubdev_info *hubdev;
  383. hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  384. return hubdev->hdi_geoid;
  385. }
  386. subsys_initcall(sn_pci_init);