@@ -3253,6 +3253,11 @@ static int wm_adsp_buffer_populate(struct wm_adsp_compr_buf *buf)
32533253 u32 offset = 0 ;
32543254 int i , ret ;
32553255
3256+ buf -> regions = kcalloc (caps -> num_regions , sizeof (* buf -> regions ),
3257+ GFP_KERNEL );
3258+ if (!buf -> regions )
3259+ return - ENOMEM ;
3260+
32563261 for (i = 0 ; i < caps -> num_regions ; ++ i ) {
32573262 region = & buf -> regions [i ];
32583263
@@ -3287,13 +3292,34 @@ static void wm_adsp_buffer_clear(struct wm_adsp_compr_buf *buf)
32873292 buf -> avail = 0 ;
32883293}
32893294
3290- static int wm_adsp_legacy_host_buf_addr (struct wm_adsp_compr_buf * buf )
3295+ static struct wm_adsp_compr_buf * wm_adsp_buffer_alloc (struct wm_adsp * dsp )
3296+ {
3297+ struct wm_adsp_compr_buf * buf ;
3298+
3299+ buf = kzalloc (sizeof (* buf ), GFP_KERNEL );
3300+ if (!buf )
3301+ return NULL ;
3302+
3303+ buf -> dsp = dsp ;
3304+
3305+ wm_adsp_buffer_clear (buf );
3306+
3307+ dsp -> buffer = buf ;
3308+
3309+ return buf ;
3310+ }
3311+
3312+ static int wm_adsp_buffer_parse_legacy (struct wm_adsp * dsp )
32913313{
32923314 struct wm_adsp_alg_region * alg_region ;
3293- struct wm_adsp * dsp = buf -> dsp ;
3315+ struct wm_adsp_compr_buf * buf ;
32943316 u32 xmalg , addr , magic ;
32953317 int i , ret ;
32963318
3319+ buf = wm_adsp_buffer_alloc (dsp );
3320+ if (!buf )
3321+ return - ENOMEM ;
3322+
32973323 alg_region = wm_adsp_find_alg_region (dsp , WMFW_ADSP2_XM , dsp -> fw_id );
32983324 xmalg = sizeof (struct wm_adsp_system_config_xm_hdr ) / sizeof (__be32 );
32993325
@@ -3303,7 +3329,7 @@ static int wm_adsp_legacy_host_buf_addr(struct wm_adsp_compr_buf *buf)
33033329 return ret ;
33043330
33053331 if (magic != WM_ADSP_ALG_XM_STRUCT_MAGIC )
3306- return - EINVAL ;
3332+ return - ENODEV ;
33073333
33083334 addr = alg_region -> base + xmalg + ALG_XM_FIELD (host_buf_ptr );
33093335 for (i = 0 ; i < 5 ; ++ i ) {
@@ -3323,49 +3349,27 @@ static int wm_adsp_legacy_host_buf_addr(struct wm_adsp_compr_buf *buf)
33233349
33243350 buf -> host_buf_mem_type = WMFW_ADSP2_XM ;
33253351
3326- adsp_dbg (dsp , "host_buf_ptr=%x\n" , buf -> host_buf_ptr );
3327-
3328- return 0 ;
3329- }
3330-
3331- static struct wm_coeff_ctl *
3332- wm_adsp_find_host_buffer_ctrl (struct wm_adsp_compr_buf * buf )
3333- {
3334- struct wm_adsp * dsp = buf -> dsp ;
3335- struct wm_coeff_ctl * ctl ;
3336-
3337- list_for_each_entry (ctl , & dsp -> ctl_list , list ) {
3338- if (ctl -> type != WMFW_CTL_TYPE_HOST_BUFFER )
3339- continue ;
3340-
3341- if (!ctl -> enabled )
3342- continue ;
3352+ ret = wm_adsp_buffer_populate (buf );
3353+ if (ret < 0 )
3354+ return ret ;
33433355
3344- buf -> host_buf_mem_type = ctl -> alg_region .type ;
3345- return ctl ;
3346- }
3356+ adsp_dbg (dsp , "legacy host_buf_ptr=%x\n" , buf -> host_buf_ptr );
33473357
3348- return NULL ;
3358+ return 0 ;
33493359}
33503360
3351- static int wm_adsp_buffer_locate (struct wm_adsp_compr_buf * buf )
3361+ static int wm_adsp_buffer_parse_coeff (struct wm_coeff_ctl * ctl )
33523362{
3353- struct wm_adsp * dsp = buf -> dsp ;
3354- struct wm_coeff_ctl * ctl ;
3355- unsigned int reg ;
3356- u32 val ;
3357- int i , ret ;
3358-
3359- ctl = wm_adsp_find_host_buffer_ctrl (buf );
3360- if (!ctl )
3361- return wm_adsp_legacy_host_buf_addr (buf );
3363+ struct wm_adsp_compr_buf * buf ;
3364+ unsigned int val , reg ;
3365+ int ret , i ;
33623366
33633367 ret = wm_coeff_base_reg (ctl , & reg );
33643368 if (ret )
33653369 return ret ;
33663370
33673371 for (i = 0 ; i < 5 ; ++ i ) {
3368- ret = regmap_raw_read (dsp -> regmap , reg , & val , sizeof (val ));
3372+ ret = regmap_raw_read (ctl -> dsp -> regmap , reg , & val , sizeof (val ));
33693373 if (ret < 0 )
33703374 return ret ;
33713375
@@ -3375,56 +3379,61 @@ static int wm_adsp_buffer_locate(struct wm_adsp_compr_buf *buf)
33753379 usleep_range (1000 , 2000 );
33763380 }
33773381
3378- if (!val )
3382+ if (!val ) {
3383+ adsp_err (ctl -> dsp , "Failed to acquire host buffer\n" );
33793384 return - EIO ;
3385+ }
3386+
3387+ buf = wm_adsp_buffer_alloc (ctl -> dsp );
3388+ if (!buf )
3389+ return - ENOMEM ;
33803390
3391+ buf -> host_buf_mem_type = ctl -> alg_region .type ;
33813392 buf -> host_buf_ptr = be32_to_cpu (val );
3382- adsp_dbg (dsp , "host_buf_ptr=%x\n" , buf -> host_buf_ptr );
3393+
3394+ ret = wm_adsp_buffer_populate (buf );
3395+ if (ret < 0 )
3396+ return ret ;
3397+
3398+ adsp_dbg (ctl -> dsp , "host_buf_ptr=%x\n" , buf -> host_buf_ptr );
33833399
33843400 return 0 ;
33853401}
33863402
3387-
33883403static int wm_adsp_buffer_init (struct wm_adsp * dsp )
33893404{
3390- struct wm_adsp_compr_buf * buf ;
3405+ struct wm_coeff_ctl * ctl ;
33913406 int ret ;
33923407
3393- buf = kzalloc (sizeof (* buf ), GFP_KERNEL );
3394- if (!buf )
3395- return - ENOMEM ;
3396-
3397- buf -> dsp = dsp ;
3408+ list_for_each_entry (ctl , & dsp -> ctl_list , list ) {
3409+ if (ctl -> type != WMFW_CTL_TYPE_HOST_BUFFER )
3410+ continue ;
33983411
3399- wm_adsp_buffer_clear (buf );
3412+ if (!ctl -> enabled )
3413+ continue ;
34003414
3401- ret = wm_adsp_buffer_locate ( buf );
3402- if (ret < 0 ) {
3403- adsp_err (dsp , "Failed to acquire host buffer : %d\n" , ret );
3404- goto err_buffer ;
3405- }
3415+ ret = wm_adsp_buffer_parse_coeff ( ctl );
3416+ if (ret < 0 ) {
3417+ adsp_err (dsp , "Failed to parse coeff : %d\n" , ret );
3418+ goto error ;
3419+ }
34063420
3407- buf -> regions = kcalloc (wm_adsp_fw [dsp -> fw ].caps -> num_regions ,
3408- sizeof (* buf -> regions ), GFP_KERNEL );
3409- if (!buf -> regions ) {
3410- ret = - ENOMEM ;
3411- goto err_buffer ;
3421+ return 0 ;
34123422 }
34133423
3414- ret = wm_adsp_buffer_populate (buf );
3415- if (ret < 0 ) {
3416- adsp_err (dsp , "Failed to populate host buffer: %d\n" , ret );
3417- goto err_regions ;
3424+ if (!dsp -> buffer ) {
3425+ /* Fall back to legacy support */
3426+ ret = wm_adsp_buffer_parse_legacy (dsp );
3427+ if (ret ) {
3428+ adsp_err (dsp , "Failed to parse legacy: %d\n" , ret );
3429+ goto error ;
3430+ }
34183431 }
34193432
3420- dsp -> buffer = buf ;
3421-
34223433 return 0 ;
34233434
3424- err_regions :
3425- kfree (buf -> regions );
3426- err_buffer :
3427- kfree (buf );
3435+ error :
3436+ wm_adsp_buffer_free (dsp );
34283437 return ret ;
34293438}
34303439
0 commit comments