-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbsp_test.c
173 lines (138 loc) · 5.07 KB
/
bsp_test.c
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
169
170
171
172
173
/*
* Copyright (C) 2013 Ilia Mirkin <imirkin@alum.mit.edu>
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <xf86drm.h>
#include <xcb/dri2.h>
#include "nv50/nv50_context.h"
#undef NDEBUG
#include <assert.h>
/* From pipe_loader_drm.c in mesa */
static void
pipe_loader_drm_x_auth(int fd)
{
/* Try authenticate with the X server to give us access to devices that X
* is running on. */
xcb_connection_t *xcb_conn;
const xcb_setup_t *xcb_setup;
xcb_screen_iterator_t s;
xcb_dri2_connect_cookie_t connect_cookie;
xcb_dri2_connect_reply_t *connect;
drm_magic_t magic;
xcb_dri2_authenticate_cookie_t authenticate_cookie;
xcb_dri2_authenticate_reply_t *authenticate;
xcb_conn = xcb_connect(NULL, NULL);
if(!xcb_conn)
return;
xcb_setup = xcb_get_setup(xcb_conn);
if (!xcb_setup)
goto disconnect;
s = xcb_setup_roots_iterator(xcb_setup);
connect_cookie = xcb_dri2_connect_unchecked(xcb_conn, s.data->root,
XCB_DRI2_DRIVER_TYPE_DRI);
connect = xcb_dri2_connect_reply(xcb_conn, connect_cookie, NULL);
if (!connect || connect->driver_name_length
+ connect->device_name_length == 0) {
goto disconnect;
}
if (drmGetMagic(fd, &magic))
goto disconnect;
authenticate_cookie = xcb_dri2_authenticate_unchecked(xcb_conn,
s.data->root,
magic);
authenticate = xcb_dri2_authenticate_reply(xcb_conn,
authenticate_cookie,
NULL);
FREE(authenticate);
disconnect:
xcb_disconnect(xcb_conn);
}
int main() {
struct nouveau_device *dev;
struct nouveau_client *client;
struct nouveau_object *channel;
struct nouveau_object *bsp;
struct nouveau_pushbuf *push;
struct nouveau_bo *sem = NULL;
struct nv04_fifo nv04_data = { .vram = 0xbeef0201, .gart = 0xbeef0202 };
int fd, i;
fd = open("/dev/dri/card0", O_RDWR);
assert(fd);
pipe_loader_drm_x_auth(fd);
assert(!nouveau_device_wrap(fd, 0, &dev));
assert(!nouveau_client_new(dev, &client));
assert(!nouveau_object_new(&dev->object, 0, NOUVEAU_FIFO_CHANNEL_CLASS,
&nv04_data, sizeof(nv04_data), &channel));
assert(!nouveau_pushbuf_new(client, channel, 2, 4096, 1, &push));
assert(!nouveau_object_new(channel, 0xbeef74b0, 0x74b0, NULL, 0, &bsp));
assert(!nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 0x1000, NULL, &sem));
printf("bo offset: %lx\n", sem->offset);
printf("bo handle: %x\n", sem->handle);
assert(!nouveau_bo_map(sem, NOUVEAU_BO_RD | NOUVEAU_BO_WR, client));
/*
struct nouveau_pushbuf_refn refs[] = {
{ sem, NOUVEAU_BO_RDWR }
};
assert(!nouveau_pushbuf_refn(push, refs, 1));
*/
printf("bo map: %p\n", sem->map);
uint32_t *map = sem->map;
*map = 0xdeadbeef;
BEGIN_NV04(push, 0, 0x60, 1);
PUSH_DATA (push, nv04_data.vram);
/* Bind the BSP to the fifo */
BEGIN_NV04(push, 1, 0, 1);
PUSH_DATA (push, bsp->handle);
/* Set the DMA channels */
BEGIN_NV04(push, 1, 0x180, 11);
for (i = 0; i < 11; i++)
PUSH_DATA(push, nv04_data.vram);
BEGIN_NV04(push, 1, 0x1b8, 1);
PUSH_DATA (push, nv04_data.vram);
/* Set the semaphore */
BEGIN_NV04(push, 1, 0x610, 3);
PUSH_DATAh(push, sem->offset);
PUSH_DATA (push, sem->offset);
PUSH_DATA (push, 0xabce);
/* Write abce to the semaphore location */
BEGIN_NV04(push, 1, 0x304, 1);
PUSH_DATA (push, 0x101);
BEGIN_NV04(push, 1, 0x80, 1);
PUSH_DATA (push, 0);
PUSH_KICK (push);
/* Wait for abce to come out */
BEGIN_NV04(push, 4, 0x10, 4);
PUSH_DATAh(push, sem->offset);
PUSH_DATA (push, sem->offset);
PUSH_DATA (push, 0xabce);
PUSH_DATA (push, 1); /* Wait for equal */
PUSH_KICK (push);
nouveau_bo_wait(sem, NOUVEAU_BO_RDWR, client);
printf("%x\n", *map);
usleep(10000);
printf("%x\n", *map);
return 0;
}