-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP [dev][virtio][pci] PCI based virtio
Mostly wired up at this point for virtio-block. Interrupts are wired up (non MSI-X) but not seeing any results after submitting a block transfer. Unclear if kick is not working.
- Loading branch information
Showing
18 changed files
with
651 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,5 +91,4 @@ static inline uint arch_curr_cpu_num(void) { | |
#define smp_rmb() CF | ||
#endif | ||
|
||
|
||
#endif // !ASSEMBLY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Fake module that just declares deps on all the PCI drivers in the system. | ||
# | ||
MODULES += dev/bus/pci | ||
|
||
MODULES += dev/net/e1000 | ||
MODULES += dev/virtio/block | ||
MODULES += dev/virtio/net | ||
MODULES += dev/virtio/gpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2024 Travis Geiselbrecht | ||
* | ||
* Use of this source code is governed by a MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <sys/types.h> | ||
|
||
#include <dev/virtio/virtio-bus.h> | ||
|
||
#include <dev/bus/pci.h> | ||
|
||
struct virtio_pci_common_cfg; | ||
|
||
class virtio_pci_bus final : public virtio_bus { | ||
public: | ||
virtio_pci_bus() = default; | ||
~virtio_pci_bus() override = default; | ||
|
||
void virtio_reset_device() override; | ||
void virtio_status_acknowledge_driver() override; | ||
uint32_t virtio_read_host_feature_word(uint32_t word) override; | ||
void virtio_set_guest_features(uint32_t word, uint32_t features) override; | ||
void virtio_status_driver_ok() override; | ||
void virtio_kick(uint16_t ring_index) override; | ||
|
||
void register_ring(uint32_t page_size, uint32_t queue_sel, uint32_t queue_num, uint32_t queue_align, uint32_t queue_pfn) override; | ||
|
||
status_t init(pci_location_t loc, size_t index); | ||
|
||
static handler_return virtio_pci_irq(void *arg); | ||
|
||
volatile virtio_pci_common_cfg *common_config() { | ||
return reinterpret_cast<volatile virtio_pci_common_cfg *>(config_ptr(common_cfg_)); | ||
} | ||
|
||
void *device_config() { | ||
return reinterpret_cast<void *>(config_ptr(device_cfg_)); | ||
} | ||
|
||
//private: | ||
struct config_pointer { | ||
bool valid; | ||
int bar; | ||
size_t offset; | ||
size_t length; | ||
}; | ||
|
||
struct mapped_bars { | ||
bool mapped; | ||
void *vaddr; | ||
}; | ||
|
||
pci_location_t loc_ = {}; | ||
|
||
mapped_bars bar_map_[6] = {}; | ||
|
||
config_pointer common_cfg_ = {}; | ||
config_pointer notify_cfg_ = {}; | ||
config_pointer isr_cfg_ = {}; | ||
config_pointer device_cfg_ = {}; | ||
config_pointer pci_cfg_ = {}; | ||
|
||
uint32_t notify_offset_multiplier_ = {}; | ||
|
||
// TODO: handle MSI-X | ||
uint32_t irq_ = {}; | ||
|
||
void *config_ptr(const config_pointer &cfg) { | ||
if (!cfg.valid) { | ||
return nullptr; | ||
} | ||
|
||
auto &bar = bar_map_[cfg.bar]; | ||
return (void *)((uintptr_t)bar.vaddr + cfg.offset); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.