diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-10-09 03:11:34 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-10-09 03:11:34 +0200 |
commit | 3b8e32c9bbe0d909c34303da0ad36ef0ef5be852 (patch) | |
tree | ed22378979b2889a84615cf9f24de76359a95244 /pcilib/bank.c | |
parent | 21812f8d763fac8ee9bb3fdc593642b06f405a2b (diff) | |
download | pcitool-3b8e32c9bbe0d909c34303da0ad36ef0ef5be852.tar.gz pcitool-3b8e32c9bbe0d909c34303da0ad36ef0ef5be852.tar.bz2 pcitool-3b8e32c9bbe0d909c34303da0ad36ef0ef5be852.tar.xz pcitool-3b8e32c9bbe0d909c34303da0ad36ef0ef5be852.zip |
Introduce hashes
Diffstat (limited to 'pcilib/bank.c')
-rw-r--r-- | pcilib/bank.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/pcilib/bank.c b/pcilib/bank.c index 66ff739..24ddf1f 100644 --- a/pcilib/bank.c +++ b/pcilib/bank.c @@ -208,6 +208,7 @@ pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const ch pcilib_register_t i; pcilib_register_bank_t bank_id; pcilib_register_bank_addr_t bank_addr = 0; + pcilib_register_context_t *reg_ctx; const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); const pcilib_register_description_t *registers = model_info->registers; @@ -220,11 +221,16 @@ pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const ch } bank_addr = model_info->banks[bank_id].addr; + + // ToDo: we can use additionaly per-bank hashes + for (i = 0; registers[i].bits; i++) { + if ((!strcasecmp(registers[i].name, reg))&&((!bank)||(registers[i].bank == bank_addr))) return i; + } + } else { + HASH_FIND_STR(ctx->reg_hash, reg, reg_ctx); + if (reg_ctx) return reg_ctx->reg; } - - for (i = 0; registers[i].bits; i++) { - if ((!strcasecmp(registers[i].name, reg))&&((!bank)||(registers[i].bank == bank_addr))) return i; - } + return PCILIB_REGISTER_INVALID; }; |