2 * ACPI PCI Hot Plug Controller Driver
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002,2003 NEC Corporation
10 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
11 * Copyright (C) 2003-2005 Hewlett Packard
13 * All rights reserved.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or (at
18 * your option) any later version.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
23 * NON INFRINGEMENT. See the GNU General Public License for more
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 * Send feedback to <gregkh@us.ibm.com>,
31 * <t-kochi@bq.jp.nec.com>
35 #include <linux/init.h>
36 #include <linux/module.h>
37 #include <linux/moduleparam.h>
39 #include <linux/kernel.h>
40 #include <linux/pci.h>
41 #include <linux/slab.h>
42 #include <linux/smp.h>
43 #include <linux/smp_lock.h>
44 #include "pci_hotplug.h"
47 #define MY_NAME "acpiphp"
54 static struct acpiphp_attention_info *attention_info;
56 #define DRIVER_VERSION "0.5"
57 #define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>, Matthew Wilcox <willy@hp.com>"
58 #define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver"
60 MODULE_AUTHOR(DRIVER_AUTHOR);
61 MODULE_DESCRIPTION(DRIVER_DESC);
62 MODULE_LICENSE("GPL");
63 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
64 module_param(debug, bool, 0644);
66 /* export the attention callback registration methods */
67 EXPORT_SYMBOL_GPL(acpiphp_register_attention);
68 EXPORT_SYMBOL_GPL(acpiphp_unregister_attention);
70 static int enable_slot (struct hotplug_slot *slot);
71 static int disable_slot (struct hotplug_slot *slot);
72 static int set_attention_status (struct hotplug_slot *slot, u8 value);
73 static int get_power_status (struct hotplug_slot *slot, u8 *value);
74 static int get_attention_status (struct hotplug_slot *slot, u8 *value);
75 static int get_address (struct hotplug_slot *slot, u32 *value);
76 static int get_latch_status (struct hotplug_slot *slot, u8 *value);
77 static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
79 static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
81 .enable_slot = enable_slot,
82 .disable_slot = disable_slot,
83 .set_attention_status = set_attention_status,
84 .get_power_status = get_power_status,
85 .get_attention_status = get_attention_status,
86 .get_latch_status = get_latch_status,
87 .get_adapter_status = get_adapter_status,
88 .get_address = get_address,
93 * acpiphp_register_attention - set attention LED callback
94 * @info: must be completely filled with LED callbacks
96 * Description: this is used to register a hardware specific ACPI
97 * driver that manipulates the attention LED. All the fields in
100 int acpiphp_register_attention(struct acpiphp_attention_info *info)
102 int retval = -EINVAL;
104 if (info && info->owner && info->set_attn &&
105 info->get_attn && !attention_info) {
107 attention_info = info;
114 * acpiphp_unregister_attention - unset attention LED callback
115 * @info: must match the pointer used to register
117 * Description: this is used to un-register a hardware specific acpi
118 * driver that manipulates the attention LED. The pointer to the
119 * info struct must be the same as the one used to set it.
121 int acpiphp_unregister_attention(struct acpiphp_attention_info *info)
123 int retval = -EINVAL;
125 if (info && attention_info == info) {
126 attention_info = NULL;
134 * enable_slot - power on and enable a slot
135 * @hotplug_slot: slot to enable
137 * Actual tasks are done in acpiphp_enable_slot()
140 static int enable_slot(struct hotplug_slot *hotplug_slot)
142 struct slot *slot = hotplug_slot->private;
144 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
146 /* enable the specified slot */
147 return acpiphp_enable_slot(slot->acpi_slot);
152 * disable_slot - disable and power off a slot
153 * @hotplug_slot: slot to disable
155 * Actual tasks are done in acpiphp_disable_slot()
158 static int disable_slot(struct hotplug_slot *hotplug_slot)
160 struct slot *slot = hotplug_slot->private;
162 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
164 /* disable the specified slot */
165 return acpiphp_disable_slot(slot->acpi_slot);
170 * set_attention_status - set attention LED
171 * @hotplug_slot: slot to set attention LED on
172 * @status: value to set attention LED to (0 or 1)
174 * attention status LED, so we use a callback that
175 * was registered with us. This allows hardware specific
176 * ACPI implementations to blink the light for us.
178 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
180 int retval = -ENODEV;
182 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
184 if (attention_info && try_module_get(attention_info->owner)) {
185 retval = attention_info->set_attn(hotplug_slot, status);
186 module_put(attention_info->owner);
188 attention_info = NULL;
194 * get_power_status - get power status of a slot
195 * @hotplug_slot: slot to get status
196 * @value: pointer to store status
198 * Some platforms may not implement _STA method properly.
199 * In that case, the value returned may not be reliable.
202 static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
204 struct slot *slot = hotplug_slot->private;
206 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
208 *value = acpiphp_get_power_status(slot->acpi_slot);
215 * get_attention_status - get attention LED status
216 * @hotplug_slot: slot to get status from
217 * @value: returns with value of attention LED
219 * ACPI doesn't have known method to determine the state
220 * of the attention status LED, so we use a callback that
221 * was registered with us. This allows hardware specific
222 * ACPI implementations to determine its state
224 static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
226 int retval = -EINVAL;
228 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
230 if (attention_info && try_module_get(attention_info->owner)) {
231 retval = attention_info->get_attn(hotplug_slot, value);
232 module_put(attention_info->owner);
234 attention_info = NULL;
240 * get_latch_status - get latch status of a slot
241 * @hotplug_slot: slot to get status
242 * @value: pointer to store status
244 * ACPI doesn't provide any formal means to access latch status.
245 * Instead, we fake latch status from _STA
248 static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
250 struct slot *slot = hotplug_slot->private;
252 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
254 *value = acpiphp_get_latch_status(slot->acpi_slot);
261 * get_adapter_status - get adapter status of a slot
262 * @hotplug_slot: slot to get status
263 * @value: pointer to store status
265 * ACPI doesn't provide any formal means to access adapter status.
266 * Instead, we fake adapter status from _STA
269 static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
271 struct slot *slot = hotplug_slot->private;
273 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
275 *value = acpiphp_get_adapter_status(slot->acpi_slot);
282 * get_address - get pci address of a slot
283 * @hotplug_slot: slot to get status
284 * @value: pointer to struct pci_busdev (seg, bus, dev)
286 static int get_address(struct hotplug_slot *hotplug_slot, u32 *value)
288 struct slot *slot = hotplug_slot->private;
290 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
292 *value = acpiphp_get_address(slot->acpi_slot);
297 static int __init init_acpi(void)
301 /* initialize internal data structure etc. */
302 retval = acpiphp_glue_init();
304 /* read initial number of slots */
306 num_slots = acpiphp_get_num_slots();
316 * make_slot_name - make a slot name that appears in pcihpfs
317 * @slot: slot to name
320 static void make_slot_name(struct slot *slot)
322 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%u",
323 slot->acpi_slot->sun);
327 * release_slot - free up the memory used by a slot
328 * @hotplug_slot: slot to free
330 static void release_slot(struct hotplug_slot *hotplug_slot)
332 struct slot *slot = hotplug_slot->private;
334 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
336 kfree(slot->hotplug_slot->info);
337 kfree(slot->hotplug_slot->name);
338 kfree(slot->hotplug_slot);
342 /* callback routine to initialize 'struct slot' for each slot */
343 int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
346 struct hotplug_slot *hotplug_slot;
347 struct hotplug_slot_info *hotplug_slot_info;
348 int retval = -ENOMEM;
350 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
354 slot->hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
355 if (!slot->hotplug_slot)
358 slot->hotplug_slot->info = kzalloc(sizeof(*hotplug_slot_info),
360 if (!slot->hotplug_slot->info)
363 slot->hotplug_slot->name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL);
364 if (!slot->hotplug_slot->name)
367 slot->hotplug_slot->private = slot;
368 slot->hotplug_slot->release = &release_slot;
369 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
371 slot->acpi_slot = acpiphp_slot;
372 slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
373 slot->hotplug_slot->info->attention_status = 0;
374 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
375 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
376 slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
377 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
379 acpiphp_slot->slot = slot;
380 make_slot_name(slot);
382 retval = pci_hp_register(slot->hotplug_slot);
384 err("pci_hp_register failed with error %d\n", retval);
388 info("Slot [%s] registered\n", slot->hotplug_slot->name);
392 kfree(slot->hotplug_slot->name);
394 kfree(slot->hotplug_slot->info);
396 kfree(slot->hotplug_slot);
404 void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
406 struct slot *slot = acpiphp_slot->slot;
409 info ("Slot [%s] unregistered\n", slot->hotplug_slot->name);
411 retval = pci_hp_deregister(slot->hotplug_slot);
413 err("pci_hp_deregister failed with error %d\n", retval);
417 static int __init acpiphp_init(void)
422 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
424 acpiphp_debug = debug;
426 docking_station = find_dock_station();
428 /* read all the ACPI info from the system */
429 retval = init_acpi();
431 /* if we have found a docking station, we should
432 * go ahead and load even if init_acpi has found
433 * no slots. This handles the case when the _DCK
434 * method not defined under the actual dock bridge
443 static void __exit acpiphp_exit(void)
445 /* deallocate internal data structures etc. */
448 remove_dock_station();
451 module_init(acpiphp_init);
452 module_exit(acpiphp_exit);