[U-Boot] [PATCH V2 08/32] misc: imx8: add scfw api impementation

Peng Fan peng.fan at nxp.com
Wed Jul 18 09:08:21 UTC 2018


Hi Lokesh,

> -----Original Message-----
> From: Lokesh Vutla [mailto:lokeshvutla at ti.com]
> Sent: 2018年7月18日 16:54
> To: Peng Fan <peng.fan at nxp.com>; sbabic at denx.de; Fabio Estevam
> <fabio.estevam at nxp.com>
> Cc: u-boot at lists.denx.de; dl-linux-imx <linux-imx at nxp.com>
> Subject: Re: [U-Boot] [PATCH V2 08/32] misc: imx8: add scfw api impementation
> 
> 
> 
> On Wednesday 18 July 2018 07:05 AM, Peng Fan wrote:
> > Add clk/misc/pad/pm/rm scfw api implementaion for different drivers to
> > invoke. The low level code is using misc_call to invoke imx8_scu
> > driver.
> 
> Hmm.. there should be abstraction of all API specification under
> drivers/firmware and exported as firmware ops. And respective pm/clk/pad
> drivers should call the firmware ops to do respective job.
> 
> Ideally this is how the sw architecture should looks like[1]. Atleast this is how
> kernel follows. This way clock framework, PM framework can be used and DT
> can be same as kernel.

I understand.

The misc driver in this patch holding the protocol and communication part.
This patch is only the protocol part.

Other drivers will invoke misc_call to get service from scu.

I do not want add another mailbox driver here. Also the uboot firmware uclass
only has psci there.

Thanks,
Peng.

