gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/qemu_arm64.go (about) 1 // Copyright (c) 2018 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers 7 8 import ( 9 "context" 10 "time" 11 12 govmmQemu "github.com/intel/govmm/qemu" 13 ) 14 15 type qemuArm64 struct { 16 // inherit from qemuArchBase, overwrite methods if needed 17 qemuArchBase 18 } 19 20 const defaultQemuPath = "/usr/bin/qemu-system-aarch64" 21 22 const defaultQemuMachineType = QemuVirt 23 24 const qmpMigrationWaitTimeout = 10 * time.Second 25 26 const defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=host" 27 28 var defaultGICVersion = uint32(3) 29 30 var qemuPaths = map[string]string{ 31 QemuVirt: defaultQemuPath, 32 } 33 34 var kernelParams = []Param{ 35 {"console", "hvc0"}, 36 {"console", "hvc1"}, 37 {"iommu.passthrough", "0"}, 38 } 39 40 var supportedQemuMachines = []govmmQemu.Machine{ 41 { 42 Type: QemuVirt, 43 Options: defaultQemuMachineOptions, 44 }, 45 } 46 47 //In qemu, maximum number of vCPUs depends on the GIC version, or on how 48 //many redistributors we can fit into the memory map. 49 //related codes are under github.com/qemu/qemu/hw/arm/virt.c(Line 135 and 1306 in stable-2.11) 50 //for now, qemu only supports v2 and v3, we treat v4 as v3 based on 51 //backward compatibility. 52 var gicList = map[uint32]uint32{ 53 uint32(2): uint32(8), 54 uint32(3): uint32(123), 55 uint32(4): uint32(123), 56 } 57 58 // MaxQemuVCPUs returns the maximum number of vCPUs supported 59 func MaxQemuVCPUs() uint32 { 60 return gicList[defaultGICVersion] 61 } 62 63 func newQemuArch(config HypervisorConfig) qemuArch { 64 machineType := config.HypervisorMachineType 65 if machineType == "" { 66 machineType = defaultQemuMachineType 67 } 68 69 q := &qemuArm64{ 70 qemuArchBase{ 71 machineType: machineType, 72 memoryOffset: config.MemOffset, 73 qemuPaths: qemuPaths, 74 supportedQemuMachines: supportedQemuMachines, 75 kernelParamsNonDebug: kernelParamsNonDebug, 76 kernelParamsDebug: kernelParamsDebug, 77 kernelParams: kernelParams, 78 disableNvdimm: config.DisableImageNvdimm, 79 dax: true, 80 }, 81 } 82 83 q.handleImagePath(config) 84 85 return q 86 } 87 88 func (q *qemuArm64) bridges(number uint32) { 89 q.Bridges = genericBridges(number, q.machineType) 90 } 91 92 // appendBridges appends to devices the given bridges 93 func (q *qemuArm64) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device { 94 return genericAppendBridges(devices, q.Bridges, q.machineType) 95 } 96 97 func (q *qemuArm64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) { 98 if !q.disableNvdimm { 99 return q.appendNvdimmImage(devices, path) 100 } 101 return q.appendBlockImage(devices, path) 102 } 103 104 func (q *qemuArm64) setIgnoreSharedMemoryMigrationCaps(_ context.Context, _ *govmmQemu.QMP) error { 105 // x-ignore-shared not support in arm64 for now 106 return nil 107 }