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 static void
30b1e4553cSBen Skeggs nv25_fb_tile_comp(struct nvkm_fb *fb, int i, u32 size, u32 flags,
31639c308eSBen Skeggs 		  struct nvkm_fb_tile *tile)
32c39f472eSBen Skeggs {
33c39f472eSBen Skeggs 	u32 tiles = DIV_ROUND_UP(size, 0x40);
34b1e4553cSBen Skeggs 	u32 tags  = round_up(tiles / fb->ram->parts, 0x40);
35d36a99d2SBen Skeggs 	if (!nvkm_mm_head(&fb->ram->tags, 0, 1, tags, tags, 1, &tile->tag)) {
36c39f472eSBen Skeggs 		if (!(flags & 2)) tile->zcomp = 0x00100000; /* Z16 */
37c39f472eSBen Skeggs 		else              tile->zcomp = 0x00200000; /* Z24S8 */
38c39f472eSBen Skeggs 		tile->zcomp |= tile->tag->offset;
39c39f472eSBen Skeggs #ifdef __BIG_ENDIAN
40c39f472eSBen Skeggs 		tile->zcomp |= 0x01000000;
41c39f472eSBen Skeggs #endif
42c39f472eSBen Skeggs 	}
43c39f472eSBen Skeggs }
44c39f472eSBen Skeggs 
4503c8952fSBen Skeggs static const struct nvkm_fb_func
4603c8952fSBen Skeggs nv25_fb = {
47c39f472eSBen Skeggs 	.tile.regions = 8,
48c39f472eSBen Skeggs 	.tile.init = nv20_fb_tile_init,
49c39f472eSBen Skeggs 	.tile.comp = nv25_fb_tile_comp,
50c39f472eSBen Skeggs 	.tile.fini = nv20_fb_tile_fini,
51c39f472eSBen Skeggs 	.tile.prog = nv20_fb_tile_prog,
5203c8952fSBen Skeggs 	.ram_new = nv20_ram_new,
5303c8952fSBen Skeggs 	.memtype_valid = nv04_fb_memtype_valid,
5403c8952fSBen Skeggs };
5503c8952fSBen Skeggs 
5603c8952fSBen Skeggs int
5703c8952fSBen Skeggs nv25_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb)
5803c8952fSBen Skeggs {
5903c8952fSBen Skeggs 	return nvkm_fb_new_(&nv25_fb, device, index, pfb);
6003c8952fSBen Skeggs }
61