Re: [PATCH v1] ASoC: tas2783-sdw: Add basic BPT support
From: Pierre-Louis Bossart
Date: Tue Nov 03 2026 - 12:24:19 EST
> +static int tas2783_fw_download_bpt(struct tas2783_prv *tas_dev,
> + const struct firmware *fmw)
> +{
> + struct sdw_slave *slave = tas_dev->sdw_peripheral;
> + struct sdw_bpt_section *sections = NULL;
> + struct sdw_bus *bus = slave->bus;
> + struct sdw_bpt_msg msg = {0};
> + struct tas_fw_file file;
> + struct tas_fw_hdr hdr;
> + size_t offset = FW_DL_OFFSET;
> + size_t img_sz = fmw->size;
> + const u8 *buf = fmw->data;
> + int num_sections = 0;
> + int i, ret;
> +
> + if (img_sz < FW_DL_OFFSET)
> + return -EINVAL;
> +
> + tas_fw_read_hdr(buf, &hdr);
> + if (hdr.size != img_sz)
> + return -EINVAL;
> +
> + while (offset < (img_sz - FW_FL_HDR)) {
> + size_t adv = (size_t)tas_fw_get_next_file(&buf[offset], &file);
> +
> + /*
> + * Reject a section whose payload runs past the image. Compare
> + * file.length (not adv) against the space left after this
> + * section's header, so the check is immune to the size_t wrap
> + * in tas_fw_get_next_file() on 32-bit kernels.
> + */
> + if (file.length > img_sz - offset - FW_FL_HDR) {
> + dev_err(tas_dev->dev,
> + "Firmware section at offset %zu exceeded.\n",
> + offset);
> + return -EINVAL;
> + }
> + if (num_sections >= TAS2783_MAX_FW_SECTIONS) {
> + dev_err(tas_dev->dev,
> + "BPT fw has too many sections (max %d)\n",
> + TAS2783_MAX_FW_SECTIONS);
> + return -EINVAL;
> + }
> + offset += adv;
> + num_sections++;
> + }
> +
> + if (num_sections == 0)
> + return -EINVAL;
> +
> + sections = kcalloc(num_sections, sizeof(*sections), GFP_KERNEL);
> + if (!sections)
> + return -ENOMEM;
> +
> + offset = FW_DL_OFFSET;
> + for (i = 0; i < num_sections && offset < (img_sz - FW_FL_HDR); i++) {
> + size_t adv = (size_t)tas_fw_get_next_file(&buf[offset], &file);
> +
> + sections[i].addr = file.dest_addr;
> + sections[i].len = file.length;
> + sections[i].buf = file.fw_data;
> + offset += adv;
> +
> + dev_dbg(tas_dev->dev, "BPT section %d: addr=0x%x len=%d",
> + i, file.dest_addr, file.length);
> + }
> +
> + msg.sec = sections;
> + msg.sections = num_sections;
> + msg.dev_num = slave->dev_num;
> + msg.flags = SDW_MSG_FLAG_WRITE;
> +
> + dev_dbg(tas_dev->dev, "BPT starting: %d sections, dev_num=%d",
> + num_sections, slave->dev_num);
> +
> + ret = sdw_bpt_send_sync(bus, slave, &msg);
> +
> + if (ret < 0)
> + dev_err(tas_dev->dev, "BPT firmware download failed: %d", ret);
> + else
> + dev_dbg(tas_dev->dev,
> + "BPT firmware download complete: %d sections",
> + num_sections);
> +
> + kfree(sections);
> + return ret;
> +}
Before adding BPT-based optimizations to speed-up firmware download,
it'd be good to address existing problems with firmware download, e.g.
when a firmware contains volume configuration information that bypasses
regmap, see the thread in "ASoC: tas2783-sdw: keep the volume settings
across resets". Using BPT will only make things worse I am afraid,
unless there's a check that this is only used for resources not managed
by regmap?