apus_pci.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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