@@ -134,23 +134,18 @@ Virtio::Virtio(hw::PCI_Device& dev)
134134 }
135135
136136 INFO (" Virtio" , " Initialization complete" );
137-
138- // It would be nice if we new that all queues were the same size.
139- // Then we could pass this size on to the device-specific constructor
140- // But, it seems there aren't any guarantees in the standard.
141-
142- // @note this is "the Legacy interface" according to Virtio std. 4.1.4.8.
143- // uint32_t queue_size = hw::inpd(_iobase + 0x0C);
144137}
145138
146- void Virtio::get_config (void * buf, int len){
139+ void Virtio::get_config (void * buf, int len)
140+ {
147141 // io addr is different when MSI-X is enabled
148142 uint32_t ioaddr = _iobase;
149143 ioaddr += (has_msix ()) ? VIRTIO_PCI_CONFIG_MSIX : VIRTIO_PCI_CONFIG;
150144
151145 uint8_t * ptr = (uint8_t *) buf;
152- for (int i = 0 ; i < len; i++)
146+ for (int i = 0 ; i < len; i++) {
153147 ptr[i] = hw::inp (ioaddr + i);
148+ }
154149}
155150
156151
@@ -162,7 +157,7 @@ uint8_t Virtio::get_legacy_irq()
162157{
163158 // Get legacy IRQ from PCI
164159 uint32_t value = _pcidev.read_dword (PCI::CONFIG_INTR);
165- if ((value & 0xFF ) > 0 && (value & 0xFF ) < 32 ) {
160+ if ((value & 0xFF ) != 0xFF ) {
166161 return value & 0xFF ;
167162 }
168163 return 0 ;
@@ -173,7 +168,6 @@ uint32_t Virtio::queue_size(uint16_t index) {
173168 return hw::inpw (iobase () + VIRTIO_PCI_QUEUE_SIZE);
174169}
175170
176- #define BTOP (x ) ((unsigned long )(x) >> PAGESHIFT)
177171bool Virtio::assign_queue (uint16_t index, const void * queue_desc)
178172{
179173 hw::outpw (iobase () + VIRTIO_PCI_QUEUE_SEL, index);
@@ -196,20 +190,12 @@ uint32_t Virtio::probe_features() {
196190}
197191
198192void Virtio::negotiate_features (uint32_t features) {
199- _features = hw::inpd (_iobase + VIRTIO_PCI_HOST_FEATURES);
200- // _features &= features; //SanOS just adds features
201- _features = features;
202- debug (" <Virtio> Wanted features: 0x%lx \n " ,_features);
193+ // _features = hw::inpd(_iobase + VIRTIO_PCI_HOST_FEATURES);
194+ this ->_features = features;
195+ debug (" <Virtio> Wanted features: 0x%lx \n " , _features);
203196 hw::outpd (_iobase + VIRTIO_PCI_GUEST_FEATURES, _features);
204197 _features = probe_features ();
205198 debug (" <Virtio> Got features: 0x%lx \n " ,_features);
206-
207- }
208-
209- void Virtio::setup_complete (bool ok) {
210- uint8_t status = ok ? VIRTIO_CONFIG_S_DRIVER_OK : VIRTIO_CONFIG_S_FAILED;
211- debug (" <VIRTIO> status: %i " ,status);
212- hw::outp (_iobase + VIRTIO_PCI_STATUS, hw::inp (_iobase + VIRTIO_PCI_STATUS) | status);
213199}
214200
215201void Virtio::move_to_this_cpu ()
@@ -232,3 +218,13 @@ void Virtio::move_to_this_cpu()
232218 }
233219 }
234220}
221+
222+ void Virtio::setup_complete (bool ok)
223+ {
224+ uint8_t value = hw::inp (_iobase + VIRTIO_PCI_STATUS);
225+ value |= ok ? VIRTIO_CONFIG_S_DRIVER_OK : VIRTIO_CONFIG_S_FAILED;
226+ if (!ok) {
227+ INFO (" Virtio" , " Setup failed, status: %hhx" , value);
228+ }
229+ hw::outp (_iobase + VIRTIO_PCI_STATUS, value);
230+ }
0 commit comments