blob: bf2663969689e1c7ef95b891475f2cc216deef54 [file] [log] [blame]
Alice Wang9a8b39f2023-04-12 15:31:48 +00001// Copyright 2022, 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//! This module contains the error thrown by Rialto.
16
17use aarch64_paging::MapError;
18use core::{fmt, result};
Alice Wangdda3ba92023-05-25 15:15:30 +000019use fdtpci::PciError;
Alice Wang90e6f162023-04-17 13:49:45 +000020use hyp::Error as HypervisorError;
Alice Wangdda3ba92023-05-25 15:15:30 +000021use libfdt::FdtError;
Alice Wang9a8b39f2023-04-12 15:31:48 +000022
23pub type Result<T> = result::Result<T, Error>;
24
25#[derive(Clone, Debug)]
26pub enum Error {
Alice Wang90e6f162023-04-17 13:49:45 +000027 /// Hypervisor error.
28 Hypervisor(HypervisorError),
Alice Wang9a8b39f2023-04-12 15:31:48 +000029 /// Failed when attempting to map some range in the page table.
30 PageTableMapping(MapError),
31 /// Failed to initialize the logger.
32 LoggerInit,
Alice Wangdda3ba92023-05-25 15:15:30 +000033 /// Invalid FDT.
34 InvalidFdt(FdtError),
35 /// Invalid PCI.
36 InvalidPci(PciError),
Alice Wang9a8b39f2023-04-12 15:31:48 +000037}
38
39impl fmt::Display for Error {
40 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41 match self {
Alice Wangdda3ba92023-05-25 15:15:30 +000042 Self::Hypervisor(e) => write!(f, "Hypervisor error: {e}."),
Alice Wang9a8b39f2023-04-12 15:31:48 +000043 Self::PageTableMapping(e) => {
44 write!(f, "Failed when attempting to map some range in the page table: {e}.")
45 }
46 Self::LoggerInit => write!(f, "Failed to initialize the logger."),
Alice Wangdda3ba92023-05-25 15:15:30 +000047 Self::InvalidFdt(e) => write!(f, "Invalid FDT: {e}"),
48 Self::InvalidPci(e) => write!(f, "Invalid PCI: {e}"),
Alice Wang9a8b39f2023-04-12 15:31:48 +000049 }
50 }
51}
52
Alice Wang90e6f162023-04-17 13:49:45 +000053impl From<HypervisorError> for Error {
54 fn from(e: HypervisorError) -> Self {
55 Self::Hypervisor(e)
Alice Wang9a8b39f2023-04-12 15:31:48 +000056 }
57}
58
59impl From<MapError> for Error {
60 fn from(e: MapError) -> Self {
61 Self::PageTableMapping(e)
62 }
63}
Alice Wangdda3ba92023-05-25 15:15:30 +000064
65impl From<FdtError> for Error {
66 fn from(e: FdtError) -> Self {
67 Self::InvalidFdt(e)
68 }
69}
70
71impl From<PciError> for Error {
72 fn from(e: PciError) -> Self {
73 Self::InvalidPci(e)
74 }
75}