Commit 2c6089d1 authored by Alessandro Rubini's avatar Alessandro Rubini

fmc-sdb: fixed find_device

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent e8bbbf6c
...@@ -190,13 +190,14 @@ void fmc_show_sdb_tree(struct fmc_device *fmc) ...@@ -190,13 +190,14 @@ void fmc_show_sdb_tree(struct fmc_device *fmc)
EXPORT_SYMBOL(fmc_show_sdb_tree); EXPORT_SYMBOL(fmc_show_sdb_tree);
signed long fmc_find_sdb_device(struct sdb_array *tree, signed long fmc_find_sdb_device(struct sdb_array *tree,
uint64_t vid, uint32_t did) uint64_t vid, uint32_t did, unsigned long *sz)
{ {
signed long res = -ENODEV; signed long res = -ENODEV;
union sdb_record *r; union sdb_record *r;
struct sdb_product *p; struct sdb_product *p;
struct sdb_component *c; struct sdb_component *c;
int i, n = tree->len; int i, n = tree->len;
uint64_t last, first;
/* FIXME: what if the first interconnect is not at zero? */ /* FIXME: what if the first interconnect is not at zero? */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
...@@ -205,7 +206,8 @@ signed long fmc_find_sdb_device(struct sdb_array *tree, ...@@ -205,7 +206,8 @@ signed long fmc_find_sdb_device(struct sdb_array *tree,
p = &c->product; p = &c->product;
if (!IS_ERR(tree->subtree[i])) if (!IS_ERR(tree->subtree[i]))
res = fmc_find_sdb_device(tree->subtree[i], vid, did); res = fmc_find_sdb_device(tree->subtree[i],
vid, did, sz);
if (res > 0) if (res > 0)
return res + tree->baseaddr; return res + tree->baseaddr;
if (r->empty.record_type != sdb_type_device) if (r->empty.record_type != sdb_type_device)
...@@ -214,7 +216,11 @@ signed long fmc_find_sdb_device(struct sdb_array *tree, ...@@ -214,7 +216,11 @@ signed long fmc_find_sdb_device(struct sdb_array *tree,
continue; continue;
if (__be32_to_cpu(p->device_id) != did) if (__be32_to_cpu(p->device_id) != did)
continue; continue;
return __be64_to_cpu(c->addr_first); /* found */
last = __be64_to_cpu(c->addr_last);
first = __be64_to_cpu(c->addr_first);
if (sz) *sz = (typeof(*sz))(last + 1 -first);
return first + tree->baseaddr;
} }
return res; return res;
} }
......
...@@ -31,6 +31,6 @@ struct sdb_array { ...@@ -31,6 +31,6 @@ struct sdb_array {
extern int fmc_scan_sdb_tree(struct fmc_device *fmc, unsigned long address); extern int fmc_scan_sdb_tree(struct fmc_device *fmc, unsigned long address);
extern void fmc_show_sdb_tree(struct fmc_device *fmc); extern void fmc_show_sdb_tree(struct fmc_device *fmc);
extern signed long fmc_find_sdb_device(struct sdb_array *tree, extern signed long fmc_find_sdb_device(struct sdb_array *tree, uint64_t vendor,
uint64_t vendor, uint32_t device); uint32_t device, unsigned long *sz);
extern int fmc_free_sdb_tree(struct fmc_device *fmc); extern int fmc_free_sdb_tree(struct fmc_device *fmc);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment