| .. | .. | 
|---|
|  | 1 | +// SPDX-License-Identifier: GPL-2.0-only | 
|---|
| 1 | 2 | /* | 
|---|
| 2 | 3 | * skl-sst.c - HDA DSP library functions for SKL platform | 
|---|
| 3 | 4 | * | 
|---|
| .. | .. | 
|---|
| 5 | 6 | * Author:Rafal Redzimski <rafal.f.redzimski@intel.com> | 
|---|
| 6 | 7 | *	Jeeja KP <jeeja.kp@intel.com> | 
|---|
| 7 | 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 8 |  | - * | 
|---|
| 9 |  | - * This program is free software; you can redistribute it and/or modify | 
|---|
| 10 |  | - * it under the terms of the GNU General Public License as version 2, as | 
|---|
| 11 |  | - * published by the Free Software Foundation. | 
|---|
| 12 |  | - * | 
|---|
| 13 |  | - * This program is distributed in the hope that it will be useful, but | 
|---|
| 14 |  | - * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 |  | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 16 |  | - * General Public License for more details. | 
|---|
| 17 | 9 | */ | 
|---|
| 18 | 10 |  | 
|---|
| 19 | 11 | #include <linux/module.h> | 
|---|
| .. | .. | 
|---|
| 24 | 16 | #include "../common/sst-dsp.h" | 
|---|
| 25 | 17 | #include "../common/sst-dsp-priv.h" | 
|---|
| 26 | 18 | #include "../common/sst-ipc.h" | 
|---|
| 27 |  | -#include "skl-sst-ipc.h" | 
|---|
|  | 19 | +#include "skl.h" | 
|---|
| 28 | 20 |  | 
|---|
| 29 | 21 | #define SKL_BASEFW_TIMEOUT	300 | 
|---|
| 30 | 22 | #define SKL_INIT_TIMEOUT	1000 | 
|---|
| .. | .. | 
|---|
| 74 | 66 | static int skl_load_base_firmware(struct sst_dsp *ctx) | 
|---|
| 75 | 67 | { | 
|---|
| 76 | 68 | int ret = 0, i; | 
|---|
| 77 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 69 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 78 | 70 | struct firmware stripped_fw; | 
|---|
| 79 | 71 | u32 reg; | 
|---|
| 80 | 72 |  | 
|---|
| .. | .. | 
|---|
| 169 | 161 | { | 
|---|
| 170 | 162 | int ret; | 
|---|
| 171 | 163 | struct skl_ipc_dxstate_info dx; | 
|---|
| 172 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 164 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 173 | 165 | unsigned int core_mask = SKL_DSP_CORE_MASK(core_id); | 
|---|
| 174 | 166 |  | 
|---|
| 175 | 167 | /* If core0 is being turned on, we need to load the FW */ | 
|---|
| .. | .. | 
|---|
| 223 | 215 | { | 
|---|
| 224 | 216 | int ret; | 
|---|
| 225 | 217 | struct skl_ipc_dxstate_info dx; | 
|---|
| 226 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 218 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 227 | 219 | unsigned int core_mask = SKL_DSP_CORE_MASK(core_id); | 
|---|
| 228 | 220 |  | 
|---|
| 229 | 221 | dx.core_mask = core_mask; | 
|---|
| .. | .. | 
|---|
| 340 | 332 | u32 size, u16 mod_id, u8 table_id, bool is_module) | 
|---|
| 341 | 333 | { | 
|---|
| 342 | 334 | int ret, bytes_left, curr_pos; | 
|---|
| 343 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 335 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 344 | 336 | skl->mod_load_complete = false; | 
|---|
| 345 | 337 |  | 
|---|
| 346 | 338 | bytes_left = ctx->cl_dev.ops.cl_copy_to_dmabuf(ctx, data, size, false); | 
|---|
| .. | .. | 
|---|
| 362 | 354 | /* | 
|---|
| 363 | 355 | * if bytes_left > 0 then wait for BDL complete interrupt and | 
|---|
| 364 | 356 | * copy the next chunk till bytes_left is 0. if bytes_left is | 
|---|
| 365 |  | -	 * is zero, then wait for load module IPC reply | 
|---|
|  | 357 | +	 * zero, then wait for load module IPC reply | 
|---|
| 366 | 358 | */ | 
|---|
| 367 | 359 | while (bytes_left > 0) { | 
|---|
| 368 | 360 | curr_pos = size - bytes_left; | 
|---|
| .. | .. | 
|---|
| 392 | 384 | static int | 
|---|
| 393 | 385 | skl_load_library(struct sst_dsp *ctx, struct skl_lib_info *linfo, int lib_count) | 
|---|
| 394 | 386 | { | 
|---|
| 395 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 387 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 396 | 388 | struct firmware stripped_fw; | 
|---|
| 397 | 389 | int ret, i; | 
|---|
| 398 | 390 |  | 
|---|
| .. | .. | 
|---|
| 420 | 412 | struct skl_module_table *module_entry = NULL; | 
|---|
| 421 | 413 | int ret = 0; | 
|---|
| 422 | 414 | char mod_name[64]; /* guid str = 32 chars + 4 hyphens */ | 
|---|
| 423 |  | -	uuid_le *uuid_mod; | 
|---|
| 424 | 415 |  | 
|---|
| 425 |  | -	uuid_mod = (uuid_le *)guid; | 
|---|
| 426 |  | -	snprintf(mod_name, sizeof(mod_name), "%s%pUL%s", | 
|---|
| 427 |  | -				"intel/dsp_fw_", uuid_mod, ".bin"); | 
|---|
|  | 416 | +	snprintf(mod_name, sizeof(mod_name), "intel/dsp_fw_%pUL.bin", guid); | 
|---|
| 428 | 417 |  | 
|---|
| 429 | 418 | module_entry = skl_module_get_from_id(ctx, mod_id); | 
|---|
| 430 | 419 | if (module_entry == NULL) { | 
|---|
| .. | .. | 
|---|
| 453 | 442 | static int skl_unload_module(struct sst_dsp *ctx, u16 mod_id) | 
|---|
| 454 | 443 | { | 
|---|
| 455 | 444 | int usage_cnt; | 
|---|
| 456 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 445 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 457 | 446 | int ret = 0; | 
|---|
| 458 | 447 |  | 
|---|
| 459 | 448 | usage_cnt = skl_put_module(ctx, mod_id); | 
|---|
| .. | .. | 
|---|
| 517 | 506 | .irq_handler = skl_dsp_sst_interrupt, | 
|---|
| 518 | 507 | .write = sst_shim32_write, | 
|---|
| 519 | 508 | .read = sst_shim32_read, | 
|---|
| 520 |  | -	.ram_read = sst_memcpy_fromio_32, | 
|---|
| 521 |  | -	.ram_write = sst_memcpy_toio_32, | 
|---|
| 522 | 509 | .free = skl_dsp_free, | 
|---|
| 523 | 510 | }; | 
|---|
| 524 | 511 |  | 
|---|
| .. | .. | 
|---|
| 528 | 515 | }; | 
|---|
| 529 | 516 |  | 
|---|
| 530 | 517 | int skl_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq, | 
|---|
| 531 |  | -		const char *fw_name, struct skl_dsp_loader_ops dsp_ops, struct skl_sst **dsp) | 
|---|
|  | 518 | +		const char *fw_name, struct skl_dsp_loader_ops dsp_ops, | 
|---|
|  | 519 | +		struct skl_dev **dsp) | 
|---|
| 532 | 520 | { | 
|---|
| 533 |  | -	struct skl_sst *skl; | 
|---|
|  | 521 | +	struct skl_dev *skl; | 
|---|
| 534 | 522 | struct sst_dsp *sst; | 
|---|
| 535 | 523 | int ret; | 
|---|
| 536 | 524 |  | 
|---|
| .. | .. | 
|---|
| 564 | 552 | } | 
|---|
| 565 | 553 | EXPORT_SYMBOL_GPL(skl_sst_dsp_init); | 
|---|
| 566 | 554 |  | 
|---|
| 567 |  | -int skl_sst_init_fw(struct device *dev, struct skl_sst *ctx) | 
|---|
|  | 555 | +int skl_sst_init_fw(struct device *dev, struct skl_dev *skl) | 
|---|
| 568 | 556 | { | 
|---|
| 569 | 557 | int ret; | 
|---|
| 570 |  | -	struct sst_dsp *sst = ctx->dsp; | 
|---|
|  | 558 | +	struct sst_dsp *sst = skl->dsp; | 
|---|
| 571 | 559 |  | 
|---|
| 572 | 560 | ret = sst->fw_ops.load_fw(sst); | 
|---|
| 573 | 561 | if (ret < 0) { | 
|---|
| .. | .. | 
|---|
| 577 | 565 |  | 
|---|
| 578 | 566 | skl_dsp_init_core_state(sst); | 
|---|
| 579 | 567 |  | 
|---|
| 580 |  | -	if (ctx->lib_count > 1) { | 
|---|
| 581 |  | -		ret = sst->fw_ops.load_library(sst, ctx->lib_info, | 
|---|
| 582 |  | -						ctx->lib_count); | 
|---|
|  | 568 | +	if (skl->lib_count > 1) { | 
|---|
|  | 569 | +		ret = sst->fw_ops.load_library(sst, skl->lib_info, | 
|---|
|  | 570 | +						skl->lib_count); | 
|---|
| 583 | 571 | if (ret < 0) { | 
|---|
| 584 | 572 | dev_err(dev, "Load Library failed : %x\n", ret); | 
|---|
| 585 | 573 | return ret; | 
|---|
| 586 | 574 | } | 
|---|
| 587 | 575 | } | 
|---|
| 588 |  | -	ctx->is_first_boot = false; | 
|---|
|  | 576 | +	skl->is_first_boot = false; | 
|---|
| 589 | 577 |  | 
|---|
| 590 | 578 | return 0; | 
|---|
| 591 | 579 | } | 
|---|
| 592 | 580 | EXPORT_SYMBOL_GPL(skl_sst_init_fw); | 
|---|
| 593 | 581 |  | 
|---|
| 594 |  | -void skl_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx) | 
|---|
|  | 582 | +void skl_sst_dsp_cleanup(struct device *dev, struct skl_dev *skl) | 
|---|
| 595 | 583 | { | 
|---|
| 596 | 584 |  | 
|---|
| 597 |  | -	if (ctx->dsp->fw) | 
|---|
| 598 |  | -		release_firmware(ctx->dsp->fw); | 
|---|
| 599 |  | -	skl_clear_module_table(ctx->dsp); | 
|---|
| 600 |  | -	skl_freeup_uuid_list(ctx); | 
|---|
| 601 |  | -	skl_ipc_free(&ctx->ipc); | 
|---|
| 602 |  | -	ctx->dsp->ops->free(ctx->dsp); | 
|---|
| 603 |  | -	if (ctx->boot_complete) { | 
|---|
| 604 |  | -		ctx->dsp->cl_dev.ops.cl_cleanup_controller(ctx->dsp); | 
|---|
| 605 |  | -		skl_cldma_int_disable(ctx->dsp); | 
|---|
|  | 585 | +	if (skl->dsp->fw) | 
|---|
|  | 586 | +		release_firmware(skl->dsp->fw); | 
|---|
|  | 587 | +	skl_clear_module_table(skl->dsp); | 
|---|
|  | 588 | +	skl_freeup_uuid_list(skl); | 
|---|
|  | 589 | +	skl_ipc_free(&skl->ipc); | 
|---|
|  | 590 | +	skl->dsp->ops->free(skl->dsp); | 
|---|
|  | 591 | +	if (skl->boot_complete) { | 
|---|
|  | 592 | +		skl->dsp->cl_dev.ops.cl_cleanup_controller(skl->dsp); | 
|---|
|  | 593 | +		skl_cldma_int_disable(skl->dsp); | 
|---|
| 606 | 594 | } | 
|---|
| 607 | 595 | } | 
|---|
| 608 | 596 | EXPORT_SYMBOL_GPL(skl_sst_dsp_cleanup); | 
|---|