From b79b3177d3c0eaf18a595feed82b250ac391a87f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 17 Jan 2020 13:46:13 +0900 Subject: [PATCH] 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 --- plat/socionext/uniphier/uniphier.h | 12 +++-- plat/socionext/uniphier/uniphier_emmc.c | 12 ++--- plat/socionext/uniphier/uniphier_io_storage.c | 44 +++++++++++-------- plat/socionext/uniphier/uniphier_nand.c | 10 ++--- plat/socionext/uniphier/uniphier_usb.c | 11 ++--- 5 files changed, 42 insertions(+), 47 deletions(-) diff --git a/plat/socionext/uniphier/uniphier.h b/plat/socionext/uniphier/uniphier.h index 1d3651a03..6ccd422de 100644 --- a/plat/socionext/uniphier/uniphier.h +++ b/plat/socionext/uniphier/uniphier.h @@ -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 */ diff --git a/plat/socionext/uniphier/uniphier_emmc.c b/plat/socionext/uniphier/uniphier_emmc.c index 4ac1f5108..d666ba781 100644 --- a/plat/socionext/uniphier/uniphier_emmc.c +++ b/plat/socionext/uniphier/uniphier_emmc.c @@ -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; } diff --git a/plat/socionext/uniphier/uniphier_io_storage.c b/plat/socionext/uniphier/uniphier_io_storage.c index c039acc86..d15191474 100644 --- a/plat/socionext/uniphier/uniphier_io_storage.c +++ b/plat/socionext/uniphier/uniphier_io_storage.c @@ -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; diff --git a/plat/socionext/uniphier/uniphier_nand.c b/plat/socionext/uniphier/uniphier_nand.c index 27e10e4b7..3925177ed 100644 --- a/plat/socionext/uniphier/uniphier_nand.c +++ b/plat/socionext/uniphier/uniphier_nand.c @@ -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; } diff --git a/plat/socionext/uniphier/uniphier_usb.c b/plat/socionext/uniphier/uniphier_usb.c index ef7079a5f..7469ad1cc 100644 --- a/plat/socionext/uniphier/uniphier_usb.c +++ b/plat/socionext/uniphier/uniphier_usb.c @@ -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; }