Subversion Repositories Kolibri OS

Rev

Rev 1119 | 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_DEBUG(fmt, arg...)     \
  90.     printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
  91.  
  92. #define DRM_ERROR(fmt, arg...) \
  93.     printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
  94.  
  95. #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
  96.  
  97. #define __must_be_array(a) \
  98.     BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
  99.  
  100. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
  101.  
  102.  
  103.  
  104.  
  105. #ifndef HAVE_ARCH_BUG
  106. #define BUG() do { \
  107.          printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
  108.        /*  panic("BUG!"); */ \
  109.  } while (0)
  110. #endif
  111.  
  112. #ifndef HAVE_ARCH_BUG_ON
  113. #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
  114. #endif
  115.  
  116.  
  117.  
  118. #define MTRR_TYPE_UNCACHABLE 0
  119. #define MTRR_TYPE_WRCOMB     1
  120. #define MTRR_TYPE_WRTHROUGH  4
  121. #define MTRR_TYPE_WRPROT     5
  122. #define MTRR_TYPE_WRBACK     6
  123. #define MTRR_NUM_TYPES       7
  124.  
  125. int dbgprintf(const char* format, ...);
  126.  
  127. #define GFP_KERNEL           0
  128.  
  129. //#include <stdio.h>
  130.  
  131. int snprintf(char *str, size_t size, const char *format, ...);
  132.  
  133.  
  134. //#include <string.h>
  135.  
  136. void*   memcpy(void *s1, const void *s2, size_t n);
  137. void*   memset(void *s, int c, size_t n);
  138. size_t  strlen(const char *s);
  139. char *strncpy (char *dst, const char *src, size_t len);
  140.  
  141. void *malloc(size_t size);
  142.  
  143. #define kmalloc(s,f) malloc((s))
  144. #define kfree free
  145.  
  146. static inline void *kzalloc(size_t size, u32_t flags)
  147. {
  148.     void *ret = malloc(size);
  149.     memset(ret, 0, size);
  150.     return ret;
  151. }
  152.  
  153. struct drm_gem_object {
  154.  
  155.     /** Reference count of this object */
  156. //    struct kref refcount;
  157.  
  158.     /** Handle count of this object. Each handle also holds a reference */
  159. //    struct kref handlecount;
  160.  
  161.     /** Related drm device */
  162. //    struct drm_device *dev;
  163.  
  164.     /** File representing the shmem storage */
  165. //    struct file *filp;
  166.  
  167.     /* Mapping info for this object */
  168. //    struct drm_map_list map_list;
  169.  
  170.     /**
  171.      * Size of the object, in bytes.  Immutable over the object's
  172.      * lifetime.
  173.      */
  174.     size_t size;
  175.  
  176.     /**
  177.      * Global name for this object, starts at 1. 0 means unnamed.
  178.      * Access is covered by the object_name_lock in the related drm_device
  179.      */
  180.     int name;
  181.  
  182.     /**
  183.      * Memory domains. These monitor which caches contain read/write data
  184.      * related to the object. When transitioning from one set of domains
  185.      * to another, the driver is called to ensure that caches are suitably
  186.      * flushed and invalidated
  187.      */
  188.     uint32_t read_domains;
  189.     uint32_t write_domain;
  190.  
  191.     /**
  192.      * While validating an exec operation, the
  193.      * new read/write domain values are computed here.
  194.      * They will be transferred to the above values
  195.      * at the point that any cache flushing occurs
  196.      */
  197.     uint32_t pending_read_domains;
  198.     uint32_t pending_write_domain;
  199.  
  200.     void *driver_private;
  201. };
  202.  
  203. struct drm_file;
  204.  
  205. #define offsetof(TYPE,MEMBER) __builtin_offsetof(TYPE,MEMBER)
  206.  
  207. #define container_of(ptr, type, member) ({                      \
  208.         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
  209.         (type *)( (char *)__mptr - offsetof(type,member) );})
  210.  
  211.  
  212.  
  213. #define DRM_MEMORYBARRIER() __asm__ __volatile__("lock; addl $0,0(%esp)")
  214. #define mb() __asm__ __volatile__("lock; addl $0,0(%esp)")
  215.  
  216. #define PAGE_SIZE 4096
  217. #define PAGE_SHIFT      12
  218.  
  219. #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
  220.  
  221. static inline void bitmap_zero(unsigned long *dst, int nbits)
  222. {
  223.         if (nbits <= BITS_PER_LONG)
  224.                 *dst = 0UL;
  225.         else {
  226.                 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
  227.                 memset(dst, 0, len);
  228.         }
  229. }
  230.  
  231. #define EXPORT_SYMBOL(x)
  232.  
  233. #define IDR_BITS 5
  234. #define IDR_FULL 0xfffffffful
  235.  
  236. struct idr_layer {
  237.         unsigned long            bitmap; /* A zero bit means "space here" */
  238.         struct idr_layer        *ary[1<<IDR_BITS];
  239.         int                      count;  /* When zero, we can release it */
  240. };
  241.  
  242. struct idr {
  243.         struct idr_layer *top;
  244.         struct idr_layer *id_free;
  245.         int               layers;
  246.         int               id_free_cnt;
  247. //        spinlock_t        lock;
  248. };
  249.  
  250.  
  251. #define min(x,y) ({ \
  252.         typeof(x) _x = (x);     \
  253.         typeof(y) _y = (y);     \
  254.         (void) (&_x == &_y);            \
  255.         _x < _y ? _x : _y; })
  256.  
  257. #define max(x,y) ({ \
  258.         typeof(x) _x = (x);     \
  259.         typeof(y) _y = (y);     \
  260.         (void) (&_x == &_y);            \
  261.         _x > _y ? _x : _y; })
  262.  
  263.  
  264. extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
  265.  
  266. # define do_div(n,base) ({                             \
  267.        uint32_t __base = (base);                       \
  268.        uint32_t __rem;                                 \
  269.        (void)(((typeof((n)) *)0) == ((uint64_t *)0));  \
  270.        if (likely(((n) >> 32) == 0)) {                 \
  271.                __rem = (uint32_t)(n) % __base;         \
  272.                (n) = (uint32_t)(n) / __base;           \
  273.        } else                                          \
  274.                __rem = __div64_32(&(n), __base);       \
  275.        __rem;                                          \
  276. })
  277.  
  278. #define lower_32_bits(n) ((u32)(n))
  279.  
  280. #define INT_MAX         ((int)(~0U>>1))
  281. #define INT_MIN         (-INT_MAX - 1)
  282. #define UINT_MAX        (~0U)
  283. #define LONG_MAX        ((long)(~0UL>>1))
  284. #define LONG_MIN        (-LONG_MAX - 1)
  285. #define ULONG_MAX       (~0UL)
  286. #define LLONG_MAX       ((long long)(~0ULL>>1))
  287. #define LLONG_MIN       (-LLONG_MAX - 1)
  288. #define ULLONG_MAX      (~0ULL)
  289.  
  290.  
  291. static inline void *kcalloc(size_t n, size_t size, u32_t flags)
  292. {
  293.         if (n != 0 && size > ULONG_MAX / n)
  294.                 return NULL;
  295.         return kmalloc(n * size, 0);
  296. }
  297.  
  298. #endif  //__TYPES_H__
  299.