Rev 612 | Rev 615 | 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 | |||
325 | void init_completion(struct completion *x) { |
||
326 | } |
||
327 | |||
462 | giacomo | 328 | void complete(struct completion *c) { |
329 | } |
||
330 | |||
331 | void wait_for_completion(struct completion *c) { |
||
332 | } |
||
333 | |||
334 | struct device legacy_bus = { |
||
335 | .bus_id = "legacy", |
||
336 | }; |
||
337 | |||
338 | int register_chrdev(unsigned int a, const char *b, struct file_operations *c) { |
||
339 | return 0; |
||
340 | } |
||
341 | |||
342 | int unregister_chrdev(unsigned int a, const char *b) { |
||
343 | return 0; |
||
344 | } |
||
468 | giacomo | 345 | |
346 | void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) { |
||
347 | |||
348 | return (void *)offset; |
||
349 | |||
350 | } |
||
351 | |||
352 | void iounmap(void *addr) { |
||
353 | |||
354 | } |
||
355 | |||
540 | giacomo | 356 | loff_t no_llseek(struct file *file, loff_t offset, int origin) { |
357 | |||
358 | return 0; |
||
359 | |||
360 | } |
||
361 | |||
468 | giacomo | 362 | void *vmalloc(unsigned long size) { |
363 | |||
364 | return malloc(size); |
||
365 | |||
366 | } |
||
367 | |||
537 | giacomo | 368 | void * vmalloc_32(size_t size) |
369 | { |
||
370 | void *mem; |
||
371 | unsigned long diff; |
||
372 | |||
610 | giacomo | 373 | mem = malloc(size+12); |
537 | giacomo | 374 | |
375 | diff = (unsigned long)((((unsigned long)mem/4)+1)*4-(unsigned long)mem); |
||
376 | |||
613 | giacomo | 377 | *(unsigned long *)(mem+diff) = diff; |
537 | giacomo | 378 | |
613 | giacomo | 379 | return ((void *)((unsigned long)(mem+diff+4) | 0x80000000)); |
537 | giacomo | 380 | |
381 | } |
||
382 | |||
468 | giacomo | 383 | void vfree(void *addr) { |
384 | |||
613 | giacomo | 385 | if (addr == NULL) return; |
468 | giacomo | 386 | |
613 | giacomo | 387 | if (((unsigned long)(addr) & 0x80000000) == 0x80000000) { |
388 | free(addr-*(unsigned long *)(addr-4)-4); |
||
389 | return; |
||
390 | } |
||
391 | |||
392 | free(addr); |
||
393 | |||
611 | giacomo | 394 | return; |
395 | |||
468 | giacomo | 396 | } |
397 | |||
398 | /* TODO */ |
||
399 | char * strsep(char **a,const char *b) { |
||
400 | |||
401 | return NULL; |
||
402 | |||
403 | } |
||
404 | |||
405 | struct screen_info screen_info; |
||
406 | |||
469 | giacomo | 407 | int linuxcomp_setfd(struct inode *i, int i_rdev) { |
408 | |||
409 | i->i_rdev = i_rdev; |
||
410 | |||
411 | return 0; |
||
412 | |||
413 | } |
||
414 | |||
468 | giacomo | 415 | int linuxcomp_init(void) { |
416 | |||
417 | return 0; |
||
418 | |||
419 | } |