Skip to content

Commit 7e8cd56

Browse files
committed
ref(core/remio): added vm_init_remio_dev function
Signed-off-by: João Peixoto <[email protected]>
1 parent b79edf2 commit 7e8cd56

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

src/core/vm.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,44 @@ static void vm_init_dev(struct vm* vm, const struct vm_config* vm_config)
228228
}
229229
}
230230

231+
static void vm_init_remio_dev(struct remio_dev* remio_dev, struct vm* vm)
232+
{
233+
struct shmem* shmem = shmem_get(remio_dev->shmem.shmem_id);
234+
if (shmem == NULL) {
235+
ERROR("Invalid shmem id (%d) in the Remote I/O device (%d) configuration",
236+
remio_dev->shmem.shmem_id, remio_dev->id);
237+
}
238+
size_t shmem_size = remio_dev->shmem.size;
239+
if (shmem_size > shmem->size) {
240+
shmem_size = shmem->size;
241+
WARNING("Trying to map region to smaller shared memory. Truncated");
242+
}
243+
spin_lock(&shmem->lock);
244+
shmem->cpu_masters |= (1UL << cpu()->id);
245+
spin_unlock(&shmem->lock);
246+
247+
struct vm_mem_region reg = {
248+
.base = remio_dev->shmem.base,
249+
.size = shmem_size,
250+
.place_phys = true,
251+
.phys = shmem->phys,
252+
.colors = shmem->colors,
253+
};
254+
255+
vm_map_mem_region(vm, &reg);
256+
257+
if (remio_dev->type == REMIO_DEV_FRONTEND) {
258+
struct emul_mem* emu = objpool_alloc(&emul_cache);
259+
if (emu == NULL) {
260+
ERROR("Failed allocating emulation memory node");
261+
}
262+
emu->va_base = remio_dev->va;
263+
emu->size = remio_dev->size;
264+
emu->handler = remio_mmio_emul_handler;
265+
vm_emul_add_mem(vm, emu);
266+
}
267+
}
268+
231269
static void vm_init_remio(struct vm* vm, const struct vm_config* vm_config)
232270
{
233271
if (vm_config->platform.remio_dev_num == 0) {
@@ -239,40 +277,7 @@ static void vm_init_remio(struct vm* vm, const struct vm_config* vm_config)
239277

240278
for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) {
241279
struct remio_dev* remio_dev = &vm_config->platform.remio_devs[i];
242-
struct shmem* shmem = shmem_get(remio_dev->shmem.shmem_id);
243-
if (shmem == NULL) {
244-
WARNING("Invalid shmem id in configuration. Ignored.");
245-
continue;
246-
}
247-
size_t shmem_size = remio_dev->shmem.size;
248-
if (shmem_size > shmem->size) {
249-
shmem_size = shmem->size;
250-
WARNING("Trying to map region to smaller shared memory. Truncated");
251-
}
252-
spin_lock(&shmem->lock);
253-
shmem->cpu_masters |= (1UL << cpu()->id);
254-
spin_unlock(&shmem->lock);
255-
256-
struct vm_mem_region reg = {
257-
.base = remio_dev->shmem.base,
258-
.size = shmem_size,
259-
.place_phys = true,
260-
.phys = shmem->phys,
261-
.colors = shmem->colors,
262-
};
263-
264-
vm_map_mem_region(vm, &reg);
265-
266-
if (remio_dev->type == REMIO_DEV_FRONTEND) {
267-
struct emul_mem* emu = objpool_alloc(&emul_cache);
268-
if (emu == NULL) {
269-
ERROR("Failed allocating emulation memory node");
270-
}
271-
emu->va_base = remio_dev->va;
272-
emu->size = remio_dev->size;
273-
emu->handler = remio_mmio_emul_handler;
274-
vm_emul_add_mem(vm, emu);
275-
}
280+
vm_init_remio_dev(remio_dev, vm);
276281
}
277282
remio_assign_vm_cpus(vm);
278283
}

0 commit comments

Comments
 (0)