drivers/usb/acpi: Don't add GPIOs to _CRS for Intel Bluetooth
[coreboot2.git] / src / soc / amd / common / pi / image.c
blob79dd736b02e03db9a538b78dd00702445cca97ca
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <agesa_headers.h>
4 #include <amdblocks/image.h>
5 #include <types.h>
7 /* Check if the image has the desired module. */
8 static bool validate_image(void *module_chain, const char module_signature[8])
10 AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain;
11 uint64_t signature = *(uint64_t *)module_signature;
12 char *checking_str;
14 while ((mod_ptr != NULL) &&
15 (MODULE_SIGNATURE == *(uint32_t *)&mod_ptr->ModuleHeaderSignature)) {
16 checking_str = (char *)&mod_ptr->ModuleIdentifier;
17 if (signature == *(uint64_t *)checking_str)
18 return true;
19 mod_ptr = (AMD_MODULE_HEADER *)mod_ptr->NextBlock;
21 return false;
25 * Find an image that has the desired module. The image is aligned within
26 * a given range.
28 void *amd_find_image(const void *start_address, const void *end_address,
29 uint32_t alignment, const char name[8])
31 uint8_t *current_ptr = (uint8_t *)start_address;
32 uint8_t *start = (uint8_t *)start_address;
33 uint8_t *end = (uint8_t *)end_address;
34 AMD_IMAGE_HEADER *image_ptr;
36 while ((current_ptr >= start) && (current_ptr < end)) {
37 if (IMAGE_SIGNATURE == *((uint32_t *)current_ptr)) {
38 image_ptr = (AMD_IMAGE_HEADER *)current_ptr;
40 /* Check if the image has the desired module */
41 if (validate_image((void *)image_ptr->ModuleInfoOffset,
42 name))
43 return current_ptr;
45 current_ptr += alignment;
47 return NULL;