blob: 93a0e47106537fa4a255d73e0317965e1be2fc54 [file] [log] [blame]
Matt Spinlerc8705e22019-09-11 12:36:07 -05001#pragma once
2
Matt Spinler2a28c932020-02-03 14:23:40 -06003#include "dbus_types.hpp"
4#include "dbus_watcher.hpp"
5
Matt Spinlera167a7d2023-06-30 15:14:25 -05006#include <phosphor-logging/lg2.hpp>
Matt Spinlerc8705e22019-09-11 12:36:07 -05007#include <sdbusplus/bus.hpp>
8#include <sdbusplus/bus/match.hpp>
9
Arya K Padmand8ae6182024-07-19 06:25:10 -050010#include <expected>
Patrick Williams2544b412022-10-04 08:41:06 -050011#include <filesystem>
12#include <fstream>
Arya K Padmand8ae6182024-07-19 06:25:10 -050013#include <unordered_map>
Patrick Williams2544b412022-10-04 08:41:06 -050014
Matt Spinlerc8705e22019-09-11 12:36:07 -050015namespace openpower
16{
17namespace pels
18{
19
Matt Spinlerc8705e22019-09-11 12:36:07 -050020/**
21 * @class DataInterface
22 *
Matt Spinler19e89ce2019-11-06 13:02:23 -060023 * A base class for gathering data about the system for use
24 * in PELs. Implemented this way to facilitate mocking.
Matt Spinlerc8705e22019-09-11 12:36:07 -050025 */
26class DataInterfaceBase
27{
28 public:
29 DataInterfaceBase() = default;
30 virtual ~DataInterfaceBase() = default;
31 DataInterfaceBase(const DataInterfaceBase&) = default;
32 DataInterfaceBase& operator=(const DataInterfaceBase&) = default;
33 DataInterfaceBase(DataInterfaceBase&&) = default;
34 DataInterfaceBase& operator=(DataInterfaceBase&&) = default;
35
36 /**
Matt Spinler19e89ce2019-11-06 13:02:23 -060037 * @brief Returns the machine Type/Model
Matt Spinlerc8705e22019-09-11 12:36:07 -050038 *
39 * @return string - The machine Type/Model string
40 */
Vijay Lobo81b4dca2021-04-29 00:04:00 -050041 virtual std::string getMachineTypeModel() const = 0;
Matt Spinlerc8705e22019-09-11 12:36:07 -050042
43 /**
Matt Spinler19e89ce2019-11-06 13:02:23 -060044 * @brief Returns the machine serial number
Matt Spinlerc8705e22019-09-11 12:36:07 -050045 *
46 * @return string - The machine serial number
47 */
Vijay Lobo81b4dca2021-04-29 00:04:00 -050048 virtual std::string getMachineSerialNumber() const = 0;
Matt Spinler19e89ce2019-11-06 13:02:23 -060049
Matt Spinlera7d9d962019-11-06 15:01:25 -060050 /**
Matt Spinlercce14112019-12-11 14:20:36 -060051 * @brief Says if the system is managed by a hardware
52 * management console.
53 * @return bool - If the system is HMC managed
54 */
55 virtual bool isHMCManaged() const
56 {
57 return _hmcManaged;
58 }
59
60 /**
Matt Spinlera7d9d962019-11-06 15:01:25 -060061 * @brief Says if the host is up and running
62 *
63 * @return bool - If the host is running
64 */
65 virtual bool isHostUp() const
66 {
67 return _hostUp;
68 }
69
70 using HostStateChangeFunc = std::function<void(bool)>;
71
72 /**
73 * @brief Register a callback function that will get
74 * called on all host on/off transitions.
75 *
76 * The void(bool) function will get passed the new
77 * value of the host state.
78 *
79 * @param[in] name - The subscription name
80 * @param[in] func - The function to run
81 */
82 void subscribeToHostStateChange(const std::string& name,
83 HostStateChangeFunc func)
84 {
85 _hostChangeCallbacks[name] = func;
86 }
87
88 /**
89 * @brief Unsubscribe from host state changes.
90 *
91 * @param[in] name - The subscription name
92 */
93 void unsubscribeFromHostStateChange(const std::string& name)
94 {
95 _hostChangeCallbacks.erase(name);
96 }
97
Matt Spinler5b423652023-05-04 13:08:44 -050098 using FRUPresentFunc =
99 std::function<void(const std::string& /* locationCode */)>;
100
101 /**
102 * @brief Register a callback function that will get
103 * called when certain FRUs become present.
104 *
105 * The void(std::string) function will get passed the
106 * location code of the FRU.
107 *
108 * @param[in] name - The subscription name
109 * @param[in] func - The function to run
110 */
111 void subscribeToFruPresent(const std::string& name, FRUPresentFunc func)
112 {
113 _fruPresentCallbacks[name] = std::move(func);
114 }
115
Matt Spinlercad9c2b2019-12-02 15:42:01 -0600116 /**
117 * @brief Returns the BMC firmware version
118 *
119 * @return std::string - The BMC version
120 */
121 virtual std::string getBMCFWVersion() const
122 {
123 return _bmcFWVersion;
124 }
125
126 /**
127 * @brief Returns the server firmware version
128 *
129 * @return std::string - The server firmware version
130 */
131 virtual std::string getServerFWVersion() const
132 {
133 return _serverFWVersion;
134 }
135
Matt Spinler4dcd3f42020-01-22 14:55:07 -0600136 /**
Matt Spinler677381b2020-01-23 10:04:29 -0600137 * @brief Returns the BMC FW version ID
138 *
139 * @return std::string - The BMC FW version ID
140 */
141 virtual std::string getBMCFWVersionID() const
142 {
143 return _bmcFWVersionID;
144 }
145
146 /**
Matt Spinler4dcd3f42020-01-22 14:55:07 -0600147 * @brief Returns the process name given its PID.
148 *
149 * @param[in] pid - The PID value as a string
150 *
151 * @return std::optional<std::string> - The name, or std::nullopt
152 */
153 std::optional<std::string> getProcessName(const std::string& pid) const
154 {
155 namespace fs = std::filesystem;
156
157 fs::path path{"/proc"};
158 path /= fs::path{pid} / "exe";
159
160 if (fs::exists(path))
161 {
162 return fs::read_symlink(path);
163 }
164
165 return std::nullopt;
166 }
167
Matt Spinler9cf3cfd2020-02-03 14:41:55 -0600168 /**
George Liu9ac0d9b2022-07-15 10:57:38 +0800169 * @brief Returns the time the system was running.
170 *
171 * @return std::optional<uint64_t> - The System uptime or std::nullopt
172 */
173 std::optional<uint64_t> getUptimeInSeconds() const
174 {
175 std::ifstream versionFile{"/proc/uptime"};
176 std::string line{};
177
178 std::getline(versionFile, line);
179 auto pos = line.find(" ");
180 if (pos == std::string::npos)
181 {
182 return std::nullopt;
183 }
184
185 uint64_t seconds = atol(line.substr(0, pos).c_str());
186 if (seconds == 0)
187 {
188 return std::nullopt;
189 }
190
191 return seconds;
192 }
193
194 /**
195 * @brief Returns the time the system was running.
196 *
197 * @param[in] seconds - The number of seconds the system has been running
198 *
199 * @return std::string - days/hours/minutes/seconds
200 */
201 std::string getBMCUptime(uint64_t seconds) const
202 {
203 time_t t(seconds);
204 tm* p = gmtime(&t);
205
Patrick Williams075c7922024-08-16 15:19:49 -0400206 std::string uptime =
207 std::to_string(p->tm_year - 70) + "y " +
208 std::to_string(p->tm_yday) + "d " + std::to_string(p->tm_hour) +
209 "h " + std::to_string(p->tm_min) + "m " +
210 std::to_string(p->tm_sec) + "s";
George Liu9ac0d9b2022-07-15 10:57:38 +0800211
212 return uptime;
213 }
214
215 /**
216 * @brief Returns the system load average over the past 1 minute, 5 minutes
217 * and 15 minutes.
218 *
219 * @return std::string - The system load average
220 */
221 std::string getBMCLoadAvg() const
222 {
223 std::string loadavg{};
224
225 std::ifstream loadavgFile{"/proc/loadavg"};
226 std::string line;
227 std::getline(loadavgFile, line);
228
229 size_t count = 3;
230 for (size_t i = 0; i < count; i++)
231 {
232 auto pos = line.find(" ");
233 if (pos == std::string::npos)
234 {
235 return {};
236 }
237
238 if (i != count - 1)
239 {
240 loadavg.append(line.substr(0, pos + 1));
241 }
242 else
243 {
244 loadavg.append(line.substr(0, pos));
245 }
246
247 line = line.substr(pos + 1);
248 }
249
250 return loadavg;
251 }
252
253 /**
Matt Spinler9cf3cfd2020-02-03 14:41:55 -0600254 * @brief Returns the 'send event logs to host' setting.
255 *
256 * @return bool - If sending PELs to the host is enabled.
257 */
258 virtual bool getHostPELEnablement() const
259 {
260 return _sendPELsToHost;
261 }
262
Matt Spinler4aa23a12020-02-03 15:05:09 -0600263 /**
264 * @brief Returns the BMC state
265 *
266 * @return std::string - The BMC state property value
267 */
268 virtual std::string getBMCState() const
269 {
270 return _bmcState;
271 }
272
273 /**
274 * @brief Returns the Chassis state
275 *
276 * @return std::string - The chassis state property value
277 */
278 virtual std::string getChassisState() const
279 {
280 return _chassisState;
281 }
282
283 /**
284 * @brief Returns the chassis requested power
285 * transition value.
286 *
287 * @return std::string - The chassis transition property
288 */
289 virtual std::string getChassisTransition() const
290 {
291 return _chassisTransition;
292 }
293
294 /**
295 * @brief Returns the Host state
296 *
297 * @return std::string - The Host state property value
298 */
299 virtual std::string getHostState() const
300 {
301 return _hostState;
302 }
303
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600304 /**
Sumit Kumar2c36fdd2021-09-21 03:12:11 -0500305 * @brief Returns the Boot state
306 *
307 * @return std::string - The Boot state property value
308 */
309 virtual std::string getBootState() const
310 {
311 return _bootState;
312 }
313
314 /**
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600315 * @brief Returns the motherboard CCIN
316 *
317 * @return std::string The motherboard CCIN
318 */
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500319 virtual std::string getMotherboardCCIN() const = 0;
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600320
Matt Spinler60c4e792020-03-13 13:45:36 -0500321 /**
Ben Tynere32b7e72021-05-18 12:38:40 -0500322 * @brief Returns the system IM
323 *
324 * @return std::string The system IM
325 */
326 virtual std::vector<uint8_t> getSystemIMKeyword() const = 0;
327
328 /**
Matt Spinler60c4e792020-03-13 13:45:36 -0500329 * @brief Get the fields from the inventory necessary for doing
330 * a callout on an inventory path.
331 *
332 * @param[in] inventoryPath - The item to get the data for
Matt Spinler60c4e792020-03-13 13:45:36 -0500333 * @param[out] fruPartNumber - Filled in with the VINI/FN keyword
334 * @param[out] ccin - Filled in with the VINI/CC keyword
335 * @param[out] serialNumber - Filled in with the VINI/SN keyword
336 */
Patrick Williams075c7922024-08-16 15:19:49 -0400337 virtual void getHWCalloutFields(
338 const std::string& inventoryPath, std::string& fruPartNumber,
339 std::string& ccin, std::string& serialNumber) const = 0;
Matt Spinler60c4e792020-03-13 13:45:36 -0500340
Matt Spinler03984582020-04-09 13:17:58 -0500341 /**
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500342 * @brief Get the location code for an inventory item.
343 *
344 * @param[in] inventoryPath - The item to get the data for
345 *
346 * @return std::string - The location code
347 */
348 virtual std::string
349 getLocationCode(const std::string& inventoryPath) const = 0;
350
351 /**
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500352 * @brief Get the list of system type names the system is called.
Matt Spinler03984582020-04-09 13:17:58 -0500353 *
Matt Spinler6ea4d5f2020-05-20 13:31:07 -0500354 * @return std::vector<std::string> - The list of names
Matt Spinler03984582020-04-09 13:17:58 -0500355 */
Matt Spinler1ab66962020-10-29 13:21:44 -0500356 virtual std::vector<std::string> getSystemNames() const = 0;
Matt Spinler03984582020-04-09 13:17:58 -0500357
Matt Spinler5fb24c12020-06-04 11:21:33 -0500358 /**
359 * @brief Fills in the placeholder 'Ufcs' in the passed in location
360 * code with the machine feature code and serial number, which
361 * is needed to create a valid location code.
362 *
363 * @param[in] locationCode - Location code value starting with Ufcs-, and
364 * if that isn't present it will be added first.
365 *
366 * @param[in] node - The node number the location is on.
367 *
368 * @return std::string - The expanded location code
369 */
370 virtual std::string expandLocationCode(const std::string& locationCode,
371 uint16_t node) const = 0;
372
373 /**
Matt Spinlerbad056b2023-01-25 14:16:57 -0600374 * @brief Returns the inventory paths for the FRU that the location
Matt Spinler5fb24c12020-06-04 11:21:33 -0500375 * code represents.
376 *
Matt Spinler2f9225a2020-08-05 12:58:49 -0500377 * @param[in] locationCode - If an expanded location code, then the
378 * full location code.
379 * If not expanded, a location code value
380 * starting with Ufcs-, and if that isn't
381 * present it will be added first.
Matt Spinler5fb24c12020-06-04 11:21:33 -0500382 *
Matt Spinler2f9225a2020-08-05 12:58:49 -0500383 * @param[in] node - The node number the location is on. Ignored if the
384 * expanded location code is passed in.
385 *
386 * @param[in] expanded - If the location code already has the relevent
387 * VPD fields embedded in it.
Matt Spinler5fb24c12020-06-04 11:21:33 -0500388 *
Matt Spinlerbad056b2023-01-25 14:16:57 -0600389 * @return std::vector<std::string> - The inventory D-Bus objects
Matt Spinler5fb24c12020-06-04 11:21:33 -0500390 */
Matt Spinlerbad056b2023-01-25 14:16:57 -0600391 virtual std::vector<std::string>
392 getInventoryFromLocCode(const std::string& LocationCode, uint16_t node,
393 bool expanded) const = 0;
Matt Spinler5fb24c12020-06-04 11:21:33 -0500394
Matt Spinler34a904c2020-08-05 14:53:28 -0500395 /**
Matt Spinler34a904c2020-08-05 14:53:28 -0500396 * @brief Sets the Asserted property on the LED group passed in.
397 *
398 * @param[in] ledGroup - The LED group D-Bus path
399 * @param[in] value - The value to set it to
400 */
401 virtual void assertLEDGroup(const std::string& ledGroup,
402 bool value) const = 0;
403
Matt Spinler993168d2021-04-07 16:05:03 -0500404 /**
405 * @brief Sets the Functional property on the OperationalStatus
406 * interface on a D-Bus object.
407 *
408 * @param[in] objectPath - The D-Bus object path
409 * @param[in] functional - The value
410 */
411 virtual void setFunctional(const std::string& objectPath,
412 bool functional) const = 0;
413
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -0500414 /**
Sumit Kumar76198a22021-07-15 05:59:57 -0500415 * @brief Sets the critical association on the D-Bus object.
416 *
417 * @param[in] objectPath - The D-Bus object path
418 */
419 virtual void
420 setCriticalAssociation(const std::string& objectPath) const = 0;
421
422 /**
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -0500423 * @brief Returns the manufacturing QuiesceOnError property
424 *
425 * @return bool - Manufacturing QuiesceOnError property
426 */
427 virtual bool getQuiesceOnError() const = 0;
428
Matt Spinler0d92b522021-06-16 13:28:17 -0600429 /**
430 * @brief Split location code into base and connector segments
431 *
432 * A location code that ends in '-Tx', where 'x' is a number,
433 * represents a connector, such as a USB cable connector.
434 *
435 * This function splits the passed in location code into a
436 * base and connector segment. e.g.:
437 * P0-T1 -> ['P0', '-T1']
438 * P0 -> ['P0', '']
439 *
440 * @param[in] locationCode - location code to split
441 * @return pair<string, string> - The base and connector segments
442 */
443 static std::pair<std::string, std::string>
444 extractConnectorFromLocCode(const std::string& locationCode);
445
Sumit Kumar9d43a722021-08-24 09:46:19 -0500446 /**
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -0500447 * @brief Create guard record
448 *
449 * @param[in] binPath: phal devtree binary path used as key
450 * @param[in] type: Guard type
451 * @param[in] logPath: error log entry object path
452 */
453 virtual void createGuardRecord(const std::vector<uint8_t>& binPath,
454 const std::string& type,
455 const std::string& logPath) const = 0;
456
Sumit Kumar3e274432021-09-14 06:37:56 -0500457 /**
458 * @brief Create Progress SRC property on the boot progress
459 * interface on a D-Bus object.
460 *
461 * @param[in] priSRC - Primary SRC value (e.g. BD8D1001)
462 * @param[in] srcStruct - Full SRC base structure
463 */
464 virtual void
465 createProgressSRC(const uint64_t& priSRC,
466 const std::vector<uint8_t>& srcStruct) const = 0;
467
Sumit Kumar027bf282022-01-24 11:25:19 -0600468 /**
469 * @brief Get the list of unresolved OpenBMC event log ids that have an
470 * associated hardware isolation entry.
471 *
472 * @return std::vector<uint32_t> - The list of log ids
473 */
474 virtual std::vector<uint32_t> getLogIDWithHwIsolation() const = 0;
475
Vijay Lobo875b6c72021-10-20 17:38:56 -0500476 /**
477 * @brief Returns the latest raw progress SRC from the State.Boot.Raw
478 * D-Bus interface.
479 *
480 * @return std::vector<uint8_t> - The progress SRC bytes
481 */
482 virtual std::vector<uint8_t> getRawProgressSRC() const = 0;
483
Arya K Padmand8ae6182024-07-19 06:25:10 -0500484 /**
485 * @brief Returns the FRUs DI property value hosted on the VINI iterface for
486 * the given location code.
487 *
488 * @param[in] locationCode - The location code of the FRU
489 *
490 * @return std::optional<std::vector<uint8_t>> - The FRUs DI or
491 * std::nullopt
492 */
493 virtual std::optional<std::vector<uint8_t>>
494 getDIProperty(const std::string& locationCode) const = 0;
495
496 /**
497 * @brief Wrpper API to call pHAL API 'getFRUType()' and check whether the
498 * given location code is DIMM or not
499 *
500 * @param[in] locCode - The location code of the FRU
501 *
Arya K Padmanced8ed72024-09-02 05:18:07 -0500502 * @return - true, if the given location code is DIMM
503 * - false, if the given location code is not DIMM or if it fails to
504 * determine the FRU type.
Arya K Padmand8ae6182024-07-19 06:25:10 -0500505 */
Arya K Padmanced8ed72024-09-02 05:18:07 -0500506 bool isDIMM(const std::string& locCode);
Arya K Padmand8ae6182024-07-19 06:25:10 -0500507
508 /**
509 * @brief Check whether the given location code present in the cache
510 * memory
511 *
512 * @param[in] locCode - The location code of the FRU
513 *
514 * @return true, if the given location code present in cache and is a DIMM
515 * false, if the given location code present in cache, but a non
516 * DIMM FRU
517 * std::nullopt, if the given location code is not present in the
518 * cache.
519 */
520 std::optional<bool> isDIMMLocCode(const std::string& locCode) const;
521
522 /**
523 * @brief add the given location code to the cache memory
524 *
525 * @param[in] locCode - The location code of the FRU
526 * @param[in] isFRUDIMM - true indicates the FRU is a DIMM
527 * false indicates the FRU is a non DIMM
528 *
529 */
530 void addDIMMLocCode(const std::string& locCode, bool isFRUDIMM);
531
harsh-agarwal1d763db32024-09-03 09:18:50 -0500532 /**
533 * @brief Finds all D-Bus Associated paths that contain any of the
534 * interfaces passed in, by using GetAssociatedSubTreePaths.
535 *
536 * @param[in] associatedPath - The D-Bus object path
537 * @param[in] subtree - The subtree path for which the result should be
538 * fetched
539 * @param[in] depth - The maximum subtree depth for which results should be
540 * fetched
541 * @param[in] interfaces - The desired interfaces
542 *
543 * @return The D-Bus paths.
544 */
545 virtual DBusPathList getAssociatedPaths(
546 const DBusPath& associatedPath, const DBusPath& subtree, int32_t depth,
547 const DBusInterfaceList& interfaces) const = 0;
548
Matt Spinler19e89ce2019-11-06 13:02:23 -0600549 protected:
550 /**
Matt Spinlera7d9d962019-11-06 15:01:25 -0600551 * @brief Sets the host on/off state and runs any
552 * callback functions (if there was a change).
553 */
Matt Spinler4aa23a12020-02-03 15:05:09 -0600554 void setHostUp(bool hostUp)
Matt Spinlera7d9d962019-11-06 15:01:25 -0600555 {
Matt Spinler4aa23a12020-02-03 15:05:09 -0600556 if (_hostUp != hostUp)
Matt Spinlera7d9d962019-11-06 15:01:25 -0600557 {
Matt Spinler4aa23a12020-02-03 15:05:09 -0600558 _hostUp = hostUp;
Matt Spinlera7d9d962019-11-06 15:01:25 -0600559
560 for (auto& [name, func] : _hostChangeCallbacks)
561 {
562 try
563 {
564 func(_hostUp);
565 }
Patrick Williams66491c62021-10-06 12:23:37 -0500566 catch (const std::exception& e)
Matt Spinlera7d9d962019-11-06 15:01:25 -0600567 {
Matt Spinlera167a7d2023-06-30 15:14:25 -0500568 lg2::error(
569 "A host state change callback threw an exception");
Matt Spinlera7d9d962019-11-06 15:01:25 -0600570 }
571 }
572 }
573 }
574
575 /**
Matt Spinler5b423652023-05-04 13:08:44 -0500576 * @brief Runs the callback functions registered when
577 * FRUs become present.
578 */
579 void setFruPresent(const std::string& locationCode)
580 {
581 for (const auto& [_, func] : _fruPresentCallbacks)
582 {
583 try
584 {
585 func(locationCode);
586 }
587 catch (const std::exception& e)
588 {
Matt Spinlera167a7d2023-06-30 15:14:25 -0500589 lg2::error("A FRU present callback threw an exception");
Matt Spinler5b423652023-05-04 13:08:44 -0500590 }
591 }
592 }
593
594 /**
Matt Spinlercce14112019-12-11 14:20:36 -0600595 * @brief The hardware management console status. Always kept
596 * up to date.
597 */
598 bool _hmcManaged = false;
599
600 /**
Matt Spinlera7d9d962019-11-06 15:01:25 -0600601 * @brief The host up status. Always kept up to date.
602 */
603 bool _hostUp = false;
604
605 /**
606 * @brief The map of host state change subscriber
607 * names to callback functions.
608 */
609 std::map<std::string, HostStateChangeFunc> _hostChangeCallbacks;
Matt Spinlercad9c2b2019-12-02 15:42:01 -0600610
611 /**
Matt Spinler5b423652023-05-04 13:08:44 -0500612 * @brief The map of FRU present subscriber
613 * names to callback functions.
614 */
615 std::map<std::string, FRUPresentFunc> _fruPresentCallbacks;
616
617 /**
Matt Spinlercad9c2b2019-12-02 15:42:01 -0600618 * @brief The BMC firmware version string
619 */
620 std::string _bmcFWVersion;
621
622 /**
623 * @brief The server firmware version string
624 */
625 std::string _serverFWVersion;
Matt Spinler677381b2020-01-23 10:04:29 -0600626
627 /**
628 * @brief The BMC firmware version ID string
629 */
630 std::string _bmcFWVersionID;
Matt Spinler9cf3cfd2020-02-03 14:41:55 -0600631
632 /**
633 * @brief If sending PELs is enabled.
634 *
635 * This is usually set to false in manufacturing test.
636 */
637 bool _sendPELsToHost = true;
Matt Spinler4aa23a12020-02-03 15:05:09 -0600638
639 /**
640 * @brief The BMC state property
641 */
642 std::string _bmcState;
643
644 /**
645 * @brief The Chassis current power state property
646 */
647 std::string _chassisState;
648
649 /**
650 * @brief The Chassis requested power transition property
651 */
652 std::string _chassisTransition;
653
654 /**
655 * @brief The host state property
656 */
657 std::string _hostState;
Sumit Kumar2c36fdd2021-09-21 03:12:11 -0500658
659 /**
660 * @brief The boot state property
661 */
662 std::string _bootState;
Arya K Padmand8ae6182024-07-19 06:25:10 -0500663
664 /**
665 * @brief A cache storage for location code and its FRU Type
666 * - The key 'std::string' represents the locationCode of the FRU
667 * - The bool value - true indicates the FRU is a DIMM
668 * false indicates the FRU is a non DIMM.
669 */
670 std::unordered_map<std::string, bool> _locationCache;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500671};
672
673/**
674 * @class DataInterface
675 *
676 * Concrete implementation of DataInterfaceBase.
677 */
678class DataInterface : public DataInterfaceBase
679{
680 public:
681 DataInterface() = delete;
682 ~DataInterface() = default;
683 DataInterface(const DataInterface&) = default;
684 DataInterface& operator=(const DataInterface&) = default;
685 DataInterface(DataInterface&&) = default;
686 DataInterface& operator=(DataInterface&&) = default;
687
688 /**
689 * @brief Constructor
690 *
691 * @param[in] bus - The sdbusplus bus object
692 */
Patrick Williams45e83522022-07-22 19:26:52 -0500693 explicit DataInterface(sdbusplus::bus_t& bus);
Matt Spinlerc8705e22019-09-11 12:36:07 -0500694
Matt Spinlerb3f51862019-12-09 13:55:10 -0600695 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -0500696 * @brief Finds the D-Bus service name that hosts the
697 * passed in path and interface.
698 *
699 * @param[in] objectPath - The D-Bus object path
700 * @param[in] interface - The D-Bus interface
701 */
702 DBusService getService(const std::string& objectPath,
Matt Spinlerb3f51862019-12-09 13:55:10 -0600703 const std::string& interface) const;
Matt Spinler9cf3cfd2020-02-03 14:41:55 -0600704
Matt Spinlerc8705e22019-09-11 12:36:07 -0500705 /**
706 * @brief Wrapper for the 'GetAll' properties method call
707 *
708 * @param[in] service - The D-Bus service to call it on
709 * @param[in] objectPath - The D-Bus object path
710 * @param[in] interface - The interface to get the props on
711 *
712 * @return DBusPropertyMap - The property results
713 */
714 DBusPropertyMap getAllProperties(const std::string& service,
715 const std::string& objectPath,
Matt Spinler2a28c932020-02-03 14:23:40 -0600716 const std::string& interface) const;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500717 /**
Matt Spinlera7d9d962019-11-06 15:01:25 -0600718 * @brief Wrapper for the 'Get' properties method call
719 *
720 * @param[in] service - The D-Bus service to call it on
721 * @param[in] objectPath - The D-Bus object path
722 * @param[in] interface - The interface to get the property on
723 * @param[in] property - The property name
724 * @param[out] value - Filled in with the property value.
725 */
726 void getProperty(const std::string& service, const std::string& objectPath,
727 const std::string& interface, const std::string& property,
Matt Spinler2a28c932020-02-03 14:23:40 -0600728 DBusValue& value) const;
Vijay Lobo81b4dca2021-04-29 00:04:00 -0500729 /**
730 * @brief Returns the machine Type/Model
731 *
732 * @return string - The machine Type/Model string
733 */
734 std::string getMachineTypeModel() const override;
735
736 /**
737 * @brief Returns the machine serial number
738 *
739 * @return string - The machine serial number
740 */
741 std::string getMachineSerialNumber() const override;
742
743 /**
744 * @brief Returns the motherboard CCIN
745 *
746 * @return std::string The motherboard CCIN
747 */
748 std::string getMotherboardCCIN() const override;
Matt Spinler2a28c932020-02-03 14:23:40 -0600749
Matt Spinler60c4e792020-03-13 13:45:36 -0500750 /**
Ben Tynere32b7e72021-05-18 12:38:40 -0500751 * @brief Returns the system IM
752 *
753 * @return std::vector The system IM keyword in 4 byte vector
754 */
755 std::vector<uint8_t> getSystemIMKeyword() const override;
756
757 /**
Matt Spinler60c4e792020-03-13 13:45:36 -0500758 * @brief Get the fields from the inventory necessary for doing
759 * a callout on an inventory path.
760 *
761 * @param[in] inventoryPath - The item to get the data for
Matt Spinler60c4e792020-03-13 13:45:36 -0500762 * @param[out] fruPartNumber - Filled in with the VINI/FN keyword
763 * @param[out] ccin - Filled in with the VINI/CC keyword
764 * @param[out] serialNumber - Filled in with the VINI/SN keyword
765 */
766 void getHWCalloutFields(const std::string& inventoryPath,
Matt Spinler60c4e792020-03-13 13:45:36 -0500767 std::string& fruPartNumber, std::string& ccin,
768 std::string& serialNumber) const override;
769
Matt Spinler9b90e2a2020-04-14 10:59:04 -0500770 /**
771 * @brief Get the location code for an inventory item.
772 *
773 * Throws an exception if the inventory item doesn't have the
774 * location code interface.
775 *
776 * @param[in] inventoryPath - The item to get the data for
777 *
778 * @return std::string - The location code
779 */
780 std::string
781 getLocationCode(const std::string& inventoryPath) const override;
782
Matt Spinler5fb24c12020-06-04 11:21:33 -0500783 /**
Matt Spinler1ab66962020-10-29 13:21:44 -0500784 * @brief Get the list of system type names the system is called.
785 *
786 * @return std::vector<std::string> - The list of names
787 */
788 std::vector<std::string> getSystemNames() const override;
789
790 /**
Matt Spinler5fb24c12020-06-04 11:21:33 -0500791 * @brief Fills in the placeholder 'Ufcs' in the passed in location
792 * code with the machine feature code and serial number, which
793 * is needed to create a valid location code.
794 *
795 * @param[in] locationCode - Location code value starting with Ufcs-, and
796 * if that isn't present it will be added first.
797 *
798 * @param[in] node - The node number the location is one.
799 *
800 * @return std::string - The expanded location code
801 */
802 std::string expandLocationCode(const std::string& locationCode,
803 uint16_t node) const override;
804
805 /**
Matt Spinlerbad056b2023-01-25 14:16:57 -0600806 * @brief Returns the inventory paths for the FRU that the location
Matt Spinler5fb24c12020-06-04 11:21:33 -0500807 * code represents.
808 *
Matt Spinler2f9225a2020-08-05 12:58:49 -0500809 * @param[in] locationCode - If an expanded location code, then the
810 * full location code.
811 * If not expanded, a location code value
812 * starting with Ufcs-, and if that isn't
813 * present it will be added first.
Matt Spinler5fb24c12020-06-04 11:21:33 -0500814 *
Matt Spinler2f9225a2020-08-05 12:58:49 -0500815 * @param[in] node - The node number the location is on. Ignored if the
816 * expanded location code is passed in.
817 *
818 * @param[in] expanded - If the location code already has the relevent
819 * VPD fields embedded in it.
Matt Spinler5fb24c12020-06-04 11:21:33 -0500820 *
Matt Spinlerbad056b2023-01-25 14:16:57 -0600821 * @return std::vector<std::string> - The inventory D-Bus objects
Matt Spinler5fb24c12020-06-04 11:21:33 -0500822 */
Matt Spinlerbad056b2023-01-25 14:16:57 -0600823 std::vector<std::string>
824 getInventoryFromLocCode(const std::string& locationCode, uint16_t node,
825 bool expanded) const override;
Matt Spinler5fb24c12020-06-04 11:21:33 -0500826
Matt Spinler34a904c2020-08-05 14:53:28 -0500827 /**
Matt Spinler34a904c2020-08-05 14:53:28 -0500828 * @brief Sets the Asserted property on the LED group passed in.
829 *
830 * @param[in] ledGroup - The LED group D-Bus path
831 * @param[in] value - The value to set it to
832 */
833 void assertLEDGroup(const std::string& ledGroup, bool value) const override;
834
Matt Spinler993168d2021-04-07 16:05:03 -0500835 /**
836 * @brief Sets the Functional property on the OperationalStatus
837 * interface on a D-Bus object.
838 *
839 * @param[in] objectPath - The D-Bus object path
840 * @param[in] functional - The value
841 */
842 void setFunctional(const std::string& objectPath,
843 bool functional) const override;
844
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -0500845 /**
Sumit Kumar76198a22021-07-15 05:59:57 -0500846 * @brief Sets the critical association on the D-Bus object.
847 *
848 * @param[in] objectPath - The D-Bus object path
849 */
850 void setCriticalAssociation(const std::string& objectPath) const override;
851
852 /**
Sumit Kumar3b8ed7f2021-05-18 12:38:35 -0500853 * @brief Returns the manufacturing QuiesceOnError property
854 *
855 * @return bool - Manufacturing QuiesceOnError property
856 */
857 bool getQuiesceOnError() const override;
858
Sumit Kumar9d43a722021-08-24 09:46:19 -0500859 /**
Jayanth Othayothecaa2fc2021-11-05 02:02:52 -0500860 * @brief Create guard record
861 *
862 * @param[in] binPath: phal devtree binary path used as key
863 * @param[in] type: Guard type
864 * @param[in] logPath: error log entry object path
865 */
866 void createGuardRecord(const std::vector<uint8_t>& binPath,
867 const std::string& type,
868 const std::string& logPath) const override;
869
Sumit Kumar3e274432021-09-14 06:37:56 -0500870 /**
871 * @brief Create Progress SRC property on the boot progress
872 * interface on a D-Bus object.
873 *
874 * @param[in] priSRC - Primary SRC value
875 * @param[in] srcStruct - Full SRC base structure
876 */
877 void
878 createProgressSRC(const uint64_t& priSRC,
879 const std::vector<uint8_t>& srcStruct) const override;
880
Sumit Kumar027bf282022-01-24 11:25:19 -0600881 /**
882 * @brief Get the list of unresolved OpenBMC event log ids that have an
883 * associated hardware isolation entry.
884 *
885 * @return std::vector<uint32_t> - The list of log ids
886 */
887 std::vector<uint32_t> getLogIDWithHwIsolation() const override;
888
Vijay Lobo875b6c72021-10-20 17:38:56 -0500889 /**
890 * @brief Returns the latest raw progress SRC from the State.Boot.Raw
891 * D-Bus interface.
892 *
893 * @return std::vector<uint8_t>: The progress SRC bytes
894 */
895 std::vector<uint8_t> getRawProgressSRC() const override;
896
Arya K Padmand8ae6182024-07-19 06:25:10 -0500897 /**
898 * @brief Returns the FRUs DI property value hosted on the VINI iterface for
899 * the given location code.
900 *
901 * @param[in] locationCode - The location code of the FRU
902 *
903 * @return std::optional<std::vector<uint8_t>> - The FRUs DI or
904 * std::nullopt
905 */
906 std::optional<std::vector<uint8_t>>
907 getDIProperty(const std::string& locationCode) const override;
908
harsh-agarwal1d763db32024-09-03 09:18:50 -0500909 /**
910 * @brief Finds all D-Bus Associated paths that contain any of the
911 * interfaces passed in, by using GetAssociatedSubTreePaths.
912 *
913 * @param[in] associatedPath - The D-Bus object path
914 * @param[in] subtree - The subtree path for which the result should be
915 * fetched
916 * @param[in] depth - The maximum subtree depth for which results should be
917 * fetched
918 * @param[in] interfaces - The desired interfaces
919 *
920 * @return The D-Bus paths.
921 */
922 DBusPathList getAssociatedPaths(
923 const DBusPath& associatedPath, const DBusPath& subtree, int32_t depth,
924 const DBusInterfaceList& interfaces) const override;
925
Matt Spinler2a28c932020-02-03 14:23:40 -0600926 private:
927 /**
928 * @brief Reads the BMC firmware version string and puts it into
929 * _bmcFWVersion.
930 */
931 void readBMCFWVersion();
Matt Spinlera7d9d962019-11-06 15:01:25 -0600932
933 /**
Matt Spinler2a28c932020-02-03 14:23:40 -0600934 * @brief Reads the server firmware version string and puts it into
935 * _serverFWVersion.
Matt Spinlerc8705e22019-09-11 12:36:07 -0500936 */
Matt Spinler2a28c932020-02-03 14:23:40 -0600937 void readServerFWVersion();
Matt Spinlerc8705e22019-09-11 12:36:07 -0500938
939 /**
Matt Spinler2a28c932020-02-03 14:23:40 -0600940 * @brief Reads the BMC firmware version ID and puts it into
941 * _bmcFWVersionID.
Matt Spinlera7d9d962019-11-06 15:01:25 -0600942 */
Matt Spinler2a28c932020-02-03 14:23:40 -0600943 void readBMCFWVersionID();
Matt Spinlera7d9d962019-11-06 15:01:25 -0600944
945 /**
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600946 * @brief Finds all D-Bus paths that contain any of the interfaces
947 * passed in, by using GetSubTreePaths.
948 *
949 * @param[in] interfaces - The desired interfaces
950 *
951 * @return The D-Bus paths.
952 */
953 DBusPathList getPaths(const DBusInterfaceList& interfaces) const;
954
955 /**
956 * @brief The interfacesAdded callback used on the inventory to
957 * find the D-Bus object that has the motherboard interface.
958 * When the motherboard is found, it then adds a PropertyWatcher
959 * for the motherboard CCIN.
960 */
Patrick Williams45e83522022-07-22 19:26:52 -0500961 void motherboardIfaceAdded(sdbusplus::message_t& msg);
Matt Spinlerb3d488f2020-02-21 15:30:46 -0600962
963 /**
Matt Spinler5b423652023-05-04 13:08:44 -0500964 * @brief Start watching for the hotpluggable FRUs to become
965 * present.
966 */
967 void startFruPlugWatch();
968
969 /**
970 * @brief Create a D-Bus match object for the Present property
971 * to change on the path passed in.
972 * @param[in] path - The path to watch.
973 */
974 void addHotplugWatch(const std::string& path);
975
976 /**
977 * @brief Callback when an inventory interface was added.
978 *
979 * Only does something if it's one of the hotpluggable FRUs,
980 * in which case it will treat it as a hotplug if the
981 * Present property is true.
982 *
983 * @param[in] msg - The InterfacesAdded signal contents.
984 */
985 void inventoryIfaceAdded(sdbusplus::message_t& msg);
986
987 /**
988 * @brief Callback when the Present property changes.
989 *
990 * If present, will run the registered callbacks.
991 *
992 * @param[in] msg - The PropertiesChanged signal contents.
993 */
994 void presenceChanged(sdbusplus::message_t& msg);
995
996 /**
997 * @brief If the Present property is in the properties map
998 * passed in and it is true, notify the subscribers.
999 *
1000 * @param[in] path - The object path of the inventory item.
1001 * @param[in] properties - The properties map
1002 */
1003 void notifyPresenceSubsribers(const std::string& path,
1004 const DBusPropertyMap& properties);
1005
1006 /**
Matt Spinler0e4d72e2020-08-05 12:36:53 -05001007 * @brief Adds the Ufcs- prefix to the location code passed in
1008 * if necessary.
Matt Spinler5fb24c12020-06-04 11:21:33 -05001009 *
Matt Spinler0e4d72e2020-08-05 12:36:53 -05001010 * Needed because the location codes that come back from the
Matt Spinler5fb24c12020-06-04 11:21:33 -05001011 * message registry and device callout JSON don't have it.
1012 *
1013 * @param[in] - The location code without a prefix, like P1-C1
1014 *
1015 * @return std::string - The location code with the prefix
1016 */
1017 static std::string addLocationCodePrefix(const std::string& locationCode);
1018
Arya K Padmanafba3162024-08-30 07:41:32 -05001019 /**
1020 * @brief A helper API to check whether the PHAL device tree is exists,
1021 * ensuring the PHAL init API can be invoked.
1022 *
1023 * @return true if the PHAL device tree is exists, otherwise false
1024 */
1025 bool isPHALDevTreeExist() const;
1026
Arya K Padman0b758fb2024-09-06 11:59:45 -05001027#ifdef PEL_ENABLE_PHAL
Arya K Padmanafba3162024-08-30 07:41:32 -05001028 /**
1029 * @brief A helper API to init PHAL libraries
1030 *
1031 * @return None
1032 */
1033 void initPHAL();
Arya K Padman0b758fb2024-09-06 11:59:45 -05001034#endif // PEL_ENABLE_PHAL
Arya K Padmanafba3162024-08-30 07:41:32 -05001035
1036 /**
1037 * @brief A helper API to subscribe to systemd signals
1038 *
1039 * @return None
1040 */
1041 void subscribeToSystemdSignals();
1042
1043 /**
1044 * @brief A helper API to unsubscribe to systemd signals
1045 *
1046 * @return None
1047 */
1048 void unsubscribeFromSystemdSignals();
Arya K Padmanafba3162024-08-30 07:41:32 -05001049
Matt Spinler5fb24c12020-06-04 11:21:33 -05001050 /**
Matt Spinler2a28c932020-02-03 14:23:40 -06001051 * @brief The D-Bus property or interface watchers that have callbacks
1052 * registered that will set members in this class when
1053 * they change.
Matt Spinlerc8705e22019-09-11 12:36:07 -05001054 */
Matt Spinler2a28c932020-02-03 14:23:40 -06001055 std::vector<std::unique_ptr<DBusWatcher>> _properties;
Matt Spinlera7d9d962019-11-06 15:01:25 -06001056
Matt Spinler5b423652023-05-04 13:08:44 -05001057 std::unique_ptr<sdbusplus::bus::match_t> _invIaMatch;
1058
1059 /**
1060 * @brief The matches for watching for hotplugs.
1061 *
1062 * A map so we can check that we never get duplicates.
1063 */
1064 std::map<std::string, std::unique_ptr<sdbusplus::bus::match_t>>
1065 _invPresentMatches;
1066
Matt Spinlera7d9d962019-11-06 15:01:25 -06001067 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -05001068 * @brief The sdbusplus bus object for making D-Bus calls.
1069 */
Patrick Williams45e83522022-07-22 19:26:52 -05001070 sdbusplus::bus_t& _bus;
Arya K Padmanafba3162024-08-30 07:41:32 -05001071
Arya K Padmanafba3162024-08-30 07:41:32 -05001072 /**
1073 * @brief Watcher to check "openpower-update-bios-attr-table" service
1074 * is "done" to init PHAL libraires
1075 */
1076 std::unique_ptr<sdbusplus::bus::match_t> _systemdMatch;
Arya K Padmanafba3162024-08-30 07:41:32 -05001077
1078 /**
1079 * @brief A slot object for async dbus call
1080 */
1081 sdbusplus::slot_t _systemdSlot;
Matt Spinlerc8705e22019-09-11 12:36:07 -05001082};
1083
1084} // namespace pels
1085} // namespace openpower