This source file includes following definitions.
- rio_match_device
- rio_dev_get
- rio_dev_put
- rio_device_probe
- rio_device_remove
- rio_device_shutdown
- rio_register_driver
- rio_unregister_driver
- rio_attach_device
- rio_match_bus
- rio_uevent
- rio_bus_init
1
2
3
4
5
6
7
8
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/rio.h>
12 #include <linux/rio_ids.h>
13
14 #include "rio.h"
15
16
17
18
19
20
21
22
23
24
25 static const struct rio_device_id *rio_match_device(const struct rio_device_id
26 *id,
27 const struct rio_dev *rdev)
28 {
29 while (id->vid || id->asm_vid) {
30 if (((id->vid == RIO_ANY_ID) || (id->vid == rdev->vid)) &&
31 ((id->did == RIO_ANY_ID) || (id->did == rdev->did)) &&
32 ((id->asm_vid == RIO_ANY_ID)
33 || (id->asm_vid == rdev->asm_vid))
34 && ((id->asm_did == RIO_ANY_ID)
35 || (id->asm_did == rdev->asm_did)))
36 return id;
37 id++;
38 }
39 return NULL;
40 }
41
42
43
44
45
46
47
48
49
50
51
52
53 struct rio_dev *rio_dev_get(struct rio_dev *rdev)
54 {
55 if (rdev)
56 get_device(&rdev->dev);
57
58 return rdev;
59 }
60
61
62
63
64
65
66
67
68
69
70 void rio_dev_put(struct rio_dev *rdev)
71 {
72 if (rdev)
73 put_device(&rdev->dev);
74 }
75
76
77
78
79
80
81
82 static int rio_device_probe(struct device *dev)
83 {
84 struct rio_driver *rdrv = to_rio_driver(dev->driver);
85 struct rio_dev *rdev = to_rio_dev(dev);
86 int error = -ENODEV;
87 const struct rio_device_id *id;
88
89 if (!rdev->driver && rdrv->probe) {
90 if (!rdrv->id_table)
91 return error;
92 id = rio_match_device(rdrv->id_table, rdev);
93 rio_dev_get(rdev);
94 if (id)
95 error = rdrv->probe(rdev, id);
96 if (error >= 0) {
97 rdev->driver = rdrv;
98 error = 0;
99 } else
100 rio_dev_put(rdev);
101 }
102 return error;
103 }
104
105
106
107
108
109
110
111
112
113
114 static int rio_device_remove(struct device *dev)
115 {
116 struct rio_dev *rdev = to_rio_dev(dev);
117 struct rio_driver *rdrv = rdev->driver;
118
119 if (rdrv) {
120 if (rdrv->remove)
121 rdrv->remove(rdev);
122 rdev->driver = NULL;
123 }
124
125 rio_dev_put(rdev);
126
127 return 0;
128 }
129
130 static void rio_device_shutdown(struct device *dev)
131 {
132 struct rio_dev *rdev = to_rio_dev(dev);
133 struct rio_driver *rdrv = rdev->driver;
134
135 dev_dbg(dev, "RIO: %s\n", __func__);
136
137 if (rdrv && rdrv->shutdown)
138 rdrv->shutdown(rdev);
139 }
140
141
142
143
144
145
146
147
148
149
150 int rio_register_driver(struct rio_driver *rdrv)
151 {
152
153 rdrv->driver.name = rdrv->name;
154 rdrv->driver.bus = &rio_bus_type;
155
156
157 return driver_register(&rdrv->driver);
158 }
159
160
161
162
163
164
165
166
167
168
169 void rio_unregister_driver(struct rio_driver *rdrv)
170 {
171 driver_unregister(&rdrv->driver);
172 }
173
174 void rio_attach_device(struct rio_dev *rdev)
175 {
176 rdev->dev.bus = &rio_bus_type;
177 }
178 EXPORT_SYMBOL_GPL(rio_attach_device);
179
180
181
182
183
184
185
186
187
188
189
190 static int rio_match_bus(struct device *dev, struct device_driver *drv)
191 {
192 struct rio_dev *rdev = to_rio_dev(dev);
193 struct rio_driver *rdrv = to_rio_driver(drv);
194 const struct rio_device_id *id = rdrv->id_table;
195 const struct rio_device_id *found_id;
196
197 if (!id)
198 goto out;
199
200 found_id = rio_match_device(id, rdev);
201
202 if (found_id)
203 return 1;
204
205 out:return 0;
206 }
207
208 static int rio_uevent(struct device *dev, struct kobj_uevent_env *env)
209 {
210 struct rio_dev *rdev;
211
212 if (!dev)
213 return -ENODEV;
214
215 rdev = to_rio_dev(dev);
216 if (!rdev)
217 return -ENODEV;
218
219 if (add_uevent_var(env, "MODALIAS=rapidio:v%04Xd%04Xav%04Xad%04X",
220 rdev->vid, rdev->did, rdev->asm_vid, rdev->asm_did))
221 return -ENOMEM;
222 return 0;
223 }
224
225 struct class rio_mport_class = {
226 .name = "rapidio_port",
227 .owner = THIS_MODULE,
228 .dev_groups = rio_mport_groups,
229 };
230 EXPORT_SYMBOL_GPL(rio_mport_class);
231
232 struct bus_type rio_bus_type = {
233 .name = "rapidio",
234 .match = rio_match_bus,
235 .dev_groups = rio_dev_groups,
236 .bus_groups = rio_bus_groups,
237 .probe = rio_device_probe,
238 .remove = rio_device_remove,
239 .shutdown = rio_device_shutdown,
240 .uevent = rio_uevent,
241 };
242
243
244
245
246
247
248
249 static int __init rio_bus_init(void)
250 {
251 int ret;
252
253 ret = class_register(&rio_mport_class);
254 if (!ret) {
255 ret = bus_register(&rio_bus_type);
256 if (ret)
257 class_unregister(&rio_mport_class);
258 }
259 return ret;
260 }
261
262 postcore_initcall(rio_bus_init);
263
264 EXPORT_SYMBOL_GPL(rio_register_driver);
265 EXPORT_SYMBOL_GPL(rio_unregister_driver);
266 EXPORT_SYMBOL_GPL(rio_bus_type);
267 EXPORT_SYMBOL_GPL(rio_dev_get);
268 EXPORT_SYMBOL_GPL(rio_dev_put);