VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/the-linux-kernel.h@ 9238

Last change on this file since 9238 was 9238, checked in by vboxsync, 17 years ago

include linux/hrtimer.h too.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1/* $Id: the-linux-kernel.h 9238 2008-05-29 22:08:47Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Linux kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___the_linux_kernel_h
32#define ___the_linux_kernel_h
33
34/*
35 * Include iprt/types.h to install the bool wrappers.
36 * Then use the linux bool type for all the stuff include here.
37 */
38#include <iprt/types.h>
39#define bool linux_bool
40
41#include <linux/autoconf.h>
42#include <linux/version.h>
43
44/* We only support 2.4 and 2.6 series kernels */
45#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
46# error We only support 2.4 and 2.6 series kernels
47#endif
48#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
49# error We only support 2.4 and 2.6 series kernels
50#endif
51
52#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
53# define MODVERSIONS
54# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
55# include <linux/modversions.h>
56# endif
57#endif
58#ifndef KBUILD_STR
59# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
60# define KBUILD_STR(s) s
61# else
62# define KBUILD_STR(s) #s
63# endif
64#endif
65#include <linux/string.h>
66#include <linux/spinlock.h>
67#include <linux/slab.h>
68#include <asm/semaphore.h>
69#include <linux/module.h>
70#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
71# include <linux/moduleparam.h>
72#endif
73#include <linux/kernel.h>
74#include <linux/init.h>
75#include <linux/fs.h>
76#include <linux/mm.h>
77#include <linux/pagemap.h>
78#include <linux/slab.h>
79#include <linux/time.h>
80#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7)
81# include <linux/jiffies.h>
82#endif
83#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 16)
84# include <linux/ktime.h>
85# include <linux/hrtimer.h>
86#endif
87#include <linux/wait.h>
88/* For the basic additions module */
89#include <linux/pci.h>
90#include <linux/delay.h>
91#include <linux/interrupt.h>
92#include <linux/completion.h>
93#include <linux/compiler.h>
94#ifndef HAVE_UNLOCKED_IOCTL /* linux/fs.h defines this */
95# include <linux/smp_lock.h>
96#endif
97/* For the shared folders module */
98#include <linux/vmalloc.h>
99#define wchar_t linux_wchar_t
100#include <linux/nls.h>
101#undef wchar_t
102#include <asm/mman.h>
103#include <asm/io.h>
104#include <asm/uaccess.h>
105#include <asm/div64.h>
106
107#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
108# ifndef page_to_pfn
109# define page_to_pfn(page) ((page) - mem_map)
110# endif
111#endif
112
113#ifndef DEFINE_WAIT
114# define DEFINE_WAIT(name) DECLARE_WAITQUEUE(name, current)
115#endif
116
117/*
118 * 2.4 compatibility wrappers
119 */
120#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 7)
121
122# ifndef MAX_JIFFY_OFFSET
123# define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
124# endif
125
126#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 29) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
127
128DECLINLINE(unsigned int) jiffies_to_msecs(unsigned long cJiffies)
129{
130# if HZ <= 1000 && !(1000 % HZ)
131 return (1000 / HZ) * cJiffies;
132# elif HZ > 1000 && !(HZ % 1000)
133 return (cJiffies + (HZ / 1000) - 1) / (HZ / 1000);
134# else
135 return (cJiffies * 1000) / HZ;
136# endif
137}
138
139DECLINLINE(unsigned long) msecs_to_jiffies(unsigned int cMillies)
140{
141# if HZ > 1000
142 if (cMillies > jiffies_to_msecs(MAX_JIFFY_OFFSET))
143 return MAX_JIFFY_OFFSET;
144# endif
145# if HZ <= 1000 && !(1000 % HZ)
146 return (cMillies + (1000 / HZ) - 1) / (1000 / HZ);
147# elif HZ > 1000 && !(HZ % 1000)
148 return cMillies * (HZ / 1000);
149# else
150 return (cMillies * HZ + 999) / 1000;
151# endif
152}
153
154# endif /* < 2.4.29 || >= 2.6.0 */
155
156# define prepare_to_wait(q, wait, state) \
157 do { \
158 set_current_state(state); \
159 add_wait_queue(q, wait); \
160 } while (0)
161
162# define finish_wait(q, wait) \
163 do { \
164 remove_wait_queue(q, wait); \
165 set_current_state(TASK_RUNNING); \
166 } while (0)
167
168#endif /* < 2.6.7 */
169
170
171/*
172 * This sucks soooo badly on x86! Why don't they export __PAGE_KERNEL_EXEC so PAGE_KERNEL_EXEC would be usable?
173 */
174#if defined(RT_ARCH_AMD64)
175# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL_EXEC
176#elif defined(PAGE_KERNEL_EXEC) && defined(CONFIG_X86_PAE)
177# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? _PAGE_KERNEL_EXEC | _PAGE_GLOBAL : _PAGE_KERNEL_EXEC)
178#else
179# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL
180#endif
181
182
183/*
184 * The redhat hack section.
185 * - The current hacks are for 2.4.21-15.EL only.
186 */
187#ifndef NO_REDHAT_HACKS
188/* accounting. */
189# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
190# ifdef VM_ACCOUNT
191# define MY_DO_MUNMAP(a,b,c) do_munmap(a, b, c, 0) /* should it be 1 or 0? */
192# endif
193# endif
194
195/* backported remap_page_range. */
196# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
197# include <asm/tlb.h>
198# ifdef tlb_vma /* probably not good enough... */
199# define HAVE_26_STYLE_REMAP_PAGE_RANGE 1
200# endif
201# endif
202
203# ifndef RT_ARCH_AMD64
204/* In 2.6.9-22.ELsmp we have to call change_page_attr() twice when changing
205 * the page attributes from PAGE_KERNEL to something else, because there appears
206 * to be a bug in one of the many patches that redhat applied.
207 * It should be safe to do this on less buggy linux kernels too. ;-)
208 */
209# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
210 do { \
211 if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) \
212 change_page_attr(pPages, cPages, prot); \
213 change_page_attr(pPages, cPages, prot); \
214 } while (0)
215# endif /* !RT_ARCH_AMD64 */
216#endif /* !NO_REDHAT_HACKS */
217
218#ifndef MY_DO_MUNMAP
219# define MY_DO_MUNMAP(a,b,c) do_munmap(a, b, c)
220#endif
221
222#ifndef MY_CHANGE_PAGE_ATTR
223# ifdef RT_ARCH_AMD64 /** @todo This is a cheap hack, but it'll get around that 'else BUG();' in __change_page_attr(). */
224# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
225 do { \
226 change_page_attr(pPages, cPages, PAGE_KERNEL_NOCACHE); \
227 change_page_attr(pPages, cPages, prot); \
228 } while (0)
229# else
230# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) change_page_attr(pPages, cPages, prot)
231# endif
232#endif
233
234#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
235# define MY_SET_PAGES_EXEC(pPages, cPages) set_pages_x(pPages, cPages)
236# define MY_SET_PAGES_NOEXEC(pPages, cPages) set_pages_nx(pPages, cPages)
237#else
238# define MY_SET_PAGES_EXEC(pPages, cPages) \
239 do { \
240 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
241 MY_CHANGE_PAGE_ATTR(pPages, cPages, MY_PAGE_KERNEL_EXEC); \
242 } while (0)
243# define MY_SET_PAGES_NOEXEC(pPages, cPages) \
244 do { \
245 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
246 MY_CHANGE_PAGE_ATTR(pPages, cPages, PAGE_KERNEL); \
247 } while (0)
248#endif
249
250#ifndef PAGE_OFFSET_MASK
251# define PAGE_OFFSET_MASK (PAGE_SIZE - 1)
252#endif
253
254/** @def ONE_MSEC_IN_JIFFIES
255 * The number of jiffies that make up 1 millisecond. Must be at least 1! */
256#if HZ <= 1000
257# define ONE_MSEC_IN_JIFFIES 1
258#elif !(HZ % 1000)
259# define ONE_MSEC_IN_JIFFIES (HZ / 1000)
260#else
261# define ONE_MSEC_IN_JIFFIES ((HZ + 999) / 1000)
262# error "HZ is not a multiple of 1000, the GIP stuff won't work right!"
263#endif
264
265/** @def TICK_NSEC
266 * The time between ticks in nsec */
267#ifndef TICK_NSEC
268# define TICK_NSEC (1000000UL / HZ)
269#endif
270
271/*
272 * Stop using the linux bool type.
273 */
274#undef bool
275
276/*
277 * There are post-2.6.24 kernels (confusingly with unchanged version number)
278 * which eliminate macros which were marked as deprecated.
279 */
280#ifndef __attribute_used__
281#define __attribute_used__ __used
282#endif
283
284/**
285 * Hack for shortening pointers on linux so we can stuff more stuff into the
286 * task_struct::comm field. This is used by the semaphore code but put here
287 * because we don't have any better place atm. Don't use outside IPRT, please.
288 */
289#ifdef RT_ARCH_AMD64
290# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( ((long)(addr) & (long)~UINT64_C(0xfffffff000000000)) )
291#else
292# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( (long)(addr) )
293#endif
294
295#endif
296
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette