dc21285.c 9.3 KB

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