1 /*****************************************************************************/
2 /**
3 * \file
4 * Descriptors for virtual hardware (under UX).
5 * \ingroup l4_api
6 */
7 /*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
11 *
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
15 *
16 * As a special exception, you may use this file as part of a free software
17 * library without restriction. Specifically, if other files instantiate
18 * templates or use macros or inline functions from this file, or you compile
19 * this file and link it with other files to produce an executable, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU General Public License. This exception does not however
22 * invalidate any other reasons why the executable file might be covered by
23 * the GNU General Public License.
24 */
25 /*****************************************************************************/
26 #ifndef _L4_SYS_VHW_H
27 #define _L4_SYS_VHW_H
28
29 #include <l4/sys/types.h>
30 #include <l4/sys/kip.h>
31
32 /**
33 * \defgroup l4_kip_vhw_api Fiasco-UX Virtual devices
34 * \ingroup l4_kip_api
35 * Virtual hardware devices, provided by Fiasco-UX.
36 *
37 * \includefile{l4/sys/vhw.h}
38 */
39
40 /**
41 * Type of device.
42 * \ingroup l4_kip_vhw_api
43 */
44 enum l4_vhw_entry_type {
45 L4_TYPE_VHW_NONE, /**< None entry. */
46 L4_TYPE_VHW_FRAMEBUFFER, /**< Framebuffer device. */
47 L4_TYPE_VHW_INPUT, /**< Input device. */
48 L4_TYPE_VHW_NET, /**< Network device. */
49 };
50
51 /**
52 * Description of a device.
53 * \ingroup l4_kip_vhw_api
54 */
55 struct l4_vhw_entry {
56 enum l4_vhw_entry_type type; /**< Type of virtual hardware. */
57 l4_uint32_t provider_pid; /**< Host PID of the VHW provider. */
58
59 l4_addr_t mem_start; /**< Start of memory region. */
60 l4_addr_t mem_size; /**< Size of memory region. */
61
62 l4_uint32_t irq_no; /**< IRQ number. */
63 l4_uint32_t fd; /**< File descriptor. */
64 };
65
66 /**
67 * Virtual hardware devices description.
68 * \ingroup l4_kip_vhw_api
69 */
70 struct l4_vhw_descriptor {
71 l4_uint32_t magic; /**< Magic. */
72 l4_uint8_t version; /**< Version of the descriptor. */
73 l4_uint8_t count; /**< Number of entries. */
74 l4_uint8_t pad1; /**< padding \internal. */
75 l4_uint8_t pad2; /**< padding \internal. */
76
77 struct l4_vhw_entry descs[]; /**< Array of device descriptions. */
78 };
79
80 enum {
81 L4_VHW_MAGIC = 0x56687765,
82 };
83
84 static inline struct l4_vhw_descriptor *
l4_vhw_get(l4_kernel_info_t * kip)85 l4_vhw_get(l4_kernel_info_t *kip) L4_NOTHROW
86 {
87 struct l4_vhw_descriptor *v
88 = (struct l4_vhw_descriptor *)(((unsigned long)kip) + kip->vhw_offset);
89
90 if (v->magic == L4_VHW_MAGIC)
91 return v;
92
93 return NULL;
94 }
95
96 static inline struct l4_vhw_entry *
l4_vhw_get_entry(struct l4_vhw_descriptor * v,int entry)97 l4_vhw_get_entry(struct l4_vhw_descriptor *v, int entry) L4_NOTHROW
98 {
99 return v->descs + entry;
100 }
101
102 static inline struct l4_vhw_entry *
l4_vhw_get_entry_type(struct l4_vhw_descriptor * v,enum l4_vhw_entry_type t)103 l4_vhw_get_entry_type(struct l4_vhw_descriptor *v, enum l4_vhw_entry_type t) L4_NOTHROW
104 {
105 int i;
106 struct l4_vhw_entry *e = v->descs;
107
108 for (i = 0; i < v->count; i++, e++)
109 if (e->type == t)
110 return e;
111
112 return NULL;
113 }
114
115 #endif /* ! _L4_SYS_VHW_H */
116