]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/libsigma0/lib/src/anypage.c
Update
[l4.git] / l4 / pkg / l4re-core / libsigma0 / lib / src / anypage.c
1 /**
2  * \file        sigma0/lib/src/iomem.c
3  * \brief       map any page using sigma0 protocol
4  *
5  * \date        02/2006
6  * \author      Frank Mehnert <fm3@os.inf.tu-dresden.de> */
7
8 /*
9  * (c) 2006-2009 Author(s)
10  *     economic rights: Technische Universität Dresden (Germany)
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU Lesser General Public License 2.1.
13  * Please see the COPYING-LGPL-2.1 file for details.
14  */
15
16 #include <l4/sys/ipc.h>
17 #include <l4/sigma0/sigma0.h>
18
19
20 /**
21  * Map one page anonymous memory.
22  *
23  * \param pager          pager implementing the Sigma0 protocol
24  * \param map_area       virtual address of the map area
25  * \param log2_map_size  size of the map area
26  * \param sz             Size to map from the server, in log2.
27  * \return           #0                 on success
28  *                  -#L4SIGMA0_IPCERROR IPC error
29  *                  -#L4SIGMA0_NOFPAGE  no fpage received
30  */
31 L4_CV int
32 l4sigma0_map_anypage(l4_cap_idx_t pager, l4_addr_t map_area,
33                      unsigned log2_map_size, l4_addr_t *base, unsigned sz)
34 {
35   l4_msgtag_t tag = l4_msgtag(L4_PROTO_SIGMA0, 2, 0, 0);
36   l4_utcb_t *utcb = l4_utcb();
37   l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
38   l4_buf_regs_t *b = l4_utcb_br_u(utcb);
39
40   m->mr[0] = SIGMA0_REQ_FPAGE_ANY;
41   m->mr[1] = l4_fpage(0, sz, 0).raw;
42
43   b->bdr = 0;
44   b->br[0] = L4_ITEM_MAP;
45   b->br[1] = l4_fpage(map_area, log2_map_size, L4_FPAGE_RWX).raw;
46
47   tag = l4_ipc_call(pager, utcb, tag, L4_IPC_NEVER);
48   if (l4_ipc_error(tag, utcb))
49     return -L4SIGMA0_IPCERROR;
50
51   if (l4_msgtag_items(tag) != 1)
52     return -L4SIGMA0_NOFPAGE;
53
54   *base = m->mr[0] & (~0UL << L4_PAGESHIFT);
55
56   return 0;
57 }