Commit b79b3177 authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent b5dd85f2
...@@ -36,9 +36,11 @@ unsigned int uniphier_get_boot_master(unsigned int soc); ...@@ -36,9 +36,11 @@ unsigned int uniphier_get_boot_master(unsigned int soc);
void uniphier_console_setup(void); void uniphier_console_setup(void);
int uniphier_emmc_init(uintptr_t *block_dev_spec); struct io_block_dev_spec;
int uniphier_nand_init(uintptr_t *block_dev_spec); int uniphier_emmc_init(struct io_block_dev_spec **block_dev_spec);
int uniphier_usb_init(unsigned int soc, uintptr_t *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); int uniphier_io_setup(unsigned int soc);
...@@ -74,8 +76,4 @@ unsigned int uniphier_calc_core_pos(u_register_t mpidr); ...@@ -74,8 +76,4 @@ unsigned int uniphier_calc_core_pos(u_register_t mpidr);
(UNIPHIER_BL33_MAX_SIZE)) (UNIPHIER_BL33_MAX_SIZE))
#define UNIPHIER_SCP_MAX_SIZE 0x00020000 #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 */ #endif /* UNIPHIER_H */
/* /*
* 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 * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -225,11 +225,7 @@ static size_t uniphier_emmc_read(int lba, uintptr_t buf, size_t size) ...@@ -225,11 +225,7 @@ static size_t uniphier_emmc_read(int lba, uintptr_t buf, size_t size)
return ret ? 0 : size; return ret ? 0 : size;
} }
static const struct io_block_dev_spec uniphier_emmc_dev_spec = { static struct io_block_dev_spec uniphier_emmc_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
.ops = { .ops = {
.read = uniphier_emmc_read, .read = uniphier_emmc_read,
}, },
...@@ -278,7 +274,7 @@ static int uniphier_emmc_hw_init(void) ...@@ -278,7 +274,7 @@ static int uniphier_emmc_hw_init(void)
return 0; 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; int ret;
...@@ -286,7 +282,7 @@ int uniphier_emmc_init(uintptr_t *block_dev_spec) ...@@ -286,7 +282,7 @@ int uniphier_emmc_init(uintptr_t *block_dev_spec)
if (ret) if (ret)
return ret; return ret;
*block_dev_spec = (uintptr_t)&uniphier_emmc_dev_spec; *block_dev_spec = &uniphier_emmc_dev_spec;
return 0; return 0;
} }
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#define UNIPHIER_OCM_REGION_BASE 0x30000000ULL #define UNIPHIER_OCM_REGION_BASE 0x30000000ULL
#define UNIPHIER_OCM_REGION_SIZE 0x00040000ULL #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 const io_dev_connector_t *uniphier_fip_dev_con;
static uintptr_t uniphier_fip_dev_handle; static uintptr_t uniphier_fip_dev_handle;
...@@ -189,15 +192,20 @@ static const struct uniphier_io_policy uniphier_io_policies[] = { ...@@ -189,15 +192,20 @@ static const struct uniphier_io_policy uniphier_io_policies[] = {
#endif #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; int ret;
uniphier_fip_spec.offset = fip_offset; uniphier_fip_spec.offset = fip_offset;
ret = mmap_add_dynamic_region(UNIPHIER_BLOCK_BUF_BASE, block_dev_spec->buffer.offset = buffer_offset;
UNIPHIER_BLOCK_BUF_BASE, block_dev_spec->buffer.length = UNIPHIER_BLOCK_BUF_SIZE;
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); MT_MEMORY | MT_RW | MT_NS);
if (ret) if (ret)
return ret; return ret;
...@@ -206,7 +214,7 @@ static int uniphier_io_block_setup(size_t fip_offset, uintptr_t block_dev_spec) ...@@ -206,7 +214,7 @@ static int uniphier_io_block_setup(size_t fip_offset, uintptr_t block_dev_spec)
if (ret) if (ret)
return 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); &uniphier_backend_dev_handle);
} }
...@@ -241,38 +249,38 @@ static int uniphier_io_fip_setup(void) ...@@ -241,38 +249,38 @@ static int uniphier_io_fip_setup(void)
return io_dev_open(uniphier_fip_dev_con, 0, &uniphier_fip_dev_handle); 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; int ret;
ret = uniphier_emmc_init(&block_dev_spec); ret = uniphier_emmc_init(&block_dev_spec);
if (ret) if (ret)
return 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; int ret;
ret = uniphier_nand_init(&block_dev_spec); ret = uniphier_nand_init(&block_dev_spec);
if (ret) if (ret)
return 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); 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; int ret;
/* use ROM API for loading images from USB storage */ /* use ROM API for loading images from USB storage */
...@@ -299,10 +307,10 @@ static int uniphier_io_usb_setup(unsigned int soc_id) ...@@ -299,10 +307,10 @@ static int uniphier_io_usb_setup(unsigned int soc_id)
if (ret) if (ret)
return 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_EMMC] = uniphier_io_emmc_setup,
[UNIPHIER_BOOT_DEVICE_NAND] = uniphier_io_nand_setup, [UNIPHIER_BOOT_DEVICE_NAND] = uniphier_io_nand_setup,
[UNIPHIER_BOOT_DEVICE_NOR] = uniphier_io_nor_setup, [UNIPHIER_BOOT_DEVICE_NOR] = uniphier_io_nor_setup,
...@@ -311,7 +319,7 @@ static int (* const uniphier_io_setup_table[])(unsigned int) = { ...@@ -311,7 +319,7 @@ static int (* const uniphier_io_setup_table[])(unsigned int) = {
int uniphier_io_setup(unsigned int soc_id) 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; unsigned int boot_dev;
int ret; int ret;
...@@ -320,7 +328,7 @@ int uniphier_io_setup(unsigned int soc_id) ...@@ -320,7 +328,7 @@ int uniphier_io_setup(unsigned int soc_id)
return -EINVAL; return -EINVAL;
io_setup = uniphier_io_setup_table[boot_dev]; io_setup = uniphier_io_setup_table[boot_dev];
ret = io_setup(soc_id); ret = io_setup(soc_id, UNIPHIER_BLOCK_BUF_BASE);
if (ret) if (ret)
return ret; return ret;
......
/* /*
* 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 * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -224,10 +224,6 @@ static size_t uniphier_nand_read(int lba, uintptr_t buf, size_t size) ...@@ -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 = { static struct io_block_dev_spec uniphier_nand_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
.ops = { .ops = {
.read = uniphier_nand_read, .read = uniphier_nand_read,
}, },
...@@ -259,7 +255,7 @@ static int uniphier_nand_hw_init(struct uniphier_nand *nand) ...@@ -259,7 +255,7 @@ static int uniphier_nand_hw_init(struct uniphier_nand *nand)
return 0; 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; int ret;
...@@ -269,7 +265,7 @@ int uniphier_nand_init(uintptr_t *block_dev_spec) ...@@ -269,7 +265,7 @@ int uniphier_nand_init(uintptr_t *block_dev_spec)
uniphier_nand_dev_spec.block_size = uniphier_nand.page_size; 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; return 0;
} }
/* /*
* 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 * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -158,17 +158,14 @@ static size_t uniphier_usb_read(int lba, uintptr_t buf, size_t size) ...@@ -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 = { static struct io_block_dev_spec uniphier_usb_dev_spec = {
.buffer = {
.offset = UNIPHIER_BLOCK_BUF_BASE,
.length = UNIPHIER_BLOCK_BUF_SIZE,
},
.ops = { .ops = {
.read = uniphier_usb_read, .read = uniphier_usb_read,
}, },
.block_size = 512, .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; const struct uniphier_usb_rom_param *param;
...@@ -180,7 +177,7 @@ int uniphier_usb_init(unsigned int soc, uintptr_t *block_dev_spec) ...@@ -180,7 +177,7 @@ int uniphier_usb_init(unsigned int soc, uintptr_t *block_dev_spec)
__uniphier_usb_read = param->read; __uniphier_usb_read = param->read;
*block_dev_spec = (uintptr_t)&uniphier_usb_dev_spec; *block_dev_spec = &uniphier_usb_dev_spec;
return 0; return 0;
} }
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