Rev 469 | Rev 475 | 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> |
432 | giacomo | 4 | |
5 | #include <linuxcomp.h> |
||
6 | |||
7 | #include <linux/time.h> |
||
8 | #include <linux/sched.h> |
||
436 | giacomo | 9 | #include <linux/ioport.h> |
437 | giacomo | 10 | #include <linux/errno.h> |
436 | giacomo | 11 | #include <asm/io.h> |
437 | giacomo | 12 | #include <linux/ctype.h> |
13 | #include <linux/device.h> |
||
462 | giacomo | 14 | #include <linux/completion.h> |
468 | giacomo | 15 | #include <linux/tty.h> |
16 | #include <asm/setup.h> |
||
432 | giacomo | 17 | |
437 | giacomo | 18 | unsigned char _ctype[] = { |
19 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ |
||
20 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ |
||
21 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ |
||
22 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ |
||
23 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ |
||
24 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ |
||
25 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ |
||
26 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ |
||
27 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ |
||
28 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ |
||
29 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ |
||
30 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ |
||
31 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ |
||
32 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ |
||
33 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ |
||
34 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ |
||
35 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ |
||
36 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ |
||
37 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ |
||
38 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ |
||
39 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ |
||
40 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ |
||
41 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ |
||
42 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ |
||
43 | |||
455 | giacomo | 44 | __kernel_size_t strnlen(const char *s, __kernel_size_t count) |
45 | { |
||
46 | const char *sc; |
||
47 | |||
48 | for (sc = s; count-- && *sc != '\0'; ++sc) |
||
49 | /* nothing */; |
||
50 | return sc - s; |
||
51 | } |
||
437 | giacomo | 52 | |
432 | giacomo | 53 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); |
54 | |||
436 | giacomo | 55 | struct resource ioport_resource = { |
56 | .name = "PCI IO", |
||
57 | .start = 0x0000, |
||
58 | .end = IO_SPACE_LIMIT, |
||
59 | .flags = IORESOURCE_IO, |
||
60 | }; |
||
61 | |||
62 | struct resource iomem_resource = { |
||
63 | .name = "PCI mem", |
||
64 | .start = 0UL, |
||
65 | .end = ~0UL, |
||
66 | .flags = IORESOURCE_MEM, |
||
67 | }; |
||
68 | |||
437 | giacomo | 69 | /* Return the conflict entry if you can't request it */ |
70 | static struct resource * __request_resource(struct resource *root, struct resource *new) |
||
71 | { |
||
72 | unsigned long start = new->start; |
||
73 | unsigned long end = new->end; |
||
74 | struct resource *tmp, **p; |
||
436 | giacomo | 75 | |
437 | giacomo | 76 | if (end < start) |
77 | return root; |
||
78 | if (start < root->start) |
||
79 | return root; |
||
80 | if (end > root->end) |
||
81 | return root; |
||
82 | p = &root->child; |
||
83 | for (;;) { |
||
84 | tmp = *p; |
||
85 | if (!tmp || tmp->start > end) { |
||
86 | new->sibling = tmp; |
||
87 | *p = new; |
||
88 | new->parent = root; |
||
89 | return NULL; |
||
90 | } |
||
91 | p = &tmp->sibling; |
||
92 | if (tmp->end < start) |
||
93 | continue; |
||
94 | return tmp; |
||
95 | } |
||
436 | giacomo | 96 | } |
97 | |||
437 | giacomo | 98 | static int __release_resource(struct resource *old) |
99 | { |
||
100 | struct resource *tmp, **p; |
||
101 | |||
102 | p = &old->parent->child; |
||
103 | for (;;) { |
||
104 | tmp = *p; |
||
105 | if (!tmp) |
||
106 | break; |
||
107 | if (tmp == old) { |
||
108 | *p = tmp->sibling; |
||
109 | old->parent = NULL; |
||
110 | return 0; |
||
111 | } |
||
112 | p = &tmp->sibling; |
||
113 | } |
||
114 | return -EINVAL; |
||
115 | } |
||
116 | |||
117 | int release_resource(struct resource *old) |
||
118 | { |
||
119 | int retval; |
||
120 | |||
121 | retval = __release_resource(old); |
||
122 | |||
123 | return retval; |
||
124 | } |
||
125 | |||
126 | int request_resource(struct resource *root, struct resource *new) |
||
127 | { |
||
128 | struct resource *conflict; |
||
129 | |||
130 | conflict = __request_resource(root, new); |
||
131 | |||
132 | return conflict ? -EBUSY : 0; |
||
133 | } |
||
134 | |||
135 | |||
136 | |||
137 | struct resource * __request_region(struct resource *parent, unsigned long start, unsigned long n, const char *name) |
||
138 | { |
||
139 | struct resource *res = kmalloc(sizeof(*res), GFP_KERNEL); |
||
140 | |||
141 | if (res) { |
||
142 | memset(res, 0, sizeof(*res)); |
||
143 | res->name = name; |
||
144 | res->start = start; |
||
145 | res->end = start + n - 1; |
||
146 | res->flags = IORESOURCE_BUSY; |
||
147 | |||
148 | for (;;) { |
||
149 | struct resource *conflict; |
||
150 | |||
151 | conflict = __request_resource(parent, res); |
||
152 | if (!conflict) |
||
153 | break; |
||
154 | if (conflict != parent) { |
||
155 | parent = conflict; |
||
156 | if (!(conflict->flags & IORESOURCE_BUSY)) |
||
157 | continue; |
||
158 | } |
||
159 | |||
160 | /* Uhhuh, that didn't work out.. */ |
||
161 | kfree(res); |
||
162 | res = NULL; |
||
163 | break; |
||
164 | } |
||
165 | } |
||
166 | return res; |
||
167 | } |
||
168 | |||
169 | void __release_region(struct resource *parent, unsigned long start, unsigned long n) |
||
170 | { |
||
171 | struct resource **p; |
||
172 | unsigned long end; |
||
173 | |||
174 | p = &parent->child; |
||
175 | end = start + n - 1; |
||
176 | |||
177 | for (;;) { |
||
178 | struct resource *res = *p; |
||
179 | |||
180 | if (!res) |
||
181 | break; |
||
182 | if (res->start <= start && res->end >= end) { |
||
183 | if (!(res->flags & IORESOURCE_BUSY)) { |
||
184 | p = &res->child; |
||
185 | continue; |
||
186 | } |
||
187 | if (res->start != start || res->end != end) |
||
188 | break; |
||
189 | *p = res->sibling; |
||
190 | kfree(res); |
||
191 | return; |
||
192 | } |
||
193 | p = &res->sibling; |
||
194 | } |
||
195 | printk(KERN_WARNING "Trying to free nonexistent resource <%08lx-%08lx>\n", start, end); |
||
196 | } |
||
197 | |||
198 | static int find_resource(struct resource *root, struct resource *new, |
||
199 | unsigned long size, |
||
200 | unsigned long min, unsigned long max, |
||
201 | unsigned long align, |
||
202 | void (*alignf)(void *, struct resource *, |
||
203 | unsigned long, unsigned long), |
||
204 | void *alignf_data) |
||
205 | { |
||
206 | struct resource *this = root->child; |
||
207 | |||
208 | new->start = root->start; |
||
209 | /* |
||
210 | * Skip past an allocated resource that starts at 0, since the assignment |
||
211 | * of this->start - 1 to new->end below would cause an underflow. |
||
212 | */ |
||
213 | if (this && this->start == 0) { |
||
214 | new->start = this->end + 1; |
||
215 | this = this->sibling; |
||
216 | } |
||
217 | for(;;) { |
||
218 | if (this) |
||
219 | new->end = this->start - 1; |
||
220 | else |
||
221 | new->end = root->end; |
||
222 | if (new->start < min) |
||
223 | new->start = min; |
||
224 | if (new->end > max) |
||
225 | new->end = max; |
||
226 | new->start = (new->start + align - 1) & ~(align - 1); |
||
227 | if (alignf) |
||
228 | alignf(alignf_data, new, size, align); |
||
229 | if (new->start < new->end && new->end - new->start + 1 >= size) { |
||
230 | new->end = new->start + size - 1; |
||
231 | return 0; |
||
232 | } |
||
233 | if (!this) |
||
234 | break; |
||
235 | new->start = this->end + 1; |
||
236 | this = this->sibling; |
||
237 | } |
||
238 | return -EBUSY; |
||
239 | } |
||
240 | |||
241 | int allocate_resource(struct resource *root, struct resource *new, |
||
242 | unsigned long size, |
||
243 | unsigned long min, unsigned long max, |
||
244 | unsigned long align, |
||
245 | void (*alignf)(void *, struct resource *, |
||
246 | unsigned long, unsigned long), |
||
247 | void *alignf_data) |
||
248 | { |
||
249 | int err; |
||
250 | |||
251 | |||
252 | err = find_resource(root, new, size, min, max, align, alignf, alignf_data); |
||
253 | if (err >= 0 && __request_resource(root, new)) |
||
254 | err = -EBUSY; |
||
255 | |||
256 | return err; |
||
257 | } |
||
258 | |||
259 | int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot) |
||
260 | { return 0; } |
||
261 | |||
436 | giacomo | 262 | void dump_stack(void) { } |
263 | |||
264 | void panic(const char * fmt, ...) { |
||
265 | |||
266 | cprintf((char *)(fmt)); |
||
267 | |||
268 | } |
||
269 | |||
270 | extern void * malloc(size_t size); |
||
271 | |||
272 | void *__kmalloc(size_t size, int flags) { |
||
273 | |||
274 | return malloc(size); |
||
275 | |||
276 | } |
||
277 | |||
278 | extern void free(void *); |
||
279 | |||
280 | void kfree(const void *ptr) { |
||
281 | |||
282 | free((void *)(ptr)); |
||
283 | |||
284 | } |
||
285 | |||
286 | unsigned long pci_mem_start = 0x10000000; |
||
287 | |||
432 | giacomo | 288 | signed long schedule_timeout(signed long timeout) { |
289 | |||
290 | SYS_FLAGS f; |
||
291 | struct timespec t; |
||
292 | |||
293 | f = ll_fsave(); |
||
294 | sti(); |
||
295 | |||
296 | jiffies_to_timespec(timeout, &t); |
||
297 | |||
298 | nanosleep(&t,NULL); |
||
299 | |||
300 | ll_frestore(f); |
||
301 | |||
302 | return 0; |
||
303 | |||
304 | } |
||
436 | giacomo | 305 | |
306 | void __const_udelay(unsigned long usecs) { |
||
307 | |||
308 | SYS_FLAGS f; |
||
309 | struct timespec t; |
||
310 | |||
311 | f = ll_fsave(); |
||
312 | sti(); |
||
313 | |||
314 | t.tv_sec = 0; |
||
315 | t.tv_nsec = usecs * 1000; |
||
316 | |||
317 | nanosleep(&t,NULL); |
||
318 | |||
319 | ll_frestore(f); |
||
320 | |||
321 | } |
||
322 | |||
464 | giacomo | 323 | void __udelay(unsigned long usecs) { |
324 | |||
325 | SYS_FLAGS f; |
||
326 | struct timespec t; |
||
327 | |||
328 | f = ll_fsave(); |
||
329 | sti(); |
||
330 | |||
331 | t.tv_sec = 0; |
||
332 | t.tv_nsec = usecs * 1000; |
||
333 | |||
334 | nanosleep(&t,NULL); |
||
335 | |||
336 | ll_frestore(f); |
||
337 | |||
338 | } |
||
339 | |||
462 | giacomo | 340 | unsigned long __copy_to_user_ll(void __user *to, const void *from, unsigned long n) { |
341 | |||
342 | memcpy(to,from,n); |
||
473 | giacomo | 343 | return 0; |
462 | giacomo | 344 | |
345 | } |
||
346 | |||
347 | unsigned long __copy_from_user_ll(void *to, const void __user *from, unsigned long n) { |
||
348 | |||
349 | memcpy(to,from,n); |
||
473 | giacomo | 350 | return 0; |
462 | giacomo | 351 | |
352 | } |
||
353 | |||
354 | void complete(struct completion *c) { |
||
355 | } |
||
356 | |||
357 | void wait_for_completion(struct completion *c) { |
||
358 | } |
||
359 | |||
360 | struct device legacy_bus = { |
||
361 | .bus_id = "legacy", |
||
362 | }; |
||
363 | |||
364 | int register_chrdev(unsigned int a, const char *b, struct file_operations *c) { |
||
365 | return 0; |
||
366 | } |
||
367 | |||
368 | int unregister_chrdev(unsigned int a, const char *b) { |
||
369 | return 0; |
||
370 | } |
||
468 | giacomo | 371 | |
372 | void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) { |
||
373 | |||
374 | return (void *)offset; |
||
375 | |||
376 | } |
||
377 | |||
378 | void iounmap(void *addr) { |
||
379 | |||
380 | } |
||
381 | |||
382 | void *vmalloc(unsigned long size) { |
||
383 | |||
384 | return malloc(size); |
||
385 | |||
386 | } |
||
387 | |||
388 | void vfree(void *addr) { |
||
389 | |||
390 | return free(addr); |
||
391 | |||
392 | } |
||
393 | |||
394 | /* TODO */ |
||
395 | char * strsep(char **a,const char *b) { |
||
396 | |||
397 | return NULL; |
||
398 | |||
399 | } |
||
400 | |||
401 | struct screen_info screen_info; |
||
402 | |||
469 | giacomo | 403 | int linuxcomp_setfd(struct inode *i, int i_rdev) { |
404 | |||
405 | i->i_rdev = i_rdev; |
||
406 | |||
407 | return 0; |
||
408 | |||
409 | } |
||
410 | |||
468 | giacomo | 411 | int linuxcomp_init(void) { |
412 | |||
413 | return 0; |
||
414 | |||
415 | } |