uniphier: set buffer offset and length for io_block dynamically

Currently, the .buffer field in io_block_dev_spec is statically set,
which is not handy for PIE.

Towards the goal of making this really position-independent, set the
buffer length and length in the uniphier_io_block_setup() function.

Change-Id: I22b20d7b58d6ffd38f64f967a2820fca4bd7dade
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
Masahiro Yamada 2020-01-17 13:46:13 +09:00
parent b5dd85f2c9
commit b79b3177d3
5 changed files with 42 additions and 47 deletions

View File

@ -36,9 +36,11 @@ unsigned int uniphier_get_boot_master(unsigned int soc);
void uniphier_console_setup(void);
int uniphier_emmc_init(uintptr_t *block_dev_spec);
int uniphier_nand_init(uintptr_t *block_dev_spec);
int uniphier_usb_init(unsigned int soc, uintptr_t *block_dev_spec);
struct io_block_dev_spec;
int uniphier_emmc_init(struct io_block_dev_spec **block_dev_spec);
int uniphier_nand_init(struct io_block_dev_spec **block_dev_spec);
int uniphier_usb_init(unsigned int soc,
struct io_block_dev_spec **block_dev_spec);
int uniphier_io_setup(unsigned int soc);
@ -74,8 +76,4 @@ unsigned int uniphier_calc_core_pos(u_register_t mpidr);
(UNIPHIER_BL33_MAX_SIZE))
#define UNIPHIER_SCP_MAX_SIZE 0x00020000
#define UNIPHIER_BLOCK_BUF_BASE ((UNIPHIER_SCP_BASE) + \
(UNIPHIER_SCP_MAX_SIZE))
#define UNIPHIER_BLOCK_BUF_SIZE 0x00100000
#endif /* UNIPHIER_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -225,11 +225,7 @@ static size_t uniphier_emmc_read(int lba, uintptr_t buf, size_t size)
return ret ? 0 : size;
}
static const struct io_block_dev_spec uniphier_emmc_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
static struct io_block_dev_spec uniphier_emmc_dev_spec = {
.ops = {
.read = uniphier_emmc_read,
},
@ -278,7 +274,7 @@ static int uniphier_emmc_hw_init(void)
return 0;
}
int uniphier_emmc_init(uintptr_t *block_dev_spec)
int uniphier_emmc_init(struct io_block_dev_spec **block_dev_spec)
{
int ret;
@ -286,7 +282,7 @@ int uniphier_emmc_init(uintptr_t *block_dev_spec)
if (ret)
return ret;
*block_dev_spec = (uintptr_t)&uniphier_emmc_dev_spec;
*block_dev_spec = &uniphier_emmc_dev_spec;
return 0;
}

View File

