// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2020 Google LLC
 *
 * Modified from coreboot nhlt.c
 */

#define LOG_CATEGORY	LOGC_ACPI

#include <common.h>
#include <binman.h>
#include <dm.h>
#include <log.h>
#include <malloc.h>
#include <tables_csum.h>
#include <acpi/acpi_table.h>
#include <asm/acpi_nhlt.h>
#include <asm/unaligned.h>
#include <dm/acpi.h>

#define NHLT_RID		1
#define NHLT_SSID		1
#define WAVEFORMAT_TAG		0xfffe
#define DEFAULT_VIRTUAL_BUS_ID	0

static const struct sub_format pcm_subformat = {
	.data1 = 0x00000001,
	.data2 = 0x0000,
	.data3 = 0x0010,
	.data4 = { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 },
};

struct nhlt *nhlt_init(void)
{
	struct nhlt *nhlt;

	nhlt = malloc(sizeof(*nhlt));

	if (!nhlt)
		return NULL;

	memset(nhlt, 0, sizeof(*nhlt));
	nhlt->subsystem_id = NHLT_SSID;

	return nhlt;
}

struct nhlt_endpoint *nhlt_add_endpoint(struct nhlt *nhlt, int link_type,
					int device_type, int dir,
					u16 vid, u16 did)
{
	struct nhlt_endpoint *endp;

	if (link_type < NHLT_LINK_HDA || link_type >= NHLT_MAX_LINK_TYPES)
		return NULL;

	if (nhlt->num_endpoints >= MAX_ENDPOINTS)
		return NULL;

	endp = &nhlt->endpoints[nhlt->num_endpoints];

	endp->link_type = link_type;
	endp->instance_id = nhlt->current_instance_id[link_type];
	endp->vendor_id = vid;
	endp->device_id = did;
	endp->revision_id = NHLT_RID;
	endp->subsystem_id = nhlt->subsystem_id;
	endp->device_type = device_type;
	endp->direction = dir;
	endp->virtual_bus_id = DEFAULT_VIRTUAL_BUS_ID;

	nhlt->num_endpoints++;

	return endp;
}

static int append_specific_config(struct nhlt_specific_config *spec_cfg,
				  const void *config, size_t config_sz)
{
	size_t new_sz;
	void *new_cfg;

	new_sz = spec_cfg->size + config_sz;
	new_cfg = malloc(new_sz);
	if (!new_cfg)
		return -ENOMEM;

	/* Append new config */
	memcpy(new_cfg, spec_cfg->capabilities, spec_cfg->size);
	memcpy(new_cfg + spec_cfg->size, config, config_sz);

	free(spec_cfg->capabilities);

	/* Update with new config data */
	spec_cfg->size = new_sz;
	spec_cfg->capabilities = new_cfg;

	return 0;
}

int nhlt_endpoint_append_config(struct nhlt_endpoint *endp, const void *config,
				size_t config_sz)
{
	return append_specific_config(&endp->config, config, config_sz);
}

struct nhlt_format *nhlt_add_format(struct nhlt_endpoint *endp,
				    int num_channels, int sample_freq_khz,
				    int container_bits_per_sample,
				    int valid_bits_per_sample,
				    uint32_t speaker_mask)
{
	struct nhlt_format *fmt;
	struct nhlt_waveform *wave;

	if (endp->num_formats >= MAX_FORMATS)
		return NULL;

	fmt = &endp->formats[endp->num_formats];
	wave = &fmt->waveform;

	wave->tag = WAVEFORMAT_TAG;
	wave->num_channels = num_channels;
	wave->samples_per_second = sample_freq_khz * 1000;
	wave->bits_per_sample = container_bits_per_sample;
	wave->extra_size = sizeof(wave->valid_bits_per_sample);
	wave->extra_size += sizeof(wave->channel_mask);
	wave->extra_size += sizeof(wave->sub_format);
	wave->valid_bits_per_sample = valid_bits_per_sample;
	wave->channel_mask = speaker_mask;
	memcpy(&wave->sub_format, &pcm_subformat, sizeof(wave->sub_format));

	/* Calculate the dervied fields */
	wave->block_align = wave->num_channels * wave->bits_per_sample / 8;
	wave->bytes_per_second = wave->block_align * wave->samples_per_second;

	endp->num_formats++;

	return fmt;
}

int nhlt_format_append_config(struct nhlt_format *fmt, const void *config,
			      size_t config_sz)
{
	return append_specific_config(&fmt->config, config, config_sz);
}

