Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nv30.c
Go to the documentation of this file.
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 
29 struct nv30_fb_priv {
30  struct nouveau_fb base;
31 };
32 
33 void
34 nv30_fb_tile_init(struct nouveau_fb *pfb, int i, u32 addr, u32 size, u32 pitch,
35  u32 flags, struct nouveau_fb_tile *tile)
36 {
37  tile->addr = addr | 1;
38  tile->limit = max(1u, addr + size) - 1;
39  tile->pitch = pitch;
40 }
41 
42 void
44 {
45  tile->addr = 0;
46  tile->limit = 0;
47  tile->pitch = 0;
48 }
49 
50 static int
51 calc_bias(struct nv30_fb_priv *priv, int k, int i, int j)
52 {
53  struct nouveau_device *device = nv_device(priv);
54  int b = (device->chipset > 0x30 ?
55  nv_rd32(priv, 0x122c + 0x10 * k + 0x4 * j) >> (4 * (i ^ 1)) :
56  0) & 0xf;
57 
58  return 2 * (b & 0x8 ? b - 0x10 : b);
59 }
60 
61 static int
62 calc_ref(struct nv30_fb_priv *priv, int l, int k, int i)
63 {
64  int j, x = 0;
65 
66  for (j = 0; j < 4; j++) {
67  int m = (l >> (8 * i) & 0xff) + calc_bias(priv, k, i, j);
68 
69  x |= (0x80 | clamp(m, 0, 0x1f)) << (8 * j);
70  }
71 
72  return x;
73 }
74 
75 static int
76 nv30_fb_init(struct nouveau_object *object)
77 {
78  struct nouveau_device *device = nv_device(object);
79  struct nv30_fb_priv *priv = (void *)object;
80  int ret, i, j;
81 
82  ret = nouveau_fb_init(&priv->base);
83  if (ret)
84  return ret;
85 
86  /* Init the memory timing regs at 0x10037c/0x1003ac */
87  if (device->chipset == 0x30 ||
88  device->chipset == 0x31 ||
89  device->chipset == 0x35) {
90  /* Related to ROP count */
91  int n = (device->chipset == 0x31 ? 2 : 4);
92  int l = nv_rd32(priv, 0x1003d0);
93 
94  for (i = 0; i < n; i++) {
95  for (j = 0; j < 3; j++)
96  nv_wr32(priv, 0x10037c + 0xc * i + 0x4 * j,
97  calc_ref(priv, l, 0, j));
98 
99  for (j = 0; j < 2; j++)
100  nv_wr32(priv, 0x1003ac + 0x8 * i + 0x4 * j,
101  calc_ref(priv, l, 1, j));
102  }
103  }
104 
105  return 0;
106 }
107 
108 static int
109 nv30_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
110  struct nouveau_oclass *oclass, void *data, u32 size,
111  struct nouveau_object **pobject)
112 {
113  struct nv30_fb_priv *priv;
114  u32 pbus1218;
115  int ret;
116 
117  ret = nouveau_fb_create(parent, engine, oclass, &priv);
118  *pobject = nv_object(priv);
119  if (ret)
120  return ret;
121 
122  pbus1218 = nv_rd32(priv, 0x001218);
123  switch (pbus1218 & 0x00000300) {
124  case 0x00000000: priv->base.ram.type = NV_MEM_TYPE_SDRAM; break;
125  case 0x00000100: priv->base.ram.type = NV_MEM_TYPE_DDR1; break;
126  case 0x00000200: priv->base.ram.type = NV_MEM_TYPE_GDDR3; break;
127  case 0x00000300: priv->base.ram.type = NV_MEM_TYPE_GDDR2; break;
128  }
129  priv->base.ram.size = nv_rd32(priv, 0x10020c) & 0xff000000;
130 
131  priv->base.memtype_valid = nv04_fb_memtype_valid;
132  priv->base.tile.regions = 8;
133  priv->base.tile.init = nv30_fb_tile_init;
134  priv->base.tile.fini = nv30_fb_tile_fini;
135  priv->base.tile.prog = nv10_fb_tile_prog;
136  return nouveau_fb_created(&priv->base);
137 }
138 
139 struct nouveau_oclass
141  .handle = NV_SUBDEV(FB, 0x30),
142  .ofuncs = &(struct nouveau_ofuncs) {
143  .ctor = nv30_fb_ctor,
144  .dtor = _nouveau_fb_dtor,
145  .init = nv30_fb_init,
146  .fini = _nouveau_fb_fini,
147  },
148 };