rpaphp_vio.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * RPA Hot Plug Virtual I/O device functions
  3. * Copyright (C) 2004 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 <asm/vio.h>
  26. #include "rpaphp.h"
  27. /*
  28. * get_vio_adapter_status - get the status of a slot
  29. *
  30. * status:
  31. *
  32. * 1-- adapter is configured
  33. * 2-- adapter is not configured
  34. * 3-- not valid
  35. */
  36. inline int rpaphp_get_vio_adapter_status(struct slot *slot, int is_init, u8 *value)
  37. {
  38. *value = slot->state;
  39. return 0;
  40. }
  41. int rpaphp_unconfig_vio_adapter(struct slot *slot)
  42. {
  43. int retval = 0;
  44. dbg("Entry %s: slot[%s]\n", __FUNCTION__, slot->name);
  45. if (!slot->dev.vio_dev) {
  46. info("%s: no VIOA in slot[%s]\n", __FUNCTION__, slot->name);
  47. retval = -EINVAL;
  48. goto exit;
  49. }
  50. /* remove the device from the vio core */
  51. vio_unregister_device(slot->dev.vio_dev);
  52. slot->state = NOT_CONFIGURED;
  53. info("%s: adapter in slot[%s] unconfigured.\n", __FUNCTION__, slot->name);
  54. exit:
  55. dbg("Exit %s, rc=0x%x\n", __FUNCTION__, retval);
  56. return retval;
  57. }
  58. static int setup_vio_hotplug_slot_info(struct slot *slot)
  59. {
  60. slot->hotplug_slot->info->power_status = 1;
  61. rpaphp_get_vio_adapter_status(slot, 1,
  62. &slot->hotplug_slot->info->adapter_status);
  63. return 0;
  64. }
  65. int register_vio_slot(struct device_node *dn)
  66. {
  67. u32 *index;
  68. char *name;
  69. int rc = -EINVAL;
  70. struct slot *slot = NULL;
  71. rc = rpaphp_get_drc_props(dn, NULL, &name, NULL, NULL);
  72. if (rc < 0)
  73. goto exit_rc;
  74. index = (u32 *) get_property(dn, "ibm,my-drc-index", NULL);
  75. if (!index)
  76. goto exit_rc;
  77. if (!(slot = alloc_slot_struct(dn, *index, name, 0))) {
  78. rc = -ENOMEM;
  79. goto exit_rc;
  80. }
  81. slot->dev_type = VIO_DEV;
  82. slot->dev.vio_dev = vio_find_node(dn);
  83. if (slot->dev.vio_dev) {
  84. /*
  85. * rpaphp is the only owner of vio devices and
  86. * does not need extra reference taken by
  87. * vio_find_node
  88. */
  89. put_device(&slot->dev.vio_dev->dev);
  90. } else
  91. slot->dev.vio_dev = vio_register_device_node(dn);
  92. if (slot->dev.vio_dev)
  93. slot->state = CONFIGURED;
  94. else
  95. slot->state = NOT_CONFIGURED;
  96. if (setup_vio_hotplug_slot_info(slot))
  97. goto exit_rc;
  98. strcpy(slot->name, slot->dev.vio_dev->dev.bus_id);
  99. info("%s: registered VIO device[name=%s vio_dev=%p]\n",
  100. __FUNCTION__, slot->name, slot->dev.vio_dev);
  101. rc = register_slot(slot);
  102. exit_rc:
  103. if (rc && slot)
  104. dealloc_slot_struct(slot);
  105. return (rc);
  106. }
  107. int rpaphp_enable_vio_slot(struct slot *slot)
  108. {
  109. int retval = 0;
  110. if ((slot->dev.vio_dev = vio_register_device_node(slot->dn))) {
  111. info("%s: VIO adapter %s in slot[%s] has been configured\n",
  112. __FUNCTION__, slot->dn->name, slot->name);
  113. slot->state = CONFIGURED;
  114. } else {
  115. info("%s: no vio_dev struct for adapter in slot[%s]\n",
  116. __FUNCTION__, slot->name);
  117. slot->state = NOT_CONFIGURED;
  118. }
  119. return retval;
  120. }