• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "base/Stream.h"
2 
3 #include "host-common/GoldfishDma.h"
4 #include "host-common/DmaMap.h"
5 
6 #include "host-common/address_space_device.h"
7 #include "host-common/android_pipe_host.h"
8 
android_goldfish_dma_add_buffer(void * pipe,uint64_t guest_paddr,uint64_t sz)9 static void android_goldfish_dma_add_buffer(void* pipe, uint64_t guest_paddr, uint64_t sz) {
10     android::DmaMap::get()->addBuffer(pipe, guest_paddr, sz);
11 }
12 
android_goldfish_dma_remove_buffer(uint64_t guest_paddr)13 static void android_goldfish_dma_remove_buffer(uint64_t guest_paddr) {
14     android::DmaMap::get()->removeBuffer(guest_paddr);
15 }
16 
android_goldfish_dma_get_host_addr(uint64_t guest_paddr)17 static void* android_goldfish_dma_get_host_addr(uint64_t guest_paddr) {
18     void *host_ptr;
19 
20     host_ptr = get_address_space_device_control_ops()->get_host_ptr(guest_paddr);
21     if (host_ptr) {
22         return host_ptr;
23     }
24 
25     return android::DmaMap::get()->getHostAddr(guest_paddr);
26 }
27 
android_goldfish_dma_invalidate_host_mappings()28 static void android_goldfish_dma_invalidate_host_mappings() {
29     android::DmaMap::get()->invalidateHostMappings();
30 }
31 
android_goldfish_dma_unlock(uint64_t guest_paddr)32 static void android_goldfish_dma_unlock(uint64_t guest_paddr) {
33     void* hwpipe = android::DmaMap::get()->getPipeInstance(guest_paddr);
34 
35     if (hwpipe) {
36         /*
37          * DMA regions allocated with AddressSpaceHostMemoryAllocatorContext
38          * don't have hwpipe associated with them.
39          */
40         android_pipe_host_signal_wake(hwpipe, PIPE_WAKE_UNLOCK_DMA);
41     }
42 }
43 
android_goldfish_dma_reset_host_mappings()44 static void android_goldfish_dma_reset_host_mappings() {
45     android::DmaMap::get()->resetHostMappings();
46 }
47 
android_goldfish_dma_save_mappings(android::base::Stream * stream)48 static void android_goldfish_dma_save_mappings(android::base::Stream* stream) {
49     android::DmaMap::get()->save(stream);
50 }
51 
android_goldfish_dma_load_mappings(android::base::Stream * stream)52 static void android_goldfish_dma_load_mappings(android::base::Stream* stream) {
53     android::DmaMap::get()->load(stream);
54 }
55 
56 const GoldfishDmaOps android_goldfish_dma_ops = {
57     .add_buffer = android_goldfish_dma_add_buffer,
58     .remove_buffer = android_goldfish_dma_remove_buffer,
59     .get_host_addr = android_goldfish_dma_get_host_addr,
60     .invalidate_host_mappings = android_goldfish_dma_invalidate_host_mappings,
61     .unlock = android_goldfish_dma_unlock,
62     .reset_host_mappings = android_goldfish_dma_reset_host_mappings,
63     .save_mappings = android_goldfish_dma_save_mappings,
64     .load_mappings = android_goldfish_dma_load_mappings,
65 };
66