io_init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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-2005 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/sn_feature_sets.h>
  13. #include <asm/sn/geo.h>
  14. #include <asm/sn/io.h>
  15. #include <asm/sn/pcibr_provider.h>
  16. #include <asm/sn/pcibus_provider_defs.h>
  17. #include <asm/sn/pcidev.h>
  18. #include <asm/sn/simulator.h>
  19. #include <asm/sn/sn_sal.h>
  20. #include <asm/sn/tioca_provider.h>
  21. #include <asm/sn/tioce_provider.h>
  22. #include "xtalk/hubdev.h"
  23. #include "xtalk/xwidgetdev.h"
  24. extern void sn_init_cpei_timer(void);
  25. extern void register_sn_procfs(void);
  26. static struct list_head sn_sysdata_list;
  27. /* sysdata list struct */
  28. struct sysdata_el {
  29. struct list_head entry;
  30. void *sysdata;
  31. };
  32. struct slab_info {
  33. struct hubdev_info hubdev;
  34. };
  35. struct brick {
  36. moduleid_t id; /* Module ID of this module */
  37. struct slab_info slab_info[MAX_SLABS + 1];
  38. };
  39. int sn_ioif_inited; /* SN I/O infrastructure initialized? */
  40. struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
  41. static int max_segment_number; /* Default highest segment number */
  42. static int max_pcibus_number = 255; /* Default highest pci bus number */
  43. /*
  44. * Hooks and struct for unsupported pci providers
  45. */
  46. static dma_addr_t
  47. sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size)
  48. {
  49. return 0;
  50. }
  51. static void
  52. sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
  53. {
  54. return;
  55. }
  56. static void *
  57. sn_default_pci_bus_fixup(struct pcibus_bussoft *soft, struct pci_controller *controller)
  58. {
  59. return NULL;
  60. }
  61. static struct sn_pcibus_provider sn_pci_default_provider = {
  62. .dma_map = sn_default_pci_map,
  63. .dma_map_consistent = sn_default_pci_map,
  64. .dma_unmap = sn_default_pci_unmap,
  65. .bus_fixup = sn_default_pci_bus_fixup,
  66. };
  67. /*
  68. * Retrieve the DMA Flush List given nasid, widget, and device.
  69. * This list is needed to implement the WAR - Flush DMA data on PIO Reads.
  70. */
  71. static inline u64
  72. sal_get_device_dmaflush_list(u64 nasid, u64 widget_num, u64 device_num,
  73. u64 address)
  74. {
  75. struct ia64_sal_retval ret_stuff;
  76. ret_stuff.status = 0;
  77. ret_stuff.v0 = 0;
  78. SAL_CALL_NOLOCK(ret_stuff,
  79. (u64) SN_SAL_IOIF_GET_DEVICE_DMAFLUSH_LIST,
  80. (u64) nasid, (u64) widget_num,
  81. (u64) device_num, (u64) address, 0, 0, 0);
  82. return ret_stuff.status;
  83. }
  84. /*
  85. * Retrieve the hub device info structure for the given nasid.
  86. */
  87. static inline u64 sal_get_hubdev_info(u64 handle, u64 address)
  88. {
  89. struct ia64_sal_retval ret_stuff;
  90. ret_stuff.status = 0;
  91. ret_stuff.v0 = 0;
  92. SAL_CALL_NOLOCK(ret_stuff,
  93. (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
  94. (u64) handle, (u64) address, 0, 0, 0, 0, 0);
  95. return ret_stuff.v0;
  96. }
  97. /*
  98. * Retrieve the pci bus information given the bus number.
  99. */
  100. static inline u64 sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
  101. {
  102. struct ia64_sal_retval ret_stuff;
  103. ret_stuff.status = 0;
  104. ret_stuff.v0 = 0;
  105. SAL_CALL_NOLOCK(ret_stuff,
  106. (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
  107. (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
  108. return ret_stuff.v0;
  109. }
  110. /*
  111. * Retrieve the pci device information given the bus and device|function number.
  112. */
  113. static inline u64
  114. sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
  115. u64 sn_irq_info)
  116. {
  117. struct ia64_sal_retval ret_stuff;
  118. ret_stuff.status = 0;
  119. ret_stuff.v0 = 0;
  120. SAL_CALL_NOLOCK(ret_stuff,
  121. (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
  122. (u64) segment, (u64) bus_number, (u64) devfn,
  123. (u64) pci_dev,
  124. sn_irq_info, 0, 0);
  125. return ret_stuff.v0;
  126. }
  127. /*
  128. * sn_pcidev_info_get() - Retrieve the pcidev_info struct for the specified
  129. * device.
  130. */
  131. inline struct pcidev_info *
  132. sn_pcidev_info_get(struct pci_dev *dev)
  133. {
  134. struct pcidev_info *pcidev;
  135. list_for_each_entry(pcidev,
  136. &(SN_PCI_CONTROLLER(dev)->pcidev_info), pdi_list) {
  137. if (pcidev->pdi_linux_pcidev == dev) {
  138. return pcidev;
  139. }
  140. }
  141. return NULL;
  142. }
  143. /* Older PROM flush WAR
  144. *
  145. * 01/16/06 -- This war will be in place until a new official PROM is released.
  146. * Additionally note that the struct sn_flush_device_war also has to be
  147. * removed from arch/ia64/sn/include/xtalk/hubdev.h
  148. */
  149. static u8 war_implemented = 0;
  150. static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device,
  151. struct sn_flush_device_common *common)
  152. {
  153. struct sn_flush_device_war *war_list;
  154. struct sn_flush_device_war *dev_entry;
  155. struct ia64_sal_retval isrv = {0,0,0,0};
  156. if (!war_implemented) {
  157. printk(KERN_WARNING "PROM version < 4.50 -- implementing old "
  158. "PROM flush WAR\n");
  159. war_implemented = 1;
  160. }
  161. war_list = kzalloc(DEV_PER_WIDGET * sizeof(*war_list), GFP_KERNEL);
  162. if (!war_list)
  163. BUG();
  164. SAL_CALL_NOLOCK(isrv, SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
  165. nasid, widget, __pa(war_list), 0, 0, 0 ,0);
  166. if (isrv.status)
  167. panic("sn_device_fixup_war failed: %s\n",
  168. ia64_sal_strerror(isrv.status));
  169. dev_entry = war_list + device;
  170. memcpy(common,dev_entry, sizeof(*common));
  171. kfree(war_list);
  172. return isrv.status;
  173. }
  174. /*
  175. * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
  176. * each node in the system.
  177. */
  178. static void __init sn_fixup_ionodes(void)
  179. {
  180. struct sn_flush_device_kernel *sn_flush_device_kernel;
  181. struct sn_flush_device_kernel *dev_entry;
  182. struct hubdev_info *hubdev;
  183. u64 status;
  184. u64 nasid;
  185. int i, widget, device, size;
  186. /*
  187. * Get SGI Specific HUB chipset information.
  188. * Inform Prom that this kernel can support domain bus numbering.
  189. */
  190. for (i = 0; i < num_cnodes; i++) {
  191. hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
  192. nasid = cnodeid_to_nasid(i);
  193. hubdev->max_segment_number = 0xffffffff;
  194. hubdev->max_pcibus_number = 0xff;
  195. status = sal_get_hubdev_info(nasid, (u64) __pa(hubdev));
  196. if (status)
  197. continue;
  198. /* Save the largest Domain and pcibus numbers found. */
  199. if (hubdev->max_segment_number) {
  200. /*
  201. * Dealing with a Prom that supports segments.
  202. */
  203. max_segment_number = hubdev->max_segment_number;
  204. max_pcibus_number = hubdev->max_pcibus_number;
  205. }
  206. /* Attach the error interrupt handlers */
  207. if (nasid & 1)
  208. ice_error_init(hubdev);
  209. else
  210. hub_error_init(hubdev);
  211. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
  212. hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
  213. if (!hubdev->hdi_flush_nasid_list.widget_p)
  214. continue;
  215. size = (HUB_WIDGET_ID_MAX + 1) *
  216. sizeof(struct sn_flush_device_kernel *);
  217. hubdev->hdi_flush_nasid_list.widget_p =
  218. kzalloc(size, GFP_KERNEL);
  219. if (!hubdev->hdi_flush_nasid_list.widget_p)
  220. BUG();
  221. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
  222. size = DEV_PER_WIDGET *
  223. sizeof(struct sn_flush_device_kernel);
  224. sn_flush_device_kernel = kzalloc(size, GFP_KERNEL);
  225. if (!sn_flush_device_kernel)
  226. BUG();
  227. dev_entry = sn_flush_device_kernel;
  228. for (device = 0; device < DEV_PER_WIDGET;
  229. device++,dev_entry++) {
  230. size = sizeof(struct sn_flush_device_common);
  231. dev_entry->common = kzalloc(size, GFP_KERNEL);
  232. if (!dev_entry->common)
  233. BUG();
  234. if (sn_prom_feature_available(
  235. PRF_DEVICE_FLUSH_LIST))
  236. status = sal_get_device_dmaflush_list(
  237. nasid, widget, device,
  238. (u64)(dev_entry->common));
  239. else
  240. status = sn_device_fixup_war(nasid,
  241. widget, device,
  242. dev_entry->common);
  243. if (status != SALRET_OK)
  244. panic("SAL call failed: %s\n",
  245. ia64_sal_strerror(status));
  246. spin_lock_init(&dev_entry->sfdl_flush_lock);
  247. }
  248. if (sn_flush_device_kernel)
  249. hubdev->hdi_flush_nasid_list.widget_p[widget] =
  250. sn_flush_device_kernel;
  251. }
  252. }
  253. }
  254. /*
  255. * sn_pci_window_fixup() - Create a pci_window for each device resource.
  256. * Until ACPI support is added, we need this code
  257. * to setup pci_windows for use by
  258. * pcibios_bus_to_resource(),
  259. * pcibios_resource_to_bus(), etc.
  260. */
  261. static void
  262. sn_pci_window_fixup(struct pci_dev *dev, unsigned int count,
  263. s64 * pci_addrs)
  264. {
  265. struct pci_controller *controller = PCI_CONTROLLER(dev->bus);
  266. unsigned int i;
  267. unsigned int idx;
  268. unsigned int new_count;
  269. struct pci_window *new_window;
  270. if (count == 0)
  271. return;
  272. idx = controller->windows;
  273. new_count = controller->windows + count;
  274. new_window = kcalloc(new_count, sizeof(struct pci_window), GFP_KERNEL);
  275. if (new_window == NULL)
  276. BUG();
  277. if (controller->window) {
  278. memcpy(new_window, controller->window,
  279. sizeof(struct pci_window) * controller->windows);
  280. kfree(controller->window);
  281. }
  282. /* Setup a pci_window for each device resource. */
  283. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  284. if (pci_addrs[i] == -1)
  285. continue;
  286. new_window[idx].offset = dev->resource[i].start - pci_addrs[i];
  287. new_window[idx].resource = dev->resource[i];
  288. idx++;
  289. }
  290. controller->windows = new_count;
  291. controller->window = new_window;
  292. }
  293. void sn_pci_unfixup_slot(struct pci_dev *dev)
  294. {
  295. struct pci_dev *host_pci_dev = SN_PCIDEV_INFO(dev)->host_pci_dev;
  296. sn_irq_unfixup(dev);
  297. pci_dev_put(host_pci_dev);
  298. pci_dev_put(dev);
  299. }
  300. /*
  301. * sn_pci_fixup_slot() - This routine sets up a slot's resources
  302. * consistent with the Linux PCI abstraction layer. Resources acquired
  303. * from our PCI provider include PIO maps to BAR space and interrupt
  304. * objects.
  305. */
  306. void sn_pci_fixup_slot(struct pci_dev *dev)
  307. {
  308. unsigned int count = 0;
  309. int idx;
  310. int segment = pci_domain_nr(dev->bus);
  311. int status = 0;
  312. struct pcibus_bussoft *bs;
  313. struct pci_bus *host_pci_bus;
  314. struct pci_dev *host_pci_dev;
  315. struct pcidev_info *pcidev_info;
  316. s64 pci_addrs[PCI_ROM_RESOURCE + 1];
  317. struct sn_irq_info *sn_irq_info;
  318. unsigned long size;
  319. unsigned int bus_no, devfn;
  320. pci_dev_get(dev); /* for the sysdata pointer */
  321. pcidev_info = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
  322. if (!pcidev_info)
  323. BUG(); /* Cannot afford to run out of memory */
  324. sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  325. if (!sn_irq_info)
  326. BUG(); /* Cannot afford to run out of memory */
  327. /* Call to retrieve pci device information needed by kernel. */
  328. status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
  329. dev->devfn,
  330. (u64) __pa(pcidev_info),
  331. (u64) __pa(sn_irq_info));
  332. if (status)
  333. BUG(); /* Cannot get platform pci device information */
  334. /* Add pcidev_info to list in sn_pci_controller struct */
  335. list_add_tail(&pcidev_info->pdi_list,
  336. &(SN_PCI_CONTROLLER(dev->bus)->pcidev_info));
  337. /* Copy over PIO Mapped Addresses */
  338. for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
  339. unsigned long start, end, addr;
  340. if (!pcidev_info->pdi_pio_mapped_addr[idx]) {
  341. pci_addrs[idx] = -1;
  342. continue;
  343. }
  344. start = dev->resource[idx].start;
  345. end = dev->resource[idx].end;
  346. size = end - start;
  347. if (size == 0) {
  348. pci_addrs[idx] = -1;
  349. continue;
  350. }
  351. pci_addrs[idx] = start;
  352. count++;
  353. addr = pcidev_info->pdi_pio_mapped_addr[idx];
  354. addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  355. dev->resource[idx].start = addr;
  356. dev->resource[idx].end = addr + size;
  357. if (dev->resource[idx].flags & IORESOURCE_IO)
  358. dev->resource[idx].parent = &ioport_resource;
  359. else
  360. dev->resource[idx].parent = &iomem_resource;
  361. }
  362. /* Create a pci_window in the pci_controller struct for
  363. * each device resource.
  364. */
  365. if (count > 0)
  366. sn_pci_window_fixup(dev, count, pci_addrs);
  367. /*
  368. * Using the PROMs values for the PCI host bus, get the Linux
  369. * PCI host_pci_dev struct and set up host bus linkages
  370. */
  371. bus_no = (pcidev_info->pdi_slot_host_handle >> 32) & 0xff;
  372. devfn = pcidev_info->pdi_slot_host_handle & 0xffffffff;
  373. host_pci_bus = pci_find_bus(segment, bus_no);
  374. host_pci_dev = pci_get_slot(host_pci_bus, devfn);
  375. pcidev_info->host_pci_dev = host_pci_dev;
  376. pcidev_info->pdi_linux_pcidev = dev;
  377. pcidev_info->pdi_host_pcidev_info = SN_PCIDEV_INFO(host_pci_dev);
  378. bs = SN_PCIBUS_BUSSOFT(dev->bus);
  379. pcidev_info->pdi_pcibus_info = bs;
  380. if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
  381. SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
  382. } else {
  383. SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
  384. }
  385. /* Only set up IRQ stuff if this device has a host bus context */
  386. if (bs && sn_irq_info->irq_irq) {
  387. pcidev_info->pdi_sn_irq_info = sn_irq_info;
  388. dev->irq = pcidev_info->pdi_sn_irq_info->irq_irq;
  389. sn_irq_fixup(dev, sn_irq_info);
  390. } else {
  391. pcidev_info->pdi_sn_irq_info = NULL;
  392. kfree(sn_irq_info);
  393. }
  394. /*
  395. * MSI currently not supported on altix. Remove this when
  396. * the MSI abstraction patches are integrated into the kernel
  397. * (sometime after 2.6.16 releases)
  398. */
  399. dev->no_msi = 1;
  400. }
  401. /*
  402. * sn_pci_controller_fixup() - This routine sets up a bus's resources
  403. * consistent with the Linux PCI abstraction layer.
  404. */
  405. void sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
  406. {
  407. int status;
  408. int nasid, cnode;
  409. struct pci_controller *controller;
  410. struct sn_pci_controller *sn_controller;
  411. struct pcibus_bussoft *prom_bussoft_ptr;
  412. struct hubdev_info *hubdev_info;
  413. void *provider_soft;
  414. struct sn_pcibus_provider *provider;
  415. status = sal_get_pcibus_info((u64) segment, (u64) busnum,
  416. (u64) ia64_tpa(&prom_bussoft_ptr));
  417. if (status > 0)
  418. return; /*bus # does not exist */
  419. prom_bussoft_ptr = __va(prom_bussoft_ptr);
  420. /* Allocate a sn_pci_controller, which has a pci_controller struct
  421. * as the first member.
  422. */
  423. sn_controller = kzalloc(sizeof(struct sn_pci_controller), GFP_KERNEL);
  424. if (!sn_controller)
  425. BUG();
  426. INIT_LIST_HEAD(&sn_controller->pcidev_info);
  427. controller = &sn_controller->pci_controller;
  428. controller->segment = segment;
  429. if (bus == NULL) {
  430. bus = pci_scan_bus(busnum, &pci_root_ops, controller);
  431. if (bus == NULL)
  432. goto error_return; /* error, or bus already scanned */
  433. bus->sysdata = NULL;
  434. }
  435. if (bus->sysdata)
  436. goto error_return; /* sysdata already alloc'd */
  437. /*
  438. * Per-provider fixup. Copies the contents from prom to local
  439. * area and links SN_PCIBUS_BUSSOFT().
  440. */
  441. if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES)
  442. goto error_return; /* unsupported asic type */
  443. if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB)
  444. goto error_return; /* no further fixup necessary */
  445. provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
  446. if (provider == NULL)
  447. goto error_return; /* no provider registerd for this asic */
  448. bus->sysdata = controller;
  449. if (provider->bus_fixup)
  450. provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr, controller);
  451. else
  452. provider_soft = NULL;
  453. if (provider_soft == NULL) {
  454. /* fixup failed or not applicable */
  455. bus->sysdata = NULL;
  456. goto error_return;
  457. }
  458. /*
  459. * Setup pci_windows for legacy IO and MEM space.
  460. * (Temporary until ACPI support is in place.)
  461. */
  462. controller->window = kcalloc(2, sizeof(struct pci_window), GFP_KERNEL);
  463. if (controller->window == NULL)
  464. BUG();
  465. controller->window[0].offset = prom_bussoft_ptr->bs_legacy_io;
  466. controller->window[0].resource.name = "legacy_io";
  467. controller->window[0].resource.flags = IORESOURCE_IO;
  468. controller->window[0].resource.start = prom_bussoft_ptr->bs_legacy_io;
  469. controller->window[0].resource.end =
  470. controller->window[0].resource.start + 0xffff;
  471. controller->window[0].resource.parent = &ioport_resource;
  472. controller->window[1].offset = prom_bussoft_ptr->bs_legacy_mem;
  473. controller->window[1].resource.name = "legacy_mem";
  474. controller->window[1].resource.flags = IORESOURCE_MEM;
  475. controller->window[1].resource.start = prom_bussoft_ptr->bs_legacy_mem;
  476. controller->window[1].resource.end =
  477. controller->window[1].resource.start + (1024 * 1024) - 1;
  478. controller->window[1].resource.parent = &iomem_resource;
  479. controller->windows = 2;
  480. /*
  481. * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
  482. * after this point.
  483. */
  484. PCI_CONTROLLER(bus)->platform_data = provider_soft;
  485. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
  486. cnode = nasid_to_cnodeid(nasid);
  487. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  488. SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
  489. &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
  490. /*
  491. * If the node information we obtained during the fixup phase is invalid
  492. * then set controller->node to -1 (undetermined)
  493. */
  494. if (controller->node >= num_online_nodes()) {
  495. struct pcibus_bussoft *b = SN_PCIBUS_BUSSOFT(bus);
  496. printk(KERN_WARNING "Device ASIC=%u XID=%u PBUSNUM=%u"
  497. "L_IO=%lx L_MEM=%lx BASE=%lx\n",
  498. b->bs_asic_type, b->bs_xid, b->bs_persist_busnum,
  499. b->bs_legacy_io, b->bs_legacy_mem, b->bs_base);
  500. printk(KERN_WARNING "on node %d but only %d nodes online."
  501. "Association set to undetermined.\n",
  502. controller->node, num_online_nodes());
  503. controller->node = -1;
  504. }
  505. return;
  506. error_return:
  507. kfree(sn_controller);
  508. return;
  509. }
  510. void sn_bus_store_sysdata(struct pci_dev *dev)
  511. {
  512. struct sysdata_el *element;
  513. element = kzalloc(sizeof(struct sysdata_el), GFP_KERNEL);
  514. if (!element) {
  515. dev_dbg(dev, "%s: out of memory!\n", __FUNCTION__);
  516. return;
  517. }
  518. element->sysdata = SN_PCIDEV_INFO(dev);
  519. list_add(&element->entry, &sn_sysdata_list);
  520. }
  521. void sn_bus_free_sysdata(void)
  522. {
  523. struct sysdata_el *element;
  524. struct list_head *list, *safe;
  525. list_for_each_safe(list, safe, &sn_sysdata_list) {
  526. element = list_entry(list, struct sysdata_el, entry);
  527. list_del(&element->entry);
  528. list_del(&(((struct pcidev_info *)
  529. (element->sysdata))->pdi_list));
  530. kfree(element->sysdata);
  531. kfree(element);
  532. }
  533. return;
  534. }
  535. /*
  536. * Ugly hack to get PCI setup until we have a proper ACPI namespace.
  537. */
  538. #define PCI_BUSES_TO_SCAN 256
  539. static int __init sn_pci_init(void)
  540. {
  541. int i, j;
  542. struct pci_dev *pci_dev = NULL;
  543. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
  544. return 0;
  545. /*
  546. * prime sn_pci_provider[]. Individial provider init routines will
  547. * override their respective default entries.
  548. */
  549. for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
  550. sn_pci_provider[i] = &sn_pci_default_provider;
  551. pcibr_init_provider();
  552. tioca_init_provider();
  553. tioce_init_provider();
  554. /*
  555. * This is needed to avoid bounce limit checks in the blk layer
  556. */
  557. ia64_max_iommu_merge_mask = ~PAGE_MASK;
  558. sn_fixup_ionodes();
  559. sn_irq_lh_init();
  560. INIT_LIST_HEAD(&sn_sysdata_list);
  561. sn_init_cpei_timer();
  562. #ifdef CONFIG_PROC_FS
  563. register_sn_procfs();
  564. #endif
  565. /* busses are not known yet ... */
  566. for (i = 0; i <= max_segment_number; i++)
  567. for (j = 0; j <= max_pcibus_number; j++)
  568. sn_pci_controller_fixup(i, j, NULL);
  569. /*
  570. * Generic Linux PCI Layer has created the pci_bus and pci_dev
  571. * structures - time for us to add our SN PLatform specific
  572. * information.
  573. */
  574. while ((pci_dev =
  575. pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL)
  576. sn_pci_fixup_slot(pci_dev);
  577. sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
  578. return 0;
  579. }
  580. /*
  581. * hubdev_init_node() - Creates the HUB data structure and link them to it's
  582. * own NODE specific data area.
  583. */
  584. void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
  585. {
  586. struct hubdev_info *hubdev_info;
  587. int size;
  588. pg_data_t *pg;
  589. size = sizeof(struct hubdev_info);
  590. if (node >= num_online_nodes()) /* Headless/memless IO nodes */
  591. pg = NODE_DATA(0);
  592. else
  593. pg = NODE_DATA(node);
  594. hubdev_info = (struct hubdev_info *)alloc_bootmem_node(pg, size);
  595. npda->pdinfo = (void *)hubdev_info;
  596. }
  597. geoid_t
  598. cnodeid_get_geoid(cnodeid_t cnode)
  599. {
  600. struct hubdev_info *hubdev;
  601. hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  602. return hubdev->hdi_geoid;
  603. }
  604. subsys_initcall(sn_pci_init);
  605. EXPORT_SYMBOL(sn_pci_fixup_slot);
  606. EXPORT_SYMBOL(sn_pci_unfixup_slot);
  607. EXPORT_SYMBOL(sn_pci_controller_fixup);
  608. EXPORT_SYMBOL(sn_bus_store_sysdata);
  609. EXPORT_SYMBOL(sn_bus_free_sysdata);