stm32mp1: split code between common and private parts
authorYann Gautier <yann.gautier@st.com>
Thu, 14 Feb 2019 10:13:25 +0000 (11:13 +0100)
committerYann Gautier <yann.gautier@st.com>
Thu, 14 Feb 2019 10:20:23 +0000 (11:20 +0100)
Some parts of code could be shared with platform derivatives,
or new platforms.
A new folder plat/st/common is created to put common parts.

stm32mp_common.h is a common API aggregate.

Remove some casts where applicable.
Fix some types where applicable.
Remove also some platform includes that are already in stm32mp1_def.h.

Change-Id: I46d763c8d9e15732d1ee7383207fd58206d7f583
Signed-off-by: Yann Gautier <yann.gautier@st.com>
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
19 files changed:
drivers/st/gpio/stm32_gpio.c
plat/st/common/bl2_io_storage.c [new file with mode: 0644]
plat/st/common/include/stm32mp_common.h [new file with mode: 0644]
plat/st/common/include/stm32mp_dt.h [new file with mode: 0644]
plat/st/common/stm32mp_common.c [new file with mode: 0644]
plat/st/common/stm32mp_dt.c [new file with mode: 0644]
plat/st/stm32mp1/bl2_io_storage.c [deleted file]
plat/st/stm32mp1/bl2_plat_setup.c
plat/st/stm32mp1/include/stm32mp1_dt.h [deleted file]
plat/st/stm32mp1/include/stm32mp1_private.h
plat/st/stm32mp1/platform.mk
plat/st/stm32mp1/sp_min/sp_min_setup.c
plat/st/stm32mp1/stm32mp1_common.c [deleted file]
plat/st/stm32mp1/stm32mp1_def.h
plat/st/stm32mp1/stm32mp1_dt.c [deleted file]
plat/st/stm32mp1/stm32mp1_gic.c
plat/st/stm32mp1/stm32mp1_pm.c
plat/st/stm32mp1/stm32mp1_private.c [new file with mode: 0644]
plat/st/stm32mp1/stm32mp1_security.c

index d217c4501b6f8ca8d0b041211726440aff959b77..5fee82cdf57b85472bea32978010ebee4ed1b8ae 100644 (file)
@@ -254,17 +254,17 @@ void set_gpio(uint32_t bank, uint32_t pin, uint32_t mode, uint32_t speed,
        VERBOSE("GPIO %u mode alternate high to 0x%x\n", bank,
                mmio_read_32(base + GPIO_AFRH_OFFSET));
 
-       stm32mp1_clk_disable((unsigned long)clock);
+       stm32mp1_clk_disable(clock);
 }
 
 void set_gpio_secure_cfg(uint32_t bank, uint32_t pin, bool secure)
 {
        uintptr_t base = stm32_get_gpio_bank_base(bank);
-       int clock = stm32_get_gpio_bank_clock(bank);
+       unsigned long clock = stm32_get_gpio_bank_clock(bank);
 
        assert(pin <= GPIO_PIN_MAX);
 
-       stm32mp1_clk_enable((unsigned long)clock);
+       stm32mp1_clk_enable(clock);
 
        if (secure) {
                mmio_setbits_32(base + GPIO_SECR_OFFSET, BIT(pin));
@@ -272,5 +272,5 @@ void set_gpio_secure_cfg(uint32_t bank, uint32_t pin, bool secure)
                mmio_clrbits_32(base + GPIO_SECR_OFFSET, BIT(pin));
        }
 
-       stm32mp1_clk_disable((unsigned long)clock);
+       stm32mp1_clk_disable(clock);
 }
