io_common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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) 2006 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <linux/bootmem.h>
  9. #include <linux/export.h>
  10. #include <linux/slab.h>
  11. #include <asm/sn/types.h>
  12. #include <asm/sn/addrs.h>
  13. #include <asm/sn/sn_feature_sets.h>
  14. #include <asm/sn/geo.h>
  15. #include <asm/sn/io.h>
  16. #include <asm/sn/l1.h>
  17. #include <asm/sn/module.h>
  18. #include <asm/sn/pcibr_provider.h>
  19. #include <asm/sn/pcibus_provider_defs.h>
  20. #include <asm/sn/pcidev.h>
  21. #include <asm/sn/simulator.h>
  22. #include <asm/sn/sn_sal.h>
  23. #include <asm/sn/tioca_provider.h>
  24. #include <asm/sn/tioce_provider.h>
  25. #include "xtalk/hubdev.h"
  26. #include "xtalk/xwidgetdev.h"
  27. #include <linux/acpi.h>
  28. #include <asm/sn/sn2/sn_hwperf.h>
  29. #include <asm/sn/acpi.h>
  30. extern void sn_init_cpei_timer(void);
  31. extern void register_sn_procfs(void);
  32. extern void sn_io_acpi_init(void);
  33. extern void sn_io_init(void);
  34. static struct list_head sn_sysdata_list;
  35. /* sysdata list struct */
  36. struct sysdata_el {
  37. struct list_head entry;
  38. void *sysdata;
  39. };
  40. int sn_ioif_inited; /* SN I/O infrastructure initialized? */
  41. int sn_acpi_rev; /* SN ACPI revision */
  42. EXPORT_SYMBOL_GPL(sn_acpi_rev);
  43. struct sn_pcibus_provider *sn_pci_provider[PCIIO_ASIC_MAX_TYPES]; /* indexed by asic type */
  44. /*
  45. * Hooks and struct for unsupported pci providers
  46. */
  47. static dma_addr_t
  48. sn_default_pci_map(struct pci_dev *pdev, unsigned long paddr, size_t size, int type)
  49. {
  50. return 0;
  51. }
  52. static void
  53. sn_default_pci_unmap(struct pci_dev *pdev, dma_addr_t addr, int direction)
  54. {
  55. return;
  56. }
  57. static void *
  58. sn_default_pci_bus_fixup(struct pcibus_bussoft *soft, struct pci_controller *controller)
  59. {
  60. return NULL;
  61. }
  62. static struct sn_pcibus_provider sn_pci_default_provider = {
  63. .dma_map = sn_default_pci_map,
  64. .dma_map_consistent = sn_default_pci_map,
  65. .dma_unmap = sn_default_pci_unmap,
  66. .bus_fixup = sn_default_pci_bus_fixup,
  67. };
  68. /*
  69. * Retrieve the DMA Flush List given nasid, widget, and device.
  70. * This list is needed to implement the WAR - Flush DMA data on PIO Reads.
  71. */
  72. static inline u64
  73. sal_get_device_dmaflush_list(u64 nasid, u64 widget_num, u64 device_num,
  74. u64 address)
  75. {
  76. struct ia64_sal_retval ret_stuff;
  77. ret_stuff.status = 0;
  78. ret_stuff.v0 = 0;
  79. SAL_CALL_NOLOCK(ret_stuff,
  80. (u64) SN_SAL_IOIF_GET_DEVICE_DMAFLUSH_LIST,
  81. (u64) nasid, (u64) widget_num,
  82. (u64) device_num, (u64) address, 0, 0, 0);
  83. return ret_stuff.status;
  84. }
  85. /*
  86. * sn_pcidev_info_get() - Retrieve the pcidev_info struct for the specified
  87. * device.
  88. */
  89. inline struct pcidev_info *
  90. sn_pcidev_info_get(struct pci_dev *dev)
  91. {
  92. struct pcidev_info *pcidev;
  93. list_for_each_entry(pcidev,
  94. &(SN_PLATFORM_DATA(dev)->pcidev_info), pdi_list) {
  95. if (pcidev->pdi_linux_pcidev == dev)
  96. return pcidev;
  97. }
  98. return NULL;
  99. }
  100. /* Older PROM flush WAR
  101. *
  102. * 01/16/06 -- This war will be in place until a new official PROM is released.
  103. * Additionally note that the struct sn_flush_device_war also has to be
  104. * removed from arch/ia64/sn/include/xtalk/hubdev.h
  105. */
  106. static s64 sn_device_fixup_war(u64 nasid, u64 widget, int device,
  107. struct sn_flush_device_common *common)
  108. {
  109. struct sn_flush_device_war *war_list;
  110. struct sn_flush_device_war *dev_entry;
  111. struct ia64_sal_retval isrv = {0,0,0,0};
  112. printk_once(KERN_WARNING
  113. "PROM version < 4.50 -- implementing old PROM flush WAR\n");
  114. war_list = kzalloc(DEV_PER_WIDGET * sizeof(*war_list), GFP_KERNEL);
  115. BUG_ON(!war_list);
  116. SAL_CALL_NOLOCK(isrv, SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
  117. nasid, widget, __pa(war_list), 0, 0, 0 ,0);
  118. if (isrv.status)
  119. panic("sn_device_fixup_war failed: %s\n",
  120. ia64_sal_strerror(isrv.status));
  121. dev_entry = war_list + device;
  122. memcpy(common,dev_entry, sizeof(*common));
  123. kfree(war_list);
  124. return isrv.status;
  125. }
  126. /*
  127. * sn_common_hubdev_init() - This routine is called to initialize the HUB data
  128. * structure for each node in the system.
  129. */
  130. void __init
  131. sn_common_hubdev_init(struct hubdev_info *hubdev)
  132. {
  133. struct sn_flush_device_kernel *sn_flush_device_kernel;
  134. struct sn_flush_device_kernel *dev_entry;
  135. s64 status;
  136. int widget, device, size;
  137. /* Attach the error interrupt handlers */
  138. if (hubdev->hdi_nasid & 1) /* If TIO */
  139. ice_error_init(hubdev);
  140. else
  141. hub_error_init(hubdev);
  142. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
  143. hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
  144. if (!hubdev->hdi_flush_nasid_list.widget_p)
  145. return;
  146. size = (HUB_WIDGET_ID_MAX + 1) *
  147. sizeof(struct sn_flush_device_kernel *);
  148. hubdev->hdi_flush_nasid_list.widget_p =
  149. kzalloc(size, GFP_KERNEL);
  150. BUG_ON(!hubdev->hdi_flush_nasid_list.widget_p);
  151. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
  152. size = DEV_PER_WIDGET *
  153. sizeof(struct sn_flush_device_kernel);
  154. sn_flush_device_kernel = kzalloc(size, GFP_KERNEL);
  155. BUG_ON(!sn_flush_device_kernel);
  156. dev_entry = sn_flush_device_kernel;
  157. for (device = 0; device < DEV_PER_WIDGET;
  158. device++, dev_entry++) {
  159. size = sizeof(struct sn_flush_device_common);
  160. dev_entry->common = kzalloc(size, GFP_KERNEL);
  161. BUG_ON(!dev_entry->common);
  162. if (sn_prom_feature_available(PRF_DEVICE_FLUSH_LIST))
  163. status = sal_get_device_dmaflush_list(
  164. hubdev->hdi_nasid, widget, device,
  165. (u64)(dev_entry->common));
  166. else
  167. status = sn_device_fixup_war(hubdev->hdi_nasid,
  168. widget, device,
  169. dev_entry->common);
  170. if (status != SALRET_OK)
  171. panic("SAL call failed: %s\n",
  172. ia64_sal_strerror(status));
  173. spin_lock_init(&dev_entry->sfdl_flush_lock);
  174. }
  175. if (sn_flush_device_kernel)
  176. hubdev->hdi_flush_nasid_list.widget_p[widget] =
  177. sn_flush_device_kernel;
  178. }
  179. }
  180. void sn_pci_unfixup_slot(struct pci_dev *dev)
  181. {
  182. struct pci_dev *host_pci_dev = SN_PCIDEV_INFO(dev)->host_pci_dev;
  183. sn_irq_unfixup(dev);
  184. pci_dev_put(host_pci_dev);
  185. pci_dev_put(dev);
  186. }
  187. /*
  188. * sn_pci_fixup_slot()
  189. */
  190. void sn_pci_fixup_slot(struct pci_dev *dev, struct pcidev_info *pcidev_info,
  191. struct sn_irq_info *sn_irq_info)
  192. {
  193. int segment = pci_domain_nr(dev->bus);
  194. struct pcibus_bussoft *bs;
  195. struct pci_bus *host_pci_bus;
  196. struct pci_dev *host_pci_dev;
  197. unsigned int bus_no, devfn;
  198. pci_dev_get(dev); /* for the sysdata pointer */
  199. /* Add pcidev_info to list in pci_controller.platform_data */
  200. list_add_tail(&pcidev_info->pdi_list,
  201. &(SN_PLATFORM_DATA(dev->bus)->pcidev_info));
  202. /*
  203. * Using the PROMs values for the PCI host bus, get the Linux
  204. * PCI host_pci_dev struct and set up host bus linkages
  205. */
  206. bus_no = (pcidev_info->pdi_slot_host_handle >> 32) & 0xff;
  207. devfn = pcidev_info->pdi_slot_host_handle & 0xffffffff;
  208. host_pci_bus = pci_find_bus(segment, bus_no);
  209. host_pci_dev = pci_get_slot(host_pci_bus, devfn);
  210. pcidev_info->host_pci_dev = host_pci_dev;
  211. pcidev_info->pdi_linux_pcidev = dev;
  212. pcidev_info->pdi_host_pcidev_info = SN_PCIDEV_INFO(host_pci_dev);
  213. bs = SN_PCIBUS_BUSSOFT(dev->bus);
  214. pcidev_info->pdi_pcibus_info = bs;
  215. if (bs && bs->bs_asic_type < PCIIO_ASIC_MAX_TYPES) {
  216. SN_PCIDEV_BUSPROVIDER(dev) = sn_pci_provider[bs->bs_asic_type];
  217. } else {
  218. SN_PCIDEV_BUSPROVIDER(dev) = &sn_pci_default_provider;
  219. }
  220. /* Only set up IRQ stuff if this device has a host bus context */
  221. if (bs && sn_irq_info->irq_irq) {
  222. pcidev_info->pdi_sn_irq_info = sn_irq_info;
  223. dev->irq = pcidev_info->pdi_sn_irq_info->irq_irq;
  224. sn_irq_fixup(dev, sn_irq_info);
  225. } else {
  226. pcidev_info->pdi_sn_irq_info = NULL;
  227. kfree(sn_irq_info);
  228. }
  229. }
  230. /*
  231. * sn_common_bus_fixup - Perform platform specific bus fixup.
  232. * Execute the ASIC specific fixup routine
  233. * for this bus.
  234. */
  235. void
  236. sn_common_bus_fixup(struct pci_bus *bus,
  237. struct pcibus_bussoft *prom_bussoft_ptr)
  238. {
  239. int cnode;
  240. struct pci_controller *controller;
  241. struct hubdev_info *hubdev_info;
  242. int nasid;
  243. void *provider_soft;
  244. struct sn_pcibus_provider *provider;
  245. struct sn_platform_data *sn_platform_data;
  246. controller = PCI_CONTROLLER(bus);
  247. /*
  248. * Per-provider fixup. Copies the bus soft structure from prom
  249. * to local area and links SN_PCIBUS_BUSSOFT().
  250. */
  251. if (prom_bussoft_ptr->bs_asic_type >= PCIIO_ASIC_MAX_TYPES) {
  252. printk(KERN_WARNING "sn_common_bus_fixup: Unsupported asic type, %d",
  253. prom_bussoft_ptr->bs_asic_type);
  254. return;
  255. }
  256. if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB)
  257. return; /* no further fixup necessary */
  258. provider = sn_pci_provider[prom_bussoft_ptr->bs_asic_type];
  259. if (provider == NULL)
  260. panic("sn_common_bus_fixup: No provider registered for this asic type, %d",
  261. prom_bussoft_ptr->bs_asic_type);
  262. if (provider->bus_fixup)
  263. provider_soft = (*provider->bus_fixup) (prom_bussoft_ptr,
  264. controller);
  265. else
  266. provider_soft = NULL;
  267. /*
  268. * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
  269. * after this point.
  270. */
  271. controller->platform_data = kzalloc(sizeof(struct sn_platform_data),
  272. GFP_KERNEL);
  273. BUG_ON(controller->platform_data == NULL);
  274. sn_platform_data =
  275. (struct sn_platform_data *) controller->platform_data;
  276. sn_platform_data->provider_soft = provider_soft;
  277. INIT_LIST_HEAD(&((struct sn_platform_data *)
  278. controller->platform_data)->pcidev_info);
  279. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
  280. cnode = nasid_to_cnodeid(nasid);
  281. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  282. SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
  283. &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
  284. /*
  285. * If the node information we obtained during the fixup phase is
  286. * invalid then set controller->node to -1 (undetermined)
  287. */
  288. if (controller->node >= num_online_nodes()) {
  289. struct pcibus_bussoft *b = SN_PCIBUS_BUSSOFT(bus);
  290. printk(KERN_WARNING "Device ASIC=%u XID=%u PBUSNUM=%u "
  291. "L_IO=%llx L_MEM=%llx BASE=%llx\n",
  292. b->bs_asic_type, b->bs_xid, b->bs_persist_busnum,
  293. b->bs_legacy_io, b->bs_legacy_mem, b->bs_base);
  294. printk(KERN_WARNING "on node %d but only %d nodes online."
  295. "Association set to undetermined.\n",
  296. controller->node, num_online_nodes());
  297. controller->node = -1;
  298. }
  299. }
  300. void sn_bus_store_sysdata(struct pci_dev *dev)
  301. {
  302. struct sysdata_el *element;
  303. element = kzalloc(sizeof(struct sysdata_el), GFP_KERNEL);
  304. if (!element) {
  305. dev_dbg(&dev->dev, "%s: out of memory!\n", __func__);
  306. return;
  307. }
  308. element->sysdata = SN_PCIDEV_INFO(dev);
  309. list_add(&element->entry, &sn_sysdata_list);
  310. }
  311. void sn_bus_free_sysdata(void)
  312. {
  313. struct sysdata_el *element;
  314. struct list_head *list, *safe;
  315. list_for_each_safe(list, safe, &sn_sysdata_list) {
  316. element = list_entry(list, struct sysdata_el, entry);
  317. list_del(&element->entry);
  318. list_del(&(((struct pcidev_info *)
  319. (element->sysdata))->pdi_list));
  320. kfree(element->sysdata);
  321. kfree(element);
  322. }
  323. return;
  324. }
  325. /*
  326. * hubdev_init_node() - Creates the HUB data structure and link them to it's
  327. * own NODE specific data area.
  328. */
  329. void __init hubdev_init_node(nodepda_t * npda, cnodeid_t node)
  330. {
  331. struct hubdev_info *hubdev_info;
  332. int size;
  333. pg_data_t *pg;
  334. size = sizeof(struct hubdev_info);
  335. if (node >= num_online_nodes()) /* Headless/memless IO nodes */
  336. pg = NODE_DATA(0);
  337. else
  338. pg = NODE_DATA(node);
  339. hubdev_info = (struct hubdev_info *)alloc_bootmem_node(pg, size);
  340. npda->pdinfo = (void *)hubdev_info;
  341. }
  342. geoid_t
  343. cnodeid_get_geoid(cnodeid_t cnode)
  344. {
  345. struct hubdev_info *hubdev;
  346. hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  347. return hubdev->hdi_geoid;
  348. }
  349. void sn_generate_path(struct pci_bus *pci_bus, char *address)
  350. {
  351. nasid_t nasid;
  352. cnodeid_t cnode;
  353. geoid_t geoid;
  354. moduleid_t moduleid;
  355. u16 bricktype;
  356. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(pci_bus)->bs_base);
  357. cnode = nasid_to_cnodeid(nasid);
  358. geoid = cnodeid_get_geoid(cnode);
  359. moduleid = geo_module(geoid);
  360. sprintf(address, "module_%c%c%c%c%.2d",
  361. '0'+RACK_GET_CLASS(MODULE_GET_RACK(moduleid)),
  362. '0'+RACK_GET_GROUP(MODULE_GET_RACK(moduleid)),
  363. '0'+RACK_GET_NUM(MODULE_GET_RACK(moduleid)),
  364. MODULE_GET_BTCHAR(moduleid), MODULE_GET_BPOS(moduleid));
  365. /* Tollhouse requires slot id to be displayed */
  366. bricktype = MODULE_GET_BTYPE(moduleid);
  367. if ((bricktype == L1_BRICKTYPE_191010) ||
  368. (bricktype == L1_BRICKTYPE_1932))
  369. sprintf(address + strlen(address), "^%d",
  370. geo_slot(geoid));
  371. }
  372. void __devinit
  373. sn_pci_fixup_bus(struct pci_bus *bus)
  374. {
  375. if (SN_ACPI_BASE_SUPPORT())
  376. sn_acpi_bus_fixup(bus);
  377. else
  378. sn_bus_fixup(bus);
  379. }
  380. /*
  381. * sn_io_early_init - Perform early IO (and some non-IO) initialization.
  382. * In particular, setup the sn_pci_provider[] array.
  383. * This needs to be done prior to any bus scanning
  384. * (acpi_scan_init()) in the ACPI case, as the SN
  385. * bus fixup code will reference the array.
  386. */
  387. static int __init
  388. sn_io_early_init(void)
  389. {
  390. int i;
  391. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
  392. return 0;
  393. /* we set the acpi revision to that of the DSDT table OEM rev. */
  394. {
  395. struct acpi_table_header *header = NULL;
  396. acpi_get_table(ACPI_SIG_DSDT, 1, &header);
  397. BUG_ON(header == NULL);
  398. sn_acpi_rev = header->oem_revision;
  399. }
  400. /*
  401. * prime sn_pci_provider[]. Individual provider init routines will
  402. * override their respective default entries.
  403. */
  404. for (i = 0; i < PCIIO_ASIC_MAX_TYPES; i++)
  405. sn_pci_provider[i] = &sn_pci_default_provider;
  406. pcibr_init_provider();
  407. tioca_init_provider();
  408. tioce_init_provider();
  409. /*
  410. * This is needed to avoid bounce limit checks in the blk layer
  411. */
  412. ia64_max_iommu_merge_mask = ~PAGE_MASK;
  413. sn_irq_lh_init();
  414. INIT_LIST_HEAD(&sn_sysdata_list);
  415. sn_init_cpei_timer();
  416. #ifdef CONFIG_PROC_FS
  417. register_sn_procfs();
  418. #endif
  419. {
  420. struct acpi_table_header *header;
  421. (void)acpi_get_table(ACPI_SIG_DSDT, 1, &header);
  422. printk(KERN_INFO "ACPI DSDT OEM Rev 0x%x\n",
  423. header->oem_revision);
  424. }
  425. if (SN_ACPI_BASE_SUPPORT())
  426. sn_io_acpi_init();
  427. else
  428. sn_io_init();
  429. return 0;
  430. }
  431. arch_initcall(sn_io_early_init);
  432. /*
  433. * sn_io_late_init() - Perform any final platform specific IO initialization.
  434. */
  435. int __init
  436. sn_io_late_init(void)
  437. {
  438. struct pci_bus *bus;
  439. struct pcibus_bussoft *bussoft;
  440. cnodeid_t cnode;
  441. nasid_t nasid;
  442. cnodeid_t near_cnode;
  443. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_FAKE_PROM())
  444. return 0;
  445. /*
  446. * Setup closest node in pci_controller->node for
  447. * PIC, TIOCP, TIOCE (TIOCA does it during bus fixup using
  448. * info from the PROM).
  449. */
  450. bus = NULL;
  451. while ((bus = pci_find_next_bus(bus)) != NULL) {
  452. bussoft = SN_PCIBUS_BUSSOFT(bus);
  453. nasid = NASID_GET(bussoft->bs_base);
  454. cnode = nasid_to_cnodeid(nasid);
  455. if ((bussoft->bs_asic_type == PCIIO_ASIC_TYPE_TIOCP) ||
  456. (bussoft->bs_asic_type == PCIIO_ASIC_TYPE_TIOCE) ||
  457. (bussoft->bs_asic_type == PCIIO_ASIC_TYPE_PIC)) {
  458. /* PCI Bridge: find nearest node with CPUs */
  459. int e = sn_hwperf_get_nearest_node(cnode, NULL,
  460. &near_cnode);
  461. if (e < 0) {
  462. near_cnode = (cnodeid_t)-1; /* use any node */
  463. printk(KERN_WARNING "sn_io_late_init: failed "
  464. "to find near node with CPUs for "
  465. "node %d, err=%d\n", cnode, e);
  466. }
  467. PCI_CONTROLLER(bus)->node = near_cnode;
  468. }
  469. }
  470. sn_ioif_inited = 1; /* SN I/O infrastructure now initialized */
  471. return 0;
  472. }
  473. fs_initcall(sn_io_late_init);
  474. EXPORT_SYMBOL(sn_pci_unfixup_slot);
  475. EXPORT_SYMBOL(sn_bus_store_sysdata);
  476. EXPORT_SYMBOL(sn_bus_free_sysdata);
  477. EXPORT_SYMBOL(sn_generate_path);