ops-nile4.c 3.3 KB

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