Home | History | Annotate | Line # | Download | only in nouveau
      1  1.4  riastrad /*	$NetBSD: nouveau_nv04_fbcon.c,v 1.4 2021/12/18 23:45:32 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2009 Ben Skeggs
      5  1.1  riastrad  * Copyright 2008 Stuart Bennett
      6  1.1  riastrad  *
      7  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      8  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      9  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     10  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     11  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     12  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     13  1.1  riastrad  *
     14  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     15  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     16  1.1  riastrad  * Software.
     17  1.1  riastrad  *
     18  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     21  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     22  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     23  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     24  1.1  riastrad  * DEALINGS IN THE SOFTWARE.
     25  1.1  riastrad  */
     26  1.1  riastrad 
     27  1.1  riastrad #include <sys/cdefs.h>
     28  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: nouveau_nv04_fbcon.c,v 1.4 2021/12/18 23:45:32 riastradh Exp $");
     29  1.1  riastrad 
     30  1.4  riastrad #include "nouveau_drv.h"
     31  1.1  riastrad #include "nouveau_dma.h"
     32  1.1  riastrad #include "nouveau_fbcon.h"
     33  1.1  riastrad 
     34  1.1  riastrad int
     35  1.1  riastrad nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
     36  1.1  riastrad {
     37  1.1  riastrad 	struct nouveau_fbdev *nfbdev = info->par;
     38  1.4  riastrad 	struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
     39  1.1  riastrad 	struct nouveau_channel *chan = drm->channel;
     40  1.1  riastrad 	int ret;
     41  1.1  riastrad 
     42  1.1  riastrad 	ret = RING_SPACE(chan, 4);
     43  1.1  riastrad 	if (ret)
     44  1.1  riastrad 		return ret;
     45  1.1  riastrad 
     46  1.1  riastrad 	BEGIN_NV04(chan, NvSubImageBlit, 0x0300, 3);
     47  1.1  riastrad 	OUT_RING(chan, (region->sy << 16) | region->sx);
     48  1.1  riastrad 	OUT_RING(chan, (region->dy << 16) | region->dx);
     49  1.1  riastrad 	OUT_RING(chan, (region->height << 16) | region->width);
     50  1.1  riastrad 	FIRE_RING(chan);
     51  1.1  riastrad 	return 0;
     52  1.1  riastrad }
     53  1.1  riastrad 
     54  1.1  riastrad int
     55  1.1  riastrad nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
     56  1.1  riastrad {
     57  1.1  riastrad 	struct nouveau_fbdev *nfbdev = info->par;
     58  1.4  riastrad 	struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
     59  1.1  riastrad 	struct nouveau_channel *chan = drm->channel;
     60  1.1  riastrad 	int ret;
     61  1.1  riastrad 
     62  1.1  riastrad 	ret = RING_SPACE(chan, 7);
     63  1.1  riastrad 	if (ret)
     64  1.1  riastrad 		return ret;
     65  1.1  riastrad 
     66  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x02fc, 1);
     67  1.1  riastrad 	OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
     68  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x03fc, 1);
     69  1.1  riastrad 	if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
     70  1.1  riastrad 	    info->fix.visual == FB_VISUAL_DIRECTCOLOR)
     71  1.1  riastrad 		OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
     72  1.1  riastrad 	else
     73  1.1  riastrad 		OUT_RING(chan, rect->color);
     74  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0400, 2);
     75  1.1  riastrad 	OUT_RING(chan, (rect->dx << 16) | rect->dy);
     76  1.1  riastrad 	OUT_RING(chan, (rect->width << 16) | rect->height);
     77  1.1  riastrad 	FIRE_RING(chan);
     78  1.1  riastrad 	return 0;
     79  1.1  riastrad }
     80  1.1  riastrad 
     81  1.1  riastrad int
     82  1.1  riastrad nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
     83  1.1  riastrad {
     84  1.1  riastrad 	struct nouveau_fbdev *nfbdev = info->par;
     85  1.4  riastrad 	struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
     86  1.1  riastrad 	struct nouveau_channel *chan = drm->channel;
     87  1.1  riastrad 	uint32_t fg;
     88  1.1  riastrad 	uint32_t bg;
     89  1.1  riastrad 	uint32_t dsize;
     90  1.1  riastrad 	uint32_t *data = (uint32_t *)image->data;
     91  1.1  riastrad 	int ret;
     92  1.1  riastrad 
     93  1.1  riastrad 	if (image->depth != 1)
     94  1.1  riastrad 		return -ENODEV;
     95  1.1  riastrad 
     96  1.1  riastrad 	ret = RING_SPACE(chan, 8);
     97  1.1  riastrad 	if (ret)
     98  1.1  riastrad 		return ret;
     99  1.1  riastrad 
    100  1.1  riastrad 	if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
    101  1.1  riastrad 	    info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
    102  1.1  riastrad 		fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
    103  1.1  riastrad 		bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
    104  1.1  riastrad 	} else {
    105  1.1  riastrad 		fg = image->fg_color;
    106  1.1  riastrad 		bg = image->bg_color;
    107  1.1  riastrad 	}
    108  1.1  riastrad 
    109  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0be4, 7);
    110  1.1  riastrad 	OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
    111  1.1  riastrad 	OUT_RING(chan, ((image->dy + image->height) << 16) |
    112  1.1  riastrad 			 ((image->dx + image->width) & 0xffff));
    113  1.1  riastrad 	OUT_RING(chan, bg);
    114  1.1  riastrad 	OUT_RING(chan, fg);
    115  1.2  riastrad 	OUT_RING(chan, (image->height << 16) | ALIGN(image->width, 8));
    116  1.1  riastrad 	OUT_RING(chan, (image->height << 16) | image->width);
    117  1.1  riastrad 	OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
    118  1.1  riastrad 
    119  1.2  riastrad 	dsize = ALIGN(ALIGN(image->width, 8) * image->height, 32) >> 5;
    120  1.1  riastrad 	while (dsize) {
    121  1.1  riastrad 		int iter_len = dsize > 128 ? 128 : dsize;
    122  1.1  riastrad 
    123  1.1  riastrad 		ret = RING_SPACE(chan, iter_len + 1);
    124  1.1  riastrad 		if (ret)
    125  1.1  riastrad 			return ret;
    126  1.1  riastrad 
    127  1.1  riastrad 		BEGIN_NV04(chan, NvSubGdiRect, 0x0c00, iter_len);
    128  1.1  riastrad 		OUT_RINGp(chan, data, iter_len);
    129  1.1  riastrad 		data += iter_len;
    130  1.1  riastrad 		dsize -= iter_len;
    131  1.1  riastrad 	}
    132  1.1  riastrad 
    133  1.1  riastrad 	FIRE_RING(chan);
    134  1.1  riastrad 	return 0;
    135  1.1  riastrad }
    136  1.1  riastrad 
    137  1.1  riastrad int
    138  1.1  riastrad nv04_fbcon_accel_init(struct fb_info *info)
    139  1.1  riastrad {
    140  1.1  riastrad 	struct nouveau_fbdev *nfbdev = info->par;
    141  1.4  riastrad 	struct drm_device *dev = nfbdev->helper.dev;
    142  1.1  riastrad 	struct nouveau_drm *drm = nouveau_drm(dev);
    143  1.1  riastrad 	struct nouveau_channel *chan = drm->channel;
    144  1.4  riastrad 	struct nvif_device *device = &drm->client.device;
    145  1.1  riastrad 	int surface_fmt, pattern_fmt, rect_fmt;
    146  1.1  riastrad 	int ret;
    147  1.1  riastrad 
    148  1.1  riastrad 	switch (info->var.bits_per_pixel) {
    149  1.1  riastrad 	case 8:
    150  1.1  riastrad 		surface_fmt = 1;
    151  1.1  riastrad 		pattern_fmt = 3;
    152  1.1  riastrad 		rect_fmt = 3;
    153  1.1  riastrad 		break;
    154  1.1  riastrad 	case 16:
    155  1.1  riastrad 		surface_fmt = 4;
    156  1.1  riastrad 		pattern_fmt = 1;
    157  1.1  riastrad 		rect_fmt = 1;
    158  1.1  riastrad 		break;
    159  1.1  riastrad 	case 32:
    160  1.1  riastrad 		switch (info->var.transp.length) {
    161  1.1  riastrad 		case 0: /* depth 24 */
    162  1.1  riastrad 		case 8: /* depth 32 */
    163  1.1  riastrad 			break;
    164  1.1  riastrad 		default:
    165  1.1  riastrad 			return -EINVAL;
    166  1.1  riastrad 		}
    167  1.1  riastrad 
    168  1.1  riastrad 		surface_fmt = 6;
    169  1.1  riastrad 		pattern_fmt = 3;
    170  1.1  riastrad 		rect_fmt = 3;
    171  1.1  riastrad 		break;
    172  1.1  riastrad 	default:
    173  1.1  riastrad 		return -EINVAL;
    174  1.1  riastrad 	}
    175  1.1  riastrad 
    176  1.2  riastrad 	ret = nvif_object_init(&chan->user, 0x0062,
    177  1.2  riastrad 			       device->info.family >= NV_DEVICE_INFO_V0_CELSIUS ?
    178  1.2  riastrad 			       0x0062 : 0x0042, NULL, 0, &nfbdev->surf2d);
    179  1.1  riastrad 	if (ret)
    180  1.1  riastrad 		return ret;
    181  1.1  riastrad 
    182  1.2  riastrad 	ret = nvif_object_init(&chan->user, 0x0019, 0x0019, NULL, 0,
    183  1.2  riastrad 			       &nfbdev->clip);
    184  1.1  riastrad 	if (ret)
    185  1.1  riastrad 		return ret;
    186  1.1  riastrad 
    187  1.2  riastrad 	ret = nvif_object_init(&chan->user, 0x0043, 0x0043, NULL, 0,
    188  1.2  riastrad 			       &nfbdev->rop);
    189  1.1  riastrad 	if (ret)
    190  1.1  riastrad 		return ret;
    191  1.1  riastrad 
    192  1.2  riastrad 	ret = nvif_object_init(&chan->user, 0x0044, 0x0044, NULL, 0,
    193  1.2  riastrad 			       &nfbdev->patt);
    194  1.1  riastrad 	if (ret)
    195  1.1  riastrad 		return ret;
    196  1.1  riastrad 
    197  1.2  riastrad 	ret = nvif_object_init(&chan->user, 0x004a, 0x004a, NULL, 0,
    198  1.2  riastrad 			       &nfbdev->gdi);
    199  1.1  riastrad 	if (ret)
    200  1.1  riastrad 		return ret;
    201  1.1  riastrad 
    202  1.2  riastrad 	ret = nvif_object_init(&chan->user, 0x005f,
    203  1.2  riastrad 			       device->info.chipset >= 0x11 ? 0x009f : 0x005f,
    204  1.2  riastrad 			       NULL, 0, &nfbdev->blit);
    205  1.1  riastrad 	if (ret)
    206  1.1  riastrad 		return ret;
    207  1.1  riastrad 
    208  1.2  riastrad 	if (RING_SPACE(chan, 49 + (device->info.chipset >= 0x11 ? 4 : 0))) {
    209  1.1  riastrad 		nouveau_fbcon_gpu_lockup(info);
    210  1.1  riastrad 		return 0;
    211  1.1  riastrad 	}
    212  1.1  riastrad 
    213  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0000, 1);
    214  1.2  riastrad 	OUT_RING(chan, nfbdev->surf2d.handle);
    215  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0184, 2);
    216  1.2  riastrad 	OUT_RING(chan, chan->vram.handle);
    217  1.2  riastrad 	OUT_RING(chan, chan->vram.handle);
    218  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0300, 4);
    219  1.1  riastrad 	OUT_RING(chan, surface_fmt);
    220  1.1  riastrad 	OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
    221  1.1  riastrad 	OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
    222  1.1  riastrad 	OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
    223  1.1  riastrad 
    224  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0000, 1);
    225  1.2  riastrad 	OUT_RING(chan, nfbdev->rop.handle);
    226  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0300, 1);
    227  1.1  riastrad 	OUT_RING(chan, 0x55);
    228  1.1  riastrad 
    229  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0000, 1);
    230  1.2  riastrad 	OUT_RING(chan, nfbdev->patt.handle);
    231  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0300, 8);
    232  1.1  riastrad 	OUT_RING(chan, pattern_fmt);
    233  1.1  riastrad #ifdef __BIG_ENDIAN
    234  1.1  riastrad 	OUT_RING(chan, 2);
    235  1.1  riastrad #else
    236  1.1  riastrad 	OUT_RING(chan, 1);
    237  1.1  riastrad #endif
    238  1.1  riastrad 	OUT_RING(chan, 0);
    239  1.1  riastrad 	OUT_RING(chan, 1);
    240  1.1  riastrad 	OUT_RING(chan, ~0);
    241  1.1  riastrad 	OUT_RING(chan, ~0);
    242  1.1  riastrad 	OUT_RING(chan, ~0);
    243  1.1  riastrad 	OUT_RING(chan, ~0);
    244  1.1  riastrad 
    245  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0000, 1);
    246  1.2  riastrad 	OUT_RING(chan, nfbdev->clip.handle);
    247  1.1  riastrad 	BEGIN_NV04(chan, NvSubCtxSurf2D, 0x0300, 2);
    248  1.1  riastrad 	OUT_RING(chan, 0);
    249  1.1  riastrad 	OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
    250  1.1  riastrad 
    251  1.1  riastrad 	BEGIN_NV04(chan, NvSubImageBlit, 0x0000, 1);
    252  1.2  riastrad 	OUT_RING(chan, nfbdev->blit.handle);
    253  1.1  riastrad 	BEGIN_NV04(chan, NvSubImageBlit, 0x019c, 1);
    254  1.2  riastrad 	OUT_RING(chan, nfbdev->surf2d.handle);
    255  1.1  riastrad 	BEGIN_NV04(chan, NvSubImageBlit, 0x02fc, 1);
    256  1.1  riastrad 	OUT_RING(chan, 3);
    257  1.2  riastrad 	if (device->info.chipset >= 0x11 /*XXX: oclass == 0x009f*/) {
    258  1.1  riastrad 		BEGIN_NV04(chan, NvSubImageBlit, 0x0120, 3);
    259  1.1  riastrad 		OUT_RING(chan, 0);
    260  1.1  riastrad 		OUT_RING(chan, 1);
    261  1.1  riastrad 		OUT_RING(chan, 2);
    262  1.1  riastrad 	}
    263  1.1  riastrad 
    264  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0000, 1);
    265  1.2  riastrad 	OUT_RING(chan, nfbdev->gdi.handle);
    266  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0198, 1);
    267  1.2  riastrad 	OUT_RING(chan, nfbdev->surf2d.handle);
    268  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0188, 2);
    269  1.2  riastrad 	OUT_RING(chan, nfbdev->patt.handle);
    270  1.2  riastrad 	OUT_RING(chan, nfbdev->rop.handle);
    271  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0304, 1);
    272  1.1  riastrad 	OUT_RING(chan, 1);
    273  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x0300, 1);
    274  1.1  riastrad 	OUT_RING(chan, rect_fmt);
    275  1.1  riastrad 	BEGIN_NV04(chan, NvSubGdiRect, 0x02fc, 1);
    276  1.1  riastrad 	OUT_RING(chan, 3);
    277  1.1  riastrad 
    278  1.1  riastrad 	FIRE_RING(chan);
    279  1.1  riastrad 
    280  1.1  riastrad 	return 0;
    281  1.1  riastrad }
    282  1.1  riastrad 
    283