Mercurial > archived > louis > epitech > mq > rathaxes
annotate rathaxes_start_to_implement_pci_stuff_in_the_lkm.patch @ 6:5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
author | Louis Opter <louis@lse.epitech.net> |
---|---|
date | Thu, 05 Jan 2012 23:27:32 +0100 |
parents | e94d4a9e6bd5 |
children | 44a25ffd5c8c |
rev | line source |
---|---|
4 | 1 # HG changeset patch |
5 | 2 # Parent 23fc39d03d6679b631adc6c22f312e6cda9aa82f |
4 | 3 rathaxes: start to implement the PCI registration part in the LKM sample |
4 | |
5 diff --git a/rathaxes/samples/lkm/CMakeLists.txt b/rathaxes/samples/lkm/CMakeLists.txt | |
6 --- a/rathaxes/samples/lkm/CMakeLists.txt | |
7 +++ b/rathaxes/samples/lkm/CMakeLists.txt | |
6
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
8 @@ -1,3 +1,7 @@ |
4 | 9 ADD_RATHAXES_SOURCES(lkm lkm.rtx |
10 - RTI log.rti lkm.rti | |
11 - BLT log.blt lkm.blt) | |
12 + RTI log.rti lkm.rti pci.rti | |
13 + BLT log.blt lkm.blt pci.blt) | |
6
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
14 + |
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
15 +# We can't name lkm since it's already used as the target name to generate the |
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
16 +# source (with ADD_RATHAXES_SOURCES). |
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
17 +ADD_RATHAXES_LKM(lkm_hello lkm) |
4 | 18 diff --git a/rathaxes/samples/lkm/lkm.blt b/rathaxes/samples/lkm/lkm.blt |
19 --- a/rathaxes/samples/lkm/lkm.blt | |
20 +++ b/rathaxes/samples/lkm/lkm.blt | |
5 | 21 @@ -1,8 +1,10 @@ |
4 | 22 with LKM |
23 { | |
5 | 24 + /* Skel of the generated C file: */ |
4 | 25 ${pointcut LKM::includes}; |
26 - ${pointcut LKM::init}; | |
27 - ${pointcut LKM::exit}; | |
5 | 28 + ${pointcut LKM::prototypes}; |
4 | 29 + ${pointcut LKM::data}; |
30 + ${pointcut LKM::code}; | |
31 | |
32 template sequence LKM::init() | |
33 { | |
5 | 34 @@ -17,7 +19,7 @@ |
4 | 35 MODULE_LICENSE(${config.license}); |
36 } | |
37 | |
38 - chunk LKM::init() | |
39 + chunk LKM::code() | |
40 { | |
41 /* | |
42 * Rathaxes doesn't yet support arbitrary "decorators" like __init | |
5 | 43 @@ -34,7 +36,7 @@ |
4 | 44 |
45 template sequence LKM::exit() | |
46 { | |
47 - chunk LKM::exit | |
48 + chunk LKM::code() | |
49 { | |
50 static void __attribute((__section__(.exit.text))) rtx_module_exit(void) | |
51 { | |
52 diff --git a/rathaxes/samples/lkm/lkm.rti b/rathaxes/samples/lkm/lkm.rti | |
53 --- a/rathaxes/samples/lkm/lkm.rti | |
54 +++ b/rathaxes/samples/lkm/lkm.rti | |
6
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
55 @@ -1,8 +1,10 @@ |
4 | 56 interface LKM |
57 { | |
58 provided pointcut LKM::includes; | |
59 - provided pointcut LKM::init; | |
60 - provided pointcut LKM::exit; | |
6
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
61 + /* maybe it should be possible to use chunk ::decl in sequence templates? */ |
5 | 62 + provided pointcut LKM::prototypes; |
4 | 63 + provided pointcut LKM::data; |
64 + provided pointcut LKM::code; | |
65 | |
66 required variable ::string LKM::author; | |
67 required variable ::string LKM::description; | |
6
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
68 @@ -11,11 +13,11 @@ |
4 | 69 required sequence LKM::init() |
70 { | |
71 provided chunk LKM::includes; | |
72 - provided chunk LKM::init; | |
73 + provided chunk LKM::code; | |
74 } | |
75 | |
76 required sequence LKM::exit() | |
77 { | |
78 - provided chunk LKM::exit; | |
79 + provided chunk LKM::code; | |
80 } | |
81 } | |
82 diff --git a/rathaxes/samples/lkm/lkm.rtx b/rathaxes/samples/lkm/lkm.rtx | |
83 --- a/rathaxes/samples/lkm/lkm.rtx | |
84 +++ b/rathaxes/samples/lkm/lkm.rtx | |
85 @@ -1,5 +1,15 @@ | |
86 -device LKM use LKM, Log | |
87 +device LKM use LKM, PCI, Log | |
88 { | |
89 + PCI::probe(PCI::Device dev) | |
90 + { | |
91 + | |
92 + } | |
93 + | |
94 + PCI::remove(PCI::Device dev) | |
95 + { | |
96 + | |
97 + } | |
98 + | |
99 LKM::init() | |
100 { | |
101 Log::info("Hello this is LKM"); | |
5 | 102 @@ -12,7 +22,11 @@ |
4 | 103 |
104 configuration | |
105 { | |
106 + LKM::name = "hello"; | |
107 LKM::author = "Rathaxes"; | |
108 LKM::description = "Hello World Loadable Kernel Module (LKM)"; | |
109 LKM::license = "BSD"; | |
5 | 110 + |
111 + PCI::vendor_id = "0x8080"; | |
112 + PCI::product_id = "0x42"; | |
113 } | |
4 | 114 diff --git a/rathaxes/samples/lkm/pci.blt b/rathaxes/samples/lkm/pci.blt |
115 new file mode 100644 | |
116 --- /dev/null | |
117 +++ b/rathaxes/samples/lkm/pci.blt | |
5 | 118 @@ -0,0 +1,103 @@ |
4 | 119 +with PCI, LKM |
120 +{ | |
121 + template type PCI::Device() | |
122 + { | |
123 + /* | |
124 + * chunk LKM::includes() | |
125 + * { | |
126 + * #include <linux/pci.h> | |
127 + * | |
128 + * typedef int include_linux_pci_stamp; | |
129 + * } | |
130 + */ | |
131 + | |
132 + chunk ::decl() | |
133 + { | |
134 + struct rtx_pci_device | |
135 + { | |
136 + struct pci_dev *pci_dev; | |
137 + }; | |
138 + } | |
139 + | |
140 + chunk ::init(pci_dev) | |
141 + { | |
142 + ${self}.pci_dev = pci_dev; | |
143 + } | |
144 + | |
145 + map | |
146 + { | |
147 + } | |
148 + } | |
149 + | |
150 + template sequence PCI::probe(PCI::Device dev) | |
151 + { | |
5 | 152 + chunk LKM::prototypes() |
153 + { | |
154 + static int /* __devinit */ rtx_pci_probe(struct pci_dev *, | |
155 + const struct pci_device_id *); | |
156 + } | |
157 + | |
158 + chunk LKM::data() | |
159 + { | |
160 + /* | |
161 + * CNorm doesn't seem to like "dynamic" arrays (i.e: you always | |
162 + * have to specify the exact size). | |
163 + */ | |
164 + static struct pci_device_id rtx_pci_device_table[2] = { | |
165 + { ${config.vendor_id}, ${config.product_id}, 0, PCI_ANY_ID, PCI_ANY_ID }, | |
166 + { 0, } | |
167 + }; | |
168 + | |
169 + static struct pci_driver rtx_pci_driver = { | |
170 + .name = ${config.name}, | |
171 + .id_table = rtx_pci_device_table, | |
172 + .probe = rtx_pci_probe, | |
173 + .remove = rtx_pci_remove | |
174 + }; | |
175 + } | |
176 + | |
4 | 177 + chunk LKM::code() |
178 + { | |
179 + static int /* __devinit */ rtx_pci_probe(struct pci_dev *pdev, | |
180 + const struct pci_device_id *pdev_id) | |
181 + { | |
182 + /* workaround for CNorm __std__ dialect, shouldn't be here */ | |
183 + typedef int ${PCI::Device}; | |
184 + | |
185 + int err; | |
6
5b128dbd2c17
WIP on the PCI LKM + improve the UseRathaxes CMake "library" to easily build a kernel module from the sources generated by rathaxes
Louis Opter <louis@lse.epitech.net>
parents:
5
diff
changeset
|
186 + ${PCI::Device} dev = NULL; /* Doesn't work with a pointer */ |
4 | 187 + |
188 + err = pci_enable_device(pdev); | |
189 +// if (err < 0) /* `if' doesn't work */ | |
190 +// goto fail; | |
191 + | |
192 + ${pointcut ::IMPLEMENTATION}; | |
193 + | |
194 + pci_set_drvdata(pdev, dev); | |
195 + | |
196 + return 0; | |
197 + | |
198 + fail: | |
199 + return err; | |
200 + } | |
201 + } | |
202 + } | |
203 + | |
204 + template sequence PCI::remove(PCI::Device dev) | |
205 + { | |
5 | 206 + chunk LKM::prototypes() |
207 + { | |
208 + static void rtx_pci_remove(struct pci_dev *); | |
209 + } | |
210 + | |
4 | 211 + chunk LKM::code() |
212 + { | |
213 + static void rtx_pci_remove(struct pci_dev *pdev) | |
214 + { | |
215 + pci_disable_device(pdev); | |
216 + | |
217 + ${pointcut ::IMPLEMENTATION}; | |
218 + } | |
219 + } | |
220 + } | |
221 +} | |
222 diff --git a/rathaxes/samples/lkm/pci.rti b/rathaxes/samples/lkm/pci.rti | |
223 new file mode 100644 | |
224 --- /dev/null | |
225 +++ b/rathaxes/samples/lkm/pci.rti | |
5 | 226 @@ -0,0 +1,25 @@ |
4 | 227 +interface PCI : LKM |
228 +{ | |
229 + provided type PCI::Device; | |
230 + | |
5 | 231 + required variable ::number PCI::vendor_id; |
232 + required variable ::number PCI::product_id; | |
233 + | |
4 | 234 + provided sequence PCI::register() |
235 + { | |
236 + provided chunk ::CALL; | |
237 + } | |
238 + | |
239 + required sequence PCI::probe(PCI::Device) | |
240 + { | |
5 | 241 + provided chunk LKM::prototypes; |
242 + provided chunk LKM::data; | |
4 | 243 + provided chunk LKM::code; |
244 + } | |
245 + | |
246 + required sequence PCI::remove(PCI::Device) | |
247 + { | |
5 | 248 + provided chunk LKM::prototypes; |
4 | 249 + provided chunk LKM::code; |
250 + } | |
251 +} |