io_init.c 20 KB

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