mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 05:16:47 +00:00
Delete useless visibility for BARs
This commit is contained in:
parent
d3227df512
commit
b4a1dc03f3
@ -86,7 +86,7 @@ impl VirtioPciCapabilityData {
|
||||
offset,
|
||||
length,
|
||||
option,
|
||||
memory_bar,
|
||||
memory_bar: memory_bar.cloned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl VirtioPciLegacyTransport {
|
||||
};
|
||||
info!("[Virtio]: Found device:{:?}", device_type);
|
||||
|
||||
let config_bar = common_device.bar_manager().bar(0).unwrap();
|
||||
let config_bar = common_device.bar_manager().bar(0).clone().unwrap();
|
||||
|
||||
let mut num_queues = 0u16;
|
||||
while num_queues < u16::MAX {
|
||||
|
@ -73,10 +73,9 @@ impl CapabilityMsixData {
|
||||
let pba_bar;
|
||||
|
||||
let bar_manager = dev.bar_manager_mut();
|
||||
bar_manager.set_invisible((pba_info & 0b111) as u8);
|
||||
bar_manager.set_invisible((table_info & 0b111) as u8);
|
||||
match bar_manager
|
||||
.bar_space_without_invisible((pba_info & 0b111) as u8)
|
||||
.bar((pba_info & 0b111) as u8)
|
||||
.clone()
|
||||
.expect("MSIX cfg:pba BAR is none")
|
||||
{
|
||||
Bar::Memory(memory) => {
|
||||
@ -87,7 +86,8 @@ impl CapabilityMsixData {
|
||||
}
|
||||
};
|
||||
match bar_manager
|
||||
.bar_space_without_invisible((table_info & 0b111) as u8)
|
||||
.bar((table_info & 0b111) as u8)
|
||||
.clone()
|
||||
.expect("MSIX cfg:table BAR is none")
|
||||
{
|
||||
Bar::Memory(memory) => {
|
||||
|
@ -3,7 +3,6 @@
|
||||
//! PCI device common definitions or functions.
|
||||
|
||||
#![expect(dead_code)]
|
||||
#![expect(unused_variables)]
|
||||
|
||||
use alloc::vec::Vec;
|
||||
|
||||
@ -96,19 +95,14 @@ impl PciCommonDevice {
|
||||
/// Base Address Registers manager.
|
||||
#[derive(Debug)]
|
||||
pub struct BarManager {
|
||||
/// BARs, the bool indicate whether this bar should exposed to unprivileged part.
|
||||
bars: [Option<(Bar, bool)>; 6],
|
||||
/// There are at most 6 BARs in PCI device.
|
||||
bars: [Option<Bar>; 6],
|
||||
}
|
||||
|
||||
impl BarManager {
|
||||
/// Gain access to the BAR space and return None if that BAR is set to be invisible or absent.
|
||||
pub fn bar(&self, idx: u8) -> Option<Bar> {
|
||||
let (bar, visible) = self.bars[idx as usize].clone()?;
|
||||
if visible {
|
||||
Some(bar)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
/// Gain access to the BAR space and return None if that BAR is absent.
|
||||
pub fn bar(&self, idx: u8) -> &Option<Bar> {
|
||||
&self.bars[idx as usize]
|
||||
}
|
||||
|
||||
/// Parse the BAR space by PCI device location.
|
||||
@ -133,32 +127,11 @@ impl BarManager {
|
||||
}
|
||||
Bar::Io(_) => {}
|
||||
}
|
||||
bars[idx as usize] = Some((bar, true));
|
||||
bars[idx as usize] = Some(bar);
|
||||
idx += idx_step;
|
||||
}
|
||||
idx += 1;
|
||||
}
|
||||
Self { bars }
|
||||
}
|
||||
|
||||
pub(super) fn set_invisible(&mut self, idx: u8) {
|
||||
if self.bars[idx as usize].is_some() {
|
||||
let Some((bar, _)) = self.bars[idx as usize].clone() else {
|
||||
return;
|
||||
};
|
||||
self.bars[idx as usize] = Some((bar, false));
|
||||
}
|
||||
let Some((_, visible)) = self.bars[idx as usize] else {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
/// Gain access to the BAR space and return None if that BAR is absent.
|
||||
pub(super) fn bar_space_without_invisible(&self, idx: u8) -> Option<Bar> {
|
||||
if let Some((bar, _)) = self.bars[idx as usize].clone() {
|
||||
Some(bar)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user