lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230111090222.2016499-6-Vijendar.Mukunda@amd.com>
Date:   Wed, 11 Jan 2023 14:32:08 +0530
From:   Vijendar Mukunda <Vijendar.Mukunda@....com>
To:     <broonie@...nel.org>, <vkoul@...nel.org>,
        <alsa-devel@...a-project.org>
CC:     <Basavaraj.Hiregoudar@....com>, <Sunil-kumar.Dommati@....com>,
        <Mario.Limonciello@....com>, <Mastan.Katragadda@....com>,
        <arungopal.kondaveeti@....com>,
        Vijendar Mukunda <Vijendar.Mukunda@....com>,
        Bard Liao <yung-chuan.liao@...ux.intel.com>,
        Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>,
        Sanyog Kale <sanyog.r.kale@...el.com>,
        open list <linux-kernel@...r.kernel.org>
Subject: [PATCH 05/19] soundwire: amd: add soundwire interrupt handling

Add support for handling soundwire controller interrupts.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@....com>
Signed-off-by: Mastan Katragadda <Mastan.Katragadda@....com>
---
 drivers/soundwire/amd_master.c    | 156 ++++++++++++++++++++++++++++++
 drivers/soundwire/amd_master.h    |   1 +
 include/linux/soundwire/sdw_amd.h |   3 +
 3 files changed, 160 insertions(+)

diff --git a/drivers/soundwire/amd_master.c b/drivers/soundwire/amd_master.c
index 93bffe6ff9e2..c7063b8bdd7b 100644
--- a/drivers/soundwire/amd_master.c
+++ b/drivers/soundwire/amd_master.c
@@ -557,6 +557,47 @@ amd_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num)
 	return amd_program_scp_addr(ctrl, &msg);
 }
 
+static void amd_sdwc_process_ping_status(u64 response, struct amd_sdwc_ctrl *ctrl)
+{
+	u64 slave_stat = 0;
+	u32 val = 0;
+	u16 dev_index;
+
+	/* slave status from ping response*/
+	slave_stat = FIELD_GET(AMD_SDW_MCP_SLAVE_STAT_0_3, response);
+	slave_stat |= FIELD_GET(AMD_SDW_MCP_SLAVE_STAT_4_11, response) << 8;
+
+	dev_dbg(ctrl->dev, "%s: slave_stat:0x%llx\n", __func__, slave_stat);
+	for (dev_index = 0; dev_index <= SDW_MAX_DEVICES; ++dev_index) {
+		val = (slave_stat >> (dev_index * 2)) & AMD_SDW_MCP_SLAVE_STATUS_MASK;
+		dev_dbg(ctrl->dev, "%s val:0x%x\n", __func__, val);
+		switch (val) {
+		case SDW_SLAVE_ATTACHED:
+			ctrl->status[dev_index] = SDW_SLAVE_ATTACHED;
+			break;
+		case SDW_SLAVE_UNATTACHED:
+			ctrl->status[dev_index] = SDW_SLAVE_UNATTACHED;
+			break;
+		case SDW_SLAVE_ALERT:
+			ctrl->status[dev_index] = SDW_SLAVE_ALERT;
+			break;
+		default:
+			ctrl->status[dev_index] = SDW_SLAVE_RESERVED;
+			break;
+		}
+	}
+}
+
+static void amd_sdwc_read_and_process_ping_status(struct amd_sdwc_ctrl *ctrl)
+{
+	u64 response = 0;
+
+	mutex_lock(&ctrl->bus.msg_lock);
+	response = amd_sdwc_send_cmd_get_resp(ctrl, 0, 0);
+	mutex_unlock(&ctrl->bus.msg_lock);
+	amd_sdwc_process_ping_status(response, ctrl);
+}
+
 static u32 amd_sdwc_read_ping_status(struct sdw_bus *bus)
 {
 	struct amd_sdwc_ctrl *ctrl = to_amd_sdw(bus);
@@ -1132,6 +1173,119 @@ static int amd_sdwc_register_dais(struct amd_sdwc_ctrl *ctrl)
 					       dais, num_dais);
 }
 