diff --git a/plat/st/common/bl2_io_storage.c b/plat/st/common/bl2_io_storage.c
new file mode 100644 (file)
index 0000000..18342aa
--- /dev/null
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <string.h>
+
+#include <platform_def.h>
+
+#include <arch_helpers.h>
+#include <common/debug.h>
+#include <drivers/io/io_block.h>
+#include <drivers/io/io_driver.h>
+#include <drivers/io/io_dummy.h>
+#include <drivers/io/io_storage.h>
+#include <drivers/mmc.h>
+#include <drivers/partition/partition.h>
+#include <drivers/st/io_mmc.h>
+#include <drivers/st/io_stm32image.h>
+#include <drivers/st/stm32_sdmmc2.h>
+#include <drivers/st/stm32mp1_rcc.h>
+#include <lib/mmio.h>
+#include <lib/utils.h>
+#include <plat/common/platform.h>
+
+/* IO devices */
+static const io_dev_connector_t *dummy_dev_con;
+static uintptr_t dummy_dev_handle;
+static uintptr_t dummy_dev_spec;
+
+static uintptr_t image_dev_handle;
+
+static io_block_spec_t gpt_block_spec = {
+       .offset = 0,
+       .length = 34 * MMC_BLOCK_SIZE, /* Size of GPT table */
+};
+
+static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
+
+static const io_block_dev_spec_t mmc_block_dev_spec = {
+       /* It's used as temp buffer in block driver */
+       .buffer = {
+               .offset = (size_t)&block_buffer,
+               .length = MMC_BLOCK_SIZE,
+       },
+       .ops = {
+               .read = mmc_read_blocks,
+               .write = NULL,
+       },
+       .block_size = MMC_BLOCK_SIZE,
+};
+
+static uintptr_t storage_dev_handle;
+static const io_dev_connector_t *mmc_dev_con;
+
+static const io_block_spec_t bl32_block_spec = {
+       .offset = BL32_BASE,
+       .length = STM32MP1_BL32_SIZE
+};
+
+static const io_block_spec_t bl2_block_spec = {
+       .offset = BL2_BASE,
+       .length = STM32MP1_BL2_SIZE,
+};
+
+static const struct stm32image_part_info bl33_partition_spec = {
+       .name = BL33_IMAGE_NAME,
+       .binary_type = BL33_BINARY_TYPE,
+};
+
+enum {
+       IMG_IDX_BL33,
+       IMG_IDX_NUM
+};
+
+static struct stm32image_device_info stm32image_dev_info_spec = {
+       .lba_size = MMC_BLOCK_SIZE,
+       .part_info[IMG_IDX_BL33] = {
+               .name = BL33_IMAGE_NAME,
+               .binary_type = BL33_BINARY_TYPE,
+       },
+};
+
+static io_block_spec_t stm32image_block_spec = {
+       .offset = 0,
+       .length = 0,
+};
+
+static const io_dev_connector_t *stm32image_dev_con;
+
+static int open_dummy(const uintptr_t spec);
+static int open_image(const uintptr_t spec);
+static int open_storage(const uintptr_t spec);
+
+struct plat_io_policy {
+       uintptr_t *dev_handle;
+       uintptr_t image_spec;
+       int (*check)(const uintptr_t spec);
+};
+
+static const struct plat_io_policy policies[] = {
+       [BL2_IMAGE_ID] = {
+               .dev_handle = &dummy_dev_handle,
+               .image_spec = (uintptr_t)&bl2_block_spec,
+               .check = open_dummy
+       },
+       [BL32_IMAGE_ID] = {
+               .dev_handle = &dummy_dev_handle,
+               .image_spec = (uintptr_t)&bl32_block_spec,
+               .check = open_dummy
+       },
+       [BL33_IMAGE_ID] = {
+               .dev_handle = &image_dev_handle,
+               .image_spec = (uintptr_t)&bl33_partition_spec,
+               .check = open_image
+       },
+       [GPT_IMAGE_ID] = {
+               .dev_handle = &storage_dev_handle,
+               .image_spec = (uintptr_t)&gpt_block_spec,
+               .check = open_storage
+       },
+       [STM32_IMAGE_ID] = {
+               .dev_handle = &storage_dev_handle,
+               .image_spec = (uintptr_t)&stm32image_block_spec,
+               .check = open_storage
+       }
+};
+
+static int open_dummy(const uintptr_t spec)
+{
+       return io_dev_init(dummy_dev_handle, 0);
+}
+
+static int open_image(const uintptr_t spec)
+{
+       return io_dev_init(image_dev_handle, 0);
+}
+
+static int open_storage(const uintptr_t spec)
+{
+       return io_dev_init(storage_dev_handle, 0);
+}
+
+static void print_boot_device(boot_api_context_t *boot_context)
+{
+       switch (boot_context->boot_interface_selected) {
+       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
+               INFO("Using SDMMC\n");
+               break;
+       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
+               INFO("Using EMMC\n");
+               break;
+       default:
+               ERROR("Boot interface not found\n");
+               panic();
+               break;
+       }
+
+       if (boot_context->boot_interface_instance != 0U) {
+               INFO("  Instance %d\n", boot_context->boot_interface_instance);
+       }
+}
+
+void stm32mp1_io_setup(void)
+{
+       int io_result __unused;
+       uint8_t idx;
+       struct stm32image_part_info *part;
+       struct stm32_sdmmc2_params params;
+       struct mmc_device_info device_info;
+       uintptr_t mmc_default_instance;
+       const partition_entry_t *entry;
+       boot_api_context_t *boot_context =
+               (boot_api_context_t *)stm32mp1_get_boot_ctx_address();
+
+       print_boot_device(boot_context);
+
+       if ((boot_context->boot_partition_used_toboot == 1U) ||
+           (boot_context->boot_partition_used_toboot == 2U)) {
+               INFO("Boot used partition fsbl%d\n",
+                    boot_context->boot_partition_used_toboot);
+       }
+
+       io_result = register_io_dev_dummy(&dummy_dev_con);
+       assert(io_result == 0);
+
+       io_result = io_dev_open(dummy_dev_con, dummy_dev_spec,
+                               &dummy_dev_handle);
+       assert(io_result == 0);
+
+       switch (boot_context->boot_interface_selected) {
+       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
+       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
+               dmbsy();
+
+               memset(&params, 0, sizeof(struct stm32_sdmmc2_params));
+
+               if (boot_context->boot_interface_selected ==
+                   BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC) {
+                       device_info.mmc_dev_type = MMC_IS_EMMC;
+                       mmc_default_instance = STM32MP1_SDMMC2_BASE;
+               } else {
+                       device_info.mmc_dev_type = MMC_IS_SD;
+                       mmc_default_instance = STM32MP1_SDMMC1_BASE;
+               }
+
+               switch (boot_context->boot_interface_instance) {
+               case 1:
+                       params.reg_base = STM32MP1_SDMMC1_BASE;
+                       break;
+               case 2:
+                       params.reg_base = STM32MP1_SDMMC2_BASE;
+                       break;
+               case 3:
+                       params.reg_base = STM32MP1_SDMMC3_BASE;
+                       break;
+               default:
+                       WARN("SDMMC instance not found, using default\n");
+                       params.reg_base = mmc_default_instance;
+                       break;
+               }
+
+               params.device_info = &device_info;
+               if (stm32_sdmmc2_mmc_init(&params) != 0) {
+                       ERROR("SDMMC%u init failed\n",
+                             boot_context->boot_interface_instance);
+                       panic();
+               }
+
+               /* Open MMC as a block device to read GPT table */
+               io_result = register_io_dev_block(&mmc_dev_con);
+               if (io_result != 0) {
+                       panic();
+               }
+
+               io_result = io_dev_open(mmc_dev_con,
+                                       (uintptr_t)&mmc_block_dev_spec,
+                                       &storage_dev_handle);
+               assert(io_result == 0);
+
+               partition_init(GPT_IMAGE_ID);
+
+               io_result = io_dev_close(storage_dev_handle);
+               assert(io_result == 0);
+
+               stm32image_dev_info_spec.device_size =
+                       stm32_sdmmc2_mmc_get_device_size();
+
+               for (idx = 0U; idx < IMG_IDX_NUM; idx++) {
+                       part = &stm32image_dev_info_spec.part_info[idx];
+                       entry = get_partition_entry(part->name);
+                       if (entry == NULL) {
+                               ERROR("Partition %s not found\n",
+                                     part->name);
+                               panic();
+                       }
+
+                       part->part_offset = entry->start;
+                       part->bkp_offset = 0U;
+               }
+
+               /*
+                * Re-open MMC with io_mmc, for better perfs compared to
+                * io_block.
+                */
+               io_result = register_io_dev_mmc(&mmc_dev_con);
+               assert(io_result == 0);
+
+               io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle);
+               assert(io_result == 0);
+
+               io_result = register_io_dev_stm32image(&stm32image_dev_con);
+               assert(io_result == 0);
+
+               io_result = io_dev_open(stm32image_dev_con,
+                                       (uintptr_t)&stm32image_dev_info_spec,
+                                       &image_dev_handle);
+               assert(io_result == 0);
+               break;
+
+       default:
+               ERROR("Boot interface %d not supported\n",
+                     boot_context->boot_interface_selected);
+               break;
+       }
+}
+
+/*
+ * Return an IO device handle and specification which can be used to access
+ * an image. Use this to enforce platform load policy.
+ */
+int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
+                         uintptr_t *image_spec)
+{
+       int rc;
+       const struct plat_io_policy *policy;
+
+       assert(image_id < ARRAY_SIZE(policies));
+
+       policy = &policies[image_id];
+       rc = policy->check(policy->image_spec);
+       if (rc == 0) {
+               *image_spec = policy->image_spec;
+               *dev_handle = *(policy->dev_handle);
+       }
+
+       return rc;
+}
diff --git a/plat/st/common/include/stm32mp_common.h b/plat/st/common/include/stm32mp_common.h
new file mode 100644 (file)
index 0000000..11dd845
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018-2019, STMicroelectronics - All Rights Reserved
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef STM32MP_COMMON_H
+#define STM32MP_COMMON_H
+
+/* Functions to save and get boot context address given by ROM code */
+void stm32mp1_save_boot_ctx_address(uintptr_t address);
+uintptr_t stm32mp1_get_boot_ctx_address(void);
+
+/*
+ * Platform util functions for the GPIO driver
+ * @bank: Target GPIO bank ID as per DT bindings
+ *
+ * Platform shall implement these functions to provide to stm32_gpio
+ * driver the resource reference for a target GPIO bank. That are
+ * memory mapped interface base address, interface offset (see below)
+ * and clock identifier.
+ *
+ * stm32_get_gpio_bank_offset() returns a bank offset that is used to
+ * check DT configuration matches platform implementation of the banks
+ * description.
+ */
+uintptr_t stm32_get_gpio_bank_base(unsigned int bank);
+unsigned long stm32_get_gpio_bank_clock(unsigned int bank);
+uint32_t stm32_get_gpio_bank_offset(unsigned int bank);
+
+/* Initialise the IO layer and register platform IO devices */
+void stm32mp1_io_setup(void);
+
+#endif /* STM32MP_COMMON_H */
diff --git a/plat/st/common/include/stm32mp_dt.h b/plat/st/common/include/stm32mp_dt.h
new file mode 100644 (file)
index 0000000..56357db
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef STM32MP_DT_H
+#define STM32MP_DT_H
+
+#include <stdbool.h>
+
+#define DT_DISABLED            U(0)
+#define DT_NON_SECURE          U(1)
+#define DT_SECURE              U(2)
+#define DT_SHARED              (DT_NON_SECURE | DT_SECURE)
+
+struct dt_node_info {
+       uint32_t base;
+       int32_t clock;
+       int32_t reset;
+       uint32_t status;
+};
+
+/*******************************************************************************
+ * Function and variable prototypes
+ ******************************************************************************/
+int dt_open_and_check(void);
+int fdt_get_address(void **fdt_addr);
+bool fdt_check_node(int node);
+uint8_t fdt_get_status(int node);
+uint32_t fdt_read_uint32_default(int node, const char *prop_name,
+                                uint32_t dflt_value);
+int fdt_read_uint32_array(int node, const char *prop_name,
+                         uint32_t *array, uint32_t count);
+int dt_set_stdout_pinctrl(void);
+void dt_fill_device_info(struct dt_node_info *info, int node);
+int dt_get_node(struct dt_node_info *info, int offset, const char *compat);
+int dt_get_stdout_uart_info(struct dt_node_info *info);
+int dt_get_stdout_node_offset(void);
+uint32_t dt_get_ddr_size(void);
+const char *dt_get_board_model(void);
+
+#endif /* STM32MP_DT_H */
diff --git a/plat/st/common/stm32mp_common.c b/plat/st/common/stm32mp_common.c
new file mode 100644 (file)
index 0000000..7744aa0
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+
+#include <platform_def.h>
+
+#include <arch_helpers.h>
+#include <common/debug.h>
+#include <dt-bindings/clock/stm32mp1-clks.h>
+#include <plat/common/platform.h>
+
+uintptr_t plat_get_ns_image_entrypoint(void)
+{
+       return BL33_BASE;
+}
+
+unsigned int plat_get_syscnt_freq2(void)
+{
+       return read_cntfrq_el0();
+}
+
+static uintptr_t boot_ctx_address;
+
+void stm32mp1_save_boot_ctx_address(uintptr_t address)
+{
+       boot_ctx_address = address;
+}
+
+uintptr_t stm32mp1_get_boot_ctx_address(void)
+{
+       return boot_ctx_address;
+}
+
+uintptr_t stm32_get_gpio_bank_base(unsigned int bank)
+{
+       if (bank == GPIO_BANK_Z) {
+               return GPIOZ_BASE;
+       }
+
+       assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K);
+
+       return GPIOA_BASE + (bank * GPIO_BANK_OFFSET);
+}
+
+unsigned long stm32_get_gpio_bank_clock(unsigned int bank)
+{
+       if (bank == GPIO_BANK_Z) {
+               return GPIOZ;
+       }
+
+       assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K);
+
+       return GPIOA + (bank - GPIO_BANK_A);
+}
+
+uint32_t stm32_get_gpio_bank_offset(unsigned int bank)
+{
+       if (bank == GPIO_BANK_Z) {
+               return 0;
+       }
+
+       assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K);
+
+       return bank * GPIO_BANK_OFFSET;
+}
diff --git a/plat/st/common/stm32mp_dt.c b/plat/st/common/stm32mp_dt.c
new file mode 100644 (file)
index 0000000..2eaa9d9
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <errno.h>
+
+#include <libfdt.h>
+
+#include <platform_def.h>
+
+#include <common/debug.h>
+#include <drivers/st/stm32_gpio.h>
+#include <drivers/st/stm32mp1_clk.h>
+#include <drivers/st/stm32mp1_ddr.h>
+#include <drivers/st/stm32mp1_ram.h>
+
+#include <stm32mp_dt.h>
+
+static int fdt_checked;
+
+static void *fdt = (void *)(uintptr_t)STM32MP1_DTB_BASE;
+
+/*******************************************************************************
+ * This function checks device tree file with its header.
+ * Returns 0 on success and a negative FDT error code on failure.
+ ******************************************************************************/
+int dt_open_and_check(void)
+{
+       int ret = fdt_check_header(fdt);
+
+       if (ret == 0) {
+               fdt_checked = 1;
+       }
+
+       return ret;
+}
+
+/*******************************************************************************
+ * This function gets the address of the DT.
+ * If DT is OK, fdt_addr is filled with DT address.
+ * Returns 1 if success, 0 otherwise.
+ ******************************************************************************/
+int fdt_get_address(void **fdt_addr)
+{
+       if (fdt_checked == 1) {
+               *fdt_addr = fdt;
+       }
+
+       return fdt_checked;
+}
+
+/*******************************************************************************
+ * This function check the presence of a node (generic use of fdt library).
+ * Returns true if present, else return false.
+ ******************************************************************************/
+bool fdt_check_node(int node)
+{
+       int len;
+       const char *cchar;
+
+       cchar = fdt_get_name(fdt, node, &len);
+
+       return (cchar != NULL) && (len >= 0);
+}
+
+/*******************************************************************************
+ * This function return global node status (generic use of fdt library).
+ ******************************************************************************/
+uint8_t fdt_get_status(int node)
+{
+       uint8_t status = DT_DISABLED;
+       int len;
+       const char *cchar;
+
+       cchar = fdt_getprop(fdt, node, "status", &len);
+       if ((cchar == NULL) ||
+           (strncmp(cchar, "okay", (size_t)len) == 0)) {
+               status |= DT_NON_SECURE;
+       }
+
+       cchar = fdt_getprop(fdt, node, "secure-status", &len);
+       if (cchar == NULL) {
+               if (status == DT_NON_SECURE) {
+                       status |= DT_SECURE;
+               }
+       } else if (strncmp(cchar, "okay", (size_t)len) == 0) {
+               status |= DT_SECURE;
+       }
+
+       return status;
+}
+
+/*******************************************************************************
+ * This function reads a value of a node property (generic use of fdt
+ * library).
+ * Returns value if success, and a default value if property not found.
+ * Default value is passed as parameter.
+ ******************************************************************************/
+uint32_t fdt_read_uint32_default(int node, const char *prop_name,
+                                uint32_t dflt_value)
+{
+       const fdt32_t *cuint;
+       int lenp;
+
+       cuint = fdt_getprop(fdt, node, prop_name, &lenp);
+       if (cuint == NULL) {
+               return dflt_value;
+       }
+
+       return fdt32_to_cpu(*cuint);
+}
+
+/*******************************************************************************
+ * This function reads a series of parameters in a node property
+ * (generic use of fdt library).
+ * It reads the values inside the device tree, from property name and node.
+ * The number of parameters is also indicated as entry parameter.
+ * Returns 0 on success and a negative FDT error code on failure.
+ * If success, values are stored at the third parameter address.
+ ******************************************************************************/
+int fdt_read_uint32_array(int node, const char *prop_name, uint32_t *array,
+                         uint32_t count)
+{
+       const fdt32_t *cuint;
+       int len;
+       uint32_t i;
+
+       cuint = fdt_getprop(fdt, node, prop_name, &len);
+       if (cuint == NULL) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       if ((uint32_t)len != (count * sizeof(uint32_t))) {
+               return -FDT_ERR_BADLAYOUT;
+       }
+
+       for (i = 0; i < ((uint32_t)len / sizeof(uint32_t)); i++) {
+               *array = fdt32_to_cpu(*cuint);
+               array++;
+               cuint++;
+       }
+
+       return 0;
+}
+
+/*******************************************************************************
+ * This function gets the stdout pin configuration information from the DT.
+ * And then calls the sub-function to treat it and set GPIO registers.
+ * Returns 0 on success and a negative FDT error code on failure.
+ ******************************************************************************/
+int dt_set_stdout_pinctrl(void)
+{
+       int node;
+
+       node = dt_get_stdout_node_offset();
+       if (node < 0) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       return dt_set_pinctrl_config(node);
+}
+
+/*******************************************************************************
+ * This function fills the generic information from a given node.
+ ******************************************************************************/
+void dt_fill_device_info(struct dt_node_info *info, int node)
+{
+       const fdt32_t *cuint;
+
+       cuint = fdt_getprop(fdt, node, "reg", NULL);
+       if (cuint != NULL) {
+               info->base = fdt32_to_cpu(*cuint);
+       } else {
+               info->base = 0;
+       }
+
+       cuint = fdt_getprop(fdt, node, "clocks", NULL);
+       if (cuint != NULL) {
+               cuint++;
+               info->clock = (int)fdt32_to_cpu(*cuint);
+       } else {
+               info->clock = -1;
+       }
+
+       cuint = fdt_getprop(fdt, node, "resets", NULL);
+       if (cuint != NULL) {
+               cuint++;
+               info->reset = (int)fdt32_to_cpu(*cuint);
+       } else {
+               info->reset = -1;
+       }
+
+       info->status = fdt_get_status(node);
+}
+
+/*******************************************************************************
+ * This function retrieve the generic information from DT.
+ * Returns node on success and a negative FDT error code on failure.
+ ******************************************************************************/
+int dt_get_node(struct dt_node_info *info, int offset, const char *compat)
+{
+       int node;
+
+       node = fdt_node_offset_by_compatible(fdt, offset, compat);
+       if (node < 0) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       dt_fill_device_info(info, node);
+
+       return node;
+}
+
+/*******************************************************************************
+ * This function gets the UART instance info of stdout from the DT.
+ * Returns node on success and a negative FDT error code on failure.
+ ******************************************************************************/
+int dt_get_stdout_uart_info(struct dt_node_info *info)
+{
+       int node;
+
+       node = dt_get_stdout_node_offset();
+       if (node < 0) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       dt_fill_device_info(info, node);
+
+       return node;
+}
+
+/*******************************************************************************
+ * This function gets the stdout path node.
+ * It reads the value indicated inside the device tree.
+ * Returns node if success, and a negative value else.
+ ******************************************************************************/
+int dt_get_stdout_node_offset(void)
+{
+       int node;
+       const char *cchar;
+
+       node = fdt_path_offset(fdt, "/chosen");
+       if (node < 0) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       cchar = fdt_getprop(fdt, node, "stdout-path", NULL);
+       if (cchar == NULL) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       node = -FDT_ERR_NOTFOUND;
+       if (strchr(cchar, (int)':') != NULL) {
+               const char *name;
+               char *str = (char *)cchar;
+               int len = 0;
+
+               while (strncmp(":", str, 1)) {
+                       len++;
+                       str++;
+               }
+
+               name = fdt_get_alias_namelen(fdt, cchar, len);
+
+               if (name != NULL) {
+                       node = fdt_path_offset(fdt, name);
+               }
+       } else {
+               node = fdt_path_offset(fdt, cchar);
+       }
+
+       return node;
+}
+
+/*******************************************************************************
+ * This function gets DDR size information from the DT.
+ * Returns value in bytes on success, and 0 on failure.
+ ******************************************************************************/
+uint32_t dt_get_ddr_size(void)
+{
+       int node;
+
+       node = fdt_node_offset_by_compatible(fdt, -1, DT_DDR_COMPAT);
+       if (node < 0) {
+               INFO("%s: Cannot read DDR node in DT\n", __func__);
+               return 0;
+       }
+
+       return fdt_read_uint32_default(node, "st,mem-size", 0);
+}
+
+/*******************************************************************************
+ * This function retrieves board model from DT
+ * Returns string taken from model node, NULL otherwise
+ ******************************************************************************/
+const char *dt_get_board_model(void)
+{
+       int node = fdt_path_offset(fdt, "/");
+
+       if (node < 0) {
+               return NULL;
+       }
+
+       return (const char *)fdt_getprop(fdt, node, "model", NULL);
+}
diff --git a/plat/st/stm32mp1/bl2_io_storage.c b/plat/st/stm32mp1/bl2_io_storage.c
deleted file mode 100644 (file)
index 8ccbc24..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <assert.h>
-#include <string.h>
-
-#include <platform_def.h>
-
-#include <arch_helpers.h>
-#include <common/debug.h>
-#include <drivers/io/io_block.h>
-#include <drivers/io/io_driver.h>
-#include <drivers/io/io_dummy.h>
-#include <drivers/io/io_storage.h>
-#include <drivers/mmc.h>
-#include <drivers/partition/partition.h>
-#include <drivers/st/io_mmc.h>
-#include <drivers/st/io_stm32image.h>
-#include <drivers/st/stm32_sdmmc2.h>
-#include <drivers/st/stm32mp1_rcc.h>
-#include <lib/mmio.h>
-#include <lib/utils.h>
-#include <plat/common/platform.h>
-
-#include <boot_api.h>
-#include <stm32mp1_private.h>
-
-/* IO devices */
-static const io_dev_connector_t *dummy_dev_con;
-static uintptr_t dummy_dev_handle;
-static uintptr_t dummy_dev_spec;
-
-static uintptr_t image_dev_handle;
-
-static io_block_spec_t gpt_block_spec = {
-       .offset = 0,
-       .length = 34 * MMC_BLOCK_SIZE, /* Size of GPT table */
-};
-
-static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE);
-
-static const io_block_dev_spec_t mmc_block_dev_spec = {
-       /* It's used as temp buffer in block driver */
-       .buffer = {
-               .offset = (size_t)&block_buffer,
-               .length = MMC_BLOCK_SIZE,
-       },
-       .ops = {
-               .read = mmc_read_blocks,
-               .write = NULL,
-       },
-       .block_size = MMC_BLOCK_SIZE,
-};
-
-static uintptr_t storage_dev_handle;
-static const io_dev_connector_t *mmc_dev_con;
-
-static const io_block_spec_t bl32_block_spec = {
-       .offset = BL32_BASE,
-       .length = STM32MP1_BL32_SIZE
-};
-
-static const io_block_spec_t bl2_block_spec = {
-       .offset = BL2_BASE,
-       .length = STM32MP1_BL2_SIZE,
-};
-
-static const struct stm32image_part_info bl33_partition_spec = {
-       .name = BL33_IMAGE_NAME,
-       .binary_type = BL33_BINARY_TYPE,
-};
-
-enum {
-       IMG_IDX_BL33,
-       IMG_IDX_NUM
-};
-
-static struct stm32image_device_info stm32image_dev_info_spec = {
-       .lba_size = MMC_BLOCK_SIZE,
-       .part_info[IMG_IDX_BL33] = {
-               .name = BL33_IMAGE_NAME,
-               .binary_type = BL33_BINARY_TYPE,
-       },
-};
-
-static io_block_spec_t stm32image_block_spec = {
-       .offset = 0,
-       .length = 0,
-};
-
-static const io_dev_connector_t *stm32image_dev_con;
-
-static int open_dummy(const uintptr_t spec);
-static int open_image(const uintptr_t spec);
-static int open_storage(const uintptr_t spec);
-
-struct plat_io_policy {
-       uintptr_t *dev_handle;
-       uintptr_t image_spec;
-       int (*check)(const uintptr_t spec);
-};
-
-static const struct plat_io_policy policies[] = {
-       [BL2_IMAGE_ID] = {
-               .dev_handle = &dummy_dev_handle,
-               .image_spec = (uintptr_t)&bl2_block_spec,
-               .check = open_dummy
-       },
-       [BL32_IMAGE_ID] = {
-               .dev_handle = &dummy_dev_handle,
-               .image_spec = (uintptr_t)&bl32_block_spec,
-               .check = open_dummy
-       },
-       [BL33_IMAGE_ID] = {
-               .dev_handle = &image_dev_handle,
-               .image_spec = (uintptr_t)&bl33_partition_spec,
-               .check = open_image
-       },
-       [GPT_IMAGE_ID] = {
-               .dev_handle = &storage_dev_handle,
-               .image_spec = (uintptr_t)&gpt_block_spec,
-               .check = open_storage
-       },
-       [STM32_IMAGE_ID] = {
-               .dev_handle = &storage_dev_handle,
-               .image_spec = (uintptr_t)&stm32image_block_spec,
-               .check = open_storage
-       }
-};
-
-static int open_dummy(const uintptr_t spec)
-{
-       return io_dev_init(dummy_dev_handle, 0);
-}
-
-static int open_image(const uintptr_t spec)
-{
-       return io_dev_init(image_dev_handle, 0);
-}
-
-static int open_storage(const uintptr_t spec)
-{
-       return io_dev_init(storage_dev_handle, 0);
-}
-
-static void print_boot_device(boot_api_context_t *boot_context)
-{
-       switch (boot_context->boot_interface_selected) {
-       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
-               INFO("Using SDMMC\n");
-               break;
-       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
-               INFO("Using EMMC\n");
-               break;
-       default:
-               ERROR("Boot interface not found\n");
-               panic();
-               break;
-       }
-
-       if (boot_context->boot_interface_instance != 0U) {
-               INFO("  Instance %d\n", boot_context->boot_interface_instance);
-       }
-}
-
-void stm32mp1_io_setup(void)
-{
-       int io_result __unused;
-       uint8_t idx;
-       struct stm32image_part_info *part;
-       struct stm32_sdmmc2_params params;
-       struct mmc_device_info device_info;
-       uintptr_t mmc_default_instance;
-       const partition_entry_t *entry;
-       boot_api_context_t *boot_context =
-               (boot_api_context_t *)stm32mp1_get_boot_ctx_address();
-
-       print_boot_device(boot_context);
-
-       if ((boot_context->boot_partition_used_toboot == 1U) ||
-           (boot_context->boot_partition_used_toboot == 2U)) {
-               INFO("Boot used partition fsbl%d\n",
-                    boot_context->boot_partition_used_toboot);
-       }
-
-       io_result = register_io_dev_dummy(&dummy_dev_con);
-       assert(io_result == 0);
-
-       io_result = io_dev_open(dummy_dev_con, dummy_dev_spec,
-                               &dummy_dev_handle);
-       assert(io_result == 0);
-
-       switch (boot_context->boot_interface_selected) {
-       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD:
-       case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC:
-               dmbsy();
-
-               memset(&params, 0, sizeof(struct stm32_sdmmc2_params));
-
-               if (boot_context->boot_interface_selected ==
-                   BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC) {
-                       device_info.mmc_dev_type = MMC_IS_EMMC;
-                       mmc_default_instance = STM32MP1_SDMMC2_BASE;
-               } else {
-                       device_info.mmc_dev_type = MMC_IS_SD;
-                       mmc_default_instance = STM32MP1_SDMMC1_BASE;
-               }
-
-               switch (boot_context->boot_interface_instance) {
-               case 1:
-                       params.reg_base = STM32MP1_SDMMC1_BASE;
-                       break;
-               case 2:
-                       params.reg_base = STM32MP1_SDMMC2_BASE;
-                       break;
-               case 3:
-                       params.reg_base = STM32MP1_SDMMC3_BASE;
-                       break;
-               default:
-                       WARN("SDMMC instance not found, using default\n");
-                       params.reg_base = mmc_default_instance;
-                       break;
-               }
-
-               params.device_info = &device_info;
-               if (stm32_sdmmc2_mmc_init(&params) != 0) {
-                       ERROR("SDMMC%u init failed\n",
-                             boot_context->boot_interface_instance);
-                       panic();
-               }
-
-               /* Open MMC as a block device to read GPT table */
-               io_result = register_io_dev_block(&mmc_dev_con);
-               if (io_result != 0) {
-                       panic();
-               }
-
-               io_result = io_dev_open(mmc_dev_con,
-                                       (uintptr_t)&mmc_block_dev_spec,
-                                       &storage_dev_handle);
-               assert(io_result == 0);
-
-               partition_init(GPT_IMAGE_ID);
-
-               io_result = io_dev_close(storage_dev_handle);
-               assert(io_result == 0);
-
-               stm32image_dev_info_spec.device_size =
-                       stm32_sdmmc2_mmc_get_device_size();
-
-               for (idx = 0U; idx < IMG_IDX_NUM; idx++) {
-                       part = &stm32image_dev_info_spec.part_info[idx];
-                       entry = get_partition_entry(part->name);
-                       if (entry == NULL) {
-                               ERROR("Partition %s not found\n",
-                                     part->name);
-                               panic();
-                       }
-
-                       part->part_offset = entry->start;
-                       part->bkp_offset = 0U;
-               }
-
-               /*
-                * Re-open MMC with io_mmc, for better perfs compared to
-                * io_block.
-                */
-               io_result = register_io_dev_mmc(&mmc_dev_con);
-               assert(io_result == 0);
-
-               io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle);
-               assert(io_result == 0);
-
-               io_result = register_io_dev_stm32image(&stm32image_dev_con);
-               assert(io_result == 0);
-
-               io_result = io_dev_open(stm32image_dev_con,
-                                       (uintptr_t)&stm32image_dev_info_spec,
-                                       &image_dev_handle);
-               assert(io_result == 0);
-               break;
-
-       default:
-               ERROR("Boot interface %d not supported\n",
-                     boot_context->boot_interface_selected);
-               break;
-       }
-}
-
-/*
- * Return an IO device handle and specification which can be used to access
- * an image. Use this to enforce platform load policy.
- */
-int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
-                         uintptr_t *image_spec)
-{
-       int rc;
-       const struct plat_io_policy *policy;
-
-       assert(image_id < ARRAY_SIZE(policies));
-
-       policy = &policies[image_id];
-       rc = policy->check(policy->image_spec);
-       if (rc == 0) {
-               *image_spec = policy->image_spec;
-               *dev_handle = *(policy->dev_handle);
-       }
-
-       return rc;
-}
index a1ffd5a9db5a05d572add84f5251e314dbb6887a..5525efd237b125b0cff9a896147d6e7b2cfb937c 100644 (file)
 #include <lib/xlat_tables/xlat_tables_v2.h>
 #include <plat/common/platform.h>
 
