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