blob: b8eb1461782c68c4f634f1768a7a52e3941aaf0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include "drivers/chardev.h"
#include "drivers/memdevs.h"
#include "drivers/tty/tty.h"
#include "kernel.h"
#include "util/debug.h"
static list_t chardevs = LIST_INITIALIZER(chardevs);
void chardev_init()
{
tty_init();
memdevs_init();
}
long chardev_register(chardev_t *dev)
{
if (!dev || (NULL_DEVID == dev->cd_id) || !(dev->cd_ops))
{
return -1;
}
list_iterate(&chardevs, cd, chardev_t, cd_link)
{
if (dev->cd_id == cd->cd_id)
{
return -1;
}
}
list_insert_tail(&chardevs, &dev->cd_link);
return 0;
}
chardev_t *chardev_lookup(devid_t id)
{
list_iterate(&chardevs, cd, chardev_t, cd_link)
{
KASSERT(NULL_DEVID != cd->cd_id);
if (id == cd->cd_id)
{
return cd;
}
}
return NULL;
}
|