|
XenevaOS
|
#include <aurora.h>#include <aucon.h>#include "virtioblk.h"#include <audrv.h>#include <pcie.h>#include <Drivers/virtio.h>#include <Mm/vmmngr.h>#include <Hal/AA64/aa64lowlevel.h>#include <Drivers/uart.h>#include <Hal/AA64/gic.h>#include <Mm/pmmngr.h>#include <Mm/dma.h>#include <Fs/vdisk.h>#include <string.h>#include <stdio.h>
Classes | |
| struct | VirtioBLKBuffer |
| struct | VirtioBLKAvail |
| struct | VirtioBLKRing |
| struct | VirtioBLKUsed |
| struct | VirtioBLKQueue |
Macros | |
| #define | VIRTIO_PCI_CAP_ID 0x09 |
| #define | VIRTIO_PCI_CAP_COMMON_CFG 1 |
| #define | VIRTIO_PCI_CAP_DEVICE_CFG 4 |
| #define | VIRTIO_STATUS_ACKNOWLEDGE 1 |
| #define | VIRTIO_STATUS_DRIVER 2 |
| #define | VIRTIO_STATUS_DRIVER_OK 4 |
| #define | VIRTIO_STATUS_FEATURES_OK 8 |
| #define | VIRTIO_F_VERSION_1 (1ull << 32) |
| #define | VIRTQ_DESC_F_NEXT 1 |
| #define | VIRTQ_DESC_F_WRITE 2 |
| #define | VIRTIO_STATUS_ACK 0x01 |
| #define | VIRTIO_STATUS_DRIVER 0x02 |
| #define | VIRTIO_STATUS_DRIVER_OK 0x04 |
| #define | VIRTIO_STATUS_FEATURES_OK 0x08 |
| #define | VIRTIO_STATUS_DEVICE_NEEDS_RESET 0x40 |
| #define | VIRTIO_STATUS_FAILED 0x80 |
| #define | VIRTIO_DEFAULT_SECT_COUNT 1 |
Functions | |
| void | virtioblk_reset (VirtioCommonCfg *cfg) |
| virtioblk_reset – reset the device | |
| void | virtioblk_feature_negotiate (VirtioCommonCfg *cfg) |
| virtioblk_feature_negotiate – check available features of host device and enable only those supported by the driver | |
| void | virtioblk_notify_queu (VirtioCommonCfg *cfg, uint16_t queueIdx) |
| virtioblk_notify_queue – notify host that new command is present | |
| void | virtioblk_interrupt_handler (int spiID) |
| void | virtioblk_alloc_requestQ (VirtioCommonCfg *cfg) |
| virtioblk_alloc_requestQ – allocate requestQ of virtio | |
| bool | virtioblk_read (VirtioCommonCfg *cfg, size_t lba, uint64_t buffer, size_t numSector) |
| virtioblk_read – read data from disc | |
| bool | virtioblk_write (VirtioCommonCfg *cfg, size_t lba, uint64_t buffer, size_t numSector) |
| virtioblk_write – write data to disc | |
| int | virtblk_read_vdisk (AuVDisk *disk, uint64_t lba, uint32_t count, uint64_t *buffer) |
| int | virtblk_write_vdisk (AuVDisk *disk, uint64_t lba, uint32_t count, uint64_t *buffer) |
| AU_EXTERN AU_EXPORT int | AuDriverUnload () |
| AU_EXTERN AU_EXPORT int | AuDriverMain (AuDriver *drv) |
BSD 2-Clause License
Copyright (c) 2022-2026, Manas Kamal Choudhury All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| #define VIRTIO_DEFAULT_SECT_COUNT 1 |
| #define VIRTIO_F_VERSION_1 (1ull << 32) |
| #define VIRTIO_PCI_CAP_COMMON_CFG 1 |
| #define VIRTIO_PCI_CAP_DEVICE_CFG 4 |
| #define VIRTIO_PCI_CAP_ID 0x09 |
| #define VIRTIO_STATUS_ACK 0x01 |
| #define VIRTIO_STATUS_ACKNOWLEDGE 1 |
| #define VIRTIO_STATUS_DEVICE_NEEDS_RESET 0x40 |
| #define VIRTIO_STATUS_DRIVER 2 |
| #define VIRTIO_STATUS_DRIVER 0x02 |
| #define VIRTIO_STATUS_DRIVER_OK 4 |
| #define VIRTIO_STATUS_DRIVER_OK 0x04 |
| #define VIRTIO_STATUS_FAILED 0x80 |
| #define VIRTIO_STATUS_FEATURES_OK 8 |
| #define VIRTIO_STATUS_FEATURES_OK 0x08 |
| #define VIRTQ_DESC_F_NEXT 1 |
| #define VIRTQ_DESC_F_WRITE 2 |
reset the virtio block device
whenever new storage device detected, three kernel objects are needed to create : (1) — VDisk info for read write access (2) — Device file at /dev for ioctl and raw read write without partition overhead, write it to anywhere (3) — File System node after registering partitions
| void virtioblk_alloc_requestQ | ( | VirtioCommonCfg * | cfg | ) |
virtioblk_alloc_requestQ – allocate requestQ of virtio
| void virtioblk_feature_negotiate | ( | VirtioCommonCfg * | cfg | ) |
virtioblk_feature_negotiate – check available features of host device and enable only those supported by the driver
| cfg | – pointer to virtio common config |
| void virtioblk_interrupt_handler | ( | int | spiID | ) |
| void virtioblk_notify_queu | ( | VirtioCommonCfg * | cfg, |
| uint16_t | queueIdx | ||
| ) |
virtioblk_notify_queue – notify host that new command is present
| queueIdx | – queue number, zero for controlq and one for cursorq |
| bool virtioblk_read | ( | VirtioCommonCfg * | cfg, |
| size_t | lba, | ||
| uint64_t | buffer, | ||
| size_t | numSector | ||
| ) |
virtioblk_read – read data from disc
| void virtioblk_reset | ( | VirtioCommonCfg * | cfg | ) |
virtioblk_reset – reset the device
| cfg | – pointer to virtio common config |
| bool virtioblk_write | ( | VirtioCommonCfg * | cfg, |
| size_t | lba, | ||
| uint64_t | buffer, | ||
| size_t | numSector | ||
| ) |
virtioblk_write – write data to disc