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"
54 static struct acpiphp_attention_info
*attention_info
;
56 #define DRIVER_VERSION "0.4"
57 #define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.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 * @busdev: pointer to struct pci_busdev (seg, bus, dev)
287 static int get_address(struct hotplug_slot
*hotplug_slot
, u32
*value
)
289 struct slot
*slot
= hotplug_slot
->private;
291 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
293 *value
= acpiphp_get_address(slot
->acpi_slot
);
298 static int __init
init_acpi(void)
302 /* initialize internal data structure etc. */
303 retval
= acpiphp_glue_init();
305 /* read initial number of slots */
307 num_slots
= acpiphp_get_num_slots();
317 * make_slot_name - make a slot name that appears in pcihpfs
318 * @slot: slot to name
321 static void make_slot_name(struct slot
*slot
)
323 snprintf(slot
->hotplug_slot
->name
, SLOT_NAME_SIZE
, "%u",
324 slot
->acpi_slot
->sun
);
328 * release_slot - free up the memory used by a slot
329 * @hotplug_slot: slot to free
331 static void release_slot(struct hotplug_slot
*hotplug_slot
)
333 struct slot
*slot
= hotplug_slot
->private;
335 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
337 kfree(slot
->hotplug_slot
->info
);
338 kfree(slot
->hotplug_slot
->name
);
339 kfree(slot
->hotplug_slot
);
344 * init_slots - initialize 'struct slot' structures for each slot
347 static int __init
init_slots(void)
350 int retval
= -ENOMEM
;
353 for (i
= 0; i
< num_slots
; ++i
) {
354 slot
= kmalloc(sizeof(struct slot
), GFP_KERNEL
);
357 memset(slot
, 0, sizeof(struct slot
));
359 slot
->hotplug_slot
= kmalloc(sizeof(struct hotplug_slot
), GFP_KERNEL
);
360 if (!slot
->hotplug_slot
)
362 memset(slot
->hotplug_slot
, 0, sizeof(struct hotplug_slot
));
364 slot
->hotplug_slot
->info
= kmalloc(sizeof(struct hotplug_slot_info
), GFP_KERNEL
);
365 if (!slot
->hotplug_slot
->info
)
367 memset(slot
->hotplug_slot
->info
, 0, sizeof(struct hotplug_slot_info
));
369 slot
->hotplug_slot
->name
= kmalloc(SLOT_NAME_SIZE
, GFP_KERNEL
);
370 if (!slot
->hotplug_slot
->name
)
375 slot
->hotplug_slot
->private = slot
;
376 slot
->hotplug_slot
->release
= &release_slot
;
377 slot
->hotplug_slot
->ops
= &acpi_hotplug_slot_ops
;
379 slot
->acpi_slot
= get_slot_from_id(i
);
380 slot
->hotplug_slot
->info
->power_status
= acpiphp_get_power_status(slot
->acpi_slot
);
381 slot
->hotplug_slot
->info
->attention_status
= 0;
382 slot
->hotplug_slot
->info
->latch_status
= acpiphp_get_latch_status(slot
->acpi_slot
);
383 slot
->hotplug_slot
->info
->adapter_status
= acpiphp_get_adapter_status(slot
->acpi_slot
);
384 slot
->hotplug_slot
->info
->max_bus_speed
= PCI_SPEED_UNKNOWN
;
385 slot
->hotplug_slot
->info
->cur_bus_speed
= PCI_SPEED_UNKNOWN
;
387 make_slot_name(slot
);
389 retval
= pci_hp_register(slot
->hotplug_slot
);
391 err("pci_hp_register failed with error %d\n", retval
);
395 /* add slot to our internal list */
396 list_add(&slot
->slot_list
, &slot_list
);
397 info("Slot [%s] registered\n", slot
->hotplug_slot
->name
);
402 kfree(slot
->hotplug_slot
->name
);
404 kfree(slot
->hotplug_slot
->info
);
406 kfree(slot
->hotplug_slot
);
414 static void __exit
cleanup_slots (void)
416 struct list_head
*tmp
, *n
;
419 list_for_each_safe (tmp
, n
, &slot_list
) {
420 /* memory will be freed in release_slot callback */
421 slot
= list_entry(tmp
, struct slot
, slot_list
);
422 list_del(&slot
->slot_list
);
423 pci_hp_deregister(slot
->hotplug_slot
);
428 static int __init
acpiphp_init(void)
432 info(DRIVER_DESC
" version: " DRIVER_VERSION
"\n");
434 acpiphp_debug
= debug
;
436 /* read all the ACPI info from the system */
437 retval
= init_acpi();
445 static void __exit
acpiphp_exit(void)
448 /* deallocate internal data structures etc. */
452 module_init(acpiphp_init
);
453 module_exit(acpiphp_exit
);