1 /**
2  * \file
3  * \brief Data space C interface.
4  */
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 #pragma once
24 
25 /**
26  * \defgroup api_l4re_c_ds Dataspace interface
27  * \ingroup api_l4re_c
28  * \brief Dataspace C interface.
29  */
30 
31 #include <l4/sys/types.h>
32 
33 EXTERN_C_BEGIN
34 
35 /**
36  * \brief Dataspace type
37  * \ingroup api_l4re_c_ds
38  */
39 typedef l4_cap_idx_t l4re_ds_t;
40 typedef l4_uint64_t l4re_ds_size_t;
41 typedef l4_uint64_t l4re_ds_offset_t;
42 typedef l4_uint64_t l4re_ds_map_addr_t;
43 typedef unsigned long l4re_ds_flags_t;
44 
45 /**
46  * \brief Information about the data space.
47  * \ingroup api_l4re_c_ds
48  */
49 typedef struct {
50   l4re_ds_size_t size;    ///< size
51   l4re_ds_flags_t flags;  ///< flags
52 } l4re_ds_stats_t;
53 
54 /**
55  * Flags to specify the memory mapping type of a request
56  * \ingroup api_l4re_c_ds
57  */
58 enum l4re_ds_map_flags {
59   L4RE_DS_F_R   = L4_FPAGE_RO,
60   L4RE_DS_F_W   = L4_FPAGE_W,
61   L4RE_DS_F_X   = L4_FPAGE_X,
62   L4RE_DS_F_RW  = L4_FPAGE_RW,
63   L4RE_DS_F_RX  = L4_FPAGE_RX,
64   L4RE_DS_F_RWX = L4_FPAGE_RWX,
65 
66   L4RE_DS_F_RIGHTS_MASK = 0x0f,
67 
68   L4RE_DS_F_NORMAL        = 0x00, ///< request normal memory mapping
69   L4RE_DS_F_CACHEABLE     = L4RE_DS_F_NORMAL, ///< request normal memory mapping
70   L4RE_DS_F_BUFFERABLE    = 0x10, ///< request bufferable (write buffered) mappings
71   L4RE_DS_F_UNCACHEABLE   = 0x20, ///< request uncacheable memory mappings
72   L4RE_DS_F_CACHING_MASK  = 0x30, ///< mask for caching flags
73   L4RE_DS_F_CACHING_SHIFT = 4,    ///< shift value for caching flags
74 };
75 
76 /**
77  * \internal
78  * \ingroup api_l4re_c_ds
79  * \see L4Re::Dataspace::map
80  */
81 L4_CV int
82 l4re_ds_map(l4re_ds_t ds,
83             l4re_ds_offset_t offset,
84             l4re_ds_flags_t flags,
85             l4re_ds_map_addr_t local_addr,
86             l4re_ds_map_addr_t min_addr,
87             l4re_ds_map_addr_t max_addr) L4_NOTHROW;
88 
89 /**
90  * \internal
91  * \ingroup api_l4re_c_ds
92  * \see L4Re::Dataspace::map_page
93  */
94 L4_CV int
95 l4re_ds_map_region(l4re_ds_t ds,
96                    l4re_ds_offset_t offset,
97                    l4re_ds_flags_t flags,
98                    l4re_ds_map_addr_t min_addr,
99                    l4re_ds_map_addr_t max_addr) L4_NOTHROW;
100 
101 /**
102  * \ingroup api_l4re_c_ds
103  *
104  * \return 0 on success, <0 on errors
105  * \see L4Re::Dataspace::clear
106  */
107 L4_CV long
108 l4re_ds_clear(l4re_ds_t ds, l4re_ds_offset_t offset,
109               l4re_ds_size_t size) L4_NOTHROW;
110 
111 /**
112  * \ingroup api_l4re_c_ds
113  * \return 0 on success, <0 on errors
114  * \see L4Re::Dataspace::allocate
115  */
116 L4_CV long
117 l4re_ds_allocate(l4re_ds_t ds,
118                  l4re_ds_offset_t offset,
119                  l4re_ds_size_t size) L4_NOTHROW;
120 
121 /**
122  * \ingroup api_l4re_c_ds
123  * \return 0 on success, <0 on errors
124  * \see L4Re::Dataspace::copy_in
125  */
126 L4_CV int
127 l4re_ds_copy_in(l4re_ds_t ds, l4re_ds_offset_t dst_offs,
128                 l4re_ds_t src, l4re_ds_offset_t src_offs,
129                 l4re_ds_size_t size) L4_NOTHROW;
130 
131 /**
132  * \ingroup api_l4re_c_ds
133  * \return Size of the dataspace in bytes.
134  * \see L4Re::Dataspace::size
135  */
136 L4_CV l4re_ds_size_t
137 l4re_ds_size(l4re_ds_t ds) L4_NOTHROW;
138 
139 /**
140  * \ingroup api_l4re_c_ds
141  * \see L4Re::Dataspace::flags
142  */
143 L4_CV l4re_ds_flags_t
144 l4re_ds_flags(l4re_ds_t ds) L4_NOTHROW;
145 
146 /**
147  * \ingroup api_l4re_c_ds
148  * \see L4Re::Dataspace::info
149  */
150 L4_CV int
151 l4re_ds_info(l4re_ds_t ds, l4re_ds_stats_t *stats) L4_NOTHROW;
152 
153 EXTERN_C_END
154