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 <string>
19#include <unordered_map>
20#include <vector>
21
27
28namespace cuttlefish {
29namespace vm_manager {
30
31// Class for tagging that the CommandSource is a dependency command for the
32// VmManager.
34
35// Superclass of every guest VM manager.
36class VmManager {
37 public:
38 // This is the number of HVC virtual console ports that should be configured
39 // by the VmManager. Because crosvm currently allocates these ports as the
40 // first PCI devices, and it does not control the allocation of PCI ID
41 // assignments, the number of these ports affects the PCI paths for
42 // subsequent PCI devices, and these paths are hard-coded in SEPolicy.
43 // Fortunately, HVC virtual console ports can be set up to be "sink" devices,
44 // so even if they are disabled and the guest isn't using them, they don't
45 // need to consume host resources, except for the PCI ID. Use this trick to
46 // keep the number of PCI IDs assigned constant for all flags/vm manager
47 // combinations.
48 // - /dev/hvc0 = kernel console
49 // - /dev/hvc1 = serial console
50 // - /dev/hvc2 = serial logging
51 // - /dev/hvc3 = keymaster
52 // - /dev/hvc4 = gatekeeper
53 // - /dev/hvc5 = bt
54 // - /dev/hvc6 = gnss
55 // - /dev/hvc7 = location
56 // - /dev/hvc8 = confirmationui (always a sink)
57 // - /dev/hvc9 = uwb
58 // - /dev/hvc10 = oemlock
59 // - /dev/hvc11 = keymint
60 // - /dev/hvc12 = NFC
61 // - /dev/hvc13 = weaver
62 // - /dev/hvc14 = MCU control
63 // - /dev/hvc15 = MCU UART
64 // - /dev/hvc16 = Ti50 TPM FIFO
65 // - /dev/hvc17 = jcardsimulator
66 // - /dev/hvc18 = Sensors control
67 // - /dev/hvc19 = Sensors data
68 static const int kDefaultNumHvcs = 20;
69
70 // This is the number of virtual disks (block devices) that should be
71 // configured by the VmManager. Related to the description above regarding
72 // HVC ports, this problem can also affect block devices (which are
73 // enumerated second) if not all of the block devices are available. Unlike
74 // HVC virtual console ports, block devices cannot be configured to be sinks,
75 // so we once again leverage HVC virtual console ports to "bump up" the last
76 // assigned virtual disk PCI ID (i.e. 2 disks = 7 hvcs, 1 disks = 8 hvcs)
77 static constexpr int kMaxDisks = 3;
78
79 // This is the number of virtual disks that contribute to the named partition
80 // list (/dev/block/by-name/*) under Android. The partitions names from
81 // multiple disks *must not* collide. Normally we have one set of partitions
82 // from the powerwashed disk (operating system disk) and another set from
83 // the persistent disk
84 static const int kDefaultNumBootDevices = 2;
85
86 static constexpr const int kNetPciDeviceNum = 1;
87
88 // LINT.IfChange(virtio_gpu_pci_address)
89 static constexpr const int kGpuPciSlotNum = 2;
90 // LINT.ThenChange(../../../shared/sepolicy/vendor/genfs_contexts:virtio_gpu_pci_address)
91
92 virtual ~VmManager() = default;
93
94 virtual bool IsSupported() = 0;
95
98
101
102 // Starts the VMM. It will usually build a command and pass it to the
103 // command_starter function, although it may start more than one. The
104 // command_starter function allows to customize the way vmm commands are
105 // started/tracked/etc.
107 const CuttlefishConfig& config, const AdbConfig& adb_config,
108 std::vector<VmmDependencyCommand*>& dependencyCommands) = 0;
109
110 // Block until the restore work is finished and the guest is running. Only
111 // called if a snapshot is being restored.
112 //
113 // If FD becomes readable or closed, gives up and returns false.
114 //
115 // Must be thread safe.
117 return CF_ERR("not implemented");
118 }
119};
120
121} // namespace vm_manager
122} // namespace cuttlefish
Definition: adb.h:42
Definition: cuttlefish_config.h:264
Definition: cuttlefish_config.h:54
Definition: shared_fd.h:125
Definition: command_source.h:75
Definition: vm_manager.h:36
virtual Result< std::unordered_map< std::string, std::string > > ConfigureGraphics(const CuttlefishConfig::InstanceSpecific &instance)=0
static constexpr const int kGpuPciSlotNum
Definition: vm_manager.h:89
static const int kDefaultNumHvcs
Definition: vm_manager.h:68
virtual Result< std::unordered_map< std::string, std::string > > ConfigureBootDevices(const CuttlefishConfig::InstanceSpecific &instance)=0
static const int kDefaultNumBootDevices
Definition: vm_manager.h:84
virtual Result< std::vector< MonitorCommand > > StartCommands(const CuttlefishConfig &config, const AdbConfig &adb_config, std::vector< VmmDependencyCommand * > &dependencyCommands)=0
virtual Result< bool > WaitForRestoreComplete(SharedFD) const
Definition: vm_manager.h:116
static constexpr const int kNetPciDeviceNum
Definition: vm_manager.h:86
static constexpr int kMaxDisks
Definition: vm_manager.h:77
#define CF_ERR(MSG)
Definition: expect.h:48
Definition: alloc_driver.h:21
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30