blob: 911cb9ba525ed058f8c6e6d0df43a752345136d1 [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 Wang474c0ee2023-09-14 12:52:33 +000019use diced_open_dice::DiceError;
Alice Wangdda3ba92023-05-25 15:15:30 +000020use fdtpci::PciError;
Alice Wang90e6f162023-04-17 13:49:45 +000021use hyp::Error as HypervisorError;
Alice Wangdda3ba92023-05-25 15:15:30 +000022use libfdt::FdtError;
Alice Wangd36c7112023-07-04 09:50:45 +000023use vmbase::{memory::MemoryTrackerError, virtio::pci};
Alice Wang9a8b39f2023-04-12 15:31:48 +000024
25pub type Result<T> = result::Result<T, Error>;
26
Alice Wang748b0322023-07-24 12:51:18 +000027type CiboriumSerError = ciborium::ser::Error<virtio_drivers::Error>;
28type CiboriumDeError = ciborium::de::Error<virtio_drivers::Error>;
29
30#[derive(Debug)]
Alice Wang9a8b39f2023-04-12 15:31:48 +000031pub enum Error {
Alice Wang90e6f162023-04-17 13:49:45 +000032 /// Hypervisor error.
33 Hypervisor(HypervisorError),
Alice Wang9a8b39f2023-04-12 15:31:48 +000034 /// Failed when attempting to map some range in the page table.
35 PageTableMapping(MapError),
Alice Wangdda3ba92023-05-25 15:15:30 +000036 /// Invalid FDT.
37 InvalidFdt(FdtError),
38 /// Invalid PCI.
39 InvalidPci(PciError),
Alice Wang74f7f4b2023-06-13 08:24:50 +000040 /// Failed memory operation.
41 MemoryOperationFailed(MemoryTrackerError),
Alice Wangd36c7112023-07-04 09:50:45 +000042 /// Failed to initialize PCI.
43 PciInitializationFailed(pci::PciError),
Alice Wang62183352023-07-04 08:33:27 +000044 /// Failed to create VirtIO Socket device.
45 VirtIOSocketCreationFailed(virtio_drivers::Error),
46 /// Missing socket device.
47 MissingVirtIOSocketDevice,
Alice Wang4e082c32023-07-11 07:41:50 +000048 /// Failed VirtIO driver operation.
49 VirtIODriverOperationFailed(virtio_drivers::Error),
Alice Wang748b0322023-07-24 12:51:18 +000050 /// Failed to serialize.
51 SerializationFailed(CiboriumSerError),
52 /// Failed to deserialize.
53 DeserializationFailed(CiboriumDeError),
Alice Wang474c0ee2023-09-14 12:52:33 +000054 /// Failed DICE operation.
55 DiceOperationFailed(DiceError),
Alice Wang9a8b39f2023-04-12 15:31:48 +000056}
57
58impl fmt::Display for Error {
59 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60 match self {
Alice Wangdda3ba92023-05-25 15:15:30 +000061 Self::Hypervisor(e) => write!(f, "Hypervisor error: {e}."),
Alice Wang9a8b39f2023-04-12 15:31:48 +000062 Self::PageTableMapping(e) => {
63 write!(f, "Failed when attempting to map some range in the page table: {e}.")
64 }
Alice Wangdda3ba92023-05-25 15:15:30 +000065 Self::InvalidFdt(e) => write!(f, "Invalid FDT: {e}"),
66 Self::InvalidPci(e) => write!(f, "Invalid PCI: {e}"),
Alice Wang74f7f4b2023-06-13 08:24:50 +000067 Self::MemoryOperationFailed(e) => write!(f, "Failed memory operation: {e}"),
Alice Wangd36c7112023-07-04 09:50:45 +000068 Self::PciInitializationFailed(e) => write!(f, "Failed to initialize PCI: {e}"),
Alice Wang62183352023-07-04 08:33:27 +000069 Self::VirtIOSocketCreationFailed(e) => {
70 write!(f, "Failed to create VirtIO Socket device: {e}")
71 }
72 Self::MissingVirtIOSocketDevice => write!(f, "Missing VirtIO Socket device."),
Alice Wang4e082c32023-07-11 07:41:50 +000073 Self::VirtIODriverOperationFailed(e) => {
74 write!(f, "Failed VirtIO driver operation: {e}")
75 }
Alice Wang748b0322023-07-24 12:51:18 +000076 Self::SerializationFailed(e) => write!(f, "Failed to serialize: {e}"),
77 Self::DeserializationFailed(e) => write!(f, "Failed to deserialize: {e}"),
Alice Wang474c0ee2023-09-14 12:52:33 +000078 Self::DiceOperationFailed(e) => write!(f, "Failed DICE operation: {e}"),
Alice Wang9a8b39f2023-04-12 15:31:48 +000079 }
80 }
81}
82
Alice Wang90e6f162023-04-17 13:49:45 +000083impl From<HypervisorError> for Error {
84 fn from(e: HypervisorError) -> Self {
85 Self::Hypervisor(e)
Alice Wang9a8b39f2023-04-12 15:31:48 +000086 }
87}
88
89impl From<MapError> for Error {
90 fn from(e: MapError) -> Self {
91 Self::PageTableMapping(e)
92 }
93}
Alice Wangdda3ba92023-05-25 15:15:30 +000094
95impl From<FdtError> for Error {
96 fn from(e: FdtError) -> Self {
97 Self::InvalidFdt(e)
98 }
99}
100
101impl From<PciError> for Error {
102 fn from(e: PciError) -> Self {
103 Self::InvalidPci(e)
104 }
105}
Alice Wang74f7f4b2023-06-13 08:24:50 +0000106
107impl From<MemoryTrackerError> for Error {
108 fn from(e: MemoryTrackerError) -> Self {
109 Self::MemoryOperationFailed(e)
110 }
111}
Alice Wang4e082c32023-07-11 07:41:50 +0000112
113impl From<virtio_drivers::Error> for Error {
114 fn from(e: virtio_drivers::Error) -> Self {
115 Self::VirtIODriverOperationFailed(e)
116 }
117}
Alice Wang748b0322023-07-24 12:51:18 +0000118
119impl From<CiboriumSerError> for Error {
120 fn from(e: CiboriumSerError) -> Self {
121 Self::SerializationFailed(e)
122 }
123}
124
125impl From<CiboriumDeError> for Error {
126 fn from(e: CiboriumDeError) -> Self {
127 Self::DeserializationFailed(e)
128 }
129}
Alice Wang474c0ee2023-09-14 12:52:33 +0000130
131impl From<DiceError> for Error {
132 fn from(e: DiceError) -> Self {
133 Self::DiceOperationFailed(e)
134 }
135}