Merge commit 'v2.6.34' into next
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / dt3155 / allocator.README
CommitLineData
aa337ef1
SS
1
2The allocator shown here exploits high memory. This document explains
3how a user can deal with drivers uses this allocator and how a
4programmer can link in the module.
5
6The module is being used by my pxc and pxdrv device drivers (as well as
7other ones), available from ftp.systemy.it/pub/develop and
8ftp.linux.it/pub/People/Rubini
9
10 User's manual
11 =============
12
13
14One of the most compelling problems with any DMA-capable device is the
15allocation of a suitable memory buffer. The "allocator" module tries
16to deal with the problem in a clean way. The module is able to use
17high memory (above the one used in normal operation) for DMA
18allocation.
19
20To prevent the kernel for using high memory, so that it remains
21available for DMA, you should pass a command line argument to the
22kernel. Command line arguments can be passed to Lilo, to Loadlin or
23to whichever loader you are using (unless it's very poor in design).
24For Lilo, either use "append=" in /etc/lilo.conf or add commandline
25arguments to the interactive prompt. For example, I have a 32MB box
26and reserve two megs for DMA:
27
28In lilo.conf:
29 image = /zImage
30 label = linux
31 append = "mem=30M"
32
33Or, interactively:
34 LILO: linux mem=30M
35
36Once the kernel is booted with the right command-line argument, any
37driver linked with the allocator module will be able to get
38DMA-capable memory without much trouble (unless the various drivers
39need more memory than available).
40
41The module implements an alloc/free mechanism, so that it can serve
42multiple drivers at the same time. Note however that the allocator
43uses all of high memory and assumes to be the only piece of software
44using such memory.
45
46
47 Programmer's manual
48 ===================
49
50The allocator, as released, is designed to be linked to a device
51driver. In this case, the driver must call allocator_init() before
52using the allocator and must call allocator_cleanup() before
53unloading. This is usually done from within init_module() and
54cleanup_module(). If the allocator is linked to a driver, it won't be
55possible for several drivers to allocate high DMA memory, as explained
56above.
57
58It is possible, on the other hand, to compile the module as a standalone
59module, so that several modules can rely on the allocator for they DMA
60buffers. To compile the allocator as a standalone module, do the
61following in this directory (or provide a suitable Makefile, or edit
62the source code):
63
64 make allocator.o CC="gcc -Dallocator_init=init_module -Dallocator_cleanup=cleanup_module -include /usr/include/linux/module.h"
65
66The previous commandline tells to include <linux/module.h> in the
67first place, and to rename the init and cleanup function to the ones
68needed for module loading and unloading. Drivers using a standalone
69allocator won't need to call allocator_init() nor allocator_cleanup().
70
71The allocator exports the following functions (declared in allocator.h):
72
73 unsigned long allocator_allocate_dma (unsigned long kilobytes,
74 int priority);
75
76 This function returns a physical address, over high_memory,
77 which corresponds to an area of at least "kilobytes" kilobytes.
78 The area will be owned by the module calling the function.
79 The returned address can be passed to device boards, to instruct
80 their DMA controllers, via phys_to_bus(). The address can be used
81 by C code after vremap()/ioremap(). The "priority" argument should
82 be GFP_KERNEL or GFP_ATOMIC, according to the context of the
83 caller; it is used to call kmalloc(), as the allocator must keep
84 track of any region it gives away. In case of error the function
85 returns 0, and the caller is expected to issue a -ENOMEM error.
86
87
88 void allocator_free_dma (unsigned long address);
89
90 This function is the reverse of the previous one. If a driver
91 doesn't free the DMA memory it allocated, the allocator will
92 consider such memory as busy. Note, however, that
93 allocator_cleanup() calls kfree() on every region it reclaimed,
94 so that a driver with the allocator linked in can avoid calling
95 allocator_free_dma() at unload time.
96
97
98