[IA64] Provide ACPI fixup for /proc/cpuinfo/physical_id
[safe/jmp/linux-2.6] / drivers / acpi / processor_core.c
index 7aefb7c..5241e3f 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/seq_file.h>
 #include <linux/dmi.h>
 #include <linux/moduleparam.h>
+#include <linux/cpuidle.h>
 
 #include <asm/io.h>
 #include <asm/system.h>
@@ -88,14 +89,22 @@ static int acpi_processor_handle_eject(struct acpi_processor *pr);
 extern int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
 
 
+static const struct acpi_device_id processor_device_ids[] = {
+       {ACPI_PROCESSOR_HID, 0},
+       {"", 0},
+};
+MODULE_DEVICE_TABLE(acpi, processor_device_ids);
+
 static struct acpi_driver acpi_processor_driver = {
        .name = "processor",
        .class = ACPI_PROCESSOR_CLASS,
-       .ids = ACPI_PROCESSOR_HID,
+       .ids = processor_device_ids,
        .ops = {
                .add = acpi_processor_add,
                .remove = acpi_processor_remove,
                .start = acpi_processor_start,
+               .suspend = acpi_processor_suspend,
+               .resume = acpi_processor_resume,
                },
 };
 
@@ -103,6 +112,7 @@ static struct acpi_driver acpi_processor_driver = {
 #define UNINSTALL_NOTIFY_HANDLER       2
 
 static const struct file_operations acpi_processor_info_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_processor_info_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -118,7 +128,6 @@ struct acpi_processor_errata errata __read_mostly;
 
 static int acpi_processor_errata_piix4(struct pci_dev *dev)
 {
-       u8 rev = 0;
        u8 value1 = 0;
        u8 value2 = 0;
 
@@ -130,9 +139,7 @@ static int acpi_processor_errata_piix4(struct pci_dev *dev)
         * Note that 'dev' references the PIIX4 ACPI Controller.
         */
 
-       pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
-
-       switch (rev) {
+       switch (dev->revision) {
        case 0:
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
                break;
@@ -150,7 +157,7 @@ static int acpi_processor_errata_piix4(struct pci_dev *dev)
                break;
        }
 
-       switch (rev) {
+       switch (dev->revision) {
 
        case 0:         /* PIIX4 A-step */
        case 1:         /* PIIX4 B-step */
@@ -320,40 +327,30 @@ static int acpi_processor_add_fs(struct acpi_device *device)
        acpi_device_dir(device)->owner = THIS_MODULE;
 
        /* 'info' [R] */
-       entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO,
-                                 S_IRUGO, acpi_device_dir(device));
+       entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO,
+                                S_IRUGO, acpi_device_dir(device),
+                                &acpi_processor_info_fops,
+                                acpi_driver_data(device));
        if (!entry)
                return -EIO;
-       else {
-               entry->proc_fops = &acpi_processor_info_fops;
-               entry->data = acpi_driver_data(device);
-               entry->owner = THIS_MODULE;
-       }
 
        /* 'throttling' [R/W] */
-       entry = create_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
-                                 S_IFREG | S_IRUGO | S_IWUSR,
-                                 acpi_device_dir(device));
+       entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING,
+                                S_IFREG | S_IRUGO | S_IWUSR,
+                                acpi_device_dir(device),
+                                &acpi_processor_throttling_fops,
+                                acpi_driver_data(device));
        if (!entry)
                return -EIO;
-       else {
-               entry->proc_fops = &acpi_processor_throttling_fops;
-               entry->data = acpi_driver_data(device);
-               entry->owner = THIS_MODULE;
-       }
 
        /* 'limit' [R/W] */
-       entry = create_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
-                                 S_IFREG | S_IRUGO | S_IWUSR,
-                                 acpi_device_dir(device));
+       entry = proc_create_data(ACPI_PROCESSOR_FILE_LIMIT,
+                                S_IFREG | S_IRUGO | S_IWUSR,
+                                acpi_device_dir(device),
+                                &acpi_processor_limit_fops,
+                                acpi_driver_data(device));
        if (!entry)
                return -EIO;
-       else {
-               entry->proc_fops = &acpi_processor_limit_fops;
-               entry->data = acpi_driver_data(device);
-               entry->owner = THIS_MODULE;
-       }
-
        return 0;
 }
 
@@ -416,12 +413,6 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
        return 0;
 }
 
-#ifdef CONFIG_IA64
-#define arch_cpu_to_apicid     ia64_cpu_to_sapicid
-#else
-#define arch_cpu_to_apicid     x86_cpu_to_apicid
-#endif
-
 static int map_madt_entry(u32 acpi_id)
 {
        unsigned long madt_end, entry;
@@ -494,8 +485,8 @@ static int get_cpu_id(acpi_handle handle, u32 acpi_id)
        if (apic_id == -1)
                return apic_id;
 
-       for (i = 0; i < NR_CPUS; ++i) {
-               if (arch_cpu_to_apicid[i] == apic_id)
+       for_each_possible_cpu(i) {
+               if (cpu_physical_id(i) == apic_id)
                        return i;
        }
        return -1;
@@ -612,11 +603,14 @@ static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
                request_region(pr->throttling.address, 6, "ACPI CPU throttle");
        }
 
-#ifdef CONFIG_CPU_FREQ
-       acpi_processor_ppc_has_changed(pr);
-#endif
-       acpi_processor_get_throttling_info(pr);
-       acpi_processor_get_limit_info(pr);
+       /*
+        * If ACPI describes a slot number for this CPU, we can use it
+        * ensure we get the right value in the "physical id" field
+        * of /proc/cpuinfo
+        */
+       status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
+       if (ACPI_SUCCESS(status))
+               arch_fix_phys_package_id(pr->id, object.integer.value);
 
        return 0;
 }
