1 // Copyright 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 #include <memory>
17 #include "aemu/base/files/Stream.h"
18 
19 namespace android {
20 namespace emulation {
21 
22 // Protocol:
23 // Guest open()'s the device, kernel gets internal handle
24 // first ioctl is all 0 fields except for metadata,
25 // which establishes what kind of thing we want to run,
26 // enumerated here.
27 
28 // From there, it's all up to the individual device types.
29 
30 enum AddressSpaceDeviceType {
31     // Covers renderControl, opengles, and vulkan
32     Graphics = 0,
33     // (audio/video codec devices)
34     Media = 1,
35     Sensors = 2,
36     Power = 3,
37     // TODO: All other services currently using goldfish pipe
38     GenericPipe = 4,
39     HostMemoryAllocator = 5,
40     SharedSlotsHostMemoryAllocator = 6,
41     VirtioGpuGraphics = 10,
42 };
43 
44 struct AddressSpaceDevicePingInfo {
45     uint64_t phys_addr;
46     uint64_t size;
47     uint64_t metadata;
48     uint64_t wait_phys_addr;
49     uint32_t wait_flags;
50     uint32_t direction;
51 };
52 
53 class AddressSpaceDeviceContext {
54 public:
~AddressSpaceDeviceContext()55     virtual ~AddressSpaceDeviceContext() {}
56     virtual void perform(AddressSpaceDevicePingInfo *info) = 0;
57     virtual AddressSpaceDeviceType getDeviceType() const = 0;
58     virtual void save(base::Stream* stream) const = 0;
59     virtual bool load(base::Stream* stream) = 0;
60 
preSave()61     virtual void preSave() const { }
postSave()62     virtual void postSave() const { }
63 };
64 
65 struct AddressSpaceContextDescription {
66     AddressSpaceDevicePingInfo* pingInfo = nullptr;
67     uint64_t pingInfoGpa = 0;  // for snapshots
68     std::unique_ptr<AddressSpaceDeviceContext> device_context;
69 };
70 
71 } // namespace emulation
72 } // namespace android
73