xref: /linux/include/linux/rio_drv.h (revision 71e2f4dd5a65bd8dbca0b77661e75eea471168f8)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * RapidIO driver services
4  *
5  * Copyright 2005 MontaVista Software, Inc.
6  * Matt Porter <mporter@kernel.crashing.org>
7  */
8 
9 #ifndef LINUX_RIO_DRV_H
10 #define LINUX_RIO_DRV_H
11 
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>
18 
19 extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset,
20 				      u32 * data);
21 extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset,
22 				       u32 data);
23 extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset,
24 				      u16 * data);
25 extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset,
26 				       u16 data);
27 extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset,
28 				     u8 * data);
29 extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset,
30 				      u8 data);
31 
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);
44 
45 /**
46  * rio_local_read_config_32 - Read 32 bits from local configuration space
47  * @port: Master port
48  * @offset: Offset into local configuration space
49  * @data: Pointer to read data into
50  *
51  * Reads 32 bits of data from the specified offset within the local
52  * device's configuration space.
53  */
54 static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
55 					   u32 * data)
56 {
57 	return __rio_local_read_config_32(port, offset, data);
58 }
59 
60 /**
61  * rio_local_write_config_32 - Write 32 bits to local configuration space
62  * @port: Master port
63  * @offset: Offset into local configuration space
64  * @data: Data to be written
65  *
66  * Writes 32 bits of data to the specified offset within the local
67  * device's configuration space.
68  */
69 static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
70 					    u32 data)
71 {
72 	return __rio_local_write_config_32(port, offset, data);
73 }
74 
75 /**
76  * rio_local_read_config_16 - Read 16 bits from local configuration space
77  * @port: Master port
78  * @offset: Offset into local configuration space
79  * @data: Pointer to read data into
80  *
81  * Reads 16 bits of data from the specified offset within the local
82  * device's configuration space.
83  */
84 static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
85 					   u16 * data)
86 {
87 	return __rio_local_read_config_16(port, offset, data);
88 }
89 
90 /**
91  * rio_local_write_config_16 - Write 16 bits to local configuration space
92  * @port: Master port
93  * @offset: Offset into local configuration space
94  * @data: Data to be written
95  *
96  * Writes 16 bits of data to the specified offset within the local
97  * device's configuration space.
98  */
99 
100 static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
101 					    u16 data)
102 {
103 	return __rio_local_write_config_16(port, offset, data);
104 }
105 
106 /**
107  * rio_local_read_config_8 - Read 8 bits from local configuration space
108  * @port: Master port
109  * @offset: Offset into local configuration space
110  * @data: Pointer to read data into
111  *
112  * Reads 8 bits of data from the specified offset within the local
113  * device's configuration space.
114  */
115 static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
116 					  u8 * data)
117 {
118 	return __rio_local_read_config_8(port, offset, data);
119 }
120 
121 /**
122  * rio_local_write_config_8 - Write 8 bits to local configuration space
123  * @port: Master port
124  * @offset: Offset into local configuration space
125  * @data: Data to be written
126  *
127  * Writes 8 bits of data to the specified offset within the local
128  * device's configuration space.
129  */
130 static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
131 					   u8 data)
132 {
133 	return __rio_local_write_config_8(port, offset, data);
134 }
135 
136 /**
137  * rio_read_config_32 - Read 32 bits from configuration space
138  * @rdev: RIO device
139  * @offset: Offset into device configuration space
140  * @data: Pointer to read data into
141  *
142  * Reads 32 bits of data from the specified offset within the
143  * RIO device's configuration space.
144  */
145 static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
146 				     u32 * data)
147 {
148 	return rio_mport_read_config_32(rdev->net->hport, rdev->destid,
149 					rdev->hopcount, offset, data);
150 };
151 
152 /**
153  * rio_write_config_32 - Write 32 bits to configuration space
154  * @rdev: RIO device
155  * @offset: Offset into device configuration space
156  * @data: Data to be written
157  *
158  * Writes 32 bits of data to the specified offset within the
159  * RIO device's configuration space.
160  */
161 static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
162 				      u32 data)
163 {
164 	return rio_mport_write_config_32(rdev->net->hport, rdev->destid,
165 					 rdev->hopcount, offset, data);
166 };
167 
168 /**
169  * rio_read_config_16 - Read 16 bits from configuration space
170  * @rdev: RIO device
171  * @offset: Offset into device configuration space
172  * @data: Pointer to read data into
173  *
174  * Reads 16 bits of data from the specified offset within the
175  * RIO device's configuration space.
176  */
177 static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
178 				     u16 * data)
179 {
180 	return rio_mport_read_config_16(rdev->net->hport, rdev->destid,
181 					rdev->hopcount, offset, data);
182 };
183 
184 /**
185  * rio_write_config_16 - Write 16 bits to configuration space
186  * @rdev: RIO device
187  * @offset: Offset into device configuration space
188  * @data: Data to be written
189  *
190  * Writes 16 bits of data to the specified offset within the
191  * RIO device's configuration space.
192  */
193 static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
194 				      u16 data)
195 {
196 	return rio_mport_write_config_16(rdev->net->hport, rdev->destid,
197 					 rdev->hopcount, offset, data);
198 };
199 
200 /**
201  * rio_read_config_8 - Read 8 bits from configuration space
202  * @rdev: RIO device
203  * @offset: Offset into device configuration space
204  * @data: Pointer to read data into
205  *
206  * Reads 8 bits of data from the specified offset within the
207  * RIO device's configuration space.
208  */
209 static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
210 {
211 	return rio_mport_read_config_8(rdev->net->hport, rdev->destid,
212 				       rdev->hopcount, offset, data);
213 };
214 
215 /**
216  * rio_write_config_8 - Write 8 bits to configuration space
217  * @rdev: RIO device
218  * @offset: Offset into device configuration space
219  * @data: Data to be written
220  *
221  * Writes 8 bits of data to the specified offset within the
222  * RIO device's configuration space.
223  */
224 static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
225 {
226 	return rio_mport_write_config_8(rdev->net->hport, rdev->destid,
227 					rdev->hopcount, offset, data);
228 };
229 
230 extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
231 				   u16 data);
232 
233 /**
234  * rio_send_doorbell - Send a doorbell message to a device
235  * @rdev: RIO device
236  * @data: Doorbell message data
237  *
238  * Send a doorbell message to a RIO device. The doorbell message
239  * has a 16-bit info field provided by the @data argument.
240  */
241 static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
242 {
243 	return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
244 };
245 
246 /**
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
251  *
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.
255  */
256 static inline void rio_init_mbox_res(struct resource *res, int start, int end)
257 {
258 	memset(res, 0, sizeof(struct resource));
259 	res->start = start;
260 	res->end = end;
261 	res->flags = RIO_RESOURCE_MAILBOX;
262 }
263 
264 /**
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
269  *
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.
273  */
274 static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
275 {
276 	memset(res, 0, sizeof(struct resource));
277 	res->start = start;
278 	res->end = end;
279 	res->flags = RIO_RESOURCE_DOORBELL;
280 }
281 
282 /**
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
286  *
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.
290  */
291 #define RIO_DEVICE(dev,ven) \
292 	.did = (dev), .vid = (ven), \
293 	.asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
294 
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);
299 
300 /**
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
307  *
308  * Adds a RIO message buffer to an outbound mailbox queue for
309  * transmission. Returns 0 on success.
310  */
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)
314 {
315 	return mport->ops->add_outb_message(mport, rdev, mbox,
316 						   buffer, len);
317 }
318 
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);
322 
323 /**
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
328  *
329  * Adds a buffer to an inbound mailbox queue for reception. Returns
330  * 0 on success.
331  */
332 static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
333 				     void *buffer)
334 {
335 	return mport->ops->add_inb_buffer(mport, mbox, buffer);
336 }
337 
338 /**
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
342  *
343  * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
344  */
345 static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
346 {
347 	return mport->ops->get_inb_message(mport, mbox);
348 }
349 
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 *);
356 
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);
363 
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);
372 
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);
386 
387 /* LDM support */
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 *);
392 
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);
405 #endif
406 
407 /**
408  * rio_name - Get the unique RIO device identifier
409  * @rdev: RIO device
410  *
411  * Get the unique RIO device identifier. Returns the device
412  * identifier string.
413  */
414 static inline const char *rio_name(struct rio_dev *rdev)
415 {
416 	return dev_name(&rdev->dev);
417 }
418 
419 /**
420  * rio_get_drvdata - Get RIO driver specific data
421  * @rdev: RIO device
422  *
423  * Get RIO driver specific data. Returns a pointer to the
424  * driver specific data.
425  */
426 static inline void *rio_get_drvdata(struct rio_dev *rdev)
427 {
428 	return dev_get_drvdata(&rdev->dev);
429 }
430 
431 /**
432  * rio_set_drvdata - Set RIO driver specific data
433  * @rdev: RIO device
434  * @data: Pointer to driver specific data
435  *
436  * Set RIO driver specific data. device struct driver data pointer
437  * is set to the @data argument.
438  */
439 static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
440 {
441 	dev_set_drvdata(&rdev->dev, data);
442 }
443 
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 struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from);
448 extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did,
449 				   struct rio_dev *from);
450 extern int rio_init_mports(void);
451 
452 #endif				/* LINUX_RIO_DRV_H */
453