1 /** @file
2 * Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
3 * SPDX-License-Identifier : Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 **/
17
18 #include "val_target.h"
19 #include "target_database.h"
20
21 /* Use raw print for driver partition */
22 #ifdef DRIVER_PARTITION_INCLUDE
23 #define val_print(x, y, z) \
24 do { \
25 if (x >= VERBOSE) \
26 val_print_sf(y,z); \
27 } while(0)
28 #else
29 __UNUSED STATIC_DECLARE val_status_t val_print
30 (print_verbosity_t verbosity, char *string, int32_t data);
31 #endif
32
33 /**
34 @brief - Returns the base address of target configuration block database.
35 @param - blob : Populates the base address
36 @return - val_status_t
37 **/
val_target_cfg_get_next(void ** blob)38 STATIC_DECLARE val_status_t val_target_cfg_get_next(void **blob)
39 {
40 val_status_t status = VAL_STATUS_SUCCESS;
41 target_cfg_hdr_t *hdr;
42 uint32_t size;
43
44 if (*blob == NULL)
45 {
46 *blob = (void *) &target_database;
47 hdr = *blob;
48
49 /* Sanity check signature and version here */
50 if ((hdr->version != 1) || (hdr->size == 0))
51 {
52 val_print(PRINT_ERROR, "\tTarget config database Error. \n", 0);
53 return VAL_STATUS_ERROR;
54 }
55 hdr++;
56 *blob = hdr; // skip the header. start with the first record.
57 return status;
58 }
59
60 size = (((cfg_type_t *)*blob)->size) & 0xFFFFFF;
61 if (size)
62 {
63 *blob = (void *)((uint8_t *)*blob + size);
64 return VAL_STATUS_SUCCESS;
65 }
66 return VAL_STATUS_ERROR;
67 }
68
69 /**
70 @brief - This function checks for the given configuration ID with the block in
71 target configuration database.
72 @param - cfg_id : Configuration ID of a block
73 - data : Returns block base address
74 - size : Block size
75 @return - val_status_t
76 **/
val_target_get_cfg_blob(cfg_id_t cfg_id,uint8_t ** data,uint32_t * size)77 STATIC_DECLARE val_status_t val_target_get_cfg_blob(cfg_id_t cfg_id, uint8_t **data, uint32_t *size)
78 {
79 val_status_t status;
80 void *config_blob = NULL;
81
82 (void)size;
83
84 val_print(PRINT_INFO, "\tInput id is %x \n", cfg_id);
85 do
86 {
87
88 status = val_target_cfg_get_next(&config_blob);
89
90 if (VAL_ERROR(status))
91 {
92 break;
93 }
94
95 if (((cfg_type_t *)config_blob)->cfg_id == cfg_id)
96 {
97 *data = (uint8_t *)config_blob;
98 status = VAL_STATUS_SUCCESS;
99 break;
100 }
101 else if (((((cfg_type_t *)config_blob)->cfg_id & VAL_TEST_MAJOR_GROUP_MASK) == \
102 (cfg_id & VAL_TEST_MAJOR_GROUP_MASK)) && \
103 !(((cfg_type_t *)config_blob)->cfg_id & \
104 (VAL_TEST_MINOR_GROUP_MASK | VAL_TEST_CFG_INSTANCE_MASK)))
105 {
106 config_blob = (void *)((uint8_t *)config_blob + sizeof(memory_hdr_t));
107 if (((cfg_type_t *)config_blob)->cfg_id == cfg_id)
108 {
109 *data = (uint8_t *)config_blob;
110 status = VAL_STATUS_SUCCESS;
111 break;
112 }
113 }
114 else if (((cfg_type_t *)config_blob)->cfg_id == VAL_TEST_INVALID_CFG_ID)
115 {
116 status = VAL_STATUS_NOT_FOUND;
117 break;
118 }
119 } while(1);
120
121 return status;
122 }
123
124 /**
125
126 @brief - This function returns the data associated with a given
127 config ID.
128 @param - size - if the input size is less than the data size to
129 returned, the size is updated with the actual data size and
130 error is returned.
131 @return - data contains the information of type specific to a
132 config id.
133 **/
val_target_get_config(cfg_id_t cfg_id,uint8_t ** data,uint32_t * size)134 STATIC_DECLARE val_status_t val_target_get_config(cfg_id_t cfg_id, uint8_t **data, uint32_t *size)
135 {
136 val_status_t status;
137
138 if ((cfg_id < (cfg_id_t)TARGET_MIN_CFG_ID) || (cfg_id > (cfg_id_t)TARGET_MAX_CFG_ID))
139 {
140 val_print(PRINT_ERROR, "\tInvalid Target data config ID = %x \n", cfg_id);
141 return VAL_STATUS_INSUFFICIENT_SIZE;
142 }
143
144 status = val_target_get_cfg_blob(cfg_id, data, size);
145
146 if (VAL_ERROR(status))
147 {
148 val_print(PRINT_ERROR, "\tGet Config failed with status = %x", status);
149 val_print(PRINT_ERROR, " for cfg_id = %x\n", cfg_id);
150 return status;
151 }
152 return VAL_STATUS_SUCCESS;
153 }
154
155