ops-ifxmips.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <linux/types.h>
  2. #include <linux/pci.h>
  3. #include <linux/kernel.h>
  4. #include <linux/init.h>
  5. #include <linux/delay.h>
  6. #include <linux/mm.h>
  7. #include <asm/addrspace.h>
  8. #include <linux/vmalloc.h>
  9. #include <ifxmips.h>
  10. #include <ifxmips_irq.h>
  11. #include <ifxmips_ebu.h>
  12. #define IFXMIPS_PCI_CFG_BUSNUM_SHF 16
  13. #define IFXMIPS_PCI_CFG_DEVNUM_SHF 11
  14. #define IFXMIPS_PCI_CFG_FUNNUM_SHF 8
  15. #define PCI_ACCESS_READ 0
  16. #define PCI_ACCESS_WRITE 1
  17. extern u32 ifxmips_pci_mapped_cfg;
  18. static int
  19. ifxmips_pci_config_access(unsigned char access_type,
  20. struct pci_bus *bus, unsigned int devfn, unsigned int where, u32 *data)
  21. {
  22. unsigned long cfg_base;
  23. unsigned long flags;
  24. u32 temp;
  25. /* IFXMips support slot from 0 to 15 */
  26. /* dev_fn 0&0x68 (AD29) is ifxmips itself */
  27. if ((bus->number != 0) || ((devfn & 0xf8) > 0x78)
  28. || ((devfn & 0xf8) == 0) || ((devfn & 0xf8) == 0x68))
  29. return 1;
  30. spin_lock_irqsave(&ebu_lock, flags);
  31. cfg_base = ifxmips_pci_mapped_cfg;
  32. cfg_base |= (bus->number << IFXMIPS_PCI_CFG_BUSNUM_SHF) | (devfn <<
  33. IFXMIPS_PCI_CFG_FUNNUM_SHF) | (where & ~0x3);
  34. /* Perform access */
  35. if (access_type == PCI_ACCESS_WRITE)
  36. {
  37. #ifdef CONFIG_SWAP_IO_SPACE
  38. ifxmips_w32(swab32(*data), ((u32*)cfg_base));
  39. #else
  40. ifxmips_w32(*data, ((u32*)cfg_base));
  41. #endif
  42. } else {
  43. *data = ifxmips_r32(((u32*)(cfg_base)));
  44. #ifdef CONFIG_SWAP_IO_SPACE
  45. *data = swab32(*data);
  46. #endif
  47. }
  48. wmb();
  49. /* clean possible Master abort */
  50. cfg_base = (ifxmips_pci_mapped_cfg | (0x0 << IFXMIPS_PCI_CFG_FUNNUM_SHF)) + 4;
  51. temp = ifxmips_r32(((u32*)(cfg_base)));
  52. #ifdef CONFIG_SWAP_IO_SPACE
  53. temp = swab32 (temp);
  54. #endif
  55. cfg_base = (ifxmips_pci_mapped_cfg | (0x68 << IFXMIPS_PCI_CFG_FUNNUM_SHF)) + 4;
  56. ifxmips_w32(temp, ((u32*)cfg_base));
  57. spin_unlock_irqrestore(&ebu_lock, flags);
  58. if (((*data) == 0xffffffff) && (access_type == PCI_ACCESS_READ))
  59. return 1;
  60. return 0;
  61. }
  62. int
  63. ifxmips_pci_read_config_dword(struct pci_bus *bus, unsigned int devfn,
  64. int where, int size, u32 * val)
  65. {
  66. u32 data = 0;
  67. if (ifxmips_pci_config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
  68. return PCIBIOS_DEVICE_NOT_FOUND;
  69. if (size == 1)
  70. *val = (data >> ((where & 3) << 3)) & 0xff;
  71. else if (size == 2)
  72. *val = (data >> ((where & 3) << 3)) & 0xffff;
  73. else
  74. *val = data;
  75. return PCIBIOS_SUCCESSFUL;
  76. }
  77. int
  78. ifxmips_pci_write_config_dword(struct pci_bus *bus, unsigned int devfn,
  79. int where, int size, u32 val)
  80. {
  81. u32 data = 0;
  82. if (size == 4)
  83. {
  84. data = val;
  85. } else {
  86. if (ifxmips_pci_config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
  87. return PCIBIOS_DEVICE_NOT_FOUND;
  88. if (size == 1)
  89. data = (data & ~(0xff << ((where & 3) << 3))) |
  90. (val << ((where & 3) << 3));
  91. else if (size == 2)
  92. data = (data & ~(0xffff << ((where & 3) << 3))) |
  93. (val << ((where & 3) << 3));
  94. }
  95. if (ifxmips_pci_config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
  96. return PCIBIOS_DEVICE_NOT_FOUND;
  97. return PCIBIOS_SUCCESSFUL;
  98. }