]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c
090a7f2ac9b39fcad5b1930d595d20b752b9160b
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / nvkm / subdev / fb / base.c
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/M0203.h>
27
28 #include "priv.h"
29
30 int
31 nouveau_fb_bios_memtype(struct nouveau_bios *bios)
32 {
33         const u8 ramcfg = (nv_rd32(bios, 0x101000) & 0x0000003c) >> 2;
34         struct nvbios_M0203E M0203E;
35         u8 ver, hdr;
36
37         if (nvbios_M0203Em(bios, ramcfg, &ver, &hdr, &M0203E)) {
38                 switch (M0203E.type) {
39                 case M0203E_TYPE_DDR2 : return NV_MEM_TYPE_DDR2;
40                 case M0203E_TYPE_DDR3 : return NV_MEM_TYPE_DDR3;
41                 case M0203E_TYPE_GDDR3: return NV_MEM_TYPE_GDDR3;
42                 case M0203E_TYPE_GDDR5: return NV_MEM_TYPE_GDDR5;
43                 default:
44                         nv_warn(bios, "M0203E type %02x\n", M0203E.type);
45                         return NV_MEM_TYPE_UNKNOWN;
46                 }
47         }
48
49         nv_warn(bios, "M0203E not matched!\n");
50         return NV_MEM_TYPE_UNKNOWN;
51 }
52
53 int
54 _nouveau_fb_fini(struct nouveau_object *object, bool suspend)
55 {
56         struct nouveau_fb *pfb = (void *)object;
57         int ret;
58
59         ret = nv_ofuncs(pfb->ram)->fini(nv_object(pfb->ram), suspend);
60         if (ret && suspend)
61                 return ret;
62
63         return nouveau_subdev_fini(&pfb->base, suspend);
64 }
65
66 int
67 _nouveau_fb_init(struct nouveau_object *object)
68 {
69         struct nouveau_fb *pfb = (void *)object;
70         int ret, i;
71
72         ret = nouveau_subdev_init(&pfb->base);
73         if (ret)
74                 return ret;
75
76         ret = nv_ofuncs(pfb->ram)->init(nv_object(pfb->ram));
77         if (ret)
78                 return ret;
79
80         for (i = 0; i < pfb->tile.regions; i++)
81                 pfb->tile.prog(pfb, i, &pfb->tile.region[i]);
82
83         return 0;
84 }
85
86 void
87 _nouveau_fb_dtor(struct nouveau_object *object)
88 {
89         struct nouveau_fb *pfb = (void *)object;
90         int i;
91
92         for (i = 0; i < pfb->tile.regions; i++)
93                 pfb->tile.fini(pfb, i, &pfb->tile.region[i]);
94         nouveau_mm_fini(&pfb->tags);
95         nouveau_mm_fini(&pfb->vram);
96
97         nouveau_object_ref(NULL, (struct nouveau_object **)&pfb->ram);
98         nouveau_subdev_destroy(&pfb->base);
99 }
100
101 int
102 nouveau_fb_create_(struct nouveau_object *parent, struct nouveau_object *engine,
103                    struct nouveau_oclass *oclass, int length, void **pobject)
104 {
105         struct nouveau_fb_impl *impl = (void *)oclass;
106         static const char *name[] = {
107                 [NV_MEM_TYPE_UNKNOWN] = "unknown",
108                 [NV_MEM_TYPE_STOLEN ] = "stolen system memory",
109                 [NV_MEM_TYPE_SGRAM  ] = "SGRAM",
110                 [NV_MEM_TYPE_SDRAM  ] = "SDRAM",
111                 [NV_MEM_TYPE_DDR1   ] = "DDR1",
112                 [NV_MEM_TYPE_DDR2   ] = "DDR2",
113                 [NV_MEM_TYPE_DDR3   ] = "DDR3",
114                 [NV_MEM_TYPE_GDDR2  ] = "GDDR2",
115                 [NV_MEM_TYPE_GDDR3  ] = "GDDR3",
116                 [NV_MEM_TYPE_GDDR4  ] = "GDDR4",
117                 [NV_MEM_TYPE_GDDR5  ] = "GDDR5",
118         };
119         struct nouveau_object *ram;
120         struct nouveau_fb *pfb;
121         int ret;
122
123         ret = nouveau_subdev_create_(parent, engine, oclass, 0, "PFB", "fb",
124                                      length, pobject);
125         pfb = *pobject;
126         if (ret)
127                 return ret;
128
129         pfb->memtype_valid = impl->memtype;
130
131         ret = nouveau_object_ctor(nv_object(pfb), NULL,
132                                   impl->ram, NULL, 0, &ram);
133         if (ret) {
134                 nv_fatal(pfb, "error detecting memory configuration!!\n");
135                 return ret;
136         }
137
138         pfb->ram = (void *)ram;
139
140         if (!nouveau_mm_initialised(&pfb->vram)) {
141                 ret = nouveau_mm_init(&pfb->vram, 0, pfb->ram->size >> 12, 1);
142                 if (ret)
143                         return ret;
144         }
145
146         if (!nouveau_mm_initialised(&pfb->tags)) {
147                 ret = nouveau_mm_init(&pfb->tags, 0, pfb->ram->tags ?
148                                      ++pfb->ram->tags : 0, 1);
149                 if (ret)
150                         return ret;
151         }
152
153         nv_info(pfb, "RAM type: %s\n", name[pfb->ram->type]);
154         nv_info(pfb, "RAM size: %d MiB\n", (int)(pfb->ram->size >> 20));
155         nv_info(pfb, "   ZCOMP: %d tags\n", pfb->ram->tags);
156         return 0;
157 }