Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
Jason M. Bills | 6a2cb69 | 2019-08-06 11:03:49 -0700 | [diff] [blame] | 16 | #include <peci.h> |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 17 | #include <systemd/sd-journal.h> |
| 18 | |
Jason M. Bills | 08b2c7a | 2020-08-28 15:39:14 -0700 | [diff] [blame] | 19 | #include <boost/asio/io_service.hpp> |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 20 | #include <boost/asio/posix/stream_descriptor.hpp> |
Jason M. Bills | 08b2c7a | 2020-08-28 15:39:14 -0700 | [diff] [blame] | 21 | #include <boost/asio/steady_timer.hpp> |
Jason M. Bills | 5245ed6 | 2020-12-04 16:50:21 -0800 | [diff] [blame] | 22 | #include <error_monitors.hpp> |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 23 | #include <gpiod.hpp> |
Jason M. Bills | d711cc8 | 2020-12-04 16:46:39 -0800 | [diff] [blame] | 24 | #include <host_error_monitor.hpp> |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 25 | #include <sdbusplus/asio/object_server.hpp> |
Jason M. Bills | 48e5dff | 2020-06-10 13:47:47 -0700 | [diff] [blame] | 26 | |
| 27 | #include <bitset> |
| 28 | #include <iostream> |
Jason M. Bills | d1a19f6 | 2019-08-06 11:52:58 -0700 | [diff] [blame] | 29 | #include <variant> |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 30 | |
| 31 | namespace host_error_monitor |
| 32 | { |
| 33 | static boost::asio::io_service io; |
| 34 | static std::shared_ptr<sdbusplus::asio::connection> conn; |
| 35 | |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 36 | static std::shared_ptr<sdbusplus::asio::dbus_interface> associationSSBThermTrip; |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 37 | |
| 38 | static const constexpr char* rootPath = "/xyz/openbmc_project/CallbackManager"; |
| 39 | |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 40 | static bool hostOff = true; |
Jason M. Bills | d711cc8 | 2020-12-04 16:46:39 -0800 | [diff] [blame] | 41 | bool hostIsOff() |
| 42 | { |
| 43 | return hostOff; |
| 44 | } |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 45 | |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 46 | // GPIO Lines and Event Descriptors |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 47 | static gpiod::line cpu1VRHotLine; |
| 48 | static boost::asio::posix::stream_descriptor cpu1VRHotEvent(io); |
| 49 | static gpiod::line cpu2VRHotLine; |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 50 | static boost::asio::posix::stream_descriptor cpu1MemABCDVRHotEvent(io); |
| 51 | static gpiod::line cpu1MemEFGHVRHotLine; |
| 52 | static boost::asio::posix::stream_descriptor cpu1MemEFGHVRHotEvent(io); |
| 53 | static gpiod::line cpu2MemABCDVRHotLine; |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 54 | static boost::asio::posix::stream_descriptor cpu2VRHotEvent(io); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 55 | static gpiod::line cpu1MemABCDVRHotLine; |
| 56 | static boost::asio::posix::stream_descriptor cpu2MemABCDVRHotEvent(io); |
| 57 | static gpiod::line cpu2MemEFGHVRHotLine; |
| 58 | static boost::asio::posix::stream_descriptor cpu2MemEFGHVRHotEvent(io); |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 59 | //---------------------------------- |
| 60 | // PCH_BMC_THERMTRIP function related definition |
| 61 | //---------------------------------- |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 62 | static gpiod::line pchThermtripLine; |
| 63 | static boost::asio::posix::stream_descriptor pchThermtripEvent(io); |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 64 | //---------------------------------- |
| 65 | // CPU_MEM_THERM_EVENT function related definition |
| 66 | //---------------------------------- |
| 67 | static gpiod::line cpu1MemtripLine; |
| 68 | static boost::asio::posix::stream_descriptor cpu1MemtripEvent(io); |
| 69 | static gpiod::line cpu2MemtripLine; |
| 70 | static boost::asio::posix::stream_descriptor cpu2MemtripEvent(io); |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 71 | |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 72 | static void memThermTripLog(const int cpuNum) |
| 73 | { |
| 74 | std::string cpuNumber = "CPU " + std::to_string(cpuNum); |
| 75 | std::string msg = cpuNumber + " Memory Thermal trip."; |
| 76 | |
| 77 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 78 | LOG_ERR, "REDFISH_MESSAGE_ID=%s", |
| 79 | "OpenBMC.0.1.MemoryThermTrip", "REDFISH_MESSAGE_ARGS=%s", |
| 80 | cpuNumber.c_str(), NULL); |
| 81 | } |
| 82 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 83 | static void cpuVRHotLog(const std::string& vr) |
| 84 | { |
| 85 | std::string msg = vr + " Voltage Regulator Overheated."; |
| 86 | |
| 87 | sd_journal_send("MESSAGE=HostError: %s", msg.c_str(), "PRIORITY=%i", |
| 88 | LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 89 | "OpenBMC.0.1.VoltageRegulatorOverheated", |
| 90 | "REDFISH_MESSAGE_ARGS=%s", vr.c_str(), NULL); |
| 91 | } |
| 92 | |
Jason M. Bills | 0886654 | 2019-08-16 12:04:19 -0700 | [diff] [blame] | 93 | static void ssbThermTripLog() |
| 94 | { |
| 95 | sd_journal_send("MESSAGE=HostError: SSB thermal trip", "PRIORITY=%i", |
| 96 | LOG_INFO, "REDFISH_MESSAGE_ID=%s", |
| 97 | "OpenBMC.0.1.SsbThermalTrip", NULL); |
| 98 | } |
| 99 | |
Jason M. Bills | a15c252 | 2019-08-16 10:01:44 -0700 | [diff] [blame] | 100 | static void initializeErrorState(); |
Jason M. Bills | 5245ed6 | 2020-12-04 16:50:21 -0800 | [diff] [blame] | 101 | static void init() |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 102 | { |
Jason M. Bills | 5245ed6 | 2020-12-04 16:50:21 -0800 | [diff] [blame] | 103 | // Get the current host state to prepare to start the signal monitors |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 104 | conn->async_method_call( |
| 105 | [](boost::system::error_code ec, |
| 106 | const std::variant<std::string>& property) { |
| 107 | if (ec) |
| 108 | { |
| 109 | return; |
| 110 | } |
| 111 | const std::string* state = std::get_if<std::string>(&property); |
| 112 | if (state == nullptr) |
| 113 | { |
| 114 | std::cerr << "Unable to read host state value\n"; |
| 115 | return; |
| 116 | } |
| 117 | hostOff = *state == "xyz.openbmc_project.State.Host.HostState.Off"; |
Jason M. Bills | a15c252 | 2019-08-16 10:01:44 -0700 | [diff] [blame] | 118 | // If the system is on, initialize the error state |
| 119 | if (!hostOff) |
| 120 | { |
| 121 | initializeErrorState(); |
| 122 | } |
Jason M. Bills | 5245ed6 | 2020-12-04 16:50:21 -0800 | [diff] [blame] | 123 | |
| 124 | // Now we have the host state, start the signal monitors |
| 125 | if (!error_monitors::startMonitors(io, conn)) |
| 126 | { |
| 127 | throw std::runtime_error("Failed to start signal monitors"); |
| 128 | } |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 129 | }, |
| 130 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", |
| 131 | "org.freedesktop.DBus.Properties", "Get", |
| 132 | "xyz.openbmc_project.State.Host", "CurrentHostState"); |
| 133 | } |
| 134 | |
| 135 | static std::shared_ptr<sdbusplus::bus::match::match> startHostStateMonitor() |
| 136 | { |
| 137 | return std::make_shared<sdbusplus::bus::match::match>( |
| 138 | *conn, |
| 139 | "type='signal',interface='org.freedesktop.DBus.Properties'," |
Jason M. Bills | 2fbb9ea | 2020-06-19 14:46:54 -0700 | [diff] [blame] | 140 | "member='PropertiesChanged',arg0='xyz.openbmc_project.State.Host'", |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 141 | [](sdbusplus::message::message& msg) { |
| 142 | std::string interfaceName; |
| 143 | boost::container::flat_map<std::string, std::variant<std::string>> |
| 144 | propertiesChanged; |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 145 | try |
| 146 | { |
| 147 | msg.read(interfaceName, propertiesChanged); |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 148 | } |
| 149 | catch (std::exception& e) |
| 150 | { |
| 151 | std::cerr << "Unable to read host state\n"; |
| 152 | return; |
| 153 | } |
Jason M. Bills | 566ccc4 | 2020-06-18 16:38:26 -0700 | [diff] [blame] | 154 | // We only want to check for CurrentHostState |
| 155 | if (propertiesChanged.begin()->first != "CurrentHostState") |
| 156 | { |
| 157 | return; |
| 158 | } |
| 159 | std::string* state = |
| 160 | std::get_if<std::string>(&(propertiesChanged.begin()->second)); |
| 161 | if (state == nullptr) |
| 162 | { |
| 163 | std::cerr << propertiesChanged.begin()->first |
| 164 | << " property invalid\n"; |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | hostOff = *state == "xyz.openbmc_project.State.Host.HostState.Off"; |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 169 | |
Jason M. Bills | 8fa1c96 | 2020-12-10 14:33:56 -0800 | [diff] [blame] | 170 | if (!hostOff) |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 171 | { |
| 172 | // Handle any initial errors when the host turns on |
| 173 | initializeErrorState(); |
Jason M. Bills | 5245ed6 | 2020-12-04 16:50:21 -0800 | [diff] [blame] | 174 | error_monitors::sendHostOn(); |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 175 | } |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 176 | }); |
| 177 | } |
| 178 | |
| 179 | static bool requestGPIOEvents( |
| 180 | const std::string& name, const std::function<void()>& handler, |
| 181 | gpiod::line& gpioLine, |
| 182 | boost::asio::posix::stream_descriptor& gpioEventDescriptor) |
| 183 | { |
| 184 | // Find the GPIO line |
| 185 | gpioLine = gpiod::find_line(name); |
| 186 | if (!gpioLine) |
| 187 | { |
| 188 | std::cerr << "Failed to find the " << name << " line\n"; |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | try |
| 193 | { |
| 194 | gpioLine.request( |
| 195 | {"host-error-monitor", gpiod::line_request::EVENT_BOTH_EDGES}); |
| 196 | } |
| 197 | catch (std::exception&) |
| 198 | { |
| 199 | std::cerr << "Failed to request events for " << name << "\n"; |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | int gpioLineFd = gpioLine.event_get_fd(); |
| 204 | if (gpioLineFd < 0) |
| 205 | { |
| 206 | std::cerr << "Failed to get " << name << " fd\n"; |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | gpioEventDescriptor.assign(gpioLineFd); |
| 211 | |
| 212 | gpioEventDescriptor.async_wait( |
| 213 | boost::asio::posix::stream_descriptor::wait_read, |
| 214 | [&name, handler](const boost::system::error_code ec) { |
| 215 | if (ec) |
| 216 | { |
| 217 | std::cerr << name << " fd handler error: " << ec.message() |
| 218 | << "\n"; |
| 219 | return; |
| 220 | } |
| 221 | handler(); |
| 222 | }); |
| 223 | return true; |
| 224 | } |
| 225 | |
Jason M. Bills | 45e87e0 | 2019-09-09 14:45:38 -0700 | [diff] [blame] | 226 | static bool requestGPIOInput(const std::string& name, gpiod::line& gpioLine) |
| 227 | { |
| 228 | // Find the GPIO line |
| 229 | gpioLine = gpiod::find_line(name); |
| 230 | if (!gpioLine) |
| 231 | { |
| 232 | std::cerr << "Failed to find the " << name << " line.\n"; |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | // Request GPIO input |
| 237 | try |
| 238 | { |
| 239 | gpioLine.request({__FUNCTION__, gpiod::line_request::DIRECTION_INPUT}); |
| 240 | } |
| 241 | catch (std::exception&) |
| 242 | { |
| 243 | std::cerr << "Failed to request " << name << " input\n"; |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | return true; |
| 248 | } |
| 249 | |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 250 | static void cpu1MemtripHandler() |
| 251 | { |
Jason M. Bills | 5287c02 | 2020-05-19 11:16:09 -0700 | [diff] [blame] | 252 | gpiod::line_event gpioLineEvent = cpu1MemtripLine.event_read(); |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 253 | |
Jason M. Bills | 5287c02 | 2020-05-19 11:16:09 -0700 | [diff] [blame] | 254 | bool cpu1Memtrip = |
| 255 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 256 | if (cpu1Memtrip) |
| 257 | { |
| 258 | memThermTripLog(1); |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 259 | } |
Jason M. Bills | 5287c02 | 2020-05-19 11:16:09 -0700 | [diff] [blame] | 260 | |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 261 | cpu1MemtripEvent.async_wait( |
| 262 | boost::asio::posix::stream_descriptor::wait_read, |
| 263 | [](const boost::system::error_code ec) { |
| 264 | if (ec) |
| 265 | { |
| 266 | std::cerr << "CPU 1 Memory Thermaltrip handler error: " |
| 267 | << ec.message() << "\n"; |
| 268 | return; |
| 269 | } |
| 270 | cpu1MemtripHandler(); |
| 271 | }); |
| 272 | } |
| 273 | |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 274 | static void cpu2MemtripHandler() |
| 275 | { |
Jason M. Bills | 5287c02 | 2020-05-19 11:16:09 -0700 | [diff] [blame] | 276 | gpiod::line_event gpioLineEvent = cpu2MemtripLine.event_read(); |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 277 | |
Jason M. Bills | 5287c02 | 2020-05-19 11:16:09 -0700 | [diff] [blame] | 278 | bool cpu2Memtrip = |
| 279 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 280 | if (cpu2Memtrip) |
| 281 | { |
| 282 | memThermTripLog(2); |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 283 | } |
Jason M. Bills | 5287c02 | 2020-05-19 11:16:09 -0700 | [diff] [blame] | 284 | |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 285 | cpu2MemtripEvent.async_wait( |
| 286 | boost::asio::posix::stream_descriptor::wait_read, |
| 287 | [](const boost::system::error_code ec) { |
| 288 | if (ec) |
| 289 | { |
| 290 | std::cerr << "CPU 2 Memory Thermaltrip handler error: " |
| 291 | << ec.message() << "\n"; |
| 292 | return; |
| 293 | } |
| 294 | cpu2MemtripHandler(); |
| 295 | }); |
| 296 | } |
| 297 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 298 | static void cpu1VRHotAssertHandler() |
| 299 | { |
| 300 | cpuVRHotLog("CPU 1"); |
| 301 | } |
| 302 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 303 | static void cpu1VRHotHandler() |
| 304 | { |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 305 | gpiod::line_event gpioLineEvent = cpu1VRHotLine.event_read(); |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 306 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 307 | bool cpu1VRHot = |
| 308 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 309 | if (cpu1VRHot) |
| 310 | { |
| 311 | cpu1VRHotAssertHandler(); |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 312 | } |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 313 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 314 | cpu1VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read, |
| 315 | [](const boost::system::error_code ec) { |
| 316 | if (ec) |
| 317 | { |
| 318 | std::cerr << "CPU 1 VRHot handler error: " |
| 319 | << ec.message() << "\n"; |
| 320 | return; |
| 321 | } |
| 322 | cpu1VRHotHandler(); |
| 323 | }); |
| 324 | } |
| 325 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 326 | static void cpu1MemABCDVRHotAssertHandler() |
| 327 | { |
| 328 | cpuVRHotLog("CPU 1 Memory ABCD"); |
| 329 | } |
| 330 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 331 | static void cpu1MemABCDVRHotHandler() |
| 332 | { |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 333 | gpiod::line_event gpioLineEvent = cpu1MemABCDVRHotLine.event_read(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 334 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 335 | bool cpu1MemABCDVRHot = |
| 336 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 337 | if (cpu1MemABCDVRHot) |
| 338 | { |
| 339 | cpu1MemABCDVRHotAssertHandler(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 340 | } |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 341 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 342 | cpu1MemABCDVRHotEvent.async_wait( |
| 343 | boost::asio::posix::stream_descriptor::wait_read, |
| 344 | [](const boost::system::error_code ec) { |
| 345 | if (ec) |
| 346 | { |
| 347 | std::cerr << "CPU 1 Memory ABCD VRHot handler error: " |
| 348 | << ec.message() << "\n"; |
| 349 | return; |
| 350 | } |
| 351 | cpu1MemABCDVRHotHandler(); |
| 352 | }); |
| 353 | } |
| 354 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 355 | static void cpu1MemEFGHVRHotAssertHandler() |
| 356 | { |
| 357 | cpuVRHotLog("CPU 1 Memory EFGH"); |
| 358 | } |
| 359 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 360 | static void cpu1MemEFGHVRHotHandler() |
| 361 | { |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 362 | gpiod::line_event gpioLineEvent = cpu1MemEFGHVRHotLine.event_read(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 363 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 364 | bool cpu1MemEFGHVRHot = |
| 365 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 366 | if (cpu1MemEFGHVRHot) |
| 367 | { |
| 368 | cpu1MemEFGHVRHotAssertHandler(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 369 | } |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 370 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 371 | cpu1MemEFGHVRHotEvent.async_wait( |
| 372 | boost::asio::posix::stream_descriptor::wait_read, |
| 373 | [](const boost::system::error_code ec) { |
| 374 | if (ec) |
| 375 | { |
| 376 | std::cerr << "CPU 1 Memory EFGH VRHot handler error: " |
| 377 | << ec.message() << "\n"; |
| 378 | return; |
| 379 | } |
| 380 | cpu1MemEFGHVRHotHandler(); |
| 381 | }); |
| 382 | } |
| 383 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 384 | static void cpu2VRHotAssertHandler() |
| 385 | { |
| 386 | cpuVRHotLog("CPU 2"); |
| 387 | } |
| 388 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 389 | static void cpu2VRHotHandler() |
| 390 | { |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 391 | gpiod::line_event gpioLineEvent = cpu2VRHotLine.event_read(); |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 392 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 393 | bool cpu2VRHot = |
| 394 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 395 | if (cpu2VRHot) |
| 396 | { |
| 397 | cpu2VRHotAssertHandler(); |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 398 | } |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 399 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 400 | cpu2VRHotEvent.async_wait(boost::asio::posix::stream_descriptor::wait_read, |
| 401 | [](const boost::system::error_code ec) { |
| 402 | if (ec) |
| 403 | { |
| 404 | std::cerr << "CPU 2 VRHot handler error: " |
| 405 | << ec.message() << "\n"; |
| 406 | return; |
| 407 | } |
| 408 | cpu2VRHotHandler(); |
| 409 | }); |
| 410 | } |
| 411 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 412 | static void cpu2MemABCDVRHotAssertHandler() |
| 413 | { |
| 414 | cpuVRHotLog("CPU 2 Memory ABCD"); |
| 415 | } |
| 416 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 417 | static void cpu2MemABCDVRHotHandler() |
| 418 | { |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 419 | gpiod::line_event gpioLineEvent = cpu2MemABCDVRHotLine.event_read(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 420 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 421 | bool cpu2MemABCDVRHot = |
| 422 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 423 | if (cpu2MemABCDVRHot) |
| 424 | { |
| 425 | cpu2MemABCDVRHotAssertHandler(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 426 | } |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 427 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 428 | cpu2MemABCDVRHotEvent.async_wait( |
| 429 | boost::asio::posix::stream_descriptor::wait_read, |
| 430 | [](const boost::system::error_code ec) { |
| 431 | if (ec) |
| 432 | { |
| 433 | std::cerr << "CPU 2 Memory ABCD VRHot handler error: " |
| 434 | << ec.message() << "\n"; |
| 435 | return; |
| 436 | } |
| 437 | cpu2MemABCDVRHotHandler(); |
| 438 | }); |
| 439 | } |
| 440 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 441 | static void cpu2MemEFGHVRHotAssertHandler() |
| 442 | { |
| 443 | cpuVRHotLog("CPU 2 Memory EFGH"); |
| 444 | } |
| 445 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 446 | static void cpu2MemEFGHVRHotHandler() |
| 447 | { |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 448 | gpiod::line_event gpioLineEvent = cpu2MemEFGHVRHotLine.event_read(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 449 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 450 | bool cpu2MemEFGHVRHot = |
| 451 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 452 | if (cpu2MemEFGHVRHot) |
| 453 | { |
| 454 | cpu2MemEFGHVRHotAssertHandler(); |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 455 | } |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 456 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 457 | cpu2MemEFGHVRHotEvent.async_wait( |
| 458 | boost::asio::posix::stream_descriptor::wait_read, |
| 459 | [](const boost::system::error_code ec) { |
| 460 | if (ec) |
| 461 | { |
| 462 | std::cerr << "CPU 2 Memory EFGH VRHot handler error: " |
| 463 | << ec.message() << "\n"; |
| 464 | return; |
| 465 | } |
| 466 | cpu2MemEFGHVRHotHandler(); |
| 467 | }); |
| 468 | } |
| 469 | |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 470 | static void pchThermtripHandler() |
| 471 | { |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 472 | std::vector<Association> associations; |
| 473 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 474 | gpiod::line_event gpioLineEvent = pchThermtripLine.event_read(); |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 475 | |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 476 | bool pchThermtrip = |
| 477 | gpioLineEvent.event_type == gpiod::line_event::FALLING_EDGE; |
| 478 | if (pchThermtrip) |
| 479 | { |
| 480 | ssbThermTripLog(); |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 481 | associations.emplace_back( |
| 482 | "", "critical", |
| 483 | "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip"); |
| 484 | associations.emplace_back("", "critical", host_error_monitor::rootPath); |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 485 | } |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 486 | else |
| 487 | { |
| 488 | associations.emplace_back("", "", ""); |
| 489 | } |
| 490 | host_error_monitor::associationSSBThermTrip->set_property("Associations", |
| 491 | associations); |
Jason M. Bills | 8495114 | 2020-04-17 15:57:11 -0700 | [diff] [blame] | 492 | |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 493 | pchThermtripEvent.async_wait( |
| 494 | boost::asio::posix::stream_descriptor::wait_read, |
| 495 | [](const boost::system::error_code ec) { |
| 496 | if (ec) |
| 497 | { |
| 498 | std::cerr << "PCH Thermal trip handler error: " << ec.message() |
| 499 | << "\n"; |
| 500 | return; |
| 501 | } |
| 502 | pchThermtripHandler(); |
| 503 | }); |
| 504 | } |
| 505 | |
Jason M. Bills | a15c252 | 2019-08-16 10:01:44 -0700 | [diff] [blame] | 506 | static void initializeErrorState() |
| 507 | { |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 508 | // Handle CPU1_MEM_THERM_EVENT (CPU1 DIMM Thermal trip) if it's asserted now |
| 509 | if (cpu1MemtripLine.get_value() == 0) |
| 510 | { |
| 511 | memThermTripLog(1); |
| 512 | } |
| 513 | |
| 514 | // Handle CPU2_MEM_THERM_EVENT (CPU2 DIMM Thermal trip) if it's asserted now |
| 515 | if (cpu2MemtripLine.get_value() == 0) |
| 516 | { |
| 517 | memThermTripLog(2); |
| 518 | } |
| 519 | |
Jason M. Bills | e94f5e1 | 2019-09-13 11:11:34 -0700 | [diff] [blame] | 520 | // Handle CPU1_VRHOT if it's asserted now |
| 521 | if (cpu1VRHotLine.get_value() == 0) |
| 522 | { |
| 523 | cpu1VRHotAssertHandler(); |
| 524 | } |
| 525 | |
| 526 | // Handle CPU1_MEM_ABCD_VRHOT if it's asserted now |
| 527 | if (cpu1MemABCDVRHotLine.get_value() == 0) |
| 528 | { |
| 529 | cpu1MemABCDVRHotAssertHandler(); |
| 530 | } |
| 531 | |
| 532 | // Handle CPU1_MEM_EFGH_VRHOT if it's asserted now |
| 533 | if (cpu1MemEFGHVRHotLine.get_value() == 0) |
| 534 | { |
| 535 | cpu1MemEFGHVRHotAssertHandler(); |
| 536 | } |
| 537 | |
| 538 | // Handle CPU2_VRHOT if it's asserted now |
| 539 | if (cpu2VRHotLine.get_value() == 0) |
| 540 | { |
| 541 | cpu2VRHotAssertHandler(); |
| 542 | } |
| 543 | |
| 544 | // Handle CPU2_MEM_ABCD_VRHOT if it's asserted now |
| 545 | if (cpu2MemABCDVRHotLine.get_value() == 0) |
| 546 | { |
| 547 | cpu2MemABCDVRHotAssertHandler(); |
| 548 | } |
| 549 | |
| 550 | // Handle CPU2_MEM_EFGH_VRHOT if it's asserted now |
| 551 | if (cpu2MemEFGHVRHotLine.get_value() == 0) |
| 552 | { |
| 553 | cpu2MemEFGHVRHotAssertHandler(); |
| 554 | } |
| 555 | |
Jason M. Bills | 0886654 | 2019-08-16 12:04:19 -0700 | [diff] [blame] | 556 | // Handle PCH_BMC_THERMTRIP if it's asserted now |
| 557 | if (pchThermtripLine.get_value() == 0) |
| 558 | { |
| 559 | ssbThermTripLog(); |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 560 | std::vector<Association> associations; |
| 561 | associations.emplace_back( |
| 562 | "", "critical", |
| 563 | "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip"); |
| 564 | associations.emplace_back("", "critical", host_error_monitor::rootPath); |
| 565 | host_error_monitor::associationSSBThermTrip->set_property( |
| 566 | "Associations", associations); |
Jason M. Bills | 0886654 | 2019-08-16 12:04:19 -0700 | [diff] [blame] | 567 | } |
Jason M. Bills | a15c252 | 2019-08-16 10:01:44 -0700 | [diff] [blame] | 568 | } |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 569 | } // namespace host_error_monitor |
| 570 | |
| 571 | int main(int argc, char* argv[]) |
| 572 | { |
| 573 | // setup connection to dbus |
| 574 | host_error_monitor::conn = |
| 575 | std::make_shared<sdbusplus::asio::connection>(host_error_monitor::io); |
| 576 | |
Jason M. Bills | c4b91f2 | 2019-11-26 17:04:50 -0800 | [diff] [blame] | 577 | // Host Error Monitor Service |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 578 | host_error_monitor::conn->request_name( |
| 579 | "xyz.openbmc_project.HostErrorMonitor"); |
| 580 | sdbusplus::asio::object_server server = |
| 581 | sdbusplus::asio::object_server(host_error_monitor::conn); |
| 582 | |
Yong Li | 1429ca8 | 2020-04-27 16:49:45 +0800 | [diff] [blame] | 583 | // Associations interface for led status |
| 584 | std::vector<host_error_monitor::Association> associations; |
| 585 | associations.emplace_back("", "", ""); |
| 586 | host_error_monitor::associationSSBThermTrip = server.add_interface( |
| 587 | "/xyz/openbmc_project/host_error_monitor/ssb_thermal_trip", |
| 588 | "xyz.openbmc_project.Association.Definitions"); |
| 589 | host_error_monitor::associationSSBThermTrip->register_property( |
| 590 | "Associations", associations); |
| 591 | host_error_monitor::associationSSBThermTrip->initialize(); |
| 592 | |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 593 | // Start tracking host state |
| 594 | std::shared_ptr<sdbusplus::bus::match::match> hostStateMonitor = |
| 595 | host_error_monitor::startHostStateMonitor(); |
| 596 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 597 | // Request CPU1_VRHOT GPIO events |
| 598 | if (!host_error_monitor::requestGPIOEvents( |
| 599 | "CPU1_VRHOT", host_error_monitor::cpu1VRHotHandler, |
| 600 | host_error_monitor::cpu1VRHotLine, |
| 601 | host_error_monitor::cpu1VRHotEvent)) |
| 602 | { |
| 603 | return -1; |
| 604 | } |
| 605 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 606 | // Request CPU1_MEM_ABCD_VRHOT GPIO events |
| 607 | if (!host_error_monitor::requestGPIOEvents( |
| 608 | "CPU1_MEM_ABCD_VRHOT", host_error_monitor::cpu1MemABCDVRHotHandler, |
| 609 | host_error_monitor::cpu1MemABCDVRHotLine, |
| 610 | host_error_monitor::cpu1MemABCDVRHotEvent)) |
| 611 | { |
| 612 | return -1; |
| 613 | } |
| 614 | |
| 615 | // Request CPU1_MEM_EFGH_VRHOT GPIO events |
| 616 | if (!host_error_monitor::requestGPIOEvents( |
| 617 | "CPU1_MEM_EFGH_VRHOT", host_error_monitor::cpu1MemEFGHVRHotHandler, |
| 618 | host_error_monitor::cpu1MemEFGHVRHotLine, |
| 619 | host_error_monitor::cpu1MemEFGHVRHotEvent)) |
| 620 | { |
| 621 | return -1; |
| 622 | } |
| 623 | |
Jason M. Bills | 250fa63 | 2019-08-28 15:58:25 -0700 | [diff] [blame] | 624 | // Request CPU2_VRHOT GPIO events |
| 625 | if (!host_error_monitor::requestGPIOEvents( |
| 626 | "CPU2_VRHOT", host_error_monitor::cpu2VRHotHandler, |
| 627 | host_error_monitor::cpu2VRHotLine, |
| 628 | host_error_monitor::cpu2VRHotEvent)) |
| 629 | { |
| 630 | return -1; |
| 631 | } |
| 632 | |
Jason M. Bills | 9647ba7 | 2019-08-29 14:19:19 -0700 | [diff] [blame] | 633 | // Request CPU2_MEM_ABCD_VRHOT GPIO events |
| 634 | if (!host_error_monitor::requestGPIOEvents( |
| 635 | "CPU2_MEM_ABCD_VRHOT", host_error_monitor::cpu2MemABCDVRHotHandler, |
| 636 | host_error_monitor::cpu2MemABCDVRHotLine, |
| 637 | host_error_monitor::cpu2MemABCDVRHotEvent)) |
| 638 | { |
| 639 | return -1; |
| 640 | } |
| 641 | |
| 642 | // Request CPU2_MEM_EFGH_VRHOT GPIO events |
| 643 | if (!host_error_monitor::requestGPIOEvents( |
| 644 | "CPU2_MEM_EFGH_VRHOT", host_error_monitor::cpu2MemEFGHVRHotHandler, |
| 645 | host_error_monitor::cpu2MemEFGHVRHotLine, |
| 646 | host_error_monitor::cpu2MemEFGHVRHotEvent)) |
| 647 | { |
| 648 | return -1; |
| 649 | } |
| 650 | |
Chen Yugang | e6c0f1c | 2019-08-02 20:36:42 +0800 | [diff] [blame] | 651 | // Request PCH_BMC_THERMTRIP GPIO events |
| 652 | if (!host_error_monitor::requestGPIOEvents( |
| 653 | "PCH_BMC_THERMTRIP", host_error_monitor::pchThermtripHandler, |
| 654 | host_error_monitor::pchThermtripLine, |
| 655 | host_error_monitor::pchThermtripEvent)) |
| 656 | { |
| 657 | return -1; |
| 658 | } |
| 659 | |
jayaprakash Mutyala | 009adbc | 2019-12-24 22:08:07 +0000 | [diff] [blame] | 660 | // Request CPU1_MEM_THERM_EVENT GPIO events |
| 661 | if (!host_error_monitor::requestGPIOEvents( |
| 662 | "CPU1_MEM_THERM_EVENT", host_error_monitor::cpu1MemtripHandler, |
| 663 | host_error_monitor::cpu1MemtripLine, |
| 664 | host_error_monitor::cpu1MemtripEvent)) |
| 665 | { |
| 666 | return -1; |
| 667 | } |
| 668 | |
| 669 | // Request CPU2_MEM_THERM_EVENT GPIO events |
| 670 | if (!host_error_monitor::requestGPIOEvents( |
| 671 | "CPU2_MEM_THERM_EVENT", host_error_monitor::cpu2MemtripHandler, |
| 672 | host_error_monitor::cpu2MemtripLine, |
| 673 | host_error_monitor::cpu2MemtripEvent)) |
| 674 | { |
| 675 | return -1; |
| 676 | } |
| 677 | |
Jason M. Bills | 5245ed6 | 2020-12-04 16:50:21 -0800 | [diff] [blame] | 678 | // Initialize the signal monitors |
| 679 | host_error_monitor::init(); |
| 680 | |
Jason M. Bills | 1490b14 | 2019-07-01 15:48:43 -0700 | [diff] [blame] | 681 | host_error_monitor::io.run(); |
| 682 | |
| 683 | return 0; |
| 684 | } |