pci_v3.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. /*
  2. * linux/arch/arm/mach-integrator/pci_v3.c
  3. *
  4. * PCI functions for V3 host PCI bridge
  5. *
  6. * Copyright (C) 1999 ARM Limited
  7. * Copyright (C) 2000-2001 Deep Blue Solutions Ltd
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/pci.h>
  25. #include <linux/ioport.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/init.h>
  29. #include <linux/io.h>
  30. #include <linux/platform_device.h>
  31. #include <mach/hardware.h>
  32. #include <mach/platform.h>
  33. #include <mach/irqs.h>
  34. #include <asm/signal.h>
  35. #include <asm/mach/pci.h>
  36. #include <asm/irq_regs.h>
  37. /*
  38. * V3 Local Bus to PCI Bridge definitions
  39. *
  40. * Registers (these are taken from page 129 of the EPC User's Manual Rev 1.04
  41. * All V3 register names are prefaced by V3_ to avoid clashing with any other
  42. * PCI definitions. Their names match the user's manual.
  43. *
  44. * I'm assuming that I20 is disabled.
  45. *
  46. */
  47. #define V3_PCI_VENDOR 0x00000000
  48. #define V3_PCI_DEVICE 0x00000002
  49. #define V3_PCI_CMD 0x00000004
  50. #define V3_PCI_STAT 0x00000006
  51. #define V3_PCI_CC_REV 0x00000008
  52. #define V3_PCI_HDR_CFG 0x0000000C
  53. #define V3_PCI_IO_BASE 0x00000010
  54. #define V3_PCI_BASE0 0x00000014
  55. #define V3_PCI_BASE1 0x00000018
  56. #define V3_PCI_SUB_VENDOR 0x0000002C
  57. #define V3_PCI_SUB_ID 0x0000002E
  58. #define V3_PCI_ROM 0x00000030
  59. #define V3_PCI_BPARAM 0x0000003C
  60. #define V3_PCI_MAP0 0x00000040
  61. #define V3_PCI_MAP1 0x00000044
  62. #define V3_PCI_INT_STAT 0x00000048
  63. #define V3_PCI_INT_CFG 0x0000004C
  64. #define V3_LB_BASE0 0x00000054
  65. #define V3_LB_BASE1 0x00000058
  66. #define V3_LB_MAP0 0x0000005E
  67. #define V3_LB_MAP1 0x00000062
  68. #define V3_LB_BASE2 0x00000064
  69. #define V3_LB_MAP2 0x00000066
  70. #define V3_LB_SIZE 0x00000068
  71. #define V3_LB_IO_BASE 0x0000006E
  72. #define V3_FIFO_CFG 0x00000070
  73. #define V3_FIFO_PRIORITY 0x00000072
  74. #define V3_FIFO_STAT 0x00000074
  75. #define V3_LB_ISTAT 0x00000076
  76. #define V3_LB_IMASK 0x00000077
  77. #define V3_SYSTEM 0x00000078
  78. #define V3_LB_CFG 0x0000007A
  79. #define V3_PCI_CFG 0x0000007C
  80. #define V3_DMA_PCI_ADR0 0x00000080
  81. #define V3_DMA_PCI_ADR1 0x00000090
  82. #define V3_DMA_LOCAL_ADR0 0x00000084
  83. #define V3_DMA_LOCAL_ADR1 0x00000094
  84. #define V3_DMA_LENGTH0 0x00000088
  85. #define V3_DMA_LENGTH1 0x00000098
  86. #define V3_DMA_CSR0 0x0000008B
  87. #define V3_DMA_CSR1 0x0000009B
  88. #define V3_DMA_CTLB_ADR0 0x0000008C
  89. #define V3_DMA_CTLB_ADR1 0x0000009C
  90. #define V3_DMA_DELAY 0x000000E0
  91. #define V3_MAIL_DATA 0x000000C0
  92. #define V3_PCI_MAIL_IEWR 0x000000D0
  93. #define V3_PCI_MAIL_IERD 0x000000D2
  94. #define V3_LB_MAIL_IEWR 0x000000D4
  95. #define V3_LB_MAIL_IERD 0x000000D6
  96. #define V3_MAIL_WR_STAT 0x000000D8
  97. #define V3_MAIL_RD_STAT 0x000000DA
  98. #define V3_QBA_MAP 0x000000DC
  99. /* PCI COMMAND REGISTER bits
  100. */
  101. #define V3_COMMAND_M_FBB_EN (1 << 9)
  102. #define V3_COMMAND_M_SERR_EN (1 << 8)
  103. #define V3_COMMAND_M_PAR_EN (1 << 6)
  104. #define V3_COMMAND_M_MASTER_EN (1 << 2)
  105. #define V3_COMMAND_M_MEM_EN (1 << 1)
  106. #define V3_COMMAND_M_IO_EN (1 << 0)
  107. /* SYSTEM REGISTER bits
  108. */
  109. #define V3_SYSTEM_M_RST_OUT (1 << 15)
  110. #define V3_SYSTEM_M_LOCK (1 << 14)
  111. /* PCI_CFG bits
  112. */
  113. #define V3_PCI_CFG_M_I2O_EN (1 << 15)
  114. #define V3_PCI_CFG_M_IO_REG_DIS (1 << 14)
  115. #define V3_PCI_CFG_M_IO_DIS (1 << 13)
  116. #define V3_PCI_CFG_M_EN3V (1 << 12)
  117. #define V3_PCI_CFG_M_RETRY_EN (1 << 10)
  118. #define V3_PCI_CFG_M_AD_LOW1 (1 << 9)
  119. #define V3_PCI_CFG_M_AD_LOW0 (1 << 8)
  120. /* PCI_BASE register bits (PCI -> Local Bus)
  121. */
  122. #define V3_PCI_BASE_M_ADR_BASE 0xFFF00000
  123. #define V3_PCI_BASE_M_ADR_BASEL 0x000FFF00
  124. #define V3_PCI_BASE_M_PREFETCH (1 << 3)
  125. #define V3_PCI_BASE_M_TYPE (3 << 1)
  126. #define V3_PCI_BASE_M_IO (1 << 0)
  127. /* PCI MAP register bits (PCI -> Local bus)
  128. */
  129. #define V3_PCI_MAP_M_MAP_ADR 0xFFF00000
  130. #define V3_PCI_MAP_M_RD_POST_INH (1 << 15)
  131. #define V3_PCI_MAP_M_ROM_SIZE (3 << 10)
  132. #define V3_PCI_MAP_M_SWAP (3 << 8)
  133. #define V3_PCI_MAP_M_ADR_SIZE 0x000000F0
  134. #define V3_PCI_MAP_M_REG_EN (1 << 1)
  135. #define V3_PCI_MAP_M_ENABLE (1 << 0)
  136. /*
  137. * LB_BASE0,1 register bits (Local bus -> PCI)
  138. */
  139. #define V3_LB_BASE_ADR_BASE 0xfff00000
  140. #define V3_LB_BASE_SWAP (3 << 8)
  141. #define V3_LB_BASE_ADR_SIZE (15 << 4)
  142. #define V3_LB_BASE_PREFETCH (1 << 3)
  143. #define V3_LB_BASE_ENABLE (1 << 0)
  144. #define V3_LB_BASE_ADR_SIZE_1MB (0 << 4)
  145. #define V3_LB_BASE_ADR_SIZE_2MB (1 << 4)
  146. #define V3_LB_BASE_ADR_SIZE_4MB (2 << 4)
  147. #define V3_LB_BASE_ADR_SIZE_8MB (3 << 4)
  148. #define V3_LB_BASE_ADR_SIZE_16MB (4 << 4)
  149. #define V3_LB_BASE_ADR_SIZE_32MB (5 << 4)
  150. #define V3_LB_BASE_ADR_SIZE_64MB (6 << 4)
  151. #define V3_LB_BASE_ADR_SIZE_128MB (7 << 4)
  152. #define V3_LB_BASE_ADR_SIZE_256MB (8 << 4)
  153. #define V3_LB_BASE_ADR_SIZE_512MB (9 << 4)
  154. #define V3_LB_BASE_ADR_SIZE_1GB (10 << 4)
  155. #define V3_LB_BASE_ADR_SIZE_2GB (11 << 4)
  156. #define v3_addr_to_lb_base(a) ((a) & V3_LB_BASE_ADR_BASE)
  157. /*
  158. * LB_MAP0,1 register bits (Local bus -> PCI)
  159. */
  160. #define V3_LB_MAP_MAP_ADR 0xfff0
  161. #define V3_LB_MAP_TYPE (7 << 1)
  162. #define V3_LB_MAP_AD_LOW_EN (1 << 0)
  163. #define V3_LB_MAP_TYPE_IACK (0 << 1)
  164. #define V3_LB_MAP_TYPE_IO (1 << 1)
  165. #define V3_LB_MAP_TYPE_MEM (3 << 1)
  166. #define V3_LB_MAP_TYPE_CONFIG (5 << 1)
  167. #define V3_LB_MAP_TYPE_MEM_MULTIPLE (6 << 1)
  168. #define v3_addr_to_lb_map(a) (((a) >> 16) & V3_LB_MAP_MAP_ADR)
  169. /*
  170. * LB_BASE2 register bits (Local bus -> PCI IO)
  171. */
  172. #define V3_LB_BASE2_ADR_BASE 0xff00
  173. #define V3_LB_BASE2_SWAP (3 << 6)
  174. #define V3_LB_BASE2_ENABLE (1 << 0)
  175. #define v3_addr_to_lb_base2(a) (((a) >> 16) & V3_LB_BASE2_ADR_BASE)
  176. /*
  177. * LB_MAP2 register bits (Local bus -> PCI IO)
  178. */
  179. #define V3_LB_MAP2_MAP_ADR 0xff00
  180. #define v3_addr_to_lb_map2(a) (((a) >> 16) & V3_LB_MAP2_MAP_ADR)
  181. /*
  182. * The V3 PCI interface chip in Integrator provides several windows from
  183. * local bus memory into the PCI memory areas. Unfortunately, there
  184. * are not really enough windows for our usage, therefore we reuse
  185. * one of the windows for access to PCI configuration space. The
  186. * memory map is as follows:
  187. *
  188. * Local Bus Memory Usage
  189. *
  190. * 40000000 - 4FFFFFFF PCI memory. 256M non-prefetchable
  191. * 50000000 - 5FFFFFFF PCI memory. 256M prefetchable
  192. * 60000000 - 60FFFFFF PCI IO. 16M
  193. * 61000000 - 61FFFFFF PCI Configuration. 16M
  194. *
  195. * There are three V3 windows, each described by a pair of V3 registers.
  196. * These are LB_BASE0/LB_MAP0, LB_BASE1/LB_MAP1 and LB_BASE2/LB_MAP2.
  197. * Base0 and Base1 can be used for any type of PCI memory access. Base2
  198. * can be used either for PCI I/O or for I20 accesses. By default, uHAL
  199. * uses this only for PCI IO space.
  200. *
  201. * Normally these spaces are mapped using the following base registers:
  202. *
  203. * Usage Local Bus Memory Base/Map registers used
  204. *
  205. * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0
  206. * Mem 50000000 - 5FFFFFFF LB_BASE1/LB_MAP1
  207. * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2
  208. * Cfg 61000000 - 61FFFFFF
  209. *
  210. * This means that I20 and PCI configuration space accesses will fail.
  211. * When PCI configuration accesses are needed (via the uHAL PCI
  212. * configuration space primitives) we must remap the spaces as follows:
  213. *
  214. * Usage Local Bus Memory Base/Map registers used
  215. *
  216. * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0
  217. * Mem 50000000 - 5FFFFFFF LB_BASE0/LB_MAP0
  218. * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2
  219. * Cfg 61000000 - 61FFFFFF LB_BASE1/LB_MAP1
  220. *
  221. * To make this work, the code depends on overlapping windows working.
  222. * The V3 chip translates an address by checking its range within
  223. * each of the BASE/MAP pairs in turn (in ascending register number
  224. * order). It will use the first matching pair. So, for example,
  225. * if the same address is mapped by both LB_BASE0/LB_MAP0 and
  226. * LB_BASE1/LB_MAP1, the V3 will use the translation from
  227. * LB_BASE0/LB_MAP0.
  228. *
  229. * To allow PCI Configuration space access, the code enlarges the
  230. * window mapped by LB_BASE0/LB_MAP0 from 256M to 512M. This occludes
  231. * the windows currently mapped by LB_BASE1/LB_MAP1 so that it can
  232. * be remapped for use by configuration cycles.
  233. *
  234. * At the end of the PCI Configuration space accesses,
  235. * LB_BASE1/LB_MAP1 is reset to map PCI Memory. Finally the window
  236. * mapped by LB_BASE0/LB_MAP0 is reduced in size from 512M to 256M to
  237. * reveal the now restored LB_BASE1/LB_MAP1 window.
  238. *
  239. * NOTE: We do not set up I2O mapping. I suspect that this is only
  240. * for an intelligent (target) device. Using I2O disables most of
  241. * the mappings into PCI memory.
  242. */
  243. static void __iomem *pci_v3_base;
  244. // V3 access routines
  245. #define v3_writeb(o,v) __raw_writeb(v, pci_v3_base + (unsigned int)(o))
  246. #define v3_readb(o) (__raw_readb(pci_v3_base + (unsigned int)(o)))
  247. #define v3_writew(o,v) __raw_writew(v, pci_v3_base + (unsigned int)(o))
  248. #define v3_readw(o) (__raw_readw(pci_v3_base + (unsigned int)(o)))
  249. #define v3_writel(o,v) __raw_writel(v, pci_v3_base + (unsigned int)(o))
  250. #define v3_readl(o) (__raw_readl(pci_v3_base + (unsigned int)(o)))
  251. /*============================================================================
  252. *
  253. * routine: uHALir_PCIMakeConfigAddress()
  254. *
  255. * parameters: bus = which bus
  256. * device = which device
  257. * function = which function
  258. * offset = configuration space register we are interested in
  259. *
  260. * description: this routine will generate a platform dependent config
  261. * address.
  262. *
  263. * calls: none
  264. *
  265. * returns: configuration address to play on the PCI bus
  266. *
  267. * To generate the appropriate PCI configuration cycles in the PCI
  268. * configuration address space, you present the V3 with the following pattern
  269. * (which is very nearly a type 1 (except that the lower two bits are 00 and
  270. * not 01). In order for this mapping to work you need to set up one of
  271. * the local to PCI aperatures to 16Mbytes in length translating to
  272. * PCI configuration space starting at 0x0000.0000.
  273. *
  274. * PCI configuration cycles look like this:
  275. *
  276. * Type 0:
  277. *
  278. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  279. * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
  280. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  281. * | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|0|
  282. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  283. *
  284. * 31:11 Device select bit.
  285. * 10:8 Function number
  286. * 7:2 Register number
  287. *
  288. * Type 1:
  289. *
  290. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  291. * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
  292. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  293. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  294. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  295. *
  296. * 31:24 reserved
  297. * 23:16 bus number (8 bits = 128 possible buses)
  298. * 15:11 Device number (5 bits)
  299. * 10:8 function number
  300. * 7:2 register number
  301. *
  302. */
  303. static DEFINE_RAW_SPINLOCK(v3_lock);
  304. #define PCI_BUS_NONMEM_START 0x00000000
  305. #define PCI_BUS_NONMEM_SIZE SZ_256M
  306. #define PCI_BUS_PREMEM_START PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE
  307. #define PCI_BUS_PREMEM_SIZE SZ_256M
  308. #if PCI_BUS_NONMEM_START & 0x000fffff
  309. #error PCI_BUS_NONMEM_START must be megabyte aligned
  310. #endif
  311. #if PCI_BUS_PREMEM_START & 0x000fffff
  312. #error PCI_BUS_PREMEM_START must be megabyte aligned
  313. #endif
  314. #undef V3_LB_BASE_PREFETCH
  315. #define V3_LB_BASE_PREFETCH 0
  316. static void __iomem *v3_open_config_window(struct pci_bus *bus,
  317. unsigned int devfn, int offset)
  318. {
  319. unsigned int address, mapaddress, busnr;
  320. busnr = bus->number;
  321. /*
  322. * Trap out illegal values
  323. */
  324. BUG_ON(offset > 255);
  325. BUG_ON(busnr > 255);
  326. BUG_ON(devfn > 255);
  327. if (busnr == 0) {
  328. int slot = PCI_SLOT(devfn);
  329. /*
  330. * local bus segment so need a type 0 config cycle
  331. *
  332. * build the PCI configuration "address" with one-hot in
  333. * A31-A11
  334. *
  335. * mapaddress:
  336. * 3:1 = config cycle (101)
  337. * 0 = PCI A1 & A0 are 0 (0)
  338. */
  339. address = PCI_FUNC(devfn) << 8;
  340. mapaddress = V3_LB_MAP_TYPE_CONFIG;
  341. if (slot > 12)
  342. /*
  343. * high order bits are handled by the MAP register
  344. */
  345. mapaddress |= 1 << (slot - 5);
  346. else
  347. /*
  348. * low order bits handled directly in the address
  349. */
  350. address |= 1 << (slot + 11);
  351. } else {
  352. /*
  353. * not the local bus segment so need a type 1 config cycle
  354. *
  355. * address:
  356. * 23:16 = bus number
  357. * 15:11 = slot number (7:3 of devfn)
  358. * 10:8 = func number (2:0 of devfn)
  359. *
  360. * mapaddress:
  361. * 3:1 = config cycle (101)
  362. * 0 = PCI A1 & A0 from host bus (1)
  363. */
  364. mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN;
  365. address = (busnr << 16) | (devfn << 8);
  366. }
  367. /*
  368. * Set up base0 to see all 512Mbytes of memory space (not
  369. * prefetchable), this frees up base1 for re-use by
  370. * configuration memory
  371. */
  372. v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
  373. V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE);
  374. /*
  375. * Set up base1/map1 to point into configuration space.
  376. */
  377. v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) |
  378. V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE);
  379. v3_writew(V3_LB_MAP1, mapaddress);
  380. return PCI_CONFIG_VADDR + address + offset;
  381. }
  382. static void v3_close_config_window(void)
  383. {
  384. /*
  385. * Reassign base1 for use by prefetchable PCI memory
  386. */
  387. v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
  388. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
  389. V3_LB_BASE_ENABLE);
  390. v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
  391. V3_LB_MAP_TYPE_MEM_MULTIPLE);
  392. /*
  393. * And shrink base0 back to a 256M window (NOTE: MAP0 already correct)
  394. */
  395. v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
  396. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
  397. }
  398. static int v3_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  399. int size, u32 *val)
  400. {
  401. void __iomem *addr;
  402. unsigned long flags;
  403. u32 v;
  404. raw_spin_lock_irqsave(&v3_lock, flags);
  405. addr = v3_open_config_window(bus, devfn, where);
  406. switch (size) {
  407. case 1:
  408. v = __raw_readb(addr);
  409. break;
  410. case 2:
  411. v = __raw_readw(addr);
  412. break;
  413. default:
  414. v = __raw_readl(addr);
  415. break;
  416. }
  417. v3_close_config_window();
  418. raw_spin_unlock_irqrestore(&v3_lock, flags);
  419. *val = v;
  420. return PCIBIOS_SUCCESSFUL;
  421. }
  422. static int v3_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  423. int size, u32 val)
  424. {
  425. void __iomem *addr;
  426. unsigned long flags;
  427. raw_spin_lock_irqsave(&v3_lock, flags);
  428. addr = v3_open_config_window(bus, devfn, where);
  429. switch (size) {
  430. case 1:
  431. __raw_writeb((u8)val, addr);
  432. __raw_readb(addr);
  433. break;
  434. case 2:
  435. __raw_writew((u16)val, addr);
  436. __raw_readw(addr);
  437. break;
  438. case 4:
  439. __raw_writel(val, addr);
  440. __raw_readl(addr);
  441. break;
  442. }
  443. v3_close_config_window();
  444. raw_spin_unlock_irqrestore(&v3_lock, flags);
  445. return PCIBIOS_SUCCESSFUL;
  446. }
  447. static struct pci_ops pci_v3_ops = {
  448. .read = v3_read_config,
  449. .write = v3_write_config,
  450. };
  451. static struct resource non_mem = {
  452. .name = "PCI non-prefetchable",
  453. .start = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START,
  454. .end = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1,
  455. .flags = IORESOURCE_MEM,
  456. };
  457. static struct resource pre_mem = {
  458. .name = "PCI prefetchable",
  459. .start = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START,
  460. .end = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1,
  461. .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH,
  462. };
  463. static int __init pci_v3_setup_resources(struct pci_sys_data *sys)
  464. {
  465. if (request_resource(&iomem_resource, &non_mem)) {
  466. printk(KERN_ERR "PCI: unable to allocate non-prefetchable "
  467. "memory region\n");
  468. return -EBUSY;
  469. }
  470. if (request_resource(&iomem_resource, &pre_mem)) {
  471. release_resource(&non_mem);
  472. printk(KERN_ERR "PCI: unable to allocate prefetchable "
  473. "memory region\n");
  474. return -EBUSY;
  475. }
  476. /*
  477. * the mem resource for this bus
  478. * the prefetch mem resource for this bus
  479. */
  480. pci_add_resource_offset(&sys->resources, &non_mem, sys->mem_offset);
  481. pci_add_resource_offset(&sys->resources, &pre_mem, sys->mem_offset);
  482. return 1;
  483. }
  484. /*
  485. * These don't seem to be implemented on the Integrator I have, which
  486. * means I can't get additional information on the reason for the pm2fb
  487. * problems. I suppose I'll just have to mind-meld with the machine. ;)
  488. */
  489. static void __iomem *ap_syscon_base;
  490. #define INTEGRATOR_SC_PCIENABLE_OFFSET 0x18
  491. #define INTEGRATOR_SC_LBFADDR_OFFSET 0x20
  492. #define INTEGRATOR_SC_LBFCODE_OFFSET 0x24
  493. static int
  494. v3_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  495. {
  496. unsigned long pc = instruction_pointer(regs);
  497. unsigned long instr = *(unsigned long *)pc;
  498. #if 0
  499. char buf[128];
  500. sprintf(buf, "V3 fault: addr 0x%08lx, FSR 0x%03x, PC 0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n",
  501. addr, fsr, pc, instr, __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET), __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255,
  502. v3_readb(V3_LB_ISTAT));
  503. printk(KERN_DEBUG "%s", buf);
  504. #endif
  505. v3_writeb(V3_LB_ISTAT, 0);
  506. __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
  507. /*
  508. * If the instruction being executed was a read,
  509. * make it look like it read all-ones.
  510. */
  511. if ((instr & 0x0c100000) == 0x04100000) {
  512. int reg = (instr >> 12) & 15;
  513. unsigned long val;
  514. if (instr & 0x00400000)
  515. val = 255;
  516. else
  517. val = -1;
  518. regs->uregs[reg] = val;
  519. regs->ARM_pc += 4;
  520. return 0;
  521. }
  522. if ((instr & 0x0e100090) == 0x00100090) {
  523. int reg = (instr >> 12) & 15;
  524. regs->uregs[reg] = -1;
  525. regs->ARM_pc += 4;
  526. return 0;
  527. }
  528. return 1;
  529. }
  530. static irqreturn_t v3_irq(int dummy, void *devid)
  531. {
  532. #ifdef CONFIG_DEBUG_LL
  533. struct pt_regs *regs = get_irq_regs();
  534. unsigned long pc = instruction_pointer(regs);
  535. unsigned long instr = *(unsigned long *)pc;
  536. char buf[128];
  537. extern void printascii(const char *);
  538. sprintf(buf, "V3 int %d: pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x "
  539. "ISTAT=%02x\n", IRQ_AP_V3INT, pc, instr,
  540. __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET),
  541. __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255,
  542. v3_readb(V3_LB_ISTAT));
  543. printascii(buf);
  544. #endif
  545. v3_writew(V3_PCI_STAT, 0xf000);
  546. v3_writeb(V3_LB_ISTAT, 0);
  547. __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
  548. #ifdef CONFIG_DEBUG_LL
  549. /*
  550. * If the instruction being executed was a read,
  551. * make it look like it read all-ones.
  552. */
  553. if ((instr & 0x0c100000) == 0x04100000) {
  554. int reg = (instr >> 16) & 15;
  555. sprintf(buf, " reg%d = %08lx\n", reg, regs->uregs[reg]);
  556. printascii(buf);
  557. }
  558. #endif
  559. return IRQ_HANDLED;
  560. }
  561. static int __init pci_v3_setup(int nr, struct pci_sys_data *sys)
  562. {
  563. int ret = 0;
  564. if (!ap_syscon_base)
  565. return -EINVAL;
  566. if (nr == 0) {
  567. sys->mem_offset = PHYS_PCI_MEM_BASE;
  568. ret = pci_v3_setup_resources(sys);
  569. }
  570. return ret;
  571. }
  572. /*
  573. * V3_LB_BASE? - local bus address
  574. * V3_LB_MAP? - pci bus address
  575. */
  576. static void __init pci_v3_preinit(void)
  577. {
  578. unsigned long flags;
  579. unsigned int temp;
  580. pcibios_min_mem = 0x00100000;
  581. /*
  582. * Hook in our fault handler for PCI errors
  583. */
  584. hook_fault_code(4, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
  585. hook_fault_code(6, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
  586. hook_fault_code(8, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
  587. hook_fault_code(10, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
  588. raw_spin_lock_irqsave(&v3_lock, flags);
  589. /*
  590. * Unlock V3 registers, but only if they were previously locked.
  591. */
  592. if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK)
  593. v3_writew(V3_SYSTEM, 0xa05f);
  594. /*
  595. * Setup window 0 - PCI non-prefetchable memory
  596. * Local: 0x40000000 Bus: 0x00000000 Size: 256MB
  597. */
  598. v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
  599. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
  600. v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) |
  601. V3_LB_MAP_TYPE_MEM);
  602. /*
  603. * Setup window 1 - PCI prefetchable memory
  604. * Local: 0x50000000 Bus: 0x10000000 Size: 256MB
  605. */
  606. v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
  607. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
  608. V3_LB_BASE_ENABLE);
  609. v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
  610. V3_LB_MAP_TYPE_MEM_MULTIPLE);
  611. /*
  612. * Setup window 2 - PCI IO
  613. */
  614. v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) |
  615. V3_LB_BASE_ENABLE);
  616. v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0));
  617. /*
  618. * Disable PCI to host IO cycles
  619. */
  620. temp = v3_readw(V3_PCI_CFG) & ~V3_PCI_CFG_M_I2O_EN;
  621. temp |= V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS;
  622. v3_writew(V3_PCI_CFG, temp);
  623. printk(KERN_DEBUG "FIFO_CFG: %04x FIFO_PRIO: %04x\n",
  624. v3_readw(V3_FIFO_CFG), v3_readw(V3_FIFO_PRIORITY));
  625. /*
  626. * Set the V3 FIFO such that writes have higher priority than
  627. * reads, and local bus write causes local bus read fifo flush.
  628. * Same for PCI.
  629. */
  630. v3_writew(V3_FIFO_PRIORITY, 0x0a0a);
  631. /*
  632. * Re-lock the system register.
  633. */
  634. temp = v3_readw(V3_SYSTEM) | V3_SYSTEM_M_LOCK;
  635. v3_writew(V3_SYSTEM, temp);
  636. /*
  637. * Clear any error conditions, and enable write errors.
  638. */
  639. v3_writeb(V3_LB_ISTAT, 0);
  640. v3_writew(V3_LB_CFG, v3_readw(V3_LB_CFG) | (1 << 10));
  641. v3_writeb(V3_LB_IMASK, 0x28);
  642. __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
  643. raw_spin_unlock_irqrestore(&v3_lock, flags);
  644. }
  645. static void __init pci_v3_postinit(void)
  646. {
  647. unsigned int pci_cmd;
  648. pci_cmd = PCI_COMMAND_MEMORY |
  649. PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE;
  650. v3_writew(V3_PCI_CMD, pci_cmd);
  651. v3_writeb(V3_LB_ISTAT, ~0x40);
  652. v3_writeb(V3_LB_IMASK, 0x68);
  653. #if 0
  654. ret = request_irq(IRQ_AP_LBUSTIMEOUT, lb_timeout, 0, "bus timeout", NULL);
  655. if (ret)
  656. printk(KERN_ERR "PCI: unable to grab local bus timeout "
  657. "interrupt: %d\n", ret);
  658. #endif
  659. register_isa_ports(PHYS_PCI_MEM_BASE, PHYS_PCI_IO_BASE, 0);
  660. }
  661. /*
  662. * A small note about bridges and interrupts. The DECchip 21050 (and
  663. * later) adheres to the PCI-PCI bridge specification. This says that
  664. * the interrupts on the other side of a bridge are swizzled in the
  665. * following manner:
  666. *
  667. * Dev Interrupt Interrupt
  668. * Pin on Pin on
  669. * Device Connector
  670. *
  671. * 4 A A
  672. * B B
  673. * C C
  674. * D D
  675. *
  676. * 5 A B
  677. * B C
  678. * C D
  679. * D A
  680. *
  681. * 6 A C
  682. * B D
  683. * C A
  684. * D B
  685. *
  686. * 7 A D
  687. * B A
  688. * C B
  689. * D C
  690. *
  691. * Where A = pin 1, B = pin 2 and so on and pin=0 = default = A.
  692. * Thus, each swizzle is ((pin-1) + (device#-4)) % 4
  693. */
  694. /*
  695. * This routine handles multiple bridges.
  696. */
  697. static u8 __init pci_v3_swizzle(struct pci_dev *dev, u8 *pinp)
  698. {
  699. if (*pinp == 0)
  700. *pinp = 1;
  701. return pci_common_swizzle(dev, pinp);
  702. }
  703. static int irq_tab[4] __initdata = {
  704. IRQ_AP_PCIINT0, IRQ_AP_PCIINT1, IRQ_AP_PCIINT2, IRQ_AP_PCIINT3
  705. };
  706. /*
  707. * map the specified device/slot/pin to an IRQ. This works out such
  708. * that slot 9 pin 1 is INT0, pin 2 is INT1, and slot 10 pin 1 is INT1.
  709. */
  710. static int __init pci_v3_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  711. {
  712. int intnr = ((slot - 9) + (pin - 1)) & 3;
  713. return irq_tab[intnr];
  714. }
  715. static struct hw_pci pci_v3 __initdata = {
  716. .swizzle = pci_v3_swizzle,
  717. .map_irq = pci_v3_map_irq,
  718. .setup = pci_v3_setup,
  719. .nr_controllers = 1,
  720. .ops = &pci_v3_ops,
  721. .preinit = pci_v3_preinit,
  722. .postinit = pci_v3_postinit,
  723. };
  724. static int __init pci_v3_probe(struct platform_device *pdev)
  725. {
  726. int ret;
  727. /* Remap the Integrator system controller */
  728. ap_syscon_base = ioremap(INTEGRATOR_SC_BASE, 0x100);
  729. if (!ap_syscon_base) {
  730. dev_err(&pdev->dev, "unable to remap the AP syscon for PCIv3\n");
  731. return -ENODEV;
  732. }
  733. pci_v3_base = devm_ioremap(&pdev->dev, PHYS_PCI_V3_BASE, SZ_64K);
  734. if (!pci_v3_base) {
  735. dev_err(&pdev->dev, "unable to remap PCIv3 base\n");
  736. return -ENODEV;
  737. }
  738. ret = devm_request_irq(&pdev->dev, IRQ_AP_V3INT, v3_irq, 0, "V3", NULL);
  739. if (ret) {
  740. dev_err(&pdev->dev, "unable to grab PCI error interrupt: %d\n",
  741. ret);
  742. return -ENODEV;
  743. }
  744. pci_common_init(&pci_v3);
  745. return 0;
  746. }
  747. static struct platform_driver pci_v3_driver = {
  748. .driver = {
  749. .name = "pci-v3",
  750. },
  751. };
  752. static int __init pci_v3_init(void)
  753. {
  754. return platform_driver_probe(&pci_v3_driver, pci_v3_probe);
  755. }
  756. subsys_initcall(pci_v3_init);