pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (C) 2001 Dave Engebretsen, IBM Corporation
  3. * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
  4. *
  5. * pSeries specific routines for PCI.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/ioport.h>
  23. #include <linux/kernel.h>
  24. #include <linux/pci.h>
  25. #include <linux/string.h>
  26. #include <asm/eeh.h>
  27. #include <asm/pci-bridge.h>
  28. #include <asm/prom.h>
  29. #include <asm/ppc-pci.h>
  30. #include "pseries.h"
  31. #if 0
  32. void pcibios_name_device(struct pci_dev *dev)
  33. {
  34. struct device_node *dn;
  35. /*
  36. * Add IBM loc code (slot) as a prefix to the device names for service
  37. */
  38. dn = pci_device_to_OF_node(dev);
  39. if (dn) {
  40. const char *loc_code = of_get_property(dn, "ibm,loc-code",
  41. NULL);
  42. if (loc_code) {
  43. int loc_len = strlen(loc_code);
  44. if (loc_len < sizeof(dev->dev.name)) {
  45. memmove(dev->dev.name+loc_len+1, dev->dev.name,
  46. sizeof(dev->dev.name)-loc_len-1);
  47. memcpy(dev->dev.name, loc_code, loc_len);
  48. dev->dev.name[loc_len] = ' ';
  49. dev->dev.name[sizeof(dev->dev.name)-1] = '\0';
  50. }
  51. }
  52. }
  53. }
  54. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_name_device);
  55. #endif
  56. static void __init pSeries_request_regions(void)
  57. {
  58. if (!isa_io_base)
  59. return;
  60. request_region(0x20,0x20,"pic1");
  61. request_region(0xa0,0x20,"pic2");
  62. request_region(0x00,0x20,"dma1");
  63. request_region(0x40,0x20,"timer");
  64. request_region(0x80,0x10,"dma page reg");
  65. request_region(0xc0,0x20,"dma2");
  66. }
  67. void __init pSeries_final_fixup(void)
  68. {
  69. pSeries_request_regions();
  70. eeh_addr_cache_build();
  71. }
  72. /*
  73. * Assume the winbond 82c105 is the IDE controller on a
  74. * p610/p615/p630. We should probably be more careful in case
  75. * someone tries to plug in a similar adapter.
  76. */
  77. static void fixup_winbond_82c105(struct pci_dev* dev)
  78. {
  79. int i;
  80. unsigned int reg;
  81. if (!machine_is(pseries))
  82. return;
  83. printk("Using INTC for W82c105 IDE controller.\n");
  84. pci_read_config_dword(dev, 0x40, &reg);
  85. /* Enable LEGIRQ to use INTC instead of ISA interrupts */
  86. pci_write_config_dword(dev, 0x40, reg | (1<<11));
  87. for (i = 0; i < DEVICE_COUNT_RESOURCE; ++i) {
  88. /* zap the 2nd function of the winbond chip */
  89. if (dev->resource[i].flags & IORESOURCE_IO
  90. && dev->bus->number == 0 && dev->devfn == 0x81)
  91. dev->resource[i].flags &= ~IORESOURCE_IO;
  92. if (dev->resource[i].start == 0 && dev->resource[i].end) {
  93. dev->resource[i].flags = 0;
  94. dev->resource[i].end = 0;
  95. }
  96. }
  97. }
  98. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,
  99. fixup_winbond_82c105);
  100. int pseries_root_bridge_prepare(struct pci_host_bridge *bridge)
  101. {
  102. struct device_node *dn, *pdn;
  103. struct pci_bus *bus;
  104. u32 pcie_link_speed_stats[2];
  105. int rc;
  106. bus = bridge->bus;
  107. /* Rely on the pcibios_free_controller_deferred() callback. */
  108. pci_set_host_bridge_release(bridge, pcibios_free_controller_deferred,
  109. (void *) pci_bus_to_host(bus));
  110. dn = pcibios_get_phb_of_node(bus);
  111. if (!dn)
  112. return 0;
  113. for (pdn = dn; pdn != NULL; pdn = of_get_next_parent(pdn)) {
  114. rc = of_property_read_u32_array(pdn,
  115. "ibm,pcie-link-speed-stats",
  116. &pcie_link_speed_stats[0], 2);
  117. if (!rc)
  118. break;
  119. }
  120. of_node_put(pdn);
  121. if (rc) {
  122. pr_debug("no ibm,pcie-link-speed-stats property\n");
  123. return 0;
  124. }
  125. switch (pcie_link_speed_stats[0]) {
  126. case 0x01:
  127. bus->max_bus_speed = PCIE_SPEED_2_5GT;
  128. break;
  129. case 0x02:
  130. bus->max_bus_speed = PCIE_SPEED_5_0GT;
  131. break;
  132. case 0x04:
  133. bus->max_bus_speed = PCIE_SPEED_8_0GT;
  134. break;
  135. default:
  136. bus->max_bus_speed = PCI_SPEED_UNKNOWN;
  137. break;
  138. }
  139. switch (pcie_link_speed_stats[1]) {
  140. case 0x01:
  141. bus->cur_bus_speed = PCIE_SPEED_2_5GT;
  142. break;
  143. case 0x02:
  144. bus->cur_bus_speed = PCIE_SPEED_5_0GT;
  145. break;
  146. case 0x04:
  147. bus->cur_bus_speed = PCIE_SPEED_8_0GT;
  148. break;
  149. default:
  150. bus->cur_bus_speed = PCI_SPEED_UNKNOWN;
  151. break;
  152. }
  153. return 0;
  154. }