From patchwork Thu Dec 27 19:01:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 154574 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7252063ljp; Thu, 27 Dec 2018 11:01:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN7dC3PUL/Rmpv6GTyFoQAzcJVN7fPS8J13+NEoLJC3E2rvKC8kdZXvfiNSEKVZ8o7rTTjAB X-Received: by 2002:a63:fc05:: with SMTP id j5mr24039474pgi.434.1545937302166; Thu, 27 Dec 2018 11:01:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545937302; cv=none; d=google.com; s=arc-20160816; b=B4ZrI62NPAtnjVgOreOnhfQ9A3x99VVTrpu9oVtoBJPy1poUegFlvZYY45tPM9G+MJ 1QLXU0rBRWj2IeQJTPSq6uZWzO4WeXPzz0dP4kN0/vXJOrCdkjLB5r+NvD2tpblfUfRh FIYBuRRll+C7LXzDHRIxii3T1w3f7ZGweZwxARVp28mz+TUxsR26wuGXh4bEOy6jGjyn Qc6hwChID5zdIjaW43b9ZhtdVKXMKRIqm5vYFw6u2fJ2fajQZtzXa8JPw0a1UDoUzB/q ZFk3IsT2+qCE3VLHqhoSXvYC3LBSXdqiflaimVO7aZfm/nJGJcw44AtnfnLeWwvLYPzX J5Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Qblhmiprb14dt3JwrUg0Jgn1GqhbwfvP3JBFxTbrN30=; b=UY5kWYb+T3daCx3uRgEfT3cNEFHrGG7cMNvQbJ09sCehHNXBzTVUIeC9jm5rZ+xAGn +W3z6sTaA+/uc4i4gYYIkcEHdN5a0cQ09ZvPJrXGXZfj/vLS146XSO6Zv6fTiclPXIzR cli8Y8HxTTy/d78GDxpvsT+yDfRe6iHBOpXWDgTykHassNeX2SCIuZIPNSI3mF/49xQ+ MSktAo28FbiY8O51IhehM8RXC68isBnuGtZLV60xAcYh/qVmoEIHWxeh/3Rjs+EPP2oA NjZeWN8cV83/env1EBu0jV2Ufrlfeav7oxjqjMuWHEoh03UbFvQWqKXuQkarHUAx0ZB+ 4GYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FSVf3Kec; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 33si2957412plu.169.2018.12.27.11.01.41; Thu, 27 Dec 2018 11:01:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FSVf3Kec; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbeL0TBj (ORCPT + 31 others); Thu, 27 Dec 2018 14:01:39 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:34700 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727551AbeL0TBg (ORCPT ); Thu, 27 Dec 2018 14:01:36 -0500 Received: by mail-ed1-f65.google.com with SMTP id b3so15987786ede.1 for ; Thu, 27 Dec 2018 11:01:34 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=Qblhmiprb14dt3JwrUg0Jgn1GqhbwfvP3JBFxTbrN30=; b=FSVf3KecdyaE6VC5jPfzJHP8hK2j8+f28HO9/M/OZ/lFo4AlAZtKhSlzC84UpuB2bY tbfFkEG4kNxTF9uK0Z9hsasxYMPuUlpo1Zu2qlnBbuZ5P/pwF7aitgzPOrR4csBJUlSH MQjikQ4nXzKFnWKuMdSDExCENDQN1p2bNXPeQ= 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:mime-version:content-transfer-encoding; bh=Qblhmiprb14dt3JwrUg0Jgn1GqhbwfvP3JBFxTbrN30=; b=k5j5tsMd9YggdVvjzyEqN1ES9VzWBNgQAe/rkkXxq3RAl8qn0ObCwaS546Q87KC91+ Rza6bpce/FkUKqp6CKr9F4pkKz3zkqJCMPWs59mSEAz5OvGrAJPbcWdxjKoe/NFKtvmx spQ+tBf5gq9E+mqC3+KYqwvJz0vSK4tfjpKG8r6+xW0n8Vcc/YXkqJQAM4IrrsBVCYzu VLS4Wh62fSfwen4+5UmMBLcAqwMJ1uu6DScPbKVg0TxeqfLpEspL5TUdhtYdw+lUOGVx odpSJq19J70PouuWctLxTf3zirwirxqIxY382EVtMl5j2VG3JA8VMZ1y4rXCwbfHdv03 bInQ== X-Gm-Message-State: AA+aEWZ9/MJMmvu0jfjHTQrFdnU+bsIsrNm5wigH8W04o0ewvIht6+fd Omy9QRfIIjnWMYaKAu+P2sZzkQ== X-Received: by 2002:a50:b3c9:: with SMTP id t9mr19987995edd.270.1545937294016; Thu, 27 Dec 2018 11:01:34 -0800 (PST) Received: from chuckie.home ([2a01:cb1d:112:6f00:6488:e12:eb9c:4813]) by smtp.gmail.com with ESMTPSA id v14sm11224376edq.74.2018.12.27.11.01.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 11:01:33 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Jens Wiklander , Sumit Garg , Graeme Gregory , Jerome Forissier Subject: [RFC PATCH 1/2] optee: model OP-TEE as a platform device/driver Date: Thu, 27 Dec 2018 20:01:21 +0100 Message-Id: <20181227190122.23149-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181227190122.23149-1-ard.biesheuvel@linaro.org> References: <20181227190122.23149-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To simplify adding ACPI support to the OP-TEE driver, model it as a platform driver. This will permit us to use the generic device property layer for parsing additional properties, regardless of whether DT or ACPI is being used. Note that this change will result in the OP-TEE driver to be loaded automatically on systems that advertise the presence of OP-TEE via the device tree. Signed-off-by: Ard Biesheuvel --- drivers/tee/optee/core.c | 86 ++++++++------------ 1 file changed, 32 insertions(+), 54 deletions(-) -- 2.19.2 diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index e1aafe842d66..61ea65cfaedd 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -529,13 +529,13 @@ static void optee_smccc_hvc(unsigned long a0, unsigned long a1, arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res); } -static optee_invoke_fn *get_invoke_func(struct device_node *np) +static optee_invoke_fn *get_invoke_func(struct device *dev) { const char *method; - pr_info("probing for conduit method from DT.\n"); + pr_info("probing for conduit method.\n"); - if (of_property_read_string(np, "method", &method)) { + if (device_property_read_string(dev, "method", &method)) { pr_warn("missing \"method\" property\n"); return ERR_PTR(-ENXIO); } @@ -549,7 +549,7 @@ static optee_invoke_fn *get_invoke_func(struct device_node *np) return ERR_PTR(-EINVAL); } -static struct optee *optee_probe(struct device_node *np) +static int optee_probe(struct platform_device *pdev) { optee_invoke_fn *invoke_fn; struct tee_shm_pool *pool; @@ -559,25 +559,25 @@ static struct optee *optee_probe(struct device_node *np) u32 sec_caps; int rc; - invoke_fn = get_invoke_func(np); + invoke_fn = get_invoke_func(&pdev->dev); if (IS_ERR(invoke_fn)) - return (void *)invoke_fn; + return PTR_ERR(invoke_fn); if (!optee_msg_api_uid_is_optee_api(invoke_fn)) { pr_warn("api uid mismatch\n"); - return ERR_PTR(-EINVAL); + return -EINVAL; } optee_msg_get_os_revision(invoke_fn); if (!optee_msg_api_revision_is_compatible(invoke_fn)) { pr_warn("api revision mismatch\n"); - return ERR_PTR(-EINVAL); + return -EINVAL; } if (!optee_msg_exchange_capabilities(invoke_fn, &sec_caps)) { pr_warn("capabilities mismatch\n"); - return ERR_PTR(-EINVAL); + return -EINVAL; } /* @@ -585,11 +585,11 @@ static struct optee *optee_probe(struct device_node *np) * doesn't have any reserved memory we can use we can't continue. */ if (!(sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM)) - return ERR_PTR(-EINVAL); + return -EINVAL; pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm, sec_caps); if (IS_ERR(pool)) - return (void *)pool; + return PTR_ERR(pool); optee = kzalloc(sizeof(*optee), GFP_KERNEL); if (!optee) { @@ -600,6 +600,8 @@ static struct optee *optee_probe(struct device_node *np) optee->invoke_fn = invoke_fn; optee->sec_caps = sec_caps; + platform_set_drvdata(pdev, optee); + teedev = tee_device_alloc(&optee_desc, NULL, pool, optee); if (IS_ERR(teedev)) { rc = PTR_ERR(teedev); @@ -632,7 +634,7 @@ static struct optee *optee_probe(struct device_node *np) optee_enable_shm_cache(optee); pr_info("initialized driver\n"); - return optee; + return 0; err: if (optee) { /* @@ -648,11 +650,13 @@ static struct optee *optee_probe(struct device_node *np) tee_shm_pool_free(pool); if (memremaped_shm) memunmap(memremaped_shm); - return ERR_PTR(rc); + return rc; } -static void optee_remove(struct optee *optee) +static int optee_remove(struct platform_device *pdev) { + struct optee *optee = platform_get_drvdata(pdev); + /* * Ask OP-TEE to free all cached shared memory objects to decrease * reference counters and also avoid wild pointers in secure world @@ -675,51 +679,25 @@ static void optee_remove(struct optee *optee) mutex_destroy(&optee->call_queue.mutex); kfree(optee); + + return 0; } -static const struct of_device_id optee_match[] = { +static const struct of_device_id optee_dt_match[] = { { .compatible = "linaro,optee-tz" }, {}, }; - -static struct optee *optee_svc; - -static int __init optee_driver_init(void) -{ - struct device_node *fw_np; - struct device_node *np; - struct optee *optee; - - /* Node is supposed to be below /firmware */ - fw_np = of_find_node_by_name(NULL, "firmware"); - if (!fw_np) - return -ENODEV; - - np = of_find_matching_node(fw_np, optee_match); - if (!np) - return -ENODEV; - - optee = optee_probe(np); - of_node_put(np); - - if (IS_ERR(optee)) - return PTR_ERR(optee); - - optee_svc = optee; - - return 0; -} -module_init(optee_driver_init); - -static void __exit optee_driver_exit(void) -{ - struct optee *optee = optee_svc; - - optee_svc = NULL; - if (optee) - optee_remove(optee); -} -module_exit(optee_driver_exit); +MODULE_DEVICE_TABLE(of, optee_dt_match); + +static struct platform_driver optee_driver = { + .probe = optee_probe, + .remove = optee_remove, + .driver = { + .name = "optee", + .of_match_table = optee_dt_match, + }, +}; +module_platform_driver(optee_driver); MODULE_AUTHOR("Linaro"); MODULE_DESCRIPTION("OP-TEE driver"); From patchwork Thu Dec 27 19:01:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 154575 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7252140ljp; Thu, 27 Dec 2018 11:01:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN5mF0/N2/RH++U2xq65SKt5J6edG+NerRXmvopWRQhOmN0HYOB+1Ed2uKd45vDe3JExtb9F X-Received: by 2002:a63:6ecf:: with SMTP id j198mr24072796pgc.3.1545937305915; Thu, 27 Dec 2018 11:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545937305; cv=none; d=google.com; s=arc-20160816; b=vC8cTeRHEmj1keQGhnF1SVJ1aG/u0GpY69h9ZB14rZIvBpEaPSMiBISWQkL0nFTSy9 /2oBeLNgnV7lE+5lwPCfL3vgho/4FtZdtOm3AYiOmZ8+mwLRFl1+Fs0ev7oaPnIl5/ja sf9XtaALfwuYxcJ8/yypLbKoRGfcbFGqRkKFebakVrSNzkOfM+KgOFP49tOe4xlysuah U1/0sD2V0tWU8nLqmBvP4tCLq7YZ/UuAQpMp+VigI5+blGY1f2Afg85PZBktTRVvI18h RqqSPVRtOXSFr1tZItSrZ4B/Oh/+QOkQtlwmM7jgVAGapqi8UkLBUFB5QJir8Zlolkzl wsjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lELMYxGBq1wtuJWcpqHPQ/HdXwW1NxaQ8FdwNt6SqtQ=; b=VomWqTH0yUVNNPu6JKBje6TT3sLG1yuuozhJmbkjW5NRibPiDZl5iHR27aNuIUna9E tREg3Of3toWYEFcIcZQ8z5Bai64ICWkVevSU5lWLcq2khG3dO3/hSPblSlWdn9sS1Csu +lu8iiSUAXf8fsi714/tnwBLfI8fd+t5gwOCo/BzoWuSIdH+XFtzGLTG21BS+z05jXmK lVEpzkwFCgueH8ta/ODc2WAub11/GxnPmYkUzUzMeZLiMZVXz7LNvEwMJn+q8KNc54yT bIHbStOWrFhdFC9j2+m/PuX1uXm9hQhS+wjKzHivMoPGn8hpUjWxl9ASwvkrlOdlfb8Z slPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=THTBRY5V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 33si2957412plu.169.2018.12.27.11.01.45; Thu, 27 Dec 2018 11:01:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=THTBRY5V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728655AbeL0TBo (ORCPT + 31 others); Thu, 27 Dec 2018 14:01:44 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:40099 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbeL0TBh (ORCPT ); Thu, 27 Dec 2018 14:01:37 -0500 Received: by mail-ed1-f67.google.com with SMTP id g22so15931568edr.7 for ; Thu, 27 Dec 2018 11:01:36 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=lELMYxGBq1wtuJWcpqHPQ/HdXwW1NxaQ8FdwNt6SqtQ=; b=THTBRY5VIJFxdEBovHezMJXVb1V2sUUyVCFlLcR5L58BGTNcGGqowUhxJ45svP58Jq ASgENUBMus/b96vj56w8k03CG/6cjJ6LqX0C7z25S3lhUkgYWRHvdu9f1QOfA/0yg421 0qK1dcESMdiaopjlZF9fJJmZ/1SZsghcNhGQA= 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:mime-version:content-transfer-encoding; bh=lELMYxGBq1wtuJWcpqHPQ/HdXwW1NxaQ8FdwNt6SqtQ=; b=ALFNkYSqKWgE0sVIi4ho1f/l/JF+y+Q9jc35Q9Zw7oHbcPy+B19cYzNIoob4wFiys3 g3nM2qB02Aiz0nqNKSYOwj2FuylmOIbuS4tbVx4OycGUJWvZ8Onq2cM4q8smVhPyOXjz mQp0WNP41Dm+tPMRaHvVVwfUnL4GeU8SlB6aNGJ+sAipK9iMgwaVwb/jCfcmcnrXGOLX WGWSrBSb5jYNTZsQJY3KI//iwR3/sMp4QRrYWMabpITsA5+aqLEyxYHySH96NB0Q3RWn Q15mnHWzmdPC0oWf/+aNYLkVA+ClXTk5g02A3czhObJgtb2aJ9QOXFmXG7LQ5mdbMpcb M7GQ== X-Gm-Message-State: AA+aEWbyOVhZ8SmSiFasLktBKqqnPMo2jnSy0HG0MWlzwIyy0jbONlcX QlWNavLQZ2SHeEoWuXFMBRy6yQ== X-Received: by 2002:a17:906:1604:: with SMTP id m4-v6mr16471470ejd.167.1545937295497; Thu, 27 Dec 2018 11:01:35 -0800 (PST) Received: from chuckie.home ([2a01:cb1d:112:6f00:6488:e12:eb9c:4813]) by smtp.gmail.com with ESMTPSA id v14sm11224376edq.74.2018.12.27.11.01.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 11:01:34 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Jens Wiklander , Sumit Garg , Graeme Gregory , Jerome Forissier Subject: [RFC PATCH 2/2] optee: add ACPI support Date: Thu, 27 Dec 2018 20:01:22 +0100 Message-Id: <20181227190122.23149-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181227190122.23149-1-ard.biesheuvel@linaro.org> References: <20181227190122.23149-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for devices that expose the presence of OPTEE via device object in the ACPI namespace. Signed-off-by: Ard Biesheuvel --- drivers/tee/optee/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.19.2 diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 61ea65cfaedd..94b2fd08b446 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -14,6 +14,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -689,12 +690,21 @@ static const struct of_device_id optee_dt_match[] = { }; MODULE_DEVICE_TABLE(of, optee_dt_match); +#ifdef CONFIG_ACPI +static const struct acpi_device_id optee_acpi_match[] = { + { "LNRO0020" }, + { } +}; +MODULE_DEVICE_TABLE(acpi, optee_acpi_match); +#endif + static struct platform_driver optee_driver = { .probe = optee_probe, .remove = optee_remove, .driver = { .name = "optee", .of_match_table = optee_dt_match, + .acpi_match_table = ACPI_PTR(optee_acpi_match), }, }; module_platform_driver(optee_driver);