Unverified Commit fd4b8004 authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: SOF: Add IPC4 FW loader support

Merge series from Ranjani Sridharan <ranjani.sridharan@linux.intel.com>:

The patches in this series add support for FW loading for IPC4 in the SOF
driver.
parents 0b7f644f a4cfdebd
Loading
Loading
Loading
Loading
+119 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
/*
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 * redistributing this file, you may do so under either license.
 *
 * Copyright(c) 2022 Intel Corporation. All rights reserved.
 */

/*
 * Extended manifest is a place to store metadata about firmware, known during
 * compilation time - for example firmware version or used compiler.
 * Given information are read on host side before firmware startup.
 * This part of output binary is not signed.
 */

#ifndef __SOF_FIRMWARE_EXT_MANIFEST4_H__
#define __SOF_FIRMWARE_EXT_MANIFEST4_H__

#include <linux/uuid.h>

/* In ASCII  $AE1 */
#define SOF_EXT_MAN4_MAGIC_NUMBER	0x31454124

#define MAX_MODULE_NAME_LEN		8
#define MAX_FW_BINARY_NAME		8
#define DEFAULT_HASH_SHA256_LEN		32
#define SOF_MAN4_FW_HDR_OFFSET		0x2000
#define SOF_MAN4_FW_HDR_OFFSET_CAVS_1_5	0x284

/*********************************************************************
 *	extended manifest		(struct sof_ext_manifest4_hdr)
 *-------------------
 *	css_manifest hdr
 *-------------------
 *	offset reserved for future
 *-------------------
 *	fw_hdr				(struct sof_man4_fw_binary_header)
 *-------------------
 *	module_entry[0]			(struct sof_man4_module)
 *-------------------
 *	module_entry[1]
 *-------------------
 *	...
 *-------------------
 *	module_entry[n]
 *-------------------
 *	module_config[0]		(struct sof_man4_module_config)
 *-------------------
 *	module_config[1]
 *-------------------
 *	...
 *-------------------
 *	module_config[m]
 *-------------------
 *	FW content
 *-------------------
 *********************************************************************/

struct sof_ext_manifest4_hdr {
	uint32_t id;
	uint32_t len; /* length of extension manifest */
	uint16_t version_major; /* header version */
	uint16_t version_minor;
	uint32_t num_module_entries;
} __packed;

struct sof_man4_fw_binary_header {
	/* This part must be unchanged to be backward compatible with SPT-LP ROM */
	uint32_t id;
	uint32_t len; /* sizeof(sof_man4_fw_binary_header) in bytes */
	uint8_t name[MAX_FW_BINARY_NAME];
	uint32_t preload_page_count; /* number of pages of preloaded image */
	uint32_t fw_image_flags;
	uint32_t feature_mask;
	uint16_t major_version; /* Firmware version */
	uint16_t minor_version;
	uint16_t hotfix_version;
	uint16_t build_version;
	uint32_t num_module_entries;

	/* This part may change to contain any additional data for BaseFw that is skipped by ROM */
	uint32_t hw_buf_base_addr;
	uint32_t hw_buf_length;
	uint32_t load_offset; /* This value is used by ROM */
} __packed;

struct sof_man4_segment_desc {
	uint32_t flags;
	uint32_t v_base_addr;
	uint32_t file_offset;
} __packed;

struct sof_man4_module {
	uint32_t id;
	uint8_t name[MAX_MODULE_NAME_LEN];
	guid_t uuid;
	uint32_t type;
	uint8_t hash[DEFAULT_HASH_SHA256_LEN];
	uint32_t entry_point;
	uint16_t cfg_offset;
	uint16_t cfg_count;
	uint32_t affinity_mask;
	uint16_t instance_max_count;
	uint16_t instance_stack_size;
	struct sof_man4_segment_desc	segments[3];
} __packed;

struct sof_man4_module_config {
	uint32_t par[4];	/* module parameters */
	uint32_t is_bytes;	/* actual size of instance .bss (bytes) */
	uint32_t cps;		/* cycles per second */
	uint32_t ibs;		/* input buffer size (bytes) */
	uint32_t obs;		/* output buffer size (bytes) */
	uint32_t module_flags;	/* flags, reserved for future use */
	uint32_t cpc;		/* cycles per single run */
	uint32_t obls;		/* output block size, reserved for future use */
} __packed;

#endif /* __SOF_FIRMWARE_EXT_MANIFEST4_H__ */
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
		control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
		ipc3-topology.o ipc3-control.o ipc3.o ipc3-pcm.o ipc3-loader.o\
		ipc4.o
		ipc4.o ipc4-loader.o
ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
snd-sof-objs += sof-client.o
endif
+25 −4
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 * Hardware interface for audio DSP on Apollolake and GeminiLake
 */

