2 * RapidIO driver services
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
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.
13 #ifndef LINUX_RIO_DRV_H
14 #define LINUX_RIO_DRV_H
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>
26 extern int __rio_local_read_config_32(struct rio_mport
*port
, u32 offset
,
28 extern int __rio_local_write_config_32(struct rio_mport
*port
, u32 offset
,
30 extern int __rio_local_read_config_16(struct rio_mport
*port
, u32 offset
,
32 extern int __rio_local_write_config_16(struct rio_mport
*port
, u32 offset
,
34 extern int __rio_local_read_config_8(struct rio_mport
*port
, u32 offset
,
36 extern int __rio_local_write_config_8(struct rio_mport
*port
, u32 offset
,
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
);
53 * rio_local_read_config_32 - Read 32 bits from local configuration space
55 * @offset: Offset into local configuration space
56 * @data: Pointer to read data into
58 * Reads 32 bits of data from the specified offset within the local
59 * device's configuration space.
61 static inline int rio_local_read_config_32(struct rio_mport
*port
, u32 offset
,
64 return __rio_local_read_config_32(port
, offset
, data
);
68 * rio_local_write_config_32 - Write 32 bits to local configuration space
70 * @offset: Offset into local configuration space
71 * @data: Data to be written
73 * Writes 32 bits of data to the specified offset within the local
74 * device's configuration space.
76 static inline int rio_local_write_config_32(struct rio_mport
*port
, u32 offset
,
79 return __rio_local_write_config_32(port
, offset
, data
);
83 * rio_local_read_config_16 - Read 16 bits from local configuration space
85 * @offset: Offset into local configuration space
86 * @data: Pointer to read data into
88 * Reads 16 bits of data from the specified offset within the local
89 * device's configuration space.
91 static inline int rio_local_read_config_16(struct rio_mport
*port
, u32 offset
,
94 return __rio_local_read_config_16(port
, offset
, data
);
98 * rio_local_write_config_16 - Write 16 bits to local configuration space
100 * @offset: Offset into local configuration space
101 * @data: Data to be written
103 * Writes 16 bits of data to the specified offset within the local
104 * device's configuration space.
107 static inline int rio_local_write_config_16(struct rio_mport
*port
, u32 offset
,
110 return __rio_local_write_config_16(port
, offset
, data
);
114 * rio_local_read_config_8 - Read 8 bits from local configuration space
116 * @offset: Offset into local configuration space
117 * @data: Pointer to read data into
119 * Reads 8 bits of data from the specified offset within the local
120 * device's configuration space.
122 static inline int rio_local_read_config_8(struct rio_mport
*port
, u32 offset
,
125 return __rio_local_read_config_8(port
, offset
, data
);
129 * rio_local_write_config_8 - Write 8 bits to local configuration space
131 * @offset: Offset into local configuration space
132 * @data: Data to be written
134 * Writes 8 bits of data to the specified offset within the local
135 * device's configuration space.
137 static inline int rio_local_write_config_8(struct rio_mport
*port
, u32 offset
,
140 return __rio_local_write_config_8(port
, offset
, data
);
144 * rio_read_config_32 - Read 32 bits from configuration space
146 * @offset: Offset into device configuration space
147 * @data: Pointer to read data into
149 * Reads 32 bits of data from the specified offset within the
150 * RIO device's configuration space.
152 static inline int rio_read_config_32(struct rio_dev
*rdev
, u32 offset
,
156 u16 destid
= rdev
->destid
;
159 destid
= rdev
->rswitch
->destid
;
160 hopcount
= rdev
->rswitch
->hopcount
;
163 return rio_mport_read_config_32(rdev
->net
->hport
, destid
, hopcount
,
168 * rio_write_config_32 - Write 32 bits to configuration space
170 * @offset: Offset into device configuration space
171 * @data: Data to be written
173 * Writes 32 bits of data to the specified offset within the
174 * RIO device's configuration space.
176 static inline int rio_write_config_32(struct rio_dev
*rdev
, u32 offset
,
180 u16 destid
= rdev
->destid
;
183 destid
= rdev
->rswitch
->destid
;
184 hopcount
= rdev
->rswitch
->hopcount
;
187 return rio_mport_write_config_32(rdev
->net
->hport
, destid
, hopcount
,
192 * rio_read_config_16 - Read 16 bits from configuration space
194 * @offset: Offset into device configuration space
195 * @data: Pointer to read data into
197 * Reads 16 bits of data from the specified offset within the
198 * RIO device's configuration space.
200 static inline int rio_read_config_16(struct rio_dev
*rdev
, u32 offset
,
204 u16 destid
= rdev
->destid
;
207 destid
= rdev
->rswitch
->destid
;
208 hopcount
= rdev
->rswitch
->hopcount
;
211 return rio_mport_read_config_16(rdev
->net
->hport
, destid
, hopcount
,
216 * rio_write_config_16 - Write 16 bits to configuration space
218 * @offset: Offset into device configuration space
219 * @data: Data to be written
221 * Writes 16 bits of data to the specified offset within the
222 * RIO device's configuration space.
224 static inline int rio_write_config_16(struct rio_dev
*rdev
, u32 offset
,
228 u16 destid
= rdev
->destid
;
231 destid
= rdev
->rswitch
->destid
;
232 hopcount
= rdev
->rswitch
->hopcount
;
235 return rio_mport_write_config_16(rdev
->net
->hport
, destid
, hopcount
,
240 * rio_read_config_8 - Read 8 bits from configuration space
242 * @offset: Offset into device configuration space
243 * @data: Pointer to read data into
245 * Reads 8 bits of data from the specified offset within the
246 * RIO device's configuration space.
248 static inline int rio_read_config_8(struct rio_dev
*rdev
, u32 offset
, u8
* data
)
251 u16 destid
= rdev
->destid
;
254 destid
= rdev
->rswitch
->destid
;
255 hopcount
= rdev
->rswitch
->hopcount
;
258 return rio_mport_read_config_8(rdev
->net
->hport
, destid
, hopcount
,
263 * rio_write_config_8 - Write 8 bits to configuration space
265 * @offset: Offset into device configuration space
266 * @data: Data to be written
268 * Writes 8 bits of data to the specified offset within the
269 * RIO device's configuration space.
271 static inline int rio_write_config_8(struct rio_dev
*rdev
, u32 offset
, u8 data
)
274 u16 destid
= rdev
->destid
;
277 destid
= rdev
->rswitch
->destid
;
278 hopcount
= rdev
->rswitch
->hopcount
;
281 return rio_mport_write_config_8(rdev
->net
->hport
, destid
, hopcount
,
285 extern int rio_mport_send_doorbell(struct rio_mport
*mport
, u16 destid
,
289 * rio_send_doorbell - Send a doorbell message to a device
291 * @data: Doorbell message data
293 * Send a doorbell message to a RIO device. The doorbell message
294 * has a 16-bit info field provided by the @data argument.
296 static inline int rio_send_doorbell(struct rio_dev
*rdev
, u16 data
)
298 return rio_mport_send_doorbell(rdev
->net
->hport
, rdev
->destid
, data
);
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
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.
311 static inline void rio_init_mbox_res(struct resource
*res
, int start
, int end
)
313 memset(res
, 0, sizeof(struct resource
));
316 res
->flags
= RIO_RESOURCE_MAILBOX
;
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
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.
329 static inline void rio_init_dbell_res(struct resource
*res
, u16 start
, u16 end
)
331 memset(res
, 0, sizeof(struct resource
));
334 res
->flags
= RIO_RESOURCE_DOORBELL
;
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
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.
346 #define RIO_DEVICE(dev,ven) \
347 .did = (dev), .vid = (ven), \
348 .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
350 /* Mailbox management */
351 extern int rio_request_outb_mbox(struct rio_mport
*, void *, int, int,
352 void (*)(struct rio_mport
*, void *,int, int));
353 extern int rio_release_outb_mbox(struct rio_mport
*, int);
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
363 * Adds a RIO message buffer to an outbound mailbox queue for
364 * transmission. Returns 0 on success.
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
)
370 return rio_hw_add_outb_message(mport
, rdev
, mbox
, buffer
, len
);
373 extern int rio_request_inb_mbox(struct rio_mport
*, void *, int, int,
374 void (*)(struct rio_mport
*, void *, int, int));
375 extern int rio_release_inb_mbox(struct rio_mport
*, int);
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
383 * Adds a buffer to an inbound mailbox queue for reception. Returns
386 static inline int rio_add_inb_buffer(struct rio_mport
*mport
, int mbox
,
389 return rio_hw_add_inb_buffer(mport
, mbox
, buffer
);
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
398 * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
400 static inline void *rio_get_inb_message(struct rio_mport
*mport
, int mbox
)
402 return rio_hw_get_inb_message(mport
, mbox
);
405 /* Doorbell management */
406 extern int rio_request_inb_dbell(struct rio_mport
*, void *, u16
, u16
,
407 void (*)(struct rio_mport
*, void *, 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
*);
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);
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
*);
426 * rio_name - Get the unique RIO device identifier
429 * Get the unique RIO device identifier. Returns the device
432 static inline char *rio_name(struct rio_dev
*rdev
)
434 return rdev
->dev
.bus_id
;
438 * rio_get_drvdata - Get RIO driver specific data
441 * Get RIO driver specific data. Returns a pointer to the
442 * driver specific data.
444 static inline void *rio_get_drvdata(struct rio_dev
*rdev
)
446 return dev_get_drvdata(&rdev
->dev
);
450 * rio_set_drvdata - Set RIO driver specific data
452 * @data: Pointer to driver specific data
454 * Set RIO driver specific data. device struct driver data pointer
455 * is set to the @data argument.
457 static inline void rio_set_drvdata(struct rio_dev
*rdev
, void *data
)
459 dev_set_drvdata(&rdev
->dev
, data
);
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
);
468 #endif /* __KERNEL__ */
469 #endif /* LINUX_RIO_DRV_H */