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