apus_pci.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (C) Michel Dänzer <michdaen@iiic.ethz.ch>
  3. *
  4. * APUS PCI routines.
  5. *
  6. * Currently, only B/CVisionPPC cards (Permedia2) are supported.
  7. *
  8. * Thanks to Geert Uytterhoeven for the idea:
  9. * Read values from given config space(s) for the first devices, -1 otherwise
  10. *
  11. */
  12. #ifdef CONFIG_AMIGA
  13. #include <linux/kernel.h>
  14. #include <linux/pci.h>
  15. #include <linux/delay.h>
  16. #include <linux/string.h>
  17. #include <linux/init.h>
  18. #include <asm/io.h>
  19. #include <asm/pci-bridge.h>
  20. #include <asm/machdep.h>
  21. #include "apus_pci.h"
  22. /* These definitions are mostly adapted from pm2fb.c */
  23. #undef APUS_PCI_MASTER_DEBUG
  24. #ifdef APUS_PCI_MASTER_DEBUG
  25. #define DPRINTK(a,b...) printk(KERN_DEBUG "apus_pci: %s: " a, __FUNCTION__ , ## b)
  26. #else
  27. #define DPRINTK(a,b...)
  28. #endif
  29. /*
  30. * The _DEFINITIVE_ memory mapping/unmapping functions.
  31. * This is due to the fact that they're changing soooo often...
  32. */
  33. #define DEFW() wmb()
  34. #define DEFR() rmb()
  35. #define DEFRW() mb()
  36. #define DEVNO(d) ((d)>>3)
  37. #define FNNO(d) ((d)&7)
  38. extern unsigned long powerup_PCI_present;
  39. static struct pci_controller *apus_hose;
  40. void *pci_io_base(unsigned int bus)
  41. {
  42. return 0;
  43. }
  44. int
  45. apus_pcibios_read_config(struct pci_bus *bus, int devfn, int offset,
  46. int len, u32 *val)
  47. {
  48. int fnno = FNNO(devfn);
  49. int devno = DEVNO(devfn);
  50. volatile unsigned char *cfg_data;
  51. if (bus->number > 0 || devno != 1) {
  52. *val = ~0;
  53. return PCIBIOS_DEVICE_NOT_FOUND;
  54. }
  55. /* base address + function offset + offset ^ endianness conversion */
  56. /* XXX the fnno<<5 bit seems wacky -- paulus */
  57. cfg_data = apus_hose->cfg_data + (fnno<<5) + (offset ^ (len - 1));
  58. switch (len) {
  59. case 1:
  60. *val = readb(cfg_data);
  61. break;
  62. case 2:
  63. *val = readw(cfg_data);
  64. break;
  65. default:
  66. *val = readl(cfg_data);
  67. break;
  68. }
  69. DPRINTK("read b: 0x%x, d: 0x%x, f: 0x%x, o: 0x%x, l: %d, v: 0x%x\n",
  70. bus->number, devfn>>3, devfn&7, offset, len, *val);
  71. return PCIBIOS_SUCCESSFUL;
  72. }
  73. int
  74. apus_pcibios_write_config(struct pci_bus *bus, int devfn, int offset,
  75. int len, u32 *val)
  76. {
  77. int fnno = FNNO(devfn);
  78. int devno = DEVNO(devfn);
  79. volatile unsigned char *cfg_data;
  80. if (bus->number > 0 || devno != 1) {
  81. return PCIBIOS_DEVICE_NOT_FOUND;
  82. }
  83. /* base address + function offset + offset ^ endianness conversion */
  84. /* XXX the fnno<<5 bit seems wacky -- paulus */
  85. cfg_data = apus_hose->cfg_data + (fnno<<5) + (offset ^ (len - 1));
  86. switch (len) {
  87. case 1:
  88. writeb(val, cfg_data); DEFW();
  89. break;
  90. case 2:
  91. writew(val, cfg_data); DEFW();
  92. break;
  93. default:
  94. writel(val, cfg_data); DEFW();
  95. break;
  96. }
  97. DPRINTK("write b: 0x%x, d: 0x%x, f: 0x%x, o: 0x%x, l: %d, v: 0x%x\n",
  98. bus->number, devfn>>3, devfn&7, offset, len, val);
  99. return PCIBIOS_SUCCESSFUL;
  100. }
  101. static struct pci_ops apus_pci_ops = {
  102. apus_pcibios_read_config,
  103. apus_pcibios_write_config
  104. };
  105. static struct resource pci_mem = { "B/CVisionPPC PCI mem", CVPPC_FB_APERTURE_ONE, CVPPC_PCI_CONFIG, IORESOURCE_MEM };
  106. void __init
  107. apus_pcibios_fixup(void)
  108. {
  109. /* struct pci_dev *dev = pci_find_slot(0, 1<<3);
  110. unsigned int reg, val, offset;*/
  111. /* FIXME: interrupt? */
  112. /*dev->interrupt = xxx;*/
  113. request_resource(&iomem_resource, &pci_mem);
  114. printk("%s: PCI mem resource requested\n", __FUNCTION__);
  115. }
  116. static void __init apus_pcibios_fixup_bus(struct pci_bus *bus)
  117. {
  118. bus->resource[1] = &pci_mem;
  119. }
  120. /*
  121. * This is from pm2fb.c again
  122. *
  123. * Check if PCI (B/CVisionPPC) is available, initialize it and set up
  124. * the pcibios_* pointers
  125. */
  126. void __init
  127. apus_setup_pci_ptrs(void)
  128. {
  129. if (!powerup_PCI_present) {
  130. DPRINTK("no PCI bridge detected\n");
  131. return;
  132. }
  133. DPRINTK("Phase5 B/CVisionPPC PCI bridge detected.\n");
  134. apus_hose = pcibios_alloc_controller();
  135. if (!apus_hose) {
  136. printk("apus_pci: Can't allocate PCI controller structure\n");
  137. return;
  138. }
  139. if (!(apus_hose->cfg_data = ioremap(CVPPC_PCI_CONFIG, 256))) {
  140. printk("apus_pci: unable to map PCI config region\n");
  141. return;
  142. }
  143. if (!(apus_hose->cfg_addr = ioremap(CSPPC_PCI_BRIDGE, 256))) {
  144. printk("apus_pci: unable to map PCI bridge\n");
  145. return;
  146. }
  147. writel(CSPPCF_BRIDGE_BIG_ENDIAN, apus_hose->cfg_addr + CSPPC_BRIDGE_ENDIAN);
  148. DEFW();
  149. writel(CVPPC_REGS_REGION, apus_hose->cfg_data+ PCI_BASE_ADDRESS_0);
  150. DEFW();
  151. writel(CVPPC_FB_APERTURE_ONE, apus_hose->cfg_data + PCI_BASE_ADDRESS_1);
  152. DEFW();
  153. writel(CVPPC_FB_APERTURE_TWO, apus_hose->cfg_data + PCI_BASE_ADDRESS_2);
  154. DEFW();
  155. writel(CVPPC_ROM_ADDRESS, apus_hose->cfg_data + PCI_ROM_ADDRESS);
  156. DEFW();
  157. writel(0xef000000 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
  158. PCI_COMMAND_MASTER, apus_hose->cfg_data + PCI_COMMAND);
  159. DEFW();
  160. apus_hose->first_busno = 0;
  161. apus_hose->last_busno = 0;
  162. apus_hose->ops = &apus_pci_ops;
  163. ppc_md.pcibios_fixup = apus_pcibios_fixup;
  164. ppc_md.pcibios_fixup_bus = apus_pcibios_fixup_bus;
  165. return;
  166. }
  167. #endif /* CONFIG_AMIGA */