drm/nouveau/fbcon: convert copyarea() to new push macros
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / nv50_fbcon.c
1 /*
2  * Copyright 2010 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24 #define NVIF_DEBUG_PRINT_DISABLE
25 #include "nouveau_drv.h"
26 #include "nouveau_dma.h"
27 #include "nouveau_fbcon.h"
28 #include "nouveau_vmm.h"
29
30 #include <nvif/push206e.h>
31
32 int
33 nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
34 {
35         struct nouveau_fbdev *nfbdev = info->par;
36         struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
37         struct nouveau_channel *chan = drm->channel;
38         struct nvif_push *push = chan->chan.push;
39         u32 colour;
40         int ret;
41
42         if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
43             info->fix.visual == FB_VISUAL_DIRECTCOLOR)
44                 colour = ((uint32_t *)info->pseudo_palette)[rect->color];
45         else
46                 colour = rect->color;
47
48         ret = PUSH_WAIT(push, rect->rop == ROP_COPY ? 7 : 11);
49         if (ret)
50                 return ret;
51
52         if (rect->rop != ROP_COPY) {
53                 PUSH_NVSQ(push, NV502D, 0x02ac, 1);
54         }
55
56         PUSH_NVSQ(push, NV502D, 0x0588, colour);
57         PUSH_NVSQ(push, NV502D, 0x0600, rect->dx,
58                                 0x0604, rect->dy,
59                                 0x0608, rect->dx + rect->width,
60                                 0x060c, rect->dy + rect->height);
61
62         if (rect->rop != ROP_COPY) {
63                 PUSH_NVSQ(push, NV502D, 0x02ac, 3);
64         }
65
66         PUSH_KICK(push);
67         return 0;
68 }
69
70 int
71 nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
72 {
73         struct nouveau_fbdev *nfbdev = info->par;
74         struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
75         struct nouveau_channel *chan = drm->channel;
76         struct nvif_push *push = chan->chan.push;
77         int ret;
78
79         ret = PUSH_WAIT(push, 12);
80         if (ret)
81                 return ret;
82
83         PUSH_NVSQ(push, NV502D, 0x0110, 0);
84         PUSH_NVSQ(push, NV502D, 0x08b0, region->dx,
85                                 0x08b4, region->dy,
86                                 0x08b8, region->width,
87                                 0x08bc, region->height);
88         PUSH_NVSQ(push, NV502D, 0x08d0, 0,
89                                 0x08d4, region->sx,
90                                 0x08d8, 0,
91                                 0x08dc, region->sy);
92         PUSH_KICK(push);
93         return 0;
94 }
95
96 int
97 nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
98 {
99         struct nouveau_fbdev *nfbdev = info->par;
100         struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
101         struct nouveau_channel *chan = drm->channel;
102         struct nvif_push *push = chan->chan.push;
103         uint32_t dwords, *data = (uint32_t *)image->data;
104         uint32_t mask = ~(~0 >> (32 - info->var.bits_per_pixel));
105         uint32_t *palette = info->pseudo_palette, bg, fg;
106         int ret;
107
108         if (image->depth != 1)
109                 return -ENODEV;
110
111         if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
112             info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
113                 bg = palette[image->bg_color] | mask;
114                 fg = palette[image->fg_color] | mask;
115         } else {
116                 bg = image->bg_color;
117                 fg = image->fg_color;
118         }
119
120         ret = PUSH_WAIT(push, 11);
121         if (ret)
122                 return ret;
123
124         PUSH_NVSQ(push, NV502D, 0x0814, bg,
125                                 0x0818, fg);
126         PUSH_NVSQ(push, NV502D, 0x0838, image->width,
127                                 0x083c, image->height);
128         PUSH_NVSQ(push, NV502D, 0x0850, 0,
129                                 0x0854, image->dx,
130                                 0x0858, 0,
131                                 0x085c, image->dy);
132
133         dwords = ALIGN(ALIGN(image->width, 8) * image->height, 32) >> 5;
134         while (dwords) {
135                 int count = dwords > 2047 ? 2047 : dwords;
136
137                 ret = PUSH_WAIT(push, count + 1);
138                 if (ret)
139                         return ret;
140
141                 dwords -= count;
142
143                 PUSH_NVNI(push, NV502D, 0x0860, data, count);
144                 data += count;
145         }
146
147         PUSH_KICK(push);
148         return 0;
149 }
150
151 int
152 nv50_fbcon_accel_init(struct fb_info *info)
153 {
154         struct nouveau_fbdev *nfbdev = info->par;
155         struct drm_device *dev = nfbdev->helper.dev;
156         struct nouveau_drm *drm = nouveau_drm(dev);
157         struct nouveau_channel *chan = drm->channel;
158         struct nvif_push *push = chan->chan.push;
159         int ret, format;
160
161         switch (info->var.bits_per_pixel) {
162         case 8:
163                 format = 0xf3;
164                 break;
165         case 15:
166                 format = 0xf8;
167                 break;
168         case 16:
169                 format = 0xe8;
170                 break;
171         case 32:
172                 switch (info->var.transp.length) {
173                 case 0: /* depth 24 */
174                 case 8: /* depth 32, just use 24.. */
175                         format = 0xe6;
176                         break;
177                 case 2: /* depth 30 */
178                         format = 0xd1;
179                         break;
180                 default:
181                         return -EINVAL;
182                 }
183                 break;
184         default:
185                 return -EINVAL;
186         }
187
188         ret = nvif_object_ctor(&chan->user, "fbconTwoD", 0x502d, 0x502d,
189                                NULL, 0, &nfbdev->twod);
190         if (ret)
191                 return ret;
192
193         ret = PUSH_WAIT(push, 56);
194         if (ret) {
195                 nouveau_fbcon_gpu_lockup(info);
196                 return ret;
197         }
198
199         PUSH_NVSQ(push, NV502D, 0x0000, nfbdev->twod.handle);
200         PUSH_NVSQ(push, NV502D, 0x0184, chan->vram.handle,
201                                 0x0188, chan->vram.handle,
202                                 0x018c, chan->vram.handle);
203
204         PUSH_NVSQ(push, NV502D, 0x0200, format,
205                                 0x0204, 1);
206         PUSH_NVSQ(push, NV502D, 0x0214, info->fix.line_length,
207                                 0x0218, info->var.xres_virtual,
208                                 0x021c, info->var.yres_virtual,
209                                 0x0220, upper_32_bits(nfbdev->vma->addr),
210                                 0x0224, lower_32_bits(nfbdev->vma->addr));
211
212         PUSH_NVSQ(push, NV502D, 0x0230, format,
213                                 0x0234, 1);
214         PUSH_NVSQ(push, NV502D, 0x0244, info->fix.line_length,
215                                 0x0248, info->var.xres_virtual,
216                                 0x024c, info->var.yres_virtual,
217                                 0x0250, upper_32_bits(nfbdev->vma->addr),
218                                 0x0254, lower_32_bits(nfbdev->vma->addr));
219
220         PUSH_NVSQ(push, NV502D, 0x0290, 0);
221         PUSH_NVSQ(push, NV502D, 0x02a0, 0x55);
222         PUSH_NVSQ(push, NV502D, 0x02ac, 3);
223         PUSH_NVSQ(push, NV502D, 0x02e8, 2,
224                                 0x02ec, 1);
225
226         PUSH_NVSQ(push, NV502D, 0X0580, 4,
227                                 0x0584, format);
228
229         PUSH_NVSQ(push, NV502D, 0x0800, 1,
230                                 0x0804, format,
231                                 0x0808, 0,
232                                 0x080c, 0,
233                                 0x0810, 1);
234         PUSH_NVSQ(push, NV502D, 0x081c, 1);
235         PUSH_NVSQ(push, NV502D, 0x0840, 0,
236                                 0x0844, 1,
237                                 0x0848, 0,
238                                 0x084c, 1);
239
240         PUSH_NVSQ(push, NV502D, 0x0888, 1);
241         PUSH_NVSQ(push, NV502D, 0x08c0, 0,
242                                 0x08c4, 1,
243                                 0x08c8, 0,
244                                 0x08cc, 1);
245
246         PUSH_KICK(push);
247         return 0;
248 }
249