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
174
175
176
177
178
179
|
#include "pipe/p_context.h"
#include "nouveau_context.h"
static INLINE int
nv50_format(int cpp)
{
switch (cpp) {
case 4: return NV50_2D_DST_FORMAT_32BPP;
case 3: return NV50_2D_DST_FORMAT_24BPP;
case 2: return NV50_2D_DST_FORMAT_16BPP;
case 1: return NV50_2D_DST_FORMAT_8BPP;
default:
return -1;
}
}
static int
nv50_surface_copy_prep(struct nouveau_context *nv,
struct pipe_surface *dst, struct pipe_surface *src)
{
struct nouveau_channel *chan = nv->nvc->channel;
struct nouveau_grobj *eng2d = nv->nvc->Nv2D;
int surf_format;
assert(src->cpp == dst->cpp);
surf_format = nv50_format(dst->cpp);
assert(surf_format >= 0);
BEGIN_RING(chan, eng2d, NV50_2D_DMA_IN_MEMORY0, 2);
OUT_RELOCo(chan, src->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
OUT_RELOCo(chan, dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 2);
OUT_RING (chan, surf_format);
OUT_RING (chan, 1);
BEGIN_RING(chan, eng2d, NV50_2D_DST_PITCH, 5);
OUT_RING (chan, dst->pitch * dst->cpp);
OUT_RING (chan, dst->pitch);
OUT_RING (chan, dst->height);
OUT_RELOCh(chan, dst->buffer, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
OUT_RELOCl(chan, dst->buffer, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, eng2d, NV50_2D_CLIP_X, 4);
OUT_RING (chan, 0);
OUT_RING (chan, 0);
OUT_RING (chan, dst->pitch);
OUT_RING (chan, dst->height);
BEGIN_RING(chan, eng2d, NV50_2D_SRC_FORMAT, 2);
OUT_RING (chan, surf_format);
OUT_RING (chan, 1);
BEGIN_RING(chan, eng2d, NV50_2D_SRC_PITCH, 5);
OUT_RING (chan, src->pitch * src->cpp);
OUT_RING (chan, src->pitch);
OUT_RING (chan, src->height);
OUT_RELOCh(chan, src->buffer, src->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
OUT_RELOCl(chan, src->buffer, src->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
return 0;
}
static void
nv50_surface_copy(struct nouveau_context *nv, unsigned dx, unsigned dy,
unsigned sx, unsigned sy, unsigned w, unsigned h)
{
struct nouveau_channel *chan = nv->nvc->channel;
struct nouveau_grobj *eng2d = nv->nvc->Nv2D;
BEGIN_RING(chan, eng2d, 0x0110, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, eng2d, NV50_2D_BLIT_DST_X, 12);
OUT_RING (chan, dx);
OUT_RING (chan, dy);
OUT_RING (chan, w);
OUT_RING (chan, h);
OUT_RING (chan, 0);
OUT_RING (chan, 1);
OUT_RING (chan, 0);
OUT_RING (chan, 1);
OUT_RING (chan, 0);
OUT_RING (chan, sx);
OUT_RING (chan, 0);
OUT_RING (chan, sy);
}
static void
nv50_surface_copy_done(struct nouveau_context *nv)
{
FIRE_RING(nv->nvc->channel);
}
static int
nv50_surface_fill(struct nouveau_context *nv, struct pipe_surface *dst,
unsigned dx, unsigned dy, unsigned w, unsigned h,
unsigned value)
{
struct nouveau_channel *chan = nv->nvc->channel;
struct nouveau_grobj *eng2d = nv->nvc->Nv2D;
int surf_format, rect_format;
surf_format = nv50_format(dst->cpp);
if (surf_format < 0)
return 1;
rect_format = nv50_format(dst->cpp);
if (rect_format < 0)
return 1;
BEGIN_RING(chan, eng2d, NV50_2D_DMA_IN_MEMORY1, 1);
OUT_RELOCo(chan, dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 2);
OUT_RING (chan, surf_format);
OUT_RING (chan, 1);
BEGIN_RING(chan, eng2d, NV50_2D_DST_PITCH, 5);
OUT_RING (chan, dst->pitch * dst->cpp);
OUT_RING (chan, dst->pitch);
OUT_RING (chan, dst->height);
OUT_RELOCh(chan, dst->buffer, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
OUT_RELOCl(chan, dst->buffer, dst->offset,
NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
BEGIN_RING(chan, eng2d, NV50_2D_CLIP_X, 4);
OUT_RING (chan, 0);
OUT_RING (chan, 0);
OUT_RING (chan, dst->pitch);
OUT_RING (chan, dst->height);
BEGIN_RING(chan, eng2d, 0x0580, 3);
OUT_RING (chan, 4);
OUT_RING (chan, rect_format);
OUT_RING (chan, value);
BEGIN_RING(chan, eng2d, NV50_2D_RECT_X1, 4);
OUT_RING (chan, dx);
OUT_RING (chan, dy);
OUT_RING (chan, dx + w);
OUT_RING (chan, dy + h);
FIRE_RING(chan);
return 0;
}
int
nouveau_surface_channel_create_nv50(struct nouveau_channel_context *nvc)
{
int ret;
ret = nouveau_grobj_alloc(nvc->channel, nvc->next_handle++, NV50_2D,
&nvc->Nv2D);
if (ret)
return ret;
BIND_RING (nvc->channel, nvc->Nv2D, nvc->next_subchannel++);
BEGIN_RING(nvc->channel, nvc->Nv2D, NV50_2D_DMA_NOTIFY, 1);
OUT_RING (nvc->channel, nvc->sync_notifier->handle);
BEGIN_RING(nvc->channel, nvc->Nv2D, NV50_2D_DMA_IN_MEMORY0, 2);
OUT_RING (nvc->channel, nvc->channel->vram->handle);
OUT_RING (nvc->channel, nvc->channel->vram->handle);
BEGIN_RING(nvc->channel, nvc->Nv2D, NV50_2D_OPERATION, 1);
OUT_RING (nvc->channel, NV50_2D_OPERATION_SRCCOPY);
return 0;
}
int
nouveau_surface_init_nv50(struct nouveau_context *nv)
{
nv->surface_copy_prep = nv50_surface_copy_prep;
nv->surface_copy = nv50_surface_copy;
nv->surface_copy_done = nv50_surface_copy_done;
nv->surface_fill = nv50_surface_fill;
return 0;
}
|