]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/rapidio/rio.c
2 * RapidIO interconnect services
3 * (RapidIO Interconnect Specification, http://www.rapidio.org)
5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
18 #include <linux/delay.h>
19 #include <linux/init.h>
20 #include <linux/rio.h>
21 #include <linux/rio_drv.h>
22 #include <linux/rio_ids.h>
23 #include <linux/rio_regs.h>
24 #include <linux/module.h>
25 #include <linux/spinlock.h>
29 static LIST_HEAD(rio_mports
);
32 * rio_local_get_device_id - Get the base/extended device id for a port
33 * @port: RIO master port from which to get the deviceid
35 * Reads the base/extended device id from the local device
36 * implementing the master port. Returns the 8/16-bit device
39 u16
rio_local_get_device_id(struct rio_mport
*port
)
43 rio_local_read_config_32(port
, RIO_DID_CSR
, &result
);
45 return (RIO_GET_DID(result
));
49 * rio_request_inb_mbox - request inbound mailbox service
50 * @mport: RIO master port from which to allocate the mailbox resource
51 * @mbox: Mailbox number to claim
52 * @entries: Number of entries in inbound mailbox queue
53 * @minb: Callback to execute when inbound message is received
55 * Requests ownership of an inbound mailbox resource and binds
56 * a callback function to the resource. Returns %0 on success.
58 int rio_request_inb_mbox(struct rio_mport
*mport
,
61 void (*minb
) (struct rio_mport
* mport
, int mbox
,
66 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
69 rio_init_mbox_res(res
, mbox
, mbox
);
71 /* Make sure this mailbox isn't in use */
73 request_resource(&mport
->riores
[RIO_INB_MBOX_RESOURCE
],
79 mport
->inb_msg
[mbox
].res
= res
;
81 /* Hook the inbound message callback */
82 mport
->inb_msg
[mbox
].mcback
= minb
;
84 rc
= rio_open_inb_mbox(mport
, mbox
, entries
);
93 * rio_release_inb_mbox - release inbound mailbox message service
94 * @mport: RIO master port from which to release the mailbox resource
95 * @mbox: Mailbox number to release
97 * Releases ownership of an inbound mailbox resource. Returns 0
98 * if the request has been satisfied.
100 int rio_release_inb_mbox(struct rio_mport
*mport
, int mbox
)
102 rio_close_inb_mbox(mport
, mbox
);
104 /* Release the mailbox resource */
105 return release_resource(mport
->inb_msg
[mbox
].res
);
109 * rio_request_outb_mbox - request outbound mailbox service
110 * @mport: RIO master port from which to allocate the mailbox resource
111 * @mbox: Mailbox number to claim
112 * @entries: Number of entries in outbound mailbox queue
113 * @moutb: Callback to execute when outbound message is sent
115 * Requests ownership of an outbound mailbox resource and binds
116 * a callback function to the resource. Returns 0 on success.
118 int rio_request_outb_mbox(struct rio_mport
*mport
,
121 void (*moutb
) (struct rio_mport
* mport
, int mbox
,
126 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
129 rio_init_mbox_res(res
, mbox
, mbox
);
131 /* Make sure this outbound mailbox isn't in use */
133 request_resource(&mport
->riores
[RIO_OUTB_MBOX_RESOURCE
],
139 mport
->outb_msg
[mbox
].res
= res
;
141 /* Hook the inbound message callback */
142 mport
->outb_msg
[mbox
].mcback
= moutb
;
144 rc
= rio_open_outb_mbox(mport
, mbox
, entries
);
153 * rio_release_outb_mbox - release outbound mailbox message service
154 * @mport: RIO master port from which to release the mailbox resource
155 * @mbox: Mailbox number to release
157 * Releases ownership of an inbound mailbox resource. Returns 0
158 * if the request has been satisfied.
160 int rio_release_outb_mbox(struct rio_mport
*mport
, int mbox
)
162 rio_close_outb_mbox(mport
, mbox
);
164 /* Release the mailbox resource */
165 return release_resource(mport
->outb_msg
[mbox
].res
);
169 * rio_setup_inb_dbell - bind inbound doorbell callback
170 * @mport: RIO master port to bind the doorbell callback
171 * @res: Doorbell message resource
172 * @dinb: Callback to execute when doorbell is received
174 * Adds a doorbell resource/callback pair into a port's
175 * doorbell event list. Returns 0 if the request has been
179 rio_setup_inb_dbell(struct rio_mport
*mport
, struct resource
*res
,
180 void (*dinb
) (struct rio_mport
* mport
, u16 src
, u16 dst
,
184 struct rio_dbell
*dbell
;
186 if (!(dbell
= kmalloc(sizeof(struct rio_dbell
), GFP_KERNEL
))) {
194 list_add_tail(&dbell
->node
, &mport
->dbells
);
201 * rio_request_inb_dbell - request inbound doorbell message service
202 * @mport: RIO master port from which to allocate the doorbell resource
203 * @start: Doorbell info range start
204 * @end: Doorbell info range end
205 * @dinb: Callback to execute when doorbell is received
207 * Requests ownership of an inbound doorbell resource and binds
208 * a callback function to the resource. Returns 0 if the request
209 * has been satisfied.
211 int rio_request_inb_dbell(struct rio_mport
*mport
,
214 void (*dinb
) (struct rio_mport
* mport
, u16 src
,
219 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
222 rio_init_dbell_res(res
, start
, end
);
224 /* Make sure these doorbells aren't in use */
226 request_resource(&mport
->riores
[RIO_DOORBELL_RESOURCE
],
232 /* Hook the doorbell callback */
233 rc
= rio_setup_inb_dbell(mport
, res
, dinb
);
242 * rio_release_inb_dbell - release inbound doorbell message service
243 * @mport: RIO master port from which to release the doorbell resource
244 * @start: Doorbell info range start
245 * @end: Doorbell info range end
247 * Releases ownership of an inbound doorbell resource and removes
248 * callback from the doorbell event list. Returns 0 if the request
249 * has been satisfied.
251 int rio_release_inb_dbell(struct rio_mport
*mport
, u16 start
, u16 end
)
253 int rc
= 0, found
= 0;
254 struct rio_dbell
*dbell
;
256 list_for_each_entry(dbell
, &mport
->dbells
, node
) {
257 if ((dbell
->res
->start
== start
) && (dbell
->res
->end
== end
)) {
263 /* If we can't find an exact match, fail */
269 /* Delete from list */
270 list_del(&dbell
->node
);
272 /* Release the doorbell resource */
273 rc
= release_resource(dbell
->res
);
275 /* Free the doorbell event */
283 * rio_request_outb_dbell - request outbound doorbell message range
284 * @rdev: RIO device from which to allocate the doorbell resource
285 * @start: Doorbell message range start
286 * @end: Doorbell message range end
288 * Requests ownership of a doorbell message range. Returns a resource
289 * if the request has been satisfied or %NULL on failure.
291 struct resource
*rio_request_outb_dbell(struct rio_dev
*rdev
, u16 start
,
294 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
297 rio_init_dbell_res(res
, start
, end
);
299 /* Make sure these doorbells aren't in use */
300 if (request_resource(&rdev
->riores
[RIO_DOORBELL_RESOURCE
], res
)
311 * rio_release_outb_dbell - release outbound doorbell message range
312 * @rdev: RIO device from which to release the doorbell resource
313 * @res: Doorbell resource to be freed
315 * Releases ownership of a doorbell message range. Returns 0 if the
316 * request has been satisfied.
318 int rio_release_outb_dbell(struct rio_dev
*rdev
, struct resource
*res
)
320 int rc
= release_resource(res
);
328 * rio_mport_get_feature - query for devices' extended features
329 * @port: Master port to issue transaction
330 * @local: Indicate a local master port or remote device access
331 * @destid: Destination ID of the device
332 * @hopcount: Number of switch hops to the device
333 * @ftr: Extended feature code
335 * Tell if a device supports a given RapidIO capability.
336 * Returns the offset of the requested extended feature
337 * block within the device's RIO configuration space or
338 * 0 in case the device does not support it. Possible
341 * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
343 * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
345 * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
347 * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
349 * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
351 * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
354 rio_mport_get_feature(struct rio_mport
* port
, int local
, u16 destid
,
355 u8 hopcount
, int ftr
)
357 u32 asm_info
, ext_ftr_ptr
, ftr_header
;
360 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
, &asm_info
);
362 rio_mport_read_config_32(port
, destid
, hopcount
,
363 RIO_ASM_INFO_CAR
, &asm_info
);
365 ext_ftr_ptr
= asm_info
& RIO_EXT_FTR_PTR_MASK
;
367 while (ext_ftr_ptr
) {
369 rio_local_read_config_32(port
, ext_ftr_ptr
,
372 rio_mport_read_config_32(port
, destid
, hopcount
,
373 ext_ftr_ptr
, &ftr_header
);
374 if (RIO_GET_BLOCK_ID(ftr_header
) == ftr
)
376 if (!(ext_ftr_ptr
= RIO_GET_BLOCK_PTR(ftr_header
)))
384 * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
385 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
386 * @did: RIO did to match or %RIO_ANY_ID to match all dids
387 * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
388 * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
389 * @from: Previous RIO device found in search, or %NULL for new search
391 * Iterates through the list of known RIO devices. If a RIO device is
392 * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
393 * count to the device is incrememted and a pointer to its device
394 * structure is returned. Otherwise, %NULL is returned. A new search
395 * is initiated by passing %NULL to the @from argument. Otherwise, if
396 * @from is not %NULL, searches continue from next device on the global
397 * list. The reference count for @from is always decremented if it is
400 struct rio_dev
*rio_get_asm(u16 vid
, u16 did
,
401 u16 asm_vid
, u16 asm_did
, struct rio_dev
*from
)
404 struct rio_dev
*rdev
;
406 WARN_ON(in_interrupt());
407 spin_lock(&rio_global_list_lock
);
408 n
= from
? from
->global_list
.next
: rio_devices
.next
;
410 while (n
&& (n
!= &rio_devices
)) {
412 if ((vid
== RIO_ANY_ID
|| rdev
->vid
== vid
) &&
413 (did
== RIO_ANY_ID
|| rdev
->did
== did
) &&
414 (asm_vid
== RIO_ANY_ID
|| rdev
->asm_vid
== asm_vid
) &&
415 (asm_did
== RIO_ANY_ID
|| rdev
->asm_did
== asm_did
))
422 rdev
= rio_dev_get(rdev
);
423 spin_unlock(&rio_global_list_lock
);
428 * rio_get_device - Begin or continue searching for a RIO device by vid/did
429 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
430 * @did: RIO did to match or %RIO_ANY_ID to match all dids
431 * @from: Previous RIO device found in search, or %NULL for new search
433 * Iterates through the list of known RIO devices. If a RIO device is
434 * found with a matching @vid and @did, the reference count to the
435 * device is incrememted and a pointer to its device structure is returned.
436 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
437 * to the @from argument. Otherwise, if @from is not %NULL, searches
438 * continue from next device on the global list. The reference count for
439 * @from is always decremented if it is not %NULL.
441 struct rio_dev
*rio_get_device(u16 vid
, u16 did
, struct rio_dev
*from
)
443 return rio_get_asm(vid
, did
, RIO_ANY_ID
, RIO_ANY_ID
, from
);
446 static void rio_fixup_device(struct rio_dev
*dev
)
450 static int __devinit
rio_init(void)
452 struct rio_dev
*dev
= NULL
;
454 while ((dev
= rio_get_device(RIO_ANY_ID
, RIO_ANY_ID
, dev
)) != NULL
) {
455 rio_fixup_device(dev
);
460 device_initcall(rio_init
);
462 int rio_init_mports(void)
465 struct rio_mport
*port
;
467 list_for_each_entry(port
, &rio_mports
, node
) {
468 if (!request_mem_region(port
->iores
.start
,
469 port
->iores
.end
- port
->iores
.start
,
472 "RIO: Error requesting master port region %8.8lx-%8.8lx\n",
473 port
->iores
.start
, port
->iores
.end
- 1);
478 if (port
->host_deviceid
>= 0)
479 rio_enum_mport(port
);
481 rio_disc_mport(port
);
488 void rio_register_mport(struct rio_mport
*port
)
490 list_add_tail(&port
->node
, &rio_mports
);
493 EXPORT_SYMBOL_GPL(rio_local_get_device_id
);
494 EXPORT_SYMBOL_GPL(rio_get_device
);
495 EXPORT_SYMBOL_GPL(rio_get_asm
);
496 EXPORT_SYMBOL_GPL(rio_request_inb_dbell
);
497 EXPORT_SYMBOL_GPL(rio_release_inb_dbell
);
498 EXPORT_SYMBOL_GPL(rio_request_outb_dbell
);
499 EXPORT_SYMBOL_GPL(rio_release_outb_dbell
);
500 EXPORT_SYMBOL_GPL(rio_request_inb_mbox
);
501 EXPORT_SYMBOL_GPL(rio_release_inb_mbox
);
502 EXPORT_SYMBOL_GPL(rio_request_outb_mbox
);
503 EXPORT_SYMBOL_GPL(rio_release_outb_mbox
);