apus_pci.c 4.7 KB

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