soc/intel/pantherlake: Remove soc_info.[hc] interface
[coreboot2.git] / src / soc / intel / common / block / gpmr / gpmr.c
blobcef2e57dfa4ad93a716e1b6e830ea661826f3cfb
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>
8 #include <types.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);
15 else
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);
24 else
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);
32 else
33 return pcr_or32(PID_DMI, offset, ordata);
36 /* Check for available free gpmr */
37 static int get_available_gpmr(void)
39 int i;
40 uint32_t val;
42 for (i = 0; i < MAX_GPMR_REGS; i++) {
43 val = gpmr_read32(GPMR_DID_OFFSET(i));
44 if (!(val & GPMR_EN))
45 return i;
47 printk(BIOS_ERR, "%s: No available free gpmr found\n", __func__);
48 return CB_ERR;
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)
54 int gpmr_num;
55 uint32_t limit;
57 if (base & ~(GPMR_BASE_MASK << GPMR_BASE_SHIFT)) {
58 printk(BIOS_ERR, "base is not 64-KiB aligned!\n");
59 return CB_ERR;
62 limit = base + (size - 1);
64 if (limit < base) {
65 printk(BIOS_ERR, "Invalid limit: limit cannot be less than base!\n");
66 return CB_ERR;
69 if ((limit & ~GPMR_LIMIT_MASK) != 0xffff) {
70 printk(BIOS_ERR, "limit does not end on a 64-KiB boundary!\n");
71 return CB_ERR;
74 /* Get available free GPMR */
75 gpmr_num = get_available_gpmr();
76 if (gpmr_num == CB_ERR)
77 return 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);
86 return CB_SUCCESS;