ops-nile4.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include <linux/kernel.h>
  2. #include <linux/pci.h>
  3. #include <asm/bootinfo.h>
  4. #include <asm/lasat/lasat.h>
  5. #include <asm/nile4.h>
  6. #define PCI_ACCESS_READ 0
  7. #define PCI_ACCESS_WRITE 1
  8. #define LO(reg) (reg / 4)
  9. #define HI(reg) (reg / 4 + 1)
  10. volatile unsigned long *const vrc_pciregs = (void *) Vrc5074_BASE;
  11. static int nile4_pcibios_config_access(unsigned char access_type,
  12. struct pci_bus *bus, unsigned int devfn, int where, u32 *val)
  13. {
  14. unsigned char busnum = bus->number;
  15. u32 adr, mask, err;
  16. if ((busnum == 0) && (PCI_SLOT(devfn) > 8))
  17. /* The addressing scheme chosen leaves room for just
  18. * 8 devices on the first busnum (besides the PCI
  19. * controller itself) */
  20. return PCIBIOS_DEVICE_NOT_FOUND;
  21. if ((busnum == 0) && (devfn == PCI_DEVFN(0, 0))) {
  22. /* Access controller registers directly */
  23. if (access_type == PCI_ACCESS_WRITE) {
  24. vrc_pciregs[(0x200 + where) >> 2] = *val;
  25. } else {
  26. *val = vrc_pciregs[(0x200 + where) >> 2];
  27. }
  28. return PCIBIOS_SUCCESSFUL;
  29. }
  30. /* Temporarily map PCI Window 1 to config space */
  31. mask = vrc_pciregs[LO(NILE4_PCIINIT1)];
  32. vrc_pciregs[LO(NILE4_PCIINIT1)] = 0x0000001a | (busnum ? 0x200 : 0);
  33. /* Clear PCI Error register. This also clears the Error Type
  34. * bits in the Control register */
  35. vrc_pciregs[LO(NILE4_PCIERR)] = 0;
  36. vrc_pciregs[HI(NILE4_PCIERR)] = 0;
  37. /* Setup address */
  38. if (busnum == 0)
  39. adr =
  40. KSEG1ADDR(PCI_WINDOW1) +
  41. ((1 << (PCI_SLOT(devfn) + 15)) | (PCI_FUNC(devfn) << 8)
  42. | (where & ~3));
  43. else
  44. adr = KSEG1ADDR(PCI_WINDOW1) | (busnum << 16) | (devfn << 8) |
  45. (where & ~3);
  46. if (access_type == PCI_ACCESS_WRITE)
  47. *(u32 *) adr = *val;
  48. else
  49. *val = *(u32 *) adr;
  50. /* Check for master or target abort */
  51. err = (vrc_pciregs[HI(NILE4_PCICTRL)] >> 5) & 0x7;
  52. /* Restore PCI Window 1 */
  53. vrc_pciregs[LO(NILE4_PCIINIT1)] = mask;
  54. if (err)
  55. return PCIBIOS_DEVICE_NOT_FOUND;
  56. return PCIBIOS_SUCCESSFUL;
  57. }
  58. static int nile4_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  59. int where, int size, u32 *val)
  60. {
  61. u32 data = 0;
  62. int err;
  63. if ((size == 2) && (where & 1))
  64. return PCIBIOS_BAD_REGISTER_NUMBER;
  65. else if ((size == 4) && (where & 3))
  66. return PCIBIOS_BAD_REGISTER_NUMBER;
  67. err = nile4_pcibios_config_access(PCI_ACCESS_READ, bus, devfn, where,
  68. &data);
  69. if (err)
  70. return err;
  71. if (size == 1)
  72. *val = (data >> ((where & 3) << 3)) & 0xff;
  73. else if (size == 2)
  74. *val = (data >> ((where & 3) << 3)) & 0xffff;
  75. else
  76. *val = data;
  77. return PCIBIOS_SUCCESSFUL;
  78. }
  79. static int nile4_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  80. int where, int size, u32 val)
  81. {
  82. u32 data = 0;
  83. int err;
  84. if ((size == 2) && (where & 1))
  85. return PCIBIOS_BAD_REGISTER_NUMBER;
  86. else if ((size == 4) && (where & 3))
  87. return PCIBIOS_BAD_REGISTER_NUMBER;
  88. err = nile4_pcibios_config_access(PCI_ACCESS_READ, bus, devfn, where,
  89. &data);
  90. if (err)
  91. return err;
  92. if (size == 1)
  93. data = (data & ~(0xff << ((where & 3) << 3))) |
  94. (val << ((where & 3) << 3));
  95. else if (size == 2)
  96. data = (data & ~(0xffff << ((where & 3) << 3))) |
  97. (val << ((where & 3) << 3));
  98. else
  99. data = val;
  100. if (nile4_pcibios_config_access
  101. (PCI_ACCESS_WRITE, bus, devfn, where, &data))
  102. return -1;
  103. return PCIBIOS_SUCCESSFUL;
  104. }
  105. struct pci_ops nile4_pci_ops = {
  106. .read = nile4_pcibios_read,
  107. .write = nile4_pcibios_write,
  108. };