OSDN Git Service

modified dependency for kernel
[android-x86/hardware-menlow-psb.git] / drm_os_linux.h
1 /**
2  * \file drm_os_linux.h
3  * OS abstraction macros.
4  */
5
6 #include <linux/interrupt.h>    /* For task queue support */
7 #include <linux/delay.h>
8
9 /** Current process ID */
10 #define DRM_CURRENTPID                  current->pid
11 #define DRM_SUSER(p)                    capable(CAP_SYS_ADMIN)
12 #define DRM_UDELAY(d)                   udelay(d)
13 #if LINUX_VERSION_CODE <= 0x020608      /* KERNEL_VERSION(2,6,8) */
14 #ifndef __iomem
15 #define __iomem
16 #endif
17 /** Read a byte from a MMIO region */
18 #define DRM_READ8(map, offset)          readb(((void __iomem *)(map)->handle) + (offset))
19 /** Read a word from a MMIO region */
20 #define DRM_READ16(map, offset)         readw(((void __iomem *)(map)->handle) + (offset))
21 /** Read a dword from a MMIO region */
22 #define DRM_READ32(map, offset)         readl(((void __iomem *)(map)->handle) + (offset))
23 /** Write a byte into a MMIO region */
24 #define DRM_WRITE8(map, offset, val)    writeb(val, ((void __iomem *)(map)->handle) + (offset))
25 /** Write a word into a MMIO region */
26 #define DRM_WRITE16(map, offset, val)   writew(val, ((void __iomem *)(map)->handle) + (offset))
27 /** Write a dword into a MMIO region */
28 #define DRM_WRITE32(map, offset, val)   writel(val, ((void __iomem *)(map)->handle) + (offset))
29 #else
30 /** Read a byte from a MMIO region */
31 #define DRM_READ8(map, offset)          readb((map)->handle + (offset))
32 /** Read a word from a MMIO region */
33 #define DRM_READ16(map, offset)         readw((map)->handle + (offset))
34 /** Read a dword from a MMIO region */
35 #define DRM_READ32(map, offset)         readl((map)->handle + (offset))
36 /** Write a byte into a MMIO region */
37 #define DRM_WRITE8(map, offset, val)    writeb(val, (map)->handle + (offset))
38 /** Write a word into a MMIO region */
39 #define DRM_WRITE16(map, offset, val)   writew(val, (map)->handle + (offset))
40 /** Write a dword into a MMIO region */
41 #define DRM_WRITE32(map, offset, val)   writel(val, (map)->handle + (offset))
42 #endif
43 /** Read memory barrier */
44 #define DRM_READMEMORYBARRIER()         rmb()
45 /** Write memory barrier */
46 #define DRM_WRITEMEMORYBARRIER()        wmb()
47 /** Read/write memory barrier */
48 #define DRM_MEMORYBARRIER()             mb()
49
50 /** IRQ handler arguments and return type and values */
51 #define DRM_IRQ_ARGS            int irq, void *arg
52 /** backwards compatibility with old irq return values */
53 #ifndef IRQ_HANDLED
54 typedef void irqreturn_t;
55 #define IRQ_HANDLED             /* nothing */
56 #define IRQ_NONE                /* nothing */
57 #endif
58
59 /** AGP types */
60 #if __OS_HAS_AGP
61 #define DRM_AGP_MEM             struct agp_memory
62 #define DRM_AGP_KERN            struct agp_kern_info
63 #else
64 /* define some dummy types for non AGP supporting kernels */
65 struct no_agp_kern {
66         unsigned long aper_base;
67         unsigned long aper_size;
68 };
69 #define DRM_AGP_MEM             int
70 #define DRM_AGP_KERN            struct no_agp_kern
71 #endif
72
73 #if !(__OS_HAS_MTRR)
74 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
75                                unsigned int type, char increment)
76 {
77         return -ENODEV;
78 }
79
80 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
81 {
82         return -ENODEV;
83 }
84
85 #define MTRR_TYPE_WRCOMB     1
86 #endif
87
88 /** Other copying of data to kernel space */
89 #define DRM_COPY_FROM_USER(arg1, arg2, arg3)            \
90         copy_from_user(arg1, arg2, arg3)
91 /** Other copying of data from kernel space */
92 #define DRM_COPY_TO_USER(arg1, arg2, arg3)              \
93         copy_to_user(arg1, arg2, arg3)
94 /* Macros for copyfrom user, but checking readability only once */
95 #define DRM_VERIFYAREA_READ( uaddr, size )              \
96         (access_ok( VERIFY_READ, uaddr, size) ? 0 : -EFAULT)
97 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3)  \
98         __copy_from_user(arg1, arg2, arg3)
99 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)    \
100         __copy_to_user(arg1, arg2, arg3)
101 #define DRM_GET_USER_UNCHECKED(val, uaddr)              \
102         __get_user(val, uaddr)
103
104 #define DRM_HZ HZ
105
106 #define DRM_WAIT_ON( ret, queue, timeout, condition )           \
107 do {                                                            \
108         DECLARE_WAITQUEUE(entry, current);                      \
109         unsigned long end = jiffies + (timeout);                \
110         add_wait_queue(&(queue), &entry);                       \
111                                                                 \
112         for (;;) {                                              \
113                 __set_current_state(TASK_INTERRUPTIBLE);        \
114                 if (condition)                                  \
115                         break;                                  \
116                 if (time_after_eq(jiffies, end)) {              \
117                         ret = -EBUSY;                           \
118                         break;                                  \
119                 }                                               \
120                 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
121                 if (signal_pending(current)) {                  \
122                         ret = -EINTR;                           \
123                         break;                                  \
124                 }                                               \
125         }                                                       \
126         __set_current_state(TASK_RUNNING);                      \
127         remove_wait_queue(&(queue), &entry);                    \
128 } while (0)
129
130 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
131 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
132
133 /** Type for the OS's non-sleepable mutex lock */
134 #define DRM_SPINTYPE            spinlock_t
135 /**
136  * Initialize the lock for use.  name is an optional string describing the
137  * lock
138  */
139 #define DRM_SPININIT(l,name)    spin_lock_init(l)
140 #define DRM_SPINUNINIT(l)
141 #define DRM_SPINLOCK(l)         spin_lock(l)
142 #define DRM_SPINUNLOCK(l)       spin_unlock(l)
143 #define DRM_SPINLOCK_IRQSAVE(l, _flags) spin_lock_irqsave(l, _flags);
144 #define DRM_SPINUNLOCK_IRQRESTORE(l, _flags) spin_unlock_irqrestore(l, _flags);
145 #define DRM_SPINLOCK_ASSERT(l)          do {} while (0)