Import from upstream.
[nvidia.git] / src / nvidia_linux.c
1 /* _NVRM_COPYRIGHT_BEGIN_
2  *
3  * Copyright 2001-2002 by NVIDIA Corporation.  All rights reserved.  All
4  * information contained herein is proprietary and confidential to NVIDIA
5  * Corporation.  Any use, reproduction, or disclosure without the written
6  * permission of NVIDIA Corporation is prohibited.
7  *
8  * _NVRM_COPYRIGHT_END_
9  */
10
11 #include "nv-misc.h"
12 #include "os-interface.h"
13 #include "nv.h"
14 #include "nv-freebsd.h"
15
16 #ifdef NV_SUPPORT_LINUX_COMPAT /* (COMPAT_LINUX || COMPAT_LINUX32) */
17
18 #define LINUX_IOCTL_NVIDIA_MIN 0x4600
19 #define LINUX_IOCTL_NVIDIA_MAX 0x46ff
20
21 #if defined(NVCPU_X86)
22 #include "machine/../linux/linux.h"
23 #endif
24
25 #if defined(NVCPU_X86_64)
26 #include "machine/../linux32/linux.h"
27 #endif
28
29 int linux_ioctl_nvidia(d_thread_t *, struct linux_ioctl_args *);
30
31 int linux_ioctl_nvidia(
32     d_thread_t *td,
33     struct linux_ioctl_args *args
34 )
35 {
36     /*
37      * The range has already been checked, and the native NVIDIA ioctl()
38      * implementation will throw out any commands it does not recognize.
39      * There is no good reason why we should manually translate each and
40      * every one of the possible NVIDIA ioctl commands.
41      *
42      * Since the Linux driver uses the _IO macros to encode the required
43      * data, the native ioctl layer can determine the parameter size and
44      * copy the user data in/out correctly.
45      */
46
47     return (ioctl(td, (struct ioctl_args *) args));
48 }
49
50 struct linux_ioctl_handler nvidia_handler = {
51     linux_ioctl_nvidia,
52     LINUX_IOCTL_NVIDIA_MIN,
53     LINUX_IOCTL_NVIDIA_MAX
54 };
55 #endif /* NV_SUPPORT_LINUX_COMPAT */
56
57
58 void nvidia_linux_init(void)
59 {
60 #ifdef NV_SUPPORT_LINUX_COMPAT /* (COMPAT_LINUX || COMPAT_LINUX32) */
61     linux_ioctl_register_handler(&nvidia_handler);
62 #endif
63 }
64
65 void nvidia_linux_exit(void)
66 {
67 #ifdef NV_SUPPORT_LINUX_COMPAT /* (COMPAT_LINUX || COMPAT_LINUX32) */
68     linux_ioctl_unregister_handler(&nvidia_handler);
69 #endif
70 }
71