tioca_provider.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. volatile 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. kzalloc(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. ca_base->ca_control1 |= CA_AGPDMA_OP_ENB_COMBDELAY; /* PV895469 ? */
  155. ca_base->ca_control2 &= ~(CA_GART_MEM_PARAM);
  156. ca_base->ca_control2 |= (0x2ull << CA_GART_MEM_PARAM_SHFT);
  157. tioca_kern->ca_gart_iscoherent = 1;
  158. ca_base->ca_control2 &=
  159. ~(CA_GART_WR_PREFETCH_ENB | CA_GART_RD_PREFETCH_ENB);
  160. /*
  161. * Unmask GART fetch error interrupts. Clear residual errors first.
  162. */
  163. ca_base->ca_int_status_alias = CA_GART_FETCH_ERR;
  164. ca_base->ca_mult_error_alias = CA_GART_FETCH_ERR;
  165. ca_base->ca_int_mask &= ~CA_GART_FETCH_ERR;
  166. /*
  167. * Program the aperature and gart registers in TIOCA
  168. */
  169. ca_base->ca_gart_aperature = ap_reg;
  170. ca_base->ca_gart_ptr_table = tioca_kern->ca_gart_coretalk_addr | 1;
  171. return 0;
  172. }
  173. /**
  174. * tioca_fastwrite_enable - enable AGP FW for a tioca and its functions
  175. * @tioca_kernel: structure representing the CA
  176. *
  177. * Given a CA, scan all attached functions making sure they all support
  178. * FastWrite. If so, enable FastWrite for all functions and the CA itself.
  179. */
  180. void
  181. tioca_fastwrite_enable(struct tioca_kernel *tioca_kern)
  182. {
  183. int cap_ptr;
  184. uint64_t ca_control1;
  185. uint32_t reg;
  186. struct tioca *tioca_base;
  187. struct pci_dev *pdev;
  188. struct tioca_common *common;
  189. common = tioca_kern->ca_common;
  190. /*
  191. * Scan all vga controllers on this bus making sure they all
  192. * suport FW. If not, return.
  193. */
  194. list_for_each_entry(pdev, tioca_kern->ca_devices, bus_list) {
  195. if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8))
  196. continue;
  197. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  198. if (!cap_ptr)
  199. return; /* no AGP CAP means no FW */
  200. pci_read_config_dword(pdev, cap_ptr + PCI_AGP_STATUS, &reg);
  201. if (!(reg & PCI_AGP_STATUS_FW))
  202. return; /* function doesn't support FW */
  203. }
  204. /*
  205. * Set fw for all vga fn's
  206. */
  207. list_for_each_entry(pdev, tioca_kern->ca_devices, bus_list) {
  208. if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8))
  209. continue;
  210. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  211. pci_read_config_dword(pdev, cap_ptr + PCI_AGP_COMMAND, &reg);
  212. reg |= PCI_AGP_COMMAND_FW;
  213. pci_write_config_dword(pdev, cap_ptr + PCI_AGP_COMMAND, reg);
  214. }
  215. /*
  216. * Set ca's fw to match
  217. */
  218. tioca_base = (struct tioca *)common->ca_common.bs_base;
  219. ca_control1 = tioca_base->ca_control1;
  220. ca_control1 |= CA_AGP_FW_ENABLE;
  221. tioca_base->ca_control1 = ca_control1;
  222. }
  223. EXPORT_SYMBOL(tioca_fastwrite_enable); /* used by agp-sgi */
  224. /**
  225. * tioca_dma_d64 - create a DMA mapping using 64-bit direct mode
  226. * @paddr: system physical address
  227. *
  228. * Map @paddr into 64-bit CA bus space. No device context is necessary.
  229. * Bits 53:0 come from the coretalk address. We just need to mask in the
  230. * following optional bits of the 64-bit pci address:
  231. *
  232. * 63:60 - Coretalk Packet Type - 0x1 for Mem Get/Put (coherent)
  233. * 0x2 for PIO (non-coherent)
  234. * We will always use 0x1
  235. * 55:55 - Swap bytes Currently unused
  236. */
  237. static uint64_t
  238. tioca_dma_d64(unsigned long paddr)
  239. {
  240. dma_addr_t bus_addr;
  241. bus_addr = PHYS_TO_TIODMA(paddr);
  242. BUG_ON(!bus_addr);
  243. BUG_ON(bus_addr >> 54);
  244. /* Set upper nibble to Cache Coherent Memory op */
  245. bus_addr |= (1UL << 60);
  246. return bus_addr;
  247. }
  248. /**
  249. * tioca_dma_d48 - create a DMA mapping using 48-bit direct mode
  250. * @pdev: linux pci_dev representing the function
  251. * @paddr: system physical address
  252. *
  253. * Map @paddr into 64-bit bus space of the CA associated with @pcidev_info.
  254. *
  255. * The CA agp 48 bit direct address falls out as follows:
  256. *
  257. * When direct mapping AGP addresses, the 48 bit AGP address is
  258. * constructed as follows:
  259. *
  260. * [47:40] - Low 8 bits of the page Node ID extracted from coretalk
  261. * address [47:40]. The upper 8 node bits are fixed
  262. * and come from the xxx register bits [5:0]
  263. * [39:38] - Chiplet ID extracted from coretalk address [39:38]
  264. * [37:00] - node offset extracted from coretalk address [37:00]
  265. *
  266. * Since the node id in general will be non-zero, and the chiplet id
  267. * will always be non-zero, it follows that the device must support
  268. * a dma mask of at least 0xffffffffff (40 bits) to target node 0
  269. * and in general should be 0xffffffffffff (48 bits) to target nodes
  270. * up to 255. Nodes above 255 need the support of the xxx register,
  271. * and so a given CA can only directly target nodes in the range
  272. * xxx - xxx+255.
  273. */
  274. static uint64_t
  275. tioca_dma_d48(struct pci_dev *pdev, uint64_t paddr)
  276. {
  277. struct tioca_common *tioca_common;
  278. struct tioca *ca_base;
  279. uint64_t ct_addr;
  280. dma_addr_t bus_addr;
  281. uint32_t node_upper;
  282. uint64_t agp_dma_extn;
  283. struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(pdev);
  284. tioca_common = (struct tioca_common *)pcidev_info->pdi_pcibus_info;
  285. ca_base = (struct tioca *)tioca_common->ca_common.bs_base;
  286. ct_addr = PHYS_TO_TIODMA(paddr);
  287. if (!ct_addr)
  288. return 0;
  289. bus_addr = (dma_addr_t) (ct_addr & 0xffffffffffffUL);
  290. node_upper = ct_addr >> 48;
  291. if (node_upper > 64) {
  292. printk(KERN_ERR "%s: coretalk addr 0x%p node id out "
  293. "of range\n", __FUNCTION__, (void *)ct_addr);
  294. return 0;
  295. }
  296. agp_dma_extn = ca_base->ca_agp_dma_addr_extn;
  297. if (node_upper != (agp_dma_extn >> CA_AGP_DMA_NODE_ID_SHFT)) {
  298. printk(KERN_ERR "%s: coretalk upper node (%u) "
  299. "mismatch with ca_agp_dma_addr_extn (%lu)\n",
  300. __FUNCTION__,
  301. node_upper, (agp_dma_extn >> CA_AGP_DMA_NODE_ID_SHFT));
  302. return 0;
  303. }
  304. return bus_addr;
  305. }
  306. /**
  307. * tioca_dma_mapped - create a DMA mapping using a CA GART
  308. * @pdev: linux pci_dev representing the function
  309. * @paddr: host physical address to map
  310. * @req_size: len (bytes) to map
  311. *
  312. * Map @paddr into CA address space using the GART mechanism. The mapped
  313. * dma_addr_t is guarenteed to be contiguous in CA bus space.
  314. */
  315. static dma_addr_t
  316. tioca_dma_mapped(struct pci_dev *pdev, uint64_t paddr, size_t req_size)
  317. {
  318. int i, ps, ps_shift, entry, entries, mapsize, last_entry;
  319. uint64_t xio_addr, end_xio_addr;
  320. struct tioca_common *tioca_common;
  321. struct tioca_kernel *tioca_kern;
  322. dma_addr_t bus_addr = 0;
  323. struct tioca_dmamap *ca_dmamap;
  324. void *map;
  325. unsigned long flags;
  326. struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(pdev);;
  327. tioca_common = (struct tioca_common *)pcidev_info->pdi_pcibus_info;
  328. tioca_kern = (struct tioca_kernel *)tioca_common->ca_kernel_private;
  329. xio_addr = PHYS_TO_TIODMA(paddr);
  330. if (!xio_addr)
  331. return 0;
  332. spin_lock_irqsave(&tioca_kern->ca_lock, flags);
  333. /*
  334. * allocate a map struct
  335. */
  336. ca_dmamap = kzalloc(sizeof(struct tioca_dmamap), GFP_ATOMIC);
  337. if (!ca_dmamap)
  338. goto map_return;
  339. /*
  340. * Locate free entries that can hold req_size. Account for
  341. * unaligned start/length when allocating.
  342. */
  343. ps = tioca_kern->ca_ap_pagesize; /* will be power of 2 */
  344. ps_shift = ffs(ps) - 1;
  345. end_xio_addr = xio_addr + req_size - 1;
  346. entries = (end_xio_addr >> ps_shift) - (xio_addr >> ps_shift) + 1;
  347. map = tioca_kern->ca_pcigart_pagemap;
  348. mapsize = tioca_kern->ca_pcigart_entries;
  349. entry = find_first_zero_bit(map, mapsize);
  350. while (entry < mapsize) {
  351. last_entry = find_next_bit(map, mapsize, entry);
  352. if (last_entry - entry >= entries)
  353. break;
  354. entry = find_next_zero_bit(map, mapsize, last_entry);
  355. }
  356. if (entry > mapsize)
  357. goto map_return;
  358. for (i = 0; i < entries; i++)
  359. set_bit(entry + i, map);
  360. bus_addr = tioca_kern->ca_pciap_base + (entry * ps);
  361. ca_dmamap->cad_dma_addr = bus_addr;
  362. ca_dmamap->cad_gart_size = entries;
  363. ca_dmamap->cad_gart_entry = entry;
  364. list_add(&ca_dmamap->cad_list, &tioca_kern->ca_dmamaps);
  365. if (xio_addr % ps) {
  366. tioca_kern->ca_pcigart[entry] = tioca_paddr_to_gart(xio_addr);
  367. bus_addr += xio_addr & (ps - 1);
  368. xio_addr &= ~(ps - 1);
  369. xio_addr += ps;
  370. entry++;
  371. }
  372. while (xio_addr < end_xio_addr) {
  373. tioca_kern->ca_pcigart[entry] = tioca_paddr_to_gart(xio_addr);
  374. xio_addr += ps;
  375. entry++;
  376. }
  377. tioca_tlbflush(tioca_kern);
  378. map_return:
  379. spin_unlock_irqrestore(&tioca_kern->ca_lock, flags);
  380. return bus_addr;
  381. }
  382. /**
  383. * tioca_dma_unmap - release CA mapping resources
  384. * @pdev: linux pci_dev representing the function
  385. * @bus_addr: bus address returned by an earlier tioca_dma_map
  386. * @dir: mapping direction (unused)
  387. *
  388. * Locate mapping resources associated with @bus_addr and release them.
  389. * For mappings created using the direct modes (64 or 48) there are no
  390. * resources to release.
  391. */
  392. static void
  393. tioca_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
  394. {
  395. int i, entry;
  396. struct tioca_common *tioca_common;
  397. struct tioca_kernel *tioca_kern;
  398. struct tioca_dmamap *map;
  399. struct pcidev_info *pcidev_info = SN_PCIDEV_INFO(pdev);
  400. unsigned long flags;
  401. tioca_common = (struct tioca_common *)pcidev_info->pdi_pcibus_info;
  402. tioca_kern = (struct tioca_kernel *)tioca_common->ca_kernel_private;
  403. /* return straight away if this isn't be a mapped address */
  404. if (bus_addr < tioca_kern->ca_pciap_base ||
  405. bus_addr >= (tioca_kern->ca_pciap_base + tioca_kern->ca_pciap_size))
  406. return;
  407. spin_lock_irqsave(&tioca_kern->ca_lock, flags);
  408. list_for_each_entry(map, &tioca_kern->ca_dmamaps, cad_list)
  409. if (map->cad_dma_addr == bus_addr)
  410. break;
  411. BUG_ON(map == NULL);
  412. entry = map->cad_gart_entry;
  413. for (i = 0; i < map->cad_gart_size; i++, entry++) {
  414. clear_bit(entry, tioca_kern->ca_pcigart_pagemap);
  415. tioca_kern->ca_pcigart[entry] = 0;
  416. }
  417. tioca_tlbflush(tioca_kern);
  418. list_del(&map->cad_list);
  419. spin_unlock_irqrestore(&tioca_kern->ca_lock, flags);
  420. kfree(map);
  421. }
  422. /**
  423. * tioca_dma_map - map pages for PCI DMA
  424. * @pdev: linux pci_dev representing the function
  425. * @paddr: host physical address to map
  426. * @byte_count: bytes to map
  427. *
  428. * This is the main wrapper for mapping host physical pages to CA PCI space.
  429. * The mapping mode used is based on the devices dma_mask. As a last resort
  430. * use the GART mapped mode.
  431. */
  432. static uint64_t
  433. tioca_dma_map(struct pci_dev *pdev, uint64_t paddr, size_t byte_count)
  434. {
  435. uint64_t mapaddr;
  436. /*
  437. * If card is 64 or 48 bit addresable, use a direct mapping. 32
  438. * bit direct is so restrictive w.r.t. where the memory resides that
  439. * we don't use it even though CA has some support.
  440. */
  441. if (pdev->dma_mask == ~0UL)
  442. mapaddr = tioca_dma_d64(paddr);
  443. else if (pdev->dma_mask == 0xffffffffffffUL)
  444. mapaddr = tioca_dma_d48(pdev, paddr);
  445. else
  446. mapaddr = 0;
  447. /* Last resort ... use PCI portion of CA GART */
  448. if (mapaddr == 0)
  449. mapaddr = tioca_dma_mapped(pdev, paddr, byte_count);
  450. return mapaddr;
  451. }
  452. /**
  453. * tioca_error_intr_handler - SGI TIO CA error interrupt handler
  454. * @irq: unused
  455. * @arg: pointer to tioca_common struct for the given CA
  456. * @pt: unused
  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, struct pt_regs *pt)
  463. {
  464. struct tioca_common *soft = arg;
  465. struct ia64_sal_retval ret_stuff;
  466. uint64_t segment;
  467. uint64_t 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 (sn_sal_rev() < 0x0406) {
  496. printk
  497. (KERN_ERR "%s: SGI prom rev 4.06 or greater required "
  498. "for tioca support\n", __FUNCTION__);
  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 |= __IA64_UNCACHED_OFFSET;
  509. /* init kernel-private area */
  510. tioca_kern = kzalloc(sizeof(struct tioca_kernel), GFP_KERNEL);
  511. if (!tioca_kern) {
  512. kfree(tioca_common);
  513. return NULL;
  514. }
  515. tioca_kern->ca_common = tioca_common;
  516. spin_lock_init(&tioca_kern->ca_lock);
  517. INIT_LIST_HEAD(&tioca_kern->ca_dmamaps);
  518. tioca_kern->ca_closest_node =
  519. nasid_to_cnodeid(tioca_common->ca_closest_nasid);
  520. tioca_common->ca_kernel_private = (uint64_t) tioca_kern;
  521. bus = pci_find_bus(tioca_common->ca_common.bs_persist_segment,
  522. tioca_common->ca_common.bs_persist_busnum);
  523. BUG_ON(!bus);
  524. tioca_kern->ca_devices = &bus->devices;
  525. /* init GART */
  526. if (tioca_gart_init(tioca_kern) < 0) {
  527. kfree(tioca_kern);
  528. kfree(tioca_common);
  529. return NULL;
  530. }
  531. tioca_gart_found++;
  532. list_add(&tioca_kern->ca_list, &tioca_list);
  533. if (request_irq(SGI_TIOCA_ERROR,
  534. tioca_error_intr_handler,
  535. SA_SHIRQ, "TIOCA error", (void *)tioca_common))
  536. printk(KERN_WARNING
  537. "%s: Unable to get irq %d. "
  538. "Error interrupts won't be routed for TIOCA bus %d\n",
  539. __FUNCTION__, SGI_TIOCA_ERROR,
  540. (int)tioca_common->ca_common.bs_persist_busnum);
  541. /* Setup locality information */
  542. controller->node = tioca_kern->ca_closest_node;
  543. return tioca_common;
  544. }
  545. static struct sn_pcibus_provider tioca_pci_interfaces = {
  546. .dma_map = tioca_dma_map,
  547. .dma_map_consistent = tioca_dma_map,
  548. .dma_unmap = tioca_dma_unmap,
  549. .bus_fixup = tioca_bus_fixup,
  550. .force_interrupt = NULL,
  551. .target_interrupt = NULL
  552. };
  553. /**
  554. * tioca_init_provider - init SN PCI provider ops for TIO CA
  555. */
  556. int
  557. tioca_init_provider(void)
  558. {
  559. sn_pci_provider[PCIIO_ASIC_TYPE_TIOCA] = &tioca_pci_interfaces;
  560. return 0;
  561. }