2015-04-11 07:44:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011-2014 Wind River Systems, Inc.
|
2015-11-07 02:55:47 +08:00
|
|
|
* Copyright (c) 2015 Intel Corporation
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-11-07 02:55:47 +08:00
|
|
|
/**
|
|
|
|
* @file Utilities to read/write the Model Specific Registers (MSRs)
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-11-07 02:55:47 +08:00
|
|
|
#include <zephyr.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Write to a model specific register (MSR)
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This function is used to write to an MSR.
|
|
|
|
*
|
|
|
|
* The definitions of the so-called "Architectural MSRs" are contained
|
2016-11-08 23:36:50 +08:00
|
|
|
* in kernel_structs.h and have the format: IA32_XXX_MSR
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* INTERNAL
|
|
|
|
* 1) The 'wrmsr' instruction was introduced in the Pentium processor; executing
|
|
|
|
* this instruction on an earlier IA-32 processor will result in an invalid
|
|
|
|
* opcode exception.
|
|
|
|
* 2) The 'wrmsr' uses the ECX, EDX, and EAX registers which matches the set of
|
2015-08-23 06:41:06 +08:00
|
|
|
* volatile registers!
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2017-04-21 02:30:33 +08:00
|
|
|
void _MsrWrite(unsigned int msr, u64_t msr_data)
|
2015-11-07 02:55:47 +08:00
|
|
|
{
|
|
|
|
__asm__ volatile (
|
|
|
|
"movl %[msr], %%ecx\n\t"
|
|
|
|
"movl %[data_lo], %%eax\n\t"
|
|
|
|
"movl %[data_hi], %%edx\n\t"
|
|
|
|
"wrmsr"
|
|
|
|
:
|
|
|
|
: [msr] "m" (msr),
|
2017-04-21 02:30:33 +08:00
|
|
|
[data_lo] "rm" ((u32_t)(msr_data & 0xFFFFFFFF)),
|
|
|
|
[data_hi] "rm" ((u32_t)(msr_data >> 32))
|
2015-11-07 02:55:47 +08:00
|
|
|
: "eax", "ecx", "edx");
|
|
|
|
}
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Read from a model specific register (MSR)
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This function is used to read from an MSR.
|
|
|
|
*
|
|
|
|
* The definitions of the so-called "Architectural MSRs" are contained
|
2016-11-08 23:36:50 +08:00
|
|
|
* in kernel_structs.h and have the format: IA32_XXX_MSR
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* INTERNAL
|
|
|
|
* 1) The 'rdmsr' instruction was introduced in the Pentium processor; executing
|
|
|
|
* this instruction on an earlier IA-32 processor will result in an invalid
|
|
|
|
* opcode exception.
|
|
|
|
* 2) The 'rdmsr' uses the ECX, EDX, and EAX registers which matches the set of
|
2015-08-23 06:41:06 +08:00
|
|
|
* volatile registers!
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2017-04-21 02:30:33 +08:00
|
|
|
u64_t _MsrRead(unsigned int msr)
|
2015-11-07 02:55:47 +08:00
|
|
|
{
|
2017-04-21 02:30:33 +08:00
|
|
|
u64_t ret;
|
2015-11-07 02:55:47 +08:00
|
|
|
|
|
|
|
__asm__ volatile (
|
|
|
|
"movl %[msr], %%ecx\n\t"
|
|
|
|
"rdmsr"
|
|
|
|
: "=A" (ret)
|
|
|
|
: [msr] "rm" (msr)
|
|
|
|
: "ecx");
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-11-07 02:55:47 +08:00
|
|
|
return ret;
|
|
|
|
}
|