0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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
0034 if (!(flags & 4)) {
0035 tile->addr = (0 << 4);
0036 } else {
0037 if (fb->func->tile.comp)
0038 fb->func->tile.comp(fb, i, size, flags, tile);
0039 tile->addr = (1 << 4);
0040 }
0041
0042 tile->addr |= 0x00000001;
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;
0056 else tile->zcomp |= 0x02000000;
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
0098 if (device->chipset == 0x30 ||
0099 device->chipset == 0x31 ||
0100 device->chipset == 0x35) {
0101
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 }