ops-loongson3.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <linux/types.h>
  2. #include <linux/pci.h>
  3. #include <linux/kernel.h>
  4. #include <asm/mips-boards/bonito64.h>
  5. #include <loongson.h>
  6. #define PCI_ACCESS_READ 0
  7. #define PCI_ACCESS_WRITE 1
  8. #define HT1LO_PCICFG_BASE 0x1a000000
  9. #define HT1LO_PCICFG_BASE_TP1 0x1b000000
  10. static int loongson3_pci_config_access(unsigned char access_type,
  11. struct pci_bus *bus, unsigned int devfn,
  12. int where, u32 *data)
  13. {
  14. unsigned char busnum = bus->number;
  15. u_int64_t addr, type;
  16. void *addrp;
  17. int device = PCI_SLOT(devfn);
  18. int function = PCI_FUNC(devfn);
  19. int reg = where & ~3;
  20. addr = (busnum << 16) | (device << 11) | (function << 8) | reg;
  21. if (busnum == 0) {
  22. if (device > 31)
  23. return PCIBIOS_DEVICE_NOT_FOUND;
  24. addrp = (void *)(TO_UNCAC(HT1LO_PCICFG_BASE) | (addr & 0xffff));
  25. type = 0;
  26. } else {
  27. addrp = (void *)(TO_UNCAC(HT1LO_PCICFG_BASE_TP1) | (addr));
  28. type = 0x10000;
  29. }
  30. if (access_type == PCI_ACCESS_WRITE)
  31. writel(*data, addrp);
  32. else {
  33. *data = readl(addrp);
  34. if (*data == 0xffffffff) {
  35. *data = -1;
  36. return PCIBIOS_DEVICE_NOT_FOUND;
  37. }
  38. }
  39. return PCIBIOS_SUCCESSFUL;
  40. }
  41. static int loongson3_pci_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  42. int where, int size, u32 *val)
  43. {
  44. u32 data = 0;
  45. int ret = loongson3_pci_config_access(PCI_ACCESS_READ,
  46. bus, devfn, where, &data);
  47. if (ret != PCIBIOS_SUCCESSFUL)
  48. return ret;
  49. if (size == 1)
  50. *val = (data >> ((where & 3) << 3)) & 0xff;
  51. else if (size == 2)
  52. *val = (data >> ((where & 3) << 3)) & 0xffff;
  53. else
  54. *val = data;
  55. return PCIBIOS_SUCCESSFUL;
  56. }
  57. static int loongson3_pci_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  58. int where, int size, u32 val)
  59. {
  60. u32 data = 0;
  61. int ret;
  62. if (size == 4)
  63. data = val;
  64. else {
  65. ret = loongson3_pci_config_access(PCI_ACCESS_READ,
  66. bus, devfn, where, &data);
  67. if (ret != PCIBIOS_SUCCESSFUL)
  68. return ret;
  69. if (size == 1)
  70. data = (data & ~(0xff << ((where & 3) << 3))) |
  71. (val << ((where & 3) << 3));
  72. else if (size == 2)
  73. data = (data & ~(0xffff << ((where & 3) << 3))) |
  74. (val << ((where & 3) << 3));
  75. }
  76. ret = loongson3_pci_config_access(PCI_ACCESS_WRITE,
  77. bus, devfn, where, &data);
  78. return ret;
  79. }
  80. struct pci_ops loongson_pci_ops = {
  81. .read = loongson3_pci_pcibios_read,
  82. .write = loongson3_pci_pcibios_write
  83. };