io_init.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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/addrs.h>
  12. #include <asm/sn/geo.h>
  13. #include <asm/sn/io.h>
  14. #include <asm/sn/pcibr_provider.h>
  15. #include <asm/sn/pcibus_provider_defs.h>
  16. #include <asm/sn/pcidev.h>
  17. #include <asm/sn/simulator.h>
  18. #include <asm/sn/sn_sal.h>
  19. #include <asm/sn/tioca_provider.h>
  20. #include <asm/sn/tioce_provider.h>
  21. #include "xtalk/hubdev.h"
  22. #include "xtalk/xwidgetdev.h"
  23. nasid_t master_nasid = INVALID_NASID; /* Partition Master */
  24. static struct list_head sn_sysdata_list;
  25. /* sysdata list struct */
  26. struct sysdata_el {
  27. struct list_head entry;
  28. void *sysdata;
  29. };
  30. struct slab_info {
  31. struct hubdev_info hubdev;
  32. };
  33. struct brick {
  34. moduleid_t id; /* Module ID of this module */
  35. struct slab_info slab_info[MAX_SLABS + 1];
  36. };
  37. int sn_ioif_inited = 0; /* SN I/O infrastructure initialized? */
  38. struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
  39. static int max_segment_number = 0; /* Default highest segment number */
  40. static int max_pcibus_number = 255; /* Default highest pci bus number */
  41. /*
  42. * Hooks and struct for unsupported pci providers
  43. */
  44. static dma_addr_t
  45. sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size)
  46. {
  47. return 0;
  48. }
  49. static void
  50. sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
  51. {
  52. return;
  53. }
  54. static void *
  55. sn_default_pci_bus_fixup(struct pcibus_bussoft *soft, struct pci_controller *controller)
  56. {
  57. return NULL;
  58. }
  59. static struct sn_pcibus_provider sn_pci_default_provider = {
  60. .dma_map = sn_default_pci_map,
  61. .dma_map_consistent = sn_default_pci_map,
  62. .dma_unmap = sn_default_pci_unmap,
  63. .bus_fixup = sn_default_pci_bus_fixup,
  64. };
  65. /*
  66. * Retrieve the DMA Flush List given nasid. This list is needed
  67. * to implement the WAR - Flush DMA data on PIO Reads.
  68. */
  69. static inline uint64_t
  70. sal_get_widget_dmaflush_list(u64 nasid, u64 widget_num, u64 address)
  71. {
  72. struct ia64_sal_retval ret_stuff;
  73. ret_stuff.status = 0;
  74. ret_stuff.v0 = 0;
  75. SAL_CALL_NOLOCK(ret_stuff,
  76. (u64) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
  77. (u64) nasid, (u64) widget_num, (u64) address, 0, 0, 0,
  78. 0);
  79. return ret_stuff.v0;
  80. }
  81. /*
  82. * Retrieve the hub device info structure for the given nasid.
  83. */
  84. static inline uint64_t sal_get_hubdev_info(u64 handle, u64 address)
  85. {
  86. struct ia64_sal_retval ret_stuff;
  87. ret_stuff.status = 0;
  88. ret_stuff.v0 = 0;
  89. SAL_CALL_NOLOCK(ret_stuff,
  90. (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
  91. (u64) handle, (u64) address, 0, 0, 0, 0, 0);
  92. return ret_stuff.v0;
  93. }
  94. /*
  95. * Retrieve the pci bus information given the bus number.
  96. */
  97. static inline uint64_t sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
  98. {
  99. struct ia64_sal_retval ret_stuff;
  100. ret_stuff.status = 0;
  101. ret_stuff.v0 = 0;
  102. SAL_CALL_NOLOCK(ret_stuff,
  103. (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
  104. (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
  105. return ret_stuff.v0;
  106. }
  107. /*
  108. * Retrieve the pci device information given the bus and device|function number.
  109. */
  110. static inline uint64_t
  111. sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
  112. u64 sn_irq_info)
  113. {
  114. struct ia64_sal_retval ret_stuff;
  115. ret_stuff.status = 0;
  116. ret_stuff.v0 = 0;
  117. SAL_CALL_NOLOCK(ret_stuff,
  118. (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
  119. (u64) segment, (u64) bus_number, (u64) devfn,
  120. (u64) pci_dev,
  121. sn_irq_info, 0, 0);
  122. return ret_stuff.v0;
  123. }
  124. /*
  125. * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
  126. * each node in the system.
  127. */
  128. static void sn_fixup_ionodes(void)
  129. {
  130. struct sn_flush_device_list *sn_flush_device_list;
  131. struct hubdev_info *hubdev;
  132. uint64_t status;
  133. uint64_t nasid;
  134. int i, widget;
  135. /*
  136. * Get SGI Specific HUB chipset information.
  137. * Inform Prom that this kernel can support domain bus numbering.
  138. */
  139. for (i = 0; i < numionodes; i++) {
  140. hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
  141. nasid = cnodeid_to_nasid(i);
  142. hubdev->max_segment_number = 0xffffffff;
  143. hubdev->max_pcibus_number = 0xff;
  144. status = sal_get_hubdev_info(nasid, (uint64_t) __pa(hubdev));
  145. if (status)
  146. continue;
  147. /* Save the largest Domain and pcibus numbers found. */
  148. if (hubdev->max_segment_number) {
  149. /*
  150. * Dealing with a Prom that supports segments.
  151. */
  152. max_segment_number = hubdev->max_segment_number;
  153. max_pcibus_number = hubdev->max_pcibus_number;
  154. }
  155. /* Attach the error interrupt handlers */
  156. if (nasid & 1)
  157. ice_error_init(hubdev);
  158. else
  159. hub_error_init(hubdev);
  160. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
  161. hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
  162. if (!hubdev->hdi_flush_nasid_list.widget_p)
  163. continue;
  164. hubdev->hdi_flush_nasid_list.widget_p =
  165. kmalloc((HUB_WIDGET_ID_MAX + 1) *
  166. sizeof(struct sn_flush_device_list *), GFP_KERNEL);
  167. memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
  168. (HUB_WIDGET_ID_MAX + 1) *
  169. sizeof(struct sn_flush_device_list *));
  170. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
  171. sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
  172. sizeof(struct
  173. sn_flush_device_list),
  174. GFP_KERNEL);
  175. memset(sn_flush_device_list, 0x0,
  176. DEV_PER_WIDGET *
  177. sizeof(struct sn_flush_device_list));
  178. status =
  179. sal_get_widget_dmaflush_list(nasid, widget,
  180. (uint64_t)
  181. __pa
  182. (sn_flush_device_list));
  183. if (status) {
  184. kfree(sn_flush_device_list);
  185. continue;
  186. }
  187. spin_lock_init(&sn_flush_device_list->sfdl_flush_lock);
  188. hubdev->hdi_flush_nasid_list.widget_p[widget] =
  189. sn_flush_device_list;
  190. }
  191. }
  192. }
  193. void sn_pci_unfixup_slot(struct pci_dev *dev)
  194. {
  195. struct pci_dev *host_pci_dev = SN_PCIDEV_INFO(dev)->host_pci_dev;
  196. sn_irq_unfixup(dev);
  197. pci_dev_put(host_pci_dev);
  198. pci_dev_put(dev);
  199. }
  200. /*
  201. * sn_pci_fixup_slot() - This routine sets up a slot's resources
  202. * consistent with the Linux PCI abstraction layer. Resources acquired
  203. * from our PCI provider include PIO maps to BAR space and interrupt
  204. * objects.
  205. */
  206. void sn_pci_fixup_slot(struct pci_dev *dev)
  207. {
  208. int idx;
  209. int segment = pci_domain_nr(dev->bus);
  210. int status = 0;
  211. struct pcibus_bussoft *bs;
  212. struct pci_bus *host_pci_bus;
  213. struct pci_dev *host_pci_dev;
  214. struct sn_irq_info *sn_irq_info;
  215. unsigned long size;
  216. unsigned int bus_no, devfn;
  217. pci_dev_get(dev); /* for the sysdata pointer */
  218. dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
  219. if (SN_PCIDEV_INFO(dev) <= 0)
  220. BUG(); /* Cannot afford to run out of memory */
  221. memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
  222. sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  223. if (sn_irq_info <= 0)
  224. BUG(); /* Cannot afford to run out of memory */
  225. memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
  226. /* Call to retrieve pci device information needed by kernel. */
  227. status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
  228. dev->devfn,
  229. (u64) __pa(SN_PCIDEV_INFO(dev)),
  230. (u64) __pa(sn_irq_info));
  231. if (status)
  232. BUG(); /* Cannot get platform pci device information */
  233. /* Copy over PIO Mapped Addresses */
  234. for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
  235. unsigned long start, end, addr;
  236. if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
  237. continue;
  238. start = dev->resource[idx].start;
  239. end = dev->resource[idx].end;
  240. size = end - start;
  241. addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
  242. addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  243. dev->resource[idx].start = addr;
  244. dev->resource[idx].end = addr + size;
  245. if (dev->resource[idx].flags & IORESOURCE_IO)
  246. dev->resource[idx].parent = &ioport_resource;
  247. else
  248. dev->resource[idx].parent = &iomem_resource;
  249. }
  250. /*
  251. * Using the PROMs values for the PCI host bus, get the Linux
  252. * PCI host_pci_dev struct and set up host bus linkages
  253. */
  254. bus_no = (SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32) & 0xff;
  255. devfn = SN_PCIDEV_INFO(dev)->pdi_slot_host_handle & 0xffffffff;
  256. host_pci_bus = pci_find_bus(segment, bus_no);
  257. host_pci_dev = pci_get_slot(host_pci_bus, devfn);
  258. SN_PCIDEV_INFO(dev)->host_pci_dev = host_pci_dev;
  259. SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
  260. SN_PCIDEV_INFO(host_pci_dev);
  261. SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
  262. bs = SN_PCIBUS_BUSSOFT(dev->bus);
  263. SN_PCIDEV_INFO(dev)->pdi_pcibus_info = bs;
  264. if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
  265. SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
  266. } else {
  267. SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
  268. }
  269. /* Only set up IRQ stuff if this device has a host bus context */
  270. if (bs && sn_irq_info->irq_irq) {
  271. SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
  272. dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
  273. sn_irq_fixup(dev, sn_irq_info);
  274. } else {
  275. SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = NULL;
  276. kfree(sn_irq_info);
  277. }
  278. }
  279. /*
  280. * sn_pci_controller_fixup() - This routine sets up a bus's resources
  281. * consistent with the Linux PCI abstraction layer.
  282. */
  283. void sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
  284. {
  285. int status = 0;
  286. int nasid, cnode;
  287. struct pci_controller *controller;
  288. struct pcibus_bussoft *prom_bussoft_ptr;
  289. struct hubdev_info *hubdev_info;
  290. void *provider_soft = NULL;
  291. struct sn_pcibus_provider *provider;
  292. status = sal_get_pcibus_info((u64) segment, (u64) busnum,
  293. (u64) ia64_tpa(&prom_bussoft_ptr));
  294. if (status > 0)
  295. return; /*bus # does not exist */
  296. prom_bussoft_ptr = __va(prom_bussoft_ptr);
  297. controller = kcalloc(1,sizeof(struct pci_controller), GFP_KERNEL);
  298. controller->segment = segment;
  299. if (!controller)
  300. BUG();
  301. if (bus == NULL) {
  302. bus = pci_scan_bus(busnum, &pci_root_ops, controller);
  303. if (bus == NULL)
  304. goto error_return; /* error, or bus already scanned */
  305. bus->sysdata = NULL;
  306. }
  307. if (bus->sysdata)
  308. goto error_return; /* sysdata already alloc'd */
  309. /*
  310. * Per-provider fixup. Copies the contents from prom to local
  311. * area and links SN_PCIBUS_BUSSOFT().
  312. */
  313. if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES)
  314. goto error_return; /* unsupported asic type */
  315. if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB)
  316. goto error_return; /* no further fixup necessary */
  317. provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
  318. if (provider == NULL)
  319. goto error_return; /* no provider registerd for this asic */
  320. bus->sysdata = controller;
  321. if (provider->bus_fixup)
  322. provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr, controller);
  323. if (provider_soft == NULL) {
  324. /* fixup failed or not applicable */
  325. bus->sysdata = NULL;
  326. goto error_return;
  327. }
  328. /*
  329. * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
  330. * after this point.
  331. */
  332. PCI_CONTROLLER(bus)->platform_data = provider_soft;
  333. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
  334. cnode = nasid_to_cnodeid(nasid);
  335. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  336. SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
  337. &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
  338. /*
  339. * If the node information we obtained during the fixup phase is invalid
  340. * then set controller->node to -1 (undetermined)
  341. */
  342. if (controller->node >= num_online_nodes()) {
  343. struct pcibus_bussoft *b = SN_PCIBUS_BUSSOFT(bus);
  344. printk(KERN_WARNING "Device ASIC=%u XID=%u PBUSNUM=%u"
  345. "L_IO=%lx L_MEM=%lx BASE=%lx\n",
  346. b->bs_asic_type, b->bs_xid, b->bs_persist_busnum,
  347. b->bs_legacy_io, b->bs_legacy_mem, b->bs_base);
  348. printk(KERN_WARNING "on node %d but only %d nodes online."
  349. "Association set to undetermined.\n",
  350. controller->node, num_online_nodes());
  351. controller->node = -1;
  352. }
  353. return;
  354. error_return:
  355. kfree(controller);
  356. return;
  357. }
  358. void sn_bus_store_sysdata(struct pci_dev *dev)
  359. {
  360. struct sysdata_el *element;
  361. element = kzalloc(sizeof(struct sysdata_el), GFP_KERNEL);
  362. if (!element) {
  363. dev_dbg(dev, "%s: out of memory!\n", __FUNCTION__);
  364. return;
  365. }
  366. element->sysdata = dev->sysdata;
  367. list_add(&element->entry, &sn_sysdata_list);
  368. }
  369. void sn_bus_free_sysdata(void)
  370. {
  371. struct sysdata_el *element;
  372. struct list_head *list;
  373. sn_sysdata_free_start:
  374. list_for_each(list, &sn_sysdata_list) {
  375. element = list_entry(list, struct sysdata_el, entry);
  376. list_del(&element->entry);
  377. kfree(element->sysdata);
  378. kfree(element);
  379. goto sn_sysdata_free_start;
  380. }
  381. return;
  382. }
  383. /*
  384. * Ugly hack to get PCI setup until we have a proper ACPI namespace.
  385. */
  386. #define PCI_BUSES_TO_SCAN 256
  387. static int __init sn_pci_init(void)
  388. {
  389. int i = 0;
  390. int j = 0;
  391. struct pci_dev *pci_dev = NULL;
  392. extern void sn_init_cpei_timer(void);
  393. #ifdef CONFIG_PROC_FS
  394. extern void register_sn_procfs(void);
  395. #endif
  396. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
  397. return 0;
  398. /*
  399. * prime sn_pci_provider[]. Individial provider init routines will
  400. * override their respective default entries.
  401. */
  402. for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
  403. sn_pci_provider[i] = &sn_pci_default_provider;
  404. pcibr_init_provider();
  405. tioca_init_provider();
  406. tioce_init_provider();
  407. /*
  408. * This is needed to avoid bounce limit checks in the blk layer
  409. */
  410. ia64_max_iommu_merge_mask = ~PAGE_MASK;
  411. sn_fixup_ionodes();
  412. sn_irq_lh_init();
  413. INIT_LIST_HEAD(&sn_sysdata_list);
  414. sn_init_cpei_timer();
  415. #ifdef CONFIG_PROC_FS
  416. register_sn_procfs();
  417. #endif
  418. /* busses are not known yet ... */
  419. for (i = 0; i <= max_segment_number; i++)
  420. for (j = 0; j <= max_pcibus_number; j++)
  421. sn_pci_controller_fixup(i, j, NULL);
  422. /*
  423. * Generic Linux PCI Layer has created the pci_bus and pci_dev
  424. * structures - time for us to add our SN PLatform specific
  425. * information.
  426. */
  427. while ((pci_dev =
  428. pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL)
  429. sn_pci_fixup_slot(pci_dev);
  430. sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
  431. return 0;
  432. }
  433. /*
  434. * hubdev_init_node() - Creates the HUB data structure and link them to it's
  435. * own NODE specific data area.
  436. */
  437. void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
  438. {
  439. struct hubdev_info *hubdev_info;
  440. if (node >= num_online_nodes()) /* Headless/memless IO nodes */
  441. hubdev_info =
  442. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
  443. sizeof(struct
  444. hubdev_info));
  445. else
  446. hubdev_info =
  447. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
  448. sizeof(struct
  449. hubdev_info));
  450. npda->pdinfo = (void *)hubdev_info;
  451. }
  452. geoid_t
  453. cnodeid_get_geoid(cnodeid_t cnode)
  454. {
  455. struct hubdev_info *hubdev;
  456. hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  457. return hubdev->hdi_geoid;
  458. }
  459. subsys_initcall(sn_pci_init);
  460. EXPORT_SYMBOL(sn_pci_fixup_slot);
  461. EXPORT_SYMBOL(sn_pci_unfixup_slot);
  462. EXPORT_SYMBOL(sn_pci_controller_fixup);
  463. EXPORT_SYMBOL(sn_bus_store_sysdata);
  464. EXPORT_SYMBOL(sn_bus_free_sysdata);