From patchwork Tue Aug 26 19:35:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 36050 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 6D5152054F for ; Tue, 26 Aug 2014 19:36:41 +0000 (UTC) Received: by mail-yk0-f197.google.com with SMTP id 142sf50403626ykq.4 for ; Tue, 26 Aug 2014 12:36:41 -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=21pmJW8Zfpm0/AWGcxPM2HTrnmBYqGwyMw5/xiJOKZ0=; b=HDMDefthRcjNkP20aMwAKehcQz1wtaKT/X6RTK0he7ORZDwbkYFOmAz/DIlYTrUc1V Pua/26+kf1TPVo7oDO/OPkZ7XjrVEx9PmzVHDPKBvc5QYFRRZ0zBvuigCO+KlTlzIgZ+ VRmS6vucRo9U1H7BdLXNabkpJmHR7Du8Z6/GUwPbkzmiDep20r3t2pdcV/MOxFUxomgi 0viWK0HuutZZ3t6diNKYym2oE/3GnSZA8cwBt2scVkJxsVNjJZ2ncTF84Nk36UrZQJQ2 7OE6TvAr3f+mChWQtS0TaVAe07pgyfpbsWLfvIr/t6m+BYbAv9fgVPWUJPl8gL+txVud fSpw== X-Gm-Message-State: ALoCoQkIHccL/po33r5giEOAQzVQ7tNMQvIYXc0URKkGj/TXapMTiC0845Ba3qaIaNUyEP2z6GNa X-Received: by 10.236.180.202 with SMTP id j50mr6359528yhm.51.1409081801256; Tue, 26 Aug 2014 12:36:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.242 with SMTP id m105ls2782534qga.84.gmail; Tue, 26 Aug 2014 12:36:41 -0700 (PDT) X-Received: by 10.236.99.39 with SMTP id w27mr5136908yhf.109.1409081801141; Tue, 26 Aug 2014 12:36:41 -0700 (PDT) Received: from mail-yk0-f180.google.com (mail-yk0-f180.google.com [209.85.160.180]) by mx.google.com with ESMTPS id h68si1083625yhb.64.2014.08.26.12.36.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Aug 2014 12:36:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.160.180 as permitted sender) client-ip=209.85.160.180; Received: by mail-yk0-f180.google.com with SMTP id 200so11880679ykr.11 for ; Tue, 26 Aug 2014 12:36:41 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr2333478vcd.49.1409081800977; Tue, 26 Aug 2014 12:36:40 -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.221.45.67 with SMTP id uj3csp224467vcb; Tue, 26 Aug 2014 12:36:40 -0700 (PDT) X-Received: by 10.70.95.100 with SMTP id dj4mr37021318pdb.94.1409081800088; Tue, 26 Aug 2014 12:36:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kg8si5607247pab.152.2014.08.26.12.36.39 for ; Tue, 26 Aug 2014 12:36:40 -0700 (PDT) Received-SPF: none (google.com: linux-acpi-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 S1753814AbaHZTgi (ORCPT + 8 others); Tue, 26 Aug 2014 15:36:38 -0400 Received: from mail-qc0-f176.google.com ([209.85.216.176]:42587 "EHLO mail-qc0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752339AbaHZTgf (ORCPT ); Tue, 26 Aug 2014 15:36:35 -0400 Received: by mail-qc0-f176.google.com with SMTP id m20so15808754qcx.7 for ; Tue, 26 Aug 2014 12:36:34 -0700 (PDT) X-Received: by 10.224.161.140 with SMTP id r12mr19120877qax.74.1409081794731; Tue, 26 Aug 2014 12:36:34 -0700 (PDT) Received: from esagroth.qualcomm.com (rrcs-67-52-130-30.west.biz.rr.com. [67.52.130.30]) by mx.google.com with ESMTPSA id x3sm12217376qam.15.2014.08.26.12.36.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Aug 2014 12:36:33 -0700 (PDT) From: Ashwin Chaugule To: arnd@arndb.de Cc: Ashwin Chaugule , linux-acpi@vger.kernel.org, linaro-acpi@lists.linaro.org, rjw@rjwysocki.net, broonie@kernel.org Subject: [PATCH v3 3/3] PCC-test: Test driver to trigger PCC commands Date: Tue, 26 Aug 2014 15:35:38 -0400 Message-Id: <1409081738-5602-4-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409081738-5602-1-git-send-email-ashwin.chaugule@linaro.org> References: <1409081738-5602-1-git-send-email-ashwin.chaugule@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@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.160.180 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: , echo 2 > /proc/pcc_test [ to get channel base address ] echo 1 > /proc/pcc_test [ to trigger a PCC write ] echo 0 > /proc/pcc_test [ to trigger a PCC read ] The pcc-test driver is implemented as an example of a PCC Mailbox client. Signed-off-by: Ashwin Chaugule --- drivers/mailbox/Makefile | 2 +- drivers/mailbox/pcc-test.c | 208 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 drivers/mailbox/pcc-test.c diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 3f57ee9..695d6ab 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -10,4 +10,4 @@ mailbox_omap1-objs := mailbox-omap1.o obj-$(CONFIG_OMAP2PLUS_MBOX) += mailbox_omap2.o mailbox_omap2-objs := mailbox-omap2.o -obj-$(CONFIG_PCC) += pcc.o +obj-$(CONFIG_PCC) += pcc.o pcc-test.o diff --git a/drivers/mailbox/pcc-test.c b/drivers/mailbox/pcc-test.c new file mode 100644 index 0000000..737a036 --- /dev/null +++ b/drivers/mailbox/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 *pcc_mbox_request_channel(struct mbox_client *, char *, unsigned int); +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 u64 reg1, reg2; + +static void run_pcc_test_read(void) +{ + u64 reg1_addr = (u64)comm_base_addr + 0x100; + u64 reg2_addr = (u64)comm_base_addr + 0x110; + char mssg[2]; + int ret; + + /* READ part of the test */ + pr_info("Sending PCC read req from Channel base addr: %llx\n", (u64)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 = readq((void*)reg1_addr); + reg2 = readq((void*)reg2_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: ret=%d\n", ret); +} + +static void run_pcc_test_write(void) +{ + u64 reg1_addr = (u64)comm_base_addr + 0x100; + u64 reg2_addr = (u64)comm_base_addr + 0x110; + char mssg[2]; + int ret; + + /* WRITE part of the test */ + reg1++; + reg2++; + + writeq(reg1, (void *)reg1_addr); + writeq(reg2, (void *)reg2_addr); + + pr_info("Sending PCC write req from Channel base addr: %llx\n", (u64)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, int ret) +{ + if (!ret) + 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 = { + .tx_done = pcc_chan_tx_done, +}; + +void get_pcc_comm(void) +{ + u64 base_addr; + u32 len; + struct acpi_pcct_subspace *pcc_ss; + + pcc_test_chan = pcc_mbox_request_channel(&pcc_mbox_cl, "PCCT", PCC_SUBSPACE_IDX); + + 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: %llx, len: %x\n", base_addr, len); + +// comm_base_addr = ioremap_nocache(base_addr, len); + /* HACK to test PCC commands */ + comm_base_addr = kzalloc(PAGE_SIZE, GFP_KERNEL); + + if (!comm_base_addr) { + pr_err("Could not ioremap channel\n"); + return; + } + + pcc_ss->base_address = (u64)comm_base_addr; + + pr_info("Comm_base_addr: %llx\n", (u64)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);