@@ -638,7 +632,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
                return 0;
        }
 
-       BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0));
+       BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
 
        /*
         * Buggy BIOS check
@@ -647,7 +641,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
         */
        if (processor_device_array[pr->id] != NULL &&
            processor_device_array[pr->id] != device) {
-               printk(KERN_WARNING "BIOS reported wrong ACPI id"
+               printk(KERN_WARNING "BIOS reported wrong ACPI id "
                        "for the processor\n");
                return -ENODEV;
        }
@@ -665,9 +659,38 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
        /* _PDC call should be done before doing anything else (if reqd.). */
        arch_acpi_processor_init_pdc(pr);
        acpi_processor_set_pdc(pr);
+#ifdef CONFIG_CPU_FREQ
+       acpi_processor_ppc_has_changed(pr);
+#endif
+       acpi_processor_get_throttling_info(pr);
+       acpi_processor_get_limit_info(pr);
+
 
        acpi_processor_power_init(pr, device);
 
+       pr->cdev = thermal_cooling_device_register("Processor", device,
+                                               &processor_cooling_ops);
+       if (IS_ERR(pr->cdev)) {
+               result = PTR_ERR(pr->cdev);
+               goto end;
+       }
+       if (pr->cdev) {
+               printk(KERN_INFO PREFIX
+                       "%s is registered as cooling_device%d\n",
+                       device->dev.bus_id, pr->cdev->id);
+
+               result = sysfs_create_link(&device->dev.kobj,
+                                          &pr->cdev->device.kobj,
+                                          "thermal_cooling");
+               if (result)
+                       return result;
+               result = sysfs_create_link(&pr->cdev->device.kobj,
+                                          &device->dev.kobj,
+                                          "device");
+               if (result)
+                       return result;
+       }
+
        if (pr->flags.throttling) {
                printk(KERN_INFO PREFIX "%s [%s] (supports",
                       acpi_device_name(device), acpi_device_bid(device));
@@ -684,7 +707,7 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
 {
        struct acpi_processor *pr = data;
        struct acpi_device *device = NULL;
-
+       int saved;
 
        if (!pr)
                return;
@@ -694,17 +717,27 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
 
        switch (event) {
        case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
+               saved = pr->performance_platform_limit;
                acpi_processor_ppc_has_changed(pr);
-               acpi_bus_generate_event(device, event,
+               if (saved == pr->performance_platform_limit)
+                       break;
+               acpi_bus_generate_proc_event(device, event,
                                        pr->performance_platform_limit);
+               acpi_bus_generate_netlink_event(device->pnp.device_class,
+                                                 device->dev.bus_id, event,
+                                                 pr->performance_platform_limit);
                break;
        case ACPI_PROCESSOR_NOTIFY_POWER:
                acpi_processor_cst_has_changed(pr);
-               acpi_bus_generate_event(device, event, 0);
+               acpi_bus_generate_proc_event(device, event, 0);
+               acpi_bus_generate_netlink_event(device->pnp.device_class,
+                                                 device->dev.bus_id, event, 0);
                break;
        case ACPI_PROCESSOR_NOTIFY_THROTTLING:
                acpi_processor_tstate_has_changed(pr);
-               acpi_bus_generate_event(device, event, 0);
+               acpi_bus_generate_proc_event(device, event, 0);
+               acpi_bus_generate_netlink_event(device->pnp.device_class,
+                                                 device->dev.bus_id, event, 0);
        default:
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                  "Unsupported event [0x%x]\n", event));
@@ -714,6 +747,25 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
        return;
 }
 
+static int acpi_cpu_soft_notify(struct notifier_block *nfb,
+               unsigned long action, void *hcpu)
+{
+       unsigned int cpu = (unsigned long)hcpu;
+       struct acpi_processor *pr = processors[cpu];
+
+       if (action == CPU_ONLINE && pr) {
+               acpi_processor_ppc_has_changed(pr);
+               acpi_processor_cst_has_changed(pr);
+               acpi_processor_tstate_has_changed(pr);
+       }
+       return NOTIFY_OK;
+}
+
+static struct notifier_block acpi_cpu_notifier =
+{
+           .notifier_call = acpi_cpu_soft_notify,
+};
+
 static int acpi_processor_add(struct acpi_device *device)
 {
        struct acpi_processor *pr = NULL;
@@ -745,7 +797,7 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
 
        pr = acpi_driver_data(device);
 
-       if (pr->id >= NR_CPUS) {
+       if (pr->id >= nr_cpu_ids) {
                kfree(pr);
                return 0;
        }
@@ -762,8 +814,15 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
 
        acpi_processor_remove_fs(device);
 
-       processors[pr->id] = NULL;
+       if (pr->cdev) {
+               sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
+               sysfs_remove_link(&pr->cdev->device.kobj, "device");
+               thermal_cooling_device_unregister(pr->cdev);
+               pr->cdev = NULL;
+       }
 
+       processors[pr->id] = NULL;
+       processor_device_array[pr->id] = NULL;
        kfree(pr);
 
        return 0;
@@ -774,8 +833,6 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
  *     Acpi processor hotplug support                                      *
  ****************************************************************************/
 
-static int is_processor_present(acpi_handle handle);
-
 static int is_processor_present(acpi_handle handle)
 {
        acpi_status status;
@@ -783,11 +840,20 @@ static int is_processor_present(acpi_handle handle)
 
 
        status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
-       if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) {
-               ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present"));
-               return 0;
-       }
-       return 1;
+
+       if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
+               return 1;
+
+       /*
+        * _STA is mandatory for a processor that supports hot plug
+        */
+       if (status == AE_NOT_FOUND)
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                               "Processor does not support hot plug\n"));
+       else
+               ACPI_EXCEPTION((AE_INFO, status,
+                               "Processor Device is not present"));
+       return 0;
 }
 
 static
@@ -816,14 +882,14 @@ int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
        if (!pr)
                return -ENODEV;
 
-       if ((pr->id >= 0) && (pr->id < NR_CPUS)) {
+       if ((pr->id >= 0) && (pr->id < nr_cpu_ids)) {
                kobject_uevent(&(*device)->dev.kobj, KOBJ_ONLINE);
        }
        return 0;
 }
 
-static void
-acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
+static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
+                                               u32 event, void *data)
 {
        struct acpi_processor *pr;
        struct acpi_device *device = NULL;
@@ -833,9 +899,10 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
        switch (event) {
        case ACPI_NOTIFY_BUS_CHECK:
        case ACPI_NOTIFY_DEVICE_CHECK:
-               printk("Processor driver received %s event\n",
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+               "Processor driver received %s event\n",
                       (event == ACPI_NOTIFY_BUS_CHECK) ?
-                      "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK");
+                      "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
 
                if (!is_processor_present(handle))
                        break;
@@ -854,13 +921,13 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
                        break;
                }
 
-               if (pr->id >= 0 && (pr->id < NR_CPUS)) {
+               if (pr->id >= 0 && (pr->id < nr_cpu_ids)) {
                        kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
                        break;
                }
 
                result = acpi_processor_start(device);
-               if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) {
+               if ((!result) && ((pr->id >= 0) && (pr->id < nr_cpu_ids))) {
                        kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
                } else {
                        printk(KERN_ERR PREFIX "Device [%s] failed to start\n",
@@ -883,7 +950,7 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
                        return;
                }
 
-               if ((pr->id < NR_CPUS) && (cpu_present(pr->id)))
+               if ((pr->id < nr_cpu_ids) && (cpu_present(pr->id)))
                        kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
                break;
        default:
@@ -977,6 +1044,7 @@ void acpi_processor_install_hotplug_notify(void)
                            ACPI_UINT32_MAX,
                            processor_walk_namespace_cb, &action, NULL);
 #endif
+       register_hotcpu_notifier(&acpi_cpu_notifier);
 }
 
 static
@@ -989,6 +1057,7 @@ void acpi_processor_uninstall_hotplug_notify(void)
                            ACPI_UINT32_MAX,
                            processor_walk_namespace_cb, &action, NULL);
 #endif