-#include <boot_api.h>
 #include <stm32mp1_context.h>
-#include <stm32mp1_dt.h>
-#include <stm32mp1_private.h>
 
 static struct console_stm32 console;
 
diff --git a/plat/st/stm32mp1/include/stm32mp1_dt.h b/plat/st/stm32mp1/include/stm32mp1_dt.h
deleted file mode 100644 (file)
index d5640c1..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef STM32MP1_DT_H
-#define STM32MP1_DT_H
-
-#include <stdbool.h>
-
-#define DT_DISABLED            U(0)
-#define DT_NON_SECURE          U(1)
-#define DT_SECURE              U(2)
-#define DT_SHARED              (DT_NON_SECURE | DT_SECURE)
-
-struct dt_node_info {
-       uint32_t base;
-       int32_t clock;
-       int32_t reset;
-       uint32_t status;
-};
-
-/*******************************************************************************
- * Function and variable prototypes
- ******************************************************************************/
-int dt_open_and_check(void);
-int fdt_get_address(void **fdt_addr);
-bool fdt_check_node(int node);
-uint32_t fdt_get_status(int node);
-uint32_t fdt_read_uint32_default(int node, const char *prop_name,
-                                uint32_t dflt_value);
-int fdt_read_uint32_array(int node, const char *prop_name,
-                         uint32_t *array, uint32_t count);
-int dt_set_stdout_pinctrl(void);
-void dt_fill_device_info(struct dt_node_info *info, int node);
-int dt_get_node(struct dt_node_info *info, int offset, const char *compat);
-int dt_get_stdout_uart_info(struct dt_node_info *info);
-int dt_get_stdout_node_offset(void);
-uint32_t dt_get_ddr_size(void);
-const char *dt_get_board_model(void);
-
-#endif /* STM32MP1_DT_H */
index 04c9a9ad5fb566230eb23d1ca1bf8d97d768b1af..49a2bdf415d0eb1c715ac2d698c44ad75908271f 100644 (file)
@@ -9,20 +9,12 @@
 
 #include <stdint.h>
 
