Rev 462 |
Rev 469 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <ll/i386/hw-instr.h>
#include <ll/i386/cons.h>
#include <linuxcomp.h>
#include <linux/time.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <asm/io.h>
#include <linux/ctype.h>
#include <linux/device.h>
#include <linux/completion.h>
unsigned char _ctype
[] = {
_C
,_C
,_C
,_C
,_C
,_C
,_C
,_C
, /* 0-7 */
_C
,_C
|_S
,_C
|_S
,_C
|_S
,_C
|_S
,_C
|_S
,_C
,_C
, /* 8-15 */
_C
,_C
,_C
,_C
,_C
,_C
,_C
,_C
, /* 16-23 */
_C
,_C
,_C
,_C
,_C
,_C
,_C
,_C
, /* 24-31 */
_S
|_SP
,_P
,_P
,_P
,_P
,_P
,_P
,_P
, /* 32-39 */
_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
, /* 40-47 */
_D
,_D
,_D
,_D
,_D
,_D
,_D
,_D
, /* 48-55 */
_D
,_D
,_P
,_P
,_P
,_P
,_P
,_P
, /* 56-63 */
_P
,_U
|_X
,_U
|_X
,_U
|_X
,_U
|_X
,_U
|_X
,_U
|_X
,_U
, /* 64-71 */
_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
, /* 72-79 */
_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
, /* 80-87 */
_U
,_U
,_U
,_P
,_P
,_P
,_P
,_P
, /* 88-95 */
_P
,_L
|_X
,_L
|_X
,_L
|_X
,_L
|_X
,_L
|_X
,_L
|_X
,_L
, /* 96-103 */
_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
, /* 104-111 */
_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
, /* 112-119 */
_L
,_L
,_L
,_P
,_P
,_P
,_P
,_C
, /* 120-127 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
_S
|_SP
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
, /* 160-175 */
_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
,_P
, /* 176-191 */
_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_U
, /* 192-207 */
_U
,_U
,_U
,_U
,_U
,_U
,_U
,_P
,_U
,_U
,_U
,_U
,_U
,_U
,_U
,_L
, /* 208-223 */
_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
, /* 224-239 */
_L
,_L
,_L
,_L
,_L
,_L
,_L
,_P
,_L
,_L
,_L
,_L
,_L
,_L
,_L
,_L
}; /* 240-255 */
__kernel_size_t strnlen
(const char *s
, __kernel_size_t count
)
{
const char *sc
;
for (sc
= s
; count
-- && *sc
!= '\0'; ++sc
)
/* nothing */;
return sc
- s
;
}
int nanosleep
(const struct timespec
*rqtp
, struct timespec
*rmtp
);
struct resource ioport_resource
= {
.
name = "PCI IO",
.
start = 0x0000,
.
end = IO_SPACE_LIMIT
,
.
flags = IORESOURCE_IO
,
};
struct resource iomem_resource
= {
.
name = "PCI mem",
.
start = 0UL
,
.
end = ~0UL
,
.
flags = IORESOURCE_MEM
,
};
/* Return the conflict entry if you can't request it */
static struct resource
* __request_resource
(struct resource
*root
, struct resource
*new
)
{
unsigned long start
= new
->start
;
unsigned long end
= new
->end
;
struct resource
*tmp
, **p
;
if (end
< start
)
return root
;
if (start
< root
->start
)
return root
;
if (end
> root
->end
)
return root
;
p
= &root
->child
;
for (;;) {
tmp
= *p
;
if (!tmp
|| tmp
->start
> end
) {
new
->sibling
= tmp
;
*p
= new
;
new
->parent
= root
;
return NULL
;
}
p
= &tmp
->sibling
;
if (tmp
->end
< start
)
continue;
return tmp
;
}
}
static int __release_resource
(struct resource
*old
)
{
struct resource
*tmp
, **p
;
p
= &old
->parent
->child
;
for (;;) {
tmp
= *p
;
if (!tmp
)
break;
if (tmp
== old
) {
*p
= tmp
->sibling
;
old
->parent
= NULL
;
return 0;
}
p
= &tmp
->sibling
;
}
return -EINVAL
;
}
int release_resource
(struct resource
*old
)
{
int retval
;
retval
= __release_resource
(old
);
return retval
;
}
int request_resource
(struct resource
*root
, struct resource
*new
)
{
struct resource
*conflict
;
conflict
= __request_resource
(root
, new
);
return conflict
? -EBUSY
: 0;
}
struct resource
* __request_region
(struct resource
*parent
, unsigned long start
, unsigned long n
, const char *name
)
{
struct resource
*res
= kmalloc
(sizeof(*res
), GFP_KERNEL
);
if (res
) {
memset(res
, 0, sizeof(*res
));
res
->name
= name
;
res
->start
= start
;
res
->end
= start
+ n
- 1;
res
->flags
= IORESOURCE_BUSY
;
for (;;) {
struct resource
*conflict
;
conflict
= __request_resource
(parent
, res
);
if (!conflict
)
break;
if (conflict
!= parent
) {
parent
= conflict
;
if (!(conflict
->flags
& IORESOURCE_BUSY
))
continue;
}
/* Uhhuh, that didn't work out.. */
kfree
(res
);
res
= NULL
;
break;
}
}
return res
;
}
void __release_region
(struct resource
*parent
, unsigned long start
, unsigned long n
)
{
struct resource
**p
;
unsigned long end
;
p
= &parent
->child
;
end
= start
+ n
- 1;
for (;;) {
struct resource
*res
= *p
;
if (!res
)
break;
if (res
->start
<= start
&& res
->end
>= end
) {
if (!(res
->flags
& IORESOURCE_BUSY
)) {
p
= &res
->child
;
continue;
}
if (res
->start
!= start
|| res
->end
!= end
)
break;
*p
= res
->sibling
;
kfree
(res
);
return;
}
p
= &res
->sibling
;
}
printk
(KERN_WARNING
"Trying to free nonexistent resource <%08lx-%08lx>\n", start
, end
);
}
static int find_resource
(struct resource
*root
, struct resource
*new
,
unsigned long size
,
unsigned long min
, unsigned long max
,
unsigned long align
,
void (*alignf
)(void *, struct resource
*,
unsigned long, unsigned long),
void *alignf_data
)
{
struct resource
*this
= root
->child
;
new
->start
= root
->start
;
/*
* Skip past an allocated resource that starts at 0, since the assignment
* of this->start - 1 to new->end below would cause an underflow.
*/
if (this
&& this
->start
== 0) {
new
->start
= this
->end
+ 1;
this
= this
->sibling
;
}
for(;;) {
if (this
)
new
->end
= this
->start
- 1;
else
new
->end
= root
->end
;
if (new
->start
< min
)
new
->start
= min
;
if (new
->end
> max
)
new
->end
= max
;
new
->start
= (new
->start
+ align
- 1) & ~
(align
- 1);
if (alignf
)
alignf
(alignf_data
, new
, size
, align
);
if (new
->start
< new
->end
&& new
->end
- new
->start
+ 1 >= size
) {
new
->end
= new
->start
+ size
- 1;
return 0;
}
if (!this
)
break;
new
->start
= this
->end
+ 1;
this
= this
->sibling
;
}
return -EBUSY
;
}
int allocate_resource
(struct resource
*root
, struct resource
*new
,
unsigned long size
,
unsigned long min
, unsigned long max
,
unsigned long align
,
void (*alignf
)(void *, struct resource
*,
unsigned long, unsigned long),
void *alignf_data
)
{
int err
;
err
= find_resource
(root
, new
, size
, min
, max
, align
, alignf
, alignf_data
);
if (err
>= 0 && __request_resource
(root
, new
))
err
= -EBUSY
;
return err
;
}
int remap_page_range
(struct vm_area_struct
*vma
, unsigned long from
, unsigned long phys_addr
, unsigned long size
, pgprot_t prot
)
{ return 0; }
void dump_stack
(void) { }
void panic
(const char * fmt
, ...
) {
cprintf
((char *)(fmt
));
}
extern void * malloc(size_t size
);
void *__kmalloc
(size_t size
, int flags
) {
return malloc(size
);
}
extern void free(void *);
void kfree
(const void *ptr
) {
free((void *)(ptr
));
}
unsigned long pci_mem_start
= 0x10000000;
signed long schedule_timeout
(signed long timeout
) {
SYS_FLAGS f
;
struct timespec t
;
f
= ll_fsave
();
sti
();
jiffies_to_timespec
(timeout
, &t
);
nanosleep
(&t
,NULL
);
ll_frestore
(f
);
return 0;
}
void __const_udelay
(unsigned long usecs
) {
SYS_FLAGS f
;
struct timespec t
;
f
= ll_fsave
();
sti
();
t.
tv_sec = 0;
t.
tv_nsec = usecs
* 1000;
nanosleep
(&t
,NULL
);
ll_frestore
(f
);
}
void __udelay
(unsigned long usecs
) {
SYS_FLAGS f
;
struct timespec t
;
f
= ll_fsave
();
sti
();
t.
tv_sec = 0;
t.
tv_nsec = usecs
* 1000;
nanosleep
(&t
,NULL
);
ll_frestore
(f
);
}
unsigned long __copy_to_user_ll
(void __user
*to
, const void *from
, unsigned long n
) {
memcpy(to
,from
,n
);
return n
;
}
unsigned long __copy_from_user_ll
(void *to
, const void __user
*from
, unsigned long n
) {
memcpy(to
,from
,n
);
return n
;
}
void complete
(struct completion
*c
) {
}
void wait_for_completion
(struct completion
*c
) {
}
struct device legacy_bus
= {
.
bus_id = "legacy",
};
int register_chrdev
(unsigned int a
, const char *b
, struct file_operations
*c
) {
return 0;
}
int unregister_chrdev
(unsigned int a
, const char *b
) {
return 0;
}