dc21285.c 8.5 KB

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