pci.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * arch/arm/mach-ixp23xx/pci.c
  3. *
  4. * PCI routines for IXP23XX based systems
  5. *
  6. * Copyright (c) 2005 MontaVista Software, Inc.
  7. *
  8. * based on original code:
  9. *
  10. * Author: Naeem Afzal <naeem.m.afzal@intel.com>
  11. * Copyright 2002-2005 Intel Corp.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/pci.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/mm.h>
  23. #include <linux/init.h>
  24. #include <linux/ioport.h>
  25. #include <linux/delay.h>
  26. #include <linux/io.h>
  27. #include <asm/irq.h>
  28. #include <asm/sizes.h>
  29. #include <asm/mach/pci.h>
  30. #include <mach/hardware.h>
  31. extern int (*external_fault) (unsigned long, struct pt_regs *);
  32. static volatile int pci_master_aborts = 0;
  33. #ifdef DEBUG
  34. #define DBG(x...) printk(x)
  35. #else
  36. #define DBG(x...)
  37. #endif
  38. int clear_master_aborts(void);
  39. static u32
  40. *ixp23xx_pci_config_addr(unsigned int bus_nr, unsigned int devfn, int where)
  41. {
  42. u32 *paddress;
  43. /*
  44. * Must be dword aligned
  45. */
  46. where &= ~3;
  47. /*
  48. * For top bus, generate type 0, else type 1
  49. */
  50. if (!bus_nr) {
  51. if (PCI_SLOT(devfn) >= 8)
  52. return 0;
  53. paddress = (u32 *) (IXP23XX_PCI_CFG0_VIRT
  54. | (1 << (PCI_SLOT(devfn) + 16))
  55. | (PCI_FUNC(devfn) << 8) | where);
  56. } else {
  57. paddress = (u32 *) (IXP23XX_PCI_CFG1_VIRT
  58. | (bus_nr << 16)
  59. | (PCI_SLOT(devfn) << 11)
  60. | (PCI_FUNC(devfn) << 8) | where);
  61. }
  62. return paddress;
  63. }
  64. /*
  65. * Mask table, bits to mask for quantity of size 1, 2 or 4 bytes.
  66. * 0 and 3 are not valid indexes...
  67. */
  68. static u32 bytemask[] = {
  69. /*0*/ 0,
  70. /*1*/ 0xff,
  71. /*2*/ 0xffff,
  72. /*3*/ 0,
  73. /*4*/ 0xffffffff,
  74. };
  75. static int ixp23xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  76. int where, int size, u32 *value)
  77. {
  78. u32 n;
  79. u32 *addr;
  80. n = where % 4;
  81. DBG("In config_read(%d) %d from dev %d:%d:%d\n", size, where,
  82. bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  83. addr = ixp23xx_pci_config_addr(bus->number, devfn, where);
  84. if (!addr)
  85. return PCIBIOS_DEVICE_NOT_FOUND;
  86. pci_master_aborts = 0;
  87. *value = (*addr >> (8*n)) & bytemask[size];
  88. if (pci_master_aborts) {
  89. pci_master_aborts = 0;
  90. *value = 0xffffffff;
  91. return PCIBIOS_DEVICE_NOT_FOUND;
  92. }
  93. return PCIBIOS_SUCCESSFUL;
  94. }
  95. /*
  96. * We don't do error checking on the address for writes.
  97. * It's assumed that the user checked for the device existing first
  98. * by doing a read first.
  99. */
  100. static int ixp23xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  101. int where, int size, u32 value)
  102. {
  103. u32 mask;
  104. u32 *addr;
  105. u32 temp;
  106. mask = ~(bytemask[size] << ((where % 0x4) * 8));
  107. addr = ixp23xx_pci_config_addr(bus->number, devfn, where);
  108. if (!addr)
  109. return PCIBIOS_DEVICE_NOT_FOUND;
  110. temp = (u32) (value) << ((where % 0x4) * 8);
  111. *addr = (*addr & mask) | temp;
  112. clear_master_aborts();
  113. return PCIBIOS_SUCCESSFUL;
  114. }
  115. struct pci_ops ixp23xx_pci_ops = {
  116. .read = ixp23xx_pci_read_config,
  117. .write = ixp23xx_pci_write_config,
  118. };
  119. int ixp23xx_pci_abort_handler(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  120. {
  121. volatile unsigned long temp;
  122. unsigned long flags;
  123. pci_master_aborts = 1;
  124. local_irq_save(flags);
  125. temp = *IXP23XX_PCI_CONTROL;
  126. /*
  127. * master abort and cmd tgt err
  128. */
  129. if (temp & ((1 << 8) | (1 << 5)))
  130. *IXP23XX_PCI_CONTROL = temp;
  131. temp = *IXP23XX_PCI_CMDSTAT;
  132. if (temp & (1 << 29))
  133. *IXP23XX_PCI_CMDSTAT = temp;
  134. local_irq_restore(flags);
  135. /*
  136. * If it was an imprecise abort, then we need to correct the
  137. * return address to be _after_ the instruction.
  138. */
  139. if (fsr & (1 << 10))
  140. regs->ARM_pc += 4;
  141. return 0;
  142. }
  143. int clear_master_aborts(void)
  144. {
  145. volatile u32 temp;
  146. temp = *IXP23XX_PCI_CONTROL;
  147. /*
  148. * master abort and cmd tgt err
  149. */
  150. if (temp & ((1 << 8) | (1 << 5)))
  151. *IXP23XX_PCI_CONTROL = temp;
  152. temp = *IXP23XX_PCI_CMDSTAT;
  153. if (temp & (1 << 29))
  154. *IXP23XX_PCI_CMDSTAT = temp;
  155. return 0;
  156. }
  157. static void __init ixp23xx_pci_common_init(void)
  158. {
  159. #ifdef __ARMEB__
  160. *IXP23XX_PCI_CONTROL |= 0x20000; /* set I/O swapping */
  161. #endif
  162. /*
  163. * ADDR_31 needs to be clear for PCI memory access to CPP memory
  164. */
  165. *IXP23XX_CPP2XSI_CURR_XFER_REG3 &= ~IXP23XX_CPP2XSI_ADDR_31;
  166. *IXP23XX_CPP2XSI_CURR_XFER_REG3 |= IXP23XX_CPP2XSI_PSH_OFF;
  167. /*
  168. * Select correct memory for PCI inbound transactions
  169. */
  170. if (ixp23xx_cpp_boot()) {
  171. *IXP23XX_PCI_CPP_ADDR_BITS &= ~(1 << 1);
  172. } else {
  173. *IXP23XX_PCI_CPP_ADDR_BITS |= (1 << 1);
  174. /*
  175. * Enable coherency on A2 silicon.
  176. */
  177. if (arch_is_coherent())
  178. *IXP23XX_CPP2XSI_CURR_XFER_REG3 &= ~IXP23XX_CPP2XSI_COH_OFF;
  179. }
  180. }
  181. void __init ixp23xx_pci_preinit(void)
  182. {
  183. pcibios_min_io = 0;
  184. pcibios_min_mem = 0xe0000000;
  185. pci_set_flags(0);
  186. ixp23xx_pci_common_init();
  187. hook_fault_code(16+6, ixp23xx_pci_abort_handler, SIGBUS, 0,
  188. "PCI config cycle to non-existent device");
  189. *IXP23XX_PCI_ADDR_EXT = 0x0000e000;
  190. }
  191. /*
  192. * Prevent PCI layer from seeing the inbound host-bridge resources
  193. */
  194. static void __devinit pci_fixup_ixp23xx(struct pci_dev *dev)
  195. {
  196. int i;
  197. dev->class &= 0xff;
  198. dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
  199. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  200. dev->resource[i].start = 0;
  201. dev->resource[i].end = 0;
  202. dev->resource[i].flags = 0;
  203. }
  204. }
  205. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9002, pci_fixup_ixp23xx);
  206. /*
  207. * IXP2300 systems often have large resource requirements, so we just
  208. * use our own resource space.
  209. */
  210. static struct resource ixp23xx_pci_mem_space = {
  211. .start = IXP23XX_PCI_MEM_START,
  212. .end = IXP23XX_PCI_MEM_START + IXP23XX_PCI_MEM_SIZE - 1,
  213. .flags = IORESOURCE_MEM,
  214. .name = "PCI Mem Space"
  215. };
  216. static struct resource ixp23xx_pci_io_space = {
  217. .start = 0x00000100,
  218. .end = 0x01ffffff,
  219. .flags = IORESOURCE_IO,
  220. .name = "PCI I/O Space"
  221. };
  222. int ixp23xx_pci_setup(int nr, struct pci_sys_data *sys)
  223. {
  224. if (nr >= 1)
  225. return 0;
  226. pci_add_resource_offset(&sys->resources,
  227. &ixp23xx_pci_io_space, sys->io_offset);
  228. pci_add_resource_offset(&sys->resources,
  229. &ixp23xx_pci_mem_space, sys->mem_offset);
  230. return 1;
  231. }
  232. void __init ixp23xx_pci_slave_init(void)
  233. {
  234. ixp23xx_pci_common_init();
  235. }