1*5225e6b1SAndroid Build Coastguard Worker // Copyright 2024, The Android Open Source Project 2*5225e6b1SAndroid Build Coastguard Worker // 3*5225e6b1SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*5225e6b1SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*5225e6b1SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*5225e6b1SAndroid Build Coastguard Worker // 7*5225e6b1SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*5225e6b1SAndroid Build Coastguard Worker // 9*5225e6b1SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*5225e6b1SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*5225e6b1SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*5225e6b1SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*5225e6b1SAndroid Build Coastguard Worker // limitations under the License. 14*5225e6b1SAndroid Build Coastguard Worker 15*5225e6b1SAndroid Build Coastguard Worker //! Rust wrapper for `RISCV_EFI_BOOT_PROTOCOL`. 16*5225e6b1SAndroid Build Coastguard Worker 17*5225e6b1SAndroid Build Coastguard Worker use crate::efi_call; 18*5225e6b1SAndroid Build Coastguard Worker use crate::protocol::{Protocol, ProtocolInfo}; 19*5225e6b1SAndroid Build Coastguard Worker use efi_types::{EfiGuid, EfiRiscvBootProtocol}; 20*5225e6b1SAndroid Build Coastguard Worker use liberror::Result; 21*5225e6b1SAndroid Build Coastguard Worker 22*5225e6b1SAndroid Build Coastguard Worker /// RISCV_EFI_BOOT_PROTOCOL 23*5225e6b1SAndroid Build Coastguard Worker pub struct RiscvBootProtocol; 24*5225e6b1SAndroid Build Coastguard Worker 25*5225e6b1SAndroid Build Coastguard Worker impl ProtocolInfo for RiscvBootProtocol { 26*5225e6b1SAndroid Build Coastguard Worker type InterfaceType = EfiRiscvBootProtocol; 27*5225e6b1SAndroid Build Coastguard Worker 28*5225e6b1SAndroid Build Coastguard Worker const GUID: EfiGuid = 29*5225e6b1SAndroid Build Coastguard Worker EfiGuid::new(0xccd15fec, 0x6f73, 0x4eec, [0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf]); 30*5225e6b1SAndroid Build Coastguard Worker } 31*5225e6b1SAndroid Build Coastguard Worker 32*5225e6b1SAndroid Build Coastguard Worker impl<'a> Protocol<'a, RiscvBootProtocol> { 33*5225e6b1SAndroid Build Coastguard Worker /// Wraps `RISCV_EFI_BOOT_PROTOCOL.GetBootHartId()`. get_boot_hartid(&self) -> Result<usize>34*5225e6b1SAndroid Build Coastguard Worker pub fn get_boot_hartid(&self) -> Result<usize> { 35*5225e6b1SAndroid Build Coastguard Worker let mut boot_hart_id: usize = 0; 36*5225e6b1SAndroid Build Coastguard Worker // SAFETY: 37*5225e6b1SAndroid Build Coastguard Worker // `self.interface()?` guarantees `self.interface` is non-null and points to a valid object 38*5225e6b1SAndroid Build Coastguard Worker // established by `Protocol::new()`. 39*5225e6b1SAndroid Build Coastguard Worker // `self.interface` is input parameter and will not be retained. It outlives the call. 40*5225e6b1SAndroid Build Coastguard Worker // `&mut boot_hart_id` is output parameter and will not be retained. It outlives the call. 41*5225e6b1SAndroid Build Coastguard Worker unsafe { 42*5225e6b1SAndroid Build Coastguard Worker efi_call!(self.interface()?.get_boot_hartid, self.interface, &mut boot_hart_id)?; 43*5225e6b1SAndroid Build Coastguard Worker } 44*5225e6b1SAndroid Build Coastguard Worker Ok(boot_hart_id) 45*5225e6b1SAndroid Build Coastguard Worker } 46*5225e6b1SAndroid Build Coastguard Worker 47*5225e6b1SAndroid Build Coastguard Worker /// Wraps `RISCV_EFI_BOOT_PROTOCOL.Revision`. revision(&self) -> Result<u64>48*5225e6b1SAndroid Build Coastguard Worker pub fn revision(&self) -> Result<u64> { 49*5225e6b1SAndroid Build Coastguard Worker Ok(self.interface()?.revision) 50*5225e6b1SAndroid Build Coastguard Worker } 51*5225e6b1SAndroid Build Coastguard Worker } 52