1 /* Intel PRO/1000 Family Driver
2 * Copyright (C) 2004 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies, and that both the
7 * copyright notice and this permission notice appear in supporting documentation.
9 * Marcus Overhagen makes no representations about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
12 * MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
14 * OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
15 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <KernelExport.h>
23 spinlock chunk_pool_lock
= 0;
28 area_malloc(size_t size
)
31 size
= ROUNDUP(size
, B_PAGE_SIZE
);
33 if (create_area("area_malloc", &p
, B_ANY_KERNEL_ADDRESS
, size
, B_FULL_LOCK
, 0) < 0)
41 delete_area(area_for(p
));
45 mempool_init(int count
)
47 int chunk_size
= 2048;
49 int chunk_alloc_size
= chunk_size
* (count
+ 1);
55 chunk_pool
= area_malloc(chunk_alloc_size
);
60 chunk_base
= (char *)ROUNDUP((unsigned long)chunk_pool
, 2048);
62 for (i
= 0; i
< count
; i
++) {
63 chunk_pool_put(chunk_base
+ i
* chunk_size
);
72 area_free(chunk_pool
);
80 s
= disable_interrupts();
81 acquire_spinlock(&chunk_pool_lock
);
85 chunk_head
= *(void **)p
;
87 release_spinlock(&chunk_pool_lock
);
88 restore_interrupts(s
);
93 chunk_pool_put(void *p
)
96 s
= disable_interrupts();
97 acquire_spinlock(&chunk_pool_lock
);
99 *(void **)p
= chunk_head
;
102 release_spinlock(&chunk_pool_lock
);
103 restore_interrupts(s
);