Rev 1047 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
432 | giacomo | 1 | |
2 | #include <ll/i386/hw-instr.h> |
||
436 | giacomo | 3 | #include <ll/i386/cons.h> |
500 | giacomo | 4 | #include <ll/sys/ll/time.h> |
432 | giacomo | 5 | |
6 | #include <linuxcomp.h> |
||
7 | |||
8 | #include <linux/time.h> |
||
9 | #include <linux/sched.h> |
||
436 | giacomo | 10 | #include <linux/ioport.h> |
437 | giacomo | 11 | #include <linux/errno.h> |
436 | giacomo | 12 | #include <asm/io.h> |
437 | giacomo | 13 | #include <linux/ctype.h> |
14 | #include <linux/device.h> |
||
462 | giacomo | 15 | #include <linux/completion.h> |
468 | giacomo | 16 | #include <linux/tty.h> |
17 | #include <asm/setup.h> |
||
432 | giacomo | 18 | |
537 | giacomo | 19 | #define memory_barrier __asm__("" ::: "memory") |
20 | |||
500 | giacomo | 21 | extern unsigned long intr_count; |
22 | extern int activeInt; |
||
23 | |||
437 | giacomo | 24 | unsigned char _ctype[] = { |
25 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ |
||
26 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ |
||
27 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ |
||
28 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ |
||
29 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ |
||
30 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ |
||
31 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ |
||
32 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ |
||
33 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ |
||
34 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ |
||
35 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ |
||
36 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ |
||
37 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ |
||
38 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ |
||
39 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ |
||
40 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ |
||
41 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ |
||
42 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ |
||
43 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ |
||
44 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ |
||
45 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ |
||
46 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ |
||
47 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ |
||
48 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ |
||
1047 | mauro | 49 | |
455 | giacomo | 50 | __kernel_size_t strnlen(const char *s, __kernel_size_t count) |
51 | { |
||
1047 | mauro | 52 | const char *sc; |
53 | |||
54 | for (sc = s; count-- && *sc != '\0'; ++sc) |
||
455 | giacomo | 55 | /* nothing */; |
1047 | mauro | 56 | return sc - s; |
455 | giacomo | 57 | } |
437 | giacomo | 58 | |
432 | giacomo | 59 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); |
60 | |||
436 | giacomo | 61 | struct resource ioport_resource = { |
1047 | mauro | 62 | .name = "PCI IO", |
63 | .start = 0x0000, |
||
64 | .end = IO_SPACE_LIMIT, |
||
65 | .flags = IORESOURCE_IO, |
||
436 | giacomo | 66 | }; |
67 | |||
68 | struct resource iomem_resource = { |
||
1047 | mauro | 69 | .name = "PCI mem", |
70 | .start = 0UL, |
||
71 | .end = ~0UL, |
||
72 | .flags = IORESOURCE_MEM, |
||
436 | giacomo | 73 | }; |
74 | |||
437 | giacomo | 75 | /* Return the conflict entry if you can't request it */ |
76 | static struct resource * __request_resource(struct resource *root, struct resource *new) |
||
77 | { |
||
78 | unsigned long start = new->start; |
||
79 | unsigned long end = new->end; |
||
80 | struct resource *tmp, **p; |
||
436 | giacomo | 81 | |
437 | giacomo | 82 | if (end < start) |
83 | return root; |
||
84 | if (start < root->start) |
||
85 | return root; |
||
86 | if (end > root->end) |
||
87 | return root; |
||
88 | p = &root->child; |
||
89 | for (;;) { |
||
90 | tmp = *p; |
||
91 | if (!tmp || tmp->start > end) { |
||
92 | new->sibling = tmp; |
||
93 | *p = new; |
||
94 | new->parent = root; |
||
95 | return NULL; |
||
96 | } |
||
97 | p = &tmp->sibling; |
||
98 | if (tmp->end < start) |
||
99 | continue; |
||
100 | return tmp; |
||
101 | } |
||
436 | giacomo | 102 | } |
103 | |||
437 | giacomo | 104 | static int __release_resource(struct resource *old) |
105 | { |
||
106 | struct resource *tmp, **p; |
||
107 | |||
108 | p = &old->parent->child; |
||
109 | for (;;) { |
||
110 | tmp = *p; |
||
111 | if (!tmp) |
||
112 | break; |
||
113 | if (tmp == old) { |
||
114 | *p = tmp->sibling; |
||
115 | old->parent = NULL; |
||
116 | return 0; |
||
117 | } |
||
118 | p = &tmp->sibling; |
||
119 | } |
||
120 | return -EINVAL; |
||
121 | } |
||
122 | |||
123 | int release_resource(struct resource *old) |
||
124 | { |
||
125 | int retval; |
||
126 | |||
127 | retval = __release_resource(old); |
||
128 | |||
129 | return retval; |
||
130 | } |
||
131 | |||
132 | int request_resource(struct resource *root, struct resource *new) |
||
133 | { |
||
134 | struct resource *conflict; |
||
135 | |||
136 | conflict = __request_resource(root, new); |
||
137 | |||
138 | return conflict ? -EBUSY : 0; |
||
139 | } |
||
140 | |||
141 | |||
142 | |||
143 | struct resource * __request_region(struct resource *parent, unsigned long start, unsigned long n, const char *name) |
||
144 | { |
||
475 | giacomo | 145 | return (void *)(0xFFFFFFFF); |
437 | giacomo | 146 | } |
147 | |||
148 | void __release_region(struct resource *parent, unsigned long start, unsigned long n) |
||
149 | { |
||
150 | |||
151 | } |
||
152 | |||
153 | static int find_resource(struct resource *root, struct resource *new, |
||
154 | unsigned long size, |
||
155 | unsigned long min, unsigned long max, |
||
156 | unsigned long align, |
||
157 | void (*alignf)(void *, struct resource *, |
||
158 | unsigned long, unsigned long), |
||
159 | void *alignf_data) |
||
160 | { |
||
161 | struct resource *this = root->child; |
||
162 | |||
163 | new->start = root->start; |
||
164 | /* |
||
165 | * Skip past an allocated resource that starts at 0, since the assignment |
||
166 | * of this->start - 1 to new->end below would cause an underflow. |
||
167 | */ |
||
168 | if (this && this->start == 0) { |
||
169 | new->start = this->end + 1; |
||
170 | this = this->sibling; |
||
171 | } |
||
172 | for(;;) { |
||
173 | if (this) |
||
174 | new->end = this->start - 1; |
||
175 | else |
||
176 | new->end = root->end; |
||
177 | if (new->start < min) |
||
178 | new->start = min; |
||
179 | if (new->end > max) |
||
180 | new->end = max; |
||
181 | new->start = (new->start + align - 1) & ~(align - 1); |
||
182 | if (alignf) |
||
183 | alignf(alignf_data, new, size, align); |
||
184 | if (new->start < new->end && new->end - new->start + 1 >= size) { |
||
185 | new->end = new->start + size - 1; |
||
186 | return 0; |
||
187 | } |
||
188 | if (!this) |
||
189 | break; |
||
190 | new->start = this->end + 1; |
||
191 | this = this->sibling; |
||
192 | } |
||
193 | return -EBUSY; |
||
194 | } |
||
195 | |||
196 | int allocate_resource(struct resource *root, struct resource *new, |
||
197 | unsigned long size, |
||
198 | unsigned long min, unsigned long max, |
||
199 | unsigned long align, |
||
200 | void (*alignf)(void *, struct resource *, |
||
201 | unsigned long, unsigned long), |
||
202 | void *alignf_data) |
||
203 | { |
||
204 | int err; |
||
205 | |||
206 | err = find_resource(root, new, size, min, max, align, alignf, alignf_data); |
||
207 | if (err >= 0 && __request_resource(root, new)) |
||
208 | err = -EBUSY; |
||
209 | |||
210 | return err; |
||
211 | } |
||
212 | |||
213 | int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot) |
||
1047 | mauro | 214 | { |
215 | return 0; |
||
216 | } |
||
437 | giacomo | 217 | |
1047 | mauro | 218 | void dump_stack(void) |
219 | { |
||
436 | giacomo | 220 | |
1047 | mauro | 221 | } |
436 | giacomo | 222 | |
1047 | mauro | 223 | void panic(const char * fmt, ...) |
224 | { |
||
225 | cprintf((char *)(fmt)); |
||
436 | giacomo | 226 | } |
227 | |||
228 | extern void * malloc(size_t size); |
||
229 | |||
1047 | mauro | 230 | void *__kmalloc(size_t size, int flags) |
231 | { |
||
232 | return malloc(size); |
||
436 | giacomo | 233 | } |
234 | |||
235 | extern void free(void *); |
||
236 | |||
1047 | mauro | 237 | void kfree(const void *ptr) |
238 | { |
||
239 | free((void *)(ptr)); |
||
436 | giacomo | 240 | } |
241 | |||
242 | unsigned long pci_mem_start = 0x10000000; |
||
243 | |||
1056 | tullio | 244 | // added __attribute__ for gcc4 compatibility |
245 | __attribute__((regparm(3))) signed long schedule_timeout(signed long timeout) |
||
1047 | mauro | 246 | { |
247 | struct timespec t,s,e; |
||
432 | giacomo | 248 | |
1047 | mauro | 249 | jiffies_to_timespec(timeout, &t); |
432 | giacomo | 250 | |
1047 | mauro | 251 | if (!activeInt && !intr_count) { |
252 | nanosleep(&t,NULL); |
||
253 | } else { |
||
254 | ll_gettime(TIME_NEW,&s); |
||
255 | ADDTIMESPEC(&t,&s,&e); |
||
432 | giacomo | 256 | |
1047 | mauro | 257 | memory_barrier; |
432 | giacomo | 258 | |
1047 | mauro | 259 | while(TIMESPEC_A_LT_B(&s,&e)) { |
260 | memory_barrier; |
||
261 | ll_gettime(TIME_NEW,&s); |
||
262 | } |
||
263 | } |
||
264 | |||
265 | return 0; |
||
432 | giacomo | 266 | } |
436 | giacomo | 267 | |
1047 | mauro | 268 | void __const_udelay(unsigned long usecs) |
269 | { |
||
270 | struct timespec t,s,e; |
||
436 | giacomo | 271 | |
1047 | mauro | 272 | if (!activeInt && !intr_count) { |
273 | t.tv_sec = 0; |
||
274 | t.tv_nsec = usecs * 1000; |
||
500 | giacomo | 275 | |
1047 | mauro | 276 | nanosleep(&t,NULL); |
277 | } else { |
||
278 | ll_gettime(TIME_NEW,&e); |
||
279 | ADDUSEC2TIMESPEC(usecs,&e); |
||
436 | giacomo | 280 | |
1047 | mauro | 281 | memory_barrier; |
500 | giacomo | 282 | |
1047 | mauro | 283 | ll_gettime(TIME_NEW,&s); |
284 | while(TIMESPEC_A_LT_B(&s,&e)) { |
||
285 | memory_barrier; |
||
286 | ll_gettime(TIME_NEW,&s); |
||
287 | } |
||
288 | } |
||
464 | giacomo | 289 | } |
290 | |||
537 | giacomo | 291 | void * vmalloc_32(size_t size); |
292 | |||
1047 | mauro | 293 | void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int gfp) |
516 | giacomo | 294 | { |
1047 | mauro | 295 | void *ret; |
296 | /* ignore region specifiers */ |
||
297 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); |
||
298 | |||
299 | if (dev == NULL || (*dev->dma_mask < 0xffffffff)) |
||
300 | gfp |= GFP_DMA; |
||
301 | ret = (void *)vmalloc_32(size); |
||
302 | |||
303 | if (ret != NULL) { |
||
304 | memset(ret, 0, size); |
||
305 | *dma_handle = (dma_addr_t)ret; |
||
306 | } |
||
307 | return ret; |
||
516 | giacomo | 308 | } |
1047 | mauro | 309 | |
310 | void *dma_alloc_coherent_usb(struct device *dev, size_t size, dma_addr_t *dma_handle, int gfp) |
||
516 | giacomo | 311 | { |
1047 | mauro | 312 | void *ret; |
313 | /* ignore region specifiers */ |
||
314 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); |
||
315 | |||
316 | if (dev == NULL || (*dev->dma_mask < 0xffffffff)) |
||
317 | gfp |= GFP_DMA; |
||
318 | ret = (void *)vmalloc_32_usb(size); |
||
319 | |||
320 | if (ret != NULL) { |
||
321 | memset(ret, 0, size); |
||
322 | *dma_handle = (dma_addr_t)ret; |
||
323 | } |
||
324 | return ret; |
||
325 | } |
||
326 | |||
327 | void dma_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle) |
||
328 | { |
||
611 | giacomo | 329 | vfree((void *)dma_handle); |
516 | giacomo | 330 | } |
331 | |||
847 | giacomo | 332 | extern void __wake_up_common(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, int sync); |
333 | |||
516 | giacomo | 334 | void init_completion(struct completion *x) { |
847 | giacomo | 335 | x->done = 0; |
336 | init_waitqueue_head(&x->wait); |
||
516 | giacomo | 337 | } |
338 | |||
1056 | tullio | 339 | // added __attribute__ for gcc4 compatibility |
340 | __attribute__((regparm(3))) void complete(struct completion *x) |
||
847 | giacomo | 341 | { |
342 | x->done++; |
||
343 | __wake_up_common(&x->wait, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1, 0); |
||
462 | giacomo | 344 | } |
345 | |||
1056 | tullio | 346 | // added __attribute__ for gcc4 compatibility |
347 | __attribute__((regparm(3))) void wait_for_completion(struct completion *x) |
||
1047 | mauro | 348 | { |
847 | giacomo | 349 | spin_lock_irq(&x->wait.lock); |
350 | if (!x->done) { |
||
351 | DECLARE_WAITQUEUE(wait, current); |
||
352 | |||
353 | wait.flags |= WQ_FLAG_EXCLUSIVE; |
||
354 | __add_wait_queue_tail(&x->wait, &wait); |
||
355 | do { |
||
356 | __set_current_state(TASK_UNINTERRUPTIBLE); |
||
357 | spin_unlock_irq(&x->wait.lock); |
||
358 | schedule(); |
||
359 | spin_lock_irq(&x->wait.lock); |
||
360 | } while (!x->done); |
||
361 | __remove_wait_queue(&x->wait, &wait); |
||
362 | } |
||
363 | x->done--; |
||
364 | spin_unlock_irq(&x->wait.lock); |
||
462 | giacomo | 365 | } |
366 | |||
367 | struct device legacy_bus = { |
||
368 | .bus_id = "legacy", |
||
369 | }; |
||
370 | |||
1047 | mauro | 371 | int register_chrdev(unsigned int a, const char *b, struct file_operations *c) |
372 | { |
||
462 | giacomo | 373 | return 0; |
374 | } |
||
375 | |||
1047 | mauro | 376 | int unregister_chrdev(unsigned int a, const char *b) |
377 | { |
||
462 | giacomo | 378 | return 0; |
379 | } |
||
468 | giacomo | 380 | |
1047 | mauro | 381 | void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) |
382 | { |
||
383 | return (void *)offset; |
||
384 | } |
||
468 | giacomo | 385 | |
1047 | mauro | 386 | void iounmap(void *addr) |
387 | { |
||
468 | giacomo | 388 | |
389 | } |
||
390 | |||
1047 | mauro | 391 | loff_t no_llseek(struct file *file, loff_t offset, int origin) |
392 | { |
||
393 | return 0; |
||
394 | } |
||
468 | giacomo | 395 | |
1047 | mauro | 396 | void *vmalloc(unsigned long size) |
397 | { |
||
398 | return malloc(size); |
||
468 | giacomo | 399 | } |
400 | |||
1047 | mauro | 401 | void *kern_alloc_aligned(size_t size, DWORD flags, int align_bits, DWORD align_ofs); |
540 | giacomo | 402 | |
1047 | mauro | 403 | void * vmalloc_32(size_t size) |
404 | { |
||
405 | void *mem; |
||
406 | unsigned long diff; |
||
540 | giacomo | 407 | |
1047 | mauro | 408 | mem = malloc(size+12); |
540 | giacomo | 409 | |
1047 | mauro | 410 | diff = (unsigned long)((((unsigned long)mem/4)+1)*4-(unsigned long)mem); |
468 | giacomo | 411 | |
1047 | mauro | 412 | *(unsigned long *)(mem+diff) = (diff | 0x80000000); |
468 | giacomo | 413 | |
1047 | mauro | 414 | return (mem+diff+4); |
468 | giacomo | 415 | } |
416 | |||
1047 | mauro | 417 | void vfree(void *addr) |
537 | giacomo | 418 | { |
1047 | mauro | 419 | if (addr == NULL || *(unsigned long *)(addr-4) == 0) |
420 | return; |
||
421 | |||
422 | if ((*(unsigned long *)(addr-4) & 0x80000000) == 0x80000000) { |
||
423 | free(addr-(*(unsigned long *)(addr-4) & 0x7FFFFFFF)-4); |
||
424 | *(unsigned long *)(addr-4) = 0; |
||
425 | return; |
||
426 | } |
||
427 | |||
428 | free(addr); |
||
429 | |||
430 | return; |
||
537 | giacomo | 431 | } |
468 | giacomo | 432 | |
1047 | mauro | 433 | void * vmalloc_32_usb(size_t size) |
434 | { |
||
435 | void* mem; |
||
436 | unsigned long diff; |
||
468 | giacomo | 437 | |
1047 | mauro | 438 | mem = malloc( size + 2 * 4096 ); |
468 | giacomo | 439 | |
1047 | mauro | 440 | if (! mem) |
441 | return NULL; |
||
442 | |||
443 | diff = 4096 - (((unsigned long) mem) % 4096); |
||
444 | *(unsigned long *)(mem+diff) = (diff | 0x80000000); |
||
445 | |||
446 | return (void*)(mem + diff + 4096); |
||
468 | giacomo | 447 | } |
448 | |||
1047 | mauro | 449 | /* TODO */ |
450 | char * strsep(char **a,const char *b) |
||
451 | { |
||
452 | return NULL; |
||
453 | } |
||
454 | |||
468 | giacomo | 455 | struct screen_info screen_info; |
456 | |||
1047 | mauro | 457 | int linuxcomp_setfd(struct inode *i, int i_rdev) |
458 | { |
||
459 | i->i_rdev = i_rdev; |
||
469 | giacomo | 460 | |
1047 | mauro | 461 | return 0; |
462 | } |
||
469 | giacomo | 463 | |
1047 | mauro | 464 | int linuxcomp_init(void) |
465 | { |
||
469 | giacomo | 466 | return 0; |
467 | } |
||
468 | |||
1047 | mauro | 469 | struct page *mem_map = 0x0000; |
468 | giacomo | 470 | |
1056 | tullio | 471 | // added __attribute__ for gcc4 compatibility |
472 | __attribute__((regparm(3))) int schedule_work(struct work_struct *work) |
||
1047 | mauro | 473 | { |
474 | return 0; |
||
475 | } |
||
468 | giacomo | 476 | |
1047 | mauro | 477 | int allow_signal(int sig) |
478 | { |
||
479 | return 0; |
||
468 | giacomo | 480 | } |
847 | giacomo | 481 | |
482 | void flush_scheduled_work(void) { } |
||
483 | void daemonize(const char *name, ...) { } |
||
484 | void yield(void) { } |
||
485 | |||
486 | void do_exit(long code) { } |
||
1047 | mauro | 487 | |
847 | giacomo | 488 | void complete_and_exit(struct completion *comp, long code) |
489 | { |
||
490 | if (comp) |
||
491 | complete(comp); |
||
492 | |||
493 | do_exit(code); |
||
494 | } |
||
495 | |||
496 | inline void * ioremap_nocache(unsigned long offset, unsigned long size) |
||
497 | { |
||
498 | return __ioremap(offset, size, 0); |
||
499 | } |
||
500 | |||
501 | #define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0) |
||
502 | |||
503 | int wait_ms26(unsigned long msec) |
||
504 | { |
||
505 | struct timespec t1, t2; |
||
506 | int nsec; |
||
507 | |||
508 | t1.tv_sec = msec/1000; |
||
509 | nsec = (msec % 1000) * 1000000; |
||
510 | t1.tv_nsec = nsec; |
||
511 | NULL_TIMESPEC(&t2); |
||
512 | nanosleep(&t1, &t2); |
||
513 | |||
514 | return 0; |
||
515 | } |