Lines Matching +full:ecx +full:- +full:2000

1 // SPDX-License-Identifier: GPL-2.0-only
3 * (c) 2003-2012 Advanced Micro Devices, Inc.
8 * Based on the powernow-k7.c module written by Dave Jones.
48 #include "powernow-k8.h"
112 data->currvid = hi & MSR_S_HI_CURRENT_VID; in query_current_values_with_pending_wait()
113 data->currfid = lo & MSR_S_LO_CURRENT_FID; in query_current_values_with_pending_wait()
121 udelay((1 << data->irt) * 10); in count_off_irt()
127 udelay(data->vstable * VST_UNITS_20US); in count_off_vst()
149 u32 savevid = data->currvid; in write_new_fid()
152 if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) { in write_new_fid()
153 pr_err("internal error - overflow on fid write\n"); in write_new_fid()
158 lo |= (data->currvid << MSR_C_LO_VID_SHIFT); in write_new_fid()
162 fid, lo, data->plllock * PLL_LOCK_CONVERSION); in write_new_fid()
165 wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); in write_new_fid()
167 pr_err("Hardware error - pending bit very stuck - no further pstate changes possible\n"); in write_new_fid()
174 if (savevid != data->currvid) { in write_new_fid()
176 savevid, data->currvid); in write_new_fid()
180 if (fid != data->currfid) { in write_new_fid()
182 data->currfid); in write_new_fid()
193 u32 savefid = data->currfid; in write_new_vid()
196 if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) { in write_new_vid()
197 pr_err("internal error - overflow on vid write\n"); in write_new_vid()
201 lo = data->currfid; in write_new_vid()
211 pr_err("internal error - pending bit very stuck - no further pstate changes possible\n"); in write_new_vid()
216 if (savefid != data->currfid) { in write_new_vid()
218 savefid, data->currfid); in write_new_vid()
222 if (vid != data->currvid) { in write_new_vid()
224 vid, data->currvid); in write_new_vid()
239 if ((data->currvid - reqvid) > step) in decrease_vid_code_by_step()
240 reqvid = data->currvid - step; in decrease_vid_code_by_step()
266 if ((reqfid != data->currfid) || (reqvid != data->currvid)) { in transition_fid_vid()
269 reqfid, reqvid, data->currfid, data->currvid); in transition_fid_vid()
274 smp_processor_id(), data->currfid, data->currvid); in transition_fid_vid()
279 /* Phase 1 - core voltage transition ... setup voltage */
283 u32 rvosteps = data->rvo; in core_voltage_pre_transition()
284 u32 savefid = data->currfid; in core_voltage_pre_transition()
289 data->currfid, data->currvid, reqvid, data->rvo); in core_voltage_pre_transition()
300 while (data->currvid > reqvid) { in core_voltage_pre_transition()
302 data->currvid, reqvid); in core_voltage_pre_transition()
303 if (decrease_vid_code_by_step(data, reqvid, data->vidmvs)) in core_voltage_pre_transition()
308 ((rvomult * data->rvo + data->currvid) > reqvid)) { in core_voltage_pre_transition()
309 if (data->currvid == maxvid) { in core_voltage_pre_transition()
313 data->currvid - 1); in core_voltage_pre_transition()
314 if (decrease_vid_code_by_step(data, data->currvid-1, 1)) in core_voltage_pre_transition()
316 rvosteps--; in core_voltage_pre_transition()
323 if (savefid != data->currfid) { in core_voltage_pre_transition()
324 pr_err("ph1 err, currfid changed 0x%x\n", data->currfid); in core_voltage_pre_transition()
329 data->currfid, data->currvid); in core_voltage_pre_transition()
334 /* Phase 2 - core frequency transition */
338 u32 fid_interval, savevid = data->currvid; in core_frequency_transition()
340 if (data->currfid == reqfid) { in core_frequency_transition()
341 pr_err("ph2 null fid transition 0x%x\n", data->currfid); in core_frequency_transition()
347 data->currfid, data->currvid, reqfid); in core_frequency_transition()
350 vcocurrfid = convert_fid_to_vco_fid(data->currfid); in core_frequency_transition()
351 vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid in core_frequency_transition()
352 : vcoreqfid - vcocurrfid; in core_frequency_transition()
354 if ((reqfid <= LO_FID_TABLE_TOP) && (data->currfid <= LO_FID_TABLE_TOP)) in core_frequency_transition()
358 (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2); in core_frequency_transition()
360 if (reqfid > data->currfid) { in core_frequency_transition()
361 if (data->currfid > LO_FID_TABLE_TOP) { in core_frequency_transition()
363 data->currfid + fid_interval)) in core_frequency_transition()
368 2 + convert_fid_to_vco_fid(data->currfid))) in core_frequency_transition()
372 if (write_new_fid(data, data->currfid - fid_interval)) in core_frequency_transition()
376 vcocurrfid = convert_fid_to_vco_fid(data->currfid); in core_frequency_transition()
377 vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid in core_frequency_transition()
378 : vcoreqfid - vcocurrfid; in core_frequency_transition()
387 if (data->currfid != reqfid) { in core_frequency_transition()
389 data->currfid, reqfid); in core_frequency_transition()
393 if (savevid != data->currvid) { in core_frequency_transition()
395 savevid, data->currvid); in core_frequency_transition()
400 data->currfid, data->currvid); in core_frequency_transition()
405 /* Phase 3 - core voltage transition flow ... jump to the final vid. */
409 u32 savefid = data->currfid; in core_voltage_post_transition()
414 data->currfid, data->currvid); in core_voltage_post_transition()
416 if (reqvid != data->currvid) { in core_voltage_post_transition()
420 if (savefid != data->currfid) { in core_voltage_post_transition()
422 savefid, data->currfid); in core_voltage_post_transition()
426 if (data->currvid != reqvid) { in core_voltage_post_transition()
428 reqvid, data->currvid); in core_voltage_post_transition()
436 if (savereqvid != data->currvid) { in core_voltage_post_transition()
437 pr_debug("ph3 failed, currvid 0x%x\n", data->currvid); in core_voltage_post_transition()
441 if (savefid != data->currfid) { in core_voltage_post_transition()
443 data->currfid); in core_voltage_post_transition()
448 data->currfid, data->currvid); in core_voltage_post_transition()
462 u32 eax, ebx, ecx, edx; in check_supported_cpu() local
465 *rc = -ENODEV; in check_supported_cpu()
482 cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); in check_supported_cpu()
498 for (j = 0; j < data->numps; j++) { in check_pst_table()
502 return -EINVAL; in check_pst_table()
504 if (pst[j].vid < data->rvo) { in check_pst_table()
507 return -ENODEV; in check_pst_table()
509 if (pst[j].vid < maxvid + data->rvo) { in check_pst_table()
512 return -ENODEV; in check_pst_table()
516 return -ENODEV; in check_pst_table()
520 pr_err(FW_BUG "two low fids - %d : 0x%x\n", j, in check_pst_table()
522 return -EINVAL; in check_pst_table()
529 return -EINVAL; in check_pst_table()
546 for (j = 0; j < data->numps; j++) { in print_basics()
547 if (data->powernow_table[j].frequency != in print_basics()
550 data->powernow_table[j].driver_data & 0xff, in print_basics()
551 data->powernow_table[j].frequency/1000, in print_basics()
552 data->powernow_table[j].driver_data >> 8); in print_basics()
555 if (data->batps) in print_basics()
556 pr_info("Only %d pstates on battery\n", data->batps); in print_basics()
565 if (data->batps) { in fill_powernow_table()
568 data->batps); in fill_powernow_table()
569 data->numps = data->batps; in fill_powernow_table()
572 for (j = 1; j < data->numps; j++) { in fill_powernow_table()
573 if (pst[j-1].fid >= pst[j].fid) { in fill_powernow_table()
575 return -EINVAL; in fill_powernow_table()
579 if (data->numps < 2) { in fill_powernow_table()
581 return -ENODEV; in fill_powernow_table()
585 return -EINVAL; in fill_powernow_table()
588 * (data->numps + 1)), GFP_KERNEL); in fill_powernow_table()
590 return -ENOMEM; in fill_powernow_table()
592 for (j = 0; j < data->numps; j++) { in fill_powernow_table()
599 powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; in fill_powernow_table()
600 powernow_table[data->numps].driver_data = 0; in fill_powernow_table()
604 return -EIO; in fill_powernow_table()
607 pr_debug("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); in fill_powernow_table()
608 data->powernow_table = powernow_table; in fill_powernow_table()
609 if (cpumask_first(topology_core_cpumask(data->cpu)) == data->cpu) in fill_powernow_table()
612 for (j = 0; j < data->numps; j++) in fill_powernow_table()
613 if ((pst[j].fid == data->currfid) && in fill_powernow_table()
614 (pst[j].vid == data->currvid)) in fill_powernow_table()
633 /* It can not be at ffff0 - it is too big. */ in find_psb_table()
641 pr_debug("table vers: 0x%x\n", psb->tableversion); in find_psb_table()
642 if (psb->tableversion != PSB_VERSION_1_4) { in find_psb_table()
644 return -ENODEV; in find_psb_table()
647 pr_debug("flags: 0x%x\n", psb->flags1); in find_psb_table()
648 if (psb->flags1) { in find_psb_table()
650 return -ENODEV; in find_psb_table()
653 data->vstable = psb->vstable; in find_psb_table()
655 data->vstable); in find_psb_table()
657 pr_debug("flags2: 0x%x\n", psb->flags2); in find_psb_table()
658 data->rvo = psb->flags2 & 3; in find_psb_table()
659 data->irt = ((psb->flags2) >> 2) & 3; in find_psb_table()
660 mvs = ((psb->flags2) >> 4) & 3; in find_psb_table()
661 data->vidmvs = 1 << mvs; in find_psb_table()
662 data->batps = ((psb->flags2) >> 6) & 3; in find_psb_table()
664 pr_debug("ramp voltage offset: %d\n", data->rvo); in find_psb_table()
665 pr_debug("isochronous relief time: %d\n", data->irt); in find_psb_table()
666 pr_debug("maximum voltage step: %d - 0x%x\n", mvs, data->vidmvs); in find_psb_table()
668 pr_debug("numpst: 0x%x\n", psb->num_tables); in find_psb_table()
669 cpst = psb->num_tables; in find_psb_table()
670 if ((psb->cpuid == 0x00000fc0) || in find_psb_table()
671 (psb->cpuid == 0x00000fe0)) { in find_psb_table()
679 return -ENODEV; in find_psb_table()
682 data->plllock = psb->plllocktime; in find_psb_table()
683 pr_debug("plllocktime: 0x%x (units 1us)\n", psb->plllocktime); in find_psb_table()
684 pr_debug("maxfid: 0x%x\n", psb->maxfid); in find_psb_table()
685 pr_debug("maxvid: 0x%x\n", psb->maxvid); in find_psb_table()
686 maxvid = psb->maxvid; in find_psb_table()
688 data->numps = psb->numps; in find_psb_table()
689 pr_debug("numpstates: 0x%x\n", data->numps); in find_psb_table()
696 * nonsense, remember that Windows 2000 uses the same legacy in find_psb_table()
698 * is broken with Windows 2000. in find_psb_table()
706 return -ENODEV; in find_psb_table()
714 if (!data->acpi_data.state_count) in powernow_k8_acpi_pst_values()
717 control = data->acpi_data.states[index].control; in powernow_k8_acpi_pst_values()
718 data->irt = (control >> IRT_SHIFT) & IRT_MASK; in powernow_k8_acpi_pst_values()
719 data->rvo = (control >> RVO_SHIFT) & RVO_MASK; in powernow_k8_acpi_pst_values()
720 data->exttype = (control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK; in powernow_k8_acpi_pst_values()
721 data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; in powernow_k8_acpi_pst_values()
722 data->vidmvs = 1 << ((control >> MVS_SHIFT) & MVS_MASK); in powernow_k8_acpi_pst_values()
723 data->vstable = (control >> VST_SHIFT) & VST_MASK; in powernow_k8_acpi_pst_values()
729 int ret_val = -ENODEV; in powernow_k8_cpu_init_acpi()
732 if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { in powernow_k8_cpu_init_acpi()
734 return -EIO; in powernow_k8_cpu_init_acpi()
738 if (data->acpi_data.state_count <= 1) { in powernow_k8_cpu_init_acpi()
739 pr_debug("No ACPI P-States\n"); in powernow_k8_cpu_init_acpi()
743 control = data->acpi_data.control_register.space_id; in powernow_k8_cpu_init_acpi()
744 status = data->acpi_data.status_register.space_id; in powernow_k8_cpu_init_acpi()
748 pr_debug("Invalid control/status registers (%llx - %llx)\n", in powernow_k8_cpu_init_acpi()
753 /* fill in data->powernow_table */ in powernow_k8_cpu_init_acpi()
755 * (data->acpi_data.state_count + 1)), GFP_KERNEL); in powernow_k8_cpu_init_acpi()
760 data->numps = data->acpi_data.state_count; in powernow_k8_cpu_init_acpi()
767 powernow_table[data->acpi_data.state_count].frequency = in powernow_k8_cpu_init_acpi()
769 data->powernow_table = powernow_table; in powernow_k8_cpu_init_acpi()
771 if (cpumask_first(topology_core_cpumask(data->cpu)) == data->cpu) in powernow_k8_cpu_init_acpi()
777 if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { in powernow_k8_cpu_init_acpi()
779 ret_val = -ENOMEM; in powernow_k8_cpu_init_acpi()
789 acpi_processor_unregister_performance(data->cpu); in powernow_k8_cpu_init_acpi()
791 /* data->acpi_data.state_count informs us at ->exit() in powernow_k8_cpu_init_acpi()
793 data->acpi_data.state_count = 0; in powernow_k8_cpu_init_acpi()
803 for (i = 0; i < data->acpi_data.state_count; i++) { in fill_powernow_table_fidvid()
809 if (data->exttype) { in fill_powernow_table_fidvid()
810 status = data->acpi_data.states[i].status; in fill_powernow_table_fidvid()
814 control = data->acpi_data.states[i].control; in fill_powernow_table_fidvid()
834 /* verify voltage is OK - in fill_powernow_table_fidvid()
842 if (freq != (data->acpi_data.states[i].core_frequency * 1000)) { in fill_powernow_table_fidvid()
845 (data->acpi_data.states[i].core_frequency in fill_powernow_table_fidvid()
856 if (data->acpi_data.state_count) in powernow_k8_cpu_exit_acpi()
857 acpi_processor_unregister_performance(data->cpu); in powernow_k8_cpu_exit_acpi()
858 free_cpumask_var(data->acpi_data.shared_cpu_map); in powernow_k8_cpu_exit_acpi()
865 for (i = 0; i < data->acpi_data.state_count; i++) { in get_transition_latency()
866 int cur_latency = data->acpi_data.states[i].transition_latency in get_transition_latency()
867 + data->acpi_data.states[i].bus_master_latency; in get_transition_latency()
896 fid = data->powernow_table[index].driver_data & 0xFF; in transition_frequency_fidvid()
897 vid = (data->powernow_table[index].driver_data & 0xFF00) >> 8; in transition_frequency_fidvid()
904 if ((data->currvid == vid) && (data->currfid == fid)) { in transition_frequency_fidvid()
912 freqs.old = find_khz_freq_from_fid(data->currfid); in transition_frequency_fidvid()
930 struct cpufreq_policy *pol = pta->pol; in powernowk8_target_fn()
931 unsigned newstate = pta->newstate; in powernowk8_target_fn()
932 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); in powernowk8_target_fn()
938 return -EINVAL; in powernowk8_target_fn()
940 checkfid = data->currfid; in powernowk8_target_fn()
941 checkvid = data->currvid; in powernowk8_target_fn()
945 return -EIO; in powernowk8_target_fn()
949 pol->cpu, data->powernow_table[newstate].frequency, pol->min, in powernowk8_target_fn()
950 pol->max); in powernowk8_target_fn()
953 return -EIO; in powernowk8_target_fn()
956 data->currfid, data->currvid); in powernowk8_target_fn()
958 if ((checkvid != data->currvid) || in powernowk8_target_fn()
959 (checkfid != data->currfid)) { in powernowk8_target_fn()
960 pr_info("error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n", in powernowk8_target_fn()
961 checkfid, data->currfid, in powernowk8_target_fn()
962 checkvid, data->currvid); in powernowk8_target_fn()
978 pol->cur = find_khz_freq_from_fid(data->currfid); in powernowk8_target_fn()
988 return work_on_cpu(pol->cpu, powernowk8_target_fn, &pta); in powernowk8_target()
1002 init_on_cpu->rc = -ENODEV; in powernowk8_cpu_init_on_cpu()
1006 if (query_current_values_with_pending_wait(init_on_cpu->data)) { in powernowk8_cpu_init_on_cpu()
1007 init_on_cpu->rc = -ENODEV; in powernowk8_cpu_init_on_cpu()
1013 init_on_cpu->rc = 0; in powernowk8_cpu_init_on_cpu()
1028 smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1); in powernowk8_cpu_init()
1030 return -ENODEV; in powernowk8_cpu_init()
1034 return -ENOMEM; in powernowk8_cpu_init()
1036 data->cpu = pol->cpu; in powernowk8_cpu_init()
1047 if (pol->cpu != 0) { in powernowk8_cpu_init()
1057 pol->cpuinfo.transition_latency = ( in powernowk8_cpu_init()
1058 ((data->rvo + 8) * data->vstable * VST_UNITS_20US) + in powernowk8_cpu_init()
1059 ((1 << data->irt) * 30)) * 1000; in powernowk8_cpu_init()
1061 pol->cpuinfo.transition_latency = get_transition_latency(data); in powernowk8_cpu_init()
1065 smp_call_function_single(data->cpu, powernowk8_cpu_init_on_cpu, in powernowk8_cpu_init()
1071 cpumask_copy(pol->cpus, topology_core_cpumask(pol->cpu)); in powernowk8_cpu_init()
1072 data->available_cores = pol->cpus; in powernowk8_cpu_init()
1073 pol->freq_table = data->powernow_table; in powernowk8_cpu_init()
1076 data->currfid, data->currvid); in powernowk8_cpu_init()
1079 for_each_cpu(cpu, pol->cpus) in powernowk8_cpu_init()
1089 return -ENODEV; in powernowk8_cpu_init()
1094 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); in powernowk8_cpu_exit()
1098 return -EINVAL; in powernowk8_cpu_exit()
1102 kfree(data->powernow_table); in powernowk8_cpu_exit()
1104 for_each_cpu(cpu, pol->cpus) in powernowk8_cpu_exit()
1131 khz = find_khz_freq_from_fid(data->currfid); in powernowk8_get()
1146 .name = "powernow-k8",
1152 const char drv[] = "acpi-cpufreq"; in __request_acpi_cpufreq()
1165 pr_warn("This CPU is not supported anymore, using acpi-cpufreq instead.\n"); in __request_acpi_cpufreq()
1176 return -ENODEV; in powernowk8_init()
1180 return -ENODEV; in powernowk8_init()
1192 return -ENODEV; in powernowk8_init()