MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / kvm_init

Function kvm_init

tinyemu/x86_machine.c:1660–1752  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1658}
1659
1660static void kvm_init(PCMachine *s)
1661{
1662 int ret, i;
1663 struct sigaction act;
1664 struct kvm_pit_config pit_config;
1665 uint64_t base_addr;
1666
1667 s->kvm_enabled = FALSE;
1668 s->kvm_fd = open("/dev/kvm", O_RDWR);
1669 if (s->kvm_fd < 0) {
1670 fprintf(stderr, "KVM not available\n");
1671 return;
1672 }
1673 ret = ioctl(s->kvm_fd, KVM_GET_API_VERSION, 0);
1674 if (ret < 0) {
1675 perror("KVM_GET_API_VERSION");
1676 exit(1);
1677 }
1678 if (ret != 12) {
1679 fprintf(stderr, "Unsupported KVM version\n");
1680 close(s->kvm_fd);
1681 s->kvm_fd = -1;
1682 return;
1683 }
1684 s->vm_fd = ioctl(s->kvm_fd, KVM_CREATE_VM, 0);
1685 if (s->vm_fd < 0) {
1686 perror("KVM_CREATE_VM");
1687 exit(1);
1688 }
1689
1690 /* just before the BIOS */
1691 base_addr = 0xfffbc000;
1692 if (ioctl(s->vm_fd, KVM_SET_IDENTITY_MAP_ADDR, &base_addr) < 0) {
1693 perror("KVM_SET_IDENTITY_MAP_ADDR");
1694 exit(1);
1695 }
1696
1697 if (ioctl(s->vm_fd, KVM_SET_TSS_ADDR, (long)(base_addr + 0x1000)) < 0) {
1698 perror("KVM_SET_TSS_ADDR");
1699 exit(1);
1700 }
1701
1702 if (ioctl(s->vm_fd, KVM_CREATE_IRQCHIP, 0) < 0) {
1703 perror("KVM_CREATE_IRQCHIP");
1704 exit(1);
1705 }
1706
1707 memset(&pit_config, 0, sizeof(pit_config));
1708 pit_config.flags = KVM_PIT_SPEAKER_DUMMY;
1709 if (ioctl(s->vm_fd, KVM_CREATE_PIT2, &pit_config)) {
1710 perror("KVM_CREATE_PIT2");
1711 exit(1);
1712 }
1713
1714 s->vcpu_fd = ioctl(s->vm_fd, KVM_CREATE_VCPU, 0);
1715 if (s->vcpu_fd < 0) {
1716 perror("KVM_CREATE_VCPU");
1717 exit(1);

Callers 1

x86_machine.cFile · 0.85

Calls 3

kvm_set_cpuidFunction · 0.85
irq_initFunction · 0.85
sigactionClass · 0.70

Tested by

no test coverage detected