2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
14 #include <l4/vbus/vbus_types.h>
17 #include <l4/re/dataspace>
18 #include <l4/re/util/cap_alloc>
27 typedef std::vector<Resource *> Resource_list;
32 virtual bool request(Resource *parent, Device *pdev,
33 Resource *child, Device *cdev) = 0;
34 virtual bool alloc(Resource *parent, Device *pdev,
35 Resource *child, Device *cdev, bool resize) = 0;
36 virtual ~Resource_space() {}
46 typedef l4_uint64_t Addr;
47 typedef l4_int64_t Size;
51 Invalid_res = L4VBUS_RESOURCE_INVALID,
52 Irq_res = L4VBUS_RESOURCE_IRQ,
53 Mmio_res = L4VBUS_RESOURCE_MEM,
54 Io_res = L4VBUS_RESOURCE_PORT,
62 F_hierarchical = 0x0200,
63 F_prefetchable = 0x0400,
64 F_size_aligned = 0x0800,
67 F_fixed_size = 0x4000,
68 F_fixed_addr = 0x8000,
70 F_width_64bit = 0x010000,
71 F_relative = 0x040000,
73 Irq_info_base = 0x100000,
74 Irq_info_factor = Irq_info_base / 2,
75 Irq_level = L4_IRQ_F_LEVEL * Irq_info_factor, //0x000000,
76 Irq_edge = L4_IRQ_F_EDGE * Irq_info_factor, //0x100000,
77 Irq_high = L4_IRQ_F_POS * Irq_info_factor, //0x000000,
78 Irq_low = L4_IRQ_F_NEG * Irq_info_factor, //0x200000,
79 Irq_both = L4_IRQ_F_BOTH * Irq_info_factor, //0x400000,
82 explicit Resource(unsigned long flags = 0)
83 : _f(flags | F_fixed_size), _p(0), _s(0), _e(0), _a(0) {}
85 Resource(unsigned long flags, Addr start, Addr end)
86 : _f(flags | F_fixed_size), _p(0), _s(start), _e(end), _a(end - start)
89 unsigned long flags() const { return _f; }
90 void add_flags(unsigned long flags) { _f |= flags; }
91 void del_flags(unsigned long flags) { _f &= ~flags; }
92 bool hierarchical() const { return _f & F_hierarchical; }
93 bool disabled() const { return _f & F_disabled; }
94 bool prefetchable() const { return _f & F_prefetchable; }
95 bool empty() const { return _f & F_empty; }
96 bool fixed_addr() const { return _f & F_fixed_addr; }
97 bool fixed_size() const { return _f & F_fixed_size; }
98 bool relative() const { return _f & F_relative; }
99 unsigned type() const { return _f & F_type_mask; }
103 void set_empty(bool empty)
112 void disable() { _f |= F_disabled; }
113 void enable() { _f &= ~F_disabled; }
115 virtual Resource_space *provided() const { return 0; }
117 void dump(char const *type, int indent) const;
118 virtual void dump(int indent = 0) const;
120 virtual bool compatible(Resource *consumer, bool pref = true) const
122 if (type() != consumer->type())
125 return prefetchable() == (consumer->prefetchable() && pref);
128 Resource *parent() const { return _p; }
129 void parent(Resource *p) { _p = p; }
131 virtual ~Resource() {}
137 void _start_end(Addr s, Addr e) { _s = s; _e = e; }
140 void set_empty() { _s = _e = 0; set_empty(true); }
141 void alignment(Size a)
144 del_flags(F_size_aligned);
147 bool valid() const { return flags() && _s <= _e; }
155 Addr start() const { return _s; }
156 Addr end() const { return _e; }
157 Size size() const { return (Size)_e + 1 - _s; }
159 bool contains(Resource const &o) const
160 { return start() <= o.start() && end() >= o.end(); }
162 void start(Addr start) { _e = start + (_e - _s); _s = start; }
175 void start_end(Addr start, Addr end)
177 _start_end(start, end);
181 void start_size(Addr start, Size s)
183 _start_end(start, start - 1 + s);
187 bool is_64bit() const { return flags() & F_width_64bit; }
189 l4_umword_t alignment() const
191 return flags() & F_size_aligned ? (_e - _s) : _a;
194 virtual l4_addr_t map_iomem() const
196 if (type() != Mmio_res)
198 return res_map_iomem(start(), size());
204 class Resource_provider : public Resource
207 class _RS : public Resource_space
210 typedef Resource::Addr Addr;
211 typedef Resource::Size Size;
215 bool request(Resource *parent, Device *pdev, Resource *child, Device *cdev);
216 bool alloc(Resource *parent, Device *pdev, Resource *child, Device *cdev,
225 explicit Resource_provider(unsigned long flags)
226 : Resource(flags), _rs() {}
228 Resource_provider(unsigned long flags, Addr s, Addr e)
229 : Resource(flags, s, e), _rs() {}
231 Resource_space *provided() const
234 ~Resource_provider() {}
238 class Root_resource : public Resource
244 Root_resource(unsigned long flags, Resource_space *rs)
245 : Resource(flags), _rs(rs) {}
247 Resource_space *provided() const { return _rs; }
248 void dump(int) const {}
254 class Mmio_data_space : public Resource
257 L4Re::Util::Auto_cap<L4Re::Dataspace>::Cap _ds_ram;
260 L4Re::Rm::Auto_region<l4_addr_t> _r;
262 Mmio_data_space(Size size, unsigned long alloc_flags = 0)
263 : Resource(Mmio_res, 0, size - 1)
265 alloc_ram(size, alloc_flags);
268 void alloc_ram(Size size, unsigned long alloc_flags);
270 l4_addr_t map_iomem() const