+static void amd_sdwc_update_slave_status_work(struct work_struct *work)
+{
+	struct amd_sdwc_ctrl *ctrl =
+		container_of(work, struct amd_sdwc_ctrl, amd_sdw_work);
+	u32 sw_status_change_mask_0to7_reg;
+	u32 sw_status_change_mask_8to11_reg;
+
+	switch (ctrl->instance) {
+	case ACP_SDW0:
+		sw_status_change_mask_0to7_reg = SW_STATE_CHANGE_STATUS_MASK_0TO7;
+		sw_status_change_mask_8to11_reg = SW_STATE_CHANGE_STATUS_MASK_8TO11;
+		break;
+	case ACP_SDW1:
+		sw_status_change_mask_0to7_reg = P1_SW_STATE_CHANGE_STATUS_MASK_0TO7;
+		sw_status_change_mask_8to11_reg = P1_SW_STATE_CHANGE_STATUS_MASK_8TO11;
+		break;
+	default:
+		dev_err(ctrl->dev, "Invalid Soundwire controller instance\n");
+		return;
+	}
+
+	if (ctrl->status[0] == SDW_SLAVE_ATTACHED) {
+		acp_reg_writel(0, ctrl->mmio + sw_status_change_mask_0to7_reg);
+		acp_reg_writel(0, ctrl->mmio + sw_status_change_mask_8to11_reg);
+	}
+
+update_status:
+	sdw_handle_slave_status(&ctrl->bus, ctrl->status);
+	if (ctrl->status[0] == SDW_SLAVE_ATTACHED) {
+		acp_reg_writel(AMD_SDW_IRQ_MASK_0TO7, ctrl->mmio + sw_status_change_mask_0to7_reg);
+		acp_reg_writel(AMD_SDW_IRQ_MASK_8TO11,
+			       ctrl->mmio + sw_status_change_mask_8to11_reg);
+		amd_sdwc_read_and_process_ping_status(ctrl);
+		goto update_status;
+	}
+}
+
+static void amd_sdwc_update_slave_status(u32 status_change_0to7, u32 status_change_8to11,
+					 struct amd_sdwc_ctrl *ctrl)
+{
+	u64 slave_stat = 0;
+	u32 val = 0;
+	int dev_index;
+
+	if (status_change_0to7 == AMD_SDW_SLAVE_0_ATTACHED)
+		memset(ctrl->status, 0, sizeof(ctrl->status));
+	slave_stat = status_change_0to7;
+	slave_stat |= FIELD_GET(AMD_SDW_MCP_SLAVE_STATUS_8TO_11, status_change_8to11) << 32;
+	dev_dbg(ctrl->dev, "%s: status_change_0to7:0x%x status_change_8to11:0x%x\n",
+		__func__, status_change_0to7, status_change_8to11);
+	if (slave_stat) {
+		for (dev_index = 0; dev_index <= SDW_MAX_DEVICES; ++dev_index) {
+			if (slave_stat & AMD_SDW_MCP_SLAVE_STATUS_VALID_MASK(dev_index)) {
+				val = (slave_stat >> AMD_SDW_MCP_SLAVE_STAT_SHIFT_MASK(dev_index)) &
+				      AMD_SDW_MCP_SLAVE_STATUS_MASK;
+				switch (val) {
+				case SDW_SLAVE_ATTACHED:
+					ctrl->status[dev_index] = SDW_SLAVE_ATTACHED;
+					break;
+				case SDW_SLAVE_UNATTACHED:
+					ctrl->status[dev_index] = SDW_SLAVE_UNATTACHED;
+					break;
+				case SDW_SLAVE_ALERT:
+					ctrl->status[dev_index] = SDW_SLAVE_ALERT;
+					break;
+				default:
+					ctrl->status[dev_index] = SDW_SLAVE_RESERVED;
+					break;
+				}
+			}
+		}
+	}
+}
+
+static void amd_sdwc_irq_thread(struct work_struct *work)
+{
+	struct amd_sdwc_ctrl *ctrl =
+			container_of(work, struct amd_sdwc_ctrl, amd_sdw_irq_thread);
+	u32 sw_status_change_0to7_reg;
+	u32 sw_status_change_8to11_reg;
+	u32 status_change_8to11;
+	u32 status_change_0to7;
+
+	switch (ctrl->instance) {
+	case ACP_SDW0:
+		sw_status_change_0to7_reg = SW_STATE_CHANGE_STATUS_0TO7;
+		sw_status_change_8to11_reg = SW_STATE_CHANGE_STATUS_8TO11;
+		break;
+	case ACP_SDW1:
+		sw_status_change_0to7_reg = P1_SW_STATE_CHANGE_STATUS_0TO7;
+		sw_status_change_8to11_reg = P1_SW_STATE_CHANGE_STATUS_8TO11;
+		break;
+	default:
+		dev_err(ctrl->dev, "Invalid Soundwire controller instance\n");
+		return;
+	}
+
+	status_change_8to11 = acp_reg_readl(ctrl->mmio + sw_status_change_8to11_reg);
+	status_change_0to7 = acp_reg_readl(ctrl->mmio + sw_status_change_0to7_reg);
+	dev_dbg(ctrl->dev, "%s [SDW%d] SDW INT: 0to7=0x%x, 8to11=0x%x\n",
+		__func__, ctrl->instance, status_change_0to7, status_change_8to11);
+	if (status_change_8to11 & AMD_SDW_PREQ_INTR_STAT) {
+		amd_sdwc_read_and_process_ping_status(ctrl);
+	} else {
+		/* Check for the updated status on Slave device */
+		amd_sdwc_update_slave_status(status_change_0to7, status_change_8to11, ctrl);
+	}
+	if (status_change_8to11 || status_change_0to7)
+		schedule_work(&ctrl->amd_sdw_work);
+	acp_reg_writel(0x00, ctrl->mmio + sw_status_change_8to11_reg);
+	acp_reg_writel(0x00, ctrl->mmio + sw_status_change_0to7_reg);
+}
+
 static void amd_sdwc_probe_work(struct work_struct *work)
 {
 	struct amd_sdwc_ctrl *ctrl  = container_of(work, struct amd_sdwc_ctrl, probe_work);
@@ -1229,6 +1383,8 @@ static int amd_sdwc_probe(struct platform_device *pdev)
 		sdw_bus_master_delete(&ctrl->bus);
 		return ret;
 	}
