blob: 36982ff69c9a9b1d2e27838b36cc05777d54aefb [file] [log] [blame]
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001/*
2 * Copyright (c) 2018-present Facebook. All Rights Reserved.
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 */
16
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +053017#include <commandutils.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050018#include <usb-dbg.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080019
20namespace ipmi
21{
22
Vijay Khemka63c99be2020-05-27 19:14:35 -070023ipmi_ret_t getNetworkData(uint8_t lan_param, char* data);
Daniel Hsud8d95a32024-05-27 16:05:25 +080024std::string getMotherBoardFruName();
Vijay Khemka63c99be2020-05-27 19:14:35 -070025int8_t getFruData(std::string& serial, std::string& name);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +053026int8_t sysConfig(std::vector<std::string>& data, size_t pos);
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +053027int8_t procInfo(std::string& result, size_t pos);
Vijay Khemkae7d23d02019-03-08 13:13:40 -080028
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053029bool isMultiHostPlatform();
30
31/* Declare Host Selector interface and path */
32namespace selector
33{
34const std::string path = "/xyz/openbmc_project/Chassis/Buttons/HostSelector";
35const std::string interface =
Potin Laicff150e2022-09-19 09:34:57 +080036 "xyz.openbmc_project.Chassis.Buttons.HostSelector";
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053037} // namespace selector
38
Vijay Khemka427b2762019-12-12 12:49:25 -080039/* Declare storage functions used here */
40namespace storage
41{
Vijay Khemka63c99be2020-05-27 19:14:35 -070042int getSensorValue(std::string&, double&);
43int getSensorUnit(std::string&, std::string&);
Delphine CC Chiu2ca4aa02023-02-01 16:30:18 +080044int getSensorThreshold(std::string&, std::string&);
Vijay Khemka58bd5d82019-12-13 11:05:56 -080045} // namespace storage
Vijay Khemka427b2762019-12-12 12:49:25 -080046
Delphine CC Chiu7bb45922023-04-10 13:34:04 +080047namespace boot
48{
49std::tuple<std::string, std::string> objPath(size_t id);
50void setBootOrder(std::string bootObjPath, const std::vector<uint8_t>& bootSeq,
51 std::string hostName);
52void getBootOrder(std::string bootObjPath, std::vector<uint8_t>& bootSeq,
53 std::string hostName);
54} // namespace boot
55
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053056void getMaxHostPosition(size_t& maxPosition)
Potin Laif24c78e2022-10-27 17:13:14 +080057{
58 try
59 {
60 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Patrick Williams010dee02024-08-16 15:19:44 -040061 std::string service =
62 getService(*dbus, ipmi::selector::interface, ipmi::selector::path);
63 Value variant =
64 getDbusProperty(*dbus, service, ipmi::selector::path,
65 ipmi::selector::interface, "MaxPosition");
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053066 maxPosition = std::get<size_t>(variant);
Potin Laif24c78e2022-10-27 17:13:14 +080067 }
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053068 catch (const std::exception& e)
Potin Laif24c78e2022-10-27 17:13:14 +080069 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053070 lg2::error("Unable to get max host position - {MAXPOSITION}",
71 "MAXPOSITION", maxPosition);
72 throw e;
Potin Laif24c78e2022-10-27 17:13:14 +080073 }
Potin Laif24c78e2022-10-27 17:13:14 +080074}
75
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053076void getSelectorPosition(size_t& hostPosition)
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053077{
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053078 try
79 {
80 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Patrick Williams010dee02024-08-16 15:19:44 -040081 std::string service =
82 getService(*dbus, ipmi::selector::interface, ipmi::selector::path);
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053083 Value variant = getDbusProperty(*dbus, service, ipmi::selector::path,
84 ipmi::selector::interface, "Position");
85 hostPosition = std::get<size_t>(variant);
86 }
87 catch (const std::exception& e)
88 {
89 lg2::error("Unable to get host position - {POSITION}", "POSITION",
90 hostPosition);
91 throw e;
92 }
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053093}
94
Vijay Khemkae7d23d02019-03-08 13:13:40 -080095static int panelNum = (sizeof(panels) / sizeof(struct ctrl_panel)) - 1;
96
97/* Returns the FRU the hand-switch is switched to. If it is switched to BMC
98 * it returns FRU_ALL. Note, if in err, it returns FRU_ALL */
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053099static size_t plat_get_fru_sel()
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800100{
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530101 size_t position;
102 bool platform = isMultiHostPlatform();
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530103 if (platform == true)
104 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530105 getSelectorPosition(position);
106 if (position == BMC_POSITION)
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530107 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530108 return FRU_ALL;
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530109 }
110 }
111 else
112 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530113 /* For Tiogapass it just return 1,
114 * can modify to support more platform */
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530115 position = 1;
116 }
117 return position;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800118}
119
120// return 0 on seccuess
Patrick Williams13ce3792024-08-27 13:03:46 -0400121void frame::init(size_t size)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800122{
123 // Reset status
124 idx_head = idx_tail = 0;
125 lines = 0;
126 esc_sts = 0;
127 pages = 1;
128
Patrick Williams13ce3792024-08-27 13:03:46 -0400129 if (buf != nullptr && max_size == size)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800130 {
Patrick Williams13ce3792024-08-27 13:03:46 -0400131 return;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800132 }
133
Patrick Williams13ce3792024-08-27 13:03:46 -0400134 if (buf != nullptr && max_size != size)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800135 {
136 delete[] buf;
137 }
138 // Initialize Configuration
139 title[0] = '\0';
140 buf = new char[size];
141 max_size = size;
142 max_page = size;
143 line_per_page = 7;
144 line_width = 16;
Patrick Williams13ce3792024-08-27 13:03:46 -0400145 overwrite = false;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800146
Patrick Williams13ce3792024-08-27 13:03:46 -0400147 return;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800148}
149
150// return 0 on seccuess
Patrick Williams13ce3792024-08-27 13:03:46 -0400151void frame::append(const std::string& str, size_t indent)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800152{
Patrick Williams13ce3792024-08-27 13:03:46 -0400153 for (auto ch : parse(str, indent))
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800154 {
155 if (isFull())
156 {
157 if (overwrite)
158 {
159 if (buf[idx_head] == LINE_DELIMITER)
160 lines--;
161 idx_head = (idx_head + 1) % max_size;
162 }
163 else
Patrick Williams13ce3792024-08-27 13:03:46 -0400164 {
165 throw std::overflow_error("No room in buffer");
166 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800167 }
168
Patrick Williams13ce3792024-08-27 13:03:46 -0400169 buf[idx_tail] = ch;
170 if (ch == LINE_DELIMITER)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800171 lines++;
172
173 idx_tail = (idx_tail + 1) % max_size;
174 }
175
176 pages = (lines / line_per_page) + ((lines % line_per_page) ? 1 : 0);
177
178 if (pages > max_page)
179 pages = max_page;
180
Patrick Williams13ce3792024-08-27 13:03:46 -0400181 return;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800182}
183
184// return page size
Patrick Williams13ce3792024-08-27 13:03:46 -0400185int frame::getPage(size_t page, char* page_buf, size_t page_buf_size)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800186{
187 int ret;
188 uint16_t line = 0;
189 uint16_t idx, len;
190
Patrick Williams13ce3792024-08-27 13:03:46 -0400191 if (buf == nullptr)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800192 return -1;
193
194 // 1-based page
195 if (page > pages || page < 1)
196 return -1;
197
Patrick Williams13ce3792024-08-27 13:03:46 -0400198 if (page_buf == nullptr || page_buf_size == 0)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800199 return -1;
200
Patrick Williams13ce3792024-08-27 13:03:46 -0400201 ret = snprintf(page_buf, 17, "%-10s %02zd/%02zd", title, page, pages);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800202 len = strlen(page_buf);
203 if (ret < 0)
204 return -1;
205
206 line = 0;
207 idx = idx_head;
208 while (line < ((page - 1) * line_per_page) && idx != idx_tail)
209 {
210 if (buf[idx] == LINE_DELIMITER)
211 line++;
212 idx = (idx + 1) % max_size;
213 }
214
215 while (line < ((page)*line_per_page) && idx != idx_tail)
216 {
217 if (buf[idx] == LINE_DELIMITER)
218 {
219 line++;
220 }
221 else
222 {
223 page_buf[len++] = buf[idx];
224 if (len == (page_buf_size - 1))
225 {
226 break;
227 }
228 }
229 idx = (idx + 1) % max_size;
230 }
231
232 return len;
233}
234
Patrick Williams13ce3792024-08-27 13:03:46 -0400235bool frame::isFull() const
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800236{
Patrick Williams13ce3792024-08-27 13:03:46 -0400237 if (buf == nullptr)
238 return true;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800239
240 if ((idx_tail + 1) % max_size == idx_head)
Patrick Williams13ce3792024-08-27 13:03:46 -0400241 return true;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800242 else
Patrick Williams13ce3792024-08-27 13:03:46 -0400243 return false;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800244}
245
246// return 1 for Escape Sequence
Patrick Williams13ce3792024-08-27 13:03:46 -0400247bool frame::isEscSeq(char chr)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800248{
249 uint8_t curr_sts = esc_sts;
250
251 if (esc_sts == 0 && (chr == 0x1b))
252 esc_sts = 1; // Escape Sequence
253 else if (esc_sts == 1 && (chr == 0x5b))
254 esc_sts = 2; // Control Sequence Introducer(CSI)
255 else if (esc_sts == 1 && (chr != 0x5b))
256 esc_sts = 0;
257 else if (esc_sts == 2 && (chr >= 0x40 && chr <= 0x7e))
258 esc_sts = 0;
259
260 if (curr_sts || esc_sts)
Patrick Williams13ce3792024-08-27 13:03:46 -0400261 return true;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800262 else
Patrick Williams13ce3792024-08-27 13:03:46 -0400263 return false;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800264}
265
266// return 0 on success
Patrick Williams13ce3792024-08-27 13:03:46 -0400267auto frame::parse(const std::string& input, size_t indent) -> std::string
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800268{
Patrick Williams13ce3792024-08-27 13:03:46 -0400269 if (indent > line_width)
270 return {};
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800271
Patrick Williams13ce3792024-08-27 13:03:46 -0400272 std::string result;
273 size_t linepos = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800274
Patrick Williams13ce3792024-08-27 13:03:46 -0400275 for (auto ch : input)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800276 {
Cosmo Chou6c02bfb2024-08-29 15:49:42 +0800277 if (linepos == 0)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800278 {
Patrick Williams13ce3792024-08-27 13:03:46 -0400279 result.append(indent, ' ');
280 linepos = indent;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800281 }
282
Patrick Williams13ce3792024-08-27 13:03:46 -0400283 // Insert character.
284 result.push_back(ch);
Cosmo Chou6c02bfb2024-08-29 15:49:42 +0800285
286 if (!isEscSeq(ch))
287 {
288 // Check if new line is needed.
289 if (++linepos == line_width)
290 {
291 result.push_back(LINE_DELIMITER);
292 linepos = 0;
293 }
294 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800295 }
296
Patrick Williams13ce3792024-08-27 13:03:46 -0400297 // Fill out remaining line.
298 result.append(line_width - linepos, ' ');
299 result.push_back(LINE_DELIMITER);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800300
Patrick Williams13ce3792024-08-27 13:03:46 -0400301 return result;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800302}
303
Vijay Khemka63c99be2020-05-27 19:14:35 -0700304static int chk_cri_sel_update(uint8_t* cri_sel_up)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800305{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700306 FILE* fp;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800307 struct stat file_stat;
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530308 size_t pos = plat_get_fru_sel();
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800309 static uint8_t pre_pos = 0xff;
310
311 fp = fopen("/mnt/data/cri_sel", "r");
312 if (fp)
313 {
314 if ((stat("/mnt/data/cri_sel", &file_stat) == 0) &&
315 (file_stat.st_mtime != frame_sel.mtime || pre_pos != pos))
316 {
317 *cri_sel_up = 1;
318 }
319 else
320 {
321 *cri_sel_up = 0;
322 }
323 fclose(fp);
324 }
325 else
326 {
Patrick Williams13ce3792024-08-27 13:03:46 -0400327 if (frame_sel.buf == nullptr || frame_sel.lines != 0 || pre_pos != pos)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800328 {
329 *cri_sel_up = 1;
330 }
331 else
332 {
333 *cri_sel_up = 0;
334 }
335 }
336 pre_pos = pos;
337 return 0;
338}
339
Vijay Khemka63c99be2020-05-27 19:14:35 -0700340int plat_udbg_get_frame_info(uint8_t* num)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800341{
342 *num = 3;
343 return 0;
344}
345
Vijay Khemka63c99be2020-05-27 19:14:35 -0700346int plat_udbg_get_updated_frames(uint8_t* count, uint8_t* buffer)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800347{
348 uint8_t cri_sel_up = 0;
349 uint8_t info_page_up = 1;
350
351 *count = 0;
352
353 // info page update
354 if (info_page_up == 1)
355 {
356 buffer[*count] = 1;
357 *count += 1;
358 }
359
360 // cri sel update
361 chk_cri_sel_update(&cri_sel_up);
362 if (cri_sel_up == 1)
363 {
364 buffer[*count] = 2;
365 *count += 1;
366 }
367
368 // cri sensor update
369 buffer[*count] = 3;
370 *count += 1;
371
372 return 0;
373}
374
Vijay Khemka63c99be2020-05-27 19:14:35 -0700375int plat_udbg_get_post_desc(uint8_t index, uint8_t* next, uint8_t phase,
376 uint8_t* end, uint8_t* length, uint8_t* buffer)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800377{
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700378 nlohmann::json postObj;
379 std::string postCode;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800380
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700381 /* Get post description data stored in json file */
382 std::ifstream file(JSON_POST_DATA_FILE);
383 if (file)
384 {
385 file >> postObj;
386 file.close();
387 }
388 else
389 {
390 phosphor::logging::log<phosphor::logging::level::ERR>(
391 "Post code description file not found",
392 phosphor::logging::entry("POST_CODE_FILE=%s", JSON_POST_DATA_FILE));
393 return -1;
394 }
395
396 std::string phaseStr = "PhaseAny";
397 if (postObj.find(phaseStr) == postObj.end())
398 {
399 phaseStr = "Phase" + std::to_string(phase);
400 }
401
402 if (postObj.find(phaseStr) == postObj.end())
403 {
404 phosphor::logging::log<phosphor::logging::level::ERR>(
405 "Post code phase not available",
406 phosphor::logging::entry("PHASE=%d", phase));
407 return -1;
408 }
409
410 auto phaseObj = postObj[phaseStr];
411 int phaseSize = phaseObj.size();
412
413 for (int i = 0; i < phaseSize; i++)
414 {
415 postCode = phaseObj[i][0];
416 if (index == stoul(postCode, nullptr, 16))
417 {
418 std::string postDesc = phaseObj[i][1];
419 *length = postDesc.size();
420 memcpy(buffer, postDesc.data(), *length);
421 buffer[*length] = '\0';
422
423 if (phaseSize != i + 1)
424 {
425 postCode = phaseObj[i + 1][0];
426 *next = stoul(postCode, nullptr, 16);
427 *end = 0;
428 }
429 else
430 {
431 if (postObj.size() != phase)
432 {
Patrick Williams010dee02024-08-16 15:19:44 -0400433 std::string nextPhaseStr =
434 "Phase" + std::to_string(phase + 1);
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700435 postCode = postObj[nextPhaseStr][0][0];
436 *next = stoul(postCode, nullptr, 16);
437 *end = 0;
438 }
439 else
440 {
441 *next = 0xff;
442 *end = 1;
443 }
444 }
445
446 return 0;
447 }
448 }
449
450 phosphor::logging::log<phosphor::logging::level::ERR>(
451 "Post code description data not available",
452 phosphor::logging::entry("PHASE_CODE=%d_0x%x", phase, index));
453 return -1;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800454}
455
Vijay Khemka63c99be2020-05-27 19:14:35 -0700456int plat_udbg_get_gpio_desc(uint8_t index, uint8_t* next, uint8_t* level,
457 uint8_t* def, uint8_t* length, uint8_t* buffer)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800458{
Vijay Khemka38183d62019-08-28 16:19:33 -0700459 nlohmann::json gpioObj;
460 std::string gpioPin;
461
462 /* Get gpio data stored in json file */
463 std::ifstream file(JSON_GPIO_DATA_FILE);
464 if (file)
465 {
466 file >> gpioObj;
467 file.close();
468 }
469 else
470 {
471 phosphor::logging::log<phosphor::logging::level::ERR>(
472 "GPIO pin description file not found",
473 phosphor::logging::entry("GPIO_PIN_DETAILS_FILE=%s",
474 JSON_GPIO_DATA_FILE));
475 return -1;
476 }
477
478 if (gpioObj.find(DEBUG_GPIO_KEY) == gpioObj.end())
479 {
480 phosphor::logging::log<phosphor::logging::level::ERR>(
481 "GPIO pin details not available",
482 phosphor::logging::entry("GPIO_JSON_KEY=%d", DEBUG_GPIO_KEY));
483 return -1;
484 }
485
486 auto obj = gpioObj[DEBUG_GPIO_KEY];
487 int objSize = obj.size();
488
489 for (int i = 0; i < objSize; i++)
490 {
491 if (obj[i].size() != GPIO_ARRAY_SIZE)
492 {
493 phosphor::logging::log<phosphor::logging::level::ERR>(
494 "Size of gpio array is incorrect",
495 phosphor::logging::entry("EXPECTED_SIZE=%d", GPIO_ARRAY_SIZE));
496 return -1;
497 }
498
499 gpioPin = obj[i][GPIO_PIN_INDEX];
500 if (index == stoul(gpioPin, nullptr, 16))
501 {
502 if (objSize != i + 1)
503 {
504 gpioPin = obj[i + 1][GPIO_PIN_INDEX];
505 *next = stoul(gpioPin, nullptr, 16);
506 }
507 else
508 {
509 *next = 0xff;
510 }
511
512 *level = obj[i][GPIO_LEVEL_INDEX];
513 *def = obj[i][GPIO_DEF_INDEX];
514 std::string gpioDesc = obj[i][GPIO_DESC_INDEX];
515 *length = gpioDesc.size();
516 memcpy(buffer, gpioDesc.data(), *length);
517 buffer[*length] = '\0';
518
519 return 0;
520 }
521 }
522
523 phosphor::logging::log<phosphor::logging::level::ERR>(
524 "GPIO pin description data not available",
525 phosphor::logging::entry("GPIO_PIN=0x%x", index));
526 return -1;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800527}
528
Bonnie Loe9baaff2022-11-08 16:36:21 +0800529static int getBiosVer(std::string& ver, size_t hostPosition)
Vijay Khemka88884b82019-08-27 15:23:07 -0700530{
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800531 std::string sysfwVersionFile = std::format(SYSFW_VER_FILE, hostPosition);
532 std::ifstream file(sysfwVersionFile);
533 if (!file)
Vijay Khemka88884b82019-08-27 15:23:07 -0700534 {
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800535 phosphor::logging::log<phosphor::logging::level::ERR>(
536 "Failed to open system firmware version file",
537 phosphor::logging::entry("FILE=%s", sysfwVersionFile.c_str()));
538 return -1;
Vijay Khemka88884b82019-08-27 15:23:07 -0700539 }
540
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800541 std::getline(file, ver);
542 file.close();
543
544 return 0;
Vijay Khemka88884b82019-08-27 15:23:07 -0700545}
546
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530547int sendBicCmd(uint8_t netFn, uint8_t cmd, uint8_t bicAddr,
548 std::vector<uint8_t>& cmdData, std::vector<uint8_t>& respData)
549{
550 static constexpr uint8_t lun = 0;
551
552 auto bus = getSdBus();
553
554 auto method = bus->new_method_call("xyz.openbmc_project.Ipmi.Channel.Ipmb",
555 "/xyz/openbmc_project/Ipmi/Channel/Ipmb",
556 "org.openbmc.Ipmb", "sendRequest");
557 method.append(bicAddr, netFn, lun, cmd, cmdData);
558
Patrick Williams855e0562025-11-04 22:17:33 -0500559 try
560 {
561 auto reply = bus->call(method);
562
Patrick Williams90903802025-11-05 00:00:39 -0500563 auto resp = reply.unpack<IpmbMethodType>();
Patrick Williams855e0562025-11-04 22:17:33 -0500564
565 respData = std::move(
566 std::get<std::remove_reference_t<decltype(respData)>>(resp));
567 }
568 catch (const sdbusplus::exception_t& e)
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530569 {
570 phosphor::logging::log<phosphor::logging::level::ERR>(
571 "Error reading from BIC");
572 return -1;
573 }
574
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530575 return 0;
576}
577
Vijay Khemka63c99be2020-05-27 19:14:35 -0700578int sendMeCmd(uint8_t netFn, uint8_t cmd, std::vector<uint8_t>& cmdData,
579 std::vector<uint8_t>& respData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -0700580{
581 auto bus = getSdBus();
582
583 if (DEBUG)
584 {
585 std::cout << "ME NetFn:cmd " << (int)netFn << ":" << (int)cmd << "\n";
586 std::cout << "ME req data: ";
587 for (auto d : cmdData)
588 {
589 std::cout << d << " ";
590 }
591 std::cout << "\n";
592 }
593
594 auto method = bus->new_method_call("xyz.openbmc_project.Ipmi.Channel.Ipmb",
595 "/xyz/openbmc_project/Ipmi/Channel/Ipmb",
596 "org.openbmc.Ipmb", "sendRequest");
597 method.append(meAddress, netFn, lun, cmd, cmdData);
598
Patrick Williams855e0562025-11-04 22:17:33 -0500599 try
600 {
601 auto reply = bus->call(method);
602
Patrick Williams90903802025-11-05 00:00:39 -0500603 auto resp = reply.unpack<IpmbMethodType>();
Patrick Williams855e0562025-11-04 22:17:33 -0500604
605 respData = std::move(
606 std::get<std::remove_reference_t<decltype(respData)>>(resp));
607 }
608 catch (const sdbusplus::exception_t& e)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -0700609 {
610 phosphor::logging::log<phosphor::logging::level::ERR>(
611 "Error reading from ME");
612 return -1;
613 }
614
Vijay Khemkadd14c0f2020-03-18 14:48:13 -0700615 if (DEBUG)
616 {
617 std::cout << "ME resp data: ";
618 for (auto d : respData)
619 {
620 std::cout << d << " ";
621 }
622 std::cout << "\n";
623 }
624
625 return 0;
626}
627
Willy Tue39f9392022-06-15 13:24:20 -0700628static int udbg_get_info_page(uint8_t, uint8_t page, uint8_t* next,
Vijay Khemka63c99be2020-05-27 19:14:35 -0700629 uint8_t* count, uint8_t* buffer)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800630{
Willy Tue39f9392022-06-15 13:24:20 -0700631 char line_buff[1000];
632 [[maybe_unused]] char* pres_dev = line_buff;
633 [[maybe_unused]] size_t pos = plat_get_fru_sel();
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800634 int ret;
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530635 std::string serialName = "SerialNumber";
636 std::string partName = "PartNumber";
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800637 std::string verDel = "VERSION=";
638 std::string verPath = "/etc/os-release";
BonnieLo-wiwynn21a79232023-03-09 16:42:48 +0800639 size_t hostPosition = 0;
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530640 size_t maxPosition;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800641
642 if (page == 1)
643 {
644 // Only update frame data while getting page 1
645
646 // initialize and clear frame
Patrick Williams13ce3792024-08-27 13:03:46 -0400647 frame_info.init();
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800648 snprintf(frame_info.title, 32, "SYS_Info");
649
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530650 bool platform = isMultiHostPlatform();
651 if (platform == true)
652 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530653 hostPosition = plat_get_fru_sel();
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530654 }
655
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530656 getMaxHostPosition(maxPosition);
Liora Guo4006fe72025-08-19 15:21:24 +0800657 std::string data;
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530658 if (hostPosition == BMC_POSITION || hostInstances == "0")
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530659 {
Liora Guo4006fe72025-08-19 15:21:24 +0800660 data = "FRU:" + getMotherBoardFruName();
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530661 }
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530662 else if (hostPosition != BMC_POSITION && hostPosition <= maxPosition)
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530663 {
Liora Guo4006fe72025-08-19 15:21:24 +0800664 if (getMotherBoardFruName() != "")
665 {
666 data = "FRU:" + getMotherBoardFruName();
667 }
668 else
669 {
670 data = "FRU:slot" + std::to_string(hostPosition);
671 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530672 }
Liora Guo4006fe72025-08-19 15:21:24 +0800673 frame_info.append(data);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530674
675 // FRU
Patrick Williams13ce3792024-08-27 13:03:46 -0400676 frame_info.append("SN:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800677 if (getFruData(data, serialName) != 0)
678 {
679 data = "Not Found";
680 }
Patrick Williams13ce3792024-08-27 13:03:46 -0400681 frame_info.append(data, 1);
682 frame_info.append("PN:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800683 if (getFruData(data, partName) != 0)
684 {
685 data = "Not Found";
686 }
Patrick Williams13ce3792024-08-27 13:03:46 -0400687 frame_info.append(data, 1);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800688
689 // LAN
690 getNetworkData(3, line_buff);
Patrick Williams13ce3792024-08-27 13:03:46 -0400691 frame_info.append("BMC_IP:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800692 frame_info.append(line_buff, 1);
693 getNetworkData(59, line_buff);
Patrick Williams13ce3792024-08-27 13:03:46 -0400694 frame_info.append("BMC_IPv6:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800695 frame_info.append(line_buff, 1);
696
697 // BMC ver
698 std::ifstream file(verPath);
699 if (file)
700 {
701 std::string line;
702 while (std::getline(file, line))
703 {
704 if (line.find(verDel) != std::string::npos)
705 {
706 std::string bmcVer = line.substr(verDel.size());
Patrick Williams13ce3792024-08-27 13:03:46 -0400707 frame_info.append("BMC_FW_ver:");
708 frame_info.append(bmcVer, 1);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800709 break;
710 }
711 }
712 }
713
Daniel Hsu3add4782024-11-26 09:59:17 +0800714 if (hostPosition != BMC_POSITION || hostInstances == "0")
Vijay Khemka88884b82019-08-27 15:23:07 -0700715 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530716 // BIOS ver
717 std::string biosVer;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800718 if (getBiosVer(biosVer, hostPosition) == 0)
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530719 {
Patrick Williams13ce3792024-08-27 13:03:46 -0400720 frame_info.append("BIOS_FW_ver:");
721 frame_info.append(biosVer, 1);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530722 }
Vijay Khemka88884b82019-08-27 15:23:07 -0700723 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800724
Vijay Khemka317999d2020-01-02 13:43:42 -0800725 /* TBD: Board ID needs implementation */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800726 // Board ID
727
728 // Battery - Use Escape sequence
Patrick Williams13ce3792024-08-27 13:03:46 -0400729 frame_info.append("Battery:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800730 frame_info.append(ESC_BAT " ", 1);
731 // frame_info.append(&frame_info, esc_bat, 1);
732
733 // MCU Version - Use Escape sequence
Patrick Williams13ce3792024-08-27 13:03:46 -0400734 frame_info.append("MCUbl_ver:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800735 frame_info.append(ESC_MCU_BL_VER, 1);
Patrick Williams13ce3792024-08-27 13:03:46 -0400736 frame_info.append("MCU_ver:");
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800737 frame_info.append(ESC_MCU_RUN_VER, 1);
738
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800739 // Sys config present device
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530740 if (hostPosition != BMC_POSITION)
741 {
Patrick Williams13ce3792024-08-27 13:03:46 -0400742 frame_info.append("Sys Conf. info:");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530743
744 // Dimm info
745 std::vector<std::string> data;
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530746 if (sysConfig(data, pos) == 0)
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530747 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530748 for (auto& info : data)
749 {
Patrick Williams13ce3792024-08-27 13:03:46 -0400750 frame_info.append(info, 1);
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530751 }
752 }
753 else
754 {
755 frame_info.append("Not Found", 1);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530756 }
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +0530757
758 // Processor info
759 std::string result;
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530760 if (procInfo(result, pos) != 0)
761 {
762 result = "Not Found";
763 }
Patrick Williams13ce3792024-08-27 13:03:46 -0400764 frame_info.append(result, 1);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530765 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800766
767 } // End of update frame
768
769 if (page > frame_info.pages)
770 {
771 return -1;
772 }
773
Vijay Khemka63c99be2020-05-27 19:14:35 -0700774 ret = frame_info.getPage(page, (char*)buffer, FRAME_PAGE_BUF_SIZE);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800775 if (ret < 0)
776 {
777 *count = 0;
778 return -1;
779 }
780 *count = (uint8_t)ret;
781
782 if (page < frame_info.pages)
783 *next = page + 1;
784 else
785 *next = 0xFF; // Set the value of next to 0xFF to indicate this is the
786 // last page
787
788 return 0;
789}
790
Peter Yinb340aa22024-07-08 16:07:55 +0800791static int udbg_get_postcode(uint8_t, uint8_t page, uint8_t* next,
792 uint8_t* count, uint8_t* buffer)
793{
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800794 // up to 70 codes can be displayed on 10 pages
795 static constexpr size_t maxPostcodes = 70;
Liora Guo4006fe72025-08-19 15:21:24 +0800796 bool platform = isMultiHostPlatform();
797 size_t hostPosition = 0;
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800798
Peter Yinb340aa22024-07-08 16:07:55 +0800799 if (page == 1)
800 {
801 // Initialize and clear frame (example initialization)
Patrick Williams13ce3792024-08-27 13:03:46 -0400802 frame_postcode.init();
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800803 snprintf(frame_postcode.title, 32, "POST CODE");
804 frame_postcode.max_page = 10;
Peter Yinb340aa22024-07-08 16:07:55 +0800805
Liora Guo4006fe72025-08-19 15:21:24 +0800806 if (platform)
807 getSelectorPosition(hostPosition);
808
Peter Yinb340aa22024-07-08 16:07:55 +0800809 // Synchronously get D-Bus connection
810 auto bus = sdbusplus::bus::new_default();
Liora Guo4006fe72025-08-19 15:21:24 +0800811 std::string serviceName =
812 BOOT_POSTCODE_SERVICE + std::to_string(hostPosition);
813 std::string objectPath =
814 BOOT_POSTCODE_OBJECTPATH + std::to_string(hostPosition);
Peter Yinb340aa22024-07-08 16:07:55 +0800815
816 // Build D-Bus method call
817 auto method = bus.new_method_call(
Liora Guo4006fe72025-08-19 15:21:24 +0800818 serviceName.c_str(), // Target service name
819 objectPath.c_str(), // Object path
820 BOOT_POSTCODE_INTERFACE, // Interface name
821 "GetPostCodes"); // Method name
Peter Yinb340aa22024-07-08 16:07:55 +0800822
Liora Guo4006fe72025-08-19 15:21:24 +0800823 method.append(uint16_t(1)); // Add method parameter, assuming it's pag
Peter Yinb340aa22024-07-08 16:07:55 +0800824 try
825 {
826 auto reply = bus.call(method); // Send synchronous method call
827
828 // Read postcode value
Patrick Williams90903802025-11-05 00:00:39 -0500829 auto postcodes = reply.unpack<std::vector<
830 std::tuple<std::vector<uint8_t>, std::vector<uint8_t>>>>();
Peter Yinb340aa22024-07-08 16:07:55 +0800831
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800832 // retrieve the latest postcodes
833 size_t numEntries = std::min(maxPostcodes, postcodes.size());
Cosmo Chou5e18a702024-10-06 09:27:15 +0800834 auto range = std::ranges::subrange(postcodes.rbegin(),
835 postcodes.rbegin() + numEntries);
836 for (const auto& [code, extra] : range)
Peter Yinb340aa22024-07-08 16:07:55 +0800837 {
Cosmo Chou5e18a702024-10-06 09:27:15 +0800838 std::string result;
839 result.reserve(2 * code.size());
840 for (const auto& byte : code)
Potin Lai3c9f5b62024-08-28 13:40:37 +0800841 {
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800842 result += std::format("{:02X}", byte);
Potin Lai3c9f5b62024-08-28 13:40:37 +0800843 }
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800844
Patrick Williams13ce3792024-08-27 13:03:46 -0400845 frame_postcode.append(result);
Cosmo Chou5a6917d2024-09-05 23:29:11 +0800846 if (frame_postcode.lines >= maxPostcodes)
847 {
848 break;
849 }
Peter Yinb340aa22024-07-08 16:07:55 +0800850 }
851 }
852 catch (const std::exception& e)
853 {
854 // Handle exceptions
855 std::cerr << "Error retrieving postcodes: " << e.what()
856 << std::endl;
857 return -1;
858 }
859 }
860
861 if (page > frame_postcode.pages)
862 {
863 return -1;
864 }
865
866 int ret = frame_postcode.getPage(page, (char*)buffer, FRAME_PAGE_BUF_SIZE);
867 if (ret < 0)
868 {
869 *count = 0;
870 return -1;
871 }
872 *count = (uint8_t)ret;
873
874 if (page < frame_postcode.pages)
875 *next = page + 1;
876 else
877 *next = 0xFF; // Set next to 0xFF to indicate last page
878 return 0;
879}
880
Vijay Khemka63c99be2020-05-27 19:14:35 -0700881int plat_udbg_get_frame_data(uint8_t frame, uint8_t page, uint8_t* next,
882 uint8_t* count, uint8_t* buffer)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800883{
884 switch (frame)
885 {
886 case 1: // info_page
887 return udbg_get_info_page(frame, page, next, count, buffer);
Peter Yinb340aa22024-07-08 16:07:55 +0800888 case 2: // Extra Post Code
889 return udbg_get_postcode(frame, page, next, count, buffer);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800890 default:
891 return -1;
892 }
893}
894
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400895static panel panel_main(size_t item)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800896{
897 // Update item list when select item 0
898 switch (item)
899 {
900 case 1:
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400901 return panels[std::to_underlying(panel::BOOT_ORDER)].select(0);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800902 case 2:
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400903 return panels[std::to_underlying(panel::POWER_POLICY)].select(0);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800904 default:
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400905 return panel::MAIN;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800906 }
907}
908
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400909static panel panel_boot_order(size_t selectedItemIndex)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800910{
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800911 static constexpr size_t sizeBootOrder = 6;
912 static constexpr size_t bootValid = 0x80;
913
914 std::vector<uint8_t> bootSeq;
915
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400916 ctrl_panel& bootOrderPanel = panels[std::to_underlying(panel::BOOT_ORDER)];
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800917
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530918 size_t pos = plat_get_fru_sel();
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800919
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800920 if (pos == FRU_ALL)
921 {
922 bootOrderPanel.item_num = 0;
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400923 return panel::BOOT_ORDER;
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800924 }
925
926 auto [bootObjPath, hostName] = ipmi::boot::objPath(pos);
927 ipmi::boot::getBootOrder(bootObjPath, bootSeq, hostName);
928
929 uint8_t& bootMode = bootSeq.front();
930
931 // One item is selected to set a new boot sequence.
932 // The selected item become the first boot order.
933 if (selectedItemIndex > 0 && selectedItemIndex < sizeBootOrder)
934 {
935 // Move the selected item to second element (the first one is boot mode)
936 std::rotate(bootSeq.begin() + 1, bootSeq.begin() + selectedItemIndex,
937 bootSeq.begin() + selectedItemIndex + 1);
938
939 bootMode |= bootValid;
940 try
941 {
942 ipmi::boot::setBootOrder(bootObjPath, bootSeq, hostName);
943 }
944 catch (const std::exception& e)
945 {
946 lg2::error("Fail to set boot order : {ERROR}", "ERROR", e);
Willy Tue39f9392022-06-15 13:24:20 -0700947 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800948
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800949 // refresh items
950 return bootOrderPanel.select(0);
951 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800952
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800953 // '*': boot flags valid, BIOS has not yet read
Patrick Williams010dee02024-08-16 15:19:44 -0400954 bootOrderPanel.item_str[0] =
955 std::string("Boot Order") + ((bootMode & bootValid) ? "*" : "");
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800956
957 static const std::unordered_map<uint8_t, const char*>
958 bootOrderMappingTable = {
959 {0x00, " USB device"}, {0x01, " Network v4"}, {0x02, " SATA HDD"},
960 {0x03, " SATA-CDROM"}, {0x04, " Other"}, {0x09, " Network v6"},
961 };
962
963 size_t validItem = 0;
964 for (size_t i = 1; i < sizeBootOrder; i++)
965 {
966 auto find = bootOrderMappingTable.find(bootSeq[i]);
967 if (find == bootOrderMappingTable.end())
Willy Tue39f9392022-06-15 13:24:20 -0700968 {
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800969 lg2::error("Unknown boot order : {BOOTORDER}", "BOOTORDER",
970 bootSeq[i]);
971 break;
Willy Tue39f9392022-06-15 13:24:20 -0700972 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800973
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800974 bootOrderPanel.item_str[i] = find->second;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800975
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800976 validItem++;
Willy Tue39f9392022-06-15 13:24:20 -0700977 }
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800978
979 bootOrderPanel.item_num = validItem;
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400980 return panel::BOOT_ORDER;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800981}
982
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400983static panel panel_power_policy(size_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800984{
Willy Tue39f9392022-06-15 13:24:20 -0700985/* To be cleaned */
986#if 0
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800987 uint8_t buff[32] = {0};
988 uint8_t res_len;
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530989 size_t pos = plat_get_fru_sel();
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800990 uint8_t policy;
Willy Tue39f9392022-06-15 13:24:20 -0700991 uint8_t pwr_policy_item_map[3] = {POWER_CFG_ON, POWER_CFG_LPS,
992 POWER_CFG_OFF};
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800993
Willy Tue39f9392022-06-15 13:24:20 -0700994 if (pos != FRU_ALL)
995 {
996 if (item > 0 && item <= sizeof(pwr_policy_item_map))
997 {
998 policy = pwr_policy_item_map[item - 1];
Patrick Williams13ce3792024-08-27 13:03:46 -0400999 pal_set_power_restore_policy(pos, &policy, nullptr);
Willy Tue39f9392022-06-15 13:24:20 -07001000 }
Patrick Williams13ce3792024-08-27 13:03:46 -04001001 pal_get_chassis_status(pos, nullptr, buff, &res_len);
Willy Tue39f9392022-06-15 13:24:20 -07001002 policy = (((uint8_t)buff[0]) >> 5) & 0x7;
1003 snprintf(panels[PANEL_POWER_POLICY].item_str[1], 32, "%cPower On",
1004 policy == POWER_CFG_ON ? '*' : ' ');
1005 snprintf(panels[PANEL_POWER_POLICY].item_str[2], 32, "%cLast State",
1006 policy == POWER_CFG_LPS ? '*' : ' ');
1007 snprintf(panels[PANEL_POWER_POLICY].item_str[3], 32, "%cPower Off",
1008 policy == POWER_CFG_OFF ? '*' : ' ');
1009 panels[PANEL_POWER_POLICY].item_num = 3;
1010 }
1011 else
1012 {
1013 panels[PANEL_POWER_POLICY].item_num = 0;
1014 }
1015#endif
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001016 return panel::POWER_POLICY;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001017}
1018
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001019ipmi_ret_t plat_udbg_control_panel(uint8_t cur_panel, uint8_t operation,
Patrick Williams5e589482024-07-13 16:18:13 -05001020 uint8_t item, uint8_t* count,
1021 uint8_t* buffer)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001022{
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001023 if (cur_panel > panelNum || cur_panel < std::to_underlying(panel::MAIN))
George Liu2f454992025-07-02 16:43:57 +08001024 return ipmi::ccParmOutOfRange;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001025
1026 // No more item; End of item list
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001027 if (item > panels[cur_panel].item_num)
George Liu2f454992025-07-02 16:43:57 +08001028 return ipmi::ccParmOutOfRange;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001029
1030 switch (operation)
1031 {
1032 case 0: // Get Description
1033 break;
1034 case 1: // Select item
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001035 cur_panel = std::to_underlying(panels[cur_panel].select(item));
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001036 item = 0;
1037 break;
1038 case 2: // Back
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001039 cur_panel = std::to_underlying(panels[cur_panel].parent);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001040 item = 0;
1041 break;
1042 default:
George Liu2f454992025-07-02 16:43:57 +08001043 return ipmi::ccParmOutOfRange;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001044 }
1045
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001046 buffer[0] = cur_panel;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001047 buffer[1] = item;
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001048 buffer[2] = std::size(panels[cur_panel].item_str[item]);
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001049
Patrick Williams13ce3792024-08-27 13:03:46 -04001050 if (buffer[2] > 0 && (buffer[2] + 3u) < FRAME_PAGE_BUF_SIZE)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001051 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -04001052 std::memcpy(&buffer[3], (panels[cur_panel].item_str[item]).c_str(),
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001053 buffer[2]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001054 }
1055 *count = buffer[2] + 3;
George Liu2f454992025-07-02 16:43:57 +08001056 return ipmi::ccSuccess;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001057}
1058
1059} // end of namespace ipmi