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.
10 #include <l4/re/mem_alloc>
11 #include <l4/re/util/cap_alloc>
13 #include <l4/cxx/exceptions>
14 #include <l4/re/error_helper>
22 Resource::dump(char const *ty, int indent) const
23 { printf("<%p>", this);
43 static char const * const irq_trigger[]
62 char const *tp = prefetchable() ? "pref" : "non-pref";
63 if (type() == Irq_res)
64 tp = irq_trigger[(flags() / Irq_type_base) & 0xf];
66 printf("%*.s%s%c [%014llx-%014llx %llx] %s (%dbit) (align=%llx flags=%lx)\n",
68 ty, provided() ? '*' : ' ',
69 s, e, (l4_uint64_t)size(),
71 is_64bit() ? 64 : 32, (unsigned long long)alignment(), flags());
76 Resource::dump(int indent) const
78 static char const *ty[] = { "INVALID", "IRQ ", "IOMEM ", "IOPORT",
81 dump(ty[type()], indent);
87 Resource_provider::_RS::request(Resource *parent, Device *,
88 Resource *child, Device *)
90 Addr start = child->start();
91 Addr end = child->end();
96 if (start < parent->start())
99 if (end > parent->end())
102 Resource_list::iterator r = _rl.begin();
105 if (r == _rl.end() || (*r)->start() > end)
108 _rl.insert(r, child);
109 child->parent(parent);
113 if ((*r)->end() >= start)
122 Resource_provider::_RS::alloc(Resource *parent, Device *pdev,
123 Resource *child, Device *cdev,
126 Resource_list::iterator p = _rl.begin();
127 Addr start = parent->start();
129 Size min_align = L4_PAGESIZE - 1;
131 if (p != _rl.end() && (*p)->start() == 0)
133 start = (*p)->end() + 1;
140 end = (*p)->start() - 1;
144 Size align = cxx::max<Size>(child->alignment(), min_align);
145 start = (start + align) & ~align; // pad to get alignment
147 if (start < end && end - start >= (Addr)child->size() - 1)
153 if (p == _rl.end() && !resize)
156 if (p == _rl.end() && resize)
158 end = start + child->size() - 1;
160 return false; // wrapped around
167 start = (*p)->end() + 1;
170 return request(parent, pdev, child, cdev);
173 void Mmio_data_space::alloc_ram(Size size, unsigned long alloc_flags)
175 long ma_flags = L4Re::Mem_alloc::Continuous;
177 ma_flags |= alloc_flags ? L4Re::Mem_alloc::Super_pages : 0;
179 _ds_ram = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
180 if (!_ds_ram.is_valid())
181 throw(L4::Out_of_memory(""));
183 L4Re::chksys(L4Re::Env::env()->mem_alloc()->alloc(size, _ds_ram.get(),
186 l4_size_t ds_size = size;
187 l4_addr_t phys_start;
188 L4Re::chksys(_ds_ram->phys(0, phys_start, ds_size));
190 throw(L4::Out_of_memory("not really"));
194 add_flags(Resource::F_fixed_size | Resource::F_fixed_addr);
196 L4Re::chksys(L4Re::Env::env()->rm()->attach(&_r, ds_size,
197 L4Re::Rm::Search_addr |