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 | c8ef045 | 2018-10-04 16:32:03 +0530 | [diff] [blame] | 53 | } else if (strcmp(platform_name, "arm,sgi-clark") == 0) { |
| 54 | platid = mmio_read_32(SID_REG_BASE + SID_SYSTEM_ID_OFFSET) |
| 55 | & SID_SYSTEM_ID_PART_NUM_MASK; |
| 56 | platcfg = mmio_read_32(SID_REG_BASE + SID_SYSTEM_CFG_OFFSET); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 57 | } else { |
John Tsichritzis | 049db96 | 2018-08-16 14:37:40 +0100 | [diff] [blame] | 58 | WARN("Invalid platform\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 59 | return -1; |
| 60 | } |
| 61 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 62 | nodeoffset = fdt_subnode_offset(fdt, 0, "system-id"); |
| 63 | if (nodeoffset < 0) { |
| 64 | ERROR("Failed to get system-id node offset\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 65 | return -1; |
| 66 | } |
| 67 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 68 | err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid); |
| 69 | if (err < 0) { |
| 70 | ERROR("Failed to set platform-id\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 71 | return -1; |
| 72 | } |
| 73 | |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 74 | err = fdt_setprop_u32(fdt, nodeoffset, "config-id", platcfg); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 75 | if (err < 0) { |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 76 | ERROR("Failed to set config-id\n"); |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 77 | return -1; |
| 78 | } |
Chandni Cherukuri | 33fcfee | 2018-08-17 11:23:46 +0530 | [diff] [blame] | 79 | |
| 80 | flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size); |
| 81 | |
Chandni Cherukuri | 771d644 | 2018-05-10 12:03:50 +0530 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | /******************************************************************************* |
| 86 | * This function returns the list of executable images. |
| 87 | ******************************************************************************/ |
| 88 | bl_params_t *plat_get_next_bl_params(void) |
| 89 | { |
| 90 | int ret; |
| 91 | bl_params_t *next_bl_params; |
| 92 | |
| 93 | ret = plat_sgi_append_config_node(); |
| 94 | if (ret != 0) |
| 95 | panic(); |
| 96 | |
| 97 | next_bl_params = get_next_bl_params_from_mem_params_desc(); |
| 98 | populate_next_bl_params_config(next_bl_params); |
| 99 | |
| 100 | return next_bl_params; |
| 101 | } |