Skip to content

Commit

Permalink
CI style
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Chan <[email protected]>
  • Loading branch information
erichchan999 committed Oct 24, 2024
1 parent 2b94cff commit 8bb4870
Show file tree
Hide file tree
Showing 6 changed files with 1,083 additions and 1,000 deletions.
54 changes: 26 additions & 28 deletions examples/virtio/client_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,35 @@ blk_storage_info_t *blk_storage_info;

static struct virtio_blk_device virtio_blk;

_Static_assert(BLK_DATA_REGION_SIZE_CLI0 >= BLK_TRANSFER_SIZE && BLK_DATA_REGION_SIZE_CLI0 % BLK_TRANSFER_SIZE == 0,
"Client0 data region size must be a multiple of the transfer size");
_Static_assert(BLK_DATA_REGION_SIZE_CLI1 >= BLK_TRANSFER_SIZE && BLK_DATA_REGION_SIZE_CLI1 % BLK_TRANSFER_SIZE == 0,
"Client1 data region size must be a multiple of the transfer size");
_Static_assert(
BLK_DATA_REGION_SIZE_CLI0 >= BLK_TRANSFER_SIZE &&
BLK_DATA_REGION_SIZE_CLI0 % BLK_TRANSFER_SIZE == 0,
"Client0 data region size must be a multiple of the transfer size");
_Static_assert(
BLK_DATA_REGION_SIZE_CLI1 >= BLK_TRANSFER_SIZE &&
BLK_DATA_REGION_SIZE_CLI1 % BLK_TRANSFER_SIZE == 0,
"Client1 data region size must be a multiple of the transfer size");

void init(void)
{
/* Busy wait until blk device is ready */
while (!blk_storage_is_ready(blk_storage_info))
;

/* Initialise the VMM, the VCPU(s), and start the guest */
LOG_VMM("starting \"%s\"\n", microkit_name);
/* Place all the binaries in the right locations before starting the guest */
size_t kernel_size = _guest_kernel_image_end - _guest_kernel_image;
size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image;
size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image;
uintptr_t kernel_pc = linux_setup_images(guest_ram_vaddr,
(uintptr_t) _guest_kernel_image,
kernel_size,
(uintptr_t) _guest_dtb_image,
GUEST_DTB_VADDR,
dtb_size,
(uintptr_t) _guest_initrd_image,
GUEST_INIT_RAM_DISK_VADDR,
initrd_size
);
if (!kernel_pc) {
LOG_VMM_ERR("Failed to initialise guest images\n");
return;
}
/* Initialise the VMM, the VCPU(s), and start the guest */
LOG_VMM("starting \"%s\"\n", microkit_name);
/* Place all the binaries in the right locations before starting the guest */
size_t kernel_size = _guest_kernel_image_end - _guest_kernel_image;
size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image;
size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image;
uintptr_t kernel_pc = linux_setup_images(
guest_ram_vaddr, (uintptr_t)_guest_kernel_image, kernel_size,
(uintptr_t)_guest_dtb_image, GUEST_DTB_VADDR, dtb_size,
(uintptr_t)_guest_initrd_image, GUEST_INIT_RAM_DISK_VADDR, initrd_size);
if (!kernel_pc) {
LOG_VMM_ERR("Failed to initialise guest images\n");
return;
}

/* Initialise the virtual GIC driver */
bool success = virq_controller_init(GUEST_VCPU_ID);
Expand Down Expand Up @@ -134,10 +132,10 @@ void init(void)
blk_cli_queue_capacity(microkit_name));

/* Initialise virtIO block device */
success = virtio_mmio_blk_init(&virtio_blk, VIRTIO_BLK_BASE,
VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ, blk_data,
BLK_DATA_SIZE, blk_storage_info, &blk_queue_h,
blk_cli_queue_capacity(microkit_name), BLK_CH);
success = virtio_mmio_blk_init(
&virtio_blk, VIRTIO_BLK_BASE, VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ, blk_data,
BLK_DATA_SIZE, blk_storage_info, &blk_queue_h,
blk_cli_queue_capacity(microkit_name), BLK_CH);
assert(success);

