xref: /openbmc/google-ipmi-sys/ipmi.cpp (revision 4134c74bda1bef375e155e193bad98741912c252)
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "ipmi.hpp"
16 
17 #include "bios_setting.hpp"
18 #include "bm_instance.hpp"
19 #include "bmc_mode.hpp"
20 #include "cable.hpp"
21 #include "commands.hpp"
22 #include "cpld.hpp"
23 #include "cpu_config.hpp"
24 #include "entity_name.hpp"
25 #include "eth.hpp"
26 #include "flash_size.hpp"
27 #include "google_accel_oob.hpp"
28 #include "handler.hpp"
29 #include "host_power_off.hpp"
30 #include "linux_boot_done.hpp"
31 #include "machine_name.hpp"
32 #include "pcie_bifurcation.hpp"
33 #include "pcie_i2c.hpp"
34 #include "psu.hpp"
35 
36 #include <ipmid/api.h>
37 
38 #include <ipmid/api-types.hpp>
39 #include <ipmid/message.hpp>
40 #include <stdplus/print.hpp>
41 
42 #include <cstdint>
43 #include <cstdio>
44 #include <optional>
45 #include <span>
46 
47 namespace google
48 {
49 namespace ipmi
50 {
51 
52 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr ctx,
53                       uint8_t cmd, std::span<const uint8_t> data)
54 {
55     switch (cmd)
56     {
57         case SysGetBmcMode:
58             return getBmcMode(data, handler);
59         case SysCableCheck:
60             return cableCheck(data, handler);
61         case SysCpldVersion:
62             return cpldVersion(data, handler);
63         case SysGetEthDevice:
64             return getEthDevice(data, handler);
65         case SysPsuHardReset:
66             return psuHardReset(data, handler);
67         case SysPcieSlotCount:
68             return pcieSlotCount(data, handler);
69         case SysPcieSlotI2cBusMapping:
70             return pcieSlotI2cBusMapping(data, handler);
71         case SysEntityName:
72             return getEntityName(data, handler);
73         case SysMachineName:
74             return getMachineName(data, handler);
75         case SysPsuHardResetOnShutdown:
76             return psuHardResetOnShutdown(data, handler);
77         case SysGetFlashSize:
78             return getFlashSize(data, handler);
79         case SysHostPowerOff:
80             return hostPowerOff(data, handler);
81         case SysAccelOobDeviceCount:
82             return accelOobDeviceCount(data, handler);
83         case SysAccelOobDeviceName:
84             return accelOobDeviceName(data, handler);
85         case SysAccelOobRead:
86             return accelOobRead(data, handler);
87         case SysAccelOobWrite:
88             return accelOobWrite(data, handler);
89         case SysPCIeSlotBifurcation:
90             return pcieBifurcation(data, handler);
91         case SysLinuxBootDone:
92             return linuxBootDone(data, handler);
93         case SysGetAccelVrSettings:
94             return accelGetVrSettings(ctx, data, handler);
95         case SysSetAccelVrSettings:
96             return accelSetVrSettings(ctx, data, handler);
97         case SysGetBMInstanceProperty:
98             return getBMInstanceProperty(data, handler);
99         case SysReadBiosSetting:
100             return readBiosSetting(data, handler);
101         case SysWriteBiosSetting:
102             return writeBiosSetting(data, handler);
103         case SysGetCoreCount:
104             return getCoreCount(data, handler);
105         default:
106             stdplus::print(stderr, "Invalid subcommand: {:#x}\n", cmd);
107             return ::ipmi::responseInvalidCommand();
108     }
109 }
110 
111 } // namespace ipmi
112 } // namespace google
113