io_init.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
  148. hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
  149. if (!hubdev->hdi_flush_nasid_list.widget_p)
  150. continue;
  151. hubdev->hdi_flush_nasid_list.widget_p =
  152. kmalloc((HUB_WIDGET_ID_MAX + 1) *
  153. sizeof(struct sn_flush_device_list *), GFP_KERNEL);
  154. memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
  155. (HUB_WIDGET_ID_MAX + 1) *
  156. sizeof(struct sn_flush_device_list *));
  157. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
  158. sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
  159. sizeof(struct
  160. sn_flush_device_list),
  161. GFP_KERNEL);
  162. memset(sn_flush_device_list, 0x0,
  163. DEV_PER_WIDGET *
  164. sizeof(struct sn_flush_device_list));
  165. status =
  166. sal_get_widget_dmaflush_list(nasid, widget,
  167. (uint64_t)
  168. __pa
  169. (sn_flush_device_list));
  170. if (status) {
  171. kfree(sn_flush_device_list);
  172. continue;
  173. }
  174. hubdev->hdi_flush_nasid_list.widget_p[widget] =
  175. sn_flush_device_list;
  176. }
  177. if (!(i & 1))
  178. hub_error_init(hubdev);
  179. else
  180. ice_error_init(hubdev);
  181. }
  182. }
  183. /*
  184. * sn_pci_fixup_slot() - This routine sets up a slot's resources
  185. * consistent with the Linux PCI abstraction layer. Resources acquired
  186. * from our PCI provider include PIO maps to BAR space and interrupt
  187. * objects.
  188. */
  189. static void sn_pci_fixup_slot(struct pci_dev *dev)
  190. {
  191. int idx;
  192. int segment = 0;
  193. uint64_t size;
  194. struct sn_irq_info *sn_irq_info;
  195. struct pci_dev *host_pci_dev;
  196. int status = 0;
  197. struct pcibus_bussoft *bs;
  198. dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
  199. if (SN_PCIDEV_INFO(dev) <= 0)
  200. BUG(); /* Cannot afford to run out of memory */
  201. memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
  202. sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  203. if (sn_irq_info <= 0)
  204. BUG(); /* Cannot afford to run out of memory */
  205. memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
  206. /* Call to retrieve pci device information needed by kernel. */
  207. status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
  208. dev->devfn,
  209. (u64) __pa(SN_PCIDEV_INFO(dev)),
  210. (u64) __pa(sn_irq_info));
  211. if (status)
  212. BUG(); /* Cannot get platform pci device information information */
  213. /* Copy over PIO Mapped Addresses */
  214. for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
  215. unsigned long start, end, addr;
  216. if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
  217. continue;
  218. start = dev->resource[idx].start;
  219. end = dev->resource[idx].end;
  220. size = end - start;
  221. addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
  222. addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  223. dev->resource[idx].start = addr;
  224. dev->resource[idx].end = addr + size;
  225. if (dev->resource[idx].flags & IORESOURCE_IO)
  226. dev->resource[idx].parent = &ioport_resource;
  227. else
  228. dev->resource[idx].parent = &iomem_resource;
  229. }
  230. /* set up host bus linkages */
  231. bs = SN_PCIBUS_BUSSOFT(dev->bus);
  232. host_pci_dev =
  233. pci_find_slot(SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32,
  234. SN_PCIDEV_INFO(dev)->
  235. pdi_slot_host_handle & 0xffffffff);
  236. SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
  237. SN_PCIDEV_INFO(host_pci_dev);
  238. SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
  239. SN_PCIDEV_INFO(dev)->pdi_pcibus_info = bs;
  240. if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
  241. SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
  242. } else {
  243. SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
  244. }
  245. /* Only set up IRQ stuff if this device has a host bus context */
  246. if (bs && sn_irq_info->irq_irq) {
  247. SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
  248. dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
  249. sn_irq_fixup(dev, sn_irq_info);
  250. }
  251. }
  252. /*
  253. * sn_pci_controller_fixup() - This routine sets up a bus's resources
  254. * consistent with the Linux PCI abstraction layer.
  255. */
  256. static void sn_pci_controller_fixup(int segment, int busnum)
  257. {
  258. int status = 0;
  259. int nasid, cnode;
  260. struct pci_bus *bus;
  261. struct pci_controller *controller;
  262. struct pcibus_bussoft *prom_bussoft_ptr;
  263. struct hubdev_info *hubdev_info;
  264. void *provider_soft;
  265. struct sn_pcibus_provider *provider;
  266. status =
  267. sal_get_pcibus_info((u64) segment, (u64) busnum,
  268. (u64) ia64_tpa(&prom_bussoft_ptr));
  269. if (status > 0) {
  270. return; /* bus # does not exist */
  271. }
  272. prom_bussoft_ptr = __va(prom_bussoft_ptr);
  273. controller = sn_alloc_pci_sysdata();
  274. /* controller non-zero is BUG'd in sn_alloc_pci_sysdata */
  275. bus = pci_scan_bus(busnum, &pci_root_ops, controller);
  276. if (bus == NULL) {
  277. return; /* error, or bus already scanned */
  278. }
  279. /*
  280. * Per-provider fixup. Copies the contents from prom to local
  281. * area and links SN_PCIBUS_BUSSOFT().
  282. */
  283. if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES) {
  284. return; /* unsupported asic type */
  285. }
  286. provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
  287. if (provider == NULL) {
  288. return; /* no provider registerd for this asic */
  289. }
  290. provider_soft = NULL;
  291. if (provider->bus_fixup) {
  292. provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr);
  293. }
  294. if (provider_soft == NULL) {
  295. return; /* fixup failed or not applicable */
  296. }
  297. /*
  298. * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
  299. * after this point.
  300. */
  301. bus->sysdata = controller;
  302. PCI_CONTROLLER(bus)->platform_data = provider_soft;
  303. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
  304. cnode = nasid_to_cnodeid(nasid);
  305. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  306. SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
  307. &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
  308. }
  309. /*
  310. * Ugly hack to get PCI setup until we have a proper ACPI namespace.
  311. */
  312. #define PCI_BUSES_TO_SCAN 256
  313. static int __init sn_pci_init(void)
  314. {
  315. int i = 0;
  316. struct pci_dev *pci_dev = NULL;
  317. extern void sn_init_cpei_timer(void);
  318. #ifdef CONFIG_PROC_FS
  319. extern void register_sn_procfs(void);
  320. #endif
  321. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_SIMULATOR())
  322. return 0;
  323. /*
  324. * prime sn_pci_provider[]. Individial provider init routines will
  325. * override their respective default entries.
  326. */
  327. for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
  328. sn_pci_provider[i] = &sn_pci_default_provider;
  329. pcibr_init_provider();
  330. tioca_init_provider();
  331. /*
  332. * This is needed to avoid bounce limit checks in the blk layer
  333. */
  334. ia64_max_iommu_merge_mask = ~PAGE_MASK;
  335. sn_fixup_ionodes();
  336. sn_irq = kmalloc(sizeof(struct sn_irq_info *) * NR_IRQS, GFP_KERNEL);
  337. if (sn_irq <= 0)
  338. BUG(); /* Canno afford to run out of memory. */
  339. memset(sn_irq, 0, sizeof(struct sn_irq_info *) * NR_IRQS);
  340. sn_init_cpei_timer();
  341. #ifdef CONFIG_PROC_FS
  342. register_sn_procfs();
  343. #endif
  344. for (i = 0; i < PCI_BUSES_TO_SCAN; i++) {
  345. sn_pci_controller_fixup(0, i);
  346. }
  347. /*
  348. * Generic Linux PCI Layer has created the pci_bus and pci_dev
  349. * structures - time for us to add our SN PLatform specific
  350. * information.
  351. */
  352. while ((pci_dev =
  353. pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
  354. sn_pci_fixup_slot(pci_dev);
  355. }
  356. sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
  357. return 0;
  358. }
  359. /*
  360. * hubdev_init_node() - Creates the HUB data structure and link them to it's
  361. * own NODE specific data area.
  362. */
  363. void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
  364. {
  365. struct hubdev_info *hubdev_info;
  366. if (node >= num_online_nodes()) /* Headless/memless IO nodes */
  367. hubdev_info =
  368. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
  369. sizeof(struct
  370. hubdev_info));
  371. else
  372. hubdev_info =
  373. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
  374. sizeof(struct
  375. hubdev_info));
  376. npda->pdinfo = (void *)hubdev_info;
  377. }
  378. geoid_t
  379. cnodeid_get_geoid(cnodeid_t cnode)
  380. {
  381. struct hubdev_info *hubdev;
  382. hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  383. return hubdev->hdi_geoid;
  384. }
  385. subsys_initcall(sn_pci_init);