Mercurial > archived > louis > epitech > mq > rathaxes
comparison rathaxes_start_to_implement_the_ethernet_subsystem_in_the_lkm.patch @ 12:80cfe40c1136
WIP on the LKM sample, add a patch to work on the Ethernet subsystem
author | Louis Opter <louis@lse.epitech.net> |
---|---|
date | Fri, 06 Jan 2012 17:33:00 +0100 |
parents | |
children | d00a5829811d |
comparison
equal
deleted
inserted
replaced
11:efee5f0249e2 | 12:80cfe40c1136 |
---|---|
1 # HG changeset patch | |
2 # Parent 44a4871708b167b49df10fc6153a73730f08287a | |
3 rathaxes: start to implement the Ethernet subsystem in linux 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 | |
8 @@ -1,6 +1,6 @@ | |
9 ADD_RATHAXES_SOURCES(lkm lkm.rtx | |
10 - RTI log.rti lkm.rti pci.rti | |
11 - BLT log.blt lkm.blt pci.blt) | |
12 + RTI log.rti lkm.rti pci.rti ethernet.rti | |
13 + BLT log.blt lkm.blt pci.blt ethernet.blt) | |
14 | |
15 # We can't name lkm since it's already used as the target name to generate the | |
16 # source (with ADD_RATHAXES_SOURCES). | |
17 diff --git a/rathaxes/samples/lkm/ethernet.blt b/rathaxes/samples/lkm/ethernet.blt | |
18 new file mode 100644 | |
19 --- /dev/null | |
20 +++ b/rathaxes/samples/lkm/ethernet.blt | |
21 @@ -0,0 +1,116 @@ | |
22 +with Ethernet, PCI, LKM | |
23 +{ | |
24 + template type Ethernet::Device() | |
25 + { | |
26 + chunk LKM::includes() | |
27 + { | |
28 + #include <linux/netdevice.h> | |
29 + #include <linux/etherdevice.h> | |
30 + | |
31 + typedef int include_linux_net_system_stamp; | |
32 + } | |
33 + | |
34 + chunk ::decl() | |
35 + { | |
36 + struct net_device; | |
37 + } | |
38 + | |
39 + chunk ::init(net_dev) | |
40 + { | |
41 + ${self} = ${net_dev}; | |
42 + } | |
43 + | |
44 + map | |
45 + { | |
46 + } | |
47 + } | |
48 + | |
49 + template sequence Ethernet::open(Ethernet::Device dev) | |
50 + { | |
51 + chunk LKM::prototypes() | |
52 + { | |
53 + static int rtx_ethernet_open(struct net_device *); | |
54 + } | |
55 + | |
56 + chunk LKM::code() | |
57 + { | |
58 + static int rtx_ethernet_open(struct net_device *dev) | |
59 + { | |
60 + ${pointcut ::IMPLEMENTATION}; | |
61 + } | |
62 + } | |
63 + } | |
64 + | |
65 + template sequence Ethernet::close(Ethernet::Device dev) | |
66 + { | |
67 + chunk LKM::prototypes() | |
68 + { | |
69 + static int rtx_ethernet_close(struct net_device ); | |
70 + } | |
71 + | |
72 + chunk LKM::code() | |
73 + { | |
74 + static int rtx_ethernet_close(struct net_device dev) | |
75 + { | |
76 + ${pointcut ::IMPLEMENTATION}; | |
77 + } | |
78 + } | |
79 + } | |
80 + | |
81 + template sequence Ethernet::interrupt_handler(Ethernet::Device dev) | |
82 + { | |
83 + /* | |
84 + * Why we can't use irqreturn_t here? (we are forced to use enum | |
85 + * irqreturn, which is the real type). | |
86 + */ | |
87 + | |
88 + chunk LKM::prototypes() | |
89 + { | |
90 + static enum irqreturn rtx_ethernet_interrupt_handler(int, void *); | |
91 + } | |
92 + | |
93 + chunk LKM::code() | |
94 + { | |
95 + static enum irqreturn rtx_ethernet_interrupt_handler(int irq, void *dev_id) | |
96 + { | |
97 + ${pointcut ::IMPLEMENTATION}; | |
98 + } | |
99 + } | |
100 + } | |
101 + | |
102 + template sequence Ethernet::init(PCI::Device dev) | |
103 + { | |
104 + chunk LKM::data() | |
105 + { | |
106 + /* | |
107 + * This typedef is needed to workaround a bug in CNorm __std__ | |
108 + * dialect. | |
109 + */ | |
110 + typedef int ${Ethernet::Device}; | |
111 + | |
112 + static ${Ethernet::Device} *rtx_net_dev = NULL; | |
113 + } | |
114 + | |
115 + chunk ::CALL | |
116 + { | |
117 + /* | |
118 + * int should be replaced by the sizeof an hypothetic "context" | |
119 + * structure defined in the front-end. | |
120 + */ | |
121 + rtx_net_dev = alloc_etherdev(sizeof(int)); | |
122 + /* | |
123 + * if (rtx_net_dev == NULL) | |
124 + * { | |
125 + * // What can we do here? | |
126 + * } | |
127 + */ | |
128 + } | |
129 + } | |
130 + | |
131 + template sequence Ethernet::exit(PCI::Device dev) | |
132 + { | |
133 + chunk ::CALL | |
134 + { | |
135 + } | |
136 + } | |
137 +} | |
138 diff --git a/rathaxes/samples/lkm/ethernet.rti b/rathaxes/samples/lkm/ethernet.rti | |
139 new file mode 100644 | |
140 --- /dev/null | |
141 +++ b/rathaxes/samples/lkm/ethernet.rti | |
142 @@ -0,0 +1,33 @@ | |
143 +interface Ethernet : PCI, LKM | |
144 +{ | |
145 + provided type Ethernet::Device; | |
146 + | |
147 + required sequence Ethernet::open(Ethernet::Device) | |
148 + { | |
149 + provided chunk LKM::prototypes; | |
150 + provided chunk LKM::code; | |
151 + } | |
152 + | |
153 + required sequence Ethernet::close(Ethernet::Device) | |
154 + { | |
155 + provided chunk LKM::prototypes; | |
156 + provided chunk LKM::code; | |
157 + } | |
158 + | |
159 + required sequence Ethernet::interrupt_handler(Ethernet::Device) | |
160 + { | |
161 + provided chunk LKM::prototypes; | |
162 + provided chunk LKM::code; | |
163 + } | |
164 + | |
165 + provided sequence Ethernet::init(PCI::Device) | |
166 + { | |
167 + provided chunk LKM::data; | |
168 + provided chunk ::CALL; | |
169 + } | |
170 + | |
171 + provided sequence Ethernet::exit(PCI::Device) | |
172 + { | |
173 + provided chunk ::CALL; | |
174 + } | |
175 +} | |
176 diff --git a/rathaxes/samples/lkm/lkm.rtx b/rathaxes/samples/lkm/lkm.rtx | |
177 --- a/rathaxes/samples/lkm/lkm.rtx | |
178 +++ b/rathaxes/samples/lkm/lkm.rtx | |
179 @@ -1,13 +1,24 @@ | |
180 device LKM use LKM, PCI, Log | |
181 { | |
182 + Ethernet::open(Ethernet::Device dev) | |
183 + { | |
184 + } | |
185 + | |
186 + Ethernet::close(Ethernet::Device dev) | |
187 + { | |
188 + } | |
189 + | |
190 + Ethernet::interrupt_handler(Ethernet::Device dev) | |
191 + { | |
192 + } | |
193 + | |
194 PCI::probe(PCI::Device dev) | |
195 { | |
196 - | |
197 + Ethernet::init(dev); | |
198 } | |
199 | |
200 PCI::remove(PCI::Device dev) | |
201 { | |
202 - | |
203 } | |
204 | |
205 LKM::init() | |
206 diff --git a/rathaxes/samples/lkm/pci.blt b/rathaxes/samples/lkm/pci.blt | |
207 --- a/rathaxes/samples/lkm/pci.blt | |
208 +++ b/rathaxes/samples/lkm/pci.blt | |
209 @@ -11,15 +11,12 @@ | |
210 | |
211 chunk ::decl() | |
212 { | |
213 - struct rtx_pci_device | |
214 - { | |
215 - struct pci_dev *pci_dev; | |
216 - }; | |
217 + struct pci_dev; | |
218 } | |
219 | |
220 chunk ::init(pci_dev) | |
221 { | |
222 - ${self}.pci_dev = pci_dev; | |
223 + ${self} = ${pci_dev}; | |
224 } | |
225 | |
226 map | |
227 @@ -40,11 +37,7 @@ | |
228 static int /* __devinit */ rtx_pci_probe(struct pci_dev *pdev, | |
229 const struct pci_device_id *pdev_id) | |
230 { | |
231 - /* workaround for CNorm __std__ dialect, shouldn't be here */ | |
232 - typedef int ${PCI::Device}; | |
233 - | |
234 int err; | |
235 - ${PCI::Device} *dev = NULL; | |
236 | |
237 err = pci_enable_device(pdev); | |
238 // if (err < 0) /* `if' doesn't work */ | |
239 @@ -52,8 +45,6 @@ | |
240 | |
241 ${pointcut ::IMPLEMENTATION}; | |
242 | |
243 - pci_set_drvdata(pdev, dev); | |
244 - | |
245 return 0; | |
246 | |
247 fail: |