tioca_provider.c 18 KB

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