/* Finally start the guest */
Expand Down
38 changes: 20 additions & 18 deletions examples/virtio/include/blk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#define BLK_NAME_CLI0 "CLIENT_VMM-1"
#define BLK_NAME_CLI1 "CLIENT_VMM-2"

#define BLK_QUEUE_CAPACITY_CLI0 1024
#define BLK_QUEUE_CAPACITY_CLI1 1024
#define BLK_QUEUE_CAPACITY_DRIV (BLK_QUEUE_CAPACITY_CLI0 + BLK_QUEUE_CAPACITY_CLI1)
#define BLK_QUEUE_CAPACITY_CLI0 1024
#define BLK_QUEUE_CAPACITY_CLI1 1024
#define BLK_QUEUE_CAPACITY_DRIV \
(BLK_QUEUE_CAPACITY_CLI0 + BLK_QUEUE_CAPACITY_CLI1)

#define BLK_REGION_SIZE 0x200000
#define BLK_REGION_SIZE 0x200000
#define BLK_DATA_REGION_SIZE_CLI0 BLK_REGION_SIZE
#define BLK_DATA_REGION_SIZE_CLI1 BLK_REGION_SIZE
#define BLK_DATA_REGION_SIZE_DRIV BLK_REGION_SIZE
Expand All @@ -30,16 +31,17 @@

static const int blk_partition_mapping[BLK_NUM_CLIENTS] = { 0, 1 };