+       unregister_hotcpu_notifier(&acpi_cpu_notifier);
 }
 
 /*
@@ -1016,11 +1085,13 @@ static int __init acpi_processor_init(void)
                return -ENOMEM;
        acpi_processor_dir->owner = THIS_MODULE;
 
+       result = cpuidle_register_driver(&acpi_idle_driver);
+       if (result < 0)
+               goto out_proc;
+
        result = acpi_bus_register_driver(&acpi_processor_driver);
-       if (result < 0) {
-               remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
-               return result;
-       }
+       if (result < 0)
+               goto out_cpuidle;
 
        acpi_processor_install_hotplug_notify();
 
@@ -1028,12 +1099,21 @@ static int __init acpi_processor_init(void)
 
        acpi_processor_ppc_init();
 
+       acpi_processor_throttling_init();
+
        return 0;
+
+out_cpuidle:
+       cpuidle_unregister_driver(&acpi_idle_driver);
+
+out_proc:
+       remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
+
+       return result;
 }
 
 static void __exit acpi_processor_exit(void)
 {
-
        acpi_processor_ppc_exit();
 
        acpi_thermal_cpufreq_exit();
@@ -1042,6 +1122,8 @@ static void __exit acpi_processor_exit(void)
 
        acpi_bus_unregister_driver(&acpi_processor_driver);
 
+       cpuidle_unregister_driver(&acpi_idle_driver);
+
        remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
 
        return;