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
11 * All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or (at
16 * your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
21 * NON INFRINGEMENT. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Send feedback to <gregkh@us.ibm.com>,
29 * <t-kochi@bq.jp.nec.com>
33 #include <linux/init.h>
34 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/pci.h>
38 #include <linux/slab.h>
39 #include <linux/smp.h>
40 #include <linux/smp_lock.h>
41 #include "pci_hotplug.h"
44 static LIST_HEAD(slot_list);
46 #if !defined(CONFIG_HOTPLUG_PCI_ACPI_MODULE)
47 #define MY_NAME "acpiphp"
49 #define MY_NAME THIS_MODULE->name
58 #define DRIVER_VERSION "0.4"
59 #define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
60 #define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver"
62 MODULE_AUTHOR(DRIVER_AUTHOR);
63 MODULE_DESCRIPTION(DRIVER_DESC);
64 MODULE_LICENSE("GPL");
65 MODULE_PARM(debug, "i");
66 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
68 static int enable_slot (struct hotplug_slot *slot);
69 static int disable_slot (struct hotplug_slot *slot);
70 static int set_attention_status (struct hotplug_slot *slot, u8 value);
71 static int hardware_test (struct hotplug_slot *slot, u32 value);
72 static int get_power_status (struct hotplug_slot *slot, u8 *value);
73 static int get_attention_status (struct hotplug_slot *slot, u8 *value);
74 static int get_latch_status (struct hotplug_slot *slot, u8 *value);
75 static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
76 static int get_address (struct hotplug_slot *slot, u32 *value);
77 static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value);
78 static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value);
80 static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
82 .enable_slot = enable_slot,
83 .disable_slot = disable_slot,
84 .set_attention_status = set_attention_status,
85 .hardware_test = hardware_test,
86 .get_power_status = get_power_status,
87 .get_attention_status = get_attention_status,
88 .get_latch_status = get_latch_status,
89 .get_adapter_status = get_adapter_status,
90 .get_address = get_address,
91 .get_max_bus_speed = get_max_bus_speed,
92 .get_cur_bus_speed = get_cur_bus_speed,
96 /* Inline functions to check the sanity of a pointer that is passed to us */
97 static inline int slot_paranoia_check (struct slot *slot, const char *function)
100 dbg("%s - slot == NULL\n", function);
103 if (slot->magic != SLOT_MAGIC) {
104 dbg("%s - bad magic number for slot\n", function);
107 if (!slot->hotplug_slot) {
108 dbg("%s - slot->hotplug_slot == NULL!\n", function);
115 static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
120 dbg("%s - hotplug_slot == NULL\n", function);
124 slot = (struct slot *)hotplug_slot->private;
125 if (slot_paranoia_check(slot, function))
132 * enable_slot - power on and enable a slot
133 * @hotplug_slot: slot to enable
135 * Actual tasks are done in acpiphp_enable_slot()
138 static int enable_slot (struct hotplug_slot *hotplug_slot)
140 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
146 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
148 /* enable the specified slot */
149 retval = acpiphp_enable_slot(slot->acpi_slot);
156 * disable_slot - disable and power off a slot
157 * @hotplug_slot: slot to disable
159 * Actual tasks are done in acpiphp_disable_slot()
162 static int disable_slot (struct hotplug_slot *hotplug_slot)
164 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
170 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
172 /* disable the specified slot */
173 retval = acpiphp_disable_slot(slot->acpi_slot);
180 * set_attention_status - set attention LED
183 * ACPI doesn't have known method to manipulate
184 * attention status LED.
187 static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
191 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
195 /* FIXME turn light off */
196 hotplug_slot->info->attention_status = 0;
201 /* FIXME turn light on */
202 hotplug_slot->info->attention_status = 1;
211 * hardware_test - hardware test
213 * We have nothing to do for now...
216 static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value)
218 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
224 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
226 err("No hardware tests are defined for this driver\n");
234 * get_power_status - get power status of a slot
235 * @hotplug_slot: slot to get status
236 * @value: pointer to store status
238 * Some platforms may not implement _STA method properly.
239 * In that case, the value returned may not be reliable.
242 static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
244 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
250 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
252 *value = acpiphp_get_power_status(slot->acpi_slot);
259 * get_attention_status - get attention LED status
262 * ACPI doesn't provide any formal means to access attention LED status.
265 static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
269 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
271 *value = hotplug_slot->info->attention_status;
278 * get_latch_status - get latch status of a slot
279 * @hotplug_slot: slot to get status
280 * @value: pointer to store status
282 * ACPI doesn't provide any formal means to access latch status.
283 * Instead, we fake latch status from _STA
286 static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
288 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
294 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
296 *value = acpiphp_get_latch_status(slot->acpi_slot);
303 * get_adapter_status - get adapter status of a slot
304 * @hotplug_slot: slot to get status
305 * @value: pointer to store status
307 * ACPI doesn't provide any formal means to access adapter status.
308 * Instead, we fake adapter status from _STA
311 static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
313 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
319 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
321 *value = acpiphp_get_adapter_status(slot->acpi_slot);
328 * get_address - get pci address of a slot
329 * @hotplug_slot: slot to get status
330 * @busdev: pointer to struct pci_busdev (seg, bus, dev)
333 static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
335 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
341 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
343 *value = acpiphp_get_address(slot->acpi_slot);
349 /* return dummy value because ACPI doesn't provide any method... */
350 static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
352 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
357 *value = PCI_SPEED_UNKNOWN;
363 /* return dummy value because ACPI doesn't provide any method... */
364 static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
366 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
371 *value = PCI_SPEED_UNKNOWN;
377 static int init_acpi (void)
381 /* initialize internal data structure etc. */
382 retval = acpiphp_glue_init();
384 /* read initial number of slots */
386 num_slots = acpiphp_get_num_slots();
396 * make_slot_name - make a slot name that appears in pcihpfs
397 * @slot: slot to name
400 static void make_slot_name (struct slot *slot)
402 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%u",
403 slot->acpi_slot->sun);
407 * init_slots - initialize 'struct slot' structures for each slot
410 static int init_slots (void)
416 for (i = 0; i < num_slots; ++i) {
417 slot = kmalloc(sizeof(struct slot), GFP_KERNEL);
420 memset(slot, 0, sizeof(struct slot));
422 slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
423 if (!slot->hotplug_slot) {
427 memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
429 slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
430 if (!slot->hotplug_slot->info) {
431 kfree(slot->hotplug_slot);
435 memset(slot->hotplug_slot->info, 0, sizeof(struct hotplug_slot_info));
437 slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
438 if (!slot->hotplug_slot->name) {
439 kfree(slot->hotplug_slot->info);
440 kfree(slot->hotplug_slot);
445 slot->magic = SLOT_MAGIC;
448 slot->hotplug_slot->private = slot;
449 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
451 slot->acpi_slot = get_slot_from_id(i);
452 slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
453 slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
454 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
455 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
457 make_slot_name(slot);
459 retval = pci_hp_register(slot->hotplug_slot);
461 err("pci_hp_register failed with error %d\n", retval);
462 kfree(slot->hotplug_slot->info);
463 kfree(slot->hotplug_slot->name);
464 kfree(slot->hotplug_slot);
469 /* add slot to our internal list */
470 list_add(&slot->slot_list, &slot_list);
471 info("Slot [%s] registered\n", slot->hotplug_slot->name);
478 static void cleanup_slots (void)
480 struct list_head *tmp, *n;
483 list_for_each_safe (tmp, n, &slot_list) {
484 slot = list_entry(tmp, struct slot, slot_list);
485 list_del(&slot->slot_list);
486 pci_hp_deregister(slot->hotplug_slot);
487 kfree(slot->hotplug_slot->info);
488 kfree(slot->hotplug_slot->name);
489 kfree(slot->hotplug_slot);
497 static int __init acpiphp_init(void)
501 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
503 acpiphp_debug = debug;
505 /* read all the ACPI info from the system */
506 retval = init_acpi();
510 retval = init_slots();
518 static void __exit acpiphp_exit(void)
521 /* deallocate internal data structures etc. */
525 module_init(acpiphp_init);
526 module_exit(acpiphp_exit);