host_bridge.rs82.35%
1
// Copyright 2024 Google LLC2
//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 at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// 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 and13
// limitations under the License.14
15
use crate::device::{self, Pause};16
use crate::pci;17
use crate::pci::cap::PciCapList;18
use crate::pci::config::{CommonHeader, DeviceHeader, EmulatedConfig, HeaderType, PciConfig};19
use crate::pci::{Pci, PciBar};20
21
#[derive(Debug)]22
pub struct HostBridge {23
pub config: EmulatedConfig,24
}25
26
impl Default for HostBridge {27
fn default() -> Self {3x28
Self::new()3x29
}3x30
}31
32
impl HostBridge {33
pub fn new() -> Self {5x34
let header = DeviceHeader {5x35
common: CommonHeader {5x36
vendor: 0x1022,5x37
device: 0x1480,5x38
class: 0x06,5x39
subclass: 0x00,5x40
header_type: HeaderType::DEVICE,5x41
..Default::default()5x42
},5x43
..Default::default()5x44
};5x45
let bars = [const { PciBar::Empty }; 6];5x46
let config = EmulatedConfig::new_device(header, bars, PciCapList::new());5x47
HostBridge { config }5x48
}5x49
}50
51
impl Pause for HostBridge {52
fn pause(&self) -> device::Result<()> {53
Ok(())54
}55
56
fn resume(&self) -> device::Result<()> {57
Ok(())58
}59
}60
61
impl Pci for HostBridge {62
fn name(&self) -> &str {3x63
"host_bridge"3x64
}3x65
66
fn config(&self) -> &dyn PciConfig {4x67
&self.config4x68
}4x69
70
fn reset(&self) -> pci::Result<()> {3x71
Ok(())3x72
}3x73
}74
75
#[cfg(test)]76
#[path = "host_bridge_test.rs"]77
mod tests;78