-void stm32mp1_io_setup(void);
 void configure_mmu(void);
 
 void stm32mp1_arch_security_setup(void);
 void stm32mp1_security_setup(void);
 
-void stm32mp1_save_boot_ctx_address(uintptr_t address);
-uintptr_t stm32mp1_get_boot_ctx_address(void);
-
 void stm32mp1_gic_pcpu_init(void);
 void stm32mp1_gic_init(void);
 
-uintptr_t stm32_get_gpio_bank_base(unsigned int bank);
-unsigned long stm32_get_gpio_bank_clock(unsigned int bank);
-uint32_t stm32_get_gpio_bank_offset(unsigned int bank);
-
 #endif /* STM32MP1_PRIVATE_H */
index 4288f23d9140ee574ef02ac99ce0b37375a82b09..1c5f6273e2f046e7c349830c1dc9953a420aea16 100644 (file)
@@ -21,7 +21,8 @@ $(eval $(call add_define,STM32_TF_A_COPIES))
 PLAT_PARTITION_MAX_ENTRIES     :=      $(shell echo $$(($(STM32_TF_A_COPIES) + 1)))
 $(eval $(call add_define,PLAT_PARTITION_MAX_ENTRIES))
 
-PLAT_INCLUDES          :=      -Iplat/st/stm32mp1/include/
+PLAT_INCLUDES          :=      -Iplat/st/common/include/
+PLAT_INCLUDES          +=      -Iplat/st/stm32mp1/include/
 
 # Device tree
 DTB_FILE_NAME          ?=      stm32mp157c-ev1.dtb
