1 | /* $Id: MsrSup.cpp 69584 2017-11-04 22:31:10Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * MsrSup - SupDrv-specific MSR access.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include <iprt/ctype.h>
|
---|
23 | #include <iprt/x86.h>
|
---|
24 |
|
---|
25 | #include <VBox/sup.h>
|
---|
26 | #include "VBoxCpuReport.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | /* Wrappers to mask funny SUPR3 calling conventions on some platforms. */
|
---|
30 | static int supMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue, bool *pfGp)
|
---|
31 | {
|
---|
32 | return SUPR3MsrProberRead(uMsr, idCpu, puValue, pfGp);
|
---|
33 | }
|
---|
34 |
|
---|
35 | static int supMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue, bool *pfGp)
|
---|
36 | {
|
---|
37 | return SUPR3MsrProberWrite(uMsr, idCpu, uValue, pfGp);
|
---|
38 | }
|
---|
39 |
|
---|
40 | static int supMsrProberModify(uint32_t uMsr, RTCPUID idCpu, uint64_t fAndMask, uint64_t fOrMask, PSUPMSRPROBERMODIFYRESULT pResult)
|
---|
41 | {
|
---|
42 | return SUPR3MsrProberModify(uMsr, idCpu, fAndMask, fOrMask, pResult);
|
---|
43 | }
|
---|
44 |
|
---|
45 | static int supMsrProberTerm(void)
|
---|
46 | {
|
---|
47 | return VINF_SUCCESS;
|
---|
48 | }
|
---|
49 |
|
---|
50 | int SupDrvMsrProberInit(VBMSRFNS *fnsMsr, bool *pfAtomicMsrMod)
|
---|
51 | {
|
---|
52 | int rc = SUPR3Init(NULL);
|
---|
53 | if (RT_FAILURE(rc))
|
---|
54 | {
|
---|
55 | vbCpuRepDebug("warning: Unable to initialize the support library (%Rrc).\n", rc);
|
---|
56 | return VERR_NOT_FOUND;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* Test if the MSR prober is available, since the interface is optional. The TSC MSR will exist on any supported CPU. */
|
---|
60 | uint64_t uValue;
|
---|
61 | bool fGp;
|
---|
62 | rc = SUPR3MsrProberRead(MSR_IA32_TSC, NIL_RTCPUID, &uValue, &fGp);
|
---|
63 | if (RT_FAILURE(rc))
|
---|
64 | {
|
---|
65 | vbCpuRepDebug("warning: MSR probing not supported by the support driver (%Rrc).\n", rc);
|
---|
66 | return VERR_NOT_SUPPORTED;
|
---|
67 | }
|
---|
68 |
|
---|
69 | fnsMsr->msrRead = supMsrProberRead;
|
---|
70 | fnsMsr->msrWrite = supMsrProberWrite;
|
---|
71 | fnsMsr->msrModify = supMsrProberModify;
|
---|
72 | fnsMsr->msrProberTerm = supMsrProberTerm;
|
---|
73 | *pfAtomicMsrMod = true;
|
---|
74 |
|
---|
75 | return VINF_SUCCESS;
|
---|
76 | }
|
---|