1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11 
12 #include <l4/sys/utcb.h>
13 #include <l4/sys/types.h>
14 
15 enum
16 {
17   L4_fpage_cached   = L4_FPAGE_CACHEABLE << 4,
18   L4_fpage_uncached = L4_FPAGE_UNCACHEABLE << 4,
19   L4_fpage_buffered = L4_FPAGE_BUFFERABLE << 4,
20 };
21 
22 struct Answer
23 {
24 private:
snd_baseAnswer25   void snd_base(unsigned long base)
26   { l4_utcb_mr_u(utcb)->mr[0] = (base & L4_FPAGE_CONTROL_MASK) | L4_ITEM_MAP; }
27 
28 public:
29   l4_utcb_t *utcb;
30   l4_msgtag_t tag;
31 
AnswerAnswer32   Answer(l4_utcb_t *utcb) : utcb(utcb), tag(l4_msgtag(0, 0, 0, 0)) {}
33 
errorAnswer34   void error(int err) { tag = l4_msgtag(-err, 0, 0, 0); }
35 
36   void snd_fpage(l4_fpage_t const &fp, unsigned long snd_base = 0)
37   {
38     this->snd_base(snd_base);
39     l4_utcb_mr_u(utcb)->mr[1] = fp.raw;
40     tag = l4_msgtag(0, 0, 1, 0);
41   }
42 
snd_fpageAnswer43   void snd_fpage(unsigned long addr, unsigned size, unsigned access,
44                  bool cache)
45   {
46     snd_base(addr);
47     if (cache)
48       l4_utcb_mr_u(utcb)->mr[0] |= L4_fpage_cached;
49     else
50       l4_utcb_mr_u(utcb)->mr[0] |= L4_fpage_uncached;
51 
52     l4_utcb_mr_u(utcb)->mr[1] = l4_fpage(addr, size, access).raw;
53 
54     tag = l4_msgtag(0, 0, 1, 0);
55   }
56 
failedAnswer57   bool failed() const
58   { return tag.label() < 0; }
59 };
60