Alioth Code Coverage

host_bridge.rs82.35%

1// Copyright 2024 Google LLC
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// https://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
15use crate::device::{self, Pause};
16use crate::pci;
17use crate::pci::cap::PciCapList;
18use crate::pci::config::{CommonHeader, DeviceHeader, EmulatedConfig, HeaderType, PciConfig};
19use crate::pci::{Pci, PciBar};
20
21#[derive(Debug)]
22pub struct HostBridge {
23 pub config: EmulatedConfig,
24}
25
26impl Default for HostBridge {
27 fn default() -> Self {3x
28 Self::new()3x
29 }3x
30}
31
32impl HostBridge {
33 pub fn new() -> Self {5x
34 let header = DeviceHeader {5x
35 common: CommonHeader {5x
36 vendor: 0x1022,5x
37 device: 0x1480,5x
38 class: 0x06,5x
39 subclass: 0x00,5x
40 header_type: HeaderType::DEVICE,5x
41 ..Default::default()5x
42 },5x
43 ..Default::default()5x
44 };5x
45 let bars = [const { PciBar::Empty }; 6];5x
46 let config = EmulatedConfig::new_device(header, bars, PciCapList::new());5x
47 HostBridge { config }5x
48 }5x
49}
50
51impl Pause for HostBridge {
52 fn pause(&self) -> device::Result<()> {
53 Ok(())
54 }
55
56 fn resume(&self) -> device::Result<()> {
57 Ok(())
58 }
59}
60
61impl Pci for HostBridge {
62 fn name(&self) -> &str {3x
63 "host_bridge"3x
64 }3x
65
66 fn config(&self) -> &dyn PciConfig {4x
67 &self.config4x
68 }4x
69
70 fn reset(&self) -> pci::Result<()> {3x
71 Ok(())3x
72 }3x
73}
74
75#[cfg(test)]
76#[path = "host_bridge_test.rs"]
77mod tests;
78