pci_v3.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. #include <asm/hardware/pci_v3.h>
  38. /*
  39. * The V3 PCI interface chip in Integrator provides several windows from
  40. * local bus memory into the PCI memory areas. Unfortunately, there
  41. * are not really enough windows for our usage, therefore we reuse
  42. * one of the windows for access to PCI configuration space. The
  43. * memory map is as follows:
  44. *
  45. * Local Bus Memory Usage
  46. *
  47. * 40000000 - 4FFFFFFF PCI memory. 256M non-prefetchable
  48. * 50000000 - 5FFFFFFF PCI memory. 256M prefetchable
  49. * 60000000 - 60FFFFFF PCI IO. 16M
  50. * 61000000 - 61FFFFFF PCI Configuration. 16M
  51. *
  52. * There are three V3 windows, each described by a pair of V3 registers.
  53. * These are LB_BASE0/LB_MAP0, LB_BASE1/LB_MAP1 and LB_BASE2/LB_MAP2.
  54. * Base0 and Base1 can be used for any type of PCI memory access. Base2
  55. * can be used either for PCI I/O or for I20 accesses. By default, uHAL
  56. * uses this only for PCI IO space.
  57. *
  58. * Normally these spaces are mapped using the following base registers:
  59. *
  60. * Usage Local Bus Memory Base/Map registers used
  61. *
  62. * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0
  63. * Mem 50000000 - 5FFFFFFF LB_BASE1/LB_MAP1
  64. * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2
  65. * Cfg 61000000 - 61FFFFFF
  66. *
  67. * This means that I20 and PCI configuration space accesses will fail.
  68. * When PCI configuration accesses are needed (via the uHAL PCI
  69. * configuration space primitives) we must remap the spaces as follows:
  70. *
  71. * Usage Local Bus Memory Base/Map registers used
  72. *
  73. * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0
  74. * Mem 50000000 - 5FFFFFFF LB_BASE0/LB_MAP0
  75. * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2
  76. * Cfg 61000000 - 61FFFFFF LB_BASE1/LB_MAP1
  77. *
  78. * To make this work, the code depends on overlapping windows working.
  79. * The V3 chip translates an address by checking its range within
  80. * each of the BASE/MAP pairs in turn (in ascending register number
  81. * order). It will use the first matching pair. So, for example,
  82. * if the same address is mapped by both LB_BASE0/LB_MAP0 and
  83. * LB_BASE1/LB_MAP1, the V3 will use the translation from
  84. * LB_BASE0/LB_MAP0.
  85. *
  86. * To allow PCI Configuration space access, the code enlarges the
  87. * window mapped by LB_BASE0/LB_MAP0 from 256M to 512M. This occludes
  88. * the windows currently mapped by LB_BASE1/LB_MAP1 so that it can
  89. * be remapped for use by configuration cycles.
  90. *
  91. * At the end of the PCI Configuration space accesses,
  92. * LB_BASE1/LB_MAP1 is reset to map PCI Memory. Finally the window
  93. * mapped by LB_BASE0/LB_MAP0 is reduced in size from 512M to 256M to
  94. * reveal the now restored LB_BASE1/LB_MAP1 window.
  95. *
  96. * NOTE: We do not set up I2O mapping. I suspect that this is only
  97. * for an intelligent (target) device. Using I2O disables most of
  98. * the mappings into PCI memory.
  99. */
  100. // V3 access routines
  101. #define v3_writeb(o,v) __raw_writeb(v, PCI_V3_VADDR + (unsigned int)(o))
  102. #define v3_readb(o) (__raw_readb(PCI_V3_VADDR + (unsigned int)(o)))
  103. #define v3_writew(o,v) __raw_writew(v, PCI_V3_VADDR + (unsigned int)(o))
  104. #define v3_readw(o) (__raw_readw(PCI_V3_VADDR + (unsigned int)(o)))
  105. #define v3_writel(o,v) __raw_writel(v, PCI_V3_VADDR + (unsigned int)(o))
  106. #define v3_readl(o) (__raw_readl(PCI_V3_VADDR + (unsigned int)(o)))
  107. /*============================================================================
  108. *
  109. * routine: uHALir_PCIMakeConfigAddress()
  110. *
  111. * parameters: bus = which bus
  112. * device = which device
  113. * function = which function
  114. * offset = configuration space register we are interested in
  115. *
  116. * description: this routine will generate a platform dependent config
  117. * address.
  118. *
  119. * calls: none
  120. *
  121. * returns: configuration address to play on the PCI bus
  122. *
  123. * To generate the appropriate PCI configuration cycles in the PCI
  124. * configuration address space, you present the V3 with the following pattern
  125. * (which is very nearly a type 1 (except that the lower two bits are 00 and
  126. * not 01). In order for this mapping to work you need to set up one of
  127. * the local to PCI aperatures to 16Mbytes in length translating to
  128. * PCI configuration space starting at 0x0000.0000.
  129. *
  130. * PCI configuration cycles look like this:
  131. *
  132. * Type 0:
  133. *
  134. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  135. * 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
  136. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  137. * | | |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|
  138. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  139. *
  140. * 31:11 Device select bit.
  141. * 10:8 Function number
  142. * 7:2 Register number
  143. *
  144. * Type 1:
  145. *
  146. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  147. * 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
  148. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  149. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  150. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  151. *
  152. * 31:24 reserved
  153. * 23:16 bus number (8 bits = 128 possible buses)
  154. * 15:11 Device number (5 bits)
  155. * 10:8 function number
  156. * 7:2 register number
  157. *
  158. */
  159. static DEFINE_RAW_SPINLOCK(v3_lock);
  160. #define PCI_BUS_NONMEM_START 0x00000000
  161. #define PCI_BUS_NONMEM_SIZE SZ_256M
  162. #define PCI_BUS_PREMEM_START PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE
  163. #define PCI_BUS_PREMEM_SIZE SZ_256M
  164. #if PCI_BUS_NONMEM_START & 0x000fffff
  165. #error PCI_BUS_NONMEM_START must be megabyte aligned
  166. #endif
  167. #if PCI_BUS_PREMEM_START & 0x000fffff
  168. #error PCI_BUS_PREMEM_START must be megabyte aligned
  169. #endif
  170. #undef V3_LB_BASE_PREFETCH
  171. #define V3_LB_BASE_PREFETCH 0
  172. static void __iomem *v3_open_config_window(struct pci_bus *bus,
  173. unsigned int devfn, int offset)
  174. {
  175. unsigned int address, mapaddress, busnr;
  176. busnr = bus->number;
  177. /*
  178. * Trap out illegal values
  179. */
  180. BUG_ON(offset > 255);
  181. BUG_ON(busnr > 255);
  182. BUG_ON(devfn > 255);
  183. if (busnr == 0) {
  184. int slot = PCI_SLOT(devfn);
  185. /*
  186. * local bus segment so need a type 0 config cycle
  187. *
  188. * build the PCI configuration "address" with one-hot in
  189. * A31-A11
  190. *
  191. * mapaddress:
  192. * 3:1 = config cycle (101)
  193. * 0 = PCI A1 & A0 are 0 (0)
  194. */
  195. address = PCI_FUNC(devfn) << 8;
  196. mapaddress = V3_LB_MAP_TYPE_CONFIG;
  197. if (slot > 12)
  198. /*
  199. * high order bits are handled by the MAP register
  200. */
  201. mapaddress |= 1 << (slot - 5);
  202. else
  203. /*
  204. * low order bits handled directly in the address
  205. */
  206. address |= 1 << (slot + 11);
  207. } else {
  208. /*
  209. * not the local bus segment so need a type 1 config cycle
  210. *
  211. * address:
  212. * 23:16 = bus number
  213. * 15:11 = slot number (7:3 of devfn)
  214. * 10:8 = func number (2:0 of devfn)
  215. *
  216. * mapaddress:
  217. * 3:1 = config cycle (101)
  218. * 0 = PCI A1 & A0 from host bus (1)
  219. */
  220. mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN;
  221. address = (busnr << 16) | (devfn << 8);
  222. }
  223. /*
  224. * Set up base0 to see all 512Mbytes of memory space (not
  225. * prefetchable), this frees up base1 for re-use by
  226. * configuration memory
  227. */
  228. v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
  229. V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE);
  230. /*
  231. * Set up base1/map1 to point into configuration space.
  232. */
  233. v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) |
  234. V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE);
  235. v3_writew(V3_LB_MAP1, mapaddress);
  236. return PCI_CONFIG_VADDR + address + offset;
  237. }
  238. static void v3_close_config_window(void)
  239. {
  240. /*
  241. * Reassign base1 for use by prefetchable PCI memory
  242. */
  243. v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
  244. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
  245. V3_LB_BASE_ENABLE);
  246. v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
  247. V3_LB_MAP_TYPE_MEM_MULTIPLE);
  248. /*
  249. * And shrink base0 back to a 256M window (NOTE: MAP0 already correct)
  250. */
  251. v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
  252. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
  253. }
  254. static int v3_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  255. int size, u32 *val)
  256. {
  257. void __iomem *addr;
  258. unsigned long flags;
  259. u32 v;
  260. raw_spin_lock_irqsave(&v3_lock, flags);
  261. addr = v3_open_config_window(bus, devfn, where);
  262. switch (size) {
  263. case 1:
  264. v = __raw_readb(addr);
  265. break;
  266. case 2:
  267. v = __raw_readw(addr);
  268. break;
  269. default:
  270. v = __raw_readl(addr);
  271. break;
  272. }
  273. v3_close_config_window();
  274. raw_spin_unlock_irqrestore(&v3_lock, flags);
  275. *val = v;
  276. return PCIBIOS_SUCCESSFUL;
  277. }
  278. static int v3_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  279. int size, u32 val)
  280. {
  281. void __iomem *addr;
  282. unsigned long flags;
  283. raw_spin_lock_irqsave(&v3_lock, flags);
  284. addr = v3_open_config_window(bus, devfn, where);
  285. switch (size) {
  286. case 1:
  287. __raw_writeb((u8)val, addr);
  288. __raw_readb(addr);
  289. break;
  290. case 2:
  291. __raw_writew((u16)val, addr);
  292. __raw_readw(addr);
  293. break;
  294. case 4:
  295. __raw_writel(val, addr);
  296. __raw_readl(addr);
  297. break;
  298. }
  299. v3_close_config_window();
  300. raw_spin_unlock_irqrestore(&v3_lock, flags);
  301. return PCIBIOS_SUCCESSFUL;
  302. }
  303. static struct pci_ops pci_v3_ops = {
  304. .read = v3_read_config,
  305. .write = v3_write_config,
  306. };
  307. static struct resource non_mem = {
  308. .name = "PCI non-prefetchable",
  309. .start = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START,
  310. .end = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1,
  311. .flags = IORESOURCE_MEM,
  312. };
  313. static struct resource pre_mem = {
  314. .name = "PCI prefetchable",
  315. .start = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START,
  316. .end = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1,
  317. .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH,
  318. };
  319. static int __init pci_v3_setup_resources(struct pci_sys_data *sys)
  320. {
  321. if (request_resource(&iomem_resource, &non_mem)) {
  322. printk(KERN_ERR "PCI: unable to allocate non-prefetchable "
  323. "memory region\n");
  324. return -EBUSY;
  325. }
  326. if (request_resource(&iomem_resource, &pre_mem)) {
  327. release_resource(&non_mem);
  328. printk(KERN_ERR "PCI: unable to allocate prefetchable "
  329. "memory region\n");
  330. return -EBUSY;
  331. }
  332. /*
  333. * the mem resource for this bus
  334. * the prefetch mem resource for this bus
  335. */
  336. pci_add_resource_offset(&sys->resources, &non_mem, sys->mem_offset);
  337. pci_add_resource_offset(&sys->resources, &pre_mem, sys->mem_offset);
  338. return 1;
  339. }
  340. /*
  341. * These don't seem to be implemented on the Integrator I have, which
  342. * means I can't get additional information on the reason for the pm2fb
  343. * problems. I suppose I'll just have to mind-meld with the machine. ;)
  344. */
  345. static void __iomem *ap_syscon_base;
  346. #define INTEGRATOR_SC_PCIENABLE_OFFSET 0x18
  347. #define INTEGRATOR_SC_LBFADDR_OFFSET 0x20
  348. #define INTEGRATOR_SC_LBFCODE_OFFSET 0x24
  349. static int
  350. v3_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  351. {
  352. unsigned long pc = instruction_pointer(regs);
  353. unsigned long instr = *(unsigned long *)pc;
  354. #if 0
  355. char buf[128];
  356. sprintf(buf, "V3 fault: addr 0x%08lx, FSR 0x%03x, PC 0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n",
  357. addr, fsr, pc, instr, __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET), __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255,
  358. v3_readb(V3_LB_ISTAT));
  359. printk(KERN_DEBUG "%s", buf);
  360. #endif
  361. v3_writeb(V3_LB_ISTAT, 0);
  362. __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
  363. /*
  364. * If the instruction being executed was a read,
  365. * make it look like it read all-ones.
  366. */
  367. if ((instr & 0x0c100000) == 0x04100000) {
  368. int reg = (instr >> 12) & 15;
  369. unsigned long val;
  370. if (instr & 0x00400000)
  371. val = 255;
  372. else
  373. val = -1;
  374. regs->uregs[reg] = val;
  375. regs->ARM_pc += 4;
  376. return 0;
  377. }
  378. if ((instr & 0x0e100090) == 0x00100090) {
  379. int reg = (instr >> 12) & 15;
  380. regs->uregs[reg] = -1;
  381. regs->ARM_pc += 4;
  382. return 0;
  383. }
  384. return 1;
  385. }
  386. static irqreturn_t v3_irq(int dummy, void *devid)
  387. {
  388. #ifdef CONFIG_DEBUG_LL
  389. struct pt_regs *regs = get_irq_regs();
  390. unsigned long pc = instruction_pointer(regs);
  391. unsigned long instr = *(unsigned long *)pc;
  392. char buf[128];
  393. extern void printascii(const char *);
  394. sprintf(buf, "V3 int %d: pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x "
  395. "ISTAT=%02x\n", IRQ_AP_V3INT, pc, instr,
  396. __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFADDR_OFFSET),
  397. __raw_readl(ap_syscon_base + INTEGRATOR_SC_LBFCODE_OFFSET) & 255,
  398. v3_readb(V3_LB_ISTAT));
  399. printascii(buf);
  400. #endif
  401. v3_writew(V3_PCI_STAT, 0xf000);
  402. v3_writeb(V3_LB_ISTAT, 0);
  403. __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
  404. #ifdef CONFIG_DEBUG_LL
  405. /*
  406. * If the instruction being executed was a read,
  407. * make it look like it read all-ones.
  408. */
  409. if ((instr & 0x0c100000) == 0x04100000) {
  410. int reg = (instr >> 16) & 15;
  411. sprintf(buf, " reg%d = %08lx\n", reg, regs->uregs[reg]);
  412. printascii(buf);
  413. }
  414. #endif
  415. return IRQ_HANDLED;
  416. }
  417. static int __init pci_v3_setup(int nr, struct pci_sys_data *sys)
  418. {
  419. int ret = 0;
  420. if (!ap_syscon_base)
  421. return -EINVAL;
  422. if (nr == 0) {
  423. sys->mem_offset = PHYS_PCI_MEM_BASE;
  424. ret = pci_v3_setup_resources(sys);
  425. }
  426. return ret;
  427. }
  428. /*
  429. * V3_LB_BASE? - local bus address
  430. * V3_LB_MAP? - pci bus address
  431. */
  432. static void __init pci_v3_preinit(void)
  433. {
  434. unsigned long flags;
  435. unsigned int temp;
  436. int ret;
  437. /* Remap the Integrator system controller */
  438. ap_syscon_base = ioremap(INTEGRATOR_SC_BASE, 0x100);
  439. if (!ap_syscon_base) {
  440. pr_err("unable to remap the AP syscon for PCIv3\n");
  441. return;
  442. }
  443. pcibios_min_mem = 0x00100000;
  444. /*
  445. * Hook in our fault handler for PCI errors
  446. */
  447. hook_fault_code(4, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
  448. hook_fault_code(6, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
  449. hook_fault_code(8, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
  450. hook_fault_code(10, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
  451. raw_spin_lock_irqsave(&v3_lock, flags);
  452. /*
  453. * Unlock V3 registers, but only if they were previously locked.
  454. */
  455. if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK)
  456. v3_writew(V3_SYSTEM, 0xa05f);
  457. /*
  458. * Setup window 0 - PCI non-prefetchable memory
  459. * Local: 0x40000000 Bus: 0x00000000 Size: 256MB
  460. */
  461. v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
  462. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
  463. v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) |
  464. V3_LB_MAP_TYPE_MEM);
  465. /*
  466. * Setup window 1 - PCI prefetchable memory
  467. * Local: 0x50000000 Bus: 0x10000000 Size: 256MB
  468. */
  469. v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
  470. V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
  471. V3_LB_BASE_ENABLE);
  472. v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
  473. V3_LB_MAP_TYPE_MEM_MULTIPLE);
  474. /*
  475. * Setup window 2 - PCI IO
  476. */
  477. v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) |
  478. V3_LB_BASE_ENABLE);
  479. v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0));
  480. /*
  481. * Disable PCI to host IO cycles
  482. */
  483. temp = v3_readw(V3_PCI_CFG) & ~V3_PCI_CFG_M_I2O_EN;
  484. temp |= V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS;
  485. v3_writew(V3_PCI_CFG, temp);
  486. printk(KERN_DEBUG "FIFO_CFG: %04x FIFO_PRIO: %04x\n",
  487. v3_readw(V3_FIFO_CFG), v3_readw(V3_FIFO_PRIORITY));
  488. /*
  489. * Set the V3 FIFO such that writes have higher priority than
  490. * reads, and local bus write causes local bus read fifo flush.
  491. * Same for PCI.
  492. */
  493. v3_writew(V3_FIFO_PRIORITY, 0x0a0a);
  494. /*
  495. * Re-lock the system register.
  496. */
  497. temp = v3_readw(V3_SYSTEM) | V3_SYSTEM_M_LOCK;
  498. v3_writew(V3_SYSTEM, temp);
  499. /*
  500. * Clear any error conditions, and enable write errors.
  501. */
  502. v3_writeb(V3_LB_ISTAT, 0);
  503. v3_writew(V3_LB_CFG, v3_readw(V3_LB_CFG) | (1 << 10));
  504. v3_writeb(V3_LB_IMASK, 0x28);
  505. __raw_writel(3, ap_syscon_base + INTEGRATOR_SC_PCIENABLE_OFFSET);
  506. /*
  507. * Grab the PCI error interrupt.
  508. */
  509. ret = request_irq(IRQ_AP_V3INT, v3_irq, 0, "V3", NULL);
  510. if (ret)
  511. printk(KERN_ERR "PCI: unable to grab PCI error "
  512. "interrupt: %d\n", ret);
  513. raw_spin_unlock_irqrestore(&v3_lock, flags);
  514. }
  515. static void __init pci_v3_postinit(void)
  516. {
  517. unsigned int pci_cmd;
  518. pci_cmd = PCI_COMMAND_MEMORY |
  519. PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE;
  520. v3_writew(V3_PCI_CMD, pci_cmd);
  521. v3_writeb(V3_LB_ISTAT, ~0x40);
  522. v3_writeb(V3_LB_IMASK, 0x68);
  523. #if 0
  524. ret = request_irq(IRQ_AP_LBUSTIMEOUT, lb_timeout, 0, "bus timeout", NULL);
  525. if (ret)
  526. printk(KERN_ERR "PCI: unable to grab local bus timeout "
  527. "interrupt: %d\n", ret);
  528. #endif
  529. register_isa_ports(PHYS_PCI_MEM_BASE, PHYS_PCI_IO_BASE, 0);
  530. }
  531. /*
  532. * A small note about bridges and interrupts. The DECchip 21050 (and
  533. * later) adheres to the PCI-PCI bridge specification. This says that
  534. * the interrupts on the other side of a bridge are swizzled in the
  535. * following manner:
  536. *
  537. * Dev Interrupt Interrupt
  538. * Pin on Pin on
  539. * Device Connector
  540. *
  541. * 4 A A
  542. * B B
  543. * C C
  544. * D D
  545. *
  546. * 5 A B
  547. * B C
  548. * C D
  549. * D A
  550. *
  551. * 6 A C
  552. * B D
  553. * C A
  554. * D B
  555. *
  556. * 7 A D
  557. * B A
  558. * C B
  559. * D C
  560. *
  561. * Where A = pin 1, B = pin 2 and so on and pin=0 = default = A.
  562. * Thus, each swizzle is ((pin-1) + (device#-4)) % 4
  563. */
  564. /*
  565. * This routine handles multiple bridges.
  566. */
  567. static u8 __init pci_v3_swizzle(struct pci_dev *dev, u8 *pinp)
  568. {
  569. if (*pinp == 0)
  570. *pinp = 1;
  571. return pci_common_swizzle(dev, pinp);
  572. }
  573. static int irq_tab[4] __initdata = {
  574. IRQ_AP_PCIINT0, IRQ_AP_PCIINT1, IRQ_AP_PCIINT2, IRQ_AP_PCIINT3
  575. };
  576. /*
  577. * map the specified device/slot/pin to an IRQ. This works out such
  578. * that slot 9 pin 1 is INT0, pin 2 is INT1, and slot 10 pin 1 is INT1.
  579. */
  580. static int __init pci_v3_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  581. {
  582. int intnr = ((slot - 9) + (pin - 1)) & 3;
  583. return irq_tab[intnr];
  584. }
  585. static struct hw_pci pci_v3 __initdata = {
  586. .swizzle = pci_v3_swizzle,
  587. .map_irq = pci_v3_map_irq,
  588. .setup = pci_v3_setup,
  589. .nr_controllers = 1,
  590. .ops = &pci_v3_ops,
  591. .preinit = pci_v3_preinit,
  592. .postinit = pci_v3_postinit,
  593. };
  594. static int __init pci_v3_probe(struct platform_device *pdev)
  595. {
  596. pci_common_init(&pci_v3);
  597. return 0;
  598. }
  599. static struct platform_driver pci_v3_driver = {
  600. .driver = {
  601. .name = "pci-v3",
  602. },
  603. };
  604. static int __init pci_v3_init(void)
  605. {
  606. return platform_driver_probe(&pci_v3_driver, pci_v3_probe);
  607. }
  608. subsys_initcall(pci_v3_init);