From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0142e2c9bd=gilbert.chen@hpe.com) Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by groups.io with SMTP; Mon, 26 Aug 2019 23:26:38 -0700 Received: from pps.filterd (m0134423.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x7R6QaMB030102 for ; Tue, 27 Aug 2019 06:26:37 GMT Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com with ESMTP id 2umuvb9am1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 27 Aug 2019 06:26:37 +0000 Received: from G9W8456.americas.hpqcorp.net (g9w8456.houston.hp.com [16.216.161.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2354.austin.hpe.com (Postfix) with ESMTPS id BF3B1D6 for ; Tue, 27 Aug 2019 06:26:16 +0000 (UTC) Received: from G9W8455.americas.hpqcorp.net (2002:10d8:a15e::10d8:a15e) by G9W8456.americas.hpqcorp.net (2002:10d8:a15f::10d8:a15f) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 27 Aug 2019 06:26:16 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (15.241.52.10) by G9W8455.americas.hpqcorp.net (16.216.161.94) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Tue, 27 Aug 2019 06:26:16 +0000 Received: from TU4PR8401MB1056.NAMPRD84.PROD.OUTLOOK.COM (10.169.47.148) by TU4PR8401MB0624.NAMPRD84.PROD.OUTLOOK.COM (10.169.44.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Tue, 27 Aug 2019 06:26:15 +0000 Received: from TU4PR8401MB1056.NAMPRD84.PROD.OUTLOOK.COM ([fe80::cc02:a574:b9e3:cf1e]) by TU4PR8401MB1056.NAMPRD84.PROD.OUTLOOK.COM ([fe80::cc02:a574:b9e3:cf1e%8]) with mapi id 15.20.2199.021; Tue, 27 Aug 2019 06:26:15 +0000 From: "Chen, Gilbert" To: "devel@edk2.groups.io" CC: "Chen, Gilbert" Subject: [PATCH 10/15] [platforms/devel-riscv]: U500Pkg/Library: Library instances of U500 platform library. Thread-Topic: [PATCH 10/15] [platforms/devel-riscv]: U500Pkg/Library: Library instances of U500 platform library. Thread-Index: AdVcoFJOLGPruGQuSrGbNShtwsER0A== Date: Tue, 27 Aug 2019 06:26:14 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [16.242.247.133] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 72b9e36c-b5e9-4b34-d2b0-08d72ab7767d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:TU4PR8401MB0624; x-ms-traffictypediagnostic: TU4PR8401MB0624: x-ms-exchange-purlcount: 2 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0142F22657 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(136003)(376002)(396003)(346002)(174874002)(199004)(189003)(86362001)(316002)(6436002)(2351001)(2501003)(7736002)(6306002)(478600001)(55016002)(102836004)(3846002)(9686003)(6116002)(476003)(53936002)(26005)(256004)(76116006)(486006)(14444005)(2906002)(66946007)(64756008)(5640700003)(66476007)(5660300002)(66446008)(66556008)(186003)(71200400001)(71190400001)(966005)(16799955002)(8936002)(66066001)(14454004)(6916009)(19627235002)(53376002)(52536014)(74316002)(8676002)(1730700003)(81166006)(81156014)(25786009)(6506007)(305945005)(15188155005)(99286004)(33656002)(4326008)(7696005);DIR:OUT;SFP:1102;SCL:1;SRVR:TU4PR8401MB0624;H:TU4PR8401MB1056.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: UnHe2bht/7d5ytp/kNW8MtpdQVmES6e6yd7EYg8oqd1XUx78watasmuEWXL09wlb0fufCM/mWdjhMwRvZHoXTQVW6DNaNSNHHm8416TLhI/HBNp1mbNUwZcjd39nG6vLTQoSSgBwd+3BmSzOVDzs3NRz6RgFKAIWUJTJMcmXAYBcMtmtoZGBtKwJtH5UDllZaExgHC020zWE3RF2vgJgSr8CNuFMhpX8lB/R0wUMQ+SuipsbNaBLeK3KRZLEDCBQd5j5m0WyAt9MkRTu9kz7gM7bpDXGI2XBv+AsveP6kcjc07CXcy2RUJNbRDFgPah/KJ4zHqBldWU4QMma+pUsToB5TkfhqgijOnw62AZeS67AV9D3SzTrjaVHByMZj5TVp9t3b5ilR04zDTVaDejsdP3AQXhNha/5sMU2+tKWnGE= arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H0KdfqGkCW+NpC2LWalqi8oYGxMzN19ZC+P5kqaVABUYCzMe48O5WslByt6czKmPJFpC51Qti45/n0EF7EwU66y4mecbIAJZ9F4eztm7FBND5Z5YSaORnX0HAzVklpvJScc+aF9JWfj6PtWJvRsUutjWrHZG4ELyeIgKC+ZS4L3lG/3DgJYFd8HytbJ7xPF0SxdqwTaV+dMmeGcHklXXFMxhC5GvVvZZfnGWE+G2H7DpT7H+VZqmZKyKB9/3aqr8CRscPELOPHjoT+VkdhTac4iY4oLcWBljRil7o1n99yomtwjPdwclpFSmfxUA2j1tKFB/EgXw6M7BpIUHA6yTJA== 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=Rsa7nkSe9Y9wkohkWyUfY4qwHGrPjRfk2oOA8XxdQ+I=; b=EA3gUQbrJmM4EuhQNIYAg1GVE/WauxGluqA1haNPGRnvRHBaEzZeXE7W2hA1sjqFNSH/pVCr6FZjVv62ZIlo0w1l+pymcDxc5VvmVrOeSQ4oo42lalb0iIZynqPrWtGC8IUr2QUREJs4aEx557jjRl1CjMmU/ElCxuwzhNdpi0iKdj0lLBgO/V0wbSbr6qgSDiSeqa70zDNtDNOl7hY0me9I4cjauS/b8+eOJui2pqg0jDBu4dCLa9FpqehaOYqD7bC3DCAjYow64uqNV1NboPPoqDV4IuU6JkEtzvdrHLn2JDWT/qAmOc+w9L/jOhz+/J5R/zbNTsljW4prBR+Tug== arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none x-ms-exchange-crosstenant-network-message-id: 72b9e36c-b5e9-4b34-d2b0-08d72ab7767d x-ms-exchange-crosstenant-originalarrivaltime: 27 Aug 2019 06:26:14.9994 (UTC) x-ms-exchange-crosstenant-fromentityheader: Hosted x-ms-exchange-crosstenant-id: 105b2061-b669-4b31-92ac-24d304d195dc x-ms-exchange-crosstenant-mailboxtype: HOSTED x-ms-exchange-crosstenant-userprincipalname: JuSe4td4TykK8wjAfOaMoufNnjqpKYU3RUpv8dnbRF3kvccOY5820Nemqn42J0FGzGhrU6FdP7m4QepSiUu2IQ== x-ms-exchange-transport-crosstenantheadersstamped: TU4PR8401MB0624 x-originatororg: hpe.com X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-08-26_08:2019-08-26,2019-08-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 adultscore=0 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1908270071 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable OpneSbiPlatformLib - In order to reduce the dependencies with RISC-V OpenSBI project (https://= github.com/riscv/opensbi) and less burdens to EDK2 build process, the imple= mentation of RISC-V EDK2 platform is leverage platform source code from Ope= nSBI code tree. The "platform.c" under OpenSbiPlatformLib is cloned from RI= SC-V OpenSBI code tree (in EDK2 RiscVPkg) and built based on EDK2 build env= ironment. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Gilbert Chen --- .../OpenSbiPlatformLib/OpenSbiPlatformLib.inf | 53 +++++ .../U500Pkg/Library/OpenSbiPlatformLib/platform.c | 214 +++++++++++++++++= ++++ 2 files changed, 267 insertions(+) create mode 100644 Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLi= b/OpenSbiPlatformLib.inf create mode 100644 Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLi= b/platform.c diff --git a/Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLib/OpenS= biPlatformLib.inf b/Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLi= b/OpenSbiPlatformLib.inf new file mode 100644 index 0000000..1823e48 --- /dev/null +++ b/Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLib/OpenSbiPlatf= ormLib.inf @@ -0,0 +1,53 @@ +## @file +# RISC-V OpenSbi Platform Library +# This is the the required library which provides platform +# level opensbi functions follow RISC-V opensbi implementation. +# +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may b= e found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D OpenSbiPlatformLib + FILE_GUID =3D 9424ED54-EBDA-4FB5-8FF6-8291B07BB151 + MODULE_TYPE =3D SEC + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D OpenSbiPlatformLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D RISCV64 EBC +# + +[Sources] + platform.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RiscVPkg/RiscVPkg.dec + Platform/RiscV/RiscVPlatformPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + BaseMemoryLib + PcdLib + DebugAgentLib + RiscVCpuLib + PrintLib + +[FixedPcd] + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdHartCount + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdOpenSbiStackSize + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootHartId diff --git a/Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLib/platf= orm.c b/Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLib/platform.c new file mode 100644 index 0000000..887a279 --- /dev/null +++ b/Platform/RiscV/SiFive/U500Pkg/Library/OpenSbiPlatformLib/platform.c @@ -0,0 +1,214 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+ * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define U500_HART_COUNTFixedPcdGet32(PcdHartCount) +#define U500_HART_STACK_SIZEFixedPcdGet32(PcdOpenSbiStackSize) +#define U500_BOOT_HART_ID FixedPcdGet32(PcdBootHartId) + +#define U500_SYS_CLK100000000 + +#define U500_CLINT_ADDR0x2000000 + +#define U500_PLIC_ADDR0xc000000 +#define U500_PLIC_NUM_SOURCES0x35 +#define U500_PLIC_NUM_PRIORITIES7 + +#define U500_UART_ADDR0x54000000 + +#define U500_UART_BAUDRATE115200 + +/** + * The U500 SoC has 8 HARTs but HART ID 0 doesn't have S mode. + * HARTs 1 is selected as boot HART + */ +#ifndef U500_ENABLED_HART_MASK +#define U500_ENABLED_HART_MASK(1 << U500_BOOT_HART_ID) +#endif + +#define U500_HARTID_DISABLED~(U500_ENABLED_HART_MASK) + +/* PRCI clock related macros */ +//TODO: Do we need a separate driver for this ? +#define U500_PRCI_BASE_ADDR0x10000000 +#define U500_PRCI_CLKMUXSTATUSREG0x002C +#define U500_PRCI_CLKMUX_STATUS_TLCLKSEL(0x1 << 1) + +static void U500_modify_dt(void *fdt) +{ +u32 i, size; +int chosen_offset, err; +int cpu_offset; +char cpu_node[32] =3D ""; +const char *mmu_type; + +for (i =3D 0; i < U500_HART_COUNT; i++) { +sbi_sprintf(cpu_node, "/cpus/cpu@%d", i); +cpu_offset =3D fdt_path_offset(fdt, cpu_node); +mmu_type =3D fdt_getprop(fdt, cpu_offset, "mmu-type", NULL); +if (mmu_type && (!strcmp(mmu_type, "riscv,sv39") || + !strcmp(mmu_type,"riscv,sv48"))) +continue; +else +fdt_setprop_string(fdt, cpu_offset, "status", "masked"); +memset(cpu_node, 0, sizeof(cpu_node)); +} +size =3D fdt_totalsize(fdt); +err =3D fdt_open_into(fdt, fdt, size + 256); +if (err < 0) +sbi_printf("Device Tree can't be expanded to accmodate new node"); + +chosen_offset =3D fdt_path_offset(fdt, "/chosen"); +fdt_setprop_string(fdt, chosen_offset, "stdout-path", + "/soc/serial@10010000:115200"); + +plic_fdt_fixup(fdt, "riscv,plic0"); +} + +static int U500_final_init(bool cold_boot) +{ +void *fdt; + +if (!cold_boot) +return 0; + +fdt =3D sbi_scratch_thishart_arg1_ptr(); +U500_modify_dt(fdt); + +return 0; +} + +static u32 U500_pmp_region_count(u32 hartid) +{ +return 1; +} + +static int U500_pmp_region_info(u32 hartid, u32 index, + ulong *prot, ulong *addr, ulong *log2size) +{ +int ret =3D 0; + +switch (index) { +case 0: +*prot =3D PMP_R | PMP_W | PMP_X; +*addr =3D 0; +*log2size =3D __riscv_xlen; +break; +default: +ret =3D -1; +break; +}; + +return ret; +} + +static int U500_console_init(void) +{ +unsigned long peri_in_freq; + +peri_in_freq =3D U500_SYS_CLK/2; +return sifive_uart_init(U500_UART_ADDR, peri_in_freq, U500_UART_BAUDRATE); +} + +static int U500_irqchip_init(bool cold_boot) +{ +int rc; +u32 hartid =3D sbi_current_hartid(); + +if (cold_boot) { +rc =3D plic_cold_irqchip_init(U500_PLIC_ADDR, + U500_PLIC_NUM_SOURCES, + U500_HART_COUNT); +if (rc) +return rc; +} + +return plic_warm_irqchip_init(hartid, +(hartid) ? (2 * hartid - 1) : 0, +(hartid) ? (2 * hartid) : -1); +} + +static int U500_ipi_init(bool cold_boot) +{ +int rc; + +if (cold_boot) { +rc =3D clint_cold_ipi_init(U500_CLINT_ADDR, + U500_HART_COUNT); +if (rc) +return rc; + +} + +return clint_warm_ipi_init(); +} + +static int U500_timer_init(bool cold_boot) +{ +int rc; + +if (cold_boot) { +rc =3D clint_cold_timer_init(U500_CLINT_ADDR, + U500_HART_COUNT); +if (rc) +return rc; +} + +return clint_warm_timer_init(); +} + +static int U500_system_down(u32 type) +{ +/* For now nothing to do. */ +return 0; +} + +const struct sbi_platform_operations platform_ops =3D { +.pmp_region_count =3D U500_pmp_region_count, +.pmp_region_info =3D U500_pmp_region_info, +.final_init =3D U500_final_init, +.console_putc =3D sifive_uart_putc, +.console_getc =3D sifive_uart_getc, +.console_init =3D U500_console_init, +.irqchip_init =3D U500_irqchip_init, +.ipi_send =3D clint_ipi_send, +.ipi_sync =3D clint_ipi_sync, +.ipi_clear =3D clint_ipi_clear, +.ipi_init =3D U500_ipi_init, +.timer_value =3D clint_timer_value, +.timer_event_stop =3D clint_timer_event_stop, +.timer_event_start =3D clint_timer_event_start, +.timer_init =3D U500_timer_init, +.system_reboot =3D U500_system_down, +.system_shutdown =3D U500_system_down +}; + +const struct sbi_platform platform =3D { +.opensbi_version=3D OPENSBI_VERSION,// The OpenSBI version this platform t= able is built bassed on. +.platform_version=3D SBI_PLATFORM_VERSION(0x0001, 0x0000),// SBI Platform = version 1.0 +.name=3D "SiFive Freedom U500", +.features=3D SBI_PLATFORM_DEFAULT_FEATURES, +.hart_count=3D U500_HART_COUNT, +.hart_stack_size=3D U500_HART_STACK_SIZE, +.disabled_hart_mask=3D U500_HARTID_DISABLED, +.platform_ops_addr=3D (unsigned long)&platform_ops +}; -- 2.7.4