Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * RapidIO driver services
0004  *
0005  * Copyright 2005 MontaVista Software, Inc.
0006  * Matt Porter <mporter@kernel.crashing.org>
0007  */
0008 
0009 #ifndef LINUX_RIO_DRV_H
0010 #define LINUX_RIO_DRV_H
0011 
0012 #include <linux/types.h>
0013 #include <linux/ioport.h>
0014 #include <linux/list.h>
0015 #include <linux/errno.h>
0016 #include <linux/string.h>
0017 #include <linux/rio.h>
0018 
0019 extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset,
0020                       u32 * data);
0021 extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset,
0022                        u32 data);
0023 extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset,
0024                       u16 * data);
0025 extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset,
0026                        u16 data);
0027 extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset,
0028                      u8 * data);
0029 extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset,
0030                       u8 data);
0031 
0032 extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid,
0033                     u8 hopcount, u32 offset, u32 * data);
0034 extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid,
0035                      u8 hopcount, u32 offset, u32 data);
0036 extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid,
0037                     u8 hopcount, u32 offset, u16 * data);
0038 extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid,
0039                      u8 hopcount, u32 offset, u16 data);
0040 extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid,
0041                    u8 hopcount, u32 offset, u8 * data);
0042 extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid,
0043                     u8 hopcount, u32 offset, u8 data);
0044 
0045 /**
0046  * rio_local_read_config_32 - Read 32 bits from local configuration space
0047  * @port: Master port
0048  * @offset: Offset into local configuration space
0049  * @data: Pointer to read data into
0050  *
0051  * Reads 32 bits of data from the specified offset within the local
0052  * device's configuration space.
0053  */
0054 static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
0055                        u32 * data)
0056 {
0057     return __rio_local_read_config_32(port, offset, data);
0058 }
0059 
0060 /**
0061  * rio_local_write_config_32 - Write 32 bits to local configuration space
0062  * @port: Master port
0063  * @offset: Offset into local configuration space
0064  * @data: Data to be written
0065  *
0066  * Writes 32 bits of data to the specified offset within the local
0067  * device's configuration space.
0068  */
0069 static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
0070                         u32 data)
0071 {
0072     return __rio_local_write_config_32(port, offset, data);
0073 }
0074 
0075 /**
0076  * rio_local_read_config_16 - Read 16 bits from local configuration space
0077  * @port: Master port
0078  * @offset: Offset into local configuration space
0079  * @data: Pointer to read data into
0080  *
0081  * Reads 16 bits of data from the specified offset within the local
0082  * device's configuration space.
0083  */
0084 static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
0085                        u16 * data)
0086 {
0087     return __rio_local_read_config_16(port, offset, data);
0088 }
0089 
0090 /**
0091  * rio_local_write_config_16 - Write 16 bits to local configuration space
0092  * @port: Master port
0093  * @offset: Offset into local configuration space
0094  * @data: Data to be written
0095  *
0096  * Writes 16 bits of data to the specified offset within the local
0097  * device's configuration space.
0098  */
0099 
0100 static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
0101                         u16 data)
0102 {
0103     return __rio_local_write_config_16(port, offset, data);
0104 }
0105 
0106 /**
0107  * rio_local_read_config_8 - Read 8 bits from local configuration space
0108  * @port: Master port
0109  * @offset: Offset into local configuration space
0110  * @data: Pointer to read data into
0111  *
0112  * Reads 8 bits of data from the specified offset within the local
0113  * device's configuration space.
0114  */
0115 static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
0116                       u8 * data)
0117 {
0118     return __rio_local_read_config_8(port, offset, data);
0119 }
0120 
0121 /**
0122  * rio_local_write_config_8 - Write 8 bits to local configuration space
0123  * @port: Master port
0124  * @offset: Offset into local configuration space
0125  * @data: Data to be written
0126  *
0127  * Writes 8 bits of data to the specified offset within the local
0128  * device's configuration space.
0129  */
0130 static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
0131                        u8 data)
0132 {
0133     return __rio_local_write_config_8(port, offset, data);
0134 }
0135 
0136 /**
0137  * rio_read_config_32 - Read 32 bits from configuration space
0138  * @rdev: RIO device
0139  * @offset: Offset into device configuration space
0140  * @data: Pointer to read data into
0141  *
0142  * Reads 32 bits of data from the specified offset within the
0143  * RIO device's configuration space.
0144  */
0145 static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
0146                      u32 * data)
0147 {
0148     return rio_mport_read_config_32(rdev->net->hport, rdev->destid,
0149                     rdev->hopcount, offset, data);
0150 };
0151 
0152 /**
0153  * rio_write_config_32 - Write 32 bits to configuration space
0154  * @rdev: RIO device
0155  * @offset: Offset into device configuration space
0156  * @data: Data to be written
0157  *
0158  * Writes 32 bits of data to the specified offset within the
0159  * RIO device's configuration space.
0160  */
0161 static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
0162                       u32 data)
0163 {
0164     return rio_mport_write_config_32(rdev->net->hport, rdev->destid,
0165                      rdev->hopcount, offset, data);
0166 };
0167 
0168 /**
0169  * rio_read_config_16 - Read 16 bits from configuration space
0170  * @rdev: RIO device
0171  * @offset: Offset into device configuration space
0172  * @data: Pointer to read data into
0173  *
0174  * Reads 16 bits of data from the specified offset within the
0175  * RIO device's configuration space.
0176  */
0177 static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
0178                      u16 * data)
0179 {
0180     return rio_mport_read_config_16(rdev->net->hport, rdev->destid,
0181                     rdev->hopcount, offset, data);
0182 };
0183 
0184 /**
0185  * rio_write_config_16 - Write 16 bits to configuration space
0186  * @rdev: RIO device
0187  * @offset: Offset into device configuration space
0188  * @data: Data to be written
0189  *
0190  * Writes 16 bits of data to the specified offset within the
0191  * RIO device's configuration space.
0192  */
0193 static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
0194                       u16 data)
0195 {
0196     return rio_mport_write_config_16(rdev->net->hport, rdev->destid,
0197                      rdev->hopcount, offset, data);
0198 };
0199 
0200 /**
0201  * rio_read_config_8 - Read 8 bits from configuration space
0202  * @rdev: RIO device
0203  * @offset: Offset into device configuration space
0204  * @data: Pointer to read data into
0205  *
0206  * Reads 8 bits of data from the specified offset within the
0207  * RIO device's configuration space.
0208  */
0209 static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
0210 {
0211     return rio_mport_read_config_8(rdev->net->hport, rdev->destid,
0212                        rdev->hopcount, offset, data);
0213 };
0214 
0215 /**
0216  * rio_write_config_8 - Write 8 bits to configuration space
0217  * @rdev: RIO device
0218  * @offset: Offset into device configuration space
0219  * @data: Data to be written
0220  *
0221  * Writes 8 bits of data to the specified offset within the
0222  * RIO device's configuration space.
0223  */
0224 static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
0225 {
0226     return rio_mport_write_config_8(rdev->net->hport, rdev->destid,
0227                     rdev->hopcount, offset, data);
0228 };
0229 
0230 extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
0231                    u16 data);
0232 
0233 /**
0234  * rio_send_doorbell - Send a doorbell message to a device
0235  * @rdev: RIO device
0236  * @data: Doorbell message data
0237  *
0238  * Send a doorbell message to a RIO device. The doorbell message
0239  * has a 16-bit info field provided by the @data argument.
0240  */
0241 static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
0242 {
0243     return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
0244 };
0245 
0246 /**
0247  * rio_init_mbox_res - Initialize a RIO mailbox resource
0248  * @res: resource struct
0249  * @start: start of mailbox range
0250  * @end: end of mailbox range
0251  *
0252  * This function is used to initialize the fields of a resource
0253  * for use as a mailbox resource.  It initializes a range of
0254  * mailboxes using the start and end arguments.
0255  */
0256 static inline void rio_init_mbox_res(struct resource *res, int start, int end)
0257 {
0258     memset(res, 0, sizeof(struct resource));
0259     res->start = start;
0260     res->end = end;
0261     res->flags = RIO_RESOURCE_MAILBOX;
0262 }
0263 
0264 /**
0265  * rio_init_dbell_res - Initialize a RIO doorbell resource
0266  * @res: resource struct
0267  * @start: start of doorbell range
0268  * @end: end of doorbell range
0269  *
0270  * This function is used to initialize the fields of a resource
0271  * for use as a doorbell resource.  It initializes a range of
0272  * doorbell messages using the start and end arguments.
0273  */
0274 static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
0275 {
0276     memset(res, 0, sizeof(struct resource));
0277     res->start = start;
0278     res->end = end;
0279     res->flags = RIO_RESOURCE_DOORBELL;
0280 }
0281 
0282 /**
0283  * RIO_DEVICE - macro used to describe a specific RIO device
0284  * @dev: the 16 bit RIO device ID
0285  * @ven: the 16 bit RIO vendor ID
0286  *
0287  * This macro is used to create a struct rio_device_id that matches a
0288  * specific device.  The assembly vendor and assembly device fields
0289  * will be set to %RIO_ANY_ID.
0290  */
0291 #define RIO_DEVICE(dev,ven) \
0292     .did = (dev), .vid = (ven), \
0293     .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
0294 
0295 /* Mailbox management */
0296 extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int,
0297                  void (*)(struct rio_mport *, void *,int, int));
0298 extern int rio_release_outb_mbox(struct rio_mport *, int);
0299 
0300 /**
0301  * rio_add_outb_message - Add RIO message to an outbound mailbox queue
0302  * @mport: RIO master port containing the outbound queue
0303  * @rdev: RIO device the message is be sent to
0304  * @mbox: The outbound mailbox queue
0305  * @buffer: Pointer to the message buffer
0306  * @len: Length of the message buffer
0307  *
0308  * Adds a RIO message buffer to an outbound mailbox queue for
0309  * transmission. Returns 0 on success.
0310  */
0311 static inline int rio_add_outb_message(struct rio_mport *mport,
0312                        struct rio_dev *rdev, int mbox,
0313                        void *buffer, size_t len)
0314 {
0315     return mport->ops->add_outb_message(mport, rdev, mbox,
0316                            buffer, len);
0317 }
0318 
0319 extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int,
0320                 void (*)(struct rio_mport *, void *, int, int));
0321 extern int rio_release_inb_mbox(struct rio_mport *, int);
0322 
0323 /**
0324  * rio_add_inb_buffer - Add buffer to an inbound mailbox queue
0325  * @mport: Master port containing the inbound mailbox
0326  * @mbox: The inbound mailbox number
0327  * @buffer: Pointer to the message buffer
0328  *
0329  * Adds a buffer to an inbound mailbox queue for reception. Returns
0330  * 0 on success.
0331  */
0332 static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
0333                      void *buffer)
0334 {
0335     return mport->ops->add_inb_buffer(mport, mbox, buffer);
0336 }
0337 
0338 /**
0339  * rio_get_inb_message - Get A RIO message from an inbound mailbox queue
0340  * @mport: Master port containing the inbound mailbox
0341  * @mbox: The inbound mailbox number
0342  *
0343  * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
0344  */
0345 static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
0346 {
0347     return mport->ops->get_inb_message(mport, mbox);
0348 }
0349 
0350 /* Doorbell management */
0351 extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16,
0352                  void (*)(struct rio_mport *, void *, u16, u16, u16));
0353 extern int rio_release_inb_dbell(struct rio_mport *, u16, u16);
0354 extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16);
0355 extern int rio_release_outb_dbell(struct rio_dev *, struct resource *);
0356 
0357 /* Memory region management */
0358 int rio_claim_resource(struct rio_dev *, int);
0359 int rio_request_regions(struct rio_dev *, char *);
0360 void rio_release_regions(struct rio_dev *);
0361 int rio_request_region(struct rio_dev *, int, char *);
0362 void rio_release_region(struct rio_dev *, int);
0363 
0364 /* Memory mapping functions */
0365 extern int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
0366             u64 rbase, u32 size, u32 rflags);
0367 extern void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart);
0368 extern int rio_map_outb_region(struct rio_mport *mport, u16 destid, u64 rbase,
0369             u32 size, u32 rflags, dma_addr_t *local);
0370 extern void rio_unmap_outb_region(struct rio_mport *mport,
0371                   u16 destid, u64 rstart);
0372 
0373 /* Port-Write management */
0374 extern int rio_request_inb_pwrite(struct rio_dev *,
0375             int (*)(struct rio_dev *, union rio_pw_msg*, int));
0376 extern int rio_release_inb_pwrite(struct rio_dev *);
0377 extern int rio_add_mport_pw_handler(struct rio_mport *mport, void *dev_id,
0378             int (*pwcback)(struct rio_mport *mport, void *dev_id,
0379             union rio_pw_msg *msg, int step));
0380 extern int rio_del_mport_pw_handler(struct rio_mport *mport, void *dev_id,
0381             int (*pwcback)(struct rio_mport *mport, void *dev_id,
0382             union rio_pw_msg *msg, int step));
0383 extern int rio_inb_pwrite_handler(struct rio_mport *mport,
0384                   union rio_pw_msg *pw_msg);
0385 extern void rio_pw_enable(struct rio_mport *mport, int enable);
0386 
0387 /* LDM support */
0388 int rio_register_driver(struct rio_driver *);
0389 void rio_unregister_driver(struct rio_driver *);
0390 struct rio_dev *rio_dev_get(struct rio_dev *);
0391 void rio_dev_put(struct rio_dev *);
0392 
0393 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
0394 extern struct dma_chan *rio_request_dma(struct rio_dev *rdev);
0395 extern struct dma_chan *rio_request_mport_dma(struct rio_mport *mport);
0396 extern void rio_release_dma(struct dma_chan *dchan);
0397 extern struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(
0398         struct rio_dev *rdev, struct dma_chan *dchan,
0399         struct rio_dma_data *data,
0400         enum dma_transfer_direction direction, unsigned long flags);
0401 extern struct dma_async_tx_descriptor *rio_dma_prep_xfer(
0402         struct dma_chan *dchan, u16 destid,
0403         struct rio_dma_data *data,
0404         enum dma_transfer_direction direction, unsigned long flags);
0405 #endif
0406 
0407 /**
0408  * rio_name - Get the unique RIO device identifier
0409  * @rdev: RIO device
0410  *
0411  * Get the unique RIO device identifier. Returns the device
0412  * identifier string.
0413  */
0414 static inline const char *rio_name(struct rio_dev *rdev)
0415 {
0416     return dev_name(&rdev->dev);
0417 }
0418 
0419 /**
0420  * rio_get_drvdata - Get RIO driver specific data
0421  * @rdev: RIO device
0422  *
0423  * Get RIO driver specific data. Returns a pointer to the
0424  * driver specific data.
0425  */
0426 static inline void *rio_get_drvdata(struct rio_dev *rdev)
0427 {
0428     return dev_get_drvdata(&rdev->dev);
0429 }
0430 
0431 /**
0432  * rio_set_drvdata - Set RIO driver specific data
0433  * @rdev: RIO device
0434  * @data: Pointer to driver specific data
0435  *
0436  * Set RIO driver specific data. device struct driver data pointer
0437  * is set to the @data argument.
0438  */
0439 static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
0440 {
0441     dev_set_drvdata(&rdev->dev, data);
0442 }
0443 
0444 /* Misc driver helpers */
0445 extern u16 rio_local_get_device_id(struct rio_mport *port);
0446 extern void rio_local_set_device_id(struct rio_mport *port, u16 did);
0447 extern int rio_init_mports(void);
0448 
0449 #endif              /* LINUX_RIO_DRV_H */