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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
#include "drmP.h"
#include "nouveau_drv.h"
#include "nouveau_dma.h"
#include "nouveau_fbcon.h"
static int
nv50_fbcon_sync(struct fb_info *info)
{
struct nouveau_fbcon_par *par = info->par;
struct drm_device *dev = par->dev;
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = dev_priv->channel;
int ret, i;
if (!chan->accel_done ||
info->state != FBINFO_STATE_RUNNING ||
info->flags & FBINFO_HWACCEL_DISABLED)
return 0;
if (RING_SPACE(chan, 4)) {
DRM_ERROR("GPU lockup - switching to software fbcon\n");
info->flags |= FBINFO_HWACCEL_DISABLED;
return 0;
}
BEGIN_RING(chan, 0, 0x0104, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, 0, 0x0100, 1);
OUT_RING (chan, 0);
chan->m2mf_ntfy_map[3] = 0xffffffff;
FIRE_RING (chan);
ret = -EBUSY;
for (i = 0; i < 100000; i++) {
if (chan->m2mf_ntfy_map[3] == 0) {
ret = 0;
break;
}
DRM_UDELAY(1);
}
if (ret) {
DRM_ERROR("GPU lockup - switching to software fbcon\n");
info->flags |= FBINFO_HWACCEL_DISABLED;
return 0;
}
chan->accel_done = false;
return 0;
}
static void
nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
{
struct nouveau_fbcon_par *par = info->par;
struct drm_nouveau_private *dev_priv = par->dev->dev_private;
struct nouveau_channel *chan = dev_priv->channel;
if (info->state != FBINFO_STATE_RUNNING)
return;
if (info->flags & FBINFO_HWACCEL_DISABLED) {
cfb_fillrect(info, rect);
return;
}
if (RING_SPACE(chan, 9)) {
DRM_ERROR("GPU lockup - switching to software fbcon\n");
info->flags |= FBINFO_HWACCEL_DISABLED;
cfb_fillrect(info, rect);
return;
}
BEGIN_RING(chan, NvSub2D, 0x02ac, 1);
OUT_RING (chan, rect->rop == ROP_COPY ? 3 : 1);
BEGIN_RING(chan, NvSub2D, 0x0588, 1);
OUT_RING (chan, rect->color);
BEGIN_RING(chan, NvSub2D, 0x0600, 4);
OUT_RING (chan, rect->dx);
OUT_RING (chan, rect->dy);
OUT_RING (chan, rect->dx + rect->width);
OUT_RING (chan, rect->dy + rect->height);
FIRE_RING (chan);
}
static void
nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
{
struct nouveau_fbcon_par *par = info->par;
struct drm_nouveau_private *dev_priv = par->dev->dev_private;
struct nouveau_channel *chan = dev_priv->channel;
if (info->state != FBINFO_STATE_RUNNING)
return;
if (info->flags & FBINFO_HWACCEL_DISABLED) {
cfb_copyarea(info, region);
return;
}
if (RING_SPACE(chan, 17)) {
DRM_ERROR("GPU lockup - switching to software fbcon\n");
info->flags |= FBINFO_HWACCEL_DISABLED;
cfb_copyarea(info, region);
return;
}
BEGIN_RING(chan, NvSub2D, 0x02ac, 1);
OUT_RING (chan, 3);
BEGIN_RING(chan, NvSub2D, 0x0110, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, NvSub2D, 0x08b0, 12);
OUT_RING (chan, region->dx);
OUT_RING (chan, region->dy);
OUT_RING (chan, region->width);
OUT_RING (chan, region->height);
OUT_RING (chan, 0);
OUT_RING (chan, 1);
OUT_RING (chan, 0);
OUT_RING (chan, 1);
OUT_RING (chan, 0);
OUT_RING (chan, region->sx);
OUT_RING (chan, 0);
OUT_RING (chan, region->sy);
FIRE_RING (chan);
}
static void
nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
{
if (info->state != FBINFO_STATE_RUNNING)
return;
if (info->flags & FBINFO_HWACCEL_DISABLED) {
cfb_imageblit(info, image);
return;
}
cfb_imageblit(info, image);
}
int
nv50_fbcon_accel_init(struct fb_info *info)
{
struct nouveau_fbcon_par *par = info->par;
struct drm_device *dev = par->dev;
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = dev_priv->channel;
struct nouveau_gpuobj *eng2d = NULL;
int ret, format;
switch (info->var.bits_per_pixel) {
case 16:
format = 0xe8;
break;
default:
format = 0xe6;
break;
}
ret = nouveau_gpuobj_gr_new(dev_priv->channel, 0x502d, &eng2d);
if (ret)
return ret;
ret = nouveau_gpuobj_ref_add(dev, dev_priv->channel, Nv2D, eng2d, NULL);
if (ret)
return ret;
ret = RING_SPACE(chan, 34);
if (ret) {
DRM_ERROR("GPU lockup - switching to software fbcon\n");
return ret;
}
BEGIN_RING(chan, NvSub2D, 0x0000, 1);
OUT_RING (chan, Nv2D);
BEGIN_RING(chan, NvSub2D, 0x0180, 4);
OUT_RING (chan, NvNotify0);
OUT_RING (chan, chan->vram_handle);
OUT_RING (chan, chan->vram_handle);
OUT_RING (chan, chan->vram_handle);
BEGIN_RING(chan, NvSub2D, 0x0290, 1);
OUT_RING (chan, 0);
BEGIN_RING(chan, NvSub2D, 0x0888, 1);
OUT_RING (chan, 1);
BEGIN_RING(chan, NvSub2D, 0x02a0, 1);
OUT_RING (chan, 0x55);
BEGIN_RING(chan, NvSub2D, 0x0580, 2);
OUT_RING (chan, 4);
OUT_RING (chan, format);
BEGIN_RING(chan, NvSub2D, 0x0200, 2);
OUT_RING (chan, format);
OUT_RING (chan, 1);
BEGIN_RING(chan, NvSub2D, 0x0214, 5);
OUT_RING (chan, info->fix.line_length);
OUT_RING (chan, info->var.xres_virtual);
OUT_RING (chan, info->var.yres_virtual);
OUT_RING (chan, 0);
OUT_RING (chan, info->fix.smem_start - dev_priv->fb_phys +
dev_priv->vm_vram_base);
BEGIN_RING(chan, NvSub2D, 0x0230, 2);
OUT_RING (chan, format);
OUT_RING (chan, 1);
BEGIN_RING(chan, NvSub2D, 0x0244, 5);
OUT_RING (chan, info->fix.line_length);
OUT_RING (chan, info->var.xres_virtual);
OUT_RING (chan, info->var.yres_virtual);
OUT_RING (chan, 0);
OUT_RING (chan, info->fix.smem_start - dev_priv->fb_phys +
dev_priv->vm_vram_base);
info->fbops->fb_fillrect = nv50_fbcon_fillrect;
info->fbops->fb_copyarea = nv50_fbcon_copyarea;
info->fbops->fb_imageblit = nv50_fbcon_imageblit;
info->fbops->fb_sync = nv50_fbcon_sync;
return 0;
}
|