io_common.c 15 KB

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