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 #include "ioports.h"
11 #include "mem_man.h"
12 #include "globals.h"
13 
14 #include <l4/sys/types.h>
15 #include <l4/sys/ipc.h>
16 
17 #include <l4/cxx/iostream>
18 
19 enum { PORT_SHIFT = 12 };
20 
21 static Mem_man io_ports;
22 
init_io_ports()23 void init_io_ports()
24 {
25   io_ports.add_free(Region::kr(0, (64 * 1024) << PORT_SHIFT, 0, L4_FPAGE_RW));
26 }
27 
dump_io_ports()28 void dump_io_ports()
29 {
30   L4::cout << "IO PORTS--------------------------\n";
31   io_ports.dump();
32 }
33 
handle_io_page_fault(l4_umword_t t,l4_utcb_t * utcb,Answer * a)34 void handle_io_page_fault(l4_umword_t t, l4_utcb_t *utcb, Answer *a)
35 {
36   unsigned long port, size;
37   l4_fpage_t fp = (l4_fpage_t&)l4_utcb_mr_u(utcb)->mr[0];
38   port = l4_fpage_ioport(fp) << PORT_SHIFT;
39   size = l4_fpage_size(fp) + PORT_SHIFT;
40 
41   unsigned long i =
42     io_ports.alloc(Region::bs(port, 1UL << size, t, L4_FPAGE_RW));
43   if (i == port)
44     a->snd_fpage(l4_iofpage(port >> PORT_SHIFT, size - PORT_SHIFT));
45   else
46     a->error(L4_ENOMEM);
47 }
48