]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/compat/x86bios/x86bios_alloc.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / compat / x86bios / x86bios_alloc.c
1 /*-
2  * Copyright (C) 1999 Egbert Eich
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appear in all copies and that
7  * both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of the authors not be used
9  * in advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The authors makes no
11  * representations about the suitability of this software for any purpose.
12  * It is provided "as is" without express or implied warranty.
13  *
14  * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  *
22  * xserver/hw/xfree86/int10/generic.c
23  */
24
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
27
28 #include <sys/param.h>
29
30 #include <compat/x86bios/x86bios.h>
31
32 extern u_char *pbiosMem;
33 extern int busySegMap[5];
34
35 void *
36 x86biosAlloc(int count, int *segs)
37 {
38         int i;
39         int j;
40
41         /* find the free segblock of page */
42         for (i = 0; i < (PAGE_RESERV - count); i++)
43         {
44                 if (busySegMap[i] == 0)
45                 {
46                         /* find the capacity of segblock */
47                         for (j = i; j < (i + count); j++)
48                         {
49                                 if (busySegMap[j] == 1)
50                                         break;
51                         }
52
53                         if (j == (i + count))
54                                 break;
55                         i += count;
56                 }
57         }
58
59         if (i == (PAGE_RESERV - count))
60                 return NULL;
61
62         /* make the segblock is used */
63         for (j = i; j < (i + count); j++)
64                 busySegMap[i] = 1;
65
66         *segs = i * 4096;
67
68         return (pbiosMem + *segs);
69 }
70
71 void
72 x86biosFree(void *pbuf, int count)
73 {
74         int i;
75         int busySeg;
76
77         busySeg = ((u_char *)pbuf - pbiosMem) / 4096;
78
79         for (i = busySeg; i < (busySeg + count); i++)
80                 busySegMap[i] = 0;
81 }