diff options
Diffstat (limited to 'include/linux/rio_drv.h')
-rw-r--r-- | include/linux/rio_drv.h | 469 |
1 files changed, 469 insertions, 0 deletions
diff --git a/include/linux/rio_drv.h b/include/linux/rio_drv.h new file mode 100644 index 000000000000..7483dfc0dfa3 --- /dev/null +++ b/include/linux/rio_drv.h | |||
@@ -0,0 +1,469 @@ | |||
1 | /* | ||
2 | * RapidIO driver services | ||
3 | * | ||
4 | * Copyright 2005 MontaVista Software, Inc. | ||
5 | * Matt Porter <mporter@kernel.crashing.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the | ||
9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
10 | * option) any later version. | ||
11 | */ | ||
12 | |||
13 | #ifndef LINUX_RIO_DRV_H | ||
14 | #define LINUX_RIO_DRV_H | ||
15 | |||
16 | #ifdef __KERNEL__ | ||
17 | |||
18 | #include <linux/types.h> | ||
19 | #include <linux/config.h> | ||
20 | #include <linux/ioport.h> | ||
21 | #include <linux/list.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/device.h> | ||
24 | #include <linux/rio.h> | ||
25 | |||
26 | extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset, | ||
27 | u32 * data); | ||
28 | extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset, | ||
29 | u32 data); | ||
30 | extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset, | ||
31 | u16 * data); | ||
32 | extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset, | ||
33 | u16 data); | ||
34 | extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset, | ||
35 | u8 * data); | ||
36 | extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset, | ||
37 | u8 data); | ||
38 | |||
39 | extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid, | ||
40 | u8 hopcount, u32 offset, u32 * data); | ||
41 | extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid, | ||
42 | u8 hopcount, u32 offset, u32 data); | ||
43 | extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid, | ||
44 | u8 hopcount, u32 offset, u16 * data); | ||
45 | extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid, | ||
46 | u8 hopcount, u32 offset, u16 data); | ||
47 | extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid, | ||
48 | u8 hopcount, u32 offset, u8 * data); | ||
49 | extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid, | ||
50 | u8 hopcount, u32 offset, u8 data); | ||
51 | |||
52 | /** | ||
53 | * rio_local_read_config_32 - Read 32 bits from local configuration space | ||
54 | * @port: Master port | ||
55 | * @offset: Offset into local configuration space | ||
56 | * @data: Pointer to read data into | ||
57 | * | ||
58 | * Reads 32 bits of data from the specified offset within the local | ||
59 | * device's configuration space. | ||
60 | */ | ||
61 | static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset, | ||
62 | u32 * data) | ||
63 | { | ||
64 | return __rio_local_read_config_32(port, offset, data); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * rio_local_write_config_32 - Write 32 bits to local configuration space | ||
69 | * @port: Master port | ||
70 | * @offset: Offset into local configuration space | ||
71 | * @data: Data to be written | ||
72 | * | ||
73 | * Writes 32 bits of data to the specified offset within the local | ||
74 | * device's configuration space. | ||
75 | */ | ||
76 | static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset, | ||
77 | u32 data) | ||
78 | { | ||
79 | return __rio_local_write_config_32(port, offset, data); | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * rio_local_read_config_16 - Read 16 bits from local configuration space | ||
84 | * @port: Master port | ||
85 | * @offset: Offset into local configuration space | ||
86 | * @data: Pointer to read data into | ||
87 | * | ||
88 | * Reads 16 bits of data from the specified offset within the local | ||
89 | * device's configuration space. | ||
90 | */ | ||
91 | static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset, | ||
92 | u16 * data) | ||
93 | { | ||
94 | return __rio_local_read_config_16(port, offset, data); | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * rio_local_write_config_16 - Write 16 bits to local configuration space | ||
99 | * @port: Master port | ||
100 | * @offset: Offset into local configuration space | ||
101 | * @data: Data to be written | ||
102 | * | ||
103 | * Writes 16 bits of data to the specified offset within the local | ||
104 | * device's configuration space. | ||
105 | */ | ||
106 | |||
107 | static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset, | ||
108 | u16 data) | ||
109 | { | ||
110 | return __rio_local_write_config_16(port, offset, data); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * rio_local_read_config_8 - Read 8 bits from local configuration space | ||
115 | * @port: Master port | ||
116 | * @offset: Offset into local configuration space | ||
117 | * @data: Pointer to read data into | ||
118 | * | ||
119 | * Reads 8 bits of data from the specified offset within the local | ||
120 | * device's configuration space. | ||
121 | */ | ||
122 | static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset, | ||
123 | u8 * data) | ||
124 | { | ||
125 | return __rio_local_read_config_8(port, offset, data); | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * rio_local_write_config_8 - Write 8 bits to local configuration space | ||
130 | * @port: Master port | ||
131 | * @offset: Offset into local configuration space | ||
132 | * @data: Data to be written | ||
133 | * | ||
134 | * Writes 8 bits of data to the specified offset within the local | ||
135 | * device's configuration space. | ||
136 | */ | ||
137 | static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset, | ||
138 | u8 data) | ||
139 | { | ||
140 | return __rio_local_write_config_8(port, offset, data); | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * rio_read_config_32 - Read 32 bits from configuration space | ||
145 | * @rdev: RIO device | ||
146 | * @offset: Offset into device configuration space | ||
147 | * @data: Pointer to read data into | ||
148 | * | ||
149 | * Reads 32 bits of data from the specified offset within the | ||
150 | * RIO device's configuration space. | ||
151 | */ | ||
152 | static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset, | ||
153 | u32 * data) | ||
154 | { | ||
155 | u8 hopcount = 0xff; | ||
156 | u16 destid = rdev->destid; | ||
157 | |||
158 | if (rdev->rswitch) { | ||
159 | destid = rdev->rswitch->destid; | ||
160 | hopcount = rdev->rswitch->hopcount; | ||
161 | } | ||
162 | |||
163 | return rio_mport_read_config_32(rdev->net->hport, destid, hopcount, | ||
164 | offset, data); | ||
165 | }; | ||
166 | |||
167 | /** | ||
168 | * rio_write_config_32 - Write 32 bits to configuration space | ||
169 | * @rdev: RIO device | ||
170 | * @offset: Offset into device configuration space | ||
171 | * @data: Data to be written | ||
172 | * | ||
173 | * Writes 32 bits of data to the specified offset within the | ||
174 | * RIO device's configuration space. | ||
175 | */ | ||
176 | static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset, | ||
177 | u32 data) | ||
178 | { | ||
179 | u8 hopcount = 0xff; | ||
180 | u16 destid = rdev->destid; | ||
181 | |||
182 | if (rdev->rswitch) { | ||
183 | destid = rdev->rswitch->destid; | ||
184 | hopcount = rdev->rswitch->hopcount; | ||
185 | } | ||
186 | |||
187 | return rio_mport_write_config_32(rdev->net->hport, destid, hopcount, | ||
188 | offset, data); | ||
189 | }; | ||
190 | |||
191 | /** | ||
192 | * rio_read_config_16 - Read 16 bits from configuration space | ||
193 | * @rdev: RIO device | ||
194 | * @offset: Offset into device configuration space | ||
195 | * @data: Pointer to read data into | ||
196 | * | ||
197 | * Reads 16 bits of data from the specified offset within the | ||
198 | * RIO device's configuration space. | ||
199 | */ | ||
200 | static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset, | ||
201 | u16 * data) | ||
202 | { | ||
203 | u8 hopcount = 0xff; | ||
204 | u16 destid = rdev->destid; | ||
205 | |||
206 | if (rdev->rswitch) { | ||
207 | destid = rdev->rswitch->destid; | ||
208 | hopcount = rdev->rswitch->hopcount; | ||
209 | } | ||
210 | |||
211 | return rio_mport_read_config_16(rdev->net->hport, destid, hopcount, | ||
212 | offset, data); | ||
213 | }; | ||
214 | |||
215 | /** | ||
216 | * rio_write_config_16 - Write 16 bits to configuration space | ||
217 | * @rdev: RIO device | ||
218 | * @offset: Offset into device configuration space | ||
219 | * @data: Data to be written | ||
220 | * | ||
221 | * Writes 16 bits of data to the specified offset within the | ||
222 | * RIO device's configuration space. | ||
223 | */ | ||
224 | static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset, | ||
225 | u16 data) | ||
226 | { | ||
227 | u8 hopcount = 0xff; | ||
228 | u16 destid = rdev->destid; | ||
229 | |||
230 | if (rdev->rswitch) { | ||
231 | destid = rdev->rswitch->destid; | ||
232 | hopcount = rdev->rswitch->hopcount; | ||
233 | } | ||
234 | |||
235 | return rio_mport_write_config_16(rdev->net->hport, destid, hopcount, | ||
236 | offset, data); | ||
237 | }; | ||
238 | |||
239 | /** | ||
240 | * rio_read_config_8 - Read 8 bits from configuration space | ||
241 | * @rdev: RIO device | ||
242 | * @offset: Offset into device configuration space | ||
243 | * @data: Pointer to read data into | ||
244 | * | ||
245 | * Reads 8 bits of data from the specified offset within the | ||
246 | * RIO device's configuration space. | ||
247 | */ | ||
248 | static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data) | ||
249 | { | ||
250 | u8 hopcount = 0xff; | ||
251 | u16 destid = rdev->destid; | ||
252 | |||
253 | if (rdev->rswitch) { | ||
254 | destid = rdev->rswitch->destid; | ||
255 | hopcount = rdev->rswitch->hopcount; | ||
256 | } | ||
257 | |||
258 | return rio_mport_read_config_8(rdev->net->hport, destid, hopcount, | ||
259 | offset, data); | ||
260 | }; | ||
261 | |||
262 | /** | ||
263 | * rio_write_config_8 - Write 8 bits to configuration space | ||
264 | * @rdev: RIO device | ||
265 | * @offset: Offset into device configuration space | ||
266 | * @data: Data to be written | ||
267 | * | ||
268 | * Writes 8 bits of data to the specified offset within the | ||
269 | * RIO device's configuration space. | ||
270 | */ | ||
271 | static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data) | ||
272 | { | ||
273 | u8 hopcount = 0xff; | ||
274 | u16 destid = rdev->destid; | ||
275 | |||
276 | if (rdev->rswitch) { | ||
277 | destid = rdev->rswitch->destid; | ||
278 | hopcount = rdev->rswitch->hopcount; | ||
279 | } | ||
280 | |||
281 | return rio_mport_write_config_8(rdev->net->hport, destid, hopcount, | ||
282 | offset, data); | ||
283 | }; | ||
284 | |||
285 | extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, | ||
286 | u16 data); | ||
287 | |||
288 | /** | ||
289 | * rio_send_doorbell - Send a doorbell message to a device | ||
290 | * @rdev: RIO device | ||
291 | * @data: Doorbell message data | ||
292 | * | ||
293 | * Send a doorbell message to a RIO device. The doorbell message | ||
294 | * has a 16-bit info field provided by the @data argument. | ||
295 | */ | ||
296 | static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data) | ||
297 | { | ||
298 | return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data); | ||
299 | }; | ||
300 | |||
301 | /** | ||
302 | * rio_init_mbox_res - Initialize a RIO mailbox resource | ||
303 | * @res: resource struct | ||
304 | * @start: start of mailbox range | ||
305 | * @end: end of mailbox range | ||
306 | * | ||
307 | * This function is used to initialize the fields of a resource | ||
308 | * for use as a mailbox resource. It initializes a range of | ||
309 | * mailboxes using the start and end arguments. | ||
310 | */ | ||
311 | static inline void rio_init_mbox_res(struct resource *res, int start, int end) | ||
312 | { | ||
313 | memset(res, 0, sizeof(struct resource)); | ||
314 | res->start = start; | ||
315 | res->end = end; | ||
316 | res->flags = RIO_RESOURCE_MAILBOX; | ||
317 | } | ||
318 | |||
319 | /** | ||
320 | * rio_init_dbell_res - Initialize a RIO doorbell resource | ||
321 | * @res: resource struct | ||
322 | * @start: start of doorbell range | ||
323 | * @end: end of doorbell range | ||
324 | * | ||
325 | * This function is used to initialize the fields of a resource | ||
326 | * for use as a doorbell resource. It initializes a range of | ||
327 | * doorbell messages using the start and end arguments. | ||
328 | */ | ||
329 | static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end) | ||
330 | { | ||
331 | memset(res, 0, sizeof(struct resource)); | ||
332 | res->start = start; | ||
333 | res->end = end; | ||
334 | res->flags = RIO_RESOURCE_DOORBELL; | ||
335 | } | ||
336 | |||
337 | /** | ||
338 | * RIO_DEVICE - macro used to describe a specific RIO device | ||
339 | * @vid: the 16 bit RIO vendor ID | ||
340 | * @did: the 16 bit RIO device ID | ||
341 | * | ||
342 | * This macro is used to create a struct rio_device_id that matches a | ||
343 | * specific device. The assembly vendor and assembly device fields | ||
344 | * will be set to %RIO_ANY_ID. | ||
345 | */ | ||
346 | #define RIO_DEVICE(dev,ven) \ | ||
347 | .did = (dev), .vid = (ven), \ | ||
348 | .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID | ||
349 | |||
350 | /* Mailbox management */ | ||
351 | extern int rio_request_outb_mbox(struct rio_mport *, int, int, | ||
352 | void (*)(struct rio_mport *, int, int)); | ||
353 | extern int rio_release_outb_mbox(struct rio_mport *, int); | ||
354 | |||
355 | /** | ||
356 | * rio_add_outb_message - Add RIO message to an outbound mailbox queue | ||
357 | * @mport: RIO master port containing the outbound queue | ||
358 | * @rdev: RIO device the message is be sent to | ||
359 | * @mbox: The outbound mailbox queue | ||
360 | * @buffer: Pointer to the message buffer | ||
361 | * @len: Length of the message buffer | ||
362 | * | ||
363 | * Adds a RIO message buffer to an outbound mailbox queue for | ||
364 | * transmission. Returns 0 on success. | ||
365 | */ | ||
366 | static inline int rio_add_outb_message(struct rio_mport *mport, | ||
367 | struct rio_dev *rdev, int mbox, | ||
368 | void *buffer, size_t len) | ||
369 | { | ||
370 | return rio_hw_add_outb_message(mport, rdev, mbox, buffer, len); | ||
371 | } | ||
372 | |||
373 | extern int rio_request_inb_mbox(struct rio_mport *, int, int, | ||
374 | void (*)(struct rio_mport *, int, int)); | ||
375 | extern int rio_release_inb_mbox(struct rio_mport *, int); | ||
376 | |||
377 | /** | ||
378 | * rio_add_inb_buffer - Add buffer to an inbound mailbox queue | ||
379 | * @mport: Master port containing the inbound mailbox | ||
380 | * @mbox: The inbound mailbox number | ||
381 | * @buffer: Pointer to the message buffer | ||
382 | * | ||
383 | * Adds a buffer to an inbound mailbox queue for reception. Returns | ||
384 | * 0 on success. | ||
385 | */ | ||
386 | static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox, | ||
387 | void *buffer) | ||
388 | { | ||
389 | return rio_hw_add_inb_buffer(mport, mbox, buffer); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * rio_get_inb_message - Get A RIO message from an inbound mailbox queue | ||
394 | * @mport: Master port containing the inbound mailbox | ||
395 | * @mbox: The inbound mailbox number | ||
396 | * @buffer: Pointer to the message buffer | ||
397 | * | ||
398 | * Get a RIO message from an inbound mailbox queue. Returns 0 on success. | ||
399 | */ | ||
400 | static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox) | ||
401 | { | ||
402 | return rio_hw_get_inb_message(mport, mbox); | ||
403 | } | ||
404 | |||
405 | /* Doorbell management */ | ||
406 | extern int rio_request_inb_dbell(struct rio_mport *, u16, u16, | ||
407 | void (*)(struct rio_mport *, u16, u16, u16)); | ||
408 | extern int rio_release_inb_dbell(struct rio_mport *, u16, u16); | ||
409 | extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16); | ||
410 | extern int rio_release_outb_dbell(struct rio_dev *, struct resource *); | ||
411 | |||
412 | /* Memory region management */ | ||
413 | int rio_claim_resource(struct rio_dev *, int); | ||
414 | int rio_request_regions(struct rio_dev *, char *); | ||
415 | void rio_release_regions(struct rio_dev *); | ||
416 | int rio_request_region(struct rio_dev *, int, char *); | ||
417 | void rio_release_region(struct rio_dev *, int); | ||
418 | |||
419 | /* LDM support */ | ||
420 | int rio_register_driver(struct rio_driver *); | ||
421 | void rio_unregister_driver(struct rio_driver *); | ||
422 | struct rio_dev *rio_dev_get(struct rio_dev *); | ||
423 | void rio_dev_put(struct rio_dev *); | ||
424 | |||
425 | /** | ||
426 | * rio_name - Get the unique RIO device identifier | ||
427 | * @rdev: RIO device | ||
428 | * | ||
429 | * Get the unique RIO device identifier. Returns the device | ||
430 | * identifier string. | ||
431 | */ | ||
432 | static inline char *rio_name(struct rio_dev *rdev) | ||
433 | { | ||
434 | return rdev->dev.bus_id; | ||
435 | } | ||
436 | |||
437 | /** | ||
438 | * rio_get_drvdata - Get RIO driver specific data | ||
439 | * @rdev: RIO device | ||
440 | * | ||
441 | * Get RIO driver specific data. Returns a pointer to the | ||
442 | * driver specific data. | ||
443 | */ | ||
444 | static inline void *rio_get_drvdata(struct rio_dev *rdev) | ||
445 | { | ||
446 | return dev_get_drvdata(&rdev->dev); | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * rio_set_drvdata - Set RIO driver specific data | ||
451 | * @rdev: RIO device | ||
452 | * @data: Pointer to driver specific data | ||
453 | * | ||
454 | * Set RIO driver specific data. device struct driver data pointer | ||
455 | * is set to the @data argument. | ||
456 | */ | ||
457 | static inline void rio_set_drvdata(struct rio_dev *rdev, void *data) | ||
458 | { | ||
459 | dev_set_drvdata(&rdev->dev, data); | ||
460 | } | ||
461 | |||
462 | /* Misc driver helpers */ | ||
463 | extern u16 rio_local_get_device_id(struct rio_mport *port); | ||
464 | extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from); | ||
465 | extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did, | ||
466 | struct rio_dev *from); | ||
467 | |||
468 | #endif /* __KERNEL__ */ | ||
469 | #endif /* LINUX_RIO_DRV_H */ | ||