• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/bios.h>
26 #include <subdev/bios/bit.h>
27 
28 #include "priv.h"
29 
30 int
nouveau_fb_bios_memtype(struct nouveau_bios * bios)31 nouveau_fb_bios_memtype(struct nouveau_bios *bios)
32 {
33 	struct bit_entry M;
34 	u8 ramcfg;
35 
36 	ramcfg = (nv_rd32(bios, 0x101000) & 0x0000003c) >> 2;
37 	if (!bit_entry(bios, 'M', &M) && M.version == 2 && M.length >= 5) {
38 		u16 table   = nv_ro16(bios, M.offset + 3);
39 		u8  version = nv_ro08(bios, table + 0);
40 		u8  header  = nv_ro08(bios, table + 1);
41 		u8  record  = nv_ro08(bios, table + 2);
42 		u8  entries = nv_ro08(bios, table + 3);
43 		if (table && version == 0x10 && ramcfg < entries) {
44 			u16 entry = table + header + (ramcfg * record);
45 			switch (nv_ro08(bios, entry) & 0x0f) {
46 			case 0: return NV_MEM_TYPE_DDR2;
47 			case 1: return NV_MEM_TYPE_DDR3;
48 			case 2: return NV_MEM_TYPE_GDDR3;
49 			case 3: return NV_MEM_TYPE_GDDR5;
50 			default:
51 				break;
52 			}
53 
54 		}
55 	}
56 
57 	return NV_MEM_TYPE_UNKNOWN;
58 }
59 
60 int
_nouveau_fb_fini(struct nouveau_object * object,bool suspend)61 _nouveau_fb_fini(struct nouveau_object *object, bool suspend)
62 {
63 	struct nouveau_fb *pfb = (void *)object;
64 	int ret;
65 
66 	ret = nv_ofuncs(pfb->ram)->fini(nv_object(pfb->ram), suspend);
67 	if (ret && suspend)
68 		return ret;
69 
70 	return nouveau_subdev_fini(&pfb->base, suspend);
71 }
72 
73 int
_nouveau_fb_init(struct nouveau_object * object)74 _nouveau_fb_init(struct nouveau_object *object)
75 {
76 	struct nouveau_fb *pfb = (void *)object;
77 	int ret, i;
78 
79 	ret = nouveau_subdev_init(&pfb->base);
80 	if (ret)
81 		return ret;
82 
83 	ret = nv_ofuncs(pfb->ram)->init(nv_object(pfb->ram));
84 	if (ret)
85 		return ret;
86 
87 	for (i = 0; i < pfb->tile.regions; i++)
88 		pfb->tile.prog(pfb, i, &pfb->tile.region[i]);
89 
90 	return 0;
91 }
92 
93 void
_nouveau_fb_dtor(struct nouveau_object * object)94 _nouveau_fb_dtor(struct nouveau_object *object)
95 {
96 	struct nouveau_fb *pfb = (void *)object;
97 	int i;
98 
99 	for (i = 0; i < pfb->tile.regions; i++)
100 		pfb->tile.fini(pfb, i, &pfb->tile.region[i]);
101 	nouveau_mm_fini(&pfb->tags);
102 	nouveau_mm_fini(&pfb->vram);
103 
104 	nouveau_object_ref(NULL, (struct nouveau_object **)&pfb->ram);
105 	nouveau_subdev_destroy(&pfb->base);
106 }
107 
108 int
nouveau_fb_create_(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,int length,void ** pobject)109 nouveau_fb_create_(struct nouveau_object *parent, struct nouveau_object *engine,
110 		   struct nouveau_oclass *oclass, int length, void **pobject)
111 {
112 	struct nouveau_fb_impl *impl = (void *)oclass;
113 	static const char *name[] = {
114 		[NV_MEM_TYPE_UNKNOWN] = "unknown",
115 		[NV_MEM_TYPE_STOLEN ] = "stolen system memory",
116 		[NV_MEM_TYPE_SGRAM  ] = "SGRAM",
117 		[NV_MEM_TYPE_SDRAM  ] = "SDRAM",
118 		[NV_MEM_TYPE_DDR1   ] = "DDR1",
119 		[NV_MEM_TYPE_DDR2   ] = "DDR2",
120 		[NV_MEM_TYPE_DDR3   ] = "DDR3",
121 		[NV_MEM_TYPE_GDDR2  ] = "GDDR2",
122 		[NV_MEM_TYPE_GDDR3  ] = "GDDR3",
123 		[NV_MEM_TYPE_GDDR4  ] = "GDDR4",
124 		[NV_MEM_TYPE_GDDR5  ] = "GDDR5",
125 	};
126 	struct nouveau_object *ram;
127 	struct nouveau_fb *pfb;
128 	int ret;
129 
130 	ret = nouveau_subdev_create_(parent, engine, oclass, 0, "PFB", "fb",
131 				     length, pobject);
132 	pfb = *pobject;
133 	if (ret)
134 		return ret;
135 
136 	pfb->memtype_valid = impl->memtype;
137 
138 	ret = nouveau_object_ctor(nv_object(pfb), nv_object(pfb),
139 				  impl->ram, NULL, 0, &ram);
140 	if (ret) {
141 		nv_fatal(pfb, "error detecting memory configuration!!\n");
142 		return ret;
143 	}
144 
145 	atomic_dec(&ram->parent->refcount);
146 	atomic_dec(&ram->engine->refcount);
147 	pfb->ram = (void *)ram;
148 
149 	if (!nouveau_mm_initialised(&pfb->vram)) {
150 		ret = nouveau_mm_init(&pfb->vram, 0, pfb->ram->size >> 12, 1);
151 		if (ret)
152 			return ret;
153 	}
154 
155 	if (!nouveau_mm_initialised(&pfb->tags)) {
156 		ret = nouveau_mm_init(&pfb->tags, 0, pfb->ram->tags ?
157 				     ++pfb->ram->tags : 0, 1);
158 		if (ret)
159 			return ret;
160 	}
161 
162 	nv_info(pfb, "RAM type: %s\n", name[pfb->ram->type]);
163 	nv_info(pfb, "RAM size: %d MiB\n", (int)(pfb->ram->size >> 20));
164 	nv_info(pfb, "   ZCOMP: %d tags\n", pfb->ram->tags);
165 	return 0;
166 }
167