1 /*
2  * PCI Express 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  *
26  * Send feedback to <greg@kroah.com>, <dely.l.sy@intel.com>
27  *
28  */
29 
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/proc_fs.h>
35 #include <linux/miscdevice.h>
36 #include <linux/slab.h>
37 #include <linux/tqueue.h>
38 #include <linux/pci.h>
39 #include <linux/init.h>
40 #include <asm/uaccess.h>
41 #include "pciehp.h"
42 #include "pciehprm.h"
43 
44 /* Global variables */
45 int pciehp_debug;
46 int pciehp_poll_mode;
47 int pciehp_poll_time;
48 struct controller *pciehp_ctrl_list;	/* = NULL */
49 struct pci_func *pciehp_slot_list[256];
50 
51 #define DRIVER_VERSION	"0.5"
52 #define DRIVER_AUTHOR	"Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
53 #define DRIVER_DESC	"PCI Express Hot Plug Controller Driver"
54 
55 MODULE_AUTHOR(DRIVER_AUTHOR);
56 MODULE_DESCRIPTION(DRIVER_DESC);
57 MODULE_LICENSE("GPL");
58 
59 MODULE_PARM(pciehp_debug, "i");
60 MODULE_PARM(pciehp_poll_mode, "i");
61 MODULE_PARM(pciehp_poll_time, "i");
62 MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not");
63 MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not");
64 MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds");
65 
66 #define PCIE_MODULE_NAME "pciehp.o"
67 
68 static int pcie_start_thread (void);
69 static int set_attention_status (struct hotplug_slot *slot, u8 value);
70 static int enable_slot		(struct hotplug_slot *slot);
71 static int disable_slot		(struct hotplug_slot *slot);
72 static int hardware_test	(struct hotplug_slot *slot, u32 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_latch_status	(struct hotplug_slot *slot, u8 *value);
76 static int get_adapter_status	(struct hotplug_slot *slot, u8 *value);
77 static int get_max_bus_speed	(struct hotplug_slot *slot, enum pci_bus_speed *value);
78 static int get_cur_bus_speed	(struct hotplug_slot *slot, enum pci_bus_speed *value);
79 
80 static struct hotplug_slot_ops pciehp_hotplug_slot_ops = {
81 	.owner =		THIS_MODULE,
82 	.set_attention_status =	set_attention_status,
83 	.enable_slot =		enable_slot,
84 	.disable_slot =		disable_slot,
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_max_bus_speed =	get_max_bus_speed,
91   	.get_cur_bus_speed =	get_cur_bus_speed,
92 };
93 
init_slots(struct controller * ctrl)94 static int init_slots(struct controller *ctrl)
95 {
96 	struct slot *new_slot;
97 	u8 number_of_slots;
98 	u8 slot_device;
99 	u32 slot_number;
100 	int result;
101 
102 	dbg("%s\n",__FUNCTION__);
103 
104 	number_of_slots = ctrl->num_slots;
105 	slot_device = ctrl->slot_device_offset;
106 	slot_number = ctrl->first_slot;
107 
108 	while (number_of_slots) {
109 		new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
110 		if (!new_slot)
111 			return -ENOMEM;
112 
113 		memset(new_slot, 0, sizeof(struct slot));
114 		new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL);
115 		if (!new_slot->hotplug_slot) {
116 			kfree (new_slot);
117 			return -ENOMEM;
118 		}
119 		memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot));
120 
121 		new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
122 		if (!new_slot->hotplug_slot->info) {
123 			kfree (new_slot->hotplug_slot);
124 			kfree (new_slot);
125 			return -ENOMEM;
126 		}
127 		memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
128 		new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL);
129 		if (!new_slot->hotplug_slot->name) {
130 			kfree (new_slot->hotplug_slot->info);
131 			kfree (new_slot->hotplug_slot);
132 			kfree (new_slot);
133 			return -ENOMEM;
134 		}
135 
136 		new_slot->magic = SLOT_MAGIC;
137 		new_slot->ctrl = ctrl;
138 		new_slot->bus = ctrl->slot_bus;
139 		new_slot->device = slot_device;
140 		new_slot->hpc_ops = ctrl->hpc_ops;
141 
142 		new_slot->number = ctrl->first_slot;
143 		new_slot->hp_slot = slot_device - ctrl->slot_device_offset;
144 
145 		/* register this slot with the hotplug pci core */
146 		new_slot->hotplug_slot->private = new_slot;
147 		make_slot_name (new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
148 		new_slot->hotplug_slot->ops = &pciehp_hotplug_slot_ops;
149 
150 		new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status));
151 		new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status));
152 		new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status));
153 		new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status));
154 
155 		dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n",
156 			new_slot->bus, new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset);
157 		result = pci_hp_register (new_slot->hotplug_slot);
158 		if (result) {
159 			err ("pci_hp_register failed with error %d\n", result);
160 			kfree (new_slot->hotplug_slot->info);
161 			kfree (new_slot->hotplug_slot->name);
162 			kfree (new_slot->hotplug_slot);
163 			kfree (new_slot);
164 			return result;
165 		}
166 
167 		new_slot->next = ctrl->slot;
168 		ctrl->slot = new_slot;
169 
170 		number_of_slots--;
171 		slot_device++;
172 		slot_number += ctrl->slot_num_inc;
173 	}
174 
175 	return(0);
176 }
177 
178 
cleanup_slots(struct controller * ctrl)179 static int cleanup_slots (struct controller * ctrl)
180 {
181 	struct slot *old_slot, *next_slot;
182 
183 	old_slot = ctrl->slot;
184 	ctrl->slot = NULL;
185 
186 	while (old_slot) {
187 		next_slot = old_slot->next;
188 		pci_hp_deregister (old_slot->hotplug_slot);
189 		kfree(old_slot->hotplug_slot->info);
190 		kfree(old_slot->hotplug_slot->name);
191 		kfree(old_slot->hotplug_slot);
192 		kfree(old_slot);
193 		old_slot = next_slot;
194 	}
195 
196 
197 	return(0);
198 }
199 
get_ctlr_slot_config(struct controller * ctrl)200 static int get_ctlr_slot_config(struct controller *ctrl)
201 {
202 	int num_ctlr_slots;		/* Not needed; PCI Express has 1 slot per port */
203 	int first_device_num;	 	/* Not needed */
204 	int physical_slot_num;
205 	int updown;			/* Not needed */
206 	int rc;
207 	int flags;			/* Not needed */
208 
209 	rc = pcie_get_ctlr_slot_config(ctrl, &num_ctlr_slots, &first_device_num, &physical_slot_num, &updown, &flags);
210 	if (rc) {
211 		err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n", __FUNCTION__, ctrl->bus, ctrl->device);
212 		return (-1);
213 	}
214 
215 	ctrl->num_slots = num_ctlr_slots;	/* PCI Express has 1 slot per port */
216 	ctrl->slot_device_offset = first_device_num;
217 	ctrl->first_slot = physical_slot_num;
218 	ctrl->slot_num_inc = updown; 		/* Not needed */	/* either -1 or 1 */
219 
220 	dbg("%s: bus(0x%x) num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) updown(%d) for b:d (%x:%x)\n",
221 		__FUNCTION__, ctrl->slot_bus, num_ctlr_slots, first_device_num, physical_slot_num, updown,
222 		ctrl->bus, ctrl->device);
223 
224 	return (0);
225 }
226 
227 
228 /*
229  * set_attention_status - Turns the Amber LED for a slot on, off or blink
230  */
set_attention_status(struct hotplug_slot * hotplug_slot,u8 status)231 static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
232 {
233 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
234 
235 	if (slot == NULL)
236 		return -ENODEV;
237 
238 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
239 
240 	hotplug_slot->info->attention_status = status;
241 	slot->hpc_ops->set_attention_status(slot, status);
242 
243 
244 	return 0;
245 }
246 
247 
enable_slot(struct hotplug_slot * hotplug_slot)248 static int enable_slot (struct hotplug_slot *hotplug_slot)
249 {
250 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
251 
252 	if (slot == NULL)
253 		return -ENODEV;
254 
255 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
256 
257 	return pciehp_enable_slot(slot);
258 }
259 
260 
disable_slot(struct hotplug_slot * hotplug_slot)261 static int disable_slot (struct hotplug_slot *hotplug_slot)
262 {
263 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
264 
265 	if (slot == NULL)
266 		return -ENODEV;
267 
268 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
269 
270 	return pciehp_disable_slot(slot);
271 }
272 
273 
hardware_test(struct hotplug_slot * hotplug_slot,u32 value)274 static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value)
275 {
276 	return 0;
277 }
278 
279 
get_power_status(struct hotplug_slot * hotplug_slot,u8 * value)280 static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
281 {
282 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
283 	int retval;
284 
285 	if (slot == NULL)
286 		return -ENODEV;
287 
288 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
289 
290 	retval = slot->hpc_ops->get_power_status(slot, value);
291 	if (retval < 0)
292 		*value = hotplug_slot->info->power_status;
293 
294 	return 0;
295 }
296 
get_attention_status(struct hotplug_slot * hotplug_slot,u8 * value)297 static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
298 {
299 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
300 	int retval;
301 
302 	if (slot == NULL)
303 		return -ENODEV;
304 
305 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
306 
307 	retval = slot->hpc_ops->get_attention_status(slot, value);
308 	if (retval < 0)
309 		*value = hotplug_slot->info->attention_status;
310 
311 	return 0;
312 }
313 
get_latch_status(struct hotplug_slot * hotplug_slot,u8 * value)314 static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
315 {
316 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
317 	int retval;
318 
319 	if (slot == NULL)
320 		return -ENODEV;
321 
322 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
323 
324 	retval = slot->hpc_ops->get_latch_status(slot, value);
325 	if (retval < 0)
326 		*value = hotplug_slot->info->latch_status;
327 
328 	return 0;
329 }
330 
get_adapter_status(struct hotplug_slot * hotplug_slot,u8 * value)331 static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
332 {
333 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
334 	int retval;
335 
336 	if (slot == NULL)
337 		return -ENODEV;
338 
339 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
340 
341 	retval = slot->hpc_ops->get_adapter_status(slot, value);
342 
343 	if (retval < 0)
344 		*value = hotplug_slot->info->adapter_status;
345 
346 	return 0;
347 }
348 
get_max_bus_speed(struct hotplug_slot * hotplug_slot,enum pci_bus_speed * value)349 static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
350 {
351 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
352 	int retval;
353 
354 	if (slot == NULL)
355 		return -ENODEV;
356 
357 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
358 
359 	retval = slot->hpc_ops->get_max_bus_speed(slot, value);
360 	if (retval < 0)
361 		*value = PCI_SPEED_UNKNOWN;
362 
363 	return 0;
364 }
365 
get_cur_bus_speed(struct hotplug_slot * hotplug_slot,enum pci_bus_speed * value)366 static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
367 {
368 	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
369 	int retval;
370 
371 	if (slot == NULL)
372 		return -ENODEV;
373 
374 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
375 
376 	retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
377 	if (retval < 0)
378 		*value = PCI_SPEED_UNKNOWN;
379 
380 	return 0;
381 }
382 
pcie_probe(struct pci_dev * pdev,const struct pci_device_id * ent)383 static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
384 {
385 	int rc;
386 	struct controller *ctrl;
387 	struct slot *t_slot;
388 	int first_device_num = 0;	/* first PCI device number supported by this PCIE */
389 	int num_ctlr_slots;		/* number of slots supported by this HPC */
390 	u8 value;
391 
392 	ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
393 	if (!ctrl) {
394 		err("%s : out of memory\n", __FUNCTION__);
395 		goto err_out_none;
396 	}
397 	memset(ctrl, 0, sizeof(struct controller));
398 
399 	dbg("%s: DRV_thread pid = %d\n", __FUNCTION__, current->pid);
400 
401 	rc = pcie_init(ctrl, pdev,
402 		(php_intr_callback_t) pciehp_handle_attention_button,
403 		(php_intr_callback_t) pciehp_handle_switch_change,
404 		(php_intr_callback_t) pciehp_handle_presence_change,
405 		(php_intr_callback_t) pciehp_handle_power_fault);
406 	if (rc) {
407 		dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME);
408 		goto err_out_free_ctrl;
409 	}
410 
411 	ctrl->pci_dev = pdev;
412 
413 	ctrl->pci_bus = kmalloc (sizeof (*ctrl->pci_bus), GFP_KERNEL);
414 	if (!ctrl->pci_bus) {
415 		err("%s: out of memory\n", __FUNCTION__);
416 		rc = -ENOMEM;
417 		goto err_out_unmap_mmio_region;
418 	}
419 	dbg("%s: ctrl->pci_bus %p\n", __FUNCTION__, ctrl->pci_bus);
420 	memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
421 
422 	ctrl->bus = pdev->bus->number;  /* ctrl bus */
423 	ctrl->slot_bus = pdev->subordinate->number;  /* bus controlled by this HPC */
424 
425 	ctrl->device = PCI_SLOT(pdev->devfn);
426 	ctrl->function = PCI_FUNC(pdev->devfn);
427 	dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", __FUNCTION__,
428 		ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
429 
430 	/*
431 	 *	Save configuration headers for this and subordinate PCI buses
432 	 */
433 
434 	rc = get_ctlr_slot_config(ctrl);
435 	if (rc) {
436 		err(msg_initialization_err, rc);
437 		goto err_out_free_ctrl_bus;
438 	}
439 
440 	first_device_num = ctrl->slot_device_offset;
441 	num_ctlr_slots = ctrl->num_slots;
442 
443 
444 	/* Store PCI Config Space for all devices on this bus */
445 	dbg("%s: Before calling pciehp_save_config, ctrl->bus %x,ctrl->slot_bus %x\n",
446 		__FUNCTION__,ctrl->bus, ctrl->slot_bus);
447 	rc = pciehp_save_config(ctrl, ctrl->slot_bus, num_ctlr_slots, first_device_num);
448 	if (rc) {
449 		err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
450 		goto err_out_free_ctrl_bus;
451 	}
452 
453 	/* Get IO, memory, and IRQ resources for new devices */
454 	rc = pciehprm_find_available_resources(ctrl);
455 
456 	ctrl->add_support = !rc;
457 	if (rc) {
458 		dbg("pciehprm_find_available_resources = %#x\n", rc);
459 		err("unable to locate PCI configuration resources for hot plug add.\n");
460 		goto err_out_free_ctrl_bus;
461 	}
462 	/* Setup the slot information structures */
463 	rc = init_slots(ctrl);
464 	if (rc) {
465 		err(msg_initialization_err, 6);
466 		goto err_out_free_ctrl_slot;
467 	}
468 
469 	t_slot = pciehp_find_slot(ctrl, first_device_num);
470 	dbg("%s: t_slot %p\n", __FUNCTION__, t_slot);
471 
472 	/* Finish setting up the hot plug ctrl device */
473 	ctrl->next_event = 0;
474 
475 	if (!pciehp_ctrl_list) {
476 		pciehp_ctrl_list = ctrl;
477 		ctrl->next = NULL;
478 	} else {
479 		ctrl->next = pciehp_ctrl_list;
480 		pciehp_ctrl_list = ctrl;
481 	}
482 
483 	/* Wait for exclusive access to hardware */
484 	down(&ctrl->crit_sect);
485 
486 	t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
487 	dbg("%s: adapter value %x\n", __FUNCTION__, value);
488 	if (!value) {
489 		rc = t_slot->hpc_ops->power_off_slot(t_slot);  /* Power off slot if not occupied*/
490 		if (rc) {
491 			up(&ctrl->crit_sect);
492 			goto err_out_free_ctrl_slot;
493 		} else
494 			/* Wait for the command to complete */
495 			wait_for_ctrl_irq (ctrl);
496 		}
497 
498 	/* Done with exclusive hardware access */
499 	up(&ctrl->crit_sect);
500 
501 	return 0;
502 
503 err_out_free_ctrl_slot:
504 	cleanup_slots(ctrl);
505 err_out_free_ctrl_bus:
506 	kfree(ctrl->pci_bus);
507 err_out_unmap_mmio_region:
508 	ctrl->hpc_ops->release_ctlr(ctrl);
509 err_out_free_ctrl:
510 	kfree(ctrl);
511 err_out_none:
512 	return -ENODEV;
513 }
514 
515 
pcie_start_thread(void)516 static int pcie_start_thread(void)
517 {
518 	int loop;
519 	int retval = 0;
520 
521 	dbg("Initialize + Start the notification/polling mechanism \n");
522 
523 	retval = pciehp_event_start_thread();
524 	if (retval) {
525 		dbg("pciehp_event_start_thread() failed\n");
526 		return retval;
527 	}
528 
529 	dbg("Initialize slot lists\n");
530 	/* One slot list for each bus in the system */
531 	for (loop = 0; loop < 256; loop++) {
532 		pciehp_slot_list[loop] = NULL;
533 	}
534 
535 	return retval;
536 }
537 
538 
unload_pciehpd(void)539 static void unload_pciehpd(void)
540 {
541 	struct pci_func *next;
542 	struct pci_func *TempSlot;
543 	int loop;
544 	struct controller *ctrl;
545 	struct controller *tctrl;
546 	struct pci_resource *res;
547 	struct pci_resource *tres;
548 
549 	ctrl = pciehp_ctrl_list;
550 	while (ctrl) {
551 		cleanup_slots(ctrl);
552 
553 		res = ctrl->io_head;
554 		while (res) {
555 			tres = res;
556 			res = res->next;
557 			kfree(tres);
558 		}
559 
560 		res = ctrl->mem_head;
561 		while (res) {
562 			tres = res;
563 			res = res->next;
564 			kfree(tres);
565 		}
566 
567 		res = ctrl->p_mem_head;
568 		while (res) {
569 			tres = res;
570 			res = res->next;
571 			kfree(tres);
572 		}
573 
574 		res = ctrl->bus_head;
575 		while (res) {
576 			tres = res;
577 			res = res->next;
578 			kfree(tres);
579 		}
580 
581 		kfree (ctrl->pci_bus);
582 
583 		ctrl->hpc_ops->release_ctlr(ctrl);
584 
585 		tctrl = ctrl;
586 		ctrl = ctrl->next;
587 
588 		kfree(tctrl);
589 	}
590 
591 	for (loop = 0; loop < 256; loop++) {
592 		next = pciehp_slot_list[loop];
593 		while (next != NULL) {
594 			res = next->io_head;
595 			while (res) {
596 				tres = res;
597 				res = res->next;
598 				kfree(tres);
599 			}
600 
601 			res = next->mem_head;
602 			while (res) {
603 				tres = res;
604 				res = res->next;
605 				kfree(tres);
606 			}
607 
608 			res = next->p_mem_head;
609 			while (res) {
610 				tres = res;
611 				res = res->next;
612 				kfree(tres);
613 			}
614 
615 			res = next->bus_head;
616 			while (res) {
617 				tres = res;
618 				res = res->next;
619 				kfree(tres);
620 			}
621 
622 			TempSlot = next;
623 			next = next->next;
624 			kfree(TempSlot);
625 		}
626 	}
627 
628 	/* Stop the notification mechanism */
629 	pciehp_event_stop_thread();
630 
631 }
632 
633 
634 static struct pci_device_id pcied_pci_tbl[] __devinitdata = {
635 	{
636 	class:      	((PCI_CLASS_BRIDGE_PCI << 8) | 0x00),
637 	class_mask:	~0,
638 	vendor:		PCI_ANY_ID,
639 	device:     	PCI_ANY_ID,
640 	subvendor:   	PCI_ANY_ID,
641 	subdevice:    	PCI_ANY_ID,
642 	},
643 	{ /* end: all zeroes */ }
644 };
645 
646 MODULE_DEVICE_TABLE(pci, pcied_pci_tbl);
647 
648 
649 
650 static struct pci_driver pcie_driver = {
651 	.name		=	PCIE_MODULE_NAME,
652 	.id_table	=	pcied_pci_tbl,
653 	.probe		=	pcie_probe,
654 	/* remove:	pcie_remove_one, */
655 };
656 
657 
658 
pcied_init(void)659 static int __init pcied_init(void)
660 {
661 	int retval = 0;
662 
663 #ifdef CONFIG_HOTPLUG_PCI_PCIE_POLL_EVENT_MODE
664 	pciehp_poll_mode = 1;
665 #endif
666 	retval = pcie_start_thread();
667 	if (retval)
668 		goto error_hpc_init;
669 
670 	retval = pciehprm_init(PCI);
671 	if (!retval) {
672 		retval = pci_module_init(&pcie_driver);
673 		dbg("pci_module_init = %d\n", retval);
674 		info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
675 	}
676 
677 error_hpc_init:
678 	if (retval) {
679 		pciehprm_cleanup();
680 		pciehp_event_stop_thread();
681 	}
682 
683 	return retval;
684 }
685 
pcied_cleanup(void)686 static void __exit pcied_cleanup(void)
687 {
688 	dbg("unload_pciehpd()\n");
689 	unload_pciehpd();
690 
691 	pciehprm_cleanup();
692 
693 	dbg("pci_unregister_driver\n");
694 	pci_unregister_driver(&pcie_driver);
695 
696 	info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
697 }
698 
699 
700 module_init(pcied_init);
701 module_exit(pcied_cleanup);
702 
703 
704