L4Re - L4 Runtime Environment
dataspace_impl.h
Go to the documentation of this file.
1 
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  * Alexander Warg <warg@os.inf.tu-dresden.de>
8  * economic rights: Technische Universit├Ąt Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction. Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License. This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #include <l4/re/dataspace>
24 #include <l4/sys/cxx/ipc_client>
25 
31 L4_RPC_DEF(L4Re::Dataspace::take);
32 L4_RPC_DEF(L4Re::Dataspace::release);
33 
34 namespace L4Re {
35 
36 long
37 Dataspace::__map(unsigned long offset, unsigned char *size, unsigned long flags,
38  l4_addr_t local_addr) const throw()
39 {
40  l4_addr_t spot = local_addr & ~(~0UL << l4_umword_t(*size));
41  l4_addr_t base = local_addr & (~0UL << l4_umword_t(*size));
43  r = L4::Ipc::Rcv_fpage::mem(base, *size, 0);
44 
46  long err = map_t::call(c(), offset, spot, flags, r, fp, l4_utcb());
47  if (L4_UNLIKELY(err < 0))
48  return err;
49 
50  *size = fp.rcv_order();
51  return err;
52 }
53 
54 long
55 Dataspace::map_region(l4_addr_t offset, unsigned long flags,
56  l4_addr_t min_addr, l4_addr_t max_addr) const throw()
57 {
58  min_addr = l4_trunc_page(min_addr);
59  max_addr = l4_round_page(max_addr);
60  unsigned char order = L4_LOG2_PAGESIZE;
61 
62  long err = 0;
63 
64  while (min_addr < max_addr)
65  {
66  unsigned char order_mapped;
67  order_mapped = order
68  = l4_fpage_max_order(order, min_addr, min_addr, max_addr, min_addr);
69  err = __map(offset, &order_mapped, flags, min_addr);
70  if (L4_UNLIKELY(err < 0))
71  return err;
72 
73  if (order > order_mapped)
74  order = order_mapped;
75 
76  min_addr += 1UL << order;
77  offset += 1UL << order;
78 
79  if (min_addr >= max_addr)
80  return 0;
81 
82  while (min_addr != l4_trunc_size(min_addr, order)
83  || max_addr < l4_round_size(min_addr + 1,order))
84  --order;
85  }
86 
87  return 0;
88 }
89 
90 
91 long
92 Dataspace::map(l4_addr_t offset, unsigned long flags,
93  l4_addr_t local_addr,
94  l4_addr_t min_addr, l4_addr_t max_addr) const throw()
95 {
96  min_addr = l4_trunc_page(min_addr);
97  max_addr = l4_round_page(max_addr);
98  local_addr = l4_trunc_page(local_addr);
99  unsigned char order
100  = l4_fpage_max_order(L4_LOG2_PAGESIZE, local_addr, min_addr, max_addr, local_addr);
101 
102  return __map(offset, &order, flags, local_addr);
103 }
104 
105 unsigned long
106 Dataspace::size() const throw()
107 {
108  Stats stats = Stats();
109  int err = info(&stats);
110  if (err < 0)
111  return 0;
112  return stats.size;
113 }
114 
115 long
116 Dataspace::flags() const throw()
117 {
118  Stats stats = Stats();
119  int err = info(&stats);
120  if (err < 0)
121  return err;
122  return stats.flags;
123 }
124 
125 };
unsigned long size
size
Definition: dataspace:86
long map_region(l4_addr_t offset, unsigned long flags, l4_addr_t min_addr, l4_addr_t max_addr) const
Map a part of a dataspace completely.
unsigned long size() const
Get size of a dataspace.
long allocate(l4_addr_t offset, l4_size_t size)
Allocate a range in the dataspace.
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
Definition: consts.h:389
Information about the dataspace.
Definition: dataspace:85
l4_addr_t l4_round_size(l4_umword_t value, unsigned char bits) L4_NOTHROW
Round value up to the next alignment with bits size.
Definition: consts.h:400
l4_addr_t l4_trunc_page(l4_addr_t address) L4_NOTHROW
Round an address down to the next lower page boundary.
Definition: consts.h:364
L4Re C++ Interfaces.
Definition: cmd_control:15
long copy_in(l4_addr_t dst_offs, L4::Ipc::Cap< Dataspace > src, l4_addr_t src_offs, unsigned long size)
Copy contents from another dataspace.
l4_addr_t l4_trunc_size(l4_addr_t address, unsigned char bits) L4_NOTHROW
Round an address down to the next lower flex page with size bits.
Definition: consts.h:375
long clear(l4_addr_t offset, unsigned long size)
Clear parts of a dataspace.
long info(Stats *stats)
Get information on the dataspace.
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition: consts.h:325
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition: compiler.h:234
unsigned long flags
flags
Definition: dataspace:87
long phys(l4_addr_t offset, l4_addr_t &phys_addr, l4_size_t &phys_size)
Get the physical addresses of a dataspace.
unsigned char l4_fpage_max_order(unsigned char order, l4_addr_t addr, l4_addr_t min_addr, l4_addr_t max_addr, l4_addr_t hotspot=0)
Determine maximum flex page size of a region.
Definition: __l4_fpage.h:693
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
#define L4_RPC_DEF(name)
Generate the definition of an RPC stub.
Definition: ipc_client:43
long flags() const
Get flags of the dataspace.
Dataspace interface.
long map(l4_addr_t offset, unsigned long flags, l4_addr_t local_addr, l4_addr_t min_addr, l4_addr_t max_addr) const
Request a flex-page mapping from the dataspace.
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
Generic RPC wrapper for L4 flex-pages.
Definition: ipc_types:321