Skip to content

Commit dda426e

Browse files
committed
drivers/gfx/nvidia: Updates to NVPCF
- Add more inline docs - Add `_STA` method - Update field names to better match names from Clevo dumps/DG samples - Add fields for v2.4 (unimplemented) - Add `TGPA` field for `UPDATE_DYNAMIC_PARAMS` - Match proprietary behavior for "Set Controller Status" - Add objects for disabling boost on AC/DC - Add debug logs for unimplemented functions Change-Id: I2a8d791198e18fca6eb907e62f92143fbe1e3962 Signed-off-by: Tim Crawford <[email protected]>
1 parent 818a6f7 commit dda426e

File tree

1 file changed

+175
-82
lines changed

1 file changed

+175
-82
lines changed
Lines changed: 175 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,206 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22

33
#define NVPCF_DSM_GUID "36b49710-2483-11e7-9598-0800200c9a66"
4-
#define NVPCF_REVISION_ID 0x00000200
5-
#define NVPCF_ERROR_SUCCESS 0x0
6-
#define NVPCF_ERROR_GENERIC 0x80000001
7-
#define NVPCF_ERROR_UNSUPPORTED 0x80000002
8-
#define NVPCF_FUNC_GET_SUPPORTED 0x00000000
9-
#define NVPCF_FUNC_GET_STATIC_CONFIG_TABLES 0x00000001
10-
#define NVPCF_FUNC_UPDATE_DYNAMIC_PARAMS 0x00000002
11-
12-
Name(_HID, "NVDA0820")
13-
14-
Name(_UID, "NPCF")
15-
16-
Method(_DSM, 4, Serialized) {
17-
Printf("NVPCF _DSM")
18-
If (Arg0 == ToUUID(NVPCF_DSM_GUID)) {
19-
If (ToInteger(Arg1) == NVPCF_REVISION_ID) {
20-
Return(NPCF(Arg2, Arg3))
4+
#define NVPCF_REVISION_ID 0x200
5+
6+
#define NVPCF_ERROR_SUCCESS 0
7+
#define NVPCF_ERROR_GENERIC 0x80000001
8+
#define NVPCF_ERROR_UNSUPPORTED 0x80000002
9+
10+
#define NVPCF_FUNC_GET_SUPPORTED 0 // Required
11+
#define NVPCF_FUNC_GET_STATIC_CONFIG_TABLES 1 // Required
12+
#define NVPCF_FUNC_UPDATE_DYNAMIC_PARAMS 2 // Required
13+
#define NVPCF_FUNC_GET_WM2_TBAND_TABLES 3
14+
#define NVPCF_FUNC_GET_WM2_SL_MAP_TABLES 4
15+
#define NVPCF_FUNC_GET_WM2_DYNAMIC_PARAMS 5
16+
#define NVPCF_FUNC_CPU_CONTROL 6
17+
#define NVPCF_FUNC_GPU_INFO 7
18+
#define NVPCF_FUNC_GET_DC_SYSTEM_POWER_LIMITS_TABLE 8
19+
#define NVPCF_FUNC_CPU_TDP_CONTROL 9
20+
#define NVPCF_FUNC_GET_DC_TPP_LIMIT_PREFERENCE 10
21+
#define NVPCF_FUNC_GET_THERMAL_ZONE_STATUS 11
22+
23+
Name (DBAC, 0) // Disable GPU Boost on AC
24+
Name (DBDC, 0) // Disable GPU Boost on DC (XXX: Proprietary default disables on DC)
25+
26+
Name (_HID, "NVDA0820")
27+
Name (_UID, "NPCF")
28+
29+
Method (_STA, 0, NotSerialized)
30+
{
31+
Return (0x0F) // ACPI_STATUS_DEVICE_ALL_ON
32+
}
33+
34+
Method (_DSM, 4, Serialized)
35+
{
36+
If (Arg0 == ToUUID (NVPCF_DSM_GUID)) {
37+
Printf ("NVPCF DSM")
38+
If (ToInteger (Arg1) == NVPCF_REVISION_ID) {
39+
Return (NPCF (Arg2, Arg3))
2140
} Else {
22-
Printf(" Unsupported NVPCF revision: %o", SFST(Arg1))
23-
Return(NVPCF_ERROR_GENERIC)
41+
Printf (" NVPCF: Unsupported revision: %o", Arg1)
2442
}
25-
} Else {
26-
Printf(" Unsupported GUID: %o", IDST(Arg0))
27-
Return(NVPCF_ERROR_GENERIC)
2843
}
44+
Else {
45+
Printf (" NVPCF: Unsupported GUID: %o", IDST (Arg0))
46+
}
47+
48+
Return (NVPCF_ERROR_GENERIC)
2949
}
3050

31-
Method(NPCF, 2, Serialized) {
32-
Printf(" NVPCF NPCF")
33-
Switch(ToInteger(Arg0)) {
34-
Case(NVPCF_FUNC_GET_SUPPORTED) {
35-
Printf(" Supported Functions")
36-
Return(ITOB(
51+
Method (NPCF, 2, Serialized)
52+
{
53+
Switch (ToInteger (Arg0)) {
54+
Case (NVPCF_FUNC_GET_SUPPORTED) {
55+
Printf (" NVPCF[0]: GET_SUPPORTED")
56+
Return (ITOB (
3757
(1 << NVPCF_FUNC_GET_SUPPORTED) |
3858
(1 << NVPCF_FUNC_GET_STATIC_CONFIG_TABLES) |
3959
(1 << NVPCF_FUNC_UPDATE_DYNAMIC_PARAMS)
4060
))
4161
}
42-
Case(NVPCF_FUNC_GET_STATIC_CONFIG_TABLES) {
43-
Printf(" Get Static Config")
44-
Return(Buffer(14) {
45-
// Device table header
62+
Case (NVPCF_FUNC_GET_STATIC_CONFIG_TABLES) {
63+
Printf (" NVPCF[1]: GET_STATIC_CONFIG_TABLE")
64+
Return (Buffer (14) {
65+
// System Device Table Header (v2.0)
4666
0x20, 0x03, 0x01,
47-
// Intel + NVIDIA
67+
// System Device Table Entries
68+
// [3:0] CPU Type (0=Intel, 1=AMD)
69+
// [7:4] GPU Type (0=Nvidia)
4870
0x00,
49-
// Controller table header
71+
// System Controller Table Header (v2.3)
5072
0x23, 0x04, 0x05, 0x01,
51-
// Dynamic boost controller
52-
0x01,
53-
// Supports DC
73+
// System Controller Table Controller Entry
74+
// Controller Flags
75+
// [3:0] Controller Class Type
76+
// 0=Disabled
77+
// 1=Dynamic Boost Controller
78+
// 2=Configurable TGP-only Controller
79+
// [7:4] Reserved
5480
0x01,
55-
// Reserved
56-
0x00, 0x00, 0x00,
57-
// Checksum
81+
// Controller Params
82+
// [0:0] DC support (0=Not supported, 1=Supported)
83+
// [31:1] Reserved
84+
0x01, 0x00, 0x00, 0x00,
85+
// Single byte checksum value
5886
0xAD
5987
})
6088
}
61-
Case(NVPCF_FUNC_UPDATE_DYNAMIC_PARAMS) {
62-
Printf(" Update Dynamic Boost")
63-
64-
CreateField(Arg1, 0x28, 2, ICMD) // Input command
65-
66-
Name(PCFP, Buffer(49) {
67-
// Table version
68-
0x23,
69-
// Table header size
70-
0x05,
71-
// Size of common status in bytes
72-
0x10,
73-
// Size of controller entry in bytes
74-
0x1C,
75-
// Other fields filled in later
89+
Case (NVPCF_FUNC_UPDATE_DYNAMIC_PARAMS) {
90+
Printf (" NVPCF[2]: UPDATE_DYNAMIC_PARAMS")
91+
92+
// Dynamic Params Common Status, Input
93+
// 0=Get Controller Params
94+
// 1=Set Controller Status
95+
CreateField (Arg1, 0x28, 2, ICMD)
96+
97+
// XXX: All input params unused?
98+
// Controller Entry, Input
99+
//CreateByteField (Arg1, 0x15, IIDX) // Controller index
100+
//CreateField (Arg1, 0xB0, 0x01, PWCS) // Power control capability (0=Disabled, 1=Enabled)
101+
//CreateField (Arg1, 0xB1, 0x01, PWTS) // Power transfer status (0=Disabled, 1=Enabled)
102+
//CreateField (Arg1, 0xB2, 0x01, CGPS) // CTGP status (0=Disabled, 1=Enabled)
103+
104+
Name (PBD2, Buffer(49) {
105+
// Dynamic Params Table Header
106+
0x23, // Version 2.3
107+
0x05, // Table header size in bytes
108+
0x10, // Size of Common Status in bytes
109+
0x1C, // Size of Controller Entry in bytes
110+
0x01, // Number of Controller Entries
76111
})
77-
CreateByteField(PCFP, 0x04, CCNT) // Controller count
78-
CreateWordField(PCFP, 0x19, ATPP) // AC TPP offset
79-
CreateWordField(PCFP, 0x1D, AMXP) // AC maximum TGP offset
80-
CreateWordField(PCFP, 0x21, AMNP) // AC minimum TGP offset
81-
82-
Switch(ToInteger(ICMD)) {
83-
Case(0) {
84-
Printf(" Get Controller Params")
85-
// Number of controllers
86-
CCNT = 1
87-
// AC total processor power offset from default TGP in 1/8 watt units
88-
ATPP = (CONFIG_DRIVERS_GFX_NVIDIA_DYNAMIC_BOOST_TPP << 3)
89-
// AC maximum TGP offset from default TGP in 1/8 watt units
90-
AMXP = (CONFIG_DRIVERS_GFX_NVIDIA_DYNAMIC_BOOST_MAX << 3)
91-
// AC minimum TGP offset from default TGP in 1/8 watt units
92-
AMNP = (CONFIG_DRIVERS_GFX_NVIDIA_DYNAMIC_BOOST_MIN << 3)
93-
Printf("PCFP: %o", SFST(PCFP))
94-
Return(PCFP)
112+
113+
// Dynamic Params Common Status, Output
114+
// Baseline (configurable) TGP in AC for the intended TPP
115+
// limit, expressed as a signed offset relative to the
116+
// static TGP rates, AC, in 1/8-watt units.
117+
CreateWordField (PBD2, 0x05, TGPA)
118+
119+
// Controller Entry, Output - Dynamic Boost Controller
120+
CreateByteField (PBD2, 0x15, OIDX) // Controller index
121+
// Disable controller on AC/DC
122+
// [0:0] Disable controller on AC (0=Enable, 1=Disable)
123+
// [1:1] Disable controller on DC (0=Enable, 1=Disable)
124+
CreateByteField (PBD2, 0x16, PC02)
125+
CreateWordField (PBD2, 0x19, TPPA) // TPP target on AC
126+
CreateWordField (PBD2, 0x1D, MAGA) // Max TGP on AC
127+
CreateWordField (PBD2, 0x21, MIGA) // Min TGP on AC
128+
CreateDWordField (PBD2, 0x25, DROP) // DC Rest of system reserved power
129+
CreateDWordField (PBD2, 0x29, LTBC) // Long Timescale Battery Current Limit
130+
CreateDWordField (PBD2, 0x2D, STBC) // Short Timescale Battery Current Limit
131+
132+
Switch (ToInteger (ICMD)) {
133+
Case (0) {
134+
Printf (" Get Controller Params")
135+
136+
TGPA = 0
137+
OIDX = 0
138+
PC02 = DBAC | (DBDC << 1)
139+
TPPA = (CONFIG_DRIVERS_GFX_NVIDIA_DYNAMIC_BOOST_TPP << 3)
140+
MAGA = (CONFIG_DRIVERS_GFX_NVIDIA_DYNAMIC_BOOST_MAX << 3)
141+
MIGA = (CONFIG_DRIVERS_GFX_NVIDIA_DYNAMIC_BOOST_MIN << 3)
142+
143+
// TODO: Handle v2.3+ fields
144+
145+
Printf ("PBD2: %o", SFST(PBD2))
146+
Return (PBD2)
95147
}
96-
Case(1) {
97-
Printf(" Set Controller Status")
98-
//TODO
99-
Printf("PCFP: %o", SFST(PCFP))
100-
Return(PCFP)
148+
Case (1) {
149+
Printf (" Set Controller Status")
150+
151+
// XXX: Match proprietary firmware behavior,
152+
// which just explicitly sets fields to zero.
153+
TGPA = 0
154+
OIDX = 0
155+
PC02 = 0
156+
TPPA = 0
157+
MAGA = 0
158+
MIGA = 0
159+
160+
Printf ("PBD2: %o", SFST(PBD2))
161+
Return (PBD2)
101162
}
102163
Default {
103-
Printf(" Unknown Input Command: %o", SFST(ICMD))
104-
Return(NV_ERROR_UNSUPPORTED)
164+
Printf (" Unknown Input Command: %o", SFST(ICMD))
165+
Return (NV_ERROR_UNSUPPORTED)
105166
}
106167
}
107168
}
169+
Case (NVPCF_FUNC_GET_WM2_TBAND_TABLES) {
170+
Printf (" NVPCF[3]: GET_WM2_TBAND_TABLES")
171+
}
172+
Case (NVPCF_FUNC_GET_WM2_SL_MAP_TABLES) {
173+
Printf (" NVPCF[4]: GET_WM2_SL_MAP_TABLES")
174+
}
175+
Case (NVPCF_FUNC_GET_WM2_DYNAMIC_PARAMS) {
176+
Printf (" NVPCF[5]: GET_WM2_DYNAMIC_PARAMS")
177+
}
178+
Case (NVPCF_FUNC_CPU_CONTROL) {
179+
Printf (" NVPCF[6]: CPU_CONTROL")
180+
}
181+
Case (NVPCF_FUNC_GPU_INFO) {
182+
Printf (" NVPCF[7]: GPU_INFO")
183+
}
184+
Case (NVPCF_FUNC_GET_DC_SYSTEM_POWER_LIMITS_TABLE) {
185+
Printf (" NVPCF[8]: GET_DC_SYSTEM_POWER_LIMITS_TABLE")
186+
}
187+
Case (NVPCF_FUNC_CPU_TDP_CONTROL) {
188+
Printf (" NVPCF[9]: CPU_TDP_CONTROL")
189+
}
190+
Case (NVPCF_FUNC_GET_DC_TPP_LIMIT_PREFERENCE) {
191+
Printf (" NVPCF[10]: GET_DC_TPP_LIMIT_PREFERENCE")
192+
}
193+
Case (NVPCF_FUNC_GET_THERMAL_ZONE_STATUS) {
194+
Printf (" NVPCF[11]: GET_THERMAL_ZONE_STATUS")
195+
}
108196
Default {
109-
Printf(" Unsupported function: %o", SFST(Arg0))
110-
Return(NVPCF_ERROR_UNSUPPORTED)
197+
Printf (" NVPCF: Unknown function: %o", Arg0)
111198
}
112199
}
200+
201+
// XXX: DG says unsupported functions should return a
202+
// buffer, but even the example immediately following
203+
// this statement returns a DWORD, and this is what
204+
// proprietary firmware also does.
205+
Return (NVPCF_ERROR_UNSUPPORTED)
113206
}

0 commit comments

Comments
 (0)