dataMonitoring.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 <mach/devices.h>
  34. #include <mach/regs-pci.h>
  35. static int pci_dbg;
  36. static int pci_cfg_dbg;
  37. static void ks8695_pci_setupconfig(unsigned int bus_nr, unsigned int devfn, unsigned int where)
  38. {
  39. unsigned long pbca;
  40. pbca = PBCA_ENABLE | (where & ~3);
  41. pbca |= PCI_SLOT(devfn) << 11 ;
  42. pbca |= PCI_FUNC(devfn) << 8;
  43. pbca |= bus_nr << 16;
  44. if (bus_nr == 0) {
  45. /* use Type-0 transaction */
  46. __raw_writel(pbca, KS8695_PCI_VA + KS8695_PBCA);
  47. } else {
  48. /* use Type-1 transaction */
  49. __raw_writel(pbca | PBCA_TYPE1, KS8695_PCI_VA + KS8695_PBCA);
  50. }
  51. }
  52. /*
  53. * The KS8695 datasheet prohibits anything other than 32bit accesses
  54. * to the IO registers, so all our configuration must be done with
  55. * 32bit operations, and the correct bit masking and shifting.
  56. */
  57. static int ks8695_pci_readconfig(struct pci_bus *bus,
  58. unsigned int devfn, int where, int size, u32 *value)
  59. {
  60. ks8695_pci_setupconfig(bus->number, devfn, where);
  61. *value = __raw_readl(KS8695_PCI_VA + KS8695_PBCD);
  62. switch (size) {
  63. case 4:
  64. break;
  65. case 2:
  66. *value = *value >> ((where & 2) * 8);
  67. *value &= 0xffff;
  68. break;
  69. case 1:
  70. *value = *value >> ((where & 3) * 8);
  71. *value &= 0xff;
  72. break;
  73. }
  74. if (pci_cfg_dbg) {
  75. printk("read: %d,%08x,%02x,%d: %08x (%08x)\n",
  76. bus->number, devfn, where, size, *value,
  77. __raw_readl(KS8695_PCI_VA + KS8695_PBCD));
  78. }
  79. return PCIBIOS_SUCCESSFUL;
  80. }
  81. static int ks8695_pci_writeconfig(struct pci_bus *bus,
  82. unsigned int devfn, int where, int size, u32 value)
  83. {
  84. unsigned long tmp;
  85. if (pci_cfg_dbg) {
  86. printk("write: %d,%08x,%02x,%d: %08x\n",
  87. bus->number, devfn, where, size, value);
  88. }
  89. ks8695_pci_setupconfig(bus->number, devfn, where);
  90. switch (size) {
  91. case 4:
  92. __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
  93. break;
  94. case 2:
  95. tmp = __raw_readl(KS8695_PCI_VA + KS8695_PBCD);
  96. tmp &= ~(0xffff << ((where & 2) * 8));
  97. tmp |= value << ((where & 2) * 8);
  98. __raw_writel(tmp, KS8695_PCI_VA + KS8695_PBCD);
  99. break;
  100. case 1:
  101. tmp = __raw_readl(KS8695_PCI_VA + KS8695_PBCD);
  102. tmp &= ~(0xff << ((where & 3) * 8));
  103. tmp |= value << ((where & 3) * 8);
  104. __raw_writel(tmp, KS8695_PCI_VA + KS8695_PBCD);
  105. break;
  106. }
  107. return PCIBIOS_SUCCESSFUL;
  108. }
  109. static void ks8695_local_writeconfig(int where, u32 value)
  110. {
  111. ks8695_pci_setupconfig(0, 0, where);
  112. __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
  113. }
  114. static struct pci_ops ks8695_pci_ops = {
  115. .read = ks8695_pci_readconfig,
  116. .write = ks8695_pci_writeconfig,
  117. };
  118. static struct resource pci_mem = {
  119. .name = "PCI Memory space",
  120. .start = KS8695_PCIMEM_PA,
  121. .end = KS8695_PCIMEM_PA + (KS8695_PCIMEM_SIZE - 1),
  122. .flags = IORESOURCE_MEM,
  123. };
  124. static struct resource pci_io = {
  125. .name = "PCI IO space",
  126. .start = KS8695_PCIIO_PA,
  127. .end = KS8695_PCIIO_PA + (KS8695_PCIIO_SIZE - 1),
  128. .flags = IORESOURCE_IO,
  129. };
  130. static int __init ks8695_pci_setup(int nr, struct pci_sys_data *sys)
  131. {
  132. if (nr > 0)
  133. return 0;
  134. request_resource(&iomem_resource, &pci_mem);
  135. request_resource(&ioport_resource, &pci_io);
  136. pci_add_resource_offset(&sys->resources, &pci_io, sys->io_offset);
  137. pci_add_resource_offset(&sys->resources, &pci_mem, sys->mem_offset);
  138. /* Assign and enable processor bridge */
  139. ks8695_local_writeconfig(PCI_BASE_ADDRESS_0, KS8695_PCIMEM_PA);
  140. /* Enable bus-master & Memory Space access */
  141. ks8695_local_writeconfig(PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  142. /* Set cache-line size & latency. */
  143. ks8695_local_writeconfig(PCI_CACHE_LINE_SIZE, (32 << 8) | (L1_CACHE_BYTES / sizeof(u32)));
  144. /* Reserve PCI memory space for PCI-AHB resources */
  145. if (!request_mem_region(KS8695_PCIMEM_PA, SZ_64M, "PCI-AHB Bridge")) {
  146. printk(KERN_ERR "Cannot allocate PCI-AHB Bridge memory.\n");
  147. return -EBUSY;
  148. }
  149. return 1;
  150. }
  151. static inline unsigned int size_mask(unsigned long size)
  152. {
  153. return (~size) + 1;
  154. }
  155. static int ks8695_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  156. {
  157. unsigned long pc = instruction_pointer(regs);
  158. unsigned long instr = *(unsigned long *)pc;
  159. unsigned long cmdstat;
  160. cmdstat = __raw_readl(KS8695_PCI_VA + KS8695_CRCFCS);
  161. printk(KERN_ERR "PCI abort: address = 0x%08lx fsr = 0x%03x PC = 0x%08lx LR = 0x%08lx [%s%s%s%s%s]\n",
  162. addr, fsr, regs->ARM_pc, regs->ARM_lr,
  163. cmdstat & (PCI_STATUS_SIG_TARGET_ABORT << 16) ? "GenTarget" : " ",
  164. cmdstat & (PCI_STATUS_REC_TARGET_ABORT << 16) ? "RecvTarget" : " ",
  165. cmdstat & (PCI_STATUS_REC_MASTER_ABORT << 16) ? "MasterAbort" : " ",