|
5 | 5 | #include <linux/slab.h>
|
6 | 6 | #include <linux/soc/qcom/apr.h>
|
7 | 7 | #include <dt-bindings/soc/qcom,gpr.h>
|
| 8 | +#include "q6apm.h" |
8 | 9 | #include "audioreach.h"
|
9 | 10 |
|
10 | 11 | /* SubGraph Config */
|
@@ -253,3 +254,307 @@ void *audioreach_alloc_apm_cmd_pkt(int pkt_size, uint32_t opcode, uint32_t token
|
253 | 254 | APM_MODULE_INSTANCE_ID, true);
|
254 | 255 | }
|
255 | 256 | EXPORT_SYMBOL_GPL(audioreach_alloc_apm_cmd_pkt);
|
| 257 | + |
| 258 | +static void apm_populate_container_config(struct apm_container_obj *cfg, |
| 259 | + struct audioreach_container *cont) |
| 260 | +{ |
| 261 | + |
| 262 | + /* Container Config */ |
| 263 | + cfg->container_cfg.container_id = cont->container_id; |
| 264 | + cfg->container_cfg.num_prop = 4; |
| 265 | + |
| 266 | + /* Capability list */ |
| 267 | + cfg->cap_data.prop_id = APM_CONTAINER_PROP_ID_CAPABILITY_LIST; |
| 268 | + cfg->cap_data.prop_size = APM_CONTAINER_PROP_ID_CAPABILITY_SIZE; |
| 269 | + cfg->num_capability_id = 1; |
| 270 | + cfg->capability_id = cont->capability_id; |
| 271 | + |
| 272 | + /* Graph Position */ |
| 273 | + cfg->pos_data.prop_id = APM_CONTAINER_PROP_ID_GRAPH_POS; |
| 274 | + cfg->pos_data.prop_size = sizeof(struct apm_cont_prop_id_graph_pos); |
| 275 | + cfg->pos.graph_pos = cont->graph_pos; |
| 276 | + |
| 277 | + /* Stack size */ |
| 278 | + cfg->stack_data.prop_id = APM_CONTAINER_PROP_ID_STACK_SIZE; |
| 279 | + cfg->stack_data.prop_size = sizeof(struct apm_cont_prop_id_stack_size); |
| 280 | + cfg->stack.stack_size = cont->stack_size; |
| 281 | + |
| 282 | + /* Proc domain */ |
| 283 | + cfg->domain_data.prop_id = APM_CONTAINER_PROP_ID_PROC_DOMAIN; |
| 284 | + cfg->domain_data.prop_size = sizeof(struct apm_cont_prop_id_domain); |
| 285 | + cfg->domain.proc_domain = cont->proc_domain; |
| 286 | +} |
| 287 | + |
| 288 | +static void apm_populate_sub_graph_config(struct apm_sub_graph_data *cfg, |
| 289 | + struct audioreach_sub_graph *sg) |
| 290 | +{ |
| 291 | + cfg->sub_graph_cfg.sub_graph_id = sg->sub_graph_id; |
| 292 | + cfg->sub_graph_cfg.num_sub_graph_prop = APM_SUB_GRAPH_CFG_NPROP; |
| 293 | + |
| 294 | + /* Perf Mode */ |
| 295 | + cfg->perf_data.prop_id = APM_SUB_GRAPH_PROP_ID_PERF_MODE; |
| 296 | + cfg->perf_data.prop_size = APM_SG_PROP_ID_PERF_MODE_SIZE; |
| 297 | + cfg->perf.perf_mode = sg->perf_mode; |
| 298 | + |
| 299 | + /* Direction */ |
| 300 | + cfg->dir_data.prop_id = APM_SUB_GRAPH_PROP_ID_DIRECTION; |
| 301 | + cfg->dir_data.prop_size = APM_SG_PROP_ID_DIR_SIZE; |
| 302 | + cfg->dir.direction = sg->direction; |
| 303 | + |
| 304 | + /* Scenario ID */ |
| 305 | + cfg->sid_data.prop_id = APM_SUB_GRAPH_PROP_ID_SCENARIO_ID; |
| 306 | + cfg->sid_data.prop_size = APM_SG_PROP_ID_SID_SIZE; |
| 307 | + cfg->sid.scenario_id = sg->scenario_id; |
| 308 | +} |
| 309 | + |
| 310 | +static void apm_populate_connection_obj(struct apm_module_conn_obj *obj, |
| 311 | + struct audioreach_module *module) |
| 312 | +{ |
| 313 | + obj->src_mod_inst_id = module->src_mod_inst_id; |
| 314 | + obj->src_mod_op_port_id = module->src_mod_op_port_id; |
| 315 | + obj->dst_mod_inst_id = module->instance_id; |
| 316 | + obj->dst_mod_ip_port_id = module->in_port; |
| 317 | +} |
| 318 | + |
| 319 | +static void apm_populate_module_prop_obj(struct apm_mod_prop_obj *obj, |
| 320 | + struct audioreach_module *module) |
| 321 | +{ |
| 322 | + |
| 323 | + obj->instance_id = module->instance_id; |
| 324 | + obj->num_props = 1; |
| 325 | + obj->prop_data_1.prop_id = APM_MODULE_PROP_ID_PORT_INFO; |
| 326 | + obj->prop_data_1.prop_size = APM_MODULE_PROP_ID_PORT_INFO_SZ; |
| 327 | + obj->prop_id_port.max_ip_port = module->max_ip_port; |
| 328 | + obj->prop_id_port.max_op_port = module->max_op_port; |
| 329 | +} |
| 330 | + |
| 331 | +struct audioreach_module *audioreach_get_container_last_module( |
| 332 | + struct audioreach_container *container) |
| 333 | +{ |
| 334 | + struct audioreach_module *module; |
| 335 | + |
| 336 | + list_for_each_entry(module, &container->modules_list, node) { |
| 337 | + if (module->dst_mod_inst_id == 0) |
| 338 | + return module; |
| 339 | + } |
| 340 | + |
| 341 | + return NULL; |
| 342 | +} |
| 343 | +EXPORT_SYMBOL_GPL(audioreach_get_container_last_module); |
| 344 | + |
| 345 | +static bool is_module_in_container(struct audioreach_container *container, int module_iid) |
| 346 | +{ |
| 347 | + struct audioreach_module *module; |
| 348 | + |
| 349 | + list_for_each_entry(module, &container->modules_list, node) { |
| 350 | + if (module->instance_id == module_iid) |
| 351 | + return true; |
| 352 | + } |
| 353 | + |
| 354 | + return false; |
| 355 | +} |
| 356 | + |
| 357 | +struct audioreach_module *audioreach_get_container_first_module( |
| 358 | + struct audioreach_container *container) |
| 359 | +{ |
| 360 | + struct audioreach_module *module; |
| 361 | + |
| 362 | + /* get the first module from both connected or un-connected containers */ |
| 363 | + list_for_each_entry(module, &container->modules_list, node) { |
| 364 | + if (module->src_mod_inst_id == 0 || |
| 365 | + !is_module_in_container(container, module->src_mod_inst_id)) |
| 366 | + return module; |
| 367 | + } |
| 368 | + return NULL; |
| 369 | +} |
| 370 | +EXPORT_SYMBOL_GPL(audioreach_get_container_first_module); |
| 371 | + |
| 372 | +struct audioreach_module *audioreach_get_container_next_module( |
| 373 | + struct audioreach_container *container, |
| 374 | + struct audioreach_module *module) |
| 375 | +{ |
| 376 | + int nmodule_iid = module->dst_mod_inst_id; |
| 377 | + struct audioreach_module *nmodule; |
| 378 | + |
| 379 | + list_for_each_entry(nmodule, &container->modules_list, node) { |
| 380 | + if (nmodule->instance_id == nmodule_iid) |
| 381 | + return nmodule; |
| 382 | + } |
| 383 | + |
| 384 | + return NULL; |
| 385 | +} |
| 386 | +EXPORT_SYMBOL_GPL(audioreach_get_container_next_module); |
| 387 | + |
| 388 | +static void apm_populate_module_list_obj(struct apm_mod_list_obj *obj, |
| 389 | + struct audioreach_container *container, |
| 390 | + int sub_graph_id) |
| 391 | +{ |
| 392 | + struct audioreach_module *module; |
| 393 | + int i; |
| 394 | + |
| 395 | + obj->sub_graph_id = sub_graph_id; |
| 396 | + obj->container_id = container->container_id; |
| 397 | + obj->num_modules = container->num_modules; |
| 398 | + i = 0; |
| 399 | + list_for_each_container_module(module, container) { |
| 400 | + obj->mod_cfg[i].module_id = module->module_id; |
| 401 | + obj->mod_cfg[i].instance_id = module->instance_id; |
| 402 | + i++; |
| 403 | + } |
| 404 | +} |
| 405 | + |
| 406 | +static void audioreach_populate_graph(struct apm_graph_open_params *open, |
| 407 | + struct list_head *sg_list, |
| 408 | + int num_sub_graphs) |
| 409 | +{ |
| 410 | + struct apm_mod_conn_list_params *mc_data = open->mod_conn_list_data; |
| 411 | + struct apm_module_list_params *ml_data = open->mod_list_data; |
| 412 | + struct apm_prop_list_params *mp_data = open->mod_prop_data; |
| 413 | + struct apm_container_params *c_data = open->cont_data; |
| 414 | + struct apm_sub_graph_params *sg_data = open->sg_data; |
| 415 | + int ncontainer = 0, nmodule = 0, nconn = 0; |
| 416 | + struct apm_mod_prop_obj *module_prop_obj; |
| 417 | + struct audioreach_container *container; |
| 418 | + struct apm_module_conn_obj *conn_obj; |
| 419 | + struct audioreach_module *module; |
| 420 | + struct audioreach_sub_graph *sg; |
| 421 | + struct apm_container_obj *cobj; |
| 422 | + struct apm_mod_list_obj *mlobj; |
| 423 | + int i = 0; |
| 424 | + |
| 425 | + mlobj = &ml_data->mod_list_obj[0]; |
| 426 | + |
| 427 | + list_for_each_entry(sg, sg_list, node) { |
| 428 | + struct apm_sub_graph_data *sg_cfg = &sg_data->sg_cfg[i++]; |
| 429 | + |
| 430 | + apm_populate_sub_graph_config(sg_cfg, sg); |
| 431 | + |
| 432 | + list_for_each_entry(container, &sg->container_list, node) { |
| 433 | + cobj = &c_data->cont_obj[ncontainer]; |
| 434 | + |
| 435 | + apm_populate_container_config(cobj, container); |
| 436 | + apm_populate_module_list_obj(mlobj, container, sg->sub_graph_id); |
| 437 | + |
| 438 | + list_for_each_container_module(module, container) { |
| 439 | + uint32_t src_mod_inst_id; |
| 440 | + |
| 441 | + src_mod_inst_id = module->src_mod_inst_id; |
| 442 | + |
| 443 | + module_prop_obj = &mp_data->mod_prop_obj[nmodule]; |
| 444 | + apm_populate_module_prop_obj(module_prop_obj, module); |
| 445 | + |
| 446 | + if (src_mod_inst_id) { |
| 447 | + conn_obj = &mc_data->conn_obj[nconn]; |
| 448 | + apm_populate_connection_obj(conn_obj, module); |
| 449 | + nconn++; |
| 450 | + } |
| 451 | + |
| 452 | + nmodule++; |
| 453 | + } |
| 454 | + mlobj = (void *) mlobj + APM_MOD_LIST_OBJ_PSIZE(mlobj, container->num_modules); |
| 455 | + |
| 456 | + ncontainer++; |
| 457 | + } |
| 458 | + } |
| 459 | +} |
| 460 | + |
| 461 | +void *audioreach_alloc_graph_pkt(struct q6apm *apm, struct list_head *sg_list, int graph_id) |
| 462 | +{ |
| 463 | + int payload_size, sg_sz, cont_sz, ml_sz, mp_sz, mc_sz; |
| 464 | + struct apm_module_param_data *param_data; |
| 465 | + struct apm_container_params *cont_params; |
| 466 | + struct audioreach_container *container; |
| 467 | + struct apm_sub_graph_params *sg_params; |
| 468 | + struct apm_mod_conn_list_params *mcon; |
| 469 | + struct apm_graph_open_params params; |
| 470 | + struct apm_prop_list_params *mprop; |
| 471 | + struct audioreach_module *module; |
| 472 | + struct audioreach_sub_graph *sgs; |
| 473 | + struct apm_mod_list_obj *mlobj; |
| 474 | + int num_modules_per_list; |
| 475 | + int num_connections = 0; |
| 476 | + int num_containers = 0; |
| 477 | + int num_sub_graphs = 0; |
| 478 | + int num_modules = 0; |
| 479 | + int num_modules_list; |
| 480 | + struct gpr_pkt *pkt; |
| 481 | + void *p; |
| 482 | + |
| 483 | + list_for_each_entry(sgs, sg_list, node) { |
| 484 | + num_sub_graphs++; |
| 485 | + list_for_each_entry(container, &sgs->container_list, node) { |
| 486 | + num_containers++; |
| 487 | + num_modules += container->num_modules; |
| 488 | + list_for_each_container_module(module, container) { |
| 489 | + if (module->src_mod_inst_id) |
| 490 | + num_connections++; |
| 491 | + } |
| 492 | + } |
| 493 | + } |
| 494 | + |
| 495 | + num_modules_list = num_containers; |
| 496 | + num_modules_per_list = num_modules/num_containers; |
| 497 | + sg_sz = APM_SUB_GRAPH_PSIZE(sg_params, num_sub_graphs); |
| 498 | + cont_sz = APM_CONTAINER_PSIZE(cont_params, num_containers); |
| 499 | + ml_sz = ALIGN(sizeof(struct apm_module_list_params) + |
| 500 | + num_modules_list * APM_MOD_LIST_OBJ_PSIZE(mlobj, num_modules_per_list), 8); |
| 501 | + mp_sz = APM_MOD_PROP_PSIZE(mprop, num_modules); |
| 502 | + mc_sz = APM_MOD_CONN_PSIZE(mcon, num_connections); |
| 503 | + |
| 504 | + payload_size = sg_sz + cont_sz + ml_sz + mp_sz + mc_sz; |
| 505 | + pkt = audioreach_alloc_apm_cmd_pkt(payload_size, APM_CMD_GRAPH_OPEN, 0); |
| 506 | + if (IS_ERR(pkt)) |
| 507 | + return pkt; |
| 508 | + |
| 509 | + p = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE; |
| 510 | + |
| 511 | + /* SubGraph */ |
| 512 | + params.sg_data = p; |
| 513 | + param_data = ¶ms.sg_data->param_data; |
| 514 | + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; |
| 515 | + param_data->param_id = APM_PARAM_ID_SUB_GRAPH_CONFIG; |
| 516 | + param_data->param_size = sg_sz - APM_MODULE_PARAM_DATA_SIZE; |
| 517 | + params.sg_data->num_sub_graphs = num_sub_graphs; |
| 518 | + p += sg_sz; |
| 519 | + |
| 520 | + /* Container */ |
| 521 | + params.cont_data = p; |
| 522 | + param_data = ¶ms.cont_data->param_data; |
| 523 | + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; |
| 524 | + param_data->param_id = APM_PARAM_ID_CONTAINER_CONFIG; |
| 525 | + param_data->param_size = cont_sz - APM_MODULE_PARAM_DATA_SIZE; |
| 526 | + params.cont_data->num_containers = num_containers; |
| 527 | + p += cont_sz; |
| 528 | + |
| 529 | + /* Module List*/ |
| 530 | + params.mod_list_data = p; |
| 531 | + param_data = ¶ms.mod_list_data->param_data; |
| 532 | + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; |
| 533 | + param_data->param_id = APM_PARAM_ID_MODULE_LIST; |
| 534 | + param_data->param_size = ml_sz - APM_MODULE_PARAM_DATA_SIZE; |
| 535 | + params.mod_list_data->num_modules_list = num_sub_graphs; |
| 536 | + p += ml_sz; |
| 537 | + |
| 538 | + /* Module Properties */ |
| 539 | + params.mod_prop_data = p; |
| 540 | + param_data = ¶ms.mod_prop_data->param_data; |
| 541 | + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; |
| 542 | + param_data->param_id = APM_PARAM_ID_MODULE_PROP; |
| 543 | + param_data->param_size = mp_sz - APM_MODULE_PARAM_DATA_SIZE; |
| 544 | + params.mod_prop_data->num_modules_prop_cfg = num_modules; |
| 545 | + p += mp_sz; |
| 546 | + |
| 547 | + /* Module Connections */ |
| 548 | + params.mod_conn_list_data = p; |
| 549 | + param_data = ¶ms.mod_conn_list_data->param_data; |
| 550 | + param_data->module_instance_id = APM_MODULE_INSTANCE_ID; |
| 551 | + param_data->param_id = APM_PARAM_ID_MODULE_CONN; |
| 552 | + param_data->param_size = mc_sz - APM_MODULE_PARAM_DATA_SIZE; |
| 553 | + params.mod_conn_list_data->num_connections = num_connections; |
| 554 | + p += mc_sz; |
| 555 | + |
| 556 | + audioreach_populate_graph(¶ms, sg_list, num_sub_graphs); |
| 557 | + |
| 558 | + return pkt; |
| 559 | +} |
| 560 | +EXPORT_SYMBOL_GPL(audioreach_alloc_graph_pkt); |
0 commit comments