Subversion Repositories Kolibri OS

Rev

Rev 5271 | Rev 6321 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5078 serge 1
#include 
2
#include 
3
#include 
4
#include 
5271 serge 5
#include "radeon.h"
5078 serge 6
 
7
int x86_clflush_size;
8
unsigned int tsc_khz;
9
 
10
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
11
{
12
    struct file *filep;
13
    int count;
14
 
5271 serge 15
    filep = __builtin_malloc(sizeof(*filep));
5078 serge 16
 
17
    if(unlikely(filep == NULL))
18
        return ERR_PTR(-ENOMEM);
19
 
20
    count = size / PAGE_SIZE;
21
 
22
    filep->pages = kzalloc(sizeof(struct page *) * count, 0);
23
    if(unlikely(filep->pages == NULL))
24
    {
25
        kfree(filep);
26
        return ERR_PTR(-ENOMEM);
27
    };
28
 
29
    filep->count     = count;
30
    filep->allocated = 0;
31
    filep->vma       = NULL;
32
 
33
//    printf("%s file %p pages %p count %d\n",
34
//              __FUNCTION__,filep, filep->pages, count);
35
 
36
    return filep;
37
}
38
 
39
static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
40
{
41
        while (bytes) {
42
                if (*start != value)
43
                        return (void *)start;
44
                start++;
45
                bytes--;
46
        }
47
        return NULL;
48
}
49
 
50
/**
51
 * memchr_inv - Find an unmatching character in an area of memory.
52
 * @start: The memory area
53
 * @c: Find a character other than c
54
 * @bytes: The size of the area.
55
 *
56
 * returns the address of the first character other than @c, or %NULL
57
 * if the whole buffer contains just @c.
58
 */
59
void *memchr_inv(const void *start, int c, size_t bytes)
60
{
61
        u8 value = c;
62
        u64 value64;
63
        unsigned int words, prefix;
64
 
65
        if (bytes <= 16)
66
                return check_bytes8(start, value, bytes);
67
 
68
        value64 = value;
69
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
70
        value64 *= 0x0101010101010101;
71
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
72
        value64 *= 0x01010101;
73
        value64 |= value64 << 32;
74
#else
75
        value64 |= value64 << 8;
76
        value64 |= value64 << 16;
77
        value64 |= value64 << 32;
78
#endif
79
 
80
        prefix = (unsigned long)start % 8;
81
        if (prefix) {
82
                u8 *r;
83
 
84
                prefix = 8 - prefix;
85
                r = check_bytes8(start, value, prefix);
86
                if (r)
87
                        return r;
88
                start += prefix;
89
                bytes -= prefix;
90
        }
91
 
92
        words = bytes / 8;
93
 
94
        while (words) {
95
                if (*(u64 *)start != value64)
96
                        return check_bytes8(start, value, 8);
97
                start += 8;
98
                words--;
99
        }
100
 
101
        return check_bytes8(start, value, bytes % 8);
102
}
103
 
104
 
105
 
106
#define _U  0x01    /* upper */
107
#define _L  0x02    /* lower */
108
#define _D  0x04    /* digit */
109
#define _C  0x08    /* cntrl */
110
#define _P  0x10    /* punct */
111
#define _S  0x20    /* white space (space/lf/tab) */
112
#define _X  0x40    /* hex digit */
113
#define _SP 0x80    /* hard space (0x20) */
114
 
115
extern const unsigned char _ctype[];
116
 
117
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
118
 
119
#define isalnum(c)  ((__ismask(c)&(_U|_L|_D)) != 0)
120
#define isalpha(c)  ((__ismask(c)&(_U|_L)) != 0)
121
#define iscntrl(c)  ((__ismask(c)&(_C)) != 0)
122
#define isdigit(c)  ((__ismask(c)&(_D)) != 0)
123
#define isgraph(c)  ((__ismask(c)&(_P|_U|_L|_D)) != 0)
124
#define islower(c)  ((__ismask(c)&(_L)) != 0)
125
#define isprint(c)  ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
126
#define ispunct(c)  ((__ismask(c)&(_P)) != 0)
127
/* Note: isspace() must return false for %NUL-terminator */
128
#define isspace(c)  ((__ismask(c)&(_S)) != 0)
129
#define isupper(c)  ((__ismask(c)&(_U)) != 0)
130
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
131
 
