| 1 |
/* |
| 2 |
* Copyright 2011 Google |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __ADDRESS_SPACE_STREAM_H |
| 7 |
#define __ADDRESS_SPACE_STREAM_H |
| 8 |
|
| 9 |
#include "VirtGpu.h" |
| 10 |
#include "address_space.h" |
| 11 |
#include "address_space_graphics_types.h" |
| 12 |
#include "gfxstream/guest/IOStream.h" |
| 13 |
|
| 14 |
using gfxstream::guest::IOStream; |
| 15 |
|
| 16 |
class AddressSpaceStream : public IOStream { |
| 17 |
public: |
| 18 |
explicit AddressSpaceStream(address_space_handle_t handle, uint32_t version, |
| 19 |
struct asg_context context, uint64_t ringOffset, |
| 20 |
uint64_t writeBufferOffset, struct address_space_ops ops); |
| 21 |
~AddressSpaceStream(); |
| 22 |
|
| 23 |
virtual size_t idealAllocSize(size_t len); |
| 24 |
virtual void* allocBuffer(size_t minSize); |
| 25 |
virtual int commitBuffer(size_t size); |
| 26 |
virtual const unsigned char* readFully(void* buf, size_t len); |
| 27 |
virtual const unsigned char* read(void* buf, size_t* inout_len); |
| 28 |
virtual int writeFully(const void* buf, size_t len); |
| 29 |
virtual int writeFullyAsync(const void* buf, size_t len); |
| 30 |
virtual const unsigned char* commitBufferAndReadFully(size_t size, void* buf, size_t len); |
| 31 |
|
| 32 |
void setMapping(VirtGpuResourceMappingPtr mapping) { m_mapping = mapping; } |
| 33 |
|
| 34 |
void setResourceId(uint32_t id) { m_resourceId = id; } |
| 35 |
|
| 36 |
private: |
| 37 |
bool isInError() const; |
| 38 |
ssize_t speculativeRead(unsigned char* readBuffer, size_t trySize); |
| 39 |
void notifyAvailable(); |
| 40 |
uint32_t getRelativeBufferPos(uint32_t pos); |
| 41 |
void advanceWrite(); |
| 42 |
void ensureConsumerFinishing(); |
| 43 |
void ensureType1Finished(); |
| 44 |
void ensureType3Finished(); |
| 45 |
int type1Write(uint32_t offset, size_t size); |
| 46 |
|
| 47 |
void backoff(); |
| 48 |
void resetBackoff(); |
| 49 |
|
| 50 |
VirtGpuResourceMappingPtr m_mapping = nullptr; |
| 51 |
struct address_space_ops m_ops; |
| 52 |
|
| 53 |
unsigned char* m_tmpBuf; |
| 54 |
size_t m_tmpBufSize; |
| 55 |
size_t m_tmpBufXferSize; |
| 56 |
bool m_usingTmpBuf; |
| 57 |
|
| 58 |
unsigned char* m_readBuf; |
| 59 |
size_t m_read; |
| 60 |
size_t m_readLeft; |
| 61 |
|
| 62 |
address_space_handle_t m_handle; |
| 63 |
uint32_t m_version; |
| 64 |
struct asg_context m_context; |
| 65 |
|
| 66 |
uint64_t m_ringOffset; |
| 67 |
uint64_t m_writeBufferOffset; |
| 68 |
|
| 69 |
uint32_t m_writeBufferSize; |
| 70 |
uint32_t m_writeBufferMask; |
| 71 |
unsigned char* m_buf; |
| 72 |
unsigned char* m_writeStart; |
| 73 |
uint32_t m_writeStep; |
| 74 |
|
| 75 |
uint32_t m_notifs; |
| 76 |
uint32_t m_written; |
| 77 |
|
| 78 |
uint64_t m_backoffIters; |
| 79 |
uint64_t m_backoffFactor; |
| 80 |
|
| 81 |
size_t m_ringStorageSize; |
| 82 |
uint32_t m_resourceId = 0; |
| 83 |
}; |
| 84 |
|
| 85 |
#endif |