blob: 92f3fb6765abfc9e69aedc35a2030493be359c72 [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 */
Ben Skeggsd9a91302020-06-22 11:08:51 +100024#define NVIF_DEBUG_PRINT_DISABLE
Ben Skeggs4dc28132016-05-20 09:22:55 +100025#include "nouveau_drv.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100026#include "nouveau_dma.h"
27#include "nouveau_fbcon.h"
28
Ben Skeggsd9a91302020-06-22 11:08:51 +100029#include <nvif/push006c.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;
Ben Skeggs9dec9282016-11-04 17:20:35 +100035 struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
Ben Skeggsebb945a2012-07-20 08:17:34 +100036 struct nouveau_channel *chan = drm->channel;
Ben Skeggsa535aa62020-06-22 11:31:45 +100037 struct nvif_push *push = chan->chan.push;
Ben Skeggsceed5f32010-10-05 16:41:29 +100038 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100039
Ben Skeggsa535aa62020-06-22 11:31:45 +100040 ret = PUSH_WAIT(push, 4);
Ben Skeggsceed5f32010-10-05 16:41:29 +100041 if (ret)
42 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100043
Ben Skeggsa535aa62020-06-22 11:31:45 +100044 PUSH_NVSQ(push, NV05F, 0x0300, (region->sy << 16) | region->sx,
45 0x0304, (region->dy << 16) | region->dx,
46 0x0308, (region->height << 16) | region->width);
47 PUSH_KICK(push);
Ben Skeggsceed5f32010-10-05 16:41:29 +100048 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +100049}
50
Ben Skeggsceed5f32010-10-05 16:41:29 +100051int
Ben Skeggs6ee73862009-12-11 19:24:15 +100052nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
53{
Dave Airlie8be48d92010-03-30 05:34:14 +000054 struct nouveau_fbdev *nfbdev = info->par;
Ben Skeggs9dec9282016-11-04 17:20:35 +100055 struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
Ben Skeggsebb945a2012-07-20 08:17:34 +100056 struct nouveau_channel *chan = drm->channel;
Ben Skeggs9ec52572020-06-22 11:31:56 +100057 struct nvif_push *push = chan->chan.push;
Ben Skeggsceed5f32010-10-05 16:41:29 +100058 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100059
Ben Skeggs9ec52572020-06-22 11:31:56 +100060 ret = PUSH_WAIT(push, 7);
Ben Skeggsceed5f32010-10-05 16:41:29 +100061 if (ret)
62 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100063
Ben Skeggs9ec52572020-06-22 11:31:56 +100064 PUSH_NVSQ(push, NV04A, 0x02fc, (rect->rop != ROP_COPY) ? 1 : 3);
Ben Skeggsbf5302b2010-01-04 09:10:55 +100065 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
66 info->fix.visual == FB_VISUAL_DIRECTCOLOR)
Ben Skeggs9ec52572020-06-22 11:31:56 +100067 PUSH_NVSQ(push, NV04A, 0x03fc, ((uint32_t *)info->pseudo_palette)[rect->color]);
Ben Skeggsbf5302b2010-01-04 09:10:55 +100068 else
Ben Skeggs9ec52572020-06-22 11:31:56 +100069 PUSH_NVSQ(push, NV04A, 0x03fc, rect->color);
70 PUSH_NVSQ(push, NV04A, 0x0400, (rect->dx << 16) | rect->dy,
71 0x0404, (rect->width << 16) | rect->height);
72 PUSH_KICK(push);
Ben Skeggsceed5f32010-10-05 16:41:29 +100073 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +100074}
75
Ben Skeggsceed5f32010-10-05 16:41:29 +100076int
Ben Skeggs6ee73862009-12-11 19:24:15 +100077nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
78{
Dave Airlie8be48d92010-03-30 05:34:14 +000079 struct nouveau_fbdev *nfbdev = info->par;
Ben Skeggs9dec9282016-11-04 17:20:35 +100080 struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
Ben Skeggsebb945a2012-07-20 08:17:34 +100081 struct nouveau_channel *chan = drm->channel;
Ben Skeggs1d04a642020-06-22 11:22:28 +100082 struct nvif_push *push = chan->chan.push;
Ben Skeggs6ee73862009-12-11 19:24:15 +100083 uint32_t fg;
84 uint32_t bg;
85 uint32_t dsize;
Ben Skeggs6ee73862009-12-11 19:24:15 +100086 uint32_t *data = (uint32_t *)image->data;
Ben Skeggsceed5f32010-10-05 16:41:29 +100087 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100088
Ben Skeggsceed5f32010-10-05 16:41:29 +100089 if (image->depth != 1)
90 return -ENODEV;
Ben Skeggs6ee73862009-12-11 19:24:15 +100091
Ben Skeggs1d04a642020-06-22 11:22:28 +100092 ret = PUSH_WAIT(push, 8);
Ben Skeggsceed5f32010-10-05 16:41:29 +100093 if (ret)
94 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100095
Ben Skeggs6ee73862009-12-11 19:24:15 +100096 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
97 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
98 fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
99 bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
100 } else {
101 fg = image->fg_color;
102 bg = image->bg_color;
103 }
104
Ben Skeggs1d04a642020-06-22 11:22:28 +1000105 PUSH_NVSQ(push, NV04A, 0x0be4, (image->dy << 16) | (image->dx & 0xffff),
106 0x0be8, ((image->dy + image->height) << 16) |
107 ((image->dx + image->width) & 0xffff),
108 0x0bec, bg,
109 0x0bf0, fg,
110 0x0bf4, (image->height << 16) | ALIGN(image->width, 8),
111 0x0bf8, (image->height << 16) | image->width,
112 0x0bfc, (image->dy << 16) | (image->dx & 0xffff));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000113
Mikulas Patocka28668f42016-07-28 18:56:13 -0400114 dsize = ALIGN(ALIGN(image->width, 8) * image->height, 32) >> 5;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000115 while (dsize) {
116 int iter_len = dsize > 128 ? 128 : dsize;
117
Ben Skeggs1d04a642020-06-22 11:22:28 +1000118 ret = PUSH_WAIT(push, iter_len + 1);
Ben Skeggsceed5f32010-10-05 16:41:29 +1000119 if (ret)
120 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000121
Ben Skeggs1d04a642020-06-22 11:22:28 +1000122 PUSH_NVSQ(push, NV04A, 0x0c00, data, iter_len);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000123 data += iter_len;
124 dsize -= iter_len;
125 }
126
Ben Skeggs1d04a642020-06-22 11:22:28 +1000127 PUSH_KICK(push);
Ben Skeggsceed5f32010-10-05 16:41:29 +1000128 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000129}
130
Ben Skeggs6ee73862009-12-11 19:24:15 +1000131int
132nv04_fbcon_accel_init(struct fb_info *info)
133{
Dave Airlie8be48d92010-03-30 05:34:14 +0000134 struct nouveau_fbdev *nfbdev = info->par;
Ben Skeggs9dec9282016-11-04 17:20:35 +1000135 struct drm_device *dev = nfbdev->helper.dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000136 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000137 struct nouveau_channel *chan = drm->channel;
Ben Skeggs1167c6b2016-05-18 13:57:42 +1000138 struct nvif_device *device = &drm->client.device;
Ben Skeggsd9a91302020-06-22 11:08:51 +1000139 struct nvif_push *push = chan->chan.push;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000140 int surface_fmt, pattern_fmt, rect_fmt;
141 int ret;
142
143 switch (info->var.bits_per_pixel) {
144 case 8:
145 surface_fmt = 1;
146 pattern_fmt = 3;
147 rect_fmt = 3;
148 break;
149 case 16:
150 surface_fmt = 4;
151 pattern_fmt = 1;
152 rect_fmt = 1;
153 break;
154 case 32:
155 switch (info->var.transp.length) {
156 case 0: /* depth 24 */
157 case 8: /* depth 32 */
158 break;
159 default:
160 return -EINVAL;
161 }
162
163 surface_fmt = 6;
164 pattern_fmt = 3;
165 rect_fmt = 3;
166 break;
167 default:
168 return -EINVAL;
169 }
170
Ben Skeggs9ac596a2020-03-30 09:51:33 +1000171 ret = nvif_object_ctor(&chan->user, "fbconCtxSurf2d", 0x0062,
Ben Skeggs0ad72862014-08-10 04:10:22 +1000172 device->info.family >= NV_DEVICE_INFO_V0_CELSIUS ?
173 0x0062 : 0x0042, NULL, 0, &nfbdev->surf2d);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000174 if (ret)
175 return ret;
176
Ben Skeggs9ac596a2020-03-30 09:51:33 +1000177 ret = nvif_object_ctor(&chan->user, "fbconCtxClip", 0x0019, 0x0019,
178 NULL, 0, &nfbdev->clip);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000179 if (ret)
180 return ret;
181
Ben Skeggs9ac596a2020-03-30 09:51:33 +1000182 ret = nvif_object_ctor(&chan->user, "fbconCtxRop", 0x0043, 0x0043,
183 NULL, 0, &nfbdev->rop);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000184 if (ret)
185 return ret;
186
Ben Skeggs9ac596a2020-03-30 09:51:33 +1000187 ret = nvif_object_ctor(&chan->user, "fbconCtxPatt", 0x0044, 0x0044,
188 NULL, 0, &nfbdev->patt);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000189 if (ret)
190 return ret;
191
Ben Skeggs9ac596a2020-03-30 09:51:33 +1000192 ret = nvif_object_ctor(&chan->user, "fbconGdiRectText", 0x004a, 0x004a,
193 NULL, 0, &nfbdev->gdi);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000194 if (ret)
195 return ret;
196
Ben Skeggs9ac596a2020-03-30 09:51:33 +1000197 ret = nvif_object_ctor(&chan->user, "fbconImageBlit", 0x005f,
Ben Skeggs0ad72862014-08-10 04:10:22 +1000198 device->info.chipset >= 0x11 ? 0x009f : 0x005f,
199 NULL, 0, &nfbdev->blit);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000200 if (ret)
201 return ret;
202
Ben Skeggsd9a91302020-06-22 11:08:51 +1000203 if (PUSH_WAIT(push, 49 + (device->info.chipset >= 0x11 ? 4 : 0))) {
Marcin Slusarz846975a2010-01-04 19:25:09 +0100204 nouveau_fbcon_gpu_lockup(info);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000205 return 0;
206 }
207
Ben Skeggsd9a91302020-06-22 11:08:51 +1000208 PUSH_NVSQ(push, NV042, 0x0000, nfbdev->surf2d.handle);
209 PUSH_NVSQ(push, NV042, 0x0184, chan->vram.handle,
210 0x0188, chan->vram.handle);
211 PUSH_NVSQ(push, NV042, 0x0300, surface_fmt,
212 0x0304, info->fix.line_length | (info->fix.line_length << 16),
213 0x0308, info->fix.smem_start - dev->mode_config.fb_base,
214 0x030c, info->fix.smem_start - dev->mode_config.fb_base);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000215
Ben Skeggsd9a91302020-06-22 11:08:51 +1000216 PUSH_NVSQ(push, NV043, 0x0000, nfbdev->rop.handle);
217 PUSH_NVSQ(push, NV043, 0x0300, 0x55);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000218
Ben Skeggsd9a91302020-06-22 11:08:51 +1000219 PUSH_NVSQ(push, NV044, 0x0000, nfbdev->patt.handle);
220 PUSH_NVSQ(push, NV044, 0x0300, pattern_fmt,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000221#ifdef __BIG_ENDIAN
Ben Skeggsd9a91302020-06-22 11:08:51 +1000222 0x0304, 2,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000223#else
Ben Skeggsd9a91302020-06-22 11:08:51 +1000224 0x0304, 1,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000225#endif
Ben Skeggsd9a91302020-06-22 11:08:51 +1000226 0x0308, 0,
227 0x030c, 1,
228 0x0310, ~0,
229 0x0314, ~0,
230 0x0318, ~0,
231 0x031c, ~0);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000232
Ben Skeggsd9a91302020-06-22 11:08:51 +1000233 PUSH_NVSQ(push, NV019, 0x0000, nfbdev->clip.handle);
234 PUSH_NVSQ(push, NV019, 0x0300, 0,
235 0x0304, (info->var.yres_virtual << 16) | info->var.xres_virtual);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000236
Ben Skeggsd9a91302020-06-22 11:08:51 +1000237 PUSH_NVSQ(push, NV05F, 0x0000, nfbdev->blit.handle);
238 PUSH_NVSQ(push, NV05F, 0x019c, nfbdev->surf2d.handle);
239 PUSH_NVSQ(push, NV05F, 0x02fc, 3);
240 if (nfbdev->blit.oclass == 0x009f) {
241 PUSH_NVSQ(push, NV09F, 0x0120, 0,
242 0x0124, 1,
243 0x0128, 2);
Ben Skeggsb9d9dcd2013-11-11 13:59:40 +1000244 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000245
Ben Skeggsd9a91302020-06-22 11:08:51 +1000246 PUSH_NVSQ(push, NV04A, 0x0000, nfbdev->gdi.handle);
247 PUSH_NVSQ(push, NV04A, 0x0198, nfbdev->surf2d.handle);
248 PUSH_NVSQ(push, NV04A, 0x0188, nfbdev->patt.handle,
249 0x018c, nfbdev->rop.handle);
250 PUSH_NVSQ(push, NV04A, 0x0304, 1);
251 PUSH_NVSQ(push, NV04A, 0x0300, rect_fmt);
252 PUSH_NVSQ(push, NV04A, 0x02fc, 3);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000253
Ben Skeggsd9a91302020-06-22 11:08:51 +1000254 PUSH_KICK(push);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000255 return 0;
256}
257