@@ -30,7 +31,8 @@ DTC_FLAGS             +=      -Wno-unit_address_vs_reg
 
 include lib/libfdt/libfdt.mk
 
-PLAT_BL_COMMON_SOURCES :=      plat/st/stm32mp1/stm32mp1_common.c
+PLAT_BL_COMMON_SOURCES :=      plat/st/common/stm32mp_common.c                         \
+                               plat/st/stm32mp1/stm32mp1_private.c
 
 PLAT_BL_COMMON_SOURCES +=      drivers/st/uart/aarch32/stm32_console.S
 
@@ -56,8 +58,8 @@ PLAT_BL_COMMON_SOURCES        +=      ${LIBFDT_SRCS}                                          \
                                drivers/st/pmic/stm32mp_pmic.c                          \
                                drivers/st/pmic/stpmic1.c                               \
                                drivers/st/reset/stm32mp1_reset.c                       \
+                               plat/st/common/stm32mp_dt.c                             \
                                plat/st/stm32mp1/stm32mp1_context.c                     \
-                               plat/st/stm32mp1/stm32mp1_dt.c                          \
                                plat/st/stm32mp1/stm32mp1_helper.S                      \
                                plat/st/stm32mp1/stm32mp1_security.c
 
@@ -65,7 +67,7 @@ BL2_SOURCES           +=      drivers/io/io_block.c                                   \
                                drivers/io/io_dummy.c                                   \
                                drivers/io/io_storage.c                                 \
                                drivers/st/io/io_stm32image.c                           \
