From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.38 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796213284; b=2VsMtu0WJfpJ0JzW3GgIK95Qo0IPmhQP++6xJBowWc1ts2eaf4OBhq/dcXWkaC5uJ1oE VqWo++dELdyUO1VpBxjXVis7GAekjufxZdNh7yolFTvBY5UZDZ9LdwVnV1AfkLUfmi8yt Z3G3nWHJ/ReHb7gn4IxUaX7raaUdGJiSw4ZoWsrbAFAwpc+bAmpo6/wO9y3Q0kUjYqjXh WBTvYUtCWtapgNiwWZKW0rDLhLOCe0Qour1uW8CJ3kiu3uJmLg+GYfAXIYIoHBemt4rub rWtdB5X8PfczDrrvyhYIJlOaQrcj5K9MgUewGGM314ef7p66W8GVyJYrRv9FWa66DFQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796213284; h=DMARC-Filter:DKIM-Signature:Received:Received:From:Date:Subject: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0: X-MS-Exchange-AntiSpam-MessageData-1:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=KC9yRP6EdvHlRiswMSAH2Qc1fAQW+i11VmhFHKlU9ps=; b=h5Rom1TGxmJA/picjlPNUlT6kcfrIHnFEhOzWQuF4kPFHg7jEnVnAHoR9PjyeyyyAMqX 99Q7V5njQjm8kvtm96ljE2beFB928Cpao23qThaK4qMzyvyYrmAGlO81/yTHXKH4HNky1 VIqwfY+lu3KwMWsMjYRLYoh1MaMJIByKrcd94c2nMcQApi955yk2BTPMVno4Cy3Cjq7ix fSKvY/Cqkr+ULuRsx5Su847VeXszF7Eyhj/ycICszLSfCFG3D/l/ywFEobzjlBKF4O6t9 CFOtWLeyMh3vCHgu+vf/mdTD4OSMRm10IROMXB6OLL0neUNx7tscDi2bN6iP/0JSzmw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=adA6N2fY; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.38 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013038.outbound.protection.outlook.com [40.93.201.38]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC0D8606A685 for ; Wed, 2 Dec 2026 12:08:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC0D8606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=adA6N2fY ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RLDg01DM2C/FkgyrsmFgXALPLoTNqMzg34b4SvuByELWabSEbWE9zQgJH2CZcVBIkxHJ8sdMOzEpgFcMzZ+SLbhCCYPx0e5OJcxNHztfS7Y83H71on8MBIR/TFJG4ALgEEWIV9yWUURppeRZ3S6SRFuuWuyk4lRqvijNEUKxlxtHYIFngpPqed5vXCJQEwxicbJzqe/hOwaX/nZsibWdbVcep5NAyAEfDgRowoa5ESjPDSg1ADC2ICtN6dSOxWnNU3PmEsTTzHDm3Igdo91+HrvRE90yPDz2ZxQIkhHswoGMbMDeWKlsIHl+kOaN9SML9IPvkY2IZnu8jdMTmOtxqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=KC9yRP6EdvHlRiswMSAH2Qc1fAQW+i11VmhFHKlU9ps=; b=p3bo8yjp+tXHKx0n1fE5Hl9eAktsOkN/AcXONbrIW7ssXy2DLdujWshBbPfytrgEOmwyYGjLnjXjtJkX3INkwBBGHF5+GzaW7r2StsWH43x0SYFoWsTSHV45GLH/bjParUGB2rxa5pBGQN16IUpa3IxKcXxa8vgnOrTbtZ6GdeYSekDUJBLDkhK1CJH0pxvvWi/3Eqm3kJ1eiD3E7RR0SiCqBznBAGtgWjYL+oqmPfsBZHyKxBB3xJxihyI+PaaTfo864CdIJhy+EPCw/hkn6JtDoUeufLvuP4mFrybg8Olmll3exo2KgLFT2ShafJcSa9nLlcZa5gokDpofyf+maA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KC9yRP6EdvHlRiswMSAH2Qc1fAQW+i11VmhFHKlU9ps=; b=adA6N2fYF/r6bMcM54qdSbDY9rOnd11lw25sB+QI0RUWBZbgZFHxRzBRJKuQxjGvDJ6dBmKCQShQ/V1jCTVSjmOoYvZOhiAVmcT3wOcRYwSfdWDE8kt+/RzFexvxG2zwkqpSjmoUtiq6LhT543eJm5iF4geWvcU7zVEjuxL4R7zuCDhU06G3iuFmwzqAChyVxHlIMwvBmDT52ajjKOgB7qHdNuWhFzmb8oDwtSxqJoJf/gSgZlDXEIRQynfjVNiNKWIUPo1H58SqAK2cYvXGB8YV1wd9CHKSjOLFSp7oxSEYmEbR5vGzaBGoqI8FdGjfSEc/Zc603oCjf/sTrlWmQg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) by SAEPR12MB181460.namprd12.prod.outlook.com (2603:10b6:802:200::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 12:07:58 +0000 Received: from DS0PR12MB6413.namprd12.prod.outlook.com ([fe80::e82a:6673:4142:37fa]) by DS0PR12MB6413.namprd12.prod.outlook.com ([fe80::e82a:6673:4142:37fa%5]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 12:07:58 +0000 From: Eliot Courtney Date: Wed, 02 Dec 2026 21:06:38 +0900 Subject: [PATCH v2 6/7] gpu: nova-core: gsp: add the r000 load-and-execute bootloader handler Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-falcon-v2-6-33ed73a20796@nvidia.com> References: <20261202-falcon-v2-0-33ed73a20796@nvidia.com> In-Reply-To: <20261202-falcon-v2-0-33ed73a20796@nvidia.com> To: Danilo Krummrich , Alice Ryhl , Alexandre Courbot , David Airlie , Simona Vetter Cc: John Hubbard , Alistair Popple , Timur Tabi , Zhi Wang , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Eliot Courtney X-Mailer: b4 0.15.2 X-ClientProxiedBy: JK2P305CA0021.IDNP305.PROD.OUTLOOK.COM (2603:1096:180:11::6) To DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB6413:EE_|SAEPR12MB181460:EE_ X-MS-Office365-Filtering-Correlation-Id: 30f58c64-0545-4c39-6969-08df506ce77f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|23010399003|1800799024|261102123227099003|10067099003|56012099006|11063799006|261021121427099003|261009223027099003|261009221227099003|261022105027099003|261022075727099003|261022115727099003|261026121527099003|261028144727099003|261021123027099003|261026140227099003|18002099003|22082099003|6133799003; X-Microsoft-Antispam-Message-Info: 9hgMJryFeb47MwRnF4fmQLdRIVKUn7EFkd2zacg+sG8R7OPVOVJZ8fTeEkywjo8X+PhFLtTG1+wJZrnJJ291SKK0+v59qlnsOE6DNLf7L0iWtzNpqn3Nyr8xv/05V+Q3R+iBO0UOObDmFE01dCb8MnHueZkUcKBITopqQ3Qdc/vd+zPuOMo1Kwc7XHR8vOEO6NVqPsdhB7ekKVCjDwNPdUJFkzt/dd8WXarIHv/7b8zBzcqkYD8E/PlhzAPaMuK61Buu5dspfaTxIjrmbjaWVo4izvkegJPA4eiZIbf4EfTRnpHlB8GSMrBCbwnoLljxEF4iEVNrheXYhpf1OjVidg/9yazA2wiZp/CaGmXrmKutNL6cTRHMpMwhqJNkCKXJLZxouAKa6cqbqWZ+bLiTVDQW/q9ico1L2yUNPpcYwGkWYxKk3osh9lJ4C1Uzn4BEpz4jfG3//5jo+xNb48oBpJdk3kFA4v/RSWoDaaFVCI+CgKmgyHYzIm3QxMH1tToiBW8813YJOII9A08Y3LDeCaMI5vxpZDwOYBvXLYrXPXll0sSwe2Uso3hhtuqcFafBNF/iuJ5iuxq3uVQMn6QnzutBo9BlMGSLngi+SCCb9NteT0IRnzdDRpkSZhgfGx/9162njLkZECqY1TbF0fUCTTseLyKFmdGMHx5ih3Uumzo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB6413.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(23010399003)(1800799024)(261102123227099003)(10067099003)(56012099006)(11063799006)(261021121427099003)(261009223027099003)(261009221227099003)(261022105027099003)(261022075727099003)(261022115727099003)(261026121527099003)(261028144727099003)(261021123027099003)(261026140227099003)(18002099003)(22082099003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MzNybzhsd2F3YmNtc0NlUFl5aGQxZE02Qzc5OUhWSzZSa0JZbFp2bnhRanQz?= =?utf-8?B?WlF3Qm5rRXRvbUxoamhZRzBTNHo5Y21HdzhsTUFhOWNpd1VaT2VHNU1UYTJw?= =?utf-8?B?S1dvd1RTQ0swMHF4M1hEbFZsSTlaR2xrL2ltUUVrUUh0SFI5amlOcDNqRVlU?= =?utf-8?B?bmZsWGJFKzlsZFFJN0E2T1p6aWxsRnVIZndaZ0c2UUdZaVFPWWZ2bjF3QzFu?= =?utf-8?B?QXMreG05YkFUZ1g3ZnFLMXFrVThSNkoycFJOanBmT3krZmNJUzNSbDRWVjY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RERaako1cDdXSGVIL2hJNDBvVkpaTjh4Zk1u?= =?utf-8?B?SWxsRmw5MWJid1VFd3FLNC9uVTZlbVJ0Z3ZPSTZiMVM3YWFhcHB1TEd5VWc0?= =?utf-8?B?ZUdWM1ppem9VSTg4ZnpBbnRwR2lneWVJSThpaDh2ZXdpd0NISFVUV1RNNUFr?= =?utf-8?B?dUxJTVdNTFd6bFNiUlZSR2ZYRmozRmlTQlFTQXJrREowdFZLYklKa2NQcWxJ?= =?utf-8?B?UmpycStJSlBQUytvUklad1RIaHRXbStGZ1FNcS8xcTJhbEg0SkZUTU03WU81?= =?utf-8?Q?W023pIXwZDaG+kyMOW3IYE+Bc53vnDm/uhRke+iaNVNTC?= X-MS-Exchange-AntiSpam-MessageData-1: 9Yf2LEv3GHUKWA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30f58c64-0545-4c39-6969-08df506ce77f X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6413.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 12:07:58.3571 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dCokTl/ZpiEBEQ0rnyTyOq6ehfvf3t3WX4N15ec1oLsCL/Wpque0FoxMy2j2d3lHGPCpKoc2XMyF4c/4KPap8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SAEPR12MB181460 From: John Hubbard On Turing and GA100, the r000 GSP-RM requires an image to run on the falcon core during boot, through the generic falcon bootloader. GSP-RM is suspended while the image runs. The driver runs the image on behalf of GSP-RM, in the following steps: 1. GSP-RM raises a load-and-execute event, which carries a descriptor of the image. 2. GSP-RM suspends the RISC-V core. 3. The driver waits until the RISC-V core is suspended. 4. The driver resets the GSP falcon, which selects the falcon core. 5. The driver loads the bootloader and the descriptor into the GSP falcon. 6. The driver starts the bootloader, which loads the image and starts it. 7. The driver waits for the falcon core to halt. 8. The driver resumes GSP-RM on the RISC-V core. Nova-core has no handler for the bootloader's load-and-execute event. Add the handler, which performs steps 3 through 8. Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Signed-off-by: John Hubbard [ecourtney: zerocopy derives for `GenericBootloaderParams`, no `unsafe impl`] [ecourtney: derive `FromBytes` for `BootloaderDmemDescV2`, no `unsafe impl`] [ecourtney: move MAILBOX0 check and resume to `handle_load_exec_event()`] [ecourtney: module doc's FBIF sentence moved to the HS binary patch] [ecourtney: move some methods to be impls of `GspBootContext`] [ecourtney: load the generic bootloader in the handler, don't pass it in] Signed-off-by: Eliot Courtney --- drivers/gpu/nova-core/firmware/gen_bootloader.rs | 2 +- drivers/gpu/nova-core/gsp/load_exec.rs | 131 +++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs index 7e53f287ca2a..b4631cf9e76c 100644 --- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs +++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs @@ -46,7 +46,7 @@ /// This has to be filled by the GPU driver and copied into DMEM at offset /// [`BootloaderDesc.dmem_load_off`]. #[repr(C, packed)] -#[derive(Debug, Clone, IntoBytes, Immutable)] +#[derive(Debug, Clone, FromBytes, IntoBytes, Immutable)] pub(crate) struct BootloaderDmemDescV2 { /// Reserved, should always be first element. reserved: [u32; 4], diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs index 6d832cb9ec24..1eab4c00e4d3 100644 --- a/drivers/gpu/nova-core/gsp/load_exec.rs +++ b/drivers/gpu/nova-core/gsp/load_exec.rs @@ -29,11 +29,16 @@ Falcon, FalconBromParams, FalconDmemSegment, + FalconFbifTarget, FalconFirmware, FalconImage, FalconImemSegment, FalconSegmentSource, // }, + firmware::gen_bootloader::{ + BootloaderDmemDescV2, + GenericBootloader, // + }, gsp::{ cmdq::gmc::MessageFromGsp, GspBootContext, // @@ -172,6 +177,79 @@ fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result { ); }) } + + /// Runs the image of a `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` event on the + /// falcon core of the GSP falcon, through the generic falcon bootloader, and + /// returns `MAILBOX0` once the image has halted. + /// + /// `params` holds the descriptor of the image. The generic falcon bootloader + /// loads and starts the image that the descriptor names, per + /// [`GenericBootloader::run`]. The handler: + /// + /// 1. Checks that the descriptor in `params` has the size of + /// [`BootloaderDmemDescV2`], and gets the FBIF (Framebuffer Interface) + /// target that `params` selects. + /// 2. Loads the generic falcon bootloader image for the GPU's chipset. + /// 3. Waits until GSP-RM has suspended the RISC-V core, for up to five + /// seconds. + /// 4. Resets the GSP falcon, which selects the falcon core. + /// 5. Runs the bootloader with the descriptor and with + /// [`FLCN_ERR_BINARY_NOT_STARTED`] in `MAILBOX0`, and waits until the + /// falcon core halts, for up to two seconds. The image halts the falcon + /// core when it is done, so the handler learns from the halt that the + /// image has finished. + /// + /// # Errors + /// + /// - `EINVAL` if the descriptor size in `params` is not the size of + /// [`BootloaderDmemDescV2`], or if the address space and the cache + /// attribute in `params` select no FBIF target. + /// - `ETIMEDOUT` if GSP-RM has not suspended the RISC-V core within five + /// seconds, or if the falcon core has not halted within two seconds of + /// its start. + /// + /// Errors from loading the bootloader, the reset of the GSP falcon, and the + /// run of the bootloader are propagated as-is. + #[expect(dead_code)] + fn handle_generic_bootloader(&self, params: &GenericBootloaderParams) -> Result { + /// Expected size of the descriptor, in bytes. + const DMEM_DESC_SIZE: u32 = cv!(size_of::()); + + let dev = self.dev(); + let gsp_falcon = self.gsp_falcon; + + if params.dmem_desc_size != DMEM_DESC_SIZE { + dev_err!( + dev, + "Generic bootloader descriptor is {} bytes, expected {}\n", + params.dmem_desc_size, + DMEM_DESC_SIZE + ); + return Err(EINVAL); + } + + let fbif_target = params.fbif_target()?; + let bootloader = GenericBootloader::new(dev, self.chipset)?; + + self.reset_gsp_falcon_after_suspend()?; + + bootloader + .run( + gsp_falcon, + ¶ms.dmem_desc, + fbif_target, + FLCN_ERR_BINARY_NOT_STARTED, + ) + .map(|(mbox0, _)| mbox0) + .inspect_err(|e| { + dev_err!( + dev, + "Failed to run the generic bootloader: {:?} (mbox0={:#x})\n", + e, + gsp_falcon.read_mailbox0() + ); + }) + } } /// Payload of a `GMCAPI_CMD_EXEC_HS_BINARY` event, which describes the HS binary to run. @@ -291,3 +369,56 @@ fn boot_addr(&self) -> u32 { self.imem.va } } + +/// Payload of a `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` event, which describes the image for the +/// generic falcon bootloader to run. +#[repr(C)] +#[derive(FromBytes, IntoBytes)] +struct GenericBootloaderParams { + /// Descriptor of the image, which the bootloader reads from DMEM. + dmem_desc: BootloaderDmemDescV2, + /// Size in bytes of the descriptor, as GSP-RM defines it. + dmem_desc_size: u32, + /// Address space of the image: [`Self::ADDR_SYSMEM`] for system memory, or + /// [`Self::ADDR_FBMEM`] for the framebuffer. + addr_space: u32, + /// CPU cache attribute of an image in system memory: [`Self::NV_MEMORY_CACHED`] or + /// [`Self::NV_MEMORY_UNCACHED`]. + cpu_cache_attrib: u32, + _reserved: [u32; 4], +} + +impl GenericBootloaderParams { + const ADDR_SYSMEM: u32 = 1; + const ADDR_FBMEM: u32 = 2; + const NV_MEMORY_CACHED: u32 = 0; + const NV_MEMORY_UNCACHED: u32 = 1; + + /// Returns the FBIF target that `addr_space` and `cpu_cache_attrib` select. + /// + /// # Errors + /// + /// - `EINVAL` if the pair selects no FBIF target. + fn fbif_target(&self) -> Result { + match (self.addr_space, self.cpu_cache_attrib) { + (Self::ADDR_FBMEM, _) => Ok(FalconFbifTarget::LocalFb), + (Self::ADDR_SYSMEM, Self::NV_MEMORY_CACHED) => Ok(FalconFbifTarget::CoherentSysmem), + (Self::ADDR_SYSMEM, Self::NV_MEMORY_UNCACHED) => { + Ok(FalconFbifTarget::NoncoherentSysmem) + } + _ => Err(EINVAL), + } + } +} + +impl MessageFromGsp for GenericBootloaderParams { + type InitError = Error; + + fn read(payload: &mut SBufferIter>) -> Result { + let mut params = Self::new_zeroed(); + + payload.read_exact(params.as_mut_bytes())?; + + Ok(params) + } +} -- 2.56.1