pci.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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(2 * sizeof(struct resource), GFP_KERNEL);
  165. if (!res)
  166. panic("PCI: unable to alloc resources");
  167. res[0].start = IOP3XX_PCI_LOWER_IO_PA;
  168. res[0].end = IOP3XX_PCI_LOWER_IO_PA + IOP3XX_PCI_IO_WINDOW_SIZE - 1;
  169. res[0].name = "IOP3XX PCI I/O Space";
  170. res[0].flags = IORESOURCE_IO;
  171. request_resource(&ioport_resource, &res[0]);
  172. res[1].start = IOP3XX_PCI_LOWER_MEM_PA;
  173. res[1].end = IOP3XX_PCI_LOWER_MEM_PA + IOP3XX_PCI_MEM_WINDOW_SIZE - 1;
  174. res[1].name = "IOP3XX PCI Memory Space";
  175. res[1].flags = IORESOURCE_MEM;
  176. request_resource(&iomem_resource, &res[1]);
  177. /*
  178. * Use whatever translation is already setup.
  179. */
  180. sys->mem_offset = IOP3XX_PCI_LOWER_MEM_PA - *IOP3XX_OMWTVR0;
  181. sys->io_offset = IOP3XX_PCI_LOWER_IO_PA - *IOP3XX_OIOWTVR;
  182. pci_add_resource_offset(&sys->resources, &res[0], sys->io_offset);
  183. pci_add_resource_offset(&sys->resources, &res[1], sys->mem_offset);
  184. return 1;
  185. }
  186. void __init iop3xx_atu_setup(void)
  187. {
  188. /* BAR 0 ( Disabled ) */
  189. *IOP3XX_IAUBAR0 = 0x0;
  190. *IOP3XX_IABAR0 = 0x0;
  191. *IOP3XX_IATVR0 = 0x0;
  192. *IOP3XX_IALR0 = 0x0;
  193. /* BAR 1 ( Disabled ) */
  194. *IOP3XX_IAUBAR1 = 0x0;
  195. *IOP3XX_IABAR1 = 0x0;
  196. *IOP3XX_IALR1 = 0x0;
  197. /* BAR 2 (1:1 mapping with Physical RAM) */
  198. /* Set limit and enable */
  199. *IOP3XX_IALR2 = ~((u32)IOP3XX_MAX_RAM_SIZE - 1) & ~0x1;
  200. *IOP3XX_IAUBAR2 = 0x0;
  201. /* Align the inbound bar with the base of memory */
  202. *IOP3XX_IABAR2 = PHYS_OFFSET |
  203. PCI_BASE_ADDRESS_MEM_TYPE_64 |
  204. PCI_BASE_ADDRESS_MEM_PREFETCH;
  205. *IOP3XX_IATVR2 = PHYS_OFFSET;
  206. /* Outbound window 0 */
  207. *IOP3XX_OMWTVR0 = IOP3XX_PCI_LOWER_MEM_BA;
  208. *IOP3XX_OUMWTVR0 = 0;
  209. /* Outbound window 1 */
  210. *IOP3XX_OMWTVR1 = IOP3XX_PCI_LOWER_MEM_BA +
  211. IOP3XX_PCI_MEM_WINDOW_SIZE / 2;
  212. *IOP3XX_OUMWTVR1 = 0;
  213. /* BAR 3 ( Disabled ) */
  214. *IOP3XX_IAUBAR3 = 0x0;
  215. *IOP3XX_IABAR3 = 0x0;
  216. *IOP3XX_IATVR3 = 0x0;
  217. *IOP3XX_IALR3 = 0x0;
  218. /* Setup the I/O Bar
  219. */
  220. *IOP3XX_OIOWTVR = IOP3XX_PCI_LOWER_IO_BA;
  221. /* Enable inbound and outbound cycles
  222. */
  223. *IOP3XX_ATUCMD |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  224. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  225. *IOP3XX_ATUCR |= IOP3XX_ATUCR_OUT_EN;
  226. }
  227. void __init iop3xx_atu_disable(void)
  228. {
  229. *IOP3XX_ATUCMD = 0;
  230. *IOP3XX_ATUCR = 0;
  231. /* wait for cycles to quiesce */
  232. while (*IOP3XX_PCSR & (IOP3XX_PCSR_OUT_Q_BUSY |
  233. IOP3XX_PCSR_IN_Q_BUSY))
  234. cpu_relax();
  235. /* BAR 0 ( Disabled ) */
  236. *IOP3XX_IAUBAR0 = 0x0;
  237. *IOP3XX_IABAR0 = 0x0;
  238. *IOP3XX_IATVR0 = 0x0;
  239. *IOP3XX_IALR0 = 0x0;
  240. /* BAR 1 ( Disabled ) */
  241. *IOP3XX_IAUBAR1 = 0x0;
  242. *IOP3XX_IABAR1 = 0x0;
  243. *IOP3XX_IALR1 = 0x0;
  244. /* BAR 2 ( Disabled ) */
  245. *IOP3XX_IAUBAR2 = 0x0;
  246. *IOP3XX_IABAR2 = 0x0;
  247. *IOP3XX_IATVR2 = 0x0;
  248. *IOP3XX_IALR2 = 0x0;
  249. /* BAR 3 ( Disabled ) */
  250. *IOP3XX_IAUBAR3 = 0x0;
  251. *IOP3XX_IABAR3 = 0x0;
  252. *IOP3XX_IATVR3 = 0x0;
  253. *IOP3XX_IALR3 = 0x0;
  254. /* Clear the outbound windows */
  255. *IOP3XX_OIOWTVR = 0;
  256. /* Outbound window 0 */
  257. *IOP3XX_OMWTVR0 = 0;
  258. *IOP3XX_OUMWTVR0 = 0;
  259. /* Outbound window 1 */
  260. *IOP3XX_OMWTVR1 = 0;
  261. *IOP3XX_OUMWTVR1 = 0;
  262. }
  263. /* Flag to determine whether the ATU is initialized and the PCI bus scanned */
  264. int init_atu;
  265. int iop3xx_get_init_atu(void) {
  266. /* check if default has been overridden */
  267. if (init_atu != IOP3XX_INIT_ATU_DEFAULT)
  268. return init_atu;
  269. else
  270. return IOP3XX_INIT_ATU_DISABLE;
  271. }
  272. static void __init iop3xx_atu_debug(void)
  273. {
  274. DBG("PCI: Intel IOP3xx PCI init.\n");
  275. DBG("PCI: Outbound memory window 0: PCI 0x%08x%08x\n",
  276. *IOP3XX_OUMWTVR0, *IOP3XX_OMWTVR0);
  277. DBG("PCI: Outbound memory window 1: PCI 0x%08x%08x\n",
  278. *IOP3XX_OUMWTVR1, *IOP3XX_OMWTVR1);
  279. DBG("PCI: Outbound IO window: PCI 0x%08x\n",
  280. *IOP3XX_OIOWTVR);
  281. DBG("PCI: Inbound memory window 0: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  282. *IOP3XX_IAUBAR0, *IOP3XX_IABAR0, *IOP3XX_IALR0, *IOP3XX_IATVR0);
  283. DBG("PCI: Inbound memory window 1: PCI 0x%08x%08x 0x%08x\n",
  284. *IOP3XX_IAUBAR1, *IOP3XX_IABAR1, *IOP3XX_IALR1);
  285. DBG("PCI: Inbound memory window 2: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  286. *IOP3XX_IAUBAR2, *IOP3XX_IABAR2, *IOP3XX_IALR2, *IOP3XX_IATVR2);
  287. DBG("PCI: Inbound memory window 3: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  288. *IOP3XX_IAUBAR3, *IOP3XX_IABAR3, *IOP3XX_IALR3, *IOP3XX_IATVR3);
  289. DBG("PCI: Expansion ROM window: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
  290. 0, *IOP3XX_ERBAR, *IOP3XX_ERLR, *IOP3XX_ERTVR);
  291. DBG("ATU: IOP3XX_ATUCMD=0x%04x\n", *IOP3XX_ATUCMD);
  292. DBG("ATU: IOP3XX_ATUCR=0x%08x\n", *IOP3XX_ATUCR);
  293. hook_fault_code(16+6, iop3xx_pci_abort, SIGBUS, 0, "imprecise external abort");
  294. }
  295. /* for platforms that might be host-bus-adapters */
  296. void __init iop3xx_pci_preinit_cond(void)
  297. {
  298. if (iop3xx_get_init_atu() == IOP3XX_INIT_ATU_ENABLE) {
  299. iop3xx_atu_disable();
  300. iop3xx_atu_setup();
  301. iop3xx_atu_debug();
  302. }
  303. }
  304. void __init iop3xx_pci_preinit(void)
  305. {
  306. pcibios_min_io = 0;
  307. pcibios_min_mem = 0;
  308. iop3xx_atu_disable();
  309. iop3xx_atu_setup();
  310. iop3xx_atu_debug();
  311. }
  312. /* allow init_atu to be user overridden */
  313. static int __init iop3xx_init_atu_setup(char *str)
  314. {
  315. init_atu = IOP3XX_INIT_ATU_DEFAULT;
  316. if (str) {
  317. while (*str != '\0') {
  318. switch (*str) {
  319. case 'y':
  320. case 'Y':
  321. init_atu = IOP3XX_INIT_ATU_ENABLE;
  322. break;
  323. case 'n':
  324. case 'N':
  325. init_atu = IOP3XX_INIT_ATU_DISABLE;
  326. break;
  327. case ',':
  328. case '=':
  329. break;
  330. default:
  331. printk(KERN_DEBUG "\"%s\" malformed at "
  332. "character: \'%c\'",
  333. __func__,
  334. *str);
  335. *(str + 1) = '\0';
  336. }
  337. str++;
  338. }
  339. }
  340. return 1;
  341. }
  342. __setup("iop3xx_init_atu", iop3xx_init_atu_setup);