mirror of
https://github.com/StepanovPlaton/OSin1000Lines.git
synced 2026-04-03 20:30:46 +04:00
Disk I/O
This commit is contained in:
73
src/kernel.h
73
src/kernel.h
@@ -75,6 +75,79 @@ struct process *idle_proc;
|
||||
#define PAGE_X (1 << 3)
|
||||
#define PAGE_U (1 << 4)
|
||||
|
||||
// ===== Disk I/O =====
|
||||
#define SECTOR_SIZE 512
|
||||
#define VIRTQ_ENTRY_NUM 16
|
||||
#define VIRTIO_DEVICE_BLK 2
|
||||
#define VIRTIO_BLK_PADDR 0x10001000
|
||||
#define VIRTIO_REG_MAGIC 0x00
|
||||
#define VIRTIO_REG_VERSION 0x04
|
||||
#define VIRTIO_REG_DEVICE_ID 0x08
|
||||
#define VIRTIO_REG_QUEUE_SEL 0x30
|
||||
#define VIRTIO_REG_QUEUE_NUM_MAX 0x34
|
||||
#define VIRTIO_REG_QUEUE_NUM 0x38
|
||||
#define VIRTIO_REG_QUEUE_ALIGN 0x3c
|
||||
#define VIRTIO_REG_QUEUE_PFN 0x40
|
||||
#define VIRTIO_REG_QUEUE_READY 0x44
|
||||
#define VIRTIO_REG_QUEUE_NOTIFY 0x50
|
||||
#define VIRTIO_REG_DEVICE_STATUS 0x70
|
||||
#define VIRTIO_REG_DEVICE_CONFIG 0x100
|
||||
#define VIRTIO_STATUS_ACK 1
|
||||
#define VIRTIO_STATUS_DRIVER 2
|
||||
#define VIRTIO_STATUS_DRIVER_OK 4
|
||||
#define VIRTIO_STATUS_FEAT_OK 8
|
||||
#define VIRTQ_DESC_F_NEXT 1
|
||||
#define VIRTQ_DESC_F_WRITE 2
|
||||
#define VIRTQ_AVAIL_F_NO_INTERRUPT 1
|
||||
#define VIRTIO_BLK_T_IN 0
|
||||
#define VIRTIO_BLK_T_OUT 1
|
||||
|
||||
struct virtq_desc {
|
||||
uint64_t addr;
|
||||
uint32_t len;
|
||||
uint16_t flags;
|
||||
uint16_t next;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct virtq_avail {
|
||||
uint16_t flags;
|
||||
uint16_t index;
|
||||
uint16_t ring[VIRTQ_ENTRY_NUM];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct virtq_used_elem {
|
||||
uint32_t id;
|
||||
uint32_t len;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct virtq_used {
|
||||
uint16_t flags;
|
||||
uint16_t index;
|
||||
struct virtq_used_elem ring[VIRTQ_ENTRY_NUM];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct virtio_virtq {
|
||||
struct virtq_desc descs[VIRTQ_ENTRY_NUM];
|
||||
struct virtq_avail avail;
|
||||
struct virtq_used used __attribute__((aligned(PAGE_SIZE)));
|
||||
int queue_index;
|
||||
volatile uint16_t *used_index;
|
||||
uint16_t last_used_index;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct virtio_blk_req {
|
||||
uint32_t type;
|
||||
uint32_t reserved;
|
||||
uint64_t sector;
|
||||
uint8_t data[512];
|
||||
uint8_t status;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct virtio_virtq *blk_request_vq;
|
||||
struct virtio_blk_req *blk_req;
|
||||
paddr_t blk_req_paddr;
|
||||
unsigned blk_capacity;
|
||||
|
||||
// ===== Macros =====
|
||||
#define READ_CSR(reg) \
|
||||
({ \
|
||||
|
||||
Reference in New Issue
Block a user