* Coding style cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34407 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b834a54550
commit
c1cb57b1b1
|
@ -1,6 +1,15 @@
|
|||
/*
|
||||
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Clemens Zeidler, haiku@clemens-zeidler.de
|
||||
*/
|
||||
|
||||
|
||||
#include "frequency.h"
|
||||
|
||||
#include <kernel/arch/x86/arch_cpu.h>
|
||||
#include <arch/x86/arch_cpu.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -8,14 +17,14 @@
|
|||
|
||||
|
||||
void
|
||||
est_get_id16(uint16 *id16_p)
|
||||
est_get_id16(uint16* _id16)
|
||||
{
|
||||
*id16_p = x86_read_msr(MSR_GET_FREQ_STATE) & 0xffff;
|
||||
*_id16 = x86_read_msr(MSR_GET_FREQ_STATE) & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
est_set_id16(uint16 id16, bool need_check)
|
||||
est_set_id16(uint16 id16, bool needCheck)
|
||||
{
|
||||
uint64 msr;
|
||||
|
||||
|
@ -24,13 +33,13 @@ est_set_id16(uint16 id16, bool need_check)
|
|||
msr = (msr & ~0xffff) | id16;
|
||||
x86_write_msr(MSR_SET_FREQ_STATE, msr);
|
||||
|
||||
if (need_check) {
|
||||
if (needCheck) {
|
||||
// Wait a short while for the new setting. XXX Is this necessary?
|
||||
snooze(EST_TRANS_LAT);
|
||||
|
||||
uint16 new_id16;
|
||||
est_get_id16(&new_id16);
|
||||
if (new_id16 != id16)
|
||||
uint16 newID16;
|
||||
est_get_id16(&newID16);
|
||||
if (newID16 != id16)
|
||||
return B_ERROR;
|
||||
TRACE("EST: set frequency ok, id %i\n", id16);
|
||||
}
|
||||
|
@ -38,24 +47,21 @@ est_set_id16(uint16 id16, bool need_check)
|
|||
}
|
||||
|
||||
|
||||
freq_info *
|
||||
est_get_current(freq_info *freq_list)
|
||||
freq_info*
|
||||
est_get_current(freq_info* list)
|
||||
{
|
||||
freq_info *f;
|
||||
int i;
|
||||
// Try a few times to get a valid value. Sometimes, if the CPU
|
||||
// is in the middle of an asynchronous transition (i.e., P4TCC),
|
||||
// we get a temporary invalid result.
|
||||
for (uint32 i = 0; i < 5; i++) {
|
||||
uint16 id16;
|
||||
|
||||
/*
|
||||
* Try a few times to get a valid value. Sometimes, if the CPU
|
||||
* is in the middle of an asynchronous transition (i.e., P4TCC),
|
||||
* we get a temporary invalid result.
|
||||
*/
|
||||
for (i = 0; i < 5; i++) {
|
||||
est_get_id16(&id16);
|
||||
for (f = freq_list; f->id != 0; f++) {
|
||||
if (f->id == id16)
|
||||
return (f);
|
||||
|
||||
for (freq_info* info = list; info->id != 0; info++) {
|
||||
if (info->id == id16)
|
||||
return info;
|
||||
}
|
||||
|
||||
snooze(100);
|
||||
}
|
||||
return NULL;
|
||||
|
@ -63,21 +69,18 @@ est_get_current(freq_info *freq_list)
|
|||
|
||||
|
||||
status_t
|
||||
est_get_info(freq_info **freqsInfo)
|
||||
est_get_info(freq_info** _frequencyInfos)
|
||||
{
|
||||
uint64 msr;
|
||||
status_t error = B_ERROR;
|
||||
|
||||
msr = x86_read_msr(MSR_GET_FREQ_STATE);
|
||||
error = est_table_info(msr, freqsInfo);
|
||||
if (error != B_OK) {
|
||||
uint64 msr = x86_read_msr(MSR_GET_FREQ_STATE);
|
||||
status_t status = est_table_info(msr, _frequencyInfos);
|
||||
if (status != B_OK) {
|
||||
TRACE("EST: Get frequency table from model specific register\n");
|
||||
error = est_msr_info(msr, freqsInfo);
|
||||
status = est_msr_info(msr, _frequencyInfos);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
if (status != B_OK) {
|
||||
TRACE("est: CPU supports Enhanced Speedstep, but is not recognized.\n");
|
||||
return error;
|
||||
return status;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
|
@ -85,31 +88,30 @@ est_get_info(freq_info **freqsInfo)
|
|||
|
||||
|
||||
status_t
|
||||
est_table_info(uint64 msr, freq_info **freqs)
|
||||
est_table_info(uint64 msr, freq_info** _frequencyInfos)
|
||||
{
|
||||
ss_cpu_info *p;
|
||||
uint32 id;
|
||||
|
||||
/* Find a table which matches (vendor, id32). */
|
||||
system_info sysInfo;
|
||||
if (get_system_info(&sysInfo) != B_OK)
|
||||
// Find a table which matches (vendor, id32).
|
||||
system_info info;
|
||||
if (get_system_info(&info) != B_OK)
|
||||
return B_ERROR;
|
||||
id = msr >> 32;
|
||||
for (p = ESTprocs; p->id32 != 0; p++) {
|
||||
if (p->vendor_id == uint32(sysInfo.cpu_type & B_CPU_x86_VENDOR_MASK)
|
||||
&& p->id32 == id)
|
||||
|
||||
ss_cpu_info* cpuInfo;
|
||||
uint32 id = msr >> 32;
|
||||
for (cpuInfo = ESTprocs; cpuInfo->id32 != 0; cpuInfo++) {
|
||||
if (cpuInfo->vendor_id == uint32(info.cpu_type & B_CPU_x86_VENDOR_MASK)
|
||||
&& cpuInfo->id32 == id)
|
||||
break;
|
||||
}
|
||||
if (p->id32 == 0)
|
||||
if (cpuInfo->id32 == 0)
|
||||
return B_ERROR;
|
||||
|
||||
/* Make sure the current setpoint is valid. */
|
||||
if (est_get_current(p->freqtab) == NULL) {
|
||||
// Make sure the current setpoint is valid.
|
||||
if (est_get_current(cpuInfo->freqtab) == NULL) {
|
||||
TRACE("current setting not found in table\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
*freqs = p->freqtab;
|
||||
*_frequencyInfos = cpuInfo->freqtab;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -128,25 +130,21 @@ bus_speed_ok(int bus)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Flesh out a simple rate table containing the high and low frequencies
|
||||
* based on the current clock speed and the upper 32 bits of the MSR.
|
||||
*/
|
||||
status_t
|
||||
est_msr_info(uint64 msr, freq_info **freqs)
|
||||
{
|
||||
freq_info *fp;
|
||||
int32 bus, freq, volts;
|
||||
uint16 id;
|
||||
|
||||
/*! Flesh out a simple rate table containing the high and low frequencies
|
||||
based on the current clock speed and the upper 32 bits of the MSR.
|
||||
*/
|
||||
status_t
|
||||
est_msr_info(uint64 msr, freq_info** _frequencyInfos)
|
||||
{
|
||||
// Figure out the bus clock.
|
||||
system_info sysInfo;
|
||||
if (get_system_info(&sysInfo) != B_OK)
|
||||
system_info info;
|
||||
if (get_system_info(&info) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
freq = sysInfo.cpu_clock_speed / 1000000;
|
||||
id = msr >> 32;
|
||||
bus = freq / (id >> 8);
|
||||
int32 freq = info.cpu_clock_speed / 1000000;
|
||||
uint16 id = msr >> 32;
|
||||
int32 bus = freq / (id >> 8);
|
||||
|
||||
TRACE("est: Guessed bus clock (high) of %d MHz\n", int(bus));
|
||||
if (!bus_speed_ok(bus)) {
|
||||
|
@ -163,19 +161,22 @@ est_msr_info(uint64 msr, freq_info **freqs)
|
|||
}
|
||||
|
||||
// Fill out a new freq table containing just the high and low freqs.
|
||||
fp = (freq_info*)malloc(sizeof(freq_info) * 3);
|
||||
memset(fp, 0, sizeof(freq_info) * 3);
|
||||
freq_info* frequencyInfo = (freq_info*)malloc(sizeof(freq_info) * 3);
|
||||
if (frequencyInfo == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
memset(frequencyInfo, 0, sizeof(freq_info) * 3);
|
||||
|
||||
// First, the high frequency.
|
||||
volts = id & 0xff;
|
||||
int32 volts = id & 0xff;
|
||||
if (volts != 0) {
|
||||
volts <<= 4;
|
||||
volts += 700;
|
||||
}
|
||||
fp[0].frequency = freq;
|
||||
fp[0].volts = volts;
|
||||
fp[0].id = id;
|
||||
fp[0].power = CPUFREQ_VAL_UNKNOWN;
|
||||
frequencyInfo[0].frequency = freq;
|
||||
frequencyInfo[0].volts = volts;
|
||||
frequencyInfo[0].id = id;
|
||||
frequencyInfo[0].power = CPUFREQ_VAL_UNKNOWN;
|
||||
TRACE("Guessed high setting of %d MHz @ %d Mv\n", int(freq), int(volts));
|
||||
|
||||
// Second, the low frequency.
|
||||
|
@ -186,13 +187,13 @@ est_msr_info(uint64 msr, freq_info **freqs)
|
|||
volts <<= 4;
|
||||
volts += 700;
|
||||
}
|
||||
fp[1].frequency = freq;
|
||||
fp[1].volts = volts;
|
||||
fp[1].id = id;
|
||||
fp[1].power = CPUFREQ_VAL_UNKNOWN;
|
||||
frequencyInfo[1].frequency = freq;
|
||||
frequencyInfo[1].volts = volts;
|
||||
frequencyInfo[1].id = id;
|
||||
frequencyInfo[1].power = CPUFREQ_VAL_UNKNOWN;
|
||||
TRACE("Guessed low setting of %d MHz @ %d Mv\n", int(freq), int(volts));
|
||||
|
||||
// Table is already terminated due to M_ZERO.
|
||||
*freqs = fp;
|
||||
*_frequencyInfos = frequencyInfo;
|
||||
return B_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue