Subversion Repositories Kolibri OS

Rev

Rev 1128 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #ifndef __TYPES_H__
  3. #define __TYPES_H__
  4.  
  5.  
  6. typedef int                  bool;
  7.  
  8. #define false                0
  9. #define true                 1
  10.  
  11. typedef unsigned int         size_t;
  12. typedef unsigned int         count_t;
  13. typedef unsigned int         addr_t;
  14.  
  15. typedef unsigned char        u8;
  16. typedef unsigned short       u16;
  17. typedef unsigned int         u32;
  18. typedef unsigned long long   u64;
  19.  
  20. typedef unsigned char        __u8;
  21. typedef unsigned short       __u16;
  22. typedef unsigned int         __u32;
  23. typedef unsigned long long   __u64;
  24.  
  25. typedef signed char         __s8;
  26. typedef signed short        __s16;
  27. typedef signed int          __s32;
  28. typedef signed long long    __s64;
  29.  
  30.  
  31. typedef unsigned char        uint8_t;
  32. typedef unsigned short       uint16_t;
  33. typedef unsigned int         uint32_t;
  34. typedef unsigned long long   uint64_t;
  35.  
  36. typedef unsigned char        u8_t;
  37. typedef unsigned short       u16_t;
  38. typedef unsigned int         u32_t;
  39. typedef unsigned long long   u64_t;
  40.  
  41. typedef signed char          int8_t;
  42. typedef signed long long     int64_t;
  43.  
  44. #define  NULL     (void*)0
  45.  
  46. typedef uint32_t             dma_addr_t;
  47. typedef uint32_t             resource_size_t;
  48.  
  49. #define __user
  50.  
  51. #define cpu_to_le16(v16) (v16)
  52. #define cpu_to_le32(v32) (v32)
  53. #define cpu_to_le64(v64) (v64)
  54. #define le16_to_cpu(v16) (v16)
  55. #define le32_to_cpu(v32) (v32)
  56. #define le64_to_cpu(v64) (v64)
  57.  
  58. #define likely(x)       __builtin_expect(!!(x), 1)
  59. #define unlikely(x)     __builtin_expect(!!(x), 0)
  60.  
  61. #define BITS_PER_LONG 32
  62.  
  63. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  64.  
  65. #define BITS_TO_LONGS(nr)   DIV_ROUND_UP(nr, BITS_PER_LONG)
  66.  
  67. #define DECLARE_BITMAP(name,bits) \
  68.         unsigned long name[BITS_TO_LONGS(bits)]
  69.  
  70.  
  71. #define KERN_EMERG      "<0>"   /* system is unusable                   */
  72. #define KERN_ALERT      "<1>"   /* action must be taken immediately     */
  73. #define KERN_CRIT       "<2>"   /* critical conditions                  */
  74. #define KERN_ERR        "<3>"   /* error conditions                     */
  75. #define KERN_WARNING    "<4>"   /* warning conditions                   */
  76. #define KERN_NOTICE     "<5>"   /* normal but significant condition     */
  77. #define KERN_INFO       "<6>"   /* informational                        */
  78. #define KERN_DEBUG      "<7>"   /* debug-level messages                 */
  79.  
  80. //int printk(const char *fmt, ...);
  81.  
  82. #define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
  83.  
  84.  
  85. #define DRM_NAME    "drm"     /**< Name in kernel, /dev, and /proc */
  86.  
  87. #define DRM_INFO(fmt, arg...)  dbgprintf("DRM: "fmt , ##arg)
  88.  
  89. #define DRM_ERROR(fmt, arg...) \
  90.     printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
  91.  
  92. #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
  93.  
  94. #define __must_be_array(a) \
  95.     BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
  96.  
  97. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
  98.  
  99.  
  100.  
  101.  
  102. #ifndef HAVE_ARCH_BUG
  103. #define BUG() do { \
  104.          printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
  105.        /*  panic("BUG!"); */ \
  106.  } while (0)
  107. #endif
  108.  
  109. #ifndef HAVE_ARCH_BUG_ON
  110. #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
  111. #endif
  112.  
  113.  
  114.  
  115. #define MTRR_TYPE_UNCACHABLE 0
  116. #define MTRR_TYPE_WRCOMB     1
  117. #define MTRR_TYPE_WRTHROUGH  4
  118. #define MTRR_TYPE_WRPROT     5
  119. #define MTRR_TYPE_WRBACK     6
  120. #define MTRR_NUM_TYPES       7
  121.  
  122. int dbgprintf(const char* format, ...);
  123.  
  124. #define GFP_KERNEL           0
  125.  
  126. //#include <stdio.h>
  127.  
  128. int snprintf(char *str, size_t size, const char *format, ...);
  129.  
  130.  
  131. //#include <string.h>
  132.  
  133. void*   memcpy(void *s1, const void *s2, size_t n);
  134. void*   memset(void *s, int c, size_t n);
  135. size_t  strlen(const char *s);
  136. char *strcpy(char *s1, const char *s2);
  137. char *strncpy (char *dst, const char *src, size_t len);
  138.  
  139. void *malloc(size_t size);
  140.  
  141. #define kmalloc(s,f) malloc((s))
  142. #define kfree free
  143.  
  144. static inline void *kzalloc(size_t size, u32_t flags)
  145. {
  146.     void *ret = malloc(size);
  147.     memset(ret, 0, size);
  148.     return ret;
  149. }
  150.  
  151. struct drm_file;
  152.  
  153. #define offsetof(TYPE,MEMBER) __builtin_offsetof(TYPE,MEMBER)
  154.  
  155. #define container_of(ptr, type, member) ({                      \
  156.         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
  157.         (type *)( (char *)__mptr - offsetof(type,member) );})
  158.  
  159.  
  160.  
  161. #define DRM_MEMORYBARRIER() __asm__ __volatile__("lock; addl $0,0(%esp)")
  162. #define mb() __asm__ __volatile__("lock; addl $0,0(%esp)")
  163.  
  164. #define PAGE_SIZE 4096
  165. #define PAGE_SHIFT      12
  166.  
  167. #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
  168.  
  169. static inline void bitmap_zero(unsigned long *dst, int nbits)
  170. {
  171.         if (nbits <= BITS_PER_LONG)
  172.                 *dst = 0UL;
  173.         else {
  174.                 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
  175.                 memset(dst, 0, len);
  176.         }
  177. }
  178.  
  179. #define EXPORT_SYMBOL(x)
  180.  
  181. #define min(x,y) ({ \
  182.         typeof(x) _x = (x);     \
  183.         typeof(y) _y = (y);     \
  184.         (void) (&_x == &_y);            \
  185.         _x < _y ? _x : _y; })
  186.  
  187. #define max(x,y) ({ \
  188.         typeof(x) _x = (x);     \
  189.         typeof(y) _y = (y);     \
  190.         (void) (&_x == &_y);            \
  191.         _x > _y ? _x : _y; })
  192.  
  193.  
  194. extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
  195.  
  196. # define do_div(n,base) ({                             \
  197.        uint32_t __base = (base);                       \
  198.        uint32_t __rem;                                 \
  199.        (void)(((typeof((n)) *)0) == ((uint64_t *)0));  \
  200.        if (likely(((n) >> 32) == 0)) {                 \
  201.                __rem = (uint32_t)(n) % __base;         \
  202.                (n) = (uint32_t)(n) / __base;           \
  203.        } else                                          \
  204.                __rem = __div64_32(&(n), __base);       \
  205.        __rem;                                          \
  206. })
  207.  
  208. #define lower_32_bits(n) ((u32)(n))
  209.  
  210. #define INT_MAX         ((int)(~0U>>1))
  211. #define INT_MIN         (-INT_MAX - 1)
  212. #define UINT_MAX        (~0U)
  213. #define LONG_MAX        ((long)(~0UL>>1))
  214. #define LONG_MIN        (-LONG_MAX - 1)
  215. #define ULONG_MAX       (~0UL)
  216. #define LLONG_MAX       ((long long)(~0ULL>>1))
  217. #define LLONG_MIN       (-LLONG_MAX - 1)
  218. #define ULLONG_MAX      (~0ULL)
  219.  
  220.  
  221. static inline void *kcalloc(size_t n, size_t size, u32_t flags)
  222. {
  223.         if (n != 0 && size > ULONG_MAX / n)
  224.                 return NULL;
  225.         return kzalloc(n * size, 0);
  226. }
  227.  
  228. #define ENTRY()   dbgprintf("enter %s\n",__FUNCTION__)
  229. #define LEAVE()   dbgprintf("leave %s\n",__FUNCTION__)
  230.  
  231. #define ALIGN(x,a)              __ALIGN_MASK(x,(typeof(x))(a)-1)
  232. #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
  233.  
  234. #define PCI_DEVICE_ID_ATI_RADEON_QY 0x5159
  235.  
  236. #endif  //__TYPES_H__
  237.