MCPcopy Create free account
hub / github.com/Ruddle/Fomos / init

Method init

bootloader/kernel/src/virtio.rs:82–477  ·  view source on GitHub ↗
(
        pci: &Pci,

        mapper: &mut impl Mapper<Size4KiB>,
        frame_allocator: &mut impl FrameAllocator<Size4KiB>,
    )

Source from the content-addressed store, hash-verified

80
81impl Virtio {
82 pub fn init(
83 pci: &Pci,
84
85 mapper: &mut impl Mapper<Size4KiB>,
86 frame_allocator: &mut impl FrameAllocator<Size4KiB>,
87 ) -> Option<Self> {
88 let device_id =
89 pci.config_read_u16(pci::PCIConfigRegisters::PCIDeviceID as u8) as isize - 0x1040;
90
91 let device_type = device_id_to_type(device_id);
92 if device_type.is_none() {
93 return None;
94 }
95 let device_type = device_type.unwrap();
96
97 let mut bars = [Bar::None; 6];
98 for idx in 0..=5 {
99 let bar = pci.get_bar(idx);
100 if bar != Bar::None {
101 // log::info!("bar {}:{:?}", idx, bar);
102 }
103 bars[idx as usize] = bar;
104 }
105
106 let cap_ptr = pci.config_read_u8(pci::PCIConfigRegisters::PCICapabilitiesPointer as u8);
107
108 let mut current_off = cap_ptr;
109 const VirtioStatusNone: u8 = 0;
110 const VirtioStatusAcknowledge: u8 = 1;
111 const VirtioStatusDriver: u8 = 2;
112 const VirtioStatusFailed: u8 = 128;
113 const VirtioStatusFeatureOk: u8 = 8;
114 const VirtioStatusDriverOk: u8 = 4;
115 const VirtioStatusNeedsReset: u8 = 64;
116
117 let mut common: Option<VirtioCap<&'static mut VirtioPciCommonCfg>> = None;
118 let mut device: Option<VirtioCap<&'static mut ()>> = None;
119 let mut notify: Option<VirtioCap<u32>> = None;
120 let mut pci_conf: Option<VirtioCap<[u8; 4]>> = None;
121 loop {
122 let cap = pci.config_read_u8(current_off);
123
124 //VIRTIO
125 if cap == 0x9 {
126 let cap_len = pci.config_read_u8(current_off + 2);
127 let cfg_type = pci.config_read_u8(current_off + 3);
128 let bar = pci.config_read_u8(current_off + 4);
129 let offset = pci.config_read_u32(current_off + 8);
130 let length = pci.config_read_u32(current_off + 12);
131
132 // log::info!(
133 // "virtio {} {} {} {} {}",
134 // cap_len,
135 // cfg_type,
136 // bar,
137 // offset,
138 // length
139 // );

Callers

nothing calls this directly

Calls 8

device_id_to_typeFunction · 0.85
phys_to_virtFunction · 0.85
config_read_u16Method · 0.80
get_barMethod · 0.80
config_read_u8Method · 0.80
config_read_u32Method · 0.80
queue_selectMethod · 0.80

Tested by

no test coverage detected