iop321-pci.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * arch/arm/mach-iop3xx/iop321-pci.c
  3. *
  4. * PCI support for the Intel IOP321 chipset
  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. */
  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/iop321.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 80321 then a type0 made, else a type1 is created.
  35. */
  36. static u32 iop321_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 occure during a config cycle where there is no device, like during
  52. * the discovery stage.
  53. */
  54. static int iop321_pci_status(void)
  55. {
  56. unsigned int status;
  57. int ret = 0;
  58. /*
  59. * Check the status registers.
  60. */
  61. status = *IOP321_ATUSR;
  62. if (status & 0xf900)
  63. {
  64. DBG("\t\t\tPCI: P0 - status = 0x%08x\n", status);
  65. *IOP321_ATUSR = status & 0xf900;
  66. ret = 1;
  67. }
  68. status = *IOP321_ATUISR;
  69. if (status & 0x679f)
  70. {
  71. DBG("\t\t\tPCI: P1 - status = 0x%08x\n", status);
  72. *IOP321_ATUISR = status & 0x679f;
  73. ret = 1;
  74. }
  75. return ret;
  76. }
  77. /*
  78. * Simply write the address register and read the configuration
  79. * data. Note that the 4 nop's ensure that we are able to handle
  80. * a delayed abort (in theory.)
  81. */
  82. static inline u32 iop321_read(unsigned long addr)
  83. {
  84. u32 val;
  85. __asm__ __volatile__(
  86. "str %1, [%2]\n\t"
  87. "ldr %0, [%3]\n\t"
  88. "nop\n\t"
  89. "nop\n\t"
  90. "nop\n\t"
  91. "nop\n\t"
  92. : "=r" (val)
  93. : "r" (addr), "r" (IOP321_OCCAR), "r" (IOP321_OCCDR));
  94. return val;
  95. }
  96. /*
  97. * The read routines must check the error status of the last configuration
  98. * cycle. If there was an error, the routine returns all hex f's.
  99. */
  100. static int
  101. iop321_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  102. int size, u32 *value)
  103. {
  104. unsigned long addr = iop321_cfg_address(bus, devfn, where);
  105. u32 val = iop321_read(addr) >> ((where & 3) * 8);
  106. if( iop321_pci_status() )
  107. val = 0xffffffff;
  108. *value = val;
  109. return PCIBIOS_SUCCESSFUL;
  110. }
  111. static int
  112. iop321_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  113. int size, u32 value)
  114. {
  115. unsigned long addr = iop321_cfg_address(bus, devfn, where);
  116. u32 val;
  117. if (size != 4) {
  118. val = iop321_read(addr);
  119. if (!iop321_pci_status() == 0)
  120. return PCIBIOS_SUCCESSFUL;
  121. where = (where & 3) * 8;
  122. if (size == 1)
  123. val &= ~(0xff << where);
  124. else
  125. val &= ~(0xffff << where);
  126. *IOP321_OCCDR = val | value << where;
  127. } else {
  128. asm volatile(
  129. "str %1, [%2]\n\t"
  130. "str %0, [%3]\n\t"
  131. "nop\n\t"
  132. "nop\n\t"
  133. "nop\n\t"
  134. "nop\n\t"
  135. :
  136. : "r" (value), "r" (addr),
  137. "r" (IOP321_OCCAR), "r" (IOP321_OCCDR));
  138. }
  139. return PCIBIOS_SUCCESSFUL;
  140. }
  141. static struct pci_ops iop321_ops = {
  142. .read = iop321_read_config,
  143. .write = iop321_write_config,
  144. };
  145. /*
  146. * When a PCI device does not exist during config cycles, the 80200 gets a
  147. * bus error instead of returning 0xffffffff. This handler simply returns.
  148. */
  149. int
  150. iop321_pci_abort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  151. {
  152. DBG("PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx\n",
  153. addr, fsr, regs->ARM_pc, regs->ARM_lr);
  154. /*
  155. * If it was an imprecise abort, then we need to correct the
  156. * return address to be _after_ the instruction.
  157. */
  158. if (fsr & (1 << 10))
  159. regs->ARM_pc += 4;
  160. return 0;
  161. }
  162. /*
  163. * Scan an IOP321 PCI bus. sys->bus defines which bus we scan.
  164. */
  165. struct pci_bus *iop321_scan_bus(int nr, struct pci_sys_data *sys)
  166. {
  167. return pci_scan_bus(sys->busnr, &iop321_ops, sys);
  168. }
  169. void iop321_init(void)
  170. {
  171. DBG("PCI: Intel 80321 PCI init code.\n");
  172. DBG("ATU: IOP321_ATUCMD=0x%04x\n", *IOP321_ATUCMD);
  173. DBG("ATU: IOP321_OMWTVR0=0x%04x, IOP321_OIOWTVR=0x%04x\n",
  174. *IOP321_OMWTVR0,
  175. *IOP321_OIOWTVR);
  176. DBG("ATU: IOP321_ATUCR=0x%08x\n", *IOP321_ATUCR);
  177. DBG("ATU: IOP321_IABAR0=0x%08x IOP321_IALR0=0x%08x IOP321_IATVR0=%08x\n",
  178. *IOP321_IABAR0, *IOP321_IALR0, *IOP321_IATVR0);
  179. DBG("ATU: IOP321_OMWTVR0=0x%08x\n", *IOP321_OMWTVR0);
  180. DBG("ATU: IOP321_IABAR1=0x%08x IOP321_IALR1=0x%08x\n",
  181. *IOP321_IABAR1, *IOP321_IALR1);
  182. DBG("ATU: IOP321_ERBAR=0x%08x IOP321_ERLR=0x%08x IOP321_ERTVR=%08x\n",
  183. *IOP321_ERBAR, *IOP321_ERLR, *IOP321_ERTVR);
  184. DBG("ATU: IOP321_IABAR2=0x%08x IOP321_IALR2=0x%08x IOP321_IATVR2=%08x\n",
  185. *IOP321_IABAR2, *IOP321_IALR2, *IOP321_IATVR2);
  186. DBG("ATU: IOP321_IABAR3=0x%08x IOP321_IALR3=0x%08x IOP321_IATVR3=%08x\n",
  187. *IOP321_IABAR3, *IOP321_IALR3, *IOP321_IATVR3);
  188. hook_fault_code(16+6, iop321_pci_abort, SIGBUS, "imprecise external abort");
  189. }