nvc0_fbcon.c 6.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright 2010 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 */

25
#include "nouveau_drm.h"
26 27 28 29 30 31 32
#include "nouveau_dma.h"
#include "nouveau_fbcon.h"

int
nvc0_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
{
	struct nouveau_fbdev *nfbdev = info->par;
33
	struct nouveau_drm *drm = nouveau_drm(nfbdev->dev);
34
	struct nouveau_channel *chan = drm->channel;
35 36 37 38 39 40 41
	int ret;

	ret = RING_SPACE(chan, rect->rop == ROP_COPY ? 7 : 11);
	if (ret)
		return ret;

	if (rect->rop != ROP_COPY) {
42
		BEGIN_NVC0(chan, NvSub2D, 0x02ac, 1);
43 44
		OUT_RING  (chan, 1);
	}
45
	BEGIN_NVC0(chan, NvSub2D, 0x0588, 1);
46 47 48 49 50
	if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
	    info->fix.visual == FB_VISUAL_DIRECTCOLOR)
		OUT_RING  (chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
	else
		OUT_RING  (chan, rect->color);
51
	BEGIN_NVC0(chan, NvSub2D, 0x0600, 4);
52 53 54 55 56
	OUT_RING  (chan, rect->dx);
	OUT_RING  (chan, rect->dy);
	OUT_RING  (chan, rect->dx + rect->width);
	OUT_RING  (chan, rect->dy + rect->height);
	if (rect->rop != ROP_COPY) {
57
		BEGIN_NVC0(chan, NvSub2D, 0x02ac, 1);
58 59 60 61 62 63 64 65 66 67
		OUT_RING  (chan, 3);
	}
	FIRE_RING(chan);
	return 0;
}

int
nvc0_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
{
	struct nouveau_fbdev *nfbdev = info->par;
68
	struct nouveau_drm *drm = nouveau_drm(nfbdev->dev);
69
	struct nouveau_channel *chan = drm->channel;
70 71 72 73 74 75
	int ret;

	ret = RING_SPACE(chan, 12);
	if (ret)
		return ret;

76
	BEGIN_NVC0(chan, NvSub2D, 0x0110, 1);
77
	OUT_RING  (chan, 0);
78
	BEGIN_NVC0(chan, NvSub2D, 0x08b0, 4);
79 80 81 82
	OUT_RING  (chan, region->dx);
	OUT_RING  (chan, region->dy);
	OUT_RING  (chan, region->width);
	OUT_RING  (chan, region->height);
83
	BEGIN_NVC0(chan, NvSub2D, 0x08d0, 4);
84 85 86 87 88 89 90 91 92 93 94 95
	OUT_RING  (chan, 0);
	OUT_RING  (chan, region->sx);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, region->sy);
	FIRE_RING(chan);
	return 0;
}

int
nvc0_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
{
	struct nouveau_fbdev *nfbdev = info->par;
96
	struct nouveau_drm *drm = nouveau_drm(nfbdev->dev);
97
	struct nouveau_channel *chan = drm->channel;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	uint32_t width, dwords, *data = (uint32_t *)image->data;
	uint32_t mask = ~(~0 >> (32 - info->var.bits_per_pixel));
	uint32_t *palette = info->pseudo_palette;
	int ret;

	if (image->depth != 1)
		return -ENODEV;

	ret = RING_SPACE(chan, 11);
	if (ret)
		return ret;

	width = ALIGN(image->width, 32);
	dwords = (width * image->height) >> 5;

113
	BEGIN_NVC0(chan, NvSub2D, 0x0814, 2);
114 115 116 117 118 119 120 121
	if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
	    info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
		OUT_RING  (chan, palette[image->bg_color] | mask);
		OUT_RING  (chan, palette[image->fg_color] | mask);
	} else {
		OUT_RING  (chan, image->bg_color);
		OUT_RING  (chan, image->fg_color);
	}
122
	BEGIN_NVC0(chan, NvSub2D, 0x0838, 2);
123 124
	OUT_RING  (chan, image->width);
	OUT_RING  (chan, image->height);
125
	BEGIN_NVC0(chan, NvSub2D, 0x0850, 4);
126 127 128 129 130 131 132 133 134 135 136 137 138 139
	OUT_RING  (chan, 0);
	OUT_RING  (chan, image->dx);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, image->dy);

	while (dwords) {
		int push = dwords > 2047 ? 2047 : dwords;

		ret = RING_SPACE(chan, push + 1);
		if (ret)
			return ret;

		dwords -= push;

140
		BEGIN_NIC0(chan, NvSub2D, 0x0860, push);
141 142 143 144 145 146 147 148 149 150 151 152 153
		OUT_RINGp(chan, data, push);
		data += push;
	}

	FIRE_RING(chan);
	return 0;
}

