]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/server/src/vicu.h
update
[l4.git] / l4 / pkg / io / server / src / vicu.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/sys/capability>
12 #include <l4/sys/irq>
13 #include <l4/sys/icu>
14
15 #include <l4/cxx/ipc_server>
16 #include <l4/cxx/avl_tree>
17 #include <l4/cxx/list>
18
19 #include <l4/re/util/cap_alloc>
20
21 #include "irqs.h"
22 #include "vdevice.h"
23
24 namespace Vi {
25
26 class Sw_icu : public Device, public Dev_feature, public L4::Server_object
27 {
28 public:
29   Sw_icu();
30   virtual ~Sw_icu();
31
32   int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
33
34   char const *hid() const { return "L40009"; }
35   int dispatch(l4_umword_t, l4_uint32_t func, L4::Ipc::Iostream &ios);
36   bool match_hw_feature(Hw::Dev_feature const *) const { return false; }
37
38   bool add_irqs(Resource const *r);
39   bool add_irq(unsigned n, unsigned flags, Io_irq_pin *be);
40   int alloc_irq(unsigned flags, Io_irq_pin *be);
41   bool irqs_allocated(Resource const *r);
42
43 private:
44   int bind_irq(l4_msgtag_t tag, unsigned irqn, L4::Ipc::Snd_fpage const &irqc);
45   int unbind_irq(l4_msgtag_t tag, unsigned irqn, L4::Ipc::Snd_fpage const &irqc);
46   int unmask_irq(l4_msgtag_t tag, unsigned irqn);
47   int set_mode(l4_msgtag_t tag, unsigned irqn, l4_umword_t mode);
48
49
50   class Sw_irq_pin : public cxx::Avl_tree_node
51   {
52   private:
53     enum
54     {
55       S_bound = 1,
56       S_unmask_via_icu = 2,
57     };
58
59     unsigned _state;
60     unsigned _irqn;
61     Io_irq_pin *_master;
62     L4Re::Util::Auto_cap<L4::Irq>::Cap _irq;
63
64   public:
65     enum Irq_type
66     {
67       S_irq_type_mask  = Resource::Irq_type_mask,
68     };
69
70     enum
71     {
72       S_allow_set_mode = 4,
73       S_user_mask = S_irq_type_mask | S_allow_set_mode
74     };
75
76     typedef unsigned Key_type;
77
78     static unsigned key_of(Sw_irq_pin const *o) { return o->_irqn; }
79
80     Sw_irq_pin(Io_irq_pin *master, unsigned irqn, unsigned flags)
81     : _state(flags & S_user_mask), _irqn(irqn), _master(master)
82     {
83       master->add_sw_irq();
84     }
85
86     unsigned irqn() const { return _irqn; }
87     L4::Cap<L4::Irq> irq() const { return _irq.get(); }
88
89     bool bound() const { return _state & S_bound; }
90     bool unmask_via_icu() const { return _state & S_unmask_via_icu; }
91     unsigned type() const { return _state & S_irq_type_mask; }
92     unsigned l4_type() const;
93     int bind(L4::Cap<void> rc);
94     int unmask() { return _master->unmask(); }
95     int unbind();
96     int set_mode(l4_umword_t mode);
97     int trigger() const;
98
99   protected:
100     int _unbind();
101 //    int share(L4Re::Util::Auto_cap<L4::Irq>::Cap const &irq);
102     void allocate_master_irq();
103   };
104
105   typedef cxx::Avl_tree<Sw_irq_pin, Sw_irq_pin> Irq_set;
106   Irq_set _irqs;
107
108 public:
109   static Kernel_irq_pin *real_irq(unsigned n);
110
111   enum
112   {
113     S_allow_set_mode = Sw_irq_pin::S_allow_set_mode,
114   };
115
116   static void *irq_loop(void*);
117   void set_host(Device *d) { _host = d; }
118   Device *host() const { return _host; }
119
120 private:
121   Device *_host;
122 };
123
124 }