#include <lunaix/device.h>
#include <lunaix/fs/twifs.h>
#include <lunaix/status.h>
+#include <lunaix/syslog.h>
-#include <lib/hash.h>
+#include <klibc/hash.h>
-#include <klibc/stdio.h>
+#include <klibc/strfmt.h>
+
+LOG_MODULE("devdb")
static DECLARE_HASHTABLE(dev_registry, 32);
static DECLARE_HASHTABLE(dev_byif, 8);
static DEFINE_LLIST(dev_registry_flat);
-static struct device* adhoc_devcat;
+static struct device_cat* adhoc_devcat;
static inline u32_t
hash_dev(u32_t fngrp, u32_t dev)
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 = "<unspecified>";
}
+ 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
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)) {
return &dev_byif[__hashkey(dev_byif, if_type)];
}
-#define device_load_on_stage(stage) \
+#define __device_load_on_stage(stage) \
({ \
int idx = 0; \
struct device_def* devdef; \
- ldga_foreach(dev_ld_##stage, struct device_def*, idx, 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)
void
-device_earlystage()
+device_onboot_load()
{
- device_load_on_stage(early);
+ device_load_on_stage(load_onboot);
}
void
-device_timerstage()
+device_postboot_load()
{
- device_load_on_stage(aftertimer);
+ device_load_on_stage(load_postboot);
}
void
-device_poststage()
+device_sysconf_load()
{
- device_load_on_stage(post);
+ device_load_on_stage(load_sysconf);
}
static int
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,
- "%xh:%d \"%s\" %s\n",
+ "%08xh:%04d \"%s\" %s\n",
def->class.fn_grp,
def->class.device,
def->name,