From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.2.80; helo=eur02-ve1-obe.outbound.protection.outlook.com; envelope-from=achin.gupta@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20080.outbound.protection.outlook.com [40.107.2.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D64EB21962301 for ; Tue, 28 Aug 2018 06:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fzaUdWzdT0Lmnh4Qy4oEAqlRdaXL2IjdopcjYZozHRA=; b=FSBkd7CUB0lh+DbY5XEWF0UVih5kvWdQyrCe6e0BiezkhxMU8dqL+Jby1TxPlhyKx8BGH7nS3hLsTHFLdxNdfF/fxyB0wbZsgR2b7N/SGkZgFfeiFVItJZtPdWLuXMNl1LLsDEDO/Yp6/qjQcRFL2afpa8syMPcHGxTQl0dKrmc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Achin.Gupta@arm.com; Received: from e104320-lin (217.140.106.50) by AM0PR08MB2980.eurprd08.prod.outlook.com (2603:10a6:208:5b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.15; Tue, 28 Aug 2018 13:08:22 +0000 Date: Tue, 28 Aug 2018 14:08:23 +0100 From: Achin Gupta To: Sumit Garg Cc: Matteo.Carlini@arm.com, udit.kumar@nxp.com, Ard Biesheuvel , edk2-devel@lists.01.org, tee-dev@lists.linaro.org, Daniel Thompson , Jens Wiklander , rod.dorris@nxp.com, nd@arm.com Message-ID: <20180828130822.GL28113@e104320-lin> References: <1535102474-24383-1-git-send-email-sumit.garg@linaro.org> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [217.140.106.50] X-ClientProxiedBy: CWLP265CA0148.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:52::16) To AM0PR08MB2980.eurprd08.prod.outlook.com (2603:10a6:208:5b::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6a9e03b-96a9-4c27-fb12-08d60ce7553e X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB2980; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 3:LKMm7yU/tN2/XwltksDF3PWjbG3/i3c51CeZix1Z1X+VsSQ2pXem38mU0RKkjOYwr8oZGx4OYxNthgLI9KztZHmuFEIODJatjIJENhPPgRdy9e875k4iIAb4feK//qk4KLF0G977fnri0uZ+wrNeyiP8+4yvo02WMkHWsj1fXQK+d+9IxI/fIWBNDCaQNkFO8OaogN1G245dqZGVM+Ap/JcsV5PK5TJSPuotgAImfYlq8uoxLjPcm9vla0s+8dUl; 25:CYiPbwZdMAkTpCudp8YrrxnFurrosDqbnImSVGhc90l5f0JBjcZRKICspPqHqOx+SHh03rta/pX/VNC4rqLSn4KXIaqQSc6PQgGTjGmvGfvUHiSbCGmjaUa80WmMW73stK68UBpUBpUEAijXQyF7PlM4Fk1kieukEtBBIhgGEss6DDuAQ/7QgGGEOhcFFfxq6IZzOjIhpRUQFIbfo/Iy/dPZ2CItQ3L9obGbnJF1NmmGWAcQnFptNRZtwuBJsZXaBy/XIMfWm7/HeEP85OFjNdO00F/b11v3MpphRutHqGuK07/PJdSeD3tsqqPMTmatWESqkbehRk3sgYKRIN/Zyw==; 31:ZlWhAjFmNE51ODaB4v3ZptJTPLHK+OX5BirWrzlkx+b3CDI52A5lEvA5+7mSXvVRPoGeOEYyKHI8SP7t5UZVJcwWUxhJ/UVF9BrmLextVjA6OvxRIIoYGOLostrnAYbLHeM5gtsB8/bREaKS4fbRxUFCj57WBAPsWnMNTaV9V8Rt2fjTiWEnyS/eY+y2+Dq5mOkoDXui4z5p350S2f8RVDuE0xKkdm770ARGpE0brCs= X-MS-TrafficTypeDiagnostic: AM0PR08MB2980: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 20:OrAyDc0xDzqol+xB/bfEJDEnN4pnKo9xeVMt+CU15KE3xexe9dAd1krpPhVvbYjk1WDxrE+nxaTHMncg9u9gANAcmnjkvITknmJSNm1l9l7VnaamHPFQEeVq/gbQHlObf0BkidBNyJSYGDyUqSMOV1Vrh3gZwfrHG8DoqBNUt79M0BgsChd1sLqLPqoIKrqrMaUXAHOsrShOCi8h96QHuJIfj4iiuedrIQeCx22PRrEg/EAfQ0ej/ShI0fIe6HoXb4Y4l3DFpHKPVPiDOHks7wG0OE2V8q0AXuG3Yu1V+Ytzb06ZP/NOd6N7mjXGv/18p3PiPzGuOn1n0tW+/i5wgzO/WyA1mu3yP14MYYxqv5IbSrety18KhBzKaaB9RJgnjOBAxvuu7El4G5XI5kUxRsqdwK7mK2iF9pzbkddLHbc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(11711142671493)(189930954265078)(185117386973197)(162533806227266)(1553240931313)(45079756050767); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(3231311)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(201708071742011)(7699016); SRVR:AM0PR08MB2980; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB2980; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 4:R0T1dUmuSuc5ra31yQPNrPnQ3ZDJ3pJu7V9RzCzK6CcAnEoIWTtjIMel+0pp4jaVTKtXsezE5yJparUu6X7U78LJ19O9KmnpvAQqLTkhze2BOBtOKZYvyU3VWZc9eolEEVdMR9y3GqG6U8+VNlENkEPbkb0yQFh2L5/TZBmzzupan2Ipi11+kYXka0mrCD8LczBW+UFJhFEd3sSv3VVvPZEWQ6mFRRAh38t9A+qazrukDBBIcQb6osjkFAqxGVh/w8+I6JEBOX/aZf1veTcVr+zHsKwU8mI6EQheI4uhDA0AfAoNPAnCA8kioovuxliziqY459lV4B50yDrhXK6luqpU0woq64MbEGDRTNunk13HdHNVamCzJDakOrkm7lr/VzXlukeBDLUB6RDahovUyh2HJlQLhb3MhMEnrCvhmC5fMvPKKfcU3RmujfH611bDwI7nNceUYg3HQekfD0hbmjEZwD0I1R+Txr0BIVyaT8Uq55yg3ud7TbyZEflWxjNU1le1C+Qj4KcUmgIwU0cfYg== X-Forefront-PRVS: 077884B8B5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(396003)(346002)(39860400002)(376002)(366004)(199004)(189003)(13464003)(40434004)(14444005)(5024004)(386003)(54906003)(68736007)(8936002)(478600001)(81166006)(58126008)(2486003)(50466002)(52146003)(2906002)(186003)(81156014)(45080400002)(53936002)(966005)(6116002)(6306002)(1076002)(55016002)(575784001)(86362001)(72206003)(16799955002)(4326008)(53946003)(11346002)(446003)(956004)(6246003)(25786009)(23676004)(9686003)(7736002)(316002)(53546011)(8676002)(3846002)(52116002)(6496006)(26005)(2870700001)(33716001)(105586002)(476003)(5660300001)(47776003)(76176011)(6916009)(44832011)(486006)(93886005)(33656002)(106356001)(16526019)(97736004)(305945005)(229853002)(66066001)(33896004)(18370500001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB2980; H:e104320-lin; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTBQUjA4TUIyOTgwOzIzOnZpSXh0SFR6WlZUcFBkZDJpWUZVZEN6Mnh4?= =?utf-8?B?cDBPUzVydjN5OW5FMkdNTldUdXVTNjhWNFEwY2FJRHltdDc2MTFzd1VtYkc1?= =?utf-8?B?NElNeEJtRnNKRXdSUmNhdFQwdzluRy94UjZiSWRUTmxBMEFTVE5aMkw1YXRO?= =?utf-8?B?THlNTG5QZHFlbGg3R2FJOHNvQ3NWblcxU3JBQnRuRm1HbHJLM1ZiTDBFQzNC?= =?utf-8?B?ZCtkTWFPSDVTRm5CZlJSSkdIZTNXNGZJMHREa1pDUGwvbDgxS2Jad2tlQkRv?= =?utf-8?B?TDFaZTVTeStXS05RbU1RZ1UrQVhxa0YvU1B6M1k5ZDUrMDhBeFhCT1FnRzFT?= =?utf-8?B?ZkZKdEgxV0FKdHBXbW1xTmlvR3hReVRCUE5wTk5pWkZzMkFnak9QWU4xWCs5?= =?utf-8?B?SzB5V0lMWXVFT1FKN0UwQnIzZGY4SXp6eHUzMnNIRGtSSi9RT240c2ZWbEYv?= =?utf-8?B?Z1FDdHFxWjNDT291UWN6aklPZlhKSjlnUExpc01UVUxSNzZkSUkzbVFySkNK?= =?utf-8?B?cXZrcGxhaWtaMW9td2IzUzVackliWEhOeE5TMEdSdURia0JsVWtoTGxCYVhL?= =?utf-8?B?YzU1bnlxdGdHd2F3T1lKYWNzdFBmYW9KTTl5YzMxK21hSFc5ZzlJait4L3pQ?= =?utf-8?B?b3NIZnRxaG8wa3FUL2RXdGcwdnZQbWhybE94NnJDS3UxNlJKNUVKRXJ5MWxG?= =?utf-8?B?UUh4bWVvaVVKakRZaUMzOUVxc3R0OHNlRDJCcUhBVzB1bHpQQ08wTmd1MXFn?= =?utf-8?B?cUtZUDc1U2RSWlk1b3AyN2Jqc0RaUU9LNFVGZ2paYUdRc01TU01YU09PZEhs?= =?utf-8?B?cXNUTnh4R3pmK0wvcjVHQkNYQTZQRmNDVHdlUlhLR1hMM3hhazNyWXVpZTRt?= =?utf-8?B?WlpUQVlhQzhvY05OUW1XT3VOUzFjaW1QM2lneEVHS2I1ci95RnozeUVYdlls?= =?utf-8?B?elRBU1FKdjFtbUJHaTh5ZEM1NmNqUlYrTjh5TVBoQzNQUUVFR3RzSHpNMEMr?= =?utf-8?B?V2xxUGdqMHplM2xlaHZBY2EvWEdjRkV1VGdNWkNMUGhRTW9YaElFbzdSSUh2?= =?utf-8?B?Q0FhalVoTzNBWm1iVjZqMlVqZzFHMW83Qnh2cmMwa2s2NEJXRTdYVGQzZ2JT?= =?utf-8?B?NWpLQzZGMW5RU0d5dXkyTWVjVjQ1SzBuVG5tb0J5YWRLakpIcEZFMjN2aVZ0?= =?utf-8?B?d3NCWUJsKzVOMndHcC9UMDg5VnpWbFF6SDZFV0VUM254NkdPYUF0ZklHUnNZ?= =?utf-8?B?NWczMk5KUFBCVXY1dngwNjlrQjArSzNwL2p6bFlTdVJSemI3WFUrRGt3VExq?= =?utf-8?B?bW9QOWhnQ2R0cVlDTEtta29JYjVScnN1bno2Y1RSUFRGa2EydWRLQ2p5cDcy?= =?utf-8?B?STlmUjh2R3NLaG56Z2RqZ1VsQTZxTitmeS9nYjdUTENIWFlHSFpKRitBMTJq?= =?utf-8?B?dEpQWjJxWEpza1FwN21kckwraW41cDhHbE1MNkJwcS9ncHgyVnNqVUxnREUw?= =?utf-8?B?dXByV0dXUXJTeUtPaTBwRW5FOXR4OVFBaTRQOElvK1J2UDJQcG0vOVREc3FQ?= =?utf-8?B?ZGk4eExVV0lMN1cvRHdXdGdOVmVuUXNqdS9sRmFma2F1OGtWaEdUa2lydFBR?= =?utf-8?B?M0tJV1FWakd1VWp3L0ZxSUorN0h4ZzRjQTNOd0ZUNmZxbUY3RGxiQ2ROUXJa?= =?utf-8?B?SlZIUDFVeUVES0pqU1ovZFgzNklwRFhTeWEvcUF3ckRHT0R6TDZYNkMzZDZC?= =?utf-8?B?R2ZGVzE5NEFHbDlUUDlsZVk0akN5Q2wyaDEwUlloc3pWazZrNy9oaFJBY2lS?= =?utf-8?B?Ly9mOVd4R2M3TXhKdXhibDErWjA4cFNkbnpKTndtdk5PVjBTdkZiZkZ4SHlh?= =?utf-8?B?UVlRaWtiNWhQK1diNktISzZRTWhhdldORHljVkJUZ2Qva3Fac3NtQnc1QjVh?= =?utf-8?B?QXlpSDhZUnpFRFhEZnljOWR4STl0ajRkbi9JZUlvcThPN0xYNVBHTU5rNHFW?= =?utf-8?B?S2JWSndpOHduMEpKc0tONHlaNS9weEpkd1A1OEpLODBqMVNBemJaMnpabHdH?= =?utf-8?B?ZndMUXNSdmZDUFNmWWJsOWtIdmJ0QzR2UzB2R0pjOWh2MmtmSDBVbFpocWIv?= =?utf-8?B?QlBQOERiY2tUTWtremszc1F6eGkwUzNoMHZvNnY3M0RMUlA5N3c1dTBjUTQw?= =?utf-8?Q?m/KGSvDbcZm4hgAAF2P+Aq06IH4h8Hn4TSvft7XVIk=3D?= X-Microsoft-Antispam-Message-Info: hdqG6cKn+QAuD3M40SCaAjQAkBZ9NJMnHbbYc0XXGVbsEllgRKHt+7qPgi8H6LaklZwaATx0Z1N7uLPSM/VJXpNmW1OdS9GNsaJGF2Xr5pdEXLNfIjutZmfqjsoj64/tBdJQsHFu0YVUoPlsAHM3B4Z5zG1FX4TpZMRZzlXI+kCKlRgtsuxEQHlAnXhp+flNeYI8WqzzDywPPCy1gXde19jCBawa9KknvkFmJy9+stNSJn+3aWs8WBfR9B6R0LtUlD6+ZRG4TaKweo2FOTZpvLBuz1VpxpS/iBDkDb8+ZMSbu5sGcqduLXargLxQHsM3w6Zxxy2kzXVx3w7QjEPmxETKbwWUk6iSzVLnjBQP9aM= X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 6:H2+Yw8P/spNehogldmrXz4T6uE2CZ7K7GR3fErb2WG/z/Pf2OMjpbHl7vROL4EpttsD5h6jTpO5RuplA9I1MI0bnfiSXHBQQy3HmR8O1YCM8BXstpK00iuGOKw43e0bYxQGvpg+QYJX7yJ05X7UvX2T/kMzBGemX0xj7zwi0PAccwU+1P012PpN/uta0J5kLbxymiAALORXnSslN8bEn5t/2UADbfU0I5GHQdpEmd7qFKs8cRVwJhxmGRKbBlplk3c55h9iyPph7CnrfpT/S2W97Ge/jueEinrBQzaPASrY/LByQ1g6rXzUbQck+CwFRkcQUA3lhIyWUKQGFjKVlgLeUMsZgHriebPfd5b+9hyd8VWXhvGaACKavB/OWtmPPhFdh8hP/ZMBIjnXikQLq9dwWcDwKitBIPdEdWonCGF+9IeeS242/myozoRS5A2ObisuRB/+hgHGVfk1jJjEEtg==; 5:DpQDeYD3F0k9aRAq43iECRVADuc91sa5U59qGtKoRwl1i8/JfMDc/AqpOawwDtDNG+gVs1o7UyK1q1MMyNN8AjXs4UklIwsaXSCNErSwvgHIFLt1cAKEvYH7c1h8NKihMDn3cDptmOXDjB44sKDvQUCS+z5nRw9EUTJ9XaHQMXs=; 7:XRFjYK4Jk0dsuDNQZVv2h4F6S326H6qNnG4FaxYxlnsyPa/cvcsUeam387UvhUYxKSlBa+W3YoNtM0TFYnMwKUE/qma40OgoCNBUH9KNj90heDmfpUM/KuMjXf7AoHWwfw6lEgevXvFb7TqY+wqCamyivptzD38delNq+qixZWI/3Ts3/JXLWVB09GeFBl2qxw9s6lhFTDTfqnZ6DKfPzcNlI1KbW3BCIklmSLfg9bFRC1RQHyz+mesufCin55po SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2018 13:08:22.3079 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6a9e03b-96a9-4c27-fb12-08d60ce7553e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB2980 Subject: Re: [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to communicate with OP-TEE X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Aug 2018 13:08:27 -0000 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi Sumit, Apologies for not replying sooner. Some questions and thoughts inline. On Mon, Aug 27, 2018 at 03:28:52PM +0530, Sumit Garg wrote: > On Fri, 24 Aug 2018 at 23:33, Matteo Carlini wrote: > > > > +Achin > > > > SPD (for OP-TEE and other Trusted-OSes payloads running at S-EL1) and SPM (for Secure Partitions at S-EL0) are currently mutually exclusive into Trusted Firmware-A codebase. > > > > In other words, you cannot turn them on in parallel and execute both a S-EL1 Trusted OS AND (one or many) S-EL0 Secure Partitions in the Secure World with the current Software Architecture. > > > > IIUC, currently BL32 image is common in Trusted Firmware-A code-base. > If we turn on SPD then BL32= else if we turn on SPM > then BL32=, correct? Yes! BL32 is a TOS image if SPD is enabled. It is a S-EL0 Standalone MM Secure partition image if SPM is enabled. > > But I think SMC calling conventions (SMC Calling Convention [1] and > Management Mode Interface Specification [2]) doesn't put any such > restrictions as SMC function IDs are totally separate. Yes, this was an implementation choice to ensure that either a S-EL1 payload (Trusted OS) or a S-EL0 payload (MM SP) could be included in an Arm TF build but not both. > > > Achin and other Arm architects are trying to figure out a way for solving this problem without the need for a v8.4 Secure-EL2 Hypervisor, obviously without leveraging the isolation benefits of it (see also [1]). > > > > Agree we won't be having isolation benefits which provides added level > of Security. > > > But Ard is right: there could be use-cases to ship UEFI systems with OP-TEE and TAs on top...and this should still be currently possible using the SPD dispatcher into TF-A. I've not looked deeply into this patch, but it doesn’t seem to contradict the above Sw architecture. > > > > The question would be: would you foresee the need for running one (or many) other (UEFI/EDK2-based) Secure Services in the Secure World into a Secure Partition (using the StandaloneMmPkg) *together* with OP-TEE? > > > > As per following quote from Management Mode Interface Specification [2]: > > "Management Mode (MM) provides an environment for implementing OS > agnostic services (MM services) like RAS error handling, secure > variable storage, and firmware updates in system firmware. The > services can be invoked synchronously and asynchronously." > > It seems that MM mode is designed for more robust and platform > specific services whereas OP-TEE (or any trusted OS) use-cases seem to > be more complex like Entropy pool (RNG as in our case), DRM (could be > valid use-case for Android TV or Chromebook), keymaster or keystore > (for Edge devices) etc. It really depends upon the secure sw stack, use case and the requirements. MM interface specification specifies a blocking SMC (MM_COMMUNICATE) to access a secure service implemented in S-EL0. In the UEFI/PI/EDK2 context, MM drivers are used to satisfy a variety of use cases during boot through the EFI_MM_COMMUNICATION_PROTOCOL (the bad press of SMM aside!). MM_COMMUNICATE SMC provides a channel into the secure world to the backend of this protocol on Arm systems. So any service accessible through this protocol could be implemented on Arm systems in a MM SP. IIUC, in your case there is OP-TEE and firmware in the secure world. OP-TEE has a static TA that provides the random data service and you want to leverage it at boot time? Ditto for other services? So you do not really need an MM partition running alongside OP-TEE? In any case, what we are working on is to define a set of standard SMC interfaces that can be used to talk to a secure service in a payload in S-EL1 or S-EL0. This standard ABI will avoid the need to use payload specific SMCs in the normal world e.g. OP-TEE specific SMCs. Side topic! Do you foresee a usecase for DRM through UEFI during boot? Would it work in the absence of RPC support in the Optee Library? IIUC, at runtime, DRM traffic will be routed through the OP-TEE driver in the OS instead of UEFI since there is no UEFI runtime service interface to do DRM? > > So it looks like they complement each other and we will have more > robustness once we migrate to v8.4 Secure-EL2 Hypervisor for isolation > support. In a way yes! The robustness bit is not really related to the interface used to access as service. > > Please feel free to correct me if I missed something. Hope this makes sense. cheers, Achin > > Regards, > Sumit > > [1] http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ARM_DEN0028B_SMC_Calling_Convention.pdf > [2] http://infocenter.arm.com/help/topic/com.arm.doc.den0060a/DEN0060A_ARM_MM_Interface_Specification.pdf > > > Thanks > > Matteo > > > > [1]: https://community.arm.com/processors/b/blog/posts/architecting-more-secure-world-with-isolation-and-virtualization > > > > > -----Original Message----- > > > From: Udit Kumar > > > Sent: 24 August 2018 18:46 > > > To: Ard Biesheuvel ; Matteo Carlini > > > > > > Cc: Sumit Garg ; edk2-devel@lists.01.org; tee- > > > dev@lists.linaro.org; daniel.thompson@linaro.org; jens.wiklander@linaro.org; > > > Rod Dorris > > > Subject: RE: [edk2] [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to communicate > > > with OP-TEE > > > > > > Hi Ard > > > > > > > If MM mode is fundamentally incompatible with OP-TEE, then you cannot > > > > run both at the same time, > > > > > > Both cannot coexist unless you have v8.4 CPU > > > > > > Regards > > > Udit > > > > > > > > > > > > > > > >> -----Original Message----- > > > > >> From: edk2-devel On Behalf Of > > > > >> Sumit Garg > > > > >> Sent: Friday, August 24, 2018 2:51 PM > > > > >> To: edk2-devel@lists.01.org > > > > >> Cc: daniel.thompson@linaro.org; tee-dev@lists.linaro.org; > > > > >> jens.wiklander@linaro.org > > > > >> Subject: [edk2] [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to > > > > >> communicate with OP-TEE > > > > >> > > > > >> Add following APIs to communicate with OP-TEE static TA: > > > > >> 1. OpteeInit > > > > >> 2. OpteeOpenSession > > > > >> 3. OpteeCloseSession > > > > >> 4. OpteeInvokeFunc > > > > >> > > > > >> Cc: Ard Biesheuvel > > > > >> Cc: Leif Lindholm > > > > >> Contributed-under: TianoCore Contribution Agreement 1.1 > > > > >> Signed-off-by: Sumit Garg > > > > >> --- > > > > >> ArmPkg/Include/Library/OpteeLib.h | 102 ++++++ > > > > >> ArmPkg/Library/OpteeLib/Optee.c | 358 > > > > >> +++++++++++++++++++++ > > > > >> ArmPkg/Library/OpteeLib/OpteeLib.inf | 2 + > > > > >> ArmPkg/Library/OpteeLib/OpteeSmc.h | 43 +++ > > > > >> .../Include/IndustryStandard/GlobalPlatform.h | 60 ++-- > > > > >> 5 files changed, 531 insertions(+), 34 deletions(-) create mode > > > > >> 100644 ArmPkg/Library/OpteeLib/OpteeSmc.h > > > > >> copy ArmPkg/Include/Library/OpteeLib.h => > > > > >> MdePkg/Include/IndustryStandard/GlobalPlatform.h (53%) > > > > >> > > > > >> diff --git a/ArmPkg/Include/Library/OpteeLib.h > > > > >> b/ArmPkg/Include/Library/OpteeLib.h > > > > >> index f65d8674d9b8..c323f49072f8 100644 > > > > >> --- a/ArmPkg/Include/Library/OpteeLib.h > > > > >> +++ b/ArmPkg/Include/Library/OpteeLib.h > > > > >> @@ -25,10 +25,112 @@ > > > > >> #define OPTEE_OS_UID2 0xaf630002 > > > > >> #define OPTEE_OS_UID3 0xa5d5c51b > > > > >> > > > > >> +#define OPTEE_MSG_ATTR_TYPE_NONE 0x0 > > > > >> +#define OPTEE_MSG_ATTR_TYPE_VALUE_INPUT 0x1 > > > > >> +#define OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT 0x2 > > > > >> +#define OPTEE_MSG_ATTR_TYPE_VALUE_INOUT 0x3 > > > > >> +#define OPTEE_MSG_ATTR_TYPE_MEM_INPUT 0x9 > > > > >> +#define OPTEE_MSG_ATTR_TYPE_MEM_OUTPUT 0xa > > > > >> +#define OPTEE_MSG_ATTR_TYPE_MEM_INOUT 0xb > > > > >> + > > > > >> +#define OPTEE_MSG_ATTR_TYPE_MASK 0xff > > > > >> + > > > > >> +typedef struct { > > > > >> + UINT64 BufPtr; > > > > >> + UINT64 Size; > > > > >> + UINT64 ShmRef; > > > > >> +} OPTEE_MSG_PARAM_MEM; > > > > >> + > > > > >> +typedef struct { > > > > >> + UINT64 A; > > > > >> + UINT64 B; > > > > >> + UINT64 C; > > > > >> +} OPTEE_MSG_PARAM_VALUE; > > > > >> + > > > > >> +typedef struct { > > > > >> + UINT64 Attr; > > > > >> + union { > > > > >> + OPTEE_MSG_PARAM_MEM Mem; > > > > >> + OPTEE_MSG_PARAM_VALUE Value; > > > > >> + } U; > > > > >> +} OPTEE_MSG_PARAM; > > > > >> + > > > > >> +#define MAX_PARAMS 4 > > > > >> + > > > > >> +typedef struct { > > > > >> + UINT32 Cmd; > > > > >> + UINT32 Func; > > > > >> + UINT32 Session; > > > > >> + UINT32 CancelId; > > > > >> + UINT32 Pad; > > > > >> + UINT32 Ret; > > > > >> + UINT32 RetOrigin; > > > > >> + UINT32 NumParams; > > > > >> + > > > > >> + // NumParams tells the actual number of element in Params > > > > >> + OPTEE_MSG_PARAM Params[MAX_PARAMS]; > > > > >> +} OPTEE_MSG_ARG; > > > > >> + > > > > >> +#define OPTEE_UUID_LEN 16 > > > > >> + > > > > >> +// > > > > >> +// struct OPTEE_OPEN_SESSION_ARG - Open session argument > > > > >> +// @Uuid: [in] UUID of the Trusted Application > > > > >> +// @Session: [out] Session id > > > > >> +// @Ret: [out] Return value > > > > >> +// @RetOrigin [out] Origin of the return value > > > > >> +// > > > > >> +typedef struct { > > > > >> + UINT8 Uuid[OPTEE_UUID_LEN]; > > > > >> + UINT32 Session; > > > > >> + UINT32 Ret; > > > > >> + UINT32 RetOrigin; > > > > >> +} OPTEE_OPEN_SESSION_ARG; > > > > >> + > > > > >> +// > > > > >> +// struct OPTEE_INVOKE_FUNC_ARG - Invoke function argument > > > > >> +// @Func: [in] Trusted Application function, specific to the TA > > > > >> +// @Session: [in] Session id > > > > >> +// @Ret: [out] Return value > > > > >> +// @RetOrigin [out] Origin of the return value > > > > >> +// @Params [inout] Parameters for function to be invoked > > > > >> +// > > > > >> +typedef struct { > > > > >> + UINT32 Func; > > > > >> + UINT32 Session; > > > > >> + UINT32 Ret; > > > > >> + UINT32 RetOrigin; > > > > >> + OPTEE_MSG_PARAM Params[MAX_PARAMS]; > > > > >> +} OPTEE_INVOKE_FUNC_ARG; > > > > >> + > > > > >> BOOLEAN > > > > >> EFIAPI > > > > >> IsOpteePresent ( > > > > >> VOID > > > > >> ); > > > > >> > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeInit ( > > > > >> + VOID > > > > >> + ); > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeOpenSession ( > > > > >> + IN OUT OPTEE_OPEN_SESSION_ARG *OpenSessionArg > > > > >> + ); > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeCloseSession ( > > > > >> + IN UINT32 Session > > > > >> + ); > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeInvokeFunc ( > > > > >> + IN OUT OPTEE_INVOKE_FUNC_ARG *InvokeFuncArg > > > > >> + ); > > > > >> + > > > > >> #endif > > > > >> diff --git a/ArmPkg/Library/OpteeLib/Optee.c > > > > >> b/ArmPkg/Library/OpteeLib/Optee.c index 574527f8b5ea..2111022d3662 > > > > >> 100644 > > > > >> --- a/ArmPkg/Library/OpteeLib/Optee.c > > > > >> +++ b/ArmPkg/Library/OpteeLib/Optee.c > > > > >> @@ -14,11 +14,19 @@ > > > > >> > > > > >> **/ > > > > >> > > > > >> +#include > > > > >> #include > > > > >> +#include > > > > >> #include > > > > >> +#include > > > > >> #include > > > > >> > > > > >> #include > > > > >> +#include > > > > >> +#include > > > > >> +#include > > > > >> + > > > > >> +STATIC OPTEE_SHARED_MEMORY_INFO OpteeShmInfo = { 0 }; > > > > >> > > > > >> /** > > > > >> Check for OP-TEE presence. > > > > >> @@ -31,6 +39,7 @@ IsOpteePresent ( > > > > >> { > > > > >> ARM_SMC_ARGS ArmSmcArgs; > > > > >> > > > > >> + ZeroMem (&ArmSmcArgs, sizeof (ARM_SMC_ARGS)); > > > > >> // Send a Trusted OS Calls UID command > > > > >> ArmSmcArgs.Arg0 = ARM_SMC_ID_TOS_UID; > > > > >> ArmCallSmc (&ArmSmcArgs); > > > > >> @@ -44,3 +53,352 @@ IsOpteePresent ( > > > > >> return FALSE; > > > > >> } > > > > >> } > > > > >> + > > > > >> +STATIC > > > > >> +EFI_STATUS > > > > >> +OpteeShmMemRemap ( > > > > >> + VOID > > > > >> + ) > > > > >> +{ > > > > >> + ARM_SMC_ARGS ArmSmcArgs; > > > > >> + EFI_PHYSICAL_ADDRESS Paddr; > > > > >> + EFI_PHYSICAL_ADDRESS Start; > > > > >> + EFI_PHYSICAL_ADDRESS End; > > > > >> + EFI_STATUS Status; > > > > >> + UINTN Size; > > > > >> + > > > > >> + ZeroMem (&ArmSmcArgs, sizeof (ARM_SMC_ARGS)); > > > > >> + ArmSmcArgs.Arg0 = OPTEE_SMC_GET_SHM_CONFIG; > > > > >> + > > > > >> + ArmCallSmc (&ArmSmcArgs); > > > > >> + if (ArmSmcArgs.Arg0 != OPTEE_SMC_RETURN_OK) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE shared memory not supported\n")); > > > > >> + return EFI_UNSUPPORTED; > > > > >> + } > > > > >> + > > > > >> + if (ArmSmcArgs.Arg3 != OPTEE_SMC_SHM_CACHED) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE: Only normal cached shared > > > > memory > > > > >> supported\n")); > > > > >> + return EFI_UNSUPPORTED; > > > > >> + } > > > > >> + > > > > >> + Start = (ArmSmcArgs.Arg1 + SIZE_4KB - 1) & ~(SIZE_4KB - 1); End > > > > >> + = > > > > >> + (ArmSmcArgs.Arg1 + ArmSmcArgs.Arg2) & ~(SIZE_4KB - 1); Paddr = > > > > >> + Start; Size = End - Start; > > > > >> + > > > > >> + if (Size < SIZE_4KB) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE shared memory too small\n")); > > > > >> + return EFI_BUFFER_TOO_SMALL; > > > > >> + } > > > > >> + > > > > >> + Status = ArmSetMemoryAttributes (Paddr, Size, EFI_MEMORY_WB); > > > > >> + if (EFI_ERROR (Status)) { > > > > >> + return Status; > > > > >> + } > > > > >> + > > > > >> + OpteeShmInfo.Base = (UINTN)Paddr; OpteeShmInfo.Size = Size; > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeInit ( > > > > >> + VOID > > > > >> + ) > > > > >> +{ > > > > >> + EFI_STATUS Status; > > > > >> + > > > > >> + if (!IsOpteePresent ()) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE not present\n")); > > > > >> + return EFI_UNSUPPORTED; > > > > >> + } > > > > >> + > > > > >> + Status = OpteeShmMemRemap (); > > > > >> + if (EFI_ERROR (Status)) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE shared memory remap failed\n")); > > > > >> + return Status; > > > > >> + } > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> + > > > > >> +/** > > > > >> + Does Standard SMC to OP-TEE in secure world. > > > > >> + > > > > >> + @param[in] Parg Physical address of message to pass to secure world > > > > >> + > > > > >> + @return 0 on success, secure world return code otherwise > > > > >> + > > > > >> +**/ > > > > >> +STATIC > > > > >> +UINT32 > > > > >> +OpteeCallWithArg ( > > > > >> + IN EFI_PHYSICAL_ADDRESS Parg > > > > >> + ) > > > > >> +{ > > > > >> + ARM_SMC_ARGS ArmSmcArgs; > > > > >> + > > > > >> + ZeroMem (&ArmSmcArgs, sizeof (ARM_SMC_ARGS)); > > > > >> + ArmSmcArgs.Arg0 = OPTEE_SMC_CALL_WITH_ARG; > > > > >> + ArmSmcArgs.Arg1 = (UINT32)(Parg >> 32); > > > > >> + ArmSmcArgs.Arg2 = (UINT32)Parg; > > > > >> + > > > > >> + while (TRUE) { > > > > >> + ArmCallSmc (&ArmSmcArgs); > > > > >> + > > > > >> + if (ArmSmcArgs.Arg0 == OPTEE_SMC_RETURN_RPC_FOREIGN_INTR) { > > > > >> + // > > > > >> + // A foreign interrupt was raised while secure world was > > > > >> + // executing, since they are handled in UEFI a dummy RPC is > > > > >> + // performed to let UEFI take the interrupt through the normal > > > > >> + // vector. > > > > >> + // > > > > >> + ArmSmcArgs.Arg0 = OPTEE_SMC_RETURN_FROM_RPC; > > > > >> + } else { > > > > >> + break; > > > > >> + } > > > > >> + } > > > > >> + > > > > >> + return ArmSmcArgs.Arg0; > > > > >> +} > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeOpenSession ( > > > > >> + IN OUT OPTEE_OPEN_SESSION_ARG *OpenSessionArg > > > > >> + ) > > > > >> +{ > > > > >> + OPTEE_MSG_ARG *MsgArg; > > > > >> + > > > > >> + MsgArg = NULL; > > > > >> + > > > > >> + if (OpteeShmInfo.Base == 0) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); > > > > >> + return EFI_NOT_STARTED; > > > > >> + } > > > > >> + > > > > >> + MsgArg = (OPTEE_MSG_ARG *)OpteeShmInfo.Base; ZeroMem (MsgArg, > > > > >> sizeof > > > > >> + (OPTEE_MSG_ARG)); > > > > >> + > > > > >> + MsgArg->Cmd = OPTEE_MSG_CMD_OPEN_SESSION; > > > > >> + > > > > >> + // > > > > >> + // Initialize and add the meta parameters needed when opening a > > > > >> + // session. > > > > >> + // > > > > >> + MsgArg->Params[0].Attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | > > > > >> + OPTEE_MSG_ATTR_META; > > > > >> + MsgArg->Params[1].Attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | > > > > >> + OPTEE_MSG_ATTR_META; CopyMem > > > > >> + (&MsgArg->Params[0].U.Value, OpenSessionArg->Uuid, > > > > OPTEE_UUID_LEN); > > > > >> + ZeroMem (&MsgArg->Params[1].U.Value, OPTEE_UUID_LEN); > > > > >> + MsgArg->Params[1].U.Value.C = TEE_LOGIN_PUBLIC; > > > > >> + > > > > >> + MsgArg->NumParams = 2; > > > > >> + > > > > >> + if (OpteeCallWithArg ((EFI_PHYSICAL_ADDRESS)MsgArg)) { > > > > >> + MsgArg->Ret = TEEC_ERROR_COMMUNICATION; > > > > >> + MsgArg->RetOrigin = TEEC_ORIGIN_COMMS; } > > > > >> + > > > > >> + OpenSessionArg->Session = MsgArg->Session; OpenSessionArg->Ret > > > > >> + = > > > > >> + MsgArg->Ret; OpenSessionArg->RetOrigin = MsgArg->RetOrigin; > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeCloseSession ( > > > > >> + IN UINT32 Session > > > > >> + ) > > > > >> +{ > > > > >> + OPTEE_MSG_ARG *MsgArg; > > > > >> + > > > > >> + MsgArg = NULL; > > > > >> + > > > > >> + if (OpteeShmInfo.Base == 0) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); > > > > >> + return EFI_NOT_STARTED; > > > > >> + } > > > > >> + > > > > >> + MsgArg = (OPTEE_MSG_ARG *)OpteeShmInfo.Base; ZeroMem (MsgArg, > > > > >> sizeof > > > > >> + (OPTEE_MSG_ARG)); > > > > >> + > > > > >> + MsgArg->Cmd = OPTEE_MSG_CMD_CLOSE_SESSION; MsgArg->Session > > > > = > > > > >> + Session; > > > > >> + > > > > >> + OpteeCallWithArg ((EFI_PHYSICAL_ADDRESS)MsgArg); > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> + > > > > >> +STATIC > > > > >> +EFI_STATUS > > > > >> +OpteeToMsgParam ( > > > > >> + OUT OPTEE_MSG_PARAM *MsgParams, > > > > >> + IN UINT32 NumParams, > > > > >> + IN OPTEE_MSG_PARAM *InParams > > > > >> + ) > > > > >> +{ > > > > >> + UINT32 Idx; > > > > >> + UINTN ParamShmAddr; > > > > >> + UINTN ShmSize; > > > > >> + UINTN Size; > > > > >> + > > > > >> + Size = (sizeof (OPTEE_MSG_ARG) + sizeof (UINT64) - 1) & ~(sizeof > > > > >> + (UINT64) - 1); ParamShmAddr = OpteeShmInfo.Base + Size; ShmSize > > > > >> + = OpteeShmInfo.Size - Size; > > > > >> + > > > > >> + for (Idx = 0; Idx < NumParams; Idx++) { > > > > >> + CONST OPTEE_MSG_PARAM *Ip; > > > > >> + OPTEE_MSG_PARAM *Mp; > > > > >> + UINT32 Attr; > > > > >> + > > > > >> + Ip = InParams + Idx; > > > > >> + Mp = MsgParams + Idx; > > > > >> + Attr = Ip->Attr & OPTEE_MSG_ATTR_TYPE_MASK; > > > > >> + > > > > >> + switch (Attr) { > > > > >> + case OPTEE_MSG_ATTR_TYPE_NONE: > > > > >> + Mp->Attr = OPTEE_MSG_ATTR_TYPE_NONE; > > > > >> + ZeroMem (&Mp->U, sizeof (Mp->U)); > > > > >> + break; > > > > >> + > > > > >> + case OPTEE_MSG_ATTR_TYPE_VALUE_INPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_VALUE_INOUT: > > > > >> + Mp->Attr = Attr; > > > > >> + Mp->U.Value.A = Ip->U.Value.A; > > > > >> + Mp->U.Value.B = Ip->U.Value.B; > > > > >> + Mp->U.Value.C = Ip->U.Value.C; > > > > >> + break; > > > > >> + > > > > >> + case OPTEE_MSG_ATTR_TYPE_MEM_INPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_MEM_OUTPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_MEM_INOUT: > > > > >> + Mp->Attr = Attr; > > > > >> + > > > > >> + if (Ip->U.Mem.Size > ShmSize) { > > > > >> + return EFI_OUT_OF_RESOURCES; > > > > >> + } > > > > >> + > > > > >> + CopyMem ((VOID *)ParamShmAddr, (VOID *)Ip->U.Mem.BufPtr, Ip- > > > > >> >U.Mem.Size); > > > > >> + Mp->U.Mem.BufPtr = (UINT64)ParamShmAddr; > > > > >> + Mp->U.Mem.Size = Ip->U.Mem.Size; > > > > >> + > > > > >> + Size = (Ip->U.Mem.Size + sizeof (UINT64) - 1) & ~(sizeof (UINT64) - 1); > > > > >> + ParamShmAddr += Size; > > > > >> + ShmSize -= Size; > > > > >> + break; > > > > >> + > > > > >> + default: > > > > >> + return EFI_INVALID_PARAMETER; > > > > >> + } > > > > >> + } > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> + > > > > >> +STATIC > > > > >> +EFI_STATUS > > > > >> +OpteeFromMsgParam ( > > > > >> + OUT OPTEE_MSG_PARAM *OutParams, > > > > >> + IN UINT32 NumParams, > > > > >> + IN OPTEE_MSG_PARAM *MsgParams > > > > >> + ) > > > > >> +{ > > > > >> + UINT32 Idx; > > > > >> + > > > > >> + for (Idx = 0; Idx < NumParams; Idx++) { > > > > >> + OPTEE_MSG_PARAM *Op; > > > > >> + CONST OPTEE_MSG_PARAM *Mp; > > > > >> + UINT32 Attr; > > > > >> + > > > > >> + Op = OutParams + Idx; > > > > >> + Mp = MsgParams + Idx; > > > > >> + Attr = Mp->Attr & OPTEE_MSG_ATTR_TYPE_MASK; > > > > >> + > > > > >> + switch (Attr) { > > > > >> + case OPTEE_MSG_ATTR_TYPE_NONE: > > > > >> + Op->Attr = OPTEE_MSG_ATTR_TYPE_NONE; > > > > >> + ZeroMem (&Op->U, sizeof (Op->U)); > > > > >> + break; > > > > >> + > > > > >> + case OPTEE_MSG_ATTR_TYPE_VALUE_INPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_VALUE_INOUT: > > > > >> + Op->Attr = Attr; > > > > >> + Op->U.Value.A = Mp->U.Value.A; > > > > >> + Op->U.Value.B = Mp->U.Value.B; > > > > >> + Op->U.Value.C = Mp->U.Value.C; > > > > >> + break; > > > > >> + > > > > >> + case OPTEE_MSG_ATTR_TYPE_MEM_INPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_MEM_OUTPUT: > > > > >> + case OPTEE_MSG_ATTR_TYPE_MEM_INOUT: > > > > >> + Op->Attr = Attr; > > > > >> + > > > > >> + if (Mp->U.Mem.Size > Op->U.Mem.Size) { > > > > >> + return EFI_BAD_BUFFER_SIZE; > > > > >> + } > > > > >> + > > > > >> + CopyMem ((VOID *)Op->U.Mem.BufPtr, (VOID *)Mp->U.Mem.BufPtr, > > > > >> Mp->U.Mem.Size); > > > > >> + Op->U.Mem.Size = Mp->U.Mem.Size; > > > > >> + break; > > > > >> + > > > > >> + default: > > > > >> + return EFI_INVALID_PARAMETER; > > > > >> + } > > > > >> + } > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> + > > > > >> +EFI_STATUS > > > > >> +EFIAPI > > > > >> +OpteeInvokeFunc ( > > > > >> + IN OUT OPTEE_INVOKE_FUNC_ARG *InvokeFuncArg > > > > >> + ) > > > > >> +{ > > > > >> + EFI_STATUS Status; > > > > >> + OPTEE_MSG_ARG *MsgArg; > > > > >> + > > > > >> + MsgArg = NULL; > > > > >> + > > > > >> + if (OpteeShmInfo.Base == 0) { > > > > >> + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); > > > > >> + return EFI_NOT_STARTED; > > > > >> + } > > > > >> + > > > > >> + MsgArg = (OPTEE_MSG_ARG *)OpteeShmInfo.Base; ZeroMem (MsgArg, > > > > >> sizeof > > > > >> + (OPTEE_MSG_ARG)); > > > > >> + > > > > >> + MsgArg->Cmd = OPTEE_MSG_CMD_INVOKE_COMMAND; MsgArg- > > > > >Func = > > > > >> + InvokeFuncArg->Func; MsgArg->Session = InvokeFuncArg->Session; > > > > >> + > > > > >> + Status = OpteeToMsgParam (MsgArg->Params, MAX_PARAMS, > > > > >> + InvokeFuncArg->Params); if (Status) > > > > >> + return Status; > > > > >> + > > > > >> + MsgArg->NumParams = MAX_PARAMS; > > > > >> + > > > > >> + if (OpteeCallWithArg ((EFI_PHYSICAL_ADDRESS)MsgArg)) { > > > > >> + MsgArg->Ret = TEEC_ERROR_COMMUNICATION; > > > > >> + MsgArg->RetOrigin = TEEC_ORIGIN_COMMS; } > > > > >> + > > > > >> + if (OpteeFromMsgParam (InvokeFuncArg->Params, MAX_PARAMS, > > > > >> MsgArg->Params)) { > > > > >> + MsgArg->Ret = TEEC_ERROR_COMMUNICATION; > > > > >> + MsgArg->RetOrigin = TEEC_ORIGIN_COMMS; } > > > > >> + > > > > >> + InvokeFuncArg->Ret = MsgArg->Ret; InvokeFuncArg->RetOrigin = > > > > >> + MsgArg->RetOrigin; > > > > >> + > > > > >> + return EFI_SUCCESS; > > > > >> +} > > > > >> diff --git a/ArmPkg/Library/OpteeLib/OpteeLib.inf > > > > >> b/ArmPkg/Library/OpteeLib/OpteeLib.inf > > > > >> index 5abd427379cc..e03054a7167d 100644 > > > > >> --- a/ArmPkg/Library/OpteeLib/OpteeLib.inf > > > > >> +++ b/ArmPkg/Library/OpteeLib/OpteeLib.inf > > > > >> @@ -23,11 +23,13 @@ [Defines] > > > > >> > > > > >> [Sources] > > > > >> Optee.c > > > > >> + OpteeSmc.h > > > > >> > > > > >> [Packages] > > > > >> ArmPkg/ArmPkg.dec > > > > >> MdePkg/MdePkg.dec > > > > >> > > > > >> [LibraryClasses] > > > > >> + ArmMmuLib > > > > >> ArmSmcLib > > > > >> BaseLib > > > > >> diff --git a/ArmPkg/Library/OpteeLib/OpteeSmc.h > > > > >> b/ArmPkg/Library/OpteeLib/OpteeSmc.h > > > > >> new file mode 100644 > > > > >> index 000000000000..e2ea35784a0a > > > > >> --- /dev/null > > > > >> +++ b/ArmPkg/Library/OpteeLib/OpteeSmc.h > > > > >> @@ -0,0 +1,43 @@ > > > > >> +/** @file > > > > >> + OP-TEE SMC header file. > > > > >> + > > > > >> + Copyright (c) 2018, Linaro Ltd. All rights reserved.
> > > > >> + > > > > >> + This program and the accompanying materials are licensed and > > > > >> + made available under the terms and conditions of the BSD License > > > > >> + which accompanies this distribution. The full text of the > > > > >> + license may be found at > > > > >> + > > > > >> + > > > > >> > > > > https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fope > > > > >> n > > > > >> + source.org%2Flicenses%2Fbsd- > > > > >> license.php&data=02%7C01%7Cudit.kumar% > > > > >> + > > > > >> > > > > 40nxp.com%7Ce95635d0c3c74edbf79808d609a30c7b%7C686ea1d3bc2b4c6f > > > > >> a92cd99 > > > > >> + > > > > >> > > > > c5c301635%7C0%7C0%7C636706993250535371&sdata=pyZF9Ku3qEpp > > > > >> OOKCyshbg > > > > >> + 9oCT4P6AwM2olKY3%2B2ImWs%3D&reserved=0 > > > > >> + > > > > >> + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > > >> BASIS, > > > > >> + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > > > >> EXPRESS OR IMPLIED. > > > > >> + > > > > >> +**/ > > > > >> + > > > > >> +#ifndef _OPTEE_SMC_H_ > > > > >> +#define _OPTEE_SMC_H_ > > > > >> + > > > > >> +/* Returned in Arg0 only from Trusted OS functions */ > > > > >> +#define OPTEE_SMC_RETURN_OK 0x0 > > > > >> + > > > > >> +#define OPTEE_SMC_RETURN_FROM_RPC 0x32000003 > > > > >> +#define OPTEE_SMC_CALL_WITH_ARG 0x32000004 > > > > >> +#define OPTEE_SMC_GET_SHM_CONFIG 0xb2000007 > > > > >> + > > > > >> +#define OPTEE_SMC_SHM_CACHED 1 > > > > >> + > > > > >> +#define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR 0xffff0004 > > > > >> + > > > > >> +#define OPTEE_MSG_CMD_OPEN_SESSION 0 > > > > >> +#define OPTEE_MSG_CMD_INVOKE_COMMAND 1 > > > > >> +#define OPTEE_MSG_CMD_CLOSE_SESSION 2 > > > > >> + > > > > >> +#define OPTEE_MSG_ATTR_META 0x100 > > > > >> + > > > > >> +#define TEE_LOGIN_PUBLIC 0x0 > > > > >> + > > > > >> +typedef struct { > > > > >> + UINTN Base; > > > > >> + UINTN Size; > > > > >> +} OPTEE_SHARED_MEMORY_INFO; > > > > >> + > > > > >> +#endif > > > > >> diff --git a/ArmPkg/Include/Library/OpteeLib.h > > > > >> b/MdePkg/Include/IndustryStandard/GlobalPlatform.h > > > > >> similarity index 53% > > > > >> copy from ArmPkg/Include/Library/OpteeLib.h copy to > > > > >> MdePkg/Include/IndustryStandard/GlobalPlatform.h > > > > >> index f65d8674d9b8..14c621d89971 100644 > > > > >> --- a/ArmPkg/Include/Library/OpteeLib.h > > > > >> +++ b/MdePkg/Include/IndustryStandard/GlobalPlatform.h > > > > >> @@ -1,34 +1,26 @@ > > > > >> -/** @file > > > > >> - OP-TEE specific header file. > > > > >> - > > > > >> - Copyright (c) 2018, Linaro Ltd. All rights reserved.
> > > > >> - > > > > >> - This program and the accompanying materials > > > > >> - are licensed and made available under the terms and conditions > > > > >> of the BSD License > > > > >> - which accompanies this distribution. The full text of the > > > > >> license may be found at > > > > >> - > > > > >> > > > > https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fope > > > > >> nsource.org%2Flicenses%2Fbsd- > > > > >> > > > > license.php&data=02%7C01%7Cudit.kumar%40nxp.com%7Ce95635d0c > > > > >> > > > > 3c74edbf79808d609a30c7b%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0% > > > > >> > > > > 7C0%7C636706993250535371&sdata=pyZF9Ku3qEppOOKCyshbg9oCT4 > > > > >> P6AwM2olKY3%2B2ImWs%3D&reserved=0 > > > > >> - > > > > >> - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > > >> BASIS, > > > > >> - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > > > EXPRESS > > > > >> OR IMPLIED. > > > > >> - > > > > >> -**/ > > > > >> - > > > > >> -#ifndef _OPTEE_H_ > > > > >> -#define _OPTEE_H_ > > > > >> - > > > > >> -/* > > > > >> - * The 'Trusted OS Call UID' is supposed to return the following > > > > >> UUID for > > > > >> - * OP-TEE OS. This is a 128-bit value. > > > > >> - */ > > > > >> -#define OPTEE_OS_UID0 0x384fb3e0 > > > > >> -#define OPTEE_OS_UID1 0xe7f811e3 > > > > >> -#define OPTEE_OS_UID2 0xaf630002 > > > > >> -#define OPTEE_OS_UID3 0xa5d5c51b > > > > >> - > > > > >> -BOOLEAN > > > > >> -EFIAPI > > > > >> -IsOpteePresent ( > > > > >> - VOID > > > > >> - ); > > > > >> - > > > > >> -#endif > > > > >> +/** @file > > > > >> + Standardized Global Platform header file. > > > > >> + > > > > >> + Copyright (c) 2018, Linaro Ltd. All rights reserved.
> > > > >> + > > > > >> + This program and the accompanying materials are licensed and > > > > >> + made available under the terms and conditions of the BSD License > > > > >> + which accompanies this distribution. The full text of the > > > > >> + license may be found at > > > > >> + > > > > >> + > > > > >> > > > > https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fope > > > > >> n > > > > >> + source.org%2Flicenses%2Fbsd- > > > > >> license.php&data=02%7C01%7Cudit.kumar% > > > > >> + > > > > >> > > > > 40nxp.com%7Ce95635d0c3c74edbf79808d609a30c7b%7C686ea1d3bc2b4c6f > > > > >> a92cd99 > > > > >> + > > > > >> > > > > c5c301635%7C0%7C0%7C636706993250535371&sdata=pyZF9Ku3qEpp > > > > >> OOKCyshbg > > > > >> + 9oCT4P6AwM2olKY3%2B2ImWs%3D&reserved=0 > > > > >> + > > > > >> + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > > >> BASIS, > > > > >> + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > > > >> EXPRESS OR IMPLIED. > > > > >> + > > > > >> +**/ > > > > >> + > > > > >> +#ifndef _GLOBAL_PLATFORM_H_ > > > > >> +#define _GLOBAL_PLATFORM_H_ > > > > >> + > > > > >> +#define TEEC_ORIGIN_COMMS 0x00000002 > > > > >> + > > > > >> +#define TEEC_SUCCESS 0x00000000 > > > > >> +#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006 > > > > >> +#define TEEC_ERROR_COMMUNICATION 0xFFFF000E > > > > >> +#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C > > > > >> + > > > > >> +#endif > > > > >> -- > > > > >> 2.7.4 > > > > >> > > > > >> _______________________________________________ > > > > >> edk2-devel mailing list > > > > >> edk2-devel@lists.01.org > > > > >> > > > > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fli > > > > >> st > > > > >> s.01.org%2Fmailman%2Flistinfo%2Fedk2- > > > > >> > > > > devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Ce95635d0c3c74e > > > > >> > > > > dbf79808d609a30c7b%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0% > > > > >> > > > > 7C636706993250535371&sdata=msA6jGRAkpWoQ33VsDfbWqgGcIMTP > > > > >> u%2Fhcds3j9aDPnU%3D&reserved=0 > > > > > _______________________________________________ > > > > > edk2-devel mailing list > > > > > edk2-devel@lists.01.org > > > > > > > > > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flis > > > > > ts.01.org%2Fmailman%2Flistinfo%2Fedk2- > > > > devel&data=02%7C01%7Cudit.ku > > > > > > > > > mar%40nxp.com%7C5311c5dc22d54095d79d08d609e7fbf5%7C686ea1d3bc2 > > > > b4c6fa92 > > > > > > > > > cd99c5c301635%7C0%7C0%7C636707289305519903&sdata=dwLUq8j9f > > > > 9rxeb37V > > > > > 8fGZKoiWh1TNBnhVFqnuF5oN3g%3D&reserved=0 > > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.