paul@93 | 1 | /* |
paul@93 | 2 | * Interprocess communication utilities. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@2 | 22 | #include <l4/re/c/dataspace.h> |
paul@4 | 23 | #include <l4/re/consts.h> |
paul@4 | 24 | #include <l4/sys/task.h> |
paul@2 | 25 | |
paul@94 | 26 | #include <mem/send_flexpage.h> |
paul@94 | 27 | |
paul@2 | 28 | #include "ipc.h" |
paul@2 | 29 | |
paul@2 | 30 | |
paul@4 | 31 | /* Make an L4 representation of the given flexpage. */ |
paul@4 | 32 | |
paul@11 | 33 | static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage) |
paul@4 | 34 | { |
paul@4 | 35 | return l4_fpage(send_flexpage->base_addr, send_flexpage->order, |
paul@11 | 36 | (send_flexpage->flags & L4RE_DS_MAP_FLAG_RW) ? L4_FPAGE_RW : L4_FPAGE_RO); |
paul@4 | 37 | } |
paul@4 | 38 | |
paul@4 | 39 | /* Make a representation of a flexpage for the IPC system. */ |
paul@4 | 40 | |
paul@92 | 41 | long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, |
paul@92 | 42 | offset_t max_offset, address_t hot_spot, |
paul@86 | 43 | flags_t flags, l4_snd_fpage_t *region) |
paul@2 | 44 | { |
paul@86 | 45 | SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags, |
paul@86 | 46 | max_offset); |
paul@4 | 47 | |
paul@25 | 48 | /* NOTE: Consider l4_fpage_invalid() as the fpage here. */ |
paul@25 | 49 | |
paul@4 | 50 | if (!send_flexpage.order) |
paul@4 | 51 | return -L4_ERANGE; |
paul@4 | 52 | |
paul@11 | 53 | region->fpage = ipc_get_fpage(&send_flexpage); |
paul@4 | 54 | region->snd_base = hot_spot; |
paul@2 | 55 | |
paul@4 | 56 | return L4_EOK; |
paul@4 | 57 | } |
paul@4 | 58 | |
paul@4 | 59 | /* Unmap the given flexpage. */ |
paul@4 | 60 | |
paul@4 | 61 | void ipc_unmap_flexpage(Flexpage *flexpage) |
paul@4 | 62 | { |
paul@4 | 63 | SendFlexpage send_flexpage = flexpage->to_unmap(); |
paul@4 | 64 | |
paul@11 | 65 | l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES); |
paul@2 | 66 | } |
paul@2 | 67 | |
paul@2 | 68 | // vim: tabstop=4 expandtab shiftwidth=4 |