xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/subdev/fb/nv20.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright (C) 2010 Francisco Jerez.
3c39f472eSBen Skeggs  * All Rights Reserved.
4c39f472eSBen Skeggs  *
5c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining
6c39f472eSBen Skeggs  * a copy of this software and associated documentation files (the
7c39f472eSBen Skeggs  * "Software"), to deal in the Software without restriction, including
8c39f472eSBen Skeggs  * without limitation the rights to use, copy, modify, merge, publish,
9c39f472eSBen Skeggs  * distribute, sublicense, and/or sell copies of the Software, and to
10c39f472eSBen Skeggs  * permit persons to whom the Software is furnished to do so, subject to
11c39f472eSBen Skeggs  * the following conditions:
12c39f472eSBen Skeggs  *
13c39f472eSBen Skeggs  * The above copyright notice and this permission notice (including the
14c39f472eSBen Skeggs  * next paragraph) shall be included in all copies or substantial
15c39f472eSBen Skeggs  * portions of the Software.
16c39f472eSBen Skeggs  *
17c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18c39f472eSBen Skeggs  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19c39f472eSBen Skeggs  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20c39f472eSBen Skeggs  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21c39f472eSBen Skeggs  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22c39f472eSBen Skeggs  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23c39f472eSBen Skeggs  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24c39f472eSBen Skeggs  *
25c39f472eSBen Skeggs  */
2603c8952fSBen Skeggs #include "priv.h"
27d36a99d2SBen Skeggs #include "ram.h"
28c39f472eSBen Skeggs 
29c39f472eSBen Skeggs void
nv20_fb_tile_init(struct nvkm_fb * fb,int i,u32 addr,u32 size,u32 pitch,u32 flags,struct nvkm_fb_tile * tile)30b1e4553cSBen Skeggs nv20_fb_tile_init(struct nvkm_fb *fb, int i, u32 addr, u32 size, u32 pitch,
31639c308eSBen Skeggs 		  u32 flags, struct nvkm_fb_tile *tile)
32c39f472eSBen Skeggs {
33c39f472eSBen Skeggs 	tile->addr  = 0x00000001 | addr;
34c39f472eSBen Skeggs 	tile->limit = max(1u, addr + size) - 1;
35c39f472eSBen Skeggs 	tile->pitch = pitch;
36c39f472eSBen Skeggs 	if (flags & 4) {
3703c8952fSBen Skeggs 		fb->func->tile.comp(fb, i, size, flags, tile);
38c39f472eSBen Skeggs 		tile->addr |= 2;
39c39f472eSBen Skeggs 	}
40c39f472eSBen Skeggs }
41c39f472eSBen Skeggs 
42c39f472eSBen Skeggs static void
nv20_fb_tile_comp(struct nvkm_fb * fb,int i,u32 size,u32 flags,struct nvkm_fb_tile * tile)43b1e4553cSBen Skeggs nv20_fb_tile_comp(struct nvkm_fb *fb, int i, u32 size, u32 flags,
44639c308eSBen Skeggs 		  struct nvkm_fb_tile *tile)
45c39f472eSBen Skeggs {
46c39f472eSBen Skeggs 	u32 tiles = DIV_ROUND_UP(size, 0x40);
47b1e4553cSBen Skeggs 	u32 tags  = round_up(tiles / fb->ram->parts, 0x40);
48f5cfbd99SBen Skeggs 	if (!nvkm_mm_head(&fb->tags.mm, 0, 1, tags, tags, 1, &tile->tag)) {
49c39f472eSBen Skeggs 		if (!(flags & 2)) tile->zcomp = 0x00000000; /* Z16 */
50c39f472eSBen Skeggs 		else              tile->zcomp = 0x04000000; /* Z24S8 */
51c39f472eSBen Skeggs 		tile->zcomp |= tile->tag->offset;
52c39f472eSBen Skeggs 		tile->zcomp |= 0x80000000; /* enable */
53c39f472eSBen Skeggs #ifdef __BIG_ENDIAN
54c39f472eSBen Skeggs 		tile->zcomp |= 0x08000000;
55c39f472eSBen Skeggs #endif
56c39f472eSBen Skeggs 	}
57c39f472eSBen Skeggs }
58c39f472eSBen Skeggs 
59c39f472eSBen Skeggs void
nv20_fb_tile_fini(struct nvkm_fb * fb,int i,struct nvkm_fb_tile * tile)60b1e4553cSBen Skeggs nv20_fb_tile_fini(struct nvkm_fb *fb, int i, struct nvkm_fb_tile *tile)
61c39f472eSBen Skeggs {
62c39f472eSBen Skeggs 	tile->addr  = 0;
63c39f472eSBen Skeggs 	tile->limit = 0;
64c39f472eSBen Skeggs 	tile->pitch = 0;
65c39f472eSBen Skeggs 	tile->zcomp = 0;
66f5cfbd99SBen Skeggs 	nvkm_mm_free(&fb->tags.mm, &tile->tag);
67c39f472eSBen Skeggs }
68c39f472eSBen Skeggs 
69c39f472eSBen Skeggs void
nv20_fb_tile_prog(struct nvkm_fb * fb,int i,struct nvkm_fb_tile * tile)70b1e4553cSBen Skeggs nv20_fb_tile_prog(struct nvkm_fb *fb, int i, struct nvkm_fb_tile *tile)
71c39f472eSBen Skeggs {
726758745bSBen Skeggs 	struct nvkm_device *device = fb->subdev.device;
736758745bSBen Skeggs 	nvkm_wr32(device, 0x100244 + (i * 0x10), tile->limit);
746758745bSBen Skeggs 	nvkm_wr32(device, 0x100248 + (i * 0x10), tile->pitch);
756758745bSBen Skeggs 	nvkm_wr32(device, 0x100240 + (i * 0x10), tile->addr);
766758745bSBen Skeggs 	nvkm_rd32(device, 0x100240 + (i * 0x10));
776758745bSBen Skeggs 	nvkm_wr32(device, 0x100300 + (i * 0x04), tile->zcomp);
78c39f472eSBen Skeggs }
79c39f472eSBen Skeggs 
80af793b8cSBen Skeggs u32
nv20_fb_tags(struct nvkm_fb * fb)81af793b8cSBen Skeggs nv20_fb_tags(struct nvkm_fb *fb)
82af793b8cSBen Skeggs {
83af793b8cSBen Skeggs 	const u32 tags = nvkm_rd32(fb->subdev.device, 0x100320);
84af793b8cSBen Skeggs 	return tags ? tags + 1 : 0;
85af793b8cSBen Skeggs }
86af793b8cSBen Skeggs 
8703c8952fSBen Skeggs static const struct nvkm_fb_func
8803c8952fSBen Skeggs nv20_fb = {
89af793b8cSBen Skeggs 	.tags = nv20_fb_tags,
90c39f472eSBen Skeggs 	.tile.regions = 8,
91c39f472eSBen Skeggs 	.tile.init = nv20_fb_tile_init,
92c39f472eSBen Skeggs 	.tile.comp = nv20_fb_tile_comp,
93c39f472eSBen Skeggs 	.tile.fini = nv20_fb_tile_fini,
94c39f472eSBen Skeggs 	.tile.prog = nv20_fb_tile_prog,
9503c8952fSBen Skeggs 	.ram_new = nv20_ram_new,
9603c8952fSBen Skeggs };
9703c8952fSBen Skeggs 
9803c8952fSBen Skeggs int
nv20_fb_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_fb ** pfb)99*b7a9369aSBen Skeggs nv20_fb_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_fb **pfb)
10003c8952fSBen Skeggs {
101*b7a9369aSBen Skeggs 	return nvkm_fb_new_(&nv20_fb, device, type, inst, pfb);
10203c8952fSBen Skeggs }
103