int nhlt_endpoint_add_formats(struct nhlt_endpoint *endp,
			      const struct nhlt_format_config *formats,
			      size_t num_formats)
{
	ofnode node;
	size_t i;

	node = binman_section_find_node("private-files");

	for (i = 0; i < num_formats; i++) {
		const struct nhlt_format_config *cfg = &formats[i];
		struct nhlt_format *fmt;
		void *data;
		int size;
		int ret;

		fmt = nhlt_add_format(endp, cfg->num_channels,
				      cfg->sample_freq_khz,
				      cfg->container_bits_per_sample,
				      cfg->valid_bits_per_sample,
				      cfg->speaker_mask);
		if (!fmt)
			return -ENOSPC;

		if (!cfg->settings_file)
			continue;

		ret = binman_entry_map(node, cfg->settings_file, &data, &size);
		if (ret) {
			log_warning("Failed to find settings file %s\n",
				    cfg->settings_file);
			return log_msg_ret("settings", ret);
		}

		ret = nhlt_format_append_config(fmt, data, size);
		if (ret)
			return log_msg_ret("append", ret);
	}

	return 0;
}

void nhlt_next_instance(struct nhlt *nhlt, int link_type)
{
	if (link_type < NHLT_LINK_HDA || link_type >= NHLT_MAX_LINK_TYPES)
		return;

	nhlt->current_instance_id[link_type]++;
}

static size_t calc_specific_config_size(struct nhlt_specific_config *cfg)
{
	return sizeof(cfg->size) + cfg->size;
}

static size_t calc_format_size(struct nhlt_format *fmt)
{
	size_t sz = 0;

	/* Wave format first */
	sz += sizeof(fmt->waveform.tag);
	sz += sizeof(fmt->waveform.num_channels);
	sz += sizeof(fmt->waveform.samples_per_second);
	sz += sizeof(fmt->waveform.bytes_per_second);
	sz += sizeof(fmt->waveform.block_align);
	sz += sizeof(fmt->waveform.bits_per_sample);
	sz += sizeof(fmt->waveform.extra_size);
	sz += sizeof(fmt->waveform.valid_bits_per_sample);
	sz += sizeof(fmt->waveform.channel_mask);
	sz += sizeof(fmt->waveform.sub_format);

	sz += calc_specific_config_size(&fmt->config);

	return sz;
}

static size_t calc_endpoint_size(struct nhlt_endpoint *endp)
{
	int i;
	size_t sz = 0;

	sz += sizeof(endp->length) + sizeof(endp->link_type);
	sz += sizeof(endp->instance_id) + sizeof(endp->vendor_id);
	sz += sizeof(endp->device_id) + sizeof(endp->revision_id);
	sz += sizeof(endp->subsystem_id) + sizeof(endp->device_type);
	sz += sizeof(endp->direction) + sizeof(endp->virtual_bus_id);
	sz += calc_specific_config_size(&endp->config);
	sz += sizeof(endp->num_formats);

	for (i = 0; i < endp->num_formats; i++)
		sz += calc_format_size(&endp->formats[i]);

	/* Adjust endpoint length to reflect current configuration */
	endp->length = sz;

	return sz;
}

static size_t calc_endpoints_size(struct nhlt *nhlt)
{
	size_t sz = 0;
	int i;

	for (i = 0; i < nhlt->num_endpoints; i++)
		sz += calc_endpoint_size(&nhlt->endpoints[i]);

	return sz;
}

static size_t calc_size(struct nhlt *nhlt)
{
	return sizeof(nhlt->num_endpoints) + calc_endpoints_size(nhlt);
}

size_t nhlt_current_size(struct nhlt *nhlt)
{
	return calc_size(nhlt) + sizeof(struct acpi_table_header);
}

static void nhlt_free_resources(struct nhlt *nhlt)
{
	int i, j;

	/* Free all specific configs */
	for (i = 0; i < nhlt->num_endpoints; i++) {
		struct nhlt_endpoint *endp = &nhlt->endpoints[i];

		free(endp->config.capabilities);
		for (j = 0; j < endp->num_formats; j++) {
			struct nhlt_format *fmt = &endp->formats[j];

			free(fmt->config.capabilities);
		}
	}

	/* Free nhlt object proper */
	free(nhlt);
}

struct cursor {
	u8 *buf;
};

static void ser8(struct cursor *cur, uint val)
{
	*cur->buf = val;
	cur->buf += sizeof(val);
}

static void ser16(struct cursor *cur, uint val)
{
	put_unaligned_le16(val, cur->buf);
	cur->buf += sizeof(val);
}

static void ser32(struct cursor *cur, uint val)
{
	put_unaligned_le32(val, cur->buf);
	cur->buf += sizeof(val);
}

static void serblob(struct cursor *cur, void *from, size_t sz)
{
	memcpy(cur->buf, from, sz);
	cur->buf += sz;
}

static void serialise_specific_config(struct nhlt_specific_config *cfg,
				      struct cursor *cur)
{
	ser32(cur, cfg->size);
	serblob(cur, cfg->capabilities, cfg->size);
}

