1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 #include <commonlib/region.h>
5 #include <console/console.h>
7 #include <cpu/intel/cpu_ids.h>
8 #include <device/mmio.h>
10 #include <intelblocks/pmclib.h>
11 #include <soc/bootblock.h>
14 /* Flash Master 1 : HOST/BIOS */
17 /* Flash signature Offset */
18 #define FLASH_SIGN_OFFSET 0x10
19 #define FLMSTR_WR_SHIFT_V2 20
20 #define FLASH_VAL_SIGN 0xFF0A55A
22 /* It checks whether host (Flash Master 1) has write access to the Descriptor Region or not */
23 static bool is_descriptor_writeable(uint8_t *desc
)
25 /* Check flash has valid signature */
26 if (read32p(desc
+ FLASH_SIGN_OFFSET
) != FLASH_VAL_SIGN
) {
27 printk(BIOS_ERR
, "Flash Descriptor is not valid\n");
31 /* Check host has write access to the Descriptor Region */
32 if (!((read32p(desc
+ FLMSTR1
) >> FLMSTR_WR_SHIFT_V2
) & BIT(0))) {
33 printk(BIOS_ERR
, "Host doesn't have write access to Descriptor Region\n");
40 void configure_descriptor(struct descriptor_byte
*bytes
, size_t num
)
42 uint8_t si_desc_buf
[CONFIG_SI_DESC_REGION_SZ
];
43 struct region_device desc_rdev
;
44 bool update_required
= false;
46 if (fmap_locate_area_as_rdev_rw(CONFIG_SI_DESC_REGION
, &desc_rdev
) < 0) {
47 printk(BIOS_ERR
, "Failed to locate %s in the FMAP\n", CONFIG_SI_DESC_REGION
);
51 if (rdev_readat(&desc_rdev
, si_desc_buf
, 0, CONFIG_SI_DESC_REGION_SZ
) !=
52 CONFIG_SI_DESC_REGION_SZ
) {
53 printk(BIOS_ERR
, "Failed to read Descriptor Region from SPI Flash\n");
57 if (!is_descriptor_writeable(si_desc_buf
))
60 for (size_t i
= 0; i
< num
; i
++) {
61 size_t offset
= bytes
[i
].offset
;
62 uint8_t desired_value
= bytes
[i
].desired_value
;
63 printk(BIOS_DEBUG
, "Current value of Descriptor byte 0x%zx: 0x%x\n",
64 offset
, si_desc_buf
[offset
]);
65 if (si_desc_buf
[offset
] != desired_value
) {
66 update_required
= true;
67 si_desc_buf
[offset
] = desired_value
;
71 if (!update_required
) {
72 printk(BIOS_DEBUG
, "Update of Descriptor is not required!\n");
76 if (rdev_eraseat(&desc_rdev
, 0, CONFIG_SI_DESC_REGION_SZ
) != CONFIG_SI_DESC_REGION_SZ
) {
77 printk(BIOS_ERR
, "Failed to erase Descriptor Region area\n");
81 if (rdev_writeat(&desc_rdev
, si_desc_buf
, 0, CONFIG_SI_DESC_REGION_SZ
)
82 != CONFIG_SI_DESC_REGION_SZ
) {
83 printk(BIOS_ERR
, "Failed to update Descriptor Region\n");
87 printk(BIOS_DEBUG
, "Update of Descriptor successful, trigger GLOBAL RESET\n");
89 pmc_global_reset_enable(true);
91 die("Failed to trigger GLOBAL RESET\n");