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
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
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
|
|
|
|
* in nano_private.h and have the format: IA32_XXX_MSR
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2015-11-07 02:55:47 +08:00
|
|
|
void _MsrWrite(unsigned int msr, uint64_t msr_data)
|
|
|
|
{
|
|
|
|
__asm__ volatile (
|
|
|
|
"movl %[msr], %%ecx\n\t"
|
|
|
|
"movl %[data_lo], %%eax\n\t"
|
|
|
|
"movl %[data_hi], %%edx\n\t"
|
|
|
|
"wrmsr"
|
|
|
|
:
|
|
|
|
: [msr] "m" (msr),
|
|
|
|
[data_lo] "rm" ((uint32_t)(msr_data & 0xFFFFFFFF)),
|
|
|
|
[data_hi] "rm" ((uint32_t)(msr_data >> 32))
|
|
|
|
: "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
|
|
|
|
* in nano_private.h and have the format: IA32_XXX_MSR
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2015-11-07 02:55:47 +08:00
|
|
|
uint64_t _MsrRead(unsigned int msr)
|
|
|
|
{
|
|
|
|
uint64_t ret;
|
|
|
|
|
|
|
|
__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;
|
|
|
|
}
|