blob: 33e4c9388bc1b8f787f5bc89e7350670098a7722 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright 2009 Ben Skeggs
3 * Copyright 2008 Stuart Bennett
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include "drmP.h"
26#include "nouveau_drv.h"
27#include "nouveau_dma.h"
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100028#include "nouveau_ramht.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100029#include "nouveau_fbcon.h"
30
Marcin Kościelnicki126b5442010-01-27 14:03:18 +000031void
Ben Skeggs6ee73862009-12-11 19:24:15 +100032nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
33{
Dave Airlie8be48d92010-03-30 05:34:14 +000034 struct nouveau_fbdev *nfbdev = info->par;
35 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +100036 struct drm_nouveau_private *dev_priv = dev->dev_private;
37 struct nouveau_channel *chan = dev_priv->channel;
38
39 if (info->state != FBINFO_STATE_RUNNING)
40 return;
41
42 if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 4)) {
Marcin Slusarz846975a2010-01-04 19:25:09 +010043 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +100044 }
45
46 if (info->flags & FBINFO_HWACCEL_DISABLED) {
47 cfb_copyarea(info, region);
48 return;
49 }
50
51 BEGIN_RING(chan, NvSubImageBlit, 0x0300, 3);
52 OUT_RING(chan, (region->sy << 16) | region->sx);
53 OUT_RING(chan, (region->dy << 16) | region->dx);
54 OUT_RING(chan, (region->height << 16) | region->width);
55 FIRE_RING(chan);
56}
57
Marcin Kościelnicki126b5442010-01-27 14:03:18 +000058void
Ben Skeggs6ee73862009-12-11 19:24:15 +100059nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
60{
Dave Airlie8be48d92010-03-30 05:34:14 +000061 struct nouveau_fbdev *nfbdev = info->par;
62 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +100063 struct drm_nouveau_private *dev_priv = dev->dev_private;
64 struct nouveau_channel *chan = dev_priv->channel;
Ben Skeggs6ee73862009-12-11 19:24:15 +100065
66 if (info->state != FBINFO_STATE_RUNNING)
67 return;
68
69 if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 7)) {
Marcin Slusarz846975a2010-01-04 19:25:09 +010070 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +100071 }
72
73 if (info->flags & FBINFO_HWACCEL_DISABLED) {
74 cfb_fillrect(info, rect);
75 return;
76 }
77
78 BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
79 OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
80 BEGIN_RING(chan, NvSubGdiRect, 0x03fc, 1);
Ben Skeggsbf5302b2010-01-04 09:10:55 +100081 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
82 info->fix.visual == FB_VISUAL_DIRECTCOLOR)
83 OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
84 else
85 OUT_RING(chan, rect->color);
Ben Skeggs6ee73862009-12-11 19:24:15 +100086 BEGIN_RING(chan, NvSubGdiRect, 0x0400, 2);
87 OUT_RING(chan, (rect->dx << 16) | rect->dy);
88 OUT_RING(chan, (rect->width << 16) | rect->height);
89 FIRE_RING(chan);
90}
91
Marcin Kościelnicki126b5442010-01-27 14:03:18 +000092void
Ben Skeggs6ee73862009-12-11 19:24:15 +100093nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
94{
Dave Airlie8be48d92010-03-30 05:34:14 +000095 struct nouveau_fbdev *nfbdev = info->par;
96 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +100097 struct drm_nouveau_private *dev_priv = dev->dev_private;
98 struct nouveau_channel *chan = dev_priv->channel;
99 uint32_t fg;
100 uint32_t bg;
101 uint32_t dsize;
102 uint32_t width;
103 uint32_t *data = (uint32_t *)image->data;
104
105 if (info->state != FBINFO_STATE_RUNNING)
106 return;
107
108 if (image->depth != 1) {
109 cfb_imageblit(info, image);
110 return;
111 }
112
113 if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 8)) {
Marcin Slusarz846975a2010-01-04 19:25:09 +0100114 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000115 }
116
117 if (info->flags & FBINFO_HWACCEL_DISABLED) {
118 cfb_imageblit(info, image);
119 return;
120 }
121
Marcin Kościelnickic82b88d2010-02-27 18:13:35 +0000122 width = ALIGN(image->width, 8);
123 dsize = ALIGN(width * image->height, 32) >> 5;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000124
125 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
126 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
127 fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
128 bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
129 } else {
130 fg = image->fg_color;
131 bg = image->bg_color;
132 }
133
134 BEGIN_RING(chan, NvSubGdiRect, 0x0be4, 7);
135 OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
136 OUT_RING(chan, ((image->dy + image->height) << 16) |
137 ((image->dx + image->width) & 0xffff));
138 OUT_RING(chan, bg);
139 OUT_RING(chan, fg);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000140 OUT_RING(chan, (image->height << 16) | width);
Marcin Kościelnickic82b88d2010-02-27 18:13:35 +0000141 OUT_RING(chan, (image->height << 16) | image->width);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000142 OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
143
144 while (dsize) {
145 int iter_len = dsize > 128 ? 128 : dsize;
146
147 if (RING_SPACE(chan, iter_len + 1)) {
Marcin Slusarz846975a2010-01-04 19:25:09 +0100148 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000149 cfb_imageblit(info, image);
150 return;
151 }
152
153 BEGIN_RING(chan, NvSubGdiRect, 0x0c00, iter_len);
154 OUT_RINGp(chan, data, iter_len);
155 data += iter_len;
156 dsize -= iter_len;
157 }
158
159 FIRE_RING(chan);
160}
161
162static int
163nv04_fbcon_grobj_new(struct drm_device *dev, int class, uint32_t handle)
164{
165 struct drm_nouveau_private *dev_priv = dev->dev_private;
166 struct nouveau_gpuobj *obj = NULL;
167 int ret;
168
169 ret = nouveau_gpuobj_gr_new(dev_priv->channel, class, &obj);
170 if (ret)
171 return ret;
172
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000173 ret = nouveau_ramht_insert(dev_priv->channel, handle, obj);
174 nouveau_gpuobj_ref(NULL, &obj);
175 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000176}
177
178int
179nv04_fbcon_accel_init(struct fb_info *info)
180{
Dave Airlie8be48d92010-03-30 05:34:14 +0000181 struct nouveau_fbdev *nfbdev = info->par;
182 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000183 struct drm_nouveau_private *dev_priv = dev->dev_private;
184 struct nouveau_channel *chan = dev_priv->channel;
Francisco Jerezf03a3142009-12-26 02:42:45 +0100185 const int sub = NvSubCtxSurf2D;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000186 int surface_fmt, pattern_fmt, rect_fmt;
187 int ret;
188
189 switch (info->var.bits_per_pixel) {
190 case 8:
191 surface_fmt = 1;
192 pattern_fmt = 3;
193 rect_fmt = 3;
194 break;
195 case 16:
196 surface_fmt = 4;
197 pattern_fmt = 1;
198 rect_fmt = 1;
199 break;
200 case 32:
201 switch (info->var.transp.length) {
202 case 0: /* depth 24 */
203 case 8: /* depth 32 */
204 break;
205 default:
206 return -EINVAL;
207 }
208
209 surface_fmt = 6;
210 pattern_fmt = 3;
211 rect_fmt = 3;
212 break;
213 default:
214 return -EINVAL;
215 }
216
217 ret = nv04_fbcon_grobj_new(dev, dev_priv->card_type >= NV_10 ?
218 0x0062 : 0x0042, NvCtxSurf2D);
219 if (ret)
220 return ret;
221
222 ret = nv04_fbcon_grobj_new(dev, 0x0019, NvClipRect);
223 if (ret)
224 return ret;
225
226 ret = nv04_fbcon_grobj_new(dev, 0x0043, NvRop);
227 if (ret)
228 return ret;
229
230 ret = nv04_fbcon_grobj_new(dev, 0x0044, NvImagePatt);
231 if (ret)
232 return ret;
233
234 ret = nv04_fbcon_grobj_new(dev, 0x004a, NvGdiRect);
235 if (ret)
236 return ret;
237
Marcin Kościelnickia0e65442010-04-11 18:16:21 +0000238 ret = nv04_fbcon_grobj_new(dev, dev_priv->chipset >= 0x11 ?
Ben Skeggs6ee73862009-12-11 19:24:15 +1000239 0x009f : 0x005f, NvImageBlit);
240 if (ret)
241 return ret;
242
243 if (RING_SPACE(chan, 49)) {
Marcin Slusarz846975a2010-01-04 19:25:09 +0100244 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000245 return 0;
246 }
247
Francisco Jerezf03a3142009-12-26 02:42:45 +0100248 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000249 OUT_RING(chan, NvCtxSurf2D);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100250 BEGIN_RING(chan, sub, 0x0184, 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000251 OUT_RING(chan, NvDmaFB);
252 OUT_RING(chan, NvDmaFB);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100253 BEGIN_RING(chan, sub, 0x0300, 4);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000254 OUT_RING(chan, surface_fmt);
255 OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
256 OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
257 OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
258
Francisco Jerezf03a3142009-12-26 02:42:45 +0100259 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000260 OUT_RING(chan, NvRop);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100261 BEGIN_RING(chan, sub, 0x0300, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000262 OUT_RING(chan, 0x55);
263
Francisco Jerezf03a3142009-12-26 02:42:45 +0100264 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000265 OUT_RING(chan, NvImagePatt);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100266 BEGIN_RING(chan, sub, 0x0300, 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000267 OUT_RING(chan, pattern_fmt);
268#ifdef __BIG_ENDIAN
269 OUT_RING(chan, 2);
270#else
271 OUT_RING(chan, 1);
272#endif
273 OUT_RING(chan, 0);
274 OUT_RING(chan, 1);
275 OUT_RING(chan, ~0);
276 OUT_RING(chan, ~0);
277 OUT_RING(chan, ~0);
278 OUT_RING(chan, ~0);
279
Francisco Jerezf03a3142009-12-26 02:42:45 +0100280 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000281 OUT_RING(chan, NvClipRect);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100282 BEGIN_RING(chan, sub, 0x0300, 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000283 OUT_RING(chan, 0);
284 OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
285
286 BEGIN_RING(chan, NvSubImageBlit, 0x0000, 1);
287 OUT_RING(chan, NvImageBlit);
288 BEGIN_RING(chan, NvSubImageBlit, 0x019c, 1);
289 OUT_RING(chan, NvCtxSurf2D);
290 BEGIN_RING(chan, NvSubImageBlit, 0x02fc, 1);
291 OUT_RING(chan, 3);
292
293 BEGIN_RING(chan, NvSubGdiRect, 0x0000, 1);
294 OUT_RING(chan, NvGdiRect);
295 BEGIN_RING(chan, NvSubGdiRect, 0x0198, 1);
296 OUT_RING(chan, NvCtxSurf2D);
297 BEGIN_RING(chan, NvSubGdiRect, 0x0188, 2);
298 OUT_RING(chan, NvImagePatt);
299 OUT_RING(chan, NvRop);
300 BEGIN_RING(chan, NvSubGdiRect, 0x0304, 1);
301 OUT_RING(chan, 1);
302 BEGIN_RING(chan, NvSubGdiRect, 0x0300, 1);
303 OUT_RING(chan, rect_fmt);
304 BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
305 OUT_RING(chan, 3);
306
307 FIRE_RING(chan);
308
Ben Skeggs6ee73862009-12-11 19:24:15 +1000309 return 0;
310}
311