forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_set_acpi_power_state.go
127 lines (110 loc) · 3.46 KB
/
cmd_set_acpi_power_state.go
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
package ipmi
// 20.6 Set ACPI Power State Command
type SetACPIPowerStateRequest struct {
SetSystemPowerState bool // false means don't change system power state
SystemPowerState SystemPowerState
SetDevicePowerState bool // false means don't change device power state
DevicePowerState DevicePowerState
}
type SetACPIPowerStateResponse struct {
// empty
}
// see: https://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface#Global_states
type SystemPowerState uint8
const (
SystemPowerStateS0G0 uint8 = 0x00
SystemPowerStateS1 uint8 = 0x01
SystemPowerStateS2 uint8 = 0x02
SystemPowerStateS3 uint8 = 0x03
SystemPowerStateS4 uint8 = 0x04
SystemPowerStateS5G2 uint8 = 0x05
SystemPowerStateS4S5 uint8 = 0x06
SystemPowerStateG3 uint8 = 0x07
SystemPowerStateSleeping uint8 = 0x08
SystemPowerStateG1Sleeping uint8 = 0x09
SystemPowerStateOverride uint8 = 0x0a
SystemPowerStateLegacyOn uint8 = 0x20
SystemPowerStateLegacyOff uint8 = 0x21
SystemPowerStateUnknown uint8 = 0x2a
SystemPowerStateNoChange uint8 = 0x7f
)
func (s SystemPowerState) String() string {
m := map[SystemPowerState]string{
0x00: "S0/G0, working",
0x01: "S1, hardware context maintained, typically equates to processor/chip set clocks stopped",
0x02: "S2, typically equates to stopped clocks with processor/cache context lost",
0x03: "S3, typically equates to suspend-to-RAM",
0x04: "S4, typically equates to suspend-to-disk",
0x05: "S5/G2, soft off",
0x06: "S4/S5, sent when message source canno differentiate between S4 and S5",
0x07: "G3, mechanical off",
0x08: "sleeping, sleeping - cannot differentiate between S1-S3",
0x09: "G1 sleeping, sleeping - cannot differentiate between S1-S4",
0x0a: "override, S5 entered by override",
0x20: "Legacy On, Legacy On (indicates On for system that don't support ACPI or have ACPI capabilities disabled)",
0x21: "Legacy Soft-Off",
0x2a: "Unknown, system power state unknown",
0x7f: "No Chagne",
}
o, ok := m[s]
if ok {
return o
}
return ""
}
type DevicePowerState uint8
const (
DevicePowerStateD0 uint8 = 0x00
DevicePowerStateD1 uint8 = 0x01
DevicePowerStateD2 uint8 = 0x02
DevicePowerStateD3 uint8 = 0x03
DevicePowerStateUnknown uint8 = 0x2a
DevicePowerStateNoChange uint8 = 0x7f
)
func (s DevicePowerState) String() string {
m := map[DevicePowerState]string{
0x00: "D0",
0x01: "D1",
0x02: "D2",
0x03: "D2",
0x2a: "Unknown",
0x7f: "No Change",
}
o, ok := m[s]
if ok {
return o
}
return ""
}
func (req *SetACPIPowerStateRequest) Pack() []byte {
out := make([]byte, 2)
var b1 = uint8(req.SystemPowerState)
if req.SetSystemPowerState {
b1 |= 0x80
}
packUint8(b1, out, 0)
var b2 = uint8(req.DevicePowerState)
if req.SetDevicePowerState {
b2 |= 0x80
}
packUint8(b2, out, 1)
return out
}
func (req *SetACPIPowerStateRequest) Command() Command {
return CommandSetACPIPowerState
}
func (res *SetACPIPowerStateResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *SetACPIPowerStateResponse) Unpack(msg []byte) error {
return nil
}
func (res *SetACPIPowerStateResponse) Format() string {
return ""
}
// This command is provided to allow system software to tell a controller the present ACPI power state of the system.
func (c *Client) SetACPIPowerState(request *SetACPIPowerStateRequest) (err error) {
response := &SetACPIPowerStateResponse{}
err = c.Exchange(request, response)
return
}