xen-acpi-processor.c 17 KB

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