159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* 259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * Copyright 2012 by Oracle Inc 359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * Author: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * 559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * This code borrows ideas from https://lkml.org/lkml/2011/11/30/249 659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * so many thanks go to Kevin Tian <kevin.tian@intel.com> 759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * and Yu Ke <ke.yu@intel.com>. 859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * 959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * This program is free software; you can redistribute it and/or modify it 1059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * under the terms and conditions of the GNU General Public License, 1159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * version 2, as published by the Free Software Foundation. 1259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * 1359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * This program is distributed in the hope it will be useful, but WITHOUT 1459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * more details. 1759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * 1859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 1959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 20283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches 2259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/cpumask.h> 2359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/cpufreq.h> 2459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/freezer.h> 2559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/kernel.h> 2659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/kthread.h> 2759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/init.h> 2859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/module.h> 2959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <linux/types.h> 308b48463f89429af408ff695244dc627e1acff4f7Lv Zheng#include <linux/acpi.h> 3159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <acpi/processor.h> 32323f90a60864f30fd6b7c99806584bb90ada1a29H. Peter Anvin#include <xen/xen.h> 33cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszka#include <xen/xen-ops.h> 3459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <xen/interface/platform.h> 3559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#include <asm/xen/hypercall.h> 3659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 3759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int no_hypercall; 3859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek WilkMODULE_PARM_DESC(off, "Inhibit the hypercall."); 3959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkmodule_param_named(off, no_hypercall, int, 0400); 4059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 4159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* 4259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * Note: Do not convert the acpi_id* below to cpumask_var_t or use cpumask_bit 4359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * - as those shrink to nr_cpu_bits (which is dependent on possible_cpu), which 4459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * can be less than what we want to put in. Instead use the 'nr_acpi_bits' 4559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * which is dynamically computed based on the MADT or x2APIC table. 4659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 4759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic unsigned int nr_acpi_bits; 4859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* Mutex to protect the acpi_ids_done - for CPU hotplug use. */ 4959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic DEFINE_MUTEX(acpi_ids_mutex); 5059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* Which ACPI ID we have processed from 'struct acpi_processor'. */ 5159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic unsigned long *acpi_ids_done; 5259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* Which ACPI ID exist in the SSDT/DSDT processor definitions. */ 533fac10145b766a2244422788f62dc35978613fd8Ben Guthrostatic unsigned long *acpi_id_present; 5459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* And if there is an _CST definition (or a PBLK) for the ACPI IDs */ 553fac10145b766a2244422788f62dc35978613fd8Ben Guthrostatic unsigned long *acpi_id_cst_present; 5659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 5759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int push_cxx_to_hypervisor(struct acpi_processor *_pr) 5859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 5959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_platform_op op = { 6059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .cmd = XENPF_set_processor_pminfo, 6159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .interface_version = XENPF_INTERFACE_VERSION, 6259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .u.set_pminfo.id = _pr->acpi_id, 6359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .u.set_pminfo.type = XEN_PM_CX, 6459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk }; 6559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_processor_cx *dst_cx, *dst_cx_states = NULL; 6659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_processor_cx *cx; 6759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i, ok; 6859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk int ret = 0; 6959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 7059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx_states = kcalloc(_pr->power.count, 7159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk sizeof(struct xen_processor_cx), GFP_KERNEL); 7259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!dst_cx_states) 7359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENOMEM; 7459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 7559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for (ok = 0, i = 1; i <= _pr->power.count; i++) { 7659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk cx = &_pr->power.states[i]; 7759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!cx->valid) 7859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk continue; 7959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 8059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx = &(dst_cx_states[ok++]); 8159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 8259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.space_id = ACPI_ADR_SPACE_SYSTEM_IO; 8359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) { 8459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.bit_width = 8; 8559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.bit_offset = 0; 8659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.access_size = 1; 8759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } else { 8859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.space_id = ACPI_ADR_SPACE_FIXED_HARDWARE; 8959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (cx->entry_method == ACPI_CSTATE_FFH) { 9059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* NATIVE_CSTATE_BEYOND_HALT */ 9159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.bit_offset = 2; 9259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.bit_width = 1; /* VENDOR_INTEL */ 9359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 9459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.access_size = 0; 9559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 9659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->reg.address = cx->address; 9759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 9859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->type = cx->type; 9959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->latency = cx->latency; 10059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 10159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_cx->dpcnt = 0; 10259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk set_xen_guest_handle(dst_cx->dp, NULL); 10359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 10459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!ok) { 105283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_debug("No _Cx for ACPI CPU %u\n", _pr->acpi_id); 10659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(dst_cx_states); 10759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -EINVAL; 10859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 10959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk op.u.set_pminfo.power.count = ok; 11059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk op.u.set_pminfo.power.flags.bm_control = _pr->flags.bm_control; 11159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk op.u.set_pminfo.power.flags.bm_check = _pr->flags.bm_check; 11259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk op.u.set_pminfo.power.flags.has_cst = _pr->flags.has_cst; 11359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk op.u.set_pminfo.power.flags.power_setup_done = 11459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk _pr->flags.power_setup_done; 11559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 11659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk set_xen_guest_handle(op.u.set_pminfo.power.states, dst_cx_states); 11759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 11859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!no_hypercall) 11959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ret = HYPERVISOR_dom0_op(&op); 12059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 12159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!ret) { 12259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pr_debug("ACPI CPU%u - C-states uploaded.\n", _pr->acpi_id); 12359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for (i = 1; i <= _pr->power.count; i++) { 12459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk cx = &_pr->power.states[i]; 12559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!cx->valid) 12659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk continue; 12759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pr_debug(" C%d: %s %d uS\n", 12859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk cx->type, cx->desc, (u32)cx->latency); 12959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 1301a4b50f674d0d2f66569f08d063996971b7d48f2Konrad Rzeszutek Wilk } else if ((ret != -EINVAL) && (ret != -ENOSYS)) 131b930fe5e1f5646e071facda70b25b137ebeae5afKonrad Rzeszutek Wilk /* EINVAL means the ACPI ID is incorrect - meaning the ACPI 132b930fe5e1f5646e071facda70b25b137ebeae5afKonrad Rzeszutek Wilk * table is referencing a non-existing CPU - which can happen 133b930fe5e1f5646e071facda70b25b137ebeae5afKonrad Rzeszutek Wilk * with broken ACPI tables. */ 134283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_err("(CX): Hypervisor error (%d) for ACPI CPU%u\n", 13559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ret, _pr->acpi_id); 13659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 13759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(dst_cx_states); 13859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 13959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return ret; 14059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 14159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic struct xen_processor_px * 14259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkxen_copy_pss_data(struct acpi_processor *_pr, 14359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_processor_performance *dst_perf) 14459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 14559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_processor_px *dst_states = NULL; 14659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i; 14759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 14859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk BUILD_BUG_ON(sizeof(struct xen_processor_px) != 14959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk sizeof(struct acpi_processor_px)); 15059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 15159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_states = kcalloc(_pr->performance->state_count, 15259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk sizeof(struct xen_processor_px), GFP_KERNEL); 15359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!dst_states) 15459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return ERR_PTR(-ENOMEM); 15559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 15659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf->state_count = _pr->performance->state_count; 15759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for (i = 0; i < _pr->performance->state_count; i++) { 15859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* Fortunatly for us, they are both the same size */ 15959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk memcpy(&(dst_states[i]), &(_pr->performance->states[i]), 16059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk sizeof(struct acpi_processor_px)); 16159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 16259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return dst_states; 16359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 16459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int xen_copy_psd_data(struct acpi_processor *_pr, 16559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_processor_performance *dst) 16659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 16759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_psd_package *pdomain; 16859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 16959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk BUILD_BUG_ON(sizeof(struct xen_psd_package) != 17059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk sizeof(struct acpi_psd_package)); 17159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 17259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* This information is enumerated only if acpi_processor_preregister_performance 17359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * has been called. 17459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 17559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst->shared_type = _pr->performance->shared_type; 17659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 17759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pdomain = &(_pr->performance->domain_info); 17859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 17959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* 'acpi_processor_preregister_performance' does not parse if the 18059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * num_processors <= 1, but Xen still requires it. Do it manually here. 18159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 18259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (pdomain->num_processors <= 1) { 18359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL) 18459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst->shared_type = CPUFREQ_SHARED_TYPE_ALL; 18559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) 18659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst->shared_type = CPUFREQ_SHARED_TYPE_HW; 18759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY) 18859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst->shared_type = CPUFREQ_SHARED_TYPE_ANY; 18959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 19059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 19159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk memcpy(&(dst->domain_info), pdomain, sizeof(struct acpi_psd_package)); 19259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return 0; 19359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 19459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int xen_copy_pct_data(struct acpi_pct_register *pct, 19559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_pct_register *dst_pct) 19659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 19759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* It would be nice if you could just do 'memcpy(pct, dst_pct') but 19859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * sadly the Xen structure did not have the proper padding so the 19959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * descriptor field takes two (dst_pct) bytes instead of one (pct). 20059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 20159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->descriptor = pct->descriptor; 20259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->length = pct->length; 20359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->space_id = pct->space_id; 20459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->bit_width = pct->bit_width; 20559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->bit_offset = pct->bit_offset; 20659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->reserved = pct->reserved; 20759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_pct->address = pct->address; 20859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return 0; 20959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 21059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int push_pxx_to_hypervisor(struct acpi_processor *_pr) 21159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 21259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk int ret = 0; 21359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_platform_op op = { 21459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .cmd = XENPF_set_processor_pminfo, 21559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .interface_version = XENPF_INTERFACE_VERSION, 21659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .u.set_pminfo.id = _pr->acpi_id, 21759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .u.set_pminfo.type = XEN_PM_PX, 21859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk }; 21959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_processor_performance *dst_perf; 22059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_processor_px *dst_states = NULL; 22159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 22259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf = &op.u.set_pminfo.perf; 22359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 22459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf->platform_limit = _pr->performance_platform_limit; 22559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf->flags |= XEN_PX_PPC; 22659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk xen_copy_pct_data(&(_pr->performance->control_register), 22759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk &dst_perf->control_register); 22859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk xen_copy_pct_data(&(_pr->performance->status_register), 22959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk &dst_perf->status_register); 23059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf->flags |= XEN_PX_PCT; 23159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_states = xen_copy_pss_data(_pr, dst_perf); 23259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!IS_ERR_OR_NULL(dst_states)) { 23359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk set_xen_guest_handle(dst_perf->states, dst_states); 23459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf->flags |= XEN_PX_PSS; 23559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 23659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!xen_copy_psd_data(_pr, dst_perf)) 23759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk dst_perf->flags |= XEN_PX_PSD; 23859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 23959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (dst_perf->flags != (XEN_PX_PSD | XEN_PX_PSS | XEN_PX_PCT | XEN_PX_PPC)) { 240283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_warn("ACPI CPU%u missing some P-state data (%x), skipping\n", 24159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk _pr->acpi_id, dst_perf->flags); 24259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ret = -ENODEV; 24359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk goto err_free; 24459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 24559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 24659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!no_hypercall) 24759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ret = HYPERVISOR_dom0_op(&op); 24859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 24959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!ret) { 25059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_processor_performance *perf; 25159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i; 25259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 25359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk perf = _pr->performance; 25459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pr_debug("ACPI CPU%u - P-states uploaded.\n", _pr->acpi_id); 25559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for (i = 0; i < perf->state_count; i++) { 25659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n", 25759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk (i == perf->state ? '*' : ' '), i, 25859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk (u32) perf->states[i].core_frequency, 25959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk (u32) perf->states[i].power, 26059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk (u32) perf->states[i].transition_latency); 26159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 2621a4b50f674d0d2f66569f08d063996971b7d48f2Konrad Rzeszutek Wilk } else if ((ret != -EINVAL) && (ret != -ENOSYS)) 26359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* EINVAL means the ACPI ID is incorrect - meaning the ACPI 26459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * table is referencing a non-existing CPU - which can happen 26559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * with broken ACPI tables. */ 266283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_warn("(_PXX): Hypervisor error (%d) for ACPI CPU%u\n", 267283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches ret, _pr->acpi_id); 26859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkerr_free: 26959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!IS_ERR_OR_NULL(dst_states)) 27059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(dst_states); 27159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 27259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return ret; 27359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 27459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int upload_pm_data(struct acpi_processor *_pr) 27559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 27659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk int err = 0; 27759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 27859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk mutex_lock(&acpi_ids_mutex); 27959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (__test_and_set_bit(_pr->acpi_id, acpi_ids_done)) { 28059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk mutex_unlock(&acpi_ids_mutex); 28159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -EBUSY; 28259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 28359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (_pr->flags.power) 28459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk err = push_cxx_to_hypervisor(_pr); 28559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 28659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (_pr->performance && _pr->performance->states) 28759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk err |= push_pxx_to_hypervisor(_pr); 28859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 28959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk mutex_unlock(&acpi_ids_mutex); 29059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return err; 29159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 29259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic unsigned int __init get_max_acpi_id(void) 29359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 29459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xenpf_pcpuinfo *info; 29559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct xen_platform_op op = { 29659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .cmd = XENPF_get_cpuinfo, 29759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk .interface_version = XENPF_INTERFACE_VERSION, 29859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk }; 29959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk int ret = 0; 30059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i, last_cpu, max_acpi_id = 0; 30159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 30259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk info = &op.u.pcpu_info; 30359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk info->xen_cpuid = 0; 30459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 30559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ret = HYPERVISOR_dom0_op(&op); 30659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (ret) 30759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return NR_CPUS; 30859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 30959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* The max_present is the same irregardless of the xen_cpuid */ 31059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk last_cpu = op.u.pcpu_info.max_present; 31159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for (i = 0; i <= last_cpu; i++) { 31259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk info->xen_cpuid = i; 31359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ret = HYPERVISOR_dom0_op(&op); 31459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (ret) 31559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk continue; 31659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk max_acpi_id = max(info->acpi_id, max_acpi_id); 31759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 31859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk max_acpi_id *= 2; /* Slack for CPU hotplug support. */ 319283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_debug("Max ACPI ID: %u\n", max_acpi_id); 32059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return max_acpi_id; 32159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 32259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* 32359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * The read_acpi_id and check_acpi_ids are there to support the Xen 32459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * oddity of virtual CPUs != physical CPUs in the initial domain. 32559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * The user can supply 'xen_max_vcpus=X' on the Xen hypervisor line 32659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * which will band the amount of CPUs the initial domain can see. 32759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * In general that is OK, except it plays havoc with any of the 32859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * for_each_[present|online]_cpu macros which are banded to the virtual 32959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * CPU amount. 33059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 33118c0025b692a293e3e4aecb34264563c0a442448Ben Guthrostatic acpi_status 33259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkread_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) 33359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 33459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk u32 acpi_id; 33559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_status status; 33659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_object_type acpi_type; 33759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned long long tmp; 33859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk union acpi_object object = { 0 }; 33959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; 34059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_io_address pblk = 0; 34159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 34259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk status = acpi_get_type(handle, &acpi_type); 34359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (ACPI_FAILURE(status)) 34459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 34559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 34659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk switch (acpi_type) { 34759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk case ACPI_TYPE_PROCESSOR: 34859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk status = acpi_evaluate_object(handle, NULL, NULL, &buffer); 34959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (ACPI_FAILURE(status)) 35059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 35159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_id = object.processor.proc_id; 35259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pblk = object.processor.pblk_address; 35359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk break; 35459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk case ACPI_TYPE_DEVICE: 35559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp); 35659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (ACPI_FAILURE(status)) 35759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 35859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_id = tmp; 35959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk break; 36059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk default: 36159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 36259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 36359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* There are more ACPI Processor objects than in x2APIC or MADT. 36459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * This can happen with incorrect ACPI SSDT declerations. */ 36559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (acpi_id > nr_acpi_bits) { 366283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_debug("We only have %u, trying to set %u\n", 36759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk nr_acpi_bits, acpi_id); 36859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 36959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 37059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* OK, There is a ACPI Processor object */ 37159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk __set_bit(acpi_id, acpi_id_present); 37259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 373283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_debug("ACPI CPU%u w/ PBLK:0x%lx\n", acpi_id, (unsigned long)pblk); 37459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 37559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); 37659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (ACPI_FAILURE(status)) { 37759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!pblk) 37859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 37959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 38059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* .. and it has a C-state */ 38159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk __set_bit(acpi_id, acpi_id_cst_present); 38259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 38359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return AE_OK; 38459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 38518c0025b692a293e3e4aecb34264563c0a442448Ben Guthrostatic int check_acpi_ids(struct acpi_processor *pr_backup) 38659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 38759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 38859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!pr_backup) 38959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENODEV; 39059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 3913fac10145b766a2244422788f62dc35978613fd8Ben Guthro if (acpi_id_present && acpi_id_cst_present) 3923fac10145b766a2244422788f62dc35978613fd8Ben Guthro /* OK, done this once .. skip to uploading */ 3933fac10145b766a2244422788f62dc35978613fd8Ben Guthro goto upload; 3943fac10145b766a2244422788f62dc35978613fd8Ben Guthro 39559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* All online CPUs have been processed at this stage. Now verify 39659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * whether in fact "online CPUs" == physical CPUs. 39759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 39859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_id_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); 39959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!acpi_id_present) 40059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENOMEM; 40159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 40259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_id_cst_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); 40359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!acpi_id_cst_present) { 40459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(acpi_id_present); 40559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENOMEM; 40659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 40759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 40859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, 40959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ACPI_UINT32_MAX, 41059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk read_acpi_id, NULL, NULL, NULL); 41159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_get_devices("ACPI0007", read_acpi_id, NULL, NULL); 41259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 4133fac10145b766a2244422788f62dc35978613fd8Ben Guthroupload: 41459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!bitmap_equal(acpi_id_present, acpi_ids_done, nr_acpi_bits)) { 41559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i; 41659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for_each_set_bit(i, acpi_id_present, nr_acpi_bits) { 41759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pr_backup->acpi_id = i; 41859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* Mask out C-states if there are no _CST or PBLK */ 41959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk pr_backup->flags.power = test_bit(i, acpi_id_cst_present); 42059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk (void)upload_pm_data(pr_backup); 42159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 42259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 4233fac10145b766a2244422788f62dc35978613fd8Ben Guthro 42459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return 0; 42559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 42659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic int __init check_prereq(void) 42759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 42859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct cpuinfo_x86 *c = &cpu_data(0); 42959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 43059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!xen_initial_domain()) 43159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENODEV; 43259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 43359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!acpi_gbl_FADT.smi_command) 43459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENODEV; 43559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 43659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (c->x86_vendor == X86_VENDOR_INTEL) { 43759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!cpu_has(c, X86_FEATURE_EST)) 43859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENODEV; 43959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 44059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return 0; 44159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 44259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (c->x86_vendor == X86_VENDOR_AMD) { 44359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* Copied from powernow-k8.h, can't include ../cpufreq/powernow 44459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * as we get compile warnings for the static functions. 44559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk */ 44659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 44759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk#define USE_HW_PSTATE 0x00000080 44859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk u32 eax, ebx, ecx, edx; 44959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); 45059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if ((edx & USE_HW_PSTATE) != USE_HW_PSTATE) 45159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENODEV; 45259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return 0; 45359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 45459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENODEV; 45559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 45659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* acpi_perf_data is a pointer to percpu data. */ 45759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic struct acpi_processor_performance __percpu *acpi_perf_data; 45859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 45959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic void free_acpi_perf_data(void) 46059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 46159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i; 46259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 46359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */ 46459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for_each_possible_cpu(i) 46559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk free_cpumask_var(per_cpu_ptr(acpi_perf_data, i) 46659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk ->shared_cpu_map); 46759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk free_percpu(acpi_perf_data); 46859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 46959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 4703fac10145b766a2244422788f62dc35978613fd8Ben Guthrostatic int xen_upload_processor_pm_data(void) 47159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 47259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_processor *pr_backup = NULL; 47359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk unsigned int i; 4743fac10145b766a2244422788f62dc35978613fd8Ben Guthro int rc = 0; 4753fac10145b766a2244422788f62dc35978613fd8Ben Guthro 476283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_info("Uploading Xen processor PM info\n"); 4773fac10145b766a2244422788f62dc35978613fd8Ben Guthro 4783fac10145b766a2244422788f62dc35978613fd8Ben Guthro for_each_possible_cpu(i) { 4793fac10145b766a2244422788f62dc35978613fd8Ben Guthro struct acpi_processor *_pr; 4803fac10145b766a2244422788f62dc35978613fd8Ben Guthro _pr = per_cpu(processors, i /* APIC ID */); 4813fac10145b766a2244422788f62dc35978613fd8Ben Guthro if (!_pr) 4823fac10145b766a2244422788f62dc35978613fd8Ben Guthro continue; 4833fac10145b766a2244422788f62dc35978613fd8Ben Guthro 4843fac10145b766a2244422788f62dc35978613fd8Ben Guthro if (!pr_backup) { 4853fac10145b766a2244422788f62dc35978613fd8Ben Guthro pr_backup = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); 4863fac10145b766a2244422788f62dc35978613fd8Ben Guthro if (pr_backup) 4873fac10145b766a2244422788f62dc35978613fd8Ben Guthro memcpy(pr_backup, _pr, sizeof(struct acpi_processor)); 4883fac10145b766a2244422788f62dc35978613fd8Ben Guthro } 4893fac10145b766a2244422788f62dc35978613fd8Ben Guthro (void)upload_pm_data(_pr); 4903fac10145b766a2244422788f62dc35978613fd8Ben Guthro } 4913fac10145b766a2244422788f62dc35978613fd8Ben Guthro 4923fac10145b766a2244422788f62dc35978613fd8Ben Guthro rc = check_acpi_ids(pr_backup); 4933fac10145b766a2244422788f62dc35978613fd8Ben Guthro kfree(pr_backup); 4943fac10145b766a2244422788f62dc35978613fd8Ben Guthro 4953fac10145b766a2244422788f62dc35978613fd8Ben Guthro return rc; 4963fac10145b766a2244422788f62dc35978613fd8Ben Guthro} 4973fac10145b766a2244422788f62dc35978613fd8Ben Guthro 498cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszkastatic int xen_acpi_processor_resume(struct notifier_block *nb, 499cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszka unsigned long action, void *data) 5003fac10145b766a2244422788f62dc35978613fd8Ben Guthro{ 5013fac10145b766a2244422788f62dc35978613fd8Ben Guthro bitmap_zero(acpi_ids_done, nr_acpi_bits); 502cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszka return xen_upload_processor_pm_data(); 5033fac10145b766a2244422788f62dc35978613fd8Ben Guthro} 5043fac10145b766a2244422788f62dc35978613fd8Ben Guthro 505cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszkastruct notifier_block xen_acpi_processor_resume_nb = { 506cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszka .notifier_call = xen_acpi_processor_resume, 5073fac10145b766a2244422788f62dc35978613fd8Ben Guthro}; 5083fac10145b766a2244422788f62dc35978613fd8Ben Guthro 5093fac10145b766a2244422788f62dc35978613fd8Ben Guthrostatic int __init xen_acpi_processor_init(void) 5103fac10145b766a2244422788f62dc35978613fd8Ben Guthro{ 5113fac10145b766a2244422788f62dc35978613fd8Ben Guthro unsigned int i; 51259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk int rc = check_prereq(); 51359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 51459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (rc) 51559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return rc; 51659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 51759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk nr_acpi_bits = get_max_acpi_id() + 1; 51859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_ids_done = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); 51959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!acpi_ids_done) 52059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENOMEM; 52159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 52259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_perf_data = alloc_percpu(struct acpi_processor_performance); 52359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!acpi_perf_data) { 524283c0972d53769ee44750cad4c27e3f5fa26ec1fJoe Perches pr_debug("Memory allocation error for acpi_perf_data\n"); 52559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(acpi_ids_done); 52659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return -ENOMEM; 52759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 52859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for_each_possible_cpu(i) { 52959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk if (!zalloc_cpumask_var_node( 53059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map, 53159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk GFP_KERNEL, cpu_to_node(i))) { 53259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk rc = -ENOMEM; 53359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk goto err_out; 53459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 53559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 53659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 53759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* Do initialization in ACPI core. It is OK to fail here. */ 53859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk (void)acpi_processor_preregister_performance(acpi_perf_data); 53959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 54059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for_each_possible_cpu(i) { 541c705c78c0d0835a4aa5d0d9a3422e3218462030cKonrad Rzeszutek Wilk struct acpi_processor *pr; 54259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_processor_performance *perf; 54359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 544c705c78c0d0835a4aa5d0d9a3422e3218462030cKonrad Rzeszutek Wilk pr = per_cpu(processors, i); 54559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk perf = per_cpu_ptr(acpi_perf_data, i); 546949dd8c14fb2b20b4b815817e66120b22cf531d4Konrad Rzeszutek Wilk if (!pr) 547949dd8c14fb2b20b4b815817e66120b22cf531d4Konrad Rzeszutek Wilk continue; 548949dd8c14fb2b20b4b815817e66120b22cf531d4Konrad Rzeszutek Wilk 549c705c78c0d0835a4aa5d0d9a3422e3218462030cKonrad Rzeszutek Wilk pr->performance = perf; 550c705c78c0d0835a4aa5d0d9a3422e3218462030cKonrad Rzeszutek Wilk rc = acpi_processor_get_performance_info(pr); 55127257fc07c044af99d85400c4bab670342bbc8a5Konrad Rzeszutek Wilk if (rc) 55259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk goto err_out; 55359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 55459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 5553fac10145b766a2244422788f62dc35978613fd8Ben Guthro rc = xen_upload_processor_pm_data(); 55617f9b896b06d314da890174584278dea8da7e0ceKonrad Rzeszutek Wilk if (rc) 55717f9b896b06d314da890174584278dea8da7e0ceKonrad Rzeszutek Wilk goto err_unregister; 55859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 559cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszka xen_resume_notifier_register(&xen_acpi_processor_resume_nb); 5603fac10145b766a2244422788f62dc35978613fd8Ben Guthro 56159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return 0; 56259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkerr_unregister: 56359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for_each_possible_cpu(i) { 56459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_processor_performance *perf; 56559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk perf = per_cpu_ptr(acpi_perf_data, i); 56659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_processor_unregister_performance(perf, i); 56759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 56859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkerr_out: 56959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ 57059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk free_acpi_perf_data(); 57159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(acpi_ids_done); 57259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk return rc; 57359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 57459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkstatic void __exit xen_acpi_processor_exit(void) 57559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk{ 57659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk int i; 57759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 578cd979883b9ede90643e019f33cb317933eb867b4Stanislaw Gruszka xen_resume_notifier_unregister(&xen_acpi_processor_resume_nb); 57959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk kfree(acpi_ids_done); 5803fac10145b766a2244422788f62dc35978613fd8Ben Guthro kfree(acpi_id_present); 5813fac10145b766a2244422788f62dc35978613fd8Ben Guthro kfree(acpi_id_cst_present); 58259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk for_each_possible_cpu(i) { 58359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk struct acpi_processor_performance *perf; 58459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk perf = per_cpu_ptr(acpi_perf_data, i); 58559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk acpi_processor_unregister_performance(perf, i); 58659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk } 58759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk free_acpi_perf_data(); 58859a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk} 58959a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 59059a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek WilkMODULE_AUTHOR("Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>"); 59159a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek WilkMODULE_DESCRIPTION("Xen ACPI Processor P-states (and Cx) driver which uploads PM data to Xen hypervisor"); 59259a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek WilkMODULE_LICENSE("GPL"); 59359a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk 59459a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk/* We want to be loaded before the CPU freq scaling drivers are loaded. 59559a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilk * They are loaded in late_initcall. */ 59659a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkdevice_initcall(xen_acpi_processor_init); 59759a56802918100c1e39e68c30a2e5ae9f7d837f0Konrad Rzeszutek Wilkmodule_exit(xen_acpi_processor_exit); 598