Skip to content

Commit c08a824

Browse files
Olivia Wenmathieupoirier
authored andcommitted
remoteproc: mediatek: Support setting DRAM and IPI shared buffer sizes
The SCP on different chips will require different DRAM sizes and IPI shared buffer sizes based on varying requirements. Signed-off-by: Olivia Wen <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 928a55a commit c08a824

File tree

3 files changed

+79
-23
lines changed

3 files changed

+79
-23
lines changed

drivers/remoteproc/mtk_common.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#define MT8195_L2TCM_OFFSET 0x850d0
7979

8080
#define SCP_FW_VER_LEN 32
81-
#define SCP_SHARE_BUFFER_SIZE 288
8281

8382
struct scp_run {
8483
u32 signaled;
@@ -97,6 +96,11 @@ struct scp_ipi_desc {
9796

9897
struct mtk_scp;
9998

99+
struct mtk_scp_sizes_data {
100+
size_t max_dram_size;
101+
size_t ipi_share_buffer_size;
102+
};
103+
100104
struct mtk_scp_of_data {
101105
int (*scp_clk_get)(struct mtk_scp *scp);
102106
int (*scp_before_load)(struct mtk_scp *scp);
@@ -110,6 +114,7 @@ struct mtk_scp_of_data {
110114
u32 host_to_scp_int_bit;
111115

112116
size_t ipi_buf_offset;
117+
const struct mtk_scp_sizes_data *scp_sizes;
113118
};
114119

115120
struct mtk_scp_of_cluster {
@@ -141,10 +146,10 @@ struct mtk_scp {
141146
struct scp_ipi_desc ipi_desc[SCP_IPI_MAX];
142147
bool ipi_id_ack[SCP_IPI_MAX];
143148
wait_queue_head_t ack_wq;
149+
u8 *share_buf;
144150

145151
void *cpu_addr;
146152
dma_addr_t dma_addr;
147-
size_t dram_size;
148153

149154
struct rproc_subdev *rpmsg_subdev;
150155

@@ -162,7 +167,7 @@ struct mtk_scp {
162167
struct mtk_share_obj {
163168
u32 id;
164169
u32 len;
165-
u8 share_buf[SCP_SHARE_BUFFER_SIZE];
170+
u8 *share_buf;
166171
};
167172

168173
void scp_memcpy_aligned(void __iomem *dst, const void *src, unsigned int len);

drivers/remoteproc/mtk_scp.c

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "mtk_common.h"
2121
#include "remoteproc_internal.h"
2222

23-
#define MAX_CODE_SIZE 0x500000
2423
#define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
2524

2625
/**
@@ -94,14 +93,15 @@ static void scp_ipi_handler(struct mtk_scp *scp)
9493
{
9594
struct mtk_share_obj __iomem *rcv_obj = scp->recv_buf;
9695
struct scp_ipi_desc *ipi_desc = scp->ipi_desc;
97-
u8 tmp_data[SCP_SHARE_BUFFER_SIZE];
9896
scp_ipi_handler_t handler;
9997
u32 id = readl(&rcv_obj->id);
10098
u32 len = readl(&rcv_obj->len);
99+
const struct mtk_scp_sizes_data *scp_sizes;
101100

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);
105105
return;
106106
}
107107
if (id >= SCP_IPI_MAX) {
@@ -117,8 +117,9 @@ static void scp_ipi_handler(struct mtk_scp *scp)
117117
return;
118118
}
119119

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);
122123
scp_ipi_unlock(scp, id);
123124

124125
scp->ipi_id_ack[id] = true;
@@ -133,6 +134,8 @@ static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw)
133134
{
134135
int ret;
135136
size_t buf_sz, offset;
137+
size_t share_buf_offset;
138+
const struct mtk_scp_sizes_data *scp_sizes;
136139

137140
/* read the ipi buf addr from FW itself first */
138141
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)
152155
return -EOVERFLOW;
153156
}
154157

158+
scp_sizes = scp->data->scp_sizes;
155159
scp->recv_buf = (struct mtk_share_obj __iomem *)
156160
(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;
157163
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);
161167

162168
return 0;
163169
}
@@ -741,14 +747,16 @@ static int scp_start(struct rproc *rproc)
741747
static void *mt8183_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
742748
{
743749
int offset;
750+
const struct mtk_scp_sizes_data *scp_sizes;
744751

752+
scp_sizes = scp->data->scp_sizes;
745753
if (da < scp->sram_size) {
746754
offset = da;
747755
if (offset >= 0 && (offset + len) <= scp->sram_size)
748756
return (void __force *)scp->sram_base + offset;
749-
} else if (scp->dram_size) {
757+
} else if (scp_sizes->max_dram_size) {
750758
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)
752760
return scp->cpu_addr + offset;
753761
}
754762

@@ -758,7 +766,9 @@ static void *mt8183_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
758766
static void *mt8192_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len)
759767
{
760768
int offset;
769+
const struct mtk_scp_sizes_data *scp_sizes;
761770

771+
scp_sizes = scp->data->scp_sizes;
762772
if (da >= scp->sram_phys &&
763773
(da + len) <= scp->sram_phys + scp->sram_size) {
764774
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)
774784
}
775785

776786
/* optional memory region */
777-
if (scp->dram_size &&
787+
if (scp_sizes->max_dram_size &&
778788
da >= scp->dma_addr &&
779-
(da + len) <= scp->dma_addr + scp->dram_size) {
789+
(da + len) <= scp->dma_addr + scp_sizes->max_dram_size) {
780790
offset = da - scp->dma_addr;
781791
return scp->cpu_addr + offset;
782792
}
@@ -997,6 +1007,7 @@ EXPORT_SYMBOL_GPL(scp_mapping_dm_addr);
9971007
static int scp_map_memory_region(struct mtk_scp *scp)
9981008
{
9991009
int ret;
1010+
const struct mtk_scp_sizes_data *scp_sizes;
10001011

10011012
ret = of_reserved_mem_device_init(scp->dev);
10021013

@@ -1012,8 +1023,8 @@ static int scp_map_memory_region(struct mtk_scp *scp)
10121023
}
10131024

10141025
/* 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,
10171028
&scp->dma_addr, GFP_KERNEL);
10181029
if (!scp->cpu_addr)
10191030
return -ENOMEM;
@@ -1023,10 +1034,13 @@ static int scp_map_memory_region(struct mtk_scp *scp)
10231034

10241035
static void scp_unmap_memory_region(struct mtk_scp *scp)
10251036
{
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)
10271041
return;
10281042

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,
10301044
scp->dma_addr);
10311045
of_reserved_mem_device_release(scp->dev);
10321046
}
@@ -1090,6 +1104,7 @@ static struct mtk_scp *scp_rproc_init(struct platform_device *pdev,
10901104
struct resource *res;
10911105
const char *fw_name = "scp.img";
10921106
int ret, i;
1107+
const struct mtk_scp_sizes_data *scp_sizes;
10931108

10941109
ret = rproc_of_parse_firmware(dev, 0, &fw_name);
10951110
if (ret < 0 && ret != -EINVAL)
@@ -1137,6 +1152,13 @@ static struct mtk_scp *scp_rproc_init(struct platform_device *pdev,
11371152
goto release_dev_mem;
11381153
}
11391154

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+
11401162
init_waitqueue_head(&scp->run.wq);
11411163
init_waitqueue_head(&scp->ack_wq);
11421164

@@ -1156,6 +1178,8 @@ static struct mtk_scp *scp_rproc_init(struct platform_device *pdev,
11561178
remove_subdev:
11571179
scp_remove_rpmsg_subdev(scp);
11581180
scp_ipi_unregister(scp, SCP_IPI_INIT);
1181+
kfree(scp->share_buf);
1182+
scp->share_buf = NULL;
11591183
release_dev_mem:
11601184
scp_unmap_memory_region(scp);
11611185
for (i = 0; i < SCP_IPI_MAX; i++)
@@ -1171,6 +1195,8 @@ static void scp_free(struct mtk_scp *scp)
11711195

11721196
scp_remove_rpmsg_subdev(scp);
11731197
scp_ipi_unregister(scp, SCP_IPI_INIT);
1198+
kfree(scp->share_buf);
1199+
scp->share_buf = NULL;
11741200
scp_unmap_memory_region(scp);
11751201
for (i = 0; i < SCP_IPI_MAX; i++)
11761202
mutex_destroy(&scp->ipi_desc[i].lock);
@@ -1357,6 +1383,21 @@ static void scp_remove(struct platform_device *pdev)
13571383
mutex_destroy(&scp_cluster->cluster_lock);
13581384
}
13591385

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+
13601401
static const struct mtk_scp_of_data mt8183_of_data = {
13611402
.scp_clk_get = mt8183_scp_clk_get,
13621403
.scp_before_load = mt8183_scp_before_load,
@@ -1368,6 +1409,7 @@ static const struct mtk_scp_of_data mt8183_of_data = {
13681409
.host_to_scp_reg = MT8183_HOST_TO_SCP,
13691410
.host_to_scp_int_bit = MT8183_HOST_IPC_INT_BIT,
13701411
.ipi_buf_offset = 0x7bdb0,
1412+
.scp_sizes = &default_scp_sizes,
13711413
};
13721414

13731415
static const struct mtk_scp_of_data mt8186_of_data = {
@@ -1381,6 +1423,7 @@ static const struct mtk_scp_of_data mt8186_of_data = {
13811423
.host_to_scp_reg = MT8183_HOST_TO_SCP,
13821424
.host_to_scp_int_bit = MT8183_HOST_IPC_INT_BIT,
13831425
.ipi_buf_offset = 0x3bdb0,
1426+
.scp_sizes = &default_scp_sizes,
13841427
};
13851428

13861429
static const struct mtk_scp_of_data mt8188_of_data = {
@@ -1393,6 +1436,7 @@ static const struct mtk_scp_of_data mt8188_of_data = {
13931436
.scp_da_to_va = mt8192_scp_da_to_va,
13941437
.host_to_scp_reg = MT8192_GIPC_IN_SET,
13951438
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT,
1439+
.scp_sizes = &mt8188_scp_sizes,
13961440
};
13971441

13981442
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 = {
14051449
.scp_da_to_va = mt8192_scp_da_to_va,
14061450
.host_to_scp_reg = MT8192_GIPC_IN_SET,
14071451
.host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
1452+
.scp_sizes = &mt8188_scp_c1_sizes,
14081453
};
14091454

14101455
static const struct mtk_scp_of_data mt8192_of_data = {
@@ -1417,6 +1462,7 @@ static const struct mtk_scp_of_data mt8192_of_data = {
14171462
.scp_da_to_va = mt8192_scp_da_to_va,
14181463
.host_to_scp_reg = MT8192_GIPC_IN_SET,
14191464
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT,
1465+
.scp_sizes = &default_scp_sizes,
14201466
};
14211467

14221468
static const struct mtk_scp_of_data mt8195_of_data = {
@@ -1429,6 +1475,7 @@ static const struct mtk_scp_of_data mt8195_of_data = {
14291475
.scp_da_to_va = mt8192_scp_da_to_va,
14301476
.host_to_scp_reg = MT8192_GIPC_IN_SET,
14311477
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT,
1478+
.scp_sizes = &default_scp_sizes,
14321479
};
14331480

14341481
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 = {
14411488
.scp_da_to_va = mt8192_scp_da_to_va,
14421489
.host_to_scp_reg = MT8192_GIPC_IN_SET,
14431490
.host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
1491+
.scp_sizes = &default_scp_sizes,
14441492
};
14451493

14461494
static const struct mtk_scp_of_data *mt8188_of_data_cores[] = {

drivers/remoteproc/mtk_scp_ipi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,13 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,
162162
struct mtk_share_obj __iomem *send_obj = scp->send_buf;
163163
u32 val;
164164
int ret;
165+
const struct mtk_scp_sizes_data *scp_sizes;
166+
167+
scp_sizes = scp->data->scp_sizes;
165168

166169
if (WARN_ON(id <= SCP_IPI_INIT) || WARN_ON(id >= SCP_IPI_MAX) ||
167170
WARN_ON(id == SCP_IPI_NS_SERVICE) ||
168-
WARN_ON(len > sizeof(send_obj->share_buf)) || WARN_ON(!buf))
171+
WARN_ON(len > scp_sizes->ipi_share_buffer_size) || WARN_ON(!buf))
169172
return -EINVAL;
170173

171174
ret = clk_prepare_enable(scp->clk);
@@ -184,7 +187,7 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,
184187
goto unlock_mutex;
185188
}
186189

187-
scp_memcpy_aligned(send_obj->share_buf, buf, len);
190+
scp_memcpy_aligned(&send_obj->share_buf, buf, len);
188191

189192
writel(len, &send_obj->len);
190193
writel(id, &send_obj->id);

0 commit comments

Comments
 (0)