pcie: shell: Use pcie_scan() for scanning for devices
Use the new pcie_scan() API instead of doing a brute-force scan.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
diff --git a/drivers/pcie/host/shell.c b/drivers/pcie/host/shell.c
index 307a2c9..4137aec 100644
--- a/drivers/pcie/host/shell.c
+++ b/drivers/pcie/host/shell.c
@@ -186,18 +186,37 @@
}
}
+struct scan_cb_data {
+ const struct shell *sh;
+ bool dump;
+};
+
+static bool scan_cb(pcie_bdf_t bdf, pcie_id_t id, void *cb_data)
+{
+ struct scan_cb_data *data = cb_data;
+
+ show(data->sh, bdf, data->dump);
+
+ return true;
+}
+
static int cmd_pcie_ls(const struct shell *sh, size_t argc, char **argv)
{
pcie_bdf_t bdf = PCIE_BDF_NONE;
- bool dump = false;
- int bus;
- int dev;
- int func;
+ struct scan_cb_data data = {
+ .sh = sh,
+ .dump = false,
+ };
+ struct pcie_scan_opt scan_opt = {
+ .cb = scan_cb,
+ .cb_data = &data,
+ .flags = (PCIE_SCAN_RECURSIVE | PCIE_SCAN_CB_ALL),
+ };
for (int i = 1; i < argc; i++) {
/* Check dump argument */
if (strncmp(argv[i], "dump", 4) == 0) {
- dump = true;
+ data.dump = true;
continue;
}
@@ -214,17 +233,11 @@
/* Show only specified device */
if (bdf != PCIE_BDF_NONE) {
- show(sh, bdf, dump);
+ show(sh, bdf, data.dump);
return 0;
}
- for (bus = 0; bus <= PCIE_MAX_BUS; ++bus) {
- for (dev = 0; dev <= PCIE_MAX_DEV; ++dev) {
- for (func = 0; func <= PCIE_MAX_FUNC; ++func) {
- show(sh, PCIE_BDF(bus, dev, func), dump);
- }
- }
- }
+ pcie_scan(&scan_opt);
return 0;
}