Vishwanatha Subbanna | 2180b2d | 2017-06-28 14:05:57 +0530 | [diff] [blame] | 1 | #include "config.h" |
Deepak Kodihalli | 92a6341 | 2017-03-17 05:01:00 -0500 | [diff] [blame] | 2 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include "occ_events.hpp" |
| 4 | #include "occ_manager.hpp" |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 5 | #include "powermode.hpp" |
Sheldon Bailey | 16a5adb | 2025-06-10 14:10:06 -0500 | [diff] [blame] | 6 | #include "utils.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | |
| 8 | #include <org/open_power/OCC/Device/error.hpp> |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
Chris Cain | ffb6321 | 2025-08-01 14:39:38 -0500 | [diff] [blame] | 10 | #include <sdeventplus/source/signal.hpp> |
| 11 | #include <stdplus/signal.hpp> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Common/error.hpp> |
| 13 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 14 | using namespace sdbusplus::org::open_power::OCC::Device::Error; |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 15 | using InternalFailure = |
| 16 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 17 | |
George Liu | d0345ae | 2021-09-10 13:13:28 +0800 | [diff] [blame] | 18 | int main(int /*argc*/, char** /*argv[]*/) |
Deepak Kodihalli | 92a6341 | 2017-03-17 05:01:00 -0500 | [diff] [blame] | 19 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 20 | auto& bus = open_power::occ::utils::getBus(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 21 | |
| 22 | // Need sd_event to watch for OCC device errors |
| 23 | sd_event* event = nullptr; |
| 24 | auto r = sd_event_default(&event); |
| 25 | if (r < 0) |
Deepak Kodihalli | 92a6341 | 2017-03-17 05:01:00 -0500 | [diff] [blame] | 26 | { |
Chris Cain | 37abe9b | 2024-10-31 17:20:31 -0500 | [diff] [blame] | 27 | lg2::error("Error creating a default sd_event handler"); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 28 | return r; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 29 | } |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 30 | open_power::occ::EventPtr eventP{event}; |
| 31 | event = nullptr; |
| 32 | |
| 33 | // Attach the bus to sd_event to service user requests |
| 34 | bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); |
| 35 | |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 36 | // Add object manager interfaces (for mapper) |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 37 | sdbusplus::server::manager_t objManager(bus, OCC_CONTROL_ROOT); |
Sheldon Bailey | 16a5adb | 2025-06-10 14:10:06 -0500 | [diff] [blame] | 38 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 39 | sdbusplus::server::manager_t objManagerXyz(bus, OCC_SENSORS_ROOT); |
Sheldon Bailey | 16a5adb | 2025-06-10 14:10:06 -0500 | [diff] [blame] | 40 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 41 | sdbusplus::server::manager_t objManagerXyzControl( |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 42 | bus, "/xyz/openbmc_project/control"); |
Sheldon Bailey | 16a5adb | 2025-06-10 14:10:06 -0500 | [diff] [blame] | 43 | |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 44 | sdbusplus::server::manager_t objManagerXyzInventory( |
| 45 | bus, "/xyz/openbmc_project/inventory"); |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 46 | open_power::occ::Manager mgr(eventP); |
Chris Cain | 720a384 | 2025-01-09 10:23:36 -0600 | [diff] [blame] | 47 | mgr.createPldmHandle(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 48 | |
Chris Cain | ffb6321 | 2025-08-01 14:39:38 -0500 | [diff] [blame] | 49 | try |
| 50 | { |
| 51 | // Enable SIGUSR1 handling to collect data on dump request |
| 52 | stdplus::signal::block(SIGUSR1); |
| 53 | sdeventplus::source::Signal sigUsr1( |
| 54 | eventP.get(), SIGUSR1, |
| 55 | std::bind(&open_power::occ::Manager::collectDumpData, &mgr, |
| 56 | std::placeholders::_1, std::placeholders::_2)); |
| 57 | sigUsr1.set_floating(true); |
| 58 | lg2::info("USR1 signal handler enabled"); |
| 59 | } |
| 60 | catch (const std::exception& e) |
| 61 | { |
| 62 | lg2::error("Failed to enable SIGUSR1 handler: {ERR}", "ERR", e.what()); |
| 63 | } |
| 64 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 65 | // Claim the bus since all the house keeping is done now |
| 66 | bus.request_name(OCC_CONTROL_BUSNAME); |
| 67 | |
| 68 | // Wait for requests |
| 69 | sd_event_loop(eventP.get()); |
Deepak Kodihalli | 92a6341 | 2017-03-17 05:01:00 -0500 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |