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>
This commit is contained in:
parent
e4b8e97c1a
commit
7feb7ef914
1 changed files with 26 additions and 13 deletions
|
@ -186,18 +186,37 @@ static void show(const struct shell *sh, pcie_bdf_t bdf, bool dump)
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ static int cmd_pcie_ls(const struct shell *sh, size_t argc, char **argv)
|
|||
|
||||
/* 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue