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>
35 #include <linux/moduleparam.h>
37 #include <linux/kernel.h>
38 #include <linux/pci.h>
39 #include <linux/slab.h>
40 #include <linux/smp.h>
41 #include <linux/smp_lock.h>
42 #include "pci_hotplug.h"
45 static LIST_HEAD(slot_list);
47 #define MY_NAME "acpiphp"
55 #define DRIVER_VERSION "0.4"
56 #define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
57 #define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver"
59 MODULE_AUTHOR(DRIVER_AUTHOR);
60 MODULE_DESCRIPTION(DRIVER_DESC);
61 MODULE_LICENSE("GPL");
62 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
63 module_param(debug, bool, 644);
65 static int enable_slot (struct hotplug_slot *slot);
66 static int disable_slot (struct hotplug_slot *slot);
67 static int set_attention_status (struct hotplug_slot *slot, u8 value);
68 static int get_power_status (struct hotplug_slot *slot, u8 *value);
69 static int get_address (struct hotplug_slot *slot, u32 *value);
70 static int get_latch_status (struct hotplug_slot *slot, u8 *value);
71 static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
73 static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
75 .enable_slot = enable_slot,
76 .disable_slot = disable_slot,
77 .set_attention_status = set_attention_status,
78 .get_power_status = get_power_status,
79 .get_latch_status = get_latch_status,
80 .get_adapter_status = get_adapter_status,
81 .get_address = get_address,
85 * enable_slot - power on and enable a slot
86 * @hotplug_slot: slot to enable
88 * Actual tasks are done in acpiphp_enable_slot()
91 static int enable_slot(struct hotplug_slot *hotplug_slot)
93 struct slot *slot = hotplug_slot->private;
95 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
97 /* enable the specified slot */
98 return acpiphp_enable_slot(slot->acpi_slot);
103 * disable_slot - disable and power off a slot
104 * @hotplug_slot: slot to disable
106 * Actual tasks are done in acpiphp_disable_slot()
109 static int disable_slot(struct hotplug_slot *hotplug_slot)
111 struct slot *slot = hotplug_slot->private;
113 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
115 /* disable the specified slot */
116 return acpiphp_disable_slot(slot->acpi_slot);
121 * set_attention_status - set attention LED
124 * ACPI doesn't have known method to manipulate
125 * attention status LED.
128 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
130 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
134 /* FIXME turn light off */
135 hotplug_slot->info->attention_status = 0;
140 /* FIXME turn light on */
141 hotplug_slot->info->attention_status = 1;
149 * get_power_status - get power status of a slot
150 * @hotplug_slot: slot to get status
151 * @value: pointer to store status
153 * Some platforms may not implement _STA method properly.
154 * In that case, the value returned may not be reliable.
157 static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
159 struct slot *slot = hotplug_slot->private;
161 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
163 *value = acpiphp_get_power_status(slot->acpi_slot);
169 * get_latch_status - get latch status of a slot
170 * @hotplug_slot: slot to get status
171 * @value: pointer to store status
173 * ACPI doesn't provide any formal means to access latch status.
174 * Instead, we fake latch status from _STA
177 static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
179 struct slot *slot = hotplug_slot->private;
181 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
183 *value = acpiphp_get_latch_status(slot->acpi_slot);
190 * get_adapter_status - get adapter status of a slot
191 * @hotplug_slot: slot to get status
192 * @value: pointer to store status
194 * ACPI doesn't provide any formal means to access adapter status.
195 * Instead, we fake adapter status from _STA
198 static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
200 struct slot *slot = hotplug_slot->private;
202 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
204 *value = acpiphp_get_adapter_status(slot->acpi_slot);
211 * get_address - get pci address of a slot
212 * @hotplug_slot: slot to get status
213 * @busdev: pointer to struct pci_busdev (seg, bus, dev)
216 static int get_address(struct hotplug_slot *hotplug_slot, u32 *value)
218 struct slot *slot = hotplug_slot->private;
220 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
222 *value = acpiphp_get_address(slot->acpi_slot);
227 static int __init init_acpi(void)
231 /* initialize internal data structure etc. */
232 retval = acpiphp_glue_init();
234 /* read initial number of slots */
236 num_slots = acpiphp_get_num_slots();
246 * make_slot_name - make a slot name that appears in pcihpfs
247 * @slot: slot to name
250 static void make_slot_name(struct slot *slot)
252 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%u",
253 slot->acpi_slot->sun);
257 * release_slot - free up the memory used by a slot
258 * @hotplug_slot: slot to free
260 static void release_slot(struct hotplug_slot *hotplug_slot)
262 struct slot *slot = hotplug_slot->private;
264 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
266 kfree(slot->hotplug_slot->info);
267 kfree(slot->hotplug_slot->name);
268 kfree(slot->hotplug_slot);
273 * init_slots - initialize 'struct slot' structures for each slot
276 static int __init init_slots(void)
279 int retval = -ENOMEM;
282 for (i = 0; i < num_slots; ++i) {
283 slot = kmalloc(sizeof(struct slot), GFP_KERNEL);
286 memset(slot, 0, sizeof(struct slot));
288 slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
289 if (!slot->hotplug_slot)
291 memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
293 slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
294 if (!slot->hotplug_slot->info)
296 memset(slot->hotplug_slot->info, 0, sizeof(struct hotplug_slot_info));
298 slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
299 if (!slot->hotplug_slot->name)
304 slot->hotplug_slot->private = slot;
305 slot->hotplug_slot->release = &release_slot;
306 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
308 slot->acpi_slot = get_slot_from_id(i);
309 slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
310 slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
311 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
312 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
313 slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
314 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
316 make_slot_name(slot);
318 retval = pci_hp_register(slot->hotplug_slot);
320 err("pci_hp_register failed with error %d\n", retval);
324 /* add slot to our internal list */
325 list_add(&slot->slot_list, &slot_list);
326 info("Slot [%s] registered\n", slot->hotplug_slot->name);
331 kfree(slot->hotplug_slot->name);
333 kfree(slot->hotplug_slot->info);
335 kfree(slot->hotplug_slot);
343 static void __exit cleanup_slots (void)
345 struct list_head *tmp, *n;
348 list_for_each_safe (tmp, n, &slot_list) {
349 /* memory will be freed in release_slot callback */
350 slot = list_entry(tmp, struct slot, slot_list);
351 list_del(&slot->slot_list);
352 pci_hp_deregister(slot->hotplug_slot);
357 static int __init acpiphp_init(void)
361 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
363 acpiphp_debug = debug;
365 /* read all the ACPI info from the system */
366 retval = init_acpi();
374 static void __exit acpiphp_exit(void)
377 /* deallocate internal data structures etc. */
381 module_init(acpiphp_init);
382 module_exit(acpiphp_exit);