📄 cpu.c
字号:
/*- * Copyright (c) 2005, Kohsuke Ohtani * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* $OpenBSD: est.c,v 1.11 2005/03/07 06:59:14 mbalmer Exp $ *//* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* * This is a driver for Intel's Enhanced SpeedStep, as implemented in * Pentium M processors. * * Reference documentation: * * - IA-32 Intel Architecture Software Developer's Manual, Volume 3: * System Programming Guide. * Section 13.14, Enhanced Intel SpeedStep technology. * Table B-2, MSRs in Pentium M Processors. * http://www.intel.com/design/pentium4/manuals/245472.htm * * - Intel Pentium M Processor Datasheet. * Table 5, Voltage and Current Specifications. * http://www.intel.com/design/mobile/datashts/252612.htm * * - Intel Pentium M Processor on 90 nm Process with 2-MB L2 Cache Datasheet * Table 3-4, Voltage and Current Specifications. * http://www.intel.com/design/mobile/datashts/302189.htm * * - Linux cpufreq patches, speedstep-centrino.c. * Encoding of MSR_PERF_CTL and MSR_PERF_STATUS. * http://www.codemonkey.org.uk/projects/cpufreq/cpufreq-2.4.22-pre6-1.gz *//* * cpu.c - Processor driver for Intel CPU */#include <driver.h>#include <cpu.h>#include <string.h>#include <io.h>/* #define DEBUG_CPU */#ifdef DEBUG_CPU#define cpu_dbg(x,y...) printk("%s: "x, __FUNCTION__, ##y)#else#define cpu_dbg(x,y...)#endif/* * Macro to read/write the machine specific register (MSR) */#define rdmsr(msr,val1,val2) \ __asm__ __volatile__("rdmsr" \ : "=a" (val1), "=d" (val2) \ : "c" (msr))#define wrmsr(msr,val1,val2) \ __asm__ __volatile__("wrmsr" \ : /* no outputs */ \ : "c" (msr), "a" (val1), "d" (val2))/* Status/control registers (from the IA-32 System Programming Guide). */#define MSR_PERF_STATUS 0x198#define MSR_PERF_CTL 0x199/* Register and bit for enabling SpeedStep. */#define MSR_MISC_ENABLE 0x1a0#define MSR_SS_ENABLE (1<<16)static int cpu_ioctl(device_t dev, int cmd, u_long arg);static int cpu_init(void);/* * Driver structure */struct driver cpu_drv __driver_entry = { /* name */ "Processor", /* order */ 1, /* init */ cpu_init,};static struct devio cpu_io = { /* open */ NULL, /* close */ NULL, /* read */ NULL, /* write */ NULL, /* ioctl */ cpu_ioctl, /* event */ NULL,};static device_t cpu_dev; /* Device object *//* * Frequency tables */struct fq_info { u_short mhz; u_short mv;};/* Ultra Low Voltage Intel Pentium M processor 900 MHz */static const struct fq_info pentium_m_900[] = { { 900, 1004 }, { 800, 988 }, { 600, 844 },};/* Ultra Low Voltage Intel Pentium M processor 1.00 GHz */static const struct fq_info pentium_m_1000[] = { { 1000, 1004 }, { 900, 988 }, { 800, 972 }, { 600, 844 },};/* Low Voltage Intel Pentium M processor 1.10 GHz */static const struct fq_info pentium_m_1100[] = { { 1100, 1180 }, { 1000, 1164 }, { 900, 1100 }, { 800, 1020 }, { 600, 956 },};/* Low Voltage Intel Pentium M processor 1.20 GHz */static const struct fq_info pentium_m_1200[] = { { 1200, 1180 }, { 1100, 1164 }, { 1000, 1100 }, { 900, 1020 }, { 800, 1004 }, { 600, 956 },};/* Intel Pentium M processor 1.30 GHz */static const struct fq_info pentium_m_1300[] = { { 1300, 1388 }, { 1200, 1356 }, { 1000, 1292 }, { 800, 1260 }, { 600, 956 },};/* Intel Pentium M processor 1.40 GHz */static const struct fq_info pentium_m_1400[] = { { 1400, 1484 }, { 1200, 1436 }, { 1000, 1308 }, { 800, 1180 }, { 600, 956 }};/* Intel Pentium M processor 1.50 GHz */static const struct fq_info pentium_m_1500[] = { { 1500, 1484 }, { 1400, 1452 }, { 1200, 1356 }, { 1000, 1228 }, { 800, 1116 }, { 600, 956 }};/* Intel Pentium M processor 1.60 GHz */static const struct fq_info pentium_m_1600[] = { { 1600, 1484 }, { 1400, 1420 }, { 1200, 1276 }, { 1000, 1164 }, { 800, 1036 }, { 600, 956 }};/* Intel Pentium M processor 1.70 GHz */static const struct fq_info pentium_m_1700[] = { { 1700, 1484 }, { 1400, 1308 }, { 1200, 1228 }, { 1000, 1116 }, { 800, 1004 }, { 600, 956 }};/* Intel Pentium M processor 723 1.0 GHz */static const struct fq_info pentium_m_n723[] = { { 1000, 940 }, { 900, 908 }, { 800, 876 }, { 600, 812 } };/* Intel Pentium M processor 733 1.1 GHz */static const struct fq_info pentium_m_n733[] = { { 1100, 940 }, { 1000, 924 }, { 900, 892 }, { 800, 876 }, { 600, 812 }};/* Intel Pentium M processor 753 1.2 GHz */static const struct fq_info pentium_m_n753[] = { { 1200, 940 }, { 1100, 924 }, { 1000, 908 }, { 900, 876 }, { 800, 860 }, { 600, 812 }};/* Intel Pentium M processor 738 1.4 GHz */static const struct fq_info pentium_m_n738[] = { { 1400, 1116 }, { 1300, 1116 }, { 1200, 1100 }, { 1100, 1068 }, { 1000, 1052 }, { 900, 1036 }, { 800, 1020 }, { 600, 988 }};#if 0/* Intel Pentium M processor 758 1.5 GHz */static const struct fq_info pentium_m_n758[] = { { 1500, 1116 }, { 1400, 1116 }, { 1300, 1100 }, { 1200, 1084 }, { 1100, 1068 }, { 1000, 1052 }, { 900, 1036 }, { 800, 1020 }, { 600, 988 }};#endif/* Intel Pentium M processor 715 1.5 GHz */static const struct fq_info pentium_m_n715[] = { { 1500, 1340 }, { 1200, 1228 }, { 1000, 1148 }, { 800, 1068 }, { 600, 988 }};/* Intel Pentium M processor 725 1.6 GHz */static const struct fq_info pentium_m_n725[] = { { 1600, 1340 }, { 1400, 1276 }, { 1200, 1212 }, { 1000, 1132 }, { 800, 1068 }, { 600, 988 }};/* Intel Pentium M processor 735 1.7 GHz */static const struct fq_info pentium_m_n735[] = { { 1700, 1340 }, { 1400, 1244 }, { 1200, 1180 }, { 1000, 1116 }, { 800, 1052 }, { 600, 988 }};/* Intel Pentium M processor 745 1.8 GHz */static const struct fq_info pentium_m_n745[] = { { 1800, 1340 }, { 1600, 1292 }, { 1400, 1228 }, { 1200, 1164 }, { 1000, 1116 }, { 800, 1052 }, { 600, 988 }};/* Intel Pentium M processor 755 2.0 GHz */static const struct fq_info pentium_m_n755[] = { { 2000, 1340 }, { 1800, 1292 }, { 1600, 1244 }, { 1400, 1196 }, { 1200, 1148 },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -