2016-05-25 12:03:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
|
|
|
|
*
|
2017-05-03 09:38:09 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2016-05-25 12:03:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <common/bl_common.h>
|
|
|
|
#include <common/debug.h>
|
|
|
|
#include <drivers/console.h>
|
|
|
|
#include <drivers/gpio.h>
|
|
|
|
#include <lib/coreboot.h>
|
|
|
|
#include <lib/mmio.h>
|
|
|
|
#include <plat/common/platform.h>
|
|
|
|
|
2016-05-25 12:03:04 +01:00
|
|
|
#include <plat_params.h>
|
|
|
|
#include <plat_private.h>
|
|
|
|
|
2016-09-09 19:43:15 +01:00
|
|
|
static struct gpio_info param_reset;
|
|
|
|
static struct gpio_info param_poweroff;
|
2016-09-09 19:47:53 +01:00
|
|
|
static struct bl31_apio_param param_apio;
|
2016-05-25 12:03:04 +01:00
|
|
|
static struct gpio_info *rst_gpio;
|
|
|
|
static struct gpio_info *poweroff_gpio;
|
2016-09-09 19:43:15 +01:00
|
|
|
static struct gpio_info suspend_gpio[10];
|
|
|
|
uint32_t suspend_gpio_cnt;
|
2016-09-09 19:47:53 +01:00
|
|
|
static struct apio_info *suspend_apio;
|
2016-05-25 12:03:04 +01:00
|
|
|
|
2016-09-09 19:43:15 +01:00
|
|
|
struct gpio_info *plat_get_rockchip_gpio_reset(void)
|
2016-05-25 12:03:04 +01:00
|
|
|
{
|
|
|
|
return rst_gpio;
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:43:15 +01:00
|
|
|
struct gpio_info *plat_get_rockchip_gpio_poweroff(void)
|
2016-05-25 12:03:04 +01:00
|
|
|
{
|
|
|
|
return poweroff_gpio;
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:43:15 +01:00
|
|
|
struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count)
|
|
|
|
{
|
|
|
|
*count = suspend_gpio_cnt;
|
|
|
|
|
|
|
|
return &suspend_gpio[0];
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:47:53 +01:00
|
|
|
struct apio_info *plat_get_rockchip_suspend_apio(void)
|
|
|
|
{
|
|
|
|
return suspend_apio;
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:03:04 +01:00
|
|
|
void params_early_setup(void *plat_param_from_bl2)
|
|
|
|
{
|
|
|
|
struct bl31_plat_param *bl2_param;
|
|
|
|
struct bl31_gpio_param *gpio_param;
|
|
|
|
|
|
|
|
/* keep plat parameters for later processing if need */
|
|
|
|
bl2_param = (struct bl31_plat_param *)plat_param_from_bl2;
|
|
|
|
while (bl2_param) {
|
|
|
|
switch (bl2_param->type) {
|
|
|
|
case PARAM_RESET:
|
2016-09-09 19:43:15 +01:00
|
|
|
gpio_param = (struct bl31_gpio_param *)bl2_param;
|
|
|
|
memcpy(¶m_reset, &gpio_param->gpio,
|
|
|
|
sizeof(struct gpio_info));
|
|
|
|
rst_gpio = ¶m_reset;
|
2016-05-25 12:03:04 +01:00
|
|
|
break;
|
|
|
|
case PARAM_POWEROFF:
|
2016-09-09 19:43:15 +01:00
|
|
|
gpio_param = (struct bl31_gpio_param *)bl2_param;
|
|
|
|
memcpy(¶m_poweroff, &gpio_param->gpio,
|
|
|
|
sizeof(struct gpio_info));
|
|
|
|
poweroff_gpio = ¶m_poweroff;
|
|
|
|
break;
|
|
|
|
case PARAM_SUSPEND_GPIO:
|
|
|
|
if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) {
|
|
|
|
ERROR("exceed support suspend gpio number\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gpio_param = (struct bl31_gpio_param *)bl2_param;
|
|
|
|
memcpy(&suspend_gpio[suspend_gpio_cnt],
|
|
|
|
&gpio_param->gpio,
|
|
|
|
sizeof(struct gpio_info));
|
|
|
|
suspend_gpio_cnt++;
|
2016-05-25 12:03:04 +01:00
|
|
|
break;
|
2016-09-09 19:47:53 +01:00
|
|
|
case PARAM_SUSPEND_APIO:
|
|
|
|
memcpy(¶m_apio, bl2_param,
|
|
|
|
sizeof(struct bl31_apio_param));
|
|
|
|
suspend_apio = ¶m_apio.apio;
|
|
|
|
break;
|
2017-06-09 23:22:44 +01:00
|
|
|
#if COREBOOT
|
|
|
|
case PARAM_COREBOOT_TABLE:
|
|
|
|
coreboot_table_setup((void *)
|
|
|
|
((struct bl31_u64_param *)bl2_param)->value);
|
|
|
|
break;
|
|
|
|
#endif
|
2016-05-25 12:03:04 +01:00
|
|
|
default:
|
types: use int-ll64 for both aarch32 and aarch64
Since commit 031dbb122472 ("AArch32: Add essential Arch helpers"),
it is difficult to use consistent format strings for printf() family
between aarch32 and aarch64.
For example, uint64_t is defined as 'unsigned long long' for aarch32
and as 'unsigned long' for aarch64. Likewise, uintptr_t is defined
as 'unsigned int' for aarch32, and as 'unsigned long' for aarch64.
A problem typically arises when you use printf() in common code.
One solution could be, to cast the arguments to a type long enough
for both architectures. For example, if 'val' is uint64_t type,
like this:
printf("val = %llx\n", (unsigned long long)val);
Or, somebody may suggest to use a macro provided by <inttypes.h>,
like this:
printf("val = %" PRIx64 "\n", val);
But, both would make the code ugly.
The solution adopted in Linux kernel is to use the same typedefs for
all architectures. The fixed integer types in the kernel-space have
been unified into int-ll64, like follows:
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
[ Linux commit: 0c79a8e29b5fcbcbfd611daf9d500cfad8370fcf ]
This gets along with the codebase shared between 32 bit and 64 bit,
with the data model called ILP32, LP64, respectively.
The width for primitive types is defined as follows:
ILP32 LP64
int 32 32
long 32 64
long long 64 64
pointer 32 64
'long long' is 64 bit for both, so it is used for defining uint64_t.
'long' has the same width as pointer, so for uintptr_t.
We still need an ifdef conditional for (s)size_t.
All 64 bit architectures use "unsigned long" size_t, and most 32 bit
architectures use "unsigned int" size_t. H8/300, S/390 are known as
exceptions; they use "unsigned long" size_t despite their architecture
is 32 bit.
One idea for simplification might be to define size_t as 'unsigned long'
across architectures, then forbid the use of "%z" string format.
However, this would cause a distortion between size_t and sizeof()
operator. We have unknowledge about the native type of sizeof(), so
we need a guess of it anyway. I want the following formula to always
return 1:
__builtin_types_compatible_p(size_t, typeof(sizeof(int)))
Fortunately, ARM is probably a majority case. As far as I know, all
32 bit ARM compilers use "unsigned int" size_t.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-02-02 06:09:36 +00:00
|
|
|
ERROR("not expected type found %lld\n",
|
2016-09-09 19:43:15 +01:00
|
|
|
bl2_param->type);
|
|
|
|
break;
|
2016-05-25 12:03:04 +01:00
|
|
|
}
|
|
|
|
bl2_param = bl2_param->next;
|
|
|
|
}
|
|
|
|
}
|