diff mbox series

[U-Boot,12/13] firmware: zynqmp: Separate function for sending message via mailbox

Message ID 3bf20ccc54d5d8fa1951cfa7546fd1f0113727dd.1569591296.git.michal.simek@xilinx.com
State New
Delegated to: Michal Simek
Headers show
Series arm64: zynqmp: Clean communication with PMUFW | expand

Commit Message

Michal Simek Sept. 27, 2019, 1:35 p.m. UTC
U-Boot running in EL3 can't use SMC that's why there is a need to talk to
PMUFW directly via mailbox. The same logic is applied to all functions
which need to talk to PMUFW that's why move this logic to separate function
to avoid code duplication.

Also SMC request ID can be composed from PM_SIP_SVC offset that's why
ZYNQMP_SIP_SVC_GET_API_VERSION macro can be removed completely.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 drivers/firmware/firmware-zynqmp.c | 19 ++++++++++---------
 include/zynqmp_firmware.h          |  2 --
 2 files changed, 10 insertions(+), 11 deletions(-)

Comments

Luca Ceresoli Oct. 2, 2019, 9:34 a.m. UTC | #1
Hi Michal,

On 27/09/19 15:35, Michal Simek wrote:
> U-Boot running in EL3 can't use SMC that's why there is a need to talk to
> PMUFW directly via mailbox. The same logic is applied to all functions
> which need to talk to PMUFW that's why move this logic to separate function
> to avoid code duplication.
> 
> Also SMC request ID can be composed from PM_SIP_SVC offset that's why
> ZYNQMP_SIP_SVC_GET_API_VERSION macro can be removed completely.
> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
> 
>  drivers/firmware/firmware-zynqmp.c | 19 ++++++++++---------
>  include/zynqmp_firmware.h          |  2 --
>  2 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c
> index d70f34f24388..b7e3039c8337 100644
> --- a/drivers/firmware/firmware-zynqmp.c
> +++ b/drivers/firmware/firmware-zynqmp.c
> @@ -40,6 +40,14 @@ static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
>  	return 0;
>  }
>  
> +static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
> +{
> +	if (IS_ENABLED(CONFIG_SPL_BUILD))
> +		return ipi_req(req, req_len, res, 2);

I guess the last parameter should be res_maxlen, not 2.

Other than than, looks good.
Michal Simek Oct. 2, 2019, 10:03 a.m. UTC | #2
On 02. 10. 19 11:34, Luca Ceresoli wrote:
> Hi Michal,
> 
> On 27/09/19 15:35, Michal Simek wrote:
>> U-Boot running in EL3 can't use SMC that's why there is a need to talk to
>> PMUFW directly via mailbox. The same logic is applied to all functions
>> which need to talk to PMUFW that's why move this logic to separate function
>> to avoid code duplication.
>>
>> Also SMC request ID can be composed from PM_SIP_SVC offset that's why
>> ZYNQMP_SIP_SVC_GET_API_VERSION macro can be removed completely.
>>
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
>> ---
>>
>>  drivers/firmware/firmware-zynqmp.c | 19 ++++++++++---------
>>  include/zynqmp_firmware.h          |  2 --
>>  2 files changed, 10 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c
>> index d70f34f24388..b7e3039c8337 100644
>> --- a/drivers/firmware/firmware-zynqmp.c
>> +++ b/drivers/firmware/firmware-zynqmp.c
>> @@ -40,6 +40,14 @@ static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
>>  	return 0;
>>  }
>>  
>> +static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
>> +{
>> +	if (IS_ENABLED(CONFIG_SPL_BUILD))
>> +		return ipi_req(req, req_len, res, 2);
> 
> I guess the last parameter should be res_maxlen, not 2.
> 
> Other than than, looks good.

good catch. Will fix.

M
diff mbox series

Patch

diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c
index d70f34f24388..b7e3039c8337 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -40,6 +40,14 @@  static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
 	return 0;
 }
 
+static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
+{
+	if (IS_ENABLED(CONFIG_SPL_BUILD))
+		return ipi_req(req, req_len, res, 2);
+
+	return invoke_smc(req[0] + PM_SIP_SVC, 0, 0, 0, 0, res);
+}
+
 unsigned int zynqmp_firmware_version(void)
 {
 	int ret;
@@ -52,16 +60,9 @@  unsigned int zynqmp_firmware_version(void)
 	 * asking PMUFW again.
 	 **/
 	if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) {
-		if (IS_ENABLED(CONFIG_SPL_BUILD)) {
-			const u32 request[] = { PM_GET_API_VERSION };
-
-			ret = ipi_req(request, ARRAY_SIZE(request),
-				      ret_payload, 2);
-		} else {
-			ret = invoke_smc(ZYNQMP_SIP_SVC_GET_API_VERSION, 0, 0,
-					 0, 0, ret_payload);
-		};
+		const u32 request[] = { PM_GET_API_VERSION };
 
+		ret = send_req(request, ARRAY_SIZE(request), ret_payload, 2);
 		if (ret)
 			panic("PMUFW is not found - Please load it!\n");
 
diff --git a/include/zynqmp_firmware.h b/include/zynqmp_firmware.h
index c522cae8399b..1fbc82414ab5 100644
--- a/include/zynqmp_firmware.h
+++ b/include/zynqmp_firmware.h
@@ -9,8 +9,6 @@ 
 #define _ZYNQM_FIRMWARE_H_
 
 #define PM_SIP_SVC      0xc2000000
-#define ZYNQMP_SIP_SVC_GET_API_VERSION          \
-	(PM_SIP_SVC + PM_GET_API_VERSION)
 #define ZYNQMP_SIP_SVC_PM_SECURE_IMG_LOAD       \
 	(PM_SIP_SVC + PM_SECURE_IMAGE)