tioca_provider.c 18 KB

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