sba_iommu.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:48k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2. **  IA64 System Bus Adapter (SBA) I/O MMU manager
  3. **
  4. ** (c) Copyright 2002 Alex Williamson
  5. ** (c) Copyright 2002 Hewlett-Packard Company
  6. **
  7. ** Portions (c) 2000 Grant Grundler (from parisc I/O MMU code)
  8. ** Portions (c) 1999 Dave S. Miller (from sparc64 I/O MMU code)
  9. **
  10. ** This program is free software; you can redistribute it and/or modify
  11. ** it under the terms of the GNU General Public License as published by
  12. **      the Free Software Foundation; either version 2 of the License, or
  13. **      (at your option) any later version.
  14. **
  15. **
  16. ** This module initializes the IOC (I/O Controller) found on HP
  17. ** McKinley machines and their successors.
  18. **
  19. */
  20. #include <linux/config.h>
  21. #include <linux/types.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/slab.h>
  26. #include <linux/init.h>
  27. #include <linux/mm.h>
  28. #include <linux/string.h>
  29. #include <linux/pci.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/acpi.h>
  32. #include <linux/efi.h>
  33. #include <asm/delay.h> /* ia64_get_itc() */
  34. #include <asm/io.h>
  35. #include <asm/page.h> /* PAGE_OFFSET */
  36. #define PFX "IOC: "
  37. #define ALLOW_IOV_BYPASS
  38. #define ENABLE_MARK_CLEAN
  39. /*
  40. ** The number of debug flags is a clue - this code is fragile.
  41. */
  42. #undef DEBUG_SBA_INIT
  43. #undef DEBUG_SBA_RUN
  44. #undef DEBUG_SBA_RUN_SG
  45. #undef DEBUG_SBA_RESOURCE
  46. #undef ASSERT_PDIR_SANITY
  47. #undef DEBUG_LARGE_SG_ENTRIES
  48. #undef DEBUG_BYPASS
  49. #define SBA_INLINE __inline__
  50. /* #define SBA_INLINE */
  51. #ifdef DEBUG_SBA_INIT
  52. #define DBG_INIT(x...) printk(x)
  53. #else
  54. #define DBG_INIT(x...)
  55. #endif
  56. #ifdef DEBUG_SBA_RUN
  57. #define DBG_RUN(x...) printk(x)
  58. #else
  59. #define DBG_RUN(x...)
  60. #endif
  61. #ifdef DEBUG_SBA_RUN_SG
  62. #define DBG_RUN_SG(x...) printk(x)
  63. #else
  64. #define DBG_RUN_SG(x...)
  65. #endif
  66. #ifdef DEBUG_SBA_RESOURCE
  67. #define DBG_RES(x...) printk(x)
  68. #else
  69. #define DBG_RES(x...)
  70. #endif
  71. #ifdef DEBUG_BYPASS
  72. #define DBG_BYPASS(x...) printk(x)
  73. #else
  74. #define DBG_BYPASS(x...)
  75. #endif
  76. #ifdef ASSERT_PDIR_SANITY
  77. #define ASSERT(expr) 
  78.         if(!(expr)) { 
  79.                 printk( "n" __FILE__ ":%d: Assertion " #expr " failed!n",__LINE__); 
  80.                 panic(#expr); 
  81.         }
  82. #else
  83. #define ASSERT(expr)
  84. #endif
  85. /*
  86. ** The number of pdir entries to "free" before issueing
  87. ** a read to PCOM register to flush out PCOM writes.
  88. ** Interacts with allocation granularity (ie 4 or 8 entries
  89. ** allocated and free'd/purged at a time might make this
  90. ** less interesting).
  91. */
  92. #define DELAYED_RESOURCE_CNT 16
  93. #define DEFAULT_DMA_HINT_REG 0
  94. #define ZX1_IOC_ID ((PCI_DEVICE_ID_HP_ZX1_IOC << 16) | PCI_VENDOR_ID_HP)
  95. #define REO_IOC_ID ((PCI_DEVICE_ID_HP_REO_IOC << 16) | PCI_VENDOR_ID_HP)
  96. #define ZX1_IOC_OFFSET 0x1000 /* ACPI reports SBA, we want IOC */
  97. #define IOC_FUNC_ID 0x000
  98. #define IOC_FCLASS 0x008 /* function class, bist, header, rev... */
  99. #define IOC_IBASE 0x300 /* IO TLB */
  100. #define IOC_IMASK 0x308
  101. #define IOC_PCOM 0x310
  102. #define IOC_TCNFG 0x318
  103. #define IOC_PDIR_BASE 0x320
  104. /* AGP GART driver looks for this */
  105. #define ZX1_SBA_IOMMU_COOKIE 0x0000badbadc0ffeeUL
  106. /*
  107. ** IOC supports 4/8/16/64KB page sizes (see TCNFG register)
  108. ** It's safer (avoid memory corruption) to keep DMA page mappings
  109. ** equivalently sized to VM PAGE_SIZE.
  110. **
  111. ** We really can't avoid generating a new mapping for each
  112. ** page since the Virtual Coherence Index has to be generated
  113. ** and updated for each page.
  114. **
  115. ** IOVP_SIZE could only be greater than PAGE_SIZE if we are
  116. ** confident the drivers really only touch the next physical
  117. ** page iff that driver instance owns it.
  118. */
  119. #define IOVP_SIZE PAGE_SIZE
  120. #define IOVP_SHIFT PAGE_SHIFT
  121. #define IOVP_MASK PAGE_MASK
  122. struct ioc {
  123. void *ioc_hpa; /* I/O MMU base address */
  124. char *res_map; /* resource map, bit == pdir entry */
  125. u64 *pdir_base; /* physical base address */
  126. unsigned long ibase; /* pdir IOV Space base */
  127. unsigned long imask; /* pdir IOV Space mask */
  128. unsigned long *res_hint; /* next avail IOVP - circular search */
  129. spinlock_t res_lock;
  130. unsigned long hint_mask_pdir; /* bits used for DMA hints */
  131. unsigned int res_bitshift; /* from the RIGHT! */
  132. unsigned int res_size; /* size of resource map in bytes */
  133. unsigned int hint_shift_pdir;
  134. unsigned long dma_mask;
  135. #if DELAYED_RESOURCE_CNT > 0
  136. int saved_cnt;
  137. struct sba_dma_pair {
  138. dma_addr_t iova;
  139. size_t size;
  140. } saved[DELAYED_RESOURCE_CNT];
  141. #endif
  142. #ifdef CONFIG_PROC_FS
  143. #define SBA_SEARCH_SAMPLE 0x100
  144. unsigned long avg_search[SBA_SEARCH_SAMPLE];
  145. unsigned long avg_idx; /* current index into avg_search */
  146. unsigned long used_pages;
  147. unsigned long msingle_calls;
  148. unsigned long msingle_pages;
  149. unsigned long msg_calls;
  150. unsigned long msg_pages;
  151. unsigned long usingle_calls;
  152. unsigned long usingle_pages;
  153. unsigned long usg_calls;
  154. unsigned long usg_pages;
  155. #ifdef ALLOW_IOV_BYPASS
  156. unsigned long msingle_bypass;
  157. unsigned long usingle_bypass;
  158. unsigned long msg_bypass;
  159. #endif
  160. #endif
  161. /* Stuff we don't need in performance path */
  162. struct ioc *next; /* list of IOC's in system */
  163. acpi_handle handle; /* for multiple IOC's */
  164. const char  *name;
  165. unsigned int func_id;
  166. unsigned int rev; /* HW revision of chip */
  167. u32 iov_size;
  168. unsigned int pdir_size; /* in bytes, determined by IOV Space size */
  169. struct pci_dev *sac_only_dev;
  170. };
  171. static struct ioc *ioc_list;
  172. static int reserve_sba_gart = 1;
  173. #define sba_sg_iova(sg) (sg->address)
  174. #define sba_sg_len(sg) (sg->length)
  175. #define sba_sg_buffer(sg) (sg->orig_address)
  176. #define GET_IOC(dev) ((struct ioc *) PCI_CONTROLLER(dev)->iommu)
  177. /*
  178. ** DMA_CHUNK_SIZE is used by the SCSI mid-layer to break up
  179. ** (or rather not merge) DMA's into managable chunks.
  180. ** On parisc, this is more of the software/tuning constraint
  181. ** rather than the HW. I/O MMU allocation alogorithms can be
  182. ** faster with smaller size is (to some degree).
  183. */
  184. #define DMA_CHUNK_SIZE  (BITS_PER_LONG*PAGE_SIZE)
  185. #define ROUNDUP(x,y) ((x + ((y)-1)) & ~((y)-1))
  186. /************************************
  187. ** SBA register read and write support
  188. **
  189. ** BE WARNED: register writes are posted.
  190. **  (ie follow writes which must reach HW with a read)
  191. **
  192. */
  193. #define READ_REG(addr)       __raw_readq(addr)
  194. #define WRITE_REG(val, addr) __raw_writeq(val, addr)
  195. #ifdef DEBUG_SBA_INIT
  196. /**
  197.  * sba_dump_tlb - debugging only - print IOMMU operating parameters
  198.  * @hpa: base address of the IOMMU
  199.  *
  200.  * Print the size/location of the IO MMU PDIR.
  201.  */
  202. static void
  203. sba_dump_tlb(char *hpa)
  204. {
  205. DBG_INIT("IO TLB at 0x%pn", (void *)hpa);
  206. DBG_INIT("IOC_IBASE    : %016lxn", READ_REG(hpa+IOC_IBASE));
  207. DBG_INIT("IOC_IMASK    : %016lxn", READ_REG(hpa+IOC_IMASK));
  208. DBG_INIT("IOC_TCNFG    : %016lxn", READ_REG(hpa+IOC_TCNFG));
  209. DBG_INIT("IOC_PDIR_BASE: %016lxn", READ_REG(hpa+IOC_PDIR_BASE));
  210. DBG_INIT("n");
  211. }
  212. #endif
  213. #ifdef ASSERT_PDIR_SANITY
  214. /**
  215.  * sba_dump_pdir_entry - debugging only - print one IOMMU PDIR entry
  216.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  217.  * @msg: text to print ont the output line.
  218.  * @pide: pdir index.
  219.  *
  220.  * Print one entry of the IO MMU PDIR in human readable form.
  221.  */
  222. static void
  223. sba_dump_pdir_entry(struct ioc *ioc, char *msg, uint pide)
  224. {
  225. /* start printing from lowest pde in rval */
  226. u64 *ptr = &(ioc->pdir_base[pide  & ~(BITS_PER_LONG - 1)]);
  227. unsigned long *rptr = (unsigned long *) &(ioc->res_map[(pide >>3) & ~(sizeof(unsigned long) - 1)]);
  228. uint rcnt;
  229. /* printk(KERN_DEBUG "SBA: %s rp %p bit %d rval 0x%lxn", */
  230. printk("SBA: %s rp %p bit %d rval 0x%lxn",
  231.  msg, rptr, pide & (BITS_PER_LONG - 1), *rptr);
  232. rcnt = 0;
  233. while (rcnt < BITS_PER_LONG) {
  234. printk("%s %2d %p %016Lxn",
  235. (rcnt == (pide & (BITS_PER_LONG - 1)))
  236. ? "    -->" : "       ",
  237. rcnt, ptr, *ptr );
  238. rcnt++;
  239. ptr++;
  240. }
  241. printk("%s", msg);
  242. }
  243. /**
  244.  * sba_check_pdir - debugging only - consistency checker
  245.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  246.  * @msg: text to print ont the output line.
  247.  *
  248.  * Verify the resource map and pdir state is consistent
  249.  */
  250. static int
  251. sba_check_pdir(struct ioc *ioc, char *msg)
  252. {
  253. u64 *rptr_end = (u64 *) &(ioc->res_map[ioc->res_size]);
  254. u64 *rptr = (u64 *) ioc->res_map; /* resource map ptr */
  255. u64 *pptr = ioc->pdir_base; /* pdir ptr */
  256. uint pide = 0;
  257. while (rptr < rptr_end) {
  258. u64 rval;
  259. int rcnt; /* number of bits we might check */
  260. rval = *rptr;
  261. rcnt = 64;
  262. while (rcnt) {
  263. /* Get last byte and highest bit from that */
  264. u32 pde = ((u32)((*pptr >> (63)) & 0x1));
  265. if ((rval & 0x1) ^ pde)
  266. {
  267. /*
  268. ** BUMMER!  -- res_map != pdir --
  269. ** Dump rval and matching pdir entries
  270. */
  271. sba_dump_pdir_entry(ioc, msg, pide);
  272. return(1);
  273. }
  274. rcnt--;
  275. rval >>= 1; /* try the next bit */
  276. pptr++;
  277. pide++;
  278. }
  279. rptr++; /* look at next word of res_map */
  280. }
  281. /* It'd be nice if we always got here :^) */
  282. return 0;
  283. }
  284. /**
  285.  * sba_dump_sg - debugging only - print Scatter-Gather list
  286.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  287.  * @startsg: head of the SG list
  288.  * @nents: number of entries in SG list
  289.  *
  290.  * print the SG list so we can verify it's correct by hand.
  291.  */
  292. static void
  293. sba_dump_sg( struct ioc *ioc, struct scatterlist *startsg, int nents)
  294. {
  295. while (nents-- > 0) {
  296. printk(" %d : %08lx/%05x %pn",
  297. nents,
  298. (unsigned long) sba_sg_iova(startsg),
  299. sba_sg_len(startsg),
  300. sba_sg_buffer(startsg));
  301. startsg++;
  302. }
  303. }
  304. static void
  305. sba_check_sg( struct ioc *ioc, struct scatterlist *startsg, int nents)
  306. {
  307. struct scatterlist *the_sg = startsg;
  308. int the_nents = nents;
  309. while (the_nents-- > 0) {
  310. if (sba_sg_buffer(the_sg) == 0x0UL)
  311. sba_dump_sg(NULL, startsg, nents);
  312. the_sg++;
  313. }
  314. }
  315. #endif /* ASSERT_PDIR_SANITY */
  316. /**************************************************************
  317. *
  318. *   I/O Pdir Resource Management
  319. *
  320. *   Bits set in the resource map are in use.
  321. *   Each bit can represent a number of pages.
  322. *   LSbs represent lower addresses (IOVA's).
  323. *
  324. ***************************************************************/
  325. #define PAGES_PER_RANGE 1 /* could increase this to 4 or 8 if needed */
  326. /* Convert from IOVP to IOVA and vice versa. */
  327. #define SBA_IOVA(ioc,iovp,offset,hint_reg) ((ioc->ibase) | (iovp) | (offset) | ((hint_reg)<<(ioc->hint_shift_pdir)))
  328. #define SBA_IOVP(ioc,iova) (((iova) & ioc->hint_mask_pdir) & ~(ioc->ibase))
  329. /* FIXME : review these macros to verify correctness and usage */
  330. #define PDIR_INDEX(iovp)   ((iovp)>>IOVP_SHIFT)
  331. #define RESMAP_MASK(n)    ~(~0UL << (n))
  332. #define RESMAP_IDX_MASK   (sizeof(unsigned long) - 1)
  333. /**
  334.  * sba_search_bitmap - find free space in IO PDIR resource bitmap
  335.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  336.  * @bits_wanted: number of entries we need.
  337.  *
  338.  * Find consecutive free bits in resource bitmap.
  339.  * Each bit represents one entry in the IO Pdir.
  340.  * Cool perf optimization: search for log2(size) bits at a time.
  341.  */
  342. static SBA_INLINE unsigned long
  343. sba_search_bitmap(struct ioc *ioc, unsigned long bits_wanted)
  344. {
  345. unsigned long *res_ptr = ioc->res_hint;
  346. unsigned long *res_end = (unsigned long *) &(ioc->res_map[ioc->res_size]);
  347. unsigned long pide = ~0UL;
  348. ASSERT(((unsigned long) ioc->res_hint & (sizeof(unsigned long) - 1UL)) == 0);
  349. ASSERT(res_ptr < res_end);
  350. if (bits_wanted > (BITS_PER_LONG/2)) {
  351. /* Search word at a time - no mask needed */
  352. for(; res_ptr < res_end; ++res_ptr) {
  353. if (*res_ptr == 0) {
  354. *res_ptr = RESMAP_MASK(bits_wanted);
  355. pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map);
  356. pide <<= 3; /* convert to bit address */
  357. break;
  358. }
  359. }
  360. /* point to the next word on next pass */
  361. res_ptr++;
  362. ioc->res_bitshift = 0;
  363. } else {
  364. /*
  365. ** Search the resource bit map on well-aligned values.
  366. ** "o" is the alignment.
  367. ** We need the alignment to invalidate I/O TLB using
  368. ** SBA HW features in the unmap path.
  369. */
  370. unsigned long o = 1 << get_order(bits_wanted << PAGE_SHIFT);
  371. uint bitshiftcnt = ROUNDUP(ioc->res_bitshift, o);
  372. unsigned long mask;
  373. if (bitshiftcnt >= BITS_PER_LONG) {
  374. bitshiftcnt = 0;
  375. res_ptr++;
  376. }
  377. mask = RESMAP_MASK(bits_wanted) << bitshiftcnt;
  378. DBG_RES("%s() o %ld %p", __FUNCTION__, o, res_ptr);
  379. while(res_ptr < res_end)
  380. DBG_RES("    %p %lx %lxn", res_ptr, mask, *res_ptr);
  381. ASSERT(0 != mask);
  382. if(0 == ((*res_ptr) & mask)) {
  383. *res_ptr |= mask;     /* mark resources busy! */
  384. pide = ((unsigned long)res_ptr - (unsigned long)ioc->res_map);
  385. pide <<= 3; /* convert to bit address */
  386. pide += bitshiftcnt;
  387. break;
  388. }
  389. mask <<= o;
  390. bitshiftcnt += o;
  391. if (0 == mask) {
  392. mask = RESMAP_MASK(bits_wanted);
  393. bitshiftcnt=0;
  394. res_ptr++;
  395. }
  396. }
  397. /* look in the same word on the next pass */
  398. ioc->res_bitshift = bitshiftcnt + bits_wanted;
  399. }
  400. /* wrapped ? */
  401. if (res_end <= res_ptr) {
  402. ioc->res_hint = (unsigned long *) ioc->res_map;
  403. ioc->res_bitshift = 0;
  404. } else {
  405. ioc->res_hint = res_ptr;
  406. }
  407. return (pide);
  408. }
  409. /**
  410.  * sba_alloc_range - find free bits and mark them in IO PDIR resource bitmap
  411.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  412.  * @size: number of bytes to create a mapping for
  413.  *
  414.  * Given a size, find consecutive unmarked and then mark those bits in the
  415.  * resource bit map.
  416.  */
  417. static int
  418. sba_alloc_range(struct ioc *ioc, size_t size)
  419. {
  420. unsigned int pages_needed = size >> IOVP_SHIFT;
  421. #ifdef CONFIG_PROC_FS
  422. unsigned long itc_start = ia64_get_itc();
  423. #endif
  424. unsigned long pide;
  425. ASSERT(pages_needed);
  426. ASSERT((pages_needed * IOVP_SIZE) <= DMA_CHUNK_SIZE);
  427. ASSERT(pages_needed <= BITS_PER_LONG);
  428. ASSERT(0 == (size & ~IOVP_MASK));
  429. /*
  430. ** "seek and ye shall find"...praying never hurts either...
  431. */
  432. pide = sba_search_bitmap(ioc, pages_needed);
  433. if (pide >= (ioc->res_size << 3)) {
  434. pide = sba_search_bitmap(ioc, pages_needed);
  435. if (pide >= (ioc->res_size << 3))
  436. panic(__FILE__ ": I/O MMU @ %lx is out of mapping resourcesn", ioc->ioc_hpa);
  437. }
  438. #ifdef ASSERT_PDIR_SANITY
  439. /* verify the first enable bit is clear */
  440. if(0x00 != ((u8 *) ioc->pdir_base)[pide*sizeof(u64) + 7]) {
  441. sba_dump_pdir_entry(ioc, "sba_search_bitmap() botched it?", pide);
  442. }
  443. #endif
  444. DBG_RES("%s(%x) %d -> %lx hint %x/%xn",
  445. __FUNCTION__, size, pages_needed, pide,
  446. (uint) ((unsigned long) ioc->res_hint - (unsigned long) ioc->res_map),
  447. ioc->res_bitshift );
  448. #ifdef CONFIG_PROC_FS
  449. {
  450. unsigned long itc_end = ia64_get_itc();
  451. unsigned long tmp = itc_end - itc_start;
  452. /* check for roll over */
  453. itc_start = (itc_end < itc_start) ?  -(tmp) : (tmp);
  454. }
  455. ioc->avg_search[ioc->avg_idx++] = itc_start;
  456. ioc->avg_idx &= SBA_SEARCH_SAMPLE - 1;
  457. ioc->used_pages += pages_needed;
  458. #endif
  459. return (pide);
  460. }
  461. /**
  462.  * sba_free_range - unmark bits in IO PDIR resource bitmap
  463.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  464.  * @iova: IO virtual address which was previously allocated.
  465.  * @size: number of bytes to create a mapping for
  466.  *
  467.  * clear bits in the ioc's resource map
  468.  */
  469. static SBA_INLINE void
  470. sba_free_range(struct ioc *ioc, dma_addr_t iova, size_t size)
  471. {
  472. unsigned long iovp = SBA_IOVP(ioc, iova);
  473. unsigned int pide = PDIR_INDEX(iovp);
  474. unsigned int ridx = pide >> 3; /* convert bit to byte address */
  475. unsigned long *res_ptr = (unsigned long *) &((ioc)->res_map[ridx & ~RESMAP_IDX_MASK]);
  476. int bits_not_wanted = size >> IOVP_SHIFT;
  477. /* 3-bits "bit" address plus 2 (or 3) bits for "byte" == bit in word */
  478. unsigned long m = RESMAP_MASK(bits_not_wanted) << (pide & (BITS_PER_LONG - 1));
  479. DBG_RES("%s( ,%x,%x) %x/%lx %x %p %lxn",
  480. __FUNCTION__, (uint) iova, size,
  481. bits_not_wanted, m, pide, res_ptr, *res_ptr);
  482. #ifdef CONFIG_PROC_FS
  483. ioc->used_pages -= bits_not_wanted;
  484. #endif
  485. ASSERT(m != 0);
  486. ASSERT(bits_not_wanted);
  487. ASSERT((bits_not_wanted * IOVP_SIZE) <= DMA_CHUNK_SIZE);
  488. ASSERT(bits_not_wanted <= BITS_PER_LONG);
  489. ASSERT((*res_ptr & m) == m); /* verify same bits are set */
  490. *res_ptr &= ~m;
  491. }
  492. /**************************************************************
  493. *
  494. *   "Dynamic DMA Mapping" support (aka "Coherent I/O")
  495. *
  496. ***************************************************************/
  497. #define SBA_DMA_HINT(ioc, val) ((val) << (ioc)->hint_shift_pdir)
  498. /**
  499.  * sba_io_pdir_entry - fill in one IO PDIR entry
  500.  * @pdir_ptr:  pointer to IO PDIR entry
  501.  * @vba: Virtual CPU address of buffer to map
  502.  *
  503.  * SBA Mapping Routine
  504.  *
  505.  * Given a virtual address (vba, arg1) sba_io_pdir_entry()
  506.  * loads the I/O PDIR entry pointed to by pdir_ptr (arg0).
  507.  * Each IO Pdir entry consists of 8 bytes as shown below
  508.  * (LSB == bit 0):
  509.  *
  510.  *  63                    40                                 11    7        0
  511.  * +-+---------------------+----------------------------------+----+--------+
  512.  * |V|        U            |            PPN[39:12]            | U  |   FF   |
  513.  * +-+---------------------+----------------------------------+----+--------+
  514.  *
  515.  *  V  == Valid Bit
  516.  *  U  == Unused
  517.  * PPN == Physical Page Number
  518.  *
  519.  * The physical address fields are filled with the results of virt_to_phys()
  520.  * on the vba.
  521.  */
  522. #if 1
  523. #define sba_io_pdir_entry(pdir_ptr, vba) *pdir_ptr = ((vba & ~0xE000000000000FFFULL) | 0x8000000000000000ULL)
  524. #else
  525. void SBA_INLINE
  526. sba_io_pdir_entry(u64 *pdir_ptr, unsigned long vba)
  527. {
  528. *pdir_ptr = ((vba & ~0xE000000000000FFFULL) | 0x80000000000000FFULL);
  529. }
  530. #endif
  531. #ifdef ENABLE_MARK_CLEAN
  532. /**
  533.  * Since DMA is i-cache coherent, any (complete) pages that were written via
  534.  * DMA can be marked as "clean" so that update_mmu_cache() doesn't have to
  535.  * flush them when they get mapped into an executable vm-area.
  536.  */
  537. static void
  538. mark_clean (void *addr, size_t size)
  539. {
  540. unsigned long pg_addr, end;
  541. pg_addr = PAGE_ALIGN((unsigned long) addr);
  542. end = (unsigned long) addr + size;
  543. while (pg_addr + PAGE_SIZE <= end) {
  544. struct page *page = virt_to_page(pg_addr);
  545. set_bit(PG_arch_1, &page->flags);
  546. pg_addr += PAGE_SIZE;
  547. }
  548. }
  549. #endif
  550. /**
  551.  * sba_mark_invalid - invalidate one or more IO PDIR entries
  552.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  553.  * @iova:  IO Virtual Address mapped earlier
  554.  * @byte_cnt:  number of bytes this mapping covers.
  555.  *
  556.  * Marking the IO PDIR entry(ies) as Invalid and invalidate
  557.  * corresponding IO TLB entry. The PCOM (Purge Command Register)
  558.  * is to purge stale entries in the IO TLB when unmapping entries.
  559.  *
  560.  * The PCOM register supports purging of multiple pages, with a minium
  561.  * of 1 page and a maximum of 2GB. Hardware requires the address be
  562.  * aligned to the size of the range being purged. The size of the range
  563.  * must be a power of 2. The "Cool perf optimization" in the
  564.  * allocation routine helps keep that true.
  565.  */
  566. static SBA_INLINE void
  567. sba_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
  568. {
  569. u32 iovp = (u32) SBA_IOVP(ioc,iova);
  570. int off = PDIR_INDEX(iovp);
  571. /* Must be non-zero and rounded up */
  572. ASSERT(byte_cnt > 0);
  573. ASSERT(0 == (byte_cnt & ~IOVP_MASK));
  574. #ifdef ASSERT_PDIR_SANITY
  575. /* Assert first pdir entry is set */
  576. if (!(ioc->pdir_base[off] >> 60)) {
  577. sba_dump_pdir_entry(ioc,"sba_mark_invalid()", PDIR_INDEX(iovp));
  578. }
  579. #endif
  580. if (byte_cnt <= IOVP_SIZE)
  581. {
  582. ASSERT(off < ioc->pdir_size);
  583. iovp |= IOVP_SHIFT;     /* set "size" field for PCOM */
  584. /*
  585. ** clear I/O PDIR entry "valid" bit
  586. ** Do NOT clear the rest - save it for debugging.
  587. ** We should only clear bits that have previously
  588. ** been enabled.
  589. */
  590. ioc->pdir_base[off] &= ~(0x80000000000000FFULL);
  591. } else {
  592. u32 t = get_order(byte_cnt) + PAGE_SHIFT;
  593. iovp |= t;
  594. ASSERT(t <= 31);   /* 2GB! Max value of "size" field */
  595. do {
  596. /* verify this pdir entry is enabled */
  597. ASSERT(ioc->pdir_base[off]  >> 63);
  598. /* clear I/O Pdir entry "valid" bit first */
  599. ioc->pdir_base[off] &= ~(0x80000000000000FFULL);
  600. off++;
  601. byte_cnt -= IOVP_SIZE;
  602. } while (byte_cnt > 0);
  603. }
  604. WRITE_REG(iovp, ioc->ioc_hpa+IOC_PCOM);
  605. }
  606. /**
  607.  * sba_map_single - map one buffer and return IOVA for DMA
  608.  * @dev: instance of PCI owned by the driver that's asking.
  609.  * @addr:  driver buffer to map.
  610.  * @size:  number of bytes to map in driver buffer.
  611.  * @direction:  R/W or both.
  612.  *
  613.  * See Documentation/DMA-mapping.txt
  614.  */
  615. dma_addr_t
  616. sba_map_single(struct pci_dev *dev, void *addr, size_t size, int direction)
  617. {
  618. struct ioc *ioc;
  619. unsigned long flags; 
  620. dma_addr_t iovp;
  621. dma_addr_t offset;
  622. u64 *pdir_start;
  623. int pide;
  624. #ifdef ALLOW_IOV_BYPASS
  625. unsigned long pci_addr = virt_to_phys(addr);
  626. #endif
  627. ioc = GET_IOC(dev);
  628. ASSERT(ioc);
  629. #ifdef ALLOW_IOV_BYPASS
  630. /*
  631.   ** Check if the PCI device can DMA to ptr... if so, just return ptr
  632.   */
  633. if ((pci_addr & ~dev->dma_mask) == 0) {
  634. /*
  635.   ** Device is bit capable of DMA'ing to the buffer...
  636. ** just return the PCI address of ptr
  637.   */
  638. #ifdef CONFIG_PROC_FS
  639. spin_lock_irqsave(&ioc->res_lock, flags);
  640. ioc->msingle_bypass++;
  641. spin_unlock_irqrestore(&ioc->res_lock, flags);
  642. #endif
  643. DBG_BYPASS("sba_map_single() bypass mask/addr: 0x%lx/0x%lxn",
  644.            dev->dma_mask, pci_addr);
  645. return pci_addr;
  646. }
  647. #endif
  648. ASSERT(size > 0);
  649. ASSERT(size <= DMA_CHUNK_SIZE);
  650. /* save offset bits */
  651. offset = ((dma_addr_t) (long) addr) & ~IOVP_MASK;
  652. /* round up to nearest IOVP_SIZE */
  653. size = (size + offset + ~IOVP_MASK) & IOVP_MASK;
  654. spin_lock_irqsave(&ioc->res_lock, flags);
  655. #ifdef ASSERT_PDIR_SANITY
  656. if (sba_check_pdir(ioc,"Check before sba_map_single()"))
  657. panic("Sanity check failed");
  658. #endif
  659. #ifdef CONFIG_PROC_FS
  660. ioc->msingle_calls++;
  661. ioc->msingle_pages += size >> IOVP_SHIFT;
  662. #endif
  663. pide = sba_alloc_range(ioc, size);
  664. iovp = (dma_addr_t) pide << IOVP_SHIFT;
  665. DBG_RUN("%s() 0x%p -> 0x%lxn",
  666. __FUNCTION__, addr, (long) iovp | offset);
  667. pdir_start = &(ioc->pdir_base[pide]);
  668. while (size > 0) {
  669. ASSERT(((u8 *)pdir_start)[7] == 0); /* verify availability */
  670. sba_io_pdir_entry(pdir_start, (unsigned long) addr);
  671. DBG_RUN("     pdir 0x%p %lxn", pdir_start, *pdir_start);
  672. addr += IOVP_SIZE;
  673. size -= IOVP_SIZE;
  674. pdir_start++;
  675. }
  676. /* form complete address */
  677. #ifdef ASSERT_PDIR_SANITY
  678. sba_check_pdir(ioc,"Check after sba_map_single()");
  679. #endif
  680. spin_unlock_irqrestore(&ioc->res_lock, flags);
  681. return SBA_IOVA(ioc, iovp, offset, DEFAULT_DMA_HINT_REG);
  682. }
  683. /**
  684.  * sba_unmap_single - unmap one IOVA and free resources
  685.  * @dev: instance of PCI owned by the driver that's asking.
  686.  * @iova:  IOVA of driver buffer previously mapped.
  687.  * @size:  number of bytes mapped in driver buffer.
  688.  * @direction:  R/W or both.
  689.  *
  690.  * See Documentation/DMA-mapping.txt
  691.  */
  692. void sba_unmap_single(struct pci_dev *dev, dma_addr_t iova, size_t size,
  693. int direction)
  694. {
  695. struct ioc *ioc;
  696. #if DELAYED_RESOURCE_CNT > 0
  697. struct sba_dma_pair *d;
  698. #endif
  699. unsigned long flags; 
  700. dma_addr_t offset;
  701. ioc = GET_IOC(dev);
  702. ASSERT(ioc);
  703. #ifdef ALLOW_IOV_BYPASS
  704. if ((iova & ioc->imask) != ioc->ibase) {
  705. /*
  706. ** Address does not fall w/in IOVA, must be bypassing
  707. */
  708. #ifdef CONFIG_PROC_FS
  709. spin_lock_irqsave(&ioc->res_lock, flags);
  710. ioc->usingle_bypass++;
  711. spin_unlock_irqrestore(&ioc->res_lock, flags);
  712. #endif
  713. DBG_BYPASS("sba_unmap_single() bypass addr: 0x%lxn", iova);
  714. #ifdef ENABLE_MARK_CLEAN
  715. if (direction == PCI_DMA_FROMDEVICE) {
  716. mark_clean(phys_to_virt(iova), size);
  717. }
  718. #endif
  719. return;
  720. }
  721. #endif
  722. offset = iova & ~IOVP_MASK;
  723. DBG_RUN("%s() iovp 0x%lx/%xn",
  724. __FUNCTION__, (long) iova, size);
  725. iova ^= offset;        /* clear offset bits */
  726. size += offset;
  727. size = ROUNDUP(size, IOVP_SIZE);
  728. spin_lock_irqsave(&ioc->res_lock, flags);
  729. #ifdef CONFIG_PROC_FS
  730. ioc->usingle_calls++;
  731. ioc->usingle_pages += size >> IOVP_SHIFT;
  732. #endif
  733. #if DELAYED_RESOURCE_CNT > 0
  734. d = &(ioc->saved[ioc->saved_cnt]);
  735. d->iova = iova;
  736. d->size = size;
  737. if (++(ioc->saved_cnt) >= DELAYED_RESOURCE_CNT) {
  738. int cnt = ioc->saved_cnt;
  739. while (cnt--) {
  740. sba_mark_invalid(ioc, d->iova, d->size);
  741. sba_free_range(ioc, d->iova, d->size);
  742. d--;
  743. }
  744. ioc->saved_cnt = 0;
  745. READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */
  746. }
  747. #else /* DELAYED_RESOURCE_CNT == 0 */
  748. sba_mark_invalid(ioc, iova, size);
  749. sba_free_range(ioc, iova, size);
  750. READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */
  751. #endif /* DELAYED_RESOURCE_CNT == 0 */
  752. #ifdef ENABLE_MARK_CLEAN
  753. if (direction == PCI_DMA_FROMDEVICE) {
  754. u32 iovp = (u32) SBA_IOVP(ioc,iova);
  755. int off = PDIR_INDEX(iovp);
  756. void *addr;
  757. if (size <= IOVP_SIZE) {
  758. addr = phys_to_virt(ioc->pdir_base[off] &
  759.     ~0xE000000000000FFFULL);
  760. mark_clean(addr, size);
  761. } else {
  762. size_t byte_cnt = size;
  763. do {
  764. addr = phys_to_virt(ioc->pdir_base[off] &
  765.                     ~0xE000000000000FFFULL);
  766. mark_clean(addr, min(byte_cnt, IOVP_SIZE));
  767. off++;
  768. byte_cnt -= IOVP_SIZE;
  769.    } while (byte_cnt > 0);
  770. }
  771. }
  772. #endif
  773. spin_unlock_irqrestore(&ioc->res_lock, flags);
  774. /* XXX REVISIT for 2.5 Linux - need syncdma for zero-copy support.
  775. ** For Astro based systems this isn't a big deal WRT performance.
  776. ** As long as 2.4 kernels copyin/copyout data from/to userspace,
  777. ** we don't need the syncdma. The issue here is I/O MMU cachelines
  778. ** are *not* coherent in all cases.  May be hwrev dependent.
  779. ** Need to investigate more.
  780. asm volatile("syncdma");
  781. */
  782. }
  783. /**
  784.  * sba_alloc_consistent - allocate/map shared mem for DMA
  785.  * @hwdev: instance of PCI owned by the driver that's asking.
  786.  * @size:  number of bytes mapped in driver buffer.
  787.  * @dma_handle:  IOVA of new buffer.
  788.  *
  789.  * See Documentation/DMA-mapping.txt
  790.  */
  791. void *
  792. sba_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
  793. {
  794. struct ioc *ioc;
  795. void *ret;
  796. if (!hwdev) {
  797. /* only support PCI */
  798. *dma_handle = 0;
  799. return 0;
  800. }
  801.         ret = (void *) __get_free_pages(GFP_ATOMIC, get_order(size));
  802. if (ret) {
  803. memset(ret, 0, size);
  804. /*
  805.  * REVISIT: if sba_map_single starts needing more
  806.  * than dma_mask from the device, this needs to be
  807.  * updated.
  808.  */
  809. ioc = GET_IOC(hwdev);
  810. *dma_handle = sba_map_single(ioc->sac_only_dev, ret, size, 0);
  811. }
  812. return ret;
  813. }
  814. /**
  815.  * sba_free_consistent - free/unmap shared mem for DMA
  816.  * @hwdev: instance of PCI owned by the driver that's asking.
  817.  * @size:  number of bytes mapped in driver buffer.
  818.  * @vaddr:  virtual address IOVA of "consistent" buffer.
  819.  * @dma_handler:  IO virtual address of "consistent" buffer.
  820.  *
  821.  * See Documentation/DMA-mapping.txt
  822.  */
  823. void sba_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr,
  824. dma_addr_t dma_handle)
  825. {
  826. sba_unmap_single(hwdev, dma_handle, size, 0);
  827. free_pages((unsigned long) vaddr, get_order(size));
  828. }
  829. /*
  830. ** Since 0 is a valid pdir_base index value, can't use that
  831. ** to determine if a value is valid or not. Use a flag to indicate
  832. ** the SG list entry contains a valid pdir index.
  833. */
  834. #define PIDE_FLAG 0x1UL
  835. #ifdef DEBUG_LARGE_SG_ENTRIES
  836. int dump_run_sg = 0;
  837. #endif
  838. /**
  839.  * sba_fill_pdir - write allocated SG entries into IO PDIR
  840.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  841.  * @startsg:  list of IOVA/size pairs
  842.  * @nents: number of entries in startsg list
  843.  *
  844.  * Take preprocessed SG list and write corresponding entries
  845.  * in the IO PDIR.
  846.  */
  847. static SBA_INLINE int
  848. sba_fill_pdir(
  849. struct ioc *ioc,
  850. struct scatterlist *startsg,
  851. int nents)
  852. {
  853. struct scatterlist *dma_sg = startsg; /* pointer to current DMA */
  854. int n_mappings = 0;
  855. u64 *pdirp = 0;
  856. unsigned long dma_offset = 0;
  857. dma_sg--;
  858. while (nents-- > 0) {
  859. int     cnt = sba_sg_len(startsg);
  860. sba_sg_len(startsg) = 0;
  861. #ifdef DEBUG_LARGE_SG_ENTRIES
  862. if (dump_run_sg)
  863. printk(" %2d : %08lx/%05x %pn",
  864. nents,
  865. (unsigned long) sba_sg_iova(startsg), cnt,
  866. sba_sg_buffer(startsg)
  867. );
  868. #else
  869. DBG_RUN_SG(" %d : %08lx/%05x %pn",
  870. nents,
  871. (unsigned long) sba_sg_iova(startsg), cnt,
  872. sba_sg_buffer(startsg)
  873. );
  874. #endif
  875. /*
  876. ** Look for the start of a new DMA stream
  877. */
  878. if ((u64)sba_sg_iova(startsg) & PIDE_FLAG) {
  879. u32 pide = (u64)sba_sg_iova(startsg) & ~PIDE_FLAG;
  880. dma_offset = (unsigned long) pide & ~IOVP_MASK;
  881. sba_sg_iova(startsg) = 0;
  882. dma_sg++;
  883. sba_sg_iova(dma_sg) = (char *)(pide | ioc->ibase);
  884. pdirp = &(ioc->pdir_base[pide >> IOVP_SHIFT]);
  885. n_mappings++;
  886. }
  887. /*
  888. ** Look for a VCONTIG chunk
  889. */
  890. if (cnt) {
  891. unsigned long vaddr = (unsigned long) sba_sg_buffer(startsg);
  892. ASSERT(pdirp);
  893. /* Since multiple Vcontig blocks could make up
  894. ** one DMA stream, *add* cnt to dma_len.
  895. */
  896. sba_sg_len(dma_sg) += cnt;
  897. cnt += dma_offset;
  898. dma_offset=0; /* only want offset on first chunk */
  899. cnt = ROUNDUP(cnt, IOVP_SIZE);
  900. #ifdef CONFIG_PROC_FS
  901. ioc->msg_pages += cnt >> IOVP_SHIFT;
  902. #endif
  903. do {
  904. sba_io_pdir_entry(pdirp, vaddr);
  905. vaddr += IOVP_SIZE;
  906. cnt -= IOVP_SIZE;
  907. pdirp++;
  908. } while (cnt > 0);
  909. }
  910. startsg++;
  911. }
  912. #ifdef DEBUG_LARGE_SG_ENTRIES
  913. dump_run_sg = 0;
  914. #endif
  915. return(n_mappings);
  916. }
  917. /*
  918. ** Two address ranges are DMA contiguous *iff* "end of prev" and
  919. ** "start of next" are both on a page boundry.
  920. **
  921. ** (shift left is a quick trick to mask off upper bits)
  922. */
  923. #define DMA_CONTIG(__X, __Y) 
  924. (((((unsigned long) __X) | ((unsigned long) __Y)) << (BITS_PER_LONG - PAGE_SHIFT)) == 0UL)
  925. /**
  926.  * sba_coalesce_chunks - preprocess the SG list
  927.  * @ioc: IO MMU structure which owns the pdir we are interested in.
  928.  * @startsg:  list of IOVA/size pairs
  929.  * @nents: number of entries in startsg list
  930.  *
  931.  * First pass is to walk the SG list and determine where the breaks are
  932.  * in the DMA stream. Allocates PDIR entries but does not fill them.
  933.  * Returns the number of DMA chunks.
  934.  *
  935.  * Doing the fill seperate from the coalescing/allocation keeps the
  936.  * code simpler. Future enhancement could make one pass through
  937.  * the sglist do both.
  938.  */
  939. static SBA_INLINE int
  940. sba_coalesce_chunks( struct ioc *ioc,
  941. struct scatterlist *startsg,
  942. int nents)
  943. {
  944. struct scatterlist *vcontig_sg;    /* VCONTIG chunk head */
  945. unsigned long vcontig_len;         /* len of VCONTIG chunk */
  946. unsigned long vcontig_end;
  947. struct scatterlist *dma_sg;        /* next DMA stream head */
  948. unsigned long dma_offset, dma_len; /* start/len of DMA stream */
  949. int n_mappings = 0;
  950. while (nents > 0) {
  951. unsigned long vaddr = (unsigned long) (startsg->address); 
  952. /*
  953. ** Prepare for first/next DMA stream
  954. */
  955. dma_sg = vcontig_sg = startsg;
  956. dma_len = vcontig_len = vcontig_end = sba_sg_len(startsg);
  957. vcontig_end +=  vaddr;
  958. dma_offset = vaddr & ~IOVP_MASK;
  959. /* PARANOID: clear entries */
  960. sba_sg_buffer(startsg) = sba_sg_iova(startsg);
  961. sba_sg_iova(startsg) = 0;
  962. sba_sg_len(startsg) = 0;
  963. /*
  964. ** This loop terminates one iteration "early" since
  965. ** it's always looking one "ahead".
  966. */
  967. while (--nents > 0) {
  968. unsigned long vaddr; /* tmp */
  969. startsg++;
  970. /* catch brokenness in SCSI layer */
  971. ASSERT(startsg->length <= DMA_CHUNK_SIZE);
  972. /*
  973. ** First make sure current dma stream won't
  974. ** exceed DMA_CHUNK_SIZE if we coalesce the
  975. ** next entry.
  976. */
  977. if (((dma_len + dma_offset + startsg->length + ~IOVP_MASK) & IOVP_MASK) > DMA_CHUNK_SIZE)
  978. break;
  979. /*
  980. ** Then look for virtually contiguous blocks.
  981. **
  982. ** append the next transaction?
  983. */
  984. vaddr = (unsigned long) sba_sg_iova(startsg);
  985. if  (vcontig_end == vaddr)
  986. {
  987. vcontig_len += sba_sg_len(startsg);
  988. vcontig_end += sba_sg_len(startsg);
  989. dma_len     += sba_sg_len(startsg);
  990. sba_sg_buffer(startsg) = (char *)vaddr;
  991. sba_sg_iova(startsg) = 0;
  992. sba_sg_len(startsg) = 0;
  993. continue;
  994. }
  995. #ifdef DEBUG_LARGE_SG_ENTRIES
  996. dump_run_sg = (vcontig_len > IOVP_SIZE);
  997. #endif
  998. /*
  999. ** Not virtually contigous.
  1000. ** Terminate prev chunk.
  1001. ** Start a new chunk.
  1002. **
  1003. ** Once we start a new VCONTIG chunk, dma_offset
  1004. ** can't change. And we need the offset from the first
  1005. ** chunk - not the last one. Ergo Successive chunks
  1006. ** must start on page boundaries and dove tail
  1007. ** with it's predecessor.
  1008. */
  1009. sba_sg_len(vcontig_sg) = vcontig_len;
  1010. vcontig_sg = startsg;
  1011. vcontig_len = sba_sg_len(startsg);
  1012. /*
  1013. ** 3) do the entries end/start on page boundaries?
  1014. **    Don't update vcontig_end until we've checked.
  1015. */
  1016. if (DMA_CONTIG(vcontig_end, vaddr))
  1017. {
  1018. vcontig_end = vcontig_len + vaddr;
  1019. dma_len += vcontig_len;
  1020. sba_sg_buffer(startsg) = (char *)vaddr;
  1021. sba_sg_iova(startsg) = 0;
  1022. continue;
  1023. } else {
  1024. break;
  1025. }
  1026. }
  1027. /*
  1028. ** End of DMA Stream
  1029. ** Terminate last VCONTIG block.
  1030. ** Allocate space for DMA stream.
  1031. */
  1032. sba_sg_len(vcontig_sg) = vcontig_len;
  1033. dma_len = (dma_len + dma_offset + ~IOVP_MASK) & IOVP_MASK;
  1034. ASSERT(dma_len <= DMA_CHUNK_SIZE);
  1035. sba_sg_iova(dma_sg) = (char *) (PIDE_FLAG 
  1036. | (sba_alloc_range(ioc, dma_len) << IOVP_SHIFT)
  1037. | dma_offset);
  1038. n_mappings++;
  1039. }
  1040. return n_mappings;
  1041. }
  1042. /**
  1043.  * sba_map_sg - map Scatter/Gather list
  1044.  * @dev: instance of PCI owned by the driver that's asking.
  1045.  * @sglist:  array of buffer/length pairs
  1046.  * @nents:  number of entries in list
  1047.  * @direction:  R/W or both.
  1048.  *
  1049.  * See Documentation/DMA-mapping.txt
  1050.  */
  1051. int sba_map_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents,
  1052. int direction)
  1053. {
  1054. struct ioc *ioc;
  1055. int coalesced, filled = 0;
  1056. unsigned long flags;
  1057. #ifdef ALLOW_IOV_BYPASS
  1058. struct scatterlist *sg;
  1059. #endif
  1060. DBG_RUN_SG("%s() START %d entriesn", __FUNCTION__, nents);
  1061. ioc = GET_IOC(dev);
  1062. ASSERT(ioc);
  1063. #ifdef ALLOW_IOV_BYPASS
  1064. if (dev->dma_mask >= ioc->dma_mask) {
  1065. for (sg = sglist ; filled < nents ; filled++, sg++){
  1066. sba_sg_buffer(sg) = sba_sg_iova(sg);
  1067. sba_sg_iova(sg) = (char *)virt_to_phys(sba_sg_buffer(sg));
  1068. }
  1069. #ifdef CONFIG_PROC_FS
  1070. spin_lock_irqsave(&ioc->res_lock, flags);
  1071. ioc->msg_bypass++;
  1072. spin_unlock_irqrestore(&ioc->res_lock, flags);
  1073. #endif
  1074. return filled;
  1075. }
  1076. #endif
  1077. /* Fast path single entry scatterlists. */
  1078. if (nents == 1) {
  1079. sba_sg_buffer(sglist) = sba_sg_iova(sglist);
  1080. sba_sg_iova(sglist) = (char *)sba_map_single(dev,
  1081. sba_sg_buffer(sglist),
  1082. sba_sg_len(sglist), direction);
  1083. #ifdef CONFIG_PROC_FS
  1084. /*
  1085. ** Should probably do some stats counting, but trying to
  1086. ** be precise quickly starts wasting CPU time.
  1087. */
  1088. #endif
  1089. return 1;
  1090. }
  1091. spin_lock_irqsave(&ioc->res_lock, flags);
  1092. #ifdef ASSERT_PDIR_SANITY
  1093. if (sba_check_pdir(ioc,"Check before sba_map_sg()"))
  1094. {
  1095. sba_dump_sg(ioc, sglist, nents);
  1096. panic("Check before sba_map_sg()");
  1097. }
  1098. #endif
  1099. #ifdef CONFIG_PROC_FS
  1100. ioc->msg_calls++;
  1101. #endif
  1102. /*
  1103. ** First coalesce the chunks and allocate I/O pdir space
  1104. **
  1105. ** If this is one DMA stream, we can properly map using the
  1106. ** correct virtual address associated with each DMA page.
  1107. ** w/o this association, we wouldn't have coherent DMA!
  1108. ** Access to the virtual address is what forces a two pass algorithm.
  1109. */
  1110. coalesced = sba_coalesce_chunks(ioc, sglist, nents);
  1111.  
  1112. /*
  1113. ** Program the I/O Pdir
  1114. **
  1115. ** map the virtual addresses to the I/O Pdir
  1116. ** o dma_address will contain the pdir index
  1117. ** o dma_len will contain the number of bytes to map 
  1118. ** o address contains the virtual address.
  1119. */
  1120. filled = sba_fill_pdir(ioc, sglist, nents);
  1121. #ifdef ASSERT_PDIR_SANITY
  1122. if (sba_check_pdir(ioc,"Check after sba_map_sg()"))
  1123. {
  1124. sba_dump_sg(ioc, sglist, nents);
  1125. panic("Check after sba_map_sg()n");
  1126. }
  1127. #endif
  1128. spin_unlock_irqrestore(&ioc->res_lock, flags);
  1129. ASSERT(coalesced == filled);
  1130. DBG_RUN_SG("%s() DONE %d mappingsn", __FUNCTION__, filled);
  1131. return filled;
  1132. }
  1133. /**
  1134.  * sba_unmap_sg - unmap Scatter/Gather list
  1135.  * @dev: instance of PCI owned by the driver that's asking.
  1136.  * @sglist:  array of buffer/length pairs
  1137.  * @nents:  number of entries in list
  1138.  * @direction:  R/W or both.
  1139.  *
  1140.  * See Documentation/DMA-mapping.txt
  1141.  */
  1142. void sba_unmap_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents,
  1143. int direction)
  1144. {
  1145. struct ioc *ioc;
  1146. #ifdef ASSERT_PDIR_SANITY
  1147. unsigned long flags;
  1148. #endif
  1149. DBG_RUN_SG("%s() START %d entries,  %p,%xn",
  1150. __FUNCTION__, nents, sba_sg_buffer(sglist), sglist->length);
  1151. ioc = GET_IOC(dev);
  1152. ASSERT(ioc);
  1153. #ifdef CONFIG_PROC_FS
  1154. ioc->usg_calls++;
  1155. #endif
  1156. #ifdef ASSERT_PDIR_SANITY
  1157. spin_lock_irqsave(&ioc->res_lock, flags);
  1158. sba_check_pdir(ioc,"Check before sba_unmap_sg()");
  1159. spin_unlock_irqrestore(&ioc->res_lock, flags);
  1160. #endif
  1161. while (sba_sg_len(sglist) && nents--) {
  1162. sba_unmap_single(dev, (dma_addr_t)sba_sg_iova(sglist),
  1163.                  sba_sg_len(sglist), direction);
  1164. #ifdef CONFIG_PROC_FS
  1165. /*
  1166. ** This leaves inconsistent data in the stats, but we can't
  1167. ** tell which sg lists were mapped by map_single and which
  1168. ** were coalesced to a single entry.  The stats are fun,
  1169. ** but speed is more important.
  1170. */
  1171. ioc->usg_pages += (((u64)sba_sg_iova(sglist) & ~IOVP_MASK) + sba_sg_len(sglist) + IOVP_SIZE - 1) >> PAGE_SHIFT;
  1172. #endif
  1173. ++sglist;
  1174. }
  1175. DBG_RUN_SG("%s() DONE (nents %d)n", __FUNCTION__,  nents);
  1176. #ifdef ASSERT_PDIR_SANITY
  1177. spin_lock_irqsave(&ioc->res_lock, flags);
  1178. sba_check_pdir(ioc,"Check after sba_unmap_sg()");
  1179. spin_unlock_irqrestore(&ioc->res_lock, flags);
  1180. #endif
  1181. }
  1182. unsigned long
  1183. sba_dma_address (struct scatterlist *sg)
  1184. {
  1185. return ((unsigned long)sba_sg_iova(sg));
  1186. }
  1187. int
  1188. sba_dma_supported (struct pci_dev *dev, u64 mask)
  1189. {
  1190. return 1;
  1191. }
  1192. /**************************************************************
  1193. *
  1194. *   Initialization and claim
  1195. *
  1196. ***************************************************************/
  1197. static void __init
  1198. ioc_iova_init(struct ioc *ioc)
  1199. {
  1200. u32 iova_space_mask;
  1201. int iov_order, tcnfg;
  1202. int agp_found = 0;
  1203. struct pci_dev *device;
  1204. /*
  1205. ** Firmware programs the base and size of a "safe IOVA space"
  1206. ** (one that doesn't overlap memory or LMMIO space) in the
  1207. ** IBASE and IMASK registers.
  1208. */
  1209. ioc->ibase = READ_REG(ioc->ioc_hpa + IOC_IBASE) & ~0x1UL;
  1210. ioc->iov_size = ~(READ_REG(ioc->ioc_hpa + IOC_IMASK) & 0xFFFFFFFFUL) + 1;
  1211. if (ioc->ibase == 0) {
  1212. if (((unsigned long) ioc->ioc_hpa & 0x3000UL) == 0x2000)
  1213. ioc->ibase = 0xc0000000;
  1214. else
  1215. ioc->ibase = 0x80000000;
  1216. printk("WARNING: IBASE is zero; setting to 0x%lxn", ioc->ibase);
  1217. }
  1218. if (ioc->ibase < 0xfed00000UL && ioc->ibase + ioc->iov_size >= 0xfee00000UL) {
  1219. printk("WARNING: IOV space overlaps local config and interrupt message, truncatingn");
  1220. ioc->iov_size /= 2;
  1221. }
  1222. /*
  1223. ** iov_order is always based on a 1GB IOVA space since we want to
  1224. ** turn on the other half for AGP GART.
  1225. */
  1226. iov_order = get_order(ioc->iov_size >> (IOVP_SHIFT - PAGE_SHIFT));
  1227. ioc->pdir_size = (ioc->iov_size / IOVP_SIZE) * sizeof(u64);
  1228. DBG_INIT("%s() hpa 0x%lx IOV %dMB (%d bits) PDIR size 0x%0xn",
  1229. __FUNCTION__, ioc->ioc_hpa, ioc->iov_size >> 20,
  1230. iov_order + PAGE_SHIFT, ioc->pdir_size);
  1231. /* FIXME : DMA HINTs not used */
  1232. ioc->hint_shift_pdir = iov_order + PAGE_SHIFT;
  1233. ioc->hint_mask_pdir = ~(0x3 << (iov_order + PAGE_SHIFT));
  1234. ioc->pdir_base = (void *) __get_free_pages(GFP_KERNEL,
  1235.    get_order(ioc->pdir_size));
  1236. if (!ioc->pdir_base)
  1237. panic(PFX "Couldn't allocate I/O Page Tablen");
  1238. memset(ioc->pdir_base, 0, ioc->pdir_size);
  1239. DBG_INIT("%s() pdir %p size %x hint_shift_pdir %x hint_mask_pdir %lxn",
  1240. __FUNCTION__, ioc->pdir_base, ioc->pdir_size,
  1241. ioc->hint_shift_pdir, ioc->hint_mask_pdir);
  1242. ASSERT((((unsigned long) ioc->pdir_base) & PAGE_MASK) == (unsigned long) ioc->pdir_base);
  1243. WRITE_REG(virt_to_phys(ioc->pdir_base), ioc->ioc_hpa + IOC_PDIR_BASE);
  1244. DBG_INIT(" base %pn", ioc->pdir_base);
  1245. /* build IMASK for IOC and Elroy */
  1246. iova_space_mask =  0xffffffff;
  1247. iova_space_mask <<= (iov_order + PAGE_SHIFT);
  1248. ioc->imask = iova_space_mask;
  1249. DBG_INIT("%s() IOV base 0x%lx mask 0x%0lxn",
  1250. __FUNCTION__, ioc->ibase, ioc->imask);
  1251. /*
  1252. ** FIXME: Hint registers are programmed with default hint
  1253. ** values during boot, so hints should be sane even if we
  1254. ** can't reprogram them the way drivers want.
  1255. */
  1256. WRITE_REG(ioc->imask, ioc->ioc_hpa + IOC_IMASK);
  1257. /*
  1258. ** Setting the upper bits makes checking for bypass addresses
  1259. ** a little faster later on.
  1260. */
  1261. ioc->imask |= 0xFFFFFFFF00000000UL;
  1262. /* Set I/O PDIR Page size to system page size */
  1263. switch (PAGE_SHIFT) {
  1264. case 12: tcnfg = 0; break; /*  4K */
  1265. case 13: tcnfg = 1; break; /*  8K */
  1266. case 14: tcnfg = 2; break; /* 16K */
  1267. case 16: tcnfg = 3; break; /* 64K */
  1268. default:
  1269. panic(PFX "Unsupported system page size %d",
  1270. 1 << PAGE_SHIFT);
  1271. break;
  1272. }
  1273. WRITE_REG(tcnfg, ioc->ioc_hpa + IOC_TCNFG);
  1274. /*
  1275. ** Program the IOC's ibase and enable IOVA translation
  1276. ** Bit zero == enable bit.
  1277. */
  1278. WRITE_REG(ioc->ibase | 1, ioc->ioc_hpa + IOC_IBASE);
  1279. /*
  1280. ** Clear I/O TLB of any possible entries.
  1281. ** (Yes. This is a bit paranoid...but so what)
  1282. */
  1283. WRITE_REG(0 | 31, ioc->ioc_hpa + IOC_PCOM);
  1284. /*
  1285. ** If an AGP device is present, only use half of the IOV space
  1286. ** for PCI DMA.  Unfortunately we can't know ahead of time
  1287. ** whether GART support will actually be used, for now we
  1288. ** can just key on an AGP device found in the system.
  1289. ** We program the next pdir index after we stop w/ a key for
  1290. ** the GART code to handshake on.
  1291. */
  1292. pci_for_each_dev(device)
  1293. agp_found |= pci_find_capability(device, PCI_CAP_ID_AGP);
  1294. if (agp_found && reserve_sba_gart) {
  1295. DBG_INIT("%s: AGP device found, reserving half of IOVA for GART supportn", __FUNCTION__);
  1296. ioc->pdir_size /= 2;
  1297. ((u64 *)ioc->pdir_base)[PDIR_INDEX(ioc->iov_size/2)] = ZX1_SBA_IOMMU_COOKIE;
  1298. }
  1299. }
  1300. static void __init
  1301. ioc_resource_init(struct ioc *ioc)
  1302. {
  1303. spin_lock_init(&ioc->res_lock);
  1304. /* resource map size dictated by pdir_size */
  1305. ioc->res_size = ioc->pdir_size / sizeof(u64); /* entries */
  1306. ioc->res_size >>= 3;  /* convert bit count to byte count */
  1307. DBG_INIT("%s() res_size 0x%xn", __FUNCTION__, ioc->res_size);
  1308. ioc->res_map = (char *) __get_free_pages(GFP_KERNEL,
  1309.  get_order(ioc->res_size));
  1310. if (!ioc->res_map)
  1311. panic(PFX "Couldn't allocate resource mapn");
  1312. memset(ioc->res_map, 0, ioc->res_size);
  1313. /* next available IOVP - circular search */
  1314. ioc->res_hint = (unsigned long *) ioc->res_map;
  1315. #ifdef ASSERT_PDIR_SANITY
  1316. /* Mark first bit busy - ie no IOVA 0 */
  1317. ioc->res_map[0] = 0x1;
  1318. ioc->pdir_base[0] = 0x8000000000000000ULL | ZX1_SBA_IOMMU_COOKIE;
  1319. #endif
  1320. DBG_INIT("%s() res_map %x %pn", __FUNCTION__,
  1321.  ioc->res_size, (void *) ioc->res_map);
  1322. }
  1323. static void __init
  1324. ioc_sac_init(struct ioc *ioc)
  1325. {
  1326. struct pci_dev *sac = NULL;
  1327. struct pci_controller *controller = NULL;
  1328. /*
  1329.  * pci_alloc_consistent() must return a DMA address which is
  1330.  * SAC (single address cycle) addressable, so allocate a
  1331.  * pseudo-device to enforce that.
  1332.  */
  1333. sac = kmalloc(sizeof(*sac), GFP_KERNEL);
  1334. if (!sac)
  1335. panic(PFX "Couldn't allocate struct pci_dev");
  1336. memset(sac, 0, sizeof(*sac));
  1337. controller = kmalloc(sizeof(*controller), GFP_KERNEL);
  1338. if (!controller)
  1339. panic(PFX "Couldn't allocate struct pci_controller");
  1340. memset(controller, 0, sizeof(*controller));
  1341. controller->iommu = ioc;
  1342. sac->sysdata = controller;
  1343. sac->dma_mask = 0xFFFFFFFFUL;
  1344. ioc->sac_only_dev = sac;
  1345. }
  1346. static void __init
  1347. ioc_zx1_init(struct ioc *ioc)
  1348. {
  1349. if (ioc->rev < 0x20)
  1350. panic(PFX "IOC 2.0 or later required for IOMMU supportn");
  1351. ioc->dma_mask = 0xFFFFFFFFFFUL;
  1352. }
  1353. typedef void (initfunc)(struct ioc *);
  1354. struct ioc_iommu {
  1355. u32 func_id;
  1356. char *name;
  1357. initfunc *init;
  1358. };
  1359. static struct ioc_iommu ioc_iommu_info[] __initdata = {
  1360. { ZX1_IOC_ID, "zx1", ioc_zx1_init },
  1361. { REO_IOC_ID, "REO" },
  1362. };
  1363. static struct ioc * __init
  1364. ioc_init(u64 hpa, void *handle)
  1365. {
  1366. struct ioc *ioc;
  1367. struct ioc_iommu *info;
  1368. ioc = kmalloc(sizeof(*ioc), GFP_KERNEL);
  1369. if (!ioc)
  1370. return NULL;
  1371. memset(ioc, 0, sizeof(*ioc));
  1372. ioc->next = ioc_list;
  1373. ioc_list = ioc;
  1374. ioc->handle = handle;
  1375. ioc->ioc_hpa = ioremap(hpa, 0x1000);
  1376. ioc->func_id = READ_REG(ioc->ioc_hpa + IOC_FUNC_ID);
  1377. ioc->rev = READ_REG(ioc->ioc_hpa + IOC_FCLASS) & 0xFFUL;
  1378. ioc->dma_mask = 0xFFFFFFFFFFFFFFFFUL; /* conservative */
  1379. for (info = ioc_iommu_info; info < ioc_iommu_info + ARRAY_SIZE(ioc_iommu_info); info++) {
  1380. if (ioc->func_id == info->func_id) {
  1381. ioc->name = info->name;
  1382. if (info->init)
  1383. (info->init)(ioc);
  1384. }
  1385. }
  1386. if (!ioc->name)
  1387. ioc->name = "Unknown";
  1388. ioc_iova_init(ioc);
  1389. ioc_resource_init(ioc);
  1390. ioc_sac_init(ioc);
  1391. printk(KERN_INFO PFX
  1392. "Found %s IOC %d.%d HPA 0x%lx IOVA space %dMb at 0x%lxn",
  1393. ioc->name, (ioc->rev >> 4) & 0xF, ioc->rev & 0xF,
  1394. hpa, ioc->iov_size >> 20, ioc->ibase);
  1395. return ioc;
  1396. }
  1397. /**************************************************************************
  1398. **
  1399. **   SBA initialization code (HW and SW)
  1400. **
  1401. **   o identify SBA chip itself
  1402. **   o FIXME: initialize DMA hints for reasonable defaults
  1403. **
  1404. **************************************************************************/
  1405. #ifdef CONFIG_PROC_FS
  1406. static int
  1407. sba_proc_info_one(char *buf, struct ioc *ioc)
  1408. {
  1409. int total_pages = (int) (ioc->res_size << 3); /* 8 bits per byte */
  1410. unsigned long i = 0, avg = 0, min, max;
  1411. sprintf(buf, "Hewlett Packard %s IOC rev %d.%dn",
  1412. ioc->name, ((ioc->rev >> 4) & 0xF), (ioc->rev & 0xF));
  1413. sprintf(buf, "%sIO PDIR size    : %d bytes (%d entries)n",
  1414. buf,
  1415. (int) ((ioc->res_size << 3) * sizeof(u64)), /* 8 bits/byte */
  1416. total_pages);
  1417. sprintf(buf, "%sIO PDIR entries : %ld free  %ld used (%d%%)n", buf,
  1418. total_pages - ioc->used_pages, ioc->used_pages,
  1419. (int) (ioc->used_pages * 100 / total_pages));
  1420. sprintf(buf, "%sResource bitmap : %d bytes (%d pages)n", 
  1421. buf, ioc->res_size, ioc->res_size << 3);   /* 8 bits per byte */
  1422. min = max = ioc->avg_search[0];
  1423. for (i = 0; i < SBA_SEARCH_SAMPLE; i++) {
  1424. avg += ioc->avg_search[i];
  1425. if (ioc->avg_search[i] > max) max = ioc->avg_search[i];
  1426. if (ioc->avg_search[i] < min) min = ioc->avg_search[i];
  1427. }
  1428. avg /= SBA_SEARCH_SAMPLE;
  1429. sprintf(buf, "%s  Bitmap search : %ld/%ld/%ld (min/avg/max CPU Cycles)n",
  1430. buf, min, avg, max);
  1431. sprintf(buf, "%spci_map_single(): %12ld calls  %12ld pages (avg %d/1000)n",
  1432. buf, ioc->msingle_calls, ioc->msingle_pages,
  1433. (int) ((ioc->msingle_pages * 1000)/ioc->msingle_calls));
  1434. #ifdef ALLOW_IOV_BYPASS
  1435. sprintf(buf, "%spci_map_single(): %12ld bypassesn",
  1436.         buf, ioc->msingle_bypass);
  1437. #endif
  1438. sprintf(buf, "%spci_unmap_single: %12ld calls  %12ld pages (avg %d/1000)n",
  1439. buf, ioc->usingle_calls, ioc->usingle_pages,
  1440. (int) ((ioc->usingle_pages * 1000)/ioc->usingle_calls));
  1441. #ifdef ALLOW_IOV_BYPASS
  1442. sprintf(buf, "%spci_unmap_single: %12ld bypassesn",
  1443.         buf, ioc->usingle_bypass);
  1444. #endif
  1445. sprintf(buf, "%spci_map_sg()    : %12ld calls  %12ld pages (avg %d/1000)n",
  1446. buf, ioc->msg_calls, ioc->msg_pages,
  1447. (int) ((ioc->msg_pages * 1000)/ioc->msg_calls));
  1448. #ifdef ALLOW_IOV_BYPASS
  1449. sprintf(buf, "%spci_map_sg()    : %12ld bypassesn",
  1450.         buf, ioc->msg_bypass);
  1451. #endif
  1452. sprintf(buf, "%spci_unmap_sg()  : %12ld calls  %12ld pages (avg %d/1000)n",
  1453. buf, ioc->usg_calls, ioc->usg_pages,
  1454. (int) ((ioc->usg_pages * 1000)/ioc->usg_calls));
  1455. return strlen(buf);
  1456. }
  1457. static int
  1458. sba_proc_info(char *buf, char **start, off_t offset, int len)
  1459. {
  1460. struct ioc *ioc;
  1461. char *base = buf;
  1462. for (ioc = ioc_list; ioc; ioc = ioc->next) {
  1463. buf += sba_proc_info_one(buf, ioc);
  1464. }
  1465. return strlen(base);
  1466. }
  1467. static int
  1468. sba_resource_map_one(char *buf, struct ioc *ioc)
  1469. {
  1470. unsigned int *res_ptr = (unsigned int *)ioc->res_map;
  1471. int i;
  1472. buf[0] = '';
  1473. for(i = 0; i < (ioc->res_size / sizeof(unsigned int)); ++i, ++res_ptr) {
  1474. if ((i & 7) == 0)
  1475.     strcat(buf,"n   ");
  1476. sprintf(buf, "%s %08x", buf, *res_ptr);
  1477. }
  1478. strcat(buf, "n");
  1479. return strlen(buf);
  1480. }
  1481. static int
  1482. sba_resource_map(char *buf, char **start, off_t offset, int len)
  1483. {
  1484. struct ioc *ioc;
  1485. char *base = buf;
  1486. for (ioc = ioc_list; ioc; ioc = ioc->next) {
  1487. buf += sba_resource_map_one(buf, ioc);
  1488. }
  1489. return strlen(base);
  1490. }
  1491. #endif
  1492. void
  1493. sba_enable_device(struct pci_dev *dev)
  1494. {
  1495. acpi_handle handle, parent;
  1496. acpi_status status;
  1497. struct ioc *ioc;
  1498. handle = PCI_CONTROLLER(dev)->acpi_handle;
  1499. if (!handle)
  1500. return;
  1501. /*
  1502.  * The IOC scope encloses PCI root bridges in the ACPI
  1503.  * namespace, so work our way out until we find an IOC we
  1504.  * claimed previously.
  1505.  */
  1506. do {
  1507. for (ioc = ioc_list; ioc; ioc = ioc->next)
  1508. if (ioc->handle == handle) {
  1509. PCI_CONTROLLER(dev)->iommu = ioc;
  1510. return;
  1511. }
  1512. status = acpi_get_parent(handle, &parent);
  1513. handle = parent;
  1514. } while (ACPI_SUCCESS(status));
  1515. printk("No IOC for %s in ACPIn", dev->slot_name);
  1516. }
  1517. static int __init
  1518. acpi_sba_ioc_add(struct acpi_device *device)
  1519. {
  1520. struct ioc *ioc;
  1521. acpi_status status;
  1522. u64 hpa, length;
  1523. /*
  1524.  * Only SBA appears in ACPI namespace.  It encloses the PCI
  1525.  * root bridges, and its CSR space includes the IOC function.
  1526.  */
  1527. status = acpi_hp_csr_space(device->handle, &hpa, &length);
  1528. if (ACPI_FAILURE(status))
  1529. return 1;
  1530. ioc = ioc_init(hpa + ZX1_IOC_OFFSET, device->handle);
  1531. if (!ioc)
  1532. return 1;
  1533. return 0;
  1534. }
  1535. static int __init
  1536. acpi_ioc_add(struct acpi_device *device)
  1537. {
  1538. struct ioc *ioc;
  1539. acpi_status status;
  1540. u64 hpa, length;
  1541. status = acpi_hp_csr_space(device->handle, &hpa, &length);
  1542. if (ACPI_FAILURE(status))
  1543. return 1;
  1544. ioc = ioc_init(hpa, device->handle);
  1545. if (!ioc)
  1546. return 1;
  1547. return 0;
  1548. }
  1549. static struct acpi_driver acpi_sba_ioc_driver = {
  1550. name: "IOC IOMMU Driver",
  1551. ids: "HWP0001",
  1552. ops: {
  1553. add: acpi_sba_ioc_add,
  1554.      },
  1555. };
  1556. static struct acpi_driver acpi_ioc_driver = {
  1557. name: "IOC IOMMU Driver",
  1558. ids: "HWP0004",
  1559. ops: {
  1560. add: acpi_ioc_add,
  1561.      },
  1562. };
  1563. void __init
  1564. ioc_acpi_init(void)
  1565. {
  1566. acpi_bus_register_driver(&acpi_sba_ioc_driver);
  1567. acpi_bus_register_driver(&acpi_ioc_driver);
  1568. }
  1569. void __init
  1570. sba_init(void)
  1571. {
  1572. ioc_acpi_init();
  1573. #ifdef CONFIG_PROC_FS
  1574. if (ioc_list) {
  1575. struct proc_dir_entry * proc_mckinley_root;
  1576. proc_mckinley_root = proc_mkdir("bus/mckinley",0);
  1577. create_proc_info_entry(ioc_list->name, 0, proc_mckinley_root, sba_proc_info);
  1578. create_proc_info_entry("bitmap", 0, proc_mckinley_root, sba_resource_map);
  1579. }
  1580. #endif
  1581. }
  1582. static int __init
  1583. nosbagart(char *str)
  1584. {
  1585. reserve_sba_gart = 0;
  1586. return 1;
  1587. }
  1588. __setup("nosbagart", nosbagart);
  1589. EXPORT_SYMBOL(sba_init);
  1590. EXPORT_SYMBOL(sba_map_single);
  1591. EXPORT_SYMBOL(sba_unmap_single);
  1592. EXPORT_SYMBOL(sba_map_sg);
  1593. EXPORT_SYMBOL(sba_unmap_sg);
  1594. EXPORT_SYMBOL(sba_dma_address);
  1595. EXPORT_SYMBOL(sba_dma_supported);
  1596. EXPORT_SYMBOL(sba_alloc_consistent);
  1597. EXPORT_SYMBOL(sba_free_consistent);