Subversion Repositories Kolibri OS

Rev

Rev 1246 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1246 Rev 1403
Line 24... Line 24...
24
 * don't need to go to the memory "store" during an id allocate, just
24
 * don't need to go to the memory "store" during an id allocate, just
25
 * so you don't need to be too concerned about locking and conflicts
25
 * so you don't need to be too concerned about locking and conflicts
26
 * with the slab allocator.
26
 * with the slab allocator.
27
 */
27
 */
Line -... Line 28...
-
 
28
 
-
 
29
#include 
28
 
30
 
29
#include 
31
#include 
30
#include 
32
//#include 
31
#include "drm.h"
33
#include "drm.h"
32
#include "drmP.h"
34
#include "drmP.h"
Line 33... Line -...
33
#include "drm_crtc.h"
-
 
34
 
-
 
35
#define ADDR "=m" (*(volatile long *) addr)
-
 
36
 
-
 
37
static inline void __set_bit(int nr, volatile void *addr)
-
 
38
{
-
 
39
        asm volatile("bts %1,%0"
-
 
40
                     : ADDR
-
 
41
                     : "Ir" (nr) : "memory");
-
 
42
}
-
 
43
 
-
 
44
static inline void __clear_bit(int nr, volatile void *addr)
-
 
45
{
-
 
46
        asm volatile("btr %1,%0" : ADDR : "Ir" (nr));
-
 
47
}
-
 
48
 
-
 
49
static inline int constant_test_bit(int nr, const volatile void *addr)
-
 
50
{
-
 
51
        return ((1UL << (nr % 32)) &
-
 
52
                (((unsigned long *)addr)[nr / 32])) != 0;
-
 
53
}
-
 
54
 
-
 
55
static inline int variable_test_bit(int nr, volatile const void *addr)
-
 
56
{
-
 
57
        int oldbit;
-
 
58
 
-
 
59
        asm volatile("bt %2,%1\n\t"
-
 
60
                     "sbb %0,%0"
-
 
61
                     : "=r" (oldbit)
-
 
62
                     : "m" (*(unsigned long *)addr), "Ir" (nr));
-
 
63
 
-
 
64
        return oldbit;
-
 
65
};
-
 
66
 
-
 
67
 
-
 
68
#define test_bit(nr,addr)                       \
-
 
69
        (__builtin_constant_p(nr) ?             \
-
 
70
         constant_test_bit((nr),(addr)) :       \
-
 
71
         variable_test_bit((nr),(addr)))
-
 
72
 
-
 
73
 
-
 
74
static inline int fls(int x)
-
 
75
{
-
 
76
        int r;
-
 
77
 
-
 
78
        __asm__("bsrl %1,%0\n\t"
-
 
79
                "jnz 1f\n\t"
-
 
80
                "movl $-1,%0\n"
-
 
81
                "1:" : "=r" (r) : "rm" (x));
-
 
82
        return r+1;
-
 
83
}
-
 
84
 
-
 
85
static inline unsigned long __ffs(unsigned long word)
-
 
86
{
-
 
87
        __asm__("bsfl %1,%0"
-
 
88
                :"=r" (word)
-
 
89
                :"rm" (word));
-
 
90
        return word;
-
 
91
}
-
 
92
 
-
 
93
 
-
 
94
static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
-
 
95
{
-
 
96
        unsigned x = 0;
-
 
97
 
-
 
98
        while (x < size) {
-
 
99
                unsigned long val = *addr++;
-
 
100
                if (val)
-
 
101
                        return __ffs(val) + x;
-
 
102
                x += (sizeof(*addr)<<3);
-
 
103
        }
-
 
104
        return x;
-
 
105
}
-
 
106
 
-
 
107
 
-
 
108
int find_next_bit(const unsigned long *addr, int size, int offset)
-
 
109
{
-
 
110
    const unsigned long *p = addr + (offset >> 5);
-
 
111
    int set = 0, bit = offset & 31, res;
-
 
112
 
-
 
113
    if (bit)
-
 
114
    {
-
 
115
        /*
-
 
116
         * Look for nonzero in the first 32 bits:
-
 
117
         */
-
 
118
        __asm__("bsfl %1,%0\n\t"
-
 
119
                "jne 1f\n\t"
-
 
120
                "movl $32, %0\n"
-
 
121
                "1:"
-
 
122
                : "=r" (set)
-
 
123
                : "r" (*p >> bit));
-
 
124
        if (set < (32 - bit))
-
 
125
                return set + offset;
-
 
126
        set = 32 - bit;
-
 
127
        p++;
-
 
128
    }
-
 
129
    /*
-
 
130
     * No set bit yet, search remaining full words for a bit
-
 
131
     */
-
 
132
    res = find_first_bit (p, size - 32 * (p - addr));
-
 
133
    return (offset + set + res);
-
 
Line 134... Line 35...
134
}
35
#include "drm_crtc.h"
Line 135... Line 36...
135
 
36
 
136
 
37