^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright(c) 2020 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Author: Cezary Rojewski <cezary.rojewski@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/irqreturn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "messages.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "registers.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define CATPT_IPC_TIMEOUT_MS 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void catpt_ipc_init(struct catpt_ipc *ipc, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ipc->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ipc->ready = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ipc->default_timeout = CATPT_IPC_TIMEOUT_MS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) init_completion(&ipc->done_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) init_completion(&ipc->busy_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) spin_lock_init(&ipc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) mutex_init(&ipc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int catpt_ipc_arm(struct catpt_ipc *ipc, struct catpt_fw_ready *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Both tx and rx are put into and received from outbox. Inbox is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * only used for notifications where payload size is known upfront,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * thus no separate buffer is allocated for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ipc->rx.data = devm_kzalloc(ipc->dev, config->outbox_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (!ipc->rx.data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) memcpy(&ipc->config, config, sizeof(*config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ipc->ready = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void catpt_ipc_msg_init(struct catpt_ipc *ipc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct catpt_ipc_msg *reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) lockdep_assert_held(&ipc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ipc->rx.header = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ipc->rx.size = reply ? reply->size : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) reinit_completion(&ipc->done_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) reinit_completion(&ipc->busy_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void catpt_dsp_send_tx(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) const struct catpt_ipc_msg *tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u32 header = tx->header | CATPT_IPCC_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) trace_catpt_ipc_request(header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) trace_catpt_ipc_payload(tx->data, tx->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) memcpy_toio(catpt_outbox_addr(cdev), tx->data, tx->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) catpt_writel_shim(cdev, IPCC, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int catpt_wait_msg_completion(struct catpt_dev *cdev, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct catpt_ipc *ipc = &cdev->ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ret = wait_for_completion_timeout(&ipc->done_completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) msecs_to_jiffies(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (ipc->rx.rsp.status != CATPT_REPLY_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* wait for delayed reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = wait_for_completion_timeout(&ipc->busy_completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) msecs_to_jiffies(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return ret ? 0 : -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int catpt_dsp_do_send_msg(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct catpt_ipc_msg request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct catpt_ipc_msg *reply, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct catpt_ipc *ipc = &cdev->ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!ipc->ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (request.size > ipc->config.outbox_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) (reply && reply->size > ipc->config.outbox_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) spin_lock_irqsave(&ipc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) catpt_ipc_msg_init(ipc, reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) catpt_dsp_send_tx(cdev, &request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) spin_unlock_irqrestore(&ipc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ret = catpt_wait_msg_completion(cdev, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) dev_crit(cdev->dev, "communication severed: %d, rebooting dsp..\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ipc->ready = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* TODO: attempt recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ret = ipc->rx.rsp.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (reply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) reply->header = ipc->rx.header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!ret && reply->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) memcpy(reply->data, ipc->rx.data, reply->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int catpt_dsp_send_msg_timeout(struct catpt_dev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct catpt_ipc_msg request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct catpt_ipc_msg *reply, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct catpt_ipc *ipc = &cdev->ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) mutex_lock(&ipc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ret = catpt_dsp_do_send_msg(cdev, request, reply, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) mutex_unlock(&ipc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int catpt_dsp_send_msg(struct catpt_dev *cdev, struct catpt_ipc_msg request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct catpt_ipc_msg *reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return catpt_dsp_send_msg_timeout(cdev, request, reply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) cdev->ipc.default_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) catpt_dsp_notify_stream(struct catpt_dev *cdev, union catpt_notify_msg msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct catpt_stream_runtime *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct catpt_notify_position pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct catpt_notify_glitch glitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) stream = catpt_stream_find(cdev, msg.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dev_warn(cdev->dev, "notify %d for non-existent stream %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) msg.notify_reason, msg.stream_hw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) switch (msg.notify_reason) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) case CATPT_NOTIFY_POSITION_CHANGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) memcpy_fromio(&pos, catpt_inbox_addr(cdev), sizeof(pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) trace_catpt_ipc_payload((u8 *)&pos, sizeof(pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) catpt_stream_update_position(cdev, stream, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) case CATPT_NOTIFY_GLITCH_OCCURRED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) memcpy_fromio(&glitch, catpt_inbox_addr(cdev), sizeof(glitch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) trace_catpt_ipc_payload((u8 *)&glitch, sizeof(glitch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_warn(cdev->dev, "glitch %d at pos: 0x%08llx, wp: 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) glitch.type, glitch.presentation_pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) glitch.write_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dev_warn(cdev->dev, "unknown notification: %d received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) msg.notify_reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void catpt_dsp_copy_rx(struct catpt_dev *cdev, u32 header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct catpt_ipc *ipc = &cdev->ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ipc->rx.header = header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (ipc->rx.rsp.status != CATPT_REPLY_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) memcpy_fromio(ipc->rx.data, catpt_outbox_addr(cdev), ipc->rx.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) trace_catpt_ipc_payload(ipc->rx.data, ipc->rx.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static void catpt_dsp_process_response(struct catpt_dev *cdev, u32 header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) union catpt_notify_msg msg = CATPT_MSG(header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct catpt_ipc *ipc = &cdev->ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (msg.fw_ready) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct catpt_fw_ready config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* to fit 32b header original address is shifted right by 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u32 off = msg.mailbox_address << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) memcpy_fromio(&config, cdev->lpe_ba + off, sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) trace_catpt_ipc_payload((u8 *)&config, sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) catpt_ipc_arm(ipc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) complete(&cdev->fw_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) switch (msg.global_msg_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case CATPT_GLB_REQUEST_CORE_DUMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) dev_err(cdev->dev, "ADSP device coredump received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ipc->ready = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) catpt_coredump(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* TODO: attempt recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) case CATPT_GLB_STREAM_MESSAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) switch (msg.stream_msg_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) case CATPT_STRM_NOTIFICATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) catpt_dsp_notify_stream(cdev, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) catpt_dsp_copy_rx(cdev, header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* signal completion of delayed reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) complete(&ipc->busy_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) dev_warn(cdev->dev, "unknown response: %d received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) msg.global_msg_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) irqreturn_t catpt_dsp_irq_thread(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct catpt_dev *cdev = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u32 ipcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ipcd = catpt_readl_shim(cdev, IPCD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) trace_catpt_ipc_notify(ipcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* ensure there is delayed reply or notification to process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!(ipcd & CATPT_IPCD_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) catpt_dsp_process_response(cdev, ipcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* tell DSP processing is completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) catpt_updatel_shim(cdev, IPCD, CATPT_IPCD_BUSY | CATPT_IPCD_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) CATPT_IPCD_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* unmask dsp BUSY interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) catpt_updatel_shim(cdev, IMC, CATPT_IMC_IPCDB, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) irqreturn_t catpt_dsp_irq_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct catpt_dev *cdev = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) irqreturn_t ret = IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u32 isc, ipcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) isc = catpt_readl_shim(cdev, ISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) trace_catpt_irq(isc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* immediate reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (isc & CATPT_ISC_IPCCD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* mask host DONE interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) catpt_updatel_shim(cdev, IMC, CATPT_IMC_IPCCD, CATPT_IMC_IPCCD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ipcc = catpt_readl_shim(cdev, IPCC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) trace_catpt_ipc_reply(ipcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) catpt_dsp_copy_rx(cdev, ipcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) complete(&cdev->ipc.done_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /* tell DSP processing is completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) catpt_updatel_shim(cdev, IPCC, CATPT_IPCC_DONE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* unmask host DONE interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) catpt_updatel_shim(cdev, IMC, CATPT_IMC_IPCCD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ret = IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* delayed reply or notification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (isc & CATPT_ISC_IPCDB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* mask dsp BUSY interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) catpt_updatel_shim(cdev, IMC, CATPT_IMC_IPCDB, CATPT_IMC_IPCDB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ret = IRQ_WAKE_THREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }