From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD520C433E2 for ; Mon, 7 Sep 2020 11:22:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CB9B206D4 for ; Mon, 7 Sep 2020 11:22:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dKz6zh09"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="are6IYp+"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="are6IYp+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CB9B206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TgoUFxkB1uI+LF7u2g75OLaC4RdY+jZToJwCpAN9glE=; b=dKz6zh09S9z6aaOQrhV3Dc1jD DyqOHhnjYPboZuiC0HUh02U3crYaM7HGhE3Df6gGmuhdqSJew9VH4VrQ726m2VURQSNzg8hkU8F3Y yxIzpiE8a0Mu7AEvXFw03BFLimNcyJHIVvtc0kdF/hPKyUd0Lbdlnk1zg5JAWhQ91TJiKnczdJMQR UoPe8Z/rg+prVK8y+icTAoKfp/WH0e+c0adQSkpnDW4eOeNIooX8FobKR6f0xf7BBmA1ZkqJro/iK XmjIBTd5MNL7RHzziBOcuG7izYS2EmWOJwHHESZ9Ws0ZoMPhEJfu2snSvekASkzs5oqW7CkLpc/ii TZHbxx1Ng==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFFD0-0005nW-Ar; Mon, 07 Sep 2020 11:21:14 +0000 Received: from mail-eopbgr70075.outbound.protection.outlook.com ([40.107.7.75] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFFCx-0005my-35 for linux-arm-kernel@lists.infradead.org; Mon, 07 Sep 2020 11:21:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1AN2nvbjNZzhCAdb1Rjo9jWXKj8P2OffFkHCVyHIEl4=; b=are6IYp+Og0jpsHOrUaxFFYgeB3JbayVuamJh/dV7monBg9xYp7GW8z7XV41X+DVOTj4VU6PVPlDyJalJtuAvf3KUK57bqQjC+fzWnrCxZP487PKA5sqRsEtnARHnsR3O8mYUp5pePwD66YCFTo0ea8CZQMpQR8m5LxaxTsojD4= Received: from DB6PR1001CA0045.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::31) by AM6PR08MB5189.eurprd08.prod.outlook.com (2603:10a6:20b:e7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15; Mon, 7 Sep 2020 11:21:02 +0000 Received: from DB5EUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:55:cafe::9f) by DB6PR1001CA0045.outlook.office365.com (2603:10a6:4:55::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Mon, 7 Sep 2020 11:21:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.infradead.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.infradead.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT062.mail.protection.outlook.com (10.152.20.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16 via Frontend Transport; Mon, 7 Sep 2020 11:21:02 +0000 Received: ("Tessian outbound 195a290eb161:v64"); Mon, 07 Sep 2020 11:21:02 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0dd72d3c514b6484 X-CR-MTA-TID: 64aa7808 Received: from da09965d63e5.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DED2736F-78F6-420C-8B47-6EBBD1F406E7.1; Mon, 07 Sep 2020 11:20:56 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id da09965d63e5.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 07 Sep 2020 11:20:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y5B6WQv4u6XKGqj7p0vmrZVhjVMK+0v9x6aFo7ifSj/IuEC94lsq8NO3EkGPK+WW6xgndicvApNtCMSZqIKq9TT64N+lJ79aJpHbHqt5+yvUSVsk/cUDwOc/tQ3utH7/o/pCpq8JlFOlzbMm93GB4JieaU3b5Mm+X5TDVPUoSVbA9WL3fCHcIGTbDPaYwde7eMksSl8pp+8olYRbLNr0CVWbIGKorQEnSGRtSVRmqP/Wn8W3DcwccY9eygJTyGI2iCscSEGcQLOOeCJtFXrZwoHFRZ4UHHi6wCIexQJVOa1ZR8cK1oU9zVo0D2ApJZFFdrgCvaDZsP/NDzElAqK4fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1AN2nvbjNZzhCAdb1Rjo9jWXKj8P2OffFkHCVyHIEl4=; b=SDGKhrMF6kHkqmZMLHuM5BZFFm1X6jEg4bkQBRfjddKkmcUvxqKlGQm2DTPfBEnrPAhUrosbCYpUYSx1qP41n3A81Zpi0g8HNCCHodhhc830pk/plBkTVlnPXOKSfZdk0j1ugmxNkDeaN8Xecmw5SJkTf7FFLffI44EV2xDN3471lr7Yz6VVqJ+EjJo/L1PxOzaVdlQp0xw8gatoH/2gL3d7PQxIARgXjnkbtm0lmUc5Gd6ggmbWsIfAbwppPhCL63Cq4ZFMimFp8fq2El34xLA/tvzeXe4hL7aglzl1ncUil5QzY8WKFM1NSiRuUgqX4JNq9oXaxXvWkx0mHnTIkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1AN2nvbjNZzhCAdb1Rjo9jWXKj8P2OffFkHCVyHIEl4=; b=are6IYp+Og0jpsHOrUaxFFYgeB3JbayVuamJh/dV7monBg9xYp7GW8z7XV41X+DVOTj4VU6PVPlDyJalJtuAvf3KUK57bqQjC+fzWnrCxZP487PKA5sqRsEtnARHnsR3O8mYUp5pePwD66YCFTo0ea8CZQMpQR8m5LxaxTsojD4= Received: from DB6PR0801MB1861.eurprd08.prod.outlook.com (2603:10a6:4:73::21) by DB8PR08MB4090.eurprd08.prod.outlook.com (2603:10a6:10:ab::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15; Mon, 7 Sep 2020 11:20:54 +0000 Received: from DB6PR0801MB1861.eurprd08.prod.outlook.com ([fe80::359c:ebc2:fe11:e50b]) by DB6PR0801MB1861.eurprd08.prod.outlook.com ([fe80::359c:ebc2:fe11:e50b%10]) with mapi id 15.20.3348.019; Mon, 7 Sep 2020 11:20:54 +0000 From: Achin Gupta To: Sudeep Holla Subject: Re: [PATCH 8/9] firmware: arm_ffa: Setup and register all the KVM managed partitions Thread-Topic: [PATCH 8/9] firmware: arm_ffa: Setup and register all the KVM managed partitions Thread-Index: AQHWhQjzGWl2YGoSvUm5AudDEPjfMg== Date: Mon, 7 Sep 2020 11:20:54 +0000 Message-ID: References: <20200829170923.29949-1-sudeep.holla@arm.com> <20200829170923.29949-9-sudeep.holla@arm.com> In-Reply-To: <20200829170923.29949-9-sudeep.holla@arm.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3445.104.14) Authentication-Results-Original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; x-originating-ip: [84.68.62.30] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5ca342d0-e262-46b3-b3b6-08d853201ab6 x-ms-traffictypediagnostic: DB8PR08MB4090:|AM6PR08MB5189: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:6430;OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: iWaV02TdqDr2mMOSqICkMCJvpu0wtsPMUItsWt1jkRguUlZWB8xCDWn+dwGTsQGgnvQyuiUkAQZFF3h5X3y+XvES+Pd4AbCApSH23xTd7V63+WQcsUjhZPG+8jqDdlja3u+kqJaL4GLpreJ5iyMAYi++Okys6lh2JONnq8a/csJty0Qz32INeUocKmX+A66Yn9rtYvwNgfvv0rzjN+iHmNNsTCu4Qca6QI5PQZWsw4tPRkSMCtjBqkuqqwLI+kTFD1C+L/9oNme8KoIxVrPHZdLR8PjOicEP9aRQ1eobJyx8+5MH7NWq0OaG5tH152dPU7I/Z0W5wC/I3F0MlJ3hKw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0801MB1861.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39860400002)(366004)(136003)(396003)(346002)(186003)(33656002)(5660300002)(66476007)(66556008)(6506007)(37006003)(26005)(54906003)(53546011)(478600001)(86362001)(36756003)(83380400001)(2616005)(2906002)(4326008)(6862004)(8676002)(8936002)(316002)(6636002)(6486002)(66946007)(64756008)(76116006)(6512007)(71200400001)(66446008)(91956017); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: DqZlMPWdvLV21SUd35DKZzK94WU47ZEorOeDgM3YmqqR4QuNhNhPdTFRp+FSVGadZIll3xViU/f0REvQ1eWwrknIe9EcStvVT8CkgUinFFsDRrOr/cga/WqaLyRHnveGiatBrgqW50Y/tAN3sueebIAvc5cHaXp5JHVriSs/UDcs0Mi2fTLSozGnExCM1poIVyqMi4YA6S0kVvTzqL8QovKTtXlH417wj7zp1m9+98yT5Tt5rN1LFUjfAs23EgxNwcVNyP3tUshKv3eL9jDuZ268YYB4NChcQcv9k91tpih9me6j1zHD9GBNtP0X9S0VqSn6luKPTZoAb42iCFcZucIh2AQ5s9C6Zkjqdjz9TnUNME92bOmpXNPNy3+55ck1nFcOF09G0KoieoptUIDOojaVGoQvRPpZAJAWnh3RnIzG8CQcyYDMlzhwFR3vsJzxqRjiQZhziqToYvNk9TcJrDXmBtyPmJBU94w96LBH1hJUxFIW8j6MXcgzGG1dYHK6AGxlzVtDh7cIwFCU6DDDjuxL45ENbUxCNkLjNGdhLyvCCfvLndKvM3PXGJuG9FHdOothyTBdSvAi+ui97E8FR+wCijB92msRe8TZ+0c0EbNoSEl4ALazyKSoxfTNnGwPf8LvzriO4Ub49u0F3Bmhng== Content-ID: <15A921A2A837AC4AB8D6441C43042AAF@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB4090 Original-Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ed5bd25b-aeb2-40ed-a90d-08d8532015ff X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bUZxPJSh9FpIa0v39bHqifX89xZqUXvUEW7W6UPEzfNAvGbXuBmRJzxX7alj91zmlRF+VTtPeJV/x1eS0rXm3BOjmC80fJW8AIONpw212/+EskDC0vSN/qpZAUsRibQZiuvsq/7vIAEtqwjvMNxqfaZFtppa2SbB6uvQJTGeEcjzn2zO6QfasevQIGBGJtb9f+vq8jsCpQC41ri42UqavY3Ngn23NO9Qk7kDivYzDfGPbeUX65rhcgwyESDlrdK0lm6cZr5mk6WoQCkBMoIxn+y+n+V3te0v5x1J4V2Ik9O4Cww3SxJFp/wzuY6pmQbsGNtfFBdim+WOJc4Uqs1TDm3swFF2tLWN5UB3umNHXC+trM6NQzZ9fJ7bCpz/Fr+s7qbaxH6uRLiiO3ixOpq+Zg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(376002)(396003)(346002)(46966005)(33656002)(2906002)(26005)(36756003)(54906003)(336012)(4326008)(316002)(186003)(6486002)(6862004)(70586007)(37006003)(70206006)(53546011)(86362001)(83380400001)(82310400003)(6506007)(2616005)(478600001)(6636002)(82740400003)(8936002)(5660300002)(356005)(8676002)(47076004)(81166007)(6512007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2020 11:21:02.5085 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ca342d0-e262-46b3-b3b6-08d853201ab6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5189 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200907_072111_391240_881BFB34 X-CRM114-Status: GOOD ( 22.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "devicetree@vger.kernel.org" , "kernel-team@android.com" , Pratik Patel , "tsoni@quicinc.com" , nd , Will Deacon , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Sudeep, A couple of questions inline... > On 29 Aug 2020, at 18:09, Sudeep Holla wrote: > > Parse the FFA nodes from the device-tree and register all the partitions > managed by the KVM hypervisor. > > All the partitions including the host(self) are registered as the > character device with a set of file operations. Most of the interface > will concentrated in the ioctl. > > For now, we have a tiny set of initial ioctls implemented. > > Signed-off-by: Sudeep Holla > --- > drivers/firmware/arm_ffa/bus.c | 2 + > drivers/firmware/arm_ffa/driver.c | 378 +++++++++++++++++++++++++++++- > include/linux/arm_ffa.h | 3 + > include/uapi/linux/arm_ffa.h | 56 +++++ > 4 files changed, 438 insertions(+), 1 deletion(-) > create mode 100644 include/uapi/linux/arm_ffa.h > [snip] > + > +static long ffa_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) > +{ > + long r = -EINVAL; > + void __user *argp = (void __user *)arg; > + struct ffa_device *ffa_dev = filp->private_data; > + > + switch (ioctl) { > + case FFA_GET_API_VERSION: > + if (arg) > + goto out; > + r = drv_info->version; > + break; > + case FFA_GET_PARTITION_ID: > + if (arg) > + goto out; > + r = ffa_dev->vm_id; > + break; > + case FFA_GET_PARTITION_INFO: { > + struct ffa_partition_info pbuf; > + struct ffa_part_info __user *pinfo = argp; > + struct ffa_part_info info; > + unsigned int count; > + > + r = -EFAULT; > + if (copy_from_user(&info, pinfo, sizeof(info))) > + break; > + count = ffa_partition_probe(info.uuid_str, &pbuf); > + if (count > 1) { > + r = -E2BIG; > + break; > + } > + r = -EFAULT; > + if (copy_to_user(pinfo, &info, sizeof(info))) > + break; > + r = 0; > + break; > + } > + case FFA_SEND_RECEIVE_SYNC: { > + struct ffa_send_recv_sync __user *udata = argp; > + struct ffa_send_recv_sync kdata; > + > + r = -EFAULT; > + if (copy_from_user(&kdata, udata, sizeof(kdata))) > + break; > + r = ffa_msg_send_direct_req(ffa_dev->vm_id, kdata.endpoint_id, > + &kdata.data); > + if (r) > + break; > + if (copy_to_user(udata, &kdata, sizeof(kdata))) > + break; > + break; > + } > + case FFA_SEND_RECEIVE_ASYNC: { Should this be FFA_SEND_ASYNC? Since asynchronous messaging is being used, there should be a separate FFA_RECEIVE_ASYNC ioctl? This could be a request to block until a message arrives or poll. I am also thinking if instead of sync/async, direct/indirect should be used to align with the function names in the module and the FF-A spec. Also wanted to confirm if an ioctl for FFA_RUN is also on the cards? Once the message has been posted, a vCPU of the target VM would need to run to pick it up? I have some more comments on how in-kernel users will use indirect messaging. Will leave those in reply to your next patch. Cheers, Achin > + struct ffa_send_recv_async __user *udata = argp; > + struct ffa_send_recv_async kdata; > + void *buf; > + > + r = -EFAULT; > + if (copy_from_user(&kdata, udata, sizeof(kdata))) > + break; > + > + if (kdata.length < 0 || kdata.length > RXTX_BUFFER_SIZE) { > + r = -EINVAL; > + break; > + } > + > + buf = kzalloc(kdata.length, GFP_KERNEL); > + if (!buf) { > + r = -ENOMEM; > + break; > + } > + > + if (copy_from_user(buf, udata->buffer, kdata.length)) { > + kfree(buf); > + break; > + } > + > + r = ffa_msg_send(ffa_dev->vm_id, kdata.endpoint_id, buf, > + kdata.length); > + if (r) { > + kfree(buf); > + break; > + } > + > + break; > + } > + default: > + r = -EINVAL; > + } > +out: > + return r; > +} > + > +static const struct file_operations ffa_fops = { > + .owner = THIS_MODULE, > + .open = ffa_open, > + .release = ffa_release, > + .unlocked_ioctl = ffa_ioctl, > + .llseek = noop_llseek, > +}; > + > +static int ffa_device_alloc_register(const char *name, u16 vm_id, uuid_t *uuid) > +{ > + int ret; > + struct ffa_device *ffa_dev; > + > + ffa_dev = kzalloc(sizeof(*ffa_dev), GFP_KERNEL); > + if (!ffa_dev) > + return -ENOMEM; > + > + ffa_dev->vm_id = vm_id; > + if (uuid) > + memcpy(uuid, &ffa_dev->uuid, sizeof(*uuid)); > + > + dev_set_name(&ffa_dev->dev, name); > + dev_set_drvdata(&ffa_dev->dev, drv_info); > + cdev_init(&ffa_dev->cdev, &ffa_fops); > + > + ret = ffa_device_register(ffa_dev); > + if (ret) > + return ret; > + > + mutex_lock(&ffa_devs_list_mutex); > + list_add_tail(&ffa_dev->node, &ffa_devs_list); > + mutex_unlock(&ffa_devs_list_mutex); > + > + return 0; > +} > + > +static int ffa_setup_partitions(void) > +{ > + int ret; > + struct ffa_partition_info pbuf; > + struct device_node *child, *parent; > + const char *p_uuid, *pfx = "Ignoring FFA partition"; > + const char *compatible = "arm,ffa-1.0-hypervisor"; > + uuid_t uuid = UUID_INIT(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); > + > + parent = of_find_compatible_node(NULL, NULL, compatible); > + if (!parent) > + return 0; > + > + for_each_child_of_node(parent, child) { > + if (!of_device_is_compatible(child, "arm,ffa-1.0-partition")) { > + of_node_put(child); > + continue; > + } > + > + if (of_property_read_string(child, "uuid", &p_uuid)) { > + pr_err("%s: failed to parse \"uuid\" property\n", pfx); > + of_node_put(child); > + continue; > + } > + > + of_node_put(child); > + > + if (uuid_parse(p_uuid, &uuid)) { > + pr_err("%s: invalid \"uuid\" property (%s)\n", > + pfx, p_uuid); > + continue; > + } > + > + ret = ffa_partition_probe(p_uuid, &pbuf); > + if (ret != 1) { > + pr_err("%s: %s partition info probe failed\n", > + pfx, p_uuid); > + return -EINVAL; > + } > + > + ret = ffa_device_alloc_register(p_uuid, pbuf.id, &uuid); > + if (ret) { > + pr_err("%s: failed to register %s\n", pfx, p_uuid); > + continue; > + } > + } > + > + of_node_put(parent); > + return 0; > +} > + > static int __init ffa_init(void) > { > int ret; > @@ -262,6 +623,14 @@ static int __init ffa_init(void) > mutex_init(&drv_info->rx_lock); > mutex_init(&drv_info->tx_lock); > > + /* This will be default device both in theguests and host */ > + ret = ffa_device_alloc_register("self", drv_info->vm_id, NULL); > + if (ret) > + return ret; > + > + /* Set up all the partitions that KVM hypervisor maintains */ > + ffa_setup_partitions(); > + > return 0; > free_pages: > if (drv_info->tx_buffer) > @@ -275,6 +644,13 @@ module_init(ffa_init); > > static void __exit ffa_exit(void) > { > + struct list_head *p; > + > + mutex_lock(&ffa_devs_list_mutex); > + list_for_each(p, &ffa_devs_list) > + ffa_device_unregister(list_to_ffa_dev(p)); > + mutex_unlock(&ffa_devs_list_mutex); > + > ffa_rxtx_unmap(drv_info->vm_id); > free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); > free_pages_exact(drv_info->rx_buffer, RXTX_BUFFER_SIZE); > diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h > index 2fe16176149f..6824e0633c77 100644 > --- a/include/linux/arm_ffa.h > +++ b/include/linux/arm_ffa.h > @@ -17,6 +17,9 @@ struct ffa_device { > uuid_t uuid; > struct device dev; > struct cdev cdev; > + size_t num_users; > + struct mutex mutex; /* protects num_users */ > + struct list_head node; > }; > > #define to_ffa_dev(d) container_of(d, struct ffa_device, dev) > diff --git a/include/uapi/linux/arm_ffa.h b/include/uapi/linux/arm_ffa.h > new file mode 100644 > index 000000000000..88ddddb4742f > --- /dev/null > +++ b/include/uapi/linux/arm_ffa.h > @@ -0,0 +1,56 @@ > +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ > +/* > + * Copyright (C) 2020 Arm Ltd. > + */ > + > +#ifndef _UAPI_LINUX_ARM_FFA_H > +#define _UAPI_LINUX_ARM_FFA_H > + > +#include > +#include > + > +#define FFA_BASE 0xFF > + > +struct ffa_partition_info { > + __u16 id; > + __u16 exec_ctxt; > +/* partition supports receipt of direct requests */ > +#define FFA_PARTITION_DIRECT_RECV BIT(0) > +/* partition can send direct requests. */ > +#define FFA_PARTITION_DIRECT_SEND BIT(1) > +/* partition can send and receive indirect messages. */ > +#define FFA_PARTITION_INDIRECT_MSG BIT(2) > + __u32 properties; > +}; > + > +struct ffa_part_info { > + char uuid_str[36]; > + struct ffa_partition_info info; > +}; > + > +struct ffa_send_direct_data { > + unsigned long data0; > + unsigned long data1; > + unsigned long data2; > + unsigned long data3; > + unsigned long data4; > +}; > + > +struct ffa_send_recv_sync { > + __u16 endpoint_id; > + struct ffa_send_direct_data data; > +}; > + > +struct ffa_send_recv_async { > + __u16 endpoint_id; > + int length; > + char buffer[]; > +}; > + > +#define FFA_GET_API_VERSION _IO(FFA_BASE, 0x00) > +#define FFA_GET_PARTITION_ID _IO(FFA_BASE, 0x01) > +#define FFA_GET_PARTITION_INFO _IOWR(FFA_BASE, 0x02, struct ffa_part_info) > +#define FFA_SEND_RECEIVE_SYNC _IOWR(FFA_BASE, 0x03, struct ffa_send_recv_sync) > +#define FFA_SEND_RECEIVE_ASYNC _IOW(FFA_BASE, 0x04, struct ffa_send_recv_async) > + > +#endif /*_UAPI_LINUX_ARM_FFA_H*/ > -- > 2.17.1 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel