[IA64] Provide ACPI fixup for /proc/cpuinfo/physical_id
[safe/jmp/linux-2.6] / drivers / acpi / processor_core.c
index a735108..5241e3f 100644 (file)
@@ -112,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,
@@ -326,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;
 }
 
@@ -422,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;
@@ -500,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;
@@ -618,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;
 }
@@ -644,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
@@ -653,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;
        }
@@ -671,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));
@@ -690,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;
@@ -700,7 +717,10 @@ 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);
+               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,
@@ -777,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;
        }
@@ -794,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;
@@ -806,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;
@@ -815,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
@@ -848,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;
@@ -865,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;
@@ -886,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",
@@ -915,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:
@@ -1064,6 +1099,8 @@ static int __init acpi_processor_init(void)
 
        acpi_processor_ppc_init();
 
+       acpi_processor_throttling_init();
+
        return 0;
 
 out_cpuidle: