1 /* $Id: modutil.c,v 1.4 1998/07/26 06:29:08 davem Exp $
2 * arch/sparc64/mm/modutil.c
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Based upon code written by Linus Torvalds and others.
8 #include <linux/malloc.h>
9 #include <linux/vmalloc.h>
11 #include <asm/uaccess.h>
12 #include <asm/system.h>
13 #include <asm/vaddrs.h>
15 static struct vm_struct
* modvmlist
= NULL
;
17 void module_unmap (void * addr
)
19 struct vm_struct
**p
, *tmp
;
23 if ((PAGE_SIZE
-1) & (unsigned long) addr
) {
24 printk("Trying to unmap module with bad address (%p)\n", addr
);
27 for (p
= &modvmlist
; (tmp
= *p
) ; p
= &tmp
->next
) {
28 if (tmp
->addr
== addr
) {
30 vmfree_area_pages(VMALLOC_VMADDR(tmp
->addr
), tmp
->size
);
35 printk("Trying to unmap nonexistent module vm area (%p)\n", addr
);
38 void * module_map (unsigned long size
)
41 struct vm_struct
**p
, *tmp
, *area
;
43 size
= PAGE_ALIGN(size
);
44 if (!size
|| size
> MODULES_LEN
) return NULL
;
46 addr
= (void *) MODULES_VADDR
;
47 for (p
= &modvmlist
; (tmp
= *p
) ; p
= &tmp
->next
) {
48 if (size
+ (unsigned long) addr
< (unsigned long) tmp
->addr
)
50 addr
= (void *) (tmp
->size
+ (unsigned long) tmp
->addr
);
52 if ((unsigned long) addr
+ size
>= MODULES_END
) return NULL
;
54 area
= (struct vm_struct
*) kmalloc(sizeof(*area
), GFP_KERNEL
);
55 if (!area
) return NULL
;
56 area
->size
= size
+ PAGE_SIZE
;
61 if (vmalloc_area_pages(VMALLOC_VMADDR(addr
), size
)) {