]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/server/src/vbus.h
update
[l4.git] / l4 / pkg / io / server / src / vbus.h
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #pragma once
10
11 #include <l4/cxx/avl_set>
12 #include <l4/cxx/ipc_server>
13 #include <l4/cxx/hlist>
14
15 #include <l4/vbus/vbus_types.h>
16
17 #include "vdevice.h"
18 #include "device.h"
19
20 namespace Vi {
21 class Sw_icu;
22
23 class System_bus : public Device, public Dev_feature, public L4::Server_object
24 {
25 public:
26   class Root_resource_factory : public cxx::H_list_item
27   {
28   public:
29     virtual Root_resource *create(System_bus *bus) const = 0;
30     Root_resource_factory()
31     { _factories.push_front(this); }
32
33     typedef cxx::H_list<Root_resource_factory> Factory_list;
34     static Factory_list _factories;
35   };
36
37   template< unsigned TYPE, typename RS >
38   class Root_resource_factory_t : public Root_resource_factory
39   {
40   public:
41     Root_resource *create(System_bus *bus) const
42     {
43       return new Root_resource(TYPE, new RS(bus));
44     }
45   };
46
47   System_bus();
48   ~System_bus();
49
50   // dispatch for the server object
51   int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
52   int dispatch(l4_umword_t, l4_uint32_t func, L4::Ipc::Iostream &ios);
53   bool match_hw_feature(Hw::Dev_feature const *) const { return false; }
54
55 private:
56   int request_resource(L4::Ipc::Iostream &ios);
57   int request_iomem(L4::Ipc::Iostream &ios);
58
59 public:
60   bool resource_allocated(Resource const *) const;
61
62   void dump_resources() const;
63
64 private:
65   struct Res_cmp
66   {
67     bool operator () (Resource const *a, Resource const *b) const
68     {
69       if (a->type() == b->type())
70         return a->lt_compare(b);
71       return a->type() < b->type();
72     }
73   };
74   //typedef std::set<Resource*, Res_cmp> Resource_set;
75
76 public:
77   typedef cxx::Avl_set<Resource*, Res_cmp> Resource_set;
78
79   Resource_set const *resource_set() const { return &_resources; }
80   Resource_set *resource_set() { return &_resources; }
81
82   void set_host(Device *d) { _host = d; }
83   Device *host() const { return _host; }
84   Sw_icu *sw_icu() const { return _sw_icu; }
85
86   void sw_icu(Sw_icu *icu) { _sw_icu = icu; }
87
88 private:
89   Resource_set _resources;
90   Device *_host;
91   Sw_icu *_sw_icu;
92
93 };
94
95 }