static void serialise_waveform(struct nhlt_waveform *wave, struct cursor *cur)
{
	ser16(cur, wave->tag);
	ser16(cur, wave->num_channels);
	ser32(cur, wave->samples_per_second);
	ser32(cur, wave->bytes_per_second);
	ser16(cur, wave->block_align);
	ser16(cur, wave->bits_per_sample);
	ser16(cur, wave->extra_size);
	ser16(cur, wave->valid_bits_per_sample);
	ser32(cur, wave->channel_mask);
	ser32(cur, wave->sub_format.data1);
	ser16(cur, wave->sub_format.data2);
	ser16(cur, wave->sub_format.data3);
	serblob(cur, wave->sub_format.data4, sizeof(wave->sub_format.data4));
}

static void serialise_format(struct nhlt_format *fmt, struct cursor *cur)
{
	serialise_waveform(&fmt->waveform, cur);
	serialise_specific_config(&fmt->config, cur);
}

static void serialise_endpoint(struct nhlt_endpoint *endp, struct cursor *cur)
{
	int i;

	ser32(cur, endp->length);
	ser8(cur, endp->link_type);
	ser8(cur, endp->instance_id);
	ser16(cur, endp->vendor_id);
	ser16(cur, endp->device_id);
	ser16(cur, endp->revision_id);
	ser32(cur, endp->subsystem_id);
	ser8(cur, endp->device_type);
	ser8(cur, endp->direction);
	ser8(cur, endp->virtual_bus_id);
	serialise_specific_config(&endp->config, cur);
	ser8(cur, endp->num_formats);

	for (i = 0; i < endp->num_formats; i++)
		serialise_format(&endp->formats[i], cur);
}

static void nhlt_serialise_endpoints(struct nhlt *nhlt, struct cursor *cur)
{
	int i;

	ser8(cur, nhlt->num_endpoints);

	for (i = 0; i < nhlt->num_endpoints; i++)
		serialise_endpoint(&nhlt->endpoints[i], cur);
}

int nhlt_serialise_oem_overrides(struct acpi_ctx *ctx, struct nhlt *nhlt,
				 const char *oem_id, const char *oem_table_id,
				 uint32_t oem_revision)
{
	struct cursor cur;
	struct acpi_table_header *header;
	size_t sz;
	size_t oem_id_len;
	size_t oem_table_id_len;
	int ret;

	log_info("ACPI:    * NHLT\n");
	sz = nhlt_current_size(nhlt);

	/* Create header */
	header = (void *)ctx->current;
	memset(header, '\0', sizeof(struct acpi_table_header));
	acpi_fill_header(header, "NHLT");
	header->length = sz;
	header->revision = acpi_get_table_revision(ACPITAB_NHLT);

	if (oem_id) {
		oem_id_len = min((int)strlen(oem_id), 6);
		memcpy(header->oem_id, oem_id, oem_id_len);
	}
	if (oem_table_id) {
		oem_table_id_len = min((int)strlen(oem_table_id), 8);
		memcpy(header->oem_table_id, oem_table_id, oem_table_id_len);
	}
	header->oem_revision = oem_revision;

	cur.buf = (void *)(header + 1);
	nhlt_serialise_endpoints(nhlt, &cur);

	header->checksum = table_compute_checksum(header, sz);
	nhlt_free_resources(nhlt);

	ret = acpi_add_table(ctx, ctx->current);
	if (ret)
		return log_msg_ret("add", ret);
	acpi_inc_align(ctx, sz);

	return 0;
}

static int _nhlt_add_single_endpoint(struct nhlt *nhlt, int virtual_bus_id,
				     const struct nhlt_endp_descriptor *epd)
{
	struct nhlt_endpoint *endp;
	int ret;

	endp = nhlt_add_endpoint(nhlt, epd->link, epd->device, epd->direction,
				 epd->vid, epd->did);
	if (!endp)
		return -EINVAL;

	endp->virtual_bus_id = virtual_bus_id;

	ret = nhlt_endpoint_append_config(endp, epd->cfg, epd->cfg_size);
	if (ret)
		return ret;

	ret = nhlt_endpoint_add_formats(endp, epd->formats, epd->num_formats);
	if (ret)
		return log_msg_ret("formats", ret);

	return 0;
}

static int _nhlt_add_endpoints(struct nhlt *nhlt, int virtual_bus_id,
			       const struct nhlt_endp_descriptor *epds,
			       size_t num_epds)
{
	size_t i;
	int ret;

	for (i = 0; i < num_epds; i++) {
		ret = _nhlt_add_single_endpoint(nhlt, virtual_bus_id, &epds[i]);
		if (ret)
			return log_ret(ret);
	}

	return 0;
}

int nhlt_add_endpoints(struct nhlt *nhlt,
		       const struct nhlt_endp_descriptor *epds, size_t num_epds)
{
	int ret;

	ret = _nhlt_add_endpoints(nhlt, DEFAULT_VIRTUAL_BUS_ID, epds, num_epds);

	return ret;
}

int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id,
			   const struct nhlt_endp_descriptor *epds,
			   size_t num_epds)
{
	int ret;

	ret = _nhlt_add_endpoints(nhlt, virtual_bus_id, epds, num_epds);
	if (!ret)
		nhlt_next_instance(nhlt, NHLT_LINK_SSP);

	return ret;
}
