Fixed PCI bus scan to scan bus 0xFF.
Previously, the PCI bus scan was skipping bus 0xFF. Now it does not. I used a match expression to make sure that all cases are accounted for. I also changed the PCI dev scan and PCI func scan to use a match expression in a similar way to make sure all cases are account. While this is functionally the same as before, the match expression will not allow unhandled cases and should be easier to read and make it harder to introduce bugs. Signed-off-by: Wren Turkal <wt@penguintechs.org>
This commit is contained in:
+11
-10
@@ -20,7 +20,7 @@ impl<'pci> PciBus<'pci> {
|
||||
|
||||
pub struct PciBusIter<'pci> {
|
||||
bus: &'pci PciBus<'pci>,
|
||||
num: u32
|
||||
num: u8
|
||||
}
|
||||
|
||||
impl<'pci> PciBusIter<'pci> {
|
||||
@@ -35,15 +35,16 @@ impl<'pci> PciBusIter<'pci> {
|
||||
impl<'pci> Iterator for PciBusIter<'pci> {
|
||||
type Item = PciDev<'pci>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.num < 32 {
|
||||
let dev = PciDev {
|
||||
bus: self.bus,
|
||||
num: self.num as u8
|
||||
};
|
||||
self.num += 1;
|
||||
Some(dev)
|
||||
} else {
|
||||
None
|
||||
match self.num {
|
||||
dev_num if dev_num < 32 => {
|
||||
let dev = PciDev {
|
||||
bus: self.bus,
|
||||
num: self.num
|
||||
};
|
||||
self.num += 1;
|
||||
Some(dev)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-10
@@ -20,7 +20,7 @@ impl<'pci> PciDev<'pci> {
|
||||
|
||||
pub struct PciDevIter<'pci> {
|
||||
dev: &'pci PciDev<'pci>,
|
||||
num: u32
|
||||
num: u8
|
||||
}
|
||||
|
||||
impl<'pci> PciDevIter<'pci> {
|
||||
@@ -35,15 +35,16 @@ impl<'pci> PciDevIter<'pci> {
|
||||
impl<'pci> Iterator for PciDevIter<'pci> {
|
||||
type Item = PciFunc<'pci>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.num < 8 {
|
||||
let func = PciFunc {
|
||||
dev: self.dev,
|
||||
num: self.num as u8
|
||||
};
|
||||
self.num += 1;
|
||||
Some(func)
|
||||
} else {
|
||||
None
|
||||
match self.num {
|
||||
func_num if func_num < 8 => {
|
||||
let func = PciFunc {
|
||||
dev: self.dev,
|
||||
num: self.num
|
||||
};
|
||||
self.num += 1;
|
||||
Some(func)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -106,14 +106,14 @@ impl CfgAccess for Pci {
|
||||
|
||||
pub struct PciIter<'pci> {
|
||||
pci: &'pci dyn CfgAccess,
|
||||
num: u32
|
||||
num: Option<u8>
|
||||
}
|
||||
|
||||
impl<'pci> PciIter<'pci> {
|
||||
pub fn new(pci: &'pci dyn CfgAccess) -> Self {
|
||||
PciIter {
|
||||
pci,
|
||||
num: 0
|
||||
num: Some(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,15 +121,16 @@ impl<'pci> PciIter<'pci> {
|
||||
impl<'pci> Iterator for PciIter<'pci> {
|
||||
type Item = PciBus<'pci>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.num < 255 { /* TODO: Do not ignore 0xFF bus */
|
||||
let bus = PciBus {
|
||||
pci: self.pci,
|
||||
num: self.num as u8
|
||||
};
|
||||
self.num += 1;
|
||||
Some(bus)
|
||||
} else {
|
||||
None
|
||||
match self.num {
|
||||
Some(bus_num) => {
|
||||
let bus = PciBus {
|
||||
pci: self.pci,
|
||||
num: bus_num
|
||||
};
|
||||
self.num = bus_num.checked_add(1);
|
||||
Some(bus)
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user