Subversion Repositories Kolibri OS

Rev

Rev 1123 | 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 *strncpy (char *dst, const char *src, size_t len);
  137.  
  138. void *malloc(size_t size);
  139.  
  140. #define kmalloc(s,f) malloc((s))
  141. #define kfree free
  142.  
  143. static inline void *kzalloc(size_t size, u32_t flags)
  144. {
  145.     void *ret = malloc(size);
  146.     memset(ret, 0, size);
  147.     return ret;
  148. }
  149.  
  150. struct drm_gem_object {
  151.  
  152.     /** Reference count of this object */
  153. //    struct kref refcount;
  154.  
  155.     /** Handle count of this object. Each handle also holds a reference */
  156. //    struct kref handlecount;
  157.  
  158.     /** Related drm device */
  159. //    struct drm_device *dev;
  160.  
  161.     /** File representing the shmem storage */
  162. //    struct file *filp;
  163.  
  164.     /* Mapping info for this object */
  165. //    struct drm_map_list map_list;
  166.  
  167.     /**
  168.      * Size of the object, in bytes.  Immutable over the object's
  169.      * lifetime.
  170.      */
  171.     size_t size;
  172.  
  173.     /**
  174.      * Global name for this object, starts at 1. 0 means unnamed.
  175.      * Access is covered by the object_name_lock in the related drm_device
  176.      */
  177.     int name;
  178.  
  179.     /**
  180.      * Memory domains. These monitor which caches contain read/write data
  181.      * related to the object. When transitioning from one set of domains
  182.      * to another, the driver is called to ensure that caches are suitably
  183.      * flushed and invalidated
  184.      */
  185.     uint32_t read_domains;
  186.     uint32_t write_domain;
  187.  
  188.     /**
  189.      * While validating an exec operation, the
  190.      * new read/write domain values are computed here.
  191.      * They will be transferred to the above values
  192.      * at the point that any cache flushing occurs
  193.      */
  194.     uint32_t pending_read_domains;
  195.     uint32_t pending_write_domain;
  196.  
  197.     void *driver_private;
  198. };
  199.  
  200. struct drm_file;
  201.  
  202. #define offsetof(TYPE,MEMBER) __builtin_offsetof(TYPE,MEMBER)
  203.  
  204. #define container_of(ptr, type, member) ({                      \
  205.         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
  206.         (type *)( (char *)__mptr - offsetof(type,member) );})
  207.  
  208.  
  209.  
  210. #define DRM_MEMORYBARRIER() __asm__ __volatile__("lock; addl $0,0(%esp)")
  211. #define mb() __asm__ __volatile__("lock; addl $0,0(%esp)")
  212.  
  213. #define PAGE_SIZE 4096
  214. #define PAGE_SHIFT      12
  215.  
  216. #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
  217.  
  218. static inline void bitmap_zero(unsigned long *dst, int nbits)
  219. {
  220.         if (nbits <= BITS_PER_LONG)
  221.                 *dst = 0UL;
  222.         else {
  223.                 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
  224.                 memset(dst, 0, len);
  225.         }
  226. }
  227.  
  228. #define EXPORT_SYMBOL(x)
  229.  
  230. #define min(x,y) ({ \
  231.         typeof(x) _x = (x);     \
  232.         typeof(y) _y = (y);     \
  233.         (void) (&_x == &_y);            \
  234.         _x < _y ? _x : _y; })
  235.  
  236. #define max(x,y) ({ \
  237.         typeof(x) _x = (x);     \
  238.         typeof(y) _y = (y);     \
  239.         (void) (&_x == &_y);            \
  240.         _x > _y ? _x : _y; })
  241.  
  242.  
  243. extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
  244.  
  245. # define do_div(n,base) ({                             \
  246.        uint32_t __base = (base);                       \
  247.        uint32_t __rem;                                 \
  248.        (void)(((typeof((n)) *)0) == ((uint64_t *)0));  \
  249.        if (likely(((n) >> 32) == 0)) {                 \
  250.                __rem = (uint32_t)(n) % __base;         \
  251.                (n) = (uint32_t)(n) / __base;           \
  252.        } else                                          \
  253.                __rem = __div64_32(&(n), __base);       \
  254.        __rem;                                          \
  255. })
  256.  
  257. #define lower_32_bits(n) ((u32)(n))
  258.  
  259. #define INT_MAX         ((int)(~0U>>1))
  260. #define INT_MIN         (-INT_MAX - 1)
  261. #define UINT_MAX        (~0U)
  262. #define LONG_MAX        ((long)(~0UL>>1))
  263. #define LONG_MIN        (-LONG_MAX - 1)
  264. #define ULONG_MAX       (~0UL)
  265. #define LLONG_MAX       ((long long)(~0ULL>>1))
  266. #define LLONG_MIN       (-LLONG_MAX - 1)
  267. #define ULLONG_MAX      (~0ULL)
  268.  
  269.  
  270. static inline void *kcalloc(size_t n, size_t size, u32_t flags)
  271. {
  272.         if (n != 0 && size > ULONG_MAX / n)
  273.                 return NULL;
  274.         return kzalloc(n * size, 0);
  275. }
  276.  
  277. #define ENTRY()   dbgprintf("entry %s\n",__FUNCTION__)
  278. #define LEAVE()   dbgprintf("leave %s\n",__FUNCTION__)
  279.  
  280. #endif  //__TYPES_H__
  281.