tioce_provider.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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/tioce_provider.h>
  16. /**
  17. * Bus address ranges for the 5 flavors of TIOCE DMA
  18. */
  19. #define TIOCE_D64_MIN 0x8000000000000000UL
  20. #define TIOCE_D64_MAX 0xffffffffffffffffUL
  21. #define TIOCE_D64_ADDR(a) ((a) >= TIOCE_D64_MIN)
  22. #define TIOCE_D32_MIN 0x0000000080000000UL
  23. #define TIOCE_D32_MAX 0x00000000ffffffffUL
  24. #define TIOCE_D32_ADDR(a) ((a) >= TIOCE_D32_MIN && (a) <= TIOCE_D32_MAX)
  25. #define TIOCE_M32_MIN 0x0000000000000000UL
  26. #define TIOCE_M32_MAX 0x000000007fffffffUL
  27. #define TIOCE_M32_ADDR(a) ((a) >= TIOCE_M32_MIN && (a) <= TIOCE_M32_MAX)
  28. #define TIOCE_M40_MIN 0x0000004000000000UL
  29. #define TIOCE_M40_MAX 0x0000007fffffffffUL
  30. #define TIOCE_M40_ADDR(a) ((a) >= TIOCE_M40_MIN && (a) <= TIOCE_M40_MAX)
  31. #define TIOCE_M40S_MIN 0x0000008000000000UL
  32. #define TIOCE_M40S_MAX 0x000000ffffffffffUL
  33. #define TIOCE_M40S_ADDR(a) ((a) >= TIOCE_M40S_MIN && (a) <= TIOCE_M40S_MAX)
  34. /*
  35. * ATE manipulation macros.
  36. */
  37. #define ATE_PAGESHIFT(ps) (__ffs(ps))
  38. #define ATE_PAGEMASK(ps) ((ps)-1)
  39. #define ATE_PAGE(x, ps) ((x) >> ATE_PAGESHIFT(ps))
  40. #define ATE_NPAGES(start, len, pagesize) \
  41. (ATE_PAGE((start)+(len)-1, pagesize) - ATE_PAGE(start, pagesize) + 1)
  42. #define ATE_VALID(ate) ((ate) & (1UL << 63))
  43. #define ATE_MAKE(addr, ps) (((addr) & ~ATE_PAGEMASK(ps)) | (1UL << 63))
  44. /*
  45. * Flavors of ate-based mapping supported by tioce_alloc_map()
  46. */
  47. #define TIOCE_ATE_M32 1
  48. #define TIOCE_ATE_M40 2
  49. #define TIOCE_ATE_M40S 3
  50. #define KB(x) ((x) << 10)
  51. #define MB(x) ((x) << 20)
  52. #define GB(x) ((x) << 30)
  53. /**
  54. * tioce_dma_d64 - create a DMA mapping using 64-bit direct mode
  55. * @ct_addr: system coretalk address
  56. *
  57. * Map @ct_addr into 64-bit CE bus space. No device context is necessary
  58. * and no CE mapping are consumed.
  59. *
  60. * Bits 53:0 come from the coretalk address. The remaining bits are set as
  61. * follows:
  62. *
  63. * 63 - must be 1 to indicate d64 mode to CE hardware
  64. * 62 - barrier bit ... controlled with tioce_dma_barrier()
  65. * 61 - 0 since this is not an MSI transaction
  66. * 60:54 - reserved, MBZ
  67. */
  68. static uint64_t
  69. tioce_dma_d64(unsigned long ct_addr)
  70. {
  71. uint64_t bus_addr;
  72. bus_addr = ct_addr | (1UL << 63);
  73. return bus_addr;
  74. }
  75. /**
  76. * pcidev_to_tioce - return misc ce related pointers given a pci_dev
  77. * @pci_dev: pci device context
  78. * @base: ptr to store struct tioce_mmr * for the CE holding this device
  79. * @kernel: ptr to store struct tioce_kernel * for the CE holding this device
  80. * @port: ptr to store the CE port number that this device is on
  81. *
  82. * Return pointers to various CE-related structures for the CE upstream of
  83. * @pci_dev.
  84. */
  85. static inline void
  86. pcidev_to_tioce(struct pci_dev *pdev, struct tioce **base,
  87. struct tioce_kernel **kernel, int *port)
  88. {
  89. struct pcidev_info *pcidev_info;
  90. struct tioce_common *ce_common;
  91. struct tioce_kernel *ce_kernel;
  92. pcidev_info = SN_PCIDEV_INFO(pdev);
  93. ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
  94. ce_kernel = (struct tioce_kernel *)ce_common->ce_kernel_private;
  95. if (base)
  96. *base = (struct tioce *)ce_common->ce_pcibus.bs_base;
  97. if (kernel)
  98. *kernel = ce_kernel;
  99. /*
  100. * we use port as a zero-based value internally, even though the
  101. * documentation is 1-based.
  102. */
  103. if (port)
  104. *port =
  105. (pdev->bus->number < ce_kernel->ce_port1_secondary) ? 0 : 1;
  106. }
  107. /**
  108. * tioce_alloc_map - Given a coretalk address, map it to pcie bus address
  109. * space using one of the various ATE-based address modes.
  110. * @ce_kern: tioce context
  111. * @type: map mode to use
  112. * @port: 0-based port that the requesting device is downstream of
  113. * @ct_addr: the coretalk address to map
  114. * @len: number of bytes to map
  115. *
  116. * Given the addressing type, set up various paramaters that define the
  117. * ATE pool to use. Search for a contiguous block of entries to cover the
  118. * length, and if enough resources exist, fill in the ATE's and construct a
  119. * tioce_dmamap struct to track the mapping.
  120. */
  121. static uint64_t
  122. tioce_alloc_map(struct tioce_kernel *ce_kern, int type, int port,
  123. uint64_t ct_addr, int len)
  124. {
  125. int i;
  126. int j;
  127. int first;
  128. int last;
  129. int entries;
  130. int nates;
  131. int pagesize;
  132. uint64_t *ate_shadow;
  133. uint64_t *ate_reg;
  134. uint64_t addr;
  135. struct tioce *ce_mmr;
  136. uint64_t bus_base;
  137. struct tioce_dmamap *map;
  138. ce_mmr = (struct tioce *)ce_kern->ce_common->ce_pcibus.bs_base;
  139. switch (type) {
  140. case TIOCE_ATE_M32:
  141. /*
  142. * The first 64 entries of the ate3240 pool are dedicated to
  143. * super-page (TIOCE_ATE_M40S) mode.
  144. */
  145. first = 64;
  146. entries = TIOCE_NUM_M3240_ATES - 64;
  147. ate_shadow = ce_kern->ce_ate3240_shadow;
  148. ate_reg = ce_mmr->ce_ure_ate3240;
  149. pagesize = ce_kern->ce_ate3240_pagesize;
  150. bus_base = TIOCE_M32_MIN;
  151. break;
  152. case TIOCE_ATE_M40:
  153. first = 0;
  154. entries = TIOCE_NUM_M40_ATES;
  155. ate_shadow = ce_kern->ce_ate40_shadow;
  156. ate_reg = ce_mmr->ce_ure_ate40;
  157. pagesize = MB(64);
  158. bus_base = TIOCE_M40_MIN;
  159. break;
  160. case TIOCE_ATE_M40S:
  161. /*
  162. * ate3240 entries 0-31 are dedicated to port1 super-page
  163. * mappings. ate3240 entries 32-63 are dedicated to port2.
  164. */
  165. first = port * 32;
  166. entries = 32;
  167. ate_shadow = ce_kern->ce_ate3240_shadow;
  168. ate_reg = ce_mmr->ce_ure_ate3240;
  169. pagesize = GB(16);
  170. bus_base = TIOCE_M40S_MIN;
  171. break;
  172. default:
  173. return 0;
  174. }
  175. nates = ATE_NPAGES(ct_addr, len, pagesize);
  176. if (nates > entries)
  177. return 0;
  178. last = first + entries - nates;
  179. for (i = first; i <= last; i++) {
  180. if (ATE_VALID(ate_shadow[i]))
  181. continue;
  182. for (j = i; j < i + nates; j++)
  183. if (ATE_VALID(ate_shadow[j]))
  184. break;
  185. if (j >= i + nates)
  186. break;
  187. }
  188. if (i > last)
  189. return 0;
  190. map = kcalloc(1, sizeof(struct tioce_dmamap), GFP_ATOMIC);
  191. if (!map)
  192. return 0;
  193. addr = ct_addr;
  194. for (j = 0; j < nates; j++) {
  195. uint64_t ate;
  196. ate = ATE_MAKE(addr, pagesize);
  197. ate_shadow[i + j] = ate;
  198. ate_reg[i + j] = ate;
  199. addr += pagesize;
  200. }
  201. map->refcnt = 1;
  202. map->nbytes = nates * pagesize;
  203. map->ct_start = ct_addr & ~ATE_PAGEMASK(pagesize);
  204. map->pci_start = bus_base + (i * pagesize);
  205. map->ate_hw = &ate_reg[i];
  206. map->ate_shadow = &ate_shadow[i];
  207. map->ate_count = nates;
  208. list_add(&map->ce_dmamap_list, &ce_kern->ce_dmamap_list);
  209. return (map->pci_start + (ct_addr - map->ct_start));
  210. }
  211. /**
  212. * tioce_dma_d32 - create a DMA mapping using 32-bit direct mode
  213. * @pdev: linux pci_dev representing the function
  214. * @paddr: system physical address
  215. *
  216. * Map @paddr into 32-bit bus space of the CE associated with @pcidev_info.
  217. */
  218. static uint64_t
  219. tioce_dma_d32(struct pci_dev *pdev, uint64_t ct_addr)
  220. {
  221. int dma_ok;
  222. int port;
  223. struct tioce *ce_mmr;
  224. struct tioce_kernel *ce_kern;
  225. uint64_t ct_upper;
  226. uint64_t ct_lower;
  227. dma_addr_t bus_addr;
  228. ct_upper = ct_addr & ~0x3fffffffUL;
  229. ct_lower = ct_addr & 0x3fffffffUL;
  230. pcidev_to_tioce(pdev, &ce_mmr, &ce_kern, &port);
  231. if (ce_kern->ce_port[port].dirmap_refcnt == 0) {
  232. volatile uint64_t tmp;
  233. ce_kern->ce_port[port].dirmap_shadow = ct_upper;
  234. ce_mmr->ce_ure_dir_map[port] = ct_upper;
  235. tmp = ce_mmr->ce_ure_dir_map[port];
  236. dma_ok = 1;
  237. } else
  238. dma_ok = (ce_kern->ce_port[port].dirmap_shadow == ct_upper);
  239. if (dma_ok) {
  240. ce_kern->ce_port[port].dirmap_refcnt++;
  241. bus_addr = TIOCE_D32_MIN + ct_lower;
  242. } else
  243. bus_addr = 0;
  244. return bus_addr;
  245. }
  246. /**
  247. * tioce_dma_barrier - swizzle a TIOCE bus address to include or exclude
  248. * the barrier bit.
  249. * @bus_addr: bus address to swizzle
  250. *
  251. * Given a TIOCE bus address, set the appropriate bit to indicate barrier
  252. * attributes.
  253. */
  254. static uint64_t
  255. tioce_dma_barrier(uint64_t bus_addr, int on)
  256. {
  257. uint64_t barrier_bit;
  258. /* barrier not supported in M40/M40S mode */
  259. if (TIOCE_M40_ADDR(bus_addr) || TIOCE_M40S_ADDR(bus_addr))
  260. return bus_addr;
  261. if (TIOCE_D64_ADDR(bus_addr))
  262. barrier_bit = (1UL << 62);
  263. else /* must be m32 or d32 */
  264. barrier_bit = (1UL << 30);
  265. return (on) ? (bus_addr | barrier_bit) : (bus_addr & ~barrier_bit);
  266. }
  267. /**
  268. * tioce_dma_unmap - release CE mapping resources
  269. * @pdev: linux pci_dev representing the function
  270. * @bus_addr: bus address returned by an earlier tioce_dma_map
  271. * @dir: mapping direction (unused)
  272. *
  273. * Locate mapping resources associated with @bus_addr and release them.
  274. * For mappings created using the direct modes there are no resources
  275. * to release.
  276. */
  277. void
  278. tioce_dma_unmap(struct pci_dev *pdev, dma_addr_t bus_addr, int dir)
  279. {
  280. int i;
  281. int port;
  282. struct tioce_kernel *ce_kern;
  283. struct tioce *ce_mmr;
  284. unsigned long flags;
  285. bus_addr = tioce_dma_barrier(bus_addr, 0);
  286. pcidev_to_tioce(pdev, &ce_mmr, &ce_kern, &port);
  287. /* nothing to do for D64 */
  288. if (TIOCE_D64_ADDR(bus_addr))
  289. return;
  290. spin_lock_irqsave(&ce_kern->ce_lock, flags);
  291. if (TIOCE_D32_ADDR(bus_addr)) {
  292. if (--ce_kern->ce_port[port].dirmap_refcnt == 0) {
  293. ce_kern->ce_port[port].dirmap_shadow = 0;
  294. ce_mmr->ce_ure_dir_map[port] = 0;
  295. }
  296. } else {
  297. struct tioce_dmamap *map;
  298. list_for_each_entry(map, &ce_kern->ce_dmamap_list,
  299. ce_dmamap_list) {
  300. uint64_t last;
  301. last = map->pci_start + map->nbytes - 1;
  302. if (bus_addr >= map->pci_start && bus_addr <= last)
  303. break;
  304. }
  305. if (&map->ce_dmamap_list == &ce_kern->ce_dmamap_list) {
  306. printk(KERN_WARNING
  307. "%s: %s - no map found for bus_addr 0x%lx\n",
  308. __FUNCTION__, pci_name(pdev), bus_addr);
  309. } else if (--map->refcnt == 0) {
  310. for (i = 0; i < map->ate_count; i++) {
  311. map->ate_shadow[i] = 0;
  312. map->ate_hw[i] = 0;
  313. }
  314. list_del(&map->ce_dmamap_list);
  315. kfree(map);
  316. }
  317. }
  318. spin_unlock_irqrestore(&ce_kern->ce_lock, flags);
  319. }
  320. /**
  321. * tioce_do_dma_map - map pages for PCI DMA
  322. * @pdev: linux pci_dev representing the function
  323. * @paddr: host physical address to map
  324. * @byte_count: bytes to map
  325. *
  326. * This is the main wrapper for mapping host physical pages to CE PCI space.
  327. * The mapping mode used is based on the device's dma_mask.
  328. */
  329. static uint64_t
  330. tioce_do_dma_map(struct pci_dev *pdev, uint64_t paddr, size_t byte_count,
  331. int barrier)
  332. {
  333. unsigned long flags;
  334. uint64_t ct_addr;
  335. uint64_t mapaddr = 0;
  336. struct tioce_kernel *ce_kern;
  337. struct tioce_dmamap *map;
  338. int port;
  339. uint64_t dma_mask;
  340. dma_mask = (barrier) ? pdev->dev.coherent_dma_mask : pdev->dma_mask;
  341. /* cards must be able to address at least 31 bits */
  342. if (dma_mask < 0x7fffffffUL)
  343. return 0;
  344. ct_addr = PHYS_TO_TIODMA(paddr);
  345. /*
  346. * If the device can generate 64 bit addresses, create a D64 map.
  347. * Since this should never fail, bypass the rest of the checks.
  348. */
  349. if (dma_mask == ~0UL) {
  350. mapaddr = tioce_dma_d64(ct_addr);
  351. goto dma_map_done;
  352. }
  353. pcidev_to_tioce(pdev, NULL, &ce_kern, &port);
  354. spin_lock_irqsave(&ce_kern->ce_lock, flags);
  355. /*
  356. * D64 didn't work ... See if we have an existing map that covers
  357. * this address range. Must account for devices dma_mask here since
  358. * an existing map might have been done in a mode using more pci
  359. * address bits than this device can support.
  360. */
  361. list_for_each_entry(map, &ce_kern->ce_dmamap_list, ce_dmamap_list) {
  362. uint64_t last;
  363. last = map->ct_start + map->nbytes - 1;
  364. if (ct_addr >= map->ct_start &&
  365. ct_addr + byte_count - 1 <= last &&
  366. map->pci_start <= dma_mask) {
  367. map->refcnt++;
  368. mapaddr = map->pci_start + (ct_addr - map->ct_start);
  369. break;
  370. }
  371. }
  372. /*
  373. * If we don't have a map yet, and the card can generate 40
  374. * bit addresses, try the M40/M40S modes. Note these modes do not
  375. * support a barrier bit, so if we need a consistent map these
  376. * won't work.
  377. */
  378. if (!mapaddr && !barrier && dma_mask >= 0xffffffffffUL) {
  379. /*
  380. * We have two options for 40-bit mappings: 16GB "super" ATE's
  381. * and 64MB "regular" ATE's. We'll try both if needed for a
  382. * given mapping but which one we try first depends on the
  383. * size. For requests >64MB, prefer to use a super page with
  384. * regular as the fallback. Otherwise, try in the reverse order.
  385. */
  386. if (byte_count > MB(64)) {
  387. mapaddr = tioce_alloc_map(ce_kern, TIOCE_ATE_M40S,
  388. port, ct_addr, byte_count);
  389. if (!mapaddr)
  390. mapaddr =
  391. tioce_alloc_map(ce_kern, TIOCE_ATE_M40, -1,
  392. ct_addr, byte_count);
  393. } else {
  394. mapaddr = tioce_alloc_map(ce_kern, TIOCE_ATE_M40, -1,
  395. ct_addr, byte_count);
  396. if (!mapaddr)
  397. mapaddr =
  398. tioce_alloc_map(ce_kern, TIOCE_ATE_M40S,
  399. port, ct_addr, byte_count);
  400. }
  401. }
  402. /*
  403. * 32-bit direct is the next mode to try
  404. */
  405. if (!mapaddr && dma_mask >= 0xffffffffUL)
  406. mapaddr = tioce_dma_d32(pdev, ct_addr);
  407. /*
  408. * Last resort, try 32-bit ATE-based map.
  409. */
  410. if (!mapaddr)
  411. mapaddr =
  412. tioce_alloc_map(ce_kern, TIOCE_ATE_M32, -1, ct_addr,
  413. byte_count);
  414. spin_unlock_irqrestore(&ce_kern->ce_lock, flags);
  415. dma_map_done:
  416. if (mapaddr & barrier)
  417. mapaddr = tioce_dma_barrier(mapaddr, 1);
  418. return mapaddr;
  419. }
  420. /**
  421. * tioce_dma - standard pci dma map interface
  422. * @pdev: pci device requesting the map
  423. * @paddr: system physical address to map into pci space
  424. * @byte_count: # bytes to map
  425. *
  426. * Simply call tioce_do_dma_map() to create a map with the barrier bit clear
  427. * in the address.
  428. */
  429. static uint64_t
  430. tioce_dma(struct pci_dev *pdev, uint64_t paddr, size_t byte_count)
  431. {
  432. return tioce_do_dma_map(pdev, paddr, byte_count, 0);
  433. }
  434. /**
  435. * tioce_dma_consistent - consistent pci dma map interface
  436. * @pdev: pci device requesting the map
  437. * @paddr: system physical address to map into pci space
  438. * @byte_count: # bytes to map
  439. *
  440. * Simply call tioce_do_dma_map() to create a map with the barrier bit set
  441. * in the address.
  442. */ static uint64_t
  443. tioce_dma_consistent(struct pci_dev *pdev, uint64_t paddr, size_t byte_count)
  444. {
  445. return tioce_do_dma_map(pdev, paddr, byte_count, 1);
  446. }
  447. /**
  448. * tioce_error_intr_handler - SGI TIO CE error interrupt handler
  449. * @irq: unused
  450. * @arg: pointer to tioce_common struct for the given CE
  451. * @pt: unused
  452. *
  453. * Handle a CE error interrupt. Simply a wrapper around a SAL call which
  454. * defers processing to the SGI prom.
  455. */ static irqreturn_t
  456. tioce_error_intr_handler(int irq, void *arg, struct pt_regs *pt)
  457. {
  458. struct tioce_common *soft = arg;
  459. struct ia64_sal_retval ret_stuff;
  460. ret_stuff.status = 0;
  461. ret_stuff.v0 = 0;
  462. SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_ERROR_INTERRUPT,
  463. soft->ce_pcibus.bs_persist_segment,
  464. soft->ce_pcibus.bs_persist_busnum, 0, 0, 0, 0, 0);
  465. return IRQ_HANDLED;
  466. }
  467. /**
  468. * tioce_kern_init - init kernel structures related to a given TIOCE
  469. * @tioce_common: ptr to a cached tioce_common struct that originated in prom
  470. */ static struct tioce_kernel *
  471. tioce_kern_init(struct tioce_common *tioce_common)
  472. {
  473. int i;
  474. uint32_t tmp;
  475. struct tioce *tioce_mmr;
  476. struct tioce_kernel *tioce_kern;
  477. tioce_kern = kcalloc(1, sizeof(struct tioce_kernel), GFP_KERNEL);
  478. if (!tioce_kern) {
  479. return NULL;
  480. }
  481. tioce_kern->ce_common = tioce_common;
  482. spin_lock_init(&tioce_kern->ce_lock);
  483. INIT_LIST_HEAD(&tioce_kern->ce_dmamap_list);
  484. tioce_common->ce_kernel_private = (uint64_t) tioce_kern;
  485. /*
  486. * Determine the secondary bus number of the port2 logical PPB.
  487. * This is used to decide whether a given pci device resides on
  488. * port1 or port2. Note: We don't have enough plumbing set up
  489. * here to use pci_read_config_xxx() so use the raw_pci_ops vector.
  490. */
  491. raw_pci_ops->read(tioce_common->ce_pcibus.bs_persist_segment,
  492. tioce_common->ce_pcibus.bs_persist_busnum,
  493. PCI_DEVFN(2, 0), PCI_SECONDARY_BUS, 1, &tmp);
  494. tioce_kern->ce_port1_secondary = (uint8_t) tmp;
  495. /*
  496. * Set PMU pagesize to the largest size available, and zero out
  497. * the ate's.
  498. */
  499. tioce_mmr = (struct tioce *)tioce_common->ce_pcibus.bs_base;
  500. tioce_mmr->ce_ure_page_map &= ~CE_URE_PAGESIZE_MASK;
  501. tioce_mmr->ce_ure_page_map |= CE_URE_256K_PAGESIZE;
  502. tioce_kern->ce_ate3240_pagesize = KB(256);
  503. for (i = 0; i < TIOCE_NUM_M40_ATES; i++) {
  504. tioce_kern->ce_ate40_shadow[i] = 0;
  505. tioce_mmr->ce_ure_ate40[i] = 0;
  506. }
  507. for (i = 0; i < TIOCE_NUM_M3240_ATES; i++) {
  508. tioce_kern->ce_ate3240_shadow[i] = 0;
  509. tioce_mmr->ce_ure_ate3240[i] = 0;
  510. }
  511. return tioce_kern;
  512. }
  513. /**
  514. * tioce_force_interrupt - implement altix force_interrupt() backend for CE
  515. * @sn_irq_info: sn asic irq that we need an interrupt generated for
  516. *
  517. * Given an sn_irq_info struct, set the proper bit in ce_adm_force_int to
  518. * force a secondary interrupt to be generated. This is to work around an
  519. * asic issue where there is a small window of opportunity for a legacy device
  520. * interrupt to be lost.
  521. */
  522. static void
  523. tioce_force_interrupt(struct sn_irq_info *sn_irq_info)
  524. {
  525. struct pcidev_info *pcidev_info;
  526. struct tioce_common *ce_common;
  527. struct tioce *ce_mmr;
  528. uint64_t force_int_val;
  529. if (!sn_irq_info->irq_bridge)
  530. return;
  531. if (sn_irq_info->irq_bridge_type != PCIIO_ASIC_TYPE_TIOCE)
  532. return;
  533. pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  534. if (!pcidev_info)
  535. return;
  536. ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
  537. ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base;
  538. /*
  539. * irq_int_bit is originally set up by prom, and holds the interrupt
  540. * bit shift (not mask) as defined by the bit definitions in the
  541. * ce_adm_int mmr. These shifts are not the same for the
  542. * ce_adm_force_int register, so do an explicit mapping here to make
  543. * things clearer.
  544. */
  545. switch (sn_irq_info->irq_int_bit) {
  546. case CE_ADM_INT_PCIE_PORT1_DEV_A_SHFT:
  547. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_A_SHFT;
  548. break;
  549. case CE_ADM_INT_PCIE_PORT1_DEV_B_SHFT:
  550. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_B_SHFT;
  551. break;
  552. case CE_ADM_INT_PCIE_PORT1_DEV_C_SHFT:
  553. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_C_SHFT;
  554. break;
  555. case CE_ADM_INT_PCIE_PORT1_DEV_D_SHFT:
  556. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT1_DEV_D_SHFT;
  557. break;
  558. case CE_ADM_INT_PCIE_PORT2_DEV_A_SHFT:
  559. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_A_SHFT;
  560. break;
  561. case CE_ADM_INT_PCIE_PORT2_DEV_B_SHFT:
  562. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_B_SHFT;
  563. break;
  564. case CE_ADM_INT_PCIE_PORT2_DEV_C_SHFT:
  565. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_C_SHFT;
  566. break;
  567. case CE_ADM_INT_PCIE_PORT2_DEV_D_SHFT:
  568. force_int_val = 1UL << CE_ADM_FORCE_INT_PCIE_PORT2_DEV_D_SHFT;
  569. break;
  570. default:
  571. return;
  572. }
  573. ce_mmr->ce_adm_force_int = force_int_val;
  574. }
  575. /**
  576. * tioce_target_interrupt - implement set_irq_affinity for tioce resident
  577. * functions. Note: only applies to line interrupts, not MSI's.
  578. *
  579. * @sn_irq_info: SN IRQ context
  580. *
  581. * Given an sn_irq_info, set the associated CE device's interrupt destination
  582. * register. Since the interrupt destination registers are on a per-ce-slot
  583. * basis, this will retarget line interrupts for all functions downstream of
  584. * the slot.
  585. */
  586. static void
  587. tioce_target_interrupt(struct sn_irq_info *sn_irq_info)
  588. {
  589. struct pcidev_info *pcidev_info;
  590. struct tioce_common *ce_common;
  591. struct tioce *ce_mmr;
  592. int bit;
  593. pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  594. if (!pcidev_info)
  595. return;
  596. ce_common = (struct tioce_common *)pcidev_info->pdi_pcibus_info;
  597. ce_mmr = (struct tioce *)ce_common->ce_pcibus.bs_base;
  598. bit = sn_irq_info->irq_int_bit;
  599. ce_mmr->ce_adm_int_mask |= (1UL << bit);
  600. ce_mmr->ce_adm_int_dest[bit] =
  601. ((uint64_t)sn_irq_info->irq_irq << INTR_VECTOR_SHFT) |
  602. sn_irq_info->irq_xtalkaddr;
  603. ce_mmr->ce_adm_int_mask &= ~(1UL << bit);
  604. tioce_force_interrupt(sn_irq_info);
  605. }
  606. /**
  607. * tioce_bus_fixup - perform final PCI fixup for a TIO CE bus
  608. * @prom_bussoft: Common prom/kernel struct representing the bus
  609. *
  610. * Replicates the tioce_common pointed to by @prom_bussoft in kernel
  611. * space. Allocates and initializes a kernel-only area for a given CE,
  612. * and sets up an irq for handling CE error interrupts.
  613. *
  614. * On successful setup, returns the kernel version of tioce_common back to
  615. * the caller.
  616. */
  617. static void *
  618. tioce_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
  619. {
  620. struct tioce_common *tioce_common;
  621. /*
  622. * Allocate kernel bus soft and copy from prom.
  623. */
  624. tioce_common = kcalloc(1, sizeof(struct tioce_common), GFP_KERNEL);
  625. if (!tioce_common)
  626. return NULL;
  627. memcpy(tioce_common, prom_bussoft, sizeof(struct tioce_common));
  628. tioce_common->ce_pcibus.bs_base |= __IA64_UNCACHED_OFFSET;
  629. if (tioce_kern_init(tioce_common) == NULL) {
  630. kfree(tioce_common);
  631. return NULL;
  632. }
  633. if (request_irq(SGI_PCIASIC_ERROR,
  634. tioce_error_intr_handler,
  635. SA_SHIRQ, "TIOCE error", (void *)tioce_common))
  636. printk(KERN_WARNING
  637. "%s: Unable to get irq %d. "
  638. "Error interrupts won't be routed for "
  639. "TIOCE bus %04x:%02x\n",
  640. __FUNCTION__, SGI_PCIASIC_ERROR,
  641. tioce_common->ce_pcibus.bs_persist_segment,
  642. tioce_common->ce_pcibus.bs_persist_busnum);
  643. return tioce_common;
  644. }
  645. static struct sn_pcibus_provider tioce_pci_interfaces = {
  646. .dma_map = tioce_dma,
  647. .dma_map_consistent = tioce_dma_consistent,
  648. .dma_unmap = tioce_dma_unmap,
  649. .bus_fixup = tioce_bus_fixup,
  650. .force_interrupt = tioce_force_interrupt,
  651. .target_interrupt = tioce_target_interrupt
  652. };
  653. /**
  654. * tioce_init_provider - init SN PCI provider ops for TIO CE
  655. */
  656. int
  657. tioce_init_provider(void)
  658. {
  659. sn_pci_provider[PCIIO_ASIC_TYPE_TIOCE] = &tioce_pci_interfaces;
  660. return 0;
  661. }