blob: 7f07470e1ed9443e20cbc1cafe0d696e04bdb8c6 [file] [log] [blame]
Matt Porter70a50eb2005-11-07 01:00:16 -08001/*
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
Matt Porter70a50eb2005-11-07 01:00:16 -080016#include <linux/types.h>
Matt Porter70a50eb2005-11-07 01:00:16 -080017#include <linux/ioport.h>
18#include <linux/list.h>
19#include <linux/errno.h>
Tim Schmielaude259682006-01-08 01:02:05 -080020#include <linux/string.h>
Matt Porter70a50eb2005-11-07 01:00:16 -080021#include <linux/rio.h>
22
23extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset,
24 u32 * data);
25extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset,
26 u32 data);
27extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset,
28 u16 * data);
29extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset,
30 u16 data);
31extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset,
32 u8 * data);
33extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset,
34 u8 data);
35
36extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid,
37 u8 hopcount, u32 offset, u32 * data);
38extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid,
39 u8 hopcount, u32 offset, u32 data);
40extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid,
41 u8 hopcount, u32 offset, u16 * data);
42extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid,
43 u8 hopcount, u32 offset, u16 data);
44extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid,
45 u8 hopcount, u32 offset, u8 * data);
46extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid,
47 u8 hopcount, u32 offset, u8 data);
48
49/**
50 * rio_local_read_config_32 - Read 32 bits from local configuration space
51 * @port: Master port
52 * @offset: Offset into local configuration space
53 * @data: Pointer to read data into
54 *
55 * Reads 32 bits of data from the specified offset within the local
56 * device's configuration space.
57 */
58static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
59 u32 * data)
60{
61 return __rio_local_read_config_32(port, offset, data);
62}
63
64/**
65 * rio_local_write_config_32 - Write 32 bits to local configuration space
66 * @port: Master port
67 * @offset: Offset into local configuration space
68 * @data: Data to be written
69 *
70 * Writes 32 bits of data to the specified offset within the local
71 * device's configuration space.
72 */
73static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
74 u32 data)
75{
76 return __rio_local_write_config_32(port, offset, data);
77}
78
79/**
80 * rio_local_read_config_16 - Read 16 bits from local configuration space
81 * @port: Master port
82 * @offset: Offset into local configuration space
83 * @data: Pointer to read data into
84 *
85 * Reads 16 bits of data from the specified offset within the local
86 * device's configuration space.
87 */
88static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
89 u16 * data)
90{
91 return __rio_local_read_config_16(port, offset, data);
92}
93
94/**
95 * rio_local_write_config_16 - Write 16 bits to local configuration space
96 * @port: Master port
97 * @offset: Offset into local configuration space
98 * @data: Data to be written
99 *
100 * Writes 16 bits of data to the specified offset within the local
101 * device's configuration space.
102 */
103
104static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
105 u16 data)
106{
107 return __rio_local_write_config_16(port, offset, data);
108}
109
110/**
111 * rio_local_read_config_8 - Read 8 bits from local configuration space
112 * @port: Master port
113 * @offset: Offset into local configuration space
114 * @data: Pointer to read data into
115 *
116 * Reads 8 bits of data from the specified offset within the local
117 * device's configuration space.
118 */
119static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
120 u8 * data)
121{
122 return __rio_local_read_config_8(port, offset, data);
123}
124
125/**
126 * rio_local_write_config_8 - Write 8 bits to local configuration space
127 * @port: Master port
128 * @offset: Offset into local configuration space
129 * @data: Data to be written
130 *
131 * Writes 8 bits of data to the specified offset within the local
132 * device's configuration space.
133 */
134static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
135 u8 data)
136{
137 return __rio_local_write_config_8(port, offset, data);
138}
139
140/**
141 * rio_read_config_32 - Read 32 bits from configuration space
142 * @rdev: RIO device
143 * @offset: Offset into device configuration space
144 * @data: Pointer to read data into
145 *
146 * Reads 32 bits of data from the specified offset within the
147 * RIO device's configuration space.
148 */
149static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
150 u32 * data)
151{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800152 return rio_mport_read_config_32(rdev->net->hport, rdev->destid,
153 rdev->hopcount, offset, data);
Matt Porter70a50eb2005-11-07 01:00:16 -0800154};
155
156/**
157 * rio_write_config_32 - Write 32 bits to configuration space
158 * @rdev: RIO device
159 * @offset: Offset into device configuration space
160 * @data: Data to be written
161 *
162 * Writes 32 bits of data to the specified offset within the
163 * RIO device's configuration space.
164 */
165static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
166 u32 data)
167{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800168 return rio_mport_write_config_32(rdev->net->hport, rdev->destid,
169 rdev->hopcount, offset, data);
Matt Porter70a50eb2005-11-07 01:00:16 -0800170};
171
172/**
173 * rio_read_config_16 - Read 16 bits from configuration space
174 * @rdev: RIO device
175 * @offset: Offset into device configuration space
176 * @data: Pointer to read data into
177 *
178 * Reads 16 bits of data from the specified offset within the
179 * RIO device's configuration space.
180 */
181static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
182 u16 * data)
183{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800184 return rio_mport_read_config_16(rdev->net->hport, rdev->destid,
185 rdev->hopcount, offset, data);
Matt Porter70a50eb2005-11-07 01:00:16 -0800186};
187
188/**
189 * rio_write_config_16 - Write 16 bits to configuration space
190 * @rdev: RIO device
191 * @offset: Offset into device configuration space
192 * @data: Data to be written
193 *
194 * Writes 16 bits of data to the specified offset within the
195 * RIO device's configuration space.
196 */
197static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
198 u16 data)
199{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800200 return rio_mport_write_config_16(rdev->net->hport, rdev->destid,
201 rdev->hopcount, offset, data);
Matt Porter70a50eb2005-11-07 01:00:16 -0800202};
203
204/**
205 * rio_read_config_8 - Read 8 bits from configuration space
206 * @rdev: RIO device
207 * @offset: Offset into device configuration space
208 * @data: Pointer to read data into
209 *
210 * Reads 8 bits of data from the specified offset within the
211 * RIO device's configuration space.
212 */
213static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
214{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800215 return rio_mport_read_config_8(rdev->net->hport, rdev->destid,
216 rdev->hopcount, offset, data);
Matt Porter70a50eb2005-11-07 01:00:16 -0800217};
218
219/**
220 * rio_write_config_8 - Write 8 bits to configuration space
221 * @rdev: RIO device
222 * @offset: Offset into device configuration space
223 * @data: Data to be written
224 *
225 * Writes 8 bits of data to the specified offset within the
226 * RIO device's configuration space.
227 */
228static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
229{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800230 return rio_mport_write_config_8(rdev->net->hport, rdev->destid,
231 rdev->hopcount, offset, data);
Matt Porter70a50eb2005-11-07 01:00:16 -0800232};
233
234extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
235 u16 data);
236
237/**
238 * rio_send_doorbell - Send a doorbell message to a device
239 * @rdev: RIO device
240 * @data: Doorbell message data
241 *
242 * Send a doorbell message to a RIO device. The doorbell message
243 * has a 16-bit info field provided by the @data argument.
244 */
245static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
246{
247 return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
248};
249
250/**
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
255 *
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.
259 */
260static inline void rio_init_mbox_res(struct resource *res, int start, int end)
261{
262 memset(res, 0, sizeof(struct resource));
263 res->start = start;
264 res->end = end;
265 res->flags = RIO_RESOURCE_MAILBOX;
266}
267
268/**
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
273 *
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.
277 */
278static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
279{
280 memset(res, 0, sizeof(struct resource));
281 res->start = start;
282 res->end = end;
283 res->flags = RIO_RESOURCE_DOORBELL;
284}
285
286/**
287 * RIO_DEVICE - macro used to describe a specific RIO device
Martin Waitz0863afb2006-01-09 20:53:55 -0800288 * @dev: the 16 bit RIO device ID
289 * @ven: the 16 bit RIO vendor ID
Matt Porter70a50eb2005-11-07 01:00:16 -0800290 *
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.
294 */
295#define RIO_DEVICE(dev,ven) \
296 .did = (dev), .vid = (ven), \
297 .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
298
299/* Mailbox management */
Matt Porter6978bbc2005-11-07 01:00:20 -0800300extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int,
301 void (*)(struct rio_mport *, void *,int, int));
Matt Porter70a50eb2005-11-07 01:00:16 -0800302extern int rio_release_outb_mbox(struct rio_mport *, int);
303
304/**
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
311 *
312 * Adds a RIO message buffer to an outbound mailbox queue for
313 * transmission. Returns 0 on success.
314 */
315static inline int rio_add_outb_message(struct rio_mport *mport,
316 struct rio_dev *rdev, int mbox,
317 void *buffer, size_t len)
318{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700319 return mport->ops->add_outb_message(mport, rdev, mbox,
320 buffer, len);
Matt Porter70a50eb2005-11-07 01:00:16 -0800321}
322
Matt Porter6978bbc2005-11-07 01:00:20 -0800323extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int,
324 void (*)(struct rio_mport *, void *, int, int));
Matt Porter70a50eb2005-11-07 01:00:16 -0800325extern int rio_release_inb_mbox(struct rio_mport *, int);
326
327/**
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
332 *
333 * Adds a buffer to an inbound mailbox queue for reception. Returns
334 * 0 on success.
335 */
336static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
337 void *buffer)
338{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700339 return mport->ops->add_inb_buffer(mport, mbox, buffer);
Matt Porter70a50eb2005-11-07 01:00:16 -0800340}
341
342/**
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
Matt Porter70a50eb2005-11-07 01:00:16 -0800346 *
347 * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
348 */
349static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
350{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700351 return mport->ops->get_inb_message(mport, mbox);
Matt Porter70a50eb2005-11-07 01:00:16 -0800352}
353
354/* Doorbell management */
Matt Porter6978bbc2005-11-07 01:00:20 -0800355extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16,
356 void (*)(struct rio_mport *, void *, u16, u16, u16));
Matt Porter70a50eb2005-11-07 01:00:16 -0800357extern int rio_release_inb_dbell(struct rio_mport *, u16, u16);
358extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16);
359extern int rio_release_outb_dbell(struct rio_dev *, struct resource *);
360
361/* Memory region management */
362int rio_claim_resource(struct rio_dev *, int);
363int rio_request_regions(struct rio_dev *, char *);
364void rio_release_regions(struct rio_dev *);
365int rio_request_region(struct rio_dev *, int, char *);
366void rio_release_region(struct rio_dev *, int);
367
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700368/* Port-Write management */
369extern int rio_request_inb_pwrite(struct rio_dev *,
370 int (*)(struct rio_dev *, union rio_pw_msg*, int));
371extern int rio_release_inb_pwrite(struct rio_dev *);
372extern int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg);
373
Matt Porter70a50eb2005-11-07 01:00:16 -0800374/* LDM support */
375int rio_register_driver(struct rio_driver *);
376void rio_unregister_driver(struct rio_driver *);
377struct rio_dev *rio_dev_get(struct rio_dev *);
378void rio_dev_put(struct rio_dev *);
379
380/**
381 * rio_name - Get the unique RIO device identifier
382 * @rdev: RIO device
383 *
384 * Get the unique RIO device identifier. Returns the device
385 * identifier string.
386 */
Kay Sieversb53c7582008-12-04 10:01:52 -0800387static inline const char *rio_name(struct rio_dev *rdev)
Matt Porter70a50eb2005-11-07 01:00:16 -0800388{
Kay Sieversb53c7582008-12-04 10:01:52 -0800389 return dev_name(&rdev->dev);
Matt Porter70a50eb2005-11-07 01:00:16 -0800390}
391
392/**
393 * rio_get_drvdata - Get RIO driver specific data
394 * @rdev: RIO device
395 *
396 * Get RIO driver specific data. Returns a pointer to the
397 * driver specific data.
398 */
399static inline void *rio_get_drvdata(struct rio_dev *rdev)
400{
401 return dev_get_drvdata(&rdev->dev);
402}
403
404/**
405 * rio_set_drvdata - Set RIO driver specific data
406 * @rdev: RIO device
407 * @data: Pointer to driver specific data
408 *
409 * Set RIO driver specific data. device struct driver data pointer
410 * is set to the @data argument.
411 */
412static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
413{
414 dev_set_drvdata(&rdev->dev, data);
415}
416
417/* Misc driver helpers */
418extern u16 rio_local_get_device_id(struct rio_mport *port);
419extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from);
420extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did,
421 struct rio_dev *from);
422
Matt Porter70a50eb2005-11-07 01:00:16 -0800423#endif /* LINUX_RIO_DRV_H */