]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/gpu/drm/nouveau/nv04_fbcon.c
Merge branch 'drm-fixes' of /home/airlied/kernel/linux-2.6 into drm-core-next
[mv-sheeva.git] / drivers / gpu / drm / nouveau / nv04_fbcon.c
1 /*
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"
28 #include "nouveau_ramht.h"
29 #include "nouveau_fbcon.h"
30
31 void
32 nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
33 {
34         struct nouveau_fbdev *nfbdev = info->par;
35         struct drm_device *dev = nfbdev->dev;
36         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)) {
43                 nouveau_fbcon_gpu_lockup(info);
44         }
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
58 void
59 nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
60 {
61         struct nouveau_fbdev *nfbdev = info->par;
62         struct drm_device *dev = nfbdev->dev;
63         struct drm_nouveau_private *dev_priv = dev->dev_private;
64         struct nouveau_channel *chan = dev_priv->channel;
65
66         if (info->state != FBINFO_STATE_RUNNING)
67                 return;
68
69         if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 7)) {
70                 nouveau_fbcon_gpu_lockup(info);
71         }
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);
81         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);
86         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
92 void
93 nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
94 {
95         struct nouveau_fbdev *nfbdev = info->par;
96         struct drm_device *dev = nfbdev->dev;
97         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)) {
114                 nouveau_fbcon_gpu_lockup(info);
115         }
116
117         if (info->flags & FBINFO_HWACCEL_DISABLED) {
118                 cfb_imageblit(info, image);
119                 return;
120         }
121
122         width = ALIGN(image->width, 8);
123         dsize = ALIGN(width * image->height, 32) >> 5;
124
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);
140         OUT_RING(chan, (image->height << 16) | width);
141         OUT_RING(chan, (image->height << 16) | image->width);
142         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)) {
148                         nouveau_fbcon_gpu_lockup(info);
149                         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
162 static int
163 nv04_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
173         ret = nouveau_ramht_insert(dev_priv->channel, handle, obj);
174         nouveau_gpuobj_ref(NULL, &obj);
175         return ret;
176 }
177
178 int
179 nv04_fbcon_accel_init(struct fb_info *info)
180 {
181         struct nouveau_fbdev *nfbdev = info->par;
182         struct drm_device *dev = nfbdev->dev;
183         struct drm_nouveau_private *dev_priv = dev->dev_private;
184         struct nouveau_channel *chan = dev_priv->channel;
185         const int sub = NvSubCtxSurf2D;
186         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
238         ret = nv04_fbcon_grobj_new(dev, dev_priv->chipset >= 0x11 ?
239                                    0x009f : 0x005f, NvImageBlit);
240         if (ret)
241                 return ret;
242
243         if (RING_SPACE(chan, 49)) {
244                 nouveau_fbcon_gpu_lockup(info);
245                 return 0;
246         }
247
248         BEGIN_RING(chan, sub, 0x0000, 1);
249         OUT_RING(chan, NvCtxSurf2D);
250         BEGIN_RING(chan, sub, 0x0184, 2);
251         OUT_RING(chan, NvDmaFB);
252         OUT_RING(chan, NvDmaFB);
253         BEGIN_RING(chan, sub, 0x0300, 4);
254         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
259         BEGIN_RING(chan, sub, 0x0000, 1);
260         OUT_RING(chan, NvRop);
261         BEGIN_RING(chan, sub, 0x0300, 1);
262         OUT_RING(chan, 0x55);
263
264         BEGIN_RING(chan, sub, 0x0000, 1);
265         OUT_RING(chan, NvImagePatt);
266         BEGIN_RING(chan, sub, 0x0300, 8);
267         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
280         BEGIN_RING(chan, sub, 0x0000, 1);
281         OUT_RING(chan, NvClipRect);
282         BEGIN_RING(chan, sub, 0x0300, 2);
283         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
309         return 0;
310 }
311