18 "device at %d:%d:%d has virtio "
19 "flag but no capability",
20 pci->pci_bus,
pci->pci_dev,
pci->pci_func);
29 auto next_ptr =
pci_read8(pci_bus, pci_dev, pci_func, virtio_cap + 1);
30 auto cap_type =
pci_read8(pci_bus, pci_dev, pci_func, virtio_cap + 3);
31 auto bar =
pci_read8(pci_bus, pci_dev, pci_func, virtio_cap + 4);
35 " virtio cap type %d len %d bar %d "
43 pci_read32(pci_bus, pci_dev, pci_func, virtio_cap + 12);
46 virtio_common_cap->
bar =
bar;
47 virtio_common_cap->offset =
offset;
48 virtio_common_cap->length = multiplier;
50 virtio_common_cap->cap_next = next_ptr;
55 pci_read32(pci_bus, pci_dev, pci_func, virtio_cap + 12);
57 virtio_notify_cap->
bar =
bar;
58 virtio_notify_cap->offset =
offset;
59 virtio_notify_cap->length = multiplier;
61 virtio_notify_cap->cap_next = next_ptr;
66 pci_read32(pci_bus, pci_dev, pci_func, virtio_cap + 12);
67 auto virtio_isr_cap = &v->
isr_cfg;
69 virtio_isr_cap->offset =
offset;
70 virtio_isr_cap->length = multiplier;
72 virtio_isr_cap->cap_next = next_ptr;
88 LOG2_INFO(
"VIRTIO",
"found virtio device at %d:%d:%d",
89 pci->pci_bus,
pci->pci_dev,
pci->pci_func);
93 sizeof(*virtio_device));
94 memset(virtio_device, 0,
sizeof(*virtio_device));
99 auto cap_ptr =
pci->capability_ptr;
104 while (cap_ptr != 0 && cap_ptr >= 0x40
105 && cap_ptr <= 0xFF) {
107 bus,
device, func, cap_ptr);
109 bus,
device, func, cap_ptr + 1);
126 "Missing required VirtIO capabilities");
127 kfree(virtio_device,
sizeof(*virtio_device));
128 goto for_each_virtio_next;
136 || virtio_device->
pci.
bar[common_bar]
140 "Invalid common config BAR: %d",
149 || virtio_device->
pci.
bar[notify_bar]
152 "Invalid notify BAR: %d",
161 || virtio_device->
pci.
bar[isr_bar]
164 "Invalid ISR BAR: %d",
190 "scanning for virtio devices under PCI root at 0x%x",
static struct ioforge_device * pci_root
struct ioforge_device * ioforge_get_root()
void ioforge_attach(struct ioforge_device *parent, struct ioforge_device *child)
struct ioforge_device * ioforge_get_pci_root()
struct ioforge_pci_device pci
void kfree(void *ptr, size_t size)
void * kalloc(size_t size)
uint8_t pci_read8(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
uint32_t pci_read32(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
#define LOG2_WARN(mod, fmt,...)
#define LOG2_ERROR(mod, fmt,...)
#define LOG2_INFO(mod, fmt,...)
void strcpy(char *dest, const char *src)
void memset(void *ptr, int value, size_t num)
void memcopy(void *dest, void *src, size_t size)
struct ioforge_device * first_child
struct ioforge_device * next_sibling
struct ioforge_pci_bar bar[6]
struct ioforge_device base
struct ioforge_pci_device pci
struct virtio_pci_cap notify_cfg
struct virtio_pci_cap isr_cfg
struct virtio_pci_cap common_cfg
static void for_each_virtio_device(struct ioforge_device *node)
struct ioforge_device * virtio_root
static void virtio_scan_capabilities(struct ioforge_pci_device *pci, uint16_t virtio_cap, struct ioforge_virtio_device *v)
struct ioforge_virtio_device * find_virtio_device_by_id(uint16_t vendor_id, uint16_t device_id)
#define VIRTIO_PCI_CAP_ISR_CFG
#define VIRTIO_PCI_CAP_NOTIFY_CFG
#define VIRTIO_PCI_CAP_COMMON_CFG