dc21285.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * linux/arch/arm/kernel/dec21285.c: PCI functions for DC21285
  3. *
  4. * Copyright (C) 1998-2001 Russell King
  5. * Copyright (C) 1998-2000 Phil Blundell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/pci.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/mm.h>
  15. #include <linux/slab.h>
  16. #include <linux/init.h>
  17. #include <linux/ioport.h>
  18. #include <linux/irq.h>
  19. #include <linux/io.h>
  20. #include <linux/spinlock.h>
  21. #include <asm/irq.h>
  22. #include <asm/mach/pci.h>
  23. #include <asm/hardware/dec21285.h>
  24. #define MAX_SLOTS 21
  25. #define PCICMD_ABORT ((PCI_STATUS_REC_MASTER_ABORT| \
  26. PCI_STATUS_REC_TARGET_ABORT)<<16)
  27. #define PCICMD_ERROR_BITS ((PCI_STATUS_DETECTED_PARITY | \
  28. PCI_STATUS_REC_MASTER_ABORT | \
  29. PCI_STATUS_REC_TARGET_ABORT | \
  30. PCI_STATUS_PARITY) << 16)
  31. extern int setup_arm_irq(int, struct irqaction *);
  32. extern void pcibios_report_status(u_int status_mask, int warn);
  33. static unsigned long
  34. dc21285_base_address(struct pci_bus *bus, unsigned int devfn)
  35. {
  36. unsigned long addr = 0;
  37. if (bus->number == 0) {
  38. if (PCI_SLOT(devfn) == 0)
  39. /*
  40. * For devfn 0, point at the 21285
  41. */
  42. addr = ARMCSR_BASE;
  43. else {
  44. devfn -= 1 << 3;
  45. if (devfn < PCI_DEVFN(MAX_SLOTS, 0))
  46. addr = PCICFG0_BASE | 0xc00000 | (devfn << 8);
  47. }
  48. } else
  49. addr = PCICFG1_BASE | (bus->number << 16) | (devfn << 8);
  50. return addr;
  51. }
  52. static int
  53. dc21285_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  54. int size, u32 *value)
  55. {
  56. unsigned long addr = dc21285_base_address(bus, devfn);
  57. u32 v = 0xffffffff;
  58. if (addr)
  59. switch (size) {
  60. case 1:
  61. asm("ldrb %0, [%1, %2]"
  62. : "=r" (v) : "r" (addr), "r" (where) : "cc");
  63. break;
  64. case 2:
  65. asm("ldrh %0, [%1, %2]"
  66. : "=r" (v) : "r" (addr), "r" (where) : "cc");
  67. break;
  68. case 4:
  69. asm("ldr %0, [%1, %2]"
  70. : "=r" (v) : "r" (addr), "r" (where) : "cc");
  71. break;
  72. }
  73. *value = v;
  74. v = *CSR_PCICMD;
  75. if (v & PCICMD_ABORT) {
  76. *CSR_PCICMD = v & (0xffff|PCICMD_ABORT);
  77. return -1;
  78. }
  79. return PCIBIOS_SUCCESSFUL;
  80. }
  81. static int
  82. dc21285_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  83. int size, u32 value)
  84. {
  85. unsigned long addr = dc21285_base_address(bus, devfn);
  86. u32 v;
  87. if (addr)
  88. switch (size) {
  89. case 1:
  90. asm("strb %0, [%1, %2]"
  91. : : "r" (value), "r" (addr), "r" (where)
  92. : "cc");
  93. break;
  94. case 2:
  95. asm("strh %0, [%1, %2]"
  96. : : "r" (value), "r" (addr), "r" (where)
  97. : "cc");
  98. break;
  99. case 4:
  100. asm("str %0, [%1, %2]"
  101. : : "r" (value), "r" (addr), "r" (where)
  102. : "cc");
  103. break;
  104. }
  105. v = *CSR_PCICMD;
  106. if (v & PCICMD_ABORT) {
  107. *CSR_PCICMD = v & (0xffff|PCICMD_ABORT);
  108. return -1;
  109. }
  110. return PCIBIOS_SUCCESSFUL;
  111. }
  112. struct pci_ops dc21285_ops = {
  113. .read = dc21285_read_config,
  114. .write = dc21285_write_config,
  115. };
  116. static struct timer_list serr_timer;
  117. static struct timer_list perr_timer;
  118. static void dc21285_enable_error(struct timer_list *timer)
  119. {
  120. del_timer(timer);
  121. if (timer == &serr_timer)
  122. enable_irq(IRQ_PCI_SERR);
  123. else if (timer == &perr_timer)
  124. enable_irq(IRQ_PCI_PERR);
  125. }
  126. /*
  127. * Warn on PCI errors.
  128. */
  129. static irqreturn_t dc21285_abort_irq(int irq, void *dev_id)
  130. {
  131. unsigned int cmd;
  132. unsigned int status;
  133. cmd = *CSR_PCICMD;
  134. status = cmd >> 16;
  135. cmd = cmd & 0xffff;
  136. if (status & PCI_STATUS_REC_MASTER_ABORT) {
  137. printk(KERN_DEBUG "PCI: master abort, pc=0x%08lx\n",
  138. instruction_pointer(get_irq_regs()));
  139. cmd |= PCI_STATUS_REC_MASTER_ABORT << 16;
  140. }
  141. if (status & PCI_STATUS_REC_TARGET_ABORT) {
  142. printk(KERN_DEBUG "PCI: target abort: ");
  143. pcibios_report_status(PCI_STATUS_REC_MASTER_ABORT |
  144. PCI_STATUS_SIG_TARGET_ABORT |
  145. PCI_STATUS_REC_TARGET_ABORT, 1);
  146. printk("\n");
  147. cmd |= PCI_STATUS_REC_TARGET_ABORT << 16;
  148. }
  149. *CSR_PCICMD = cmd;
  150. return IRQ_HANDLED;
  151. }
  152. static irqreturn_t dc21285_serr_irq(int irq, void *dev_id)
  153. {
  154. struct timer_list *timer = dev_id;
  155. unsigned int cntl;
  156. printk(KERN_DEBUG "PCI: system error received: ");
  157. pcibios_report_status(PCI_STATUS_SIG_SYSTEM_ERROR, 1);
  158. printk("\n");
  159. cntl = *CSR_SA110_CNTL & 0xffffdf07;
  160. *CSR_SA110_CNTL = cntl | SA110_CNTL_RXSERR;
  161. /*
  162. * back off this interrupt
  163. */
  164. disable_irq(irq);
  165. timer->expires = jiffies + HZ;
  166. add_timer(timer);
  167. return IRQ_HANDLED;
  168. }
  169. static irqreturn_t dc21285_discard_irq(int irq, void *dev_id)
  170. {
  171. printk(KERN_DEBUG "PCI: discard timer expired\n");
  172. *CSR_SA110_CNTL &= 0xffffde07;
  173. return IRQ_HANDLED;
  174. }
  175. static irqreturn_t dc21285_dparity_irq(int irq, void *dev_id)
  176. {
  177. unsigned int cmd;
  178. printk(KERN_DEBUG "PCI: data parity error detected: ");
  179. pcibios_report_status(PCI_STATUS_PARITY | PCI_STATUS_DETECTED_PARITY, 1);
  180. printk("\n");
  181. cmd = *CSR_PCICMD & 0xffff;
  182. *CSR_PCICMD = cmd | 1 << 24;
  183. return IRQ_HANDLED;
  184. }
  185. static irqreturn_t dc21285_parity_irq(int irq, void *dev_id)
  186. {
  187. struct timer_list *timer = dev_id;
  188. unsigned int cmd;
  189. printk(KERN_DEBUG "PCI: parity error detected: ");
  190. pcibios_report_status(PCI_STATUS_PARITY | PCI_STATUS_DETECTED_PARITY, 1);
  191. printk("\n");
  192. cmd = *CSR_PCICMD & 0xffff;
  193. *CSR_PCICMD = cmd | 1 << 31;
  194. /*
  195. * back off this interrupt
  196. */
  197. disable_irq(irq);
  198. timer->expires = jiffies + HZ;
  199. add_timer(timer);
  200. return IRQ_HANDLED;
  201. }
  202. int __init dc21285_setup(int nr, struct pci_sys_data *sys)
  203. {
  204. struct resource *res;
  205. if (nr || !footbridge_cfn_mode())
  206. return 0;
  207. res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
  208. if (!res) {
  209. printk("out of memory for root bus resources");
  210. return 0;
  211. }
  212. res[0].flags = IORESOURCE_MEM;
  213. res[0].name = "Footbridge non-prefetch";
  214. res[1].flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  215. res[1].name = "Footbridge prefetch";
  216. allocate_resource(&iomem_resource, &res[1], 0x20000000,
  217. 0xa0000000, 0xffffffff, 0x20000000, NULL, NULL);
  218. allocate_resource(&iomem_resource, &res[0], 0x40000000,
  219. 0x80000000, 0xffffffff, 0x40000000, NULL, NULL);
  220. sys->mem_offset = DC21285_PCI_MEM;
  221. pci_add_resource_offset(&sys->resources, &res[0], sys->mem_offset);
  222. pci_add_resource_offset(&sys->resources, &res[1], sys->mem_offset);
  223. return 1;
  224. }
  225. #define dc21285_request_irq(_a, _b, _c, _d, _e) \
  226. WARN_ON(request_irq(_a, _b, _c, _d, _e) < 0)
  227. void __init dc21285_preinit(void)
  228. {
  229. unsigned int mem_size, mem_mask;
  230. int cfn_mode;
  231. pcibios_min_mem = 0x81000000;
  232. mem_size = (unsigned int)high_memory - PAGE_OFFSET;
  233. for (mem_mask = 0x00100000; mem_mask < 0x10000000; mem_mask <<= 1)
  234. if (mem_mask >= mem_size)
  235. break;
  236. /*
  237. * These registers need to be set up whether we're the
  238. * central function or not.
  239. */
  240. *CSR_SDRAMBASEMASK = (mem_mask - 1) & 0x0ffc0000;
  241. *CSR_SDRAMBASEOFFSET = 0;
  242. *CSR_ROMBASEMASK = 0x80000000;
  243. *CSR_CSRBASEMASK = 0;
  244. *CSR_CSRBASEOFFSET = 0;
  245. *CSR_PCIADDR_EXTN = 0;
  246. cfn_mode = __footbridge_cfn_mode();
  247. printk(KERN_INFO "PCI: DC21285 footbridge, revision %02lX, in "
  248. "%s mode\n", *CSR_CLASSREV & 0xff, cfn_mode ?
  249. "central function" : "addin");
  250. if (footbridge_cfn_mode()) {
  251. /*
  252. * Clear any existing errors - we aren't
  253. * interested in historical data...
  254. */
  255. *CSR_SA110_CNTL = (*CSR_SA110_CNTL & 0xffffde07) |
  256. SA110_CNTL_RXSERR;
  257. *CSR_PCICMD = (*CSR_PCICMD & 0xffff) | PCICMD_ERROR_BITS;
  258. }
  259. timer_setup(&serr_timer, dc21285_enable_error, 0);
  260. timer_setup(&perr_timer, dc21285_enable_error, 0);
  261. /*
  262. * We don't care if these fail.
  263. */
  264. dc21285_request_irq(IRQ_PCI_SERR, dc21285_serr_irq, 0,
  265. "PCI system error", &serr_timer);
  266. dc21285_request_irq(IRQ_PCI_PERR, dc21285_parity_irq, 0,
  267. "PCI parity error", &perr_timer);
  268. dc21285_request_irq(IRQ_PCI_ABORT, dc21285_abort_irq, 0,
  269. "PCI abort", NULL);
  270. dc21285_request_irq(IRQ_DISCARD_TIMER, dc21285_discard_irq, 0,
  271. "Discard timer", NULL);
  272. dc21285_request_irq(IRQ_PCI_DPERR, dc21285_dparity_irq, 0,
  273. "PCI data parity", NULL);
  274. if (cfn_mode) {
  275. /*
  276. * Map our SDRAM at a known address in PCI space, just in case
  277. * the firmware had other ideas. Using a nonzero base is
  278. * necessary, since some VGA cards forcefully use PCI addresses
  279. * in the range 0x000a0000 to 0x000c0000. (eg, S3 cards).
  280. */
  281. *CSR_PCICSRBASE = 0xf4000000;
  282. *CSR_PCICSRIOBASE = 0;
  283. *CSR_PCISDRAMBASE = __virt_to_bus(PAGE_OFFSET);
  284. *CSR_PCIROMBASE = 0;
  285. *CSR_PCICMD = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  286. PCI_COMMAND_INVALIDATE | PCICMD_ERROR_BITS;
  287. } else if (footbridge_cfn_mode() != 0) {
  288. /*
  289. * If we are not compiled to accept "add-in" mode, then
  290. * we are using a constant virt_to_bus translation which
  291. * can not hope to cater for the way the host BIOS has
  292. * set up the machine.
  293. */
  294. panic("PCI: this kernel is compiled for central "
  295. "function mode only");
  296. }
  297. }
  298. void __init dc21285_postinit(void)
  299. {
  300. register_isa_ports(DC21285_PCI_MEM, DC21285_PCI_IO, 0);
  301. }