132
#define isascii(c) (((unsigned char)(c))<=0x7f)
133
#define toascii(c) (((unsigned char)(c))&0x7f)
134
 
135
static inline unsigned char __tolower(unsigned char c)
136
{
137
    if (isupper(c))
138
        c -= 'A'-'a';
139
    return c;
140
}
141
 
142
static inline unsigned char __toupper(unsigned char c)
143
{
144
    if (islower(c))
145
        c -= 'a'-'A';
146
    return c;
147
}
148
 
149
#define tolower(c) __tolower(c)
150
#define toupper(c) __toupper(c)
151
 
152
/*
153
 * Fast implementation of tolower() for internal usage. Do not use in your
154
 * code.
155
 */
156
static inline char _tolower(const char c)
157
{
158
    return c | 0x20;
159
}
160
 
161
 
162
//const char hex_asc[] = "0123456789abcdef";
163
 
164
/**
165
 * hex_to_bin - convert a hex digit to its real value
166
 * @ch: ascii character represents hex digit
167
 *
168
 * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
169
 * input.
170
 */
171
int hex_to_bin(char ch)
172
{
173
    if ((ch >= '0') && (ch <= '9'))
174
        return ch - '0';
175
    ch = tolower(ch);
176
    if ((ch >= 'a') && (ch <= 'f'))
177
        return ch - 'a' + 10;
178
    return -1;
179
}
180
EXPORT_SYMBOL(hex_to_bin);
181
 
182
/**
183
 * hex2bin - convert an ascii hexadecimal string to its binary representation
184
 * @dst: binary result
185
 * @src: ascii hexadecimal string
186
 * @count: result length
187
 *
188
 * Return 0 on success, -1 in case of bad input.
189
 */
190
int hex2bin(u8 *dst, const char *src, size_t count)
191
{
192
    while (count--) {
193
        int hi = hex_to_bin(*src++);
194
        int lo = hex_to_bin(*src++);
195
 
196
        if ((hi < 0) || (lo < 0))
197
            return -1;
198
 
199
        *dst++ = (hi << 4) | lo;
200
    }
201
    return 0;
202
}
203
EXPORT_SYMBOL(hex2bin);
204
 
205
/**
206
 * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
207
 * @buf: data blob to dump
208
 * @len: number of bytes in the @buf
209
 * @rowsize: number of bytes to print per line; must be 16 or 32
210
 * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
211
 * @linebuf: where to put the converted data
212
 * @linebuflen: total size of @linebuf, including space for terminating NUL
213
 * @ascii: include ASCII after the hex output
214
 *
215
 * hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
216
 * 16 or 32 bytes of input data converted to hex + ASCII output.
217
 *
218
 * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
219
 * to a hex + ASCII dump at the supplied memory location.
220
 * The converted output is always NUL-terminated.
221
 *
222
 * E.g.:
223
 *   hex_dump_to_buffer(frame->data, frame->len, 16, 1,
224
 *          linebuf, sizeof(linebuf), true);
225
 *
226
 * example output buffer:
227
 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
228
 */
6104 serge 229
int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
230
               char *linebuf, size_t linebuflen, bool ascii)
5078 serge 231
{
232
    const u8 *ptr = buf;
6104 serge 233
    int ngroups;
5078 serge 234
    u8 ch;
235
    int j, lx = 0;
236
    int ascii_column;
6104 serge 237
    int ret;
5078 serge 238
 
239
    if (rowsize != 16 && rowsize != 32)
240
        rowsize = 16;
241
 
242
    if (len > rowsize)      /* limit to one line at a time */
243
        len = rowsize;
6104 serge 244
    if (!is_power_of_2(groupsize) || groupsize > 8)
245
        groupsize = 1;
5078 serge 246
    if ((len % groupsize) != 0) /* no mixed size output */
247
        groupsize = 1;
248
 
6104 serge 249
    ngroups = len / groupsize;
250
    ascii_column = rowsize * 2 + rowsize / groupsize + 1;
251
 
252
    if (!linebuflen)
253
        goto overflow1;
254
 
255
    if (!len)
256
        goto nil;
257
 
258
    if (groupsize == 8) {
5078 serge 259
        const u64 *ptr8 = buf;
260