xen-acpi-processor.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2012 by Oracle Inc
  4. * Author: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
  5. *
  6. * This code borrows ideas from https://lkml.org/lkml/2011/11/30/249
  7. * so many thanks go to Kevin Tian <kevin.tian@intel.com>
  8. * and Yu Ke <ke.yu@intel.com>.
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/cpumask.h>
  12. #include <linux/cpufreq.h>
  13. #include <linux/freezer.h>
  14. #include <linux/kernel.h>
  15. #include <linux/kthread.h>
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/types.h>
  19. #include <linux/syscore_ops.h>
  20. #include <linux/acpi.h>
  21. #include <acpi/processor.h>
  22. #include <xen/xen.h>
  23. #include <xen/interface/platform.h>
  24. #include <asm/xen/hypercall.h>
  25. static int no_hypercall;
  26. MODULE_PARM_DESC(off, "Inhibit the hypercall.");
  27. module_param_named(off, no_hypercall, int, 0400);
  28. /*
  29. * Note: Do not convert the acpi_id* below to cpumask_var_t or use cpumask_bit
  30. * - as those shrink to nr_cpu_bits (which is dependent on possible_cpu), which
  31. * can be less than what we want to put in. Instead use the 'nr_acpi_bits'
  32. * which is dynamically computed based on the MADT or x2APIC table.
  33. */
  34. static unsigned int nr_acpi_bits;
  35. /* Mutex to protect the acpi_ids_done - for CPU hotplug use. */
  36. static DEFINE_MUTEX(acpi_ids_mutex);
  37. /* Which ACPI ID we have processed from 'struct acpi_processor'. */
  38. static unsigned long *acpi_ids_done;
  39. /* Which ACPI ID exist in the SSDT/DSDT processor definitions. */
  40. static unsigned long *acpi_id_present;
  41. /* And if there is an _CST definition (or a PBLK) for the ACPI IDs */
  42. static unsigned long *acpi_id_cst_present;
  43. /* Which ACPI P-State dependencies for a enumerated processor */
  44. static struct acpi_psd_package *acpi_psd;
  45. static int push_cxx_to_hypervisor(struct acpi_processor *_pr)
  46. {
  47. struct xen_platform_op op = {
  48. .cmd = XENPF_set_processor_pminfo,
  49. .interface_version = XENPF_INTERFACE_VERSION,
  50. .u.set_pminfo.id = _pr->acpi_id,
  51. .u.set_pminfo.type = XEN_PM_CX,
  52. };
  53. struct xen_processor_cx *dst_cx, *dst_cx_states = NULL;
  54. struct acpi_processor_cx *cx;
  55. unsigned int i, ok;
  56. int ret = 0;
  57. dst_cx_states = kcalloc(_pr->power.count,
  58. sizeof(struct xen_processor_cx), GFP_KERNEL);
  59. if (!dst_cx_states)
  60. return -ENOMEM;
  61. for (ok = 0, i = 1; i <= _pr->power.count; i++) {
  62. cx = &_pr->power.states[i];
  63. if (!cx->valid)
  64. continue;
  65. dst_cx = &(dst_cx_states[ok++]);
  66. dst_cx->reg.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  67. if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
  68. dst_cx->reg.bit_width = 8;
  69. dst_cx->reg.bit_offset = 0;
  70. dst_cx->reg.access_size = 1;
  71. } else {
  72. dst_cx->reg.space_id = ACPI_ADR_SPACE_FIXED_HARDWARE;
  73. if (cx->entry_method == ACPI_CSTATE_FFH) {
  74. /* NATIVE_CSTATE_BEYOND_HALT */
  75. dst_cx->reg.bit_offset = 2;
  76. dst_cx->reg.bit_width = 1; /* VENDOR_INTEL */
  77. }
  78. dst_cx->reg.access_size = 0;
  79. }
  80. dst_cx->reg.address = cx->address;
  81. dst_cx->type = cx->type;
  82. dst_cx->latency = cx->latency;
  83. dst_cx->dpcnt = 0;
  84. set_xen_guest_handle(dst_cx->dp, NULL);
  85. }
  86. if (!ok) {
  87. pr_debug("No _Cx for ACPI CPU %u\n", _pr->acpi_id);
  88. kfree(dst_cx_states);
  89. return -EINVAL;
  90. }
  91. op.u.set_pminfo.power.count = ok;
  92. op.u.set_pminfo.power.flags.bm_control = _pr->flags.bm_control;
  93. op.u.set_pminfo.power.flags.bm_check = _pr->flags.bm_check;
  94. op.u.set_pminfo.power.flags.has_cst = _pr->flags.has_cst;
  95. op.u.set_pminfo.power.flags.power_setup_done =
  96. _pr->flags.power_setup_done;
  97. set_xen_guest_handle(op.u.set_pminfo.power.states, dst_cx_states);
  98. if (!no_hypercall)
  99. ret = HYPERVISOR_platform_op(&op);
  100. if (!ret) {
  101. pr_debug("ACPI CPU%u - C-states uploaded.\n", _pr->acpi_id);
  102. for (i = 1; i <= _pr->power.count; i++) {
  103. cx = &_pr->power.states[i];
  104. if (!cx->valid)
  105. continue;
  106. pr_debug(" C%d: %s %d uS\n",
  107. cx->type, cx->desc, (u32)cx->latency);
  108. }
  109. } else if ((ret != -EINVAL) && (ret != -ENOSYS))
  110. /* EINVAL means the ACPI ID is incorrect - meaning the ACPI
  111. * table is referencing a non-existing CPU - which can happen
  112. * with broken ACPI tables. */
  113. pr_err("(CX): Hypervisor error (%d) for ACPI CPU%u\n",
  114. ret, _pr->acpi_id);
  115. kfree(dst_cx_states);
  116. return ret;
  117. }
  118. static struct xen_processor_px *
  119. xen_copy_pss_data(struct acpi_processor *_pr,
  120. struct xen_processor_performance *dst_perf)
  121. {
  122. struct xen_processor_px *dst_states = NULL;
  123. unsigned int i;
  124. BUILD_BUG_ON(sizeof(struct xen_processor_px) !=
  125. sizeof(struct acpi_processor_px));
  126. dst_states = kcalloc(_pr->performance->state_count,
  127. sizeof(struct xen_processor_px), GFP_KERNEL);
  128. if (!dst_states)
  129. return ERR_PTR(-ENOMEM);
  130. dst_perf->state_count = _pr->performance->state_count;
  131. for (i = 0; i < _pr->performance->state_count; i++) {
  132. /* Fortunatly for us, they are both the same size */
  133. memcpy(&(dst_states[i]), &(_pr->performance->states[i]),
  134. sizeof(struct acpi_processor_px));
  135. }
  136. return dst_states;
  137. }
  138. static int xen_copy_psd_data(struct acpi_processor *_pr,
  139. struct xen_processor_performance *dst)
  140. {
  141. struct acpi_psd_package *pdomain;
  142. BUILD_BUG_ON(sizeof(struct xen_psd_package) !=
  143. sizeof(struct acpi_psd_package));
  144. /* This information is enumerated only if acpi_processor_preregister_performance
  145. * has been called.
  146. */
  147. dst->shared_type = _pr->performance->shared_type;
  148. pdomain = &(_pr->performance->domain_info);
  149. /* 'acpi_processor_preregister_performance' does not parse if the
  150. * num_processors <= 1, but Xen still requires it. Do it manually here.
  151. */
  152. if (pdomain->num_processors <= 1) {
  153. if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
  154. dst->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  155. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
  156. dst->shared_type = CPUFREQ_SHARED_TYPE_HW;
  157. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
  158. dst->shared_type = CPUFREQ_SHARED_TYPE_ANY;
  159. }
  160. memcpy(&(dst->domain_info), pdomain, sizeof(struct acpi_psd_package));
  161. return 0;
  162. }
  163. static int xen_copy_pct_data(struct acpi_pct_register *pct,
  164. struct xen_pct_register *dst_pct)
  165. {
  166. /* It would be nice if you could just do 'memcpy(pct, dst_pct') but
  167. * sadly the Xen structure did not have the proper padding so the
  168. * descriptor field takes two (dst_pct) bytes instead of one (pct).
  169. */
  170. dst_pct->descriptor = pct->descriptor;
  171. dst_pct->length = pct->length;
  172. dst_pct->space_id = pct->space_id;
  173. dst_pct->bit_width = pct->bit_width;
  174. dst_pct->bit_offset = pct->bit_offset;
  175. dst_pct->reserved = pct->reserved;
  176. dst_pct->address = pct->address;
  177. return 0;
  178. }
  179. static int push_pxx_to_hypervisor(struct acpi_processor *_pr)
  180. {
  181. int ret = 0;
  182. struct xen_platform_op op = {
  183. .cmd = XENPF_set_processor_pminfo,
  184. .interface_version = XENPF_INTERFACE_VERSION,
  185. .u.set_pminfo.id = _pr->acpi_id,
  186. .u.set_pminfo.type = XEN_PM_PX,
  187. };
  188. struct xen_processor_performance *dst_perf;
  189. struct xen_processor_px *dst_states = NULL;
  190. dst_perf = &op.u.set_pminfo.perf;
  191. dst_perf->platform_limit = _pr->performance_platform_limit;
  192. dst_perf->flags |= XEN_PX_PPC;
  193. xen_copy_pct_data(&(_pr->performance->control_register),
  194. &dst_perf->control_register);
  195. xen_copy_pct_data(&(_pr->performance->status_register),
  196. &dst_perf->status_register);
  197. dst_perf->flags |= XEN_PX_PCT;
  198. dst_states = xen_copy_pss_data(_pr, dst_perf);
  199. if (!IS_ERR_OR_NULL(dst_states)) {
  200. set_xen_guest_handle(dst_perf->states, dst_states);
  201. dst_perf->flags |= XEN_PX_PSS;
  202. }
  203. if (!xen_copy_psd_data(_pr, dst_perf))
  204. dst_perf->flags |= XEN_PX_PSD;
  205. if (dst_perf->flags != (XEN_PX_PSD | XEN_PX_PSS | XEN_PX_PCT | XEN_PX_PPC)) {
  206. pr_warn("ACPI CPU%u missing some P-state data (%x), skipping\n",
  207. _pr->acpi_id, dst_perf->flags);
  208. ret = -ENODEV;
  209. goto err_free;
  210. }
  211. if (!no_hypercall)
  212. ret = HYPERVISOR_platform_op(&op);
  213. if (!ret) {
  214. struct acpi_processor_performance *perf;
  215. unsigned int i;
  216. perf = _pr->performance;
  217. pr_debug("ACPI CPU%u - P-states uploaded.\n", _pr->acpi_id);
  218. for (i = 0; i < perf->state_count; i++) {
  219. pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n",
  220. (i == perf->state ? '*' : ' '), i,
  221. (u32) perf->states[i].core_frequency,
  222. (u32) perf->states[i].power,
  223. (u32) perf->states[i].transition_latency);
  224. }
  225. } else if ((ret != -EINVAL) && (ret != -ENOSYS))
  226. /* EINVAL means the ACPI ID is incorrect - meaning the ACPI
  227. * table is referencing a non-existing CPU - which can happen
  228. * with broken ACPI tables. */
  229. pr_warn("(_PXX): Hypervisor error (%d) for ACPI CPU%u\n",
  230. ret, _pr->acpi_id);
  231. err_free:
  232. if (!IS_ERR_OR_NULL(dst_states))
  233. kfree(dst_states);
  234. return ret;
  235. }
  236. static int upload_pm_data(struct acpi_processor *_pr)
  237. {
  238. int err = 0;
  239. mutex_lock(&acpi_ids_mutex);
  240. if (__test_and_set_bit(_pr->acpi_id, acpi_ids_done)) {
  241. mutex_unlock(&acpi_ids_mutex);
  242. return -EBUSY;
  243. }
  244. if (_pr->flags.power)
  245. err = push_cxx_to_hypervisor(_pr);
  246. if (_pr->performance && _pr->performance->states)
  247. err |= push_pxx_to_hypervisor(_pr);
  248. mutex_unlock(&acpi_ids_mutex);
  249. return err;
  250. }
  251. static unsigned int __init get_max_acpi_id(void)
  252. {
  253. struct xenpf_pcpuinfo *info;
  254. struct xen_platform_op op = {
  255. .cmd = XENPF_get_cpuinfo,
  256. .interface_version = XENPF_INTERFACE_VERSION,
  257. };
  258. int ret = 0;
  259. unsigned int i, last_cpu, max_acpi_id = 0;
  260. info = &op.u.pcpu_info;
  261. info->xen_cpuid = 0;
  262. ret = HYPERVISOR_platform_op(&op);
  263. if (ret)
  264. return NR_CPUS;
  265. /* The max_present is the same irregardless of the xen_cpuid */
  266. last_cpu = op.u.pcpu_info.max_present;
  267. for (i = 0; i <= last_cpu; i++) {
  268. info->xen_cpuid = i;
  269. ret = HYPERVISOR_platform_op(&op);
  270. if (ret)
  271. continue;
  272. max_acpi_id = max(info->acpi_id, max_acpi_id);
  273. }
  274. max_acpi_id *= 2; /* Slack for CPU hotplug support. */
  275. pr_debug("Max ACPI ID: %u\n", max_acpi_id);
  276. return max_acpi_id;
  277. }
  278. /*
  279. * The read_acpi_id and check_acpi_ids are there to support the Xen
  280. * oddity of virtual CPUs != physical CPUs in the initial domain.
  281. * The user can supply 'xen_max_vcpus=X' on the Xen hypervisor line
  282. * which will band the amount of CPUs the initial domain can see.
  283. * In general that is OK, except it plays havoc with any of the
  284. * for_each_[present|online]_cpu macros which are banded to the virtual
  285. * CPU amount.
  286. */
  287. static acpi_status
  288. read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
  289. {
  290. u32 acpi_id;
  291. acpi_status status;
  292. acpi_object_type acpi_type;
  293. unsigned long long tmp;
  294. union acpi_object object = { 0 };
  295. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  296. acpi_io_address pblk = 0;
  297. status = acpi_get_type(handle, &acpi_type);
  298. if (ACPI_FAILURE(status))
  299. return AE_OK;
  300. switch (acpi_type) {
  301. case ACPI_TYPE_PROCESSOR:
  302. status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
  303. if (ACPI_FAILURE(status))
  304. return AE_OK;
  305. acpi_id = object.processor.proc_id;
  306. pblk = object.processor.pblk_address;
  307. break;
  308. case ACPI_TYPE_DEVICE:
  309. status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
  310. if (ACPI_FAILURE(status))
  311. return AE_OK;
  312. acpi_id = tmp;
  313. break;
  314. default:
  315. return AE_OK;
  316. }
  317. if (invalid_phys_cpuid(acpi_get_phys_id(handle,
  318. acpi_type == ACPI_TYPE_DEVICE,
  319. acpi_id))) {
  320. pr_debug("CPU with ACPI ID %u is unavailable\n", acpi_id);
  321. return AE_OK;
  322. }
  323. /* There are more ACPI Processor objects than in x2APIC or MADT.
  324. * This can happen with incorrect ACPI SSDT declerations. */
  325. if (acpi_id >= nr_acpi_bits) {
  326. pr_debug("max acpi id %u, trying to set %u\n",
  327. nr_acpi_bits - 1, acpi_id);
  328. return AE_OK;
  329. }
  330. /* OK, There is a ACPI Processor object */
  331. __set_bit(acpi_id, acpi_id_present);
  332. pr_debug("ACPI CPU%u w/ PBLK:0x%lx\n", acpi_id, (unsigned long)pblk);
  333. /* It has P-state dependencies */
  334. if (!acpi_processor_get_psd(handle, &acpi_psd[acpi_id])) {
  335. pr_debug("ACPI CPU%u w/ PST:coord_type = %llu domain = %llu\n",
  336. acpi_id, acpi_psd[acpi_id].coord_type,
  337. acpi_psd[acpi_id].domain);
  338. }
  339. status = acpi_evaluate_object(handle, "_CST", NULL, &buffer);
  340. if (ACPI_FAILURE(status)) {
  341. if (!pblk)
  342. return AE_OK;
  343. }
  344. /* .. and it has a C-state */
  345. __set_bit(acpi_id, acpi_id_cst_present);
  346. return AE_OK;
  347. }
  348. static int check_acpi_ids(struct acpi_processor *pr_backup)
  349. {
  350. if (!pr_backup)
  351. return -ENODEV;
  352. if (acpi_id_present && acpi_id_cst_present)
  353. /* OK, done this once .. skip to uploading */
  354. goto upload;
  355. /* All online CPUs have been processed at this stage. Now verify
  356. * whether in fact "online CPUs" == physical CPUs.
  357. */
  358. acpi_id_present = bitmap_zalloc(nr_acpi_bits, GFP_KERNEL);
  359. if (!acpi_id_present)
  360. return -ENOMEM;
  361. acpi_id_cst_present = bitmap_zalloc(nr_acpi_bits, GFP_KERNEL);
  362. if (!acpi_id_cst_present) {
  363. bitmap_free(acpi_id_present);
  364. return -ENOMEM;
  365. }
  366. acpi_psd = kcalloc(nr_acpi_bits, sizeof(struct acpi_psd_package),
  367. GFP_KERNEL);
  368. if (!acpi_psd) {
  369. bitmap_free(acpi_id_present);
  370. bitmap_free(acpi_id_cst_present);
  371. return -ENOMEM;
  372. }
  373. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  374. ACPI_UINT32_MAX,
  375. read_acpi_id, NULL, NULL, NULL);
  376. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, read_acpi_id, NULL, NULL);
  377. upload:
  378. if (!bitmap_equal(acpi_id_present, acpi_ids_done, nr_acpi_bits)) {
  379. unsigned int i;
  380. for_each_set_bit(i, acpi_id_present, nr_acpi_bits) {
  381. pr_backup->acpi_id = i;
  382. /* Mask out C-states if there are no _CST or PBLK */
  383. pr_backup->flags.power = test_bit(i, acpi_id_cst_present);
  384. /* num_entries is non-zero if we evaluated _PSD */
  385. if (acpi_psd[i].num_entries) {
  386. memcpy(&pr_backup->performance->domain_info,
  387. &acpi_psd[i],
  388. sizeof(struct acpi_psd_package));
  389. }
  390. (void)upload_pm_data(pr_backup);
  391. }
  392. }
  393. return 0;
  394. }
  395. /* acpi_perf_data is a pointer to percpu data. */
  396. static struct acpi_processor_performance __percpu *acpi_perf_data;
  397. static void free_acpi_perf_data(void)
  398. {
  399. unsigned int i;
  400. /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */
  401. for_each_possible_cpu(i)
  402. free_cpumask_var(per_cpu_ptr(acpi_perf_data, i)
  403. ->shared_cpu_map);
  404. free_percpu(acpi_perf_data);
  405. }
  406. static int xen_upload_processor_pm_data(void)
  407. {
  408. struct acpi_processor *pr_backup = NULL;
  409. unsigned int i;
  410. int rc = 0;
  411. pr_info("Uploading Xen processor PM info\n");
  412. for_each_possible_cpu(i) {
  413. struct acpi_processor *_pr;
  414. _pr = per_cpu(processors, i /* APIC ID */);
  415. if (!_pr)
  416. continue;
  417. if (!pr_backup) {
  418. pr_backup = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  419. if (pr_backup)
  420. memcpy(pr_backup, _pr, sizeof(struct acpi_processor));
  421. }
  422. (void)upload_pm_data(_pr);
  423. }
  424. rc = check_acpi_ids(pr_backup);
  425. kfree(pr_backup);
  426. return rc;
  427. }
  428. static void xen_acpi_processor_resume_worker(struct work_struct *dummy)
  429. {
  430. int rc;
  431. bitmap_zero(acpi_ids_done, nr_acpi_bits);
  432. rc = xen_upload_processor_pm_data();
  433. if (rc != 0)
  434. pr_info("ACPI data upload failed, error = %d\n", rc);
  435. }
  436. static void xen_acpi_processor_resume(void)
  437. {
  438. static DECLARE_WORK(wq, xen_acpi_processor_resume_worker);
  439. /*
  440. * xen_upload_processor_pm_data() calls non-atomic code.
  441. * However, the context for xen_acpi_processor_resume is syscore
  442. * with only the boot CPU online and in an atomic context.
  443. *
  444. * So defer the upload for some point safer.
  445. */
  446. schedule_work(&wq);
  447. }
  448. static struct syscore_ops xap_syscore_ops = {
  449. .resume = xen_acpi_processor_resume,
  450. };
  451. static int __init xen_acpi_processor_init(void)
  452. {
  453. unsigned int i;
  454. int rc;
  455. if (!xen_initial_domain())
  456. return -ENODEV;
  457. nr_acpi_bits = get_max_acpi_id() + 1;
  458. acpi_ids_done = bitmap_zalloc(nr_acpi_bits, GFP_KERNEL);
  459. if (!acpi_ids_done)
  460. return -ENOMEM;
  461. acpi_perf_data = alloc_percpu(struct acpi_processor_performance);
  462. if (!acpi_perf_data) {
  463. pr_debug("Memory allocation error for acpi_perf_data\n");
  464. bitmap_free(acpi_ids_done);
  465. return -ENOMEM;
  466. }
  467. for_each_possible_cpu(i) {
  468. if (!zalloc_cpumask_var_node(
  469. &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map,
  470. GFP_KERNEL, cpu_to_node(i))) {
  471. rc = -ENOMEM;
  472. goto err_out;
  473. }
  474. }
  475. /* Do initialization in ACPI core. It is OK to fail here. */
  476. (void)acpi_processor_preregister_performance(acpi_perf_data);
  477. for_each_possible_cpu(i) {
  478. struct acpi_processor *pr;
  479. struct acpi_processor_performance *perf;
  480. pr = per_cpu(processors, i);
  481. perf = per_cpu_ptr(acpi_perf_data, i);
  482. if (!pr)
  483. continue;
  484. pr->performance = perf;
  485. rc = acpi_processor_get_performance_info(pr);
  486. if (rc)
  487. goto err_out;
  488. }
  489. rc = xen_upload_processor_pm_data();
  490. if (rc)
  491. goto err_unregister;
  492. register_syscore_ops(&xap_syscore_ops);
  493. return 0;
  494. err_unregister:
  495. for_each_possible_cpu(i)
  496. acpi_processor_unregister_performance(i);
  497. err_out:
  498. /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */
  499. free_acpi_perf_data();
  500. bitmap_free(acpi_ids_done);
  501. return rc;
  502. }
  503. static void __exit xen_acpi_processor_exit(void)
  504. {
  505. int i;
  506. unregister_syscore_ops(&xap_syscore_ops);
  507. bitmap_free(acpi_ids_done);
  508. bitmap_free(acpi_id_present);
  509. bitmap_free(acpi_id_cst_present);
  510. kfree(acpi_psd);
  511. for_each_possible_cpu(i)
  512. acpi_processor_unregister_performance(i);
  513. free_acpi_perf_data();
  514. }
  515. MODULE_AUTHOR("Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>");
  516. MODULE_DESCRIPTION("Xen ACPI Processor P-states (and Cx) driver which uploads PM data to Xen hypervisor");
  517. MODULE_LICENSE("GPL");
  518. /* We want to be loaded before the CPU freq scaling drivers are loaded.
  519. * They are loaded in late_initcall. */
  520. device_initcall(xen_acpi_processor_init);
  521. module_exit(xen_acpi_processor_exit);