30 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
45 #define DRIVER_VERSION "0.4"
47 #define DRIVER_DESC "Standard Hot Plug PCI Controller Driver"
60 #define SHPC_MODULE_NAME "shpchp"
62 static int set_attention_status (
struct hotplug_slot *
slot,
u8 value);
63 static int enable_slot (
struct hotplug_slot *
slot);
64 static int disable_slot (
struct hotplug_slot *
slot);
65 static int get_power_status (
struct hotplug_slot *
slot,
u8 *
value);
66 static int get_attention_status (
struct hotplug_slot *
slot,
u8 *
value);
67 static int get_latch_status (
struct hotplug_slot *
slot,
u8 *
value);
68 static int get_adapter_status (
struct hotplug_slot *
slot,
u8 *
value);
84 static void release_slot(
struct hotplug_slot *hotplug_slot)
86 struct slot *
slot = hotplug_slot->private;
89 __func__, slot_name(slot));
99 struct hotplug_slot *hotplug_slot;
112 hotplug_slot = kzalloc(
sizeof(*hotplug_slot),
GFP_KERNEL);
124 hotplug_slot->info =
info;
128 slot->
bus = ctrl->
pci_dev->subordinate->number;
136 hotplug_slot->private =
slot;
137 hotplug_slot->release = &release_slot;
139 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
141 ctrl_dbg(ctrl,
"Registering domain:bus:dev=%04x:%02x:%02x "
142 "hp_slot=%x sun=%x slot_device_offset=%x\n",
149 ctrl_err(ctrl,
"pci_hp_register failed with error %d\n",
192 static int set_attention_status (
struct hotplug_slot *hotplug_slot,
u8 status)
194 struct slot *slot = get_slot(hotplug_slot);
197 __func__, slot_name(slot));
199 hotplug_slot->info->attention_status =
status;
200 slot->
hpc_ops->set_attention_status(slot, status);
205 static int enable_slot (
struct hotplug_slot *hotplug_slot)
207 struct slot *slot = get_slot(hotplug_slot);
210 __func__, slot_name(slot));
215 static int disable_slot (
struct hotplug_slot *hotplug_slot)
217 struct slot *slot = get_slot(hotplug_slot);
220 __func__, slot_name(slot));
225 static int get_power_status (
struct hotplug_slot *hotplug_slot,
u8 *
value)
227 struct slot *slot = get_slot(hotplug_slot);
231 __func__, slot_name(slot));
233 retval = slot->
hpc_ops->get_power_status(slot, value);
235 *value = hotplug_slot->info->power_status;
240 static int get_attention_status (
struct hotplug_slot *hotplug_slot,
u8 *value)
242 struct slot *slot = get_slot(hotplug_slot);
246 __func__, slot_name(slot));
248 retval = slot->
hpc_ops->get_attention_status(slot, value);
250 *value = hotplug_slot->info->attention_status;
255 static int get_latch_status (
struct hotplug_slot *hotplug_slot,
u8 *value)
257 struct slot *slot = get_slot(hotplug_slot);
261 __func__, slot_name(slot));
263 retval = slot->
hpc_ops->get_latch_status(slot, value);
265 *value = hotplug_slot->info->latch_status;
270 static int get_adapter_status (
struct hotplug_slot *hotplug_slot,
u8 *value)
272 struct slot *slot = get_slot(hotplug_slot);
276 __func__, slot_name(slot));
278 retval = slot->
hpc_ops->get_adapter_status(slot, value);
280 *value = hotplug_slot->info->adapter_status;
285 static int is_shpc_capable(
struct pci_dev *
dev)
302 if (!is_shpc_capable(pdev))
307 dev_err(&pdev->
dev,
"%s: Out of memory\n", __func__);
314 ctrl_dbg(ctrl,
"Controller initialization failed\n");
315 goto err_out_free_ctrl;
318 pci_set_drvdata(pdev, ctrl);
321 rc = init_slots(ctrl);
323 ctrl_err(ctrl,
"Slot initialization failed\n");
324 goto err_out_release_ctlr;
329 goto err_cleanup_slots;
335 err_out_release_ctlr:
336 ctrl->
hpc_ops->release_ctlr(ctrl);
343 static void shpc_remove(
struct pci_dev *dev)
345 struct controller *ctrl = pci_get_drvdata(dev);
348 ctrl->
hpc_ops->release_ctlr(ctrl);
360 .id_table = shpcd_pci_tbl,
362 .remove = shpc_remove,
365 static int __init shpcd_init(
void)
374 if (!shpchp_ordered_wq) {
379 retval = pci_register_driver(&shpc_driver);
380 dbg(
"%s: pci_register_driver = %d\n", __func__, retval);
389 static void __exit shpcd_cleanup(
void)
391 dbg(
"unload_shpchpd()\n");