Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 7 | #include <arch_helpers.h> |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 8 | #include <debug.h> |
| 9 | #include <desc_image_load.h> |
| 10 | #include <libfdt.h> |
| 11 | #include <platform.h> |
| 12 | |
| 13 | /******************************************************************************* |
| 14 | * This function inserts Platform information via device tree nodes as, |
| 15 | * system-id { |
| 16 | * platform-id = <0>; |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 17 | * config-id = <0>; |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 18 | * } |
| 19 | ******************************************************************************/ |
| 20 | static int plat_sgi_append_config_node(void) |
| 21 | { |
| 22 | bl_mem_params_node_t *mem_params; |
| 23 | void *fdt; |
| 24 | int nodeoffset, err; |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 25 | unsigned int platid = 0, platcfg = 0; |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 26 | char *platform_name; |
| 27 | |
| 28 | mem_params = get_bl_mem_params_node(HW_CONFIG_ID); |
| 29 | if (mem_params == NULL) { |
| 30 | ERROR("HW CONFIG base address is NULL"); |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | fdt = (void *)(mem_params->image_info.image_base); |
| 35 | |
| 36 | /* Check the validity of the fdt */ |
| 37 | if (fdt_check_header(fdt) != 0) { |
| 38 | ERROR("Invalid HW_CONFIG DTB passed\n"); |
| 39 | return -1; |
| 40 | } |
| 41 | |
| 42 | platform_name = (char *)fdt_getprop(fdt, 0, "compatible", NULL); |
| 43 | |
John Tsichritzis | 049db96 | 2018-08-16 14:37:40 +0100 | [diff] [blame] | 44 | if (platform_name == NULL) { |
| 45 | ERROR("Invalid HW_CONFIG DTB passed\n"); |
| 46 | return -1; |
| 47 | } |
| 48 | |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 49 | if (strcmp(platform_name, "arm,sgi575") == 0) { |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 50 | platid = mmio_read_32(SSC_VERSION) & SSC_VERSION_PART_NUM_MASK; |
| 51 | platcfg = (mmio_read_32(SSC_VERSION) >> SSC_VERSION_CONFIG_SHIFT) |
| 52 | & SSC_VERSION_CONFIG_MASK; |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 53 | } else { |
John Tsichritzis | 049db96 | 2018-08-16 14:37:40 +0100 | [diff] [blame] | 54 | WARN("Invalid platform\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 55 | return -1; |
| 56 | } |
| 57 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 58 | nodeoffset = fdt_subnode_offset(fdt, 0, "system-id"); |
| 59 | if (nodeoffset < 0) { |
| 60 | ERROR("Failed to get system-id node offset\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 61 | return -1; |
| 62 | } |
| 63 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 64 | err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid); |
| 65 | if (err < 0) { |
| 66 | ERROR("Failed to set platform-id\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 67 | return -1; |
| 68 | } |
| 69 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 70 | err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 71 | if (err < 0) { |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 72 | ERROR("Failed to set config-id\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 73 | return -1; |
| 74 | } |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 75 | |
| 76 | flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size); |
| 77 | |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | /******************************************************************************* |
| 82 | * This function returns the list of executable images. |
| 83 | ******************************************************************************/ |
| 84 | bl_params_t *plat_get_next_bl_params(void) |
| 85 | { |
| 86 | int ret; |
| 87 | bl_params_t *next_bl_params; |
| 88 | |
| 89 | ret = plat_sgi_append_config_node(); |
| 90 | if (ret != 0) |
| 91 | panic(); |
| 92 | |
| 93 | next_bl_params = get_next_bl_params_from_mem_params_desc(); |
| 94 | populate_next_bl_params_config(next_bl_params); |
| 95 | |
| 96 | return next_bl_params; |
| 97 | } |