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