1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2005 Intel Corporation
4 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
6 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
7 * - Added _PDC for platforms with Intel CPUs
10 #define pr_fmt(fmt) "ACPI: " fmt
12 #include <linux/dmi.h>
13 #include <linux/slab.h>
14 #include <linux/acpi.h>
15 #include <acpi/processor.h>
21 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
22 ACPI_MODULE_NAME("processor_pdc");
24 static bool __init processor_physically_present(acpi_handle handle)
29 acpi_object_type acpi_type;
30 unsigned long long tmp;
31 union acpi_object object = { 0 };
32 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
34 status = acpi_get_type(handle, &acpi_type);
35 if (ACPI_FAILURE(status))
39 case ACPI_TYPE_PROCESSOR:
40 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
41 if (ACPI_FAILURE(status))
43 acpi_id = object.processor.proc_id;
45 case ACPI_TYPE_DEVICE:
46 status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
47 if (ACPI_FAILURE(status))
55 if (xen_initial_domain())
57 * When running as a Xen dom0 the number of processors Linux
58 * sees can be different from the real number of processors on
59 * the system, and we still need to execute _PDC for all of
62 return xen_processor_present(acpi_id);
64 type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
65 cpuid = acpi_get_cpuid(handle, type, acpi_id);
67 return !invalid_logical_cpuid(cpuid);
70 static void acpi_set_pdc_bits(u32 *buf)
72 buf[0] = ACPI_PDC_REVISION_ID;
75 /* Enable coordination with firmware's _TSD info */
76 buf[2] = ACPI_PDC_SMP_T_SWCOORD;
78 /* Twiddle arch-specific bits needed for _PDC */
79 arch_acpi_set_pdc_bits(buf);
82 static struct acpi_object_list *acpi_processor_alloc_pdc(void)
84 struct acpi_object_list *obj_list;
85 union acpi_object *obj;
88 /* allocate and initialize pdc. It will be used later. */
89 obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
93 obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
99 buf = kmalloc(12, GFP_KERNEL);
106 acpi_set_pdc_bits(buf);
108 obj->type = ACPI_TYPE_BUFFER;
109 obj->buffer.length = 12;
110 obj->buffer.pointer = (u8 *) buf;
112 obj_list->pointer = obj;
116 pr_err("Memory allocation error\n");
121 * _PDC is required for a BIOS-OS handshake for most of the newer
122 * ACPI processor features.
125 acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
127 acpi_status status = AE_OK;
129 if (boot_option_idle_override == IDLE_NOMWAIT) {
131 * If mwait is disabled for CPU C-states, the C2C3_FFH access
132 * mode will be disabled in the parameter of _PDC object.
133 * Of course C1_FFH access mode will also be disabled.
135 union acpi_object *obj;
138 obj = pdc_in->pointer;
139 buffer = (u32 *)(obj->buffer.pointer);
140 buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
143 status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
145 if (ACPI_FAILURE(status))
146 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
147 "Could not evaluate _PDC, using legacy perf. control.\n"));
152 void acpi_processor_set_pdc(acpi_handle handle)
154 struct acpi_object_list *obj_list;
156 if (arch_has_acpi_pdc() == false)
159 obj_list = acpi_processor_alloc_pdc();
163 acpi_processor_eval_pdc(handle, obj_list);
165 kfree(obj_list->pointer->buffer.pointer);
166 kfree(obj_list->pointer);
170 static acpi_status __init
171 early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
173 if (processor_physically_present(handle) == false)
176 acpi_processor_set_pdc(handle);
180 static int __init set_no_mwait(const struct dmi_system_id *id)
182 pr_notice("%s detected - disabling mwait for CPU C-states\n",
184 boot_option_idle_override = IDLE_NOMWAIT;
188 static const struct dmi_system_id processor_idle_dmi_table[] __initconst = {
190 set_no_mwait, "Extensa 5220", {
191 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
192 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
193 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
194 DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
198 static void __init processor_dmi_check(void)
201 * Check whether the system is DMI table. If yes, OSPM
202 * should not use mwait for CPU-states.
204 dmi_check_system(processor_idle_dmi_table);
207 void __init acpi_early_processor_set_pdc(void)
209 processor_dmi_check();
211 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
213 early_init_pdc, NULL, NULL, NULL);
214 acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);