[PATCH] 64bit resource: fix up printks for resources in pci core and hotplug drivers
[linux-2.6.git] / drivers / pci / hotplug / cpqphp_core.c
index 9aed8ef..f8658d6 100644 (file)
@@ -327,7 +327,9 @@ static int ctrl_slot_setup(struct controller *ctrl,
                        void __iomem *smbios_start,
                        void __iomem *smbios_table)
 {
-       struct slot *new_slot;
+       struct slot *slot;
+       struct hotplug_slot *hotplug_slot;
+       struct hotplug_slot_info *hotplug_slot_info;
        u8 number_of_slots;
        u8 slot_device;
        u8 slot_number;
@@ -345,93 +347,101 @@ static int ctrl_slot_setup(struct controller *ctrl,
        slot_number = ctrl->first_slot;
 
        while (number_of_slots) {
-               new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL);
-               if (!new_slot)
+               slot = kzalloc(sizeof(*slot), GFP_KERNEL);
+               if (!slot)
                        goto error;
 
-               memset(new_slot, 0, sizeof(struct slot));
-               new_slot->hotplug_slot = kmalloc(sizeof(*(new_slot->hotplug_slot)),
+               slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
                                                GFP_KERNEL);
-               if (!new_slot->hotplug_slot)
+               if (!slot->hotplug_slot)
                        goto error_slot;
-               memset(new_slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
+               hotplug_slot = slot->hotplug_slot;
 
-               new_slot->hotplug_slot->info =
-                               kmalloc(sizeof(*(new_slot->hotplug_slot->info)),
+               hotplug_slot->info =
+                               kzalloc(sizeof(*(hotplug_slot->info)),
                                                        GFP_KERNEL);
-               if (!new_slot->hotplug_slot->info)
+               if (!hotplug_slot->info)
                        goto error_hpslot;
-               memset(new_slot->hotplug_slot->info, 0,
-                               sizeof(struct hotplug_slot_info));
-               new_slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
-               if (!new_slot->hotplug_slot->name)
+               hotplug_slot_info = hotplug_slot->info;
+               hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
+
+               if (!hotplug_slot->name)
                        goto error_info;
 
-               new_slot->ctrl = ctrl;
-               new_slot->bus = ctrl->bus;
-               new_slot->device = slot_device;
-               new_slot->number = slot_number;
-               dbg("slot->number = %d\n",new_slot->number);
+               slot->ctrl = ctrl;
+               slot->bus = ctrl->bus;
+               slot->device = slot_device;
+               slot->number = slot_number;
+               dbg("slot->number = %d\n", slot->number);
 
                slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
                                        slot_entry);
 
-               while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) != new_slot->number)) {
+               while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) !=
+                               slot->number)) {
                        slot_entry = get_SMBIOS_entry(smbios_start,
                                                smbios_table, 9, slot_entry);
                }
 
-               new_slot->p_sm_slot = slot_entry;
+               slot->p_sm_slot = slot_entry;
 
-               init_timer(&new_slot->task_event);
-               new_slot->task_event.expires = jiffies + 5 * HZ;
-               new_slot->task_event.function = cpqhp_pushbutton_thread;
+               init_timer(&slot->task_event);
+               slot->task_event.expires = jiffies + 5 * HZ;
+               slot->task_event.function = cpqhp_pushbutton_thread;
 
                //FIXME: these capabilities aren't used but if they are
                //       they need to be correctly implemented
-               new_slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
-               new_slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
+               slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
+               slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
 
-               if (is_slot64bit(new_slot))
-                       new_slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
-               if (is_slot66mhz(new_slot))
-                       new_slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
+               if (is_slot64bit(slot))
+                       slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
+               if (is_slot66mhz(slot))
+                       slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
                if (ctrl->speed == PCI_SPEED_66MHz)
-                       new_slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
+                       slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
 
-               ctrl_slot = slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
+               ctrl_slot =
+                       slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
 
                // Check presence
