-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmc.h
150 lines (132 loc) · 3.96 KB
/
smc.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (C) 2022 Ömürcan Cengiz
* The source code does not belong to me. I only edited, added,
* modified, enchanged the codes in a way that I need. You can find the
* sources on README.md.
=================================================================
* Apple System Management Control (SMC) Tool
* Copyright (C) 2006 devnull
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdint.h>
#include <mach/kern_return.h>
#include <MacTypes.h>
#define VERSION "0.01"
#define KERNEL_INDEX_SMC 2
#define SMC_CMD_READ_BYTES 5
#define SMC_CMD_WRITE_BYTES 6
#define SMC_CMD_READ_INDEX 8
#define SMC_CMD_READ_KEYINFO 9
#define SMC_CMD_READ_PLIMIT 11
#define SMC_CMD_READ_VERS 12
#define DATATYPE_UINT8 "ui8 "
#define DATATYPE_UINT16 "ui16"
#define DATATYPE_UINT32 "ui32"
#define DATATYPE_SP1E "sp1e"
#define DATATYPE_SP3C "sp3c"
#define DATATYPE_SP4B "sp4b"
#define DATATYPE_SP5A "sp5a"
#define DATATYPE_SP69 "sp669"
#define DATATYPE_SP78 "sp78"
#define DATATYPE_SP87 "sp87"
#define DATATYPE_SP96 "sp96"
#define DATATYPE_SPB4 "spb4"
#define DATATYPE_SPF0 "spf0"
#define DATATYPE_FLT "flt "
#define DATATYPE_FP1F "fp1f"
#define DATATYPE_FPE2 "fpe2"
#define DATATYPE_FP2E "fp2e"
#define DATATYPE_FP4C "fp4c"
#define DATATYPE_FPC4 "fpc4"
#define DATATYPE_CH8 "ch8*"
#define DATATYPE_FDS "{fds"
#define SMC_KEY_CPU_TEMP "TC0P"
// int value is % with
#define SMC_KEY_CPU_CORE_TEMP "TC1C"
#define SMC_KEY_GPU_TEMP "TG0P"
#define SMC_KEY_FAN_COUNT "FNum"
#define SMC_KEY_FAN0_RPM_CUR "F0Ac"
#define SMC_KEY_FAN0_RPM_MIN "F0Mn"
#define SMC_KEY_FAN0_RPM_MAX "F0Mx"
#define SMC_KEY_FAN1_RPM_CUR "F1Ac"
#define SMC_KEY_FAN1_RPM_MIN "F1Mn"
#define SMC_KEY_FAN1_RPM_MAX "F1Mx"
#define SMC_KEY_FAN_TS "F0Tg"
#define SMC_KEY_FAN_POS "F0ID"
// Apple Silicon
#define SMC_KEY_BATTERY_1_TEMP "TB1T"
#define SMC_KEY_BATTERY_2_TEMP "TB2T"
// m1,m1 pro,m1 max, m1 ultra
#define SMC_KEY_CPU_ECORE_1_TEMP_M1 "Tp09"
#define SMC_KEY_CPU_ECORE_2_TEMP_M1 "Tp0T"
#define SMC_KEY_CPU_PCORE_1_TEMP_M1 "Tp01"
#define SMC_KEY_CPU_PCORE_2_TEMP_M1 "Tp05"
#define SMC_KEY_CPU_PCORE_3_TEMP_M1 "Tp0D"
#define SMC_KEY_CPU_PCORE_4_TEMP_M1 "Tp0H"
#define SMC_KEY_CPU_PCORE_5_TEMP_M1 "Tp0L"
#define SMC_KEY_CPU_PCORE_6_TEMP_M1 "Tp0P"
#define SMC_KEY_CPU_PCORE_7_TEMP_M1 "Tp0X"
#define SMC_KEY_CPU_PCORE_8_TEMP_M1 "Tp0b"
#define SMC_KEY_GPU_1_TEMP_M1 "Tg05"
#define SMC_KEY_GPU_2_TEMP_M1 "Tg0D"
#define SMC_KEY_GPU_3_TEMP_M1 "Tg0L"
#define SMC_KEY_GPU_4_TEMP_M1 "Tg0T"
typedef struct
{
char major;
char minor;
char build;
char reserved[1];
UInt16 release;
} SMCKeyData_vers_t;
typedef struct
{
UInt16 version;
UInt16 length;
UInt32 cpuPLimit;
UInt32 gpuPLimit;
UInt32 memPLimit;
} SMCKeyData_pLimitData_t;
typedef struct
{
UInt32 dataSize;
UInt32 dataType;
char dataAttributes;
} SMCKeyData_keyInfo_t;
typedef char SMCBytes_t[32];
typedef struct
{
UInt32 key;
SMCKeyData_vers_t vers;
SMCKeyData_pLimitData_t pLimitData;
SMCKeyData_keyInfo_t keyInfo;
char result;
char status;
char data8;
UInt32 data32;
SMCBytes_t bytes;
} SMCKeyData_t;
typedef char UInt32Char_t[5];
typedef struct
{
UInt32Char_t key;
UInt32 dataSize;
UInt32Char_t dataType;
SMCBytes_t bytes;
} SMCVal_t;
// prototypes
double SMCGetTemperature(char *key);
// kern_return_t SMCSetFanRpm(char *key, int rpm);
kern_return_t SMCOpen(void);
void readAndPrintFanRPMs(void);