1/*
2 * Copyright 2002-2003, Thomas Kurschel. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef __LOCKED_POOL_H__
6#define __LOCKED_POOL_H__
7
8
9/*!	Paging-safe allocation of locked memory.
10
11	Library for managing temporary, locked memory with the condition of
12	not calling any function during allocation that can lead to paging.
13	Such memory is needed by drivers that are used to access the page file
14	but still need locked memory to execute requests.
15
16	Basically, a background thread manages a memory pool where blocks
17	are allocated from. If the pool is empty, allocation is delayed until
18	either a blocks is freed or the pool is enlarged by the background
19	thread.
20
21	All memory blocks must have same size and can be pre-initialized when
22	added to memory pool (and cleaned-up when removed from pool). The
23	free list is stored within free memory blocks, so you have to specify
24	a block offset where the manager can store the list pointers without
25	interfering with pre-initialization.
26
27	You can also specify an alignment, e.g. if the blocks are used for
28	DMA access, a minimum pool size (in blocks), a maximum pool size
29	(in blocks) and the size of memory chunks to be added if the entire
30	pool is allocated.
31*/
32
33
34#include <device_manager.h>
35
36
37typedef struct locked_pool *locked_pool_cookie;
38
39typedef status_t (*locked_pool_add_hook)(void *block, void *arg);
40typedef void (*locked_pool_remove_hook)(void *block, void *arg);
41
42typedef struct {
43	module_info minfo;
44
45	// allocate block
46	void *(*alloc)(locked_pool_cookie pool);
47	// free block
48	void (*free)(locked_pool_cookie pool, void *block);
49
50	// create new pool
51	// block_size	- size of one memory block
52	// alignment	- set address bits here that must be zero for block addresses
53	// next_ofs		- offset in block where internal next-pointer can be stored
54	// chunk_size	- how much system memory is to be allocated at once
55	// max_blocks	- maximum number of blocks
56	// min_free_block - minimum number of free blocks
57	// name			- name of pool
58	// lock_flags	- flags to be passed to lock_memory()
59	// alloc_hook	- hook to be called when new block is added to pool (can be NULL )
60	// free_hook	- hook to be called when block is removed from pool (can be NULL )
61	// hook_arg		- value to be passed to hooks as arg
62	locked_pool_cookie (*create)(int block_size, int alignment, int next_ofs,
63		int chunk_size, int max_blocks, int min_free_blocks, const char *name,
64		uint32 lock_flags, locked_pool_add_hook add_hook,
65		locked_pool_remove_hook remove_hook, void *hook_arg);
66	void (*destroy)(locked_pool_cookie pool);
67} locked_pool_interface;
68
69#define LOCKED_POOL_MODULE_NAME "generic/locked_pool/v1"
70
71#endif
72