Lines Matching refs:rd
125 static bool is_pl_valid(struct rapl_domain *rd, int pl) in is_pl_valid() argument
129 return rd->rpl[pl].name ? true : false; in is_pl_valid()
132 static int get_pl_lock_prim(struct rapl_domain *rd, int pl) in get_pl_lock_prim() argument
134 if (rd->rp->priv->type == RAPL_IF_TPMI) { in get_pl_lock_prim()
151 if (rd->rp->priv->limits[rd->id] & BIT(POWER_LIMIT2)) in get_pl_lock_prim()
156 static int get_pl_prim(struct rapl_domain *rd, int pl, enum pl_prims prim) in get_pl_prim() argument
162 if (prim == PL_CLAMP && rd->rp->priv->type != RAPL_IF_TPMI) in get_pl_prim()
171 return get_pl_lock_prim(rd, pl); in get_pl_prim()
176 if (prim == PL_CLAMP && rd->rp->priv->type != RAPL_IF_TPMI) in get_pl_prim()
185 return get_pl_lock_prim(rd, pl); in get_pl_prim()
196 return get_pl_lock_prim(rd, pl); in get_pl_prim()
208 int (*check_unit)(struct rapl_domain *rd);
209 void (*set_floor_freq)(struct rapl_domain *rd, bool mode);
210 u64 (*compute_time_window)(struct rapl_domain *rd, u64 val,
253 static int rapl_read_data_raw(struct rapl_domain *rd,
256 static int rapl_write_data_raw(struct rapl_domain *rd,
259 static int rapl_read_pl_data(struct rapl_domain *rd, int pl,
262 static int rapl_write_pl_data(struct rapl_domain *rd, int pl,
265 static u64 rapl_unit_xlate(struct rapl_domain *rd,
282 struct rapl_domain *rd; in get_energy_counter() local
289 rd = power_zone_to_rapl_domain(power_zone); in get_energy_counter()
291 if (!rapl_read_data_raw(rd, ENERGY_COUNTER, true, &energy_now)) { in get_energy_counter()
304 struct rapl_domain *rd = power_zone_to_rapl_domain(pcd_dev); in get_max_energy_counter() local
306 *energy = rapl_unit_xlate(rd, ENERGY_UNIT, ENERGY_STATUS_MASK, 0); in get_max_energy_counter()
312 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone); in release_zone() local
313 struct rapl_package *rp = rd->rp; in release_zone()
318 if (rd->id == RAPL_DOMAIN_PACKAGE) { in release_zone()
319 kfree(rd); in release_zone()
327 static int find_nr_power_limit(struct rapl_domain *rd) in find_nr_power_limit() argument
332 if (is_pl_valid(rd, i)) in find_nr_power_limit()
341 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone); in set_domain_enable() local
342 struct rapl_defaults *defaults = get_defaults(rd->rp); in set_domain_enable()
346 ret = rapl_write_pl_data(rd, POWER_LIMIT1, PL_ENABLE, mode); in set_domain_enable()
348 defaults->set_floor_freq(rd, mode); in set_domain_enable()
356 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone); in get_domain_enable() local
360 if (rd->rpl[POWER_LIMIT1].locked) { in get_domain_enable()
365 ret = rapl_read_pl_data(rd, POWER_LIMIT1, PL_ENABLE, true, &val); in get_domain_enable()
422 static int contraint_to_pl(struct rapl_domain *rd, int cid) in contraint_to_pl() argument
427 if (is_pl_valid(rd, i) && j++ == cid) { in contraint_to_pl()
440 struct rapl_domain *rd; in set_power_limit() local
446 rd = power_zone_to_rapl_domain(power_zone); in set_power_limit()
447 id = contraint_to_pl(rd, cid); in set_power_limit()
448 rp = rd->rp; in set_power_limit()
450 ret = rapl_write_pl_data(rd, id, PL_LIMIT, power_limit); in set_power_limit()
460 struct rapl_domain *rd; in get_current_power_limit() local
466 rd = power_zone_to_rapl_domain(power_zone); in get_current_power_limit()
467 id = contraint_to_pl(rd, cid); in get_current_power_limit()
469 ret = rapl_read_pl_data(rd, id, PL_LIMIT, true, &val); in get_current_power_limit()
481 struct rapl_domain *rd; in set_time_window() local
486 rd = power_zone_to_rapl_domain(power_zone); in set_time_window()
487 id = contraint_to_pl(rd, cid); in set_time_window()
489 ret = rapl_write_pl_data(rd, id, PL_TIME_WINDOW, window); in set_time_window()
498 struct rapl_domain *rd; in get_time_window() local
504 rd = power_zone_to_rapl_domain(power_zone); in get_time_window()
505 id = contraint_to_pl(rd, cid); in get_time_window()
507 ret = rapl_read_pl_data(rd, id, PL_TIME_WINDOW, true, &val); in get_time_window()
519 struct rapl_domain *rd; in get_constraint_name() local
522 rd = power_zone_to_rapl_domain(power_zone); in get_constraint_name()
523 id = contraint_to_pl(rd, cid); in get_constraint_name()
525 return rd->rpl[id].name; in get_constraint_name()
532 struct rapl_domain *rd; in get_max_power() local
538 rd = power_zone_to_rapl_domain(power_zone); in get_max_power()
539 id = contraint_to_pl(rd, cid); in get_max_power()
541 ret = rapl_read_pl_data(rd, id, PL_MAX_POWER, true, &val); in get_max_power()
574 struct rapl_domain *rd = rp->domains; in rapl_init_domains() local
583 rd->rp = rp; in rapl_init_domains()
586 snprintf(rd->name, RAPL_DOMAIN_NAME_LENGTH, "psys-%d", in rapl_init_domains()
590 snprintf(rd->name, RAPL_DOMAIN_NAME_LENGTH, "%s", in rapl_init_domains()
594 rd->id = i; in rapl_init_domains()
601 rd->rpl[t].name = pl_names[t]; in rapl_init_domains()
605 rd->regs[j] = rp->priv->regs[i][j]; in rapl_init_domains()
607 rd++; in rapl_init_domains()
611 static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type, in rapl_unit_xlate() argument
615 struct rapl_defaults *defaults = get_defaults(rd->rp); in rapl_unit_xlate()
620 units = rd->power_unit; in rapl_unit_xlate()
624 units = rd->energy_unit; in rapl_unit_xlate()
627 return defaults->compute_time_window(rd, value, to_raw); in rapl_unit_xlate()
774 prim_fixups(struct rapl_domain *rd, enum rapl_primitives prim) in prim_fixups() argument
776 struct rapl_defaults *defaults = get_defaults(rd->rp); in prim_fixups()
781 if (rd->id != RAPL_DOMAIN_PLATFORM) in prim_fixups()
815 static int rapl_read_data_raw(struct rapl_domain *rd, in rapl_read_data_raw() argument
819 enum rapl_primitives prim_fixed = prim_fixups(rd, prim); in rapl_read_data_raw()
820 struct rapl_primitive_info *rpi = get_rpi(rd->rp, prim_fixed); in rapl_read_data_raw()
826 ra.reg = rd->regs[rpi->id]; in rapl_read_data_raw()
832 *data = rd->rdd.primitives[prim]; in rapl_read_data_raw()
838 if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra)) { in rapl_read_data_raw()
839 pr_debug("failed to read reg 0x%llx for %s:%s\n", ra.reg.val, rd->rp->name, rd->name); in rapl_read_data_raw()
846 *data = rapl_unit_xlate(rd, rpi->unit, value, 0); in rapl_read_data_raw()
854 static int rapl_write_data_raw(struct rapl_domain *rd, in rapl_write_data_raw() argument
858 enum rapl_primitives prim_fixed = prim_fixups(rd, prim); in rapl_write_data_raw()
859 struct rapl_primitive_info *rpi = get_rpi(rd->rp, prim_fixed); in rapl_write_data_raw()
867 bits = rapl_unit_xlate(rd, rpi->unit, value, 1); in rapl_write_data_raw()
873 ra.reg = rd->regs[rpi->id]; in rapl_write_data_raw()
877 ret = rd->rp->priv->write_raw(get_rid(rd->rp), &ra); in rapl_write_data_raw()
882 static int rapl_read_pl_data(struct rapl_domain *rd, int pl, in rapl_read_pl_data() argument
885 enum rapl_primitives prim = get_pl_prim(rd, pl, pl_prim); in rapl_read_pl_data()
887 if (!is_pl_valid(rd, pl)) in rapl_read_pl_data()
890 return rapl_read_data_raw(rd, prim, xlate, data); in rapl_read_pl_data()
893 static int rapl_write_pl_data(struct rapl_domain *rd, int pl, in rapl_write_pl_data() argument
897 enum rapl_primitives prim = get_pl_prim(rd, pl, pl_prim); in rapl_write_pl_data()
899 if (!is_pl_valid(rd, pl)) in rapl_write_pl_data()
902 if (rd->rpl[pl].locked) { in rapl_write_pl_data()
903 pr_debug("%s:%s:%s locked by BIOS\n", rd->rp->name, rd->name, pl_names[pl]); in rapl_write_pl_data()
907 return rapl_write_data_raw(rd, prim, value); in rapl_write_pl_data()
920 static int rapl_check_unit_core(struct rapl_domain *rd) in rapl_check_unit_core() argument
925 ra.reg = rd->regs[RAPL_DOMAIN_REG_UNIT]; in rapl_check_unit_core()
927 if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra)) { in rapl_check_unit_core()
929 ra.reg.val, rd->rp->name, rd->name); in rapl_check_unit_core()
934 rd->energy_unit = ENERGY_UNIT_SCALE * 1000000 / (1 << value); in rapl_check_unit_core()
937 rd->power_unit = 1000000 / (1 << value); in rapl_check_unit_core()
940 rd->time_unit = 1000000 / (1 << value); in rapl_check_unit_core()
943 rd->rp->name, rd->name, rd->energy_unit, rd->time_unit, rd->power_unit); in rapl_check_unit_core()
948 static int rapl_check_unit_atom(struct rapl_domain *rd) in rapl_check_unit_atom() argument
953 ra.reg = rd->regs[RAPL_DOMAIN_REG_UNIT]; in rapl_check_unit_atom()
955 if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra)) { in rapl_check_unit_atom()
957 ra.reg.val, rd->rp->name, rd->name); in rapl_check_unit_atom()
962 rd->energy_unit = ENERGY_UNIT_SCALE * 1 << value; in rapl_check_unit_atom()
965 rd->power_unit = (1 << value) * 1000; in rapl_check_unit_atom()
968 rd->time_unit = 1000000 / (1 << value); in rapl_check_unit_atom()
971 rd->rp->name, rd->name, rd->energy_unit, rd->time_unit, rd->power_unit); in rapl_check_unit_atom()
1040 static void set_floor_freq_default(struct rapl_domain *rd, bool mode) in set_floor_freq_default() argument
1047 rapl_write_pl_data(rd, POWER_LIMIT1, PL_CLAMP, mode); in set_floor_freq_default()
1050 rapl_write_pl_data(rd, i, PL_ENABLE, mode); in set_floor_freq_default()
1051 rapl_write_pl_data(rd, i, PL_CLAMP, mode); in set_floor_freq_default()
1055 static void set_floor_freq_atom(struct rapl_domain *rd, bool enable) in set_floor_freq_atom() argument
1058 struct rapl_defaults *defaults = get_defaults(rd->rp); in set_floor_freq_atom()
1079 static u64 rapl_compute_time_window_core(struct rapl_domain *rd, u64 value, in rapl_compute_time_window_core() argument
1091 value = (1 << y) * (4 + f) * rd->time_unit / 4; in rapl_compute_time_window_core()
1093 if (value < rd->time_unit) in rapl_compute_time_window_core()
1096 do_div(value, rd->time_unit); in rapl_compute_time_window_core()
1112 static u64 rapl_compute_time_window_atom(struct rapl_domain *rd, u64 value, in rapl_compute_time_window_atom() argument
1120 return (value) ? value * rd->time_unit : rd->time_unit; in rapl_compute_time_window_atom()
1122 value = div64_u64(value, rd->time_unit); in rapl_compute_time_window_atom()
1135 static int rapl_check_unit_tpmi(struct rapl_domain *rd) in rapl_check_unit_tpmi() argument
1140 ra.reg = rd->regs[RAPL_DOMAIN_REG_UNIT]; in rapl_check_unit_tpmi()
1142 if (rd->rp->priv->read_raw(get_rid(rd->rp), &ra)) { in rapl_check_unit_tpmi()
1144 ra.reg.val, rd->rp->name, rd->name); in rapl_check_unit_tpmi()
1149 rd->energy_unit = ENERGY_UNIT_SCALE * 1000000 / (1 << value); in rapl_check_unit_tpmi()
1152 rd->power_unit = 1000000 / (1 << value); in rapl_check_unit_tpmi()
1155 rd->time_unit = 1000000 / (1 << value); in rapl_check_unit_tpmi()
1158 rd->rp->name, rd->name, rd->energy_unit, rd->time_unit, rd->power_unit); in rapl_check_unit_tpmi()
1318 struct rapl_domain *rd; in rapl_package_register_powercap() local
1326 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_package_register_powercap()
1327 if (rd->id == RAPL_DOMAIN_PACKAGE) { in rapl_package_register_powercap()
1328 nr_pl = find_nr_power_limit(rd); in rapl_package_register_powercap()
1330 power_zone = powercap_register_zone(&rd->power_zone, in rapl_package_register_powercap()
1332 NULL, &zone_ops[rd->id], nr_pl, in rapl_package_register_powercap()
1350 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_package_register_powercap()
1353 if (rd->id == RAPL_DOMAIN_PACKAGE) in rapl_package_register_powercap()
1355 if (rd->id == RAPL_DOMAIN_PLATFORM) in rapl_package_register_powercap()
1358 nr_pl = find_nr_power_limit(rd); in rapl_package_register_powercap()
1359 power_zone = powercap_register_zone(&rd->power_zone, in rapl_package_register_powercap()
1361 rd->name, parent, in rapl_package_register_powercap()
1362 &zone_ops[rd->id], nr_pl, in rapl_package_register_powercap()
1367 rp->name, rd->name); in rapl_package_register_powercap()
1379 while (--rd >= rp->domains) { in rapl_package_register_powercap()
1380 pr_debug("unregister %s domain %s\n", rp->name, rd->name); in rapl_package_register_powercap()
1382 &rd->power_zone); in rapl_package_register_powercap()
1420 static int rapl_get_domain_unit(struct rapl_domain *rd) in rapl_get_domain_unit() argument
1422 struct rapl_defaults *defaults = get_defaults(rd->rp); in rapl_get_domain_unit()
1425 if (!rd->regs[RAPL_DOMAIN_REG_UNIT].val) { in rapl_get_domain_unit()
1426 if (!rd->rp->priv->reg_unit.val) { in rapl_get_domain_unit()
1430 rd->regs[RAPL_DOMAIN_REG_UNIT] = rd->rp->priv->reg_unit; in rapl_get_domain_unit()
1438 ret = defaults->check_unit(rd); in rapl_get_domain_unit()
1442 if (rd->id == RAPL_DOMAIN_DRAM && defaults->dram_domain_energy_unit) in rapl_get_domain_unit()
1443 rd->energy_unit = defaults->dram_domain_energy_unit; in rapl_get_domain_unit()
1444 if (rd->id == RAPL_DOMAIN_PLATFORM && defaults->psys_domain_energy_unit) in rapl_get_domain_unit()
1445 rd->energy_unit = defaults->psys_domain_energy_unit; in rapl_get_domain_unit()
1458 static void rapl_detect_powerlimit(struct rapl_domain *rd) in rapl_detect_powerlimit() argument
1464 if (!rapl_read_pl_data(rd, i, PL_LOCK, false, &val64)) { in rapl_detect_powerlimit()
1466 rd->rpl[i].locked = true; in rapl_detect_powerlimit()
1468 rd->rp->name, rd->name, pl_names[i]); in rapl_detect_powerlimit()
1472 if (rapl_read_pl_data(rd, i, PL_LIMIT, false, &val64)) in rapl_detect_powerlimit()
1473 rd->rpl[i].name = NULL; in rapl_detect_powerlimit()
1482 struct rapl_domain *rd; in rapl_detect_domains() local
1506 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_detect_domains()
1507 rapl_get_domain_unit(rd); in rapl_detect_domains()
1508 rapl_detect_powerlimit(rd); in rapl_detect_domains()
2022 struct rapl_domain *rd = &rp->domains[idx]; in rapl_package_add_pmu() local
2023 int domain = rd->id; in rapl_package_add_pmu()
2033 val = rd->energy_unit * (1ULL << 32); in rapl_package_add_pmu()
2052 val *= rd->energy_unit; in rapl_package_add_pmu()
2059 pr_debug("Domain %s: hw unit %lld * 2^-32 Joules\n", rd->name, data->scale[domain]); in rapl_package_add_pmu()
2097 struct rapl_domain *rd, *rd_package = NULL; in rapl_remove_package_cpuslocked() local
2101 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { in rapl_remove_package_cpuslocked()
2105 rapl_write_pl_data(rd, i, PL_ENABLE, 0); in rapl_remove_package_cpuslocked()
2106 rapl_write_pl_data(rd, i, PL_CLAMP, 0); in rapl_remove_package_cpuslocked()
2109 if (rd->id == RAPL_DOMAIN_PACKAGE) { in rapl_remove_package_cpuslocked()
2110 rd_package = rd; in rapl_remove_package_cpuslocked()
2114 rp->name, rd->name); in rapl_remove_package_cpuslocked()
2116 &rd->power_zone); in rapl_remove_package_cpuslocked()
2247 struct rapl_domain *rd; in power_limit_state_save() local
2254 rd = power_zone_to_rapl_domain(rp->power_zone); in power_limit_state_save()
2256 ret = rapl_read_pl_data(rd, i, PL_LIMIT, true, in power_limit_state_save()
2257 &rd->rpl[i].last_power_limit); in power_limit_state_save()
2259 rd->rpl[i].last_power_limit = 0; in power_limit_state_save()
2268 struct rapl_domain *rd; in power_limit_state_restore() local
2275 rd = power_zone_to_rapl_domain(rp->power_zone); in power_limit_state_restore()
2277 if (rd->rpl[i].last_power_limit) in power_limit_state_restore()
2278 rapl_write_pl_data(rd, i, PL_LIMIT, in power_limit_state_restore()
2279 rd->rpl[i].last_power_limit); in power_limit_state_restore()