Skip to content

Commit 13a6c8e

Browse files
committed
Merge tag 'amlogic-drivers' of https://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-amlogic into arm/drivers
soc: amlogic: updates for v5.5 Highlights - socinfo: more SoC IDs - firmware: misc secure-monitor cleanups * tag 'amlogic-drivers' of https://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-amlogic: soc: amlogic: meson-gx-socinfo: Fix S905D3 ID for VIM3L soc: amlogic: meson-gx-socinfo: Add S905X3 ID for VIM3L soc: amlogic: meson-gx-socinfo: Add A1 and A113L IDs firmware: meson_sm: use %*ph to print small buffer firmware: meson_sm: Rework driver as a proper platform driver nvmem: meson-efuse: bindings: Add secure-monitor phandle firmware: meson_sm: Mark chip struct as static const Link: https://lore.kernel.org/r/7hftivs11f.fsf@baylibre.com Signed-off-by: Olof Johansson <olof@lixom.net>
2 parents e24eb5e + fdfc699 commit 13a6c8e

5 files changed

Lines changed: 105 additions & 53 deletions

File tree

‎Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Required properties:
44
- compatible: should be "amlogic,meson-gxbb-efuse"
55
- clocks: phandle to the efuse peripheral clock provided by the
66
clock controller.
7+
- secure-monitor: phandle to the secure-monitor node
78

89
= Data cells =
910
Are child nodes of eFuse, bindings of which as described in
@@ -16,6 +17,7 @@ Example:
1617
clocks = <&clkc CLKID_EFUSE>;
1718
#address-cells = <1>;
1819
#size-cells = <1>;
20+
secure-monitor = <&sm>;
1921

2022
sn: sn@14 {
2123
reg = <0x14 0x10>;
@@ -30,6 +32,10 @@ Example:
3032
};
3133
};
3234

35+
sm: secure-monitor {
36+
compatible = "amlogic,meson-gxbb-sm";
37+
};
38+
3339
= Data consumers =
3440
Are device nodes which consume nvmem data cells.
3541

‎drivers/firmware/meson/meson_sm.c‎

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct meson_sm_chip {
3535
struct meson_sm_cmd cmd[];
3636
};
3737

