source: rtems-libbsd/rtemsbsd/include/rtems/bsd/bsd.h @ 6215813

55-freebsd-126-freebsd-12
Last change on this file since 6215813 was 7ec935e, checked in by Christian Mauderer <christian.mauderer@…>, on 03/23/18 at 06:58:18

vprintf: Add handler that mutes all output.

This adds a vprintf handler that can be used to suppress all outputs of
the libbsd.

  • Property mode set to 100755
File size: 9.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd
5 *
6 * @brief TODO.
7 */
8
9/*
10 * Copyright (c) 2009, 2016 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 *    notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 *    notice, this list of conditions and the following disclaimer in the
25 *    documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 */
39
40#ifndef _RTEMS_BSD_BSD_H_
41#define _RTEMS_BSD_BSD_H_
42
43#include <sys/cdefs.h>
44#include <sys/queue.h>
45#include <sys/kernel.h>
46
47#include <stdarg.h>
48
49#include <rtems.h>
50
51#ifdef __cplusplus
52extern "C" {
53#endif /* __cplusplus */
54
55/*
56 * The default memory size. Do not change, use
57 * RTEMS_BSD_CONFIG_DOMAIN_PAGE_MBUFS_SIZE to override for your application.
58 */
59#define RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE_MBUF_DEFAULT (8 * 1024 * 1024)
60
61typedef enum {
62        RTEMS_BSD_RES_IRQ = 1,
63        RTEMS_BSD_RES_MEMORY = 3
64} rtems_bsd_device_resource_type;
65
66typedef struct {
67        rtems_bsd_device_resource_type type;
68        unsigned long start_request;
69        unsigned long start_actual;
70} rtems_bsd_device_resource;
71
72typedef struct {
73        const char *name;
74        int unit;
75        size_t resource_count;
76        const rtems_bsd_device_resource *resources;
77        const struct sysinit *driver_reference;
78} rtems_bsd_device;
79
80#define RTEMS_BSD_DEFINE_NEXUS_DEVICE(name, unit, resource_count, resources) \
81    extern struct sysinit SYSINIT_ENTRY_NAME(name##_nexusmodule); \
82    RTEMS_BSD_DEFINE_SET_ITEM(nexus, name##unit, rtems_bsd_device) = \
83        { #name, unit, (resource_count), (resources), \
84            &SYSINIT_ENTRY_NAME(name##_nexusmodule) }
85
86#define RTEMS_BSD_DEFINE_NEXUS_DEVICE_ORDERED(name, unit, order, resource_count, resources) \
87    extern struct sysinit SYSINIT_ENTRY_NAME(name##_nexusmodule); \
88    RTEMS_BSD_DEFINE_SET_ITEM_ORDERED(nexus, name##unit, order, rtems_bsd_device) = \
89        { #name, unit, (resource_count), (resources), \
90            &SYSINIT_ENTRY_NAME(name##_nexusmodule) }
91
92rtems_status_code rtems_bsd_initialize(void);
93
94/**
95 * @brief Initializes the libbsd and starts a DHCPCD task.
96 *
97 * The libbsd is initialized via rtems_bsd_initialize().  If this is
98 * successful, then the loop back interfaces are created.  If this is
99 * successful, then a DHCPCD task is started at the least important priority.
100 *
101 * The default devices of the BSP are initialized.  Support for
102 *   - IF_BRIDGE(4),
103 *   - LAGG(4),
104 *   - multicast routing,
105 *   - UNIX(4), and
106 *   - VLAN(4),
107 * is enabled.
108 *
109 * No RTEMS shell commands are registered.
110 *
111 * @retval RTEMS_SUCCESSFUL Successful operation.
112 * @retval otherwise An error occurred.
113 */
114rtems_status_code rtems_bsd_initialize_dhcp(void);
115
116/**
117 * @brief Configures the lo0 (loopback) interface.
118 *
119 * @return Returns an exit code, see also <sysexits.h>.
120 */
121int rtems_bsd_ifconfig_lo0(void);
122
123/**
124 * @brief Configures an interface.
125 *
126 * In case addr_gateway is not NULL, then it will be used as the default
127 * gateway.
128 *
129 * @param[in] ifname The interface name.
130 * @param[in] addr_self The address of the interface.
131 * @param[in] netmask The sub-network mask.
132 * @param[in] addr_gateway The address of the gateway.  May be NULL.
133 *
134 * @return Returns an exit code, see also <sysexits.h>.
135 */
136int rtems_bsd_ifconfig(const char *ifname, const char *addr_self,
137    const char *netmask, const char *addr_gateway);
138
139/**
140 * @brief Returns the initial priority for a task specified by its name.
141 *
142 * Applications may provide their own implementation of this function.  For
143 * example they can define their implementation in the same module which calls
144 * rtems_bsd_initialize().
145 *
146 * @param[in] name The task name.
147 *
148 * @return The desired initial task priority.
149 */
150rtems_task_priority rtems_bsd_get_task_priority(const char *name);
151
152/**
153 * @brief Returns the stack size for a task specified by its name.
154 *
155 * Applications may provide their own implementation of this function.  For
156 * example they can define their implementation in the same module which calls
157 * rtems_bsd_initialize().
158 *
159 * @param[in] name The task name.
160 *
161 * @return The desired task stack size.
162 */
163size_t rtems_bsd_get_task_stack_size(const char *name);
164
165typedef enum {
166        RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE,
167        RTEMS_BSD_ALLOCATOR_DOMAIN_MBUF,
168        RTEMS_BSD_ALLOCATOR_DOMAIN_MALLOC
169} rtems_bsd_allocator_domain;
170
171/**
172 * @brief The size for the page/mbufs default allocator domain.
173 *
174 * Applications may set this value to change the value returned by the default.
175 */
176extern uintptr_t rtems_bsd_allocator_domain_page_mbuf_size;
177
178/**
179 * @brief Returns the size for a specific allocator domain.
180 *
181 * Applications may provide their own implementation of this function.  For
182 * example they can define their implementation in the same module which calls
183 * rtems_bsd_initialize().
184 *
185 * @param[in] domain The allocator domain.
186 *
187 * @return The desired size for the specified allocator domain.
188 */
189uintptr_t rtems_bsd_get_allocator_domain_size(
190    rtems_bsd_allocator_domain domain);
191
192/**
193 * @brief Returns the Ethernet MAC address for a specified device.
194 *
195 * Applications may provide their own implementation of this function.  For
196 * example they can define their implementation in the same module which calls
197 * rtems_bsd_initialize().
198 *
199 * The default implementation returns
200 * { 0x0e, 0xb0, 0xba, 0x5e, 0xba, 0x11 + unit }.
201 *
202 * This is a workaround.  A better approach would be to use a device tree and a
203 * bus device similar to the FreeBSD SIMPLEBUS(4).
204 *
205 * @param[in] name The device name.
206 * @param[in] unit The device unit.
207 * @param[out] mac_addr The Ethernet MAC address.
208 */
209void rtems_bsd_get_mac_address(const char *name, int unit,
210    uint8_t mac_addr[6]);
211
212/**
213 * @defgroup BSDBusRoot Bus Root Functions
214 *
215 * @brief Functions to perform bus root operations.
216 *
217 * Suspend and resume can be used to go into or exit a power saving state.
218 * Detach may be used to shutdown the system and do a warm reset.
219 *
220 * All functions must be called from task context.  They perform complex
221 * operations affecting all devices of the bus tree and work only if all
222 * drivers are written properly and no resources used by the drivers are
223 * blocked.
224 *
225 * @{
226 */
227
228/**
229 * @brief Attach the root bus.
230 *
231 * @retval 0 Successful operation.
232 * @retval errno Otherwise.
233 */
234int rtems_bsd_bus_root_attach(void);
235
236/**
237 * @brief Suspend the root bus.
238 *
239 * @retval 0 Successful operation.
240 * @retval errno Otherwise.
241 */
242int rtems_bsd_bus_root_suspend(void);
243
244/**
245 * @brief Resume the root bus.
246 *
247 * @retval 0 Successful operation.
248 * @retval errno Otherwise.
249 */
250int rtems_bsd_bus_root_resume(void);
251
252/**
253 * @brief Detach the root bus.
254 *
255 * @retval 0 Successful operation.
256 * @retval errno Otherwise.
257 */
258int rtems_bsd_bus_root_detach(void);
259
260/**
261 * @brief The output back-end for logging functions.
262 */
263typedef int (*rtems_bsd_vprintf_handler)(int, const char *, va_list);
264
265/**
266 * @brief Sets the output back-end for logging functions.
267 *
268 * @param new_handler The new output back-end for logging functions.
269 *
270 * @return The previous handler.
271 *
272 * @see rtems_bsd_vprintf().
273 */
274rtems_bsd_vprintf_handler rtems_bsd_set_vprintf_handler(
275    rtems_bsd_vprintf_handler new_handler);
276
277/**
278 * @brief Output back-end for logging functions.
279 *
280 * Used by kernel space printf(), vprintf(), log() and vlog().  Used by user
281 * space syslog() and vsyslog().
282 *
283 * The default uses putchar() and uses a mutex to serialize the output.  It may
284 * be customized via rtems_bsd_set_vprintf_handler().
285 */
286int rtems_bsd_vprintf(int level, const char *fmt, va_list ap);
287
288/**
289 * @brief Set the syslog priority. See syslog.h for the names.
290 *
291 * @param priority One of the standard names.
292 * @retval 0 Priority set.
293 * @retval errno Otherwise.
294 */
295int rtems_bsd_setlogpriority(const char* priority);
296
297/**
298 * @brief Set this vprintf handler to suppress all output.
299 *
300 * @retval Allways 0.
301 *
302 * @see rtems_bsd_vprintf() for the parameters.
303 */
304int rtems_bsd_vprintf_handler_mute(int level, const char *fmt, va_list ap);
305
306/** @} */
307
308#ifdef __cplusplus
309}
310#endif /* __cplusplus */
311
312#endif /* _RTEMS_BSD_BSD_H_ */
Note: See TracBrowser for help on using the repository browser.