Rev 856 | Go to most recent revision | 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 | |||
1047 | mauro | 244 | signed long schedule_timeout(signed long timeout) |
245 | { |
||
246 | struct timespec t,s,e; |
||
432 | giacomo | 247 | |
1047 | mauro | 248 | jiffies_to_timespec(timeout, &t); |
432 | giacomo | 249 | |
1047 | mauro | 250 | if (!activeInt && !intr_count) { |
251 | nanosleep(&t,NULL); |
||
252 | } else { |
||
253 | ll_gettime(TIME_NEW,&s); |
||
254 | ADDTIMESPEC(&t,&s,&e); |
||
432 | giacomo | 255 | |
1047 | mauro | 256 | memory_barrier; |
432 | giacomo | 257 | |
1047 | mauro | 258 | while(TIMESPEC_A_LT_B(&s,&e)) { |
259 | memory_barrier; |
||
260 | ll_gettime(TIME_NEW,&s); |
||
261 | } |
||
262 | } |
||
263 | |||
264 | return 0; |
||
432 | giacomo | 265 | } |
436 | giacomo | 266 | |
1047 | mauro | 267 | void __const_udelay(unsigned long usecs) |
268 | { |
||
269 | struct timespec t,s,e; |
||
436 | giacomo | 270 | |
1047 | mauro | 271 | if (!activeInt && !intr_count) { |
272 | t.tv_sec = 0; |
||
273 | t.tv_nsec = usecs * 1000; |
||
500 | giacomo | 274 | |
1047 | mauro | 275 | nanosleep(&t,NULL); |
276 | } else { |
||
277 | ll_gettime(TIME_NEW,&e); |
||
278 | ADDUSEC2TIMESPEC(usecs,&e); |
||
436 | giacomo | 279 | |
1047 | mauro | 280 | memory_barrier; |
500 | giacomo | 281 | |
1047 | mauro | 282 | ll_gettime(TIME_NEW,&s); |
283 | while(TIMESPEC_A_LT_B(&s,&e)) { |
||
284 | memory_barrier; |
||
285 | ll_gettime(TIME_NEW,&s); |
||
286 | } |
||
287 | } |
||
464 | giacomo | 288 | } |
289 | |||
537 | giacomo | 290 | void * vmalloc_32(size_t size); |
291 | |||
1047 | mauro | 292 | void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int gfp) |
516 | giacomo | 293 | { |
1047 | mauro | 294 | void *ret; |
295 | /* ignore region specifiers */ |
||
296 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); |
||
297 | |||
298 | if (dev == NULL || (*dev->dma_mask < 0xffffffff)) |
||
299 | gfp |= GFP_DMA; |
||
300 | ret = (void *)vmalloc_32(size); |
||
301 | |||
302 | if (ret != NULL) { |
||
303 | memset(ret, 0, size); |
||
304 | *dma_handle = (dma_addr_t)ret; |
||
305 | } |
||
306 | return ret; |
||
516 | giacomo | 307 | } |
1047 | mauro | 308 | |
309 | void *dma_alloc_coherent_usb(struct device *dev, size_t size, dma_addr_t *dma_handle, int gfp) |
||
516 | giacomo | 310 | { |
1047 | mauro | 311 | void *ret; |
312 | /* ignore region specifiers */ |
||
313 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); |
||
314 | |||
315 | if (dev == NULL || (*dev->dma_mask < 0xffffffff)) |
||
316 | gfp |= GFP_DMA; |
||
317 | ret = (void *)vmalloc_32_usb(size); |
||
318 | |||
319 | if (ret != NULL) { |
||
320 | memset(ret, 0, size); |
||
321 | *dma_handle = (dma_addr_t)ret; |
||
322 | } |
||
323 | return ret; |
||
324 | } |
||
325 | |||
326 | void dma_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle) |
||
327 | { |
||
611 | giacomo | 328 | vfree((void *)dma_handle); |
516 | giacomo | 329 | } |
330 | |||
847 | giacomo | 331 | extern void __wake_up_common(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, int sync); |
332 | |||
516 | giacomo | 333 | void init_completion(struct completion *x) { |
847 | giacomo | 334 | x->done = 0; |
335 | init_waitqueue_head(&x->wait); |
||
516 | giacomo | 336 | } |
337 | |||
847 | giacomo | 338 | void complete(struct completion *x) |
339 | { |
||
340 | x->done++; |
||
341 | __wake_up_common(&x->wait, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1, 0); |
||
462 | giacomo | 342 | } |
343 | |||
1047 | mauro | 344 | void wait_for_completion(struct completion *x) |
345 | { |
||
847 | giacomo | 346 | spin_lock_irq(&x->wait.lock); |
347 | if (!x->done) { |
||
348 | DECLARE_WAITQUEUE(wait, current); |
||
349 | |||
350 | wait.flags |= WQ_FLAG_EXCLUSIVE; |
||
351 | __add_wait_queue_tail(&x->wait, &wait); |
||
352 | do { |
||
353 | __set_current_state(TASK_UNINTERRUPTIBLE); |
||
354 | spin_unlock_irq(&x->wait.lock); |
||
355 | schedule(); |
||
356 | spin_lock_irq(&x->wait.lock); |
||
357 | } while (!x->done); |
||
358 | __remove_wait_queue(&x->wait, &wait); |
||
359 | } |
||
360 | x->done--; |
||
361 | spin_unlock_irq(&x->wait.lock); |
||
462 | giacomo | 362 | } |
363 | |||
364 | struct device legacy_bus = { |
||
365 | .bus_id = "legacy", |
||
366 | }; |
||
367 | |||
1047 | mauro | 368 | int register_chrdev(unsigned int a, const char *b, struct file_operations *c) |
369 | { |
||
462 | giacomo | 370 | return 0; |
371 | } |
||
372 | |||
1047 | mauro | 373 | int unregister_chrdev(unsigned int a, const char *b) |
374 | { |
||
462 | giacomo | 375 | return 0; |
376 | } |
||
468 | giacomo | 377 | |
1047 | mauro | 378 | void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) |
379 | { |
||
380 | return (void *)offset; |
||
381 | } |
||
468 | giacomo | 382 | |
1047 | mauro | 383 | void iounmap(void *addr) |
384 | { |
||
468 | giacomo | 385 | |
386 | } |
||
387 | |||
1047 | mauro | 388 | loff_t no_llseek(struct file *file, loff_t offset, int origin) |
389 | { |
||
390 | return 0; |
||
391 | } |
||
468 | giacomo | 392 | |
1047 | mauro | 393 | void *vmalloc(unsigned long size) |
394 | { |
||
395 | return malloc(size); |
||
468 | giacomo | 396 | } |
397 | |||
1047 | mauro | 398 | void *kern_alloc_aligned(size_t size, DWORD flags, int align_bits, DWORD align_ofs); |
540 | giacomo | 399 | |
1047 | mauro | 400 | void * vmalloc_32(size_t size) |
401 | { |
||
402 | void *mem; |
||
403 | unsigned long diff; |
||
540 | giacomo | 404 | |
1047 | mauro | 405 | mem = malloc(size+12); |
540 | giacomo | 406 | |
1047 | mauro | 407 | diff = (unsigned long)((((unsigned long)mem/4)+1)*4-(unsigned long)mem); |
468 | giacomo | 408 | |
1047 | mauro | 409 | *(unsigned long *)(mem+diff) = (diff | 0x80000000); |
468 | giacomo | 410 | |
1047 | mauro | 411 | return (mem+diff+4); |
468 | giacomo | 412 | } |
413 | |||
1047 | mauro | 414 | void vfree(void *addr) |
537 | giacomo | 415 | { |
1047 | mauro | 416 | if (addr == NULL || *(unsigned long *)(addr-4) == 0) |
417 | return; |
||
418 | |||
419 | if ((*(unsigned long *)(addr-4) & 0x80000000) == 0x80000000) { |
||
420 | free(addr-(*(unsigned long *)(addr-4) & 0x7FFFFFFF)-4); |
||
421 | *(unsigned long *)(addr-4) = 0; |
||
422 | return; |
||
423 | } |
||
424 | |||
425 | free(addr); |
||
426 | |||
427 | return; |
||
537 | giacomo | 428 | } |
468 | giacomo | 429 | |
1047 | mauro | 430 | void * vmalloc_32_usb(size_t size) |
431 | { |
||
432 | void* mem; |
||
433 | unsigned long diff; |
||
468 | giacomo | 434 | |
1047 | mauro | 435 | mem = malloc( size + 2 * 4096 ); |
468 | giacomo | 436 | |
1047 | mauro | 437 | if (! mem) |
438 | return NULL; |
||
439 | |||
440 | diff = 4096 - (((unsigned long) mem) % 4096); |
||
441 | *(unsigned long *)(mem+diff) = (diff | 0x80000000); |
||
442 | |||
443 | return (void*)(mem + diff + 4096); |
||
468 | giacomo | 444 | } |
445 | |||
1047 | mauro | 446 | /* TODO */ |
447 | char * strsep(char **a,const char *b) |
||
448 | { |
||
449 | return NULL; |
||
450 | } |
||
451 | |||
468 | giacomo | 452 | struct screen_info screen_info; |
453 | |||
1047 | mauro | 454 | int linuxcomp_setfd(struct inode *i, int i_rdev) |
455 | { |
||
456 | i->i_rdev = i_rdev; |
||
469 | giacomo | 457 | |
1047 | mauro | 458 | return 0; |
459 | } |
||
469 | giacomo | 460 | |
1047 | mauro | 461 | int linuxcomp_init(void) |
462 | { |
||
469 | giacomo | 463 | return 0; |
464 | } |
||
465 | |||
1047 | mauro | 466 | struct page *mem_map = 0x0000; |
468 | giacomo | 467 | |
1047 | mauro | 468 | int schedule_work(struct work_struct *work) |
469 | { |
||
470 | return 0; |
||
471 | } |
||
468 | giacomo | 472 | |
1047 | mauro | 473 | int allow_signal(int sig) |
474 | { |
||
475 | return 0; |
||
468 | giacomo | 476 | } |
847 | giacomo | 477 | |
478 | void flush_scheduled_work(void) { } |
||
479 | void daemonize(const char *name, ...) { } |
||
480 | void yield(void) { } |
||
481 | |||
482 | void do_exit(long code) { } |
||
1047 | mauro | 483 | |
847 | giacomo | 484 | void complete_and_exit(struct completion *comp, long code) |
485 | { |
||
486 | if (comp) |
||
487 | complete(comp); |
||
488 | |||
489 | do_exit(code); |
||
490 | } |
||
491 | |||
492 | inline void * ioremap_nocache(unsigned long offset, unsigned long size) |
||
493 | { |
||
494 | return __ioremap(offset, size, 0); |
||
495 | } |
||
496 | |||
497 | #define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0) |
||
498 | |||
499 | int wait_ms26(unsigned long msec) |
||
500 | { |
||
501 | struct timespec t1, t2; |
||
502 | int nsec; |
||
503 | |||
504 | t1.tv_sec = msec/1000; |
||
505 | nsec = (msec % 1000) * 1000000; |
||
506 | t1.tv_nsec = nsec; |
||
507 | NULL_TIMESPEC(&t2); |
||
508 | nanosleep(&t1, &t2); |
||
509 | |||
510 | return 0; |
||
511 | } |