Rev 847 | Rev 1047 | 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 */ |
||
49 | |||
455 | giacomo | 50 | __kernel_size_t strnlen(const char *s, __kernel_size_t count) |
51 | { |
||
52 | const char *sc; |
||
53 | |||
54 | for (sc = s; count-- && *sc != '\0'; ++sc) |
||
55 | /* nothing */; |
||
56 | return sc - s; |
||
57 | } |
||
437 | giacomo | 58 | |
432 | giacomo | 59 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); |
60 | |||
436 | giacomo | 61 | struct resource ioport_resource = { |
62 | .name = "PCI IO", |
||
63 | .start = 0x0000, |
||
64 | .end = IO_SPACE_LIMIT, |
||
65 | .flags = IORESOURCE_IO, |
||
66 | }; |
||
67 | |||
68 | struct resource iomem_resource = { |
||
69 | .name = "PCI mem", |
||
70 | .start = 0UL, |
||
71 | .end = ~0UL, |
||
72 | .flags = IORESOURCE_MEM, |
||
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 | |||
207 | err = find_resource(root, new, size, min, max, align, alignf, alignf_data); |
||
208 | if (err >= 0 && __request_resource(root, new)) |
||
209 | err = -EBUSY; |
||
210 | |||
211 | return err; |
||
212 | } |
||
213 | |||
214 | int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot) |
||
215 | { return 0; } |
||
216 | |||
436 | giacomo | 217 | void dump_stack(void) { } |
218 | |||
219 | void panic(const char * fmt, ...) { |
||
220 | |||
221 | cprintf((char *)(fmt)); |
||
222 | |||
223 | } |
||
224 | |||
225 | extern void * malloc(size_t size); |
||
226 | |||
227 | void *__kmalloc(size_t size, int flags) { |
||
228 | |||
229 | return malloc(size); |
||
230 | |||
231 | } |
||
232 | |||
233 | extern void free(void *); |
||
234 | |||
235 | void kfree(const void *ptr) { |
||
236 | |||
237 | free((void *)(ptr)); |
||
238 | |||
239 | } |
||
240 | |||
241 | unsigned long pci_mem_start = 0x10000000; |
||
242 | |||
432 | giacomo | 243 | signed long schedule_timeout(signed long timeout) { |
244 | |||
500 | giacomo | 245 | struct timespec t,s,e; |
432 | giacomo | 246 | |
247 | jiffies_to_timespec(timeout, &t); |
||
500 | giacomo | 248 | |
249 | if (!activeInt && !intr_count) { |
||
250 | |||
251 | nanosleep(&t,NULL); |
||
252 | |||
253 | } else { |
||
254 | |||
255 | ll_gettime(TIME_NEW,&s); |
||
256 | ADDTIMESPEC(&t,&s,&e); |
||
537 | giacomo | 257 | |
258 | memory_barrier; |
||
259 | |||
260 | while(TIMESPEC_A_LT_B(&s,&e)) { |
||
261 | memory_barrier; |
||
262 | ll_gettime(TIME_NEW,&s); |
||
263 | } |
||
500 | giacomo | 264 | |
265 | } |
||
432 | giacomo | 266 | |
267 | return 0; |
||
268 | |||
269 | } |
||
436 | giacomo | 270 | |
271 | void __const_udelay(unsigned long usecs) { |
||
272 | |||
500 | giacomo | 273 | struct timespec t,s,e; |
274 | |||
275 | if (!activeInt && !intr_count) { |
||
436 | giacomo | 276 | |
500 | giacomo | 277 | t.tv_sec = 0; |
278 | t.tv_nsec = usecs * 1000; |
||
436 | giacomo | 279 | |
500 | giacomo | 280 | nanosleep(&t,NULL); |
436 | giacomo | 281 | |
500 | giacomo | 282 | } else { |
436 | giacomo | 283 | |
500 | giacomo | 284 | ll_gettime(TIME_NEW,&e); |
285 | ADDUSEC2TIMESPEC(usecs,&e); |
||
286 | |||
537 | giacomo | 287 | memory_barrier; |
288 | |||
500 | giacomo | 289 | ll_gettime(TIME_NEW,&s); |
537 | giacomo | 290 | while(TIMESPEC_A_LT_B(&s,&e)) { |
291 | memory_barrier; |
||
292 | ll_gettime(TIME_NEW,&s); |
||
293 | } |
||
500 | giacomo | 294 | |
295 | } |
||
296 | |||
464 | giacomo | 297 | } |
298 | |||
537 | giacomo | 299 | void * vmalloc_32(size_t size); |
300 | |||
516 | giacomo | 301 | void *dma_alloc_coherent(struct device *dev, size_t size, |
302 | dma_addr_t *dma_handle, int gfp) |
||
303 | { |
||
304 | void *ret; |
||
305 | /* ignore region specifiers */ |
||
306 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); |
||
307 | |||
308 | if (dev == NULL || (*dev->dma_mask < 0xffffffff)) |
||
309 | gfp |= GFP_DMA; |
||
537 | giacomo | 310 | ret = (void *)vmalloc_32(size); |
516 | giacomo | 311 | |
312 | if (ret != NULL) { |
||
313 | memset(ret, 0, size); |
||
314 | *dma_handle = (dma_addr_t)ret; |
||
315 | } |
||
316 | return ret; |
||
317 | } |
||
318 | |||
319 | void dma_free_coherent(struct device *dev, size_t size, |
||
320 | void *vaddr, dma_addr_t dma_handle) |
||
321 | { |
||
611 | giacomo | 322 | vfree((void *)dma_handle); |
516 | giacomo | 323 | } |
324 | |||
847 | giacomo | 325 | extern void __wake_up_common(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, int sync); |
326 | |||
516 | giacomo | 327 | void init_completion(struct completion *x) { |
847 | giacomo | 328 | x->done = 0; |
329 | init_waitqueue_head(&x->wait); |
||
516 | giacomo | 330 | } |
331 | |||
847 | giacomo | 332 | void complete(struct completion *x) |
333 | { |
||
334 | x->done++; |
||
335 | __wake_up_common(&x->wait, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1, 0); |
||
462 | giacomo | 336 | } |
337 | |||
847 | giacomo | 338 | void wait_for_completion(struct completion *x) { |
339 | spin_lock_irq(&x->wait.lock); |
||
340 | if (!x->done) { |
||
341 | DECLARE_WAITQUEUE(wait, current); |
||
342 | |||
343 | wait.flags |= WQ_FLAG_EXCLUSIVE; |
||
344 | __add_wait_queue_tail(&x->wait, &wait); |
||
345 | do { |
||
346 | __set_current_state(TASK_UNINTERRUPTIBLE); |
||
347 | spin_unlock_irq(&x->wait.lock); |
||
348 | schedule(); |
||
349 | spin_lock_irq(&x->wait.lock); |
||
350 | } while (!x->done); |
||
351 | __remove_wait_queue(&x->wait, &wait); |
||
352 | } |
||
353 | x->done--; |
||
354 | spin_unlock_irq(&x->wait.lock); |
||
462 | giacomo | 355 | } |
356 | |||
357 | struct device legacy_bus = { |
||
358 | .bus_id = "legacy", |
||
359 | }; |
||
360 | |||
361 | int register_chrdev(unsigned int a, const char *b, struct file_operations *c) { |
||
362 | return 0; |
||
363 | } |
||
364 | |||
365 | int unregister_chrdev(unsigned int a, const char *b) { |
||
366 | return 0; |
||
367 | } |
||
468 | giacomo | 368 | |
369 | void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) { |
||
370 | |||
371 | return (void *)offset; |
||
372 | |||
373 | } |
||
374 | |||
375 | void iounmap(void *addr) { |
||
376 | |||
377 | } |
||
378 | |||
540 | giacomo | 379 | loff_t no_llseek(struct file *file, loff_t offset, int origin) { |
380 | |||
381 | return 0; |
||
382 | |||
383 | } |
||
384 | |||
468 | giacomo | 385 | void *vmalloc(unsigned long size) { |
386 | |||
387 | return malloc(size); |
||
388 | |||
389 | } |
||
390 | |||
537 | giacomo | 391 | void * vmalloc_32(size_t size) |
392 | { |
||
393 | void *mem; |
||
856 | giacomo | 394 | unsigned long diff; |
537 | giacomo | 395 | |
856 | giacomo | 396 | mem = malloc(size+12); |
397 | |||
398 | diff = (unsigned long)((((unsigned long)mem/4)+1)*4-(unsigned long)mem); |
||
399 | |||
400 | *(unsigned long *)(mem+diff) = (diff | 0x80000000); |
||
401 | |||
402 | return (mem+diff+4); |
||
403 | |||
537 | giacomo | 404 | } |
856 | giacomo | 405 | |
468 | giacomo | 406 | void vfree(void *addr) { |
856 | giacomo | 407 | |
408 | if (addr == NULL || *(unsigned long *)(addr-4) == 0) return; |
||
409 | |||
410 | if ((*(unsigned long *)(addr-4) & 0x80000000) == 0x80000000) { |
||
411 | free(addr-(*(unsigned long *)(addr-4) & 0x7FFFFFFF)-4); |
||
412 | *(unsigned long *)(addr-4) = 0; |
||
413 | return; |
||
414 | } |
||
415 | |||
416 | free(addr); |
||
417 | |||
418 | return; |
||
419 | |||
468 | giacomo | 420 | } |
421 | |||
422 | /* TODO */ |
||
423 | char * strsep(char **a,const char *b) { |
||
424 | |||
425 | return NULL; |
||
426 | |||
427 | } |
||
428 | |||
429 | struct screen_info screen_info; |
||
430 | |||
469 | giacomo | 431 | int linuxcomp_setfd(struct inode *i, int i_rdev) { |
432 | |||
433 | i->i_rdev = i_rdev; |
||
434 | |||
435 | return 0; |
||
436 | |||
437 | } |
||
438 | |||
468 | giacomo | 439 | int linuxcomp_init(void) { |
440 | |||
441 | return 0; |
||
442 | |||
443 | } |
||
847 | giacomo | 444 | |
445 | struct page *mem_map = 0x0000; |
||
446 | |||
447 | int schedule_work(struct work_struct *work) { return 0;} |
||
448 | void flush_scheduled_work(void) { } |
||
449 | void daemonize(const char *name, ...) { } |
||
450 | int allow_signal(int sig) {return 0; } |
||
451 | void yield(void) { } |
||
452 | |||
453 | void do_exit(long code) { } |
||
454 | void complete_and_exit(struct completion *comp, long code) |
||
455 | { |
||
456 | if (comp) |
||
457 | complete(comp); |
||
458 | |||
459 | do_exit(code); |
||
460 | } |
||
461 | |||
462 | inline void * ioremap_nocache(unsigned long offset, unsigned long size) |
||
463 | { |
||
464 | return __ioremap(offset, size, 0); |
||
465 | } |
||
466 | |||
467 | |||
468 | #define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0) |
||
469 | |||
470 | int wait_ms26(unsigned long msec) |
||
471 | { |
||
472 | struct timespec t1, t2; |
||
473 | int nsec; |
||
474 | |||
475 | t1.tv_sec = msec/1000; |
||
476 | nsec = (msec % 1000) * 1000000; |
||
477 | t1.tv_nsec = nsec; |
||
478 | NULL_TIMESPEC(&t2); |
||
479 | nanosleep(&t1, &t2); |
||
480 | |||
481 | return 0; |
||
482 | } |
||
483 |