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