• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 Advanced Micro Devices, Inc.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16  * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17  * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20  * USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  */
26 #ifndef _lnx_common_defs_h_
27 #define _lnx_common_defs_h_
28 
29 #if DBG
30 #include <stdarg.h>                         // We do not have any choice: need variable
31                                             // number of parameters support for debug
32                                             // build.
33 #endif                                      // #if DBG
34 
35 //
36 // --------------  External functions from Linux kernel driver ----------------
37 //
38 // Note: The definitions/declararions below must match the original ones.
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef unsigned long __ke_size_t;              // as it is defined in firegl_public.h
45 typedef int           __kernel_ptrdiff_t;       // as it is defined in posix_types.h
46 
47 
48 #if !defined(ATI_API_CALL)
49 #define ATI_API_CALL __attribute__((regparm(0)))
50 #endif
51 
52 extern void * ATI_API_CALL __ke_memset(void* s, int c, __ke_size_t count);
53 extern void * ATI_API_CALL __ke_memcpy(void* d, const void* s, __ke_size_t count);
54 extern ATI_API_CALL __ke_size_t __ke_strlen(const char *s);
55 extern char* ATI_API_CALL __ke_strcpy(char* d, const char* s);
56 extern char* ATI_API_CALL __ke_strncpy(char* d, const char* s, __ke_size_t count);
57 extern void __ke_printk(const char* fmt, ...);
58 
59 extern int ATI_API_CALL __ke_snprintf(char* buf, __ke_size_t size, const char* fmt, ...);
60 extern int ATI_API_CALL KCL_CopyFromUserSpace(void* to, const void* from, __ke_size_t size);
61 extern int ATI_API_CALL KCL_CopyToUserSpace(void* to, const void* from, __ke_size_t size);
62 #define __ke_copy_from_user  KCL_CopyFromUserSpace
63 #define __ke_copy_to_user    KCL_CopyToUserSpace
64 extern int ATI_API_CALL __ke_verify_area(int type, const void * addr, unsigned long size);
65 
66 extern unsigned long ATI_API_CALL KAS_GetTickCounter(void);
67 extern unsigned long ATI_API_CALL KAS_GetTicksPerSecond(void);
68 
69 
70 #if DBG
71 extern int ATI_API_CALL __ke_vsnprintf(char *buf, __ke_size_t size, const char *fmt, va_list ap);
72 #define vsnprintf(_dst, _size, _fmt, varg)  __ke_snprintf(_dst, _size, _fmt, varg)
73 #endif                                      // #if DBG
74 
75 
76 // Note: This function is not defined in firegl_public.h.
77 void    firegl_hardwareHangRecovery(void);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 //
84 // --------------------------  C/C++ standard typedefs ----------------------------
85 //
86 #ifdef __SIZE_TYPE__
87 typedef __SIZE_TYPE__       size_t;
88 #else                                       // #ifdef __SIZE_TYPE__
89 typedef unsigned int        size_t;
90 #endif                                      // #ifdef __SIZE_TYPE__
91 
92 #ifdef __PTRDIFF_TYPE__
93 typedef __PTRDIFF_TYPE__    ptrdiff_t;
94 #else                                       // #ifdef __PTRDIFF_TYPE__
95 typedef int                 ptrdiff_t;
96 #endif                                      // #ifdef __PTRDIFF_TYPE__
97 
98 #ifndef NULL
99 #ifdef __cplusplus
100 #define NULL    __null
101 #else
102 #define NULL    ((void *)0)
103 #endif
104 #endif
105 
106 
107 //
108 // -------------------------  C/C++ standard macros ---------------------------
109 //
110 
111 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)  // as it is defined in stddef.h
112 #define CHAR_BIT            8                                   // as it is defined in limits.h
113 
114 //
115 // ---------------------------------  C RTL -----------------------------------
116 //
117 
118 #define memset(_p, _v, _n)                  __ke_memset(_p, _v, _n)
119 #define memcpy(_d, _s, _n)                  __ke_memcpy(_d, _s, _n)
120 #define strlen(_s)                          __ke_strlen(_s)
121 #define strcpy(_d, _s)                      __ke_strcpy(_d, _s)
122 #define strncpy(_d, _s, _n)                 __ke_strncpy(_d, _s, _n)
123 // Note: C99 supports macros with variable number of arguments. GCC also supports this C99 feature as
124 //       C++ extension.
125 #define snprintf(_dst, _size, _fmt, arg...) __ke_snprintf(_dst, _size, _fmt, ##arg)
126 
127 
128 #endif                                      // #ifdef _lnx_common_defs_h_
129 
130