diff options
author | absalam <absalam@nvidia.com> | 2018-09-20 02:51:33 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-09-27 07:54:44 -0400 |
commit | 850f2ad8ada4f4c2c753644f387d75e6d75ac28b (patch) | |
tree | e2ebdf3379b5900116ed6d6dd2013a514f2e4ced /drivers/gpu/nvgpu/gv100 | |
parent | 19a27b99608fe0d0752b12f694c65e38af1c0660 (diff) |
gpu: nvgpu:Add sysfs node for GV100 clocks
Creates sysfs nodes to read clk freq on GV100
Following sysfs nodes are created: gpcclk,xbarclk,sysclk
Uses default clock source and counters for measurement
Bug 200446261
Change-Id: I6903ba77fbe34e3f486f4b663e70eab4e7c5d662
Signed-off-by: absalam <absalam@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1828030
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gv100')
-rw-r--r-- | drivers/gpu/nvgpu/gv100/clk_gv100.c | 193 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gv100/clk_gv100.h | 63 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gv100/hal_gv100.c | 13 |
3 files changed, 262 insertions, 7 deletions
diff --git a/drivers/gpu/nvgpu/gv100/clk_gv100.c b/drivers/gpu/nvgpu/gv100/clk_gv100.c new file mode 100644 index 00000000..7855aa41 --- /dev/null +++ b/drivers/gpu/nvgpu/gv100/clk_gv100.c | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | * GV100 Clocks | ||
3 | * | ||
4 | * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. | ||
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
22 | * DEALINGS IN THE SOFTWARE. | ||
23 | */ | ||
24 | |||
25 | #ifdef CONFIG_DEBUG_FS | ||
26 | #include <linux/debugfs.h> | ||
27 | #include "os/linux/os_linux.h" | ||
28 | #endif | ||
29 | |||
30 | #include <nvgpu/kmem.h> | ||
31 | #include <nvgpu/io.h> | ||
32 | #include <nvgpu/list.h> | ||
33 | #include <nvgpu/clk_arb.h> | ||
34 | #include <nvgpu/timers.h> | ||
35 | |||
36 | #include "gk20a/gk20a.h" | ||
37 | |||
38 | #include "clk_gv100.h" | ||
39 | |||
40 | #include <nvgpu/hw/gv100/hw_trim_gv100.h> | ||
41 | |||
42 | |||
43 | u32 gv100_crystal_clk_hz(struct gk20a *g) | ||
44 | { | ||
45 | return (XTAL4X_KHZ * 1000); | ||
46 | } | ||
47 | |||
48 | unsigned long gv100_clk_measure_freq(struct gk20a *g, u32 api_domain) | ||
49 | { | ||
50 | struct clk_gk20a *clk = &g->clk; | ||
51 | u32 freq_khz; | ||
52 | u32 i; | ||
53 | struct namemap_cfg *c = NULL; | ||
54 | |||
55 | for (i = 0; i < clk->namemap_num; i++) { | ||
56 | if (api_domain == clk->namemap_xlat_table[i]) { | ||
57 | c = &clk->clk_namemap[i]; | ||
58 | break; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | if (c == NULL) { | ||
63 | return 0; | ||
64 | } | ||
65 | if (c->is_counter != 0U) { | ||
66 | freq_khz = c->scale * gv100_get_rate_cntr(g, c); | ||
67 | } else { | ||
68 | freq_khz = 0U; | ||
69 | /* TODO: PLL read */ | ||
70 | } | ||
71 | |||
72 | /* Convert to HZ */ | ||
73 | return freq_khz * 1000UL; | ||
74 | } | ||
75 | |||
76 | int gv100_init_clk_support(struct gk20a *g) | ||
77 | { | ||
78 | struct clk_gk20a *clk = &g->clk; | ||
79 | int err = 0; | ||
80 | |||
81 | nvgpu_log_fn(g, " "); | ||
82 | |||
83 | err = nvgpu_mutex_init(&clk->clk_mutex); | ||
84 | if (err != 0) { | ||
85 | return err; | ||
86 | } | ||
87 | |||
88 | clk->clk_namemap = (struct namemap_cfg *) | ||
89 | nvgpu_kzalloc(g, sizeof(struct namemap_cfg) * NUM_NAMEMAPS); | ||
90 | |||
91 | if (clk->clk_namemap == NULL) { | ||
92 | nvgpu_mutex_destroy(&clk->clk_mutex); | ||
93 | return -ENOMEM; | ||
94 | } | ||
95 | |||
96 | clk->namemap_xlat_table = nvgpu_kcalloc(g, NUM_NAMEMAPS, sizeof(u32)); | ||
97 | |||
98 | if (clk->namemap_xlat_table == NULL) { | ||
99 | nvgpu_kfree(g, clk->clk_namemap); | ||
100 | nvgpu_mutex_destroy(&clk->clk_mutex); | ||
101 | return -ENOMEM; | ||
102 | } | ||
103 | |||
104 | clk->clk_namemap[0] = (struct namemap_cfg) { | ||
105 | .namemap = CLK_NAMEMAP_INDEX_GPCCLK, | ||
106 | .is_enable = 1, | ||
107 | .is_counter = 1, | ||
108 | .g = g, | ||
109 | .cntr = { | ||
110 | .reg_ctrl_addr = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cfg_r(), | ||
111 | .reg_ctrl_idx = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cfg_source_gpcclk_f(), | ||
112 | .reg_cntr_addr[0] = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cnt0_r(), | ||
113 | .reg_cntr_addr[1] = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cnt1_r() | ||
114 | }, | ||
115 | .name = "gpcclk", | ||
116 | .scale = 1 | ||
117 | }; | ||
118 | clk->namemap_xlat_table[0] = CTRL_CLK_DOMAIN_GPCCLK; | ||
119 | |||
120 | clk->clk_namemap[1] = (struct namemap_cfg) { | ||
121 | .namemap = CLK_NAMEMAP_INDEX_SYSCLK, | ||
122 | .is_enable = 1, | ||
123 | .is_counter = 1, | ||
124 | .g = g, | ||
125 | .cntr = { | ||
126 | .reg_ctrl_addr = trim_sys_fr_clk_cntr_sysclk_cfg_r(), | ||
127 | .reg_ctrl_idx = trim_sys_fr_clk_cntr_sysclk_cfg_source_sysclk_f(), | ||
128 | .reg_cntr_addr[0] = trim_sys_fr_clk_cntr_sysclk_cntr0_r(), | ||
129 | .reg_cntr_addr[1] = trim_sys_fr_clk_cntr_sysclk_cntr1_r() | ||
130 | }, | ||
131 | .name = "sysclk", | ||
132 | .scale = 1 | ||
133 | }; | ||
134 | clk->namemap_xlat_table[1] = CTRL_CLK_DOMAIN_SYSCLK; | ||
135 | |||
136 | clk->clk_namemap[2] = (struct namemap_cfg) { | ||
137 | .namemap = CLK_NAMEMAP_INDEX_XBARCLK, | ||
138 | .is_enable = 1, | ||
139 | .is_counter = 1, | ||
140 | .g = g, | ||
141 | .cntr = { | ||
142 | .reg_ctrl_addr = trim_sys_nafll_fr_clk_cntr_xbarclk_cfg_r(), | ||
143 | .reg_ctrl_idx = trim_sys_nafll_fr_clk_cntr_xbarclk_cfg_source_xbarclk_f(), | ||
144 | .reg_cntr_addr[0] = trim_sys_nafll_fr_clk_cntr_xbarclk_cntr0_r(), | ||
145 | .reg_cntr_addr[1] = trim_sys_nafll_fr_clk_cntr_xbarclk_cntr1_r() | ||
146 | }, | ||
147 | .name = "xbarclk", | ||
148 | .scale = 1 | ||
149 | }; | ||
150 | clk->namemap_xlat_table[2] = CTRL_CLK_DOMAIN_XBARCLK; | ||
151 | |||
152 | clk->namemap_num = NUM_NAMEMAPS; | ||
153 | |||
154 | clk->g = g; | ||
155 | |||
156 | return err; | ||
157 | } | ||
158 | |||
159 | u32 gv100_get_rate_cntr(struct gk20a *g, struct namemap_cfg *c) { | ||
160 | u32 cntr = 0; | ||
161 | u64 cntr_start = 0; | ||
162 | u64 cntr_stop = 0; | ||
163 | |||
164 | struct clk_gk20a *clk = &g->clk; | ||
165 | |||
166 | if ((c == NULL) || (c->cntr.reg_ctrl_addr == 0U) || | ||
167 | (c->cntr.reg_cntr_addr[0] == 0U) || | ||
168 | (c->cntr.reg_cntr_addr[1]) == 0U) { | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | nvgpu_mutex_acquire(&clk->clk_mutex); | ||
173 | |||
174 | /* Read the counter values */ | ||
175 | /* Counter is 36bits , 32 bits on addr[0] and 4 lsb on addr[1] others zero*/ | ||
176 | cntr_start = (u64)gk20a_readl(g, c->cntr.reg_cntr_addr[0]); | ||
177 | cntr_start += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32); | ||
178 | nvgpu_udelay(XTAL_CNTR_DELAY); | ||
179 | cntr_stop = (u64) gk20a_readl(g, c->cntr.reg_cntr_addr[0]); | ||
180 | cntr_stop += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32); | ||
181 | /*Calculate the difference and convert to KHz*/ | ||
182 | cntr = (u32)((cntr_stop - cntr_start) / 10ULL); | ||
183 | nvgpu_mutex_release(&clk->clk_mutex); | ||
184 | |||
185 | return cntr; | ||
186 | |||
187 | } | ||
188 | |||
189 | int gv100_suspend_clk_support(struct gk20a *g) | ||
190 | { | ||
191 | nvgpu_mutex_destroy(&g->clk.clk_mutex); | ||
192 | return 0; | ||
193 | } | ||
diff --git a/drivers/gpu/nvgpu/gv100/clk_gv100.h b/drivers/gpu/nvgpu/gv100/clk_gv100.h new file mode 100644 index 00000000..d3356a7f --- /dev/null +++ b/drivers/gpu/nvgpu/gv100/clk_gv100.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. | ||
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | * DEALINGS IN THE SOFTWARE. | ||
21 | */ | ||
22 | #ifndef CLK_GV100_H | ||
23 | #define CLK_GV100_H | ||
24 | |||
25 | #include <nvgpu/lock.h> | ||
26 | #include "gk20a/gk20a.h" | ||
27 | |||
28 | #define CLK_NAMEMAP_INDEX_GPCCLK 0x00 | ||
29 | #define CLK_NAMEMAP_INDEX_XBARCLK 0x02 | ||
30 | #define CLK_NAMEMAP_INDEX_SYSCLK 0x07 /* SYSPLL */ | ||
31 | #define CLK_NAMEMAP_INDEX_DRAMCLK 0x20 /* DRAMPLL */ | ||
32 | |||
33 | #define CLK_DEFAULT_CNTRL_SETTLE_RETRIES 10 | ||
34 | #define CLK_DEFAULT_CNTRL_SETTLE_USECS 5 | ||
35 | #define CLK_MAX_CNTRL_REGISTERS 2 | ||
36 | |||
37 | #define XTAL_CNTR_CLKS 27000 /* 1000usec at 27KHz XTAL */ | ||
38 | #define XTAL_CNTR_DELAY 10000 /* we need acuracy up to the 10ms */ | ||
39 | #define XTAL_SCALE_TO_KHZ 1 | ||
40 | #define NUM_NAMEMAPS (3U) | ||
41 | #define XTAL4X_KHZ 108000 | ||
42 | |||
43 | u32 gv100_get_rate_cntr(struct gk20a *g, struct namemap_cfg *c); | ||
44 | struct namemap_cfg { | ||
45 | u32 namemap; | ||
46 | u32 is_enable; /* Namemap enabled */ | ||
47 | u32 is_counter; /* Using cntr */ | ||
48 | struct gk20a *g; | ||
49 | struct { | ||
50 | u32 reg_ctrl_addr; | ||
51 | u32 reg_ctrl_idx; | ||
52 | u32 reg_cntr_addr[CLK_MAX_CNTRL_REGISTERS]; | ||
53 | } cntr; | ||
54 | u32 scale; | ||
55 | char name[24]; | ||
56 | }; | ||
57 | |||
58 | int gv100_init_clk_support(struct gk20a *g); | ||
59 | u32 gv100_crystal_clk_hz(struct gk20a *g); | ||
60 | unsigned long gv100_clk_measure_freq(struct gk20a *g, u32 api_domain); | ||
61 | int gv100_suspend_clk_support(struct gk20a *g); | ||
62 | |||
63 | #endif /* CLK_GV100_H */ | ||
diff --git a/drivers/gpu/nvgpu/gv100/hal_gv100.c b/drivers/gpu/nvgpu/gv100/hal_gv100.c index 041422e0..7cd466c3 100644 --- a/drivers/gpu/nvgpu/gv100/hal_gv100.c +++ b/drivers/gpu/nvgpu/gv100/hal_gv100.c | |||
@@ -66,13 +66,11 @@ | |||
66 | #include "gm20b/pmu_gm20b.h" | 66 | #include "gm20b/pmu_gm20b.h" |
67 | #include "gm20b/acr_gm20b.h" | 67 | #include "gm20b/acr_gm20b.h" |
68 | 68 | ||
69 | #include "gp106/clk_gp106.h" | ||
70 | #include "gp106/clk_arb_gp106.h" | 69 | #include "gp106/clk_arb_gp106.h" |
71 | #include "gp106/pmu_gp106.h" | 70 | #include "gp106/pmu_gp106.h" |
72 | #include "gp106/acr_gp106.h" | 71 | #include "gp106/acr_gp106.h" |
73 | #include "gp106/sec2_gp106.h" | 72 | #include "gp106/sec2_gp106.h" |
74 | #include "gp106/bios_gp106.h" | 73 | #include "gp106/bios_gp106.h" |
75 | #include "gp106/clk_gp106.h" | ||
76 | #include "gp106/flcn_gp106.h" | 74 | #include "gp106/flcn_gp106.h" |
77 | 75 | ||
78 | #include "gp10b/gr_gp10b.h" | 76 | #include "gp10b/gr_gp10b.h" |
@@ -107,6 +105,7 @@ | |||
107 | #include "gv100/nvlink_gv100.h" | 105 | #include "gv100/nvlink_gv100.h" |
108 | #include "gv100/regops_gv100.h" | 106 | #include "gv100/regops_gv100.h" |
109 | #include "gv100/perf_gv100.h" | 107 | #include "gv100/perf_gv100.h" |
108 | #include "gv100/clk_gv100.h" | ||
110 | 109 | ||
111 | #include <nvgpu/ptimer.h> | 110 | #include <nvgpu/ptimer.h> |
112 | #include <nvgpu/debug.h> | 111 | #include <nvgpu/debug.h> |
@@ -768,11 +767,11 @@ static const struct gpu_ops gv100_ops = { | |||
768 | .secured_pmu_start = gm20b_secured_pmu_start, | 767 | .secured_pmu_start = gm20b_secured_pmu_start, |
769 | }, | 768 | }, |
770 | .clk = { | 769 | .clk = { |
771 | .init_clk_support = gp106_init_clk_support, | 770 | .init_clk_support = gv100_init_clk_support, |
772 | .get_crystal_clk_hz = gp106_crystal_clk_hz, | 771 | .get_crystal_clk_hz = gv100_crystal_clk_hz, |
773 | .get_rate_cntr = gp106_get_rate_cntr, | 772 | .get_rate_cntr = gv100_get_rate_cntr, |
774 | .measure_freq = gp106_clk_measure_freq, | 773 | .measure_freq = gv100_clk_measure_freq, |
775 | .suspend_clk_support = gp106_suspend_clk_support, | 774 | .suspend_clk_support = gv100_suspend_clk_support, |
776 | .perf_pmu_vfe_load = gv100_perf_pmu_vfe_load, | 775 | .perf_pmu_vfe_load = gv100_perf_pmu_vfe_load, |
777 | }, | 776 | }, |
778 | .clk_arb = { | 777 | .clk_arb = { |