static int kvm_init_irq_routing(KVMState *s) { #ifdef KVM_CAP_IRQ_ROUTING int r, gsi_count; gsi_count = kvm_check_extension(s, KVM_CAP_IRQ_ROUTING); if (gsi_count > 0) { int gsi_bits, i; /* Round up so we can search ints using ffs */ gsi_bits = ALIGN(gsi_count, 32); s->used_gsi_bitmap = g_malloc0(gsi_bits / 8); s->max_gsi = gsi_bits; /* Mark any over-allocated bits as already in use */ for (i = gsi_count; i < gsi_bits; i++) { set_gsi(s, i); } } s->irq_routes = g_malloc0(sizeof(*s->irq_routes)); s->nr_allocated_irq_routes = 0; r = kvm_arch_init_irq_routing(); if (r < 0) { return r; } #endif return 0; }
static void kvm_init_irq_routing(KVMState *s) { int gsi_count; gsi_count = kvm_check_extension(s, KVM_CAP_IRQ_ROUTING); if (gsi_count > 0) { unsigned int gsi_bits, i; /* Round up so we can search ints using ffs */ gsi_bits = (gsi_count + 31) / 32; s->used_gsi_bitmap = g_malloc0(gsi_bits / 8); s->max_gsi = gsi_bits; /* Mark any over-allocated bits as already in use */ for (i = gsi_count; i < gsi_bits; i++) { set_gsi(s, i); } } s->irq_routes = g_malloc0(sizeof(*s->irq_routes)); s->nr_allocated_irq_routes = 0; kvm_arch_init_irq_routing(s); }
int kvm_init(void) { int fd; int r, gsi_count; fd = open("/dev/kvm", O_RDWR); if (fd == -1) { perror("open /dev/kvm"); return -1; } r = ioctl(fd, KVM_GET_API_VERSION, 0); if (r == -1) { fprintf(stderr, "kvm kernel version too old: " "KVM_GET_API_VERSION ioctl not supported\n"); goto out_close; } if (r < EXPECTED_KVM_API_VERSION) { fprintf(stderr, "kvm kernel version too old: " "We expect API version %d or newer, but got " "version %d\n", EXPECTED_KVM_API_VERSION, r); goto out_close; } if (r > EXPECTED_KVM_API_VERSION) { fprintf(stderr, "kvm userspace version too old\n"); goto out_close; } kvm_abi = r; kvm_page_size = getpagesize(); kvm_state = qemu_mallocz(sizeof(*kvm_state)); kvm_context = &kvm_state->kvm_context; kvm_state->fd = fd; kvm_state->vmfd = -1; kvm_context->opaque = cpu_single_env; kvm_context->dirty_pages_log_all = 0; kvm_context->no_irqchip_creation = 0; kvm_context->no_pit_creation = 0; #ifdef KVM_CAP_SET_GUEST_DEBUG QTAILQ_INIT(&kvm_state->kvm_sw_breakpoints); #endif gsi_count = kvm_get_gsi_count(kvm_context); if (gsi_count > 0) { int gsi_bits, i; /* Round up so we can search ints using ffs */ gsi_bits = ALIGN(gsi_count, 32); kvm_context->used_gsi_bitmap = qemu_mallocz(gsi_bits / 8); kvm_context->max_gsi = gsi_bits; /* Mark any over-allocated bits as already in use */ for (i = gsi_count; i < gsi_bits; i++) { set_gsi(kvm_context, i); } } kvm_cpu_register_phys_memory_client(); pthread_mutex_lock(&qemu_mutex); return kvm_create_context(); out_close: close(fd); return -1; }