Rev 437 | Rev 462 | 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> |
||
432 | giacomo | 14 | |
437 | giacomo | 15 | unsigned char _ctype[] = { |
16 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ |
||
17 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ |
||
18 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ |
||
19 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ |
||
20 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ |
||
21 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ |
||
22 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ |
||
23 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ |
||
24 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ |
||
25 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ |
||
26 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ |
||
27 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ |
||
28 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ |
||
29 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ |
||
30 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ |
||
31 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ |
||
32 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ |
||
33 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ |
||
34 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ |
||
35 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ |
||
36 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ |
||
37 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ |
||
38 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ |
||
39 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ |
||
40 | |||
455 | giacomo | 41 | __kernel_size_t strnlen(const char *s, __kernel_size_t count) |
42 | { |
||
43 | const char *sc; |
||
44 | |||
45 | for (sc = s; count-- && *sc != '\0'; ++sc) |
||
46 | /* nothing */; |
||
47 | return sc - s; |
||
48 | } |
||
437 | giacomo | 49 | |
432 | giacomo | 50 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); |
51 | |||
436 | giacomo | 52 | struct resource ioport_resource = { |
53 | .name = "PCI IO", |
||
54 | .start = 0x0000, |
||
55 | .end = IO_SPACE_LIMIT, |
||
56 | .flags = IORESOURCE_IO, |
||
57 | }; |
||
58 | |||
59 | struct resource iomem_resource = { |
||
60 | .name = "PCI mem", |
||
61 | .start = 0UL, |
||
62 | .end = ~0UL, |
||
63 | .flags = IORESOURCE_MEM, |
||
64 | }; |
||
65 | |||
437 | giacomo | 66 | /* Return the conflict entry if you can't request it */ |
67 | static struct resource * __request_resource(struct resource *root, struct resource *new) |
||
68 | { |
||
69 | unsigned long start = new->start; |
||
70 | unsigned long end = new->end; |
||
71 | struct resource *tmp, **p; |
||
436 | giacomo | 72 | |
437 | giacomo | 73 | if (end < start) |
74 | return root; |
||
75 | if (start < root->start) |
||
76 | return root; |
||
77 | if (end > root->end) |
||
78 | return root; |
||
79 | p = &root->child; |
||
80 | for (;;) { |
||
81 | tmp = *p; |
||
82 | if (!tmp || tmp->start > end) { |
||
83 | new->sibling = tmp; |
||
84 | *p = new; |
||
85 | new->parent = root; |
||
86 | return NULL; |
||
87 | } |
||
88 | p = &tmp->sibling; |
||
89 | if (tmp->end < start) |
||
90 | continue; |
||
91 | return tmp; |
||
92 | } |
||
436 | giacomo | 93 | } |
94 | |||
437 | giacomo | 95 | static int __release_resource(struct resource *old) |
96 | { |
||
97 | struct resource *tmp, **p; |
||
98 | |||
99 | p = &old->parent->child; |
||
100 | for (;;) { |
||
101 | tmp = *p; |
||
102 | if (!tmp) |
||
103 | break; |
||
104 | if (tmp == old) { |
||
105 | *p = tmp->sibling; |
||
106 | old->parent = NULL; |
||
107 | return 0; |
||
108 | } |
||
109 | p = &tmp->sibling; |
||
110 | } |
||
111 | return -EINVAL; |
||
112 | } |
||
113 | |||
114 | int release_resource(struct resource *old) |
||
115 | { |
||
116 | int retval; |
||
117 | |||
118 | retval = __release_resource(old); |
||
119 | |||
120 | return retval; |
||
121 | } |
||
122 | |||
123 | int request_resource(struct resource *root, struct resource *new) |
||
124 | { |
||
125 | struct resource *conflict; |
||
126 | |||
127 | conflict = __request_resource(root, new); |
||
128 | |||
129 | return conflict ? -EBUSY : 0; |
||
130 | } |
||
131 | |||
132 | |||
133 | |||
134 | struct resource * __request_region(struct resource *parent, unsigned long start, unsigned long n, const char *name) |
||
135 | { |
||
136 | struct resource *res = kmalloc(sizeof(*res), GFP_KERNEL); |
||
137 | |||
138 | if (res) { |
||
139 | memset(res, 0, sizeof(*res)); |
||
140 | res->name = name; |
||
141 | res->start = start; |
||
142 | res->end = start + n - 1; |
||
143 | res->flags = IORESOURCE_BUSY; |
||
144 | |||
145 | for (;;) { |
||
146 | struct resource *conflict; |
||
147 | |||
148 | conflict = __request_resource(parent, res); |
||
149 | if (!conflict) |
||
150 | break; |
||
151 | if (conflict != parent) { |
||
152 | parent = conflict; |
||
153 | if (!(conflict->flags & IORESOURCE_BUSY)) |
||
154 | continue; |
||
155 | } |
||
156 | |||
157 | /* Uhhuh, that didn't work out.. */ |
||
158 | kfree(res); |
||
159 | res = NULL; |
||
160 | break; |
||
161 | } |
||
162 | } |
||
163 | return res; |
||
164 | } |
||
165 | |||
166 | void __release_region(struct resource *parent, unsigned long start, unsigned long n) |
||
167 | { |
||
168 | struct resource **p; |
||
169 | unsigned long end; |
||
170 | |||
171 | p = &parent->child; |
||
172 | end = start + n - 1; |
||
173 | |||
174 | for (;;) { |
||
175 | struct resource *res = *p; |
||
176 | |||
177 | if (!res) |
||
178 | break; |
||
179 | if (res->start <= start && res->end >= end) { |
||
180 | if (!(res->flags & IORESOURCE_BUSY)) { |
||
181 | p = &res->child; |
||
182 | continue; |
||
183 | } |
||
184 | if (res->start != start || res->end != end) |
||
185 | break; |
||
186 | *p = res->sibling; |
||
187 | kfree(res); |
||
188 | return; |
||
189 | } |
||
190 | p = &res->sibling; |
||
191 | } |
||
192 | printk(KERN_WARNING "Trying to free nonexistent resource <%08lx-%08lx>\n", start, end); |
||
193 | } |
||
194 | |||
195 | static int find_resource(struct resource *root, struct resource *new, |
||
196 | unsigned long size, |
||
197 | unsigned long min, unsigned long max, |
||
198 | unsigned long align, |
||
199 | void (*alignf)(void *, struct resource *, |
||
200 | unsigned long, unsigned long), |
||
201 | void *alignf_data) |
||
202 | { |
||
203 | struct resource *this = root->child; |
||
204 | |||
205 | new->start = root->start; |
||
206 | /* |
||
207 | * Skip past an allocated resource that starts at 0, since the assignment |
||
208 | * of this->start - 1 to new->end below would cause an underflow. |
||
209 | */ |
||
210 | if (this && this->start == 0) { |
||
211 | new->start = this->end + 1; |
||
212 | this = this->sibling; |
||
213 | } |
||
214 | for(;;) { |
||
215 | if (this) |
||
216 | new->end = this->start - 1; |
||
217 | else |
||
218 | new->end = root->end; |
||
219 | if (new->start < min) |
||
220 | new->start = min; |
||
221 | if (new->end > max) |
||
222 | new->end = max; |
||
223 | new->start = (new->start + align - 1) & ~(align - 1); |
||
224 | if (alignf) |
||
225 | alignf(alignf_data, new, size, align); |
||
226 | if (new->start < new->end && new->end - new->start + 1 >= size) { |
||
227 | new->end = new->start + size - 1; |
||
228 | return 0; |
||
229 | } |
||
230 | if (!this) |
||
231 | break; |
||
232 | new->start = this->end + 1; |
||
233 | this = this->sibling; |
||
234 | } |
||
235 | return -EBUSY; |
||
236 | } |
||
237 | |||
238 | int allocate_resource(struct resource *root, struct resource *new, |
||
239 | unsigned long size, |
||
240 | unsigned long min, unsigned long max, |
||
241 | unsigned long align, |
||
242 | void (*alignf)(void *, struct resource *, |
||
243 | unsigned long, unsigned long), |
||
244 | void *alignf_data) |
||
245 | { |
||
246 | int err; |
||
247 | |||
248 | |||
249 | err = find_resource(root, new, size, min, max, align, alignf, alignf_data); |
||
250 | if (err >= 0 && __request_resource(root, new)) |
||
251 | err = -EBUSY; |
||
252 | |||
253 | return err; |
||
254 | } |
||
255 | |||
256 | int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot) |
||
257 | { return 0; } |
||
258 | |||
436 | giacomo | 259 | void dump_stack(void) { } |
260 | |||
261 | void panic(const char * fmt, ...) { |
||
262 | |||
263 | cprintf((char *)(fmt)); |
||
264 | |||
265 | } |
||
266 | |||
267 | extern void * malloc(size_t size); |
||
268 | |||
269 | void *__kmalloc(size_t size, int flags) { |
||
270 | |||
271 | return malloc(size); |
||
272 | |||
273 | } |
||
274 | |||
275 | extern void free(void *); |
||
276 | |||
277 | void kfree(const void *ptr) { |
||
278 | |||
279 | free((void *)(ptr)); |
||
280 | |||
281 | } |
||
282 | |||
283 | unsigned long pci_mem_start = 0x10000000; |
||
284 | |||
432 | giacomo | 285 | signed long schedule_timeout(signed long timeout) { |
286 | |||
287 | SYS_FLAGS f; |
||
288 | struct timespec t; |
||
289 | |||
290 | f = ll_fsave(); |
||
291 | sti(); |
||
292 | |||
293 | jiffies_to_timespec(timeout, &t); |
||
294 | |||
295 | nanosleep(&t,NULL); |
||
296 | |||
297 | ll_frestore(f); |
||
298 | |||
299 | return 0; |
||
300 | |||
301 | } |
||
436 | giacomo | 302 | |
303 | void __const_udelay(unsigned long usecs) { |
||
304 | |||
305 | SYS_FLAGS f; |
||
306 | struct timespec t; |
||
307 | |||
308 | f = ll_fsave(); |
||
309 | sti(); |
||
310 | |||
311 | t.tv_sec = 0; |
||
312 | t.tv_nsec = usecs * 1000; |
||
313 | |||
314 | nanosleep(&t,NULL); |
||
315 | |||
316 | ll_frestore(f); |
||
317 | |||
318 | } |
||
319 |