@ -26,6 +26,9 @@
#define UNIPHIER_OCM_REGION_BASE 0x30000000ULL
#define UNIPHIER_OCM_REGION_SIZE 0x00040000ULL
#define UNIPHIER_BLOCK_BUF_BASE 0x84200000UL
#define UNIPHIER_BLOCK_BUF_SIZE 0x00100000UL
static const io_dev_connector_t *uniphier_fip_dev_con;
static uintptr_t uniphier_fip_dev_handle;
@ -189,15 +192,20 @@ static const struct uniphier_io_policy uniphier_io_policies[] = {
#endif
};
static int uniphier_io_block_setup(size_t fip_offset, uintptr_t block_dev_spec)
static int uniphier_io_block_setup(size_t fip_offset,
struct io_block_dev_spec *block_dev_spec,
size_t buffer_offset)
{
int ret;
uniphier_fip_spec.offset = fip_offset;
ret = mmap_add_dynamic_region(UNIPHIER_BLOCK_BUF_BASE,
UNIPHIER_BLOCK_BUF_BASE,
UNIPHIER_BLOCK_BUF_SIZE,
block_dev_spec->buffer.offset = buffer_offset;
block_dev_spec->buffer.length = UNIPHIER_BLOCK_BUF_SIZE;
ret = mmap_add_dynamic_region(block_dev_spec->buffer.offset,
block_dev_spec->buffer.offset,
block_dev_spec->buffer.length,
MT_MEMORY | MT_RW | MT_NS);
if (ret)
return ret;
@ -206,7 +214,7 @@ static int uniphier_io_block_setup(size_t fip_offset, uintptr_t block_dev_spec)
if (ret)
return ret;
return io_dev_open(uniphier_backend_dev_con, block_dev_spec,
return io_dev_open(uniphier_backend_dev_con, (uintptr_t)block_dev_spec,
&uniphier_backend_dev_handle);
}
@ -241,38 +249,38 @@ static int uniphier_io_fip_setup(void)
return io_dev_open(uniphier_fip_dev_con, 0, &uniphier_fip_dev_handle);
}
static int uniphier_io_emmc_setup(unsigned int soc_id)
static int uniphier_io_emmc_setup(unsigned int soc_id, size_t buffer_offset)
{
uintptr_t block_dev_spec;
struct io_block_dev_spec *block_dev_spec;
int ret;
ret = uniphier_emmc_init(&block_dev_spec);
if (ret)
return ret;
return uniphier_io_block_setup(0x20000, block_dev_spec);
return uniphier_io_block_setup(0x20000, block_dev_spec, buffer_offset);
}
static int uniphier_io_nand_setup(unsigned int soc_id)
static int uniphier_io_nand_setup(unsigned int soc_id, size_t buffer_offset)
{
uintptr_t block_dev_spec;
struct io_block_dev_spec *block_dev_spec;
int ret;
ret = uniphier_nand_init(&block_dev_spec);
if (ret)
return ret;
return uniphier_io_block_setup(0x20000, block_dev_spec);
return uniphier_io_block_setup(0x20000, block_dev_spec, buffer_offset);
}
static int uniphier_io_nor_setup(unsigned int soc_id)
static int uniphier_io_nor_setup(unsigned int soc_id, size_t buffer_offset)
{
return uniphier_io_memmap_setup(0x70000);
}
static int uniphier_io_usb_setup(unsigned int soc_id)
static int uniphier_io_usb_setup(unsigned int soc_id, size_t buffer_offset)
{
uintptr_t block_dev_spec;
struct io_block_dev_spec *block_dev_spec;
int ret;
/* use ROM API for loading images from USB storage */
@ -299,10 +307,10 @@ static int uniphier_io_usb_setup(unsigned int soc_id)
if (ret)
return ret;
return uniphier_io_block_setup(0x20000, block_dev_spec);
return uniphier_io_block_setup(0x20000, block_dev_spec, buffer_offset);
}
static int (* const uniphier_io_setup_table[])(unsigned int) = {
static int (* const uniphier_io_setup_table[])(unsigned int, size_t) = {
[UNIPHIER_BOOT_DEVICE_EMMC] = uniphier_io_emmc_setup,
[UNIPHIER_BOOT_DEVICE_NAND] = uniphier_io_nand_setup,
[UNIPHIER_BOOT_DEVICE_NOR] = uniphier_io_nor_setup,
@ -311,7 +319,7 @@ static int (* const uniphier_io_setup_table[])(unsigned int) = {
int uniphier_io_setup(unsigned int soc_id)
{
int (*io_setup)(unsigned int soc_id);
int (*io_setup)(unsigned int soc_id, size_t buffer_offset);
unsigned int boot_dev;
int ret;
@ -320,7 +328,7 @@ int uniphier_io_setup(unsigned int soc_id)
return -EINVAL;
io_setup = uniphier_io_setup_table[boot_dev];
ret = io_setup(soc_id);
ret = io_setup(soc_id, UNIPHIER_BLOCK_BUF_BASE);
if (ret)
return ret;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -224,10 +224,6 @@ static size_t uniphier_nand_read(int lba, uintptr_t buf, size_t size)
}
static struct io_block_dev_spec uniphier_nand_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
.ops = {
.read = uniphier_nand_read,
},
@ -259,7 +255,7 @@ static int uniphier_nand_hw_init(struct uniphier_nand *nand)
return 0;
}
int uniphier_nand_init(uintptr_t *block_dev_spec)
int uniphier_nand_init(struct io_block_dev_spec **block_dev_spec)
{
int ret;
@ -269,7 +265,7 @@ int uniphier_nand_init(uintptr_t *block_dev_spec)
uniphier_nand_dev_spec.block_size = uniphier_nand.page_size;
*block_dev_spec = (uintptr_t)&uniphier_nand_dev_spec;
*block_dev_spec = &uniphier_nand_dev_spec;
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -158,17 +158,14 @@ static size_t uniphier_usb_read(int lba, uintptr_t buf, size_t size)
}
static struct io_block_dev_spec uniphier_usb_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
.ops = {
.read = uniphier_usb_read,
},
.block_size = 512,
};
int uniphier_usb_init(unsigned int soc, uintptr_t *block_dev_spec)
int uniphier_usb_init(unsigned int soc,
struct io_block_dev_spec **block_dev_spec)
{
const struct uniphier_usb_rom_param *param;
@ -180,7 +177,7 @@ int uniphier_usb_init(unsigned int soc, uintptr_t *block_dev_spec)
__uniphier_usb_read = param->read;
*block_dev_spec = (uintptr_t)&uniphier_usb_dev_spec;
*block_dev_spec = &uniphier_usb_dev_spec;
return 0;
}