/arch/ia64/sn/kernel/io_init.c

https://bitbucket.org/evzijst/gittest · C · 411 lines · 269 code · 72 blank · 70 comment · 30 complexity · 17d0f44111abce2c281899922dc0ac28 MD5 · raw file

  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/sn_sal.h>
  12. #include <asm/sn/addrs.h>
  13. #include "pci/pcibus_provider_defs.h"
  14. #include "pci/pcidev.h"
  15. #include "pci/pcibr_provider.h"
  16. #include "xtalk/xwidgetdev.h"
  17. #include <asm/sn/geo.h>
  18. #include "xtalk/hubdev.h"
  19. #include <asm/sn/io.h>
  20. #include <asm/sn/simulator.h>
  21. char master_baseio_wid;
  22. nasid_t master_nasid = INVALID_NASID; /* Partition Master */
  23. struct slab_info {
  24. struct hubdev_info hubdev;
  25. };
  26. struct brick {
  27. moduleid_t id; /* Module ID of this module */
  28. struct slab_info slab_info[MAX_SLABS + 1];
  29. };
  30. int sn_ioif_inited = 0; /* SN I/O infrastructure initialized? */
  31. /*
  32. * Retrieve the DMA Flush List given nasid. This list is needed
  33. * to implement the WAR - Flush DMA data on PIO Reads.
  34. */
  35. static inline uint64_t
  36. sal_get_widget_dmaflush_list(u64 nasid, u64 widget_num, u64 address)
  37. {
  38. struct ia64_sal_retval ret_stuff;
  39. ret_stuff.status = 0;
  40. ret_stuff.v0 = 0;
  41. SAL_CALL_NOLOCK(ret_stuff,
  42. (u64) SN_SAL_IOIF_GET_WIDGET_DMAFLUSH_LIST,
  43. (u64) nasid, (u64) widget_num, (u64) address, 0, 0, 0,
  44. 0);
  45. return ret_stuff.v0;
  46. }
  47. /*
  48. * Retrieve the hub device info structure for the given nasid.
  49. */
  50. static inline uint64_t sal_get_hubdev_info(u64 handle, u64 address)
  51. {
  52. struct ia64_sal_retval ret_stuff;
  53. ret_stuff.status = 0;
  54. ret_stuff.v0 = 0;
  55. SAL_CALL_NOLOCK(ret_stuff,
  56. (u64) SN_SAL_IOIF_GET_HUBDEV_INFO,
  57. (u64) handle, (u64) address, 0, 0, 0, 0, 0);
  58. return ret_stuff.v0;
  59. }
  60. /*
  61. * Retrieve the pci bus information given the bus number.
  62. */
  63. static inline uint64_t sal_get_pcibus_info(u64 segment, u64 busnum, u64 address)
  64. {
  65. struct ia64_sal_retval ret_stuff;
  66. ret_stuff.status = 0;
  67. ret_stuff.v0 = 0;
  68. SAL_CALL_NOLOCK(ret_stuff,
  69. (u64) SN_SAL_IOIF_GET_PCIBUS_INFO,
  70. (u64) segment, (u64) busnum, (u64) address, 0, 0, 0, 0);
  71. return ret_stuff.v0;
  72. }
  73. /*
  74. * Retrieve the pci device information given the bus and device|function number.
  75. */
  76. static inline uint64_t
  77. sal_get_pcidev_info(u64 segment, u64 bus_number, u64 devfn, u64 pci_dev,
  78. u64 sn_irq_info)
  79. {
  80. struct ia64_sal_retval ret_stuff;
  81. ret_stuff.status = 0;
  82. ret_stuff.v0 = 0;
  83. SAL_CALL_NOLOCK(ret_stuff,
  84. (u64) SN_SAL_IOIF_GET_PCIDEV_INFO,
  85. (u64) segment, (u64) bus_number, (u64) devfn,
  86. (u64) pci_dev,
  87. sn_irq_info, 0, 0);
  88. return ret_stuff.v0;
  89. }
  90. /*
  91. * sn_alloc_pci_sysdata() - This routine allocates a pci controller
  92. * which is expected as the pci_dev and pci_bus sysdata by the Linux
  93. * PCI infrastructure.
  94. */
  95. static inline struct pci_controller *sn_alloc_pci_sysdata(void)
  96. {
  97. struct pci_controller *pci_sysdata;
  98. pci_sysdata = kmalloc(sizeof(*pci_sysdata), GFP_KERNEL);
  99. if (!pci_sysdata)
  100. BUG();
  101. memset(pci_sysdata, 0, sizeof(*pci_sysdata));
  102. return pci_sysdata;
  103. }
  104. /*
  105. * sn_fixup_ionodes() - This routine initializes the HUB data strcuture for
  106. * each node in the system.
  107. */
  108. static void sn_fixup_ionodes(void)
  109. {
  110. struct sn_flush_device_list *sn_flush_device_list;
  111. struct hubdev_info *hubdev;
  112. uint64_t status;
  113. uint64_t nasid;
  114. int i, widget;
  115. for (i = 0; i < numionodes; i++) {
  116. hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
  117. nasid = cnodeid_to_nasid(i);
  118. status = sal_get_hubdev_info(nasid, (uint64_t) __pa(hubdev));
  119. if (status)
  120. continue;
  121. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++)
  122. hubdev->hdi_xwidget_info[widget].xwi_hubinfo = hubdev;
  123. if (!hubdev->hdi_flush_nasid_list.widget_p)
  124. continue;
  125. hubdev->hdi_flush_nasid_list.widget_p =
  126. kmalloc((HUB_WIDGET_ID_MAX + 1) *
  127. sizeof(struct sn_flush_device_list *), GFP_KERNEL);
  128. memset(hubdev->hdi_flush_nasid_list.widget_p, 0x0,
  129. (HUB_WIDGET_ID_MAX + 1) *
  130. sizeof(struct sn_flush_device_list *));
  131. for (widget = 0; widget <= HUB_WIDGET_ID_MAX; widget++) {
  132. sn_flush_device_list = kmalloc(DEV_PER_WIDGET *
  133. sizeof(struct
  134. sn_flush_device_list),
  135. GFP_KERNEL);
  136. memset(sn_flush_device_list, 0x0,
  137. DEV_PER_WIDGET *
  138. sizeof(struct sn_flush_device_list));
  139. status =
  140. sal_get_widget_dmaflush_list(nasid, widget,
  141. (uint64_t)
  142. __pa
  143. (sn_flush_device_list));
  144. if (status) {
  145. kfree(sn_flush_device_list);
  146. continue;
  147. }
  148. hubdev->hdi_flush_nasid_list.widget_p[widget] =
  149. sn_flush_device_list;
  150. }
  151. if (!(i & 1))
  152. hub_error_init(hubdev);
  153. else
  154. ice_error_init(hubdev);
  155. }
  156. }
  157. /*
  158. * sn_pci_fixup_slot() - This routine sets up a slot's resources
  159. * consistent with the Linux PCI abstraction layer. Resources acquired
  160. * from our PCI provider include PIO maps to BAR space and interrupt
  161. * objects.
  162. */
  163. static void sn_pci_fixup_slot(struct pci_dev *dev)
  164. {
  165. int idx;
  166. int segment = 0;
  167. uint64_t size;
  168. struct sn_irq_info *sn_irq_info;
  169. struct pci_dev *host_pci_dev;
  170. int status = 0;
  171. dev->sysdata = kmalloc(sizeof(struct pcidev_info), GFP_KERNEL);
  172. if (SN_PCIDEV_INFO(dev) <= 0)
  173. BUG(); /* Cannot afford to run out of memory */
  174. memset(SN_PCIDEV_INFO(dev), 0, sizeof(struct pcidev_info));
  175. sn_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  176. if (sn_irq_info <= 0)
  177. BUG(); /* Cannot afford to run out of memory */
  178. memset(sn_irq_info, 0, sizeof(struct sn_irq_info));
  179. /* Call to retrieve pci device information needed by kernel. */
  180. status = sal_get_pcidev_info((u64) segment, (u64) dev->bus->number,
  181. dev->devfn,
  182. (u64) __pa(SN_PCIDEV_INFO(dev)),
  183. (u64) __pa(sn_irq_info));
  184. if (status)
  185. BUG(); /* Cannot get platform pci device information information */
  186. /* Copy over PIO Mapped Addresses */
  187. for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
  188. unsigned long start, end, addr;
  189. if (!SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx])
  190. continue;
  191. start = dev->resource[idx].start;
  192. end = dev->resource[idx].end;
  193. size = end - start;
  194. addr = SN_PCIDEV_INFO(dev)->pdi_pio_mapped_addr[idx];
  195. addr = ((addr << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  196. dev->resource[idx].start = addr;
  197. dev->resource[idx].end = addr + size;
  198. if (dev->resource[idx].flags & IORESOURCE_IO)
  199. dev->resource[idx].parent = &ioport_resource;
  200. else
  201. dev->resource[idx].parent = &iomem_resource;
  202. }
  203. /* set up host bus linkages */
  204. host_pci_dev =
  205. pci_find_slot(SN_PCIDEV_INFO(dev)->pdi_slot_host_handle >> 32,
  206. SN_PCIDEV_INFO(dev)->
  207. pdi_slot_host_handle & 0xffffffff);
  208. SN_PCIDEV_INFO(dev)->pdi_host_pcidev_info =
  209. SN_PCIDEV_INFO(host_pci_dev);
  210. SN_PCIDEV_INFO(dev)->pdi_linux_pcidev = dev;
  211. SN_PCIDEV_INFO(dev)->pdi_pcibus_info = SN_PCIBUS_BUSSOFT(dev->bus);
  212. /* Only set up IRQ stuff if this device has a host bus context */
  213. if (SN_PCIDEV_BUSSOFT(dev) && sn_irq_info->irq_irq) {
  214. SN_PCIDEV_INFO(dev)->pdi_sn_irq_info = sn_irq_info;
  215. dev->irq = SN_PCIDEV_INFO(dev)->pdi_sn_irq_info->irq_irq;
  216. sn_irq_fixup(dev, sn_irq_info);
  217. }
  218. }
  219. /*
  220. * sn_pci_controller_fixup() - This routine sets up a bus's resources
  221. * consistent with the Linux PCI abstraction layer.
  222. */
  223. static void sn_pci_controller_fixup(int segment, int busnum)
  224. {
  225. int status = 0;
  226. int nasid, cnode;
  227. struct pci_bus *bus;
  228. struct pci_controller *controller;
  229. struct pcibus_bussoft *prom_bussoft_ptr;
  230. struct hubdev_info *hubdev_info;
  231. void *provider_soft;
  232. status =
  233. sal_get_pcibus_info((u64) segment, (u64) busnum,
  234. (u64) ia64_tpa(&prom_bussoft_ptr));
  235. if (status > 0) {
  236. return; /* bus # does not exist */
  237. }
  238. prom_bussoft_ptr = __va(prom_bussoft_ptr);
  239. controller = sn_alloc_pci_sysdata();
  240. /* controller non-zero is BUG'd in sn_alloc_pci_sysdata */
  241. bus = pci_scan_bus(busnum, &pci_root_ops, controller);
  242. if (bus == NULL) {
  243. return; /* error, or bus already scanned */
  244. }
  245. /*
  246. * Per-provider fixup. Copies the contents from prom to local
  247. * area and links SN_PCIBUS_BUSSOFT().
  248. *
  249. * Note: Provider is responsible for ensuring that prom_bussoft_ptr
  250. * represents an asic-type that it can handle.
  251. */
  252. if (prom_bussoft_ptr->bs_asic_type == PCIIO_ASIC_TYPE_PPB) {
  253. return; /* no further fixup necessary */
  254. }
  255. provider_soft = pcibr_bus_fixup(prom_bussoft_ptr);
  256. if (provider_soft == NULL) {
  257. return; /* fixup failed or not applicable */
  258. }
  259. /*
  260. * Generic bus fixup goes here. Don't reference prom_bussoft_ptr
  261. * after this point.
  262. */
  263. bus->sysdata = controller;
  264. PCI_CONTROLLER(bus)->platform_data = provider_soft;
  265. nasid = NASID_GET(SN_PCIBUS_BUSSOFT(bus)->bs_base);
  266. cnode = nasid_to_cnodeid(nasid);
  267. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  268. SN_PCIBUS_BUSSOFT(bus)->bs_xwidget_info =
  269. &(hubdev_info->hdi_xwidget_info[SN_PCIBUS_BUSSOFT(bus)->bs_xid]);
  270. }
  271. /*
  272. * Ugly hack to get PCI setup until we have a proper ACPI namespace.
  273. */
  274. #define PCI_BUSES_TO_SCAN 256
  275. static int __init sn_pci_init(void)
  276. {
  277. int i = 0;
  278. struct pci_dev *pci_dev = NULL;
  279. extern void sn_init_cpei_timer(void);
  280. #ifdef CONFIG_PROC_FS
  281. extern void register_sn_procfs(void);
  282. #endif
  283. if (!ia64_platform_is("sn2") || IS_RUNNING_ON_SIMULATOR())
  284. return 0;
  285. /*
  286. * This is needed to avoid bounce limit checks in the blk layer
  287. */
  288. ia64_max_iommu_merge_mask = ~PAGE_MASK;
  289. sn_fixup_ionodes();
  290. sn_irq = kmalloc(sizeof(struct sn_irq_info *) * NR_IRQS, GFP_KERNEL);
  291. if (sn_irq <= 0)
  292. BUG(); /* Canno afford to run out of memory. */
  293. memset(sn_irq, 0, sizeof(struct sn_irq_info *) * NR_IRQS);
  294. sn_init_cpei_timer();
  295. #ifdef CONFIG_PROC_FS
  296. register_sn_procfs();
  297. #endif
  298. for (i = 0; i < PCI_BUSES_TO_SCAN; i++) {
  299. sn_pci_controller_fixup(0, i);
  300. }
  301. /*
  302. * Generic Linux PCI Layer has created the pci_bus and pci_dev
  303. * structures - time for us to add our SN PLatform specific
  304. * information.
  305. */
  306. while ((pci_dev =
  307. pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
  308. sn_pci_fixup_slot(pci_dev);
  309. }
  310. sn_ioif_inited = 1; /* sn I/O infrastructure now initialized */
  311. return 0;
  312. }
  313. /*
  314. * hubdev_init_node() - Creates the HUB data structure and link them to it's
  315. * own NODE specific data area.
  316. */
  317. void hubdev_init_node(nodepda_t * npda, cnodeid_t node)
  318. {
  319. struct hubdev_info *hubdev_info;
  320. if (node >= num_online_nodes()) /* Headless/memless IO nodes */
  321. hubdev_info =
  322. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(0),
  323. sizeof(struct
  324. hubdev_info));
  325. else
  326. hubdev_info =
  327. (struct hubdev_info *)alloc_bootmem_node(NODE_DATA(node),
  328. sizeof(struct
  329. hubdev_info));
  330. npda->pdinfo = (void *)hubdev_info;
  331. }
  332. geoid_t
  333. cnodeid_get_geoid(cnodeid_t cnode)
  334. {
  335. struct hubdev_info *hubdev;
  336. hubdev = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  337. return hubdev->hdi_geoid;
  338. }
  339. subsys_initcall(sn_pci_init);