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 = weaver
65 // - /dev/hvc14 = MCU control
66 // - /dev/hvc15 = MCU UART
67 // - /dev/hvc16 = Ti50 TPM FIFO
68 // - /dev/hvc17 = jcardsimulator
69 // - /dev/hvc18 = Sensors control
70 // - /dev/hvc19 = Sensors data
71 static const int kDefaultNumHvcs = 20;
72
73 // This is the number of virtual disks (block devices) that should be
74 // configured by the VmManager. Related to the description above regarding
75 // HVC ports, this problem can also affect block devices (which are
76 // enumerated second) if not all of the block devices are available. Unlike
77 // HVC virtual console ports, block devices cannot be configured to be sinks,
78 // so we once again leverage HVC virtual console ports to "bump up" the last
79 // assigned virtual disk PCI ID (i.e. 2 disks = 7 hvcs, 1 disks = 8 hvcs)
80 static constexpr int kMaxDisks = 3;
81
82 // This is the number of virtual disks that contribute to the named partition
83 // list (/dev/block/by-name/*) under Android. The partitions names from
84 // multiple disks *must not* collide. Normally we have one set of partitions
85 // from the powerwashed disk (operating system disk) and another set from
86 // the persistent disk
87 static const int kDefaultNumBootDevices = 2;
88
89 static constexpr const int kNetPciDeviceNum = 1;
90
91 // LINT.IfChange(virtio_gpu_pci_address)
92 static constexpr const int kGpuPciSlotNum = 2;
93 // LINT.ThenChange(../../../shared/sepolicy/vendor/genfs_contexts:virtio_gpu_pci_address)
94
95 virtual ~VmManager() = default;
96
97 virtual bool IsSupported() = 0;
98
101
104
105 // Starts the VMM. It will usually build a command and pass it to the
106 // command_starter function, although it may start more than one. The
107 // command_starter function allows to customize the way vmm commands are
108 // started/tracked/etc.
110 const CuttlefishConfig& config,
111 std::vector<VmmDependencyCommand*>& dependencyCommands) = 0;
112
113 // Block until the restore work is finished and the guest is running. Only
114 // called if a snapshot is being restored.
115 //
116 // If FD becomes readable or closed, gives up and returns false.
117 //
118 // Must be thread safe.
120 return CF_ERR("not implemented");
121 }
122};
123
124fruit::Component<fruit::Required<const CuttlefishConfig,
126 VmManager>
128
129std::unique_ptr<VmManager> GetVmManager(VmmMode vmm, Arch arch);
130
131// Formats androidboot.boot_devices property to include the disks at a range of
132// PCI slots.
134ConfigureMultipleBootDevices(const std::string& pci_path, int disk_pci_offset,
135 int num_disks);
136
137} // namespace vm_manager
138} // namespace cuttlefish
Definition: cuttlefish_config.h:252
Definition: cuttlefish_config.h:52
Definition: shared_fd.h:124
Definition: command_source.h:43
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:92
static const int kDefaultNumHvcs
Definition: vm_manager.h:71
virtual Result< std::unordered_map< std::string, std::string > > ConfigureBootDevices(const CuttlefishConfig::InstanceSpecific &instance)=0
static const int kDefaultNumBootDevices
Definition: vm_manager.h:87
virtual Result< bool > WaitForRestoreComplete(SharedFD) const
Definition: vm_manager.h:119
static constexpr const int kNetPciDeviceNum
Definition: vm_manager.h:89
virtual Result< std::vector< MonitorCommand > > StartCommands(const CuttlefishConfig &config, std::vector< VmmDependencyCommand * > &dependencyCommands)=0
static constexpr int kMaxDisks
Definition: vm_manager.h:80
#define CF_ERR(MSG)
Definition: expect.h:48
std::unique_ptr< VmManager > GetVmManager(VmmMode vmm_mode, Arch arch)
Definition: vm_manager.cpp:55
fruit::Component< fruit::Required< const CuttlefishConfig, const CuttlefishConfig::InstanceSpecific >, VmManager > VmManagerComponent()
Definition: vm_manager.cpp:114
Result< std::unordered_map< std::string, std::string > > ConfigureMultipleBootDevices(const std::string &pci_path, int disk_pci_offset, int num_disks)
Definition: vm_manager.cpp:66
Definition: alloc_driver.h:20
static std::string VmManager(const Instance &instance)
Definition: cf_vm_configs.cpp:114
VmmMode
Definition: vmm_mode.h:26
Arch
Definition: host_info.h:23
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30