File tree Expand file tree Collapse file tree 2 files changed +22
-17
lines changed Expand file tree Collapse file tree 2 files changed +22
-17
lines changed Original file line number Diff line number Diff line change @@ -172,19 +172,19 @@ pub extern "C" fn _start() -> ! {
172
172
173
173
pci:: print_bus ( ) ;
174
174
175
- let mut pci_transport ;
176
- let mut mmio_transport ;
177
-
178
- let mut device = if let Some ( pci_device) =
179
- pci:: search_bus ( VIRTIO_PCI_VENDOR_ID , VIRTIO_PCI_BLOCK_DEVICE_ID )
180
- {
181
- pci_transport = pci :: VirtioPciTransport :: new ( pci_device ) ;
182
- block :: VirtioBlockDevice :: new ( & mut pci_transport )
183
- } else {
184
- mmio_transport = mmio :: VirtioMMIOTransport :: new ( 0xd000_0000u64 ) ;
185
- block :: VirtioBlockDevice :: new ( & mut mmio_transport )
186
- } ;
187
-
175
+ pci :: with_devices (
176
+ VIRTIO_PCI_VENDOR_ID ,
177
+ VIRTIO_PCI_BLOCK_DEVICE_ID ,
178
+ | pci_device| {
179
+ let mut pci_transport = pci:: VirtioPciTransport :: new ( pci_device ) ;
180
+ block :: VirtioBlockDevice :: new ( & mut pci_transport ) ;
181
+ let mut device = block :: VirtioBlockDevice :: new ( & mut pci_transport ) ;
182
+ boot_from_device ( & mut device )
183
+ } ,
184
+ ) ;
185
+
186
+ let mut mmio_transport = mmio :: VirtioMMIOTransport :: new ( 0xd000_0000u64 ) ;
187
+ let mut device = block :: VirtioBlockDevice :: new ( & mut mmio_transport ) ;
188
188
boot_from_device ( & mut device) ;
189
189
190
190
#[ allow( clippy:: empty_loop) ]
Original file line number Diff line number Diff line change @@ -90,14 +90,19 @@ pub fn print_bus() {
90
90
}
91
91
92
92
#[ cfg( not( test) ) ]
93
- pub fn search_bus ( target_vendor_id : u16 , target_device_id : u16 ) -> Option < PciDevice > {
93
+ pub fn with_devices < F > ( target_vendor_id : u16 , target_device_id : u16 , per_device : F )
94
+ where
95
+ F : Fn ( PciDevice ) -> bool ,
96
+ {
94
97
for device in 0 ..MAX_DEVICES {
95
98
let ( vendor_id, device_id) = get_device_details ( 0 , device, 0 ) ;
96
- if vendor_id == target_vendor_id && device_id == target_device_id {
97
- return Some ( PciDevice :: new ( 0 , device, 0 ) ) ;
99
+ if vendor_id == target_vendor_id
100
+ && device_id == target_device_id
101
+ && per_device ( PciDevice :: new ( 0 , device, 0 ) )
102
+ {
103
+ break ;
98
104
}
99
105
}
100
- None
101
106
}
102
107
103
108
#[ cfg( not( test) ) ]
You can’t perform that action at this time.
0 commit comments