#include <sound/sof/ext_manifest4.h>
#include "../ipc4-priv.h"
#include "../sof-priv.h"
#include "hda.h"
#include "../sof-audio.h"
@@ -37,11 +39,30 @@ int sof_apl_ops_init(struct snd_sof_dev *sdev)
	/* probe/remove/shutdown */
	sof_apl_ops.shutdown	= hda_dsp_shutdown;

	if (sdev->pdata->ipc_type == SOF_IPC) {
		/* doorbell */
		sof_apl_ops.irq_thread	= hda_dsp_ipc_irq_thread;

		/* ipc */
		sof_apl_ops.send_msg	= hda_dsp_ipc_send_msg;
	}

	if (sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
		struct sof_ipc4_fw_data *ipc4_data;

		sdev->private = devm_kzalloc(sdev->dev, sizeof(*ipc4_data), GFP_KERNEL);
		if (!sdev->private)
			return -ENOMEM;

		ipc4_data = sdev->private;
		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;

		/* doorbell */
		sof_apl_ops.irq_thread	= hda_dsp_ipc4_irq_thread;

		/* ipc */
		sof_apl_ops.send_msg	= hda_dsp_ipc4_send_msg;
	}

	/* set DAI driver ops */
	hda_set_dai_drv_ops(sdev, &sof_apl_ops);
+105 −4
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
 * Hardware interface for audio DSP on Cannonlake.
 */

#include <sound/sof/ext_manifest4.h>
#include <sound/sof/ipc4/header.h>
#include "../ipc4-priv.h"
#include "../ops.h"
#include "hda.h"
#include "hda-ipc.h"
@@ -29,6 +32,68 @@ static const struct snd_sof_debugfs_map cnl_dsp_debugfs[] = {
static void cnl_ipc_host_done(struct snd_sof_dev *sdev);
static void cnl_ipc_dsp_done(struct snd_sof_dev *sdev);

irqreturn_t cnl_ipc4_irq_thread(int irq, void *context)
{
	struct sof_ipc4_msg notification_data = {{ 0 }};
	struct snd_sof_dev *sdev = context;
	bool ipc_irq = false;
	u32 hipcida, hipctdr;

	hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDA);
	if (hipcida & CNL_DSP_REG_HIPCIDA_DONE) {
		/* DSP received the message */
		snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR,
					CNL_DSP_REG_HIPCCTL,
					CNL_DSP_REG_HIPCCTL_DONE, 0);
		cnl_ipc_dsp_done(sdev);

		ipc_irq = true;
	}

	hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR);
	if (hipctdr & CNL_DSP_REG_HIPCTDR_BUSY) {
		/* Message from DSP (reply or notification) */
		u32 hipctdd = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
					       CNL_DSP_REG_HIPCTDD);
		u32 primary = hipctdr & CNL_DSP_REG_HIPCTDR_MSG_MASK;
		u32 extension = hipctdd & CNL_DSP_REG_HIPCTDD_MSG_MASK;

		if (primary & SOF_IPC4_MSG_DIR_MASK) {
			/* Reply received */
			struct sof_ipc4_msg *data = sdev->ipc->msg.reply_data;

			data->primary = primary;
			data->extension = extension;

			spin_lock_irq(&sdev->ipc_lock);

			snd_sof_ipc_get_reply(sdev);
			snd_sof_ipc_reply(sdev, data->primary);

			spin_unlock_irq(&sdev->ipc_lock);
		} else {
			/* Notification received */
			notification_data.primary = primary;
			notification_data.extension = extension;

			sdev->ipc->msg.rx_data = &notification_data;
			snd_sof_ipc_msgs_rx(sdev);
			sdev->ipc->msg.rx_data = NULL;
		}

		/* Let DSP know that we have finished processing the message */
		cnl_ipc_host_done(sdev);

		ipc_irq = true;
	}

	if (!ipc_irq)
		/* This interrupt is not shared so no need to return IRQ_NONE. */
		dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n");

	return IRQ_HANDLED;
}

irqreturn_t cnl_ipc_irq_thread(int irq, void *context)
{
	struct snd_sof_dev *sdev = context;
@@ -176,6 +241,22 @@ static bool cnl_compact_ipc_compress(struct snd_sof_ipc_msg *msg,
	return false;
}

int cnl_ipc4_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)
{
	struct sof_ipc4_msg *msg_data = msg->msg_data;

	/* send the message via mailbox */
	if (msg_data->data_size)
		sof_mailbox_write(sdev, sdev->host_box.offset, msg_data->data_ptr,
				  msg_data->data_size);

	snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDD, msg_data->extension);
	snd_sof_dsp_write(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDR,
			  msg_data->primary | CNL_DSP_REG_HIPCIDR_BUSY);

	return 0;
}

