indirect_pci.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <asm/io.h>
  17. #include <asm/prom.h>
  18. #include <asm/pci-bridge.h>
  19. #include <asm/machdep.h>
  20. #ifdef CONFIG_PPC_INDIRECT_PCI_BE
  21. #define PCI_CFG_OUT out_be32
  22. #else
  23. #define PCI_CFG_OUT out_le32
  24. #endif
  25. static int
  26. indirect_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  27. int len, u32 *val)
  28. {
  29. struct pci_controller *hose = bus->sysdata;
  30. volatile void __iomem *cfg_data;
  31. u8 cfg_type = 0;
  32. u32 bus_no, reg;
  33. if (ppc_md.pci_exclude_device)
  34. if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
  35. return PCIBIOS_DEVICE_NOT_FOUND;
  36. if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
  37. if (bus->number != hose->first_busno)
  38. cfg_type = 1;
  39. bus_no = (bus->number == hose->first_busno) ?
  40. hose->self_busno : bus->number;
  41. if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
  42. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  43. else
  44. reg = offset & 0xfc;
  45. PCI_CFG_OUT(hose->cfg_addr,
  46. (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);
  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 = bus->sysdata;
  71. volatile void __iomem *cfg_data;
  72. u8 cfg_type = 0;
  73. u32 bus_no, reg;
  74. if (ppc_md.pci_exclude_device)
  75. if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
  76. return PCIBIOS_DEVICE_NOT_FOUND;
  77. if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
  78. if (bus->number != hose->first_busno)
  79. cfg_type = 1;
  80. bus_no = (bus->number == hose->first_busno) ?
  81. hose->self_busno : bus->number;
  82. if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
  83. reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
  84. else
  85. reg = offset & 0xfc;
  86. PCI_CFG_OUT(hose->cfg_addr,
  87. (0x80000000 | (bus_no << 16)
  88. | (devfn << 8) | reg | cfg_type));
  89. /* surpress setting of PCI_PRIMARY_BUS */
  90. if (hose->indirect_type & PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
  91. if ((offset == PCI_PRIMARY_BUS) &&
  92. (bus->number == hose->first_busno))
  93. val &= 0xffffff00;
  94. /*
  95. * Note: the caller has already checked that offset is
  96. * suitably aligned and that len is 1, 2 or 4.
  97. */
  98. cfg_data = hose->cfg_data + (offset & 3);
  99. switch (len) {
  100. case 1:
  101. out_8(cfg_data, val);
  102. break;
  103. case 2:
  104. out_le16(cfg_data, val);
  105. break;
  106. default:
  107. out_le32(cfg_data, val);
  108. break;
  109. }
  110. return PCIBIOS_SUCCESSFUL;
  111. }
  112. static struct pci_ops indirect_pci_ops =
  113. {
  114. indirect_read_config,
  115. indirect_write_config
  116. };
  117. void __init
  118. setup_indirect_pci_nomap(struct pci_controller* hose, void __iomem * cfg_addr,
  119. void __iomem * cfg_data)
  120. {
  121. hose->cfg_addr = cfg_addr;
  122. hose->cfg_data = cfg_data;
  123. hose->ops = &indirect_pci_ops;
  124. }
  125. void __init
  126. setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  127. {
  128. unsigned long base = cfg_addr & PAGE_MASK;
  129. void __iomem *mbase, *addr, *data;
  130. mbase = ioremap(base, PAGE_SIZE);
  131. addr = mbase + (cfg_addr & ~PAGE_MASK);
  132. if ((cfg_data & PAGE_MASK) != base)
  133. mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
  134. data = mbase + (cfg_data & ~PAGE_MASK);
  135. setup_indirect_pci_nomap(hose, addr, data);
  136. }