From patchwork Wed Oct 8 20:11:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 38491 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 83E6C202E7 for ; Wed, 8 Oct 2014 20:11:46 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id a1sf5593243wgh.5 for ; Wed, 08 Oct 2014 13:11:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=5L8KqW8Z/5EDMWGFV9rkU5CpgAGJx5PfvtdMawGV/4Q=; b=mT2AKjmFocj6dQMP2azaELmQcyssHgxK0np0I01svahK6Q1qcfpeJiwKTnf2Hj5/HS PbvI9oIbdvQxbt9opvIRFc2llAnggZmVM6eH4fwQuT4T8kzV7+ecFi+wqox0+yH+wWUo d6aZxwefiy3Fh7FnJdJltMlEHMz8plt3DmGXt87N6cQxx0oEkLH2P1hHZJZVRs1s8ocZ 84W9d8SW6NiU2ip4RTzkwPJG7aqknF8LBPFzRYZ5qsJlSFBPE1pqCZrlKRlUXS/a5GpQ BUnER+VzWSwRde5LYF/c0zT8Lp0Tqhuh2ppC0zKaj63mgJ243Wl/2s72Y0eLpB06qrbX oVNg== X-Gm-Message-State: ALoCoQnmYNeAdsNiaGeFP6pvZz/HKEiUsoMxhNYTRX5lmZJ0vuGwegveGVlcRP1riUT8YbyDKEpT X-Received: by 10.152.19.131 with SMTP id f3mr1907328lae.0.1412799105701; Wed, 08 Oct 2014 13:11:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.130 with SMTP id l2ls95867lag.45.gmail; Wed, 08 Oct 2014 13:11:45 -0700 (PDT) X-Received: by 10.112.149.36 with SMTP id tx4mr13316971lbb.79.1412799105423; Wed, 08 Oct 2014 13:11:45 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com [209.85.217.177]) by mx.google.com with ESMTPS id ld4si1545236lab.73.2014.10.08.13.11.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Oct 2014 13:11:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id w7so8807426lbi.22 for ; Wed, 08 Oct 2014 13:11:45 -0700 (PDT) X-Received: by 10.153.7.73 with SMTP id da9mr13908432lad.56.1412799105339; Wed, 08 Oct 2014 13:11:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp126718lbz; Wed, 8 Oct 2014 13:11:44 -0700 (PDT) X-Received: by 10.70.59.36 with SMTP id w4mr13761561pdq.141.1412799103226; Wed, 08 Oct 2014 13:11:43 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si646372pdd.197.2014.10.08.13.11.41 for ; Wed, 08 Oct 2014 13:11:43 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754976AbaJHULk (ORCPT + 15 others); Wed, 8 Oct 2014 16:11:40 -0400 Received: from mail-vc0-f173.google.com ([209.85.220.173]:38928 "EHLO mail-vc0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754627AbaJHULk (ORCPT ); Wed, 8 Oct 2014 16:11:40 -0400 Received: by mail-vc0-f173.google.com with SMTP id ij19so7426085vcb.4 for ; Wed, 08 Oct 2014 13:11:38 -0700 (PDT) X-Received: by 10.52.72.167 with SMTP id e7mr10183197vdv.83.1412799098333; Wed, 08 Oct 2014 13:11:38 -0700 (PDT) Received: from localhost.localdomain (cpe-098-027-049-158.nc.res.rr.com. [98.27.49.158]) by mx.google.com with ESMTPSA id yf12sm946199vdc.18.2014.10.08.13.11.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Oct 2014 13:11:37 -0700 (PDT) From: Ashwin Chaugule To: viresh.kumar@linaro.org Cc: dirk.brandewie@gmail.com, rwells@codeaurora.org, rjw@rjwysocki.net, linaro-acpi@lists.linaro.org, linux-pm@vger.kernel.org, Catalin.Marinas@arm.com, linda.knippers@hp.com, Ashwin Chaugule Subject: [RFC PATCH v2 1/3] PCC HACKS: Update PCC comm region with MSR data Date: Wed, 8 Oct 2014 16:11:02 -0400 Message-Id: <1412799064-2339-2-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412799064-2339-1-git-send-email-ashwin.chaugule@linaro.org> References: <1412799064-2339-1-git-send-email-ashwin.chaugule@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ashwin.chaugule@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Not for upstreaming. Hacked for experiments on the the Thinkpad X240. The pcc_send_data() function is modified to read certain MSRs and update a shared memory region. This enables the PCC client (CPPC in this case) to read from the buffer as though it were getting data from a remote processor. Signed-off-by: Ashwin Chaugule --- drivers/mailbox/pcc.c | 125 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 16 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index a16991e..27d0e61 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -98,22 +98,22 @@ static bool pcc_tx_done(struct mbox_chan *chan) u16 cmd_delay = pcct_ss->min_turnaround_time; unsigned int retries = 0; - /* Try a few times while waiting for platform to consume */ - while (!(readw_relaxed(&generic_comm_base->status) - & PCC_CMD_COMPLETE)) { - - if (retries++ < 5) - udelay(cmd_delay); - else { - /* - * If the remote is dead, this will cause the Mbox - * controller to timeout after mbox client.tx_tout - * msecs. - */ - pr_err("PCC platform did not respond.\n"); - return false; - } - } +// /* Try a few times while waiting for platform to consume */ +// while (!(readw_relaxed(&generic_comm_base->status) +// & PCC_CMD_COMPLETE)) { +// +// if (retries++ < 5) +// udelay(cmd_delay); +// else { +// /* +// * If the remote is dead, this will cause the Mbox +// * controller to timeout after mbox client.tx_tout +// * msecs. +// */ +// pr_err("PCC platform did not respond.\n"); +// return false; +// } +// } return true; } @@ -127,6 +127,97 @@ static int get_subspace_id(struct mbox_chan *chan) return id; } +#define PCC_HACK + +#ifdef PCC_HACK + +#include + +/* These offsets are from the SSDT9.asl table on the Thinkpad X240 */ + +/* These are offsets per CPU from which its CPC table begins. */ +int cpu_base[] = {0, 0x64, 0xC8, 0x12C, 0x190, 0x1F4, 0x258, 0x2BC}; + +/* These are offsets of the registers in each CPC table. */ +#define HIGHEST_PERF_OFFSET 0x0 +#define LOWEST_PERF_OFFSET 0xc +#define DESIRED_PERF_OFFSET 0x14 + +static int core_get_min(void) +{ + u64 val; + rdmsrl(MSR_PLATFORM_INFO, val); + return (val >> 40) & 0xff; +} + +static int core_get_max(void) +{ + u64 val; + rdmsrl(MSR_PLATFORM_INFO, val); + return (val >> 8) & 0xff; +} + +static int core_get_turbo(void) +{ + u64 value; + int nont, ret; + + rdmsrl(MSR_NHM_TURBO_RATIO_LIMIT, value); + nont = core_get_max(); + ret = ((value) & 255); + if (ret <= nont) + ret = nont; + return ret; +} + +static int pcc_send_data(struct mbox_chan *chan, void *data) +{ + struct acpi_pcct_subspace *pcct_ss = chan->con_priv; + u64 pcc_comm_addr = pcct_ss->base_address; + unsigned int cpu; + u16 cmd = *(u16 *) data; + u64 desired_val; + + /*XXX: Instead of waiting for platform to consume the cmd, + * just do what the platform would've done. + */ + switch (cmd) { + case 0: //PCC_CMD_READ + + /* XXX: Normally the Platform would need to update all the other CPPC registers as well. + * But for this experiment, since we're not really using all of them, we'll only update + * what we use. + */ + for_each_possible_cpu(cpu) { + *(char*)(pcc_comm_addr + cpu_base[cpu] + HIGHEST_PERF_OFFSET) = core_get_turbo(); + *(char*)(pcc_comm_addr + cpu_base[cpu] + LOWEST_PERF_OFFSET) = core_get_min(); + } + break; + case 1: //PCC_CMD_WRITE + + /* XXX: All this hackery is very X86 Thinkpad X240 specific. + * Normally, the cpc_write64() would have all the info on + * how, where and what to write. + */ + for_each_possible_cpu(cpu) { + desired_val = *(u64*)(pcc_comm_addr + cpu_base[cpu] + DESIRED_PERF_OFFSET); + + if (desired_val) { + wrmsrl_on_cpu(cpu, MSR_IA32_PERF_CTL, desired_val << 8); + *(u64*)(pcc_comm_addr + cpu_base[cpu] + DESIRED_PERF_OFFSET) = 0; + } + } + break; + default: + pr_err("Unknown PCC cmd from the OS\n"); + return 0; + } + + return 0; +} + +#else + /* Channel lock is already held by mbox controller code. */ static int pcc_send_data(struct mbox_chan *chan, void *data) { @@ -171,6 +262,8 @@ out_err: return ret; } +#endif + static struct mbox_chan_ops pcc_chan_ops = { .send_data = pcc_send_data, .last_tx_done = pcc_tx_done,