From patchwork Thu Sep 28 10:46:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 114407 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp579025qgf; Thu, 28 Sep 2017 03:46:22 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDodEfAZt34lcijr52XD+TW6HffnZdTzl1+eVbN8y2Cj5qXfI6E6nPltjXcaQch/eI42ssj X-Received: by 10.159.197.6 with SMTP id bj6mr3767460plb.178.1506595582722; Thu, 28 Sep 2017 03:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506595582; cv=none; d=google.com; s=arc-20160816; b=EVCAN4kppQD0YY5MwVMCYZYTsipXqTQbFJRu9dzksz3Lt0CO2FJN+yAJ19eOCXnPCs KfD/ZiMa+ehAqFT0YwksALFGZPOJCaTCYytekgvpmOMjYDyx/S+hKqayU1Y3Ep2DddgO g6AFLcS1bbIZMnNjZson1ug0zP0ovswdEP5RmC47anFZYxmiVf6GiRk7WNhfFLoKg4UF aeEgdRNpsIPADDLfP91P0o1gmW1Lxq/aXNqTG2/tl2wAVLjPAEYQyxMwD1+XiFrrXUO0 EfqTOMKHQwbo+MSs4liBbQCOPfL7WYZxn4VagE2+dJLnTKrDHKvwFQ2Rnx2Yw6lXaikq vSZA== 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:arc-authentication-results; bh=+1ACMSmtV7CiRqOYlpgXBcKRzgWAGa1xAWwLCfQoa1I=; b=hxIe4YGLi/MqMYVQ0PC4zw0qQB80r415ECpU1Te5vGIeD2+If+31vQZ5F8eVQhJFyE an/B5gpq+QqBalJfbQ8OzAtW/DY4XD2LyTgXrJoS92fWneYKKtAj7Evdk/1b8t5h4MWd xZdilsTgRU8TTfxsY5K/ztycf8jru5nfFJwDJtcQopMOTEiahBVPDWV0TMbd8zJf+Rme 8+Bj4UpyzRIGJUO9V0XQEUyOobCXolfeJy4u3P8yY1GZ188FcWBUfIHMP6DdXY0RV+OU GtoKkAGdIUe0sOwWkS220ntgOw2UfZHWHzJR5nsJaRgzhNN5qw8z7pB+3UhN/kTAoMle Gljg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si1183626pld.825.2017.09.28.03.46.22; Thu, 28 Sep 2017 03:46:22 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752860AbdI1KqU (ORCPT + 26 others); Thu, 28 Sep 2017 06:46:20 -0400 Received: from foss.arm.com ([217.140.101.70]:54982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbdI1KqR (ORCPT ); Thu, 28 Sep 2017 06:46:17 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0FFE4165C; Thu, 28 Sep 2017 03:46:17 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D25BE3F53D; Thu, 28 Sep 2017 03:46:15 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Jens Wiklander Subject: [RESEND][PATCH 3/4] drivers: tee: rework optee_driver_{init, exit} to use platform device Date: Thu, 28 Sep 2017 11:46:01 +0100 Message-Id: <1506595562-10592-4-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506595562-10592-1-git-send-email-sudeep.holla@arm.com> References: <1506595562-10592-1-git-send-email-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that of_platform_default_populate_init() takes care of populating all the devices under the /firmware/ node, this patch reworks/removes custom optee_driver_{init,exit} in favour of module_platform_driver. Cc: Jens Wiklander Signed-off-by: Sudeep Holla --- drivers/tee/optee/core.c | 74 ++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 49 deletions(-) -- 2.7.4 diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 7952357df9c8..98be0e688949 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -446,8 +446,9 @@ 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) { + struct device_node *np = pdev->dev.of_node; optee_invoke_fn *invoke_fn; struct tee_shm_pool *pool; struct optee *optee = NULL; @@ -458,21 +459,21 @@ static struct optee *optee_probe(struct device_node *np) invoke_fn = get_invoke_func(np); 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; } 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; } /* @@ -480,11 +481,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); if (IS_ERR(pool)) - return (void *)pool; + return PTR_ERR(pool); optee = kzalloc(sizeof(*optee), GFP_KERNEL); if (!optee) { @@ -524,9 +525,10 @@ static struct optee *optee_probe(struct device_node *np) optee->pool = pool; optee_enable_shm_cache(optee); + platform_set_drvdata(pdev, optee); pr_info("initialized driver\n"); - return optee; + return 0; err: if (optee) { /* @@ -542,11 +544,12 @@ 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 @@ -569,52 +572,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[] = { { .compatible = "linaro,optee-tz" }, {}, }; +MODULE_DEVICE_TABLE(of, optee_match); + +static struct platform_driver optee_platdrv = { + .driver = { + .name = "optee", + .of_match_table = of_match_ptr(optee_match), + }, + .probe = optee_probe, + .remove = optee_remove, +}; -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); - of_node_put(fw_np); - 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_platform_driver(optee_platdrv); MODULE_AUTHOR("Linaro"); MODULE_DESCRIPTION("OP-TEE driver");