Skip to content

Commit

Permalink
sdb: support any fs.depth starting value.
Browse files Browse the repository at this point in the history
Unlike the {E,P}BPM and FOFB SDB filesystems, which start at fs.depth=1,
the Timing SDB filesystem has a single item, at fs.depth=0. Instead of
hardcoding anything specific, we can simply support any starting depth.

Without this change, printing Timing SDB information hits the
indentation assertion, due to underflow when subtracting 1 from 0.
  • Loading branch information
ericonr committed Nov 19, 2024
1 parent 75631bc commit 2192e40
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions util/sdb.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cassert>
#include <limits>

#include <endian.h>
#include <limits.h>
Expand Down Expand Up @@ -44,15 +45,16 @@ static struct sdbfs sdbfs_init(struct pcie_bars *bars)
return fs;
}

static void print_sdb(const struct sdb_device_info &devinfo, const struct sdb_product *product, const struct sdbfs &fs)
static void print_sdb(const struct sdb_device_info &devinfo, const struct sdb_product *product, const struct sdbfs &fs, size_t &min_depth)
{
const char indentation[] = " ";
const size_t indent = 4;
static_assert(((sizeof indentation) - 1) % indent == 0);
const size_t max_indent = ((sizeof indentation) - 1) / indent;

/* fs.depth starts at 1 */
size_t depth = fs.depth - 1;
/* fs.depth can start at different values depending on how the SDB was created */
min_depth = std::min((size_t)fs.depth, min_depth);
size_t depth = fs.depth - min_depth;
assert(depth <= max_indent);

static_assert(sizeof product->name == 19);
Expand All @@ -70,6 +72,7 @@ std::optional<struct sdb_device_info> read_sdb(struct pcie_bars *bars, device_ma
struct sdbfs fs = sdbfs_init(bars);
defer _(nullptr, [&fs](...){sdbfs_dev_destroy(&fs);});

auto min_depth = std::numeric_limits<size_t>::max();
struct sdb_device *d;
while((d = sdbfs_scan(&fs, 0))) {
struct sdb_component *c = &d->sdb_component;
Expand All @@ -89,7 +92,7 @@ std::optional<struct sdb_device_info> read_sdb(struct pcie_bars *bars, device_ma
else pos--;
}
} else {
print_sdb(devinfo, p, fs);
print_sdb(devinfo, p, fs, min_depth);
}
}
return std::nullopt;
Expand Down

0 comments on commit 2192e40

Please sign in to comment.