38-
struct meson_sm_chip gxbb_chip = {
38+
static const struct meson_sm_chip gxbb_chip = {
3939
.shmem_size = SZ_4K,
4040
.cmd_shmem_in_base = 0x82000020,
4141
.cmd_shmem_out_base = 0x82000021,
@@ -54,8 +54,6 @@ struct meson_sm_firmware {
5454
void __iomem *sm_shmem_out_base;
5555
};
5656

57-
static struct meson_sm_firmware fw;
58-
5957
static u32 meson_sm_get_cmd(const struct meson_sm_chip *chip,
6058
unsigned int cmd_index)
6159
{
@@ -90,6 +88,7 @@ static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size)
9088
/**
9189
* meson_sm_call - generic SMC32 call to the secure-monitor
9290
*
91+
* @fw: Pointer to secure-monitor firmware
9392
* @cmd_index: Index of the SMC32 function ID
9493
* @ret: Returned value
9594
* @arg0: SMC32 Argument 0
@@ -100,15 +99,15 @@ static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size)
10099
*
101100
* Return: 0 on success, a negative value on error
102101
*/
103-
int meson_sm_call(unsigned int cmd_index, u32 *ret, u32 arg0,
104-
u32 arg1, u32 arg2, u32 arg3, u32 arg4)
102+
int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
103+
u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
105104
{
106105
u32 cmd, lret;
107106

108-
if (!fw.chip)
107+
if (!fw->chip)
109108
return -ENOENT;
110109

111-
cmd = meson_sm_get_cmd(fw.chip, cmd_index);
110+
cmd = meson_sm_get_cmd(fw->chip, cmd_index);
112111
if (!cmd)
113112
return -EINVAL;
114113

@@ -124,6 +123,7 @@ EXPORT_SYMBOL(meson_sm_call);
124123
/**
125124
* meson_sm_call_read - retrieve data from secure-monitor
126125
*
126+
* @fw: Pointer to secure-monitor firmware
127127
* @buffer: Buffer to store the retrieved data
128128
* @bsize: Size of the buffer
129129
* @cmd_index: Index of the SMC32 function ID
@@ -137,22 +137,23 @@ EXPORT_SYMBOL(meson_sm_call);
137137
* When 0 is returned there is no guarantee about the amount of
138138
* data read and bsize bytes are copied in buffer.
139139
*/
140-
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
141-
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
140+
int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
141+
unsigned int bsize, unsigned int cmd_index, u32 arg0,
142+
u32 arg1, u32 arg2, u32 arg3, u32 arg4)
142143
{
143144
u32 size;
144145
int ret;
145146

146-
if (!fw.chip)
147+
if (!fw->chip)
147148
return -ENOENT;
148149

149-
if (!fw.chip->cmd_shmem_out_base)
150+
if (!fw->chip->cmd_shmem_out_base)
150151
return -EINVAL;
151152

152-
if (bsize > fw.chip->shmem_size)
153+
if (bsize > fw->chip->shmem_size)
153154
return -EINVAL;
154155

155-
if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
156+
if (meson_sm_call(fw, cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
156157
return -EINVAL;
157158

158159
if (size > bsize)
@@ -164,7 +165,7 @@ int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
164165
size = bsize;
165166

166167
if (buffer)
167-
memcpy(buffer, fw.sm_shmem_out_base, size);
168+
memcpy(buffer, fw->sm_shmem_out_base, size);
168169

169170
return ret;
170171
}
@@ -173,6 +174,7 @@ EXPORT_SYMBOL(meson_sm_call_read);
173174
/**
174175
* meson_sm_call_write - send data to secure-monitor
175176
*
177+
* @fw: Pointer to secure-monitor firmware
176178
* @buffer: Buffer containing data to send
177179
* @size: Size of the data to send
178180
* @cmd_index: Index of the SMC32 function ID
@@ -184,23 +186,24 @@ EXPORT_SYMBOL(meson_sm_call_read);
184186
*
185187
* Return: size of sent data on success, a negative value on error
186188
*/
187-
int meson_sm_call_write(void *buffer, unsigned int size, unsigned int cmd_index,
188-
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
189+
int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
190+
unsigned int size, unsigned int cmd_index, u32 arg0,
191+
u32 arg1, u32 arg2, u32 arg3, u32 arg4)
189192
{
190193
u32 written;
191194

192-
if (!fw.chip)
195+
if (!fw->chip)
193196
return -ENOENT;
194197

195-
if (size > fw.chip->shmem_size)
198+
if (size > fw->chip->shmem_size)
196199
return -EINVAL;
197200

198-
if (!fw.chip->cmd_shmem_in_base)
201+
if (!fw->chip->cmd_shmem_in_base)
199202
return -EINVAL;
200203

201-
memcpy(fw.sm_shmem_in_base, buffer, size);
204+
memcpy(fw->sm_shmem_in_base, buffer, size);
202205

203-
if (meson_sm_call(cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)
206+
if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)
204207
return -EINVAL;
205208

206209
if (!written)
@@ -210,40 +213,50 @@ int meson_sm_call_write(void *buffer, unsigned int size, unsigned int cmd_index,
210213
}
211214
EXPORT_SYMBOL(meson_sm_call_write);
212215

216+
/**
217+
* meson_sm_get - get pointer to meson_sm_firmware structure.
218+
*
219+
* @sm_node: Pointer to the secure-monitor Device Tree node.
220+
*
221+
* Return: NULL is the secure-monitor device is not ready.
222+
*/
223+
struct meson_sm_firmware *meson_sm_get(struct device_node *sm_node)
224+
{
225+
struct platform_device *pdev = of_find_device_by_node(sm_node);
226+
227+
if (!pdev)
228+
return NULL;
229+
230+
return platform_get_drvdata(pdev);
231+
}
232+
EXPORT_SYMBOL_GPL(meson_sm_get);
233+
213234
#define SM_CHIP_ID_LENGTH 119
214235
#define SM_CHIP_ID_OFFSET 4
215236
#define SM_CHIP_ID_SIZE 12
216237

217238
static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
218239
char *buf)
219240
{
241+
struct platform_device *pdev = to_platform_device(dev);
242+
struct meson_sm_firmware *fw;
220243
uint8_t *id_buf;
221244
int ret;
222245

246+
fw = platform_get_drvdata(pdev);
247+
223248
id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL);
224249
if (!id_buf)
225250
return -ENOMEM;
226251

227-
ret = meson_sm_call_read(id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID,
252+
ret = meson_sm_call_read(fw, id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID,
228253
0, 0, 0, 0, 0);
229254
if (ret < 0) {
230255
kfree(id_buf);
231256
return ret;
232257
}
233258

234-
ret = sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
235-
id_buf[SM_CHIP_ID_OFFSET + 0],
236-
id_buf[SM_CHIP_ID_OFFSET + 1],
237-
id_buf[SM_CHIP_ID_OFFSET + 2],
238-
id_buf[SM_CHIP_ID_OFFSET + 3],
239-
id_buf[SM_CHIP_ID_OFFSET + 4],
240-
id_buf[SM_CHIP_ID_OFFSET + 5],
241-
id_buf[SM_CHIP_ID_OFFSET + 6],
242-
id_buf[SM_CHIP_ID_OFFSET + 7],
243-
id_buf[SM_CHIP_ID_OFFSET + 8],
244-
id_buf[SM_CHIP_ID_OFFSET + 9],
245-
id_buf[SM_CHIP_ID_OFFSET + 10],
246-
id_buf[SM_CHIP_ID_OFFSET + 11]);
259+
ret = sprintf(buf, "%12phN\n", &id_buf[SM_CHIP_ID_OFFSET]);
247260

248261
kfree(id_buf);
249262

@@ -268,25 +281,34 @@ static const struct of_device_id meson_sm_ids[] = {
268281

269282
static int __init meson_sm_probe(struct platform_device *pdev)
270283
{
284+
struct device *dev = &pdev->dev;
271285
const struct meson_sm_chip *chip;
286+
struct meson_sm_firmware *fw;
287+
288+
fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
289+
if (!fw)
290+
return -ENOMEM;
272291

273-
chip = of_match_device(meson_sm_ids, &pdev->dev)->data;
292+
chip = of_match_device(meson_sm_ids, dev)->data;
274293

275294
if (chip->cmd_shmem_in_base) {
276-
fw.sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,
277-
chip->shmem_size);
278-
if (WARN_ON(!fw.sm_shmem_in_base))
295+
fw->sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,
296+
chip->shmem_size);
297+
if (WARN_ON(!fw->sm_shmem_in_base))
279298
goto out;
280299
}
281300

282301
if (chip->cmd_shmem_out_base) {
283-
fw.sm_shmem_out_base = meson_sm_map_shmem(chip->cmd_shmem_out_base,
284-
chip->shmem_size);
285-
if (WARN_ON(!fw.sm_shmem_out_base))
302+
fw->sm_shmem_out_base = meson_sm_map_shmem(chip->cmd_shmem_out_base,
303+
chip->shmem_size);
304+
if (WARN_ON(!fw->sm_shmem_out_base))
286305
goto out_in_base;
287306
}
288307

289-
fw.chip = chip;
308+
fw->chip = chip;
309+
310+
platform_set_drvdata(pdev, fw);
311+
290312
pr_info("secure-monitor enabled\n");
291313

292314
if (sysfs_create_group(&pdev->dev.kobj, &meson_sm_sysfs_attr_group))
@@ -295,7 +317,7 @@ static int __init meson_sm_probe(struct platform_device *pdev)
295317
return 0;
296318

297319
out_in_base:
298-
iounmap(fw.sm_shmem_in_base);
320+
iounmap(fw->sm_shmem_in_base);
299321
out:
300322
return -EINVAL;
301323
}

‎drivers/nvmem/meson-efuse.c‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
static int meson_efuse_read(void *context, unsigned int offset,
1818
void *val, size_t bytes)
1919
{
20-
return meson_sm_call_read((u8 *)val, bytes, SM_EFUSE_READ, offset,
20+
struct meson_sm_firmware *fw = context;
21+
22+
return meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
2123
bytes, 0, 0, 0);
2224
}
2325

2426
static int meson_efuse_write(void *context, unsigned int offset,
2527
void *val, size_t bytes)
2628
{
27-
return meson_sm_call_write((u8 *)val, bytes, SM_EFUSE_WRITE, offset,
29+
struct meson_sm_firmware *fw = context;
30+
31+
return meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
2832
bytes, 0, 0, 0);
2933
}
3034

@@ -37,12 +41,25 @@ MODULE_DEVICE_TABLE(of, meson_efuse_match);
3741
static int meson_efuse_probe(struct platform_device *pdev)
3842
{
3943
struct device *dev = &pdev->dev;
44+
struct meson_sm_firmware *fw;
45+
struct device_node *sm_np;
4046
struct nvmem_device *nvmem;
4147
struct nvmem_config *econfig;
4248
struct clk *clk;
4349
unsigned int size;
4450
int ret;
4551

52+
sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
53+
if (!sm_np) {
54+
dev_err(&pdev->dev, "no secure-monitor node\n");
55+
return -ENODEV;
56+
}
57+
58+
fw = meson_sm_get(sm_np);
59+
of_node_put(sm_np);
60+
if (!fw)
61+
return -EPROBE_DEFER;
62+
4663
clk = devm_clk_get(dev, NULL);
4764
if (IS_ERR(clk)) {
4865
ret = PTR_ERR(clk);
@@ -65,7 +82,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
6582
return ret;
6683
}
6784

68-
if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) {
85+
if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) {
6986
dev_err(dev, "failed to get max user");
7087
return -EINVAL;
7188
}
@@ -81,6 +98,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
8198
econfig->reg_read = meson_efuse_read;
8299
econfig->reg_write = meson_efuse_write;
83100
econfig->size = size;
101+
econfig->priv = fw;
84102

85103
nvmem = devm_nvmem_register(&pdev->dev, econfig);
86104

‎drivers/soc/amlogic/meson-gx-socinfo.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static const struct meson_gx_soc_id {
4040
{ "G12A", 0x28 },
4141
{ "G12B", 0x29 },
4242
{ "SM1", 0x2b },
43+
{ "A1", 0x2c },
4344
};
4445

4546
static const struct meson_gx_package_id {
@@ -68,6 +69,8 @@ static const struct meson_gx_package_id {
6869
{ "S922X", 0x29, 0x40, 0xf0 },
6970
{ "A311D", 0x29, 0x10, 0xf0 },
7071
{ "S905X3", 0x2b, 0x5, 0xf },
72+
{ "S905D3", 0x2b, 0xb0, 0xf0 },
73+
{ "A113L", 0x2c, 0x0, 0xf8 },
7174
};
7275

7376
static inline unsigned int socinfo_to_major(u32 socinfo)

‎include/linux/firmware/meson/meson_sm.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ enum {
1616

1717
struct meson_sm_firmware;
1818

19-
int meson_sm_call(unsigned int cmd_index, u32 *ret, u32 arg0, u32 arg1,
20-
u32 arg2, u32 arg3, u32 arg4);
21-
int meson_sm_call_write(void *buffer, unsigned int b_size, unsigned int cmd_index,
22-
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
23-
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
24-
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
19+
int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
20+
u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
21+
int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
22+
unsigned int b_size, unsigned int cmd_index, u32 arg0,
23+
u32 arg1, u32 arg2, u32 arg3, u32 arg4);
24+
int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
25+
unsigned int bsize, unsigned int cmd_index, u32 arg0,
26+
u32 arg1, u32 arg2, u32 arg3, u32 arg4);
27+
struct meson_sm_firmware *meson_sm_get(struct device_node *firmware_node);
2528

2629
#endif /* _MESON_SM_FW_H_ */

0 commit comments

Comments
 (0)