0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/io.h>
0009 #include <linux/processor.h>
0010 #include <linux/types.h>
0011
0012 #include "common.h"
0013
0014
0015
0016
0017
0018
0019 struct scmi_shared_mem {
0020 __le32 reserved;
0021 __le32 channel_status;
0022 #define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1)
0023 #define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0)
0024 __le32 reserved1[2];
0025 __le32 flags;
0026 #define SCMI_SHMEM_FLAG_INTR_ENABLED BIT(0)
0027 __le32 length;
0028 __le32 msg_header;
0029 u8 msg_payload[];
0030 };
0031
0032 void shmem_tx_prepare(struct scmi_shared_mem __iomem *shmem,
0033 struct scmi_xfer *xfer)
0034 {
0035
0036
0037
0038
0039
0040
0041 spin_until_cond(ioread32(&shmem->channel_status) &
0042 SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
0043
0044 iowrite32(0x0, &shmem->channel_status);
0045 iowrite32(xfer->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED,
0046 &shmem->flags);
0047 iowrite32(sizeof(shmem->msg_header) + xfer->tx.len, &shmem->length);
0048 iowrite32(pack_scmi_header(&xfer->hdr), &shmem->msg_header);
0049 if (xfer->tx.buf)
0050 memcpy_toio(shmem->msg_payload, xfer->tx.buf, xfer->tx.len);
0051 }
0052
0053 u32 shmem_read_header(struct scmi_shared_mem __iomem *shmem)
0054 {
0055 return ioread32(&shmem->msg_header);
0056 }
0057
0058 void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem,
0059 struct scmi_xfer *xfer)
0060 {
0061 xfer->hdr.status = ioread32(shmem->msg_payload);
0062
0063 xfer->rx.len = min_t(size_t, xfer->rx.len,
0064 ioread32(&shmem->length) - 8);
0065
0066
0067 memcpy_fromio(xfer->rx.buf, shmem->msg_payload + 4, xfer->rx.len);
0068 }
0069
0070 void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem,
0071 size_t max_len, struct scmi_xfer *xfer)
0072 {
0073
0074 xfer->rx.len = min_t(size_t, max_len, ioread32(&shmem->length) - 4);
0075
0076
0077 memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len);
0078 }
0079
0080 void shmem_clear_channel(struct scmi_shared_mem __iomem *shmem)
0081 {
0082 iowrite32(SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE, &shmem->channel_status);
0083 }
0084
0085 bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem,
0086 struct scmi_xfer *xfer)
0087 {
0088 u16 xfer_id;
0089
0090 xfer_id = MSG_XTRACT_TOKEN(ioread32(&shmem->msg_header));
0091
0092 if (xfer->hdr.seq != xfer_id)
0093 return false;
0094
0095 return ioread32(&shmem->channel_status) &
0096 (SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR |
0097 SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
0098 }