Commit 13a6c8ef authored by Olof Johansson's avatar Olof Johansson

Merge tag 'amlogic-drivers' of...

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.comSigned-off-by: default avatarOlof Johansson <olof@lixom.net>
parents e24eb5e6 fdfc6997
...@@ -4,6 +4,7 @@ Required properties: ...@@ -4,6 +4,7 @@ Required properties:
- compatible: should be "amlogic,meson-gxbb-efuse" - compatible: should be "amlogic,meson-gxbb-efuse"
- clocks: phandle to the efuse peripheral clock provided by the - clocks: phandle to the efuse peripheral clock provided by the
clock controller. clock controller.
- secure-monitor: phandle to the secure-monitor node
= Data cells = = Data cells =
Are child nodes of eFuse, bindings of which as described in Are child nodes of eFuse, bindings of which as described in
...@@ -16,6 +17,7 @@ Example: ...@@ -16,6 +17,7 @@ Example:
clocks = <&clkc CLKID_EFUSE>; clocks = <&clkc CLKID_EFUSE>;
#address-cells = <1>; #address-cells = <1>;
#size-cells = <1>; #size-cells = <1>;
secure-monitor = <&sm>;
sn: sn@14 { sn: sn@14 {
reg = <0x14 0x10>; reg = <0x14 0x10>;
...@@ -30,6 +32,10 @@ Example: ...@@ -30,6 +32,10 @@ Example:
}; };
}; };
sm: secure-monitor {
compatible = "amlogic,meson-gxbb-sm";
};
= Data consumers = = Data consumers =
Are device nodes which consume nvmem data cells. Are device nodes which consume nvmem data cells.
......
...@@ -35,7 +35,7 @@ struct meson_sm_chip { ...@@ -35,7 +35,7 @@ struct meson_sm_chip {
struct meson_sm_cmd cmd[]; struct meson_sm_cmd cmd[];
}; };
struct meson_sm_chip gxbb_chip = { static const struct meson_sm_chip gxbb_chip = {
.shmem_size = SZ_4K, .shmem_size = SZ_4K,
.cmd_shmem_in_base = 0x82000020, .cmd_shmem_in_base = 0x82000020,
.cmd_shmem_out_base = 0x82000021, .cmd_shmem_out_base = 0x82000021,
...@@ -54,8 +54,6 @@ struct meson_sm_firmware { ...@@ -54,8 +54,6 @@ struct meson_sm_firmware {
void __iomem *sm_shmem_out_base; void __iomem *sm_shmem_out_base;
}; };
static struct meson_sm_firmware fw;
static u32 meson_sm_get_cmd(const struct meson_sm_chip *chip, static u32 meson_sm_get_cmd(const struct meson_sm_chip *chip,
unsigned int cmd_index) unsigned int cmd_index)
{ {
...@@ -90,6 +88,7 @@ static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size) ...@@ -90,6 +88,7 @@ static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size)
/** /**
* meson_sm_call - generic SMC32 call to the secure-monitor * meson_sm_call - generic SMC32 call to the secure-monitor
* *
* @fw: Pointer to secure-monitor firmware
* @cmd_index: Index of the SMC32 function ID * @cmd_index: Index of the SMC32 function ID
* @ret: Returned value * @ret: Returned value
* @arg0: SMC32 Argument 0 * @arg0: SMC32 Argument 0
...@@ -100,15 +99,15 @@ static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size) ...@@ -100,15 +99,15 @@ static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size)
* *
* Return: 0 on success, a negative value on error * Return: 0 on success, a negative value on error
*/ */
int meson_sm_call(unsigned int cmd_index, u32 *ret, u32 arg0, int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
u32 arg1, u32 arg2, u32 arg3, u32 arg4) u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
{ {
u32 cmd, lret; u32 cmd, lret;
if (!fw.chip) if (!fw->chip)
return -ENOENT; return -ENOENT;
cmd = meson_sm_get_cmd(fw.chip, cmd_index); cmd = meson_sm_get_cmd(fw->chip, cmd_index);
if (!cmd) if (!cmd)
return -EINVAL; return -EINVAL;
...@@ -124,6 +123,7 @@ EXPORT_SYMBOL(meson_sm_call); ...@@ -124,6 +123,7 @@ EXPORT_SYMBOL(meson_sm_call);
/** /**
* meson_sm_call_read - retrieve data from secure-monitor * meson_sm_call_read - retrieve data from secure-monitor
* *
* @fw: Pointer to secure-monitor firmware
* @buffer: Buffer to store the retrieved data * @buffer: Buffer to store the retrieved data
* @bsize: Size of the buffer * @bsize: Size of the buffer
* @cmd_index: Index of the SMC32 function ID * @cmd_index: Index of the SMC32 function ID
...@@ -137,22 +137,23 @@ EXPORT_SYMBOL(meson_sm_call); ...@@ -137,22 +137,23 @@ EXPORT_SYMBOL(meson_sm_call);
* When 0 is returned there is no guarantee about the amount of * When 0 is returned there is no guarantee about the amount of
* data read and bsize bytes are copied in buffer. * data read and bsize bytes are copied in buffer.
*/ */
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index, int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) unsigned int bsize, unsigned int cmd_index, u32 arg0,
u32 arg1, u32 arg2, u32 arg3, u32 arg4)
{ {
u32 size; u32 size;
int ret; int ret;
if (!fw.chip) if (!fw->chip)
return -ENOENT; return -ENOENT;
if (!fw.chip->cmd_shmem_out_base) if (!fw->chip->cmd_shmem_out_base)
return -EINVAL; return -EINVAL;
if (bsize > fw.chip->shmem_size) if (bsize > fw->chip->shmem_size)
return -EINVAL; return -EINVAL;
if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0) if (meson_sm_call(fw, cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
return -EINVAL; return -EINVAL;
if (size > bsize) if (size > bsize)
...@@ -164,7 +165,7 @@ int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index, ...@@ -164,7 +165,7 @@ int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
size = bsize; size = bsize;
if (buffer) if (buffer)
memcpy(buffer, fw.sm_shmem_out_base, size); memcpy(buffer, fw->sm_shmem_out_base, size);
return ret; return ret;
} }
...@@ -173,6 +174,7 @@ EXPORT_SYMBOL(meson_sm_call_read); ...@@ -173,6 +174,7 @@ EXPORT_SYMBOL(meson_sm_call_read);
/** /**
* meson_sm_call_write - send data to secure-monitor * meson_sm_call_write - send data to secure-monitor
* *
* @fw: Pointer to secure-monitor firmware
* @buffer: Buffer containing data to send * @buffer: Buffer containing data to send
* @size: Size of the data to send * @size: Size of the data to send
* @cmd_index: Index of the SMC32 function ID * @cmd_index: Index of the SMC32 function ID
...@@ -184,23 +186,24 @@ EXPORT_SYMBOL(meson_sm_call_read); ...@@ -184,23 +186,24 @@ EXPORT_SYMBOL(meson_sm_call_read);
* *
* Return: size of sent data on success, a negative value on error * Return: size of sent data on success, a negative value on error
*/ */
int meson_sm_call_write(void *buffer, unsigned int size, unsigned int cmd_index, int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) unsigned int size, unsigned int cmd_index, u32 arg0,
u32 arg1, u32 arg2, u32 arg3, u32 arg4)
{ {
u32 written; u32 written;
if (!fw.chip) if (!fw->chip)
return -ENOENT; return -ENOENT;
if (size > fw.chip->shmem_size) if (size > fw->chip->shmem_size)
return -EINVAL; return -EINVAL;
if (!fw.chip->cmd_shmem_in_base) if (!fw->chip->cmd_shmem_in_base)
return -EINVAL; return -EINVAL;
memcpy(fw.sm_shmem_in_base, buffer, size); memcpy(fw->sm_shmem_in_base, buffer, size);
if (meson_sm_call(cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0) if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, arg2, arg3, arg4) < 0)
return -EINVAL; return -EINVAL;
if (!written) if (!written)
...@@ -210,6 +213,24 @@ int meson_sm_call_write(void *buffer, unsigned int size, unsigned int cmd_index, ...@@ -210,6 +213,24 @@ int meson_sm_call_write(void *buffer, unsigned int size, unsigned int cmd_index,
} }
EXPORT_SYMBOL(meson_sm_call_write); EXPORT_SYMBOL(meson_sm_call_write);
/**
* meson_sm_get - get pointer to meson_sm_firmware structure.
*
* @sm_node: Pointer to the secure-monitor Device Tree node.
*
* Return: NULL is the secure-monitor device is not ready.
*/
struct meson_sm_firmware *meson_sm_get(struct device_node *sm_node)
{
struct platform_device *pdev = of_find_device_by_node(sm_node);
if (!pdev)
return NULL;
return platform_get_drvdata(pdev);
}
EXPORT_SYMBOL_GPL(meson_sm_get);
#define SM_CHIP_ID_LENGTH 119 #define SM_CHIP_ID_LENGTH 119
#define SM_CHIP_ID_OFFSET 4 #define SM_CHIP_ID_OFFSET 4
#define SM_CHIP_ID_SIZE 12 #define SM_CHIP_ID_SIZE 12
...@@ -217,33 +238,25 @@ EXPORT_SYMBOL(meson_sm_call_write); ...@@ -217,33 +238,25 @@ EXPORT_SYMBOL(meson_sm_call_write);
static ssize_t serial_show(struct device *dev, struct device_attribute *attr, static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct platform_device *pdev = to_platform_device(dev);
struct meson_sm_firmware *fw;
uint8_t *id_buf; uint8_t *id_buf;
int ret; int ret;
fw = platform_get_drvdata(pdev);
id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL);
if (!id_buf) if (!id_buf)
return -ENOMEM; return -ENOMEM;
ret = meson_sm_call_read(id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID, ret = meson_sm_call_read(fw, id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID,
0, 0, 0, 0, 0); 0, 0, 0, 0, 0);
if (ret < 0) { if (ret < 0) {
kfree(id_buf); kfree(id_buf);
return ret; return ret;
} }
ret = sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", ret = sprintf(buf, "%12phN\n", &id_buf[SM_CHIP_ID_OFFSET]);
id_buf[SM_CHIP_ID_OFFSET + 0],
id_buf[SM_CHIP_ID_OFFSET + 1],
id_buf[SM_CHIP_ID_OFFSET + 2],
id_buf[SM_CHIP_ID_OFFSET + 3],
id_buf[SM_CHIP_ID_OFFSET + 4],
id_buf[SM_CHIP_ID_OFFSET + 5],
id_buf[SM_CHIP_ID_OFFSET + 6],
id_buf[SM_CHIP_ID_OFFSET + 7],
id_buf[SM_CHIP_ID_OFFSET + 8],
id_buf[SM_CHIP_ID_OFFSET + 9],
id_buf[SM_CHIP_ID_OFFSET + 10],
id_buf[SM_CHIP_ID_OFFSET + 11]);
kfree(id_buf); kfree(id_buf);
...@@ -268,25 +281,34 @@ static const struct of_device_id meson_sm_ids[] = { ...@@ -268,25 +281,34 @@ static const struct of_device_id meson_sm_ids[] = {
static int __init meson_sm_probe(struct platform_device *pdev) static int __init meson_sm_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
const struct meson_sm_chip *chip; const struct meson_sm_chip *chip;
struct meson_sm_firmware *fw;
fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
if (!fw)
return -ENOMEM;
chip = of_match_device(meson_sm_ids, &pdev->dev)->data; chip = of_match_device(meson_sm_ids, dev)->data;
if (chip->cmd_shmem_in_base) { if (chip->cmd_shmem_in_base) {
fw.sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base, fw->sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,
chip->shmem_size); chip->shmem_size);
if (WARN_ON(!fw.sm_shmem_in_base)) if (WARN_ON(!fw->sm_shmem_in_base))
goto out; goto out;
} }
if (chip->cmd_shmem_out_base) { if (chip->cmd_shmem_out_base) {
fw.sm_shmem_out_base = meson_sm_map_shmem(chip->cmd_shmem_out_base, fw->sm_shmem_out_base = meson_sm_map_shmem(chip->cmd_shmem_out_base,
chip->shmem_size); chip->shmem_size);
if (WARN_ON(!fw.sm_shmem_out_base)) if (WARN_ON(!fw->sm_shmem_out_base))
goto out_in_base; goto out_in_base;
} }
fw.chip = chip; fw->chip = chip;
platform_set_drvdata(pdev, fw);
pr_info("secure-monitor enabled\n"); pr_info("secure-monitor enabled\n");
if (sysfs_create_group(&pdev->dev.kobj, &meson_sm_sysfs_attr_group)) 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) ...@@ -295,7 +317,7 @@ static int __init meson_sm_probe(struct platform_device *pdev)
return 0; return 0;
out_in_base: out_in_base:
iounmap(fw.sm_shmem_in_base); iounmap(fw->sm_shmem_in_base);
out: out:
return -EINVAL; return -EINVAL;
} }
......
...@@ -17,14 +17,18 @@ ...@@ -17,14 +17,18 @@
static int meson_efuse_read(void *context, unsigned int offset, static int meson_efuse_read(void *context, unsigned int offset,
void *val, size_t bytes) void *val, size_t bytes)
{ {
return meson_sm_call_read((u8 *)val, bytes, SM_EFUSE_READ, offset, struct meson_sm_firmware *fw = context;
return meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
bytes, 0, 0, 0); bytes, 0, 0, 0);
} }
static int meson_efuse_write(void *context, unsigned int offset, static int meson_efuse_write(void *context, unsigned int offset,
void *val, size_t bytes) void *val, size_t bytes)
{ {
return meson_sm_call_write((u8 *)val, bytes, SM_EFUSE_WRITE, offset, struct meson_sm_firmware *fw = context;
return meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
bytes, 0, 0, 0); bytes, 0, 0, 0);
} }
...@@ -37,12 +41,25 @@ MODULE_DEVICE_TABLE(of, meson_efuse_match); ...@@ -37,12 +41,25 @@ MODULE_DEVICE_TABLE(of, meson_efuse_match);
static int meson_efuse_probe(struct platform_device *pdev) static int meson_efuse_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct meson_sm_firmware *fw;
struct device_node *sm_np;
struct nvmem_device *nvmem; struct nvmem_device *nvmem;
struct nvmem_config *econfig; struct nvmem_config *econfig;
struct clk *clk; struct clk *clk;
unsigned int size; unsigned int size;
int ret; int ret;
sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
if (!sm_np) {
dev_err(&pdev->dev, "no secure-monitor node\n");
return -ENODEV;
}
fw = meson_sm_get(sm_np);
of_node_put(sm_np);
if (!fw)
return -EPROBE_DEFER;
clk = devm_clk_get(dev, NULL); clk = devm_clk_get(dev, NULL);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
ret = PTR_ERR(clk); ret = PTR_ERR(clk);
...@@ -65,7 +82,7 @@ static int meson_efuse_probe(struct platform_device *pdev) ...@@ -65,7 +82,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
return ret; return ret;
} }
if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) { if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) {
dev_err(dev, "failed to get max user"); dev_err(dev, "failed to get max user");
return -EINVAL; return -EINVAL;
} }
...@@ -81,6 +98,7 @@ static int meson_efuse_probe(struct platform_device *pdev) ...@@ -81,6 +98,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
econfig->reg_read = meson_efuse_read; econfig->reg_read = meson_efuse_read;
econfig->reg_write = meson_efuse_write; econfig->reg_write = meson_efuse_write;
econfig->size = size; econfig->size = size;
econfig->priv = fw;
nvmem = devm_nvmem_register(&pdev->dev, econfig); nvmem = devm_nvmem_register(&pdev->dev, econfig);
......
...@@ -40,6 +40,7 @@ static const struct meson_gx_soc_id { ...@@ -40,6 +40,7 @@ static const struct meson_gx_soc_id {
{ "G12A", 0x28 }, { "G12A", 0x28 },
{ "G12B", 0x29 }, { "G12B", 0x29 },
{ "SM1", 0x2b }, { "SM1", 0x2b },
{ "A1", 0x2c },
}; };
static const struct meson_gx_package_id { static const struct meson_gx_package_id {
...@@ -68,6 +69,8 @@ static const struct meson_gx_package_id { ...@@ -68,6 +69,8 @@ static const struct meson_gx_package_id {
{ "S922X", 0x29, 0x40, 0xf0 }, { "S922X", 0x29, 0x40, 0xf0 },
{ "A311D", 0x29, 0x10, 0xf0 }, { "A311D", 0x29, 0x10, 0xf0 },
{ "S905X3", 0x2b, 0x5, 0xf }, { "S905X3", 0x2b, 0x5, 0xf },
{ "S905D3", 0x2b, 0xb0, 0xf0 },
{ "A113L", 0x2c, 0x0, 0xf8 },
}; };
static inline unsigned int socinfo_to_major(u32 socinfo) static inline unsigned int socinfo_to_major(u32 socinfo)
......
...@@ -16,11 +16,14 @@ enum { ...@@ -16,11 +16,14 @@ enum {
struct meson_sm_firmware; struct meson_sm_firmware;
int meson_sm_call(unsigned int cmd_index, u32 *ret, u32 arg0, u32 arg1, int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
u32 arg2, u32 arg3, u32 arg4); u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
int meson_sm_call_write(void *buffer, unsigned int b_size, unsigned int cmd_index, int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4); unsigned int b_size, unsigned int cmd_index, u32 arg0,
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4); int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
unsigned int bsize, unsigned int cmd_index, u32 arg0,
u32 arg1, u32 arg2, u32 arg3, u32 arg4);
struct meson_sm_firmware *meson_sm_get(struct device_node *firmware_node);
#endif /* _MESON_SM_FW_H_ */ #endif /* _MESON_SM_FW_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment