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
nv04_fb_memtype_valid(struct nouveau_fb * pfb,u32 tile_flags)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
nv04_fb_vram_init(struct nouveau_fb * pfb)59 nv04_fb_vram_init(struct nouveau_fb *pfb)
60 {
61 u32 boot0 = nv_rd32(pfb, NV04_PFB_BOOT_0);
62 if (boot0 & 0x00000100) {
63 pfb->ram.size = ((boot0 >> 12) & 0xf) * 2 + 2;
64 pfb->ram.size *= 1024 * 1024;
65 } else {
66 switch (boot0 & NV04_PFB_BOOT_0_RAM_AMOUNT) {
67 case NV04_PFB_BOOT_0_RAM_AMOUNT_32MB:
68 pfb->ram.size = 32 * 1024 * 1024;
69 break;
70 case NV04_PFB_BOOT_0_RAM_AMOUNT_16MB:
71 pfb->ram.size = 16 * 1024 * 1024;
72 break;
73 case NV04_PFB_BOOT_0_RAM_AMOUNT_8MB:
74 pfb->ram.size = 8 * 1024 * 1024;
75 break;
76 case NV04_PFB_BOOT_0_RAM_AMOUNT_4MB:
77 pfb->ram.size = 4 * 1024 * 1024;
78 break;
79 }
80 }
81
82 if ((boot0 & 0x00000038) <= 0x10)
83 pfb->ram.type = NV_MEM_TYPE_SGRAM;
84 else
85 pfb->ram.type = NV_MEM_TYPE_SDRAM;
86 return 0;
87 }
88
89 static int
nv04_fb_init(struct nouveau_object * object)90 nv04_fb_init(struct nouveau_object *object)
91 {
92 struct nv04_fb_priv *priv = (void *)object;
93 int ret;
94
95 ret = nouveau_fb_init(&priv->base);
96 if (ret)
97 return ret;
98
99 /* This is what the DDX did for NV_ARCH_04, but a mmio-trace shows
100 * nvidia reading PFB_CFG_0, then writing back its original value.
101 * (which was 0x701114 in this case)
102 */
103 nv_wr32(priv, NV04_PFB_CFG0, 0x1114);
104 return 0;
105 }
106
107 static int
nv04_fb_ctor(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,void * data,u32 size,struct nouveau_object ** pobject)108 nv04_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
109 struct nouveau_oclass *oclass, void *data, u32 size,
110 struct nouveau_object **pobject)
111 {
112 struct nv04_fb_priv *priv;
113 int ret;
114
115 ret = nouveau_fb_create(parent, engine, oclass, &priv);
116 *pobject = nv_object(priv);
117 if (ret)
118 return ret;
119
120 priv->base.memtype_valid = nv04_fb_memtype_valid;
121 priv->base.ram.init = nv04_fb_vram_init;
122 return nouveau_fb_preinit(&priv->base);
123 }
124
125 struct nouveau_oclass
126 nv04_fb_oclass = {
127 .handle = NV_SUBDEV(FB, 0x04),
128 .ofuncs = &(struct nouveau_ofuncs) {
129 .ctor = nv04_fb_ctor,
130 .dtor = _nouveau_fb_dtor,
131 .init = nv04_fb_init,
132 .fini = _nouveau_fb_fini,
133 },
134 };
135