+	INIT_WORK(&ctrl->amd_sdw_irq_thread, amd_sdwc_irq_thread);
+	INIT_WORK(&ctrl->amd_sdw_work, amd_sdwc_update_slave_status_work);
 	INIT_WORK(&ctrl->probe_work, amd_sdwc_probe_work);
 	schedule_work(&ctrl->probe_work);
 	return 0;
diff --git a/drivers/soundwire/amd_master.h b/drivers/soundwire/amd_master.h
index 42f32ca0c7a8..b43a5d6496cb 100644
--- a/drivers/soundwire/amd_master.h
+++ b/drivers/soundwire/amd_master.h
@@ -236,6 +236,7 @@
 #define AMD_SDW1_PAD_KEEPER_EN_MASK	0x10
 #define AMD_SDW0_PAD_KEEPER_DISABLE_MASK        0x1E
 #define AMD_SDW1_PAD_KEEPER_DISABLE_MASK	0xF
+#define AMD_SDW_PREQ_INTR_STAT  BIT(19)
 
 enum amd_sdw_channel {
 	/* SDW0 */
diff --git a/include/linux/soundwire/sdw_amd.h b/include/linux/soundwire/sdw_amd.h
index 7a99d782969f..2db03b2f0c3b 100644
--- a/include/linux/soundwire/sdw_amd.h
+++ b/include/linux/soundwire/sdw_amd.h
@@ -24,9 +24,12 @@ struct amd_sdwc_ctrl {
 	struct sdw_bus bus;
 	struct device *dev;
 	void __iomem *mmio;
+	struct work_struct amd_sdw_irq_thread;
+	struct work_struct amd_sdw_work;
 	struct work_struct probe_work;
 	struct mutex *sdw_lock;
 	struct sdw_stream_runtime *sruntime[AMD_SDW_MAX_DAIS];
+	enum sdw_slave_status status[SDW_MAX_DEVICES + 1];
 	int num_din_ports;
 	int num_dout_ports;
 	int cols_index;
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