Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9066925rwd; Wed, 21 Jun 2023 02:32:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hOMI1fq4EVQzCon/Ksp6Nz5wHmhmJq+C3WLxYDsTXZYk5R57SEwnA86rPiDwsCYQRP8i2 X-Received: by 2002:a05:6358:f49:b0:131:94f:b4ff with SMTP id c9-20020a0563580f4900b00131094fb4ffmr1837426rwj.5.1687339924613; Wed, 21 Jun 2023 02:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687339924; cv=none; d=google.com; s=arc-20160816; b=dhilzi32fDmelD9mWWp12bKOt26Lnns+kGdqTuSzQIXJAENB14YCMkFSlh6QfYZMUh GjVRt0L5m0QHhFYhSyK6P7UgIYZtOerbOucCu+6UbynBsV7/ilGd5O+hGu4XIdatlNed 2XQRXBgdFfGQpo0+HPr3cmYv/vWRLyPynKhinzCPhdoDT2e3Yg2dLIkElTtGlFe506bi evbbFPBJBv/mBxt3Qf0nemYr9a3EjENFDkZyvWhdR5lVHFsBrQkWK2b4gKEhvDt4J8/l d6QW4k+z5mhzI9lOd4G4+LizSKQsbvwywrZP6AOybmyQwxfPztIEeDvW7AAvRyNO/KtC OueA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pB2kKOyXmNJk2e2QsKOkbUZlQ9krtQWymG1tqTKND7M=; b=hObJvukCVQcxirW64RnLMkEPeNAx369+dU4vECMHzN6wydTNVGhhKZp5MswD/OZLVD ckTdoZg2aaaMvLgwnFr7jwpwXQJ7hfPm5/AS2d+AeoHSLQ/UpAQPtuZ8KSGg3XiNEEby uOMOEdnNBAiDWaNcM/qDNZaRNWRiqL81Edqe6dLk9HJXvdkTv29YMOKGNZntbgGL9zS2 SIAkHLhHjqSe2ZTa9hxtB+Plgvi3Wzie6DQAfeWeAP0G37Aqcqeo7Jj2gxTfOZOUejFt Dc1/F0k7cIWAsw9ohNGYCcSenSd/hvdg0QzdFzJifun6hskw+UaGd7uEbZnrZWbk8zi2 nddw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JEl+WD8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a056a00000700b0066872c159cbsi370421pfk.122.2023.06.21.02.31.50; Wed, 21 Jun 2023 02:32:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JEl+WD8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbjFUJSs (ORCPT + 99 others); Wed, 21 Jun 2023 05:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjFUJSo (ORCPT ); Wed, 21 Jun 2023 05:18:44 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7936E68 for ; Wed, 21 Jun 2023 02:18:43 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b51488ad67so29317735ad.3 for ; Wed, 21 Jun 2023 02:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1687339123; x=1689931123; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=pB2kKOyXmNJk2e2QsKOkbUZlQ9krtQWymG1tqTKND7M=; b=JEl+WD8TxC8kp5VqXUE8dKNh2/i7vnWvgiUcocUBtcvkMYbkJ/3i/v1xwcQI/dnAYD OocJ0aboXF1NcZDeOK+0y/eEiy2dSnUKH8qOOzAKez+JCw7tFekIKtwqCFhRfiNAKlLt q5+gV8VlyclcWMQHTWua5wpsF/9nEXJZj/nZagINJw6yXeij1vuicd7+vVmeUoHRt4If bnBpQ8XUnXOkoLSp2bYEahv6V/k4PyCu7yOSZCqc7nu5EzRWafvELH50E9xAkYQwv7Jn SJe9vOVGMBBXv8+yJMdaxMtks4idFDRhUSiJN05C/KeQ6BdmEBhTcbqL7PropsMzaMpq pqbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687339123; x=1689931123; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pB2kKOyXmNJk2e2QsKOkbUZlQ9krtQWymG1tqTKND7M=; b=VQ+J/YWc4lGhHK7SU5lIpFcA+DV5VY73nfhXoOOTsIWLtLXtQqti/9bWE8OXVYWU8o k1JlihnzWii9iozCGE+PxtJFlEu6FL1BtDF3apUO/p1S2zwZFqfenfFRj8hdQlSlzCEv xLoaHxkpJEOeIERPH5DZ4VnOsoAvMk4qbTgeN6weCLHvkPp9PTsbaNu1wUZoBpGFn8/1 mrN6dro7PKSGGOMdrJtbL3h44/HFC602YPv1lLWwUdO0lRCaLmhC3pf6CRZqk9txwtzl EPRrN1UaCUhWdNQ3vABHkv/VQ5NI/++fl2yTqrAVZO7yImmbdo875m3Sb5s3kPnYYZwv n/RA== X-Gm-Message-State: AC+VfDwhpneVM9XsZlrn6U5lgYZdGjLslT74NJZEBVqRilqwx8hK4e1W wABOApAdVGARViIfOQYUjSN/SQ== X-Received: by 2002:a17:902:ce91:b0:1b6:8f1f:fc8d with SMTP id f17-20020a170902ce9100b001b68f1ffc8dmr2804577plg.0.1687339123052; Wed, 21 Jun 2023 02:18:43 -0700 (PDT) Received: from sunil-laptop ([106.51.184.72]) by smtp.gmail.com with ESMTPSA id n21-20020a170902969500b001ab1b7bae5asm3007337plp.184.2023.06.21.02.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 02:18:42 -0700 (PDT) Date: Wed, 21 Jun 2023 14:48:35 +0530 From: Sunil V L To: Song Shuai Cc: Alexandre Ghiti , Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= Subject: Re: [PATCH v2 2/3] Documentation: riscv: Add early boot document Message-ID: References: <20230621072234.9900-1-alexghiti@rivosinc.com> <20230621072234.9900-2-alexghiti@rivosinc.com> <131BBACE35371733+d5902eda-c4ea-b74d-a17c-70fd1a166b6f@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <131BBACE35371733+d5902eda-c4ea-b74d-a17c-70fd1a166b6f@tinylab.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 21, 2023 at 04:15:07PM +0800, Song Shuai wrote: > > > 在 2023/6/21 15:22, Alexandre Ghiti 写道: > > This document describes the constraints and requirements of the early > > boot process in a RISC-V kernel. > > > > Signed-off-by: Alexandre Ghiti > > Reviewed-by: Björn Töpel > > --- > > Documentation/riscv/boot-image-header.rst | 3 - > > Documentation/riscv/boot.rst | 170 ++++++++++++++++++++++ > > Documentation/riscv/index.rst | 1 + > > 3 files changed, 171 insertions(+), 3 deletions(-) > > create mode 100644 Documentation/riscv/boot.rst > > > > diff --git a/Documentation/riscv/boot-image-header.rst b/Documentation/riscv/boot-image-header.rst > > index d7752533865f..a4a45310c4c4 100644 > > --- a/Documentation/riscv/boot-image-header.rst > > +++ b/Documentation/riscv/boot-image-header.rst > > @@ -7,9 +7,6 @@ Boot image header in RISC-V Linux > > This document only describes the boot image header details for RISC-V Linux. > > -TODO: > > - Write a complete booting guide. > > - > > The following 64-byte header is present in decompressed Linux kernel image:: > > u32 code0; /* Executable code */ > > diff --git a/Documentation/riscv/boot.rst b/Documentation/riscv/boot.rst > > new file mode 100644 > > index 000000000000..019ee818686d > > --- /dev/null > > +++ b/Documentation/riscv/boot.rst > > @@ -0,0 +1,170 @@ > > +.. SPDX-License-Identifier: GPL-2.0 > > + > > +=============================================== > > +RISC-V Kernel Boot Requirements and Constraints > > +=============================================== > > + > > +:Author: Alexandre Ghiti > > +:Date: 23 May 2023 > > + > > +This document describes what the RISC-V kernel expects from bootloaders and > > +firmware, but also the constraints that any developer must have in mind when > > +touching the early boot process. For the purposes of this document, the > > +'early boot process' refers to any code that runs before the final virtual > > +mapping is set up. > > + > > +Pre-kernel Requirements and Constraints > > +======================================= > > + > > +The RISC-V kernel expects the following of bootloaders and platform firmware: > > + > > +Register state > > +-------------- > > + > > +The RISC-V kernel expects: > > + > > + * `$a0` to contain the hartid of the current core. > > + * `$a1` to contain the address of the devicetree in memory. > > + > > +CSR state > > +--------- > > + > > +The RISC-V kernel expects: > > + > > + * `$satp = 0`: the MMU, if present, must be disabled. > > + > > +Reserved memory for resident firmware > > +------------------------------------- > > + > > +The RISC-V kernel must not map any resident memory, or memory protected with > > +PMPs, in the direct mapping, so the firmware must correctly mark those regions > > +as per the devicetree specification and/or the UEFI specification. > > + > > +Kernel location > > +--------------- > > + > > +The RISC-V kernel expects to be placed at a PMD boundary (2MB aligned for rv64 > > +and 4MB aligned for rv32). Note that the EFI stub will physically relocate the > > +kernel if that's not the case. > > + > > +Hardware description > > +-------------------- > > + > > +The firmware can pass either a devicetree or ACPI tables to the RISC-V kernel. > > + > > +The devicetree is either passed directly to the kernel from the previous stage > > +using the `$a1` register, or when booting with UEFI, it can be passed using the > > +EFI configuration table. > > + > > +The ACPI tables are passed to the kernel using the EFI configuration table. In > > +this case, a tiny devicetree is still created by the EFI stub. Please refer to > > +"EFI stub and devicetree" tree section below for details about this devicetree. > > + > > +Kernel entrance > > +--------------- > > + > > +On SMP systems, there are 2 methods to enter the kernel: > > + > > +- `RISCV_BOOT_SPINWAIT`: the firmware releases all harts in the kernel, one hart > > + wins a lottery and executes the early boot code while the other harts are > > + parked waiting for the initialization to finish. This method is mostly used to > > + support older firmwares without SBI HSM extension and M-mode RISC-V kernel. > > +- `Ordered booting`: the firmware releases only one hart that will execute the > > + initialization phase and then will start all other harts using the SBI HSM > > + extension. The ordered booting method is the preferred booting method for > > + booting the RISC-V kernel because it can support cpu hotplug and kexec. > > + > > +UEFI > > +---- > > + > > +UEFI memory map > > +~~~~~~~~~~~~~~~ > > + > > +When booting with UEFI, the RISC-V kernel will use only the EFI memory map to > > +populate the system memory. > > + > > +The UEFI firmware must parse the subnodes of the `/reserved-memory` devicetree > > +node and abide by the devicetree specification to convert the attributes of > > +those subnodes (`no-map` and `reusable`) into their correct EFI equivalent > > +(refer to section "3.5.4 /reserved-memory and UEFI" of the devicetree > > +specification v0.4-rc1). > append this note ? > > Note that RISC-V edk2 diverges from the devicetree specification to declare > the !no-map regions as EfiReservedMemoryType instead of EfiBootServicesData. > > + Not required. It will be fixed in EDK2.