blob: c3b7546ef27ef0baea16bbffba49681b7b21ee48 [file] [log] [blame]
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -08001/*
2// Copyright (c) 2018 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*/
16
17#pragma once
18
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080019#include "app.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080020#include "dbus_utility.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070021#include "generated/enums/pcie_device.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080022#include "query.hpp"
23#include "registries/privilege_registry.hpp"
24#include "utils/dbus_utils.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070025
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080026#include <boost/system/linux_error.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020027#include <sdbusplus/asio/property.hpp>
28#include <sdbusplus/unpack_properties.hpp>
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080029
30namespace redfish
31{
32
Gunnar Mills1214b7e2020-06-04 10:11:30 -050033static constexpr char const* pcieService = "xyz.openbmc_project.PCIe";
34static constexpr char const* pciePath = "/xyz/openbmc_project/PCIe";
35static constexpr char const* pcieDeviceInterface =
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080036 "xyz.openbmc_project.PCIe.Device";
37
Ed Tanousb5a76932020-09-29 16:16:58 -070038static inline void
zhanghch058d1b46d2021-04-01 11:18:24 +080039 getPCIeDeviceList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanousb5a76932020-09-29 16:16:58 -070040 const std::string& name)
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080041{
George Liu7a1dbc42022-12-07 16:03:22 +080042 dbus::utility::getSubTreePaths(
43 pciePath, 1, {},
44 [asyncResp, name](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -080045 const dbus::utility::MapperGetSubTreePathsResponse&
46 pcieDevicePaths) {
Ed Tanous002d39b2022-05-31 08:59:27 -070047 if (ec)
48 {
49 BMCWEB_LOG_DEBUG << "no PCIe device paths found ec: "
50 << ec.message();
51 // Not an error, system just doesn't have PCIe info
52 return;
53 }
54 nlohmann::json& pcieDeviceList = asyncResp->res.jsonValue[name];
55 pcieDeviceList = nlohmann::json::array();
56 for (const std::string& pcieDevicePath : pcieDevicePaths)
57 {
58 size_t devStart = pcieDevicePath.rfind('/');
59 if (devStart == std::string::npos)
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080060 {
Ed Tanous002d39b2022-05-31 08:59:27 -070061 continue;
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080062 }
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080063
Ed Tanous002d39b2022-05-31 08:59:27 -070064 std::string devName = pcieDevicePath.substr(devStart + 1);
65 if (devName.empty())
66 {
67 continue;
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080068 }
Ed Tanous002d39b2022-05-31 08:59:27 -070069 nlohmann::json::object_t pcieDevice;
Willy Tueddfc432022-09-26 16:46:38 +000070 pcieDevice["@odata.id"] = crow::utility::urlFromPieces(
71 "redfish", "v1", "Systems", "system", "PCIeDevices", devName);
Ed Tanous002d39b2022-05-31 08:59:27 -070072 pcieDeviceList.push_back(std::move(pcieDevice));
73 }
74 asyncResp->res.jsonValue[name + "@odata.count"] = pcieDeviceList.size();
George Liu7a1dbc42022-12-07 16:03:22 +080075 });
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080076}
77
John Edward Broadbent7e860f12021-04-08 15:57:16 -070078inline void requestRoutesSystemPCIeDeviceCollection(App& app)
Jason M. Billsadbe1922019-10-14 15:44:35 -070079{
Jason M. Billsadbe1922019-10-14 15:44:35 -070080 /**
81 * Functions triggers appropriate requests on DBus
82 */
Ed Tanous22d268c2022-05-19 09:39:07 -070083 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/PCIeDevices/")
Ed Tanoused398212021-06-09 17:05:54 -070084 .privileges(redfish::privileges::getPCIeDeviceCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070085 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070086 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070087 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
88 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +000089 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -070090 {
91 return;
92 }
Ed Tanous22d268c2022-05-19 09:39:07 -070093 if (systemName != "system")
94 {
95 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
96 systemName);
97 return;
98 }
Ed Tanous14766872022-03-15 10:44:42 -070099
Ed Tanous002d39b2022-05-31 08:59:27 -0700100 asyncResp->res.jsonValue["@odata.type"] =
101 "#PCIeDeviceCollection.PCIeDeviceCollection";
102 asyncResp->res.jsonValue["@odata.id"] =
103 "/redfish/v1/Systems/system/PCIeDevices";
104 asyncResp->res.jsonValue["Name"] = "PCIe Device Collection";
105 asyncResp->res.jsonValue["Description"] = "Collection of PCIe Devices";
106 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
107 asyncResp->res.jsonValue["Members@odata.count"] = 0;
108 getPCIeDeviceList(asyncResp, "Members");
109 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700110}
111
Ed Tanous0ec8b832022-03-14 14:56:47 -0700112inline std::optional<pcie_device::PCIeTypes>
Spencer Ku62cd45a2021-11-22 16:41:25 +0800113 redfishPcieGenerationFromDbus(const std::string& generationInUse)
114{
115 if (generationInUse ==
116 "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen1")
117 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700118 return pcie_device::PCIeTypes::Gen1;
Spencer Ku62cd45a2021-11-22 16:41:25 +0800119 }
120 if (generationInUse ==
121 "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen2")
122 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700123 return pcie_device::PCIeTypes::Gen2;
Spencer Ku62cd45a2021-11-22 16:41:25 +0800124 }
125 if (generationInUse ==
126 "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen3")
127 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700128 return pcie_device::PCIeTypes::Gen3;
Spencer Ku62cd45a2021-11-22 16:41:25 +0800129 }
130 if (generationInUse ==
131 "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen4")
132 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700133 return pcie_device::PCIeTypes::Gen4;
Spencer Ku62cd45a2021-11-22 16:41:25 +0800134 }
135 if (generationInUse ==
136 "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Gen5")
137 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700138 return pcie_device::PCIeTypes::Gen5;
Spencer Ku62cd45a2021-11-22 16:41:25 +0800139 }
Ed Tanouse825cbc2022-06-17 11:39:22 -0700140 if (generationInUse.empty() ||
141 generationInUse ==
142 "xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Unknown")
Spencer Ku62cd45a2021-11-22 16:41:25 +0800143 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700144 return pcie_device::PCIeTypes::Invalid;
Spencer Ku62cd45a2021-11-22 16:41:25 +0800145 }
146
147 // The value is not unknown or Gen1-5, need return an internal error.
148 return std::nullopt;
149}
150
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700151inline void requestRoutesSystemPCIeDevice(App& app)
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -0800152{
Ed Tanous22d268c2022-05-19 09:39:07 -0700153 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/PCIeDevices/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700154 .privileges(redfish::privileges::getPCIeDevice)
Ed Tanous002d39b2022-05-31 08:59:27 -0700155 .methods(boost::beast::http::verb::get)(
156 [&app](const crow::Request& req,
157 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700158 const std::string& systemName, const std::string& device) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000159 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700160 {
161 return;
162 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700163 if (systemName != "system")
164 {
165 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
166 systemName);
167 return;
168 }
169
Ed Tanous002d39b2022-05-31 08:59:27 -0700170 auto getPCIeDeviceCallback =
171 [asyncResp, device](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800172 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700173 const dbus::utility::DBusPropertiesMap& pcieDevProperties) {
174 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700175 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700176 BMCWEB_LOG_DEBUG
177 << "failed to get PCIe Device properties ec: " << ec.value()
178 << ": " << ec.message();
179 if (ec.value() ==
180 boost::system::linux_error::bad_request_descriptor)
181 {
182 messages::resourceNotFound(asyncResp->res, "PCIeDevice",
183 device);
184 }
185 else
186 {
187 messages::internalError(asyncResp->res);
188 }
Ed Tanous45ca1b82022-03-25 13:07:27 -0700189 return;
190 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700191
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200192 const std::string* manufacturer = nullptr;
193 const std::string* deviceType = nullptr;
194 const std::string* generationInUse = nullptr;
Myung Bae703f6742022-11-16 18:40:40 -0500195 const size_t* lanesInUse = nullptr;
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200196
197 const bool success = sdbusplus::unpackPropertiesNoThrow(
198 dbus_utils::UnpackErrorPrinter(), pcieDevProperties,
199 "Manufacturer", manufacturer, "DeviceType", deviceType,
Myung Bae703f6742022-11-16 18:40:40 -0500200 "LanesInUse", lanesInUse, "GenerationInUse", generationInUse);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200201
202 if (!success)
203 {
204 messages::internalError(asyncResp->res);
205 return;
206 }
207
Myung Bae703f6742022-11-16 18:40:40 -0500208 // The default value of LanesInUse is 0, and the field will be
209 // left as off if it is a default value.
210 if (lanesInUse != nullptr && *lanesInUse != 0)
211 {
212 asyncResp->res.jsonValue["PCIeInterface"]["LanesInUse"] =
213 *lanesInUse;
214 }
215
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200216 if (generationInUse != nullptr)
217 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700218 std::optional<pcie_device::PCIeTypes> redfishGenerationInUse =
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200219 redfishPcieGenerationFromDbus(*generationInUse);
220 if (!redfishGenerationInUse)
221 {
222 messages::internalError(asyncResp->res);
223 return;
224 }
Ed Tanous0ec8b832022-03-14 14:56:47 -0700225 if (*redfishGenerationInUse != pcie_device::PCIeTypes::Invalid)
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200226 {
Tony Leea9f68bb2022-10-20 19:35:38 +0800227 asyncResp->res.jsonValue["PCIeInterface"]["PCIeType"] =
228 *redfishGenerationInUse;
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200229 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200230 }
231
232 if (manufacturer != nullptr)
233 {
234 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
235 }
236
237 if (deviceType != nullptr)
238 {
239 asyncResp->res.jsonValue["DeviceType"] = *deviceType;
240 }
241
Ed Tanous002d39b2022-05-31 08:59:27 -0700242 asyncResp->res.jsonValue["@odata.type"] =
243 "#PCIeDevice.v1_4_0.PCIeDevice";
244 asyncResp->res.jsonValue["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000245 crow::utility::urlFromPieces("redfish", "v1", "Systems",
246 "system", "PCIeDevices", device);
Ed Tanous002d39b2022-05-31 08:59:27 -0700247 asyncResp->res.jsonValue["Name"] = "PCIe Device";
248 asyncResp->res.jsonValue["Id"] = device;
249
250 asyncResp->res.jsonValue["PCIeFunctions"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000251 crow::utility::urlFromPieces("redfish", "v1", "Systems",
252 "system", "PCIeDevices", device,
253 "PCIeFunctions");
Ed Tanous002d39b2022-05-31 08:59:27 -0700254 };
255 std::string escapedPath = std::string(pciePath) + "/" + device;
256 dbus::utility::escapePathForDbus(escapedPath);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200257 sdbusplus::asio::getAllProperties(
258 *crow::connections::systemBus, pcieService, escapedPath,
259 pcieDeviceInterface, std::move(getPCIeDeviceCallback));
Ed Tanous45ca1b82022-03-25 13:07:27 -0700260 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700261}
262
263inline void requestRoutesSystemPCIeFunctionCollection(App& app)
264{
265 /**
266 * Functions triggers appropriate requests on DBus
267 */
268 BMCWEB_ROUTE(app,
269 "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/")
Ed Tanoused398212021-06-09 17:05:54 -0700270 .privileges(redfish::privileges::getPCIeFunctionCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -0700271 .methods(boost::beast::http::verb::get)(
272 [&app](const crow::Request& req,
273 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
274 const std::string& device) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000275 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700276 {
277 return;
278 }
279
280 asyncResp->res.jsonValue["@odata.type"] =
281 "#PCIeFunctionCollection.PCIeFunctionCollection";
Willy Tueddfc432022-09-26 16:46:38 +0000282 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
283 "redfish", "v1", "Systems", "system", "PCIeDevices", device,
284 "PCIeFunctions");
Ed Tanous002d39b2022-05-31 08:59:27 -0700285 asyncResp->res.jsonValue["Name"] = "PCIe Function Collection";
286 asyncResp->res.jsonValue["Description"] =
287 "Collection of PCIe Functions for PCIe Device " + device;
288
289 auto getPCIeDeviceCallback =
290 [asyncResp, device](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800291 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700292 const dbus::utility::DBusPropertiesMap& pcieDevProperties) {
293 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700294 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700295 BMCWEB_LOG_DEBUG
296 << "failed to get PCIe Device properties ec: " << ec.value()
297 << ": " << ec.message();
298 if (ec.value() ==
299 boost::system::linux_error::bad_request_descriptor)
300 {
301 messages::resourceNotFound(asyncResp->res, "PCIeDevice",
302 device);
303 }
304 else
305 {
306 messages::internalError(asyncResp->res);
307 }
Ed Tanous45ca1b82022-03-25 13:07:27 -0700308 return;
309 }
Ed Tanous14766872022-03-15 10:44:42 -0700310
Ed Tanous002d39b2022-05-31 08:59:27 -0700311 nlohmann::json& pcieFunctionList =
312 asyncResp->res.jsonValue["Members"];
313 pcieFunctionList = nlohmann::json::array();
314 static constexpr const int maxPciFunctionNum = 8;
315 for (int functionNum = 0; functionNum < maxPciFunctionNum;
316 functionNum++)
317 {
318 // Check if this function exists by looking for a
319 // device ID
320 std::string devIDProperty =
321 "Function" + std::to_string(functionNum) + "DeviceId";
322 const std::string* property = nullptr;
323 for (const auto& propEntry : pcieDevProperties)
324 {
325 if (propEntry.first == devIDProperty)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700326 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700327 property = std::get_if<std::string>(&propEntry.second);
Ed Tanous45ca1b82022-03-25 13:07:27 -0700328 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700329 }
Nan Zhoufb0ecc32022-10-17 19:17:36 +0000330 if (property == nullptr || property->empty())
Ed Tanous002d39b2022-05-31 08:59:27 -0700331 {
Nan Zhoue28ce0e2022-10-13 22:28:36 +0000332 continue;
Ed Tanous002d39b2022-05-31 08:59:27 -0700333 }
334 nlohmann::json::object_t pcieFunction;
Willy Tueddfc432022-09-26 16:46:38 +0000335 pcieFunction["@odata.id"] = crow::utility::urlFromPieces(
336 "redfish", "v1", "Systems", "system", "PCIeDevices", device,
337 "PCIeFunctions", std::to_string(functionNum));
Ed Tanous002d39b2022-05-31 08:59:27 -0700338 pcieFunctionList.push_back(std::move(pcieFunction));
339 }
340 asyncResp->res.jsonValue["Members@odata.count"] =
341 pcieFunctionList.size();
342 };
343 std::string escapedPath = std::string(pciePath) + "/" + device;
344 dbus::utility::escapePathForDbus(escapedPath);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200345 sdbusplus::asio::getAllProperties(
346 *crow::connections::systemBus, pcieService, escapedPath,
347 pcieDeviceInterface, std::move(getPCIeDeviceCallback));
Ed Tanous45ca1b82022-03-25 13:07:27 -0700348 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700349}
350
351inline void requestRoutesSystemPCIeFunction(App& app)
352{
353 BMCWEB_ROUTE(
354 app,
355 "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700356 .privileges(redfish::privileges::getPCIeFunction)
Ed Tanous002d39b2022-05-31 08:59:27 -0700357 .methods(boost::beast::http::verb::get)(
358 [&app](const crow::Request& req,
359 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
360 const std::string& device, const std::string& function) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000361 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700362 {
363 return;
364 }
365 auto getPCIeDeviceCallback =
366 [asyncResp, device, function](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800367 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700368 const dbus::utility::DBusPropertiesMap& pcieDevProperties) {
369 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700370 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700371 BMCWEB_LOG_DEBUG
372 << "failed to get PCIe Device properties ec: " << ec.value()
373 << ": " << ec.message();
374 if (ec.value() ==
375 boost::system::linux_error::bad_request_descriptor)
376 {
377 messages::resourceNotFound(asyncResp->res, "PCIeDevice",
378 device);
379 }
380 else
381 {
382 messages::internalError(asyncResp->res);
383 }
Ed Tanous45ca1b82022-03-25 13:07:27 -0700384 return;
385 }
Ed Tanous168e20c2021-12-13 14:39:53 -0800386
Ed Tanous002d39b2022-05-31 08:59:27 -0700387 // Check if this function exists by looking for a device
388 // ID
389 std::string functionName = "Function" + function;
390 std::string devIDProperty = functionName + "DeviceId";
Ed Tanousb9d36b42022-02-26 21:42:46 -0800391
Ed Tanous002d39b2022-05-31 08:59:27 -0700392 const std::string* devIdProperty = nullptr;
393 for (const auto& property : pcieDevProperties)
394 {
395 if (property.first == devIDProperty)
396 {
397 devIdProperty = std::get_if<std::string>(&property.second);
398 continue;
399 }
400 }
Tony Lee973c1352022-11-18 13:48:27 +0800401 if (devIdProperty == nullptr || devIdProperty->empty())
Ed Tanous002d39b2022-05-31 08:59:27 -0700402 {
403 messages::resourceNotFound(asyncResp->res, "PCIeFunction",
404 function);
405 return;
406 }
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -0800407
Ed Tanous002d39b2022-05-31 08:59:27 -0700408 asyncResp->res.jsonValue["@odata.type"] =
409 "#PCIeFunction.v1_2_0.PCIeFunction";
410 asyncResp->res.jsonValue["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000411 crow::utility::urlFromPieces("redfish", "v1", "Systems",
412 "system", "PCIeDevices", device,
413 "PCIeFunctions", function);
Ed Tanous002d39b2022-05-31 08:59:27 -0700414 asyncResp->res.jsonValue["Name"] = "PCIe Function";
415 asyncResp->res.jsonValue["Id"] = function;
416 asyncResp->res.jsonValue["FunctionId"] = std::stoi(function);
417 asyncResp->res.jsonValue["Links"]["PCIeDevice"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +0000418 crow::utility::urlFromPieces("redfish", "v1", "Systems",
419 "system", "PCIeDevices", device);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700420
Ed Tanous002d39b2022-05-31 08:59:27 -0700421 for (const auto& property : pcieDevProperties)
422 {
423 const std::string* strProperty =
424 std::get_if<std::string>(&property.second);
425 if (property.first == functionName + "DeviceId")
426 {
427 asyncResp->res.jsonValue["DeviceId"] = *strProperty;
428 }
429 if (property.first == functionName + "VendorId")
430 {
431 asyncResp->res.jsonValue["VendorId"] = *strProperty;
432 }
433 if (property.first == functionName + "FunctionType")
434 {
435 asyncResp->res.jsonValue["FunctionType"] = *strProperty;
436 }
437 if (property.first == functionName + "DeviceClass")
438 {
439 asyncResp->res.jsonValue["DeviceClass"] = *strProperty;
440 }
441 if (property.first == functionName + "ClassCode")
442 {
443 asyncResp->res.jsonValue["ClassCode"] = *strProperty;
444 }
445 if (property.first == functionName + "RevisionId")
446 {
447 asyncResp->res.jsonValue["RevisionId"] = *strProperty;
448 }
449 if (property.first == functionName + "SubsystemId")
450 {
451 asyncResp->res.jsonValue["SubsystemId"] = *strProperty;
452 }
453 if (property.first == functionName + "SubsystemVendorId")
454 {
455 asyncResp->res.jsonValue["SubsystemVendorId"] =
456 *strProperty;
457 }
458 }
459 };
460 std::string escapedPath = std::string(pciePath) + "/" + device;
461 dbus::utility::escapePathForDbus(escapedPath);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200462 sdbusplus::asio::getAllProperties(
463 *crow::connections::systemBus, pcieService, escapedPath,
464 pcieDeviceInterface, std::move(getPCIeDeviceCallback));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700465 });
466}
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -0800467
468} // namespace redfish