VirtualBox

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

Last change on this file since 1507 was 331, checked in by vboxsync, 18 years ago

Bool and AMD64 hacking.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1/* $Id: the-linux-kernel.h 331 2007-01-25 20:47:51Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Include all necessary headers for the Linux kernel.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef __the_linux_kernel_h__
23#define __the_linux_kernel_h__
24
25/*
26 * Include iprt/types.h to install the bool wrappers.
27 * Then use the linux bool type for all the stuff include here.
28 */
29#include <iprt/types.h>
30#define bool linux_bool
31
32#include <linux/autoconf.h>
33#include <linux/version.h>
34
35/* We only support 2.4 and 2.6 series kernels */
36#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
37# error We only support 2.4 and 2.6 series kernels
38#endif
39#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
40# error We only support 2.4 and 2.6 series kernels
41#endif
42
43#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
44# define MODVERSIONS
45# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
46# include <linux/modversions.h>
47# endif
48#endif
49#ifndef KBUILD_STR
50# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
51# define KBUILD_STR(s) s
52# else
53# define KBUILD_STR(s) #s
54# endif
55#endif
56#include <linux/string.h>
57#include <linux/spinlock.h>
58#include <linux/slab.h>
59#include <asm/semaphore.h>
60#include <linux/module.h>
61#include <linux/kernel.h>
62#include <linux/init.h>
63#include <linux/fs.h>
64#include <linux/mm.h>
65#include <linux/pagemap.h>
66#include <linux/slab.h>
67#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7)
68# include <linux/time.h>
69# include <linux/jiffies.h>
70#endif
71#include <linux/wait.h>
72/* For the basic additions module */
73#include <linux/pci.h>
74#include <linux/delay.h>
75#include <linux/interrupt.h>
76#include <linux/completion.h>
77/* For the shared folders module */
78#include <linux/vmalloc.h>
79#define wchar_t linux_wchar_t
80#include <linux/nls.h>
81#undef wchar_t
82#include <asm/mman.h>
83#include <asm/io.h>
84#include <asm/uaccess.h>
85#include <asm/div64.h>
86
87#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
88# ifndef page_to_pfn
89# define page_to_pfn(page) ((page) - mem_map)
90# endif
91#endif
92
93#ifndef DEFINE_WAIT
94# define DEFINE_WAIT(name) DECLARE_WAITQUEUE(name, current)
95#endif
96
97/*
98 * 2.4 compatibility wrappers
99 */
100#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 7)
101
102# ifndef MAX_JIFFY_OFFSET
103# define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
104# endif
105
106#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 29) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
107
108DECLINLINE(unsigned int) jiffies_to_msecs(unsigned long cJiffies)
109{
110# if HZ <= 1000 && !(1000 % HZ)
111 return (1000 / HZ) * cJiffies;
112# elif HZ > 1000 && !(HZ % 1000)
113 return (cJiffies + (HZ / 1000) - 1) / (HZ / 1000);
114# else
115 return (j * 1000) / HZ;
116# endif
117}
118
119DECLINLINE(unsigned long) msecs_to_jiffies(unsigned int cMillies)
120{
121# if HZ > 1000
122 if (cMillies > jiffies_to_msecs(MAX_JIFFY_OFFSET))
123 return MAX_JIFFY_OFFSET;
124# endif
125# if HZ <= 1000 && !(1000 % HZ)
126 return (cMillies + (1000 / HZ) - 1) / (1000 / HZ);
127# elif HZ > 1000 && !(HZ % 1000)
128 return cMillies * (HZ / 1000);
129# else
130 return (cMillies * HZ + 999) / 1000;
131# endif
132}
133
134# endif /* < 2.4.29 || >= 2.6.0 */
135
136# define prepare_to_wait(q, wait, state) \
137 do { \
138 set_current_state(state); \
139 add_wait_queue(q, wait); \
140 } while (0)
141
142# define finish_wait(q, wait) \
143 do { \
144 remove_wait_queue(q, wait); \
145 set_current_state(TASK_RUNNING); \
146 } while (0)
147
148#endif /* < 2.6.7 */
149
150
151/*
152 * This sucks soooo badly! Why don't they export __PAGE_KERNEL_EXEC so PAGE_KERNEL_EXEC would be usable?
153 */
154#if defined(PAGE_KERNEL_EXEC) && defined(CONFIG_X86_PAE)
155# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? _PAGE_KERNEL_EXEC | _PAGE_GLOBAL : _PAGE_KERNEL_EXEC)
156#else
157# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL
158#endif
159
160
161/*
162 * The redhat hack section.
163 * - The current hacks are for 2.4.21-15.EL only.
164 */
165#ifndef NO_REDHAT_HACKS
166/* accounting. */
167# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
168# ifdef VM_ACCOUNT
169# define MY_DO_MUNMAP(a,b,c) do_munmap(a, b, c, 0) /* should it be 1 or 0? */
170# endif
171# endif
172
173/* backported remap_page_range. */
174# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
175# include <asm/tlb.h>
176# ifdef tlb_vma /* probably not good enough... */
177# define HAVE_26_STYLE_REMAP_PAGE_RANGE 1
178# endif
179# endif
180
181# ifndef __AMD64__
182/* In 2.6.9-22.ELsmp we have to call change_page_attr() twice when changing
183 * the page attributes from PAGE_KERNEL to something else, because there appears
184 * to be a bug in one of the many patches that redhat applied.
185 * It should be safe to do this on less buggy linux kernels too. ;-)
186 */
187# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
188 do { \
189 if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) \
190 change_page_attr(pPages, cPages, prot); \
191 change_page_attr(pPages, cPages, prot); \
192 } while (0)
193# endif /* !__AMD64__ */
194#endif /* !NO_REDHAT_HACKS */
195
196
197#ifndef MY_DO_MUNMAP
198# define MY_DO_MUNMAP(a,b,c) do_munmap(a, b, c)
199#endif
200
201#ifndef MY_CHANGE_PAGE_ATTR
202# ifdef __AMD64__ /** @todo This is a cheap hack, but it'll get around that 'else BUG();' in __change_page_attr(). */
203# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
204 do { \
205 change_page_attr(pPages, cPages, PAGE_KERNEL_NOCACHE); \
206 change_page_attr(pPages, cPages, prot); \
207 } while (0)
208# else
209# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) change_page_attr(pPages, cPages, prot)
210# endif
211#endif
212
213#ifndef PAGE_OFFSET_MASK
214# define PAGE_OFFSET_MASK (PAGE_SIZE - 1)
215#endif
216
217/*
218 * Stop using the linux bool type.
219 */
220#undef bool
221
222#endif
223
Note: See TracBrowser for help on using the repository browser.

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