Subversion Repositories shark

Rev

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