tioca_provider.c 18 KB

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