indirect_pci.c 4.2 KB

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