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 3, 2024
1 parent 818dbca commit e408527
Show file tree
Hide file tree
Showing 7 changed files with 1,114 additions and 1,032 deletions.
47 changes: 26 additions & 21 deletions examples/virtio/board/odroidc4/virtio.system
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<system>
<memory_region name="client_vm_1_ram" size="0x6_000_000" page_size="0x200_000" />
<memory_region name="client_vm_2_ram" size="0x6_000_000" page_size="0x200_000" />
<memory_region name="driver_blk_vm_ram" size="0x6_000_000" page_size="0x200_000" phys_addr="0x20_000_000"/>
<memory_region name="blk_driver_vm_ram" size="0x6_000_000" page_size="0x200_000" phys_addr="0x20_000_000"/>
<memory_region name="gic_vcpu" size="0x1_000" phys_addr="0xffc06000" />
<memory_region name="uart" size="0x1000" phys_addr="0xff803000" />
<memory_region name="sd" size="0x1000" phys_addr="0xffe05000" />
Expand Down Expand Up @@ -165,20 +165,20 @@
</channel>

<!-- Block sDDF regions -->
<memory_region name="driver_blk_storage_info" size="0x1000" page_size="0x1000" />
<memory_region name="driver_blk_req_queue" size="0x200_000" page_size="0x200_000"/>
<memory_region name="driver_blk_resp_queue" size="0x200_000" page_size="0x200_000"/>
<memory_region name="driver_blk_data" size="0x200_000" page_size="0x200_000" />
<memory_region name="driver_blk_storage_info" size="0x1000" page_size="0x1000" phys_addr="0x80000000"/>
<memory_region name="driver_blk_req_queue" size="0x200_000" page_size="0x200_000" phys_addr="0x80200000"/>
<memory_region name="driver_blk_resp_queue" size="0x200_000" page_size="0x200_000" phys_addr="0x80400000"/>
<memory_region name="driver_blk_data" size="0x200_000" page_size="0x200_000" phys_addr="0x80600000"/>

<memory_region name="client_vmm_1_blk_storage_info" size="0x1000" page_size="0x1000" />
<memory_region name="client_vmm_1_blk_req_queue" size="0x200_000" page_size="0x200_000"/>
<memory_region name="client_vmm_1_blk_resp_queue" size="0x200_000" page_size="0x200_000"/>
<memory_region name="client_vmm_1_blk_data" size="0x200_000" page_size="0x200_000" />
<memory_region name="client_vmm_1_blk_data" size="0x200_000" page_size="0x200_000" phys_addr="0x80800000"/>

<memory_region name="client_vmm_2_blk_storage_info" size="0x1000" page_size="0x1000" />
<memory_region name="client_vmm_2_blk_req_queue" size="0x200_000" page_size="0x200_000"/>
<memory_region name="client_vmm_2_blk_resp_queue" size="0x200_000" page_size="0x200_000"/>
<memory_region name="client_vmm_2_blk_data" size="0x200_000" page_size="0x200_000" />
<memory_region name="client_vmm_2_blk_data" size="0x200_000" page_size="0x200_000" phys_addr="0x80a00000"/>

<!-- UIO irq status page -->
<memory_region name="uio_irq_status" size="0x1000" page_size="0x1000" />
Expand Down Expand Up @@ -207,10 +207,12 @@
<map mr="bus3" vaddr="0xffd00000" perms="rw" cached="false" />

<!-- sDDF block -->
<map mr="driver_blk_storage_info" vaddr="0x40000000" perms="rw" cached="false" />
<map mr="driver_blk_req_queue" vaddr="0x40200000" perms="rw" cached="false" />
<map mr="driver_blk_resp_queue" vaddr="0x40400000" perms="rw" cached="false" />
<map mr="driver_blk_data" vaddr="0x40800000" perms="rw" cached="true" />
<map mr="driver_blk_storage_info" vaddr="0x80000000" perms="rw" cached="false" />
<map mr="driver_blk_req_queue" vaddr="0x80200000" perms="rw" cached="false" />
<map mr="driver_blk_resp_queue" vaddr="0x80400000" perms="rw" cached="false" />
<map mr="driver_blk_data" vaddr="0x80600000" perms="rw" cached="true" />
<map mr="client_vmm_1_blk_data" vaddr="0x80800000" perms="rw" cached="true" />
<map mr="client_vmm_2_blk_data" vaddr="0x80a00000" perms="rw" cached="true" />

