fb00e82bbed04a9d8b0dc2358d10ff821d9bb617
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / nvkm / engine / pm / nvc0.c
1 /*
2  * Copyright 2013 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 "nvc0.h"
26
27 /*******************************************************************************
28  * Perfmon object classes
29  ******************************************************************************/
30
31 /*******************************************************************************
32  * PPM context
33  ******************************************************************************/
34
35 /*******************************************************************************
36  * PPM engine/subdev functions
37  ******************************************************************************/
38
39 static const struct nouveau_specdom
40 nvc0_pm_hub[] = {
41         {}
42 };
43
44 static const struct nouveau_specdom
45 nvc0_pm_gpc[] = {
46         {}
47 };
48
49 static const struct nouveau_specdom
50 nvc0_pm_part[] = {
51         {}
52 };
53
54 static void
55 nvc0_perfctr_init(struct nouveau_pm *ppm, struct nouveau_perfdom *dom,
56                   struct nouveau_perfctr *ctr)
57 {
58         struct nvc0_pm_priv *priv = (void *)ppm;
59         struct nvc0_pm_cntr *cntr = (void *)ctr;
60         u32 log = ctr->logic_op;
61         u32 src = 0x00000000;
62         int i;
63
64         for (i = 0; i < 4 && ctr->signal[i]; i++)
65                 src |= (ctr->signal[i] - dom->signal) << (i * 8);
66
67         nv_wr32(priv, dom->addr + 0x09c, 0x00040002);
68         nv_wr32(priv, dom->addr + 0x100, 0x00000000);
69         nv_wr32(priv, dom->addr + 0x040 + (cntr->base.slot * 0x08), src);
70         nv_wr32(priv, dom->addr + 0x044 + (cntr->base.slot * 0x08), log);
71 }
72
73 static void
74 nvc0_perfctr_read(struct nouveau_pm *ppm, struct nouveau_perfdom *dom,
75                   struct nouveau_perfctr *ctr)
76 {
77         struct nvc0_pm_priv *priv = (void *)ppm;
78         struct nvc0_pm_cntr *cntr = (void *)ctr;
79
80         switch (cntr->base.slot) {
81         case 0: cntr->base.ctr = nv_rd32(priv, dom->addr + 0x08c); break;
82         case 1: cntr->base.ctr = nv_rd32(priv, dom->addr + 0x088); break;
83         case 2: cntr->base.ctr = nv_rd32(priv, dom->addr + 0x080); break;
84         case 3: cntr->base.ctr = nv_rd32(priv, dom->addr + 0x090); break;
85         }
86         cntr->base.clk = nv_rd32(priv, dom->addr + 0x070);
87 }
88
89 static void
90 nvc0_perfctr_next(struct nouveau_pm *ppm, struct nouveau_perfdom *dom)
91 {
92         struct nvc0_pm_priv *priv = (void *)ppm;
93         nv_wr32(priv, dom->addr + 0x06c, dom->signal_nr - 0x40 + 0x27);
94         nv_wr32(priv, dom->addr + 0x0ec, 0x00000011);
95 }
96
97 const struct nouveau_funcdom
98 nvc0_perfctr_func = {
99         .init = nvc0_perfctr_init,
100         .read = nvc0_perfctr_read,
101         .next = nvc0_perfctr_next,
102 };
103
104 int
105 nvc0_pm_fini(struct nouveau_object *object, bool suspend)
106 {
107         struct nvc0_pm_priv *priv = (void *)object;
108         nv_mask(priv, 0x000200, 0x10000000, 0x00000000);
109         nv_mask(priv, 0x000200, 0x10000000, 0x10000000);
110         return nouveau_pm_fini(&priv->base, suspend);
111 }
112
113 static int
114 nvc0_pm_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
115                   struct nouveau_oclass *oclass, void *data, u32 size,
116                   struct nouveau_object **pobject)
117 {
118         struct nvc0_pm_priv *priv;
119         u32 mask;
120         int ret;
121
122         ret = nouveau_pm_create(parent, engine, oclass, &priv);
123         *pobject = nv_object(priv);
124         if (ret)
125                 return ret;
126
127         ret = nouveau_perfdom_new(&priv->base, "pwr", 0, 0, 0, 0,
128                                    nvc0_pm_pwr);
129         if (ret)
130                 return ret;
131
132         /* HUB */
133         ret = nouveau_perfdom_new(&priv->base, "hub", 0, 0x1b0000, 0, 0x200,
134                                    nvc0_pm_hub);
135         if (ret)
136                 return ret;
137
138         /* GPC */
139         mask  = (1 << nv_rd32(priv, 0x022430)) - 1;
140         mask &= ~nv_rd32(priv, 0x022504);
141         mask &= ~nv_rd32(priv, 0x022584);
142
143         ret = nouveau_perfdom_new(&priv->base, "gpc", mask, 0x180000,
144                                   0x1000, 0x200, nvc0_pm_gpc);
145         if (ret)
146                 return ret;
147
148         /* PART */
149         mask  = (1 << nv_rd32(priv, 0x022438)) - 1;
150         mask &= ~nv_rd32(priv, 0x022548);
151         mask &= ~nv_rd32(priv, 0x0225c8);
152
153         ret = nouveau_perfdom_new(&priv->base, "part", mask, 0x1a0000,
154                                   0x1000, 0x200, nvc0_pm_part);
155         if (ret)
156                 return ret;
157
158         nv_engine(priv)->cclass = &nouveau_pm_cclass;
159         nv_engine(priv)->sclass =  nouveau_pm_sclass;
160         priv->base.last = 7;
161         return 0;
162 }
163
164 struct nouveau_oclass
165 nvc0_pm_oclass = {
166         .handle = NV_ENGINE(PM, 0xc0),
167         .ofuncs = &(struct nouveau_ofuncs) {
168                 .ctor = nvc0_pm_ctor,
169                 .dtor = _nouveau_pm_dtor,
170                 .init = _nouveau_pm_init,
171                 .fini = nvc0_pm_fini,
172         },
173 };