summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/arch/x86_64/include/ipxe/msr.h
blob: a5816ac35461a99d66313a055c964191a8eb701a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef _IPXE_MSR_H
#define _IPXE_MSR_H

/** @file
 *
 * Model-specific registers
 *
 */

FILE_LICENCE ( GPL2_OR_LATER );

/**
 * Read model-specific register
 *
 * @v msr		Model-specific register
 * @ret value		Value
 */
static inline __attribute__ (( always_inline )) uint64_t
rdmsr ( unsigned int msr ) {
	uint32_t high;
	uint32_t low;

	__asm__ __volatile__ ( "rdmsr" :
			       "=d" ( high ), "=a" ( low ) : "c" ( msr ) );
	return ( ( ( ( uint64_t ) high ) << 32 ) | low );
}

/**
 * Write model-specific register
 *
 * @v msr		Model-specific register
 * @v value		Value
 */
static inline __attribute__ (( always_inline )) void
wrmsr ( unsigned int msr, uint64_t value ) {
	uint32_t high = ( value >> 32 );
	uint32_t low = ( value >> 0 );

	__asm__ __volatile__ ( "wrmsr" : :
			       "c" ( msr ), "d" ( high ), "a" ( low ) );
}

#endif /* _IPXE_MSR_H */