1 /* 2 * Server binding/registration. 3 * 4 * Copyright (C) 2018, 2019, 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 26 #include <ipc/message.h> 27 28 EXTERN_C_BEGIN 29 30 /* A handler function type. */ 31 32 typedef void (*ipc_server_handler_type)(ipc_message_t *, void *); 33 34 /* A finaliser function type. */ 35 36 struct ipc_server_config_type; 37 38 typedef void (*ipc_server_finaliser_type)(struct ipc_server_config_type *); 39 40 /* A server configuration type. */ 41 42 typedef struct ipc_server_config_type 43 { 44 /* Component object references. C++ objects may provide different references 45 for the handler (providing access to the exposed interface) and the 46 finaliser (providing access to a distinct control interface). */ 47 48 void *handler_obj; 49 void *finaliser_obj; 50 51 /* Expected capability item limit for incoming messages. */ 52 53 int expected_items; 54 55 /* Handler for incoming messages and finaliser upon deletion. */ 56 57 ipc_server_handler_type handler; 58 ipc_server_finaliser_type finaliser; 59 60 /* Create a new thread. */ 61 62 int new_thread; 63 64 /* Thread and IPC capabilities. */ 65 66 l4_cap_idx_t thread; 67 l4_cap_idx_t server; 68 69 /* Receive deletion notifications via an IRQ. */ 70 71 int notifications; 72 l4_cap_idx_t irq; 73 74 } ipc_server_config_type; 75 76 77 78 /* Associate a notification IRQ with an IPC gate in the main thread. */ 79 80 long ipc_server_apply_irq(l4_cap_idx_t cap, l4_cap_idx_t *irq); 81 82 /* Associate a notification IRQ with an IPC gate in the given thread. */ 83 84 long ipc_server_apply_irq_for_thread(l4_cap_idx_t cap, l4_cap_idx_t *irq, l4_cap_idx_t thread); 85 86 /* Bind the main thread to a named IPC gate capability. */ 87 88 long ipc_server_bind(const char *name, l4_umword_t id, l4_cap_idx_t *server); 89 90 /* Create a new IPC gate for the main thread. */ 91 92 long ipc_server_new(l4_cap_idx_t *cap, void *obj); 93 94 /* Create a new IPC gate for the given thread. */ 95 96 long ipc_server_new_for_thread(l4_cap_idx_t *cap, void *obj, l4_cap_idx_t thread); 97 98 /* Create an IPC gate for the main thread. */ 99 100 long ipc_server_new_gate(l4_cap_idx_t *ref, l4_umword_t id); 101 102 /* Create an IPC gate for the indicated thread. */ 103 104 long ipc_server_new_gate_for_thread(l4_cap_idx_t *ref, l4_cap_idx_t thread, l4_umword_t id); 105 106 107 108 /* Handle incoming messages for a server. */ 109 110 long ipc_server_loop(int expected_items, ipc_server_config_type *config); 111 112 /* Handle incoming messages and IRQ notifications for a server. */ 113 114 long ipc_server_managed_loop(int expected_items, ipc_server_config_type *config, 115 l4_cap_idx_t irq); 116 117 /* A pthread-compatible mainloop initiation function. */ 118 119 void *ipc_server_start_mainloop(void *data); 120 121 /* Wait for an incoming message via a dedicated IPC gate for a thread. */ 122 123 l4_msgtag_t ipc_server_wait(l4_umword_t id); 124 125 126 127 /* Finalise a server configuration. */ 128 129 void ipc_server_finalise_config(ipc_server_config_type *config); 130 131 /* Discard any thread created but not initiated. */ 132 133 void ipc_server_discard_thread(ipc_server_config_type *config); 134 135 /* Initialise a server configuration. */ 136 137 void ipc_server_init_config(ipc_server_config_type *config); 138 139 /* Initialise and start a server using the given configuration. */ 140 141 long ipc_server_start_config(ipc_server_config_type *config); 142 143 EXTERN_C_END