Skip to content

Commit ffe224e

Browse files
committed
Define virtio-net header
- Define `VIRTIO_NET_IRQ` macro for the `notify_used` virtq callback function to send IRQ - Define `VIRTIO_PCI_DEVICE_ID_NET` (0x1041) according to the Virtio 1.1 specification - Define `VIRTIO_NET_PCI_CLASS` macro according to the PCI specification with class code (0x020000) for Ethernet Controller - Define struct `virtio_net_dev` and operation functions for the virtio-net device
1 parent 6aebede commit ffe224e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/arch/x86/desc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
#define RAM_BASE 0
44
#define SERIAL_IRQ 4
5+
#define VIRTIO_NET_IRQ 14
56
#define VIRTIO_BLK_IRQ 15
67
#define KERNEL_OPTS "console=ttyS0 pci=conf1"

src/virtio-net.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <linux/virtio_net.h>
4+
#include "pci.h"
5+
#include "virtio-pci.h"
6+
#include "virtq.h"
7+
8+
#define VIRTIO_NET_VIRTQ_NUM 2
9+
#define VIRTIO_NET_PCI_CLASS 0x020000
10+
11+
struct virtio_net_dev {
12+
struct virtio_pci_dev virtio_pci_dev;
13+
struct virtio_net_config config;
14+
struct virtq vq[VIRTIO_NET_VIRTQ_NUM];
15+
int tapfd;
16+
int irqfd;
17+
int rx_ioeventfd;
18+
int tx_ioeventfd;
19+
int irq_num;
20+
pthread_t rx_thread;
21+
pthread_t tx_thread;
22+
bool enable;
23+
};
24+
25+
bool virtio_net_init(struct virtio_net_dev *virtio_net_dev);
26+
void virtio_net_exit(struct virtio_net_dev *virtio_net_dev);
27+
void virtio_net_init_pci(struct virtio_net_dev *virtio_net_dev,
28+
struct pci *pci,
29+
struct bus *io_bus,
30+
struct bus *mmio_bus);

src/virtio-pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "virtq.h"
77

88
#define VIRTIO_PCI_VENDOR_ID 0x1AF4
9+
#define VIRTIO_PCI_DEVICE_ID_NET 0x1041
910
#define VIRTIO_PCI_DEVICE_ID_BLK 0x1042
1011
#define VIRTIO_PCI_CAP_NUM 5
1112
#define VIRTIO_PCI_ISR_QUEUE 1

0 commit comments

Comments
 (0)