nv25.c revision a8749af1a0584757e52124774b603ff901f99690
1/*
2 * Copyright (C) 2010 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#include <subdev/fb.h>
28
29struct nv25_fb_priv {
30	struct nouveau_fb base;
31};
32
33static void
34nv25_fb_tile_comp(struct nouveau_fb *pfb, int i, u32 size, u32 flags,
35		  struct nouveau_fb_tile *tile)
36{
37	int bpp = (flags & 2) ? 32 : 16;
38
39	/* Allocate some of the on-die tag memory, used to store Z
40	 * compression meta-data (most likely just a bitmap determining
41	 * if a given tile is compressed or not).
42	 */
43	size /= 256;
44
45	if (!nouveau_mm_head(&pfb->tags, 1, size, size, 1, &tile->tag)) {
46		/* Enable Z compression */
47		tile->zcomp = tile->tag->offset;
48		if (bpp == 16)
49			tile->zcomp |= 0x00100000;
50		else
51			tile->zcomp |= 0x00200000;
52	}
53}
54
55static int
56nv25_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
57	     struct nouveau_oclass *oclass, void *data, u32 size,
58	     struct nouveau_object **pobject)
59{
60	struct nouveau_device *device = nv_device(parent);
61	struct nv25_fb_priv *priv;
62	u32 pbus1218;
63	int ret;
64
65	ret = nouveau_fb_create(parent, engine, oclass, &priv);
66	*pobject = nv_object(priv);
67	if (ret)
68		return ret;
69
70	pbus1218 = nv_rd32(priv, 0x001218);
71	switch (pbus1218 & 0x00000300) {
72	case 0x00000000: priv->base.ram.type = NV_MEM_TYPE_SDRAM; break;
73	case 0x00000100: priv->base.ram.type = NV_MEM_TYPE_DDR1; break;
74	case 0x00000200: priv->base.ram.type = NV_MEM_TYPE_GDDR3; break;
75	case 0x00000300: priv->base.ram.type = NV_MEM_TYPE_GDDR2; break;
76	}
77	priv->base.ram.size = nv_rd32(priv, 0x10020c) & 0xff000000;
78
79	if (device->chipset >= 0x25)
80		ret = nouveau_mm_init(&priv->base.tags, 0, 64 * 1024, 1);
81	else
82		ret = nouveau_mm_init(&priv->base.tags, 0, 32 * 1024, 1);
83	if (ret)
84		return ret;
85
86	priv->base.memtype_valid = nv04_fb_memtype_valid;
87	priv->base.tile.regions = 8;
88	priv->base.tile.init = nv20_fb_tile_init;
89	priv->base.tile.comp = nv25_fb_tile_comp;
90	priv->base.tile.fini = nv20_fb_tile_fini;
91	priv->base.tile.prog = nv20_fb_tile_prog;
92	return nouveau_fb_created(&priv->base);
93}
94
95struct nouveau_oclass
96nv25_fb_oclass = {
97	.handle = NV_SUBDEV(FB, 0x25),
98	.ofuncs = &(struct nouveau_ofuncs) {
99		.ctor = nv25_fb_ctor,
100		.dtor = _nouveau_fb_dtor,
101		.init = _nouveau_fb_init,
102		.fini = _nouveau_fb_fini,
103	},
104};
105