iop331-pci.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * arch/arm/mach-iop3xx/iop331-pci.c
  3. *
  4. * PCI support for the Intel IOP331 chipset
  5. *
  6. * Author: Dave Jiang (dave.jiang@intel.com)
  7. * Copyright (C) 2003, 2004 Intel Corp.
  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. */
  14. #include <linux/kernel.h>
  15. #include <linux/pci.h>
  16. #include <linux/slab.h>
  17. #include <linux/mm.h>
  18. #include <linux/init.h>
  19. #include <linux/ioport.h>
  20. #include <asm/io.h>
  21. #include <asm/irq.h>
  22. #include <asm/system.h>
  23. #include <asm/hardware.h>
  24. #include <asm/mach/pci.h>
  25. #include <asm/arch/iop331.h>
  26. #undef DEBUG
  27. #undef DEBUG1
  28. #ifdef DEBUG
  29. #define DBG(x...) printk(x)
  30. #else
  31. #define DBG(x...) do { } while (0)
  32. #endif
  33. #ifdef DEBUG1
  34. #define DBG1(x...) printk(x)
  35. #else
  36. #define DBG1(x...) do { } while (0)
  37. #endif
  38. /*
  39. * This routine builds either a type0 or type1 configuration command. If the
  40. * bus is on the 80331 then a type0 made, else a type1 is created.
  41. */
  42. static u32 iop331_cfg_address(struct pci_bus *bus, int devfn, int where)
  43. {
  44. struct pci_sys_data *sys = bus->sysdata;
  45. u32 addr;
  46. if (sys->busnr == bus->number)
  47. addr = 1 << (PCI_SLOT(devfn) + 16) | (PCI_SLOT(devfn) << 11);
  48. else
  49. addr = bus->number << 16 | PCI_SLOT(devfn) << 11 | 1;
  50. addr |= PCI_FUNC(devfn) << 8 | (where & ~3);
  51. return addr;
  52. }
  53. /*
  54. * This routine checks the status of the last configuration cycle. If an error
  55. * was detected it returns a 1, else it returns a 0. The errors being checked
  56. * are parity, master abort, target abort (master and target). These types of
  57. * errors occure during a config cycle where there is no device, like during
  58. * the discovery stage.
  59. */
  60. static int iop331_pci_status(void)
  61. {
  62. unsigned int status;
  63. int ret = 0;
  64. /*
  65. * Check the status registers.
  66. */
  67. status = *IOP331_ATUSR;
  68. if (status & 0xf900)
  69. {
  70. DBG("\t\t\tPCI: P0 - status = 0x%08x\n", status);
  71. *IOP331_ATUSR = status & 0xf900;
  72. ret = 1;
  73. }
  74. status = *IOP331_ATUISR;
  75. if (status & 0x679f)
  76. {
  77. DBG("\t\t\tPCI: P1 - status = 0x%08x\n", status);
  78. *IOP331_ATUISR = status & 0x679f;
  79. ret = 1;
  80. }
  81. return ret;
  82. }
  83. /*
  84. * Simply write the address register and read the configuration
  85. * data. Note that the 4 nop's ensure that we are able to handle
  86. * a delayed abort (in theory.)
  87. */
  88. static inline u32 iop331_read(unsigned long addr)
  89. {
  90. u32 val;
  91. __asm__ __volatile__(
  92. "str %1, [%2]\n\t"
  93. "ldr %0, [%3]\n\t"
  94. "nop\n\t"
  95. "nop\n\t"
  96. "nop\n\t"
  97. "nop\n\t"
  98. : "=r" (val)
  99. : "r" (addr), "r" (IOP331_OCCAR), "r" (IOP331_OCCDR));
  100. return val;
  101. }
  102. /*
  103. * The read routines must check the error status of the last configuration
  104. * cycle. If there was an error, the routine returns all hex f's.
  105. */
  106. static int
  107. iop331_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  108. int size, u32 *value)
  109. {
  110. unsigned long addr = iop331_cfg_address(bus, devfn, where);
  111. u32 val = iop331_read(addr) >> ((where & 3) * 8);
  112. if( iop331_pci_status() )
  113. val = 0xffffffff;
  114. *value = val;
  115. return PCIBIOS_SUCCESSFUL;
  116. }
  117. static int
  118. iop331_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  119. int size, u32 value)
  120. {
  121. unsigned long addr = iop331_cfg_address(bus, devfn, where);
  122. u32 val;
  123. if (size != 4) {
  124. val = iop331_read(addr);
  125. if (!iop331_pci_status() == 0)
  126. return PCIBIOS_SUCCESSFUL;
  127. where = (where & 3) * 8;
  128. if (size == 1)
  129. val &= ~(0xff << where);
  130. else
  131. val &= ~(0xffff << where);
  132. *IOP331_OCCDR = val | value << where;
  133. } else {
  134. asm volatile(
  135. "str %1, [%2]\n\t"
  136. "str %0, [%3]\n\t"
  137. "nop\n\t"
  138. "nop\n\t"
  139. "nop\n\t"
  140. "nop\n\t"
  141. :
  142. : "r" (value), "r" (addr),
  143. "r" (IOP331_OCCAR), "r" (IOP331_OCCDR));
  144. }
  145. return PCIBIOS_SUCCESSFUL;
  146. }
  147. static struct pci_ops iop331_ops = {
  148. .read = iop331_read_config,
  149. .write = iop331_write_config,
  150. };
  151. /*
  152. * When a PCI device does not exist during config cycles, the XScale gets a
  153. * bus error instead of returning 0xffffffff. This handler simply returns.
  154. */
  155. int
  156. iop331_pci_abort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  157. {
  158. DBG("PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx\n",
  159. addr, fsr, regs->ARM_pc, regs->ARM_lr);
  160. /*
  161. * If it was an imprecise abort, then we need to correct the
  162. * return address to be _after_ the instruction.
  163. */
  164. if (fsr & (1 << 10))
  165. regs->ARM_pc += 4;
  166. return 0;
  167. }
  168. /*
  169. * Scan an IOP331 PCI bus. sys->bus defines which bus we scan.
  170. */
  171. struct pci_bus *iop331_scan_bus(int nr, struct pci_sys_data *sys)
  172. {
  173. return pci_scan_bus(sys->busnr, &iop331_ops, sys);
  174. }
  175. void iop331_init(void)
  176. {
  177. DBG1("PCI: Intel 80331 PCI init code.\n");
  178. DBG1("\tATU: IOP331_ATUCMD=0x%04x\n", *IOP331_ATUCMD);
  179. DBG1("\tATU: IOP331_OMWTVR0=0x%04x, IOP331_OIOWTVR=0x%04x\n",
  180. *IOP331_OMWTVR0,
  181. *IOP331_OIOWTVR);
  182. DBG1("\tATU: IOP331_OMWTVR1=0x%04x\n", *IOP331_OMWTVR1);
  183. DBG1("\tATU: IOP331_ATUCR=0x%08x\n", *IOP331_ATUCR);
  184. DBG1("\tATU: IOP331_IABAR0=0x%08x IOP331_IALR0=0x%08x IOP331_IATVR0=%08x\n", *IOP331_IABAR0, *IOP331_IALR0, *IOP331_IATVR0);
  185. DBG1("\tATU: IOP31_IABAR1=0x%08x IOP331_IALR1=0x%08x\n", *IOP331_IABAR1, *IOP331_IALR1);
  186. DBG1("\tATU: IOP331_ERBAR=0x%08x IOP331_ERLR=0x%08x IOP331_ERTVR=%08x\n", *IOP331_ERBAR, *IOP331_ERLR, *IOP331_ERTVR);
  187. DBG1("\tATU: IOP331_IABAR2=0x%08x IOP331_IALR2=0x%08x IOP331_IATVR2=%08x\n", *IOP331_IABAR2, *IOP331_IALR2, *IOP331_IATVR2);
  188. DBG1("\tATU: IOP331_IABAR3=0x%08x IOP331_IALR3=0x%08x IOP331_IATVR3=%08x\n", *IOP331_IABAR3, *IOP331_IALR3, *IOP331_IATVR3);
  189. hook_fault_code(16+6, iop331_pci_abort, SIGBUS, "imprecise external abort");
  190. }