blob: 4e25e7fba2bb4a983e23bf563120ed7fa85e1acd [file] [log] [blame]
Alice Wang90e6f162023-04-17 13:49:45 +00001// Copyright 2023, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Error and Result types for hypervisor.
16
Andrew Walbran9afab672023-04-17 14:26:23 +000017use crate::KvmError;
Alice Wang90e6f162023-04-17 13:49:45 +000018use core::{fmt, result};
19
20/// Result type with hypervisor error.
21pub type Result<T> = result::Result<T, Error>;
22
23/// Hypervisor error.
24#[derive(Debug, Clone)]
25pub enum Error {
26 /// MMIO guard is not supported.
27 MmioGuardNotsupported,
Andrew Walbran9afab672023-04-17 14:26:23 +000028 /// Failed to invoke a certain KVM HVC function.
29 KvmError(KvmError, u32),
Alice Wang90e6f162023-04-17 13:49:45 +000030 /// The MMIO_GUARD granule used by the hypervisor is not supported.
31 UnsupportedMmioGuardGranule(usize),
32}
33
34impl fmt::Display for Error {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 match self {
37 Self::MmioGuardNotsupported => write!(f, "MMIO guard is not supported"),
Andrew Walbran9afab672023-04-17 14:26:23 +000038 Self::KvmError(e, function_id) => {
Alice Wang90e6f162023-04-17 13:49:45 +000039 write!(f, "Failed to invoke the HVC function with function ID {function_id}: {e}")
40 }
41 Self::UnsupportedMmioGuardGranule(g) => {
42 write!(f, "Unsupported MMIO guard granule: {g}")
43 }
44 }
45 }
46}