20
20
#include "mtk_common.h"
21
21
#include "remoteproc_internal.h"
22
22
23
- #define MAX_CODE_SIZE 0x500000
24
23
#define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
25
24
26
25
/**
@@ -94,14 +93,15 @@ static void scp_ipi_handler(struct mtk_scp *scp)
94
93
{
95
94
struct mtk_share_obj __iomem * rcv_obj = scp -> recv_buf ;
96
95
struct scp_ipi_desc * ipi_desc = scp -> ipi_desc ;
97
- u8 tmp_data [SCP_SHARE_BUFFER_SIZE ];
98
96
scp_ipi_handler_t handler ;
99
97
u32 id = readl (& rcv_obj -> id );
100
98
u32 len = readl (& rcv_obj -> len );
99
+ const struct mtk_scp_sizes_data * scp_sizes ;
101
100
102
- if (len > SCP_SHARE_BUFFER_SIZE ) {
103
- dev_err (scp -> dev , "ipi message too long (len %d, max %d)" , len ,
104
- SCP_SHARE_BUFFER_SIZE );
101
+ scp_sizes = scp -> data -> scp_sizes ;
102
+ if (len > scp_sizes -> ipi_share_buffer_size ) {
103
+ dev_err (scp -> dev , "ipi message too long (len %d, max %zd)" , len ,
104
+ scp_sizes -> ipi_share_buffer_size );
105
105
return ;
106
106
}
107
107
if (id >= SCP_IPI_MAX ) {
@@ -117,8 +117,9 @@ static void scp_ipi_handler(struct mtk_scp *scp)
117
117
return ;
118
118
}
119
119
120
- memcpy_fromio (tmp_data , & rcv_obj -> share_buf , len );
121
- handler (tmp_data , len , ipi_desc [id ].priv );
120
+ memset (scp -> share_buf , 0 , scp_sizes -> ipi_share_buffer_size );
121
+ memcpy_fromio (scp -> share_buf , & rcv_obj -> share_buf , len );
122
+ handler (scp -> share_buf , len , ipi_desc [id ].priv );
122
123
scp_ipi_unlock (scp , id );
123
124
124
125
scp -> ipi_id_ack [id ] = true;
@@ -133,6 +134,8 @@ static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw)
133
134
{
134
135
int ret ;
135
136
size_t buf_sz , offset ;
137
+ size_t share_buf_offset ;
138
+ const struct mtk_scp_sizes_data * scp_sizes ;
136
139
137
140
/* read the ipi buf addr from FW itself first */
138
141
ret = scp_elf_read_ipi_buf_addr (scp , fw , & offset );
@@ -152,12 +155,15 @@ static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw)
152
155
return - EOVERFLOW ;
153
156
}
154
157
158
+ scp_sizes = scp -> data -> scp_sizes ;
155
159
scp -> recv_buf = (struct mtk_share_obj __iomem * )
156
160
(scp -> sram_base + offset );
161
+ share_buf_offset = sizeof (scp -> recv_buf -> id )
162
+ + sizeof (scp -> recv_buf -> len ) + scp_sizes -> ipi_share_buffer_size ;
157
163
scp -> send_buf = (struct mtk_share_obj __iomem * )
158
- (scp -> sram_base + offset + sizeof ( * scp -> recv_buf ) );
159
- memset_io (scp -> recv_buf , 0 , sizeof ( * scp -> recv_buf ) );
160
- memset_io (scp -> send_buf , 0 , sizeof ( * scp -> send_buf ) );
164
+ (scp -> sram_base + offset + share_buf_offset );
165
+ memset_io (scp -> recv_buf , 0 , share_buf_offset );
166
+ memset_io (scp -> send_buf , 0 , share_buf_offset );
161
167
162
168
return 0 ;
163
169
}
@@ -741,14 +747,16 @@ static int scp_start(struct rproc *rproc)
741
747
static void * mt8183_scp_da_to_va (struct mtk_scp * scp , u64 da , size_t len )
742
748
{
743
749
int offset ;
750
+ const struct mtk_scp_sizes_data * scp_sizes ;
744
751
752
+ scp_sizes = scp -> data -> scp_sizes ;
745
753
if (da < scp -> sram_size ) {
746
754
offset = da ;
747
755
if (offset >= 0 && (offset + len ) <= scp -> sram_size )
748
756
return (void __force * )scp -> sram_base + offset ;
749
- } else if (scp -> dram_size ) {
757
+ } else if (scp_sizes -> max_dram_size ) {
750
758
offset = da - scp -> dma_addr ;
751
- if (offset >= 0 && (offset + len ) <= scp -> dram_size )
759
+ if (offset >= 0 && (offset + len ) <= scp_sizes -> max_dram_size )
752
760
return scp -> cpu_addr + offset ;
753
761
}
754
762
@@ -758,7 +766,9 @@ static void *mt8183_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
758
766
static void * mt8192_scp_da_to_va (struct mtk_scp * scp , u64 da , size_t len )
759
767
{
760
768
int offset ;
769
+ const struct mtk_scp_sizes_data * scp_sizes ;
761
770
771
+ scp_sizes = scp -> data -> scp_sizes ;
762
772
if (da >= scp -> sram_phys &&
763
773
(da + len ) <= scp -> sram_phys + scp -> sram_size ) {
764
774
offset = da - scp -> sram_phys ;
@@ -774,9 +784,9 @@ static void *mt8192_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
774
784
}
775
785
776
786
/* optional memory region */
777
- if (scp -> dram_size &&
787
+ if (scp_sizes -> max_dram_size &&
778
788
da >= scp -> dma_addr &&
779
- (da + len ) <= scp -> dma_addr + scp -> dram_size ) {
789
+ (da + len ) <= scp -> dma_addr + scp_sizes -> max_dram_size ) {
780
790
offset = da - scp -> dma_addr ;
781
791
return scp -> cpu_addr + offset ;
782
792
}
@@ -997,6 +1007,7 @@ EXPORT_SYMBOL_GPL(scp_mapping_dm_addr);
997
1007
static int scp_map_memory_region (struct mtk_scp * scp )
998
1008
{
999
1009
int ret ;
1010
+ const struct mtk_scp_sizes_data * scp_sizes ;
1000
1011
1001
1012
ret = of_reserved_mem_device_init (scp -> dev );
1002
1013
@@ -1012,8 +1023,8 @@ static int scp_map_memory_region(struct mtk_scp *scp)
1012
1023
}
1013
1024
1014
1025
/* Reserved SCP code size */
1015
- scp -> dram_size = MAX_CODE_SIZE ;
1016
- scp -> cpu_addr = dma_alloc_coherent (scp -> dev , scp -> dram_size ,
1026
+ scp_sizes = scp -> data -> scp_sizes ;
1027
+ scp -> cpu_addr = dma_alloc_coherent (scp -> dev , scp_sizes -> max_dram_size ,
1017
1028
& scp -> dma_addr , GFP_KERNEL );
1018
1029
if (!scp -> cpu_addr )
1019
1030
return - ENOMEM ;
@@ -1023,10 +1034,13 @@ static int scp_map_memory_region(struct mtk_scp *scp)
1023
1034
1024
1035
static void scp_unmap_memory_region (struct mtk_scp * scp )
1025
1036
{
1026
- if (scp -> dram_size == 0 )
1037
+ const struct mtk_scp_sizes_data * scp_sizes ;
1038
+
1039
+ scp_sizes = scp -> data -> scp_sizes ;
1040
+ if (scp_sizes -> max_dram_size == 0 )
1027
1041
return ;
1028
1042
1029
- dma_free_coherent (scp -> dev , scp -> dram_size , scp -> cpu_addr ,
1043
+ dma_free_coherent (scp -> dev , scp_sizes -> max_dram_size , scp -> cpu_addr ,
1030
1044
scp -> dma_addr );
1031
1045
of_reserved_mem_device_release (scp -> dev );
1032
1046
}
@@ -1090,6 +1104,7 @@ static struct mtk_scp *scp_rproc_init(struct platform_device *pdev,
1090
1104
struct resource * res ;
1091
1105
const char * fw_name = "scp.img" ;
1092
1106
int ret , i ;
1107
+ const struct mtk_scp_sizes_data * scp_sizes ;
1093
1108
1094
1109
ret = rproc_of_parse_firmware (dev , 0 , & fw_name );
1095
1110
if (ret < 0 && ret != - EINVAL )
@@ -1137,6 +1152,13 @@ static struct mtk_scp *scp_rproc_init(struct platform_device *pdev,
1137
1152
goto release_dev_mem ;
1138
1153
}
1139
1154
1155
+ scp_sizes = scp -> data -> scp_sizes ;
1156
+ scp -> share_buf = kzalloc (scp_sizes -> ipi_share_buffer_size , GFP_KERNEL );
1157
+ if (!scp -> share_buf ) {
1158
+ dev_err (dev , "Failed to allocate IPI share buffer\n" );
1159
+ goto release_dev_mem ;
1160
+ }
1161
+
1140
1162
init_waitqueue_head (& scp -> run .wq );
1141
1163
init_waitqueue_head (& scp -> ack_wq );
1142
1164
@@ -1156,6 +1178,8 @@ static struct mtk_scp *scp_rproc_init(struct platform_device *pdev,
1156
1178
remove_subdev :
1157
1179
scp_remove_rpmsg_subdev (scp );
1158
1180
scp_ipi_unregister (scp , SCP_IPI_INIT );
1181
+ kfree (scp -> share_buf );
1182
+ scp -> share_buf = NULL ;
1159
1183
release_dev_mem :
1160
1184
scp_unmap_memory_region (scp );
1161
1185
for (i = 0 ; i < SCP_IPI_MAX ; i ++ )
@@ -1171,6 +1195,8 @@ static void scp_free(struct mtk_scp *scp)
1171
1195
1172
1196
scp_remove_rpmsg_subdev (scp );
1173
1197
scp_ipi_unregister (scp , SCP_IPI_INIT );
1198
+ kfree (scp -> share_buf );
1199
+ scp -> share_buf = NULL ;
1174
1200
scp_unmap_memory_region (scp );
1175
1201
for (i = 0 ; i < SCP_IPI_MAX ; i ++ )
1176
1202
mutex_destroy (& scp -> ipi_desc [i ].lock );
@@ -1357,6 +1383,21 @@ static void scp_remove(struct platform_device *pdev)
1357
1383
mutex_destroy (& scp_cluster -> cluster_lock );
1358
1384
}
1359
1385
1386
+ static const struct mtk_scp_sizes_data default_scp_sizes = {
1387
+ .max_dram_size = 0x500000 ,
1388
+ .ipi_share_buffer_size = 288 ,
1389
+ };
1390
+
1391
+ static const struct mtk_scp_sizes_data mt8188_scp_sizes = {
1392
+ .max_dram_size = 0x500000 ,
1393
+ .ipi_share_buffer_size = 600 ,
1394
+ };
1395
+
1396
+ static const struct mtk_scp_sizes_data mt8188_scp_c1_sizes = {
1397
+ .max_dram_size = 0xA00000 ,
1398
+ .ipi_share_buffer_size = 600 ,
1399
+ };
1400
+
1360
1401
static const struct mtk_scp_of_data mt8183_of_data = {
1361
1402
.scp_clk_get = mt8183_scp_clk_get ,
1362
1403
.scp_before_load = mt8183_scp_before_load ,
@@ -1368,6 +1409,7 @@ static const struct mtk_scp_of_data mt8183_of_data = {
1368
1409
.host_to_scp_reg = MT8183_HOST_TO_SCP ,
1369
1410
.host_to_scp_int_bit = MT8183_HOST_IPC_INT_BIT ,
1370
1411
.ipi_buf_offset = 0x7bdb0 ,
1412
+ .scp_sizes = & default_scp_sizes ,
1371
1413
};
1372
1414
1373
1415
static const struct mtk_scp_of_data mt8186_of_data = {
@@ -1381,6 +1423,7 @@ static const struct mtk_scp_of_data mt8186_of_data = {
1381
1423
.host_to_scp_reg = MT8183_HOST_TO_SCP ,
1382
1424
.host_to_scp_int_bit = MT8183_HOST_IPC_INT_BIT ,
1383
1425
.ipi_buf_offset = 0x3bdb0 ,
1426
+ .scp_sizes = & default_scp_sizes ,
1384
1427
};
1385
1428
1386
1429
static const struct mtk_scp_of_data mt8188_of_data = {
@@ -1393,6 +1436,7 @@ static const struct mtk_scp_of_data mt8188_of_data = {
1393
1436
.scp_da_to_va = mt8192_scp_da_to_va ,
1394
1437
.host_to_scp_reg = MT8192_GIPC_IN_SET ,
1395
1438
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT ,
1439
+ .scp_sizes = & mt8188_scp_sizes ,
1396
1440
};
1397
1441
1398
1442
static const struct mtk_scp_of_data mt8188_of_data_c1 = {
@@ -1405,6 +1449,7 @@ static const struct mtk_scp_of_data mt8188_of_data_c1 = {
1405
1449
.scp_da_to_va = mt8192_scp_da_to_va ,
1406
1450
.host_to_scp_reg = MT8192_GIPC_IN_SET ,
1407
1451
.host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT ,
1452
+ .scp_sizes = & mt8188_scp_c1_sizes ,
1408
1453
};
1409
1454
1410
1455
static const struct mtk_scp_of_data mt8192_of_data = {
@@ -1417,6 +1462,7 @@ static const struct mtk_scp_of_data mt8192_of_data = {
1417
1462
.scp_da_to_va = mt8192_scp_da_to_va ,
1418
1463
.host_to_scp_reg = MT8192_GIPC_IN_SET ,
1419
1464
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT ,
1465
+ .scp_sizes = & default_scp_sizes ,
1420
1466
};
1421
1467
1422
1468
static const struct mtk_scp_of_data mt8195_of_data = {
@@ -1429,6 +1475,7 @@ static const struct mtk_scp_of_data mt8195_of_data = {
1429
1475
.scp_da_to_va = mt8192_scp_da_to_va ,
1430
1476
.host_to_scp_reg = MT8192_GIPC_IN_SET ,
1431
1477
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT ,
1478
+ .scp_sizes = & default_scp_sizes ,
1432
1479
};
1433
1480
1434
1481
static const struct mtk_scp_of_data mt8195_of_data_c1 = {
@@ -1441,6 +1488,7 @@ static const struct mtk_scp_of_data mt8195_of_data_c1 = {
1441
1488
.scp_da_to_va = mt8192_scp_da_to_va ,
1442
1489
.host_to_scp_reg = MT8192_GIPC_IN_SET ,
1443
1490
.host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT ,
1491
+ .scp_sizes = & default_scp_sizes ,
1444
1492
};
1445
1493
1446
1494
static const struct mtk_scp_of_data * mt8188_of_data_cores [] = {
0 commit comments