| 1 |
/* |
| 2 |
* Copyright 2018 Google LLC |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
#include "VirtGpu.h" |
| 11 |
#include "gfxstream/guest/IOStream.h" |
| 12 |
|
| 13 |
/* This file implements an IOStream that uses VIRTGPU TRANSFER* ioctls on a |
| 14 |
* virtio-gpu DRM rendernode device to communicate with a goldfish-pipe |
| 15 |
* service on the host side. |
| 16 |
*/ |
| 17 |
|
| 18 |
class VirtioGpuPipeStream : public gfxstream::guest::IOStream { |
| 19 |
public: |
| 20 |
explicit VirtioGpuPipeStream(size_t bufsize, int32_t descriptor); |
| 21 |
~VirtioGpuPipeStream(); |
| 22 |
|
| 23 |
virtual int connect(const char* serviceName = nullptr); |
| 24 |
virtual uint64_t processPipeInit(); |
| 25 |
|
| 26 |
virtual void* allocBuffer(size_t minSize); |
| 27 |
virtual int commitBuffer(size_t size); |
| 28 |
virtual const unsigned char* readFully(void* buf, size_t len); |
| 29 |
virtual const unsigned char* commitBufferAndReadFully(size_t size, void* buf, size_t len); |
| 30 |
virtual const unsigned char* read(void* buf, size_t* inout_len); |
| 31 |
|
| 32 |
bool valid(); |
| 33 |
int getRendernodeFd(); |
| 34 |
int recv(void* buf, size_t len); |
| 35 |
|
| 36 |
virtual int writeFully(const void* buf, size_t len); |
| 37 |
|
| 38 |
private: |
| 39 |
// sync. Also resets the write position. |
| 40 |
void wait(); |
| 41 |
|
| 42 |
// transfer to/from host ops |
| 43 |
ssize_t transferToHost(const void* buffer, size_t len); |
| 44 |
ssize_t transferFromHost(void* buffer, size_t len); |
| 45 |
|
| 46 |
int32_t m_fd = -1; |
| 47 |
std::unique_ptr<VirtGpuDevice> m_device; |
| 48 |
VirtGpuResourcePtr m_resource; |
| 49 |
VirtGpuResourceMappingPtr m_resourceMapping; |
| 50 |
unsigned char* m_virtio_mapped; // user mapping of bo |
| 51 |
|
| 52 |
// intermediate buffer |
| 53 |
size_t m_bufsize; |
| 54 |
unsigned char* m_buf; |
| 55 |
|
| 56 |
size_t m_writtenPos; |
| 57 |
}; |