pci.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. // #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. sys->mem_offset = IOP3XX_PCI_LOWER_MEM_PA - IOP3XX_PCI_LOWER_MEM_BA;
  179. sys->io_offset = IOP3XX_PCI_LOWER_IO_PA - IOP3XX_PCI_LOWER_IO_BA;
  180. sys->resource[0] = &res[0];
  181. sys->resource[1] = &res[1];
  182. sys->resource[2] = NULL;
  183. return 1;
  184. }
  185. struct pci_bus *iop3xx_pci_scan_bus(int nr, struct pci_sys_data *sys)
  186. {
  187. return pci_scan_bus(sys->busnr, &iop3xx_ops, sys);
  188. }
  189. void __init iop3xx_atu_setup(void)
  190. {
  191. /* BAR 0 ( Disabled ) */
  192. *IOP3XX_IAUBAR0 = 0x0;
  193. *IOP3XX_IABAR0 = 0x0;
  194. *IOP3XX_IATVR0 = 0x0;
  195. *IOP3XX_IALR0 = 0x0;
  196. /* BAR 1 ( Disabled ) */
  197. *IOP3XX_IAUBAR1 = 0x0;
  198. *IOP3XX_IABAR1 = 0x0;
  199. *IOP3XX_IALR1 = 0x0;
  200. /* BAR 2 (1:1 mapping with Physical RAM) */
  201. /* Set limit and enable */
  202. *IOP3XX_IALR2 = ~((u32)IOP3XX_MAX_RAM_SIZE - 1) & ~0x1;
  203. *IOP3XX_IAUBAR2 = 0x0;
  204. /* Align the inbound bar with the base of memory */
  205. *IOP3XX_IABAR2 = PHYS_OFFSET |
  206. PCI_BASE_ADDRESS_MEM_TYPE_64 |
  207. PCI_BASE_ADDRESS_MEM_PREFETCH;
  208. *IOP3XX_IATVR2 = PHYS_OFFSET;
  209. /* Outbound window 0 */
  210. *IOP3XX_OMWTVR0 = IOP3XX_PCI_LOWER_MEM_PA;
  211. *IOP3XX_OUMWTVR0 = 0;
  212. /* Outbound window 1 */
  213. *IOP3XX_OMWTVR1 = IOP3XX_PCI_LOWER_MEM_PA + IOP3XX_PCI_MEM_WINDOW_SIZE;
  214. *IOP3XX_OUMWTVR1 = 0;
  215. /* BAR 3 ( Disabled ) */
  216. *IOP3XX_IAUBAR3 = 0x0;
  217. *IOP3XX_IABAR3 = 0x0;
  218. *IOP3XX_IATVR3 = 0x0;
  219. *IOP3XX_IALR3 = 0x0;
  220. /* Setup the I/O Bar
  221. */
  222. *IOP3XX_OIOWTVR = IOP3XX_PCI_LOWER_IO_PA;;
  223. /* Enable inbound and outbound cycles
  224. */
  225. *IOP3XX_ATUCMD |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  226. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  227. *IOP3XX_ATUCR |= IOP3XX_ATUCR_OUT_EN;
  228. }
  229. void __init iop3xx_atu_disable(void)
  230. {
  231. *IOP3XX_ATUCMD = 0;
  232. *IOP3XX_ATUCR = 0;
  233. /* wait for cycles to quiesce */
  234. while (*IOP3XX_PCSR & (IOP3XX_PCSR_OUT_Q_BUSY |
  235. IOP3XX_PCSR_IN_Q_BUSY))
  236. cpu_relax();
  237. /* BAR 0 ( Disabled ) */
  238. *IOP3XX_IAUBAR0 = 0x0;
  239. *IOP3XX_IABAR0 = 0x0;
  240. *IOP3XX_IATVR0 = 0x0;
  241. *IOP3XX_IALR0 = 0x0;
  242. /* BAR 1 ( Disabled ) */
  243. *IOP3XX_IAUBAR1 = 0x0;
  244. *IOP3XX_IABAR1 = 0x0;
  245. *IOP3XX_IALR1 = 0x0;
  246. /* BAR 2 ( Disabled ) */
  247. *IOP3XX_IAUBAR2 = 0x0;
  248. *IOP3XX_IABAR2 = 0x0;
  249. *IOP3XX_IATVR2 = 0x0;
  250. *IOP3XX_IALR2 = 0x0;
  251. /* BAR 3 ( Disabled ) */
  252. *IOP3XX_IAUBAR3 = 0x0;
  253. *IOP3XX_IABAR3 = 0x0;
  254. *IOP3XX_IATVR3 = 0x0;
  255. *IOP3XX_IALR3 = 0x0;
  256. /* Clear the outbound windows */
  257. *IOP3XX_OIOWTVR = 0;
  258. /* Outbound window 0 */
  259. *IOP3XX_OMWTVR0 = 0;
  260. *IOP3XX_OUMWTVR0 = 0;
  261. /* Outbound window 1 */
  262. *IOP3XX_OMWTVR1 = 0;
  263. *IOP3XX_OUMWTVR1 = 0;
  264. }
  265. /* Flag to determine whether the ATU is initialized and the PCI bus scanned */
  266. int init_atu;
  267. void __init iop3xx_pci_preinit(void)
  268. {
  269. if (iop3xx_get_init_atu() == IOP3XX_INIT_ATU_ENABLE) {
  270. iop3xx_atu_disable();
  271. iop3xx_atu_setup();
  272. }
  273. DBG("PCI: Intel 803xx PCI init code.\n");
  274. DBG("ATU: IOP3XX_ATUCMD=0x%04x\n", *IOP3XX_ATUCMD);
  275. DBG("ATU: IOP3XX_OMWTVR0=0x%04x, IOP3XX_OIOWTVR=0x%04x\n",
  276. *IOP3XX_OMWTVR0,
  277. *IOP3XX_OIOWTVR);
  278. DBG("ATU: IOP3XX_ATUCR=0x%08x\n", *IOP3XX_ATUCR);
  279. DBG("ATU: IOP3XX_IABAR0=0x%08x IOP3XX_IALR0=0x%08x IOP3XX_IATVR0=%08x\n",
  280. *IOP3XX_IABAR0, *IOP3XX_IALR0, *IOP3XX_IATVR0);
  281. DBG("ATU: IOP3XX_OMWTVR0=0x%08x\n", *IOP3XX_OMWTVR0);
  282. DBG("ATU: IOP3XX_IABAR1=0x%08x IOP3XX_IALR1=0x%08x\n",
  283. *IOP3XX_IABAR1, *IOP3XX_IALR1);
  284. DBG("ATU: IOP3XX_ERBAR=0x%08x IOP3XX_ERLR=0x%08x IOP3XX_ERTVR=%08x\n",
  285. *IOP3XX_ERBAR, *IOP3XX_ERLR, *IOP3XX_ERTVR);
  286. DBG("ATU: IOP3XX_IABAR2=0x%08x IOP3XX_IALR2=0x%08x IOP3XX_IATVR2=%08x\n",
  287. *IOP3XX_IABAR2, *IOP3XX_IALR2, *IOP3XX_IATVR2);
  288. DBG("ATU: IOP3XX_IABAR3=0x%08x IOP3XX_IALR3=0x%08x IOP3XX_IATVR3=%08x\n",
  289. *IOP3XX_IABAR3, *IOP3XX_IALR3, *IOP3XX_IATVR3);
  290. hook_fault_code(16+6, iop3xx_pci_abort, SIGBUS, "imprecise external abort");
  291. }
  292. /* allow init_atu to be user overridden */
  293. static int __init iop3xx_init_atu_setup(char *str)
  294. {
  295. init_atu = IOP3XX_INIT_ATU_DEFAULT;
  296. if (str) {
  297. while (*str != '\0') {
  298. switch (*str) {
  299. case 'y':
  300. case 'Y':
  301. init_atu = IOP3XX_INIT_ATU_ENABLE;
  302. break;
  303. case 'n':
  304. case 'N':
  305. init_atu = IOP3XX_INIT_ATU_DISABLE;
  306. break;
  307. case ',':
  308. case '=':
  309. break;
  310. default:
  311. printk(KERN_DEBUG "\"%s\" malformed at "
  312. "character: \'%c\'",
  313. __FUNCTION__,
  314. *str);
  315. *(str + 1) = '\0';
  316. }
  317. str++;
  318. }
  319. }
  320. return 1;
  321. }
  322. __setup("iop3xx_init_atu", iop3xx_init_atu_setup);