From patchwork Tue Dec 14 09:34:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12675727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 623A6C433FE for ; Tue, 14 Dec 2021 09:35:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.246488.425130 (Exim 4.92) (envelope-from ) id 1mx4Cr-0008VN-BL; Tue, 14 Dec 2021 09:34:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246488.425130; Tue, 14 Dec 2021 09:34:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mx4Cr-0008VC-6s; Tue, 14 Dec 2021 09:34:45 +0000 Received: by outflank-mailman (input) for mailman id 246488; Tue, 14 Dec 2021 09:34:43 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mx4Cp-0007DW-9a for xen-devel@lists.xenproject.org; Tue, 14 Dec 2021 09:34:43 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 100e8040-5cc1-11ec-9e60-abaf8a552007; Tue, 14 Dec 2021 10:34:41 +0100 (CET) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BE8mM0e003673; Tue, 14 Dec 2021 09:34:31 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2109.outbound.protection.outlook.com [104.47.18.109]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3cxr33874b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Dec 2021 09:34:31 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by PR2PR03MB5162.eurprd03.prod.outlook.com (2603:10a6:101:26::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.16; Tue, 14 Dec 2021 09:34:25 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::85d2:c8aa:2196:21c6]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::85d2:c8aa:2196:21c6%9]) with mapi id 15.20.4778.018; Tue, 14 Dec 2021 09:34:25 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 100e8040-5cc1-11ec-9e60-abaf8a552007 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UwMCwwQXqjdWHPoSIBNlXW/2kkQyifJHYa+QPpeSwcRB7t1lx1HlqFsJvsgv9vEakc7Pn2D1k6AMcs7G4T7tQBREewIztTHdaTCXm1yJIQa3xD5qs84q8Dy8hq1e7S27+LevN4pJeX0K7UeJz3bqSiq4fOiRn1UMqKO9RoaCd+gmTSLbf5kUCr2mLU7qzWGAaFOepjw3141inXlNv+BwSREZ7G3PdKv2b6cwMdqdf9dwa/VGMENLgUlcz0nANTlvrb8bRp6OyzL/gQo2cX69Bgt5g+GDnnn/oTaY4w7qBNCJ8C7/1bqcgiNY+MM756/Wf99Zami+PpXE1RGzJitFKw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5HKrYB6SvkH+0z8vtwa49lxvxU4I58QQAwDDiPC1Yg8=; b=exkoGv/nni6YNhrwNCGwJa/o3/hHlAJYN99pZwxec5yZFjuKnQUqi8g4ZL95U//u2DlPJLzL/ePdBw702dvNDGB72jUrE4ne6x3vNgZEyxaaedYPvNTRCHxP8PP1v+y3XNUWbCzBMNaHStRjvWwSlt7QkjlCcSgurnMlFts/D1kzAsTlRPrRIJYtD31Zs7xIaag7ppbZYXfhHGdkitzVfN/5AYM6wEc15ZOEtXJl+dYjD/YXfHS8sQO55BMFSBx3q6VirlO4D2QqB3L2KubVFRiOtKKfXfksd246xhSngqncjEcryKLCNyVuXcE0XecbeVxSZfRpn8W4qLIDhJv+hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5HKrYB6SvkH+0z8vtwa49lxvxU4I58QQAwDDiPC1Yg8=; b=Ty4slgKMwrGKaBsjf+B2udHjXAv2RU8B5k6EkwDLHamKtqSEODDL5b3bUoRWtVngybn/pmeNvTWxqnUOyZKJffFkbrMPEjAa2GHZ6NfdQBiCF9Nk6CN27lE2vyPOyyrneR4e2x0T51wpOxObEu3j/xP4eyUPTsIGBqCTzyFvCFchGnkIKoobPOOT0GqaxoZ0OzBHDBLcQYnhh4x+7KYtudMvMxtTe1ZuWRlgXbV9EWJixgPCAncOuI+GBPX0F5l2f5iIN19HBm0gG3KeKLD6vGqzMm5QcguNXL2hr4KEomNF74by+Gd6HLrdFIgiC7Nd0hLK1BrEF682VnRApcdFOA== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Volodymyr Babchuk , Bertrand Marquis Subject: [RFC v1 2/5] xen/arm: add generic SCI mediator framework Thread-Topic: [RFC v1 2/5] xen/arm: add generic SCI mediator framework Thread-Index: AQHX8M3IB9WR9OXgbE2xll7qsLGWCw== Date: Tue, 14 Dec 2021 09:34:24 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e8ab3c2b-0600-422c-935b-08d9bee4ead6 x-ms-traffictypediagnostic: PR2PR03MB5162:EE_ x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Lr+EizdDW3+1EkhjMTkYs51YyfAHaFeV8ARQ6c+fXlL+W5JJQhTblV2bw7AnzpfyUfx41UUIxf6GErurKQLo9Jzu/NPGbJgf6r2sbmkytup6yZgeAkJ0O7Q3Gc8XsrWMDsXmP+PBTjaR9FPeS+RHbCRv6B5BJUPgxVoVPYwyI4mQ5wYK1MIGQ72tdvuWbLU1WbdAMEOXKyNJ5zgHanrralo3rxTSlxEMREUdSibc47aQzYdXc9kqcfAmBYEsAY8gmsnXjvbz3f4nDltil/oWnaDu6njSn5Zsr6PwnuyoeUEuteAPDE8nn7kskUz4I+UOv39croeIbcyJdG1UUEHA4+Nl0A/lcXIxpWbnufaaPkpxSLhQ8Sf7q2YCqXLF6aVcUtMRZnU/zWXZeT9HsVcXdm4sKIkE0sPfYZl8fkInpD4+7wddZxu9n62vky5PTlSrkktflv/2KI9dv6fXWu5CQxBsriGqi66e2e6dldRVLFPXr0PclJLkJLVR1M/4xAV1NuwgReDmqa3O30nsyJ1lGy3qNJpYdEOVaDbwIWzOxQAbw9GF13mZWTGcVwX/OF52pyNjD8VMspnJU00gxR6MM5db3TuGUjHIo/7Jzr/fB/09btyxbBAugnSYKifrhxu5Xyf305BcYpd3y+UXmEin7SrcUnSUd6U5Q6Gece7+oIlqLEdk6hbYxZcphNQbZXWxjYzUwfuAU5vMNfqVO72SOgrstYvOW8sy+R8V8rv0CGZiCgmvoXbQzFLB5s/I9pTpLJI6/gsaWOqQC2xZYrE3Yw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(508600001)(30864003)(5660300002)(38070700005)(38100700002)(8676002)(4326008)(316002)(122000001)(2616005)(36756003)(54906003)(6512007)(186003)(26005)(66476007)(66556008)(83380400001)(64756008)(66446008)(2906002)(6486002)(71200400001)(76116006)(6506007)(86362001)(8936002)(91956017)(66946007)(6916009)(41533002)(21314003)(2004002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?PF+a1wDPNITxYzO+CVWLhv6?= =?iso-8859-1?q?cupeYFD4x4az5b/Fw7baZ2ZiWdNurw3J+EdlrAyyuJXWs6Y3VcNxhNaqa70W?= =?iso-8859-1?q?J3sEUT60ejR8ifTplaf7Wjfz6AhnTQ/xkcCdt1NsnS1SG7EFASg6sPI5rnxU?= =?iso-8859-1?q?v/F8P2KoD4+QaosXvxiuias0h47hXraek90V8P/g8xk9xb6nJyIU7JfB9sTd?= =?iso-8859-1?q?6FXMDv0sH0Xb/DfNzqV1ctI6VKl4U+9yo94sfG2Z7CzjldJn8EdUxQbqv4tw?= =?iso-8859-1?q?+dfztT298LTsGsFoGjnqLvMk2T6okTp0Jj/VsE1VayD/jQNr7MJ+NIJ1stPO?= =?iso-8859-1?q?IPUf4qedLwSX0JWJdxlbzwiTtlxBlM0CFinxlqx91ZLoNlwNXg3l2GmYcOcj?= =?iso-8859-1?q?Y/kdxTKeRdEy8f6vqSwQWjTUYVVTyr8KDa6rWggn5PmL2r5mCRmPzIwfGLpP?= =?iso-8859-1?q?M7oPCmfLfe/0H2icE/rz2UJUkuX9SIZ98jnVf90yZc6WO8CV9BSK0ZXhk+i4?= =?iso-8859-1?q?zLfl7HG8sUALPQLNgRqStrvVwTTjxEjoZO3m8aj55jZ4/5wxz5rG+OqT6C0w?= =?iso-8859-1?q?DBDPQI0CEZLKCHwt6Prl+Px8JYf3aAyBqp11HnYaCT+O7LrzxJOS6KQyo+kU?= =?iso-8859-1?q?L3sRHwRr910oN5Fdkj0ibmB0LYPPUVitQIE8/1g2x4pwY7RcijVa16qPCkQe?= =?iso-8859-1?q?iXEuf8vkZaCOoH9+MrjEr2Vieo3FEuTRxmPBSOvOyRgZNTPKYNaxeAD4s+pe?= =?iso-8859-1?q?kQLd3uqOMvvL9+ztoAxveJRjp5fugJ8lMa1Wtz90ZHFVFCn/b06si7t7tQa4?= =?iso-8859-1?q?R36bienUS3/gt9UK5AkVjKzg/hQHKP6fDnpHLVYzrW4/p/6cdWxukSOxNXLp?= =?iso-8859-1?q?dTMsh17LIUh1Sa9LxYFf3rdIVuWKsaPaqYXCtlF9104StSkn4airCPuBo4vt?= =?iso-8859-1?q?2YdCIvR/vuJn8uCx0xSMmSoMhld8bzqzXva9iaIxfpL30WmjhxEn9AmhgLTI?= =?iso-8859-1?q?XxRbSK1X3s0ga8GUEIibzDwxfQiFvwxGkuSRHNtHnKD4NQjKmPWmFjYK8/IR?= =?iso-8859-1?q?zjoyifMIFtQ50GGHpxZkXBcrhJsv/DpgAdLN/pmYswnDH1QDsnsnTu0H8QmY?= =?iso-8859-1?q?M4mUm0r0z6xFzV/k1RLng6mEtQphDKM0mNyucYXVEjgkiur3Yr7IrPoxo1W3?= =?iso-8859-1?q?85XTfEFRCFHP5VrqfEuBNh+PZW8kTCCVPl3IjAkKP7WCubYIR4V6h7WuI0DZ?= =?iso-8859-1?q?C3WKTsDSqxw/Je6E/zeHLqlRIMypQe+35X6xykRKADwHvlS0YHV8/ZU9X3UO?= =?iso-8859-1?q?mpN1+zrbYp/z0t9ev47KJWtScb6ZNmFQxLRYjJqmJ3pnwDNi2YRoSncDe0rK?= =?iso-8859-1?q?2Qzw7GwW0jW+IXS1pIOSMjgvWTZEEcEft1V+q/mVizDo7XjTeELwTjkKM9Ws?= =?iso-8859-1?q?7RZem6j6lglK7btpg14EHPe5NqDrY5xKh0y+zVCRsI20MaZy2cfaAU5kU+Vw?= =?iso-8859-1?q?HOAgwEA7NV1+KLIXp2wx7XkD0a46F7YN6+tE2OX4JMNgSYvG7F5YvQlZh7Q5?= =?iso-8859-1?q?Wq9EfVkTwjYq1dTZG7DRNAKLsMQ2InWLRLjX3svkLmV9qiyG6bQtBtOBZsHj?= =?iso-8859-1?q?ppKiutPcunHtgmJXEQLChTuzlHGNan7/1/edF+tCOwQu2g7bfa68DLc53hz9?= =?iso-8859-1?q?7m2l7J0hJ1vCa+Hy/ZlTHa+wCRIpaZE2/v2bbBniG38K3872OWZzugmMthC7?= =?iso-8859-1?q?nJpY=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8ab3c2b-0600-422c-935b-08d9bee4ead6 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Dec 2021 09:34:25.0294 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: RfqdyPuxzpK6fVl6BWZCRh4B0qxyja2icLr2P17aFoi0M0sb2PDsGY4FW6M9rRx0f1R2uC9DFJUED9BG5sQ7NsCJzR2J7eSLsAKmmjESwPA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR03MB5162 X-Proofpoint-ORIG-GUID: wlhcHQlPM2w9Xz2Hror1NT-CP53P_nvL X-Proofpoint-GUID: wlhcHQlPM2w9Xz2Hror1NT-CP53P_nvL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2021-12-14_05,2021-12-13_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 mlxscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112140054 This patch adds the basic framework for SCI mediator. SCI is System Control Interface, which is designed to redirect requests for the Hardware (such as power-domain/clock/resets etc) from the Domains to the firmware. Originally, cpg should be passed to the domain so it can work with power-domains/clocks/resets etc. Considering that cpg can't be split between the Domains, we get the limitation that the devices, which are using power-domains/clocks/resets etc, couldn't be split between the domains. The solution is to move the power-domain/clock/resets etc to the Firmware (such as SCP firmware or ATF) and provide interface for the Domains. XEN shoud have an entity, caled SCI-Mediator, which is responsible for messages redirection between Domains and Firmware and for permission handling. This is how it works: user can build XEN with multiple SCI mediators. See the next patches, where SCMI-SMC mediator is introduced. SCI mediator register itself with REGISTER_SCI_MEDIATOR() macro. At run-time, during initialization, framework calls probe for the first matching device in the device-tree. When no device-tree is present - the first registered mediator should be probed. Signed-off-by: Oleksii Moisieiev --- MAINTAINERS | 6 ++ xen/arch/arm/Kconfig | 8 ++ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 24 +++++ xen/arch/arm/domain_build.c | 11 +++ xen/arch/arm/platforms/rcar3.c | 3 +- xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/sci.c | 128 ++++++++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/sci/sci.h | 162 +++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 10 ++ 13 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/sci/Makefile create mode 100644 xen/arch/arm/sci/sci.c create mode 100644 xen/include/asm-arm/sci/sci.h diff --git a/MAINTAINERS b/MAINTAINERS index e43dc0edce..5f96ea35ba 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -512,6 +512,12 @@ S: Supported F: xen/arch/arm/tee/ F: xen/include/asm-arm/tee +SCI MEDIATORS +M: Oleksii Moisieiev +S: Supported +F: xen/arch/arm/sci +F: xen/include/asm-arm/sci + TOOLSTACK M: Wei Liu S: Supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ecfa6822e4..186e1db389 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -106,6 +106,14 @@ config TEE source "arch/arm/tee/Kconfig" +config SCI + bool "Enable SCI mediators support" + default n + help + This option enables generic SCI (System Control Interface) mediators + support. It allows guests to control system resourcess via one of + SCI mediators implemented in XEN. + endmenu menu "ARM errata workaround via the alternative framework" diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 07f634508e..6366ff55e5 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -8,6 +8,7 @@ obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o +obj-$(CONFIG_SCI) += sci/ obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.o diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 96e1b23550..80d0a23767 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -688,6 +689,13 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) return -EINVAL; } + if ( config->arch.sci_type != XEN_DOMCTL_CONFIG_SCI_NONE && + config->arch.sci_type != sci_get_type() ) + { + dprintk(XENLOG_INFO, "Unsupported SCI type\n"); + return -EINVAL; + } + return 0; } @@ -764,6 +772,15 @@ int arch_domain_create(struct domain *d, /* At this stage vgic_reserve_virq should never fail */ if ( !vgic_reserve_virq(d, GUEST_EVTCHN_PPI) ) BUG(); + + if ( config->arch.sci_type != XEN_DOMCTL_CONFIG_SCI_NONE ) + { + if ( (rc = sci_domain_init(d, config->arch.sci_type)) != 0) + goto fail; + + if ( (rc = sci_get_channel_info(d, &config->arch)) != 0) + goto fail; + } } /* @@ -796,6 +813,7 @@ void arch_domain_destroy(struct domain *d) domain_vgic_free(d); domain_vuart_free(d); free_xenheap_page(d->shared_info); + sci_domain_destroy(d); #ifdef CONFIG_ACPI free_xenheap_pages(d->arch.efi_acpi_table, get_order_from_bytes(d->arch.efi_acpi_len)); @@ -996,6 +1014,7 @@ enum { PROG_xen, PROG_page, PROG_mapping, + PROG_sci, PROG_done, }; @@ -1056,6 +1075,11 @@ int domain_relinquish_resources(struct domain *d) if ( ret ) return ret; + PROGRESS(sci): + ret = sci_relinquish_resources(d); + if ( ret ) + return ret; + PROGRESS(done): break; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d02bacbcd1..38874615dd 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1894,6 +1895,10 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, return res; } } + + res = sci_add_dt_device(d, dev); + if ( res < 0 ) + return res; } res = handle_device_interrupts(d, dev, need_mapping); @@ -3075,6 +3080,10 @@ static int __init construct_dom0(struct domain *d) if ( rc < 0 ) return rc; + rc = sci_domain_init(d, sci_get_type()); + if ( rc < 0 ) + return rc; + if ( acpi_disabled ) rc = prepare_dtb_hwdom(d, &kinfo); else @@ -3109,6 +3118,8 @@ void __init create_dom0(void) dom0_cfg.arch.tee_type = tee_get_type(); dom0_cfg.max_vcpus = dom0_max_vcpus(); + dom0_cfg.arch.sci_type = sci_get_type(); + if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; diff --git a/xen/arch/arm/platforms/rcar3.c b/xen/arch/arm/platforms/rcar3.c index d740145c71..a268b09454 100644 --- a/xen/arch/arm/platforms/rcar3.c +++ b/xen/arch/arm/platforms/rcar3.c @@ -18,10 +18,11 @@ */ #include +#include static bool rcar3_smc(struct cpu_user_regs *regs) { - return false; + return sci_handle_call(current->domain, regs); } static const char *const rcar3_dt_compat[] __initconst = diff --git a/xen/arch/arm/sci/Makefile b/xen/arch/arm/sci/Makefile new file mode 100644 index 0000000000..837dc7492b --- /dev/null +++ b/xen/arch/arm/sci/Makefile @@ -0,0 +1 @@ +obj-y += sci.o diff --git a/xen/arch/arm/sci/sci.c b/xen/arch/arm/sci/sci.c new file mode 100644 index 0000000000..5961b4cd5d --- /dev/null +++ b/xen/arch/arm/sci/sci.c @@ -0,0 +1,128 @@ +/* + * xen/arch/arm/sci/sci.c + * + * Generic part of SCI mediator driver + * + * Oleksii Moisieiev + * Copyright (C) 2021, EPAM Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include + +#include + +extern const struct sci_mediator_desc _sscimediator[], _escimediator[]; +static const struct sci_mediator_desc __read_mostly *cur_mediator; + +bool sci_handle_call(struct domain *d, void *args) +{ + if ( unlikely(!cur_mediator) ) + return false; + + return cur_mediator->ops->handle_call(d, args); +} + +int sci_domain_init(struct domain *d, uint16_t sci_type) +{ + if ( sci_type == XEN_DOMCTL_CONFIG_SCI_NONE ) + return 0; + + if ( unlikely(!cur_mediator) ) + return -ENODEV; + + if ( cur_mediator->sci_type != sci_type ) + return -EINVAL; + + return cur_mediator->ops->domain_init(d); +} + +void sci_domain_destroy(struct domain *d) +{ + if ( unlikely(!cur_mediator) ) + return; + + cur_mediator->ops->domain_destroy(d); +} + +int sci_relinquish_resources(struct domain *d) +{ + if ( unlikely(!cur_mediator) ) + return 0; + + return cur_mediator->ops->relinquish_resources(d); +} + + +int sci_add_dt_device(struct domain *d, struct dt_device_node *dev) +{ + if ( unlikely(!cur_mediator) ) + return 0; + + return cur_mediator->ops->add_dt_device(d, dev); +} + +int sci_get_channel_info(struct domain *d, + struct xen_arch_domainconfig *config) +{ + if ( unlikely(!cur_mediator) ) + return 0; + + return cur_mediator->ops->get_channel_info(d->arch.sci, config); +} + +uint16_t sci_get_type(void) +{ + if ( unlikely(!cur_mediator) ) + return XEN_DOMCTL_CONFIG_SCI_NONE; + + return cur_mediator->sci_type; +} + +static int __init sci_init(void) +{ + const struct sci_mediator_desc *desc; + struct dt_device_node *dt = NULL; + + for ( desc = _sscimediator; desc != _escimediator; desc++ ) + { + if ( likely(dt_host) ) + { + dt = dt_find_matching_node(dt_host, desc->dt_match); + if ( !dt ) + continue; + } + + if ( desc->ops->probe(dt) ) + { + printk(XENLOG_INFO "Using SCI mediator for %s\n", desc->name); + cur_mediator = desc; + return 0; + } + } + + return 0; +} + +__initcall(sci_init); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d5d0792ed4..201de01411 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 08016948ab..3683f4821f 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -142,6 +142,13 @@ SECTIONS _eteemediator = .; } :text + . = ALIGN(8); + .scimediator.info : { + _sscimediator = .; + *(.scimediator.info) + _escimediator = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : { diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 9b3647587a..d9b164017f 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -89,6 +89,10 @@ struct arch_domain #ifdef CONFIG_TEE void *tee; #endif + +#ifdef CONFIG_SCI + void *sci; +#endif } __cacheline_aligned; struct arch_vcpu diff --git a/xen/include/asm-arm/sci/sci.h b/xen/include/asm-arm/sci/sci.h new file mode 100644 index 0000000000..aeff689c72 --- /dev/null +++ b/xen/include/asm-arm/sci/sci.h @@ -0,0 +1,162 @@ +/* + * xen/include/asm-arm/sci/sci.h + * + * Generic part of the SCI (System Control Interface) subsystem. + * + * Oleksii Moisieiev + * Copyright (C) 2021, EPAM Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __ASM_ARM_SCI_H +#define __ASM_ARM_SCI_H + +#include +#include +#include + +#ifdef CONFIG_SCI + +struct sci_mediator_ops { + + /* + * Probe for SCI. Should return true if SCI found and + * mediator is initialized. + */ + bool (*probe)(struct dt_device_node *scmi_node); + + /* + * Called during domain construction if toolstack requests to enable + * SCI support so mediator can inform SCP-firmware about new + * guest and create own structures for the new domain. + */ + int (*domain_init)(struct domain *d); + + /* + * Called during domain destruction, releases all resources, that + * were allocated by the mediator. + */ + void (*domain_destroy)(struct domain *d); + + /* + * Called during parsing partial device-sci for the domain. + * Passing device_node so mediator could process the device and + * mark the device as related to the domain if needed. + */ + int (*add_dt_device)(struct domain *d, struct dt_device_node *dev); + + /* + * Called during domain destruction to relinquish resources used + * by mediator itself. This function can return -ERESTART to indicate + * that it does not finished work and should be called again. + */ + int (*relinquish_resources)(struct domain *d); + + /* Handle call for current domain */ + bool (*handle_call)(struct domain *d, void *regs); + + /* Gets channel configuration and store it in domainconfig */ + int (*get_channel_info)(void *sci_ops, + struct xen_arch_domainconfig *config); + +}; + +struct sci_mediator_desc { + /* Printable name of the SCI. */ + const char *name; + + /* Mediator callbacks as described above. */ + const struct sci_mediator_ops *ops; + + /* + * ID of SCI. Corresponds to xen_arch_domainconfig.sci_type. + * Should be one of XEN_DOMCTL_CONFIG_SCI_xxx + */ + uint16_t sci_type; + + /* Match structure to init mediator */ + const struct dt_device_match *dt_match; + +}; + +int sci_domain_init(struct domain *d, uint16_t sci_type); +void sci_domain_destroy(struct domain *d); +int sci_add_dt_device(struct domain *d, struct dt_device_node *dev); +int sci_relinquish_resources(struct domain *d); +bool sci_handle_call(struct domain *d, void *args); +int sci_get_channel_info(struct domain *d, + struct xen_arch_domainconfig *config); +uint16_t sci_get_type(void); + +#define REGISTER_SCI_MEDIATOR(_name, _namestr, _type, _match, _ops) \ +static const struct sci_mediator_desc __sci_desc_##_name __used \ +__section(".scimediator.info") = { \ + .name = _namestr, \ + .ops = _ops, \ + .sci_type = _type, \ + .dt_match = _match \ +} + +#else +#include + +static inline int sci_domain_init(struct domain *d, uint16_t sci_type) +{ + if ( likely(sci_type == XEN_DOMCTL_CONFIG_SCI_NONE) ) + return 0; + + return -XEN_ENODEV; +} + +static inline void sci_domain_destroy(struct domain *d) +{ +} + +static inline int sci_add_dt_device(struct domain *d, + struct dt_device_node *dev) +{ + return 0; +} + +static inline int sci_relinquish_resources(struct domain *d) +{ + return 0; +} + +static inline bool sci_handle_call(struct domain *d, void *args) +{ + return false; +} + +static inline int sci_get_channel_info(struct domain *d, + struct xen_arch_domainconfig *config) +{ + return 0; +} + +static inline uint16_t sci_get_type(void) +{ + return XEN_DOMCTL_CONFIG_SCI_NONE; +} + +#endif /* CONFIG_SCI */ + +#endif /* __ASM_ARM_SCI_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 94b31511dd..9180be5e86 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -314,12 +314,16 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); #define XEN_DOMCTL_CONFIG_TEE_NONE 0 #define XEN_DOMCTL_CONFIG_TEE_OPTEE 1 +#define XEN_DOMCTL_CONFIG_SCI_NONE 0 + struct xen_arch_domainconfig { /* IN/OUT */ uint8_t gic_version; /* IN */ uint16_t tee_type; /* IN */ + uint8_t sci_type; + /* IN */ uint32_t nr_spis; /* * OUT @@ -335,6 +339,12 @@ struct xen_arch_domainconfig { * */ uint32_t clock_frequency; + + /* Sets shared address to sw domains. + * This information is needed to set correct channel in Domain partial + * device-tree + */ + uint64_t sci_agent_paddr; }; #endif /* __XEN__ || __XEN_TOOLS__ */