Commit b647f55420310beb8f576e23f3b6a69745126f71

Authored by Stephen Warren
Committed by Simon Glass
1 parent aa26776a2d

misc: add "call" uclass op

The call op requests that the callee pass a message to the underlying HW
or device, wait for a response, and then pass back the response error code
and message to the callee. It is useful for drivers that represent some
kind of messaging or IPC channel to a remote device.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 46 additions and 0 deletions Side-by-side Diff

drivers/misc/misc-uclass.c
... ... @@ -45,6 +45,17 @@
45 45 return ops->ioctl(dev, request, buf);
46 46 }
47 47  
  48 +int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
  49 + void *rx_msg, int rx_size)
  50 +{
  51 + const struct misc_ops *ops = device_get_ops(dev);
  52 +
  53 + if (!ops->call)
  54 + return -ENOSYS;
  55 +
  56 + return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size);
  57 +}
  58 +
48 59 UCLASS_DRIVER(misc) = {
49 60 .id = UCLASS_MISC,
50 61 .name = "misc",
... ... @@ -38,6 +38,27 @@
38 38 int misc_ioctl(struct udevice *dev, unsigned long request, void *buf);
39 39  
40 40 /*
  41 + * Send a message to the device and wait for a response.
  42 + *
  43 + * The caller provides the message type/ID and payload to be sent.
  44 + * The callee constructs any message header required, transmits it to the
  45 + * target, waits for a response, checks any error code in the response,
  46 + * strips any message header from the response, and returns the error code
  47 + * (or a parsed version of it) and the response message payload.
  48 + *
  49 + * @dev: the device.
  50 + * @msgid: the message ID/number to send.
  51 + * tx_msg: the request/transmit message payload.
  52 + * tx_size: the size of the buffer pointed at by tx_msg.
  53 + * rx_msg: the buffer to receive the response message payload. May be NULL if
  54 + * the caller only cares about the error code.
  55 + * rx_size: the size of the buffer pointed at by rx_msg.
  56 + * @return the response message size if OK, -ve on error
  57 + */
  58 +int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
  59 + void *rx_msg, int rx_size);
  60 +
  61 +/*
41 62 * struct misc_ops - Driver model Misc operations
42 63 *
43 64 * The uclass interface is implemented by all miscellaneous devices which
... ... @@ -74,6 +95,20 @@
74 95 * @return: 0 if OK, -ve on error
75 96 */
76 97 int (*ioctl)(struct udevice *dev, unsigned long request, void *buf);
  98 + /*
  99 + * Send a message to the device and wait for a response.
  100 + *
  101 + * @dev: the device
  102 + * @msgid: the message ID/number to send
  103 + * tx_msg: the request/transmit message payload
  104 + * tx_size: the size of the buffer pointed at by tx_msg
  105 + * rx_msg: the buffer to receive the response message payload. May be
  106 + * NULL if the caller only cares about the error code.
  107 + * rx_size: the size of the buffer pointed at by rx_msg
  108 + * @return the response message size if OK, -ve on error
  109 + */
  110 + int (*call)(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
  111 + void *rx_msg, int rx_size);
77 112 };
78 113  
79 114 #endif /* _MISC_H_ */