upgrade to fedora-2.6.12-1.1398.FC4 + vserver 2.0.rc7
[linux-2.6.git] / drivers / pci / hotplug / pciehp_core.c
index cb8569e..df4915d 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
-#include <linux/miscdevice.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 #include <linux/pci.h>
@@ -41,6 +40,7 @@
 #include <asm/uaccess.h>
 #include "pciehp.h"
 #include "pciehprm.h"
+#include <linux/interrupt.h>
 
 /* Global variables */
 int pciehp_debug;
@@ -90,6 +90,22 @@ static struct hotplug_slot_ops pciehp_hotplug_slot_ops = {
        .get_cur_bus_speed =    get_cur_bus_speed,
 };
 
+/**
+ * release_slot - free up the memory used by a slot
+ * @hotplug_slot: slot to free
+ */
+static void release_slot(struct hotplug_slot *hotplug_slot)
+{
+       struct slot *slot = hotplug_slot->private;
+
+       dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+
+       kfree(slot->hotplug_slot->info);
+       kfree(slot->hotplug_slot->name);
+       kfree(slot->hotplug_slot);
+       kfree(slot);
+}
+
 static int init_slots(struct controller *ctrl)
 {
        struct slot *new_slot;
@@ -139,7 +155,8 @@ static int init_slots(struct controller *ctrl)
 
                /* register this slot with the hotplug pci core */
                new_slot->hotplug_slot->private = new_slot;
-               make_slot_name (new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
+               new_slot->hotplug_slot->release = &release_slot;
+               make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
                new_slot->hotplug_slot->ops = &pciehp_hotplug_slot_ops;
 
                new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status));
@@ -188,10 +205,6 @@ static int cleanup_slots (struct controller * ctrl)
        while (old_slot) {
                next_slot = old_slot->next;
                pci_hp_deregister (old_slot->hotplug_slot);
-               kfree(old_slot->hotplug_slot->info);
-               kfree(old_slot->hotplug_slot->name);
-               kfree(old_slot->hotplug_slot);
-               kfree(old_slot);
                old_slot = next_slot;
        }
 
@@ -347,7 +360,7 @@ static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
        return 0;
 }
 
-static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_id *id)
 {
        int rc;
        struct controller *ctrl;
@@ -355,7 +368,9 @@ static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        int first_device_num = 0 ;      /* first PCI device number supported by this PCIE */  
        int num_ctlr_slots;             /* number of slots supported by this HPC */
        u8 value;
-
+       struct pci_dev *pdev;
+       
+       dbg("%s: Called by hp_drv\n", __FUNCTION__);
        ctrl = kmalloc(sizeof(*ctrl), GFP_KERNEL);
        if (!ctrl) {
                err("%s : out of memory\n", __FUNCTION__);
@@ -364,8 +379,10 @@ static int pcie_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        memset(ctrl, 0, sizeof(struct controller));
 
        dbg("%s: DRV_thread pid = %d\n", __FUNCTION__, current->pid);
+       
+       pdev = dev->port;
 
-       rc = pcie_init(ctrl, pdev,
+       rc = pcie_init(ctrl, dev,
                (php_intr_callback_t) pciehp_handle_attention_button,
                (php_intr_callback_t) pciehp_handle_switch_change,
                (php_intr_callback_t) pciehp_handle_presence_change,
@@ -563,32 +580,52 @@ static void __exit unload_pciehpd(void)
 
 }
 
+int hpdriver_context = 0;
 
-static struct pci_device_id pcied_pci_tbl[] = {
-       {
-       .class =        ((PCI_CLASS_BRIDGE_PCI << 8) | 0x00),
-       .class_mask =   ~0,
-       .vendor =       PCI_ANY_ID,
-       .device =       PCI_ANY_ID,
-       .subvendor =    PCI_ANY_ID,
-       .subdevice =    PCI_ANY_ID,
-       },
-       
-       { /* end: all zeroes */ }
-};
-
-MODULE_DEVICE_TABLE(pci, pcied_pci_tbl);
+static void pciehp_remove (struct pcie_device *device)
+{
+       printk("%s ENTRY\n", __FUNCTION__);     
+       printk("%s -> Call free_irq for irq = %d\n",  
+               __FUNCTION__, device->irq);
+       free_irq(device->irq, &hpdriver_context);
+}
 
+#ifdef CONFIG_PM
+static int pciehp_suspend (struct pcie_device *dev, pm_message_t state)
+{
+       printk("%s ENTRY\n", __FUNCTION__);     
+       return 0;
+}
 
+static int pciehp_resume (struct pcie_device *dev)
+{
+       printk("%s ENTRY\n", __FUNCTION__);     
+       return 0;
+}
+#endif
 
-static struct pci_driver pcie_driver = {
-       .name           =       PCIE_MODULE_NAME,
-       .id_table       =       pcied_pci_tbl,
-       .probe          =       pcie_probe,
-       /* remove:      pcie_remove_one, */
+static struct pcie_port_service_id port_pci_ids[] = { { 
+       .vendor = PCI_ANY_ID, 
+       .device = PCI_ANY_ID,
+       .port_type = PCIE_ANY_PORT,
+       .service_type = PCIE_PORT_SERVICE_HP,
+       .driver_data =  0, 
+       }, { /* end: all zeroes */ }
 };
+static const char device_name[] = "hpdriver";
+
+static struct pcie_port_service_driver hpdriver_portdrv = {
+       .name           = (char *)device_name,
+       .id_table       = &port_pci_ids[0],
 
+       .probe          = pciehp_probe,
+       .remove         = pciehp_remove,
 
+#ifdef CONFIG_PM
+       .suspend        = pciehp_suspend,
+       .resume         = pciehp_resume,
+#endif /* PM */
+};
 
 static int __init pcied_init(void)
 {
@@ -604,9 +641,11 @@ static int __init pcied_init(void)
 
        retval = pciehprm_init(PCI);
        if (!retval) {
-               retval = pci_register_driver(&pcie_driver);
-               dbg("pci_register_driver = %d\n", retval);
-               info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
+               retval = pcie_port_service_register(&hpdriver_portdrv);
+               dbg("pcie_port_service_register = %d\n", retval);
+               info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
+               if (retval)
+                  dbg("%s: Failure to register service\n", __FUNCTION__);
        }
 
 error_hpc_init:
@@ -626,8 +665,8 @@ static void __exit pcied_cleanup(void)
 
        pciehprm_cleanup();
 
-       dbg("pci_unregister_driver\n");
-       pci_unregister_driver(&pcie_driver);
+       dbg("pcie_port_service_unregister\n");
+       pcie_port_service_unregister(&hpdriver_portdrv);
 
        info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
 }