indirect_pci.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Support for indirect PCI bridges.
  3. *
  4. * Copyright (C) 1998 Gabriel Paubert.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/pci.h>
  13. #include <linux/delay.h>
  14. #include <linux/string.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <asm/pci-bridge.h>
  18. static int
  19. indirect_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  20. int len, u32 *val)
  21. {
  22. struct pci_controller *hose = pci_bus_to_host(bus);
  23. volatile void __iomem *cfg_data;
  24. u8 cfg_type = 0;
  25. u32 bus_no, reg;
  26. if (hose->indirect_type & INDIRECT_TYPE_NO_PCIE_LINK) {
  27. if (bus->number != hose->first_busno)
  28. return PCIBIOS_DEVICE_NOT_FOUND;
  29. if (devfn != 0)
  30. return PCIBIOS_DEVICE_NOT_FOUND;
  31. }
  32. if (hose->indirect_type & INDIRECT_TYPE_SET_CFG_TYPE)
  33. if (bus->number != hose->first_busno)
  34. cfg_type = 1;
  35. bus_no = (bus->number == hose->first_busno) ?
  36. hose->self_busno : bus->number;
  37. if (hose->indirect_type & INDIRECT_TYPE_EXT_REG)
  38. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  39. else
  40. reg = offset & 0xfc; /* Only 3 bits for function */
  41. if (hose->indirect_type & INDIRECT_TYPE_BIG_ENDIAN)
  42. out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  43. (devfn << 8) | reg | cfg_type));
  44. else
  45. out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  46. (devfn << 8) | reg | cfg_type));
  47. /*
  48. * Note: the caller has already checked that offset is
  49. * suitably aligned and that len is 1, 2 or 4.
  50. */
  51. cfg_data = hose->cfg_data + (offset & 3); /* Only 3 bits for function */
  52. switch (len) {
  53. case 1:
  54. *val = in_8(cfg_data);
  55. break;
  56. case 2:
  57. *val = in_le16(cfg_data);
  58. break;
  59. default:
  60. *val = in_le32(cfg_data);
  61. break;
  62. }
  63. return PCIBIOS_SUCCESSFUL;
  64. }
  65. static int
  66. indirect_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  67. int len, u32 val)
  68. {
  69. struct pci_controller *hose = pci_bus_to_host(bus);
  70. volatile void __iomem *cfg_data;
  71. u8 cfg_type = 0;
  72. u32 bus_no, reg;
  73. if (hose->indirect_type & INDIRECT_TYPE_NO_PCIE_LINK) {
  74. if (bus->number != hose->first_busno)
  75. return PCIBIOS_DEVICE_NOT_FOUND;
  76. if (devfn != 0)
  77. return PCIBIOS_DEVICE_NOT_FOUND;
  78. }
  79. if (hose->indirect_type & INDIRECT_TYPE_SET_CFG_TYPE)
  80. if (bus->number != hose->first_busno)
  81. cfg_type = 1;
  82. bus_no = (bus->number == hose->first_busno) ?
  83. hose->self_busno : bus->number;
  84. if (hose->indirect_type & INDIRECT_TYPE_EXT_REG)
  85. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  86. else
  87. reg = offset & 0xfc;
  88. if (hose->indirect_type & INDIRECT_TYPE_BIG_ENDIAN)
  89. out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  90. (devfn << 8) | reg | cfg_type));
  91. else
  92. out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
  93. (devfn << 8) | reg | cfg_type));
  94. /* suppress setting of PCI_PRIMARY_BUS */
  95. if (hose->indirect_type & INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
  96. if ((offset == PCI_PRIMARY_BUS) &&
  97. (bus->number == hose->first_busno))
  98. val &= 0xffffff00;
  99. /* Workaround for PCI_28 Errata in 440EPx/GRx */
  100. if ((hose->indirect_type & INDIRECT_TYPE_BROKEN_MRM) &&
  101. offset == PCI_CACHE_LINE_SIZE) {
  102. val = 0;
  103. }
  104. /*
  105. * Note: the caller has already checked that offset is
  106. * suitably aligned and that len is 1, 2 or 4.
  107. */
  108. cfg_data = hose->cfg_data + (offset & 3);
  109. switch (len) {
  110. case 1:
  111. out_8(cfg_data, val);
  112. break;
  113. case 2:
  114. out_le16(cfg_data, val);
  115. break;
  116. default:
  117. out_le32(cfg_data, val);
  118. break;
  119. }
  120. return PCIBIOS_SUCCESSFUL;
  121. }
  122. static struct pci_ops indirect_pci_ops = {
  123. .read = indirect_read_config,
  124. .write = indirect_write_config,
  125. };
  126. void __init
  127. setup_indirect_pci(struct pci_controller *hose,
  128. resource_size_t cfg_addr,
  129. resource_size_t cfg_data, u32 flags)
  130. {
  131. resource_size_t base = cfg_addr & PAGE_MASK;
  132. void __iomem *mbase;
  133. mbase = ioremap(base, PAGE_SIZE);
  134. hose->cfg_addr = mbase + (cfg_addr & ~PAGE_MASK);
  135. if ((cfg_data & PAGE_MASK) != base)
  136. mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
  137. hose->cfg_data = mbase + (cfg_data & ~PAGE_MASK);
  138. hose->ops = &indirect_pci_ops;
  139. hose->indirect_type = flags;
  140. }