X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/d1b1c8d9119229dbeed06cd252917e54a1cb77f6..0fd474df7001837bde53da0e42e83081827c9641:/lunaix-os/kernel/device/devdb.c diff --git a/lunaix-os/kernel/device/devdb.c b/lunaix-os/kernel/device/devdb.c index 09b6b5c..42452f8 100644 --- a/lunaix-os/kernel/device/devdb.c +++ b/lunaix-os/kernel/device/devdb.c @@ -1,11 +1,14 @@ #include #include #include +#include #include #include +LOG_MODULE("devdb") + static DECLARE_HASHTABLE(dev_registry, 32); static DECLARE_HASHTABLE(dev_byif, 8); static DEFINE_LLIST(dev_registry_flat); @@ -26,23 +29,38 @@ device_scan_drivers() hashtable_init(dev_registry); hashtable_init(dev_byif); - int idx = 0; + int idx = 0, errno; struct device_def* devdef; ldga_foreach(devdefs, struct device_def*, idx, devdef) { struct devclass* devc = &devdef->class; u32_t hash = hash_dev(devc->fn_grp, devc->device); - devc->hash = hash; + devdef->class_hash = hash; if (!devdef->name) { devdef->name = ""; } + errno = 0; + if (devdef->ad_tabulam) { + errno = devdef->ad_tabulam(devdef); + } + + if (errno) { + ERROR("driver unable to register %xh:%xh.%d (err=%d)", + devdef->class.fn_grp, + devdef->class.device, + devdef->class.variant, errno); + continue; + } + hashtable_hash_in(dev_registry, &devdef->hlist, hash); - hashtable_hash_in(dev_byif, &devdef->hlist_if, DEV_IF(devc->fn_grp)); + hashtable_hash_in(dev_byif, &devdef->hlist_if, DEV_VN(devc->fn_grp)); llist_append(&dev_registry_flat, &devdef->dev_list); } + + INFO("%d drivers registered", idx + 1); } static int @@ -60,7 +78,7 @@ devdef_byclass(struct devclass* devc) struct device_def *pos, *n; hashtable_hash_foreach(dev_registry, hash, pos, n, hlist) { - if (pos->class.hash != hash) { + if (pos->class_hash != hash) { continue; } if (devclass_eq(devc, &pos->class)) { @@ -91,7 +109,7 @@ device_definitions_byif(int if_type) struct device_def* devdef; \ ldga_foreach(dev_##stage, struct device_def*, idx, devdef) \ { \ - devdef->init(devdef); \ + device_chain_load_once(devdef); \ } \ }) #define device_load_on_stage(stage) __device_load_on_stage(stage) @@ -115,7 +133,7 @@ device_sysconf_load() } static int -__devdb_db_gonext(struct twimap* mapping) +__twimap_gonext_devtab(struct twimap* mapping) { struct device_def* current = twimap_index(mapping, struct device_def*); if (current->dev_list.next == &dev_registry_flat) { @@ -127,13 +145,13 @@ __devdb_db_gonext(struct twimap* mapping) } static void -__devdb_twifs_lsdb(struct twimap* mapping) +__twimap_read_devtab(struct twimap* mapping) { char flags[64]; struct device_def* def = twimap_index(mapping, struct device_def*); int meta = def->class.fn_grp; - ksnprintf(flags, 64, "if=%x,fn=%x", DEV_IF(meta), DEV_FN(meta)); + ksnprintf(flags, 64, "vn=%x, fn=%x", DEV_VN(meta), DEV_FN(meta)); twimap_printf(mapping, "%08xh:%04d \"%s\" %s\n", @@ -143,8 +161,8 @@ __devdb_twifs_lsdb(struct twimap* mapping) flags); } -void -__devdb_reset(struct twimap* map) +static void +__twimap_reset_devtab(struct twimap* map) { map->index = container_of(dev_registry_flat.next, struct device_def, dev_list); @@ -153,9 +171,6 @@ __devdb_reset(struct twimap* map) static void devdb_twifs_plugin() { - struct twimap* map = twifs_mapping(NULL, NULL, "devtab"); - map->reset = __devdb_reset; - map->read = __devdb_twifs_lsdb; - map->go_next = __devdb_db_gonext; + twimap_export_list(NULL, devtab, FSACL_aR, NULL); } EXPORT_TWIFS_PLUGIN(devdb, devdb_twifs_plugin); \ No newline at end of file