Added functions to move memory to and from user space.
[cascardo/kernel/old_slides/.git] / 01.hello / 01.hello.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE slides SYSTEM "/usr/share/xml/docbook/custom/slides/3.3.1/schema/dtd/slides-full.dtd">
3
4 <slides>
5
6 <slidesinfo>
7 <title>Hello World Module</title>
8 <author><firstname>Thadeu</firstname><surname>Cascardo</surname></author>
9 </slidesinfo>
10
11 <foil>
12 <title>Introduction</title>
13 <para>
14 Let's take a look at how linux modules work.
15 </para>
16 </foil>
17
18 <foil>
19 <title>Building Linux</title>
20 <para>
21 But, first, we will build Linux. The procedure is configuring, building and
22 installing. Try <screen>make help</screen>.
23 </para>
24 </foil>
25
26 <foil>
27 <title>Requirements</title>
28 <para>
29 We need the tools to build a module and a building linux tree. Running the built
30 linux kernel is highly recommended so we can test our modules.
31 </para>
32 <para>
33 The tools include GNU make, GCC and GNU binutils. Linux build is highly
34 dependent on the GNU toolchain, since the beginning.
35 </para>
36 </foil>
37
38 <foil>
39 <title>Hands-on</title>
40 <para>
41 We have prepared sample code to build in the samples/ directory. Try them.
42 </para>
43 </foil>
44
45 <foil>
46 <title>Init and Exit Functions</title>
47 <para>
48 We use <emphasis>module\_init</emphasis> and <emphasis>module\_exit</emphasis>
49 to declare our init and exit functions.
50 </para>
51 </foil>
52
53 <foil>
54 <title>Init and Exit Functions</title>
55 <para>
56 The <emphasis>\_\_init</emphasis> and <emphasis>\_\_exit</emphasis> marks allow
57 the kernel to remove them when they are not needed, reducing memory consumption.
58 </para>
59 </foil>
60
61 <foil>
62 <title>printk</title>
63 <para>
64 <emphasis>printk</emphasis> is very similar to printf. The messages are usually
65 preceded by a string in the form &lt;n&gt;, where <emphasis>n</emphasis> is a
66 priority. There are macros, like <emphasis>KERN\_ALERT</emphasis> and
67 <emphasis>KERN\_DEBUG</emphasis> to use for that.
68 </para>
69 </foil>
70
71 <foil>
72 <title>License and taint</title>
73 <para>
74 <emphasis>MODULE\_LICENSE</emphasis> is highly recommended. A free software
75 license should be used, otherwise the kernel is tainted. This indicates to
76 developers that something has gone wrong, and some bug reports are ignored some
77 times.
78 </para>
79 </foil>
80
81 <foil>
82 <title>Building</title>
83 <para>
84 Building an out-of-tree linux module is very simple:
85 </para>
86 <screen>
87 $ make -C /lib/modules/`uname -r`/build M=$PWD modules
88 </screen>
89 </foil>
90
91 <foil>
92 <title>Module Tools</title>
93 <itemizedlist>
94 <listitem>
95 insmod
96 </listitem>
97 <listitem>
98 rmmod
99 </listitem>
100 <listitem>
101 modprobe
102 </listitem>
103 <listitem>
104 modinfo
105 </listitem>
106 <listitem>
107 depmod
108 </listitem>
109 </itemizedlist>
110 </foil>
111
112 <foil>
113 <title>Module Description Definitions</title>
114 <itemizedlist>
115 <listitem>
116 MODULE\_AUTHOR
117 </listitem>
118 <listitem>
119 MODULE\_DESCRIPTION
120 </listitem>
121 <listitem>
122 MODULE\_VERSION
123 </listitem>
124 <listitem>
125 MODULE\_LICENSE
126 </listitem>
127 <listitem>
128 MODULE\_ALIAS
129 </listitem>
130 </itemizedlist>
131 </foil>
132
133 <foil>
134 <title>Module parameters</title>
135 <para>
136 Besides <emphasis>MODULE\_PARM\_DESC</emphasis> to inform user about the
137 parameter, we must use <emphasis>module\_param</emphasis>.
138 </para>
139 <screen>
140 module_param(name, type, perm);
141 </screen>
142 </foil>
143
144 </slides>