Commit 7a9bc330 authored by Carlo Caione's avatar Carlo Caione Committed by Kevin Hilman

firmware: meson-sm: Allow 0 as valid return value

Some special SMC calls (i.e. the function used to retrieve the serial
number of the Amlogic SoCs) returns 0 in the register 0 also when the
data was successfully read instead of using the register to hold the
number of bytes returned in the bounce buffer as expected.

With the current implementation of the driver this is seen as an error
and meson_sm_call_read() returns an error even though the data was
correctly read.

To deal with this when we have no information about the amount of read
data (that is 0 is returned by the SMC call) we return to the caller
the requested amount of data and 0 as return value.
Signed-off-by: default avatarCarlo Caione <carlo@endlessm.com>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarKevin Hilman <khilman@baylibre.com>
parent 83e007a0
...@@ -136,11 +136,14 @@ EXPORT_SYMBOL(meson_sm_call); ...@@ -136,11 +136,14 @@ EXPORT_SYMBOL(meson_sm_call);
* @arg4: SMC32 Argument 4 * @arg4: SMC32 Argument 4
* *
* Return: size of read data on success, a negative value on error * Return: size of read data on success, a negative value on error
* When 0 is returned there is no guarantee about the amount of
* 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(void *buffer, unsigned int bsize, unsigned int cmd_index,
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
{ {
u32 size; u32 size;
int ret;
if (!fw.chip) if (!fw.chip)
return -ENOENT; return -ENOENT;
...@@ -154,13 +157,18 @@ int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index, ...@@ -154,13 +157,18 @@ int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0) if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
return -EINVAL; return -EINVAL;
if (!size || size > bsize) if (size > bsize)
return -EINVAL; return -EINVAL;
ret = size;
if (!size)
size = bsize;
if (buffer) if (buffer)
memcpy(buffer, fw.sm_shmem_out_base, size); memcpy(buffer, fw.sm_shmem_out_base, size);
return size; return ret;
} }
EXPORT_SYMBOL(meson_sm_call_read); EXPORT_SYMBOL(meson_sm_call_read);
......
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