From patchwork Tue May 27 20:29:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 31019 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 49F50203C3 for ; Tue, 27 May 2014 20:30:17 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id m1sf51314526oag.2 for ; Tue, 27 May 2014 13:30:16 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=iCDJSmqYOg9Dw7/AGGugt1e+kNMLZo1rce1rUjrUP+g=; b=h4+jrIBYYUCx3FRgMlLSlXkU0tw1huZ2DWAL+sVCLfdLKqBmOaSrFKam3WIxte3NAM m6c/x5Z8PsaM06LTGix1Ro97LUPTucv9oBPlIZxKCI2pybkM2XgXGxsOMD++vWCmcfCZ SuzG87tfH9J2fzJRcOrJyLhcH9OGWWKG4Sx/oJ1e2WTxqT9eFWrfauUpTlJ3T2OL5hlu i8ZuYDactPP/46VBTBhU9kOZ+0/2yqdjSzamioAp80Wz48gGNie40xOTD9gHAhl/i/x0 XK53IhfKpZgR5uyggg3OGR9Jj8vNdrhVqsAhT42WsC0zk37Pi4P7TOLvdevp4MuyUNgE QJNQ== X-Gm-Message-State: ALoCoQkcernlE2eRdhdHUWbLfzCXjMmTuQVnuKkbvz+xLhmm4+Sns04QohS0t5yb6ScaY6rwi8Pt X-Received: by 10.42.83.17 with SMTP id f17mr13146047icl.17.1401222616709; Tue, 27 May 2014 13:30:16 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.183 with SMTP id 52ls3331691qgv.15.gmail; Tue, 27 May 2014 13:30:16 -0700 (PDT) X-Received: by 10.220.50.18 with SMTP id x18mr3339467vcf.66.1401222616563; Tue, 27 May 2014 13:30:16 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id ek8si8930910vdc.87.2014.05.27.13.30.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 May 2014 13:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id sa20so11316161veb.41 for ; Tue, 27 May 2014 13:30:16 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr25166911vdc.25.1401222616483; Tue, 27 May 2014 13:30:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp147789vcb; Tue, 27 May 2014 13:30:16 -0700 (PDT) X-Received: by 10.68.202.8 with SMTP id ke8mr39860149pbc.86.1401222615682; Tue, 27 May 2014 13:30:15 -0700 (PDT) Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51]) by mx.google.com with ESMTPS id yp2si20274062pbb.134.2014.05.27.13.30.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 May 2014 13:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ashwin.chaugule@linaro.org designates 209.85.160.51 as permitted sender) client-ip=209.85.160.51; Received: by mail-pb0-f51.google.com with SMTP id ma3so9808609pbc.24 for ; Tue, 27 May 2014 13:30:15 -0700 (PDT) X-Received: by 10.66.164.201 with SMTP id ys9mr39921932pab.40.1401222615111; Tue, 27 May 2014 13:30:15 -0700 (PDT) Received: from linaro5.qualcomm.com (rrcs-67-52-130-30.west.biz.rr.com. [67.52.130.30]) by mx.google.com with ESMTPSA id ln2sm51701167pab.35.2014.05.27.13.30.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 May 2014 13:30:14 -0700 (PDT) From: Ashwin Chaugule To: rjw@rjwysocki.net Cc: linux-arm-kernel@lists.infradead.org, linaro-acpi@lists.linaro.org, linux-acpi@vger.kernel.org, patches@linaro.org, Ashwin Chaugule Subject: [RFC 2/2] PCC Test driver Date: Tue, 27 May 2014 16:29:59 -0400 Message-Id: <1401222599-12416-3-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401222599-12416-1-git-send-email-ashwin.chaugule@linaro.org> References: <1401222599-12416-1-git-send-email-ashwin.chaugule@linaro.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.128.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Opens a node in /proc/pcc_test. Echo 0 for PCC read Echo 1 for PCC write Echo 2 for read base addr of PCC channel Signed-off-by: Ashwin Chaugule --- drivers/acpi/Makefile | 2 +- drivers/acpi/pcc-test.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/pcc-test.c diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index d8aa613..f7bbbe9 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -74,7 +74,7 @@ obj-$(CONFIG_ACPI_HED) += hed.o obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o obj-$(CONFIG_ACPI_BGRT) += bgrt.o -obj-$(CONFIG_ACPI_PCC) += pcc.o +obj-$(CONFIG_ACPI_PCC) += pcc.o pcc-test.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o processor_throttling.o processor-y += processor_idle.o processor_thermal.o diff --git a/drivers/acpi/pcc-test.c b/drivers/acpi/pcc-test.c new file mode 100644 index 0000000..cb6ee10 --- /dev/null +++ b/drivers/acpi/pcc-test.c @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2014 Linaro Ltd. + * Author: Ashwin Chaugule + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static u64 pcc_comm_base_addr; /* Returned by the Subspace structure */ +static u64 *comm_base_addr; /* For use after ioremap */ + +extern int get_pcc_comm_channel(u32 ss_idx, u64* addr, int *len); +extern u16 send_pcc_cmd(u8 cmd, u8 sci, u32 ss_idx, u64 * __iomem base_addr); + +/* XXX: The PCC Subspace id is hard coded here only for test purposes. + * In reality it should be parsed from the PCC package as described + * in the PCC client table. e.g. CPC for CPPC + */ +#define PCC_SUBSPACE_IDX 0 +#define CMD_COMPLETE 1 + +enum ppc_cmds { + CMD_READ, + CMD_WRITE, + RESERVED, +}; + +static u64 reg1, reg2; + +static void run_pcc_test_read(void) +{ + u16 pcc_status; + u64 reg1_addr = comm_base_addr + 8; + u64 reg2_addr = comm_base_addr + 16; + + /* READ part of the test */ + pr_info("Sending PCC read req from Channel base addr: %llx\n", pcc_comm_base_addr); + pcc_status = send_pcc_cmd(CMD_READ, 0, PCC_SUBSPACE_IDX, &pcc_comm_base_addr); + if (pcc_status & CMD_COMPLETE) { + pr_info("Read updated values from Platform.\n"); + reg1 = iorea32(®1_addr); + reg2 = ioread32(®2_addr); + pr_info("updated value of reg1:%llx\n", reg1); + pr_info("updated value of reg2:%llx\n", reg2); + } else + pr_err("Failed to read PCC parameters\n"); +} + +static void run_pcc_test_write(void) +{ + u16 pcc_status; + u64 reg1_addr = comm_base_addr + 8; + u64 reg2_addr = comm_base_addr + 16; + + /* WRITE part of the test */ + reg1++; + reg2++; + + iowrite32(reg1, ®1_addr); + iowrite32(reg2, ®2_addr); + + pr_info("Sending PCC write req from Channel base addr: %p\n", comm_base_addr); + pcc_status = send_pcc_cmd(CMD_WRITE, 0, PCC_SUBSPACE_IDX, comm_base_addr); + if (pcc_status & CMD_COMPLETE) + pr_info("OSPM successfully sent PCC read cmd to platform\n"); + else + pr_err("Failed to write PCC parameters. \n"); +} + +void get_pcc_comm(void) +{ + int ret, len; + + ret = get_pcc_comm_channel(PCC_SUBSPACE_IDX, &pcc_comm_base_addr, &len); + + if (ret) { + pr_err("No PCC Communication channel found\n"); + goto out_err; + } + + comm_base_addr = ioremap_nocache(pcc_comm_base_addr, len); + + if (!comm_base_addr) + pr_err("Could not map PCC communicate channel\n"); + + pr_info("Acquired PCC comm channel base addr: %llx\n", pcc_comm_base_addr); + +out_err: + return; +} + +static ssize_t pcc_test_write(struct file *file, const char __user *buf, + size_t count, loff_t *offs) +{ + char ctl[2]; + + if (count != 2 || *offs) + return -EINVAL; + + if (copy_from_user(ctl, buf, count)) + return -EFAULT; + + switch (ctl[0]) { + case '0': + /* PCC read */ + run_pcc_test_read(); + break; + case '1': + /* PCC write */ + run_pcc_test_write(); + break; + case '2': + /* Get PCC channel */ + get_pcc_comm(); + break; + default: + pr_err("Unknown val\n"); + break; + } + + return count; +} + +static int pcc_test_open(struct inode *inode, struct file *filp) +{ + return 0; +} + +static int pcc_test_release(struct inode *inode, struct file *filp) +{ + return 0; +} + +static const struct file_operations pcc_test_fops = { + .open = pcc_test_open, +// .read = seq_read, + .write = pcc_test_write, + .release = pcc_test_release, +}; + +static int __init pcc_test(void) +{ + struct proc_dir_entry *pe; + + pe = proc_create("pcc_test", 0644, NULL, &pcc_test_fops); + + if (!pe) + return -ENOMEM; + + return 0; +} + +late_initcall(pcc_test);