1 /* _NVRM_COPYRIGHT_BEGIN_
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.
13 * Os interface definitions needed by os-interface.c
16 #ifndef _OS_INTERFACE_H_
17 #define _OS_INTERFACE_H_
19 /******************* Operating System Interface Routines *******************\
21 * Module: os-interface.h *
23 * Operating system wrapper functions used to abstract the OS. *
25 \***************************************************************************/
28 * Define away Microsoft compiler extensions when possible
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
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)))
44 #define NV_API_CALL __attribute__((regparm(0)))
46 #elif defined(NVCPU_X86_64) && defined(__use_altstack__)
47 #define NV_API_CALL __attribute__((altstack(false)))
51 #endif /* !defined(NV_API_CALL) */
54 * ---------------------------------------------------------------------------
56 * Function prototypes for OS interface.
58 * ---------------------------------------------------------------------------
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 (U032, U032, U032);
92 RM_STATUS NV_API_CALL os_unset_mem_range (U032, U032);
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);
111 void* NV_API_CALL os_map_kernel_space_high (U032, U032);
112 void NV_API_CALL os_unmap_kernel_space_high (void *, U032, U032);
113 RM_STATUS NV_API_CALL os_set_mlock_capability (void);
114 RM_STATUS NV_API_CALL os_check_process_map_limit (NvU64);
115 S032 NV_API_CALL os_mlock_user_memory (void *, U032);
116 S032 NV_API_CALL os_munlock_user_memory (void *, U032);
118 RM_STATUS NV_API_CALL os_alloc_sema (void **);
119 RM_STATUS NV_API_CALL os_free_sema (void *);
120 RM_STATUS NV_API_CALL os_acquire_sema (void *);
121 BOOL NV_API_CALL os_cond_acquire_sema (void *);
122 RM_STATUS NV_API_CALL os_release_sema (void *);
123 BOOL NV_API_CALL os_is_acquired_sema (void *);
124 RM_STATUS NV_API_CALL os_schedule (void);
126 void NV_API_CALL os_register_compatible_ioctl (U032, U032);
127 void NV_API_CALL os_unregister_compatible_ioctl (U032, U032);
129 /* BOOL os_pat_supported(void)
130 * report to core resman whether pat is supported for marking cache attributes
131 * or if mtrrs are needed. primarily for indicating whether os_set_mem_range
132 * needs to be called to mark the agp aperture write-combined.
135 BOOL NV_API_CALL os_pat_supported(void);
137 void NV_API_CALL os_dump_stack (void);
140 * ---------------------------------------------------------------------------
144 * ---------------------------------------------------------------------------
147 /* enable debugging if any OS debugging flag is set */
149 #if defined(DEBUG) || defined(DBG)
153 #if !defined(DBG_LEVEL_INFO)
157 #define DBG_LEVEL_INFO 0x0 /* For informational debug trace info */
158 #define DBG_LEVEL_SETUPINFO 0x1 /* For informational debug setup info */
159 #define DBG_LEVEL_USERERRORS 0x2 /* For debug info on app level errors */
160 #define DBG_LEVEL_WARNINGS 0x3 /* For RM debug warning info */
161 #define DBG_LEVEL_ERRORS 0x4 /* For RM debug error info */
164 #define NV_DBG_INFO 0x0
165 #define NV_DBG_SETUP 0x1
166 #define NV_DBG_USERERRORS 0x2
167 #define NV_DBG_WARNINGS 0x3
168 #define NV_DBG_ERRORS 0x4
171 void NV_API_CALL out_string(const char *str);
172 int NV_API_CALL nv_printf(U032 debuglevel, const char *printf_format, ...);
173 void NV_API_CALL nv_prints(U032 debuglevel, const char *string);
174 int NV_API_CALL nv_snprintf(char *buf, unsigned int size, const char *fmt, ...);
175 void NV_API_CALL nv_os_log(int log_level, const char *fmt, void *ap);
178 #define NV_MEMORY_TYPE_SYSTEM 0
179 #define NV_MEMORY_TYPE_AGP 1
180 #define NV_MEMORY_TYPE_REGISTERS 2
181 #define NV_MEMORY_TYPE_FRAMEBUFFER 3
183 #define NV_MEMORY_NONCONTIGUOUS 0
184 #define NV_MEMORY_CONTIGUOUS 1
186 #define NV_MEMORY_CACHED 0
187 #define NV_MEMORY_UNCACHED 1
188 #define NV_MEMORY_WRITECOMBINED 2
189 /* #define NV_MEMORY_WRITETHRU 3 */
190 /* #define NV_MEMORY_WRITEPROTECT 4 */
191 /* #define NV_MEMORY_WRITEBACK 5 */
192 #define NV_MEMORY_DEFAULT 6
193 #define NV_MEMORY_UNCACHED_WEAK 7
195 /* in some cases, the os may have a different page size, but the
196 * hardware (fb, regs, etc) still address and "think" in 4k
197 * pages. make sure we can mask and twiddle with these addresses when
198 * PAGE_SIZE isn't what we want.
200 #define RM_PAGE_SIZE 4096
201 #define OS_PAGE_SIZE (os_get_page_size())
202 #define OS_PAGE_MASK (os_get_page_mask())
204 #define RM_PAGES_PER_OS_PAGES (OS_PAGE_SIZE/RM_PAGE_SIZE)
205 #define RM_PAGES_TO_OS_PAGES(count) (((count) + RM_PAGES_PER_OS_PAGES - 1) \
206 / RM_PAGES_PER_OS_PAGES)
208 #endif /* _OS_INTERFACE_H_ */