diff options
Diffstat (limited to 'include/lpwr')
| -rw-r--r-- | include/lpwr/lpwr.c | 448 | ||||
| -rw-r--r-- | include/lpwr/lpwr.h | 101 | ||||
| -rw-r--r-- | include/lpwr/rppg.c | 160 | ||||
| -rw-r--r-- | include/lpwr/rppg.h | 26 |
4 files changed, 735 insertions, 0 deletions
diff --git a/include/lpwr/lpwr.c b/include/lpwr/lpwr.c new file mode 100644 index 0000000..c8cfb84 --- /dev/null +++ b/include/lpwr/lpwr.c | |||
| @@ -0,0 +1,448 @@ | |||
| 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 | |||
| 23 | #include <nvgpu/bios.h> | ||
| 24 | #include <nvgpu/pmu.h> | ||
| 25 | #include <nvgpu/clk_arb.h> | ||
| 26 | #include <nvgpu/gk20a.h> | ||
| 27 | |||
| 28 | #include "gp106/bios_gp106.h" | ||
| 29 | #include "pstate/pstate.h" | ||
| 30 | #include "pmu_perf/pmu_perf.h" | ||
| 31 | #include "lpwr.h" | ||
| 32 | |||
| 33 | static int get_lpwr_idx_table(struct gk20a *g) | ||
| 34 | { | ||
| 35 | u32 *lpwr_idx_table_ptr; | ||
| 36 | u8 *entry_addr; | ||
| 37 | u32 idx; | ||
| 38 | struct nvgpu_lpwr_bios_idx_data *pidx_data = | ||
| 39 | &g->perf_pmu.lpwr.lwpr_bios_data.idx; | ||
| 40 | struct nvgpu_bios_lpwr_idx_table_1x_header header = { 0 }; | ||
| 41 | struct nvgpu_bios_lpwr_idx_table_1x_entry entry = { 0 }; | ||
| 42 | |||
| 43 | lpwr_idx_table_ptr = (u32 *)nvgpu_bios_get_perf_table_ptrs(g, | ||
| 44 | g->bios.perf_token, LOWPOWER_TABLE); | ||
| 45 | if (lpwr_idx_table_ptr == NULL) { | ||
| 46 | return -EINVAL; | ||
| 47 | } | ||
| 48 | |||
| 49 | memcpy(&header, lpwr_idx_table_ptr, | ||
| 50 | sizeof(struct nvgpu_bios_lpwr_idx_table_1x_header)); | ||
| 51 | |||
| 52 | if (header.entry_count >= LPWR_VBIOS_IDX_ENTRY_COUNT_MAX) { | ||
| 53 | return -EINVAL; | ||
| 54 | } | ||
| 55 | |||
| 56 | pidx_data->base_sampling_period = (u16)header.base_sampling_period; | ||
| 57 | |||
| 58 | /* Parse the LPWR Index Table entries.*/ | ||
| 59 | for (idx = 0; idx < header.entry_count; idx++) { | ||
| 60 | entry_addr = (u8 *)lpwr_idx_table_ptr + header.header_size + | ||
| 61 | (idx * header.entry_size); | ||
| 62 | |||
| 63 | memcpy(&entry, entry_addr, | ||
| 64 | sizeof(struct nvgpu_bios_lpwr_idx_table_1x_entry)); | ||
| 65 | |||
| 66 | pidx_data->entry[idx].pcie_idx = entry.pcie_idx; | ||
| 67 | pidx_data->entry[idx].gr_idx = entry.gr_idx; | ||
| 68 | pidx_data->entry[idx].ms_idx = entry.ms_idx; | ||
| 69 | pidx_data->entry[idx].di_idx = entry.di_idx; | ||
| 70 | pidx_data->entry[idx].gc6_idx = entry.gc6_idx; | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | return 0; | ||
| 75 | } | ||
| 76 | |||
| 77 | static int get_lpwr_gr_table(struct gk20a *g) | ||
| 78 | { | ||
| 79 | u32 *lpwr_gr_table_ptr; | ||
| 80 | u8 *entry_addr; | ||
| 81 | u32 idx; | ||
| 82 | struct nvgpu_lpwr_bios_gr_data *pgr_data = | ||
| 83 | &g->perf_pmu.lpwr.lwpr_bios_data.gr; | ||
| 84 | struct nvgpu_bios_lpwr_gr_table_1x_header header = { 0 }; | ||
| 85 | struct nvgpu_bios_lpwr_gr_table_1x_entry entry = { 0 }; | ||
| 86 | |||
| 87 | lpwr_gr_table_ptr = (u32 *)nvgpu_bios_get_perf_table_ptrs(g, | ||
| 88 | g->bios.perf_token, LOWPOWER_GR_TABLE); | ||
| 89 | if (lpwr_gr_table_ptr == NULL) { | ||
| 90 | return -EINVAL; | ||
| 91 | } | ||
| 92 | |||
| 93 | memcpy(&header, lpwr_gr_table_ptr, | ||
| 94 | sizeof(struct nvgpu_bios_lpwr_gr_table_1x_header)); | ||
| 95 | |||
| 96 | /* Parse the LPWR Index Table entries.*/ | ||
| 97 | for (idx = 0; idx < header.entry_count; idx++) { | ||
| 98 | entry_addr = (u8 *)lpwr_gr_table_ptr + header.header_size + | ||
| 99 | (idx * header.entry_size); | ||
| 100 | |||
| 101 | memcpy(&entry, entry_addr, | ||
| 102 | sizeof(struct nvgpu_bios_lpwr_gr_table_1x_entry)); | ||
| 103 | |||
| 104 | if (BIOS_GET_FIELD(entry.feautre_mask, | ||
| 105 | NV_VBIOS_LPWR_MS_FEATURE_MASK_MS)) { | ||
| 106 | pgr_data->entry[idx].gr_enabled = true; | ||
| 107 | |||
| 108 | pgr_data->entry[idx].feature_mask = | ||
| 109 | NVGPU_PMU_GR_FEATURE_MASK_ALL; | ||
| 110 | |||
| 111 | if (!BIOS_GET_FIELD(entry.feautre_mask, | ||
| 112 | NV_VBIOS_LPWR_GR_FEATURE_MASK_GR_RPPG)) { | ||
| 113 | pgr_data->entry[idx].feature_mask &= | ||
| 114 | ~NVGPU_PMU_GR_FEATURE_MASK_RPPG; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | } | ||
| 119 | |||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | |||
| 123 | static int get_lpwr_ms_table(struct gk20a *g) | ||
| 124 | { | ||
| 125 | u32 *lpwr_ms_table_ptr; | ||
| 126 | u8 *entry_addr; | ||
| 127 | u32 idx; | ||
| 128 | struct nvgpu_lpwr_bios_ms_data *pms_data = | ||
| 129 | &g->perf_pmu.lpwr.lwpr_bios_data.ms; | ||
| 130 | struct nvgpu_bios_lpwr_ms_table_1x_header header = { 0 }; | ||
| 131 | struct nvgpu_bios_lpwr_ms_table_1x_entry entry = { 0 }; | ||
| 132 | |||
| 133 | lpwr_ms_table_ptr = (u32 *)nvgpu_bios_get_perf_table_ptrs(g, | ||
| 134 | g->bios.perf_token, LOWPOWER_MS_TABLE); | ||
| 135 | if (lpwr_ms_table_ptr == NULL) { | ||
| 136 | return -EINVAL; | ||
| 137 | } | ||
| 138 | |||
| 139 | memcpy(&header, lpwr_ms_table_ptr, | ||
| 140 | sizeof(struct nvgpu_bios_lpwr_ms_table_1x_header)); | ||
| 141 | |||
| 142 | if (header.entry_count >= LPWR_VBIOS_MS_ENTRY_COUNT_MAX) { | ||
| 143 | return -EINVAL; | ||
| 144 | } | ||
| 145 | |||
| 146 | pms_data->default_entry_idx = (u8)header.default_entry_idx; | ||
| 147 | |||
| 148 | pms_data->idle_threshold_us = (u32)(header.idle_threshold_us * 10); | ||
| 149 | |||
| 150 | /* Parse the LPWR MS Table entries.*/ | ||
| 151 | for (idx = 0; idx < header.entry_count; idx++) { | ||
| 152 | entry_addr = (u8 *)lpwr_ms_table_ptr + header.header_size + | ||
| 153 | (idx * header.entry_size); | ||
| 154 | |||
| 155 | memcpy(&entry, entry_addr, | ||
| 156 | sizeof(struct nvgpu_bios_lpwr_ms_table_1x_entry)); | ||
| 157 | |||
| 158 | if (BIOS_GET_FIELD(entry.feautre_mask, | ||
| 159 | NV_VBIOS_LPWR_MS_FEATURE_MASK_MS)) { | ||
| 160 | pms_data->entry[idx].ms_enabled = true; | ||
| 161 | |||
| 162 | pms_data->entry[idx].feature_mask = | ||
| 163 | NVGPU_PMU_MS_FEATURE_MASK_ALL; | ||
| 164 | |||
| 165 | if (!BIOS_GET_FIELD(entry.feautre_mask, | ||
| 166 | NV_VBIOS_LPWR_MS_FEATURE_MASK_MS_CLOCK_GATING)) { | ||
| 167 | pms_data->entry[idx].feature_mask &= | ||
| 168 | ~NVGPU_PMU_MS_FEATURE_MASK_CLOCK_GATING; | ||
| 169 | } | ||
| 170 | |||
| 171 | if (!BIOS_GET_FIELD(entry.feautre_mask, | ||
| 172 | NV_VBIOS_LPWR_MS_FEATURE_MASK_MS_SWASR)) { | ||
| 173 | pms_data->entry[idx].feature_mask &= | ||
| 174 | ~NVGPU_PMU_MS_FEATURE_MASK_SW_ASR; | ||
| 175 | } | ||
| 176 | |||
| 177 | if (!BIOS_GET_FIELD(entry.feautre_mask, | ||
| 178 | NV_VBIOS_LPWR_MS_FEATURE_MASK_MS_RPPG)) { | ||
| 179 | pms_data->entry[idx].feature_mask &= | ||
| 180 | ~NVGPU_PMU_MS_FEATURE_MASK_RPPG; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | pms_data->entry[idx].dynamic_current_logic = | ||
| 185 | entry.dynamic_current_logic; | ||
| 186 | |||
| 187 | pms_data->entry[idx].dynamic_current_sram = | ||
| 188 | entry.dynamic_current_sram; | ||
| 189 | } | ||
| 190 | |||
| 191 | return 0; | ||
| 192 | } | ||
| 193 | |||
| 194 | u32 nvgpu_lpwr_pg_setup(struct gk20a *g) | ||
| 195 | { | ||
| 196 | u32 err = 0; | ||
| 197 | |||
| 198 | nvgpu_log_fn(g, " "); | ||
| 199 | |||
| 200 | err = get_lpwr_gr_table(g); | ||
| 201 | if (err) { | ||
| 202 | return err; | ||
| 203 | } | ||
| 204 | |||
| 205 | err = get_lpwr_ms_table(g); | ||
| 206 | if (err) { | ||
| 207 | return err; | ||
| 208 | } | ||
| 209 | |||
| 210 | err = get_lpwr_idx_table(g); | ||
| 211 | |||
| 212 | return err; | ||
| 213 | } | ||
| 214 | |||
| 215 | static void nvgpu_pmu_handle_param_lpwr_msg(struct gk20a *g, | ||
| 216 | struct pmu_msg *msg, void *param, | ||
| 217 | u32 handle, u32 status) | ||
| 218 | { | ||
| 219 | u32 *ack_status = param; | ||
| 220 | |||
| 221 | nvgpu_log_fn(g, " "); | ||
| 222 | |||
| 223 | if (status != 0) { | ||
| 224 | nvgpu_err(g, "LWPR PARAM cmd aborted"); | ||
| 225 | return; | ||