int
nvc0_fbcon_accel_init(struct fb_info *info)
{
	struct nouveau_fbdev *nfbdev = info->par;
	struct drm_device *dev = nfbdev->dev;
154
	struct nouveau_framebuffer *fb = &nfbdev->nouveau_fb;
155
	struct nouveau_drm *drm = nouveau_drm(dev);
156
	struct nouveau_channel *chan = drm->channel;
157 158
	int ret, format;

159
	ret = nvif_object_init(chan->object, NULL, 0x902d, 0x902d, NULL, 0,
160
			       &nfbdev->twod);
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
	if (ret)
		return ret;

	switch (info->var.bits_per_pixel) {
	case 8:
		format = 0xf3;
		break;
	case 15:
		format = 0xf8;
		break;
	case 16:
		format = 0xe8;
		break;
	case 32:
		switch (info->var.transp.length) {
		case 0: /* depth 24 */
		case 8: /* depth 32, just use 24.. */
			format = 0xe6;
			break;
		case 2: /* depth 30 */
			format = 0xd1;
			break;
		default:
			return -EINVAL;
		}
		break;
	default:
		return -EINVAL;
	}

	ret = RING_SPACE(chan, 60);
	if (ret) {
		WARN_ON(1);
		nouveau_fbcon_gpu_lockup(info);
		return ret;
	}

198
	BEGIN_NVC0(chan, NvSub2D, 0x0000, 1);
199
	OUT_RING  (chan, nfbdev->twod.handle);
200
	BEGIN_NVC0(chan, NvSub2D, 0x0290, 1);
201
	OUT_RING  (chan, 0);
202
	BEGIN_NVC0(chan, NvSub2D, 0x0888, 1);
203
	OUT_RING  (chan, 1);
204
	BEGIN_NVC0(chan, NvSub2D, 0x02ac, 1);
205
	OUT_RING  (chan, 3);
206
	BEGIN_NVC0(chan, NvSub2D, 0x02a0, 1);
207
	OUT_RING  (chan, 0x55);
208
	BEGIN_NVC0(chan, NvSub2D, 0x08c0, 4);
209 210 211 212
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
213
	BEGIN_NVC0(chan, NvSub2D, 0x0580, 2);
214 215
	OUT_RING  (chan, 4);
	OUT_RING  (chan, format);
216
	BEGIN_NVC0(chan, NvSub2D, 0x02e8, 2);
217 218 219
	OUT_RING  (chan, 2);
	OUT_RING  (chan, 1);

220
	BEGIN_NVC0(chan, NvSub2D, 0x0804, 1);
221
	OUT_RING  (chan, format);
222
	BEGIN_NVC0(chan, NvSub2D, 0x0800, 1);
223
	OUT_RING  (chan, 1);
224
	BEGIN_NVC0(chan, NvSub2D, 0x0808, 3);
225 226 227
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
228
	BEGIN_NVC0(chan, NvSub2D, 0x081c, 1);
229
	OUT_RING  (chan, 1);
230
	BEGIN_NVC0(chan, NvSub2D, 0x0840, 4);
231 232 233 234
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
235
	BEGIN_NVC0(chan, NvSub2D, 0x0200, 10);
236 237 238 239 240 241 242 243
	OUT_RING  (chan, format);
	OUT_RING  (chan, 1);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, info->fix.line_length);
	OUT_RING  (chan, info->var.xres_virtual);
	OUT_RING  (chan, info->var.yres_virtual);
244 245
	OUT_RING  (chan, upper_32_bits(fb->vma.offset));
	OUT_RING  (chan, lower_32_bits(fb->vma.offset));
246
	BEGIN_NVC0(chan, NvSub2D, 0x0230, 10);
247 248 249 250 251 252 253 254
	OUT_RING  (chan, format);
	OUT_RING  (chan, 1);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, 1);
	OUT_RING  (chan, 0);
	OUT_RING  (chan, info->fix.line_length);
	OUT_RING  (chan, info->var.xres_virtual);
	OUT_RING  (chan, info->var.yres_virtual);
255 256
	OUT_RING  (chan, upper_32_bits(fb->vma.offset));
	OUT_RING  (chan, lower_32_bits(fb->vma.offset));
257 258 259 260 261
	FIRE_RING (chan);

	return 0;
}