tioca_provider.c 18 KB

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