-               new_slot->capabilities |= ((((~tempdword) >> 23) | ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
+               slot->capabilities |=
+                       ((((~tempdword) >> 23) |
+                        ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
                // Check the switch state
-               new_slot->capabilities |= ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
+               slot->capabilities |=
+                       ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
                // Check the slot enable
-               new_slot->capabilities |= ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
+               slot->capabilities |=
+                       ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
 
                /* register this slot with the hotplug pci core */
-               new_slot->hotplug_slot->release = &release_slot;
-               new_slot->hotplug_slot->private = new_slot;
-               make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
-               new_slot->hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
+               hotplug_slot->release = &release_slot;
+               hotplug_slot->private = slot;
+               make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot);
+               hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
                
-               new_slot->hotplug_slot->info->power_status = get_slot_enabled(ctrl, new_slot);
-               new_slot->hotplug_slot->info->attention_status = cpq_get_attention_status(ctrl, new_slot);
-               new_slot->hotplug_slot->info->latch_status = cpq_get_latch_status(ctrl, new_slot);
-               new_slot->hotplug_slot->info->adapter_status = get_presence_status(ctrl, new_slot);
+               hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
+               hotplug_slot_info->attention_status =
+                       cpq_get_attention_status(ctrl, slot);
+               hotplug_slot_info->latch_status =
+                       cpq_get_latch_status(ctrl, slot);
+               hotplug_slot_info->adapter_status =
+                       get_presence_status(ctrl, slot);
                
-               dbg ("registering bus %d, dev %d, number %d, "
+               dbg("registering bus %d, dev %d, number %d, "
                                "ctrl->slot_device_offset %d, slot %d\n",
-                               new_slot->bus, new_slot->device,
-                               new_slot->number, ctrl->slot_device_offset,
+                               slot->bus, slot->device,
+                               slot->number, ctrl->slot_device_offset,
                                slot_number);
-               result = pci_hp_register (new_slot->hotplug_slot);
+               result = pci_hp_register(hotplug_slot);
                if (result) {
-                       err ("pci_hp_register failed with error %d\n", result);
+                       err("pci_hp_register failed with error %d\n", result);
                        goto error_name;
                }
                
-               new_slot->next = ctrl->slot;
-               ctrl->slot = new_slot;
+               slot->next = ctrl->slot;
+               ctrl->slot = slot;
 
                number_of_slots--;
                slot_device++;
@@ -439,15 +449,14 @@ static int ctrl_slot_setup(struct controller *ctrl,
        }
 
        return 0;
-
 error_name:
-       kfree(new_slot->hotplug_slot->name);
+       kfree(hotplug_slot->name);
 error_info:
-       kfree(new_slot->hotplug_slot->info);
+       kfree(hotplug_slot_info);
 error_hpslot:
-       kfree(new_slot->hotplug_slot);
+       kfree(hotplug_slot);
 error_slot:
-       kfree(new_slot);
+       kfree(slot);
 error:
        return result;
 }
@@ -466,6 +475,8 @@ static int ctrl_slot_cleanup (struct controller * ctrl)
                old_slot = next_slot;
        }
 
+       cpqhp_remove_debugfs_files(ctrl);
+
        //Free IRQ associated with hot plug device
        free_irq(ctrl->interrupt, ctrl);
        //Unmap the memory
@@ -584,7 +595,7 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
        hp_slot = func->device - ctrl->slot_device_offset;
 
        // Wait for exclusive access to hardware
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        if (status == 1) {
                amber_LED_on (ctrl, hp_slot);
@@ -592,7 +603,7 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
                amber_LED_off (ctrl, hp_slot);
        } else {
                // Done with exclusive hardware access
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
                return(1);
        }
 
@@ -602,7 +613,7 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
        wait_for_ctrl_irq (ctrl);
 
        // Done with exclusive hardware access
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 
        return(0);
 }
@@ -839,13 +850,12 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                        goto err_disable_device;
                }
 
-               ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
+               ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
                if (!ctrl) {
                        err("%s : out of memory\n", __FUNCTION__);
                        rc = -ENOMEM;
                        goto err_disable_device;
                }
-               memset(ctrl, 0, sizeof(struct controller));
 
                rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
                if (rc) {
@@ -1069,7 +1079,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
                PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
 
-       init_MUTEX(&ctrl->crit_sect);
+       mutex_init(&ctrl->crit_sect);
        init_waitqueue_head(&ctrl->queue);
 
        /* initialize our threads if they haven't already been started up */
@@ -1079,8 +1089,8 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
        
        dbg("pdev = %p\n", pdev);
-       dbg("pci resource start %lx\n", pci_resource_start(pdev, 0));
-       dbg("pci resource len %lx\n", pci_resource_len(pdev, 0));
+       dbg("pci resource start %llx\n", (unsigned long long)pci_resource_start(pdev, 0));
+       dbg("pci resource len %llx\n", (unsigned long long)pci_resource_len(pdev, 0));
 
        if (!request_mem_region(pci_resource_start(pdev, 0),
                                pci_resource_len(pdev, 0), MY_NAME)) {
@@ -1092,9 +1102,9 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0),
                                        pci_resource_len(pdev, 0));
        if (!ctrl->hpc_reg) {
-               err("cannot remap MMIO region %lx @ %lx\n",
-                               pci_resource_len(pdev, 0),
-                               pci_resource_start(pdev, 0));
+               err("cannot remap MMIO region %llx @ %llx\n",
+                   (unsigned long long)pci_resource_len(pdev, 0),
+                   (unsigned long long)pci_resource_start(pdev, 0));
                rc = -ENODEV;
                goto err_free_mem_region;
        }
@@ -1208,7 +1218,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        // turn off empty slots here unless command line option "ON" set
        // Wait for exclusive access to hardware
-       down(&ctrl->crit_sect);
+       mutex_lock(&ctrl->crit_sect);
 
        num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
 
@@ -1255,14 +1265,14 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        rc = init_SERR(ctrl);
        if (rc) {
                err("init_SERR failed\n");
-               up(&ctrl->crit_sect);
+               mutex_unlock(&ctrl->crit_sect);
                goto err_free_irq;
        }
 
        // Done with exclusive hardware access
-       up(&ctrl->crit_sect);
+       mutex_unlock(&ctrl->crit_sect);
 
-       cpqhp_create_ctrl_files(ctrl);
+       cpqhp_create_debugfs_files(ctrl);
 
        return 0;
 
@@ -1502,6 +1512,7 @@ static int __init cpqhpc_init(void)
        cpqhp_debug = debug;
 
        info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
+       cpqhp_initialize_debugfs();
        result = pci_register_driver(&cpqhpc_driver);
        dbg("pci_register_driver = %d\n", result);
        return result;
@@ -1515,6 +1526,7 @@ static void __exit cpqhpc_cleanup(void)
 
        dbg("pci_unregister_driver\n");
        pci_unregister_driver(&cpqhpc_driver);
+       cpqhp_shutdown_debugfs();
 }