1 /* 2 * Interprocess communication utilities. 3 * 4 * Copyright (C) 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 #include <l4/re/c/dataspace.h> 23 #include <l4/re/consts.h> 24 #include <l4/sys/task.h> 25 26 #include <mem/send_flexpage.h> 27 28 #include "ipc.h" 29 30 31 32 /* Make an L4 representation of the given flexpage. */ 33 34 static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage) 35 { 36 unsigned char flags = send_flexpage->flags; 37 38 if (!flags) 39 flags = L4RE_DS_MAP_FLAG_RO; 40 41 return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags); 42 } 43 44 /* Make a representation of a flexpage for the IPC system. */ 45 46 long ipc_prepare_flexpage(Flexpage *flexpage, offset_t offset, 47 offset_t max_offset, address_t hot_spot, 48 map_flags_t flags, l4_snd_fpage_t *region) 49 { 50 SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, flags, 51 max_offset); 52 53 /* NOTE: Consider l4_fpage_invalid() as the fpage here. */ 54 55 if (!send_flexpage.order) 56 return -L4_ERANGE; 57 58 region->fpage = ipc_get_fpage(&send_flexpage); 59 region->snd_base = hot_spot; 60 61 return L4_EOK; 62 } 63 64 /* Unmap the given flexpage. */ 65 66 void ipc_unmap_flexpage(Flexpage *flexpage) 67 { 68 SendFlexpage send_flexpage = flexpage->to_unmap(); 69 70 l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES); 71 } 72 73 // vim: tabstop=4 expandtab shiftwidth=4