[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / pci / hotplug / rpaphp_vio.c
blob74df6a305e64ea4030ff209df8deab34157422a8
1 /*
2 * RPA Hot Plug Virtual I/O device functions
3 * Copyright (C) 2004 Linda Xie <lxie@us.ibm.com>
5 * All rights reserved.
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.
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.
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.
22 * Send feedback to <lxie@us.ibm.com>
25 #include <asm/vio.h>
26 #include "rpaphp.h"
29 * get_vio_adapter_status - get the status of a slot
31 * status:
33 * 1-- adapter is configured
34 * 2-- adapter is not configured
35 * 3-- not valid
37 inline int rpaphp_get_vio_adapter_status(struct slot *slot, int is_init, u8 *value)
39 *value = slot->state;
40 return 0;
43 int rpaphp_unconfig_vio_adapter(struct slot *slot)
45 int retval = 0;
47 dbg("Entry %s: slot[%s]\n", __FUNCTION__, slot->name);
48 if (!slot->dev.vio_dev) {
49 info("%s: no VIOA in slot[%s]\n", __FUNCTION__, slot->name);
50 retval = -EINVAL;
51 goto exit;
53 /* remove the device from the vio core */
54 vio_unregister_device(slot->dev.vio_dev);
55 slot->state = NOT_CONFIGURED;
56 info("%s: adapter in slot[%s] unconfigured.\n", __FUNCTION__, slot->name);
57 exit:
58 dbg("Exit %s, rc=0x%x\n", __FUNCTION__, retval);
59 return retval;
62 static int setup_vio_hotplug_slot_info(struct slot *slot)
64 slot->hotplug_slot->info->power_status = 1;
65 rpaphp_get_vio_adapter_status(slot, 1,
66 &slot->hotplug_slot->info->adapter_status);
67 return 0;
70 int register_vio_slot(struct device_node *dn)
72 u32 *index;
73 char *name;
74 int rc = -EINVAL;
75 struct slot *slot = NULL;
77 rc = rpaphp_get_drc_props(dn, NULL, &name, NULL, NULL);
78 if (rc < 0)
79 goto exit_rc;
80 index = (u32 *) get_property(dn, "ibm,my-drc-index", NULL);
81 if (!index)
82 goto exit_rc;
83 if (!(slot = alloc_slot_struct(dn, *index, name, 0))) {
84 rc = -ENOMEM;
85 goto exit_rc;
87 slot->dev_type = VIO_DEV;
88 slot->dev.vio_dev = vio_find_node(dn);
89 if (slot->dev.vio_dev) {
91 * rpaphp is the only owner of vio devices and
92 * does not need extra reference taken by
93 * vio_find_node
95 put_device(&slot->dev.vio_dev->dev);
96 } else
97 slot->dev.vio_dev = vio_register_device_node(dn);
98 if (slot->dev.vio_dev)
99 slot->state = CONFIGURED;
100 else
101 slot->state = NOT_CONFIGURED;
102 if (setup_vio_hotplug_slot_info(slot))
103 goto exit_rc;
104 strcpy(slot->name, slot->dev.vio_dev->dev.bus_id);
105 info("%s: registered VIO device[name=%s vio_dev=%p]\n",
106 __FUNCTION__, slot->name, slot->dev.vio_dev);
107 rc = register_slot(slot);
108 exit_rc:
109 if (rc && slot)
110 dealloc_slot_struct(slot);
111 return (rc);
114 int rpaphp_enable_vio_slot(struct slot *slot)
116 int retval = 0;
118 if ((slot->dev.vio_dev = vio_register_device_node(slot->dn))) {
119 info("%s: VIO adapter %s in slot[%s] has been configured\n",
120 __FUNCTION__, slot->dn->name, slot->name);
121 slot->state = CONFIGURED;
122 } else {
123 info("%s: no vio_dev struct for adapter in slot[%s]\n",
124 __FUNCTION__, slot->name);
125 slot->state = NOT_CONFIGURED;
128 return retval;