Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gits-base and gits-size in arm-arch-config, add pci-config, num_p… #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion include/zone_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define CONFIG_MAX_INTERRUPTS 32
#define CONFIG_MAX_ZONES 32
#define CONFIG_NAME_MAXLEN 32

#define CONFIG_MAX_PCI_DEV 16
// #define CONFIG_KERNEL_ARGS_MAXLEN 256

struct memory_region {
Expand All @@ -23,12 +23,30 @@ struct memory_region {

typedef struct memory_region memory_region_t;

struct pci_config {
__u64 ecam_base;
__u64 ecam_size;
__u64 io_base;
__u64 io_size;
__u64 pci_io_base;
__u64 mem32_base;
__u64 mem32_size;
__u64 pci_mem32_base;
__u64 mem64_base;
__u64 mem64_size;
__u64 pci_mem64_base;
};

typedef struct pci_config pci_config_t;

#ifdef ARM64
struct arch_zone_config {
__u64 gicd_base;
__u64 gicr_base;
__u64 gicd_size;
__u64 gicr_size;
__u64 gits_base;
__u64 gits_size;
};
#endif

Expand Down Expand Up @@ -56,6 +74,9 @@ struct zone_config {
char name[CONFIG_NAME_MAXLEN];

arch_zone_config_t arch_config;
pci_config_t pci_config;
__u64 num_pci_devs;
__u64 alloc_pci_devs[CONFIG_MAX_PCI_DEV];
};

typedef struct zone_config zone_config_t;
Expand Down
116 changes: 115 additions & 1 deletion tools/hvisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,130 @@ static int parse_arch_config(cJSON *root, zone_config_t *config) {
#ifdef ARM64
cJSON *gicd_base_json = cJSON_GetObjectItem(arch_config_json, "gicd_base");
cJSON *gicr_base_json = cJSON_GetObjectItem(arch_config_json, "gicr_base");
cJSON *gits_base_json = cJSON_GetObjectItem(arch_config_json, "gits_base");
cJSON *gicd_size_json = cJSON_GetObjectItem(arch_config_json, "gicd_size");
cJSON *gicr_size_json = cJSON_GetObjectItem(arch_config_json, "gicr_size");
cJSON *gits_size_json = cJSON_GetObjectItem(arch_config_json, "gits_size");

if (gicd_base_json == NULL || gicr_base_json == NULL ||
gicd_size_json == NULL || gicr_size_json == NULL) {
gicd_size_json == NULL || gicr_size_json == NULL ||
gits_size_json == NULL || gits_size_json == NULL) {
fprintf(stderr, "Missing fields in arch_config.\n");
return -1;
}
config->arch_config.gicd_base = strtoull(gicd_base_json->valuestring, NULL, 16);
config->arch_config.gicr_base = strtoull(gicr_base_json->valuestring, NULL, 16);
config->arch_config.gits_base = strtoull(gits_base_json->valuestring, NULL, 16);
config->arch_config.gicd_size = strtoull(gicd_size_json->valuestring, NULL, 16);
config->arch_config.gicr_size = strtoull(gicr_size_json->valuestring, NULL, 16);
config->arch_config.gits_size = strtoull(gits_size_json->valuestring, NULL, 16);
#endif

#ifdef RISCV64
cJSON *plic_base_json = cJSON_GetObjectItem(arch_config_json, "plic_base");
cJSON *plic_size_json = cJSON_GetObjectItem(arch_config_json, "plic_size");

if (plic_base_json == NULL || plic_size_json == NULL) {
fprintf(stderr, "Missing fields in arch_config.\n");
return -1;
}

config->arch_config.plic_base = strtoull(plic_base_json->valuestring, NULL, 16);
config->arch_config.plic_size = strtoull(plic_size_json->valuestring, NULL, 16);
#endif

return 0;
}

static int parse_pci_config(cJSON *root, zone_config_t *config) {
cJSON *pci_config_json = cJSON_GetObjectItem(root, "pci_config");
if (pci_config_json == NULL) {
fprintf(stderr, "No pci_config field found.\n");
return -1;
}

#ifdef ARM64
cJSON *ecam_base_json = cJSON_GetObjectItem(pci_config_json, "ecam_base");
cJSON *io_base_json = cJSON_GetObjectItem(pci_config_json, "io_base");
cJSON *pci_io_base_json = cJSON_GetObjectItem(pci_config_json, "pci_io_base");
cJSON *mem32_base_json = cJSON_GetObjectItem(pci_config_json, "mem32_base");
cJSON *pci_mem32_base_json = cJSON_GetObjectItem(pci_config_json, "pci_mem32_base");
cJSON *mem64_base_json = cJSON_GetObjectItem(pci_config_json, "mem64_base");
cJSON *pci_mem64_base_json = cJSON_GetObjectItem(pci_config_json, "pci_mem64_base");
cJSON *ecam_size_json = cJSON_GetObjectItem(pci_config_json, "ecam_size");
cJSON *io_size_json = cJSON_GetObjectItem(pci_config_json, "io_size");
cJSON *mem32_size_json = cJSON_GetObjectItem(pci_config_json, "mem32_size");
cJSON *mem64_size_json = cJSON_GetObjectItem(pci_config_json, "mem64_size");

if (ecam_base_json == NULL || io_base_json == NULL ||
mem32_base_json == NULL || mem64_base_json == NULL ||
ecam_size_json == NULL || io_size_json == NULL ||
mem32_size_json == NULL || mem64_size_json == NULL ||
pci_io_base_json == NULL || pci_mem32_base_json == NULL ||
pci_mem64_base_json == NULL) {
fprintf(stderr, "Missing fields in pci_config.\n");
return -1;
}
config->pci_config.ecam_base = strtoull(ecam_base_json->valuestring, NULL, 16);
config->pci_config.io_base = strtoull(io_base_json->valuestring, NULL, 16);
config->pci_config.mem32_base = strtoull(mem32_base_json->valuestring, NULL, 16);
config->pci_config.mem64_base = strtoull(mem64_base_json->valuestring, NULL, 16);
config->pci_config.pci_io_base = strtoull(pci_io_base_json->valuestring, NULL, 16);
config->pci_config.pci_mem32_base = strtoull(pci_mem32_base_json->valuestring, NULL, 16);
config->pci_config.pci_mem64_base = strtoull(pci_mem64_base_json->valuestring, NULL, 16);
config->pci_config.ecam_size = strtoull(ecam_size_json->valuestring, NULL, 16);
config->pci_config.io_size = strtoull(io_size_json->valuestring, NULL, 16);
config->pci_config.mem32_size = strtoull(mem32_size_json->valuestring, NULL, 16);
config->pci_config.mem64_size = strtoull(mem64_size_json->valuestring, NULL, 16);
cJSON *alloc_pci_devs_json = cJSON_GetObjectItem(root, "alloc_pci_devs");
int num_pci_devs = cJSON_GetArraySize(alloc_pci_devs_json);
config->num_pci_devs = num_pci_devs;
for (int i = 0; i < num_pci_devs; i++)
{
config->alloc_pci_devs[i] = cJSON_GetArrayItem(alloc_pci_devs_json, i)->valueint;
}
#endif

#ifdef RISCV64
cJSON *ecam_base_json = cJSON_GetObjectItem(pci_config_json, "ecam_base");
cJSON *io_base_json = cJSON_GetObjectItem(pci_config_json, "io_base");
cJSON *pci_io_base_json = cJSON_GetObjectItem(pci_config_json, "pci_io_base");
cJSON *mem32_base_json = cJSON_GetObjectItem(pci_config_json, "mem32_base");
cJSON *pci_mem32_base_json = cJSON_GetObjectItem(pci_config_json, "pci_mem32_base");
cJSON *mem64_base_json = cJSON_GetObjectItem(pci_config_json, "mem64_base");
cJSON *pci_mem64_base_json = cJSON_GetObjectItem(pci_config_json, "pci_mem64_base");
cJSON *ecam_size_json = cJSON_GetObjectItem(pci_config_json, "ecam_size");
cJSON *io_size_json = cJSON_GetObjectItem(pci_config_json, "io_size");
cJSON *mem32_size_json = cJSON_GetObjectItem(pci_config_json, "mem32_size");
cJSON *mem64_size_json = cJSON_GetObjectItem(pci_config_json, "mem64_size");

if (ecam_base_json == NULL || io_base_json == NULL ||
mem32_base_json == NULL || mem64_base_json == NULL ||
ecam_size_json == NULL || io_size_json == NULL ||
mem32_size_json == NULL || mem64_size_json == NULL ||
pci_io_base_json == NULL || pci_mem32_base_json == NULL ||
pci_mem64_base_json == NULL) {
fprintf(stderr, "Missing fields in pci_config.\n");
return -1;
}
config->pci_config.ecam_base = strtoull(ecam_base_json->valuestring, NULL, 16);
config->pci_config.io_base = strtoull(io_base_json->valuestring, NULL, 16);
config->pci_config.mem32_base = strtoull(mem32_base_json->valuestring, NULL, 16);
config->pci_config.mem64_base = strtoull(mem64_base_json->valuestring, NULL, 16);
config->pci_config.pci_io_base = strtoull(pci_io_base_json->valuestring, NULL, 16);
config->pci_config.pci_mem32_base = strtoull(pci_mem32_base_json->valuestring, NULL, 16);
config->pci_config.pci_mem64_base = strtoull(pci_mem64_base_json->valuestring, NULL, 16);
config->pci_config.ecam_size = strtoull(ecam_size_json->valuestring, NULL, 16);
config->pci_config.io_size = strtoull(io_size_json->valuestring, NULL, 16);
config->pci_config.mem32_size = strtoull(mem32_size_json->valuestring, NULL, 16);
config->pci_config.mem64_size = strtoull(mem64_size_json->valuestring, NULL, 16);
cJSON *alloc_pci_devs_json = cJSON_GetObjectItem(root, "alloc_pci_devs");
int num_pci_devs = cJSON_GetArraySize(alloc_pci_devs_json);
config->num_pci_devs = num_pci_devs;
for (int i = 0; i < num_pci_devs; i++)
{
config->alloc_pci_devs[i] = cJSON_GetArrayItem(alloc_pci_devs_json, i)->valueint;
}
#endif

return 0;
Expand Down Expand Up @@ -255,6 +367,8 @@ static int zone_start_from_json(const char *json_config_path, zone_config_t *con

parse_arch_config(root, config);

parse_pci_config(root, config);

cJSON_Delete(root); // delete cJSON object
free(buffer);

Expand Down