L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
br_manager
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2014 Alexander Warg <alexander.warg@kernkonzept.com>
4 *
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
8 *
9 * As a special exception, you may use this file as part of a free software
10 * library without restriction. Specifically, if other files instantiate
11 * templates or use macros or inline functions from this file, or you compile
12 * this file and link it with other files to produce an executable, this
13 * file does not by itself cause the resulting executable to be covered by
14 * the GNU General Public License. This exception does not however
15 * invalidate any other reasons why the executable file might be covered by
16 * the GNU General Public License.
17 */
18
19#pragma once
20
21#include <l4/re/util/cap_alloc>
22#include <l4/sys/cxx/ipc_server_loop>
23#include <l4/cxx/ipc_timeout_queue>
24#include <l4/sys/assert.h>
25
26namespace L4Re { namespace Util {
27
37{
38private:
39 enum { _mem = 0, _ports = 0 };
40 enum { Brs_per_timeout = sizeof(l4_kernel_clock_t) / sizeof(l4_umword_t) };
41
42public:
44 Br_manager() : _caps(0), _cap_flags(L4_RCV_ITEM_LOCAL_ID) {}
45
46 Br_manager(Br_manager const &) = delete;
47 Br_manager &operator = (Br_manager const &) = delete;
48
49 Br_manager(Br_manager &&) = delete;
50 Br_manager &operator = (Br_manager &&) = delete;
51
53 {
54 // Slots for received capabilities are placed at the beginning of the
55 // (shadowed) buffer registers. Free those.
56 for (unsigned i = 0; i < _caps; ++i)
57 cap_alloc.free(L4::Cap<void>(_brs[i] & L4_CAP_MASK));
58 }
59
60 /*
61 * This implementation dynamically manages assignment of buffer registers for
62 * the necessary amount of receive buffers allocated by all calls to this
63 * function.
64 */
65 int alloc_buffer_demand(Demand const &d) override
66 {
68
69 // memory and IO port receive windows currently not supported
70 if (d.mem || d.ports)
71 return -L4_EINVAL;
72
73 // take extra buffers for a possible timeout and for a zero terminator
74 if (d.caps + d.mem * 2 + d.ports * 2 + Brs_per_timeout + 1
75 > L4_UTCB_GENERIC_BUFFERS_SIZE)
76 return -L4_ERANGE;
77
78 if (d.caps > _caps)
79 {
80 while (_caps < d.caps)
81 {
82 L4::Cap<void> cap = cap_alloc.alloc();
83 if (!cap)
84 return -L4_ENOMEM;
85
86 reinterpret_cast<Small_buf&>(_brs[_caps])
87 = Small_buf(cap.cap(), _cap_flags);
88 ++_caps;
89 }
90 _brs[_caps] = 0;
91 }
92
93 return L4_EOK;
94 }
95
96
97 L4::Cap<void> get_rcv_cap(int i) const override
98 {
99 if (i < 0 || i >= _caps)
101
102 return L4::Cap<void>(_brs[i] & L4_CAP_MASK);
103 }
104
105 int realloc_rcv_cap(int i) override
106 {
107 using L4::Ipc::Small_buf;
108
109 if (i < 0 || i >= _caps)
110 return -L4_EINVAL;
111
112 L4::Cap<void> cap = cap_alloc.alloc();
113 if (!cap)
114 return -L4_ENOMEM;
115
116 reinterpret_cast<Small_buf&>(_brs[i])
117 = Small_buf(cap.cap(), _cap_flags);
118
119 return L4_EOK;
120 }
121
129 void set_rcv_cap_flags(unsigned long flags)
130 {
131 l4_assert(_caps == 0);
132
133 _cap_flags = flags;
134 }
135
139
142 { return -L4_ENOSYS; }
143
146 {
147 l4_buf_regs_t *br = l4_utcb_br_u(utcb);
148 br->bdr = 0;
149 for (unsigned i = 0; i <= _caps; ++i)
150 br->br[i] = _brs[i];
151 }
152
153protected:
155 unsigned first_free_br() const
156 {
157 // The last BR (64-bit) or the last two BRs (32-bit); this is constant.
158 return L4_UTCB_GENERIC_BUFFERS_SIZE - Brs_per_timeout;
159 // We could also do the following dynamic approach:
160 // return _caps + _mem + _ports + 1
161 }
162
163private:
164 unsigned short _caps;
165 unsigned long _cap_flags;
166
167 l4_umword_t _brs[L4_UTCB_GENERIC_BUFFERS_SIZE];
168};
169
182
191 public L4::Ipc_svr::Timeout_queue_hooks<Br_manager_timeout_hooks, Br_manager>,
193{
194public:
195 static l4_kernel_clock_t now()
196 { return l4_kip_clock(l4re_kip()); }
197};
198
199}}
200
Buffer-register (BR) manager for L4::Server.
Definition br_manager:37
int realloc_rcv_cap(int i) override
Allocate a new capability for the given receive buffer.
Definition br_manager:105
unsigned first_free_br() const
Used for assigning BRs for a timeout.
Definition br_manager:155
int add_timeout(L4::Ipc_svr::Timeout *, l4_kernel_clock_t) override
No timeouts handled by us.
Definition br_manager:137
void set_rcv_cap_flags(unsigned long flags)
Set the receive flags for the buffers.
Definition br_manager:129
void setup_wait(l4_utcb_t *utcb, L4::Ipc_svr::Reply_mode)
setup_wait() used the server loop (L4::Server)
Definition br_manager:145
Br_manager()
Make a buffer-register (BR) manager.
Definition br_manager:44
L4::Cap< void > get_rcv_cap(int i) const override
Get capability slot allocated to the given receive buffer.
Definition br_manager:97
int remove_timeout(L4::Ipc_svr::Timeout *) override
No timeouts handled by us.
Definition br_manager:141
int alloc_buffer_demand(Demand const &d) override
Tells the server to allocate buffers for the given demand.
Definition br_manager:65
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
C++ interface for capabilities.
Definition capability.h:219
A receive item for receiving a single object capability.
Definition ipc_types:269
Interface for server-loop related functions.
Definition ipc_epiface:48
Loop hooks mixin for integrating a timeout queue into the server loop.
Callback interface for Timeout_queue.
Data type for expressing the needed receive buffers at the server-side of an interface.
Definition __typeinfo.h:518
unsigned char mem
number of memory receive buffers.
Definition __typeinfo.h:527
unsigned char caps
number of capability receive buffers.
Definition __typeinfo.h:525
unsigned char ports
number of IO-port receive buffers.
Definition __typeinfo.h:528
l4_kernel_info_t const * l4re_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition env.h:194
Reply_mode
Reply mode for server loop.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:64
@ L4_CAP_MASK
Mask to get only the relevant bits of an l4_cap_idx_t.
Definition consts.h:166
@ L4_ERANGE
Range error.
Definition err.h:59
@ L4_ENOSYS
No sys.
Definition err.h:61
@ L4_EINVAL
Invalid argument.
Definition err.h:57
@ L4_EOK
Ok.
Definition err.h:43
@ L4_ENOMEM
No memory.
Definition err.h:50
l4_cpu_time_t l4_kip_clock(l4_kernel_info_t const *kip) L4_NOTHROW
Return clock value from the KIP.
Definition kip.h:211
@ L4_RCV_ITEM_LOCAL_ID
The receiver requests to receive a local ID instead of a mapping whenever possible.
Definition consts.h:285
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
_Cap_alloc & cap_alloc
Capability allocator.
L4Re C++ Interfaces.
Definition l4re.dox:17
Predefined server-loop hooks for a server loop using the Br_manager.
Definition br_manager:181
Predefined server-loop hooks for a server with using the Br_manager and a timeout queue.
Definition br_manager:193
Mix in for LOOP_HOOKS to always use compound reply and wait.
Mix in for LOOP_HOOKS to use a 0 send and a infinite receive timeout.
Mix in for LOOP_HOOKS to ignore IPC errors.
Encapsulation of the buffer-registers block in the UTCB.
Definition utcb.h:94
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition utcb.h:99
l4_umword_t bdr
Buffer descriptor.
Definition utcb.h:96
Low-level assert implementation.
#define l4_assert(expr)
Low-level assert.
Definition assert.h:43
Capability allocator.