paul@181 | 1 | /* |
paul@181 | 2 | * Interprocess communication message abstraction. |
paul@181 | 3 | * |
paul@351 | 4 | * Copyright (C) 2018, 2019, 2021, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@181 | 5 | * |
paul@181 | 6 | * This program is free software; you can redistribute it and/or |
paul@181 | 7 | * modify it under the terms of the GNU General Public License as |
paul@181 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@181 | 9 | * the License, or (at your option) any later version. |
paul@181 | 10 | * |
paul@181 | 11 | * This program is distributed in the hope that it will be useful, |
paul@181 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@181 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@181 | 14 | * GNU General Public License for more details. |
paul@181 | 15 | * |
paul@181 | 16 | * You should have received a copy of the GNU General Public License |
paul@181 | 17 | * along with this program; if not, write to the Free Software |
paul@181 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@181 | 19 | * Boston, MA 02110-1301, USA |
paul@181 | 20 | */ |
paul@181 | 21 | |
paul@181 | 22 | #include <string.h> |
paul@181 | 23 | |
paul@181 | 24 | #include "cap_alloc.h" |
paul@181 | 25 | #include "message.h" |
paul@181 | 26 | #include "mem_ipc.h" |
paul@181 | 27 | #include "util_ipc.h" |
paul@181 | 28 | |
paul@181 | 29 | |
paul@181 | 30 | |
paul@181 | 31 | /* Calculate the given length rounded up to whole word increments. */ |
paul@181 | 32 | |
paul@181 | 33 | static size_t get_size_in_words(size_t length) |
paul@181 | 34 | { |
paul@181 | 35 | size_t mask = sizeof(l4_umword_t) - 1; |
paul@181 | 36 | return (length + mask) & ~mask; |
paul@181 | 37 | } |
paul@181 | 38 | |
paul@181 | 39 | |
paul@181 | 40 | |
paul@181 | 41 | /* Message operations. */ |
paul@181 | 42 | |
paul@181 | 43 | /* Discard capabilities for transfer to other tasks. */ |
paul@181 | 44 | |
paul@181 | 45 | void ipc_message_discard(ipc_message_t *msg) |
paul@181 | 46 | { |
paul@181 | 47 | unsigned int i; |
paul@181 | 48 | |
paul@181 | 49 | for (i = 0; i < msg->discarded_items; i++) |
paul@181 | 50 | ipc_cap_free_um(msg->to_discard[i]); |
paul@181 | 51 | } |
paul@181 | 52 | |
paul@181 | 53 | /* Initialise a message structure with the given number of expected items. */ |
paul@181 | 54 | |
paul@181 | 55 | long ipc_message_expect(ipc_message_t *msg, unsigned int expected_items) |
paul@181 | 56 | { |
paul@350 | 57 | return ipc_message_expect_capabilities(msg, expected_items); |
paul@181 | 58 | } |
paul@181 | 59 | |
paul@181 | 60 | /* Free capabilities expected in messages. */ |
paul@181 | 61 | |
paul@181 | 62 | void ipc_message_free(ipc_message_t *msg) |
paul@181 | 63 | { |
paul@181 | 64 | _free_expected_capabilities(&msg->bregs, msg->expected_items); |
paul@181 | 65 | } |
paul@181 | 66 | |
paul@181 | 67 | /* Clear message attributes for sending and response handling. */ |
paul@181 | 68 | |
paul@181 | 69 | void ipc_message_new(ipc_message_t *msg) |
paul@181 | 70 | { |
paul@181 | 71 | /* Set a default for expected items. */ |
paul@181 | 72 | |
paul@181 | 73 | msg->expected_items = 0; |
paul@351 | 74 | msg->receive_items = 0; |
paul@181 | 75 | ipc_message_reset(msg); |
paul@181 | 76 | } |
paul@181 | 77 | |
paul@181 | 78 | /* Open an incoming message by resetting sending state and preserving the |
paul@181 | 79 | message registers plus the buffer registers for the expected number of |
paul@181 | 80 | items. */ |
paul@181 | 81 | |
paul@181 | 82 | void ipc_message_open(ipc_message_t *msg) |
paul@181 | 83 | { |
paul@181 | 84 | ipc_message_reset(msg); |
paul@181 | 85 | ipc_message_preserve_buffer_registers(msg); |
paul@181 | 86 | ipc_message_preserve_message_registers(msg); |
paul@181 | 87 | } |
paul@181 | 88 | |
paul@181 | 89 | /* Preserve the buffer registers. */ |
paul@181 | 90 | |
paul@181 | 91 | void ipc_message_preserve_buffer_registers(ipc_message_t *msg) |
paul@181 | 92 | { |
paul@181 | 93 | unsigned int i; |
paul@181 | 94 | |
paul@181 | 95 | /* Reference the UTCB virtual registers. */ |
paul@181 | 96 | |
paul@181 | 97 | l4_buf_regs_t *bregs = l4_utcb_br(); |
paul@181 | 98 | |
paul@181 | 99 | msg->bregs.bdr = bregs->bdr; |
paul@181 | 100 | |
paul@351 | 101 | /* NOTE: Support a mixture of expected items and received flexpages. */ |
paul@351 | 102 | |
paul@351 | 103 | if ((msg->expected_items) || (msg->receive_items)) |
paul@351 | 104 | { |
paul@351 | 105 | for (i = 0; (i < msg->expected_items) || (i < msg->receive_items * 2); i++) |
paul@351 | 106 | msg->bregs.br[i] = bregs->br[i]; |
paul@351 | 107 | } |
paul@181 | 108 | } |
paul@181 | 109 | |
paul@181 | 110 | /* Preserve the message registers. */ |
paul@181 | 111 | |
paul@181 | 112 | void ipc_message_preserve_message_registers(ipc_message_t *msg) |
paul@181 | 113 | { |
paul@181 | 114 | /* Compute the number of message register words affected. */ |
paul@181 | 115 | |
paul@181 | 116 | unsigned int i, affected_words = l4_msgtag_words(msg->tag) + |
paul@181 | 117 | 2 * l4_msgtag_items(msg->tag); |
paul@181 | 118 | |
paul@181 | 119 | /* Reference the UTCB virtual registers. */ |
paul@181 | 120 | |
paul@181 | 121 | l4_msg_regs_t *mregs = l4_utcb_mr(); |
paul@181 | 122 | |
paul@181 | 123 | /* Copy message register information. */ |
paul@181 | 124 | |
paul@181 | 125 | for (i = 0; i < affected_words; i++) |
paul@181 | 126 | msg->mregs.mr[i] = mregs->mr[i]; |
paul@181 | 127 | } |
paul@181 | 128 | |
paul@181 | 129 | /* Restore the message and buffer registers. */ |
paul@181 | 130 | |
paul@181 | 131 | void ipc_message_prepare(ipc_message_t *msg) |
paul@181 | 132 | { |
paul@181 | 133 | ipc_message_restore_buffer_registers(msg); |
paul@181 | 134 | ipc_message_restore_message_registers(msg); |
paul@181 | 135 | } |
paul@181 | 136 | |
paul@181 | 137 | /* Restore buffer registers so that item expectations can be set. */ |
paul@181 | 138 | |
paul@181 | 139 | void ipc_message_restore_buffer_registers(ipc_message_t *msg) |
paul@181 | 140 | { |
paul@181 | 141 | unsigned int i; |
paul@181 | 142 | |
paul@181 | 143 | /* Reference the UTCB virtual registers. */ |
paul@181 | 144 | |
paul@181 | 145 | l4_buf_regs_t *bregs = l4_utcb_br(); |
paul@181 | 146 | |
paul@181 | 147 | /* Restore buffer register information. */ |
paul@181 | 148 | |
paul@181 | 149 | bregs->bdr = msg->bregs.bdr; |
paul@181 | 150 | |
paul@351 | 151 | /* NOTE: Support a mixture of expected items and received flexpages. */ |
paul@351 | 152 | |
paul@351 | 153 | if ((msg->expected_items) || (msg->receive_items)) |
paul@351 | 154 | { |
paul@351 | 155 | for (i = 0; (i < msg->expected_items) || (i < msg->receive_items * 2); i++) |
paul@351 | 156 | bregs->br[i] = msg->bregs.br[i]; |
paul@351 | 157 | } |
paul@181 | 158 | } |
paul@181 | 159 | |
paul@181 | 160 | /* Restore message registers to communicate recorded data and items. */ |
paul@181 | 161 | |
paul@181 | 162 | void ipc_message_restore_message_registers(ipc_message_t *msg) |
paul@181 | 163 | { |
paul@181 | 164 | /* Compute the number of message register words affected. */ |
paul@181 | 165 | |
paul@181 | 166 | unsigned int i, affected_words = msg->words + 2 * msg->items; |
paul@181 | 167 | |
paul@181 | 168 | /* Reference the UTCB virtual registers. */ |
paul@181 | 169 | |
paul@181 | 170 | l4_msg_regs_t *mregs = l4_utcb_mr(); |
paul@181 | 171 | |
paul@181 | 172 | /* Restore message register information. */ |
paul@181 | 173 | |
paul@181 | 174 | for (i = 0; i < affected_words; i++) |
paul@181 | 175 | mregs->mr[i] = msg->mregs.mr[i]; |
paul@181 | 176 | } |
paul@181 | 177 | |
paul@181 | 178 | /* Prepare and send a reply using the message. */ |
paul@181 | 179 | |
paul@181 | 180 | void ipc_message_reply(ipc_message_t *msg) |
paul@181 | 181 | { |
paul@181 | 182 | ipc_message_prepare(msg); |
paul@181 | 183 | msg->tag = util_ipc_reply(ipc_message_reply_tag(msg)); |
paul@181 | 184 | } |
paul@181 | 185 | |
paul@181 | 186 | /* Prepare and send a request using the message, involving the given operation, |
paul@181 | 187 | directed at the indicated endpoint. Open a message for the reply. */ |
paul@181 | 188 | |
paul@181 | 189 | void ipc_message_request(ipc_message_t *msg, int op, l4_cap_idx_t endpoint) |
paul@181 | 190 | { |
paul@181 | 191 | ipc_message_prepare(msg); |
paul@181 | 192 | msg->tag = util_ipc_request(ipc_message_request_tag(msg, op), endpoint); |
paul@181 | 193 | ipc_message_open(msg); |
paul@181 | 194 | } |
paul@181 | 195 | |
paul@181 | 196 | /* Prepare and send a message, involving the given operation, directed at the |
paul@181 | 197 | indicated endpoint. No reply is expected. */ |
paul@181 | 198 | |
paul@181 | 199 | void ipc_message_send(ipc_message_t *msg, int op, l4_cap_idx_t endpoint) |
paul@181 | 200 | { |
paul@181 | 201 | ipc_message_prepare(msg); |
paul@181 | 202 | msg->tag = util_ipc_send(ipc_message_request_tag(msg, op), endpoint); |
paul@181 | 203 | } |
paul@181 | 204 | |
paul@181 | 205 | /* Reset the state of the message for sending purposes. */ |
paul@181 | 206 | |
paul@181 | 207 | void ipc_message_reset(ipc_message_t *msg) |
paul@181 | 208 | { |
paul@181 | 209 | /* Initialise words and items for sending. */ |
paul@181 | 210 | |
paul@181 | 211 | msg->discarded_items = 0; |
paul@181 | 212 | msg->words = 0; |
paul@181 | 213 | msg->items = 0; |
paul@181 | 214 | |
paul@181 | 215 | /* Message label overriding. */ |
paul@181 | 216 | |
paul@181 | 217 | msg->new_label = 0; |
paul@181 | 218 | |
paul@181 | 219 | /* Server control. */ |
paul@181 | 220 | |
paul@181 | 221 | msg->terminating = 0; |
paul@181 | 222 | } |
paul@181 | 223 | |
paul@181 | 224 | /* Wait for an incoming message. */ |
paul@181 | 225 | |
paul@181 | 226 | void ipc_message_wait(ipc_message_t *msg, l4_umword_t *label) |
paul@181 | 227 | { |
paul@350 | 228 | ipc_message_restore_buffer_registers(msg); |
paul@181 | 229 | msg->tag = l4_ipc_wait(l4_utcb(), label, L4_IPC_NEVER); |
paul@181 | 230 | } |
paul@181 | 231 | |
paul@181 | 232 | |
paul@181 | 233 | |
paul@181 | 234 | /* Add a capability to the message. */ |
paul@181 | 235 | |
paul@181 | 236 | void ipc_message_add_capability(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 237 | { |
paul@181 | 238 | ipc_message_export_capability(msg, msg->items++, cap); |
paul@181 | 239 | if (cap & IPC_DISCARD_CAP_FLAG) |
paul@181 | 240 | ipc_message_discard_capability(msg, cap & ~IPC_DISCARD_CAP_FLAG); |
paul@181 | 241 | } |
paul@181 | 242 | |
paul@181 | 243 | /* Add an item to the message. */ |
paul@181 | 244 | |
paul@181 | 245 | void ipc_message_add_item(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 246 | { |
paul@181 | 247 | ipc_message_export_capability(msg, msg->items++, cap); |
paul@181 | 248 | if (cap & IPC_DISCARD_CAP_FLAG) |
paul@181 | 249 | ipc_message_discard_capability(msg, cap & ~IPC_DISCARD_CAP_FLAG); |
paul@181 | 250 | } |
paul@181 | 251 | |
paul@181 | 252 | /* Add a flexpage to the message using a type to combine the "hot spot" and |
paul@181 | 253 | flexpage. */ |
paul@181 | 254 | |
paul@181 | 255 | void ipc_message_add_fpage(ipc_message_t *msg, l4_snd_fpage_t fpage) |
paul@181 | 256 | { |
paul@181 | 257 | ipc_message_export_fpage(msg, msg->items++, fpage); |
paul@181 | 258 | } |
paul@181 | 259 | |
paul@351 | 260 | /* Add a receive window flexpage item to the message. */ |
paul@351 | 261 | |
paul@351 | 262 | void ipc_message_add_receive_fpage(ipc_message_t *msg, l4_snd_fpage_t fpage) |
paul@351 | 263 | { |
paul@351 | 264 | ipc_message_receive_fpage(msg, msg->receive_items++, fpage); |
paul@351 | 265 | } |
paul@351 | 266 | |
paul@181 | 267 | /* Add a flexpage to the message. */ |
paul@181 | 268 | |
paul@181 | 269 | void ipc_message_add_page(ipc_message_t *msg, l4_umword_t hot_spot, |
paul@181 | 270 | l4_fpage_t fpage) |
paul@181 | 271 | { |
paul@181 | 272 | ipc_message_export_page(msg, msg->items++, hot_spot, fpage); |
paul@181 | 273 | } |
paul@181 | 274 | |
paul@181 | 275 | /* Add a word value to the message. */ |
paul@181 | 276 | |
paul@181 | 277 | void ipc_message_add_word(ipc_message_t *msg, l4_umword_t value) |
paul@181 | 278 | { |
paul@181 | 279 | /* NOTE: Should raise an exception if there are items. */ |
paul@181 | 280 | |
paul@181 | 281 | if (!msg->items) |
paul@181 | 282 | msg->mregs.mr[msg->words++] = value; |
paul@181 | 283 | } |
paul@181 | 284 | |
paul@181 | 285 | /* Add the given dimensioned data to the message. */ |
paul@181 | 286 | |
paul@181 | 287 | void ipc_message_add_data(ipc_message_t *msg, const char *value, size_t length) |
paul@181 | 288 | { |
paul@181 | 289 | void *target = ipc_message_reserve_data(msg, length); |
paul@181 | 290 | |
paul@181 | 291 | memcpy(target, value, length); |
paul@181 | 292 | } |
paul@181 | 293 | |
paul@181 | 294 | /* Add the given null-terminated character string to the message. */ |
paul@181 | 295 | |
paul@181 | 296 | void ipc_message_add_string(ipc_message_t *msg, const char *value) |
paul@181 | 297 | { |
paul@181 | 298 | ipc_message_add_data(msg, value, strlen(value) + 1); |
paul@181 | 299 | } |
paul@181 | 300 | |
paul@181 | 301 | /* Propagate the given item to the message. */ |
paul@181 | 302 | |
paul@181 | 303 | void ipc_message_propagate_item(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 304 | { |
paul@181 | 305 | ipc_message_propagate_capability(msg, msg->items++, cap); |
paul@181 | 306 | } |
paul@181 | 307 | |
paul@181 | 308 | /* Indicate an error condition in the message. */ |
paul@181 | 309 | |
paul@181 | 310 | void ipc_message_send_error(ipc_message_t *msg, long error) |
paul@181 | 311 | { |
paul@181 | 312 | msg->new_label = error; |
paul@181 | 313 | } |
paul@181 | 314 | |
paul@181 | 315 | /* Return a word value from the message. */ |
paul@181 | 316 | |
paul@181 | 317 | l4_umword_t ipc_message_get_word(ipc_message_t *msg, unsigned int word) |
paul@181 | 318 | { |
paul@181 | 319 | return msg->mregs.mr[word]; |
paul@181 | 320 | } |
paul@181 | 321 | |
paul@181 | 322 | /* Return a pointer to a word in the message. */ |
paul@181 | 323 | |
paul@181 | 324 | l4_umword_t *ipc_message_get_word_address(ipc_message_t *msg, unsigned int word) |
paul@181 | 325 | { |
paul@181 | 326 | return &msg->mregs.mr[word]; |
paul@181 | 327 | } |
paul@181 | 328 | |
paul@181 | 329 | /* Return the number of received items. */ |
paul@181 | 330 | |
paul@181 | 331 | unsigned int ipc_message_number_of_items(ipc_message_t *msg) |
paul@181 | 332 | { |
paul@181 | 333 | return l4_msgtag_items(msg->tag); |
paul@181 | 334 | } |
paul@181 | 335 | |
paul@181 | 336 | /* Return the number of received words. */ |
paul@181 | 337 | |
paul@181 | 338 | unsigned int ipc_message_number_of_words(ipc_message_t *msg) |
paul@181 | 339 | { |
paul@181 | 340 | return l4_msgtag_words(msg->tag); |
paul@181 | 341 | } |
paul@181 | 342 | |
paul@181 | 343 | /* Message tag generation. */ |
paul@181 | 344 | |
paul@181 | 345 | l4_msgtag_t ipc_message_reply_tag(ipc_message_t *msg) |
paul@181 | 346 | { |
paul@181 | 347 | return l4_msgtag(msg->new_label, msg->words, msg->items, 0); |
paul@181 | 348 | } |
paul@181 | 349 | |
paul@181 | 350 | l4_msgtag_t ipc_message_request_tag(ipc_message_t *msg, int op) |
paul@181 | 351 | { |
paul@181 | 352 | return l4_msgtag(op, msg->words, msg->items, 0); |
paul@181 | 353 | } |
paul@181 | 354 | |
paul@181 | 355 | /* Reserve space for dimensioned data, returning a pointer to use to add the |
paul@181 | 356 | data. The length of the data is incorporated into the message. */ |
paul@181 | 357 | |
paul@181 | 358 | void *ipc_message_reserve_data(ipc_message_t *msg, size_t length) |
paul@181 | 359 | { |
paul@181 | 360 | /* Indicate the length of the data. */ |
paul@181 | 361 | |
paul@181 | 362 | ipc_message_add_word(msg, length); |
paul@181 | 363 | |
paul@181 | 364 | /* Reserve the space. */ |
paul@181 | 365 | |
paul@181 | 366 | return ipc_message_reserve_words(msg, length); |
paul@181 | 367 | } |
paul@181 | 368 | |
paul@181 | 369 | /* Reserve space for dimensioned data, returning a pointer to use to add the |
paul@181 | 370 | data. The length is not incorporated into the message. */ |
paul@181 | 371 | |
paul@181 | 372 | void *ipc_message_reserve_words(ipc_message_t *msg, size_t length) |
paul@181 | 373 | { |
paul@181 | 374 | /* Calculate the rounded-up size of the data and the necessary padding. */ |
paul@181 | 375 | |
paul@181 | 376 | size_t size = get_size_in_words(length); |
paul@181 | 377 | size_t padding = size - length; |
paul@181 | 378 | void *target; |
paul@181 | 379 | |
paul@181 | 380 | /* NOTE: Should test the length against the capacity of the message. */ |
paul@181 | 381 | |
paul@181 | 382 | /* Obtain the location of the next word, where the data will be copied. */ |
paul@181 | 383 | |
paul@181 | 384 | target = &msg->mregs.mr[msg->words]; |
paul@181 | 385 | |
paul@181 | 386 | /* Pad the data and update the number of words. */ |
paul@181 | 387 | |
paul@181 | 388 | memset(target + length, 0, padding); |
paul@181 | 389 | msg->words += size / sizeof(l4_umword_t); |
paul@181 | 390 | |
paul@181 | 391 | return target; |
paul@181 | 392 | } |
paul@181 | 393 | |
paul@181 | 394 | |
paul@181 | 395 | |
paul@181 | 396 | /* Discard a capability after replying. */ |
paul@181 | 397 | |
paul@181 | 398 | void ipc_message_discard_capability(ipc_message_t *msg, l4_cap_idx_t cap) |
paul@181 | 399 | { |
paul@181 | 400 | msg->to_discard[msg->discarded_items++] = cap; |
paul@181 | 401 | } |
paul@181 | 402 | |
paul@181 | 403 | /* Discard a dataspace. */ |
paul@181 | 404 | |
paul@181 | 405 | void ipc_message_discard_dataspace(ipc_message_t *msg, l4re_ds_t mem, l4_addr_t addr) |
paul@181 | 406 | { |
paul@181 | 407 | ipc_message_discard_capability(msg, mem); |
paul@181 | 408 | ipc_detach_dataspace((void *) addr); |
paul@181 | 409 | } |
paul@181 | 410 | |
paul@181 | 411 | /* Reserve the given number slots from zero for incoming capabilities. */ |
paul@181 | 412 | |
paul@181 | 413 | long ipc_message_expect_capabilities(ipc_message_t *msg, int number) |
paul@181 | 414 | { |
paul@181 | 415 | msg->expected_items = number; |
paul@181 | 416 | return _expect_capabilities(&msg->bregs, number); |
paul@181 | 417 | } |
paul@181 | 418 | |
paul@181 | 419 | /* Reserve a slot for an incoming capability. */ |
paul@181 | 420 | |
paul@181 | 421 | long ipc_message_expect_capability(ipc_message_t *msg, int item) |
paul@181 | 422 | { |
paul@181 | 423 | if (item >= (int) msg->expected_items) |
paul@181 | 424 | msg->expected_items = item + 1; |
paul@181 | 425 | |
paul@181 | 426 | return _expect_capability(&msg->bregs, item); |
paul@181 | 427 | } |
paul@181 | 428 | |
paul@181 | 429 | /* Export a capability at the given position in the message. */ |
paul@181 | 430 | |
paul@181 | 431 | void ipc_message_export_capability(ipc_message_t *msg, int item, l4_cap_idx_t ref) |
paul@181 | 432 | { |
paul@181 | 433 | msg->mregs.mr[msg->words + item * 2] = 0 | L4_ITEM_MAP; |
paul@181 | 434 | msg->mregs.mr[msg->words + item * 2 + 1] = l4_obj_fpage(ref, 0, L4_FPAGE_RWX).raw; |
paul@181 | 435 | } |
paul@181 | 436 | |
paul@181 | 437 | /* Export a flexpage at the given position in the message. Here, the snd_base |
paul@181 | 438 | member of the flexpage structure is used to hold the "hot spot" value. */ |
paul@181 | 439 | |
paul@181 | 440 | void ipc_message_export_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t fpage) |
paul@181 | 441 | { |
paul@181 | 442 | msg->mregs.mr[msg->words + item * 2] = l4_map_control(fpage.snd_base, L4_FPAGE_CACHEABLE, 0); |
paul@181 | 443 | msg->mregs.mr[msg->words + item * 2 + 1] = fpage.fpage.raw; |
paul@181 | 444 | } |
paul@181 | 445 | |
paul@181 | 446 | /* Export a flexpage at the given position in the message. */ |
paul@181 | 447 | |
paul@181 | 448 | void ipc_message_export_page(ipc_message_t *msg, int item, l4_umword_t hot_spot, l4_fpage_t fpage) |
paul@181 | 449 | { |
paul@181 | 450 | msg->mregs.mr[msg->words + item * 2] = l4_map_control(hot_spot, L4_FPAGE_CACHEABLE, 0); |
paul@181 | 451 | msg->mregs.mr[msg->words + item * 2 + 1] = fpage.raw; |
paul@181 | 452 | } |
paul@181 | 453 | |
paul@351 | 454 | /* Specify a receive window flexpage item in the message. */ |
paul@351 | 455 | |
paul@351 | 456 | void ipc_message_receive_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t fpage) |
paul@351 | 457 | { |
paul@351 | 458 | msg->bregs.br[item * 2] = l4_map_control(fpage.snd_base, 0, 0); |
paul@351 | 459 | msg->bregs.br[item * 2 + 1] = fpage.fpage.raw; |
paul@351 | 460 | } |
paul@351 | 461 | |
paul@351 | 462 | |
paul@351 | 463 | |
paul@181 | 464 | /* Import from the message the capability at the given item position, updating |
paul@181 | 465 | the buffer registers for future capabilities. */ |
paul@181 | 466 | |
paul@181 | 467 | long ipc_message_import_capability(ipc_message_t *msg, int item, l4_cap_idx_t *ref) |
paul@181 | 468 | { |
paul@181 | 469 | long err; |
paul@181 | 470 | |
paul@181 | 471 | err = _import_capability(msg->tag, &msg->bregs, &msg->mregs, item, ref); |
paul@181 | 472 | if (err) |
paul@181 | 473 | return err; |
paul@181 | 474 | |
paul@181 | 475 | return ipc_message_expect_capability(msg, item); |
paul@181 | 476 | } |
paul@181 | 477 | |
paul@181 | 478 | /* Import from the message a dataspace, mapping it to an address, updating the |
paul@181 | 479 | buffer registers for future capabilities. */ |
paul@181 | 480 | |
paul@181 | 481 | long ipc_message_import_dataspace(ipc_message_t *msg, int item, l4re_ds_t *mem, l4_addr_t *addr) |
paul@181 | 482 | { |
paul@181 | 483 | long err; |
paul@181 | 484 | |
paul@181 | 485 | err = _import_dataspace(msg->tag, &msg->bregs, &msg->mregs, item, mem, addr); |
paul@181 | 486 | if (err) |
paul@181 | 487 | return err; |
paul@181 | 488 | |
paul@181 | 489 | return ipc_message_expect_capability(msg, item); |
paul@181 | 490 | } |
paul@181 | 491 | |
paul@181 | 492 | /* Import from the message the flexpage at the given item position. */ |
paul@181 | 493 | |
paul@181 | 494 | long ipc_message_import_fpage(ipc_message_t *msg, int item, l4_snd_fpage_t *fpage) |
paul@181 | 495 | { |
paul@181 | 496 | return _import_fpage(msg->tag, &msg->bregs, &msg->mregs, item, fpage); |
paul@181 | 497 | } |
paul@181 | 498 | |
paul@181 | 499 | /* Export a capability, discarding it by propagating it to the recipient. */ |
paul@181 | 500 | |
paul@181 | 501 | void ipc_message_propagate_capability(ipc_message_t *msg, int item, l4_cap_idx_t ref) |
paul@181 | 502 | { |
paul@181 | 503 | ipc_message_export_capability(msg, item, ref); |
paul@181 | 504 | ipc_message_discard_capability(msg, ref); |
paul@181 | 505 | } |
paul@351 | 506 | |
paul@351 | 507 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@351 | 508 | */ |