blob: 033159b025344ea713a64d361c29638b08f35971 [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 Wangdda3ba92023-05-25 15:15:30 +000021use libfdt::FdtError;
Alice Wangd80e99e2023-09-15 13:26:01 +000022use service_vm_comm::RequestProcessingError;
Pierre-Clément Tosia9b345f2024-04-27 01:01:42 +010023use vmbase::{hyp::Error as HypervisorError, 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 Wangd80e99e2023-09-15 13:26:01 +000056 /// Failed to process request.
57 RequestProcessingFailed(RequestProcessingError),
Alice Wang9a8b39f2023-04-12 15:31:48 +000058}
59
60impl fmt::Display for Error {
61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62 match self {
Alice Wangdda3ba92023-05-25 15:15:30 +000063 Self::Hypervisor(e) => write!(f, "Hypervisor error: {e}."),
Alice Wang9a8b39f2023-04-12 15:31:48 +000064 Self::PageTableMapping(e) => {
65 write!(f, "Failed when attempting to map some range in the page table: {e}.")
66 }
Alice Wangdda3ba92023-05-25 15:15:30 +000067 Self::InvalidFdt(e) => write!(f, "Invalid FDT: {e}"),
68 Self::InvalidPci(e) => write!(f, "Invalid PCI: {e}"),
Alice Wang74f7f4b2023-06-13 08:24:50 +000069 Self::MemoryOperationFailed(e) => write!(f, "Failed memory operation: {e}"),
Alice Wangd36c7112023-07-04 09:50:45 +000070 Self::PciInitializationFailed(e) => write!(f, "Failed to initialize PCI: {e}"),
Alice Wang62183352023-07-04 08:33:27 +000071 Self::VirtIOSocketCreationFailed(e) => {
72 write!(f, "Failed to create VirtIO Socket device: {e}")
73 }
74 Self::MissingVirtIOSocketDevice => write!(f, "Missing VirtIO Socket device."),
Alice Wang4e082c32023-07-11 07:41:50 +000075 Self::VirtIODriverOperationFailed(e) => {
76 write!(f, "Failed VirtIO driver operation: {e}")
77 }
Alice Wang748b0322023-07-24 12:51:18 +000078 Self::SerializationFailed(e) => write!(f, "Failed to serialize: {e}"),
79 Self::DeserializationFailed(e) => write!(f, "Failed to deserialize: {e}"),
Alice Wang474c0ee2023-09-14 12:52:33 +000080 Self::DiceOperationFailed(e) => write!(f, "Failed DICE operation: {e}"),
Alice Wangd80e99e2023-09-15 13:26:01 +000081 Self::RequestProcessingFailed(e) => write!(f, "Failed to process request: {e}"),
Alice Wang9a8b39f2023-04-12 15:31:48 +000082 }
83 }
84}
85
Alice Wang90e6f162023-04-17 13:49:45 +000086impl From<HypervisorError> for Error {
87 fn from(e: HypervisorError) -> Self {
88 Self::Hypervisor(e)
Alice Wang9a8b39f2023-04-12 15:31:48 +000089 }
90}
91
92impl From<MapError> for Error {
93 fn from(e: MapError) -> Self {
94 Self::PageTableMapping(e)
95 }
96}
Alice Wangdda3ba92023-05-25 15:15:30 +000097
98impl From<FdtError> for Error {
99 fn from(e: FdtError) -> Self {
100 Self::InvalidFdt(e)
101 }
102}
103
104impl From<PciError> for Error {
105 fn from(e: PciError) -> Self {
106 Self::InvalidPci(e)
107 }
108}
Alice Wang74f7f4b2023-06-13 08:24:50 +0000109
110impl From<MemoryTrackerError> for Error {
111 fn from(e: MemoryTrackerError) -> Self {
112 Self::MemoryOperationFailed(e)
113 }
114}
Alice Wang4e082c32023-07-11 07:41:50 +0000115
116impl From<virtio_drivers::Error> for Error {
117 fn from(e: virtio_drivers::Error) -> Self {
118 Self::VirtIODriverOperationFailed(e)
119 }
120}
Alice Wang748b0322023-07-24 12:51:18 +0000121
122impl From<CiboriumSerError> for Error {
123 fn from(e: CiboriumSerError) -> Self {
124 Self::SerializationFailed(e)
125 }
126}
127
128impl From<CiboriumDeError> for Error {
129 fn from(e: CiboriumDeError) -> Self {
130 Self::DeserializationFailed(e)
131 }
132}
Alice Wang474c0ee2023-09-14 12:52:33 +0000133
134impl From<DiceError> for Error {
135 fn from(e: DiceError) -> Self {
136 Self::DiceOperationFailed(e)
137 }
138}
Alice Wangd80e99e2023-09-15 13:26:01 +0000139
140impl From<RequestProcessingError> for Error {
141 fn from(e: RequestProcessingError) -> Self {
142 Self::RequestProcessingFailed(e)
143 }
144}