rpaphp_pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
  3. * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
  4. *
  5. * All rights reserved.
  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 (at
  10. * your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  15. * NON INFRINGEMENT. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * Send feedback to <lxie@us.ibm.com>
  23. *
  24. */
  25. #include <linux/pci.h>
  26. #include <linux/string.h>
  27. #include <asm/pci-bridge.h>
  28. #include <asm/rtas.h>
  29. #include <asm/machdep.h>
  30. #include "../pci.h" /* for pci_add_new_bus */
  31. #include "rpaphp.h"
  32. int rpaphp_get_sensor_state(struct slot *slot, int *state)
  33. {
  34. int rc;
  35. int setlevel;
  36. rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
  37. if (rc < 0) {
  38. if (rc == -EFAULT || rc == -EEXIST) {
  39. dbg("%s: slot must be power up to get sensor-state\n",
  40. __func__);
  41. /* some slots have to be powered up
  42. * before get-sensor will succeed.
  43. */
  44. rc = rtas_set_power_level(slot->power_domain, POWER_ON,
  45. &setlevel);
  46. if (rc < 0) {
  47. dbg("%s: power on slot[%s] failed rc=%d.\n",
  48. __func__, slot->name, rc);
  49. } else {
  50. rc = rtas_get_sensor(DR_ENTITY_SENSE,
  51. slot->index, state);
  52. }
  53. } else if (rc == -ENODEV)
  54. info("%s: slot is unusable\n", __func__);
  55. else
  56. err("%s failed to get sensor state\n", __func__);
  57. }
  58. return rc;
  59. }
  60. /**
  61. * rpaphp_enable_slot - record slot state, config pci device
  62. * @slot: target &slot
  63. *
  64. * Initialize values in the slot, and the hotplug_slot info
  65. * structures to indicate if there is a pci card plugged into
  66. * the slot. If the slot is not empty, run the pcibios routine
  67. * to get pcibios stuff correctly set up.
  68. */
  69. int rpaphp_enable_slot(struct slot *slot)
  70. {
  71. int rc, level, state;
  72. struct pci_bus *bus;
  73. struct hotplug_slot_info *info = slot->hotplug_slot->info;
  74. info->adapter_status = NOT_VALID;
  75. slot->state = EMPTY;
  76. /* Find out if the power is turned on for the slot */
  77. rc = rtas_get_power_level(slot->power_domain, &level);
  78. if (rc)
  79. return rc;
  80. info->power_status = level;
  81. /* Figure out if there is an adapter in the slot */
  82. rc = rpaphp_get_sensor_state(slot, &state);
  83. if (rc)
  84. return rc;
  85. bus = pcibios_find_pci_bus(slot->dn);
  86. if (!bus) {
  87. err("%s: no pci_bus for dn %s\n", __func__, slot->dn->full_name);
  88. return -EINVAL;
  89. }
  90. info->adapter_status = EMPTY;
  91. slot->bus = bus;
  92. slot->pci_devs = &bus->devices;
  93. /* if there's an adapter in the slot, go add the pci devices */
  94. if (state == PRESENT) {
  95. info->adapter_status = NOT_CONFIGURED;
  96. slot->state = NOT_CONFIGURED;
  97. /* non-empty slot has to have child */
  98. if (!slot->dn->child) {
  99. err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
  100. __func__, slot->name);
  101. return -EINVAL;
  102. }
  103. if (list_empty(&bus->devices))
  104. pcibios_add_pci_devices(bus);
  105. if (!list_empty(&bus->devices)) {
  106. info->adapter_status = CONFIGURED;
  107. slot->state = CONFIGURED;
  108. }
  109. if (rpaphp_debug) {
  110. struct pci_dev *dev;
  111. dbg("%s: pci_devs of slot[%s]\n", __func__, slot->dn->full_name);
  112. list_for_each_entry (dev, &bus->devices, bus_list)
  113. dbg("\t%s\n", pci_name(dev));
  114. }
  115. }
  116. return 0;
  117. }