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
16 #include <linux/types.h>
17 #include <linux/ioport.h>
18 #include <linux/list.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
21 #include <linux/rio.h>
23 extern int __rio_local_read_config_32(struct rio_mport
*port
, u32 offset
,
25 extern int __rio_local_write_config_32(struct rio_mport
*port
, u32 offset
,
27 extern int __rio_local_read_config_16(struct rio_mport
*port
, u32 offset
,
29 extern int __rio_local_write_config_16(struct rio_mport
*port
, u32 offset
,
31 extern int __rio_local_read_config_8(struct rio_mport
*port
, u32 offset
,
33 extern int __rio_local_write_config_8(struct rio_mport
*port
, u32 offset
,
36 extern int rio_mport_read_config_32(struct rio_mport
*port
, u16 destid
,
37 u8 hopcount
, u32 offset
, u32
* data
);
38 extern int rio_mport_write_config_32(struct rio_mport
*port
, u16 destid
,
39 u8 hopcount
, u32 offset
, u32 data
);
40 extern int rio_mport_read_config_16(struct rio_mport
*port
, u16 destid
,
41 u8 hopcount
, u32 offset
, u16
* data
);
42 extern int rio_mport_write_config_16(struct rio_mport
*port
, u16 destid
,
43 u8 hopcount
, u32 offset
, u16 data
);
44 extern int rio_mport_read_config_8(struct rio_mport
*port
, u16 destid
,
45 u8 hopcount
, u32 offset
, u8
* data
);
46 extern int rio_mport_write_config_8(struct rio_mport
*port
, u16 destid
,
47 u8 hopcount
, u32 offset
, u8 data
);
50 * rio_local_read_config_32 - Read 32 bits from local configuration space
52 * @offset: Offset into local configuration space
53 * @data: Pointer to read data into
55 * Reads 32 bits of data from the specified offset within the local
56 * device's configuration space.
58 static inline int rio_local_read_config_32(struct rio_mport
*port
, u32 offset
,
61 return __rio_local_read_config_32(port
, offset
, data
);
65 * rio_local_write_config_32 - Write 32 bits to local configuration space
67 * @offset: Offset into local configuration space
68 * @data: Data to be written
70 * Writes 32 bits of data to the specified offset within the local
71 * device's configuration space.
73 static inline int rio_local_write_config_32(struct rio_mport
*port
, u32 offset
,
76 return __rio_local_write_config_32(port
, offset
, data
);
80 * rio_local_read_config_16 - Read 16 bits from local configuration space
82 * @offset: Offset into local configuration space
83 * @data: Pointer to read data into
85 * Reads 16 bits of data from the specified offset within the local
86 * device's configuration space.
88 static inline int rio_local_read_config_16(struct rio_mport
*port
, u32 offset
,
91 return __rio_local_read_config_16(port
, offset
, data
);
95 * rio_local_write_config_16 - Write 16 bits to local configuration space
97 * @offset: Offset into local configuration space
98 * @data: Data to be written
100 * Writes 16 bits of data to the specified offset within the local
101 * device's configuration space.
104 static inline int rio_local_write_config_16(struct rio_mport
*port
, u32 offset
,
107 return __rio_local_write_config_16(port
, offset
, data
);
111 * rio_local_read_config_8 - Read 8 bits from local configuration space
113 * @offset: Offset into local configuration space
114 * @data: Pointer to read data into
116 * Reads 8 bits of data from the specified offset within the local
117 * device's configuration space.
119 static inline int rio_local_read_config_8(struct rio_mport
*port
, u32 offset
,
122 return __rio_local_read_config_8(port
, offset
, data
);
126 * rio_local_write_config_8 - Write 8 bits to local configuration space
128 * @offset: Offset into local configuration space
129 * @data: Data to be written
131 * Writes 8 bits of data to the specified offset within the local
132 * device's configuration space.
134 static inline int rio_local_write_config_8(struct rio_mport
*port
, u32 offset
,
137 return __rio_local_write_config_8(port
, offset
, data
);
141 * rio_read_config_32 - Read 32 bits from configuration space
143 * @offset: Offset into device configuration space
144 * @data: Pointer to read data into
146 * Reads 32 bits of data from the specified offset within the
147 * RIO device's configuration space.
149 static inline int rio_read_config_32(struct rio_dev
*rdev
, u32 offset
,
152 return rio_mport_read_config_32(rdev
->net
->hport
, rdev
->destid
,
153 rdev
->hopcount
, offset
, data
);
157 * rio_write_config_32 - Write 32 bits to configuration space
159 * @offset: Offset into device configuration space
160 * @data: Data to be written
162 * Writes 32 bits of data to the specified offset within the
163 * RIO device's configuration space.
165 static inline int rio_write_config_32(struct rio_dev
*rdev
, u32 offset
,
168 return rio_mport_write_config_32(rdev
->net
->hport
, rdev
->destid
,
169 rdev
->hopcount
, offset
, data
);
173 * rio_read_config_16 - Read 16 bits from configuration space
175 * @offset: Offset into device configuration space
176 * @data: Pointer to read data into
178 * Reads 16 bits of data from the specified offset within the
179 * RIO device's configuration space.
181 static inline int rio_read_config_16(struct rio_dev
*rdev
, u32 offset
,
184 return rio_mport_read_config_16(rdev
->net
->hport
, rdev
->destid
,
185 rdev
->hopcount
, offset
, data
);
189 * rio_write_config_16 - Write 16 bits to configuration space
191 * @offset: Offset into device configuration space
192 * @data: Data to be written
194 * Writes 16 bits of data to the specified offset within the
195 * RIO device's configuration space.
197 static inline int rio_write_config_16(struct rio_dev
*rdev
, u32 offset
,
200 return rio_mport_write_config_16(rdev
->net
->hport
, rdev
->destid
,
201 rdev
->hopcount
, offset
, data
);
205 * rio_read_config_8 - Read 8 bits from configuration space
207 * @offset: Offset into device configuration space
208 * @data: Pointer to read data into
210 * Reads 8 bits of data from the specified offset within the
211 * RIO device's configuration space.
213 static inline int rio_read_config_8(struct rio_dev
*rdev
, u32 offset
, u8
* data
)
215 return rio_mport_read_config_8(rdev
->net
->hport
, rdev
->destid
,
216 rdev
->hopcount
, offset
, data
);
220 * rio_write_config_8 - Write 8 bits to configuration space
222 * @offset: Offset into device configuration space
223 * @data: Data to be written
225 * Writes 8 bits of data to the specified offset within the
226 * RIO device's configuration space.
228 static inline int rio_write_config_8(struct rio_dev
*rdev
, u32 offset
, u8 data
)
230 return rio_mport_write_config_8(rdev
->net
->hport
, rdev
->destid
,
231 rdev
->hopcount
, offset
, data
);
234 extern int rio_mport_send_doorbell(struct rio_mport
*mport
, u16 destid
,
238 * rio_send_doorbell - Send a doorbell message to a device
240 * @data: Doorbell message data
242 * Send a doorbell message to a RIO device. The doorbell message
243 * has a 16-bit info field provided by the @data argument.
245 static inline int rio_send_doorbell(struct rio_dev
*rdev
, u16 data
)
247 return rio_mport_send_doorbell(rdev
->net
->hport
, rdev
->destid
, data
);
251 * rio_init_mbox_res - Initialize a RIO mailbox resource
252 * @res: resource struct
253 * @start: start of mailbox range
254 * @end: end of mailbox range
256 * This function is used to initialize the fields of a resource
257 * for use as a mailbox resource. It initializes a range of
258 * mailboxes using the start and end arguments.
260 static inline void rio_init_mbox_res(struct resource
*res
, int start
, int end
)
262 memset(res
, 0, sizeof(struct resource
));
265 res
->flags
= RIO_RESOURCE_MAILBOX
;
269 * rio_init_dbell_res - Initialize a RIO doorbell resource
270 * @res: resource struct
271 * @start: start of doorbell range
272 * @end: end of doorbell range
274 * This function is used to initialize the fields of a resource
275 * for use as a doorbell resource. It initializes a range of
276 * doorbell messages using the start and end arguments.
278 static inline void rio_init_dbell_res(struct resource
*res
, u16 start
, u16 end
)
280 memset(res
, 0, sizeof(struct resource
));
283 res
->flags
= RIO_RESOURCE_DOORBELL
;
287 * RIO_DEVICE - macro used to describe a specific RIO device
288 * @dev: the 16 bit RIO device ID
289 * @ven: the 16 bit RIO vendor ID
291 * This macro is used to create a struct rio_device_id that matches a
292 * specific device. The assembly vendor and assembly device fields
293 * will be set to %RIO_ANY_ID.
295 #define RIO_DEVICE(dev,ven) \
296 .did = (dev), .vid = (ven), \
297 .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
299 /* Mailbox management */
300 extern int rio_request_outb_mbox(struct rio_mport
*, void *, int, int,
301 void (*)(struct rio_mport
*, void *,int, int));
302 extern int rio_release_outb_mbox(struct rio_mport
*, int);
305 * rio_add_outb_message - Add RIO message to an outbound mailbox queue
306 * @mport: RIO master port containing the outbound queue
307 * @rdev: RIO device the message is be sent to
308 * @mbox: The outbound mailbox queue
309 * @buffer: Pointer to the message buffer
310 * @len: Length of the message buffer
312 * Adds a RIO message buffer to an outbound mailbox queue for
313 * transmission. Returns 0 on success.
315 static inline int rio_add_outb_message(struct rio_mport
*mport
,
316 struct rio_dev
*rdev
, int mbox
,
317 void *buffer
, size_t len
)
319 return mport
->ops
->add_outb_message(mport
, rdev
, mbox
,
323 extern int rio_request_inb_mbox(struct rio_mport
*, void *, int, int,
324 void (*)(struct rio_mport
*, void *, int, int));
325 extern int rio_release_inb_mbox(struct rio_mport
*, int);
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
333 * Adds a buffer to an inbound mailbox queue for reception. Returns
336 static inline int rio_add_inb_buffer(struct rio_mport
*mport
, int mbox
,
339 return mport
->ops
->add_inb_buffer(mport
, mbox
, buffer
);
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
347 * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
349 static inline void *rio_get_inb_message(struct rio_mport
*mport
, int mbox
)
351 return mport
->ops
->get_inb_message(mport
, mbox
);
354 /* Doorbell management */
355 extern int rio_request_inb_dbell(struct rio_mport
*, void *, u16
, u16
,
356 void (*)(struct rio_mport
*, void *, u16
, u16
, u16
));
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
*);
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);
368 /* Memory mapping functions */
369 extern int rio_map_inb_region(struct rio_mport
*mport
, dma_addr_t local
,
370 u64 rbase
, u32 size
, u32 rflags
);
371 extern void rio_unmap_inb_region(struct rio_mport
*mport
, dma_addr_t lstart
);
373 /* Port-Write management */
374 extern int rio_request_inb_pwrite(struct rio_dev
*,
375 int (*)(struct rio_dev
*, union rio_pw_msg
*, int));
376 extern int rio_release_inb_pwrite(struct rio_dev
*);
377 extern int rio_inb_pwrite_handler(union rio_pw_msg
*pw_msg
);
380 int rio_register_driver(struct rio_driver
*);
381 void rio_unregister_driver(struct rio_driver
*);
382 struct rio_dev
*rio_dev_get(struct rio_dev
*);
383 void rio_dev_put(struct rio_dev
*);
385 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
386 extern struct dma_chan
*rio_request_dma(struct rio_dev
*rdev
);
387 extern void rio_release_dma(struct dma_chan
*dchan
);
388 extern struct dma_async_tx_descriptor
*rio_dma_prep_slave_sg(
389 struct rio_dev
*rdev
, struct dma_chan
*dchan
,
390 struct rio_dma_data
*data
,
391 enum dma_transfer_direction direction
, unsigned long flags
);
395 * rio_name - Get the unique RIO device identifier
398 * Get the unique RIO device identifier. Returns the device
401 static inline const char *rio_name(struct rio_dev
*rdev
)
403 return dev_name(&rdev
->dev
);
407 * rio_get_drvdata - Get RIO driver specific data
410 * Get RIO driver specific data. Returns a pointer to the
411 * driver specific data.
413 static inline void *rio_get_drvdata(struct rio_dev
*rdev
)
415 return dev_get_drvdata(&rdev
->dev
);
419 * rio_set_drvdata - Set RIO driver specific data
421 * @data: Pointer to driver specific data
423 * Set RIO driver specific data. device struct driver data pointer
424 * is set to the @data argument.
426 static inline void rio_set_drvdata(struct rio_dev
*rdev
, void *data
)
428 dev_set_drvdata(&rdev
->dev
, data
);
431 /* Misc driver helpers */
432 extern u16
rio_local_get_device_id(struct rio_mport
*port
);
433 extern struct rio_dev
*rio_get_device(u16 vid
, u16 did
, struct rio_dev
*from
);
434 extern struct rio_dev
*rio_get_asm(u16 vid
, u16 did
, u16 asm_vid
, u16 asm_did
,
435 struct rio_dev
*from
);
436 extern int rio_init_mports(void);
438 #endif /* LINUX_RIO_DRV_H */