ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / pci / hotplug / pciehp_core.c
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/workqueue.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.4"
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"
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
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
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
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  */
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         return 0;
244 }
245
246
247 static int enable_slot (struct hotplug_slot *hotplug_slot)
248 {
249         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
250         
251         if (slot == NULL)
252                 return -ENODEV;
253
254         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
255
256         return pciehp_enable_slot(slot);
257 }
258
259
260 static int disable_slot (struct hotplug_slot *hotplug_slot)
261 {
262         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
263         
264         if (slot == NULL)
265                 return -ENODEV;
266
267         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
268
269         return pciehp_disable_slot(slot);
270 }
271
272
273 static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value)
274 {
275         return 0;
276 }
277
278
279 static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
280 {
281         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
282         int retval;
283         
284         if (slot == NULL)
285                 return -ENODEV;
286         
287         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
288
289         retval = slot->hpc_ops->get_power_status(slot, value);
290         if (retval < 0)
291                 *value = hotplug_slot->info->power_status;
292
293         return 0;
294 }
295
296 static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
297 {
298         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
299         int retval;
300         
301         if (slot == NULL)
302                 return -ENODEV;
303         
304         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
305
306         retval = slot->hpc_ops->get_attention_status(slot, value);
307         if (retval < 0)
308                 *value = hotplug_slot->info->attention_status;
309
310         return 0;
311 }
312
313 static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
314 {
315         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
316         int retval;
317         
318         if (slot == NULL)
319                 return -ENODEV;
320         
321         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
322
323         retval = slot->hpc_ops->get_latch_status(slot, value);
324         if (retval < 0)
325                 *value = hotplug_slot->info->latch_status;
326
327         return 0;
328 }
329
330 static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
331 {
332         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
333         int retval;
334         
335         if (slot == NULL)
336                 return -ENODEV;
337
338         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
339
340         retval = slot->hpc_ops->get_adapter_status(slot, value);
341
342         if (retval < 0)
343                 *value = hotplug_slot->info->adapter_status;
344
345         return 0;
346 }
347
348 static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
349 {
350         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
351         int retval;
352         
353         if (slot == NULL)
354                 return -ENODEV;
355
356         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
357         
358         retval = slot->hpc_ops->get_max_bus_speed(slot, value);
359         if (retval < 0)
360                 *value = PCI_SPEED_UNKNOWN;
361
362         return 0;
363 }
364
365 static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
366 {
367         struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
368         int retval;
369         
370         if (slot == NULL)
371                 return -ENODEV;
372
373         dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
374         
375         retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
376         if (retval < 0)
377                 *value = PCI_SPEED_UNKNOWN;
378
379         return 0;
380 }
381
382 static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
383 {
384         int rc;
385         struct controller *ctrl;
386         struct slot *t_slot;
387         int first_device_num = 0 ;      /* first PCI device number supported by this PCIE */  
388         int num_ctlr_slots;             /* number of slots supported by this HPC */
389         u8 value;
390
391         ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
392         if (!ctrl) {
393                 err("%s : out of memory\n", __FUNCTION__);
394                 goto err_out_none;
395         }
396         memset(ctrl, 0, sizeof(struct controller));
397
398         dbg("%s: DRV_thread pid = %d\n", __FUNCTION__, current->pid);
399
400         rc = pcie_init(ctrl, pdev,
401                 (php_intr_callback_t) pciehp_handle_attention_button,
402                 (php_intr_callback_t) pciehp_handle_switch_change,
403                 (php_intr_callback_t) pciehp_handle_presence_change,
404                 (php_intr_callback_t) pciehp_handle_power_fault);
405         if (rc) {
406                 dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME);
407                 goto err_out_free_ctrl;
408         }
409
410         ctrl->pci_dev = pdev;
411
412         pci_set_drvdata(pdev, ctrl);
413
414         ctrl->pci_bus = kmalloc (sizeof (*ctrl->pci_bus), GFP_KERNEL);
415         if (!ctrl->pci_bus) {
416                 err("%s: out of memory\n", __FUNCTION__);
417                 rc = -ENOMEM;
418                 goto err_out_unmap_mmio_region;
419         }
420         dbg("%s: ctrl->pci_bus %p\n", __FUNCTION__, ctrl->pci_bus);
421         memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
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         first_device_num = ctrl->slot_device_offset;
440         num_ctlr_slots = ctrl->num_slots; 
441
442         /* Store PCI Config Space for all devices on this bus */
443         dbg("%s: Before calling pciehp_save_config, ctrl->bus %x,ctrl->slot_bus %x\n", 
444                 __FUNCTION__,ctrl->bus, ctrl->slot_bus);
445         rc = pciehp_save_config(ctrl, ctrl->slot_bus, num_ctlr_slots, first_device_num);
446         if (rc) {
447                 err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
448                 goto err_out_free_ctrl_bus;
449         }
450
451         /* Get IO, memory, and IRQ resources for new devices */
452         rc = pciehprm_find_available_resources(ctrl);
453         ctrl->add_support = !rc;
454         
455         if (rc) {
456                 dbg("pciehprm_find_available_resources = %#x\n", rc);
457                 err("unable to locate PCI configuration resources for hot plug add.\n");
458                 goto err_out_free_ctrl_bus;
459         }
460
461         /* Setup the slot information structures */
462         rc = init_slots(ctrl);
463         if (rc) {
464                 err(msg_initialization_err, 6);
465                 goto err_out_free_ctrl_slot;
466         }
467
468         t_slot = pciehp_find_slot(ctrl, first_device_num);
469         dbg("%s: t_slot %p\n", __FUNCTION__, t_slot);
470
471         /*      Finish setting up the hot plug ctrl device */
472         ctrl->next_event = 0;
473
474         if (!pciehp_ctrl_list) {
475                 pciehp_ctrl_list = ctrl;
476                 ctrl->next = NULL;
477         } else {
478                 ctrl->next = pciehp_ctrl_list;
479                 pciehp_ctrl_list = ctrl;
480         }
481
482         /* Wait for exclusive access to hardware */
483         down(&ctrl->crit_sect);
484
485         t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
486         dbg("%s: adpater value %x\n", __FUNCTION__, value);
487         if (!value) {
488                 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
489                 if (rc) {
490                         /* Done with exclusive hardware access */
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
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
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
551         while (ctrl) {
552                 cleanup_slots(ctrl);
553
554                 res = ctrl->io_head;
555                 while (res) {
556                         tres = res;
557                         res = res->next;
558                         kfree(tres);
559                 }
560
561                 res = ctrl->mem_head;
562                 while (res) {
563                         tres = res;
564                         res = res->next;
565                         kfree(tres);
566                 }
567
568                 res = ctrl->p_mem_head;
569                 while (res) {
570                         tres = res;
571                         res = res->next;
572                         kfree(tres);
573                 }
574
575                 res = ctrl->bus_head;
576                 while (res) {
577                         tres = res;
578                         res = res->next;
579                         kfree(tres);
580                 }
581
582                 kfree (ctrl->pci_bus);
583
584                 ctrl->hpc_ops->release_ctlr(ctrl);
585
586                 tctrl = ctrl;
587                 ctrl = ctrl->next;
588
589                 kfree(tctrl);
590         }
591
592         for (loop = 0; loop < 256; loop++) {
593                 next = pciehp_slot_list[loop];
594                 while (next != NULL) {
595                         res = next->io_head;
596                         while (res) {
597                                 tres = res;
598                                 res = res->next;
599                                 kfree(tres);
600                         }
601
602                         res = next->mem_head;
603                         while (res) {
604                                 tres = res;
605                                 res = res->next;
606                                 kfree(tres);
607                         }
608
609                         res = next->p_mem_head;
610                         while (res) {
611                                 tres = res;
612                                 res = res->next;
613                                 kfree(tres);
614                         }
615
616                         res = next->bus_head;
617                         while (res) {
618                                 tres = res;
619                                 res = res->next;
620                                 kfree(tres);
621                         }
622
623                         TempSlot = next;
624                         next = next->next;
625                         kfree(TempSlot);
626                 }
627         }
628
629         /* Stop the notification mechanism */
630         pciehp_event_stop_thread();
631
632 }
633
634
635 static struct pci_device_id pcied_pci_tbl[] = {
636         {
637         .class =        ((PCI_CLASS_BRIDGE_PCI << 8) | 0x00),
638         .class_mask =   ~0,
639         .vendor =       PCI_ANY_ID,
640         .device =       PCI_ANY_ID,
641         .subvendor =    PCI_ANY_ID,
642         .subdevice =    PCI_ANY_ID,
643         },
644         
645         { /* end: all zeroes */ }
646 };
647
648 MODULE_DEVICE_TABLE(pci, pcied_pci_tbl);
649
650
651
652 static struct pci_driver pcie_driver = {
653         .name           =       PCIE_MODULE_NAME,
654         .id_table       =       pcied_pci_tbl,
655         .probe          =       pcie_probe,
656         /* remove:      pcie_remove_one, */
657 };
658
659
660
661 static int __init pcied_init(void)
662 {
663         int retval = 0;
664
665 #ifdef CONFIG_HOTPLUG_PCI_PCIE_POLL_EVENT_MODE
666         pciehp_poll_mode = 1;
667 #endif
668
669         retval = pcie_start_thread();
670         if (retval)
671                 goto error_hpc_init;
672
673         retval = pciehprm_init(PCI);
674         if (!retval) {
675                 retval = pci_module_init(&pcie_driver);
676                 dbg("pci_module_init = %d\n", retval);
677                 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
678         }
679
680 error_hpc_init:
681         if (retval) {
682                 pciehprm_cleanup();
683                 pciehp_event_stop_thread();
684         } else
685                 pciehprm_print_pirt();
686
687         return retval;
688 }
689
690 static void __exit pcied_cleanup(void)
691 {
692         dbg("unload_pciehpd()\n");
693         unload_pciehpd();
694
695         pciehprm_cleanup();
696
697         dbg("pci_unregister_driver\n");
698         pci_unregister_driver(&pcie_driver);
699
700         info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
701 }
702
703
704 module_init(pcied_init);
705 module_exit(pcied_cleanup);
706
707