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