int cnl_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)
{
	struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
@@ -255,11 +336,31 @@ int sof_cnl_ops_init(struct snd_sof_dev *sdev)
	/* probe/remove/shutdown */
	sof_cnl_ops.shutdown	= hda_dsp_shutdown;

	/* ipc */
	if (sdev->pdata->ipc_type == SOF_IPC) {
		/* doorbell */
		sof_cnl_ops.irq_thread	= cnl_ipc_irq_thread;

		/* ipc */
		sof_cnl_ops.send_msg	= cnl_ipc_send_msg;
	}

	if (sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
		struct sof_ipc4_fw_data *ipc4_data;

		sdev->private = devm_kzalloc(sdev->dev, sizeof(*ipc4_data), GFP_KERNEL);
		if (!sdev->private)
			return -ENOMEM;

		ipc4_data = sdev->private;
		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;

		/* doorbell */
		sof_cnl_ops.irq_thread	= cnl_ipc4_irq_thread;

		/* ipc */
		sof_cnl_ops.send_msg	= cnl_ipc4_send_msg;
	}

	/* set DAI driver ops */
	hda_set_dai_drv_ops(sdev, &sof_cnl_ops);
+82 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 * Hardware interface for generic Intel audio DSP HDA IP
 */

#include <sound/sof/ipc4/header.h>
#include "../ops.h"
#include "hda.h"

@@ -65,6 +66,22 @@ int hda_dsp_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)
	return 0;
}

int hda_dsp_ipc4_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)
{
	struct sof_ipc4_msg *msg_data = msg->msg_data;

	/* send the message via mailbox */
	if (msg_data->data_size)
		sof_mailbox_write(sdev, sdev->host_box.offset, msg_data->data_ptr,
				  msg_data->data_size);

	snd_sof_dsp_write(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE, msg_data->extension);
	snd_sof_dsp_write(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCI,
			  msg_data->primary | HDA_DSP_REG_HIPCI_BUSY);

	return 0;
}

void hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev)
{
	struct snd_sof_ipc_msg *msg = sdev->msg;
@@ -100,6 +117,71 @@ void hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev)
	}
}

irqreturn_t hda_dsp_ipc4_irq_thread(int irq, void *context)
{
	struct sof_ipc4_msg notification_data = {{ 0 }};
	struct snd_sof_dev *sdev = context;
	bool ipc_irq = false;
	u32 hipcie, hipct;

	hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
	if (hipcie & HDA_DSP_REG_HIPCIE_DONE) {
		/* DSP received the message */
		snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL,
					HDA_DSP_REG_HIPCCTL_DONE, 0);
		hda_dsp_ipc_dsp_done(sdev);

		ipc_irq = true;
	}

	hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
	if (hipct & HDA_DSP_REG_HIPCT_BUSY) {
		/* Message from DSP (reply or notification) */
		u32 hipcte = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
					      HDA_DSP_REG_HIPCTE);
		u32 primary = hipct & HDA_DSP_REG_HIPCT_MSG_MASK;
		u32 extension = hipcte & HDA_DSP_REG_HIPCTE_MSG_MASK;

		/* mask BUSY interrupt */
		snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL,
					HDA_DSP_REG_HIPCCTL_BUSY, 0);

		if (primary & SOF_IPC4_MSG_DIR_MASK) {
			/* Reply received */
			struct sof_ipc4_msg *data = sdev->ipc->msg.reply_data;

			data->primary = primary;
			data->extension = extension;

			spin_lock_irq(&sdev->ipc_lock);

			snd_sof_ipc_get_reply(sdev);
			snd_sof_ipc_reply(sdev, data->primary);

			spin_unlock_irq(&sdev->ipc_lock);
		} else {
			/* Notification received */

			notification_data.primary = primary;
			notification_data.extension = extension;
			sdev->ipc->msg.rx_data = &notification_data;
			snd_sof_ipc_msgs_rx(sdev);
			sdev->ipc->msg.rx_data = NULL;
		}

		/* Let DSP know that we have finished processing the message */
		hda_dsp_ipc_host_done(sdev);

		ipc_irq = true;
	}

	if (!ipc_irq)
		/* This interrupt is not shared so no need to return IRQ_NONE. */
		dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n");

	return IRQ_HANDLED;
}

/* IPC handler thread */
irqreturn_t hda_dsp_ipc_irq_thread(int irq, void *context)
{
Loading