Rev 537 | Rev 609 | 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 | void vfree_32(void *ptr); |
||
301 | |||
516 | giacomo | 302 | void *dma_alloc_coherent(struct device *dev, size_t size, |
303 | dma_addr_t *dma_handle, int gfp) |
||
304 | { |
||
305 | void *ret; |
||
306 | /* ignore region specifiers */ |
||
307 | gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); |
||
308 | |||
309 | if (dev == NULL || (*dev->dma_mask < 0xffffffff)) |
||
310 | gfp |= GFP_DMA; |
||
537 | giacomo | 311 | ret = (void *)vmalloc_32(size); |
516 | giacomo | 312 | |
313 | if (ret != NULL) { |
||
314 | memset(ret, 0, size); |
||
315 | *dma_handle = (dma_addr_t)ret; |
||
316 | } |
||
317 | return ret; |
||
318 | } |
||
319 | |||
320 | void dma_free_coherent(struct device *dev, size_t size, |
||
321 | void *vaddr, dma_addr_t dma_handle) |
||
322 | { |
||
537 | giacomo | 323 | vfree_32((void *)dma_handle); |
516 | giacomo | 324 | } |
325 | |||
326 | void init_completion(struct completion *x) { |
||
327 | } |
||
328 | |||
462 | giacomo | 329 | void complete(struct completion *c) { |
330 | } |
||
331 | |||
332 | void wait_for_completion(struct completion *c) { |
||
333 | } |
||
334 | |||
335 | struct device legacy_bus = { |
||
336 | .bus_id = "legacy", |
||
337 | }; |
||
338 | |||
339 | int register_chrdev(unsigned int a, const char *b, struct file_operations *c) { |
||
340 | return 0; |
||
341 | } |
||
342 | |||
343 | int unregister_chrdev(unsigned int a, const char *b) { |
||
344 | return 0; |
||
345 | } |
||
468 | giacomo | 346 | |
347 | void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) { |
||
348 | |||
349 | return (void *)offset; |
||
350 | |||
351 | } |
||
352 | |||
353 | void iounmap(void *addr) { |
||
354 | |||
355 | } |
||
356 | |||
540 | giacomo | 357 | loff_t no_llseek(struct file *file, loff_t offset, int origin) { |
358 | |||
359 | return 0; |
||
360 | |||
361 | } |
||
362 | |||
468 | giacomo | 363 | void *vmalloc(unsigned long size) { |
364 | |||
365 | return malloc(size); |
||
366 | |||
367 | } |
||
368 | |||
537 | giacomo | 369 | void * vmalloc_32(size_t size) |
370 | { |
||
371 | void *mem; |
||
372 | unsigned long diff; |
||
373 | |||
374 | mem = malloc(size+8); |
||
375 | |||
376 | diff = (unsigned long)((((unsigned long)mem/4)+1)*4-(unsigned long)mem); |
||
377 | |||
378 | *(unsigned long *)(mem+diff) = (unsigned long)diff; |
||
379 | |||
380 | return (mem+diff+4); |
||
381 | |||
382 | } |
||
383 | |||
384 | void vfree_32(void *ptr) |
||
385 | { |
||
386 | |||
387 | free(ptr-4-*(unsigned long *)(ptr-4)); |
||
388 | |||
389 | } |
||
390 | |||
468 | giacomo | 391 | void vfree(void *addr) { |
392 | |||
393 | return free(addr); |
||
394 | |||
395 | } |
||
396 | |||
397 | /* TODO */ |
||
398 | char * strsep(char **a,const char *b) { |
||
399 | |||
400 | return NULL; |
||
401 | |||
402 | } |
||
403 | |||
404 | struct screen_info screen_info; |
||
405 | |||
469 | giacomo | 406 | int linuxcomp_setfd(struct inode *i, int i_rdev) { |
407 | |||
408 | i->i_rdev = i_rdev; |
||
409 | |||
410 | return 0; |
||
411 | |||
412 | } |
||
413 | |||
468 | giacomo | 414 | int linuxcomp_init(void) { |
415 | |||
416 | return 0; |
||
417 | |||
418 | } |