Rev 6103 | Rev 6296 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6103 | Rev 6131 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include "i915_drv.h" |
5 | #include "i915_drv.h" |
6 | #include "intel_drv.h" |
6 | #include "intel_drv.h" |
7 | #include |
7 | #include |
8 | #include |
8 | #include |
9 | #include |
9 | #include |
10 | #include "i915_kos32.h" |
10 | #include "i915_kos32.h" |
11 | 11 | ||
12 | struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags) |
12 | struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags) |
13 | { |
13 | { |
14 | struct file *filep; |
14 | struct file *filep; |
15 | int count; |
15 | int count; |
16 | 16 | ||
17 | filep = __builtin_malloc(sizeof(*filep)); |
17 | filep = __builtin_malloc(sizeof(*filep)); |
18 | 18 | ||
19 | if(unlikely(filep == NULL)) |
19 | if(unlikely(filep == NULL)) |
20 | return ERR_PTR(-ENOMEM); |
20 | return ERR_PTR(-ENOMEM); |
21 | 21 | ||
22 | count = size / PAGE_SIZE; |
22 | count = size / PAGE_SIZE; |
23 | 23 | ||
24 | filep->pages = kzalloc(sizeof(struct page *) * count, 0); |
24 | filep->pages = kzalloc(sizeof(struct page *) * count, 0); |
25 | if(unlikely(filep->pages == NULL)) |
25 | if(unlikely(filep->pages == NULL)) |
26 | { |
26 | { |
27 | kfree(filep); |
27 | kfree(filep); |
28 | return ERR_PTR(-ENOMEM); |
28 | return ERR_PTR(-ENOMEM); |
29 | }; |
29 | }; |
30 | 30 | ||
31 | filep->count = count; |
31 | filep->count = count; |
32 | filep->allocated = 0; |
32 | filep->allocated = 0; |
33 | filep->vma = NULL; |
33 | filep->vma = NULL; |
34 | 34 | ||
35 | // printf("%s file %p pages %p count %d\n", |
35 | // printf("%s file %p pages %p count %d\n", |
36 | // __FUNCTION__,filep, filep->pages, count); |
36 | // __FUNCTION__,filep, filep->pages, count); |
37 | 37 | ||
38 | return filep; |
38 | return filep; |
39 | } |
39 | } |
40 | 40 | ||
41 | struct page *shmem_read_mapping_page_gfp(struct file *filep, |
41 | struct page *shmem_read_mapping_page_gfp(struct file *filep, |
42 | pgoff_t index, gfp_t gfp) |
42 | pgoff_t index, gfp_t gfp) |
43 | { |
43 | { |
44 | struct page *page; |
44 | struct page *page; |
45 | 45 | ||
46 | if(unlikely(index >= filep->count)) |
46 | if(unlikely(index >= filep->count)) |
47 | return ERR_PTR(-EINVAL); |
47 | return ERR_PTR(-EINVAL); |
48 | 48 | ||
49 | page = filep->pages[index]; |
49 | page = filep->pages[index]; |
50 | 50 | ||
51 | if(unlikely(page == NULL)) |
51 | if(unlikely(page == NULL)) |
52 | { |
52 | { |
53 | page = (struct page *)AllocPage(); |
53 | page = (struct page *)AllocPage(); |
54 | 54 | ||
55 | if(unlikely(page == NULL)) |
55 | if(unlikely(page == NULL)) |
56 | return ERR_PTR(-ENOMEM); |
56 | return ERR_PTR(-ENOMEM); |
57 | 57 | ||
58 | filep->pages[index] = page; |
58 | filep->pages[index] = page; |
59 | // printf("file %p index %d page %x\n", filep, index, page); |
59 | // printf("file %p index %d page %x\n", filep, index, page); |
60 | // delay(1); |
60 | // delay(1); |
61 | 61 | ||
62 | }; |
62 | }; |
63 | 63 | ||
64 | return page; |
64 | return page; |
65 | }; |
65 | }; |
66 | 66 | ||
67 | unsigned long vm_mmap(struct file *file, unsigned long addr, |
67 | unsigned long vm_mmap(struct file *file, unsigned long addr, |
68 | unsigned long len, unsigned long prot, |
68 | unsigned long len, unsigned long prot, |
69 | unsigned long flag, unsigned long offset) |
69 | unsigned long flag, unsigned long offset) |
70 | { |
70 | { |
71 | char *mem, *ptr; |
71 | char *mem, *ptr; |
72 | int i; |
72 | int i; |
73 | 73 | ||
74 | if (unlikely(offset + PAGE_ALIGN(len) < offset)) |
74 | if (unlikely(offset + PAGE_ALIGN(len) < offset)) |
75 | return -EINVAL; |
75 | return -EINVAL; |
76 | if (unlikely(offset & ~PAGE_MASK)) |
76 | if (unlikely(offset & ~PAGE_MASK)) |
77 | return -EINVAL; |
77 | return -EINVAL; |
78 | 78 | ||
79 | mem = UserAlloc(len); |
79 | mem = UserAlloc(len); |
80 | if(unlikely(mem == NULL)) |
80 | if(unlikely(mem == NULL)) |
81 | return -ENOMEM; |
81 | return -ENOMEM; |
82 | 82 | ||
83 | for(i = offset, ptr = mem; i < offset+len; i+= 4096, ptr+= 4096) |
83 | for(i = offset, ptr = mem; i < offset+len; i+= 4096, ptr+= 4096) |
84 | { |
84 | { |
85 | struct page *page; |
85 | struct page *page; |
86 | 86 | ||
87 | page = shmem_read_mapping_page_gfp(file, i/PAGE_SIZE,0); |
87 | page = shmem_read_mapping_page_gfp(file, i/PAGE_SIZE,0); |
88 | 88 | ||
89 | if (unlikely(IS_ERR(page))) |
89 | if (unlikely(IS_ERR(page))) |
90 | goto err; |
90 | goto err; |
91 | 91 | ||
92 | MapPage(ptr, (addr_t)page, PG_SHARED|PG_UW); |
92 | MapPage(ptr, (addr_t)page, PG_SHARED|PG_UW); |
93 | } |
93 | } |
94 | 94 | ||
95 | return (unsigned long)mem; |
95 | return (unsigned long)mem; |
96 | err: |
96 | err: |
97 | UserFree(mem); |
97 | UserFree(mem); |
98 | return -ENOMEM; |
98 | return -ENOMEM; |
99 | }; |
99 | }; |
100 | 100 | ||
101 | void shmem_file_delete(struct file *filep) |
101 | void shmem_file_delete(struct file *filep) |
102 | { |
102 | { |
103 | // printf("%s file %p pages %p count %d\n", |
103 | // printf("%s file %p pages %p count %d\n", |
104 | // __FUNCTION__, filep, filep->pages, filep->count); |
104 | // __FUNCTION__, filep, filep->pages, filep->count); |
105 | 105 | ||
106 | if(filep->pages) |
106 | if(filep->pages) |
107 | kfree(filep->pages); |
107 | kfree(filep->pages); |
108 | } |
108 | } |
109 | 109 | ||
110 | 110 | ||
111 | 111 | ||
112 | static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) |
112 | static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) |
113 | { |
113 | { |
114 | while (bytes) { |
114 | while (bytes) { |
115 | if (*start != value) |
115 | if (*start != value) |
116 | return (void *)start; |
116 | return (void *)start; |
117 | start++; |
117 | start++; |
118 | bytes--; |
118 | bytes--; |
119 | } |
119 | } |
120 | return NULL; |
120 | return NULL; |
121 | } |
121 | } |
122 | 122 | ||
123 | /** |
123 | /** |
124 | * memchr_inv - Find an unmatching character in an area of memory. |
124 | * memchr_inv - Find an unmatching character in an area of memory. |
125 | * @start: The memory area |
125 | * @start: The memory area |
126 | * @c: Find a character other than c |
126 | * @c: Find a character other than c |
127 | * @bytes: The size of the area. |
127 | * @bytes: The size of the area. |
128 | * |
128 | * |
129 | * returns the address of the first character other than @c, or %NULL |
129 | * returns the address of the first character other than @c, or %NULL |
130 | * if the whole buffer contains just @c. |
130 | * if the whole buffer contains just @c. |
131 | */ |
131 | */ |
132 | void *memchr_inv(const void *start, int c, size_t bytes) |
132 | void *memchr_inv(const void *start, int c, size_t bytes) |
133 | { |
133 | { |
134 | u8 value = c; |
134 | u8 value = c; |
135 | u64 value64; |
135 | u64 value64; |
136 | unsigned int words, prefix; |
136 | unsigned int words, prefix; |
137 | 137 | ||
138 | if (bytes <= 16) |
138 | if (bytes <= 16) |
139 | return check_bytes8(start, value, bytes); |
139 | return check_bytes8(start, value, bytes); |
140 | 140 | ||
141 | value64 = value; |
141 | value64 = value; |
142 | #if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 |
142 | #if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 |
143 | value64 *= 0x0101010101010101; |
143 | value64 *= 0x0101010101010101; |
144 | #elif defined(ARCH_HAS_FAST_MULTIPLIER) |
144 | #elif defined(ARCH_HAS_FAST_MULTIPLIER) |
145 | value64 *= 0x01010101; |
145 | value64 *= 0x01010101; |
146 | value64 |= value64 << 32; |
146 | value64 |= value64 << 32; |
147 | #else |
147 | #else |
148 | value64 |= value64 << 8; |
148 | value64 |= value64 << 8; |
149 | value64 |= value64 << 16; |
149 | value64 |= value64 << 16; |
150 | value64 |= value64 << 32; |
150 | value64 |= value64 << 32; |
151 | #endif |
151 | #endif |
152 | 152 | ||
153 | prefix = (unsigned long)start % 8; |
153 | prefix = (unsigned long)start % 8; |
154 | if (prefix) { |
154 | if (prefix) { |
155 | u8 *r; |
155 | u8 *r; |
156 | 156 | ||
157 | prefix = 8 - prefix; |
157 | prefix = 8 - prefix; |
158 | r = check_bytes8(start, value, prefix); |
158 | r = check_bytes8(start, value, prefix); |
159 | if (r) |
159 | if (r) |
160 | return r; |
160 | return r; |
161 | start += prefix; |
161 | start += prefix; |
162 | bytes -= prefix; |
162 | bytes -= prefix; |
163 | } |
163 | } |
164 | 164 | ||
165 | words = bytes / 8; |
165 | words = bytes / 8; |
166 | 166 | ||
167 | while (words) { |
167 | while (words) { |
168 | if (*(u64 *)start != value64) |
168 | if (*(u64 *)start != value64) |
169 | return check_bytes8(start, value, 8); |
169 | return check_bytes8(start, value, 8); |
170 | start += 8; |
170 | start += 8; |
171 | words--; |
171 | words--; |
172 | } |
172 | } |
173 | 173 | ||
174 | return check_bytes8(start, value, bytes % 8); |
174 | return check_bytes8(start, value, bytes % 8); |
175 | } |
175 | } |
176 | 176 | ||
177 | 177 | ||
178 | 178 | ||
179 | int dma_map_sg(struct device *dev, struct scatterlist *sglist, |
179 | int dma_map_sg(struct device *dev, struct scatterlist *sglist, |
180 | int nelems, int dir) |
180 | int nelems, int dir) |
181 | { |
181 | { |
182 | struct scatterlist *s; |
182 | struct scatterlist *s; |
183 | int i; |
183 | int i; |
184 | 184 | ||
185 | for_each_sg(sglist, s, nelems, i) { |
185 | for_each_sg(sglist, s, nelems, i) { |
186 | s->dma_address = (dma_addr_t)sg_phys(s); |
186 | s->dma_address = (dma_addr_t)sg_phys(s); |
187 | #ifdef CONFIG_NEED_SG_DMA_LENGTH |
187 | #ifdef CONFIG_NEED_SG_DMA_LENGTH |
188 | s->dma_length = s->length; |
188 | s->dma_length = s->length; |
189 | #endif |
189 | #endif |
190 | } |
190 | } |
191 | 191 | ||
192 | return nelems; |
192 | return nelems; |
193 | } |
193 | } |
194 | 194 | ||
195 | 195 | ||
196 | 196 | ||
197 | #define _U 0x01 /* upper */ |
197 | #define _U 0x01 /* upper */ |
198 | #define _L 0x02 /* lower */ |
198 | #define _L 0x02 /* lower */ |
199 | #define _D 0x04 /* digit */ |
199 | #define _D 0x04 /* digit */ |
200 | #define _C 0x08 /* cntrl */ |
200 | #define _C 0x08 /* cntrl */ |
201 | #define _P 0x10 /* punct */ |
201 | #define _P 0x10 /* punct */ |
202 | #define _S 0x20 /* white space (space/lf/tab) */ |
202 | #define _S 0x20 /* white space (space/lf/tab) */ |
203 | #define _X 0x40 /* hex digit */ |
203 | #define _X 0x40 /* hex digit */ |
204 | #define _SP 0x80 /* hard space (0x20) */ |
204 | #define _SP 0x80 /* hard space (0x20) */ |
205 | 205 | ||
206 | extern const unsigned char _ctype[]; |
206 | extern const unsigned char _ctype[]; |
207 | 207 | ||
208 | #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) |
208 | #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) |
209 | 209 | ||
210 | #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0) |
210 | #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0) |
211 | #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0) |
211 | #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0) |
212 | #define iscntrl(c) ((__ismask(c)&(_C)) != 0) |
212 | #define iscntrl(c) ((__ismask(c)&(_C)) != 0) |
213 | #define isdigit(c) ((__ismask(c)&(_D)) != 0) |
213 | #define isdigit(c) ((__ismask(c)&(_D)) != 0) |
214 | #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) |
214 | #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) |
215 | #define islower(c) ((__ismask(c)&(_L)) != 0) |
215 | #define islower(c) ((__ismask(c)&(_L)) != 0) |
216 | #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) |
216 | #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) |
217 | #define ispunct(c) ((__ismask(c)&(_P)) != 0) |
217 | #define ispunct(c) ((__ismask(c)&(_P)) != 0) |
218 | /* Note: isspace() must return false for %NUL-terminator */ |
218 | /* Note: isspace() must return false for %NUL-terminator */ |
219 | #define isspace(c) ((__ismask(c)&(_S)) != 0) |
219 | #define isspace(c) ((__ismask(c)&(_S)) != 0) |
220 | #define isupper(c) ((__ismask(c)&(_U)) != 0) |
220 | #define isupper(c) ((__ismask(c)&(_U)) != 0) |
221 | #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) |
221 | #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) |
222 | 222 | ||
223 | #define isascii(c) (((unsigned char)(c))<=0x7f) |
223 | #define isascii(c) (((unsigned char)(c))<=0x7f) |
224 | #define toascii(c) (((unsigned char)(c))&0x7f) |
224 | #define toascii(c) (((unsigned char)(c))&0x7f) |
225 | 225 | ||
226 | static inline unsigned char __tolower(unsigned char c) |
226 | static inline unsigned char __tolower(unsigned char c) |
227 | { |
227 | { |
228 | if (isupper(c)) |
228 | if (isupper(c)) |
229 | c -= 'A'-'a'; |
229 | c -= 'A'-'a'; |
230 | return c; |
230 | return c; |
231 | } |
231 | } |
232 | 232 | ||
233 | static inline unsigned char __toupper(unsigned char c) |
233 | static inline unsigned char __toupper(unsigned char c) |
234 | { |
234 | { |
235 | if (islower(c)) |
235 | if (islower(c)) |
236 | c -= 'a'-'A'; |
236 | c -= 'a'-'A'; |
237 | return c; |
237 | return c; |
238 | } |
238 | } |
239 | 239 | ||
240 | #define tolower(c) __tolower(c) |
240 | #define tolower(c) __tolower(c) |
241 | #define toupper(c) __toupper(c) |
241 | #define toupper(c) __toupper(c) |
242 | 242 | ||
243 | /* |
243 | /* |
244 | * Fast implementation of tolower() for internal usage. Do not use in your |
244 | * Fast implementation of tolower() for internal usage. Do not use in your |
245 | * code. |
245 | * code. |
246 | */ |
246 | */ |
247 | static inline char _tolower(const char c) |
247 | static inline char _tolower(const char c) |
248 | { |
248 | { |
249 | return c | 0x20; |
249 | return c | 0x20; |
250 | } |
250 | } |
251 | 251 | ||
252 | 252 | ||
253 | //const char hex_asc[] = "0123456789abcdef"; |
253 | //const char hex_asc[] = "0123456789abcdef"; |
254 | 254 | ||
255 | /** |
255 | /** |
256 | * hex_to_bin - convert a hex digit to its real value |
256 | * hex_to_bin - convert a hex digit to its real value |
257 | * @ch: ascii character represents hex digit |
257 | * @ch: ascii character represents hex digit |
258 | * |
258 | * |
259 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad |
259 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad |
260 | * input. |
260 | * input. |
261 | */ |
261 | */ |
262 | int hex_to_bin(char ch) |
262 | int hex_to_bin(char ch) |
263 | { |
263 | { |
264 | if ((ch >= '0') && (ch <= '9')) |
264 | if ((ch >= '0') && (ch <= '9')) |
265 | return ch - '0'; |
265 | return ch - '0'; |
266 | ch = tolower(ch); |
266 | ch = tolower(ch); |
267 | if ((ch >= 'a') && (ch <= 'f')) |
267 | if ((ch >= 'a') && (ch <= 'f')) |
268 | return ch - 'a' + 10; |
268 | return ch - 'a' + 10; |
269 | return -1; |
269 | return -1; |
270 | } |
270 | } |
271 | EXPORT_SYMBOL(hex_to_bin); |
271 | EXPORT_SYMBOL(hex_to_bin); |
272 | 272 | ||
273 | /** |
273 | /** |
274 | * hex2bin - convert an ascii hexadecimal string to its binary representation |
274 | * hex2bin - convert an ascii hexadecimal string to its binary representation |
275 | * @dst: binary result |
275 | * @dst: binary result |
276 | * @src: ascii hexadecimal string |
276 | * @src: ascii hexadecimal string |
277 | * @count: result length |
277 | * @count: result length |
278 | * |
278 | * |
279 | * Return 0 on success, -1 in case of bad input. |
279 | * Return 0 on success, -1 in case of bad input. |
280 | */ |
280 | */ |
281 | int hex2bin(u8 *dst, const char *src, size_t count) |
281 | int hex2bin(u8 *dst, const char *src, size_t count) |
282 | { |
282 | { |
283 | while (count--) { |
283 | while (count--) { |
284 | int hi = hex_to_bin(*src++); |
284 | int hi = hex_to_bin(*src++); |
285 | int lo = hex_to_bin(*src++); |
285 | int lo = hex_to_bin(*src++); |
286 | 286 | ||
287 | if ((hi < 0) || (lo < 0)) |
287 | if ((hi < 0) || (lo < 0)) |
288 | return -1; |
288 | return -1; |
289 | 289 | ||
290 | *dst++ = (hi << 4) | lo; |
290 | *dst++ = (hi << 4) | lo; |
291 | } |
291 | } |
292 | return 0; |
292 | return 0; |
293 | } |
293 | } |
294 | EXPORT_SYMBOL(hex2bin); |
294 | EXPORT_SYMBOL(hex2bin); |
295 | 295 | ||
296 | /** |
296 | /** |
297 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
297 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
298 | * @buf: data blob to dump |
298 | * @buf: data blob to dump |
299 | * @len: number of bytes in the @buf |
299 | * @len: number of bytes in the @buf |
300 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
300 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
301 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
301 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
302 | * @linebuf: where to put the converted data |
302 | * @linebuf: where to put the converted data |
303 | * @linebuflen: total size of @linebuf, including space for terminating NUL |
303 | * @linebuflen: total size of @linebuf, including space for terminating NUL |
304 | * @ascii: include ASCII after the hex output |
304 | * @ascii: include ASCII after the hex output |
305 | * |
305 | * |
306 | * hex_dump_to_buffer() works on one "line" of output at a time, i.e., |
306 | * hex_dump_to_buffer() works on one "line" of output at a time, i.e., |
307 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
307 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
308 | * |
308 | * |
309 | * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data |
309 | * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data |
310 | * to a hex + ASCII dump at the supplied memory location. |
310 | * to a hex + ASCII dump at the supplied memory location. |
311 | * The converted output is always NUL-terminated. |
311 | * The converted output is always NUL-terminated. |
312 | * |
312 | * |
313 | * E.g.: |
313 | * E.g.: |
314 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
314 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
315 | * linebuf, sizeof(linebuf), true); |
315 | * linebuf, sizeof(linebuf), true); |
316 | * |
316 | * |
317 | * example output buffer: |
317 | * example output buffer: |
318 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
318 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
319 | */ |
319 | */ |
320 | int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, |
320 | int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, |
321 | char *linebuf, size_t linebuflen, bool ascii) |
321 | char *linebuf, size_t linebuflen, bool ascii) |
322 | { |
322 | { |
323 | const u8 *ptr = buf; |
323 | const u8 *ptr = buf; |
324 | int ngroups; |
324 | int ngroups; |
325 | u8 ch; |
325 | u8 ch; |
326 | int j, lx = 0; |
326 | int j, lx = 0; |
327 | int ascii_column; |
327 | int ascii_column; |
328 | int ret; |
328 | int ret; |
329 | 329 | ||
330 | if (rowsize != 16 && rowsize != 32) |
330 | if (rowsize != 16 && rowsize != 32) |
331 | rowsize = 16; |
331 | rowsize = 16; |
332 | 332 | ||
333 | if (len > rowsize) /* limit to one line at a time */ |
333 | if (len > rowsize) /* limit to one line at a time */ |
334 | len = rowsize; |
334 | len = rowsize; |
335 | if (!is_power_of_2(groupsize) || groupsize > 8) |
335 | if (!is_power_of_2(groupsize) || groupsize > 8) |
336 | groupsize = 1; |
336 | groupsize = 1; |
337 | if ((len % groupsize) != 0) /* no mixed size output */ |
337 | if ((len % groupsize) != 0) /* no mixed size output */ |
338 | groupsize = 1; |
338 | groupsize = 1; |
339 | 339 | ||
340 | ngroups = len / groupsize; |
340 | ngroups = len / groupsize; |
341 | ascii_column = rowsize * 2 + rowsize / groupsize + 1; |
341 | ascii_column = rowsize * 2 + rowsize / groupsize + 1; |
342 | 342 | ||
343 | if (!linebuflen) |
343 | if (!linebuflen) |
344 | goto overflow1; |
344 | goto overflow1; |
345 | 345 | ||
346 | if (!len) |
346 | if (!len) |
347 | goto nil; |
347 | goto nil; |
348 | 348 | ||
349 | if (groupsize == 8) { |
349 | if (groupsize == 8) { |
350 | const u64 *ptr8 = buf; |
350 | const u64 *ptr8 = buf; |
351 | 351 | ||
352 | for (j = 0; j < ngroups; j++) { |
352 | for (j = 0; j < ngroups; j++) { |
353 | ret = snprintf(linebuf + lx, linebuflen - lx, |
353 | ret = snprintf(linebuf + lx, linebuflen - lx, |
354 | "%s%16.16llx", j ? " " : "", |
354 | "%s%16.16llx", j ? " " : "", |
355 | (unsigned long long)*(ptr8 + j)); |
355 | (unsigned long long)*(ptr8 + j)); |
356 | if (ret >= linebuflen - lx) |
356 | if (ret >= linebuflen - lx) |
357 | goto overflow1; |
357 | goto overflow1; |
358 | lx += ret; |
358 | lx += ret; |
359 | } |
359 | } |
360 | } else if (groupsize == 4) { |
360 | } else if (groupsize == 4) { |
361 | const u32 *ptr4 = buf; |
361 | const u32 *ptr4 = buf; |
362 | 362 | ||
363 | for (j = 0; j < ngroups; j++) { |
363 | for (j = 0; j < ngroups; j++) { |
364 | ret = snprintf(linebuf + lx, linebuflen - lx, |
364 | ret = snprintf(linebuf + lx, linebuflen - lx, |
365 | "%s%8.8x", j ? " " : "", |
365 | "%s%8.8x", j ? " " : "", |
366 | *(ptr4 + j)); |
366 | *(ptr4 + j)); |
367 | if (ret >= linebuflen - lx) |
367 | if (ret >= linebuflen - lx) |
368 | goto overflow1; |
368 | goto overflow1; |
369 | lx += ret; |
369 | lx += ret; |
370 | } |
370 | } |
371 | } else if (groupsize == 2) { |
371 | } else if (groupsize == 2) { |
372 | const u16 *ptr2 = buf; |
372 | const u16 *ptr2 = buf; |
373 | 373 | ||
374 | for (j = 0; j < ngroups; j++) { |
374 | for (j = 0; j < ngroups; j++) { |
375 | ret = snprintf(linebuf + lx, linebuflen - lx, |
375 | ret = snprintf(linebuf + lx, linebuflen - lx, |
376 | "%s%4.4x", j ? " " : "", |
376 | "%s%4.4x", j ? " " : "", |
377 | *(ptr2 + j)); |
377 | *(ptr2 + j)); |
378 | if (ret >= linebuflen - lx) |
378 | if (ret >= linebuflen - lx) |
379 | goto overflow1; |
379 | goto overflow1; |
380 | lx += ret; |
380 | lx += ret; |
381 | } |
381 | } |
382 | } else { |
382 | } else { |
383 | for (j = 0; j < len; j++) { |
383 | for (j = 0; j < len; j++) { |
384 | if (linebuflen < lx + 3) |
384 | if (linebuflen < lx + 3) |
385 | goto overflow2; |
385 | goto overflow2; |
386 | ch = ptr[j]; |
386 | ch = ptr[j]; |
387 | linebuf[lx++] = hex_asc_hi(ch); |
387 | linebuf[lx++] = hex_asc_hi(ch); |
388 | linebuf[lx++] = hex_asc_lo(ch); |
388 | linebuf[lx++] = hex_asc_lo(ch); |
389 | linebuf[lx++] = ' '; |
389 | linebuf[lx++] = ' '; |
390 | } |
390 | } |
391 | if (j) |
391 | if (j) |
392 | lx--; |
392 | lx--; |
393 | } |
393 | } |
394 | if (!ascii) |
394 | if (!ascii) |
395 | goto nil; |
395 | goto nil; |
396 | 396 | ||
397 | while (lx < ascii_column) { |
397 | while (lx < ascii_column) { |
398 | if (linebuflen < lx + 2) |
398 | if (linebuflen < lx + 2) |
399 | goto overflow2; |
399 | goto overflow2; |
400 | linebuf[lx++] = ' '; |
400 | linebuf[lx++] = ' '; |
401 | } |
401 | } |
402 | for (j = 0; j < len; j++) { |
402 | for (j = 0; j < len; j++) { |
403 | if (linebuflen < lx + 2) |
403 | if (linebuflen < lx + 2) |
404 | goto overflow2; |
404 | goto overflow2; |
405 | ch = ptr[j]; |
405 | ch = ptr[j]; |
406 | linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.'; |
406 | linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.'; |
407 | } |
407 | } |
408 | nil: |
408 | nil: |
409 | linebuf[lx] = '\0'; |
409 | linebuf[lx] = '\0'; |
410 | return lx; |
410 | return lx; |
411 | overflow2: |
411 | overflow2: |
412 | linebuf[lx++] = '\0'; |
412 | linebuf[lx++] = '\0'; |
413 | overflow1: |
413 | overflow1: |
414 | return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1; |
414 | return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1; |
415 | } |
415 | } |
416 | /** |
416 | /** |
417 | * print_hex_dump - print a text hex dump to syslog for a binary blob of data |
417 | * print_hex_dump - print a text hex dump to syslog for a binary blob of data |
418 | * @level: kernel log level (e.g. KERN_DEBUG) |
418 | * @level: kernel log level (e.g. KERN_DEBUG) |
419 | * @prefix_str: string to prefix each line with; |
419 | * @prefix_str: string to prefix each line with; |
420 | * caller supplies trailing spaces for alignment if desired |
420 | * caller supplies trailing spaces for alignment if desired |
421 | * @prefix_type: controls whether prefix of an offset, address, or none |
421 | * @prefix_type: controls whether prefix of an offset, address, or none |
422 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
422 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
423 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
423 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
424 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
424 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
425 | * @buf: data blob to dump |
425 | * @buf: data blob to dump |
426 | * @len: number of bytes in the @buf |
426 | * @len: number of bytes in the @buf |
427 | * @ascii: include ASCII after the hex output |
427 | * @ascii: include ASCII after the hex output |
428 | * |
428 | * |
429 | * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump |
429 | * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump |
430 | * to the kernel log at the specified kernel log level, with an optional |
430 | * to the kernel log at the specified kernel log level, with an optional |
431 | * leading prefix. |
431 | * leading prefix. |
432 | * |
432 | * |
433 | * print_hex_dump() works on one "line" of output at a time, i.e., |
433 | * print_hex_dump() works on one "line" of output at a time, i.e., |
434 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
434 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
435 | * print_hex_dump() iterates over the entire input @buf, breaking it into |
435 | * print_hex_dump() iterates over the entire input @buf, breaking it into |
436 | * "line size" chunks to format and print. |
436 | * "line size" chunks to format and print. |
437 | * |
437 | * |
438 | * E.g.: |
438 | * E.g.: |
439 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
439 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
440 | * 16, 1, frame->data, frame->len, true); |
440 | * 16, 1, frame->data, frame->len, true); |
441 | * |
441 | * |
442 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
442 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
443 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
443 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
444 | * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode: |
444 | * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode: |
445 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
445 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
446 | */ |
446 | */ |
447 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
447 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
448 | int rowsize, int groupsize, |
448 | int rowsize, int groupsize, |
449 | const void *buf, size_t len, bool ascii) |
449 | const void *buf, size_t len, bool ascii) |
450 | { |
450 | { |
451 | const u8 *ptr = buf; |
451 | const u8 *ptr = buf; |
452 | int i, linelen, remaining = len; |
452 | int i, linelen, remaining = len; |
453 | unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
453 | unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
454 | 454 | ||
455 | if (rowsize != 16 && rowsize != 32) |
455 | if (rowsize != 16 && rowsize != 32) |
456 | rowsize = 16; |
456 | rowsize = 16; |
457 | 457 | ||
458 | for (i = 0; i < len; i += rowsize) { |
458 | for (i = 0; i < len; i += rowsize) { |
459 | linelen = min(remaining, rowsize); |
459 | linelen = min(remaining, rowsize); |
460 | remaining -= rowsize; |
460 | remaining -= rowsize; |
461 | 461 | ||
462 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
462 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
463 | linebuf, sizeof(linebuf), ascii); |
463 | linebuf, sizeof(linebuf), ascii); |
464 | 464 | ||
465 | switch (prefix_type) { |
465 | switch (prefix_type) { |
466 | case DUMP_PREFIX_ADDRESS: |
466 | case DUMP_PREFIX_ADDRESS: |
467 | printk("%s%s%p: %s\n", |
467 | printk("%s%s%p: %s\n", |
468 | level, prefix_str, ptr + i, linebuf); |
468 | level, prefix_str, ptr + i, linebuf); |
469 | break; |
469 | break; |
470 | case DUMP_PREFIX_OFFSET: |
470 | case DUMP_PREFIX_OFFSET: |
471 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
471 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
472 | break; |
472 | break; |
473 | default: |
473 | default: |
474 | printk("%s%s%s\n", level, prefix_str, linebuf); |
474 | printk("%s%s%s\n", level, prefix_str, linebuf); |
475 | break; |
475 | break; |
476 | } |
476 | } |
477 | } |
477 | } |
478 | } |
478 | } |
479 | 479 | ||
480 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
480 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
481 | const void *buf, size_t len) |
481 | const void *buf, size_t len) |
482 | { |
482 | { |
483 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, |
483 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, |
484 | buf, len, true); |
484 | buf, len, true); |
485 | } |
485 | } |
486 | 486 | ||
487 | void *kmemdup(const void *src, size_t len, gfp_t gfp) |
487 | void *kmemdup(const void *src, size_t len, gfp_t gfp) |
488 | { |
488 | { |
489 | void *p; |
489 | void *p; |
490 | 490 | ||
491 | p = kmalloc(len, gfp); |
491 | p = kmalloc(len, gfp); |
492 | if (p) |
492 | if (p) |
493 | memcpy(p, src, len); |
493 | memcpy(p, src, len); |
494 | return p; |
494 | return p; |
495 | } |
495 | } |
496 | 496 | ||
497 | 497 | ||
498 | #define KMAP_MAX 256 |
498 | #define KMAP_MAX 256 |
499 | 499 | ||
500 | static struct mutex kmap_mutex; |
500 | static struct mutex kmap_mutex; |
501 | static struct page* kmap_table[KMAP_MAX]; |
501 | static struct page* kmap_table[KMAP_MAX]; |
502 | static int kmap_av; |
502 | static int kmap_av; |
503 | static int kmap_first; |
503 | static int kmap_first; |
504 | static void* kmap_base; |
504 | static void* kmap_base; |
505 | 505 | ||
506 | 506 | ||
507 | int kmap_init() |
507 | int kmap_init() |
508 | { |
508 | { |
509 | kmap_base = AllocKernelSpace(KMAP_MAX*4096); |
509 | kmap_base = AllocKernelSpace(KMAP_MAX*4096); |
510 | if(kmap_base == NULL) |
510 | if(kmap_base == NULL) |
511 | return -1; |
511 | return -1; |
512 | 512 | ||
513 | kmap_av = KMAP_MAX; |
513 | kmap_av = KMAP_MAX; |
514 | MutexInit(&kmap_mutex); |
514 | MutexInit(&kmap_mutex); |
515 | return 0; |
515 | return 0; |
516 | }; |
516 | }; |
517 | 517 | ||
518 | void *kmap(struct page *page) |
518 | void *kmap(struct page *page) |
519 | { |
519 | { |
520 | void *vaddr = NULL; |
520 | void *vaddr = NULL; |
521 | int i; |
521 | int i; |
522 | 522 | ||
523 | do |
523 | do |
524 | { |
524 | { |
525 | MutexLock(&kmap_mutex); |
525 | MutexLock(&kmap_mutex); |
526 | if(kmap_av != 0) |
526 | if(kmap_av != 0) |
527 | { |
527 | { |
528 | for(i = kmap_first; i < KMAP_MAX; i++) |
528 | for(i = kmap_first; i < KMAP_MAX; i++) |
529 | { |
529 | { |
530 | if(kmap_table[i] == NULL) |
530 | if(kmap_table[i] == NULL) |
531 | { |
531 | { |
532 | kmap_av--; |
532 | kmap_av--; |
533 | kmap_first = i; |
533 | kmap_first = i; |
534 | kmap_table[i] = page; |
534 | kmap_table[i] = page; |
535 | vaddr = kmap_base + (i<<12); |
535 | vaddr = kmap_base + (i<<12); |
536 | MapPage(vaddr,(addr_t)page,3); |
536 | MapPage(vaddr,(addr_t)page,3); |
537 | break; |
537 | break; |
538 | }; |
538 | }; |
539 | }; |
539 | }; |
540 | }; |
540 | }; |
541 | MutexUnlock(&kmap_mutex); |
541 | MutexUnlock(&kmap_mutex); |
542 | }while(vaddr == NULL); |
542 | }while(vaddr == NULL); |
543 | 543 | ||
544 | return vaddr; |
544 | return vaddr; |
545 | }; |
545 | }; |
546 | 546 | ||
547 | void *kmap_atomic(struct page *page) __attribute__ ((alias ("kmap"))); |
547 | void *kmap_atomic(struct page *page) __attribute__ ((alias ("kmap"))); |
548 | 548 | ||
549 | void kunmap(struct page *page) |
549 | void kunmap(struct page *page) |
550 | { |
550 | { |
551 | void *vaddr; |
551 | void *vaddr; |
552 | int i; |
552 | int i; |
553 | 553 | ||
554 | MutexLock(&kmap_mutex); |
554 | MutexLock(&kmap_mutex); |
555 | 555 | ||
556 | for(i = 0; i < KMAP_MAX; i++) |
556 | for(i = 0; i < KMAP_MAX; i++) |
557 | { |
557 | { |
558 | if(kmap_table[i] == page) |
558 | if(kmap_table[i] == page) |
559 | { |
559 | { |
560 | kmap_av++; |
560 | kmap_av++; |
561 | if(i < kmap_first) |
561 | if(i < kmap_first) |
562 | kmap_first = i; |
562 | kmap_first = i; |
563 | kmap_table[i] = NULL; |
563 | kmap_table[i] = NULL; |
564 | vaddr = kmap_base + (i<<12); |
564 | vaddr = kmap_base + (i<<12); |
565 | MapPage(vaddr,0,0); |
565 | MapPage(vaddr,0,0); |
566 | break; |
566 | break; |
567 | }; |
567 | }; |
568 | }; |
568 | }; |
569 | 569 | ||
570 | MutexUnlock(&kmap_mutex); |
570 | MutexUnlock(&kmap_mutex); |
571 | }; |
571 | }; |
572 | 572 | ||
573 | void kunmap_atomic(void *vaddr) |
573 | void kunmap_atomic(void *vaddr) |
574 | { |
574 | { |
575 | int i; |
575 | int i; |
576 | 576 | ||
577 | MapPage(vaddr,0,0); |
577 | MapPage(vaddr,0,0); |
578 | 578 | ||
579 | i = (vaddr - kmap_base) >> 12; |
579 | i = (vaddr - kmap_base) >> 12; |
580 | 580 | ||
581 | MutexLock(&kmap_mutex); |
581 | MutexLock(&kmap_mutex); |
582 | 582 | ||
583 | kmap_av++; |
583 | kmap_av++; |
584 | if(i < kmap_first) |
584 | if(i < kmap_first) |
585 | kmap_first = i; |
585 | kmap_first = i; |
586 | kmap_table[i] = NULL; |
586 | kmap_table[i] = NULL; |
587 | 587 | ||
588 | MutexUnlock(&kmap_mutex); |
588 | MutexUnlock(&kmap_mutex); |
589 | } |
589 | } |
590 | - | ||
591 | size_t strlcat(char *dest, const char *src, size_t count) |
- | |
592 | { |
- | |
593 | size_t dsize = strlen(dest); |
- | |
594 | size_t len = strlen(src); |
- | |
595 | size_t res = dsize + len; |
- | |
596 | - | ||
597 | /* This would be a bug */ |
- | |
598 | BUG_ON(dsize >= count); |
- | |
599 | - | ||
600 | dest += dsize; |
- | |
601 | count -= dsize; |
- | |
602 | if (len >= count) |
- | |
603 | len = count-1; |
- | |
604 | memcpy(dest, src, len); |
- | |
605 | dest[len] = 0; |
- | |
606 | return res; |
- | |
607 | } |
- | |
608 | EXPORT_SYMBOL(strlcat); |
- | |
609 | 590 | ||
610 | void msleep(unsigned int msecs) |
591 | void msleep(unsigned int msecs) |
611 | { |
592 | { |
612 | msecs /= 10; |
593 | msecs /= 10; |
613 | if(!msecs) msecs = 1; |
594 | if(!msecs) msecs = 1; |
614 | 595 | ||
615 | __asm__ __volatile__ ( |
596 | __asm__ __volatile__ ( |
616 | "call *__imp__Delay" |
597 | "call *__imp__Delay" |
617 | ::"b" (msecs)); |
598 | ::"b" (msecs)); |
618 | __asm__ __volatile__ ( |
599 | __asm__ __volatile__ ( |
619 | "":::"ebx"); |
600 | "":::"ebx"); |
620 | 601 | ||
621 | }; |
602 | }; |
622 | 603 | ||
623 | 604 | ||
624 | /* simple loop based delay: */ |
605 | /* simple loop based delay: */ |
625 | static void delay_loop(unsigned long loops) |
606 | static void delay_loop(unsigned long loops) |
626 | { |
607 | { |
627 | asm volatile( |
608 | asm volatile( |
628 | " test %0,%0 \n" |
609 | " test %0,%0 \n" |
629 | " jz 3f \n" |
610 | " jz 3f \n" |
630 | " jmp 1f \n" |
611 | " jmp 1f \n" |
631 | 612 | ||
632 | ".align 16 \n" |
613 | ".align 16 \n" |
633 | "1: jmp 2f \n" |
614 | "1: jmp 2f \n" |
634 | 615 | ||
635 | ".align 16 \n" |
616 | ".align 16 \n" |
636 | "2: dec %0 \n" |
617 | "2: dec %0 \n" |
637 | " jnz 2b \n" |
618 | " jnz 2b \n" |
638 | "3: dec %0 \n" |
619 | "3: dec %0 \n" |
639 | 620 | ||
640 | : /* we don't need output */ |
621 | : /* we don't need output */ |
641 | :"a" (loops) |
622 | :"a" (loops) |
642 | ); |
623 | ); |
643 | } |
624 | } |
644 | 625 | ||
645 | 626 | ||
646 | static void (*delay_fn)(unsigned long) = delay_loop; |
627 | static void (*delay_fn)(unsigned long) = delay_loop; |
647 | 628 | ||
648 | void __delay(unsigned long loops) |
629 | void __delay(unsigned long loops) |
649 | { |
630 | { |
650 | delay_fn(loops); |
631 | delay_fn(loops); |
651 | } |
632 | } |
652 | 633 | ||
653 | 634 | ||
654 | inline void __const_udelay(unsigned long xloops) |
635 | inline void __const_udelay(unsigned long xloops) |
655 | { |
636 | { |
656 | int d0; |
637 | int d0; |
657 | 638 | ||
658 | xloops *= 4; |
639 | xloops *= 4; |
659 | asm("mull %%edx" |
640 | asm("mull %%edx" |
660 | : "=d" (xloops), "=&a" (d0) |
641 | : "=d" (xloops), "=&a" (d0) |
661 | : "1" (xloops), "" |
642 | : "1" (xloops), "" |
662 | (loops_per_jiffy * (HZ/4))); |
643 | (loops_per_jiffy * (HZ/4))); |
663 | 644 | ||
664 | __delay(++xloops); |
645 | __delay(++xloops); |
665 | } |
646 | } |
666 | 647 | ||
667 | void __udelay(unsigned long usecs) |
648 | void __udelay(unsigned long usecs) |
668 | { |
649 | { |
669 | __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */ |
650 | __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */ |
670 | } |
651 | } |
671 | 652 | ||
672 | unsigned int _sw_hweight32(unsigned int w) |
653 | unsigned int _sw_hweight32(unsigned int w) |
673 | { |
654 | { |
674 | #ifdef CONFIG_ARCH_HAS_FAST_MULTIPLIER |
655 | #ifdef CONFIG_ARCH_HAS_FAST_MULTIPLIER |
675 | w -= (w >> 1) & 0x55555555; |
656 | w -= (w >> 1) & 0x55555555; |
676 | w = (w & 0x33333333) + ((w >> 2) & 0x33333333); |
657 | w = (w & 0x33333333) + ((w >> 2) & 0x33333333); |
677 | w = (w + (w >> 4)) & 0x0f0f0f0f; |
658 | w = (w + (w >> 4)) & 0x0f0f0f0f; |
678 | return (w * 0x01010101) >> 24; |
659 | return (w * 0x01010101) >> 24; |
679 | #else |
660 | #else |
680 | unsigned int res = w - ((w >> 1) & 0x55555555); |
661 | unsigned int res = w - ((w >> 1) & 0x55555555); |
681 | res = (res & 0x33333333) + ((res >> 2) & 0x33333333); |
662 | res = (res & 0x33333333) + ((res >> 2) & 0x33333333); |
682 | res = (res + (res >> 4)) & 0x0F0F0F0F; |
663 | res = (res + (res >> 4)) & 0x0F0F0F0F; |
683 | res = res + (res >> 8); |
664 | res = res + (res >> 8); |
684 | return (res + (res >> 16)) & 0x000000FF; |
665 | return (res + (res >> 16)) & 0x000000FF; |
685 | #endif |
666 | #endif |
686 | } |
667 | } |
687 | EXPORT_SYMBOL(_sw_hweight32); |
668 | EXPORT_SYMBOL(_sw_hweight32); |
688 | 669 | ||
689 | 670 | ||
690 | void usleep_range(unsigned long min, unsigned long max) |
671 | void usleep_range(unsigned long min, unsigned long max) |
691 | { |
672 | { |
692 | udelay(max); |
673 | udelay(max); |
693 | } |
674 | } |
694 | EXPORT_SYMBOL(usleep_range); |
675 | EXPORT_SYMBOL(usleep_range); |
695 | 676 | ||
696 | 677 | ||
697 | static unsigned long round_jiffies_common(unsigned long j, int cpu, |
678 | static unsigned long round_jiffies_common(unsigned long j, int cpu, |
698 | bool force_up) |
679 | bool force_up) |
699 | { |
680 | { |
700 | int rem; |
681 | int rem; |
701 | unsigned long original = j; |
682 | unsigned long original = j; |
702 | 683 | ||
703 | /* |
684 | /* |
704 | * We don't want all cpus firing their timers at once hitting the |
685 | * We don't want all cpus firing their timers at once hitting the |
705 | * same lock or cachelines, so we skew each extra cpu with an extra |
686 | * same lock or cachelines, so we skew each extra cpu with an extra |
706 | * 3 jiffies. This 3 jiffies came originally from the mm/ code which |
687 | * 3 jiffies. This 3 jiffies came originally from the mm/ code which |
707 | * already did this. |
688 | * already did this. |
708 | * The skew is done by adding 3*cpunr, then round, then subtract this |
689 | * The skew is done by adding 3*cpunr, then round, then subtract this |
709 | * extra offset again. |
690 | * extra offset again. |
710 | */ |
691 | */ |
711 | j += cpu * 3; |
692 | j += cpu * 3; |
712 | 693 | ||
713 | rem = j % HZ; |
694 | rem = j % HZ; |
714 | 695 | ||
715 | /* |
696 | /* |
716 | * If the target jiffie is just after a whole second (which can happen |
697 | * If the target jiffie is just after a whole second (which can happen |
717 | * due to delays of the timer irq, long irq off times etc etc) then |
698 | * due to delays of the timer irq, long irq off times etc etc) then |
718 | * we should round down to the whole second, not up. Use 1/4th second |
699 | * we should round down to the whole second, not up. Use 1/4th second |
719 | * as cutoff for this rounding as an extreme upper bound for this. |
700 | * as cutoff for this rounding as an extreme upper bound for this. |
720 | * But never round down if @force_up is set. |
701 | * But never round down if @force_up is set. |
721 | */ |
702 | */ |
722 | if (rem < HZ/4 && !force_up) /* round down */ |
703 | if (rem < HZ/4 && !force_up) /* round down */ |
723 | j = j - rem; |
704 | j = j - rem; |
724 | else /* round up */ |
705 | else /* round up */ |
725 | j = j - rem + HZ; |
706 | j = j - rem + HZ; |
726 | 707 | ||
727 | /* now that we have rounded, subtract the extra skew again */ |
708 | /* now that we have rounded, subtract the extra skew again */ |
728 | j -= cpu * 3; |
709 | j -= cpu * 3; |
729 | 710 | ||
730 | /* |
711 | /* |
731 | * Make sure j is still in the future. Otherwise return the |
712 | * Make sure j is still in the future. Otherwise return the |
732 | * unmodified value. |
713 | * unmodified value. |
733 | */ |
714 | */ |
734 | return time_is_after_jiffies(j) ? j : original; |
715 | return time_is_after_jiffies(j) ? j : original; |
735 | } |
716 | } |
736 | 717 | ||
737 | 718 | ||
738 | unsigned long round_jiffies_up_relative(unsigned long j, int cpu) |
719 | unsigned long round_jiffies_up_relative(unsigned long j, int cpu) |
739 | { |
720 | { |
740 | unsigned long j0 = jiffies; |
721 | unsigned long j0 = jiffies; |
741 | 722 | ||
742 | /* Use j0 because jiffies might change while we run */ |
723 | /* Use j0 because jiffies might change while we run */ |
743 | return round_jiffies_common(j + j0, 0, true) - j0; |
724 | return round_jiffies_common(j + j0, 0, true) - j0; |
744 | } |
725 | } |
745 | EXPORT_SYMBOL_GPL(__round_jiffies_up_relative); |
726 | EXPORT_SYMBOL_GPL(__round_jiffies_up_relative); |
746 | 727 | ||
747 | 728 | ||
748 | #include |
729 | #include |
749 | 730 | ||
750 | struct rcu_ctrlblk { |
731 | struct rcu_ctrlblk { |
751 | struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */ |
732 | struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */ |
752 | struct rcu_head **donetail; /* ->next pointer of last "done" CB. */ |
733 | struct rcu_head **donetail; /* ->next pointer of last "done" CB. */ |
753 | struct rcu_head **curtail; /* ->next pointer of last CB. */ |
734 | struct rcu_head **curtail; /* ->next pointer of last CB. */ |
754 | // RCU_TRACE(long qlen); /* Number of pending CBs. */ |
735 | // RCU_TRACE(long qlen); /* Number of pending CBs. */ |
755 | // RCU_TRACE(unsigned long gp_start); /* Start time for stalls. */ |
736 | // RCU_TRACE(unsigned long gp_start); /* Start time for stalls. */ |
756 | // RCU_TRACE(unsigned long ticks_this_gp); /* Statistic for stalls. */ |
737 | // RCU_TRACE(unsigned long ticks_this_gp); /* Statistic for stalls. */ |
757 | // RCU_TRACE(unsigned long jiffies_stall); /* Jiffies at next stall. */ |
738 | // RCU_TRACE(unsigned long jiffies_stall); /* Jiffies at next stall. */ |
758 | // RCU_TRACE(const char *name); /* Name of RCU type. */ |
739 | // RCU_TRACE(const char *name); /* Name of RCU type. */ |
759 | }; |
740 | }; |
760 | 741 | ||
761 | /* Definition for rcupdate control block. */ |
742 | /* Definition for rcupdate control block. */ |
762 | static struct rcu_ctrlblk rcu_sched_ctrlblk = { |
743 | static struct rcu_ctrlblk rcu_sched_ctrlblk = { |
763 | .donetail = &rcu_sched_ctrlblk.rcucblist, |
744 | .donetail = &rcu_sched_ctrlblk.rcucblist, |
764 | .curtail = &rcu_sched_ctrlblk.rcucblist, |
745 | .curtail = &rcu_sched_ctrlblk.rcucblist, |
765 | // RCU_TRACE(.name = "rcu_sched") |
746 | // RCU_TRACE(.name = "rcu_sched") |
766 | }; |
747 | }; |
767 | 748 | ||
768 | static void __call_rcu(struct rcu_head *head, |
749 | static void __call_rcu(struct rcu_head *head, |
769 | void (*func)(struct rcu_head *rcu), |
750 | void (*func)(struct rcu_head *rcu), |
770 | struct rcu_ctrlblk *rcp) |
751 | struct rcu_ctrlblk *rcp) |
771 | { |
752 | { |
772 | unsigned long flags; |
753 | unsigned long flags; |
773 | 754 | ||
774 | // debug_rcu_head_queue(head); |
755 | // debug_rcu_head_queue(head); |
775 | head->func = func; |
756 | head->func = func; |
776 | head->next = NULL; |
757 | head->next = NULL; |
777 | 758 | ||
778 | local_irq_save(flags); |
759 | local_irq_save(flags); |
779 | *rcp->curtail = head; |
760 | *rcp->curtail = head; |
780 | rcp->curtail = &head->next; |
761 | rcp->curtail = &head->next; |
781 | // RCU_TRACE(rcp->qlen++); |
762 | // RCU_TRACE(rcp->qlen++); |
782 | local_irq_restore(flags); |
763 | local_irq_restore(flags); |
783 | } |
764 | } |
784 | 765 | ||
785 | /* |
766 | /* |
786 | * Post an RCU callback to be invoked after the end of an RCU-sched grace |
767 | * Post an RCU callback to be invoked after the end of an RCU-sched grace |
787 | * period. But since we have but one CPU, that would be after any |
768 | * period. But since we have but one CPU, that would be after any |
788 | * quiescent state. |
769 | * quiescent state. |
789 | */ |
770 | */ |
790 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
771 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
791 | { |
772 | { |
792 | __call_rcu(head, func, &rcu_sched_ctrlblk); |
773 | __call_rcu(head, func, &rcu_sched_ctrlblk); |
793 | } |
774 | } |
794 | 775 | ||
795 | int seq_puts(struct seq_file *m, const char *s) |
776 | int seq_puts(struct seq_file *m, const char *s) |
796 | { |
777 | { |
797 | return 0; |
778 | return 0; |
798 | }; |
779 | }; |
799 | 780 | ||
800 | __printf(2, 3) int seq_printf(struct seq_file *m, const char *f, ...) |
781 | __printf(2, 3) int seq_printf(struct seq_file *m, const char *f, ...) |
801 | { |
782 | { |
802 | return 0; |
783 | return 0; |
803 | } |
784 | } |
804 | 785 | ||
805 | 786 | ||
806 | signed long |
787 | signed long |
807 | fence_wait_timeout(struct fence *fence, bool intr, signed long timeout) |
788 | fence_wait_timeout(struct fence *fence, bool intr, signed long timeout) |
808 | { |
789 | { |
809 | signed long ret; |
790 | signed long ret; |
810 | 791 | ||
811 | if (WARN_ON(timeout < 0)) |
792 | if (WARN_ON(timeout < 0)) |
812 | return -EINVAL; |
793 | return -EINVAL; |
813 | 794 | ||
814 | // trace_fence_wait_start(fence); |
795 | // trace_fence_wait_start(fence); |
815 | ret = fence->ops->wait(fence, intr, timeout); |
796 | ret = fence->ops->wait(fence, intr, timeout); |
816 | // trace_fence_wait_end(fence); |
797 | // trace_fence_wait_end(fence); |
817 | return ret; |
798 | return ret; |
818 | } |
799 | } |
819 | 800 | ||
820 | void fence_release(struct kref *kref) |
801 | void fence_release(struct kref *kref) |
821 | { |
802 | { |
822 | struct fence *fence = |
803 | struct fence *fence = |
823 | container_of(kref, struct fence, refcount); |
804 | container_of(kref, struct fence, refcount); |
824 | 805 | ||
825 | // trace_fence_destroy(fence); |
806 | // trace_fence_destroy(fence); |
826 | 807 | ||
827 | BUG_ON(!list_empty(&fence->cb_list)); |
808 | BUG_ON(!list_empty(&fence->cb_list)); |
828 | 809 | ||
829 | if (fence->ops->release) |
810 | if (fence->ops->release) |
830 | fence->ops->release(fence); |
811 | fence->ops->release(fence); |
831 | else |
812 | else |
832 | fence_free(fence); |
813 | fence_free(fence); |
833 | } |
814 | } |
834 | 815 | ||
835 | void fence_free(struct fence *fence) |
816 | void fence_free(struct fence *fence) |
836 | { |
817 | { |
837 | kfree_rcu(fence, rcu); |
818 | kfree_rcu(fence, rcu); |
838 | } |
819 | } |
839 | EXPORT_SYMBOL(fence_free); |
820 | EXPORT_SYMBOL(fence_free); |
840 | 821 | ||
841 | 822 | ||
842 | ktime_t ktime_get(void) |
823 | ktime_t ktime_get(void) |
843 | { |
824 | { |
844 | ktime_t t; |
825 | ktime_t t; |
845 | 826 | ||
846 | t.tv64 = GetClockNs(); |
827 | t.tv64 = GetClockNs(); |
847 | 828 | ||
848 | return t; |
829 | return t; |
849 | } |
830 | } |
850 | 831 | ||
851 | char *strdup(const char *str) |
832 | char *strdup(const char *str) |
852 | { |
833 | { |
853 | size_t len = strlen(str) + 1; |
834 | size_t len = strlen(str) + 1; |
854 | char *copy = __builtin_malloc(len); |
835 | char *copy = __builtin_malloc(len); |
855 | if (copy) |
836 | if (copy) |
856 | { |
837 | { |
857 | memcpy (copy, str, len); |
838 | memcpy (copy, str, len); |
858 | } |
839 | } |
859 | return copy; |
840 | return copy; |
860 | } |
841 | } |
861 | 842 | ||
862 | int split_cmdline(char *cmdline, char **argv) |
843 | int split_cmdline(char *cmdline, char **argv) |
863 | { |
844 | { |
864 | enum quote_state |
845 | enum quote_state |
865 | { |
846 | { |
866 | QUOTE_NONE, /* no " active in current parm */ |
847 | QUOTE_NONE, /* no " active in current parm */ |
867 | QUOTE_DELIMITER, /* " was first char and must be last */ |
848 | QUOTE_DELIMITER, /* " was first char and must be last */ |
868 | QUOTE_STARTED /* " was seen, look for a match */ |
849 | QUOTE_STARTED /* " was seen, look for a match */ |
869 | }; |
850 | }; |
870 | 851 | ||
871 | enum quote_state state; |
852 | enum quote_state state; |
872 | unsigned int argc; |
853 | unsigned int argc; |
873 | char *p = cmdline; |
854 | char *p = cmdline; |
874 | char *new_arg, *start; |
855 | char *new_arg, *start; |
875 | 856 | ||
876 | argc = 0; |
857 | argc = 0; |
877 | 858 | ||
878 | for(;;) |
859 | for(;;) |
879 | { |
860 | { |
880 | /* skip over spaces and tabs */ |
861 | /* skip over spaces and tabs */ |
881 | if ( *p ) |
862 | if ( *p ) |
882 | { |
863 | { |
883 | while (*p == ' ' || *p == '\t') |
864 | while (*p == ' ' || *p == '\t') |
884 | ++p; |
865 | ++p; |
885 | } |
866 | } |
886 | 867 | ||
887 | if (*p == '\0') |
868 | if (*p == '\0') |
888 | break; |
869 | break; |
889 | 870 | ||
890 | state = QUOTE_NONE; |
871 | state = QUOTE_NONE; |
891 | if( *p == '\"' ) |
872 | if( *p == '\"' ) |
892 | { |
873 | { |
893 | p++; |
874 | p++; |
894 | state = QUOTE_DELIMITER; |
875 | state = QUOTE_DELIMITER; |
895 | } |
876 | } |
896 | new_arg = start = p; |
877 | new_arg = start = p; |
897 | for (;;) |
878 | for (;;) |
898 | { |
879 | { |
899 | if( *p == '\"' ) |
880 | if( *p == '\"' ) |
900 | { |
881 | { |
901 | p++; |
882 | p++; |
902 | if( state == QUOTE_NONE ) |
883 | if( state == QUOTE_NONE ) |
903 | { |
884 | { |
904 | state = QUOTE_STARTED; |
885 | state = QUOTE_STARTED; |
905 | } |
886 | } |
906 | else |
887 | else |
907 | { |
888 | { |
908 | state = QUOTE_NONE; |
889 | state = QUOTE_NONE; |
909 | } |
890 | } |
910 | continue; |
891 | continue; |
911 | } |
892 | } |
912 | 893 | ||
913 | if( *p == ' ' || *p == '\t' ) |
894 | if( *p == ' ' || *p == '\t' ) |
914 | { |
895 | { |
915 | if( state == QUOTE_NONE ) |
896 | if( state == QUOTE_NONE ) |
916 | { |
897 | { |
917 | break; |
898 | break; |
918 | } |
899 | } |
919 | } |
900 | } |
920 | 901 | ||
921 | if( *p == '\0' ) |
902 | if( *p == '\0' ) |
922 | break; |
903 | break; |
923 | 904 | ||
924 | if( *p == '\\' ) |
905 | if( *p == '\\' ) |
925 | { |
906 | { |
926 | if( p[1] == '\"' ) |
907 | if( p[1] == '\"' ) |
927 | { |
908 | { |
928 | ++p; |
909 | ++p; |
929 | if( p[-2] == '\\' ) |
910 | if( p[-2] == '\\' ) |
930 | { |
911 | { |
931 | continue; |
912 | continue; |
932 | } |
913 | } |
933 | } |
914 | } |
934 | } |
915 | } |
935 | if( argv ) |
916 | if( argv ) |
936 | { |
917 | { |
937 | *(new_arg++) = *p; |
918 | *(new_arg++) = *p; |
938 | } |
919 | } |
939 | ++p; |
920 | ++p; |
940 | }; |
921 | }; |
941 | 922 | ||
942 | if( argv ) |
923 | if( argv ) |
943 | { |
924 | { |
944 | argv[ argc ] = start; |
925 | argv[ argc ] = start; |
945 | ++argc; |
926 | ++argc; |
946 | 927 | ||
947 | /* |
928 | /* |
948 | The *new = '\0' is req'd in case there was a \" to " |
929 | The *new = '\0' is req'd in case there was a \" to " |
949 | translation. It must be after the *p check against |
930 | translation. It must be after the *p check against |
950 | '\0' because new and p could point to the same char |
931 | '\0' because new and p could point to the same char |
951 | in which case the scan would be terminated too soon. |
932 | in which case the scan would be terminated too soon. |
952 | */ |
933 | */ |
953 | 934 | ||
954 | if( *p == '\0' ) |
935 | if( *p == '\0' ) |
955 | { |
936 | { |
956 | *new_arg = '\0'; |
937 | *new_arg = '\0'; |
957 | break; |
938 | break; |
958 | } |
939 | } |
959 | *new_arg = '\0'; |
940 | *new_arg = '\0'; |
960 | ++p; |
941 | ++p; |
961 | } |
942 | } |
962 | else |
943 | else |
963 | { |
944 | { |
964 | ++argc; |
945 | ++argc; |
965 | if( *p == '\0' ) |
946 | if( *p == '\0' ) |
966 | { |
947 | { |
967 | break; |
948 | break; |
968 | } |
949 | } |
969 | ++p; |
950 | ++p; |
970 | } |
951 | } |
971 | } |
952 | } |
972 | 953 | ||
973 | return argc; |
954 | return argc; |
974 | }; |
955 | }; |
975 | 956 | ||
976 | 957 | ||
977 | fb_get_options(const char *name, char **option) |
958 | fb_get_options(const char *name, char **option) |
978 | { |
959 | { |
979 | char *opt, *options = NULL; |
960 | char *opt, *options = NULL; |
980 | int retval = 1; |
961 | int retval = 1; |
981 | int name_len; |
962 | int name_len; |
982 | 963 | ||
983 | if(i915.cmdline_mode == NULL) |
964 | if(i915.cmdline_mode == NULL) |
984 | return 1; |
965 | return 1; |
985 | 966 | ||
986 | name_len = __builtin_strlen(name); |
967 | name_len = __builtin_strlen(name); |
987 | 968 | ||
988 | if (name_len ) |
969 | if (name_len ) |
989 | { |
970 | { |
990 | opt = i915.cmdline_mode; |
971 | opt = i915.cmdline_mode; |
991 | if (!__builtin_strncmp(name, opt, name_len) && |
972 | if (!__builtin_strncmp(name, opt, name_len) && |
992 | opt[name_len] == ':') |
973 | opt[name_len] == ':') |
993 | { |
974 | { |
994 | options = opt + name_len + 1; |
975 | options = opt + name_len + 1; |
995 | retval = 0; |
976 | retval = 0; |
996 | } |
977 | } |
997 | } |
978 | } |
998 | 979 | ||
999 | if (option) |
980 | if (option) |
1000 | *option = options; |
981 | *option = options; |
1001 | 982 | ||
1002 | return retval; |
983 | return retval; |
1003 | }>>>12); |
984 | }>>>12); |
1004 | ><12); |
985 | ><12); |
1005 | >>>12); |
986 | >>>12); |
1006 | ><12); |
987 | ><12); |
1007 | >>>>>>>>>>>>><>>>=>=>=0x7f) |
988 | >>>>>>>>>>>>><>>>=>=>=0x7f) |
1008 | #define>><>><>><>><>=>>> |
989 | #define>><>><>><>><>=>>> |