1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * RapidIO driver services
5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org>
9 #ifndef LINUX_RIO_DRV_H
10 #define LINUX_RIO_DRV_H
12 #include <linux/types.h>
13 #include <linux/ioport.h>
14 #include <linux/list.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
17 #include <linux/rio.h>
19 extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset,
21 extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset,
23 extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset,
25 extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset,
27 extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset,
29 extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset,
32 extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid,
33 u8 hopcount, u32 offset, u32 * data);
34 extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid,
35 u8 hopcount, u32 offset, u32 data);
36 extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid,
37 u8 hopcount, u32 offset, u16 * data);
38 extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid,
39 u8 hopcount, u32 offset, u16 data);
40 extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid,
41 u8 hopcount, u32 offset, u8 * data);
42 extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid,
43 u8 hopcount, u32 offset, u8 data);
46 * rio_local_read_config_32 - Read 32 bits from local configuration space
48 * @offset: Offset into local configuration space
49 * @data: Pointer to read data into
51 * Reads 32 bits of data from the specified offset within the local
52 * device's configuration space.
54 static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
57 return __rio_local_read_config_32(port, offset, data);
61 * rio_local_write_config_32 - Write 32 bits to local configuration space
63 * @offset: Offset into local configuration space
64 * @data: Data to be written
66 * Writes 32 bits of data to the specified offset within the local
67 * device's configuration space.
69 static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
72 return __rio_local_write_config_32(port, offset, data);
76 * rio_local_read_config_16 - Read 16 bits from local configuration space
78 * @offset: Offset into local configuration space
79 * @data: Pointer to read data into
81 * Reads 16 bits of data from the specified offset within the local
82 * device's configuration space.
84 static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
87 return __rio_local_read_config_16(port, offset, data);
91 * rio_local_write_config_16 - Write 16 bits to local configuration space
93 * @offset: Offset into local configuration space
94 * @data: Data to be written
96 * Writes 16 bits of data to the specified offset within the local
97 * device's configuration space.
100 static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
103 return __rio_local_write_config_16(port, offset, data);
107 * rio_local_read_config_8 - Read 8 bits from local configuration space
109 * @offset: Offset into local configuration space
110 * @data: Pointer to read data into
112 * Reads 8 bits of data from the specified offset within the local
113 * device's configuration space.
115 static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
118 return __rio_local_read_config_8(port, offset, data);
122 * rio_local_write_config_8 - Write 8 bits to local configuration space
124 * @offset: Offset into local configuration space
125 * @data: Data to be written
127 * Writes 8 bits of data to the specified offset within the local
128 * device's configuration space.
130 static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
133 return __rio_local_write_config_8(port, offset, data);
137 * rio_read_config_32 - Read 32 bits from configuration space
139 * @offset: Offset into device configuration space
140 * @data: Pointer to read data into
142 * Reads 32 bits of data from the specified offset within the
143 * RIO device's configuration space.
145 static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
148 return rio_mport_read_config_32(rdev->net->hport, rdev->destid,
149 rdev->hopcount, offset, data);
153 * rio_write_config_32 - Write 32 bits to configuration space
155 * @offset: Offset into device configuration space
156 * @data: Data to be written
158 * Writes 32 bits of data to the specified offset within the
159 * RIO device's configuration space.
161 static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
164 return rio_mport_write_config_32(rdev->net->hport, rdev->destid,
165 rdev->hopcount, offset, data);
169 * rio_read_config_16 - Read 16 bits from configuration space
171 * @offset: Offset into device configuration space
172 * @data: Pointer to read data into
174 * Reads 16 bits of data from the specified offset within the
175 * RIO device's configuration space.
177 static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
180 return rio_mport_read_config_16(rdev->net->hport, rdev->destid,
181 rdev->hopcount, offset, data);
185 * rio_write_config_16 - Write 16 bits to configuration space
187 * @offset: Offset into device configuration space
188 * @data: Data to be written
190 * Writes 16 bits of data to the specified offset within the
191 * RIO device's configuration space.
193 static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
196 return rio_mport_write_config_16(rdev->net->hport, rdev->destid,
197 rdev->hopcount, offset, data);
201 * rio_read_config_8 - Read 8 bits from configuration space
203 * @offset: Offset into device configuration space
204 * @data: Pointer to read data into
206 * Reads 8 bits of data from the specified offset within the
207 * RIO device's configuration space.
209 static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
211 return rio_mport_read_config_8(rdev->net->hport, rdev->destid,
212 rdev->hopcount, offset, data);
216 * rio_write_config_8 - Write 8 bits to configuration space
218 * @offset: Offset into device configuration space
219 * @data: Data to be written
221 * Writes 8 bits of data to the specified offset within the
222 * RIO device's configuration space.
224 static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
226 return rio_mport_write_config_8(rdev->net->hport, rdev->destid,
227 rdev->hopcount, offset, data);
230 extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
234 * rio_send_doorbell - Send a doorbell message to a device
236 * @data: Doorbell message data
238 * Send a doorbell message to a RIO device. The doorbell message
239 * has a 16-bit info field provided by the @data argument.
241 static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
243 return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
247 * rio_init_mbox_res - Initialize a RIO mailbox resource
248 * @res: resource struct
249 * @start: start of mailbox range
250 * @end: end of mailbox range
252 * This function is used to initialize the fields of a resource
253 * for use as a mailbox resource. It initializes a range of
254 * mailboxes using the start and end arguments.
256 static inline void rio_init_mbox_res(struct resource *res, int start, int end)
258 memset(res, 0, sizeof(struct resource));
261 res->flags = RIO_RESOURCE_MAILBOX;
265 * rio_init_dbell_res - Initialize a RIO doorbell resource
266 * @res: resource struct
267 * @start: start of doorbell range
268 * @end: end of doorbell range
270 * This function is used to initialize the fields of a resource
271 * for use as a doorbell resource. It initializes a range of
272 * doorbell messages using the start and end arguments.
274 static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
276 memset(res, 0, sizeof(struct resource));
279 res->flags = RIO_RESOURCE_DOORBELL;
283 * RIO_DEVICE - macro used to describe a specific RIO device
284 * @dev: the 16 bit RIO device ID
285 * @ven: the 16 bit RIO vendor ID
287 * This macro is used to create a struct rio_device_id that matches a
288 * specific device. The assembly vendor and assembly device fields
289 * will be set to %RIO_ANY_ID.
291 #define RIO_DEVICE(dev,ven) \
292 .did = (dev), .vid = (ven), \
293 .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
295 /* Mailbox management */
296 extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int,
297 void (*)(struct rio_mport *, void *,int, int));
298 extern int rio_release_outb_mbox(struct rio_mport *, int);
301 * rio_add_outb_message - Add RIO message to an outbound mailbox queue
302 * @mport: RIO master port containing the outbound queue
303 * @rdev: RIO device the message is be sent to
304 * @mbox: The outbound mailbox queue
305 * @buffer: Pointer to the message buffer
306 * @len: Length of the message buffer
308 * Adds a RIO message buffer to an outbound mailbox queue for
309 * transmission. Returns 0 on success.
311 static inline int rio_add_outb_message(struct rio_mport *mport,
312 struct rio_dev *rdev, int mbox,
313 void *buffer, size_t len)
315 return mport->ops->add_outb_message(mport, rdev, mbox,
319 extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int,
320 void (*)(struct rio_mport *, void *, int, int));
321 extern int rio_release_inb_mbox(struct rio_mport *, int);
324 * rio_add_inb_buffer - Add buffer to an inbound mailbox queue
325 * @mport: Master port containing the inbound mailbox
326 * @mbox: The inbound mailbox number
327 * @buffer: Pointer to the message buffer
329 * Adds a buffer to an inbound mailbox queue for reception. Returns
332 static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
335 return mport->ops->add_inb_buffer(mport, mbox, buffer);
339 * rio_get_inb_message - Get A RIO message from an inbound mailbox queue
340 * @mport: Master port containing the inbound mailbox
341 * @mbox: The inbound mailbox number
343 * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
345 static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
347 return mport->ops->get_inb_message(mport, mbox);
350 /* Doorbell management */
351 extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16,
352 void (*)(struct rio_mport *, void *, u16, u16, u16));
353 extern int rio_release_inb_dbell(struct rio_mport *, u16, u16);
354 extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16);
355 extern int rio_release_outb_dbell(struct rio_dev *, struct resource *);
357 /* Memory region management */
358 int rio_claim_resource(struct rio_dev *, int);
359 int rio_request_regions(struct rio_dev *, char *);
360 void rio_release_regions(struct rio_dev *);
361 int rio_request_region(struct rio_dev *, int, char *);
362 void rio_release_region(struct rio_dev *, int);
364 /* Memory mapping functions */
365 extern int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
366 u64 rbase, u32 size, u32 rflags);
367 extern void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart);
368 extern int rio_map_outb_region(struct rio_mport *mport, u16 destid, u64 rbase,
369 u32 size, u32 rflags, dma_addr_t *local);
370 extern void rio_unmap_outb_region(struct rio_mport *mport,
371 u16 destid, u64 rstart);
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_add_mport_pw_handler(struct rio_mport *mport, void *dev_id,
378 int (*pwcback)(struct rio_mport *mport, void *dev_id,
379 union rio_pw_msg *msg, int step));
380 extern int rio_del_mport_pw_handler(struct rio_mport *mport, void *dev_id,
381 int (*pwcback)(struct rio_mport *mport, void *dev_id,
382 union rio_pw_msg *msg, int step));
383 extern int rio_inb_pwrite_handler(struct rio_mport *mport,
384 union rio_pw_msg *pw_msg);
385 extern void rio_pw_enable(struct rio_mport *mport, int enable);
388 int rio_register_driver(struct rio_driver *);
389 void rio_unregister_driver(struct rio_driver *);
390 struct rio_dev *rio_dev_get(struct rio_dev *);
391 void rio_dev_put(struct rio_dev *);
393 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
394 extern struct dma_chan *rio_request_dma(struct rio_dev *rdev);
395 extern struct dma_chan *rio_request_mport_dma(struct rio_mport *mport);
396 extern void rio_release_dma(struct dma_chan *dchan);
397 extern struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(
398 struct rio_dev *rdev, struct dma_chan *dchan,
399 struct rio_dma_data *data,
400 enum dma_transfer_direction direction, unsigned long flags);
401 extern struct dma_async_tx_descriptor *rio_dma_prep_xfer(
402 struct dma_chan *dchan, u16 destid,
403 struct rio_dma_data *data,
404 enum dma_transfer_direction direction, unsigned long flags);
408 * rio_name - Get the unique RIO device identifier
411 * Get the unique RIO device identifier. Returns the device
414 static inline const char *rio_name(struct rio_dev *rdev)
416 return dev_name(&rdev->dev);
420 * rio_get_drvdata - Get RIO driver specific data
423 * Get RIO driver specific data. Returns a pointer to the
424 * driver specific data.
426 static inline void *rio_get_drvdata(struct rio_dev *rdev)
428 return dev_get_drvdata(&rdev->dev);
432 * rio_set_drvdata - Set RIO driver specific data
434 * @data: Pointer to driver specific data
436 * Set RIO driver specific data. device struct driver data pointer
437 * is set to the @data argument.
439 static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
441 dev_set_drvdata(&rdev->dev, data);
444 /* Misc driver helpers */
445 extern u16 rio_local_get_device_id(struct rio_mport *port);
446 extern void rio_local_set_device_id(struct rio_mport *port, u16 did);
447 extern int rio_init_mports(void);
449 #endif /* LINUX_RIO_DRV_H */