-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadeonMemory.h
168 lines (130 loc) · 3.6 KB
/
RadeonMemory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#pragma once
#include <map>
#include <Referenceable.h>
#include <private/shared/AutoDeleterOS.h>
#include "ExternalAllocator.h"
#include "BitfieldAllocator.h"
#include "SADomains/Domains.h"
#include "SADomains/DomainCondVars.h"
#include "FdObject.h"
struct BufferObject;
class AddressSpace;
enum MemoryDomain {
boDomainVram = 0,
boDomainVramMappable,
boDomainGtt,
};
#define R600_PTE_VALID (1 << 0)
#define R600_PTE_SYSTEM (1 << 1)
#define R600_PTE_SNOOPED (1 << 2)
#define R600_PTE_READABLE (1 << 5)
#define R600_PTE_WRITEABLE (1 << 6)
#define R600_PTE_FRAG_4KB (0 << 7)
#define R600_PTE_FRAG_64KB (4 << 7)
#define R600_PTE_FRAG_256KB (6 << 7)
struct BufferObject: public FdObject {
// not used yet
struct Info {
uint64 size;
uint64 alignment;
MemoryDomain domain;
uint32 flags;
};
struct Metadata {
uint64 flags;
uint64 tiling_info;
uint32 data_size_bytes;
uint32 data[64];
};
MemoryDomain domain;
uint64 gpuPhysAdr;
uint64 size;
uint64 offset; // relative to area
AreaDeleter area;
Metadata metadata{};
Info GetInfo();
~BufferObject();
};
struct MappedBuffer {
BReference<BufferObject> buf;
void *adr;
MappedBuffer(): adr(NULL) {}
MappedBuffer(BReference<BufferObject> buffer) {SetTo(buffer);}
status_t SetTo(BReference<BufferObject> buffer);
};
union Pte {
struct {
uint64 flags: 12;
uint64 ppn: 52;
};
uint64 val;
};
class AddressSpace: public BReferenceable {
private:
struct Mapping {
BReference<BufferObject> buffer;
uint64 offset;
uint64 size;
};
int32 fVmId;
int32 fVmIdRefCnt;
std::map<uint64, Mapping> fMappings;
public:
enum {
pageDirLen = 1 << 12,
pageTableLen = 1 << 9,
};
private:
MappedBuffer fPageDirBuf;
ArrayDeleter<MappedBuffer> fPageTableBufs;
Pte *LookupPte(uint64 virtAdr, bool alloc);
status_t MapInt(uint64 virtAdr, uint64 physAdr, uint32 flags);
status_t MapIntRange(uint64 virtAdr, uint64 physAdr, uint64 size, uint32 flags);
status_t UnmapInt(uint64 virtAdr);
public:
AddressSpace();
virtual ~AddressSpace();
uint64 PageDir() {return fPageDirBuf.buf->gpuPhysAdr;}
void DumpPageTable();
BReference<BufferObject> Lookup(uint64 mapAdr, uint64 &offset);
status_t Map(BReference<BufferObject> buffer, uint64 mapAdr, uint64 offset, uint64 size);
status_t Unmap(BReference<BufferObject> buffer, uint64 mapAdr, uint64 offset, uint64 size);
int32 AcquireVmid();
void ReleaseVmid();
};
class MemoryManager: public Object {
public:
struct {
uint64 beg, size;
} fVramRange, fGttRange;
private:
ExternalAllocator fDomainPools[3];
friend struct BufferObject;
friend class AddressSpace;
bool fGartEnabled;
MappedBuffer fGartPageTable;
BitfieldAllocator fVmidPool;
DomainCondVar fFreeVmidCv;
MappedBuffer fWritebackBuf;
ExternalAllocator fWritebackPool;
public:
BReference<BufferObject> fDummyPage;
BReference<BufferObject> fVramScratch;
private:
status_t GartMap(BReference<BufferObject> buffer);
status_t GartUnmap(BufferObject *buffer);
void GartFlushTlb();
int32 AllocVmid();
void FreeVmid(int32 vmid);
public:
MemoryManager();
BReference<BufferObject> Alloc(MemoryDomain domain, uint64 size, uint64 alignment = B_PAGE_SIZE, uint32 flags = 0, area_id area = B_ERROR, uint64 offset = 0);
BReference<BufferObject> AllocAt(uint64 gpuAdr, uint64 size, uint64 alignment = B_PAGE_SIZE, uint32 flags = 0);
status_t CpuMap(void*& adr, BReference<BufferObject> buffer, uint64 offset, uint64 size);
status_t GetUsage(uint64 &total, uint64 &alloc, MemoryDomain domain);
status_t Init();
status_t InitGart();
status_t AllocWriteback(uint64 &gpuAdr, void *&cpuAdr, uint64 size);
void FreeWriteback(uint64 gpuAdr);
};
void MemoryTest();