[PATCH] bcm43xx: Fix array overrun in bcm43xx_geo_init
[linux-2.6/kmemtrace.git] / include / linux / rio_drv.h
blobf54772d0e7f821981e6db96b5586977f3acb5051
1 /*
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 #ifdef __KERNEL__
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>
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);
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);
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
59 * Reads 32 bits of data from the specified offset within the local
60 * device's configuration space.
62 static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
63 u32 * data)
65 return __rio_local_read_config_32(port, offset, data);
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
74 * Writes 32 bits of data to the specified offset within the local
75 * device's configuration space.
77 static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
78 u32 data)
80 return __rio_local_write_config_32(port, offset, data);
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
89 * Reads 16 bits of data from the specified offset within the local
90 * device's configuration space.
92 static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
93 u16 * data)
95 return __rio_local_read_config_16(port, offset, data);
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
104 * Writes 16 bits of data to the specified offset within the local
105 * device's configuration space.
108 static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
109 u16 data)
111 return __rio_local_write_config_16(port, offset, data);
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
120 * Reads 8 bits of data from the specified offset within the local
121 * device's configuration space.
123 static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
124 u8 * data)
126 return __rio_local_read_config_8(port, offset, data);
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
135 * Writes 8 bits of data to the specified offset within the local
136 * device's configuration space.
138 static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
139 u8 data)
141 return __rio_local_write_config_8(port, offset, data);
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
150 * Reads 32 bits of data from the specified offset within the
151 * RIO device's configuration space.
153 static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
154 u32 * data)
156 u8 hopcount = 0xff;
157 u16 destid = rdev->destid;
159 if (rdev->rswitch) {
160 destid = rdev->rswitch->destid;
161 hopcount = rdev->rswitch->hopcount;
164 return rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
165 offset, data);
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
174 * Writes 32 bits of data to the specified offset within the
175 * RIO device's configuration space.
177 static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
178 u32 data)
180 u8 hopcount = 0xff;
181 u16 destid = rdev->destid;
183 if (rdev->rswitch) {
184 destid = rdev->rswitch->destid;
185 hopcount = rdev->rswitch->hopcount;
188 return rio_mport_write_config_32(rdev->net->hport, destid, hopcount,
189 offset, data);
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
198 * Reads 16 bits of data from the specified offset within the
199 * RIO device's configuration space.
201 static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
202 u16 * data)
204 u8 hopcount = 0xff;
205 u16 destid = rdev->destid;
207 if (rdev->rswitch) {
208 destid = rdev->rswitch->destid;
209 hopcount = rdev->rswitch->hopcount;
212 return rio_mport_read_config_16(rdev->net->hport, destid, hopcount,
213 offset, data);
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
222 * Writes 16 bits of data to the specified offset within the
223 * RIO device's configuration space.
225 static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
226 u16 data)
228 u8 hopcount = 0xff;
229 u16 destid = rdev->destid;
231 if (rdev->rswitch) {
232 destid = rdev->rswitch->destid;
233 hopcount = rdev->rswitch->hopcount;
236 return rio_mport_write_config_16(rdev->net->hport, destid, hopcount,
237 offset, data);
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
246 * Reads 8 bits of data from the specified offset within the
247 * RIO device's configuration space.
249 static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
251 u8 hopcount = 0xff;
252 u16 destid = rdev->destid;
254 if (rdev->rswitch) {
255 destid = rdev->rswitch->destid;
256 hopcount = rdev->rswitch->hopcount;
259 return rio_mport_read_config_8(rdev->net->hport, destid, hopcount,
260 offset, data);
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
269 * Writes 8 bits of data to the specified offset within the
270 * RIO device's configuration space.
272 static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
274 u8 hopcount = 0xff;
275 u16 destid = rdev->destid;
277 if (rdev->rswitch) {
278 destid = rdev->rswitch->destid;
279 hopcount = rdev->rswitch->hopcount;
282 return rio_mport_write_config_8(rdev->net->hport, destid, hopcount,
283 offset, data);
286 extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
287 u16 data);
290 * rio_send_doorbell - Send a doorbell message to a device
291 * @rdev: RIO device
292 * @data: Doorbell message data
294 * Send a doorbell message to a RIO device. The doorbell message
295 * has a 16-bit info field provided by the @data argument.
297 static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
299 return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
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
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.
312 static inline void rio_init_mbox_res(struct resource *res, int start, int end)
314 memset(res, 0, sizeof(struct resource));
315 res->start = start;
316 res->end = end;
317 res->flags = RIO_RESOURCE_MAILBOX;
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
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.
330 static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
332 memset(res, 0, sizeof(struct resource));
333 res->start = start;
334 res->end = end;
335 res->flags = RIO_RESOURCE_DOORBELL;
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
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.
347 #define RIO_DEVICE(dev,ven) \
348 .did = (dev), .vid = (ven), \
349 .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
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);
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
364 * Adds a RIO message buffer to an outbound mailbox queue for
365 * transmission. Returns 0 on success.
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)
371 return rio_hw_add_outb_message(mport, rdev, mbox, buffer, len);
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);
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
384 * Adds a buffer to an inbound mailbox queue for reception. Returns
385 * 0 on success.
387 static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
388 void *buffer)
390 return rio_hw_add_inb_buffer(mport, mbox, buffer);
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
399 * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
401 static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
403 return rio_hw_get_inb_message(mport, mbox);
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 *);
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);
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 *);
427 * rio_name - Get the unique RIO device identifier
428 * @rdev: RIO device
430 * Get the unique RIO device identifier. Returns the device
431 * identifier string.
433 static inline char *rio_name(struct rio_dev *rdev)
435 return rdev->dev.bus_id;
439 * rio_get_drvdata - Get RIO driver specific data
440 * @rdev: RIO device
442 * Get RIO driver specific data. Returns a pointer to the
443 * driver specific data.
445 static inline void *rio_get_drvdata(struct rio_dev *rdev)
447 return dev_get_drvdata(&rdev->dev);
451 * rio_set_drvdata - Set RIO driver specific data
452 * @rdev: RIO device
453 * @data: Pointer to driver specific data
455 * Set RIO driver specific data. device struct driver data pointer
456 * is set to the @data argument.
458 static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
460 dev_set_drvdata(&rdev->dev, data);
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);
469 #endif /* __KERNEL__ */
470 #endif /* LINUX_RIO_DRV_H */