pci.c 9.0 KB

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