Merge branches 'release', 'button-sysfs', 'misc', 'mismatch', 'randconfig' and 'toshi...
[sfrench/cifs-2.6.git] / drivers / acpi / processor_core.c
index 015689d295c7289b38db8bfa08a87b111d64bf2d..36a68fa114e3e7b97b85585e40e3f74929110d79 100644 (file)
@@ -494,7 +494,7 @@ 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) {
+       for_each_possible_cpu(i) {
                if (cpu_physical_id(i) == apic_id)
                        return i;
        }
@@ -632,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
@@ -668,6 +668,29 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
 
        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));
@@ -774,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;
        }
@@ -791,6 +814,13 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
 
        acpi_processor_remove_fs(device);
 
+       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;
 
        kfree(pr);
@@ -803,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;
@@ -812,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
@@ -845,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;
@@ -862,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;
@@ -883,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",
@@ -912,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:
@@ -1061,6 +1099,8 @@ static int __init acpi_processor_init(void)
 
        acpi_processor_ppc_init();
 
+       acpi_processor_throttling_init();
+
        return 0;
 
 out_cpuidle: