XenevaOS
Loading...
Searching...
No Matches
Macros | Functions
virtioblk.cpp File Reference
#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>
Include dependency graph for virtioblk.cpp:

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
 

Functions

AU_EXTERN AU_EXPORT int AuDriverUnload ()
 
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 AuDriverMain (AuDriver *drv)
 

Detailed Description

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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

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.

Macro Definition Documentation

◆ VIRTIO_F_VERSION_1

#define VIRTIO_F_VERSION_1   (1ull << 32)

◆ VIRTIO_PCI_CAP_COMMON_CFG

#define VIRTIO_PCI_CAP_COMMON_CFG   1

◆ VIRTIO_PCI_CAP_DEVICE_CFG

#define VIRTIO_PCI_CAP_DEVICE_CFG   4

◆ VIRTIO_PCI_CAP_ID

#define VIRTIO_PCI_CAP_ID   0x09

◆ VIRTIO_STATUS_ACKNOWLEDGE

#define VIRTIO_STATUS_ACKNOWLEDGE   1

◆ VIRTIO_STATUS_DRIVER

#define VIRTIO_STATUS_DRIVER   2

◆ VIRTIO_STATUS_DRIVER_OK

#define VIRTIO_STATUS_DRIVER_OK   4

◆ VIRTIO_STATUS_FEATURES_OK

#define VIRTIO_STATUS_FEATURES_OK   8

◆ VIRTQ_DESC_F_NEXT

#define VIRTQ_DESC_F_NEXT   1

◆ VIRTQ_DESC_F_WRITE

#define VIRTQ_DESC_F_WRITE   2

Function Documentation

◆ AuDriverMain()

AU_EXTERN AU_EXPORT int AuDriverMain ( AuDriver drv)

reset the virtio block device

◆ AuDriverUnload()

AU_EXTERN AU_EXPORT int AuDriverUnload ( )

◆ virtblk_read_vdisk()

int virtblk_read_vdisk ( AuVDisk disk,
uint64_t  lba,
uint32_t  count,
uint64_t buffer 
)

◆ virtblk_write_vdisk()

int virtblk_write_vdisk ( AuVDisk disk,
uint64_t  lba,
uint32_t  count,
uint64_t buffer 
)

◆ virtioblk_alloc_requestQ()

void virtioblk_alloc_requestQ ( VirtioCommonCfg cfg)

virtioblk_alloc_requestQ – allocate requestQ of virtio

◆ virtioblk_feature_negotiate()

void virtioblk_feature_negotiate ( VirtioCommonCfg cfg)

virtioblk_feature_negotiate – check available features of host device and enable only those supported by the driver

Parameters
cfg– pointer to virtio common config

◆ virtioblk_interrupt_handler()

void virtioblk_interrupt_handler ( int  spiID)

◆ virtioblk_notify_queu()

void virtioblk_notify_queu ( VirtioCommonCfg cfg,
uint16_t  queueIdx 
)

virtioblk_notify_queue – notify host that new command is present

Parameters
queueIdx– queue number, zero for controlq and one for cursorq

◆ virtioblk_read()

bool virtioblk_read ( VirtioCommonCfg cfg,
size_t  lba,
uint64_t  buffer,
size_t  numSector 
)

virtioblk_read – read data from disc

◆ virtioblk_reset()

void virtioblk_reset ( VirtioCommonCfg cfg)

virtioblk_reset – reset the device

Parameters
cfg– pointer to virtio common config

◆ virtioblk_write()

bool virtioblk_write ( VirtioCommonCfg cfg,
size_t  lba,
uint64_t  buffer,
size_t  numSector 
)

virtioblk_write – write data to disc