L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
br_manager
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2014 Alexander Warg <alexander.warg@kernkonzept.com>
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7
8#pragma once
9
10#include <l4/re/util/cap_alloc>
11#include <l4/sys/cxx/ipc_server_loop>
12#include <l4/cxx/ipc_timeout_queue>
13#include <l4/sys/assert.h>
14
15namespace L4Re { namespace Util {
16
26{
27private:
28 enum { _mem = 0, _ports = 0 };
29 enum { Brs_per_timeout = sizeof(l4_kernel_clock_t) / sizeof(l4_umword_t) };
30
31public:
33 Br_manager() : _caps(0), _cap_flags(L4_RCV_ITEM_LOCAL_ID) {}
34
35 Br_manager(Br_manager const &) = delete;
36 Br_manager &operator = (Br_manager const &) = delete;
37
38 Br_manager(Br_manager &&) = delete;
39 Br_manager &operator = (Br_manager &&) = delete;
40
42 {
43 // Slots for received capabilities are placed at the beginning of the
44 // (shadowed) buffer registers. Free those.
45 for (unsigned i = 0; i < _caps; ++i)
47 }
48
49 /*
50 * This implementation dynamically manages assignment of buffer registers for
51 * the necessary amount of receive buffers allocated by all calls to this
52 * function.
53 */
54 int alloc_buffer_demand(Demand const &d) override
55 {
57
58 // memory and IO port receive windows currently not supported
59 if (d.mem || d.ports)
60 return -L4_EINVAL;
61
62 // take extra buffers for a possible timeout and for a zero terminator
63 if (d.caps + d.mem * 2 + d.ports * 2 + Brs_per_timeout + 1
64 > L4_UTCB_GENERIC_BUFFERS_SIZE)
65 return -L4_ERANGE;
66
67 if (d.caps > _caps)
68 {
69 while (_caps < d.caps)
70 {
72 if (!cap)
73 return -L4_ENOMEM;
74
75 reinterpret_cast<Small_buf&>(_brs[_caps])
76 = Small_buf(cap.cap(), _cap_flags);
77 ++_caps;
78 }
79 _brs[_caps] = 0;
80 }
81
82 return L4_EOK;
83 }
84
85
86 L4::Cap<void> get_rcv_cap(int i) const override
87 {
88 if (i < 0 || i >= _caps)
90
91 return L4::Cap<void>(_brs[i] & L4_CAP_MASK);
92 }
93
94 int realloc_rcv_cap(int i) override
95 {
97
98 if (i < 0 || i >= _caps)
99 return -L4_EINVAL;
100
102 if (!cap)
103 return -L4_ENOMEM;
104
105 reinterpret_cast<Small_buf&>(_brs[i])
106 = Small_buf(cap.cap(), _cap_flags);
107
108 return L4_EOK;
109 }
110
118 void set_rcv_cap_flags(unsigned long flags)
119 {
120 l4_assert(_caps == 0);
121
122 _cap_flags = flags;
123 }
124
128
131 { return -L4_ENOSYS; }
132
135 {
136 l4_buf_regs_t *br = l4_utcb_br_u(utcb);
137 br->bdr = 0;
138 for (unsigned i = 0; i <= _caps; ++i)
139 br->br[i] = _brs[i];
140 }
141
142protected:
144 unsigned first_free_br() const
145 {
146 // The last BR (64-bit) or the last two BRs (32-bit); this is constant.
147 return L4_UTCB_GENERIC_BUFFERS_SIZE - Brs_per_timeout;
148 // We could also do the following dynamic approach:
149 // return _caps + _mem + _ports + 1
150 }
151
152private:
153 unsigned short _caps;
154 unsigned long _cap_flags;
155
156 l4_umword_t _brs[L4_UTCB_GENERIC_BUFFERS_SIZE];
157};
158
171
180 public L4::Ipc_svr::Timeout_queue_hooks<Br_manager_timeout_hooks, Br_manager>,
182{
183public:
184 static l4_kernel_clock_t now()
185 { return l4_kip_clock(l4re_kip()); }
186};
187
188}}
189
Buffer-register (BR) manager for L4::Server.
Definition br_manager:26
int realloc_rcv_cap(int i) override
Allocate a new capability for the given receive buffer.
Definition br_manager:94
unsigned first_free_br() const
Used for assigning BRs for a timeout.
Definition br_manager:144
int add_timeout(L4::Ipc_svr::Timeout *, l4_kernel_clock_t) override
No timeouts handled by us.
Definition br_manager:126
void set_rcv_cap_flags(unsigned long flags)
Set the receive flags for the buffers.
Definition br_manager:118
void setup_wait(l4_utcb_t *utcb, L4::Ipc_svr::Reply_mode)
setup_wait() used the server loop (L4::Server)
Definition br_manager:134
Br_manager()
Make a buffer-register (BR) manager.
Definition br_manager:33
L4::Cap< void > get_rcv_cap(int i) const override
Get capability slot allocated to the given receive buffer.
Definition br_manager:86
int remove_timeout(L4::Ipc_svr::Timeout *) override
No timeouts handled by us.
Definition br_manager:130
int alloc_buffer_demand(Demand const &d) override
Tells the server to allocate buffers for the given demand.
Definition br_manager:54
L4::Cap< void > alloc() noexcept override
Allocate a capability.
void free(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept override
Free a capability.
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:258
Interface for server-loop related functions.
Definition ipc_epiface:37
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:507
unsigned char mem
number of memory receive buffers.
Definition __typeinfo.h:516
unsigned char caps
number of capability receive buffers.
Definition __typeinfo.h:514
unsigned char ports
number of IO-port receive buffers.
Definition __typeinfo.h:517
l4_kernel_info_t const * l4re_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition env.h:184
Reply_mode
Reply mode for server loop.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:53
@ L4_CAP_MASK
Mask to get only the relevant bits of an l4_cap_idx_t.
Definition consts.h:155
@ L4_ERANGE
Range error.
Definition err.h:48
@ L4_ENOSYS
No sys.
Definition err.h:50
@ L4_EINVAL
Invalid argument.
Definition err.h:46
@ L4_EOK
Ok.
Definition err.h:32
@ L4_ENOMEM
No memory.
Definition err.h:39
l4_cpu_time_t l4_kip_clock(l4_kernel_info_t const *kip) L4_NOTHROW
Return clock value from the KIP.
Definition kip.h:200
@ L4_RCV_ITEM_LOCAL_ID
The receiver requests to receive a local ID instead of a mapping whenever possible.
Definition consts.h:300
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
_Cap_alloc & cap_alloc
Capability allocator.
L4Re C++ Interfaces.
Definition cmd_control:14
Predefined server-loop hooks for a server loop using the Br_manager.
Definition br_manager:170
Predefined server-loop hooks for a server with using the Br_manager and a timeout queue.
Definition br_manager:182
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:83
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition utcb.h:88
l4_umword_t bdr
Buffer descriptor.
Definition utcb.h:85
Low-level assert implementation.
#define l4_assert(expr)
Low-level assert.
Definition assert.h:32
Capability allocator.