pci.c 9.3 KB

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