-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadeonGfx.cpp
77 lines (65 loc) · 1.68 KB
/
RadeonGfx.cpp
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
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <strings.h>
#include <FindDirectory.h>
#include <graphic_driver.h>
#include <Accelerant.h>
#include <String.h>
#include <private/shared/AutoDeleter.h>
#include <private/shared/AutoDeleterOS.h>
#include <private/shared/AutoDeleterPosix.h>
#include "RadeonDevice.h"
#include "RadeonServer.h"
#define CheckRet(err) {status_t _err = (err); if (_err < B_OK) return _err;}
status_t RadeonTest();
status_t InitDevice()
{
const char *apath = "/dev/graphics";
struct dirent *e;
char name_buf[1024];
/* open directory apath */
DirCloser d(opendir(apath));
if (!d.IsSet()) return B_ERROR;
while ((e = readdir(d.Get())) != NULL) {
if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, ".."))
continue;
sprintf(name_buf, "%s/%s", apath, e->d_name);
printf("path: %s\n", name_buf);
FileDescriptorCloser fd(open(name_buf, B_READ_WRITE));
char signature[1024];
if (ioctl(fd.Get(), B_GET_ACCELERANT_SIGNATURE, &signature, sizeof(signature)) < B_OK) {
printf("B_GET_ACCELERANT_SIGNATURE failed\n");
continue;
}
printf("signature: %s\n", signature);
if (strcmp(signature, "radeon_gfx.accelerant") == 0) {
CheckRet(gDevice.Init(fd.Get()));
return B_OK;
}
}
return B_ERROR;
}
int main(int argc, char** argv)
{
enum Mode {
testMode,
serverMode
};
Mode mode = serverMode;
if (argc >= 2) {
if (strcmp(argv[1], "server") == 0) mode = serverMode;
if (strcmp(argv[1], "test") == 0) mode = testMode;
}
/*if (mode == serverMode)*/ RadeonInitServer();
if (InitDevice() < B_OK) return -1;
switch (mode) {
case serverMode:
RadeonRunServer();
break;
case testMode:
RadeonTest();
break;
}
return 0;
}