From patchwork Mon Aug 14 22:46:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 110072 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4939338qge; Mon, 14 Aug 2017 15:48:07 -0700 (PDT) X-Received: by 10.98.152.155 with SMTP id d27mr26146202pfk.245.1502750887607; Mon, 14 Aug 2017 15:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502750887; cv=none; d=google.com; s=arc-20160816; b=ve1C9Cz93msbaYMtkdEteV6rF7NsarhuJlK1HVOopadv95e6zCHi+2n1Wh98AxbouA C9Nrh3WK7KLGXa3Owpe9Zi5Zv5rTM1zVSKIxx9FfbQ3NK6isLm8WB2fx7sjkpuZWgtVj +5uvqEm0wz0rtPs0JEg4mlHpAnGnYto+X3GG78wTYb1umlRvRg/tkjXbO+fd0hN/Nosn ZAbSkp2mWIfHIauQG7hc1cAiYZL7kS+rQ0VK1eAoQjdF4Nf+9PfT3K9HrVdUjoh8zpoJ 4HAt6PJrrVwPEMPESFHPle762JROnLmUI0RRRslLgB1MLYZ4MGMH1uId4YZoGpTzYgL5 UaVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=eGppC/hwCK3kLvk70rBYB3Z5e7j2IQ/VBW6Ywqgs5Fo=; b=jMDpIGc/XhtwJc45gAAlDipATXhSL7BYepWKrrLy0eTOEUf8LZSte/Ru+3m9dTQP6R n9pYyS/74W53umCBkWa/jFBbbYib3ewZt24Y1AVvnzSkyaX9fpdpUiq1ALKo2mzVUArC S2DBo1fOZSwKnzPSp5bvpjZWRK+WtMSbaArNCBavM0MSZXZdlkYBntv55WqTnnInQk39 N9+NV0mJ2DtU0hN6alLRZug2GCHSVrs5H2JEeMb/NF8pvsPMWan3SUikl9KqY/s6UxSc YwQKhaVhALa13KR92+bN4J+MzBKbx//TmpTZ02xv9o5ERQStQ53WzeNB/tUcT5+5+qWn XYNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ho83fqOq; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si5333612pln.567.2017.08.14.15.48.07; Mon, 14 Aug 2017 15:48:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ho83fqOq; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752969AbdHNWr7 (ORCPT + 9 others); Mon, 14 Aug 2017 18:47:59 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:37873 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752689AbdHNWqY (ORCPT ); Mon, 14 Aug 2017 18:46:24 -0400 Received: by mail-pg0-f43.google.com with SMTP id y129so55910587pgy.4 for ; Mon, 14 Aug 2017 15:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=njCLR64tv+EpKjX6lTu3rn2DtwHQepzGz+xXmBuNIqI=; b=Ho83fqOq9p4tMh7br0HyYy/4Y5LgPMh46cwIS5o8tdERb1h+McfFYycIZ9yvJdUcuI ZwP5u/zyAxjqgdjzkY08cgruf+XKFuYLdXaCfBl/MDzoJ2ikeJQchiwfVfjOIduv/3V+ oRQdfDXMiFrm8e5T8Gl0ctA4AsEoeMMjOoJ2I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=njCLR64tv+EpKjX6lTu3rn2DtwHQepzGz+xXmBuNIqI=; b=trOK0sUFPMaqBlfsi8gUGRycd0WBTnZyal43yxHZoqmKrcoK2vvjEze4JgPMmOJTx2 KiukKpD1ynAWrSUmXlF4Bv2CXHrisSBRng6OfJ/P2q6qPtjJK7/+PbgudiDaJ5nUJ7pF IMDt8v+Mdwf+ZGW1Dh6UIQkjUXaCm6UOPEO1bseLI6zvlt3u8+cnCi5Voe4MGLwaRb4s WluD/QTK2cu15S0biYB1XOzTeYFdBEQJMNEwI+lmyHvf2/o7V/mz+51bNx9La/S4fGlZ TA6WW31gDat4jGjnKpDe+DoJIyhqw13c07hlmLwTbib8sSmoa/dkupm/Bp11WS3NNEp7 EQkw== X-Gm-Message-State: AHYfb5jlad593XzeM20Wo3gkh933qzAeHpHHJZ9VCrDCWPTgQ8ct4KfR tg9g6LvaUzAy9kGk X-Received: by 10.84.147.71 with SMTP id r7mr29158292ple.461.1502750784279; Mon, 14 Aug 2017 15:46:24 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id 15sm19839428pfo.57.2017.08.14.15.46.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 15:46:23 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , David Brown Cc: Rob Herring , Mark Rutland , Stephen Boyd , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org Subject: [PATCH v4 1/3] firmware: qcom: scm: Expose secure IO service Date: Mon, 14 Aug 2017 15:46:17 -0700 Message-Id: <20170814224619.29256-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170814224619.29256-1-bjorn.andersson@linaro.org> References: <20170814224619.29256-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The secure IO service provides operations for reading and writing secure memory from non-secure mode, expose this API through SCM. Reviewed-by: Stephen Boyd Signed-off-by: Bjorn Andersson --- Changes since v3: - None Changes since v2: - Picked up Stephen's r-b Changes since v1: - Correct scm-call return value handling - Make scm_io_readl() return data by reference drivers/firmware/qcom_scm-32.c | 18 ++++++++++++++++++ drivers/firmware/qcom_scm-64.c | 31 +++++++++++++++++++++++++++++++ drivers/firmware/qcom_scm.c | 12 ++++++++++++ drivers/firmware/qcom_scm.h | 6 ++++++ include/linux/qcom_scm.h | 4 ++++ 5 files changed, 71 insertions(+) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c index 93e3b96b6dfa..11fdb1584823 100644 --- a/drivers/firmware/qcom_scm-32.c +++ b/drivers/firmware/qcom_scm-32.c @@ -596,3 +596,21 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, { return -ENODEV; } + +int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, + unsigned int *val) +{ + int ret; + + ret = qcom_scm_call_atomic1(QCOM_SCM_SVC_IO, QCOM_SCM_IO_READ, addr); + if (ret >= 0) + *val = ret; + + return ret < 0 ? ret : 0; +} + +int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val) +{ + return qcom_scm_call_atomic2(QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE, + addr, val); +} diff --git a/drivers/firmware/qcom_scm-64.c b/drivers/firmware/qcom_scm-64.c index 6e6d561708e2..bf50fb59852e 100644 --- a/drivers/firmware/qcom_scm-64.c +++ b/drivers/firmware/qcom_scm-64.c @@ -439,3 +439,34 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, return ret; } + +int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, + unsigned int *val) +{ + struct qcom_scm_desc desc = {0}; + struct arm_smccc_res res; + int ret; + + desc.args[0] = addr; + desc.arginfo = QCOM_SCM_ARGS(1); + + ret = qcom_scm_call(dev, QCOM_SCM_SVC_IO, QCOM_SCM_IO_READ, + &desc, &res); + if (ret >= 0) + *val = res.a1; + + return ret < 0 ? ret : 0; +} + +int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val) +{ + struct qcom_scm_desc desc = {0}; + struct arm_smccc_res res; + + desc.args[0] = addr; + desc.args[1] = val; + desc.arginfo = QCOM_SCM_ARGS(2); + + return qcom_scm_call(dev, QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE, + &desc, &res); +} diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index bb16510d75ba..e18d63935648 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -333,6 +333,18 @@ int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) } EXPORT_SYMBOL(qcom_scm_iommu_secure_ptbl_init); +int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val) +{ + return __qcom_scm_io_readl(__scm->dev, addr, val); +} +EXPORT_SYMBOL(qcom_scm_io_readl); + +int qcom_scm_io_writel(phys_addr_t addr, unsigned int val) +{ + return __qcom_scm_io_writel(__scm->dev, addr, val); +} +EXPORT_SYMBOL(qcom_scm_io_writel); + /** * qcom_scm_is_available() - Checks if SCM is available */ diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom_scm.h index 9bea691f30fb..a60e4b9b1394 100644 --- a/drivers/firmware/qcom_scm.h +++ b/drivers/firmware/qcom_scm.h @@ -30,6 +30,12 @@ extern int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus); #define QCOM_SCM_CMD_CORE_HOTPLUGGED 0x10 extern void __qcom_scm_cpu_power_down(u32 flags); +#define QCOM_SCM_SVC_IO 0x5 +#define QCOM_SCM_IO_READ 0x1 +#define QCOM_SCM_IO_WRITE 0x2 +extern int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, unsigned int *val); +extern int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val); + #define QCOM_SCM_SVC_INFO 0x6 #define QCOM_IS_CALL_AVAIL_CMD 0x1 extern int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, diff --git a/include/linux/qcom_scm.h b/include/linux/qcom_scm.h index e5380471c2cd..e8357f570695 100644 --- a/include/linux/qcom_scm.h +++ b/include/linux/qcom_scm.h @@ -43,6 +43,8 @@ extern int qcom_scm_set_remote_state(u32 state, u32 id); extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare); extern int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size); extern int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare); +extern int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val); +extern int qcom_scm_io_writel(phys_addr_t addr, unsigned int val); #else static inline int qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus) @@ -73,5 +75,7 @@ qcom_scm_set_remote_state(u32 state,u32 id) { return -ENODEV; } static inline int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare) { return -ENODEV; } static inline int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size) { return -ENODEV; } static inline int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) { return -ENODEV; } +static inline int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val) { return -ENODEV; } +static inline int qcom_scm_io_writel(phys_addr_t addr, unsigned int val) { return -ENODEV; } #endif #endif