2 * (c) 2008-2009 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/cxx/minmax>
12 #include "dataspace_cont.h"
15 Moe::Dataspace_cont::Dataspace_cont(void *start, unsigned long size,
17 unsigned char page_shift)
18 : Dataspace(size, flags, page_shift), _start((char*)start)
23 char *end = _start + l4_round_page(this->size());
24 for (char *x = (char *)l4_trunc_page((l4_addr_t)_start); x < end;
30 Moe::Dataspace::Address
31 Moe::Dataspace_cont::address(l4_addr_t offset,
32 Ds_rw rw, l4_addr_t hot_spot,
33 l4_addr_t min, l4_addr_t max) const
35 if (!check_limit(offset))
36 return Address(-L4_ERANGE);
38 min = l4_trunc_page(min);
39 //max = l4_round_page(max);
41 l4_addr_t adr = l4_addr_t(_start) + offset;
42 unsigned char order = L4_PAGESHIFT;
44 while (order < 30 /* limit to 1GB flexpage */)
46 l4_addr_t map_base = l4_trunc_size(adr, order + 1);
47 if (map_base < l4_addr_t(_start))
50 if (map_base + (1UL << (order + 1)) -1 > (l4_addr_t(_start) + round_size() - 1))
53 map_base = l4_trunc_size(hot_spot, order + 1);
57 if (map_base + (1UL << (order + 1)) -1 > max)
60 l4_addr_t mask = ~(~0UL << (order + 1));
61 if (hot_spot == ~0UL || ((adr ^ hot_spot) & mask))
67 l4_addr_t map_base = l4_trunc_size(adr, order);
68 l4_addr_t offs = adr & ~(~0UL << order);
73 return Address(map_base, order, rw, offs);
76 void Moe::Dataspace_cont::unmap(bool ro) const throw()
78 unsigned long _size = round_size();
83 Address addr = address(offs, Writable, ~0);
85 = l4_fpage_set_rights(addr.fp(), ro ? L4_FPAGE_W : L4_FPAGE_RWX);
86 l4_task_unmap(L4_BASE_TASK_CAP, fp, L4_FP_OTHER_SPACES);
87 _size -= (1UL << l4_fpage_size(fp));
88 offs += (1UL << l4_fpage_size(fp));
93 Moe::Dataspace_cont::dma_map(Dma_space *dma, l4_addr_t offset, l4_size_t *size,
94 Dma_attribs dma_attr, Dma_space::Direction dir,
95 Dma_space::Dma_addr *dma_addr)
101 if (offset >= this->size())
104 *dma_addr = (l4_addr_t)start() + offset;
105 *size = cxx::min(*size, (l4_size_t)(this->size() - offset));
110 Moe::Dataspace_cont::dma_unmap(Dma_space *, l4_addr_t, l4_size_t,
111 Dma_attribs, Dma_space::Direction)