blob: 7a11893710963677c5912fb305fed0a313aae162 [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
Ben Skeggsceed5f32010-10-05 16:41:29 +100031int
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;
Ben Skeggsceed5f32010-10-05 16:41:29 +100038 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100039
Ben Skeggsceed5f32010-10-05 16:41:29 +100040 ret = RING_SPACE(chan, 4);
41 if (ret)
42 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100043
44 BEGIN_RING(chan, NvSubImageBlit, 0x0300, 3);
45 OUT_RING(chan, (region->sy << 16) | region->sx);
46 OUT_RING(chan, (region->dy << 16) | region->dx);
47 OUT_RING(chan, (region->height << 16) | region->width);
48 FIRE_RING(chan);
Ben Skeggsceed5f32010-10-05 16:41:29 +100049 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +100050}
51
Ben Skeggsceed5f32010-10-05 16:41:29 +100052int
Ben Skeggs6ee73862009-12-11 19:24:15 +100053nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
54{
Dave Airlie8be48d92010-03-30 05:34:14 +000055 struct nouveau_fbdev *nfbdev = info->par;
56 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +100057 struct drm_nouveau_private *dev_priv = dev->dev_private;
58 struct nouveau_channel *chan = dev_priv->channel;
Ben Skeggsceed5f32010-10-05 16:41:29 +100059 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100060
Ben Skeggsceed5f32010-10-05 16:41:29 +100061 ret = RING_SPACE(chan, 7);
62 if (ret)
63 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100064
65 BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
66 OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
67 BEGIN_RING(chan, NvSubGdiRect, 0x03fc, 1);
Ben Skeggsbf5302b2010-01-04 09:10:55 +100068 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
69 info->fix.visual == FB_VISUAL_DIRECTCOLOR)
70 OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
71 else
72 OUT_RING(chan, rect->color);
Ben Skeggs6ee73862009-12-11 19:24:15 +100073 BEGIN_RING(chan, NvSubGdiRect, 0x0400, 2);
74 OUT_RING(chan, (rect->dx << 16) | rect->dy);
75 OUT_RING(chan, (rect->width << 16) | rect->height);
76 FIRE_RING(chan);
Ben Skeggsceed5f32010-10-05 16:41:29 +100077 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +100078}
79
Ben Skeggsceed5f32010-10-05 16:41:29 +100080int
Ben Skeggs6ee73862009-12-11 19:24:15 +100081nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
82{
Dave Airlie8be48d92010-03-30 05:34:14 +000083 struct nouveau_fbdev *nfbdev = info->par;
84 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +100085 struct drm_nouveau_private *dev_priv = dev->dev_private;
86 struct nouveau_channel *chan = dev_priv->channel;
87 uint32_t fg;
88 uint32_t bg;
89 uint32_t dsize;
90 uint32_t width;
91 uint32_t *data = (uint32_t *)image->data;
Ben Skeggsceed5f32010-10-05 16:41:29 +100092 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100093
Ben Skeggsceed5f32010-10-05 16:41:29 +100094 if (image->depth != 1)
95 return -ENODEV;
Ben Skeggs6ee73862009-12-11 19:24:15 +100096
Ben Skeggsceed5f32010-10-05 16:41:29 +100097 ret = RING_SPACE(chan, 8);
98 if (ret)
99 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000100
Marcin Koƛcielnickic82b88d2010-02-27 18:13:35 +0000101 width = ALIGN(image->width, 8);
102 dsize = ALIGN(width * image->height, 32) >> 5;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000103
104 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
105 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
106 fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
107 bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
108 } else {
109 fg = image->fg_color;
110 bg = image->bg_color;
111 }
112
113 BEGIN_RING(chan, NvSubGdiRect, 0x0be4, 7);
114 OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
115 OUT_RING(chan, ((image->dy + image->height) << 16) |
116 ((image->dx + image->width) & 0xffff));
117 OUT_RING(chan, bg);
118 OUT_RING(chan, fg);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000119 OUT_RING(chan, (image->height << 16) | width);
Marcin Koƛcielnickic82b88d2010-02-27 18:13:35 +0000120 OUT_RING(chan, (image->height << 16) | image->width);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000121 OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
122
123 while (dsize) {
124 int iter_len = dsize > 128 ? 128 : dsize;
125
Ben Skeggsceed5f32010-10-05 16:41:29 +1000126 ret = RING_SPACE(chan, iter_len + 1);
127 if (ret)
128 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000129
130 BEGIN_RING(chan, NvSubGdiRect, 0x0c00, iter_len);
131 OUT_RINGp(chan, data, iter_len);
132 data += iter_len;
133 dsize -= iter_len;
134 }
135
136 FIRE_RING(chan);
Ben Skeggsceed5f32010-10-05 16:41:29 +1000137 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000138}
139
Ben Skeggs6ee73862009-12-11 19:24:15 +1000140int
141nv04_fbcon_accel_init(struct fb_info *info)
142{
Dave Airlie8be48d92010-03-30 05:34:14 +0000143 struct nouveau_fbdev *nfbdev = info->par;
144 struct drm_device *dev = nfbdev->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000145 struct drm_nouveau_private *dev_priv = dev->dev_private;
146 struct nouveau_channel *chan = dev_priv->channel;
Francisco Jerezf03a3142009-12-26 02:42:45 +0100147 const int sub = NvSubCtxSurf2D;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000148 int surface_fmt, pattern_fmt, rect_fmt;
149 int ret;
150
151 switch (info->var.bits_per_pixel) {
152 case 8:
153 surface_fmt = 1;
154 pattern_fmt = 3;
155 rect_fmt = 3;
156 break;
157 case 16:
158 surface_fmt = 4;
159 pattern_fmt = 1;
160 rect_fmt = 1;
161 break;
162 case 32:
163 switch (info->var.transp.length) {
164 case 0: /* depth 24 */
165 case 8: /* depth 32 */
166 break;
167 default:
168 return -EINVAL;
169 }
170
171 surface_fmt = 6;
172 pattern_fmt = 3;
173 rect_fmt = 3;
174 break;
175 default:
176 return -EINVAL;
177 }
178
Ben Skeggsceac3092010-11-23 10:10:24 +1000179 ret = nouveau_gpuobj_gr_new(chan, NvCtxSurf2D,
180 dev_priv->card_type >= NV_10 ?
181 0x0062 : 0x0042);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000182 if (ret)
183 return ret;
184
Ben Skeggsceac3092010-11-23 10:10:24 +1000185 ret = nouveau_gpuobj_gr_new(chan, NvClipRect, 0x0019);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000186 if (ret)
187 return ret;
188
Ben Skeggsceac3092010-11-23 10:10:24 +1000189 ret = nouveau_gpuobj_gr_new(chan, NvRop, 0x0043);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000190 if (ret)
191 return ret;
192
Ben Skeggsceac3092010-11-23 10:10:24 +1000193 ret = nouveau_gpuobj_gr_new(chan, NvImagePatt, 0x0044);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000194 if (ret)
195 return ret;
196
Ben Skeggsceac3092010-11-23 10:10:24 +1000197 ret = nouveau_gpuobj_gr_new(chan, NvGdiRect, 0x004a);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000198 if (ret)
199 return ret;
200
Ben Skeggsceac3092010-11-23 10:10:24 +1000201 ret = nouveau_gpuobj_gr_new(chan, NvImageBlit,
202 dev_priv->chipset >= 0x11 ?
203 0x009f : 0x005f);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000204 if (ret)
205 return ret;
206
207 if (RING_SPACE(chan, 49)) {
Marcin Slusarz846975a2010-01-04 19:25:09 +0100208 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000209 return 0;
210 }
211
Francisco Jerezf03a3142009-12-26 02:42:45 +0100212 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000213 OUT_RING(chan, NvCtxSurf2D);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100214 BEGIN_RING(chan, sub, 0x0184, 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000215 OUT_RING(chan, NvDmaFB);
216 OUT_RING(chan, NvDmaFB);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100217 BEGIN_RING(chan, sub, 0x0300, 4);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000218 OUT_RING(chan, surface_fmt);
219 OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
220 OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
221 OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
222
Francisco Jerezf03a3142009-12-26 02:42:45 +0100223 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000224 OUT_RING(chan, NvRop);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100225 BEGIN_RING(chan, sub, 0x0300, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000226 OUT_RING(chan, 0x55);
227
Francisco Jerezf03a3142009-12-26 02:42:45 +0100228 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000229 OUT_RING(chan, NvImagePatt);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100230 BEGIN_RING(chan, sub, 0x0300, 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231 OUT_RING(chan, pattern_fmt);
232#ifdef __BIG_ENDIAN
233 OUT_RING(chan, 2);
234#else
235 OUT_RING(chan, 1);
236#endif
237 OUT_RING(chan, 0);
238 OUT_RING(chan, 1);
239 OUT_RING(chan, ~0);
240 OUT_RING(chan, ~0);
241 OUT_RING(chan, ~0);
242 OUT_RING(chan, ~0);
243
Francisco Jerezf03a3142009-12-26 02:42:45 +0100244 BEGIN_RING(chan, sub, 0x0000, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000245 OUT_RING(chan, NvClipRect);
Francisco Jerezf03a3142009-12-26 02:42:45 +0100246 BEGIN_RING(chan, sub, 0x0300, 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000247 OUT_RING(chan, 0);
248 OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
249
250 BEGIN_RING(chan, NvSubImageBlit, 0x0000, 1);
251 OUT_RING(chan, NvImageBlit);
252 BEGIN_RING(chan, NvSubImageBlit, 0x019c, 1);
253 OUT_RING(chan, NvCtxSurf2D);
254 BEGIN_RING(chan, NvSubImageBlit, 0x02fc, 1);
255 OUT_RING(chan, 3);
256
257 BEGIN_RING(chan, NvSubGdiRect, 0x0000, 1);
258 OUT_RING(chan, NvGdiRect);
259 BEGIN_RING(chan, NvSubGdiRect, 0x0198, 1);
260 OUT_RING(chan, NvCtxSurf2D);
261 BEGIN_RING(chan, NvSubGdiRect, 0x0188, 2);
262 OUT_RING(chan, NvImagePatt);
263 OUT_RING(chan, NvRop);
264 BEGIN_RING(chan, NvSubGdiRect, 0x0304, 1);
265 OUT_RING(chan, 1);
266 BEGIN_RING(chan, NvSubGdiRect, 0x0300, 1);
267 OUT_RING(chan, rect_fmt);
268 BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
269 OUT_RING(chan, 3);
270
271 FIRE_RING(chan);
272
Ben Skeggs6ee73862009-12-11 19:24:15 +1000273 return 0;
274}
275