1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <intelblocks/gpmr.h>
5 #include <intelblocks/ioc.h>
6 #include <intelblocks/pcr.h>
7 #include <soc/pcr_ids.h>
10 /* GPMR Register read given offset */
11 uint32_t gpmr_read32(uint16_t offset
)
13 if (CONFIG(SOC_INTEL_COMMON_BLOCK_IOC
))
14 return ioc_reg_read32(offset
);
16 return pcr_read32(PID_DMI
, offset
);
19 /* GPMR Register write given offset and val */
20 void gpmr_write32(uint16_t offset
, uint32_t val
)
22 if (CONFIG(SOC_INTEL_COMMON_BLOCK_IOC
))
23 return ioc_reg_write32(offset
, val
);
25 return pcr_write32(PID_DMI
, offset
, val
);
28 void gpmr_or32(uint16_t offset
, uint32_t ordata
)
30 if (CONFIG(SOC_INTEL_COMMON_BLOCK_IOC
))
31 return ioc_reg_or32(offset
, ordata
);
33 return pcr_or32(PID_DMI
, offset
, ordata
);
36 /* Check for available free gpmr */
37 static int get_available_gpmr(void)
42 for (i
= 0; i
< MAX_GPMR_REGS
; i
++) {
43 val
= gpmr_read32(GPMR_DID_OFFSET(i
));
47 printk(BIOS_ERR
, "%s: No available free gpmr found\n", __func__
);
51 /* Configure GPMR for the given base and size of extended BIOS Region */
52 enum cb_err
enable_gpmr(uint32_t base
, uint32_t size
, uint32_t dest_id
)
57 if (base
& ~(GPMR_BASE_MASK
<< GPMR_BASE_SHIFT
)) {
58 printk(BIOS_ERR
, "base is not 64-KiB aligned!\n");
62 limit
= base
+ (size
- 1);
65 printk(BIOS_ERR
, "Invalid limit: limit cannot be less than base!\n");
69 if ((limit
& ~GPMR_LIMIT_MASK
) != 0xffff) {
70 printk(BIOS_ERR
, "limit does not end on a 64-KiB boundary!\n");
74 /* Get available free GPMR */
75 gpmr_num
= get_available_gpmr();
76 if (gpmr_num
== CB_ERR
)
79 /* Program Range for the given decode window */
80 gpmr_write32(GPMR_OFFSET(gpmr_num
), (limit
& GPMR_LIMIT_MASK
) |
81 ((base
>> GPMR_BASE_SHIFT
) & GPMR_BASE_MASK
));
83 /* Program source decode enable bit and the Destination ID */
84 gpmr_write32(GPMR_DID_OFFSET(gpmr_num
), dest_id
| GPMR_EN
);