tioca_provider.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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) 2003-2005 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. #include <linux/types.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/pci.h>
  11. #include <asm/sn/sn_sal.h>
  12. #include <asm/sn/addrs.h>
  13. #include <asm/sn/io.h>
  14. #include <asm/sn/pcidev.h>
  15. #include <asm/sn/pcibus_provider_defs.h>
  16. #include <asm/sn/tioca_provider.h>
  17. u32 tioca_gart_found;
  18. EXPORT_SYMBOL(tioca_gart_found); /* used by agp-sgi */
  19. LIST_HEAD(tioca_list);
  20. EXPORT_SYMBOL(tioca_list); /* used by agp-sgi */
  21. static int tioca_gart_init(struct tioca_kernel *);
  22. /**
  23. * tioca_gart_init - Initialize SGI TIOCA GART
  24. * @tioca_common: ptr to common prom/kernel struct identifying the
  25. *
  26. * If the indicated tioca has devices present, initialize its associated
  27. * GART MMR's and kernel memory.
  28. */
  29. static int
  30. tioca_gart_init(struct tioca_kernel *tioca_kern)
  31. {
  32. u64 ap_reg;
  33. u64 offset;
  34. struct page *tmp;
  35. struct tioca_common *tioca_common;
  36. struct tioca __iomem *ca_base;
  37. tioca_common = tioca_kern->ca_common;
  38. ca_base = (struct tioca __iomem *)tioca_common->ca_common.bs_base;
  39. if (list_empty(tioca_kern->ca_devices))
  40. return 0;
  41. ap_reg = 0;
  42. /*
  43. * Validate aperature size
  44. */
  45. switch (CA_APERATURE_SIZE >> 20) {
  46. case 4:
  47. ap_reg |= (0x3ff << CA_GART_AP_SIZE_SHFT); /* 4MB */
  48. break;
  49. case 8:
  50. ap_reg |= (0x3fe << CA_GART_AP_SIZE_SHFT); /* 8MB */
  51. break;
  52. case 16:
  53. ap_reg |= (0x3fc << CA_GART_AP_SIZE_SHFT); /* 16MB */
  54. break;
  55. case 32:
  56. ap_reg |= (0x3f8 << CA_GART_AP_SIZE_SHFT); /* 32 MB */
  57. break;
  58. case 64:
  59. ap_reg |= (0x3f0 << CA_GART_AP_SIZE_SHFT); /* 64 MB */
  60. break;
  61. case 128:
  62. ap_reg |= (0x3e0 << CA_GART_AP_SIZE_SHFT); /* 128 MB */
  63. break;
  64. case 256:
  65. ap_reg |= (0x3c0 << CA_GART_AP_SIZE_SHFT); /* 256 MB */
  66. break;
  67. case 512:
  68. ap_reg |= (0x380 << CA_GART_AP_SIZE_SHFT); /* 512 MB */
  69. break;
  70. case 1024:
  71. ap_reg |= (0x300 << CA_GART_AP_SIZE_SHFT); /* 1GB */
  72. break;
  73. case 2048:
  74. ap_reg |= (0x200 << CA_GART_AP_SIZE_SHFT); /* 2GB */
  75. break;
  76. case 4096:
  77. ap_reg |= (0x000 << CA_GART_AP_SIZE_SHFT); /* 4 GB */
  78. break;
  79. default:
  80. printk(KERN_ERR "%s: Invalid CA_APERATURE_SIZE "
  81. "0x%lx\n", __FUNCTION__, (ulong) CA_APERATURE_SIZE);
  82. return -1;
  83. }
  84. /*
  85. * Set up other aperature parameters
  86. */
  87. if (PAGE_SIZE >= 16384) {
  88. tioca_kern->ca_ap_pagesize = 16384;
  89. ap_reg |= CA_GART_PAGE_SIZE;
  90. } else {
  91. tioca_kern->ca_ap_pagesize = 4096;
  92. }
  93. tioca_kern->ca_ap_size = CA_APERATURE_SIZE;
  94. tioca_kern->ca_ap_bus_base = CA_APERATURE_BASE;
  95. tioca_kern->ca_gart_entries =
  96. tioca_kern->ca_ap_size / tioca_kern->ca_ap_pagesize;
  97. ap_reg |= (CA_GART_AP_ENB_AGP | CA_GART_AP_ENB_PCI);
  98. ap_reg |= tioca_kern->ca_ap_bus_base;
  99. /*
  100. * Allocate and set up the GART
  101. */
  102. tioca_kern->ca_gart_size = tioca_kern->ca_gart_entries * sizeof(u64);
  103. tmp =
  104. alloc_pages_node(tioca_kern->ca_closest_node,
  105. GFP_KERNEL | __GFP_ZERO,
  106. get_order(tioca_kern->ca_gart_size));
  107. if (!tmp) {
  108. printk(KERN_ERR "%s: Could not allocate "
  109. "%lu bytes (order %d) for GART\n",
  110. __FUNCTION__,
  111. tioca_kern->ca_gart_size,
  112. get_order(tioca_kern->ca_gart_size));
  113. return -ENOMEM;
  114. }
  115. tioca_kern->ca_gart = page_address(tmp);
  116. tioca_kern->ca_gart_coretalk_addr =
  117. PHYS_TO_TIODMA(virt_to_phys(tioca_kern->ca_gart));
  118. /*
  119. * Compute PCI/AGP convenience fields
  120. */
  121. offset = CA_PCI32_MAPPED_BASE - CA_APERATURE_BASE;
  122. tioca_kern->ca_pciap_base = CA_PCI32_MAPPED_BASE;
  123. tioca_kern->ca_pciap_size = CA_PCI32_MAPPED_SIZE;
  124. tioca_kern->ca_pcigart_start = offset / tioca_kern->ca_ap_pagesize;
  125. tioca_kern->ca_pcigart_base =
  126. tioca_kern->ca_gart_coretalk_addr + offset;
  127. tioca_kern->ca_pcigart =
  128. &tioca_kern->ca_gart[tioca_kern->ca_pcigart_start];
  129. tioca_kern->ca_pcigart_entries =
  130. tioca_kern->ca_pciap_size / tioca_kern->ca_ap_pagesize;
  131. tioca_kern->ca_pcigart_pagemap =
  132. kzalloc(tioca_kern->ca_pcigart_entries / 8, GFP_KERNEL);
  133. if (!tioca_kern->ca_pcigart_pagemap) {
  134. free_pages((unsigned long)tioca_kern->ca_gart,
  135. get_order(tioca_kern->ca_gart_size));
  136. return -1;
  137. }
  138. offset = CA_AGP_MAPPED_BASE - CA_APERATURE_BASE;
  139. tioca_kern->ca_gfxap_base = CA_AGP_MAPPED_BASE;
  140. tioca_kern->ca_gfxap_size = CA_AGP_MAPPED_SIZE;
  141. tioca_kern->ca_gfxgart_start = offset / tioca_kern->ca_ap_pagesize;
  142. tioca_kern->ca_gfxgart_base =
  143. tioca_kern->ca_gart_coretalk_addr + offset;
  144. tioca_kern->ca_gfxgart =
  145. &tioca_kern->ca_gart[tioca_kern->ca_gfxgart_start];
  146. tioca_kern->ca_gfxgart_entries =
  147. tioca_kern->ca_gfxap_size / tioca_kern->ca_ap_pagesize;
  148. /*
  149. * various control settings:
  150. * use agp op-combining
  151. * use GET semantics to fetch memory
  152. * participate in coherency domain
  153. * DISABLE GART PREFETCHING due to hw bug tracked in SGI PV930029
  154. */
  155. __sn_setq_relaxed(&ca_base->ca_control1,
  156. CA_AGPDMA_OP_ENB_COMBDELAY); /* PV895469 ? */
  157. __sn_clrq_relaxed(&ca_base->ca_control2, CA_GART_MEM_PARAM);
  158. __sn_setq_relaxed(&ca_base->ca_control2,
  159. (0x2ull << CA_GART_MEM_PARAM_SHFT));
  160. tioca_kern->ca_gart_iscoherent = 1;
  161. __sn_clrq_relaxed(&ca_base->ca_control2,
  162. (CA_GART_WR_PREFETCH_ENB | CA_GART_RD_PREFETCH_ENB));
  163. /*
  164. * Unmask GART fetch error interrupts. Clear residual errors first.
  165. */
  166. writeq(CA_GART_FETCH_ERR, &ca_base->ca_int_status_alias);
  167. writeq(CA_GART_FETCH_ERR, &ca_base->ca_mult_error_alias);
  168. __sn_clrq_relaxed(&ca_base->ca_int_mask, CA_GART_FETCH_ERR);
  169. /*
  170. * Program the aperature and gart registers in TIOCA
  171. */
  172. writeq(ap_reg, &ca_base->ca_gart_aperature);
  173. writeq(tioca_kern->ca_gart_coretalk_addr|1, &ca_base->ca_gart_ptr_table);
  174. return 0;
  175. }
  176. /**
  177. * tioca_fastwrite_enable - enable AGP FW for a tioca and its functions
  178. * @tioca_kernel: structure representing the CA
  179. *
  180. * Given a CA, scan all attached functions making sure they all support
  181. * FastWrite. If so, enable FastWrite for all functions and the CA itself.
  182. */
  183. void
  184. tioca_fastwrite_enable(struct tioca_kernel *tioca_kern)
  185. {
  186. int cap_ptr;
  187. u32 reg;
  188. struct tioca __iomem *tioca_base;
  189. struct pci_dev *pdev;
  190. struct tioca_common *common;
  191. common = tioca_kern->ca_common;
  192. /*
  193. * Scan all vga controllers on this bus making sure they all
  194. * suport FW. If not, return.
  195. */
  196. list_for_each_entry(pdev, tioca_kern->ca_devices, bus_list) {
  197. if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8))
  198. continue;
  199. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  200. if (!cap_ptr)
  201. return; /* no AGP CAP means no FW */
  202. pci_read_config_dword(pdev, cap_ptr + PCI_AGP_STATUS, &reg);
  203. if (!(reg & PCI_AGP_STATUS_FW))
  204. return; /* function doesn't support FW */
  205. }
  206. /*
  207. * Set fw for all vga fn's
  208. */
  209. list_for_each_entry(pdev, tioca_kern->ca_devices, bus_list) {
  210. if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8))
  211. continue;
  212. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  213. pci_read_config_dword(pdev, cap_ptr + PCI_AGP_COMMAND, &reg);
  214. reg |= PCI_AGP_COMMAND_FW;
  215. pci_write_config_dword(pdev, cap_ptr + PCI_AGP_COMMAND, reg);
  216. }
  217. /*
  218. * Set ca's fw to match
  219. */
  220. tioca_base = (struct tioca __iomem*)common->ca_common.bs_base;
  221. __sn_setq_relaxed(&tioca_base->ca_control1, CA_AGP_FW_ENABLE);
  222. }
  223. EXPORT_SYMBOL(tioca_fastwrite_enable); /* used by agp-sgi */
  224. /**
  225. * tioca_dma_d64 - create a DMA mapping using 64-bit direct mode
  226. * @paddr: system physical address
  227. *
  228. * Map @paddr into 64-bit CA bus space. No device context is necessary.
  229. * Bits 53:0 come from the coretalk address. We just need to mask in the
  230. * following optional bits of the 64-bit pci address:
  231. *
  232. * 63:60 - Coretalk Packet Type - 0x1 for Mem Get/Put (coherent)
  233. * 0x2 for PIO (non-coherent)
  234. * We will always use 0x1
  235. * 55:55 - Swap bytes Currently unused
  236. */
  237. static u64
  238. tioca_dma_d64(unsigned long paddr)
  239. {
  240. dma_addr_t bus_addr;
  241. bus_addr = PHYS_TO_TIODMA(paddr);
  242. BUG_ON(!bus_addr);
  243. BUG_ON(bus_addr >> 54);
  244. /* Set upper nibble to Cache Coherent Memory op */
  245. bus_addr |= (1UL << 60);
  246. return bus_addr;
  247. }
  248. /**
  249. * tioca_dma_d48 - create a DMA mapping using 48-bit direct mode
  250. * @pdev: linux pci_dev representing the function
  251. * @paddr: system physical address
  252. *
  253. * Map @paddr into 64-bit bus space of the CA associated with @pcidev_info.
  254. *
  255. * The CA agp 48 bit direct address falls out as follows:
  256. *
  257. * When direct mapping AGP addresses, the 48 bit AGP address is
  258. * constructed as follows:
  259. *
  260. * [47:40] - Low 8 bits of the page Node ID extracted from coretalk
  261. * address [47:40]. The upper 8 node bits are fixed
  262. * and come from the xxx register bits [5:0]
  263. * [39:38] - Chiplet ID extracted from coretalk address [39:38]
  264. * [37:00] - node offset extracted from coretalk address [37:00]
  265. *
  266. * Since the node id in general will be non-zero, and the chiplet id
  267. * will always be non-zero, it follows that the device must support
  268. * a dma mask of at least 0xffffffffff (40 bits) to target node 0
  269. * and in general should be 0xffffffffffff (48 bits) to target nodes
  270. * up to 255. Nodes above 255 need the support of the xxx register,
  271. * and so a given CA can only directly target nodes in the range
  272. * xxx - xxx+255.
  273. */
  274. static u64
  275. tioca_dma_d48(struct pci_dev *pdev, u64 paddr)
  276. {
  277. struct tioca_common *tioca_common;
  278. struct tioca __iomem *ca_base;
  279. u64 ct_addr;
  280. dma_addr_t bus_addr;
  281. u32 node_upper;
  282. u64 agp_dma_extn;
  283. struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(pdev);
  284. tioca_common = (struct tioca_common *)pcidev_info->pdi_pcibus_info;
  285. ca_base = (struct tioca __iomem *)tioca_common->ca_common.bs_base;
  286. ct_addr = PHYS_TO_TIODMA(paddr);
  287. if (!ct_addr)
  288. return 0;
  289. bus_addr = (dma_addr_t) (ct_addr & 0xffffffffffffUL);
  290. node_upper = ct_addr >> 48;
  291. if (node_upper > 64) {
  292. printk(KERN_ERR "%s: coretalk addr 0x%p node id out "
  293. "of range\n", __FUNCTION__, (void *)ct_addr);
  294. return 0;
  295. }
  296. agp_dma_extn = __sn_readq_relaxed(&ca_base->ca_agp_dma_addr_extn);
  297. if (node_upper != (agp_dma_extn >> CA_AGP_DMA_NODE_ID_SHFT)) {
  298. printk(KERN_ERR "%s: coretalk upper node (%u) "
  299. "mismatch with ca_agp_dma_addr_extn (%lu)\n",
  300. __FUNCTION__,
  301. node_upper, (agp_dma_extn >> CA_AGP_DMA_NODE_ID_SHFT));
  302. return 0;
  303. }
  304. return bus_addr;
  305. }
  306. /**
  307. * tioca_dma_mapped - create a DMA mapping using a CA GART
  308. * @pdev: linux pci_dev representing the function
  309. * @paddr: host physical address to map
  310. * @req_size: len (bytes) to map
  311. *
  312. * Map @paddr into CA address space using the GART mechanism. The mapped
  313. * dma_addr_t is guarenteed to be contiguous in CA bus space.
  314. */
  315. static dma_addr_t
  316. tioca_dma_mapped(struct pci_dev *pdev, u64 paddr, size_t req_size)
  317. {
  318. int i, ps, ps_shift, entry, entries, mapsize, last_entry;
  319. u64 xio_addr, end_xio_addr;
  320. struct tioca_common *tioca_common;
  321. struct tioca_kernel *tioca_kern;
  322. dma_addr_t bus_addr = 0;
  323. struct tioca_dmamap *ca_dmamap;
  324. void *map;
  325. unsigned long flags;
  326. struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(pdev);
  327. tioca_common = (struct tioca_common *)pcidev_info->pdi_pcibus_info;
  328. tioca_kern = (struct tioca_kernel *)tioca_common->ca_kernel_private;
  329. xio_addr = PHYS_TO_TIODMA(paddr);
  330. if (!xio_addr)
  331. return 0;
  332. spin_lock_irqsave(&tioca_kern->ca_lock, flags);
  333. /*
  334. * allocate a map struct
  335. */
  336. ca_dmamap = kzalloc(sizeof(struct tioca_dmamap), GFP_ATOMIC);
  337. if (!ca_dmamap)
  338. goto map_return;
  339. /*
  340. * Locate free entries that can hold req_size. Account for
  341. * unaligned start/length when allocating.
  342. */
  343. ps = tioca_kern->ca_ap_pagesize; /* will be power of 2 */
  344. ps_shift = ffs(ps) - 1;
  345. end_xio_addr = xio_addr + req_size - 1;
  346. entries = (end_xio_addr >> ps_shift) - (xio_addr >> ps_shift) + 1;
  347. map = tioca_kern->ca_pcigart_pagemap;
  348. mapsize = tioca_kern->ca_pcigart_entries;
  349. entry = find_first_zero_bit(map, mapsize);
  350. while (entry < mapsize) {
  351. last_entry = find_next_bit(map, mapsize, entry);
  352. if (last_entry - entry >= entries)
  353. break;
  354. entry = find_next_zero_bit(map, mapsize, last_entry);
  355. }
  356. if (entry > mapsize)
  357. goto map_return;
  358. for (i = 0; i < entries; i++)
  359. set_bit(entry + i, map);
  360. bus_addr = tioca_kern->ca_pciap_base + (entry * ps);
  361. ca_dmamap->cad_dma_addr = bus_addr;
  362. ca_dmamap->cad_gart_size = entries;
  363. ca_dmamap->cad_gart_entry = entry;
  364. list_add(&ca_dmamap->cad_list, &tioca_kern->ca_dmamaps);
  365. if (xio_addr % ps) {
  366. tioca_kern->ca_pcigart[entry] = tioca_paddr_to_gart(xio_addr);
  367. bus_addr += xio_addr & (ps - 1);
  368. xio_addr &= ~(ps - 1);
  369. xio_addr += ps;
  370. entry++;
  371. }
  372. while (xio_addr < end_xio_addr) {
  373. tioca_kern->ca_pcigart[entry] = tioca_paddr_to_gart(xio_addr);
  374. xio_addr += ps;
  375. entry++;
  376. }
  377. tioca_tlbflush(tioca_kern);
  378. map_return:
  379. spin_unlock_irqrestore(&tioca_kern->ca_lock, flags);
  380. return bus_addr;
  381. }
  382. /**
  383. * tioca_dma_unmap - release CA mapping resources
  384. * @pdev: linux pci_dev representing the function
  385. * @bus_addr: bus address returned by an earlier tioca_dma_map
  386. * @dir: mapping direction (unused)
  387. *
  388. * Locate mapping resources associated with @bus_addr and release them.
  389. * For mappings created using the direct modes (64 or 48) there are no
  390. * resources to release.
  391. */
  392. static void
  393. tioca_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
  394. {
  395. int i, entry;
  396. struct tioca_common *tioca_common;
  397. struct tioca_kernel *tioca_kern;
  398. struct tioca_dmamap *map;
  399. struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(pdev);
  400. unsigned long flags;
  401. tioca_common = (struct tioca_common *)pcidev_info->pdi_pcibus_info;
  402. tioca_kern = (struct tioca_kernel *)tioca_common->ca_kernel_private;
  403. /* return straight away if this isn't be a mapped address */
  404. if (bus_addr < tioca_kern->ca_pciap_base ||
  405. bus_addr >= (tioca_kern->ca_pciap_base + tioca_kern->ca_pciap_size))
  406. return;
  407. spin_lock_irqsave(&tioca_kern->ca_lock, flags);
  408. list_for_each_entry(map, &tioca_kern->ca_dmamaps, cad_list)
  409. if (map->cad_dma_addr == bus_addr)
  410. break;
  411. BUG_ON(map == NULL);
  412. entry = map->cad_gart_entry;
  413. for (i = 0; i < map->cad_gart_size; i++, entry++) {
  414. clear_bit(entry, tioca_kern->ca_pcigart_pagemap);
  415. tioca_kern->ca_pcigart[entry] = 0;
  416. }
  417. tioca_tlbflush(tioca_kern);
  418. list_del(&map->cad_list);
  419. spin_unlock_irqrestore(&tioca_kern->ca_lock, flags);
  420. kfree(map);
  421. }
  422. /**
  423. * tioca_dma_map - map pages for PCI DMA
  424. * @pdev: linux pci_dev representing the function
  425. * @paddr: host physical address to map
  426. * @byte_count: bytes to map
  427. *
  428. * This is the main wrapper for mapping host physical pages to CA PCI space.
  429. * The mapping mode used is based on the devices dma_mask. As a last resort
  430. * use the GART mapped mode.
  431. */
  432. static u64
  433. tioca_dma_map(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags)
  434. {
  435. u64 mapaddr;
  436. /*
  437. * Not supported for now ...
  438. */
  439. if (dma_flags & SN_DMA_MSI)
  440. return 0;
  441. /*
  442. * If card is 64 or 48 bit addresable, use a direct mapping. 32
  443. * bit direct is so restrictive w.r.t. where the memory resides that
  444. * we don't use it even though CA has some support.
  445. */
  446. if (pdev->dma_mask == ~0UL)
  447. mapaddr = tioca_dma_d64(paddr);
  448. else if (pdev->dma_mask == 0xffffffffffffUL)
  449. mapaddr = tioca_dma_d48(pdev, paddr);
  450. else
  451. mapaddr = 0;
  452. /* Last resort ... use PCI portion of CA GART */
  453. if (mapaddr == 0)
  454. mapaddr = tioca_dma_mapped(pdev, paddr, byte_count);
  455. return mapaddr;
  456. }
  457. /**
  458. * tioca_error_intr_handler - SGI TIO CA error interrupt handler
  459. * @irq: unused
  460. * @arg: pointer to tioca_common struct for the given CA
  461. *
  462. * Handle a CA error interrupt. Simply a wrapper around a SAL call which
  463. * defers processing to the SGI prom.
  464. */
  465. static irqreturn_t
  466. tioca_error_intr_handler(int irq, void *arg)
  467. {
  468. struct tioca_common *soft = arg;
  469. struct ia64_sal_retval ret_stuff;
  470. u64 segment;
  471. u64 busnum;
  472. ret_stuff.status = 0;
  473. ret_stuff.v0 = 0;
  474. segment = soft->ca_common.bs_persist_segment;
  475. busnum = soft->ca_common.bs_persist_busnum;
  476. SAL_CALL_NOLOCK(ret_stuff,
  477. (u64) SN_SAL_IOIF_ERROR_INTERRUPT,
  478. segment, busnum, 0, 0, 0, 0, 0);
  479. return IRQ_HANDLED;
  480. }
  481. /**
  482. * tioca_bus_fixup - perform final PCI fixup for a TIO CA bus
  483. * @prom_bussoft: Common prom/kernel struct representing the bus
  484. *
  485. * Replicates the tioca_common pointed to by @prom_bussoft in kernel
  486. * space. Allocates and initializes a kernel-only area for a given CA,
  487. * and sets up an irq for handling CA error interrupts.
  488. *
  489. * On successful setup, returns the kernel version of tioca_common back to
  490. * the caller.
  491. */
  492. static void *
  493. tioca_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
  494. {
  495. struct tioca_common *tioca_common;
  496. struct tioca_kernel *tioca_kern;
  497. struct pci_bus *bus;
  498. /* sanity check prom rev */
  499. if (is_shub1() && sn_sal_rev() < 0x0406) {
  500. printk
  501. (KERN_ERR "%s: SGI prom rev 4.06 or greater required "
  502. "for tioca support\n", __FUNCTION__);
  503. return NULL;
  504. }
  505. /*
  506. * Allocate kernel bus soft and copy from prom.
  507. */
  508. tioca_common = kzalloc(sizeof(struct tioca_common), GFP_KERNEL);
  509. if (!tioca_common)
  510. return NULL;
  511. memcpy(tioca_common, prom_bussoft, sizeof(struct tioca_common));
  512. tioca_common->ca_common.bs_base |= __IA64_UNCACHED_OFFSET;
  513. /* init kernel-private area */
  514. tioca_kern = kzalloc(sizeof(struct tioca_kernel), GFP_KERNEL);
  515. if (!tioca_kern) {
  516. kfree(tioca_common);
  517. return NULL;
  518. }
  519. tioca_kern->ca_common = tioca_common;
  520. spin_lock_init(&tioca_kern->ca_lock);
  521. INIT_LIST_HEAD(&tioca_kern->ca_dmamaps);
  522. tioca_kern->ca_closest_node =
  523. nasid_to_cnodeid(tioca_common->ca_closest_nasid);
  524. tioca_common->ca_kernel_private = (u64) tioca_kern;
  525. bus = pci_find_bus(tioca_common->ca_common.bs_persist_segment,
  526. tioca_common->ca_common.bs_persist_busnum);
  527. BUG_ON(!bus);
  528. tioca_kern->ca_devices = &bus->devices;
  529. /* init GART */
  530. if (tioca_gart_init(tioca_kern) < 0) {
  531. kfree(tioca_kern);
  532. kfree(tioca_common);
  533. return NULL;
  534. }
  535. tioca_gart_found++;
  536. list_add(&tioca_kern->ca_list, &tioca_list);
  537. if (request_irq(SGI_TIOCA_ERROR,
  538. tioca_error_intr_handler,
  539. IRQF_SHARED, "TIOCA error", (void *)tioca_common))
  540. printk(KERN_WARNING
  541. "%s: Unable to get irq %d. "
  542. "Error interrupts won't be routed for TIOCA bus %d\n",
  543. __FUNCTION__, SGI_TIOCA_ERROR,
  544. (int)tioca_common->ca_common.bs_persist_busnum);
  545. /* Setup locality information */
  546. controller->node = tioca_kern->ca_closest_node;
  547. return tioca_common;
  548. }
  549. static struct sn_pcibus_provider tioca_pci_interfaces = {
  550. .dma_map = tioca_dma_map,
  551. .dma_map_consistent = tioca_dma_map,
  552. .dma_unmap = tioca_dma_unmap,
  553. .bus_fixup = tioca_bus_fixup,
  554. .force_interrupt = NULL,
  555. .target_interrupt = NULL
  556. };
  557. /**
  558. * tioca_init_provider - init SN PCI provider ops for TIO CA
  559. */
  560. int
  561. tioca_init_provider(void)
  562. {
  563. sn_pci_provider[PCIIO_ASIC_TYPE_TIOCA] = &tioca_pci_interfaces;
  564. return 0;
  565. }