Android-cuttlefish cvd tool
vm_manager.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <memory>
19#include <string>
20#include <unordered_map>
21#include <vector>
22
23#include <fruit/fruit.h>
24
30
31namespace cuttlefish {
32namespace vm_manager {
33
34// Class for tagging that the CommandSource is a dependency command for the
35// VmManager.
37
38// Superclass of every guest VM manager.
39class VmManager {
40 public:
41 // This is the number of HVC virtual console ports that should be configured
42 // by the VmManager. Because crosvm currently allocates these ports as the
43 // first PCI devices, and it does not control the allocation of PCI ID
44 // assignments, the number of these ports affects the PCI paths for
45 // subsequent PCI devices, and these paths are hard-coded in SEPolicy.
46 // Fortunately, HVC virtual console ports can be set up to be "sink" devices,
47 // so even if they are disabled and the guest isn't using them, they don't
48 // need to consume host resources, except for the PCI ID. Use this trick to
49 // keep the number of PCI IDs assigned constant for all flags/vm manager
50 // combinations.
51 // - /dev/hvc0 = kernel console
52 // - /dev/hvc1 = serial console
53 // - /dev/hvc2 = serial logging
54 // - /dev/hvc3 = keymaster
55 // - /dev/hvc4 = gatekeeper
56 // - /dev/hvc5 = bt
57 // - /dev/hvc6 = gnss
58 // - /dev/hvc7 = location
59 // - /dev/hvc8 = confirmationui
60 // - /dev/hvc9 = uwb
61 // - /dev/hvc10 = oemlock
62 // - /dev/hvc11 = keymint
63 // - /dev/hvc12 = NFC
64 // - /dev/hvc13 = sensors
65 // - /dev/hvc14 = MCU control
66 // - /dev/hvc15 = MCU UART
67 // - /dev/hvc16 = Ti50 TPM FIFO
68 // - /dev/hvc17 = jcardsimulator
69 static const int kDefaultNumHvcs = 18;
70
71 // This is the number of virtual disks (block devices) that should be
72 // configured by the VmManager. Related to the description above regarding
73 // HVC ports, this problem can also affect block devices (which are
74 // enumerated second) if not all of the block devices are available. Unlike
75 // HVC virtual console ports, block devices cannot be configured to be sinks,
76 // so we once again leverage HVC virtual console ports to "bump up" the last
77 // assigned virtual disk PCI ID (i.e. 2 disks = 7 hvcs, 1 disks = 8 hvcs)
78 static constexpr int kMaxDisks = 3;
79
80 // This is the number of virtual disks that contribute to the named partition
81 // list (/dev/block/by-name/*) under Android. The partitions names from
82 // multiple disks *must not* collide. Normally we have one set of partitions
83 // from the powerwashed disk (operating system disk) and another set from
84 // the persistent disk
85 static const int kDefaultNumBootDevices = 2;
86
87 static constexpr const int kNetPciDeviceNum = 1;
88
89 // LINT.IfChange(virtio_gpu_pci_address)
90 static constexpr const int kGpuPciSlotNum = 2;
91 // LINT.ThenChange(../../../shared/sepolicy/vendor/genfs_contexts:virtio_gpu_pci_address)
92
93 virtual ~VmManager() = default;
94
95 virtual bool IsSupported() = 0;
96
99
102
103 // Starts the VMM. It will usually build a command and pass it to the
104 // command_starter function, although it may start more than one. The
105 // command_starter function allows to customize the way vmm commands are
106 // started/tracked/etc.
108 const CuttlefishConfig& config,
109 std::vector<VmmDependencyCommand*>& dependencyCommands) = 0;
110
111 // Block until the restore work is finished and the guest is running. Only
112 // called if a snapshot is being restored.
113 //
114 // If FD becomes readable or closed, gives up and returns false.
115 //
116 // Must be thread safe.
118 return CF_ERR("not implemented");
119 }
120};
121
122fruit::Component<fruit::Required<const CuttlefishConfig,
124 VmManager>
126
127std::unique_ptr<VmManager> GetVmManager(VmmMode vmm, Arch arch);
128
130ConfigureMultipleBootDevices(const std::string& pci_path, int pci_offset,
131 int num_disks);
132
133} // namespace vm_manager
134} // namespace cuttlefish
Definition: expected.h:86
Definition: cuttlefish_config.h:269
Definition: cuttlefish_config.h:49
Definition: shared_fd.h:129
Definition: command_source.h:44
Definition: vm_manager.h:39
virtual Result< std::unordered_map< std::string, std::string > > ConfigureGraphics(const CuttlefishConfig::InstanceSpecific &instance)=0
static constexpr const int kGpuPciSlotNum
Definition: vm_manager.h:90
static const int kDefaultNumHvcs
Definition: vm_manager.h:69
virtual Result< std::unordered_map< std::string, std::string > > ConfigureBootDevices(const CuttlefishConfig::InstanceSpecific &instance)=0
static const int kDefaultNumBootDevices
Definition: vm_manager.h:85
virtual Result< bool > WaitForRestoreComplete(SharedFD) const
Definition: vm_manager.h:117
static constexpr const int kNetPciDeviceNum
Definition: vm_manager.h:87
virtual Result< std::vector< MonitorCommand > > StartCommands(const CuttlefishConfig &config, std::vector< VmmDependencyCommand * > &dependencyCommands)=0
static constexpr int kMaxDisks
Definition: vm_manager.h:78
#define CF_ERR(MSG)
Definition: result.h:301
Result< std::unordered_map< std::string, std::string > > ConfigureMultipleBootDevices(const std::string &pci_path, int pci_offset, int num_disks)
Definition: vm_manager.cpp:62
std::unique_ptr< VmManager > GetVmManager(VmmMode vmm_mode, Arch arch)
Definition: vm_manager.cpp:40
fruit::Component< fruit::Required< const CuttlefishConfig, const CuttlefishConfig::InstanceSpecific >, VmManager > VmManagerComponent()
Definition: vm_manager.cpp:109
Definition: alloc_utils.cpp:23
static std::string VmManager(const Instance &instance)
Definition: cf_vm_configs.cpp:43
VmmMode
Definition: vmm_mode.h:28
Arch
Definition: architecture.h:23