static inline blk_storage_info_t *blk_virt_cli_storage_info(blk_storage_info_t *info, unsigned int id)
{
switch (id) {
case 0:
return info;
case 1:
return (blk_storage_info_t *)((uintptr_t)info + BLK_STORAGE_INFO_REGION_SIZE);
default:
return NULL;
}
static inline blk_storage_info_t *
blk_virt_cli_storage_info(blk_storage_info_t *info, unsigned int id) {
switch (id) {
case 0:
return info;
case 1:
return (blk_storage_info_t *)((uintptr_t)info +
BLK_STORAGE_INFO_REGION_SIZE);
default:
return NULL;
}
}

static inline uintptr_t blk_virt_cli_data_region(uintptr_t data, unsigned int id)
Expand Down Expand Up @@ -94,9 +96,9 @@ static inline uint32_t blk_virt_cli_queue_capacity(unsigned int id)
{
switch (id) {
case 0:
return BLK_QUEUE_CAPACITY_CLI0;
return BLK_QUEUE_CAPACITY_CLI0;
case 1:
return BLK_QUEUE_CAPACITY_CLI1;
return BLK_QUEUE_CAPACITY_CLI1;
default:
return 0;
}
Expand All @@ -105,9 +107,9 @@ static inline uint32_t blk_virt_cli_queue_capacity(unsigned int id)
static inline uint32_t blk_cli_queue_capacity(char *pd_name)
{
if (!sddf_strcmp(pd_name, BLK_NAME_CLI0)) {
return BLK_QUEUE_CAPACITY_CLI0;
return BLK_QUEUE_CAPACITY_CLI0;
} else if (!sddf_strcmp(pd_name, BLK_NAME_CLI1)) {
return BLK_QUEUE_CAPACITY_CLI1;
return BLK_QUEUE_CAPACITY_CLI1;
} else {
return 0;
}
Expand Down
87 changes: 42 additions & 45 deletions include/libvmm/virtio/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,56 +150,53 @@ struct virtio_blk_outhdr {
* virtio response from sddf response.
*/
typedef struct reqbk {
// /* For writing response byte in virtio descriptor */
// uint8_t *virtio_resp_byte;
/* Descriptor head of the virtio request */
uint16_t virtio_desc_head;
/* For enqueuing sddf req/resp */
uintptr_t sddf_data_cell_base;
uint16_t sddf_count;
uint32_t sddf_block_number;
uintptr_t sddf_data;
/* The size of data contained in virtio request */
uint32_t virtio_body_size_bytes;
/* Indicates this request is an unaligned write from virtIO. When not true,
* this request is the "read" part of the read-modify-write. A subsequent
* write request will be enqueued to complete the read-modify-write.
*/
bool aligned;
// /* For writing response byte in virtio descriptor */
// uint8_t *virtio_resp_byte;
/* Descriptor head of the virtio request */
uint16_t virtio_desc_head;
/* For enqueuing sddf req/resp */
uintptr_t sddf_data_cell_base;
uint16_t sddf_count;
uint32_t sddf_block_number;
uintptr_t sddf_data;
/* The size of data contained in virtio request */
uint32_t virtio_body_size_bytes;
/* Indicates this request is an unaligned write from virtIO. When not true,
* this request is the "read" part of the read-modify-write. A subsequent
* write request will be enqueued to complete the read-modify-write.
*/
bool aligned;
} reqbk_t;

struct virtio_blk_device {
struct virtio_device virtio_device;
struct virtio_blk_config config;
struct virtio_queue_handler vqs[VIRTIO_BLK_NUM_VIRTQ];
/* Request bookkeep indexed by the request id */
reqbk_t reqsbk[SDDF_MAX_QUEUE_CAPACITY];
/* Data struct that handles allocation and freeing of fixed size data cells
* in sDDF memory region */
fsmalloc_t fsmalloc;
bitarray_t fsmalloc_avail_bitarr;
word_t fsmalloc_avail_bitarr_words[roundup_bits2words64(SDDF_MAX_DATA_CELLS)];
/* Index allocator for sddf request ids */
ialloc_t ialloc;
uint32_t ialloc_idxlist[SDDF_MAX_QUEUE_CAPACITY];
/* Sddf structures */
blk_storage_info_t *storage_info;
blk_queue_handle_t queue_h;
uint32_t queue_capacity;
uintptr_t data_region;
/* Channel to notify microkit component serving this client */
int server_ch;
struct virtio_device virtio_device;
struct virtio_blk_config config;
struct virtio_queue_handler vqs[VIRTIO_BLK_NUM_VIRTQ];
/* Request bookkeep indexed by the request id */
reqbk_t reqsbk[SDDF_MAX_QUEUE_CAPACITY];
/* Data struct that handles allocation and freeing of fixed size data cells
* in sDDF memory region */
fsmalloc_t fsmalloc;
bitarray_t fsmalloc_avail_bitarr;
word_t fsmalloc_avail_bitarr_words[roundup_bits2words64(SDDF_MAX_DATA_CELLS)];
/* Index allocator for sddf request ids */
ialloc_t ialloc;
uint32_t ialloc_idxlist[SDDF_MAX_QUEUE_CAPACITY];
/* Sddf structures */
blk_storage_info_t *storage_info;
blk_queue_handle_t queue_h;
uint32_t queue_capacity;
uintptr_t data_region;
/* Channel to notify microkit component serving this client */
int server_ch;
};

bool virtio_mmio_blk_init(struct virtio_blk_device *blk_dev,
uintptr_t region_base,
uintptr_t region_size,
size_t virq,
uintptr_t data_region,
size_t data_region_size,
blk_storage_info_t *storage_info,
blk_queue_handle_t *queue_h,
uint32_t queue_capacity,
int server_ch);
uintptr_t region_base, uintptr_t region_size,
size_t virq, uintptr_t data_region,
size_t data_region_size,
blk_storage_info_t *storage_info,
blk_queue_handle_t *queue_h, uint32_t queue_capacity,
int server_ch);

bool virtio_blk_handle_resp(struct virtio_blk_device *blk_dev);
Loading

0 comments on commit 8bb4870

Please sign in to comment.