-                               plat/st/stm32mp1/bl2_io_storage.c                       \
+                               plat/st/common/bl2_io_storage.c                         \
                                plat/st/stm32mp1/bl2_plat_setup.c
 
 BL2_SOURCES            +=      drivers/mmc/mmc.c                                       \
index 0d76fb7e3ea316f5e2296ccbfb426b10542858ab..f747ee71170efd40ce28d660cae72bbce179d023 100644 (file)
@@ -27,8 +27,6 @@
 #include <plat/common/platform.h>
 
 #include <platform_sp_min.h>
-#include <stm32mp1_dt.h>
-#include <stm32mp1_private.h>
 
 /******************************************************************************
  * Placeholder variables for copying the arguments that have been passed to
diff --git a/plat/st/stm32mp1/stm32mp1_common.c b/plat/st/stm32mp1/stm32mp1_common.c
deleted file mode 100644 (file)
index cd93d2e..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <assert.h>
-
-#include <platform_def.h>
-
-#include <arch_helpers.h>
-#include <common/bl_common.h>
-#include <common/debug.h>
-#include <drivers/arm/gicv2.h>
-#include <dt-bindings/clock/stm32mp1-clks.h>
-#include <lib/mmio.h>
-#include <lib/xlat_tables/xlat_tables_v2.h>
-#include <plat/common/platform.h>
-
-#include <stm32mp1_private.h>
-
-#define MAP_SRAM       MAP_REGION_FLAT(STM32MP1_SRAM_BASE, \
-                                       STM32MP1_SRAM_SIZE, \
-                                       MT_MEMORY | \
-                                       MT_RW | \
-                                       MT_SECURE | \
-                                       MT_EXECUTE_NEVER)
-
-#define MAP_DEVICE1    MAP_REGION_FLAT(STM32MP1_DEVICE1_BASE, \
-                                       STM32MP1_DEVICE1_SIZE, \
-                                       MT_DEVICE | \
-                                       MT_RW | \
-                                       MT_SECURE | \
-                                       MT_EXECUTE_NEVER)
-
-#define MAP_DEVICE2    MAP_REGION_FLAT(STM32MP1_DEVICE2_BASE, \
-                                       STM32MP1_DEVICE2_SIZE, \
-                                       MT_DEVICE | \
-                                       MT_RW | \
-                                       MT_SECURE | \
-                                       MT_EXECUTE_NEVER)
-
-#if defined(IMAGE_BL2)
-static const mmap_region_t stm32mp1_mmap[] = {
-       MAP_SRAM,
-       MAP_DEVICE1,
-       MAP_DEVICE2,
-       {0}
-};
-#endif
-#if defined(IMAGE_BL32)
-static const mmap_region_t stm32mp1_mmap[] = {
-       MAP_SRAM,
-       MAP_DEVICE1,
-       MAP_DEVICE2,
-       {0}
-};
-#endif
-
-void configure_mmu(void)
-{
-       mmap_add(stm32mp1_mmap);
-       init_xlat_tables();
-
-       enable_mmu_svc_mon(0);
-}
-
-uintptr_t plat_get_ns_image_entrypoint(void)
-{
-       return BL33_BASE;
-}
-
-unsigned int plat_get_syscnt_freq2(void)
-{
-       return read_cntfrq_el0();
-}
-
-/* Functions to save and get boot context address given by ROM code */
-static uintptr_t boot_ctx_address;
-
-void stm32mp1_save_boot_ctx_address(uintptr_t address)
-{
-       boot_ctx_address = address;
-}
-
-uintptr_t stm32mp1_get_boot_ctx_address(void)
-{
-       return boot_ctx_address;
-}
-
-uintptr_t stm32_get_gpio_bank_base(unsigned int bank)
-{
-       switch (bank) {
-       case GPIO_BANK_A ... GPIO_BANK_K:
-               return GPIOA_BASE + (bank * GPIO_BANK_OFFSET);
-       case GPIO_BANK_Z:
-               return GPIOZ_BASE;
-       default:
-               panic();
-       }
-}
-
-/* Return clock ID on success, negative value on error */
-unsigned long stm32_get_gpio_bank_clock(unsigned int bank)
-{
-       switch (bank) {
-       case GPIO_BANK_A ... GPIO_BANK_K:
-               return GPIOA + (bank - GPIO_BANK_A);
-       case GPIO_BANK_Z:
-               return GPIOZ;
-       default:
-               panic();
-       }
-}
-
-uint32_t stm32_get_gpio_bank_offset(unsigned int bank)
-{
-       if (bank == GPIO_BANK_Z) {
-               return 0;
-       } else {
-               return bank * GPIO_BANK_OFFSET;
-       }
-}
index 8cd5aeb26c6c368089671d58601b7a5091707aaf..d12a93ffb86aadc13e8a5cd80ec0e84acfd9454d 100644 (file)
@@ -13,7 +13,8 @@
 
 #ifndef __ASSEMBLY__
 #include <boot_api.h>
