]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/dataspace_svr
043891ce6c31cbab90c44fe7e0a3ba80af1fc454
[l4.git] / l4 / pkg / l4re / util / include / dataspace_svr
1 // vi:ft=cpp
2 /*
3  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4  *               Alexander Warg <warg@os.inf.tu-dresden.de>,
5  *               Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
6  *     economic rights: Technische Universität Dresden (Germany)
7  *
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU General Public License 2.
10  * Please see the COPYING-GPL-2 file for details.
11  *
12  * As a special exception, you may use this file as part of a free software
13  * library without restriction.  Specifically, if other files instantiate
14  * templates or use macros or inline functions from this file, or you compile
15  * this file and link it with other files to produce an executable, this
16  * file does not by itself cause the resulting executable to be covered by
17  * the GNU General Public License.  This exception does not however
18  * invalidate any other reasons why the executable file might be covered by
19  * the GNU General Public License.
20  */
21 #pragma once
22
23 #include <cstring>
24 #include <cstddef>
25 #include <l4/sys/types.h>
26 #include <l4/cxx/list>
27 #include <l4/cxx/ipc_server>
28 #include <l4/cxx/ipc_stream>
29 #include <l4/cxx/minmax>
30 #include <l4/re/dataspace>
31 #include <l4/re/dataspace-sys.h>
32 #include <l4/re/protocols>
33
34 inline
35 L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s,
36                                L4Re::Dataspace::Stats const &st)
37 { s.put(st); return s; }
38
39 namespace L4Re { namespace Util {
40
41 /**
42  * \brief Dataspace server class.
43  * \ingroup api_l4re_util
44  *
45  * The default implementation of the interface provides a continiously
46  * mapped dataspace.
47  */
48 class Dataspace_svr
49 {
50 private:
51   typedef L4::Ipc::Gen_fpage<L4::Ipc::Snd_item> Snd_fpage;
52 public:
53
54   typedef Snd_fpage::Map_type Map_type;
55   typedef Snd_fpage::Cacheopt Cache_type;
56   enum Rw_type {
57       Read_only = 0,
58       Writable = 1,
59   };
60
61
62   Dataspace_svr() throw()
63   : _ds_start(0), _ds_size(0), _map_flags(Snd_fpage::Map),
64   _cache_flags(Snd_fpage::Cached)
65   {}
66
67   virtual ~Dataspace_svr() throw() {}
68
69   /**
70    * \brief Map a region of the dataspace
71    *
72    * \param offset      Offset to start within data space
73    * \param local_addr  Local address to map to.
74    * \param flags       map flags, see #Map_flags.
75    * \param min_addr    Defines start of receive window.
76    * \param max_addr    Defines end of receive window.
77    * \retval memory     Send fpage to map
78    *
79    * \return 0 on success, <0 on error
80    */
81   int map(l4_addr_t offset, l4_addr_t local_addr, unsigned long flags,
82           l4_addr_t min_addr, l4_addr_t max_addr, L4::Ipc::Snd_fpage &memory);
83
84   /**
85    * \brief A hook that is called as the first operation in each map
86    *        request.
87    * \param offs  Offs param to map
88    * \param flags Flags param to map
89    * \param min   Min param to map
90    * \param max   Max param to map
91    * \return < 0 on error and the map request will be aborted with that
92    *         error
93    *         >= 0: ok
94    *
95    * \see map
96    */
97   virtual int map_hook(l4_addr_t offs, unsigned long flags,
98                        l4_addr_t min, l4_addr_t max)
99   {
100     (void)offs; (void)flags; (void)min; (void)max;
101     return 0;
102   }
103
104   /**
105    * \brief Return physical address for a virtual address
106    *
107    * \param  offset    Offset into the dataspace
108    * \retval phys_addr Physical address
109    * \retval phys_size Size of continious physical region
110    *
111    * \return Zero on success, else failure
112    */
113   virtual int phys(l4_addr_t offset, l4_addr_t &phys_addr, l4_size_t &phys_size) throw();
114   
115   /**
116    * \brief Take a reference to this dataspace
117    *
118    * Default does nothing.
119    */
120   virtual void take() throw()
121   {}
122
123   /**
124    * \brief Release a reference to this dataspace
125    *
126    * \return Number of references to the dataspace
127    *
128    * Default does nothing and returns always zero.
129    */
130   virtual unsigned long release() throw()
131   { return 0; }
132
133   /**
134    * \brief Copy from src dataspace to this destination dataspace
135    *
136    * \param dst_offs Offset into the destination dataspace
137    * \param src_id   Local id of the source dataspace
138    * \param src_offs Offset into the source dataspace
139    * \param size     Number of bytes to copy
140    *
141    * \return Number of bytes copied
142    */
143   virtual unsigned long copy(unsigned long dst_offs, l4_umword_t src_id,
144                              unsigned long src_offs, unsigned long size) throw()
145     { (void)dst_offs; (void)src_id; (void)src_offs; (void)size; return 0; }
146   
147   /**
148    * \brief Clear a region in the dataspace
149    *
150    * \param offs Start of the region
151    * \param size Size of the region
152    */
153   virtual long clear(unsigned long offs, unsigned long size) const throw();
154   
155   /**
156    * \brief Define the size of the flexpage to map
157    *
158    * \return flexpage size
159    */
160   virtual unsigned long page_shift() const throw()
161   { return L4_LOG2_PAGESIZE; }
162
163   virtual bool is_static() const throw()
164   { return true; }
165
166   int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
167
168 protected:
169   unsigned long size() const throw()
170   { return _ds_size; }
171   unsigned long map_flags() const throw()
172   { return _map_flags; }
173   unsigned long rw_flags() const throw()
174   { return _rw_flags; }
175   unsigned long is_writable() const throw()
176   { return _rw_flags & Writable; }
177   unsigned long page_size() const throw()
178   { return 1UL << page_shift(); }
179   unsigned long round_size() const throw()
180   { return l4_round_size(size(), page_shift()); }
181   bool check_limit(l4_addr_t offset) const throw()
182   { return offset < round_size(); }
183
184 protected:
185   void size(unsigned long size) throw() { _ds_size = size; }
186
187   l4_addr_t _ds_start;
188   l4_size_t _ds_size;
189   Map_type _map_flags;
190   Cache_type _cache_flags;
191   Rw_type  _rw_flags;
192 };
193
194 }}