pci.c 9.7 KB

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