]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/kip.h
update
[l4.git] / l4 / pkg / l4sys / include / kip.h
1 /**
2  * \file
3  * \brief Kernel Info Page access functions.
4  * \ingroup l4_api
5  */
6 /*
7  * (c) 2008-2013 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  *               Alexander Warg <warg@os.inf.tu-dresden.de>
9  *     economic rights: Technische Universität Dresden (Germany)
10  *
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU General Public License 2.
13  * Please see the COPYING-GPL-2 file for details.
14  *
15  * As a special exception, you may use this file as part of a free software
16  * library without restriction.  Specifically, if other files instantiate
17  * templates or use macros or inline functions from this file, or you compile
18  * this file and link it with other files to produce an executable, this
19  * file does not by itself cause the resulting executable to be covered by
20  * the GNU General Public License.  This exception does not however
21  * invalidate any other reasons why the executable file might be covered by
22  * the GNU General Public License.
23  */
24 #pragma once
25
26 #include <l4/sys/compiler.h>
27 #include <l4/sys/l4int.h>
28
29 #include <l4/sys/__kip-arch.h>
30
31 /**
32  * \internal
33  */
34 struct l4_kip_platform_info
35 {
36   char                             name[16];
37   l4_uint32_t                      is_mp;
38   struct l4_kip_platform_info_arch arch;
39 };
40
41 #if L4_MWORD_BITS == 32
42 #  include <l4/sys/__kip-32bit.h>
43 #else
44 #  include <l4/sys/__kip-64bit.h>
45 #endif
46
47 /**
48  * \addtogroup l4_kip_api
49  *
50  * C interface for the Kernel Interface Page:<br>
51  * <c>\#include <l4/sys/kip.h></c>
52  */
53 /*@{*/
54
55 /**
56  * \internal
57  */
58 enum l4_kernel_info_consts_t
59 {
60   L4_KIP_VERSION_FIASCO      = 0x87004444,
61   L4_KIP_VERSION_FIASCO_MASK = 0xff00ffff,
62 };
63
64 /**
65  * \brief Kernel Info Page identifier ("L4µK").
66  */
67 #define L4_KERNEL_INFO_MAGIC (0x4BE6344CL) /* "L4µK" */
68
69
70 /**
71  * \brief  Get the kernel version.
72  * \param kip Kernel Info Page.
73  * \return Kernel version string. 0 if KIP could not be mapped.
74  */
75 L4_INLINE l4_umword_t l4_kip_version(l4_kernel_info_t *kip) L4_NOTHROW;
76
77 /**
78  * \brief  Get the kernel version string.
79  * \param kip Kernel Info Page.
80  * \return Kernel version string.
81  */
82 L4_INLINE const char *l4_kip_version_string(l4_kernel_info_t *kip) L4_NOTHROW;
83
84 /**
85  * \brief Return offset in bytes of version_strings relative to the KIP base.
86  *
87  * \param kip   Pointer to the kernel info page (KIP).
88  *
89  * \return offset of version_strings relative to the KIP base address, in
90  *         bytes.
91  */
92 L4_INLINE int
93 l4_kernel_info_version_offset(l4_kernel_info_t *kip) L4_NOTHROW;
94
95 /**
96  * \brief Return clock value from the KIP.
97  *
98  * \param kip   Pointer to the kernel info page (KIP).
99  *
100  * \return Value of the clock field in the KIP.
101  */
102 L4_INLINE l4_cpu_time_t
103 l4_kip_clock(l4_kernel_info_t *kip) L4_NOTHROW;
104
105 /**
106  * \brief Return least significant machine word of clock value from the KIP.
107  *
108  * \param kip   Pointer to the kernel info page (KIP).
109  *
110  * \return Lower machine word of clock value from the KIP.
111  */
112 L4_INLINE l4_umword_t
113 l4_kip_clock_lw(l4_kernel_info_t *kip) L4_NOTHROW;
114
115 /*@}*/
116
117 /*************************************************************************
118  * Implementations
119  *************************************************************************/
120
121 L4_INLINE l4_umword_t
122 l4_kip_version(l4_kernel_info_t *kip) L4_NOTHROW
123 { return kip->version & L4_KIP_VERSION_FIASCO_MASK; }
124
125 L4_INLINE const char*
126 l4_kip_version_string(l4_kernel_info_t *k) L4_NOTHROW
127 { return (const char *)k + l4_kernel_info_version_offset(k); }
128
129 L4_INLINE int
130 l4_kernel_info_version_offset(l4_kernel_info_t *kip) L4_NOTHROW
131 { return kip->offset_version_strings << 4; }
132
133 L4_INLINE l4_cpu_time_t
134 l4_kip_clock(l4_kernel_info_t *kip) L4_NOTHROW
135 {
136   unsigned long h1, l;
137   unsigned long *c = (unsigned long *)&kip->_clock_val;
138
139   if (sizeof(unsigned long) == 8)
140     return kip->_clock_val;
141
142   do
143     {
144       h1 = c[1];
145       l4_mb();
146       l  = c[0];
147       l4_mb();
148     }
149   while (h1 != c[1]);
150
151   return ((unsigned long long)h1 << 32) | l;
152 }
153
154 L4_INLINE l4_umword_t
155 l4_kip_clock_lw(l4_kernel_info_t *kip) L4_NOTHROW
156 {
157   /* We do the casting because the clock field is volatile */
158   unsigned long *c = (unsigned long *)&kip->_clock_val;
159   l4_mb();
160   return c[0];
161 }