Lines Matching +full:scmi +full:- +full:shmem
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2019-2024 ARM Ltd.
20 * SCMI specification requires all parameters, message headers, return
37 static void shmem_tx_prepare(struct scmi_shared_mem __iomem *shmem, in shmem_tx_prepare() argument
47 * overwriting its response with new message payload or vice-versa. in shmem_tx_prepare()
49 * not to bail-out on intermittent issues where the platform is in shmem_tx_prepare()
52 * Note that after a timeout is detected we bail-out and carry on but in shmem_tx_prepare()
55 * due to a misbehaving SCMI firmware. in shmem_tx_prepare()
57 stop = ktime_add_ms(ktime_get(), 2 * cinfo->rx_timeout_ms); in shmem_tx_prepare()
58 spin_until_cond((ioread32(&shmem->channel_status) & in shmem_tx_prepare()
61 if (!(ioread32(&shmem->channel_status) & in shmem_tx_prepare()
64 dev_err(cinfo->dev, in shmem_tx_prepare()
70 iowrite32(0x0, &shmem->channel_status); in shmem_tx_prepare()
71 iowrite32(xfer->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED, in shmem_tx_prepare()
72 &shmem->flags); in shmem_tx_prepare()
73 iowrite32(sizeof(shmem->msg_header) + xfer->tx.len, &shmem->length); in shmem_tx_prepare()
74 iowrite32(pack_scmi_header(&xfer->hdr), &shmem->msg_header); in shmem_tx_prepare()
75 if (xfer->tx.buf) in shmem_tx_prepare()
76 memcpy_toio(shmem->msg_payload, xfer->tx.buf, xfer->tx.len); in shmem_tx_prepare()
79 static u32 shmem_read_header(struct scmi_shared_mem __iomem *shmem) in shmem_read_header() argument
81 return ioread32(&shmem->msg_header); in shmem_read_header()
84 static void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem, in shmem_fetch_response() argument
87 size_t len = ioread32(&shmem->length); in shmem_fetch_response()
89 xfer->hdr.status = ioread32(shmem->msg_payload); in shmem_fetch_response()
90 /* Skip the length of header and status in shmem area i.e 8 bytes */ in shmem_fetch_response()
91 xfer->rx.len = min_t(size_t, xfer->rx.len, len > 8 ? len - 8 : 0); in shmem_fetch_response()
94 memcpy_fromio(xfer->rx.buf, shmem->msg_payload + 4, xfer->rx.len); in shmem_fetch_response()
97 static void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem, in shmem_fetch_notification() argument
100 size_t len = ioread32(&shmem->length); in shmem_fetch_notification()
102 /* Skip only the length of header in shmem area i.e 4 bytes */ in shmem_fetch_notification()
103 xfer->rx.len = min_t(size_t, max_len, len > 4 ? len - 4 : 0); in shmem_fetch_notification()
106 memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len); in shmem_fetch_notification()
109 static void shmem_clear_channel(struct scmi_shared_mem __iomem *shmem) in shmem_clear_channel() argument
111 iowrite32(SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE, &shmem->channel_status); in shmem_clear_channel()
114 static bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem, in shmem_poll_done() argument
119 xfer_id = MSG_XTRACT_TOKEN(ioread32(&shmem->msg_header)); in shmem_poll_done()
121 if (xfer->hdr.seq != xfer_id) in shmem_poll_done()
124 return ioread32(&shmem->channel_status) & in shmem_poll_done()
129 static bool shmem_channel_free(struct scmi_shared_mem __iomem *shmem) in shmem_channel_free() argument
131 return (ioread32(&shmem->channel_status) & in shmem_channel_free()
135 static bool shmem_channel_intr_enabled(struct scmi_shared_mem __iomem *shmem) in shmem_channel_intr_enabled() argument
137 return ioread32(&shmem->flags) & SCMI_SHMEM_FLAG_INTR_ENABLED; in shmem_channel_intr_enabled()
144 struct device_node *shmem __free(device_node); in shmem_setup_iomap()
147 struct device *cdev = cinfo->dev; in shmem_setup_iomap()
152 shmem = of_parse_phandle(cdev->of_node, "shmem", idx); in shmem_setup_iomap()
153 if (!shmem) in shmem_setup_iomap()
154 return IOMEM_ERR_PTR(-ENODEV); in shmem_setup_iomap()
156 if (!of_device_is_compatible(shmem, "arm,scmi-shmem")) in shmem_setup_iomap()
157 return IOMEM_ERR_PTR(-ENXIO); in shmem_setup_iomap()
159 /* Use a local on-stack as a working area when not provided */ in shmem_setup_iomap()
163 ret = of_address_to_resource(shmem, 0, res); in shmem_setup_iomap()
165 dev_err(cdev, "failed to get SCMI %s shared memory\n", desc); in shmem_setup_iomap()
170 addr = devm_ioremap(dev, res->start, size); in shmem_setup_iomap()
172 dev_err(dev, "failed to ioremap SCMI %s shared memory\n", desc); in shmem_setup_iomap()
173 return IOMEM_ERR_PTR(-EADDRNOTAVAIL); in shmem_setup_iomap()