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