1 | /* $NetBSD: nouveau_engine_perfmon_daemon.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2013 Red Hat Inc. |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
24 | * Authors: Ben Skeggs |
25 | */ |
26 | |
27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_engine_perfmon_daemon.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $" ); |
29 | |
30 | #include "priv.h" |
31 | |
32 | static void |
33 | pwr_perfctr_init(struct nouveau_perfmon *ppm, struct nouveau_perfdom *dom, |
34 | struct nouveau_perfctr *ctr) |
35 | { |
36 | u32 mask = 0x00000000; |
37 | u32 ctrl = 0x00000001; |
38 | int i; |
39 | |
40 | for (i = 0; i < ARRAY_SIZE(ctr->signal) && ctr->signal[i]; i++) |
41 | mask |= 1 << (ctr->signal[i] - dom->signal); |
42 | |
43 | nv_wr32(ppm, 0x10a504 + (ctr->slot * 0x10), mask); |
44 | nv_wr32(ppm, 0x10a50c + (ctr->slot * 0x10), ctrl); |
45 | nv_wr32(ppm, 0x10a50c + (ppm->last * 0x10), 0x00000003); |
46 | } |
47 | |
48 | static void |
49 | pwr_perfctr_read(struct nouveau_perfmon *ppm, struct nouveau_perfdom *dom, |
50 | struct nouveau_perfctr *ctr) |
51 | { |
52 | ctr->ctr = ppm->pwr[ctr->slot]; |
53 | ctr->clk = ppm->pwr[ppm->last]; |
54 | } |
55 | |
56 | static void |
57 | pwr_perfctr_next(struct nouveau_perfmon *ppm, struct nouveau_perfdom *dom) |
58 | { |
59 | int i; |
60 | |
61 | for (i = 0; i <= ppm->last; i++) { |
62 | ppm->pwr[i] = nv_rd32(ppm, 0x10a508 + (i * 0x10)); |
63 | nv_wr32(ppm, 0x10a508 + (i * 0x10), 0x80000000); |
64 | } |
65 | } |
66 | |
67 | static const struct nouveau_funcdom |
68 | pwr_perfctr_func = { |
69 | .init = pwr_perfctr_init, |
70 | .read = pwr_perfctr_read, |
71 | .next = pwr_perfctr_next, |
72 | }; |
73 | |
74 | const struct nouveau_specdom |
75 | nva3_perfmon_pwr[] = { |
76 | { 0x20, (const struct nouveau_specsig[]) { |
77 | { 0x00, "pwr_gr_idle" }, |
78 | { 0x04, "pwr_bsp_idle" }, |
79 | { 0x05, "pwr_vp_idle" }, |
80 | { 0x06, "pwr_ppp_idle" }, |
81 | { 0x13, "pwr_ce0_idle" }, |
82 | {} |
83 | }, &pwr_perfctr_func }, |
84 | {} |
85 | }; |
86 | |
87 | const struct nouveau_specdom |
88 | nvc0_perfmon_pwr[] = { |
89 | { 0x20, (const struct nouveau_specsig[]) { |
90 | { 0x00, "pwr_gr_idle" }, |
91 | { 0x04, "pwr_bsp_idle" }, |
92 | { 0x05, "pwr_vp_idle" }, |
93 | { 0x06, "pwr_ppp_idle" }, |
94 | { 0x13, "pwr_ce0_idle" }, |
95 | { 0x14, "pwr_ce1_idle" }, |
96 | {} |
97 | }, &pwr_perfctr_func }, |
98 | {} |
99 | }; |
100 | |
101 | const struct nouveau_specdom |
102 | nve0_perfmon_pwr[] = { |
103 | { 0x20, (const struct nouveau_specsig[]) { |
104 | { 0x00, "pwr_gr_idle" }, |
105 | { 0x04, "pwr_bsp_idle" }, |
106 | { 0x05, "pwr_vp_idle" }, |
107 | { 0x06, "pwr_ppp_idle" }, |
108 | { 0x13, "pwr_ce0_idle" }, |
109 | { 0x14, "pwr_ce1_idle" }, |
110 | { 0x15, "pwr_ce2_idle" }, |
111 | {} |
112 | }, &pwr_perfctr_func }, |
113 | {} |
114 | }; |
115 | |