From patchwork Thu Jun 12 16:48:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 31852 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f197.google.com (mail-yk0-f197.google.com [209.85.160.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 60FFB2054B for ; Thu, 12 Jun 2014 16:48:31 +0000 (UTC) Received: by mail-yk0-f197.google.com with SMTP id 19sf3559753ykq.0 for ; Thu, 12 Jun 2014 09:48:31 -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=3VU2zTdjOpOyWLQRfswh90juZKD3UmTZqqKOGMadMgg=; b=hyzrTOGw0aWY0tf9HbSPflq4VddIdasU6XDzg8IZh5nxylOioqu3DdrFNoSqXONmQT xQgdzm3XkVRwnWkCVMi8SEUi3wBTOKYzMmwgLdbWDjtTNopju7Q3MAFnX+U72DrFewc3 Syp8a9a2mq/k+uQUgk0FJP3W63/T+J/Xjv8XMlxloq5vthqs7tleBtM/U3eNQ34mflQj x4m8xF3dh88DUlvlxEBLjVlpHDChiB8GkkBv+OhVO56M2r0lrX5vHZzT5fAMtA8+IlRB ET2dyDsMn2FEbnD7YTCWv1FaLZryu9b/htX4Z8Yd+IV5faJcLp7xRvzEW8Ofml1DFJkk 2ENQ== X-Gm-Message-State: ALoCoQn9gexujvkpv1UtvNbcxIC8KUFObBxxsLCZX3lRadDUJ0oqFJCnuY9LnLwxICy7GLjpw1sN X-Received: by 10.58.107.203 with SMTP id he11mr855085veb.12.1402591711208; Thu, 12 Jun 2014 09:48:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.200 with SMTP id m66ls2998023qge.83.gmail; Thu, 12 Jun 2014 09:48:31 -0700 (PDT) X-Received: by 10.220.175.70 with SMTP id w6mr41502vcz.72.1402591711111; Thu, 12 Jun 2014 09:48:31 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id ef2si490885vdc.41.2014.06.12.09.48.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 09:48:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id us18so2077230veb.34 for ; Thu, 12 Jun 2014 09:48:31 -0700 (PDT) X-Received: by 10.52.135.208 with SMTP id pu16mr8799653vdb.8.1402591711025; Thu, 12 Jun 2014 09:48:31 -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.221.54.6 with SMTP id vs6csp418071vcb; Thu, 12 Jun 2014 09:48:30 -0700 (PDT) X-Received: by 10.66.251.233 with SMTP id zn9mr22867376pac.67.1402591710168; Thu, 12 Jun 2014 09:48:30 -0700 (PDT) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by mx.google.com with ESMTPS id zz8si42169524pbc.43.2014.06.12.09.48.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 09:48:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ashwin.chaugule@linaro.org designates 209.85.220.51 as permitted sender) client-ip=209.85.220.51; Received: by mail-pa0-f51.google.com with SMTP id ey11so1203578pad.10 for ; Thu, 12 Jun 2014 09:48:29 -0700 (PDT) X-Received: by 10.66.226.172 with SMTP id rt12mr22290804pac.101.1402591709664; Thu, 12 Jun 2014 09:48:29 -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 xz7sm7701153pac.3.2014.06.12.09.48.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 09:48:28 -0700 (PDT) From: Ashwin Chaugule To: linux-acpi@vger.kernel.org Cc: linaro-acpi@lists.linaro.org, broonie@kernel.org, jassisinghbrar@gmail.com, linux-arm-kernel@lists.infradead.org, rjw@rjwysocki.net, patches@linaro.org, Ashwin Chaugule Subject: [RFC v2 3/3] PCC test driver Date: Thu, 12 Jun 2014 12:48:12 -0400 Message-Id: <1402591692-7736-4-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402591692-7736-1-git-send-email-ashwin.chaugule@linaro.org> References: <1402591692-7736-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.175 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: , A simple test driver to register as a PCC mailbox client and send PCC reads/writes via the PCC mailbox controller. echo 2 > /proc/pcc_test to register client. echo 1 > /proc/pcc_test for PCC writes. echo 0 > /proc/pcc_test for PCC reads. Signed-off-by: Ashwin Chaugule --- drivers/acpi/Makefile | 2 +- drivers/acpi/pcc-test.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 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..4ba8c1f --- /dev/null +++ b/drivers/acpi/pcc-test.c @@ -0,0 +1,208 @@ +/* + * 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 + +#include + +#include + +static void __iomem *comm_base_addr; /* For use after ioremap */ + +extern int mbox_controller_register(struct mbox_controller *mbox); +extern struct mbox_chan *mbox_request_channel(struct mbox_client *cl); +extern int mbox_send_message(struct mbox_chan *chan, void *mssg); + + +/* 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 + +struct mbox_chan *pcc_test_chan; +enum ppc_cmds { + CMD_READ, + CMD_WRITE, + RESERVED, +}; + +static u32 reg1, reg2; + +static void run_pcc_test_read(void) +{ + u32 reg1_addr = (u32)comm_base_addr + 0x100; + u32 reg2_addr = (u32)comm_base_addr + 0x110; + char mssg[2]; + int ret; + + /* READ part of the test */ + pr_info("Sending PCC read req from Channel base addr: %x\n", (u32)comm_base_addr); + + snprintf(mssg, sizeof(short), "%d", CMD_READ); + ret = mbox_send_message(pcc_test_chan, &mssg); + if (ret >= 0) { + pr_info("Read updated values from Platform.\n"); + reg1 = ioread32((void*)reg1_addr); + reg2 = ioread32((void*)reg2_addr); + pr_info("updated value of reg1:%x\n", reg1); + pr_info("updated value of reg2:%x\n", reg2); + } else + pr_err("Failed to read PCC parameters: ret=%d\n", ret); +} + +static void run_pcc_test_write(void) +{ + u32 reg1_addr = (u32)comm_base_addr + 0x100; + u32 reg2_addr = (u32)comm_base_addr + 0x110; + char mssg[2]; + int ret; + + /* WRITE part of the test */ + reg1++; + reg2++; + + iowrite32(reg1, (void *)reg1_addr); + iowrite32(reg2, (void *)reg2_addr); + + pr_info("Sending PCC write req from Channel base addr: %x\n", (u32)comm_base_addr); + snprintf(mssg, sizeof(short), "%d", CMD_WRITE); + + ret = mbox_send_message(pcc_test_chan, &mssg); + + if (ret >= 0) + pr_info("OSPM successfully sent PCC write cmd to platform\n"); + else + pr_err("Failed to write PCC parameters. ret= %d\n", ret); +} + +static void pcc_chan_tx_done(struct mbox_client *cl, void *mssg, enum mbox_result r) +{ + if (r == MBOX_OK) + pr_info("PCC channel TX successfully completed. CMD sent = %s\n", (char*)mssg); + else + pr_warn("PCC channel TX did not complete: CMD sent = %s\n", (char*)mssg); +} + +struct mbox_client pcc_mbox_cl = { + .chan_name = "0", + .ctrl_name = "PCCT", + .tx_done = pcc_chan_tx_done, +}; + +void get_pcc_comm(void) +{ + u32 base_addr; + u32 len; + struct acpi_pcct_subspace *pcc_ss; + + pcc_test_chan = mbox_request_channel(&pcc_mbox_cl); + + if (!pcc_test_chan) { + pr_err("PCC Channel not found!\n"); + return; + } + + pcc_ss = pcc_test_chan->con_priv; + + base_addr = pcc_ss->base_address; + len = pcc_ss->length; + + pr_info("ioremapping: %x, len: %x\n", base_addr, len); + + comm_base_addr = ioremap_nocache(base_addr, len); + + if (!comm_base_addr) { + pr_err("Could not ioremap channel\n"); + return; + } + + pcc_ss->base_address = (u32)comm_base_addr; + + pr_info("Comm_base_addr: %x\n", (u32)comm_base_addr); +} + +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);