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
,
34 B_32_BIT_FULL_LOCK
, 0) < 0) {
43 delete_area(area_for(p
));
47 mempool_init(int count
)
49 int chunk_size
= 2048;
51 int chunk_alloc_size
= chunk_size
* (count
+ 1);
57 chunk_pool
= area_malloc(chunk_alloc_size
);
62 chunk_base
= (char *)ROUNDUP((unsigned long)chunk_pool
, 2048);
64 for (i
= 0; i
< count
; i
++) {
65 chunk_pool_put(chunk_base
+ i
* chunk_size
);
74 area_free(chunk_pool
);
82 s
= disable_interrupts();
83 acquire_spinlock(&chunk_pool_lock
);
87 chunk_head
= *(void **)p
;
89 release_spinlock(&chunk_pool_lock
);
90 restore_interrupts(s
);
95 chunk_pool_put(void *p
)
98 s
= disable_interrupts();
99 acquire_spinlock(&chunk_pool_lock
);
101 *(void **)p
= chunk_head
;
104 release_spinlock(&chunk_pool_lock
);
105 restore_interrupts(s
);