pci.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * arch/arm/plat-iop/pci.c
  3. *
  4. * PCI support for the Intel IOP32X and IOP33X processors
  5. *
  6. * Author: Rory Bolt <rorybolt@pacbell.net>
  7. * Copyright (C) 2002 Rory Bolt
  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 version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/pci.h>
  15. #include <linux/slab.h>
  16. #include <linux/mm.h>
  17. #include <linux/init.h>
  18. #include <linux/ioport.h>
  19. #include <linux/io.h>
  20. #include <asm/irq.h>
  21. #include <asm/signal.h>
  22. #include <asm/system.h>
  23. #include <mach/hardware.h>
  24. #include <asm/mach/pci.h>
  25. #include <asm/hardware/iop3xx.h>
  26. // #define DEBUG
  27. #ifdef DEBUG
  28. #define DBG(x...) printk(x)
  29. #else
  30. #define DBG(x...) do { } while (0)
  31. #endif
  32. /*
  33. * This routine builds either a type0 or type1 configuration command. If the
  34. * bus is on the 803xx then a type0 made, else a type1 is created.
  35. */
  36. static u32 iop3xx_cfg_address(struct pci_bus *bus, int devfn, int where)
  37. {
  38. struct pci_sys_data *sys = bus->sysdata;
  39. u32 addr;
  40. if (sys->busnr == bus->number)
  41. addr = 1 << (PCI_SLOT(devfn) + 16) | (PCI_SLOT(devfn) << 11);
  42. else
  43. addr = bus->number << 16 | PCI_SLOT(devfn) << 11 | 1;
  44. addr |= PCI_FUNC(devfn) << 8 | (where & ~3);
  45. return addr;
  46. }
  47. /*
  48. * This routine checks the status of the last configuration cycle. If an error
  49. * was detected it returns a 1, else it returns a 0. The errors being checked
  50. * are parity, master abort, target abort (master and target). These types of
  51. * errors occur during a config cycle where there is no device, like during
  52. * the discovery stage.
  53. */
  54. static int iop3xx_pci_status(void)
  55. {
  56. unsigned int status;
  57. int ret = 0;
  58. /*
  59. * Check the status registers.
  60. */
  61. status = *IOP3XX_ATUSR;
  62. if (status & 0xf900) {
  63. DBG("\t\t\tPCI: P0 - status = 0x%08x\n", status);
  64. *IOP3XX_ATUSR = status & 0xf900;
  65. ret = 1;
  66. }
  67. status = *IOP3XX_ATUISR;
  68. if (status & 0x679f) {
  69. DBG("\t\t\tPCI: P1 - status = 0x%08x\n", status);
  70. *IOP3XX_ATUISR = status & 0x679f;
  71. ret = 1;
  72. }
  73. return ret;
  74. }
  75. /*
  76. * Simply write the address register and read the configuration
  77. * data. Note that the 4 nops ensure that we are able to handle
  78. * a delayed abort (in theory.)
  79. */
  80. static u32 iop3xx_read(unsigned long addr)
  81. {
  82. u32 val;
  83. __asm__ __volatile__(
  84. "str %1, [%2]\n\t"
  85. "ldr %0, [%3]\n\t"
  86. "nop\n\t"
  87. "nop\n\t"
  88. "nop\n\t"
  89. "nop\n\t"
  90. : "=r" (val)
  91. : "r" (addr), "r" (IOP3XX_OCCAR), "r" (IOP3XX_OCCDR));
  92. return val;
  93. }
  94. /*
  95. * The read routines must check the error status of the last configuration
  96. * cycle. If there was an error, the routine returns all hex f's.
  97. */
  98. static int
  99. iop3xx_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  100. int size, u32 *value)
  101. {
  102. unsigned long addr = iop3xx_cfg_address(bus, devfn, where);
  103. u32 val = iop3xx_read(addr) >> ((where & 3) * 8);
  104. if (iop3xx_pci_status())
  105. val = 0xffffffff;
  106. *value = val;
  107. return PCIBIOS_SUCCESSFUL;
  108. }
  109. static int
  110. iop3xx_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  111. int size, u32 value)
  112. {
  113. unsigned long addr = iop3xx_cfg_address(bus, devfn, where);
  114. u32 val;
  115. if (size != 4) {
  116. val = iop3xx_read(addr);
  117. if (iop3xx_pci_status())
  118. return PCIBIOS_SUCCESSFUL;
  119. where = (where & 3) * 8;
  120. if (size == 1)
  121. val &= ~(0xff << where);
  122. else
  123. val &= ~(0xffff << where);
  124. *IOP3XX_OCCDR = val | value << where;
  125. } else {
  126. asm volatile(
  127. "str %1, [%2]\n\t"
  128. "str %0, [%3]\n\t"
  129. "nop\n\t"
  130. "nop\n\t"
  131. "nop\n\t"
  132. "nop\n\t"
  133. :
  134. : "r" (value), "r" (addr),
  135. "r" (IOP3XX_OCCAR), "r" (IOP3XX_OCCDR));
  136. }
  137. return PCIBIOS_SUCCESSFUL;
  138. }
  139. static struct pci_ops iop3xx_ops = {
  140. .read = iop3xx_read_config,
  141. .write = iop3xx_write_config,
  142. };
  143. /*
  144. * When a PCI device does not exist during config cycles, the 80200 gets a
  145. * bus error instead of returning 0xffffffff. This handler simply returns.
  146. */
  147. static int
  148. iop3xx_pci_abort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  149. {
  150. DBG("PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx\n",
  151. addr, fsr, regs->ARM_pc, regs->ARM_lr);
  152. /*
  153. * If it was an imprecise abort, then we need to correct the
  154. * return address to be _after_ the instruction.
  155. */
  156. if (fsr & (1 << 10))
  157. regs->ARM_pc += 4;
  158. return 0;
  159. }
  160. int iop3xx_pci_setup(int nr, struct pci_sys_data *sys)
  161. {
  162. struct resource *res;
  163. if (nr != 0)
  164. return 0;
  165. res = kzalloc(2 * sizeof(struct resource), GFP_KERNEL);
  166. if (!res)
  167. panic("PCI: unable to alloc resources");
  168. res[0].start = IOP3XX_PCI_LOWER_IO_PA;
  169. res[0].end = IOP3XX_PCI_LOWER_IO_PA + IOP3XX_PCI_IO_WINDOW_SIZE - 1;
  170. res[0].name = "IOP3XX PCI I/O Space";
  171. res[0].flags = IORESOURCE_IO;
  172. request_resource(&ioport_resource, &res[0]);
  173. res[1].start = IOP3XX_PCI_LOWER_MEM_PA;
  174. res[1].end = IOP3XX_PCI_LOWER_MEM_PA + IOP3XX_PCI_MEM_WINDOW_SIZE - 1;
  175. res[1].name = "IOP3XX PCI Memory Space";
  176. res[1].flags = IORESOURCE_MEM;
  177. request_resource(&iomem_resource, &res[1]);
  178. /*
  179. * Use whatever translation is already setup.
  180. */
  181. sys->mem_offset = IOP3XX_PCI_LOWER_MEM_PA - *IOP3XX_OMWTVR0;
  182. sys->io_offset = IOP3XX_PCI_LOWER_IO_PA - *IOP3XX_OIOWTVR;
  183. sys->resource[0] = &res[0];
  184. sys->resource[1] = &res[1];
  185. sys->resource[2] = NULL;
  186. return 1;
  187. }
  188. struct pci_bus *iop3xx_pci_scan_bus(int nr, struct pci_sys_data *sys)
  189. {
  190. return pci_scan_bus(sys->busnr, &iop3xx_ops, sys);
  191. }
  192. void __init iop3xx_atu_setup(void)
  193. {
  194. /* BAR 0 ( Disabled ) */
  195. *IOP3XX_IAUBAR0 = 0x0;
  196. *IOP3XX_IABAR0 = 0x0;
  197. *IOP3XX_IATVR0 = 0x0;
  198. *IOP3XX_IALR0 = 0x0;
  199. /* BAR 1 ( Disabled ) */
  200. *IOP3XX_IAUBAR1 = 0x0;
  201. *IOP3XX_IABAR1 = 0x0;
  202. *IOP3XX_IALR1 = 0x0;
  203. /* BAR 2 (1:1 mapping with Physical RAM) */
  204. /* Set limit and enable */
  205. *IOP3XX_IALR2 = ~((u32)IOP3XX_MAX_RAM_SIZE - 1) & ~0x1;
  206. *IOP3XX_IAUBAR2 = 0x0;
  207. /* Align the inbound bar with the base of memory */
  208. *IOP3XX_IABAR2 = PHYS_OFFSET |
  209. PCI_BASE_ADDRESS_MEM_TYPE_64 |
  210. PCI_BASE_ADDRESS_MEM_PREFETCH;
  211. *IOP3XX_IATVR2 = PHYS_OFFSET;
  212. /* Outbound window 0 */
  213. *IOP3XX_OMWTVR0 = IOP3XX_PCI_LOWER_MEM_BA;
  214. *IOP3XX_OUMWTVR0 = 0;
  215. /* Outbound window 1 */
  216. *IOP3XX_OMWTVR1 = IOP3XX_PCI_LOWER_MEM_BA + IOP3XX_PCI_MEM_WINDOW_SIZE;
  217. *IOP3XX_OUMWTVR1 = 0;
  218. /* BAR 3 ( Disabled ) */
  219. *IOP3XX_IAUBAR3 = 0x0;
  220. *IOP3XX_IABAR3 = 0x0;
  221. *IOP3XX_IATVR3 = 0x0;
  222. *IOP3XX_IALR3 = 0x0;
  223. /* Setup the I/O Bar
  224. */
  225. *IOP3XX_OIOWTVR = IOP3XX_PCI_LOWER_IO_BA;
  226. /* Enable inbound and outbound cycles
  227. */
  228. *IOP3XX_ATUCMD |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  229. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  230. *IOP3XX_ATUCR |= IOP3XX_ATUCR_OUT_EN;
  231. }
  232. void __init iop3xx_atu_disable(void)
  233. {
  234. *IOP3XX_ATUCMD = 0;
  235. *IOP3XX_ATUCR = 0;
  236. /* wait for cycles to quiesce */
  237. while (*IOP3XX_PCSR & (IOP3XX_PCSR_OUT_Q_BUSY |
  238. IOP3XX_PCSR_IN_Q_BUSY))
  239. cpu_relax();
  240. /* BAR 0 ( Disabled ) */
  241. *IOP3XX_IAUBAR0 = 0x0;
  242. *IOP3XX_IABAR0 = 0x0;
  243. *IOP3XX_IATVR0 = 0x0;
  244. *IOP3XX_IALR0 = 0x0;
  245. /* BAR 1 ( Disabled ) */
  246. *IOP3XX_IAUBAR1 = 0x0;
  247. *IOP3XX_IABAR1 = 0x0;
  248. *IOP3XX_IALR1 = 0x0;
  249. /* BAR 2 ( Disabled ) */
  250. *IOP3XX_IAUBAR2 = 0x0;
  251. *IOP3XX_IABAR2 = 0x0;
  252. *IOP3XX_IATVR2 = 0x0;
  253. *IOP3XX_IALR2 = 0x0;
  254. /* BAR 3 ( Disabled ) */
  255. *IOP3XX_IAUBAR3 = 0x0;
  256. *IOP3XX_IABAR3 = 0x0;
  257. *IOP3XX_IATVR3 = 0x0;
  258. *IOP3XX_IALR3 = 0x0;
  259. /* Clear the outbound windows */
  260. *IOP3XX_OIOWTVR = 0;
  261. /* Outbound window 0 */
  262. *IOP3XX_OMWTVR0 = 0;
  263. *IOP3XX_OUMWTVR0 = 0;
  264. /* Outbound window 1 */
  265. *IOP3XX_OMWTVR1 = 0;
  266. *IOP3XX_OUMWTVR1 = 0;
  267. }
  268. /* Flag to determine whether the ATU is initialized and the PCI bus scanned */
  269. int init_atu;
  270. int iop3xx_get_init_atu(void) {
  271. /* check if default has been overridden */
  272. if (init_atu != IOP3XX_INIT_ATU_DEFAULT)
  273. return init_atu;
  274. else
  275. return IOP3XX_INIT_ATU_DISABLE;
  276. }
  277. static void __init iop3xx_atu_debug(void)
  278. {
  279. DBG("PCI: Intel IOP3xx PCI init.\n");
  280. DBG("PCI: Outbound memory window 0: PCI 0x%08x%08x\n",
  281. *IOP3XX_OUMWTVR0, *IOP3XX_OMWTVR0);
  282. DBG("PCI: Outbound memory window 1: PCI 0x%08x%08x\n",
  283. *IOP3XX_OUMWTVR1, *IOP3XX_OMWTVR1);
  284. DBG("PCI: Outbound IO window: PCI 0x%08x\n",
  285. *IOP3XX_OIOWTVR);
  286. DBG("PCI: Inbound memory window 0: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  287. *IOP3XX_IAUBAR0, *IOP3XX_IABAR0, *IOP3XX_IALR0, *IOP3XX_IATVR0);
  288. DBG("PCI: Inbound memory window 1: PCI 0x%08x%08x 0x%08x\n",
  289. *IOP3XX_IAUBAR1, *IOP3XX_IABAR1, *IOP3XX_IALR1);
  290. DBG("PCI: Inbound memory window 2: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  291. *IOP3XX_IAUBAR2, *IOP3XX_IABAR2, *IOP3XX_IALR2, *IOP3XX_IATVR2);
  292. DBG("PCI: Inbound memory window 3: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  293. *IOP3XX_IAUBAR3, *IOP3XX_IABAR3, *IOP3XX_IALR3, *IOP3XX_IATVR3);
  294. DBG("PCI: Expansion ROM window: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  295. 0, *IOP3XX_ERBAR, *IOP3XX_ERLR, *IOP3XX_ERTVR);
  296. DBG("ATU: IOP3XX_ATUCMD=0x%04x\n", *IOP3XX_ATUCMD);
  297. DBG("ATU: IOP3XX_ATUCR=0x%08x\n", *IOP3XX_ATUCR);
  298. hook_fault_code(16+6, iop3xx_pci_abort, SIGBUS, "imprecise external abort");
  299. }
  300. /* for platforms that might be host-bus-adapters */
  301. void __init iop3xx_pci_preinit_cond(void)
  302. {
  303. if (iop3xx_get_init_atu() == IOP3XX_INIT_ATU_ENABLE) {
  304. iop3xx_atu_disable();
  305. iop3xx_atu_setup();
  306. iop3xx_atu_debug();
  307. }
  308. }
  309. void __init iop3xx_pci_preinit(void)
  310. {
  311. iop3xx_atu_disable();
  312. iop3xx_atu_setup();
  313. iop3xx_atu_debug();
  314. }
  315. /* allow init_atu to be user overridden */
  316. static int __init iop3xx_init_atu_setup(char *str)
  317. {
  318. init_atu = IOP3XX_INIT_ATU_DEFAULT;
  319. if (str) {
  320. while (*str != '\0') {
  321. switch (*str) {
  322. case 'y':
  323. case 'Y':
  324. init_atu = IOP3XX_INIT_ATU_ENABLE;
  325. break;
  326. case 'n':
  327. case 'N':
  328. init_atu = IOP3XX_INIT_ATU_DISABLE;
  329. break;
  330. case ',':
  331. case '=':
  332. break;
  333. default:
  334. printk(KERN_DEBUG "\"%s\" malformed at "
  335. "character: \'%c\'",
  336. __func__,
  337. *str);
  338. *(str + 1) = '\0';
  339. }
  340. str++;
  341. }
  342. }
  343. return 1;
  344. }
  345. __setup("iop3xx_init_atu", iop3xx_init_atu_setup);