1.1 --- a/ipc.cc Thu Jan 21 23:36:53 2021 +0100
1.2 +++ b/ipc.cc Thu Jan 21 23:38:37 2021 +0100
1.3 @@ -1,22 +1,48 @@
1.4 #include <l4/re/c/dataspace.h>
1.5 +#include <l4/re/consts.h>
1.6 +#include <l4/sys/task.h>
1.7
1.8 #include "ipc.h"
1.9 #include "send_flexpage.h"
1.10
1.11
1.12
1.13 -/* Make a representation of the flexpage for the IPC system. */
1.14 +/* Make an L4 representation of the given flexpage. */
1.15 +
1.16 +static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage)
1.17 +{
1.18 + // NOTE: To introduce flags properly in the flexpage abstractions.
1.19 +
1.20 + unsigned long flags = L4_FPAGE_RW;
1.21
1.22 -void ipc_prepare_flexpage(Flexpage *flexpage, unsigned long offset,
1.23 - l4_addr_t hot_spot, unsigned long flags,
1.24 - l4_snd_fpage_t *region)
1.25 + return l4_fpage(send_flexpage->base_addr, send_flexpage->order,
1.26 + (flags & L4RE_DS_MAP_FLAG_RW) ? L4_FPAGE_RW : L4_FPAGE_RO);
1.27 +}
1.28 +
1.29 +/* Make a representation of a flexpage for the IPC system. */
1.30 +
1.31 +long ipc_prepare_flexpage(Flexpage *flexpage, unsigned long offset,
1.32 + unsigned long max_offset, l4_addr_t hot_spot,
1.33 + unsigned long flags, l4_snd_fpage_t *region)
1.34 {
1.35 - SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot);
1.36 + SendFlexpage send_flexpage = flexpage->to_send(offset, hot_spot, max_offset);
1.37 +
1.38 + if (!send_flexpage.order)
1.39 + return -L4_ERANGE;
1.40 +
1.41 + region->fpage = ipc_get_fpage(&send_flexpage);
1.42 + region->snd_base = hot_spot;
1.43
1.44 - region->fpage = l4_fpage(send_flexpage.base_addr, send_flexpage.order,
1.45 - (flags & L4RE_DS_MAP_FLAG_RW) ? L4_FPAGE_RW
1.46 - : L4_FPAGE_RO);
1.47 - region->snd_base = hot_spot;
1.48 + return L4_EOK;
1.49 +}
1.50 +
1.51 +/* Unmap the given flexpage. */
1.52 +
1.53 +void ipc_unmap_flexpage(Flexpage *flexpage)
1.54 +{
1.55 + SendFlexpage send_flexpage = flexpage->to_unmap();
1.56 +
1.57 + l4_task_unmap(L4RE_THIS_TASK_CAP, ipc_get_fpage(&send_flexpage), L4_FP_OTHER_SPACES);
1.58 }
1.59
1.60 // vim: tabstop=4 expandtab shiftwidth=4