-#include <stm32mp1_dt.h>
+#include <stm32mp_common.h>
+#include <stm32mp_dt.h>
 #include <stm32mp1_private.h>
 #endif
 
diff --git a/plat/st/stm32mp1/stm32mp1_dt.c b/plat/st/stm32mp1/stm32mp1_dt.c
deleted file mode 100644 (file)
index 8493b87..0000000
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <assert.h>
-#include <errno.h>
-
-#include <libfdt.h>
-
-#include <platform_def.h>
-
-#include <common/debug.h>
-#include <drivers/st/stm32_gpio.h>
-#include <drivers/st/stm32mp1_clk.h>
-#include <drivers/st/stm32mp1_clkfunc.h>
-#include <drivers/st/stm32mp1_ddr.h>
-#include <drivers/st/stm32mp1_ram.h>
-
-static int fdt_checked;
-
-static void *fdt = (void *)(uintptr_t)STM32MP1_DTB_BASE;
-
-/*******************************************************************************
- * This function checks device tree file with its header.
- * Returns 0 on success and a negative FDT error code on failure.
- ******************************************************************************/
-int dt_open_and_check(void)
-{
-       int ret = fdt_check_header(fdt);
-
-       if (ret == 0) {
-               fdt_checked = 1;
-       }
-
-       return ret;
-}
-
-/*******************************************************************************
- * This function gets the address of the DT.
- * If DT is OK, fdt_addr is filled with DT address.
- * Returns 1 if success, 0 otherwise.
- ******************************************************************************/
-int fdt_get_address(void **fdt_addr)
-{
-       if (fdt_checked == 1) {
-               *fdt_addr = fdt;
-       }
-
-       return fdt_checked;
-}
-
-/*******************************************************************************
- * This function check the presence of a node (generic use of fdt library).
- * Returns true if present, else return false.
- ******************************************************************************/
-bool fdt_check_node(int node)
-{
-       int len;
-       const char *cchar;
-
-       cchar = fdt_get_name(fdt, node, &len);
-
-       return (cchar != NULL) && (len >= 0);
-}
-
-/*******************************************************************************
- * This function return global node status (generic use of fdt library).
- ******************************************************************************/
-uint32_t fdt_get_status(int node)
-{
-       uint32_t status = DT_DISABLED;
-       int len;
-       const char *cchar;
-
-       cchar = fdt_getprop(fdt, node, "status", &len);
-       if ((cchar == NULL) ||
-           (strncmp(cchar, "okay", (size_t)len) == 0)) {
-               status |= DT_NON_SECURE;
-       }
-
-       cchar = fdt_getprop(fdt, node, "secure-status", &len);
-       if (cchar == NULL) {
-               if (status == DT_NON_SECURE) {
-                       status |= DT_SECURE;
-               }
-       } else if (strncmp(cchar, "okay", (size_t)len) == 0) {
-               status |= DT_SECURE;
-       }
-
-       return status;
-}
-
-/*******************************************************************************
- * This function reads a value of a node property (generic use of fdt
- * library).
- * Returns value if success, and a default value if property not found.
- * Default value is passed as parameter.
- ******************************************************************************/
-uint32_t fdt_read_uint32_default(int node, const char *prop_name,
-                                uint32_t dflt_value)
-{
-       const fdt32_t *cuint;
-       int lenp;
-
-       cuint = fdt_getprop(fdt, node, prop_name, &lenp);
-       if (cuint == NULL) {
-               return dflt_value;
-       }
-
-       return fdt32_to_cpu(*cuint);
-}
-
-/*******************************************************************************
- * This function reads a series of parameters in a node property
- * (generic use of fdt library).
- * It reads the values inside the device tree, from property name and node.
- * The number of parameters is also indicated as entry parameter.
- * Returns 0 on success and a negative FDT error code on failure.
- * If success, values are stored at the third parameter address.
- ******************************************************************************/
-int fdt_read_uint32_array(int node, const char *prop_name, uint32_t *array,
-                         uint32_t count)
-{
-       const fdt32_t *cuint;
-       int len;
-       uint32_t i;
-
-       cuint = fdt_getprop(fdt, node, prop_name, &len);
-       if (cuint == NULL) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       if ((uint32_t)len != (count * sizeof(uint32_t))) {
-               return -FDT_ERR_BADLAYOUT;
-       }
-
-       for (i = 0; i < ((uint32_t)len / sizeof(uint32_t)); i++) {
-               *array = fdt32_to_cpu(*cuint);
-               array++;
-               cuint++;
-       }
-
-       return 0;
-}
-
-/*******************************************************************************
- * This function gets the stdout pin configuration information from the DT.
- * And then calls the sub-function to treat it and set GPIO registers.
- * Returns 0 on success and a negative FDT error code on failure.
- ******************************************************************************/
-int dt_set_stdout_pinctrl(void)
-{
-       int node;
-
-       node = dt_get_stdout_node_offset();
-       if (node < 0) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       return dt_set_pinctrl_config(node);
-}
-
-/*******************************************************************************
- * This function fills the generic information from a given node.
- ******************************************************************************/
-void dt_fill_device_info(struct dt_node_info *info, int node)
-{
-       const fdt32_t *cuint;
-
-       cuint = fdt_getprop(fdt, node, "reg", NULL);
-       if (cuint != NULL) {
-               info->base = fdt32_to_cpu(*cuint);
-       } else {
-               info->base = 0;
-       }
-
-       cuint = fdt_getprop(fdt, node, "clocks", NULL);
-       if (cuint != NULL) {
-               cuint++;
-               info->clock = (int)fdt32_to_cpu(*cuint);
-       } else {
-               info->clock = -1;
-       }
-
-       cuint = fdt_getprop(fdt, node, "resets", NULL);
-       if (cuint != NULL) {
-               cuint++;
-               info->reset = (int)fdt32_to_cpu(*cuint);
-       } else {
-               info->reset = -1;
-       }
-
-       info->status = fdt_get_status(node);
-}
-
-/*******************************************************************************
- * This function retrieve the generic information from DT.
- * Returns node on success and a negative FDT error code on failure.
- ******************************************************************************/
-int dt_get_node(struct dt_node_info *info, int offset, const char *compat)
-{
-       int node;
-
-       node = fdt_node_offset_by_compatible(fdt, offset, compat);
-       if (node < 0) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       dt_fill_device_info(info, node);
-
-       return node;
-}
-
-/*******************************************************************************
- * This function gets the UART instance info of stdout from the DT.
- * Returns node on success and a negative FDT error code on failure.
- ******************************************************************************/
-int dt_get_stdout_uart_info(struct dt_node_info *info)
-{
-       int node;
-
-       node = dt_get_stdout_node_offset();
-       if (node < 0) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       dt_fill_device_info(info, node);
-
-       return node;
-}
-
-/*******************************************************************************
- * This function gets the stdout path node.
- * It reads the value indicated inside the device tree.
- * Returns node if success, and a negative value else.
- ******************************************************************************/
-int dt_get_stdout_node_offset(void)
-{
-       int node;
-       const char *cchar;
-
-       node = fdt_path_offset(fdt, "/chosen");
-       if (node < 0) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       cchar = fdt_getprop(fdt, node, "stdout-path", NULL);
-       if (cchar == NULL) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       node = -FDT_ERR_NOTFOUND;
-       if (strchr(cchar, (int)':') != NULL) {
-               const char *name;
-               char *str = (char *)cchar;
-               int len = 0;
-
-               while (strncmp(":", str, 1)) {
-                       len++;
-                       str++;
-               }
-
-               name = fdt_get_alias_namelen(fdt, cchar, len);
-
-               if (name != NULL) {
-                       node = fdt_path_offset(fdt, name);
-               }
-       } else {
-               node = fdt_path_offset(fdt, cchar);
-       }
-
-       return node;
-}
-
-/*******************************************************************************
- * This function gets DDR size information from the DT.
- * Returns value in bytes on success, and 0 on failure.
- ******************************************************************************/
-uint32_t dt_get_ddr_size(void)
-{
-       int node;
-
-       node = fdt_node_offset_by_compatible(fdt, -1, DT_DDR_COMPAT);
-       if (node < 0) {
-               INFO("%s: Cannot read DDR node in DT\n", __func__);
-               return 0;
-       }
-
-       return fdt_read_uint32_default(node, "st,mem-size", 0);
-}
-
-/*******************************************************************************
- * This function retrieves board model from DT
- * Returns string taken from model node, NULL otherwise
- ******************************************************************************/
-const char *dt_get_board_model(void)
-{
-       int node = fdt_path_offset(fdt, "/");
-
-       if (node < 0) {
-               return NULL;
-       }
-
-       return (const char *)fdt_getprop(fdt, node, "model", NULL);
-}
index becb925c2373ec3802797e57589ced91bb15620b..851a9cf0c4398288c343b0cc917fb55eacc44082 100644 (file)
@@ -15,9 +15,6 @@
 #include <lib/utils.h>
 #include <plat/common/platform.h>
 
