Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nv04.c
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24 
25 #include <subdev/fb.h>
26 
27 #define NV04_PFB_BOOT_0 0x00100000
28 # define NV04_PFB_BOOT_0_RAM_AMOUNT 0x00000003
29 # define NV04_PFB_BOOT_0_RAM_AMOUNT_32MB 0x00000000
30 # define NV04_PFB_BOOT_0_RAM_AMOUNT_4MB 0x00000001
31 # define NV04_PFB_BOOT_0_RAM_AMOUNT_8MB 0x00000002
32 # define NV04_PFB_BOOT_0_RAM_AMOUNT_16MB 0x00000003
33 # define NV04_PFB_BOOT_0_RAM_WIDTH_128 0x00000004
34 # define NV04_PFB_BOOT_0_RAM_TYPE 0x00000028
35 # define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_8MBIT 0x00000000
36 # define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT 0x00000008
37 # define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT_4BANK 0x00000010
38 # define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_16MBIT 0x00000018
39 # define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBIT 0x00000020
40 # define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBITX16 0x00000028
41 # define NV04_PFB_BOOT_0_UMA_ENABLE 0x00000100
42 # define NV04_PFB_BOOT_0_UMA_SIZE 0x0000f000
43 #define NV04_PFB_CFG0 0x00100200
44 
45 struct nv04_fb_priv {
46  struct nouveau_fb base;
47 };
48 
49 bool
50 nv04_fb_memtype_valid(struct nouveau_fb *pfb, u32 tile_flags)
51 {
52  if (!(tile_flags & 0xff00))
53  return true;
54 
55  return false;
56 }
57 
58 static int
59 nv04_fb_init(struct nouveau_object *object)
60 {
61  struct nv04_fb_priv *priv = (void *)object;
62  int ret;
63 
64  ret = nouveau_fb_init(&priv->base);
65  if (ret)
66  return ret;
67 
68  /* This is what the DDX did for NV_ARCH_04, but a mmio-trace shows
69  * nvidia reading PFB_CFG_0, then writing back its original value.
70  * (which was 0x701114 in this case)
71  */
72  nv_wr32(priv, NV04_PFB_CFG0, 0x1114);
73  return 0;
74 }
75 
76 static int
77 nv04_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
78  struct nouveau_oclass *oclass, void *data, u32 size,
79  struct nouveau_object **pobject)
80 {
81  struct nv04_fb_priv *priv;
82  u32 boot0;
83  int ret;
84 
85  ret = nouveau_fb_create(parent, engine, oclass, &priv);
86  *pobject = nv_object(priv);
87  if (ret)
88  return ret;
89 
90  boot0 = nv_rd32(priv, NV04_PFB_BOOT_0);
91  if (boot0 & 0x00000100) {
92  priv->base.ram.size = ((boot0 >> 12) & 0xf) * 2 + 2;
93  priv->base.ram.size *= 1024 * 1024;
94  } else {
95  switch (boot0 & NV04_PFB_BOOT_0_RAM_AMOUNT) {
97  priv->base.ram.size = 32 * 1024 * 1024;
98  break;
100  priv->base.ram.size = 16 * 1024 * 1024;
101  break;
103  priv->base.ram.size = 8 * 1024 * 1024;
104  break;
106  priv->base.ram.size = 4 * 1024 * 1024;
107  break;
108  }
109  }
110 
111  if ((boot0 & 0x00000038) <= 0x10)
112  priv->base.ram.type = NV_MEM_TYPE_SGRAM;
113  else
114  priv->base.ram.type = NV_MEM_TYPE_SDRAM;
115 
116 
117  priv->base.memtype_valid = nv04_fb_memtype_valid;
118  return nouveau_fb_created(&priv->base);
119 }
120 
121 struct nouveau_oclass
123  .handle = NV_SUBDEV(FB, 0x04),
124  .ofuncs = &(struct nouveau_ofuncs) {
125  .ctor = nv04_fb_ctor,
126  .dtor = _nouveau_fb_dtor,
127  .init = nv04_fb_init,
128  .fini = _nouveau_fb_fini,
129  },
130 };