pci.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * arch/arm/mach-ks8695/pci.c
  3. *
  4. * Copyright (C) 2003, Micrel Semiconductors
  5. * Copyright (C) 2006, Greg Ungerer <gerg@snapgear.com>
  6. * Copyright (C) 2006, Ben Dooks
  7. * Copyright (C) 2007, Andrew Victor
  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 as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/pci.h>
  25. #include <linux/mm.h>
  26. #include <linux/init.h>
  27. #include <linux/irq.h>
  28. #include <linux/delay.h>
  29. #include <linux/io.h>
  30. #include <asm/signal.h>
  31. #include <asm/mach/pci.h>
  32. #include <mach/hardware.h>
  33. #include "devices.h"
  34. #include "regs-pci.h"
  35. static int pci_dbg;
  36. static void ks8695_pci_setupconfig(unsigned int bus_nr, unsigned int devfn, unsigned int where)
  37. {
  38. unsigned long pbca;
  39. pbca = PBCA_ENABLE | (where & ~3);
  40. pbca |= PCI_SLOT(devfn) << 11 ;
  41. pbca |= PCI_FUNC(devfn) << 8;
  42. pbca |= bus_nr << 16;
  43. if (bus_nr == 0) {
  44. /* use Type-0 transaction */
  45. __raw_writel(pbca, KS8695_PCI_VA + KS8695_PBCA);
  46. } else {
  47. /* use Type-1 transaction */
  48. __raw_writel(pbca | PBCA_TYPE1, KS8695_PCI_VA + KS8695_PBCA);
  49. }
  50. }
  51. static void __iomem *ks8695_pci_map_bus(struct pci_bus *bus, unsigned int devfn,
  52. int where)
  53. {
  54. ks8695_pci_setupconfig(bus->number, devfn, where);
  55. return KS8695_PCI_VA + KS8695_PBCD;
  56. }
  57. static void ks8695_local_writeconfig(int where, u32 value)
  58. {
  59. ks8695_pci_setupconfig(0, 0, where);
  60. __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
  61. }
  62. static struct pci_ops ks8695_pci_ops = {
  63. .map_bus = ks8695_pci_map_bus,
  64. .read = pci_generic_config_read32,
  65. .write = pci_generic_config_write32,
  66. };
  67. static struct resource pci_mem = {
  68. .name = "PCI Memory space",
  69. .start = KS8695_PCIMEM_PA,
  70. .end = KS8695_PCIMEM_PA + (KS8695_PCIMEM_SIZE - 1),
  71. .flags = IORESOURCE_MEM,
  72. };
  73. static struct resource pci_io = {
  74. .name = "PCI IO space",
  75. .start = KS8695_PCIIO_PA,
  76. .end = KS8695_PCIIO_PA + (KS8695_PCIIO_SIZE - 1),
  77. .flags = IORESOURCE_IO,
  78. };
  79. static int __init ks8695_pci_setup(int nr, struct pci_sys_data *sys)
  80. {
  81. if (nr > 0)
  82. return 0;
  83. request_resource(&iomem_resource, &pci_mem);
  84. request_resource(&ioport_resource, &pci_io);
  85. pci_add_resource_offset(&sys->resources, &pci_io, sys->io_offset);
  86. pci_add_resource_offset(&sys->resources, &pci_mem, sys->mem_offset);
  87. /* Assign and enable processor bridge */
  88. ks8695_local_writeconfig(PCI_BASE_ADDRESS_0, KS8695_PCIMEM_PA);
  89. /* Enable bus-master & Memory Space access */
  90. ks8695_local_writeconfig(PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  91. /* Set cache-line size & latency. */
  92. ks8695_local_writeconfig(PCI_CACHE_LINE_SIZE, (32 << 8) | (L1_CACHE_BYTES / sizeof(u32)));
  93. /* Reserve PCI memory space for PCI-AHB resources */
  94. if (!request_mem_region(KS8695_PCIMEM_PA, SZ_64M, "PCI-AHB Bridge")) {
  95. printk(KERN_ERR "Cannot allocate PCI-AHB Bridge memory.\n");
  96. return -EBUSY;
  97. }
  98. return 1;
  99. }
  100. static inline unsigned int size_mask(unsigned long size)
  101. {
  102. return (~size) + 1;
  103. }
  104. static int ks8695_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  105. {
  106. unsigned long pc = instruction_pointer(regs);
  107. unsigned long instr = *(unsigned long *)pc;
  108. unsigned long cmdstat;
  109. cmdstat = __raw_readl(KS8695_PCI_VA + KS8695_CRCFCS);
  110. printk(KERN_ERR "PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx [%s%s%s%s%s]\n",
  111. addr, fsr, regs->ARM_pc, regs->ARM_lr,
  112. cmdstat & (PCI_STATUS_SIG_TARGET_ABORT << 16) ? "GenTarget" : " ",
  113. cmdstat & (PCI_STATUS_REC_TARGET_ABORT << 16) ? "RecvTarget" : " ",
  114. cmdstat & (PCI_STATUS_REC_MASTER_ABORT << 16) ? "MasterAbort" : " ",
  115. cmdstat & (PCI_STATUS_SIG_SYSTEM_ERROR << 16) ? "SysError" : " ",
  116. cmdstat & (PCI_STATUS_DETECTED_PARITY << 16) ? "Parity" : " "
  117. );
  118. __raw_writel(cmdstat, KS8695_PCI_VA + KS8695_CRCFCS);
  119. /*
  120. * If the instruction being executed was a read,
  121. * make it look like it read all-ones.
  122. */
  123. if ((instr & 0x0c100000) == 0x04100000) {
  124. int reg = (instr >> 12) & 15;
  125. unsigned long val;
  126. if (instr & 0x00400000)
  127. val = 255;
  128. else
  129. val = -1;
  130. regs->uregs[reg] = val;
  131. regs->ARM_pc += 4;
  132. return 0;
  133. }
  134. if ((instr & 0x0e100090) == 0x00100090) {
  135. int reg = (instr >> 12) & 15;
  136. regs->uregs[reg] = -1;
  137. regs->ARM_pc += 4;
  138. return 0;
  139. }
  140. return 1;
  141. }
  142. static void __init ks8695_pci_preinit(void)
  143. {
  144. /* make software reset to avoid freeze if PCI bus was messed up */
  145. __raw_writel(0x80000000, KS8695_PCI_VA + KS8695_PBCS);
  146. /* stage 1 initialization, subid, subdevice = 0x0001 */
  147. __raw_writel(0x00010001, KS8695_PCI_VA + KS8695_CRCSID);
  148. /* stage 2 initialization */
  149. /* prefetch limits with 16 words, retry enable */
  150. __raw_writel(0x40000000, KS8695_PCI_VA + KS8695_PBCS);
  151. /* configure memory mapping */
  152. __raw_writel(KS8695_PCIMEM_PA, KS8695_PCI_VA + KS8695_PMBA);
  153. __raw_writel(size_mask(KS8695_PCIMEM_SIZE), KS8695_PCI_VA + KS8695_PMBAM);
  154. __raw_writel(KS8695_PCIMEM_PA, KS8695_PCI_VA + KS8695_PMBAT);
  155. __raw_writel(0, KS8695_PCI_VA + KS8695_PMBAC);
  156. /* configure IO mapping */
  157. __raw_writel(KS8695_PCIIO_PA, KS8695_PCI_VA + KS8695_PIOBA);
  158. __raw_writel(size_mask(KS8695_PCIIO_SIZE), KS8695_PCI_VA + KS8695_PIOBAM);
  159. __raw_writel(KS8695_PCIIO_PA, KS8695_PCI_VA + KS8695_PIOBAT);
  160. __raw_writel(0, KS8695_PCI_VA + KS8695_PIOBAC);
  161. /* hook in fault handlers */
  162. hook_fault_code(8, ks8695_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
  163. hook_fault_code(10, ks8695_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
  164. }
  165. static void ks8695_show_pciregs(void)
  166. {
  167. if (!pci_dbg)
  168. return;
  169. printk(KERN_INFO "PCI: CRCFID = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFID));
  170. printk(KERN_INFO "PCI: CRCFCS = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFCS));
  171. printk(KERN_INFO "PCI: CRCFRV = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFRV));
  172. printk(KERN_INFO "PCI: CRCFLT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFLT));
  173. printk(KERN_INFO "PCI: CRCBMA = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCBMA));
  174. printk(KERN_INFO "PCI: CRCSID = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCSID));
  175. printk(KERN_INFO "PCI: CRCFIT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_CRCFIT));
  176. printk(KERN_INFO "PCI: PBM = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PBM));
  177. printk(KERN_INFO "PCI: PBCS = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PBCS));
  178. printk(KERN_INFO "PCI: PMBA = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBA));
  179. printk(KERN_INFO "PCI: PMBAC = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBAC));
  180. printk(KERN_INFO "PCI: PMBAM = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBAM));
  181. printk(KERN_INFO "PCI: PMBAT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PMBAT));
  182. printk(KERN_INFO "PCI: PIOBA = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBA));
  183. printk(KERN_INFO "PCI: PIOBAC = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBAC));
  184. printk(KERN_INFO "PCI: PIOBAM = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBAM));
  185. printk(KERN_INFO "PCI: PIOBAT = %08x\n", __raw_readl(KS8695_PCI_VA + KS8695_PIOBAT));
  186. }
  187. static struct hw_pci ks8695_pci __initdata = {
  188. .nr_controllers = 1,
  189. .ops = &ks8695_pci_ops,
  190. .preinit = ks8695_pci_preinit,
  191. .setup = ks8695_pci_setup,
  192. .postinit = NULL,
  193. .map_irq = NULL,
  194. };
  195. void __init ks8695_init_pci(struct ks8695_pci_cfg *cfg)
  196. {
  197. if (__raw_readl(KS8695_PCI_VA + KS8695_CRCFRV) & CFRV_GUEST) {
  198. printk("PCI: KS8695 in guest mode, not initialising\n");
  199. return;
  200. }
  201. pcibios_min_io = 0;
  202. pcibios_min_mem = 0;
  203. printk(KERN_INFO "PCI: Initialising\n");
  204. ks8695_show_pciregs();
  205. /* set Mode */
  206. __raw_writel(cfg->mode << 29, KS8695_PCI_VA + KS8695_PBM);
  207. ks8695_pci.map_irq = cfg->map_irq; /* board-specific map_irq method */
  208. pci_common_init(&ks8695_pci);
  209. }