comparison rathaxes_start_to_implement_pci_stuff_in_the_lkm.patch @ 10:44a25ffd5c8c

Reorganize the patch queue a bit: put the cmake patch first then the LKM patch then the PCI part
author Louis Opter <louis@lse.epitech.net>
date Fri, 06 Jan 2012 13:43:06 +0100
parents 5b128dbd2c17
children efee5f0249e2
comparison
equal deleted inserted replaced
9:7d51609a0ff1 10:44a25ffd5c8c
1 # HG changeset patch 1 # HG changeset patch
2 # Parent 23fc39d03d6679b631adc6c22f312e6cda9aa82f 2 # Parent 873b66890128280637d97a24221258bb297a1ac8
3 rathaxes: start to implement the PCI registration part in the LKM sample 3 rathaxes: start to implement the PCI registration part in the LKM sample
4 4
5 diff --git a/rathaxes/samples/lkm/CMakeLists.txt b/rathaxes/samples/lkm/CMakeLists.txt 5 diff --git a/rathaxes/samples/lkm/CMakeLists.txt b/rathaxes/samples/lkm/CMakeLists.txt
6 --- a/rathaxes/samples/lkm/CMakeLists.txt 6 --- a/rathaxes/samples/lkm/CMakeLists.txt
7 +++ b/rathaxes/samples/lkm/CMakeLists.txt 7 +++ b/rathaxes/samples/lkm/CMakeLists.txt
29 + ${pointcut LKM::data}; 29 + ${pointcut LKM::data};
30 + ${pointcut LKM::code}; 30 + ${pointcut LKM::code};
31 31
32 template sequence LKM::init() 32 template sequence LKM::init()
33 { 33 {
34 @@ -17,7 +19,7 @@ 34 @@ -10,22 +12,29 @@
35 {
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 - typedef int lkm_headers_include_stamp;
39
40 + typedef int include_linux_module_stamp;
41 + typedef int include_linux_kernel_stamp;
42 + }
43 +
44 + chunk LKM::data()
45 + {
46 MODULE_DESCRIPTION(${config.description});
47 MODULE_AUTHOR(${config.author});
35 MODULE_LICENSE(${config.license}); 48 MODULE_LICENSE(${config.license});
36 } 49 }
37 50
38 - chunk LKM::init() 51 - chunk LKM::init()
39 + chunk LKM::code() 52 + chunk LKM::code()
40 { 53 {
41 /* 54 /*
42 * Rathaxes doesn't yet support arbitrary "decorators" like __init 55 * Rathaxes doesn't yet support arbitrary "decorators" like __init
43 @@ -34,7 +36,7 @@ 56 * or __exit.
57 */
58 - static int __attribute__((__section__(.init.text))) rtx_module_init(void)
59 + static int __attribute__((__section__(".init.text"))) rtx_module_init(void)
60 {
61 ${pointcut ::IMPLEMENTATION};
62 +
63 + return 0;
64 }
65
66 module_init(rtx_module_init);
67 @@ -34,14 +43,14 @@
44 68
45 template sequence LKM::exit() 69 template sequence LKM::exit()
46 { 70 {
47 - chunk LKM::exit 71 - chunk LKM::exit
48 + chunk LKM::code() 72 + chunk LKM::code()
49 { 73 {
50 static void __attribute((__section__(.exit.text))) rtx_module_exit(void) 74 - static void __attribute((__section__(.exit.text))) rtx_module_exit(void)
75 + static void __attribute__((__section__(".exit.text"))) rtx_module_exit(void)
51 { 76 {
77 ${pointcut ::IMPLEMENTATION};
78 }
79
80 - module_exit(rtx_module_init);
81 + module_exit(rtx_module_exit);
82 }
83 }
84 }
52 diff --git a/rathaxes/samples/lkm/lkm.rti b/rathaxes/samples/lkm/lkm.rti 85 diff --git a/rathaxes/samples/lkm/lkm.rti b/rathaxes/samples/lkm/lkm.rti
53 --- a/rathaxes/samples/lkm/lkm.rti 86 --- a/rathaxes/samples/lkm/lkm.rti
54 +++ b/rathaxes/samples/lkm/lkm.rti 87 +++ b/rathaxes/samples/lkm/lkm.rti
55 @@ -1,8 +1,10 @@ 88 @@ -1,8 +1,10 @@
56 interface LKM 89 interface LKM
80 } 113 }
81 } 114 }
82 diff --git a/rathaxes/samples/lkm/lkm.rtx b/rathaxes/samples/lkm/lkm.rtx 115 diff --git a/rathaxes/samples/lkm/lkm.rtx b/rathaxes/samples/lkm/lkm.rtx
83 --- a/rathaxes/samples/lkm/lkm.rtx 116 --- a/rathaxes/samples/lkm/lkm.rtx
84 +++ b/rathaxes/samples/lkm/lkm.rtx 117 +++ b/rathaxes/samples/lkm/lkm.rtx
85 @@ -1,5 +1,15 @@ 118 @@ -1,19 +1,35 @@
86 -device LKM use LKM, Log 119 -device LKM use LKM, Log
87 +device LKM use LKM, PCI, Log 120 +device LKM use LKM, PCI, Log
88 { 121 {
89 + PCI::probe(PCI::Device dev) 122 + PCI::probe(PCI::Device dev)
90 + { 123 + {
97 + } 130 + }
98 + 131 +
99 LKM::init() 132 LKM::init()
100 { 133 {
101 Log::info("Hello this is LKM"); 134 Log::info("Hello this is LKM");
102 @@ -12,7 +22,11 @@ 135 + PCI::register();
136 }
137
138 LKM::exit()
139 {
140 Log::info("Good bye this was LKM");
141 + PCI::unregister();
142 }
143 }
103 144
104 configuration 145 configuration
105 { 146 {
106 + LKM::name = "hello"; 147 + LKM::name = "hello";
107 LKM::author = "Rathaxes"; 148 LKM::author = "Rathaxes";
108 LKM::description = "Hello World Loadable Kernel Module (LKM)"; 149 LKM::description = "Hello World Loadable Kernel Module (LKM)";
109 LKM::license = "BSD"; 150 LKM::license = "BSD";
110 + 151 +
111 + PCI::vendor_id = "0x8080"; 152 + PCI::vendor_id = 0x8086;
112 + PCI::product_id = "0x42"; 153 + PCI::product_id = 0x100f;
113 } 154 }
114 diff --git a/rathaxes/samples/lkm/pci.blt b/rathaxes/samples/lkm/pci.blt 155 diff --git a/rathaxes/samples/lkm/pci.blt b/rathaxes/samples/lkm/pci.blt
115 new file mode 100644 156 new file mode 100644
116 --- /dev/null 157 --- /dev/null
117 +++ b/rathaxes/samples/lkm/pci.blt 158 +++ b/rathaxes/samples/lkm/pci.blt
118 @@ -0,0 +1,103 @@ 159 @@ -0,0 +1,129 @@
119 +with PCI, LKM 160 +with PCI, LKM, Log
120 +{ 161 +{
121 + template type PCI::Device() 162 + template type PCI::Device()
122 + { 163 + {
123 + /* 164 + chunk LKM::includes()
124 + * chunk LKM::includes() 165 + {
125 + * { 166 + #include <linux/pci.h>
126 + * #include <linux/pci.h> 167 +
127 + * 168 + typedef int include_linux_pci_stamp;
128 + * typedef int include_linux_pci_stamp; 169 + }
129 + * }
130 + */
131 + 170 +
132 + chunk ::decl() 171 + chunk ::decl()
133 + { 172 + {
134 + struct rtx_pci_device 173 + struct rtx_pci_device
135 + { 174 + {
153 + { 192 + {
154 + static int /* __devinit */ rtx_pci_probe(struct pci_dev *, 193 + static int /* __devinit */ rtx_pci_probe(struct pci_dev *,
155 + const struct pci_device_id *); 194 + const struct pci_device_id *);
156 + } 195 + }
157 + 196 +
197 + chunk LKM::code()
198 + {
199 + static int /* __devinit */ rtx_pci_probe(struct pci_dev *pdev,
200 + const struct pci_device_id *pdev_id)
201 + {
202 + /* workaround for CNorm __std__ dialect, shouldn't be here */
203 + typedef int ${PCI::Device};
204 +
205 + int err;
206 + ${PCI::Device} *dev = NULL;
207 +
208 + err = pci_enable_device(pdev);
209 +// if (err < 0) /* `if' doesn't work */
210 +// goto fail;
211 +
212 + ${pointcut ::IMPLEMENTATION};
213 +
214 + pci_set_drvdata(pdev, dev);
215 +
216 + return 0;
217 +
218 + fail:
219 + return err;
220 + }
221 + }
222 + }
223 +
224 + template sequence PCI::remove(PCI::Device dev)
225 + {
226 + chunk LKM::prototypes()
227 + {
228 + static void rtx_pci_remove(struct pci_dev *);
229 + }
230 +
231 + chunk LKM::code()
232 + {
233 + static void rtx_pci_remove(struct pci_dev *pdev)
234 + {
235 + pci_disable_device(pdev);
236 +
237 + ${pointcut ::IMPLEMENTATION};
238 + }
239 + }
240 + }
241 +
242 + template sequence PCI::register()
243 + {
158 + chunk LKM::data() 244 + chunk LKM::data()
159 + { 245 + {
160 + /* 246 + /*
161 + * CNorm doesn't seem to like "dynamic" arrays (i.e: you always 247 + * CNorm doesn't seem to like "dynamic" arrays (i.e: you always
162 + * have to specify the exact size). 248 + * have to specify the exact size).
172 + .probe = rtx_pci_probe, 258 + .probe = rtx_pci_probe,
173 + .remove = rtx_pci_remove 259 + .remove = rtx_pci_remove
174 + }; 260 + };
175 + } 261 + }
176 + 262 +
177 + chunk LKM::code() 263 + chunk ::CALL
178 + { 264 + {
179 + static int /* __devinit */ rtx_pci_probe(struct pci_dev *pdev, 265 + /*
180 + const struct pci_device_id *pdev_id) 266 + * So how do we use the return value in the parent context?
181 + { 267 + */
182 + /* workaround for CNorm __std__ dialect, shouldn't be here */ 268 + pci_register_driver(&rtx_pci_driver);
183 + typedef int ${PCI::Device}; 269 + /*
184 + 270 + * if (pci_register_driver(&rtx_pci_driver))
185 + int err; 271 + * {
186 + ${PCI::Device} dev = NULL; /* Doesn't work with a pointer */ 272 + * `if' still doesn't work.
187 + 273 + *
188 + err = pci_enable_device(pdev); 274 + * Also, can I call the Log interface from here?
189 +// if (err < 0) /* `if' doesn't work */ 275 + * ${Log::info("Message")}; doesn't seem to work.
190 +// goto fail; 276 + * }
191 + 277 + */
192 + ${pointcut ::IMPLEMENTATION}; 278 + }
193 + 279 + }
194 + pci_set_drvdata(pdev, dev); 280 +
195 + 281 + template sequence PCI::unregister()
196 + return 0; 282 + {
197 + 283 + chunk ::CALL
198 + fail: 284 + {
199 + return err; 285 + pci_unregister_driver(&rtx_pci_driver);
200 + }
201 + }
202 + }
203 +
204 + template sequence PCI::remove(PCI::Device dev)
205 + {
206 + chunk LKM::prototypes()
207 + {
208 + static void rtx_pci_remove(struct pci_dev *);
209 + }
210 +
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 + } 286 + }
220 + } 287 + }
221 +} 288 +}
222 diff --git a/rathaxes/samples/lkm/pci.rti b/rathaxes/samples/lkm/pci.rti 289 diff --git a/rathaxes/samples/lkm/pci.rti b/rathaxes/samples/lkm/pci.rti
223 new file mode 100644 290 new file mode 100644
224 --- /dev/null 291 --- /dev/null
225 +++ b/rathaxes/samples/lkm/pci.rti 292 +++ b/rathaxes/samples/lkm/pci.rti
226 @@ -0,0 +1,25 @@ 293 @@ -0,0 +1,30 @@
227 +interface PCI : LKM 294 +interface PCI : LKM
228 +{ 295 +{
229 + provided type PCI::Device; 296 + provided type PCI::Device;
230 + 297 +
231 + required variable ::number PCI::vendor_id; 298 + required variable ::number PCI::vendor_id;
232 + required variable ::number PCI::product_id; 299 + required variable ::number PCI::product_id;
233 + 300 +
234 + provided sequence PCI::register() 301 + provided sequence PCI::register()
235 + { 302 + {
236 + provided chunk ::CALL; 303 + provided chunk ::CALL;
304 + provided chunk LKM::data;
305 + }
306 +
307 + provided sequence PCI::unregister()
308 + {
309 + provided chunk ::CALL;
237 + } 310 + }
238 + 311 +
239 + required sequence PCI::probe(PCI::Device) 312 + required sequence PCI::probe(PCI::Device)
240 + {
241 + provided chunk LKM::prototypes;
242 + provided chunk LKM::data;
243 + provided chunk LKM::code;
244 + }
245 +
246 + required sequence PCI::remove(PCI::Device)
247 + { 313 + {
248 + provided chunk LKM::prototypes; 314 + provided chunk LKM::prototypes;
249 + provided chunk LKM::code; 315 + provided chunk LKM::code;
250 + } 316 + }
317 +
318 + required sequence PCI::remove(PCI::Device)
319 + {
320 + provided chunk LKM::prototypes;
321 + provided chunk LKM::code;
322 + }
251 +} 323 +}