> 
> May be I am missing something, but why can the drivers in $patch follow the
> same convention?
> 
> [1]
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpastebi
> n.ubuntu.com%2Fp%2FJsxYx4QBZD%2F&data=02%7C01%7Cpeng.fan%40n
> xp.com%7Ce1f24699457a4e4a89d108d5ec8c3236%7C686ea1d3bc2b4c6fa92cd
> 99c5c301635%7C0%7C1%7C636675009253601516&sdata=J283xdFj9Q8b6
> BEhea1tcp923envUkAMgRpacHC362I%3D&reserved=0
> 
> Thanks and regards,
> Lokesh
> 
> >
> > Signed-off-by: Peng Fan <peng.fan at nxp.com>
> > Cc: Stefano Babic <sbabic at denx.de>
> > ---
> >  arch/arm/include/asm/arch-imx8/sci/sci.h | 31 +++++++++-
> >  drivers/misc/imx8/Makefile               |  2 +-
> >  drivers/misc/imx8/clk.c                  | 93
> ++++++++++++++++++++++++++++++
> >  drivers/misc/imx8/misc.c                 | 88
> +++++++++++++++++++++++++++++
> >  drivers/misc/imx8/pad.c                  | 39 +++++++++++++
> >  drivers/misc/imx8/pm.c                   | 38 +++++++++++++
> >  drivers/misc/imx8/rm.c                   | 97
> ++++++++++++++++++++++++++++++++
> >  7 files changed, 386 insertions(+), 2 deletions(-)  create mode
> > 100644 drivers/misc/imx8/clk.c  create mode 100644
> > drivers/misc/imx8/misc.c  create mode 100644 drivers/misc/imx8/pad.c
> > create mode 100644 drivers/misc/imx8/pm.c  create mode 100644
> > drivers/misc/imx8/rm.c
> >
> > diff --git a/arch/arm/include/asm/arch-imx8/sci/sci.h
> > b/arch/arm/include/asm/arch-imx8/sci/sci.h
> > index b7280aee05..4704ba9699 100644
> > --- a/arch/arm/include/asm/arch-imx8/sci/sci.h
> > +++ b/arch/arm/include/asm/arch-imx8/sci/sci.h
> > @@ -46,7 +46,8 @@ static inline int sc_err_to_linux(sc_err_t err)
> >  		ret = -EIO;
> >  		break;
> >  	default:
> > -		panic("Invalid sc_err_t value\n");
> > +		ret = 0;
> > +		break;
> >  	}
> >
> >  	debug("%s %d %d\n", __func__, err, ret); @@ -54,4 +55,32 @@ static
> > inline int sc_err_to_linux(sc_err_t err)
> >  	return ret;
> >  }
> >
> > +/* PM API*/
> > +int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
> > +				  sc_pm_power_mode_t mode);
> > +int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +			 sc_pm_clock_rate_t *rate);
> > +int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +			 sc_pm_clock_rate_t *rate);
> > +int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +			 sc_pm_clock_rate_t *rate);
> > +int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +			 sc_pm_clock_rate_t *rate);
> > +int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +		       sc_bool_t enable, sc_bool_t autog);
> > +
> > +/* MISC API */
> > +int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl,
> > +			u32 *val);
> > +void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev); void
> > +sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status);
> > +
> > +/* RM API */
> > +sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr); int
> > +sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t
> *addr_start,
> > +			  sc_faddr_t *addr_end);
> > +sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource);
> > +
> > +/* PAD API */
> > +int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val);
> >  #endif
> > diff --git a/drivers/misc/imx8/Makefile b/drivers/misc/imx8/Makefile
> > index 3395340d22..4fc08ade50 100644
> > --- a/drivers/misc/imx8/Makefile
> > +++ b/drivers/misc/imx8/Makefile
> > @@ -1,3 +1,3 @@
> >  # SPDX-License-Identifier: GPL-2.0+
> >
> > -obj-y += scu.o
> > +obj-y += pm.o clk.o misc.o pad.o rm.o scu.o
> > diff --git a/drivers/misc/imx8/clk.c b/drivers/misc/imx8/clk.c new
> > file mode 100644 index 0000000000..618b2c386f
> > --- /dev/null
> > +++ b/drivers/misc/imx8/clk.c
> > @@ -0,0 +1,93 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018 NXP
> > + *
> > + * Peng Fan <peng.fan at nxp.com>
> > + */
> > +
> > +#include <common.h>
> > +#include <asm/io.h>
> > +#include <dm.h>
> > +#include <asm/arch/sci/sci.h>
> > +#include <misc.h>
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +			 sc_pm_clock_rate_t *rate)
> > +{
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	sc_rpc_msg_t msg;
> > +	int ret;
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
> > +	RPC_FUNC(&msg) = (u8)PM_FUNC_SET_CLOCK_RATE;
> > +	RPC_U32(&msg, 0U) = *(u32 *)rate;
> > +	RPC_U16(&msg, 4U) = (u16)resource;
> > +	RPC_U8(&msg, 6U) = (u8)clk;
> > +	RPC_SIZE(&msg) = 3U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: rate:%u resource:%u: clk:%u res:%d\n",
> > +		       __func__, *rate, resource, clk, RPC_R8(&msg));
> > +
> > +	*rate = RPC_U32(&msg, 0U);
> > +
> > +	return ret;
> > +}
> > +
> > +int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +			 sc_pm_clock_rate_t *rate)
> > +{
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	sc_rpc_msg_t msg;
> > +	int ret;
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
> > +	RPC_FUNC(&msg) = (u8)PM_FUNC_GET_CLOCK_RATE;
> > +	RPC_U16(&msg, 0U) = (u16)resource;
> > +	RPC_U8(&msg, 2U) = (u8)clk;
> > +	RPC_SIZE(&msg) = 2U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret) {
> > +		printf("%s: resource:%d clk:%d: res:%d\n",
> > +		       __func__, resource, clk, RPC_R8(&msg));
> > +		return ret;
> > +	}
> > +
> > +	if (rate)
> > +		*rate = RPC_U32(&msg, 0U);
> > +
> > +	return 0;
> > +}
> > +
> > +int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
> > +		       sc_bool_t enable, sc_bool_t autog) {
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	sc_rpc_msg_t msg;
> > +	int ret;
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
> > +	RPC_FUNC(&msg) = (u8)PM_FUNC_CLOCK_ENABLE;
> > +	RPC_U16(&msg, 0U) = (u16)resource;
> > +	RPC_U8(&msg, 2U) = (u8)clk;
> > +	RPC_U8(&msg, 3U) = (u8)enable;
> > +	RPC_U8(&msg, 4U) = (u8)autog;
> > +	RPC_SIZE(&msg) = 3U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: resource:%d clk:%d: enable:%d autog: %d, res:%d\n",
> > +		       __func__, resource, clk, enable, autog, RPC_R8(&msg));
> > +
> > +	return ret;
> > +}
> > diff --git a/drivers/misc/imx8/misc.c b/drivers/misc/imx8/misc.c new
> > file mode 100644 index 0000000000..7557384b64
> > --- /dev/null
> > +++ b/drivers/misc/imx8/misc.c
> > @@ -0,0 +1,88 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018 NXP
> > + *
> > + * Peng Fan <peng.fan at nxp.com>
> > + */
> > +
> > +#include <common.h>
> > +#include <asm/io.h>
> > +#include <dm.h>
> > +#include <asm/arch/sci/sci.h>
> > +#include <misc.h>
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl,
> > +			u32 *val)
> > +{
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	int ret;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
> > +	RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_CONTROL;
> > +	RPC_U32(&msg, 0U) = (u32)ctrl;
> > +	RPC_U16(&msg, 4U) = (u16)resource;
> > +	RPC_SIZE(&msg) = 3U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: ctrl:%d resource:%d: res:%d\n",
> > +		       __func__, ctrl, resource, RPC_R8(&msg));
> > +
> > +	if (!val)
> > +		*val = RPC_U32(&msg, 0U);
> > +
> > +	return ret;
> > +}
> > +
> > +void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev) {
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	int ret;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
> > +	RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_BOOT_DEV;
> > +	RPC_SIZE(&msg) = 1U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: res:%d\n", __func__, RPC_R8(&msg));
> > +
> > +	if (!boot_dev)
> > +		*boot_dev = RPC_U16(&msg, 0U);
> > +}
> > +
> > +void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status)
> > +{
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	int ret;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
> > +	RPC_FUNC(&msg) = (u8)MISC_FUNC_BOOT_STATUS;
> > +	RPC_U8(&msg, 0U) = (u8)status;
> > +	RPC_SIZE(&msg) = 2U;
> > +
> > +	ret = misc_call(dev, SC_TRUE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: status:%d res:%d\n",
> > +		       __func__, status, RPC_R8(&msg)); }
> > diff --git a/drivers/misc/imx8/pad.c b/drivers/misc/imx8/pad.c new
> > file mode 100644 index 0000000000..06cbdc90bf
> > --- /dev/null
> > +++ b/drivers/misc/imx8/pad.c
> > @@ -0,0 +1,39 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018 NXP
> > + *
> > + * Peng Fan <peng.fan at nxp.com>
> > + */
> > +
> > +#include <common.h>
> > +#include <asm/io.h>
> > +#include <dm.h>
> > +#include <asm/arch/sci/sci.h>
> > +#include <misc.h>
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val) {
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	int ret;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_PAD;
> > +	RPC_FUNC(&msg) = (u8)PAD_FUNC_SET;
> > +	RPC_U32(&msg, 0U) = (u32)val;
> > +	RPC_U16(&msg, 4U) = (u16)pad;
> > +	RPC_SIZE(&msg) = 3U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: val:%d pad:%d: res:%d\n",
> > +		       __func__, val, pad, RPC_R8(&msg));
> > +
> > +	return ret;
> > +}
> > diff --git a/drivers/misc/imx8/pm.c b/drivers/misc/imx8/pm.c new file
> > mode 100644 index 0000000000..c857138e36
> > --- /dev/null
> > +++ b/drivers/misc/imx8/pm.c
> > @@ -0,0 +1,38 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018 NXP
> > + *
> > + * Peng Fan <peng.fan at nxp.com>
> > + */
> > +
> > +#include <common.h>
> > +#include <asm/io.h>
> > +#include <dm.h>
> > +#include <asm/arch/sci/sci.h>
> > +#include <misc.h>
> > +
> > +int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
> > +				  sc_pm_power_mode_t mode)
> > +{
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	int ret;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
> > +	RPC_FUNC(&msg) = (u8)PM_FUNC_SET_RESOURCE_POWER_MODE;
> > +	RPC_U16(&msg, 0U) = (u16)resource;
> > +	RPC_U8(&msg, 2U) = (u8)mode;
> > +	RPC_SIZE(&msg) = 2U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: resource:%d mode:%d: res:%d\n",
> > +		       __func__, resource, mode, RPC_R8(&msg));
> > +
> > +	return ret;
> > +}
> > diff --git a/drivers/misc/imx8/rm.c b/drivers/misc/imx8/rm.c new file
> > mode 100644 index 0000000000..33de1f525b
> > --- /dev/null
> > +++ b/drivers/misc/imx8/rm.c
> > @@ -0,0 +1,97 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018 NXP
> > + *
> > + * Peng Fan <peng.fan at nxp.com>
> > + */
> > +
> > +#include <common.h>
> > +#include <asm/io.h>
> > +#include <dm.h>
> > +#include <asm/arch/sci/sci.h>
> > +#include <misc.h>
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr) {
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	sc_err_t result;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
> > +	RPC_FUNC(&msg) = (u8)RM_FUNC_IS_MEMREG_OWNED;
> > +	RPC_U8(&msg, 0U) = (u8)mr;
> > +	RPC_SIZE(&msg) = 2U;
> > +
> > +	misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +
> > +	result = RPC_R8(&msg);
> > +
> > +	if (result != 0 && result != 1)
> > +		printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
> > +
> > +	return (sc_bool_t)result;
> > +}
> > +
> > +int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t
> *addr_start,
> > +			  sc_faddr_t *addr_end)
> > +{
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	int ret;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
> > +	RPC_FUNC(&msg) = (u8)RM_FUNC_GET_MEMREG_INFO;
> > +	RPC_U8(&msg, 0U) = (u8)mr;
> > +	RPC_SIZE(&msg) = 2U;
> > +
> > +	ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	if (ret)
> > +		printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
> > +
> > +	if (addr_start)
> > +		*addr_start = ((u64)RPC_U32(&msg, 0U) << 32U) |
> > +			RPC_U32(&msg, 4U);
> > +
> > +	if (addr_end)
> > +		*addr_end = ((u64)RPC_U32(&msg, 8U) << 32U) |
> > +			RPC_U32(&msg, 12U);
> > +
> > +	return ret;
> > +}
> > +
> > +sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource) {
> > +	struct udevice *dev = gd->arch.scu_dev;
> > +	int size = sizeof(sc_rpc_msg_t);
> > +	struct sc_rpc_msg_s msg;
> > +	u8 result;
> > +
> > +	if (!dev)
> > +		hang();
> > +
> > +	RPC_VER(&msg) = SC_RPC_VERSION;
> > +	RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
> > +	RPC_FUNC(&msg) = (u8)RM_FUNC_IS_RESOURCE_OWNED;
> > +	RPC_U16(&msg, 0U) = (u16)resource;
> > +	RPC_SIZE(&msg) = 2U;
> > +
> > +	misc_call(dev, SC_FALSE, &msg, size, &msg, size);
> > +	result = RPC_R8(&msg);
> > +	if (result != 0 && result != 1)
> > +		printf("%s: resource:%d res:%d\n",
> > +		       __func__, resource, RPC_R8(&msg));
> > +
> > +	return !!result;
> > +}
> >


More information about the U-Boot mailing list