processor_pdc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2005 Intel Corporation
  4. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  5. *
  6. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  7. * - Added _PDC for platforms with Intel CPUs
  8. */
  9. #define pr_fmt(fmt) "ACPI: " fmt
  10. #include <linux/slab.h>
  11. #include <linux/acpi.h>
  12. #include <acpi/processor.h>
  13. #include "internal.h"
  14. static void acpi_set_pdc_bits(u32 *buf)
  15. {
  16. buf[0] = ACPI_PDC_REVISION_ID;
  17. buf[1] = 1;
  18. buf[2] = 0;
  19. /* Twiddle arch-specific bits needed for _PDC */
  20. arch_acpi_set_proc_cap_bits(&buf[2]);
  21. }
  22. static struct acpi_object_list *acpi_processor_alloc_pdc(void)
  23. {
  24. struct acpi_object_list *obj_list;
  25. union acpi_object *obj;
  26. u32 *buf;
  27. /* allocate and initialize pdc. It will be used later. */
  28. obj_list = kmalloc_obj(struct acpi_object_list);
  29. if (!obj_list)
  30. goto out;
  31. obj = kmalloc_obj(union acpi_object);
  32. if (!obj) {
  33. kfree(obj_list);
  34. goto out;
  35. }
  36. buf = kmalloc(12, GFP_KERNEL);
  37. if (!buf) {
  38. kfree(obj);
  39. kfree(obj_list);
  40. goto out;
  41. }
  42. acpi_set_pdc_bits(buf);
  43. obj->type = ACPI_TYPE_BUFFER;
  44. obj->buffer.length = 12;
  45. obj->buffer.pointer = (u8 *) buf;
  46. obj_list->count = 1;
  47. obj_list->pointer = obj;
  48. return obj_list;
  49. out:
  50. pr_err("Memory allocation error\n");
  51. return NULL;
  52. }
  53. /*
  54. * _PDC is required for a BIOS-OS handshake for most of the newer
  55. * ACPI processor features.
  56. */
  57. static acpi_status
  58. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  59. {
  60. acpi_status status = AE_OK;
  61. status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
  62. if (ACPI_FAILURE(status))
  63. acpi_handle_debug(handle,
  64. "Could not evaluate _PDC, using legacy perf control\n");
  65. return status;
  66. }
  67. void acpi_processor_set_pdc(acpi_handle handle)
  68. {
  69. struct acpi_object_list *obj_list;
  70. if (arch_has_acpi_pdc() == false)
  71. return;
  72. obj_list = acpi_processor_alloc_pdc();
  73. if (!obj_list)
  74. return;
  75. acpi_processor_eval_pdc(handle, obj_list);
  76. kfree(obj_list->pointer->buffer.pointer);
  77. kfree(obj_list->pointer);
  78. kfree(obj_list);
  79. }
  80. static acpi_status __init
  81. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  82. {
  83. if (processor_physically_present(handle) == false)
  84. return AE_OK;
  85. acpi_processor_set_pdc(handle);
  86. return AE_OK;
  87. }
  88. void __init acpi_early_processor_set_pdc(void)
  89. {
  90. acpi_proc_quirk_mwait_check();
  91. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  92. ACPI_UINT32_MAX,
  93. early_init_pdc, NULL, NULL, NULL);
  94. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
  95. }