-#include <stm32mp1_dt.h>
-#include <stm32mp1_private.h>
-
 struct stm32_gic_instance {
        uint32_t cells;
        uint32_t phandle_node;
index c0e9c4eb8c5e133f158ccbb4d4740cff99621c03..20f66e98be04e1025e5b84c95200b435c92e10a4 100644 (file)
@@ -20,9 +20,6 @@
 #include <lib/psci/psci.h>
 #include <plat/common/platform.h>
 
-#include <boot_api.h>
-#include <stm32mp1_private.h>
-
 static uintptr_t stm32_sec_entrypoint;
 static uint32_t cntfrq_core0;
 
diff --git a/plat/st/stm32mp1/stm32mp1_private.c b/plat/st/stm32mp1/stm32mp1_private.c
new file mode 100644 (file)
index 0000000..f3beb59
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <platform_def.h>
+
+#include <lib/xlat_tables/xlat_tables_v2.h>
+
+#define MAP_SRAM       MAP_REGION_FLAT(STM32MP1_SRAM_BASE, \
+                                       STM32MP1_SRAM_SIZE, \
+                                       MT_MEMORY | \
+                                       MT_RW | \
+                                       MT_SECURE | \
+                                       MT_EXECUTE_NEVER)
+
+#define MAP_DEVICE1    MAP_REGION_FLAT(STM32MP1_DEVICE1_BASE, \
+                                       STM32MP1_DEVICE1_SIZE, \
+                                       MT_DEVICE | \
+                                       MT_RW | \
+                                       MT_SECURE | \
+                                       MT_EXECUTE_NEVER)
+
+#define MAP_DEVICE2    MAP_REGION_FLAT(STM32MP1_DEVICE2_BASE, \
+                                       STM32MP1_DEVICE2_SIZE, \
+                                       MT_DEVICE | \
+                                       MT_RW | \
+                                       MT_SECURE | \
+                                       MT_EXECUTE_NEVER)
+
+#if defined(IMAGE_BL2)
+static const mmap_region_t stm32mp1_mmap[] = {
+       MAP_SRAM,
+       MAP_DEVICE1,
+       MAP_DEVICE2,
+       {0}
+};
+#endif
+#if defined(IMAGE_BL32)
+static const mmap_region_t stm32mp1_mmap[] = {
+       MAP_SRAM,
+       MAP_DEVICE1,
+       MAP_DEVICE2,
+       {0}
+};
+#endif
+
+void configure_mmu(void)
+{
+       mmap_add(stm32mp1_mmap);
+       init_xlat_tables();
+
+       enable_mmu_svc_mon(0);
+}
index cfdbf31852bd7c72e01dc6d48bdbc52d77ac2980..99719e42fbb93b90f045a03c3a916ea3d2683dd1 100644 (file)
@@ -15,9 +15,6 @@
 #include <dt-bindings/clock/stm32mp1-clks.h>
 #include <lib/mmio.h>
 
-#include <stm32mp1_dt.h>
-#include <stm32mp1_private.h>
-
 /*******************************************************************************
  * Initialize the TrustZone Controller. Configure Region 0 with Secure RW access
  * and allow Non-Secure masters full access.