ccio-dma.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:36k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2. ** ccio-dma.c:
  3. ** DMA management routines for first generation cache-coherent machines.
  4. ** Program U2/Uturn in "Virtual Mode" and use the I/O MMU.
  5. **
  6. ** (c) Copyright 2000 Grant Grundler
  7. ** (c) Copyright 2000 Ryan Bradetich
  8. ** (c) Copyright 2000 Hewlett-Packard Company
  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. **  "Real Mode" operation refers to U2/Uturn chip operation.
  17. **  U2/Uturn were designed to perform coherency checks w/o using
  18. **  the I/O MMU - basically what x86 does.
  19. **
  20. **  Philipp Rumpf has a "Real Mode" driver for PCX-W machines at:
  21. **      CVSROOT=:pserver:anonymous@198.186.203.37:/cvsroot/linux-parisc
  22. **      cvs -z3 co linux/arch/parisc/kernel/dma-rm.c
  23. **
  24. **  I've rewritten his code to work under TPG's tree. See ccio-rm-dma.c.
  25. **
  26. **  Drawbacks of using Real Mode are:
  27. ** o outbound DMA is slower - U2 won't prefetch data (GSC+ XQL signal).
  28. **      o Inbound DMA less efficient - U2 can't use DMA_FAST attribute.
  29. ** o Ability to do scatter/gather in HW is lost.
  30. ** o Doesn't work under PCX-U/U+ machines since they didn't follow
  31. **        the coherency design originally worked out. Only PCX-W does.
  32. */
  33. #include <linux/config.h>
  34. #include <linux/types.h>
  35. #include <linux/init.h>
  36. #include <linux/mm.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/slab.h>
  39. #include <linux/string.h>
  40. #include <linux/pci.h>
  41. #include <asm/byteorder.h>
  42. #include <asm/cache.h> /* for L1_CACHE_BYTES */
  43. #include <asm/uaccess.h>
  44. #include <asm/pgalloc.h>
  45. #include <asm/page.h>
  46. #include <asm/io.h>
  47. #include <asm/gsc.h> /* for gsc_writeN()... */
  48. /* 
  49. ** Choose "ccio" since that's what HP-UX calls it.
  50. ** Make it easier for folks to migrate from one to the other :^)
  51. */
  52. #define MODULE_NAME "ccio"
  53. /*
  54. #define DEBUG_CCIO_RES
  55. #define DEBUG_CCIO_RUN
  56. #define DEBUG_CCIO_INIT
  57. #define DUMP_RESMAP
  58. */
  59. #include <linux/proc_fs.h>
  60. #include <asm/runway.h> /* for proc_runway_root */
  61. #ifdef DEBUG_CCIO_INIT
  62. #define DBG_INIT(x...)  printk(x)
  63. #else
  64. #define DBG_INIT(x...)
  65. #endif
  66. #ifdef DEBUG_CCIO_RUN
  67. #define DBG_RUN(x...)   printk(x)
  68. #else
  69. #define DBG_RUN(x...)
  70. #endif
  71. #ifdef DEBUG_CCIO_RES
  72. #define DBG_RES(x...)   printk(x)
  73. #else
  74. #define DBG_RES(x...)
  75. #endif
  76. #define CCIO_INLINE /* inline */
  77. #define WRITE_U32(value, addr) gsc_writel(value, (u32 *) (addr))
  78. #define U2_IOA_RUNWAY 0x580
  79. #define U2_BC_GSC     0x501
  80. #define UTURN_IOA_RUNWAY 0x581
  81. #define UTURN_BC_GSC     0x502
  82. /* We *can't* support JAVA (T600). Venture there at your own risk. */
  83. static void dump_resmap(void);
  84. static int ccio_driver_callback(struct hp_device *, struct pa_iodc_driver *);
  85. static struct pa_iodc_driver ccio_drivers_for[] = {
  86.    {HPHW_IOA, U2_IOA_RUNWAY, 0x0, 0xb, 0, 0x10,
  87. DRIVER_CHECK_HVERSION +
  88. DRIVER_CHECK_SVERSION + DRIVER_CHECK_HWTYPE,
  89.                 MODULE_NAME, "U2 I/O MMU", (void *) ccio_driver_callback},
  90.    {HPHW_IOA, UTURN_IOA_RUNWAY, 0x0, 0xb, 0, 0x10,
  91. DRIVER_CHECK_HVERSION +
  92. DRIVER_CHECK_SVERSION + DRIVER_CHECK_HWTYPE,
  93.                 MODULE_NAME, "Uturn I/O MMU", (void *) ccio_driver_callback},
  94. /*
  95. ** FIXME: The following claims the GSC bus port, not the IOA.
  96. **        And there are two busses below a single I/O TLB.
  97. **
  98. ** These should go away once we have a real PA bus walk.
  99. ** Firmware wants to tell the PA bus walk code about the GSC ports
  100. ** since they are not "architected" PA I/O devices. Ie a PA bus walk
  101. ** wouldn't discover them. But the PA bus walk code could check
  102. ** the "fixed module table" to add such devices to an I/O Tree
  103. ** and proceed with the recursive, depth first bus walk.
  104. */
  105.    {HPHW_BCPORT, U2_BC_GSC, 0x0, 0xc, 0, 0x10,
  106. DRIVER_CHECK_HVERSION +
  107. DRIVER_CHECK_SVERSION + DRIVER_CHECK_HWTYPE,
  108.                 MODULE_NAME, "U2 GSC+ BC", (void *) ccio_driver_callback},
  109.    {HPHW_BCPORT, UTURN_BC_GSC, 0x0, 0xc, 0, 0x10,
  110. DRIVER_CHECK_HVERSION +
  111. DRIVER_CHECK_SVERSION + DRIVER_CHECK_HWTYPE,
  112.                 MODULE_NAME, "Uturn GSC+ BC", (void *) ccio_driver_callback},
  113.    {0,0,0,0,0,0,
  114.    0,
  115.    (char *) NULL, (char *) NULL, (void *) NULL }
  116. };
  117. #define IS_U2(id) ( 
  118.     (((id)->hw_type == HPHW_IOA) && ((id)->hversion == U2_IOA_RUNWAY)) || 
  119.     (((id)->hw_type == HPHW_BCPORT) && ((id)->hversion == U2_BC_GSC))  
  120. )
  121. #define IS_UTURN(id) ( 
  122.     (((id)->hw_type == HPHW_IOA) && ((id)->hversion == UTURN_IOA_RUNWAY)) || 
  123.     (((id)->hw_type == HPHW_BCPORT) && ((id)->hversion == UTURN_BC_GSC))  
  124. )
  125. #define IOA_NORMAL_MODE      0x00020080 /* IO_CONTROL to turn on CCIO        */
  126. #define CMD_TLB_DIRECT_WRITE 35         /* IO_COMMAND for I/O TLB Writes     */
  127. #define CMD_TLB_PURGE        33         /* IO_COMMAND to Purge I/O TLB entry */
  128. struct ioa_registers {
  129.         /* Runway Supervisory Set */
  130.         volatile int32_t    unused1[12];
  131.         volatile uint32_t   io_command;             /* Offset 12 */
  132.         volatile uint32_t   io_status;              /* Offset 13 */
  133.         volatile uint32_t   io_control;             /* Offset 14 */
  134.         volatile int32_t    unused2[1];
  135.         /* Runway Auxiliary Register Set */
  136.         volatile uint32_t   io_err_resp;            /* Offset  0 */
  137.         volatile uint32_t   io_err_info;            /* Offset  1 */
  138.         volatile uint32_t   io_err_req;             /* Offset  2 */
  139.         volatile uint32_t   io_err_resp_hi;         /* Offset  3 */
  140.         volatile uint32_t   io_tlb_entry_m;         /* Offset  4 */
  141.         volatile uint32_t   io_tlb_entry_l;         /* Offset  5 */
  142.         volatile uint32_t   unused3[1];
  143.         volatile uint32_t   io_pdir_base;           /* Offset  7 */
  144.         volatile uint32_t   io_io_low_hv;           /* Offset  8 */
  145.         volatile uint32_t   io_io_high_hv;          /* Offset  9 */
  146.         volatile uint32_t   unused4[1];
  147.         volatile uint32_t   io_chain_id_mask;       /* Offset 11 */
  148.         volatile uint32_t   unused5[2];
  149.         volatile uint32_t   io_io_low;              /* Offset 14 */
  150.         volatile uint32_t   io_io_high;             /* Offset 15 */
  151. };
  152. struct ccio_device {
  153. struct ccio_device    *next;  /* list of LBA's in system */
  154. struct hp_device      *iodc;  /* data about dev from firmware */
  155. spinlock_t            ccio_lock;
  156. struct ioa_registers   *ccio_hpa; /* base address */
  157. u64   *pdir_base;   /* physical base address */
  158. char  *res_map;     /* resource map, bit == pdir entry */
  159. int   res_hint; /* next available IOVP - circular search */
  160. int   res_size; /* size of resource map in bytes */
  161. int   chainid_shift; /* specify bit location of chain_id */
  162. int   flags;         /* state/functionality enabled */
  163. #ifdef DELAYED_RESOURCE_CNT
  164. dma_addr_t res_delay[DELAYED_RESOURCE_CNT];
  165. #endif
  166. /* STUFF We don't need in performance path */
  167. int  pdir_size;     /* in bytes, determined by IOV Space size */
  168. int  hw_rev;        /* HW revision of chip */
  169. };
  170. /* Ratio of Host MEM to IOV Space size */
  171. static unsigned long ccio_mem_ratio = 4;
  172. static struct ccio_device *ccio_list = NULL;
  173. static int ccio_proc_info(char *buffer, char **start, off_t offset, int length);
  174. static unsigned long ccio_used_bytes = 0;
  175. static unsigned long ccio_used_pages = 0;
  176. static int ccio_cujo_bug = 0;
  177. static unsigned long ccio_alloc_size = 0;
  178. static unsigned long ccio_free_size = 0;
  179. /**************************************************************
  180. *
  181. *   I/O Pdir Resource Management
  182. *
  183. *   Bits set in the resource map are in use.
  184. *   Each bit can represent a number of pages.
  185. *   LSbs represent lower addresses (IOVA's).
  186. *
  187. *   This was was copied from sba_iommu.c. Don't try to unify
  188. *   the two resource managers unless a way to have different
  189. *   allocation policies is also adjusted. We'd like to avoid
  190. *   I/O TLB thrashing by having resource allocation policy
  191. *   match the I/O TLB replacement policy.
  192. *
  193. ***************************************************************/
  194. #define PAGES_PER_RANGE 1 /* could increase this to 4 or 8 if needed */
  195. #define IOVP_SIZE PAGE_SIZE
  196. #define IOVP_SHIFT PAGE_SHIFT
  197. #define IOVP_MASK PAGE_MASK
  198. /* Convert from IOVP to IOVA and vice versa. */
  199. #define CCIO_IOVA(iovp,offset) ((iovp) | (offset))
  200. #define CCIO_IOVP(iova) ((iova) & ~(IOVP_SIZE-1) )
  201. #define PDIR_INDEX(iovp)    ((iovp)>>IOVP_SHIFT)
  202. #define MKIOVP(pdir_idx)    ((long)(pdir_idx) << IOVP_SHIFT)
  203. #define MKIOVA(iovp,offset) (dma_addr_t)((long)iovp | (long)offset)
  204. /* CUJO20 KLUDGE start */
  205. #define CUJO_20_BITMASK    0x0ffff000 /* upper nibble is a don't care   */
  206. #define CUJO_20_STEP       0x10000000 /* inc upper nibble */
  207. #define CUJO_20_BADPAGE1   0x01003000 /* pages that hpmc on raven U+    */
  208. #define CUJO_20_BADPAGE2   0x01607000 /* pages that hpmc on firehawk U+ */
  209. #define CUJO_20_BADHVERS   0x6821 /* low nibble 1 is cujo rev 2.0 */
  210. #define CUJO_RAVEN_LOC     0xf1000000UL /* cujo location on raven U+ */
  211. #define CUJO_FIREHAWK_LOC  0xf1604000UL /* cujo location on firehawk U+ */
  212. /* CUJO20 KLUDGE end */
  213. /*
  214. ** Don't worry about the 150% average search length on a miss.
  215. ** If the search wraps around, and passes the res_hint, it will
  216. ** cause the kernel to panic anyhow.
  217. */
  218. /* ioa->res_hint = idx + (size >> 3);  */
  219. #define CCIO_SEARCH_LOOP(ioa, idx, mask, size)  
  220.        for(; res_ptr < res_end; ++res_ptr) 
  221.        { 
  222.                if(0 == ((*res_ptr) & mask)) { 
  223.                        *res_ptr |= mask; 
  224.                        idx = (int)((unsigned long)res_ptr - (unsigned long)ioa->res_map); 
  225.                        ioa->res_hint = 0;
  226.                        goto resource_found; 
  227.                } 
  228.        }
  229. #define CCIO_FIND_FREE_MAPPING(ioa, idx, mask, size)  { 
  230.        u##size *res_ptr = (u##size *)&((ioa)->res_map[ioa->res_hint & ~((size >> 3) - 1)]); 
  231.        u##size *res_end = (u##size *)&(ioa)->res_map[ioa->res_size]; 
  232.        CCIO_SEARCH_LOOP(ioa, idx, mask, size); 
  233.        res_ptr = (u##size *)&(ioa)->res_map[0]; 
  234.        CCIO_SEARCH_LOOP(ioa, idx, mask, size); 
  235. }
  236. /*
  237. ** Find available bit in this ioa's resource map.
  238. ** Use a "circular" search:
  239. **   o Most IOVA's are "temporary" - avg search time should be small.
  240. ** o keep a history of what happened for debugging
  241. ** o KISS.
  242. **
  243. ** Perf optimizations:
  244. ** o search for log2(size) bits at a time.
  245. ** o search for available resource bits using byte/word/whatever.
  246. ** o use different search for "large" (eg > 4 pages) or "very large"
  247. **   (eg > 16 pages) mappings.
  248. */
  249. static int
  250. ccio_alloc_range(struct ccio_device *ioa, size_t size)
  251. {
  252. int res_idx;
  253. unsigned long mask, flags;
  254. unsigned int pages_needed = size >> PAGE_SHIFT;
  255. ASSERT(pages_needed);
  256. ASSERT((pages_needed * IOVP_SIZE) < DMA_CHUNK_SIZE);
  257. ASSERT(pages_needed < (BITS_PER_LONG - IOVP_SHIFT));
  258. mask = (unsigned long) -1L;
  259.   mask >>= BITS_PER_LONG - pages_needed;
  260. DBG_RES(__FUNCTION__ " size: %d pages_needed %d pages_mask 0x%08lxn", 
  261. size, pages_needed, mask);
  262. spin_lock_irqsave(&ioa->ccio_lock, flags);
  263. /*
  264. ** "seek and ye shall find"...praying never hurts either...
  265. ** ggg sacrafices another 710 to the computer gods.
  266. */
  267. if(pages_needed <= 8) {
  268. CCIO_FIND_FREE_MAPPING(ioa, res_idx, mask, 8);
  269. } else if(pages_needed <= 16) {
  270. CCIO_FIND_FREE_MAPPING(ioa, res_idx, mask, 16);
  271. } else if(pages_needed <= 32) {
  272. CCIO_FIND_FREE_MAPPING(ioa, res_idx, mask, 32);
  273. #ifdef __LP64__
  274. } else if(pages_needed <= 64) {
  275. CCIO_FIND_FREE_MAPPING(ioa, res_idx, mask, 64)
  276. #endif
  277. } else {
  278. panic(__FILE__ ":" __FUNCTION__ "() Too many pages to map.n");
  279. }
  280. #ifdef DUMP_RESMAP
  281. dump_resmap();
  282. #endif
  283. panic(__FILE__ ":" __FUNCTION__ "() I/O MMU is out of mapping resourcesn");
  284. resource_found:
  285. DBG_RES(__FUNCTION__ " res_idx %d mask 0x%08lx res_hint: %dn",
  286. res_idx, mask, ioa->res_hint);
  287. ccio_used_pages += pages_needed;
  288. ccio_used_bytes += ((pages_needed >> 3) ? (pages_needed >> 3) : 1);
  289. spin_unlock_irqrestore(&ioa->ccio_lock, flags);
  290. #ifdef DUMP_RESMAP
  291. dump_resmap();
  292. #endif
  293. /* 
  294. ** return the bit address (convert from byte to bit).
  295. */
  296. return (res_idx << 3);
  297. }
  298. #define CCIO_FREE_MAPPINGS(ioa, idx, mask, size) 
  299.         u##size *res_ptr = (u##size *)&((ioa)->res_map[idx + (((size >> 3) - 1) & ~((size >> 3) - 1))]); 
  300.         ASSERT((*res_ptr & mask) == mask); 
  301.         *res_ptr &= ~mask;
  302. /*
  303. ** clear bits in the ioa's resource map
  304. */
  305. static void
  306. ccio_free_range(struct ccio_device *ioa, dma_addr_t iova, size_t size)
  307. {
  308. unsigned long mask, flags;
  309. unsigned long iovp = CCIO_IOVP(iova);
  310. unsigned int res_idx = PDIR_INDEX(iovp)>>3;
  311. unsigned int pages_mapped = (size >> IOVP_SHIFT) + !!(size & ~IOVP_MASK);
  312. ASSERT(pages_needed);
  313. ASSERT((pages_needed * IOVP_SIZE) < DMA_CHUNK_SIZE);
  314. ASSERT(pages_needed < (BITS_PER_LONG - IOVP_SHIFT));
  315. mask = (unsigned long) -1L;
  316.   mask >>= BITS_PER_LONG - pages_mapped;
  317. DBG_RES(__FUNCTION__ " res_idx: %d size: %d pages_mapped %d mask 0x%08lxn", 
  318. res_idx, size, pages_mapped, mask);
  319. spin_lock_irqsave(&ioa->ccio_lock, flags);
  320. if(pages_mapped <= 8) {
  321. CCIO_FREE_MAPPINGS(ioa, res_idx, mask, 8);
  322. } else if(pages_mapped <= 16) {
  323. CCIO_FREE_MAPPINGS(ioa, res_idx, mask, 16);
  324. } else if(pages_mapped <= 32) {
  325. CCIO_FREE_MAPPINGS(ioa, res_idx, mask, 32);
  326. #ifdef __LP64__
  327. } else if(pages_mapped <= 64) {
  328. CCIO_FREE_MAPPINGS(ioa, res_idx, mask, 64);
  329. #endif
  330. } else {
  331. panic(__FILE__ ":" __FUNCTION__ "() Too many pages to unmap.n");
  332. }
  333. ccio_used_pages -= (pages_mapped ? pages_mapped : 1);
  334. ccio_used_bytes -= ((pages_mapped >> 3) ? (pages_mapped >> 3) : 1);
  335. spin_unlock_irqrestore(&ioa->ccio_lock, flags);
  336. #ifdef DUMP_RESMAP
  337. dump_resmap();
  338. #endif
  339. }
  340. /****************************************************************
  341. **
  342. **          CCIO dma_ops support routines
  343. **
  344. *****************************************************************/
  345. typedef unsigned long space_t;
  346. #define KERNEL_SPACE 0
  347. /*
  348. ** DMA "Page Type" and Hints 
  349. ** o if SAFE_DMA isn't set, mapping is for FAST_DMA. SAFE_DMA should be
  350. **   set for subcacheline DMA transfers since we don't want to damage the
  351. **   other part of a cacheline.
  352. ** o SAFE_DMA must be set for "memory" allocated via pci_alloc_consistent().
  353. **   This bit tells U2 to do R/M/W for partial cachelines. "Streaming"
  354. **   data can avoid this if the mapping covers full cache lines.
  355. ** o STOP_MOST is needed for atomicity across cachelines.
  356. **   Apperently only "some EISA devices" need this.
  357. **   Using CONFIG_ISA is hack. Only the IOA with EISA under it needs
  358. **   to use this hint iff the EISA devices needs this feature.
  359. **   According to the U2 ERS, STOP_MOST enabled pages hurt performance.
  360. ** o PREFETCH should *not* be set for cases like Multiple PCI devices
  361. **   behind GSCtoPCI (dino) bus converter. Only one cacheline per GSC
  362. **   device can be fetched and multiply DMA streams will thrash the
  363. **   prefetch buffer and burn memory bandwidth. See 6.7.3 "Prefetch Rules
  364. **   and Invalidation of Prefetch Entries".
  365. **
  366. ** FIXME: the default hints need to be per GSC device - not global.
  367. ** 
  368. ** HP-UX dorks: linux device driver programming model is totally different
  369. **    than HP-UX's. HP-UX always sets HINT_PREFETCH since it's drivers
  370. **    do special things to work on non-coherent platforms...linux has to
  371. **    be much more careful with this.
  372. */
  373. #define IOPDIR_VALID    0x01UL
  374. #define HINT_SAFE_DMA   0x02UL /* used for pci_alloc_consistent() pages */
  375. #ifdef CONFIG_ISA /* EISA support really */
  376. #define HINT_STOP_MOST  0x04UL /* LSL support */
  377. #else
  378. #define HINT_STOP_MOST  0x00UL /* only needed for "some EISA devices" */
  379. #endif
  380. #define HINT_UDPATE_ENB 0x08UL  /* not used/supported by U2 */
  381. #define HINT_PREFETCH   0x10UL /* for outbound pages which are not SAFE */
  382. /*
  383. ** Use direction (ie PCI_DMA_TODEVICE) to pick hint.
  384. ** ccio_alloc_consistent() depends on this to get SAFE_DMA
  385. ** when it passes in BIDIRECTIONAL flag.
  386. */
  387. static u32 hint_lookup[] = {
  388. [PCI_DMA_BIDIRECTIONAL]  HINT_STOP_MOST | HINT_SAFE_DMA | IOPDIR_VALID,
  389. [PCI_DMA_TODEVICE]       HINT_STOP_MOST | HINT_PREFETCH | IOPDIR_VALID,
  390. [PCI_DMA_FROMDEVICE]     HINT_STOP_MOST | IOPDIR_VALID,
  391. [PCI_DMA_NONE]           0,            /* not valid */
  392. };
  393. /*
  394. ** Initialize an I/O Pdir entry
  395. **
  396. ** Given a virtual address (vba, arg2) and space id, (sid, arg1),
  397. ** load the I/O PDIR entry pointed to by pdir_ptr (arg0). Each IO Pdir
  398. ** entry consists of 8 bytes as shown below (MSB == bit 0):
  399. **
  400. **
  401. ** WORD 0:
  402. ** +------+----------------+-----------------------------------------------+
  403. ** | Phys | Virtual Index  |               Phys                            |
  404. ** | 0:3  |     0:11       |               4:19                            |
  405. ** |4 bits|   12 bits      |              16 bits                          |
  406. ** +------+----------------+-----------------------------------------------+
  407. ** WORD 1:
  408. ** +-----------------------+-----------------------------------------------+
  409. ** |      Phys    |  Rsvd  | Prefetch |Update |Rsvd  |Lock  |Safe  |Valid  |
  410. ** |     20:39    |        | Enable   |Enable |      |Enable|DMA   |       |
  411. ** |    20 bits   | 5 bits | 1 bit    |1 bit  |2 bits|1 bit |1 bit |1 bit  |
  412. ** +-----------------------+-----------------------------------------------+
  413. **
  414. ** The virtual index field is filled with the results of the LCI
  415. ** (Load Coherence Index) instruction.  The 8 bits used for the virtual
  416. ** index are bits 12:19 of the value returned by LCI.
  417. */
  418. void CCIO_INLINE
  419. ccio_io_pdir_entry(u64 *pdir_ptr, space_t sid, void * vba, unsigned long hints)
  420. {
  421. register unsigned long pa = (volatile unsigned long) vba;
  422. register unsigned long ci; /* coherent index */
  423. /* We currently only support kernel addresses */
  424. ASSERT(sid == 0);
  425. ASSERT(((unsigned long) vba & 0xf0000000UL) == 0xc0000000UL);
  426. mtsp(sid,1);
  427. /*
  428. ** WORD 1 - low order word
  429. ** "hints" parm includes the VALID bit!
  430. ** "dep" clobbers the physical address offset bits as well.
  431. */
  432. pa = virt_to_phys(vba);
  433. asm volatile("depw  %1,31,12,%0" : "+r" (pa) : "r" (hints));
  434. ((u32 *)pdir_ptr)[1] = (u32) pa;
  435. /*
  436. ** WORD 0 - high order word
  437. */
  438. #ifdef __LP64__
  439. /*
  440. ** get bits 12:15 of physical address
  441. ** shift bits 16:31 of physical address
  442. ** and deposit them
  443. */
  444. asm volatile ("extrd,u %1,15,4,%0" : "=r" (ci) : "r" (pa));
  445. asm volatile ("extrd,u %1,31,16,%0" : "+r" (ci) : "r" (ci));
  446. asm volatile ("depd  %1,35,4,%0" : "+r" (pa) : "r" (ci));
  447. #else
  448. pa = 0;
  449. #endif
  450. /*
  451. ** get CPU coherency index bits
  452. ** Grab virtual index [0:11]
  453. ** Deposit virt_idx bits into I/O PDIR word
  454. */
  455. asm volatile ("lci 0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba));
  456. asm volatile ("extru %1,19,12,%0" : "+r" (ci) : "r" (ci));
  457. asm volatile ("depw  %1,15,12,%0" : "+r" (pa) : "r" (ci));
  458. ((u32 *)pdir_ptr)[0] = (u32) pa;
  459. /* FIXME: PCX_W platforms don't need FDC/SYNC. (eg C360)
  460. **        PCX-U/U+ do. (eg C200/C240)
  461. **        PCX-T'? Don't know. (eg C110 or similar K-class)
  462. **
  463. ** See PDC_MODEL/option 0/SW_CAP word for "Non-coherent IO-PDIR bit".
  464. ** Hopefully we can patch (NOP) these out at boot time somehow.
  465. **
  466. ** "Since PCX-U employs an offset hash that is incompatible with
  467. ** the real mode coherence index generation of U2, the PDIR entry
  468. ** must be flushed to memory to retain coherence."
  469. */
  470. asm volatile("fdc 0(%0)" : : "r" (pdir_ptr));
  471. asm volatile("sync");
  472. }
  473. /*
  474. ** Remove stale entries from the I/O TLB.
  475. ** Need to do this whenever an entry in the PDIR is marked invalid.
  476. */
  477. static CCIO_INLINE void
  478. ccio_clear_io_tlb( struct ccio_device *d, dma_addr_t iovp, size_t byte_cnt)
  479. {
  480. u32 chain_size = 1 << d->chainid_shift;
  481. iovp &= ~(IOVP_SIZE-1); /* clear offset bits, just want pagenum */
  482. byte_cnt += chain_size;
  483.         while (byte_cnt > chain_size) {
  484. WRITE_U32(CMD_TLB_PURGE | iovp, &d->ccio_hpa->io_command);
  485.                 iovp += chain_size;
  486. byte_cnt -= chain_size;
  487.         }
  488. }
  489. /***********************************************************
  490.  *
  491.  * Mark the I/O Pdir entries invalid and blow away the
  492.  * corresponding I/O TLB entries.
  493.  *
  494.  * FIXME: at some threshhold it might be "cheaper" to just blow
  495.  *        away the entire I/O TLB instead of individual entries.
  496.  *
  497.  * FIXME: Uturn has 256 TLB entries. We don't need to purge every
  498.  *        PDIR entry - just once for each possible TLB entry.
  499.  *        (We do need to maker I/O PDIR entries invalid regardless).
  500.  ***********************************************************/
  501. static CCIO_INLINE void
  502. ccio_mark_invalid(struct ccio_device *d, dma_addr_t iova, size_t byte_cnt)
  503. {
  504. u32 iovp = (u32) CCIO_IOVP(iova);
  505. size_t saved_byte_cnt;
  506. /* round up to nearest page size */
  507. saved_byte_cnt = byte_cnt = (byte_cnt + IOVP_SIZE - 1) & IOVP_MASK;
  508. while (byte_cnt > 0) {
  509. /* invalidate one page at a time */
  510. unsigned int idx = PDIR_INDEX(iovp);
  511. char *pdir_ptr = (char *) &(d->pdir_base[idx]);
  512. ASSERT( idx < (d->pdir_size/sizeof(u64)));
  513. pdir_ptr[7] = 0; /* clear only VALID bit */
  514. /*
  515. ** FIXME: PCX_W platforms don't need FDC/SYNC. (eg C360)
  516. **   PCX-U/U+ do. (eg C200/C240)
  517. ** See PDC_MODEL/option 0/SW_CAP for "Non-coherent IO-PDIR bit".
  518. **
  519. ** Hopefully someone figures out how to patch (NOP) the
  520. ** FDC/SYNC out at boot time.
  521. */
  522. asm volatile("fdc 0(%0)" : : "r" (pdir_ptr[7]));
  523. iovp     += IOVP_SIZE;
  524. byte_cnt -= IOVP_SIZE;
  525. }
  526. asm volatile("sync");
  527. ccio_clear_io_tlb(d, CCIO_IOVP(iova), saved_byte_cnt);
  528. }
  529. /****************************************************************
  530. **
  531. **          CCIO dma_ops
  532. **
  533. *****************************************************************/
  534. void __init ccio_init(void)
  535. {
  536. register_driver(ccio_drivers_for);
  537. }
  538. static int ccio_dma_supported( struct pci_dev *dev, u64 mask)
  539. {
  540. if (dev == NULL) {
  541. printk(MODULE_NAME ": EISA/ISA/et al not supportedn");
  542. BUG();
  543. return(0);
  544. }
  545. dev->dma_mask = mask;   /* save it */
  546. /* only support 32-bit devices (ie PCI/GSC) */
  547. return((int) (mask >= 0xffffffffUL));
  548. }
  549. /*
  550. ** Dump a hex representation of the resource map.
  551. */
  552. #ifdef DUMP_RESMAP
  553. static 
  554. void dump_resmap()
  555. {
  556. struct ccio_device *ioa = ccio_list;
  557. unsigned long *res_ptr = (unsigned long *)ioa->res_map;
  558. unsigned long i = 0;
  559. printk("res_map: ");
  560. for(; i < (ioa->res_size / sizeof(unsigned long)); ++i, ++res_ptr)
  561. printk("%08lx ", *res_ptr);
  562. printk("n");
  563. }
  564. #endif
  565. /*
  566. ** map_single returns a fully formed IOVA
  567. */
  568. static dma_addr_t ccio_map_single(struct pci_dev *dev, void *addr, size_t size, int direction)
  569. {
  570. struct ccio_device *ioa = ccio_list;  /* FIXME : see Multi-IOC below */
  571. dma_addr_t iovp;
  572. dma_addr_t offset;
  573. u64 *pdir_start;
  574. unsigned long hint = hint_lookup[direction];
  575. int idx;
  576. ASSERT(size > 0);
  577. /* save offset bits */
  578. offset = ((dma_addr_t) addr) & ~IOVP_MASK;
  579. /* round up to nearest IOVP_SIZE */
  580. size = (size + offset + IOVP_SIZE - 1) & IOVP_MASK;
  581. idx = ccio_alloc_range(ioa, size);
  582. iovp = (dma_addr_t) MKIOVP(idx);
  583. DBG_RUN(__FUNCTION__ " 0x%p -> 0x%lx", addr, (long) iovp | offset);
  584. pdir_start = &(ioa->pdir_base[idx]);
  585. /* If not cacheline aligned, force SAFE_DMA on the whole mess */
  586. if ((size % L1_CACHE_BYTES) || ((unsigned long) addr % L1_CACHE_BYTES))
  587. hint |= HINT_SAFE_DMA;
  588. /* round up to nearest IOVP_SIZE */
  589. size = (size + IOVP_SIZE - 1) & IOVP_MASK;
  590. while (size > 0) {
  591. ccio_io_pdir_entry(pdir_start, KERNEL_SPACE, addr, hint);
  592. DBG_RUN(" pdir %p %08x%08xn",
  593. pdir_start,
  594. (u32) (((u32 *) pdir_start)[0]),
  595. (u32) (((u32 *) pdir_start)[1])
  596. );
  597. addr += IOVP_SIZE;
  598. size -= IOVP_SIZE;
  599. pdir_start++;
  600. }
  601. /* form complete address */
  602. return CCIO_IOVA(iovp, offset);
  603. }
  604. static void ccio_unmap_single(struct pci_dev *dev, dma_addr_t iova, size_t size, int direction)
  605. {
  606. #ifdef FIXME
  607. /* Multi-IOC (ie N-class) :  need to lookup IOC from dev
  608. ** o If we can't know about lba PCI data structs, that eliminates ->sysdata.
  609. ** o walking up pcidev->parent dead ends at elroy too
  610. ** o leaves hashing dev->bus->number into some lookup.
  611. **   (may only work for N-class)
  612. */
  613. struct ccio_device *ioa = dev->sysdata
  614. #else
  615. struct ccio_device *ioa = ccio_list;
  616. #endif
  617. dma_addr_t offset;
  618. offset = iova & ~IOVP_MASK;
  619. /* round up to nearest IOVP_SIZE */
  620. size = (size + offset + IOVP_SIZE - 1) & IOVP_MASK;
  621. /* Mask off offset */
  622. iova &= IOVP_MASK;
  623. DBG_RUN(__FUNCTION__ " iovp 0x%lxn", (long) iova);
  624. #ifdef DELAYED_RESOURCE_CNT
  625. if (ioa->saved_cnt < DELAYED_RESOURCE_CNT) {
  626. ioa->saved_iova[ioa->saved_cnt] = iova;
  627. ioa->saved_size[ioa->saved_cnt] = size;
  628. ccio_saved_cnt++;
  629. } else {
  630. do {
  631. #endif
  632. ccio_mark_invalid(ioa, iova, size);
  633. ccio_free_range(ioa, iova, size);
  634. #ifdef DELAYED_RESOURCE_CNT
  635. d->saved_cnt--;
  636. iova = ioa->saved_iova[ioa->saved_cnt];
  637. size = ioa->saved_size[ioa->saved_cnt];
  638. } while (ioa->saved_cnt)
  639. }
  640. #endif
  641. }
  642. static void * ccio_alloc_consistent (struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
  643. {
  644. void *ret;
  645. unsigned long flags;
  646. struct ccio_device *ioa = ccio_list;
  647. DBG_RUN(__FUNCTION__ " size 0x%xn",  size);
  648. #if 0
  649. /* GRANT Need to establish hierarchy for non-PCI devs as well
  650. ** and then provide matching gsc_map_xxx() functions for them as well.
  651. */
  652. if (!hwdev) {
  653. /* only support PCI */
  654. *dma_handle = 0;
  655. return 0;
  656. }
  657. #endif
  658. spin_lock_irqsave(&ioa->ccio_lock, flags);
  659. ccio_alloc_size += get_order(size);
  660. spin_unlock_irqrestore(&ioa->ccio_lock, flags);
  661.         ret = (void *) __get_free_pages(GFP_ATOMIC, get_order(size));
  662. if (ret) {
  663. memset(ret, 0, size);
  664. *dma_handle = ccio_map_single(hwdev, ret, size, PCI_DMA_BIDIRECTIONAL);
  665. }
  666. DBG_RUN(__FUNCTION__ " ret %pn",  ret);
  667. return ret;
  668. }
  669. static void ccio_free_consistent (struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
  670. {
  671. unsigned long flags;
  672. struct ccio_device *ioa = ccio_list;
  673. spin_lock_irqsave(&ioa->ccio_lock, flags);
  674. ccio_free_size += get_order(size);
  675. spin_unlock_irqrestore(&ioa->ccio_lock, flags);
  676. ccio_unmap_single(hwdev, dma_handle, size, 0);
  677. free_pages((unsigned long) vaddr, get_order(size));
  678. }
  679. static int ccio_map_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  680. {
  681. int tmp = nents;
  682. DBG_RUN(KERN_WARNING __FUNCTION__ " STARTn");
  683.         /* KISS: map each buffer seperately. */
  684. while (nents) {
  685. sg_dma_address(sglist) = ccio_map_single(dev, sglist->address, sglist->length, direction);
  686. sg_dma_len(sglist) = sglist->length;
  687. nents--;
  688. sglist++;
  689. }
  690. DBG_RUN(KERN_WARNING __FUNCTION__ " DONEn");
  691. return tmp;
  692. }
  693. static void ccio_unmap_sg(struct pci_dev *dev, struct scatterlist *sglist, int nents, int direction)
  694. {
  695. DBG_RUN(KERN_WARNING __FUNCTION__ " : unmapping %d entriesn", nents);
  696. while (nents) {
  697. ccio_unmap_single(dev, sg_dma_address(sglist), sg_dma_len(sglist), direction);
  698. nents--;
  699. sglist++;
  700. }
  701. return;
  702. }
  703. static struct pci_dma_ops ccio_ops = {
  704. ccio_dma_supported,
  705. ccio_alloc_consistent,
  706. ccio_free_consistent,
  707. ccio_map_single,
  708. ccio_unmap_single,
  709. ccio_map_sg,
  710. ccio_unmap_sg,
  711. NULL,                   /* dma_sync_single : NOP for U2/Uturn */
  712. NULL,                   /* dma_sync_sg     : ditto */
  713. };
  714. #if 0
  715. /* GRANT -  is this needed for U2 or not? */
  716. /*
  717. ** Get the size of the I/O TLB for this I/O MMU.
  718. **
  719. ** If spa_shift is non-zero (ie probably U2),
  720. ** then calculate the I/O TLB size using spa_shift.
  721. **
  722. ** Otherwise we are supposed to get the IODC entry point ENTRY TLB
  723. ** and execute it. However, both U2 and Uturn firmware supplies spa_shift.
  724. ** I think only Java (K/D/R-class too?) systems don't do this.
  725. */
  726. static int
  727. ccio_get_iotlb_size(struct hp_device *d)
  728. {
  729. if(d->spa_shift == 0) {
  730. panic(__FUNCTION__ ": Can't determine I/O TLB size.n");
  731. }
  732. return(1 << d->spa_shift);
  733. }
  734. #else
  735. /* Uturn supports 256 TLB entries */
  736. #define CCIO_CHAINID_SHIFT 8
  737. #define CCIO_CHAINID_MASK 0xff
  738. #endif /* 0 */
  739. /*
  740. ** Figure out how big the I/O PDIR should be and alloc it.
  741. ** Also sets variables which depend on pdir size.
  742. */
  743. static void
  744. ccio_alloc_pdir(struct ccio_device *ioa)
  745. {
  746. extern unsigned long mem_max;          /* arch.../setup.c */
  747. u32 iova_space_size = 0;
  748. void * pdir_base;
  749. int pdir_size, iov_order;
  750. /*
  751. ** Determine IOVA Space size from memory size.
  752. ** Using "mem_max" is a kluge.
  753. **
  754. ** Ideally, PCI drivers would register the maximum number
  755. ** of DMA they can have outstanding for each device they
  756. ** own.  Next best thing would be to guess how much DMA
  757. ** can be outstanding based on PCI Class/sub-class. Both
  758. ** methods still require some "extra" to support PCI
  759. ** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
  760. */
  761. /* limit IOVA space size to 1MB-1GB */
  762. if (mem_max < (ccio_mem_ratio*1024*1024)) {
  763. iova_space_size = 1024*1024;
  764. #ifdef __LP64__
  765. } else if (mem_max > (ccio_mem_ratio*512*1024*1024)) {
  766. iova_space_size = 512*1024*1024;
  767. #endif
  768. } else {
  769. iova_space_size = (u32) (mem_max/ccio_mem_ratio);
  770. }
  771. /*
  772. ** iova space must be log2() in size.
  773. ** thus, pdir/res_map will also be log2().
  774. */
  775. /* We could use larger page sizes in order to *decrease* the number
  776. ** of mappings needed.  (ie 8k pages means 1/2 the mappings).
  777.         **
  778. ** Note: Grant Grunder says "Using 8k I/O pages isn't trivial either
  779. **   since the pages must also be physically contiguous - typically
  780. **   this is the case under linux."
  781. */
  782. iov_order = get_order(iova_space_size);
  783. ASSERT(iov_order <= (30 - IOVP_SHIFT));   /* iova_space_size <= 1GB */
  784. ASSERT(iov_order >= (20 - IOVP_SHIFT));   /* iova_space_size >= 1MB */
  785. iova_space_size = 1 << (iov_order + IOVP_SHIFT);
  786. ioa->pdir_size = pdir_size = (iova_space_size/IOVP_SIZE) * sizeof(u64);
  787. ASSERT(pdir_size < 4*1024*1024);   /* max pdir size < 4MB */
  788. /* Verify it's a power of two */
  789. ASSERT((1 << get_order(pdir_size)) == (pdir_size >> PAGE_SHIFT));
  790. DBG_INIT(__FUNCTION__ " hpa 0x%p mem %dMB IOV %dMB (%d bits)n    PDIR size 0x%0x",
  791. ioa->ccio_hpa, (int) (mem_max>>20), iova_space_size>>20,
  792. iov_order + PAGE_SHIFT, pdir_size);
  793. ioa->pdir_base =
  794. pdir_base = (void *) __get_free_pages(GFP_KERNEL, get_order(pdir_size));
  795. if (NULL == pdir_base)
  796. {
  797. panic(__FILE__ ":" __FUNCTION__ "() could not allocate I/O Page Tablen");
  798. }
  799. memset(pdir_base, 0, pdir_size);
  800. ASSERT((((unsigned long) pdir_base) & PAGE_MASK) == (unsigned long) pdir_base);
  801. DBG_INIT(" base %p", pdir_base);
  802. /*
  803. ** Chainid is the upper most bits of an IOVP used to determine
  804. ** which TLB entry an IOVP will use.
  805. */
  806. ioa->chainid_shift = get_order(iova_space_size)+PAGE_SHIFT-CCIO_CHAINID_SHIFT;
  807. DBG_INIT(" chainid_shift 0x%xn", ioa->chainid_shift);
  808. }
  809. static void
  810. ccio_hw_init(struct ccio_device *ioa)
  811. {
  812. int i;
  813. /*
  814. ** Initialize IOA hardware
  815. */
  816. WRITE_U32(CCIO_CHAINID_MASK << ioa->chainid_shift, &ioa->ccio_hpa->io_chain_id_mask);
  817. WRITE_U32(virt_to_phys(ioa->pdir_base), &ioa->ccio_hpa->io_pdir_base);
  818. /*
  819. ** Go to "Virtual Mode"
  820. */
  821. WRITE_U32(IOA_NORMAL_MODE, &ioa->ccio_hpa->io_control);
  822. /*
  823. ** Initialize all I/O TLB entries to 0 (Valid bit off).
  824. */
  825. WRITE_U32(0, &ioa->ccio_hpa->io_tlb_entry_m);
  826. WRITE_U32(0, &ioa->ccio_hpa->io_tlb_entry_l);
  827. for (i = 1 << CCIO_CHAINID_SHIFT; i ; i--) {
  828. WRITE_U32((CMD_TLB_DIRECT_WRITE | (i << ioa->chainid_shift)),
  829. &ioa->ccio_hpa->io_command);
  830. }
  831. }
  832. static void
  833. ccio_resmap_init(struct ccio_device *ioa)
  834. {
  835. u32 res_size;
  836. /*
  837. ** Ok...we do more than just init resource map
  838. */
  839. ioa->ccio_lock = SPIN_LOCK_UNLOCKED;
  840. ioa->res_hint = 16;    /* next available IOVP - circular search */
  841. /* resource map size dictated by pdir_size */
  842. res_size = ioa->pdir_size/sizeof(u64); /* entries */
  843. res_size >>= 3; /* convert bit count to byte count */
  844. DBG_INIT(__FUNCTION__ "() res_size 0x%xn", res_size);
  845. ioa->res_size = res_size;
  846. ioa->res_map = (char *) __get_free_pages(GFP_KERNEL, get_order(res_size));
  847. if (NULL == ioa->res_map)
  848. {
  849. panic(__FILE__ ":" __FUNCTION__ "() could not allocate resource mapn");
  850. }
  851. memset(ioa->res_map, 0, res_size);
  852. }
  853. /* CUJO20 KLUDGE start */
  854. static struct {
  855. u16 hversion;
  856. u8  spa;
  857. u8  type;
  858. u32     foo[3]; /* 16 bytes total */
  859. } cujo_iodc __attribute__ ((aligned (64)));
  860. static unsigned long cujo_result[32] __attribute__ ((aligned (16))) = {0,0,0,0};
  861. /*
  862. ** CUJO 2.0 incorrectly decodes a memory access for specific
  863. ** pages (every page at specific iotlb locations dependent
  864. ** upon where the cujo is flexed - diff on raven/firehawk.
  865. ** resulting in an hpmc and/or silent data corruption.
  866. ** Workaround is to prevent use of those I/O TLB entries
  867. ** by marking the suspect bitmap range entries as busy.
  868. */
  869. static void
  870. ccio_cujo20_hack(struct ccio_device *ioa)
  871. {
  872. unsigned long status;
  873. unsigned int idx;
  874. u8 *res_ptr = ioa->res_map;
  875. u32 iovp=0x0;
  876. unsigned long mask;
  877. status = pdc_iodc_read( &cujo_result, (void *) CUJO_RAVEN_LOC, 0, &cujo_iodc, 16);
  878. if (status == 0) {
  879. if (cujo_iodc.hversion==CUJO_20_BADHVERS)
  880. iovp = CUJO_20_BADPAGE1;
  881. } else {
  882. status = pdc_iodc_read( &cujo_result, (void *) CUJO_FIREHAWK_LOC, 0, &cujo_iodc, 16);
  883. if (status == 0) {
  884. if (cujo_iodc.hversion==CUJO_20_BADHVERS)
  885. iovp = CUJO_20_BADPAGE2;
  886. } else {
  887. /* not a defective system */
  888. return;
  889. }
  890. }
  891. printk(MODULE_NAME ": Cujo 2.0 bug needs a work aroundn");
  892. ccio_cujo_bug = 1;
  893. /*
  894. ** mark bit entries that match "bad page"
  895. */
  896. idx = PDIR_INDEX(iovp)>>3;
  897. mask = 0xff;
  898. while(idx * sizeof(u8) < ioa->res_size) {
  899. res_ptr[idx] |= mask;
  900. idx += (PDIR_INDEX(CUJO_20_STEP)>>3);
  901. ccio_used_pages += 8;
  902. ccio_used_bytes += 1;
  903. }
  904. }
  905. /* CUJO20 KLUDGE end */
  906. #ifdef CONFIG_PROC_FS
  907. static int ccio_proc_info(char *buf, char **start, off_t offset, int len)
  908. {
  909. unsigned long i = 0;
  910. struct ccio_device *ioa = ccio_list;
  911. unsigned long *res_ptr = (unsigned long *)ioa->res_map;
  912. unsigned long total_pages = ioa->res_size << 3;            /* 8 bits per byte */
  913. sprintf(buf, "%snCujo 2.0 bug    : %sn",
  914. parisc_getHWdescription(ioa->iodc->hw_type, ioa->iodc->hversion,
  915. ioa->iodc->sversion),
  916. (ccio_cujo_bug ? "yes" : "no"));
  917. sprintf(buf, "%sIO pdir size    : %d bytes (%d entries)n",
  918. buf, ((ioa->res_size << 3) * sizeof(u64)), /* 8 bits per byte */
  919. ioa->res_size << 3);                       /* 8 bits per byte */
  920. sprintf(buf, "%sResource bitmap : %d bytes (%d pages)n", 
  921. buf, ioa->res_size, ioa->res_size << 3);   /* 8 bits per byte */
  922. strcat(buf,  "        total:    free:    used:   % used:n");
  923. sprintf(buf, "%sblocks  %8d %8ld %8ld %8ld%%n", buf, ioa->res_size,
  924. ioa->res_size - ccio_used_bytes, ccio_used_bytes,
  925. (ccio_used_bytes * 100) / ioa->res_size);
  926. sprintf(buf, "%spages   %8ld %8ld %8ld %8ld%%n", buf, total_pages,
  927. total_pages - ccio_used_pages, ccio_used_pages,
  928. (ccio_used_pages * 100 / total_pages));
  929. sprintf(buf, "%sconsistent       %8ld %8ldn", buf,
  930. ccio_alloc_size, ccio_free_size);
  931.  
  932. strcat(buf, "nResource bitmap:n");
  933. for(; i < (ioa->res_size / sizeof(unsigned long)); ++i, ++res_ptr)
  934. len += sprintf(buf, "%s%08lx ", buf, *res_ptr);
  935. strcat(buf, "n");
  936. return strlen(buf);
  937. }
  938. #endif
  939. /*
  940. ** Determine if ccio should claim this chip (return 0) or not (return 1).
  941. ** If so, initialize the chip and tell other partners in crime they
  942. ** have work to do.
  943. */
  944. static int
  945. ccio_driver_callback(struct hp_device *d, struct pa_iodc_driver *dri)
  946. {
  947. struct ccio_device *ioa;
  948. printk("%s found %s at 0x%pn", dri->name, dri->version, d->hpa);
  949. if (ccio_list) {
  950. printk(MODULE_NAME ": already initialized one devicen");
  951. return(0);
  952. }
  953. ioa = kmalloc(sizeof(struct ccio_device), GFP_KERNEL);
  954. if (NULL == ioa)
  955. {
  956. printk(MODULE_NAME " - couldn't alloc ccio_devicen");
  957. return(1);
  958. }
  959. memset(ioa, 0, sizeof(struct ccio_device));
  960. /*
  961. ** ccio list is used mainly as a kluge to support a single instance. 
  962. ** Eventually, with core dumps, it'll be useful for debugging.
  963. */
  964. ccio_list = ioa;
  965. ioa->iodc = d;
  966. #if 1
  967. /* KLUGE: determine IOA hpa based on GSC port value.
  968. ** Needed until we have a PA bus walk. Can only discover IOA via
  969. ** walking the architected PA MMIO space as described by the I/O ACD.
  970. ** "Legacy" PA Firmware only tells us about unarchitected devices
  971. ** that can't be detected by PA/EISA/PCI bus walks.
  972. */
  973. switch((long) d->hpa) {
  974. case 0xf3fbf000L:       /* C110 IOA0 LBC (aka GSC port) */
  975. /* ccio_hpa same as C200 IOA0 */
  976. case 0xf203f000L:       /* C180/C200/240/C360 IOA0 LBC (aka GSC port) */
  977. ioa->ccio_hpa = (struct ioa_registers *) 0xfff88000L;
  978. break;
  979. case 0xf103f000L:       /* C180/C200/240/C360 IOA1 LBC (aka GSC port) */
  980. ioa->ccio_hpa = (struct ioa_registers *) 0xfff8A000L;
  981. break;
  982. default:
  983. panic("ccio-dma.c doesn't know this GSC port Address!n");
  984. break;
  985. };
  986. #else
  987. ioa->ccio_hpa = d->hpa;
  988. #endif
  989. ccio_alloc_pdir(ioa);
  990. ccio_hw_init(ioa);
  991. ccio_resmap_init(ioa);
  992. /* CUJO20 KLUDGE start */
  993. ccio_cujo20_hack(ioa);
  994. /* CUJO20 KLUDGE end */
  995. hppa_dma_ops = &ccio_ops;
  996. create_proc_info_entry(MODULE_NAME, 0, proc_runway_root, ccio_proc_info);
  997. return(0);
  998. }