Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2010 Francisco Jerez.
0003  * All Rights Reserved.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining
0006  * a copy of this software and associated documentation files (the
0007  * "Software"), to deal in the Software without restriction, including
0008  * without limitation the rights to use, copy, modify, merge, publish,
0009  * distribute, sublicense, and/or sell copies of the Software, and to
0010  * permit persons to whom the Software is furnished to do so, subject to
0011  * the following conditions:
0012  *
0013  * The above copyright notice and this permission notice (including the
0014  * next paragraph) shall be included in all copies or substantial
0015  * portions of the Software.
0016  *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0018  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0020  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
0021  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0022  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0023  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0024  *
0025  */
0026 #include "priv.h"
0027 #include "ram.h"
0028 
0029 void
0030 nv30_fb_tile_init(struct nvkm_fb *fb, int i, u32 addr, u32 size, u32 pitch,
0031           u32 flags, struct nvkm_fb_tile *tile)
0032 {
0033     /* for performance, select alternate bank offset for zeta */
0034     if (!(flags & 4)) {
0035         tile->addr = (0 << 4);
0036     } else {
0037         if (fb->func->tile.comp) /* z compression */
0038             fb->func->tile.comp(fb, i, size, flags, tile);
0039         tile->addr = (1 << 4);
0040     }
0041 
0042     tile->addr |= 0x00000001; /* enable */
0043     tile->addr |= addr;
0044     tile->limit = max(1u, addr + size) - 1;
0045     tile->pitch = pitch;
0046 }
0047 
0048 static void
0049 nv30_fb_tile_comp(struct nvkm_fb *fb, int i, u32 size, u32 flags,
0050           struct nvkm_fb_tile *tile)
0051 {
0052     u32 tiles = DIV_ROUND_UP(size, 0x40);
0053     u32 tags  = round_up(tiles / fb->ram->parts, 0x40);
0054     if (!nvkm_mm_head(&fb->tags.mm, 0, 1, tags, tags, 1, &tile->tag)) {
0055         if (flags & 2) tile->zcomp |= 0x01000000; /* Z16 */
0056         else           tile->zcomp |= 0x02000000; /* Z24S8 */
0057         tile->zcomp |= ((tile->tag->offset           ) >> 6);
0058         tile->zcomp |= ((tile->tag->offset + tags - 1) >> 6) << 12;
0059 #ifdef __BIG_ENDIAN
0060         tile->zcomp |= 0x10000000;
0061 #endif
0062     }
0063 }
0064 
0065 static int
0066 calc_bias(struct nvkm_fb *fb, int k, int i, int j)
0067 {
0068     struct nvkm_device *device = fb->subdev.device;
0069     int b = (device->chipset > 0x30 ?
0070          nvkm_rd32(device, 0x122c + 0x10 * k + 0x4 * j) >>
0071             (4 * (i ^ 1)) :
0072          0) & 0xf;
0073 
0074     return 2 * (b & 0x8 ? b - 0x10 : b);
0075 }
0076 
0077 static int
0078 calc_ref(struct nvkm_fb *fb, int l, int k, int i)
0079 {
0080     int j, x = 0;
0081 
0082     for (j = 0; j < 4; j++) {
0083         int m = (l >> (8 * i) & 0xff) + calc_bias(fb, k, i, j);
0084 
0085         x |= (0x80 | clamp(m, 0, 0x1f)) << (8 * j);
0086     }
0087 
0088     return x;
0089 }
0090 
0091 void
0092 nv30_fb_init(struct nvkm_fb *fb)
0093 {
0094     struct nvkm_device *device = fb->subdev.device;
0095     int i, j;
0096 
0097     /* Init the memory timing regs at 0x10037c/0x1003ac */
0098     if (device->chipset == 0x30 ||
0099         device->chipset == 0x31 ||
0100         device->chipset == 0x35) {
0101         /* Related to ROP count */
0102         int n = (device->chipset == 0x31 ? 2 : 4);
0103         int l = nvkm_rd32(device, 0x1003d0);
0104 
0105         for (i = 0; i < n; i++) {
0106             for (j = 0; j < 3; j++)
0107                 nvkm_wr32(device, 0x10037c + 0xc * i + 0x4 * j,
0108                       calc_ref(fb, l, 0, j));
0109 
0110             for (j = 0; j < 2; j++)
0111                 nvkm_wr32(device, 0x1003ac + 0x8 * i + 0x4 * j,
0112                       calc_ref(fb, l, 1, j));
0113         }
0114     }
0115 }
0116 
0117 static const struct nvkm_fb_func
0118 nv30_fb = {
0119     .tags = nv20_fb_tags,
0120     .init = nv30_fb_init,
0121     .tile.regions = 8,
0122     .tile.init = nv30_fb_tile_init,
0123     .tile.comp = nv30_fb_tile_comp,
0124     .tile.fini = nv20_fb_tile_fini,
0125     .tile.prog = nv20_fb_tile_prog,
0126     .ram_new = nv20_ram_new,
0127 };
0128 
0129 int
0130 nv30_fb_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_fb **pfb)
0131 {
0132     return nvkm_fb_new_(&nv30_fb, device, type, inst, pfb);
0133 }