Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4667 | trochtova | 1 | #include <futex.h> |
2 | #include <assert.h> |
||
3 | |||
4 | #include "isa.h" |
||
5 | |||
6 | LIST_INITIALIZE(isa_bridges_list); |
||
7 | LIST_INITIALIZE(isa_drivers_list); |
||
8 | |||
9 | static atomic_t isa_bus_futex = FUTEX_INITIALIZER; |
||
10 | |||
11 | static void isa_probe_all(bridge_to_isa_t *bridge); |
||
12 | static void isa_drv_probe(isa_drv_t *drv); |
||
13 | |||
14 | int isa_bus_init() |
||
15 | { |
||
16 | return 1; |
||
17 | } |
||
18 | |||
19 | void isa_register_bridge(bridge_to_isa_t *bridge) |
||
20 | { |
||
21 | futex_down(&isa_bus_futex); |
||
22 | |||
23 | printf("ISA: registering new sth-to-isa bridge.\n"); |
||
24 | |||
25 | // add bridge to the list |
||
26 | list_append(&(bridge->link), &isa_bridges_list); |
||
27 | |||
28 | // call probe function of all registered drivers of isa devices |
||
29 | isa_probe_all(bridge); |
||
30 | |||
31 | futex_up(&isa_bus_futex); |
||
32 | } |
||
33 | |||
34 | void isa_register_driver(isa_drv_t *drv) |
||
35 | { |
||
36 | assert(drv->name != NULL); |
||
37 | |||
38 | futex_down(&isa_bus_futex); |
||
39 | |||
40 | printf("ISA: registering new driver '%s'.\n", drv->name); |
||
41 | |||
42 | // add bridge to the list |
||
43 | list_append(&(drv->link), &isa_drivers_list); |
||
44 | |||
45 | // call driver's probe function on all registered bridges |
||
46 | isa_drv_probe(drv); |
||
47 | |||
48 | futex_up(&isa_bus_futex); |
||
49 | } |
||
50 | |||
51 | static void isa_probe_all(bridge_to_isa_t *bridge) |
||
52 | { |
||
53 | link_t *item = isa_drivers_list.next; |
||
54 | isa_drv_t *drv = NULL; |
||
55 | |||
56 | while (item != &isa_drivers_list) { |
||
57 | drv = list_get_instance(item, isa_drv_t, link); |
||
58 | if (drv->ops != NULL && drv->ops->probe != NULL) { |
||
59 | drv->ops->probe(bridge); |
||
60 | } |
||
61 | item = item->next; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | static void isa_drv_probe(isa_drv_t *drv) |
||
66 | { |
||
67 | link_t *item = isa_bridges_list.next; |
||
68 | bridge_to_isa_t *bridge = NULL; |
||
69 | |||
70 | if (drv->ops != NULL && drv->ops->probe != NULL) { |
||
71 | while (item != &isa_bridges_list) { |
||
72 | bridge = list_get_instance(item, bridge_to_isa_t, link); |
||
73 | { |
||
74 | drv->ops->probe(bridge); |
||
75 | } |
||
76 | item = item->next; |
||
77 | } |
||
78 | } |
||
79 | } |