import NVIDIA-FreeBSD-x86-185.18.36
[nvidia.git] / src / os-interface.h
1 /* _NVRM_COPYRIGHT_BEGIN_
2  *
3  * Copyright 1999-2001 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
12 /*
13  * Os interface definitions needed by os-interface.c
14  */
15
16 #ifndef _OS_INTERFACE_H_
17 #define _OS_INTERFACE_H_
18
19 /******************* Operating System Interface Routines *******************\
20 *                                                                           *
21 * Module: os-interface.h                                                    *
22 *       Included by os.h                                                    *
23 *       Operating system wrapper functions used to abstract the OS.         *
24 *                                                                           *
25 \***************************************************************************/
26
27 /*
28  * Define away Microsoft compiler extensions when possible
29  */
30
31 #define __stdcall
32 #define far
33 #define PASCAL
34
35 /*
36  * Make sure that arguments to and from the core resource manager
37  * are passed and expected on the stack. define duplicated in nv.h
38  */
39 #if !defined(NV_API_CALL)
40 #if defined(NVCPU_X86)
41 #if defined(__use_altstack__)
42 #define NV_API_CALL __attribute__((regparm(0),altstack(false)))
43 #else
44 #define NV_API_CALL __attribute__((regparm(0)))
45 #endif
46 #elif defined(NVCPU_X86_64) && defined(__use_altstack__)
47 #define NV_API_CALL __attribute__((altstack(false)))
48 #else
49 #define NV_API_CALL
50 #endif
51 #endif /* !defined(NV_API_CALL) */
52
53 /*
54  * ---------------------------------------------------------------------------
55  *
56  * Function prototypes for OS interface.
57  *
58  * ---------------------------------------------------------------------------
59  */
60
61 U032        NV_API_CALL  os_get_page_size            (void);
62 NvU64       NV_API_CALL  os_get_page_mask            (void);
63 NvU64       NV_API_CALL  os_get_system_memory_size   (void);
64 RM_STATUS   NV_API_CALL  os_alloc_mem                (void **, U032);
65 void        NV_API_CALL  os_free_mem                 (void *);
66 RM_STATUS   NV_API_CALL  os_get_current_time         (U032 *, U032 *);
67 RM_STATUS   NV_API_CALL  os_delay                    (U032);
68 RM_STATUS   NV_API_CALL  os_delay_us                 (U032);
69 U032        NV_API_CALL  os_get_cpu_frequency        (void);
70 U032        NV_API_CALL  os_get_current_process      (void);
71 char*       NV_API_CALL  os_string_copy              (char *, const char *);
72 RM_STATUS   NV_API_CALL  os_strncpy_from_user        (char *, const char *, U032);
73 S032        NV_API_CALL  os_string_compare           (const char *, const char *);
74 U032        NV_API_CALL  os_string_length            (const char *);
75 U008*       NV_API_CALL  os_mem_copy                 (U008 *, const U008 *, U032);
76 RM_STATUS   NV_API_CALL  os_memcpy_from_user         (void *, const void *, U032);
77 RM_STATUS   NV_API_CALL  os_memcpy_to_user           (void *, const void *, U032);
78 void*       NV_API_CALL  os_mem_set                  (void *, U008, U032);
79 S032        NV_API_CALL  os_mem_cmp                  (const U008 *, const U008 *, U032);
80 void*       NV_API_CALL  os_pci_init_handle          (U008, U008, U008, U016 *, U016 *);
81 U008        NV_API_CALL  os_pci_read_byte            (void *, U008);
82 U016        NV_API_CALL  os_pci_read_word            (void *, U008);
83 U032        NV_API_CALL  os_pci_read_dword           (void *, U008);
84 void        NV_API_CALL  os_pci_write_byte           (void *, U008, U008);
85 void        NV_API_CALL  os_pci_write_word           (void *, U008, U016);
86 void        NV_API_CALL  os_pci_write_dword          (void *, U008, U032);
87 void*       NV_API_CALL  os_map_kernel_space         (NvU64, NvU64, U032);
88 void        NV_API_CALL  os_unmap_kernel_space       (void *, NvU64);
89 RM_STATUS   NV_API_CALL  os_flush_cpu_cache          (void);
90 void        NV_API_CALL  os_flush_cpu_write_combine_buffer(void);
91 RM_STATUS   NV_API_CALL  os_set_mem_range            (NvU64, NvU64, U032);
92 RM_STATUS   NV_API_CALL  os_unset_mem_range          (NvU64, NvU64);
93 BOOL        NV_API_CALL  os_pci_device_present       (U016, U016);
94 U008        NV_API_CALL  os_io_read_byte             (PHWINFO, U032);
95 U016        NV_API_CALL  os_io_read_word             (PHWINFO, U032);
96 U032        NV_API_CALL  os_io_read_dword            (PHWINFO, U032);
97 void        NV_API_CALL  os_io_write_byte            (PHWINFO, U032, U008);
98 void        NV_API_CALL  os_io_write_word            (PHWINFO, U032, U016);
99 void        NV_API_CALL  os_io_write_dword           (PHWINFO, U032, U032);
100 BOOL        NV_API_CALL  os_is_administrator         (PHWINFO);
101 void        NV_API_CALL  os_dbg_init                 (void);
102 void        NV_API_CALL  os_dbg_breakpoint           (void);
103 void        NV_API_CALL  os_dbg_set_level            (U032);
104 U032        NV_API_CALL  os_get_cpu_count            (void);
105 RM_STATUS   NV_API_CALL  os_raise_smp_barrier        (void);
106 RM_STATUS   NV_API_CALL  os_clear_smp_barrier        (void);
107 RM_STATUS   NV_API_CALL  os_disable_console_access   (void);
108 RM_STATUS   NV_API_CALL  os_enable_console_access    (void);
109 RM_STATUS   NV_API_CALL  os_registry_init            (void);
110 RM_STATUS   NV_API_CALL  os_alloc_sema               (void **);
111 RM_STATUS   NV_API_CALL  os_free_sema                (void *);
112 RM_STATUS   NV_API_CALL  os_acquire_sema             (void *);
113 BOOL        NV_API_CALL  os_cond_acquire_sema        (void *);
114 RM_STATUS   NV_API_CALL  os_release_sema             (void *);
115 BOOL        NV_API_CALL  os_is_acquired_sema         (void *);
116 RM_STATUS   NV_API_CALL  os_schedule                 (void);
117 NvU64       NV_API_CALL  os_acquire_spinlock         (void *);
118 void        NV_API_CALL  os_release_spinlock         (void *, NvU64);
119
120
121 void        NV_API_CALL  os_register_compatible_ioctl    (U032, U032);
122 void        NV_API_CALL  os_unregister_compatible_ioctl  (U032, U032);
123
124 /* BOOL os_pat_supported(void) 
125  * report to core resman whether pat is supported for marking cache attributes
126  * or if mtrrs are needed. primarily for indicating whether os_set_mem_range
127  * needs to be called to mark the agp aperture write-combined.
128  */
129
130 BOOL        NV_API_CALL  os_pat_supported(void);
131
132 void        NV_API_CALL  os_dump_stack (void);
133
134 /*
135  * ---------------------------------------------------------------------------
136  *
137  * Debug macros.
138  *
139  * ---------------------------------------------------------------------------
140  */
141
142 /* enable debugging if any OS debugging flag is set */
143 #undef DEBUGGING
144 #if defined(DEBUG) || defined(DBG)
145 #define DEBUGGING
146 #endif
147
148 #if !defined(DBG_LEVEL_INFO)
149 /*
150  * Debug Level values
151  */
152 #define DBG_LEVEL_INFO          0x0   /* For informational debug trace info */
153 #define DBG_LEVEL_SETUPINFO     0x1   /* For informational debug setup info */
154 #define DBG_LEVEL_USERERRORS    0x2   /* For debug info on app level errors */ 
155 #define DBG_LEVEL_WARNINGS      0x3   /* For RM debug warning info          */
156 #define DBG_LEVEL_ERRORS        0x4   /* For RM debug error info            */
157 #endif
158
159 #define NV_DBG_INFO       0x0
160 #define NV_DBG_SETUP      0x1
161 #define NV_DBG_USERERRORS 0x2
162 #define NV_DBG_WARNINGS   0x3
163 #define NV_DBG_ERRORS     0x4
164
165
166 void NV_API_CALL  out_string(const char *str);
167 int  NV_API_CALL  nv_printf(U032 debuglevel, const char *printf_format, ...);
168 void NV_API_CALL  nv_prints(U032 debuglevel, const char *string);
169 int  NV_API_CALL  nv_snprintf(char *buf, unsigned int size, const char *fmt, ...);
170 void NV_API_CALL  nv_os_log(int log_level, const char *fmt, void *ap);
171
172
173 #define NV_MEMORY_TYPE_SYSTEM       0
174 #define NV_MEMORY_TYPE_AGP          1
175 #define NV_MEMORY_TYPE_REGISTERS    2
176 #define NV_MEMORY_TYPE_FRAMEBUFFER  3
177
178 #define NV_MEMORY_NONCONTIGUOUS     0
179 #define NV_MEMORY_CONTIGUOUS        1
180
181 #define NV_MEMORY_CACHED            0
182 #define NV_MEMORY_UNCACHED          1
183 #define NV_MEMORY_WRITECOMBINED     2
184 /* #define NV_MEMORY_WRITETHRU         3 */
185 /* #define NV_MEMORY_WRITEPROTECT      4 */
186 /* #define NV_MEMORY_WRITEBACK         5 */
187 #define NV_MEMORY_DEFAULT           6
188 #define NV_MEMORY_UNCACHED_WEAK     7
189
190 /* in some cases, the os may have a different page size, but the
191  * hardware (fb, regs, etc) still address and "think" in 4k
192  * pages. make sure we can mask and twiddle with these addresses when
193  * PAGE_SIZE isn't what we want.
194  */
195 #define RM_PAGE_SIZE                4096
196 #define OS_PAGE_SIZE                (os_get_page_size())
197 #define OS_PAGE_MASK                (os_get_page_mask())
198
199 #define RM_PAGES_PER_OS_PAGES       (OS_PAGE_SIZE/RM_PAGE_SIZE)
200 #define RM_PAGES_TO_OS_PAGES(count) (((count) + RM_PAGES_PER_OS_PAGES - 1) \
201                                        / RM_PAGES_PER_OS_PAGES)
202
203 #endif /* _OS_INTERFACE_H_ */