blob: cb4ac43ea95cf1b0e26a0999a2810bf3570663cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Standard Hot Plug Controller Driver
3 *
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) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
Kristen Accardi8cf4c192005-08-16 15:16:10 -070026 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kernel.h>
33#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "shpchp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/* Global variables */
38int shpchp_debug;
39int shpchp_poll_mode;
40int shpchp_poll_time;
Kenji Kaneshigea4534562006-01-26 09:58:30 +090041LIST_HEAD(shpchp_ctrl_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#define DRIVER_VERSION "0.4"
44#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
45#define DRIVER_DESC "Standard Hot Plug PCI Controller Driver"
46
47MODULE_AUTHOR(DRIVER_AUTHOR);
48MODULE_DESCRIPTION(DRIVER_DESC);
49MODULE_LICENSE("GPL");
50
51module_param(shpchp_debug, bool, 0644);
52module_param(shpchp_poll_mode, bool, 0644);
53module_param(shpchp_poll_time, int, 0644);
54MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not");
55MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not");
56MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds");
57
58#define SHPC_MODULE_NAME "shpchp"
59
60static int shpc_start_thread (void);
61static int set_attention_status (struct hotplug_slot *slot, u8 value);
62static int enable_slot (struct hotplug_slot *slot);
63static int disable_slot (struct hotplug_slot *slot);
64static int get_power_status (struct hotplug_slot *slot, u8 *value);
65static int get_attention_status (struct hotplug_slot *slot, u8 *value);
66static int get_latch_status (struct hotplug_slot *slot, u8 *value);
67static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
Kenji Kaneshige81f15442005-12-05 19:31:00 +090068static int get_address (struct hotplug_slot *slot, u32 *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
70static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
71
72static struct hotplug_slot_ops shpchp_hotplug_slot_ops = {
73 .owner = THIS_MODULE,
74 .set_attention_status = set_attention_status,
75 .enable_slot = enable_slot,
76 .disable_slot = disable_slot,
77 .get_power_status = get_power_status,
78 .get_attention_status = get_attention_status,
79 .get_latch_status = get_latch_status,
80 .get_adapter_status = get_adapter_status,
Kenji Kaneshige81f15442005-12-05 19:31:00 +090081 .get_address = get_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 .get_max_bus_speed = get_max_bus_speed,
83 .get_cur_bus_speed = get_cur_bus_speed,
84};
85
86/**
87 * release_slot - free up the memory used by a slot
88 * @hotplug_slot: slot to free
89 */
90static void release_slot(struct hotplug_slot *hotplug_slot)
91{
Dely Syee17fd92005-05-05 11:57:25 -070092 struct slot *slot = hotplug_slot->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
95
96 kfree(slot->hotplug_slot->info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 kfree(slot->hotplug_slot);
98 kfree(slot);
99}
100
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900101static void make_slot_name(struct slot *slot)
102{
103 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
104 slot->bus, slot->number);
105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static int init_slots(struct controller *ctrl)
108{
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900109 struct slot *slot;
110 struct hotplug_slot *hotplug_slot;
111 struct hotplug_slot_info *info;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900112 int retval = -ENOMEM;
113 int i;
114 u32 sun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900116 for (i = 0; i < ctrl->num_slots; i++) {
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900117 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900118 if (!slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 goto error;
120
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900121 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900122 if (!hotplug_slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 goto error_slot;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900124 slot->hotplug_slot = hotplug_slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900126 info = kzalloc(sizeof(*info), GFP_KERNEL);
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900127 if (!info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 goto error_hpslot;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900129 hotplug_slot->info = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900131 hotplug_slot->name = slot->name;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900132
133 slot->hp_slot = i;
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900134 slot->ctrl = ctrl;
135 slot->bus = ctrl->slot_bus;
136 slot->device = ctrl->slot_device_offset + i;
137 slot->hpc_ops = ctrl->hpc_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 if (shpchprm_get_physical_slot_number(ctrl, &sun,
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900140 slot->bus, slot->device))
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900141 goto error_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900143 slot->number = sun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* register this slot with the hotplug pci core */
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900146 hotplug_slot->private = slot;
147 hotplug_slot->release = &release_slot;
148 make_slot_name(slot);
149 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900151 get_power_status(hotplug_slot, &info->power_status);
152 get_attention_status(hotplug_slot, &info->attention_status);
153 get_latch_status(hotplug_slot, &info->latch_status);
154 get_adapter_status(hotplug_slot, &info->adapter_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900156 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
157 "slot_device_offset=%x\n", slot->bus, slot->device,
158 slot->hp_slot, slot->number, ctrl->slot_device_offset);
159 retval = pci_hp_register(slot->hotplug_slot);
160 if (retval) {
161 err("pci_hp_register failed with error %d\n", retval);
Kenji Kaneshigebbe779d2006-01-26 10:04:56 +0900162 goto error_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 }
164
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900165 list_add(&slot->slot_list, &ctrl->slot_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167
168 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169error_info:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900170 kfree(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171error_hpslot:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900172 kfree(hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173error_slot:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900174 kfree(slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175error:
Kenji Kaneshige926030f2006-01-26 09:55:35 +0900176 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
179static void cleanup_slots(struct controller *ctrl)
180{
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900181 struct list_head *tmp;
182 struct list_head *next;
183 struct slot *slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900185 list_for_each_safe(tmp, next, &ctrl->slot_list) {
186 slot = list_entry(tmp, struct slot, slot_list);
187 list_del(&slot->slot_list);
188 pci_hp_deregister(slot->hotplug_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190}
191
192static int get_ctlr_slot_config(struct controller *ctrl)
193{
194 int num_ctlr_slots;
195 int first_device_num;
196 int physical_slot_num;
197 int updown;
198 int rc;
199 int flags;
200
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900201 rc = shpc_get_ctlr_slot_config(ctrl, &num_ctlr_slots,
202 &first_device_num, &physical_slot_num,
203 &updown, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (rc) {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900205 err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n",
206 __FUNCTION__, ctrl->bus, ctrl->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return -1;
208 }
209
210 ctrl->num_slots = num_ctlr_slots;
211 ctrl->slot_device_offset = first_device_num;
212 ctrl->first_slot = physical_slot_num;
213 ctrl->slot_num_inc = updown; /* either -1 or 1 */
214
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900215 dbg("%s: num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) updown(%d) for b:d "
216 "(%x:%x)\n", __FUNCTION__, num_ctlr_slots, first_device_num,
217 physical_slot_num, updown, ctrl->bus, ctrl->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 return 0;
220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*
223 * set_attention_status - Turns the Amber LED for a slot on, off or blink
224 */
225static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
226{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900227 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
230
231 hotplug_slot->info->attention_status = status;
232 slot->hpc_ops->set_attention_status(slot, status);
233
234 return 0;
235}
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static int enable_slot (struct hotplug_slot *hotplug_slot)
238{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900239 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
242
243 return shpchp_enable_slot(slot);
244}
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static int disable_slot (struct hotplug_slot *hotplug_slot)
247{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900248 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
251
252 return shpchp_disable_slot(slot);
253}
254
255static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
256{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900257 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 int retval;
259
260 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
261
262 retval = slot->hpc_ops->get_power_status(slot, value);
263 if (retval < 0)
264 *value = hotplug_slot->info->power_status;
265
266 return 0;
267}
268
269static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
270{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900271 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 int retval;
273
274 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
275
276 retval = slot->hpc_ops->get_attention_status(slot, value);
277 if (retval < 0)
278 *value = hotplug_slot->info->attention_status;
279
280 return 0;
281}
282
283static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
284{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900285 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 int retval;
287
288 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
289
290 retval = slot->hpc_ops->get_latch_status(slot, value);
291 if (retval < 0)
292 *value = hotplug_slot->info->latch_status;
293
294 return 0;
295}
296
297static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
298{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900299 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 int retval;
301
302 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
303
304 retval = slot->hpc_ops->get_adapter_status(slot, value);
305 if (retval < 0)
306 *value = hotplug_slot->info->adapter_status;
307
308 return 0;
309}
310
Kenji Kaneshige81f15442005-12-05 19:31:00 +0900311static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
312{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900313 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Kenji Kaneshige81f15442005-12-05 19:31:00 +0900314 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
315
316 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
317
318 *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device;
319
320 return 0;
321}
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
324{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900325 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 int retval;
327
328 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
331 if (retval < 0)
332 *value = PCI_SPEED_UNKNOWN;
333
334 return 0;
335}
336
337static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
338{
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900339 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 int retval;
341
342 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
345 if (retval < 0)
346 *value = PCI_SPEED_UNKNOWN;
347
348 return 0;
349}
350
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700351static int is_shpc_capable(struct pci_dev *dev)
352{
353 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device ==
354 PCI_DEVICE_ID_AMD_GOLAM_7450))
355 return 1;
356 if (pci_find_capability(dev, PCI_CAP_ID_SHPC))
357 return 1;
358
359 return 0;
360}
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
363{
364 int rc;
365 struct controller *ctrl;
366 struct slot *t_slot;
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900367 int first_device_num; /* first PCI device number */
368 int num_ctlr_slots; /* number of slots implemented */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
rajesh.shah@intel.com1410dc12005-10-13 12:05:39 -0700370 if (!is_shpc_capable(pdev))
371 return -ENODEV;
372
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900373 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 if (!ctrl) {
375 err("%s : out of memory\n", __FUNCTION__);
376 goto err_out_none;
377 }
Kenji Kaneshige5b1a9602006-01-26 09:57:40 +0900378 INIT_LIST_HEAD(&ctrl->slot_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
rajesh.shah@intel.comee138332005-10-13 12:05:42 -0700380 rc = shpc_init(ctrl, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (rc) {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900382 dbg("%s: controller initialization failed\n",
383 SHPC_MODULE_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 goto err_out_free_ctrl;
385 }
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 pci_set_drvdata(pdev, ctrl);
388
Kenji Kaneshige57c95c02006-01-26 10:02:41 +0900389 ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (!ctrl->pci_bus) {
391 err("out of memory\n");
392 rc = -ENOMEM;
393 goto err_out_unmap_mmio_region;
394 }
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
397 ctrl->bus = pdev->bus->number;
398 ctrl->slot_bus = pdev->subordinate->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 ctrl->device = PCI_SLOT(pdev->devfn);
400 ctrl->function = PCI_FUNC(pdev->devfn);
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900401
402 dbg("ctrl bus=0x%x, device=%x, function=%x, irq=%x\n",
403 ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 /*
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900406 * Save configuration headers for this and subordinate PCI buses
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 rc = get_ctlr_slot_config(ctrl);
409 if (rc) {
410 err(msg_initialization_err, rc);
411 goto err_out_free_ctrl_bus;
412 }
413 first_device_num = ctrl->slot_device_offset;
414 num_ctlr_slots = ctrl->num_slots;
415
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700416 ctrl->add_support = 1;
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* Setup the slot information structures */
419 rc = init_slots(ctrl);
420 if (rc) {
421 err(msg_initialization_err, 6);
422 goto err_out_free_ctrl_slot;
423 }
424
425 /* Now hpc_functions (slot->hpc_ops->functions) are ready */
426 t_slot = shpchp_find_slot(ctrl, first_device_num);
427
428 /* Check for operation bus speed */
429 rc = t_slot->hpc_ops->get_cur_bus_speed(t_slot, &ctrl->speed);
430 dbg("%s: t_slot->hp_slot %x\n", __FUNCTION__,t_slot->hp_slot);
431
432 if (rc || ctrl->speed == PCI_SPEED_UNKNOWN) {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900433 err(SHPC_MODULE_NAME ": Can't get current bus speed. "
434 "Set to 33MHz PCI.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 ctrl->speed = PCI_SPEED_33MHz;
436 }
437
438 /* Finish setting up the hot plug ctrl device */
439 ctrl->next_event = 0;
440
Kenji Kaneshigea4534562006-01-26 09:58:30 +0900441 list_add(&ctrl->ctrl_list, &shpchp_ctrl_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 shpchp_create_ctrl_files(ctrl);
444
445 return 0;
446
447err_out_free_ctrl_slot:
448 cleanup_slots(ctrl);
449err_out_free_ctrl_bus:
450 kfree(ctrl->pci_bus);
451err_out_unmap_mmio_region:
452 ctrl->hpc_ops->release_ctlr(ctrl);
453err_out_free_ctrl:
454 kfree(ctrl);
455err_out_none:
456 return -ENODEV;
457}
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459static int shpc_start_thread(void)
460{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 int retval = 0;
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 dbg("Initialize + Start the notification/polling mechanism \n");
464
465 retval = shpchp_event_start_thread();
466 if (retval) {
467 dbg("shpchp_event_start_thread() failed\n");
468 return retval;
469 }
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return retval;
472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474static void __exit unload_shpchpd(void)
475{
Kenji Kaneshigea4534562006-01-26 09:58:30 +0900476 struct list_head *tmp;
477 struct list_head *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 struct controller *ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Kenji Kaneshigea4534562006-01-26 09:58:30 +0900480 list_for_each_safe(tmp, next, &shpchp_ctrl_list) {
481 ctrl = list_entry(tmp, struct controller, ctrl_list);
rajesh.shah@intel.comc2608a12005-10-13 12:05:44 -0700482 shpchp_remove_ctrl_files(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 cleanup_slots(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 kfree (ctrl->pci_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 ctrl->hpc_ops->release_ctlr(ctrl);
Kenji Kaneshigea4534562006-01-26 09:58:30 +0900486 kfree(ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 /* Stop the notification mechanism */
490 shpchp_event_stop_thread();
491
492}
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494static struct pci_device_id shpcd_pci_tbl[] = {
Kenji Kaneshigedfcd5f62006-01-26 09:56:53 +0900495 {PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 { /* end: all zeroes */ }
497};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498MODULE_DEVICE_TABLE(pci, shpcd_pci_tbl);
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500static struct pci_driver shpc_driver = {
501 .name = SHPC_MODULE_NAME,
502 .id_table = shpcd_pci_tbl,
503 .probe = shpc_probe,
504 /* remove: shpc_remove_one, */
505};
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507static int __init shpcd_init(void)
508{
509 int retval = 0;
510
511#ifdef CONFIG_HOTPLUG_PCI_SHPC_POLL_EVENT_MODE
512 shpchp_poll_mode = 1;
513#endif
514
515 retval = shpc_start_thread();
516 if (retval)
517 goto error_hpc_init;
518
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700519 retval = pci_register_driver(&shpc_driver);
520 dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval);
521 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523error_hpc_init:
524 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 shpchp_event_stop_thread();
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return retval;
528}
529
530static void __exit shpcd_cleanup(void)
531{
532 dbg("unload_shpchpd()\n");
533 unload_shpchpd();
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 pci_unregister_driver(&shpc_driver);
536
537 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
538}
539
540module_init(shpcd_init);
541module_exit(shpcd_cleanup);