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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2. **  PCI Lower Bus Adapter (LBA) manager
  3. **
  4. ** (c) Copyright 1999,2000 Grant Grundler
  5. ** (c) Copyright 1999,2000 Hewlett-Packard Company
  6. **
  7. ** This program is free software; you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. **      the Free Software Foundation; either version 2 of the License, or
  10. **      (at your option) any later version.
  11. **
  12. **
  13. ** This module primarily provides access to PCI bus (config/IOport
  14. ** spaces) on platforms with an SBA/LBA chipset. A/B/C/J/L/N-class
  15. ** with 4 digit model numbers - eg C3000 (and A400...sigh).
  16. **
  17. ** LBA driver isn't as simple as the Dino driver because:
  18. **   (a) this chip has substantial bug fixes between revisions
  19. **       (Only one Dino bug has a software workaround :^(  )
  20. **   (b) has more options which we don't (yet) support (DMA hints, OLARD)
  21. **   (c) IRQ support lives in the I/O SAPIC driver (not with PCI driver)
  22. **   (d) play nicely with both PAT and "Legacy" PA-RISC firmware (PDC).
  23. **       (dino only deals with "Legacy" PDC)
  24. **
  25. ** LBA driver passes the I/O SAPIC HPA to the I/O SAPIC driver.
  26. ** (I/O SAPIC is integratd in the LBA chip).
  27. **
  28. ** FIXME: Add support to SBA and LBA drivers for DMA hint sets
  29. ** FIXME: Add support for PCI card hot-plug (OLARD).
  30. */
  31. #include <linux/delay.h>
  32. #include <linux/types.h>
  33. #include <linux/kernel.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/init.h> /* for __init and __devinit */
  36. /* #define PCI_DEBUG enable ASSERT */
  37. #include <linux/pci.h>
  38. #include <linux/ioport.h>
  39. #include <linux/slab.h>
  40. #include <linux/smp_lock.h>
  41. #include <asm/byteorder.h>
  42. #include <asm/irq.h> /* for struct irq_region support */
  43. #include <asm/pdc.h>
  44. #include <asm/page.h>
  45. #include <asm/segment.h>
  46. #include <asm/system.h>
  47. #include <asm/hardware.h> /* for register_parisc_driver() stuff */
  48. #include <asm/iosapic.h> /* for iosapic_register() */
  49. #include <asm/io.h> /* read/write stuff */
  50. #ifndef TRUE
  51. #define TRUE (1 == 1)
  52. #define FALSE (1 == 0)
  53. #endif
  54. #undef DEBUG_LBA /* general stuff */
  55. #undef DEBUG_LBA_PORT /* debug I/O Port access */
  56. #undef DEBUG_LBA_CFG /* debug Config Space Access (ie PCI Bus walk) */
  57. #undef DEBUG_LBA_PAT /* debug PCI Resource Mgt code - PDC PAT only */
  58. #undef FBB_SUPPORT /* Fast Back-Back xfers - NOT READY YET */
  59. #ifdef DEBUG_LBA
  60. #define DBG(x...) printk(x)
  61. #else
  62. #define DBG(x...)
  63. #endif
  64. #ifdef DEBUG_LBA_PORT
  65. #define DBG_PORT(x...) printk(x)
  66. #else
  67. #define DBG_PORT(x...)
  68. #endif
  69. #ifdef DEBUG_LBA_CFG
  70. #define DBG_CFG(x...) printk(x)
  71. #else
  72. #define DBG_CFG(x...)
  73. #endif
  74. #ifdef DEBUG_LBA_PAT
  75. #define DBG_PAT(x...) printk(x)
  76. #else
  77. #define DBG_PAT(x...)
  78. #endif
  79. /*
  80. ** Config accessor functions only pass in the 8-bit bus number and not
  81. ** the 8-bit "PCI Segment" number. Each LBA will be assigned a PCI bus
  82. ** number based on what firmware wrote into the scratch register.
  83. **
  84. ** The "secondary" bus number is set to this before calling
  85. ** pci_register_ops(). If any PPB's are present, the scan will
  86. ** discover them and update the "secondary" and "subordinate"
  87. ** fields in the pci_bus structure.
  88. **
  89. ** Changes in the configuration *may* result in a different
  90. ** bus number for each LBA depending on what firmware does.
  91. */
  92. #define MODULE_NAME "lba"
  93. #define LBA_FUNC_ID 0x0000 /* function id */
  94. #define LBA_FCLASS 0x0008 /* function class, bist, header, rev... */
  95. #define LBA_CAPABLE 0x0030 /* capabilities register */
  96. #define LBA_PCI_CFG_ADDR 0x0040 /* poke CFG address here */
  97. #define LBA_PCI_CFG_DATA 0x0048 /* read or write data here */
  98. #define LBA_PMC_MTLT 0x0050 /* Firmware sets this - read only. */
  99. #define LBA_FW_SCRATCH 0x0058 /* Firmware writes the PCI bus number here. */
  100. #define LBA_ERROR_ADDR 0x0070 /* On error, address gets logged here */
  101. #define LBA_ARB_MASK 0x0080 /* bit 0 enable arbitration. PAT/PDC enables */
  102. #define LBA_ARB_PRI 0x0088 /* firmware sets this. */
  103. #define LBA_ARB_MODE 0x0090 /* firmware sets this. */
  104. #define LBA_ARB_MTLT 0x0098 /* firmware sets this. */
  105. #define LBA_MOD_ID 0x0100 /* Module ID. PDC_PAT_CELL reports 4 */
  106. #define LBA_STAT_CTL 0x0108 /* Status & Control */
  107. #define   LBA_BUS_RESET 0x01 /*  Deassert PCI Bus Reset Signal */
  108. #define   CLEAR_ERRLOG 0x10 /*  "Clear Error Log" cmd */
  109. #define   CLEAR_ERRLOG_ENABLE 0x20 /*  "Clear Error Log" Enable */
  110. #define   HF_ENABLE 0x40 /*    enable HF mode (default is -1 mode) */
  111. #define LBA_LMMIO_BASE 0x0200 /* < 4GB I/O address range */
  112. #define LBA_LMMIO_MASK 0x0208
  113. #define LBA_GMMIO_BASE 0x0210 /* > 4GB I/O address range */
  114. #define LBA_GMMIO_MASK 0x0218
  115. #define LBA_WLMMIO_BASE 0x0220 /* All < 4GB ranges under the same *SBA* */
  116. #define LBA_WLMMIO_MASK 0x0228
  117. #define LBA_WGMMIO_BASE 0x0230 /* All > 4GB ranges under the same *SBA* */
  118. #define LBA_WGMMIO_MASK 0x0238
  119. #define LBA_IOS_BASE 0x0240 /* I/O port space for this LBA */
  120. #define LBA_IOS_MASK 0x0248
  121. #define LBA_ELMMIO_BASE 0x0250 /* Extra LMMIO range */
  122. #define LBA_ELMMIO_MASK 0x0258
  123. #define LBA_EIOS_BASE 0x0260 /* Extra I/O port space */
  124. #define LBA_EIOS_MASK 0x0268
  125. #define LBA_DMA_CTL 0x0278 /* firmware sets this */
  126. #define LBA_IBASE 0x0300 /* SBA DMA support */
  127. #define LBA_IMASK 0x0308
  128. /* FIXME: ignore DMA Hint stuff until we can measure performance */
  129. #define LBA_HINT_CFG 0x0310
  130. #define LBA_HINT_BASE 0x0380 /* 14 registers at every 8 bytes. */
  131. /* ERROR regs are needed for config cycle kluges */
  132. #define LBA_ERROR_CONFIG 0x0680
  133. #define     LBA_SMART_MODE 0x20
  134. #define LBA_ERROR_STATUS 0x0688
  135. #define LBA_ROPE_CTL     0x06A0
  136. #define LBA_IOSAPIC_BASE 0x800 /* Offset of IRQ logic */
  137. /* non-postable I/O port space, densely packed */
  138. #ifdef __LP64__
  139. #define LBA_ASTRO_PORT_BASE (0xfffffffffee00000UL)
  140. #else
  141. #define LBA_ASTRO_PORT_BASE (0xfee00000UL)
  142. #endif
  143. /*
  144. ** lba_device: Per instance Elroy data structure
  145. */
  146. struct lba_device {
  147. struct pci_hba_data hba;
  148. spinlock_t lba_lock;
  149. void *iosapic_obj;
  150. #ifdef __LP64__
  151. unsigned long lmmio_base;  /* PA_VIEW - fixup MEM addresses */
  152. unsigned long gmmio_base;  /* PA_VIEW - Not used (yet) */
  153. unsigned long iop_base;    /* PA_VIEW - for IO port accessor funcs */
  154. #endif
  155. int flags;       /* state/functionality enabled */
  156. int hw_rev;      /* HW revision of chip */
  157. };
  158. static u32 lba_t32;
  159. /*
  160. ** lba "flags"
  161. */
  162. #define LBA_FLAG_NO_DMA_DURING_CFG 0x01
  163. #define LBA_FLAG_SKIP_PROBE 0x10
  164. /* Tape Release 4 == hw_rev 5 */
  165. #define LBA_TR4PLUS(d)      ((d)->hw_rev > 0x4)
  166. #define LBA_DMA_DURING_CFG_DISABLED(d) ((d)->flags & LBA_FLAG_NO_DMA_DURING_CFG)
  167. #define LBA_SKIP_PROBE(d) ((d)->flags & LBA_FLAG_SKIP_PROBE)
  168. /* Looks nice and keeps the compiler happy */
  169. #define LBA_DEV(d) ((struct lba_device *) (d))
  170. /*
  171. ** Only allow 8 subsidiary busses per LBA
  172. ** Problem is the PCI bus numbering is globally shared.
  173. */
  174. #define LBA_MAX_NUM_BUSES 8
  175. /************************************
  176.  * LBA register read and write support
  177.  *
  178.  * BE WARNED: register writes are posted.
  179.  *  (ie follow writes which must reach HW with a read)
  180.  */
  181. #define READ_U8(addr)  __raw_readb(addr)
  182. #define READ_U16(addr) __raw_readw(addr)
  183. #define READ_U32(addr) __raw_readl(addr)
  184. #define WRITE_U8(value, addr)  __raw_writeb(value, addr)
  185. #define WRITE_U16(value, addr) __raw_writew(value, addr)
  186. #define WRITE_U32(value, addr) __raw_writel(value, addr)
  187. #define READ_REG8(addr)  readb(addr)
  188. #define READ_REG16(addr) readw(addr)
  189. #define READ_REG32(addr) readl(addr)
  190. #define READ_REG64(addr) readq(addr)
  191. #define WRITE_REG8(value, addr)  writeb(value, addr)
  192. #define WRITE_REG16(value, addr) writew(value, addr)
  193. #define WRITE_REG32(value, addr) writel(value, addr)
  194. #define LBA_CFG_TOK(bus,dfn) ((u32) ((bus)<<16 | (dfn)<<8))
  195. #define LBA_CFG_BUS(tok)  ((u8) ((tok)>>16))
  196. #define LBA_CFG_DEV(tok)  ((u8) ((tok)>>11) & 0x1f)
  197. #define LBA_CFG_FUNC(tok) ((u8) ((tok)>>8 ) & 0x7)
  198. /*
  199. ** Extract LBA (Rope) number from HPA
  200. ** REVISIT: 16 ropes for Stretch/Ike?
  201. */
  202. #define ROPES_PER_SBA 8
  203. #define LBA_NUM(x)    ((((unsigned long) x) >> 13) & (ROPES_PER_SBA-1))
  204. static void
  205. lba_dump_res(struct resource *r, int d)
  206. {
  207. int i;
  208. if (NULL == r)
  209. return;
  210. printk(KERN_DEBUG "(%p)", r->parent);
  211. for (i = d; i ; --i) printk(" ");
  212. printk(KERN_DEBUG "%p [%lx,%lx]/%xn", r, r->start, r->end, (int) r->flags);
  213. lba_dump_res(r->child, d+2);
  214. lba_dump_res(r->sibling, d);
  215. }
  216. /*
  217. ** LBA rev 2.0, 2.1, 2.2, and 3.0 bus walks require a complex
  218. ** workaround for cfg cycles:
  219. ** -- preserve  LBA state
  220. ** -- LBA_FLAG_NO_DMA_DURING_CFG workaround
  221. ** -- turn on smart mode
  222. ** -- probe with config writes before doing config reads
  223. ** -- check ERROR_STATUS
  224. ** -- clear ERROR_STATUS
  225. ** -- restore LBA state
  226. **
  227. ** The workaround is only used for device discovery.
  228. */
  229. static int
  230. lba_device_present( u8 bus, u8 dfn, struct lba_device *d)
  231. {
  232. u8 first_bus = d->hba.hba_bus->secondary;
  233. u8 last_sub_bus = d->hba.hba_bus->subordinate;
  234. #if 0
  235. /* FIXME - see below in this function */
  236.         u8 dev = PCI_SLOT(dfn);
  237.         u8 func = PCI_FUNC(dfn);
  238. #endif
  239. ASSERT(bus >= first_bus);
  240. ASSERT(bus <= last_sub_bus);
  241. ASSERT((bus - first_bus) < LBA_MAX_NUM_BUSES);
  242. if ((bus < first_bus) ||
  243.     (bus > last_sub_bus) ||
  244.     ((bus - first_bus) >= LBA_MAX_NUM_BUSES))
  245. {
  246.     /* devices that fall into any of these cases won't get claimed */
  247.     return(FALSE);
  248. }
  249. #if 0
  250. /*
  251. ** FIXME: Need to implement code to fill the devices bitmap based
  252. ** on contents of the local pci_bus tree "data base".
  253. ** pci_register_ops() walks the bus for us and builds the tree.
  254. ** For now, always do the config cycle.
  255. */
  256. bus -= first_bus;
  257. return (((d->devices[bus][dev]) >> func) & 0x1);
  258. #else
  259. return TRUE;
  260. #endif
  261. }
  262. #define LBA_CFG_SETUP(d, tok) {
  263.     /* Save contents of error config register.  */
  264.     error_config = READ_REG32(d->hba.base_addr + LBA_ERROR_CONFIG);
  265.     /* Save contents of status control register.  */
  266.     status_control = READ_REG32(d->hba.base_addr + LBA_STAT_CTL);
  267.     /* For LBA rev 2.0, 2.1, 2.2, and 3.0, we must disable DMA
  268.     ** arbitration for full bus walks.
  269.     */
  270.     if (LBA_DMA_DURING_CFG_DISABLED(d)) {
  271. /* Save contents of arb mask register. */
  272. arb_mask = READ_REG32(d->hba.base_addr + LBA_ARB_MASK);
  273. /*
  274.  * Turn off all device arbitration bits (i.e. everything
  275.  * except arbitration enable bit).
  276.  */
  277. WRITE_REG32(0x1, d->hba.base_addr + LBA_ARB_MASK);
  278.     }
  279.     /*
  280.      * Set the smart mode bit so that master aborts don't cause
  281.      * LBA to go into PCI fatal mode (required).
  282.      */
  283.     WRITE_REG32(error_config | LBA_SMART_MODE, d->hba.base_addr + LBA_ERROR_CONFIG);
  284. }
  285. #define LBA_CFG_PROBE(d, tok) {
  286.     /*
  287.      * Setup Vendor ID write and read back the address register
  288.      * to make sure that LBA is the bus master.
  289.      */
  290.     WRITE_REG32(tok | PCI_VENDOR_ID, (d)->hba.base_addr + LBA_PCI_CFG_ADDR);
  291.     /*
  292.      * Read address register to ensure that LBA is the bus master,
  293.      * which implies that DMA traffic has stopped when DMA arb is off.
  294.      */
  295.     lba_t32 = READ_REG32((d)->hba.base_addr + LBA_PCI_CFG_ADDR);
  296.     /*
  297.      * Generate a cfg write cycle (will have no affect on
  298.      * Vendor ID register since read-only).
  299.      */
  300.     WRITE_REG32(~0, (d)->hba.base_addr + LBA_PCI_CFG_DATA);
  301.     /*
  302.      * Make sure write has completed before proceeding further,
  303.      * i.e. before setting clear enable.
  304.      */
  305.     lba_t32 = READ_REG32((d)->hba.base_addr + LBA_PCI_CFG_ADDR);
  306. }
  307. /*
  308.  * HPREVISIT:
  309.  *   -- Can't tell if config cycle got the error.
  310.  *
  311.  * OV bit is broken until rev 4.0, so can't use OV bit and
  312.  * LBA_ERROR_LOG_ADDR to tell if error belongs to config cycle.
  313.  *
  314.  * As of rev 4.0, no longer need the error check.
  315.  *
  316.  *   -- Even if we could tell, we still want to return -1
  317.  * for **ANY** error (not just master abort).
  318.  *
  319.  *   -- Only clear non-fatal errors (we don't want to bring
  320.  * LBA out of pci-fatal mode).
  321.  *
  322.  * Actually, there is still a race in which
  323.  * we could be clearing a fatal error.  We will
  324.  * live with this during our initial bus walk
  325.  * until rev 4.0 (no driver activity during
  326.  * initial bus walk).  The initial bus walk
  327.  * has race conditions concerning the use of
  328.  * smart mode as well.
  329.  */
  330. #define LBA_MASTER_ABORT_ERROR 0xc
  331. #define LBA_FATAL_ERROR 0x10
  332. #define LBA_CFG_MASTER_ABORT_CHECK(d, base, tok, error) {
  333.     u32 error_status = 0;
  334.     /*
  335.      * Set clear enable (CE) bit. Unset by HW when new
  336.      * errors are logged -- LBA HW ERS section 14.3.3).
  337.      */
  338.     WRITE_REG32(status_control | CLEAR_ERRLOG_ENABLE, base + LBA_STAT_CTL); 
  339.     error_status = READ_REG32(base + LBA_ERROR_STATUS);
  340.     if ((error_status & 0x1f) != 0) {
  341. /*
  342.  * Fail the config read request.
  343.  */
  344. error = 1;
  345. if ((error_status & LBA_FATAL_ERROR) == 0) {
  346.     /*
  347.      * Clear error status (if fatal bit not set) by setting
  348.      * clear error log bit (CL).
  349.      */
  350.     WRITE_REG32(status_control | CLEAR_ERRLOG, base + LBA_STAT_CTL); 
  351. }
  352.     }
  353. }
  354. #define LBA_CFG_TR4_ADDR_SETUP(d, addr) 
  355.     WRITE_REG32(((addr) & ~3), (d)->hba.base_addr + LBA_PCI_CFG_ADDR)
  356. #define LBA_CFG_ADDR_SETUP(d, addr) {
  357.     WRITE_REG32(((addr) & ~3), (d)->hba.base_addr + LBA_PCI_CFG_ADDR);
  358.     /*
  359.      * HPREVISIT:
  360.      *       -- Potentially could skip this once DMA bug fixed.
  361.      *
  362.      * Read address register to ensure that LBA is the bus master,
  363.      * which implies that DMA traffic has stopped when DMA arb is off.
  364.      */
  365.     lba_t32 = READ_REG32((d)->hba.base_addr + LBA_PCI_CFG_ADDR);
  366. }
  367. #define LBA_CFG_RESTORE(d, base) {
  368.     /*
  369.      * Restore status control register (turn off clear enable).
  370.      */
  371.     WRITE_REG32(status_control, base + LBA_STAT_CTL);
  372.     /*
  373.      * Restore error config register (turn off smart mode).
  374.      */
  375.     WRITE_REG32(error_config, base + LBA_ERROR_CONFIG);
  376.     if (LBA_DMA_DURING_CFG_DISABLED(d)) {
  377. /*
  378.  * Restore arb mask register (reenables DMA arbitration).
  379.  */
  380. WRITE_REG32(arb_mask, base + LBA_ARB_MASK);
  381.     }
  382. }
  383. static unsigned int
  384. lba_rd_cfg(struct lba_device *d, u32 tok, u8 reg, u32 size)
  385. {
  386. u32 data = ~0;
  387. int error = 0;
  388. u32 arb_mask = 0; /* used by LBA_CFG_SETUP/RESTORE */
  389. u32 error_config = 0; /* used by LBA_CFG_SETUP/RESTORE */
  390. u32 status_control = 0; /* used by LBA_CFG_SETUP/RESTORE */
  391. ASSERT((size == sizeof(u8)) ||
  392. (size == sizeof(u16)) ||
  393. (size == sizeof(u32)));
  394. if ((size != sizeof(u8)) &&
  395. (size != sizeof(u16)) &&
  396. (size != sizeof(u32))) {
  397. return(data);
  398. }
  399. LBA_CFG_SETUP(d, tok);
  400. LBA_CFG_PROBE(d, tok);
  401. LBA_CFG_MASTER_ABORT_CHECK(d, d->hba.base_addr, tok, error);
  402. if (!error) {
  403. LBA_CFG_ADDR_SETUP(d, tok | reg);
  404. switch (size) {
  405. case sizeof(u8):
  406. data = (u32) READ_REG8(d->hba.base_addr + LBA_PCI_CFG_DATA + (reg & 3));
  407. break;
  408. case sizeof(u16):
  409. data = (u32) READ_REG16(d->hba.base_addr + LBA_PCI_CFG_DATA + (reg & 2));
  410. break;
  411. case sizeof(u32):
  412. data = READ_REG32(d->hba.base_addr + LBA_PCI_CFG_DATA);
  413. break;
  414. default:
  415. break; /* leave data as -1 */
  416. }
  417. }
  418. LBA_CFG_RESTORE(d, d->hba.base_addr);
  419. return(data);
  420. }
  421. #define LBA_CFG_RD(size, mask) 
  422. static int lba_cfg_read##size (struct pci_dev *dev, int pos, u##size *data) 
  423. struct lba_device *d = LBA_DEV(dev->bus->sysdata); 
  424. u32 local_bus = (dev->bus->parent == NULL) ? 0 : dev->bus->secondary; 
  425. u32 tok = LBA_CFG_TOK(local_bus,dev->devfn); 
  426.  
  427. /* FIXME: B2K/C3600 workaround is always use old method... */ 
  428. /* if (!LBA_TR4PLUS(d) && !LBA_SKIP_PROBE(d)) */ { 
  429. /* original - Generate config cycle on broken elroy 
  430.   with risk we will miss PCI bus errors. */ 
  431. *data = (u##size) lba_rd_cfg(d, tok, pos, sizeof(u##size)); 
  432. DBG_CFG("%s(%s+%2x) -> 0x%x (a)n", __FUNCTION__, dev->slot_name, pos, *data); 
  433. return(*data == (u##size) -1); 
  434.  
  435. if (LBA_SKIP_PROBE(d) && (!lba_device_present(dev->bus->secondary, dev->devfn, d))) 
  436. DBG_CFG("%s(%s+%2x) -> -1 (b)n", __FUNCTION__, dev->slot_name, pos); 
  437. /* either don't want to look or know device isn't present. */ 
  438. *data = (u##size) -1; 
  439. return(0); 
  440.  
  441. /* Basic Algorithm 
  442. ** Should only get here on fully working LBA rev. 
  443. ** This is how simple the code should have been. 
  444. */ 
  445. LBA_CFG_TR4_ADDR_SETUP(d, tok | pos); 
  446. *data = READ_REG##size(d->hba.base_addr + LBA_PCI_CFG_DATA + (pos & mask));
  447. DBG_CFG("%s(%s+%2x) -> 0x%x (c)n", __FUNCTION__, dev->slot_name, pos, *data);
  448. return(*data == (u##size) -1); 
  449. }
  450. LBA_CFG_RD( 8, 3) 
  451. LBA_CFG_RD(16, 2) 
  452. LBA_CFG_RD(32, 0) 
  453. static void
  454. lba_wr_cfg( struct lba_device *d, u32 tok, u8 reg, u32 data, u32 size)
  455. {
  456. int error = 0;
  457. u32 arb_mask = 0;
  458. u32 error_config = 0;
  459. u32 status_control = 0;
  460. ASSERT((size == sizeof(u8)) ||
  461. (size == sizeof(u16)) ||
  462. (size == sizeof(u32)));
  463. if ((size != sizeof(u8)) &&
  464. (size != sizeof(u16)) &&
  465. (size != sizeof(u32))) {
  466. return;
  467. }
  468. LBA_CFG_SETUP(d, tok);
  469. LBA_CFG_ADDR_SETUP(d, tok | reg);
  470. switch (size) {
  471. case sizeof(u8):
  472. WRITE_REG8((u8) data, d->hba.base_addr + LBA_PCI_CFG_DATA + (reg&3));
  473. break;
  474. case sizeof(u16):
  475. WRITE_REG16((u8) data, d->hba.base_addr + LBA_PCI_CFG_DATA +(reg&2));
  476. break;
  477. case sizeof(u32):
  478. WRITE_REG32(data, d->hba.base_addr + LBA_PCI_CFG_DATA);
  479. break;
  480. default:
  481. break;
  482. }
  483. LBA_CFG_MASTER_ABORT_CHECK(d, d->hba.base_addr, tok, error);
  484. LBA_CFG_RESTORE(d, d->hba.base_addr);
  485. }
  486. /*
  487.  * LBA 4.0 config write code implements non-postable semantics
  488.  * by doing a read of CONFIG ADDR after the write.
  489.  */
  490. #define LBA_CFG_WR(size, mask) 
  491. static int lba_cfg_write##size (struct pci_dev *dev, int pos, u##size data) 
  492. struct lba_device *d = LBA_DEV(dev->bus->sysdata); 
  493. u32 local_bus = (dev->bus->parent == NULL) ? 0 : dev->bus->secondary; 
  494. u32 tok = LBA_CFG_TOK(local_bus,dev->devfn); 
  495.  
  496.   ASSERT((tok & 0xff) == 0); 
  497. ASSERT(pos < 0x100); 
  498.  
  499. if (!LBA_TR4PLUS(d) && !LBA_SKIP_PROBE(d)) { 
  500. /* Original Workaround */ 
  501. lba_wr_cfg(d, tok, pos, (u32) data, sizeof(u##size)); 
  502. DBG_CFG("%s(%s+%2x) = 0x%x (a)n", __FUNCTION__, dev->slot_name, pos, data); 
  503. return 0; 
  504.  
  505. if (LBA_SKIP_PROBE(d) && (!lba_device_present(dev->bus->secondary, dev->devfn, d))) { 
  506. DBG_CFG("%s(%s+%2x) = 0x%x (b)n", __FUNCTION__, dev->slot_name, pos, data); 
  507. return 1; /* New Workaround */ 
  508.  
  509. DBG_CFG("%s(%s+%2x) = 0x%x (c)n", __FUNCTION__, dev->slot_name, pos, data); 
  510. /* Basic Algorithm */ 
  511. LBA_CFG_TR4_ADDR_SETUP(d, tok | pos); 
  512. WRITE_REG##size(data, d->hba.base_addr + LBA_PCI_CFG_DATA + (pos & mask)); 
  513. lba_t32 = READ_REG32(d->hba.base_addr + LBA_PCI_CFG_ADDR); 
  514. return 0; 
  515. }
  516. LBA_CFG_WR( 8, 3) 
  517. LBA_CFG_WR(16, 2) 
  518. LBA_CFG_WR(32, 0) 
  519. static struct pci_ops lba_cfg_ops = {
  520. read_byte: lba_cfg_read8,
  521. read_word: lba_cfg_read16,
  522. read_dword: lba_cfg_read32,
  523. write_byte: lba_cfg_write8,
  524. write_word: lba_cfg_write16,
  525. write_dword: lba_cfg_write32
  526. };
  527. static void
  528. lba_bios_init(void)
  529. {
  530. DBG(MODULE_NAME ": lba_bios_initn");
  531. }
  532. #ifdef __LP64__
  533. /*
  534. ** Determine if a device is already configured.
  535. ** If so, reserve it resources.
  536. **
  537. ** Read PCI cfg command register and see if I/O or MMIO is enabled.
  538. ** PAT has to enable the devices it's using.
  539. **
  540. ** Note: resources are fixed up before we try to claim them.
  541. */
  542. static void
  543. lba_claim_dev_resources(struct pci_dev *dev)
  544. {
  545. u16 cmd;
  546. int i, srch_flags;
  547. (void) lba_cfg_read16(dev, PCI_COMMAND, &cmd);
  548. srch_flags  = (cmd & PCI_COMMAND_IO) ? IORESOURCE_IO : 0;
  549. if (cmd & PCI_COMMAND_MEMORY)
  550. srch_flags |= IORESOURCE_MEM;
  551. if (!srch_flags)
  552. return;
  553. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  554. if (dev->resource[i].flags & srch_flags) {
  555. pci_claim_resource(dev, i);
  556. DBG("   claimed %s %d [%lx,%lx]/%xn",
  557. dev->slot_name, i,
  558. dev->resource[i].start,
  559. dev->resource[i].end,
  560. (int) dev->resource[i].flags
  561. );
  562. }
  563. }
  564. }
  565. #endif
  566. /*
  567. ** The algorithm is generic code.
  568. ** But it needs to access local data structures to get the IRQ base.
  569. ** Could make this a "pci_fixup_irq(bus, region)" but not sure
  570. ** it's worth it.
  571. **
  572. ** Called by do_pci_scan_bus() immediately after each PCI bus is walked.
  573. ** Resources aren't allocated until recursive buswalk below HBA is completed.
  574. */
  575. static void
  576. lba_fixup_bus(struct pci_bus *bus)
  577. {
  578. struct list_head *ln;
  579. #ifdef FBB_SUPPORT
  580. u16 fbb_enable = PCI_STATUS_FAST_BACK;
  581. u16 status;
  582. #endif
  583. struct lba_device *ldev = LBA_DEV(bus->sysdata);
  584. int lba_portbase = HBA_PORT_BASE(ldev->hba.hba_num);
  585. DBG("lba_fixup_bus(0x%p) bus %d sysdata 0x%pn",
  586. bus, bus->secondary, bus->sysdata);
  587. /*
  588. ** Properly Setup MMIO resources for this bus.
  589. ** pci_alloc_primary_bus() mangles this.
  590. */
  591. if (NULL == bus->self) {
  592. int err;
  593. DBG("lba_fixup_bus() %s [%lx/%lx]/%xn",
  594. ldev->hba.io_space.name,
  595. ldev->hba.io_space.start, ldev->hba.io_space.end,
  596. (int) ldev->hba.io_space.flags);
  597. DBG("lba_fixup_bus() %s [%lx/%lx]/%xn",
  598. ldev->hba.lmmio_space.name,
  599. ldev->hba.lmmio_space.start, ldev->hba.lmmio_space.end,
  600. (int) ldev->hba.lmmio_space.flags);
  601. err = request_resource(&ioport_resource, &(ldev->hba.io_space));
  602. if (err < 0) {
  603. BUG();
  604. lba_dump_res(&ioport_resource, 2);
  605. }
  606. err = request_resource(&iomem_resource, &(ldev->hba.lmmio_space));
  607. if (err < 0) {
  608. BUG();
  609. lba_dump_res(&iomem_resource, 2);
  610. }
  611. bus->resource[0] = &(ldev->hba.io_space);
  612. bus->resource[1] = &(ldev->hba.lmmio_space);
  613. } else {
  614. /* KLUGE ALERT!
  615. ** PCI-PCI Bridge resource munging.
  616. ** This hack should go away in the near future.
  617. ** It's based on the Alpha port.
  618. */
  619. int i;
  620. u16 cmd;
  621. for (i = 0; i < 4; i++) {
  622. bus->resource[i] =
  623. &bus->self->resource[PCI_BRIDGE_RESOURCES+i];
  624. bus->resource[i]->name = bus->name;
  625. }
  626. #if 0
  627. bus->resource[0]->flags |= pci_bridge_check_io(bus->self);
  628. #else
  629. bus->resource[0]->flags |= IORESOURCE_IO;
  630. #endif
  631. bus->resource[1]->flags |= IORESOURCE_MEM;
  632. bus->resource[2]->flags = 0; /* Don't support prefetchable */
  633. bus->resource[3]->flags = 0; /* not used */
  634. /* 
  635. ** If the PPB is enabled (ie already configured) then
  636. ** just read those values.
  637. */
  638. (void) lba_cfg_read16(bus->self, PCI_COMMAND, &cmd);
  639. if (cmd & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)) {
  640. pci_read_bridge_bases(bus);
  641. } else {
  642. /* Not configured.
  643. ** For now, propogate HBA limits to the bus;
  644. ** PCI will adjust them later.
  645. */
  646. bus->resource[0]->end = ldev->hba.io_space.end;
  647. bus->resource[1]->end = ldev->hba.lmmio_space.end;
  648. }
  649. /* Turn off downstream PF memory address range by default */
  650. bus->resource[2]->start = 1024*1024;
  651. bus->resource[2]->end = bus->resource[2]->start - 1;
  652. }
  653. list_for_each(ln, &bus->devices) {
  654. int i;
  655. struct pci_dev *dev = pci_dev_b(ln);
  656. DBG("lba_fixup_bus() %sn", dev->name);
  657. /* Virtualize Device/Bridge Resources. */
  658. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  659. struct resource *res = &dev->resource[i];
  660. /* If resource not allocated - skip it */
  661. if (!res->start)
  662. continue;
  663. if (res->flags & IORESOURCE_IO) {
  664. DBG("lba_fixup_bus() I/O Ports [%lx/%lx] -> ",
  665. res->start, res->end);
  666. res->start |= lba_portbase;
  667. res->end   |= lba_portbase;
  668. DBG("[%lx/%lx]n", res->start, res->end);
  669. } else if (res->flags & IORESOURCE_MEM) {
  670. /*
  671. ** Convert PCI (IO_VIEW) addresses to
  672. ** processor (PA_VIEW) addresses
  673.  */
  674. DBG("lba_fixup_bus() MMIO [%lx/%lx] -> ",
  675. res->start, res->end);
  676. res->start = PCI_HOST_ADDR(HBA_DATA(ldev), res->start);
  677. res->end   = PCI_HOST_ADDR(HBA_DATA(ldev), res->end);
  678. DBG("[%lx/%lx]n", res->start, res->end);
  679. }
  680. }
  681. #ifdef FBB_SUPPORT
  682. /*
  683. ** If one device does not support FBB transfers,
  684. ** No one on the bus can be allowed to use them.
  685. */
  686. (void) lba_cfg_read16(dev, PCI_STATUS, &status);
  687. fbb_enable &= status;
  688. #endif
  689. #ifdef __LP64__
  690. if (is_pdc_pat()) {
  691. /* Claim resources for PDC's devices */
  692. lba_claim_dev_resources(dev);
  693. }
  694. #endif
  695.                 /*
  696. ** P2PB's have no IRQs. ignore them.
  697. */
  698. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)
  699. continue;
  700. /* Adjust INTERRUPT_LINE for this dev */
  701. iosapic_fixup_irq(ldev->iosapic_obj, dev);
  702. }
  703. #ifdef FBB_SUPPORT
  704. /* FIXME/REVISIT - finish figuring out to set FBB on both
  705. ** pci_setup_bridge() clobbers PCI_BRIDGE_CONTROL.
  706. ** Can't fixup here anyway....garr...
  707. */
  708. if (fbb_enable) {
  709. if (bus->self) {
  710. u8 control;
  711. /* enable on PPB */
  712. (void) lba_cfg_read8(bus->self, PCI_BRIDGE_CONTROL, &control);
  713. (void) lba_cfg_write8(bus->self, PCI_BRIDGE_CONTROL, control | PCI_STATUS_FAST_BACK);
  714. } else {
  715. /* enable on LBA */
  716. }
  717. fbb_enable = PCI_COMMAND_FAST_BACK;
  718. }
  719. /* Lastly enable FBB/PERR/SERR on all devices too */
  720. list_for_each(ln, &bus->devices) {
  721. (void) lba_cfg_read16(dev, PCI_COMMAND, &status);
  722. status |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR | fbb_enable;
  723. (void) lba_cfg_write16(dev, PCI_COMMAND, status);
  724. }
  725. #endif
  726. }
  727. struct pci_bios_ops lba_bios_ops = {
  728. init: lba_bios_init,
  729. fixup_bus: lba_fixup_bus,
  730. };
  731. /*******************************************************
  732. **
  733. ** LBA Sprockets "I/O Port" Space Accessor Functions
  734. **
  735. ** This set of accessor functions is intended for use with
  736. ** "legacy firmware" (ie Sprockets on Allegro/Forte boxes).
  737. **
  738. ** Many PCI devices don't require use of I/O port space (eg Tulip,
  739. ** NCR720) since they export the same registers to both MMIO and
  740. ** I/O port space. In general I/O port space is slower than
  741. ** MMIO since drivers are designed so PIO writes can be posted.
  742. **
  743. ********************************************************/
  744. #define LBA_PORT_IN(size, mask) 
  745. static u##size lba_astro_in##size (struct pci_hba_data *d, u16 addr) 
  746. u##size t; 
  747. t = READ_REG##size(LBA_ASTRO_PORT_BASE + addr); 
  748. DBG_PORT(" 0x%xn", t); 
  749. return (t); 
  750. }
  751. LBA_PORT_IN( 8, 3)
  752. LBA_PORT_IN(16, 2)
  753. LBA_PORT_IN(32, 0)
  754. /*
  755. ** BUG X4107:  Ordering broken - DMA RD return can bypass PIO WR
  756. **
  757. ** Fixed in Elroy 2.2. The READ_U32(..., LBA_FUNC_ID) below is
  758. ** guarantee non-postable completion semantics - not avoid X4107.
  759. ** The READ_U32 only guarantees the write data gets to elroy but
  760. ** out to the PCI bus. We can't read stuff from I/O port space
  761. ** since we don't know what has side-effects. Attempting to read
  762. ** from configuration space would be suicidal given the number of
  763. ** bugs in that elroy functionality.
  764. **
  765. **      Description:
  766. **          DMA read results can improperly pass PIO writes (X4107).  The
  767. **          result of this bug is that if a processor modifies a location in
  768. **          memory after having issued PIO writes, the PIO writes are not
  769. **          guaranteed to be completed before a PCI device is allowed to see
  770. **          the modified data in a DMA read.
  771. **
  772. **          Note that IKE bug X3719 in TR1 IKEs will result in the same
  773. **          symptom.
  774. **
  775. **      Workaround:
  776. **          The workaround for this bug is to always follow a PIO write with
  777. **          a PIO read to the same bus before starting DMA on that PCI bus.
  778. **
  779. */
  780. #define LBA_PORT_OUT(size, mask) 
  781. static void lba_astro_out##size (struct pci_hba_data *d, u16 addr, u##size val) 
  782. ASSERT(d != NULL); 
  783. DBG_PORT("%s(0x%p, 0x%x, 0x%x)n", __FUNCTION__, d, addr, val); 
  784. WRITE_REG##size(val, LBA_ASTRO_PORT_BASE + addr); 
  785. if (LBA_DEV(d)->hw_rev < 3) 
  786. lba_t32 = READ_U32(d->base_addr + LBA_FUNC_ID); 
  787. }
  788. LBA_PORT_OUT( 8, 3)
  789. LBA_PORT_OUT(16, 2)
  790. LBA_PORT_OUT(32, 0)
  791. static struct pci_port_ops lba_astro_port_ops = {
  792. inb: lba_astro_in8,
  793. inw: lba_astro_in16,
  794. inl: lba_astro_in32,
  795. outb: lba_astro_out8,
  796. outw: lba_astro_out16,
  797. outl: lba_astro_out32
  798. };
  799. #ifdef __LP64__
  800. #define PIOP_TO_GMMIO(lba, addr) 
  801. ((lba)->iop_base + (((addr)&0xFFFC)<<10) + ((addr)&3))
  802. /*******************************************************
  803. **
  804. ** LBA PAT "I/O Port" Space Accessor Functions
  805. **
  806. ** This set of accessor functions is intended for use with
  807. ** "PAT PDC" firmware (ie Prelude/Rhapsody/Piranha boxes).
  808. **
  809. ** This uses the PIOP space located in the first 64MB of GMMIO.
  810. ** Each rope gets a full 64*KB* (ie 4 bytes per page) this way.
  811. ** bits 1:0 stay the same.  bits 15:2 become 25:12.
  812. ** Then add the base and we can generate an I/O Port cycle.
  813. ********************************************************/
  814. #undef LBA_PORT_IN
  815. #define LBA_PORT_IN(size, mask) 
  816. static u##size lba_pat_in##size (struct pci_hba_data *l, u16 addr) 
  817. u##size t; 
  818. ASSERT(bus != NULL); 
  819. DBG_PORT("%s(0x%p, 0x%x) ->", __FUNCTION__, l, addr); 
  820. t = READ_REG##size(PIOP_TO_GMMIO(LBA_DEV(l), addr)); 
  821. DBG_PORT(" 0x%xn", t); 
  822. return (t); 
  823. }
  824. LBA_PORT_IN( 8, 3)
  825. LBA_PORT_IN(16, 2)
  826. LBA_PORT_IN(32, 0)
  827. #undef LBA_PORT_OUT
  828. #define LBA_PORT_OUT(size, mask) 
  829. static void lba_pat_out##size (struct pci_hba_data *l, u16 addr, u##size val) 
  830. void *where = (void *) PIOP_TO_GMMIO(LBA_DEV(l), addr); 
  831. ASSERT(bus != NULL); 
  832. DBG_PORT("%s(0x%p, 0x%x, 0x%x)n", __FUNCTION__, l, addr, val); 
  833. WRITE_REG##size(val, where); 
  834. /* flush the I/O down to the elroy at least */ 
  835. lba_t32 = READ_U32(l->base_addr + LBA_FUNC_ID); 
  836. }
  837. LBA_PORT_OUT( 8, 3)
  838. LBA_PORT_OUT(16, 2)
  839. LBA_PORT_OUT(32, 0)
  840. static struct pci_port_ops lba_pat_port_ops = {
  841. inb: lba_pat_in8,
  842. inw: lba_pat_in16,
  843. inl: lba_pat_in32,
  844. outb: lba_pat_out8,
  845. outw: lba_pat_out16,
  846. outl: lba_pat_out32
  847. };
  848. /*
  849. ** make range information from PDC available to PCI subsystem.
  850. ** We make the PDC call here in order to get the PCI bus range
  851. ** numbers. The rest will get forwarded in pcibios_fixup_bus().
  852. ** We don't have a struct pci_bus assigned to us yet.
  853. */
  854. static void
  855. lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
  856. {
  857. unsigned long bytecnt;
  858. pdc_pat_cell_mod_maddr_block_t pa_pdc_cell; /* PA_VIEW */
  859. pdc_pat_cell_mod_maddr_block_t io_pdc_cell; /* IO_VIEW */
  860. long io_count;
  861. long status; /* PDC return status */
  862. long pa_count;
  863. int i;
  864. /* return cell module (IO view) */
  865. status = pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index,
  866. PA_VIEW, & pa_pdc_cell);
  867. pa_count = pa_pdc_cell.mod[1];
  868. status |= pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index,
  869. IO_VIEW, &io_pdc_cell);
  870. io_count = io_pdc_cell.mod[1];
  871. /* We've already done this once for device discovery...*/
  872. if (status != PDC_OK) {
  873. panic("pdc_pat_cell_module() call failed for LBA!n");
  874. }
  875. if (PAT_GET_ENTITY(pa_pdc_cell.mod_info) != PAT_ENTITY_LBA) {
  876. panic("pdc_pat_cell_module() entity returned != PAT_ENTITY_LBA!n");
  877. }
  878. /*
  879. ** Inspect the resources PAT tells us about
  880. */
  881. for (i = 0; i < pa_count; i++) {
  882. struct {
  883. unsigned long type;
  884. unsigned long start;
  885. unsigned long end; /* aka finish */
  886. } *p, *io;
  887. struct resource *r;
  888. p = (void *) &(pa_pdc_cell.mod[2+i*3]);
  889. io = (void *) &(io_pdc_cell.mod[2+i*3]);
  890. /* Convert the PAT range data to PCI "struct resource" */
  891. switch(p->type & 0xff) {
  892. case PAT_PBNUM:
  893. lba_dev->hba.bus_num.start = p->start;
  894. lba_dev->hba.bus_num.end   = p->end;
  895. break;
  896. case PAT_LMMIO:
  897. /* used to fix up pre-initialized MEM BARs */
  898. lba_dev->hba.lmmio_space_offset = p->start - io->start;
  899. r = &(lba_dev->hba.lmmio_space);
  900. r->name   = "LBA LMMIO";
  901. r->start  = p->start;
  902. r->end    = p->end;
  903. r->flags  = IORESOURCE_MEM;
  904. r->parent = r->sibling = r->child = NULL;
  905. break;
  906. case PAT_GMMIO:
  907. printk(KERN_WARNING MODULE_NAME
  908. " range[%d] : ignoring GMMIO (0x%lx)n",
  909. i, p->start);
  910. lba_dev->gmmio_base = p->start;
  911. break;
  912. case PAT_NPIOP:
  913. printk(KERN_WARNING MODULE_NAME
  914. " range[%d] : ignoring NPIOP (0x%lx)n",
  915. i, p->start);
  916. break;
  917. case PAT_PIOP:
  918. /*
  919. ** Postable I/O port space is per PCI host adapter.
  920. */
  921. /* save base of 64MB PIOP region */
  922. lba_dev->iop_base = p->start;
  923. r = &(lba_dev->hba.io_space);
  924. r->name   = "LBA I/O Port";
  925. r->start  = HBA_PORT_BASE(lba_dev->hba.hba_num);
  926. r->end    = r->start + HBA_PORT_SPACE_SIZE - 1;
  927. r->flags  = IORESOURCE_IO;
  928. r->parent = r->sibling = r->child = NULL;
  929. break;
  930. default:
  931. printk(KERN_WARNING MODULE_NAME
  932. " range[%d] : unknown pat range type (0x%lx)n",
  933. i, p->type & 0xff);
  934. break;
  935. }
  936. }
  937. }
  938. #endif /* __LP64__ */
  939. static void
  940. lba_legacy_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
  941. {
  942. struct resource *r;
  943. unsigned long rsize;
  944. int lba_num;
  945. #ifdef __LP64__
  946. /*
  947. ** Sign extend all BAR values on "legacy" platforms.
  948. ** "Sprockets" PDC (Forte/Allegro) initializes everything
  949. ** for "legacy" 32-bit OS (HPUX 10.20).
  950. ** Upper 32-bits of 64-bit BAR will be zero too.
  951. */
  952. lba_dev->hba.lmmio_space_offset = 0xffffffff00000000UL;
  953. #else
  954. lba_dev->hba.lmmio_space_offset = 0UL;
  955. #endif
  956. /*
  957. ** With "legacy" firmware, the lowest byte of FW_SCRATCH
  958. ** represents bus->secondary and the second byte represents
  959. ** bus->subsidiary (i.e. highest PPB programmed by firmware).
  960. ** PCI bus walk *should* end up with the same result.
  961. ** FIXME: But we don't have sanity checks in PCI or LBA.
  962. */
  963. lba_num = READ_REG32(pa_dev->hpa + LBA_FW_SCRATCH);
  964. r = &(lba_dev->hba.bus_num);
  965. r->name = "LBA PCI Busses";
  966. r->start = lba_num & 0xff;
  967. r->end = (lba_num>>8) & 0xff;
  968. /* Set up local PCI Bus resources - we don't really need
  969. ** them for Legacy boxes but it's nice to see in /proc.
  970. */
  971. r = &(lba_dev->hba.lmmio_space);
  972. r->name  = "LBA PCI LMMIO";
  973. r->flags = IORESOURCE_MEM;
  974. /* Ignore "Range Enable" bit in the BASE register */
  975. r->start = PCI_HOST_ADDR(HBA_DATA(lba_dev),
  976. ((long) READ_REG32(pa_dev->hpa + LBA_LMMIO_BASE)) & ~1UL);
  977. rsize =  ~READ_REG32(pa_dev->hpa + LBA_LMMIO_MASK) + 1;
  978. /*
  979. ** Each rope only gets part of the distributed range.
  980. ** Adjust "window" for this rope
  981. */
  982. rsize /= ROPES_PER_SBA;
  983. r->start += rsize * LBA_NUM(pa_dev->hpa);
  984. r->end = r->start + rsize - 1 ;
  985. /*
  986. ** XXX FIXME - ignore LBA_ELMMIO_BASE for now
  987. ** "Directed" ranges are used when the "distributed range" isn't
  988. ** sufficient for all devices below a given LBA.  Typically devices
  989. ** like graphics cards or X25 may need a directed range when the
  990. ** bus has multiple slots (ie multiple devices) or the device
  991. ** needs more than the typical 4 or 8MB a distributed range offers.
  992. **
  993. ** The main reason for ignoring it now frigging complications.
  994. ** Directed ranges may overlap (and have precedence) over
  995. ** distributed ranges. Ie a distributed range assigned to a unused
  996. ** rope may be used by a directed range on a different rope.
  997. ** Support for graphics devices may require fixing this
  998. ** since they may be assigned a directed range which overlaps
  999. ** an existing (but unused portion of) distributed range.
  1000. */
  1001. r = &(lba_dev->hba.elmmio_space);
  1002. r->name  = "extra LBA PCI LMMIO";
  1003. r->flags = IORESOURCE_MEM;
  1004. r->start = READ_REG32(pa_dev->hpa + LBA_ELMMIO_BASE);
  1005. r->end   = 0;
  1006. /* check Range Enable bit */
  1007. if (r->start & 1) {
  1008. /* First baby step to getting Direct Ranges listed in /proc.
  1009. ** AFAIK, only Sprockets PDC will setup a directed Range.
  1010. */
  1011. r->start &= ~1;
  1012. r->end    = r->start;
  1013. r->end   += ~READ_REG32(pa_dev->hpa + LBA_ELMMIO_MASK);
  1014. printk(KERN_DEBUG "WARNING: Ignoring enabled ELMMIO BASE 0x%0lx  SIZE 0x%lxn",
  1015. r->start,
  1016. r->end + 1);
  1017. }
  1018. r = &(lba_dev->hba.io_space);
  1019. r->name  = "LBA PCI I/O Ports";
  1020. r->flags = IORESOURCE_IO;
  1021. r->start = READ_REG32(pa_dev->hpa + LBA_IOS_BASE) & ~1L;
  1022. r->end   = r->start + (READ_REG32(pa_dev->hpa + LBA_IOS_MASK) ^ (HBA_PORT_SPACE_SIZE - 1));
  1023. /* Virtualize the I/O Port space ranges */
  1024. lba_num = HBA_PORT_BASE(lba_dev->hba.hba_num);
  1025. r->start |= lba_num;
  1026. r->end   |= lba_num;
  1027. }
  1028. /**************************************************************************
  1029. **
  1030. **   LBA initialization code (HW and SW)
  1031. **
  1032. **   o identify LBA chip itself
  1033. **   o initialize LBA chip modes (HardFail)
  1034. **   o FIXME: initialize DMA hints for reasonable defaults
  1035. **   o enable configuration functions
  1036. **   o call pci_register_ops() to discover devs (fixup/fixup_bus get invoked)
  1037. **
  1038. **************************************************************************/
  1039. static int __init
  1040. lba_hw_init(struct lba_device *d)
  1041. {
  1042. u32 stat;
  1043. u32 bus_reset; /* PDC_PAT_BUG */
  1044. #if 0
  1045. printk(KERN_DEBUG "LBA %lx  STAT_CTL %Lx  ERROR_CFG %Lx  STATUS %Lx DMA_CTL %Lxn",
  1046. d->hba.base_addr,
  1047. READ_REG64(d->hba.base_addr + LBA_STAT_CTL),
  1048. READ_REG64(d->hba.base_addr + LBA_ERROR_CONFIG),
  1049. READ_REG64(d->hba.base_addr + LBA_ERROR_STATUS),
  1050. READ_REG64(d->hba.base_addr + LBA_DMA_CTL) );
  1051. printk(KERN_DEBUG " ARB mask %Lx  pri %Lx  mode %Lx  mtlt %Lxn",
  1052. READ_REG64(d->hba.base_addr + LBA_ARB_MASK),
  1053. READ_REG64(d->hba.base_addr + LBA_ARB_PRI),
  1054. READ_REG64(d->hba.base_addr + LBA_ARB_MODE),
  1055. READ_REG64(d->hba.base_addr + LBA_ARB_MTLT) );
  1056. printk(KERN_DEBUG " HINT cfg 0x%Lxn",
  1057. READ_REG64(d->hba.base_addr + LBA_HINT_CFG));
  1058. printk(KERN_DEBUG " HINT reg ");
  1059. { int i;
  1060. for (i=LBA_HINT_BASE; i< (14*8 + LBA_HINT_BASE); i+=8)
  1061. printk(" %Lx", READ_REG64(d->hba.base_addr + i));
  1062. }
  1063. printk("n");
  1064. #endif /* DEBUG_LBA_PAT */
  1065. #ifdef __LP64__
  1066. #warning FIXME add support for PDC_PAT_IO "Get slot status" - OLAR support
  1067. #endif
  1068. /* PDC_PAT_BUG: exhibited in rev 40.48  on L2000 */
  1069. bus_reset = READ_REG32(d->hba.base_addr + LBA_STAT_CTL + 4) & 1;
  1070. if (bus_reset) {
  1071. printk(KERN_DEBUG "NOTICE: PCI bus reset still asserted! (clearing)n");
  1072. }
  1073. stat = READ_REG32(d->hba.base_addr + LBA_ERROR_CONFIG);
  1074. if (stat & LBA_SMART_MODE) {
  1075. printk(KERN_DEBUG "NOTICE: LBA in SMART mode! (cleared)n");
  1076. stat &= ~LBA_SMART_MODE;
  1077. WRITE_REG32(stat, d->hba.base_addr + LBA_ERROR_CONFIG);
  1078. }
  1079. /* Set HF mode as the default (vs. -1 mode). */
  1080.         stat = READ_REG32(d->hba.base_addr + LBA_STAT_CTL);
  1081. WRITE_REG32(stat | HF_ENABLE, d->hba.base_addr + LBA_STAT_CTL);
  1082. /*
  1083. ** Writing a zero to STAT_CTL.rf (bit 0) will clear reset signal
  1084. ** if it's not already set. If we just cleared the PCI Bus Reset
  1085. ** signal, wait a bit for the PCI devices to recover and setup.
  1086. */
  1087. if (bus_reset)
  1088. mdelay(pci_post_reset_delay);
  1089. if (0 == READ_REG32(d->hba.base_addr + LBA_ARB_MASK)) {
  1090. /*
  1091. ** PDC_PAT_BUG: PDC rev 40.48 on L2000.
  1092. ** B2000/C3600/J6000 also have this problem?
  1093. ** 
  1094. ** Elroys with hot pluggable slots don't get configured
  1095. ** correctly if the slot is empty.  ARB_MASK is set to 0
  1096. ** and we can't master transactions on the bus if it's
  1097. ** not at least one. 0x3 enables elroy and first slot.
  1098. */
  1099. printk(KERN_DEBUG "NOTICE: Enabling PCI Arbitrationn");
  1100. WRITE_REG32(0x3, d->hba.base_addr + LBA_ARB_MASK);
  1101. }
  1102. /*
  1103. ** FIXME: Hint registers are programmed with default hint
  1104. ** values by firmware. Hints should be sane even if we
  1105. ** can't reprogram them the way drivers want.
  1106. */
  1107. return 0;
  1108. }
  1109. static void __init
  1110. lba_common_init(struct lba_device *lba_dev)
  1111. {
  1112. pci_bios = &lba_bios_ops;
  1113. pcibios_register_hba(HBA_DATA(lba_dev));
  1114. lba_dev->lba_lock = SPIN_LOCK_UNLOCKED;
  1115. /*
  1116. ** Set flags which depend on hw_rev
  1117. */
  1118. if (!LBA_TR4PLUS(lba_dev)) {
  1119. lba_dev->flags |= LBA_FLAG_NO_DMA_DURING_CFG;
  1120. }
  1121. }
  1122. /*
  1123. ** Determine if lba should claim this chip (return 0) or not (return 1).
  1124. ** If so, initialize the chip and tell other partners in crime they
  1125. ** have work to do.
  1126. */
  1127. static int __init
  1128. lba_driver_callback(struct parisc_device *dev)
  1129. {
  1130. struct lba_device *lba_dev;
  1131. struct pci_bus *lba_bus;
  1132. u32 func_class;
  1133. void *tmp_obj;
  1134. char *version;
  1135. /* Read HW Rev First */
  1136. func_class = READ_REG32(dev->hpa + LBA_FCLASS);
  1137. func_class &= 0xf;
  1138. switch (func_class) {
  1139. case 0: version = "TR1.0"; break;
  1140. case 1: version = "TR2.0"; break;
  1141. case 2: version = "TR2.1"; break;
  1142. case 3: version = "TR2.2"; break;
  1143. case 4: version = "TR3.0"; break;
  1144. case 5: version = "TR4.0"; break;
  1145. default: version = "TR4+";
  1146. }
  1147. printk(KERN_INFO "%s version %s (0x%x) found at 0x%lxn",
  1148. MODULE_NAME, version, func_class & 0xf, dev->hpa);
  1149. /* Just in case we find some prototypes... */
  1150. if (func_class < 2) {
  1151. printk(KERN_WARNING "Can't support LBA older than TR2.1 "
  1152. "- continuing under adversity.n");
  1153. }
  1154. /*
  1155. ** Tell I/O SAPIC driver we have a IRQ handler/region.
  1156. */
  1157. tmp_obj = iosapic_register(dev->hpa + LBA_IOSAPIC_BASE);
  1158. /* NOTE: PCI devices (e.g. 103c:1005 graphics card) which don't
  1159. ** have an IRT entry will get NULL back from iosapic code.
  1160. */
  1161. lba_dev = kmalloc(sizeof(struct lba_device), GFP_KERNEL);
  1162. if (NULL == lba_dev)
  1163. {
  1164. printk(KERN_ERR "lba_init_chip - couldn't alloc lba_devicen");
  1165. return(1);
  1166. }
  1167. memset(lba_dev, 0, sizeof(struct lba_device));
  1168. /* ---------- First : initialize data we already have --------- */
  1169. /*
  1170. ** Need hw_rev to adjust configuration space behavior.
  1171. ** LBA_TR4PLUS macro uses hw_rev field.
  1172. */
  1173. lba_dev->hw_rev = func_class;
  1174. lba_dev->hba.base_addr = dev->hpa;  /* faster access */
  1175. lba_dev->hba.dev = dev;
  1176. lba_dev->iosapic_obj = tmp_obj;  /* save interrupt handle */
  1177. lba_dev->hba.iommu = sba_get_iommu(dev);  /* get iommu data */
  1178. /* ------------ Second : initialize common stuff ---------- */
  1179. lba_common_init(lba_dev);
  1180. if (lba_hw_init(lba_dev))
  1181. return(1);
  1182. /* ---------- Third : setup I/O Port and MMIO resources  --------- */
  1183. #ifdef __LP64__
  1184. if (is_pdc_pat()) {
  1185. /* PDC PAT firmware uses PIOP region of GMMIO space. */
  1186. pci_port = &lba_pat_port_ops;
  1187. /* Go ask PDC PAT what resources this LBA has */
  1188. lba_pat_resources(dev, lba_dev);
  1189. } else
  1190. #endif
  1191. {
  1192. /* Sprockets PDC uses NPIOP region */
  1193. pci_port = &lba_astro_port_ops;
  1194. /* Poke the chip a bit for /proc output */
  1195. lba_legacy_resources(dev, lba_dev);
  1196. }
  1197. /* 
  1198. ** Tell PCI support another PCI bus was found.
  1199. ** Walks PCI bus for us too.
  1200. */
  1201. lba_bus = lba_dev->hba.hba_bus =
  1202. pci_scan_bus(lba_dev->hba.bus_num.start, &lba_cfg_ops, (void *) lba_dev);
  1203. #ifdef __LP64__
  1204. if (is_pdc_pat()) {
  1205. /* assign resources to un-initialized devices */
  1206. DBG_PAT("LBA pcibios_assign_unassigned_resources()n");
  1207. pcibios_assign_unassigned_resources(lba_bus);
  1208. #ifdef DEBUG_LBA_PAT
  1209. DBG_PAT("nLBA PIOP resource treen");
  1210. lba_dump_res(&lba_dev->hba.io_space, 2);
  1211. DBG_PAT("nLBA LMMIO resource treen");
  1212. lba_dump_res(&lba_dev->hba.lmmio_space, 2);
  1213. #endif
  1214. }
  1215. #endif
  1216. /*
  1217. ** Once PCI register ops has walked the bus, access to config
  1218. ** space is restricted. Avoids master aborts on config cycles.
  1219. ** Early LBA revs go fatal on *any* master abort.
  1220. */
  1221. if (!LBA_TR4PLUS(lba_dev)) {
  1222. lba_dev->flags |= LBA_FLAG_SKIP_PROBE;
  1223. }
  1224. /* Whew! Finally done! Tell services we got this one covered. */
  1225. return 0;
  1226. }
  1227. static struct parisc_device_id lba_tbl[] = {
  1228. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x782, 0xa },
  1229. { 0, }
  1230. };
  1231. static struct parisc_driver lba_driver = {
  1232. name: MODULE_NAME,
  1233. id_table: lba_tbl,
  1234. probe: lba_driver_callback
  1235. };
  1236. /*
  1237. ** One time initialization to let the world know the LBA was found.
  1238. ** Must be called exactly once before pci_init().
  1239. */
  1240. void __init lba_init(void)
  1241. {
  1242. register_parisc_driver(&lba_driver);
  1243. }
  1244. /*
  1245. ** Initialize the IBASE/IMASK registers for LBA (Elroy).
  1246. ** Only called from sba_iommu.c in order to route ranges (MMIO vs DMA).
  1247. ** sba_iommu is responsible for locking (none needed at init time).
  1248. */
  1249. void
  1250. lba_set_iregs(struct parisc_device *lba, u32 ibase, u32 imask)
  1251. {
  1252. unsigned long base_addr = lba->hpa;
  1253. imask <<= 2; /* adjust for hints - 2 more bits */
  1254. ASSERT((ibase & 0x003fffff) == 0);
  1255. ASSERT((imask & 0x003fffff) == 0);
  1256. DBG("%s() ibase 0x%x imask 0x%xn", __FUNCTION__, ibase, imask);
  1257. WRITE_REG32( imask, base_addr + LBA_IMASK);
  1258. WRITE_REG32( ibase, base_addr + LBA_IBASE);
  1259. }