<!-- UIO irq status -->
<map mr="uio_irq_status" vaddr="0x39800000" perms="rw" cached="true" />
Expand All @@ -221,19 +223,22 @@

<protection_domain name="BLK_VIRT" priority="150" budget="100" period="400">
<program_image path="blk_virt.elf" />
<map mr="driver_blk_storage_info" vaddr="0x40000000" perms="rw" cached="false" setvar_vaddr="blk_driver_storage_info" />
<map mr="driver_blk_req_queue" vaddr="0x40200000" perms="rw" cached="false" setvar_vaddr="blk_req_queue_driver" />
<map mr="driver_blk_resp_queue" vaddr="0x40400000" perms="rw" cached="false" setvar_vaddr="blk_resp_queue_driver" />
<map mr="driver_blk_data" vaddr="0x40800000" perms="rw" cached="true" setvar_vaddr="blk_data_driver" />

<map mr="client_vmm_1_blk_storage_info" vaddr="0x30000000" perms="rw" cached="false" setvar_vaddr="blk_storage_info" />
<map mr="client_vmm_2_blk_storage_info" vaddr="0x30200000" perms="rw" cached="false" />
<map mr="client_vmm_1_blk_req_queue" vaddr="0x31000000" perms="rw" cached="false" setvar_vaddr="blk_req_queue" />
<map mr="driver_blk_storage_info" vaddr="0x20000000" perms="rw" cached="false" setvar_vaddr="blk_driver_storage_info" />
<map mr="driver_blk_req_queue" vaddr="0x20200000" perms="rw" cached="false" setvar_vaddr="blk_driver_req_queue" />
<map mr="driver_blk_resp_queue" vaddr="0x20400000" perms="rw" cached="false" setvar_vaddr="blk_driver_resp_queue" />
<map mr="driver_blk_data" vaddr="0x20800000" perms="rw" cached="true" setvar_vaddr="blk_driver_data" />
<setvar symbol="blk_data_paddr_driver" region_paddr="driver_blk_data" />

<map mr="client_vmm_1_blk_storage_info" vaddr="0x30000000" perms="rw" cached="false" setvar_vaddr="blk_client_storage_info" />
<map mr="client_vmm_2_blk_storage_info" vaddr="0x30001000" perms="rw" cached="false" />
<map mr="client_vmm_1_blk_req_queue" vaddr="0x31000000" perms="rw" cached="false" setvar_vaddr="blk_client_req_queue" />
<map mr="client_vmm_2_blk_req_queue" vaddr="0x31200000" perms="rw" cached="false" />
<map mr="client_vmm_1_blk_resp_queue" vaddr="0x32000000" perms="rw" cached="false" setvar_vaddr="blk_resp_queue" />
<map mr="client_vmm_1_blk_resp_queue" vaddr="0x32000000" perms="rw" cached="false" setvar_vaddr="blk_client_resp_queue" />
<map mr="client_vmm_2_blk_resp_queue" vaddr="0x32200000" perms="rw" cached="false" />
<map mr="client_vmm_1_blk_data" vaddr="0x33000000" perms="rw" cached="true" setvar_vaddr="blk_client_data_start"/>
<map mr="client_vmm_1_blk_data" vaddr="0x33000000" perms="rw" cached="true" setvar_vaddr="blk_client_data"/>
<setvar symbol="blk_client0_data_paddr" region_paddr="client_vmm_1_blk_data" />
<map mr="client_vmm_2_blk_data" vaddr="0x33200000" perms="rw" cached="true" />
<setvar symbol="blk_client1_data_paddr" region_paddr="client_vmm_2_blk_data" />
</protection_domain>

<channel>
Expand Down
69 changes: 32 additions & 37 deletions examples/virtio/client_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,37 @@ uintptr_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)
{
blk_storage_info_t *storage_info = (blk_storage_info_t *)blk_storage_info;

/* Busy wait until blk device is ready */
while (!blk_storage_is_ready(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;
}
blk_storage_info_t *storage_info = (blk_storage_info_t *)blk_storage_info;

/* Busy wait until blk device is ready */
while (!blk_storage_is_ready(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 virtual GIC driver */
bool success = virq_controller_init(GUEST_VCPU_ID);
Expand Down Expand Up @@ -135,14 +134,10 @@ void init(void)
blk_cli_queue_size(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,
storage_info,
&blk_queue_h,
blk_cli_queue_size(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, storage_info, &blk_queue_h,
blk_cli_queue_size(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_size(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_size(unsigned int id)
static inline uint32_t blk_cli_queue_size(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 e408527

Please sign in to comment.