1 // Copyright 2020 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 
15 #pragma once
16 
17 #include "aemu/base/files/Stream.h"
18 
19 #include <inttypes.h>
20 
21 static const uint32_t kDmaBufSizeMB = 32;
22 // GOLDFISH DMA
23 //
24 // Goldfish DMA is an extension to the pipe device
25 // and is designed to facilitate high-speed RAM->RAM
26 // transfers from guest to host.
27 //
28 // See docs/GOLDFISH-VIRTUAL-HARDWARE.txt and
29 //     docs/ANDROID-QEMU-PIPE.txt
30 //
31 // for more details.
32 // Host / virtual device interface:
33 typedef struct {
34 // add_buffer():
35 // Tell us that there is a physically-contiguous buffer in the guest
36 // starting at |guest_paddr|. This should be used upon allocation
37 // of the DMA buffer in the ugest.
38 void (*add_buffer)(void* pipe, uint64_t guest_paddr, uint64_t sz);
39 // remove_buffer():
40 // Tell us that we don't care about tracking this buffer anymore.
41 // This should usually be used when the DMA buffer has been freed
42 // in the ugest.
43 void (*remove_buffer)(uint64_t guest_paddr);
44 // get_host_addr():
45 // Obtain a pointer to guest physical memory that is usable as
46 // as host void*.
47 void* (*get_host_addr)(uint64_t guest_paddr);
48 // invalidate_host_mappings():
49 // Sometimes (say, on snapshot save/load) we may need to re-map
50 // the guest DMA buffers so to regain access to them.
51 // This function tells our map of DMA buffers to remap the buffers
52 // next time they are used.
53 void (*invalidate_host_mappings)(void);
54 // unlock():
55 // Unlocks the buffer at |guest_paddr| to signal the guest
56 // that we are done writing it.
57 void (*unlock)(uint64_t guest_paddr);
58 // reset_host_mappings();
59 // Not only invalidates the mappings, but also removes them from the record.
60 void (*reset_host_mappings)(void);
61 // For snapshots.
62 void (*save_mappings)(android::base::Stream* stream);
63 void (*load_mappings)(android::base::Stream* stream);
64 } GoldfishDmaOps;
65 
66 extern const GoldfishDmaOps android_goldfish_dma_ops;
67