Debian Codegraph @

src/soc/intel/common/block/gpmr/gpmr.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
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>
9
10 /* GPMR Register read given offset */
11 uint32_t gpmr_read32(uint16_t offset)
12 {
13 if (CONFIG(SOC_INTEL_COMMON_BLOCK_IOC))
14 return ioc_reg_read32(offset);
15 else
16 return pcr_read32(PID_DMI, offset);
17 }
18
19 /* GPMR Register write given offset and val */
20 void gpmr_write32(uint16_t offset, uint32_t val)
21 {
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);
26 }
27
28 void gpmr_or32(uint16_t offset, uint32_t ordata)
29 {
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);
34 }
35
36 #if CONFIG(FAST_SPI_SUPPORTS_EXT_BIOS_WINDOW)
37 /* Check for available free gpmr */
38 static int get_available_gpmr(void)
39 {
40 int i;
41 uint32_t val;
42
43 for (i = 0; i < MAX_GPMR_REGS; i++) {
44 val = gpmr_read32(GPMR_DID_OFFSET(i));
45 if (!(val & GPMR_EN))
46 return i;
47 }
48 printk(BIOS_ERR, "%s: No available free gpmr found\n", __func__);
49 return CB_ERR;
50 }
51
52 /* Configure GPMR for the given base and size of extended BIOS Region */
53 enum cb_err enable_gpmr(uint32_t base, uint32_t size, uint32_t dest_id)
54 {
55 int gpmr_num;
56 uint32_t limit;
57
58 if (base & ~(GPMR_BASE_MASK << GPMR_BASE_SHIFT)) {
59 printk(BIOS_ERR, "base is not 64-KiB aligned!\n");
60 return CB_ERR;
61 }
62
63 limit = base + (size - 1);
64
65 if (limit < base) {
66 printk(BIOS_ERR, "Invalid limit: limit cannot be less than base!\n");
67 return CB_ERR;
68 }
69
70 if ((limit & ~GPMR_LIMIT_MASK) != 0xffff) {
71 printk(BIOS_ERR, "limit does not end on a 64-KiB boundary!\n");
72 return CB_ERR;
73 }
74
75 /* Get available free GPMR */
76 gpmr_num = get_available_gpmr();
77 if (gpmr_num == CB_ERR)
78 return CB_ERR;
79
80 /* Program Range for the given decode window */
81 gpmr_write32(GPMR_OFFSET(gpmr_num), (limit & GPMR_LIMIT_MASK) |
82 ((base >> GPMR_BASE_SHIFT) & GPMR_BASE_MASK));
83
84 /* Program source decode enable bit and the Destination ID */
85 gpmr_write32(GPMR_DID_OFFSET(gpmr_num), dest_id | GPMR_EN);
86
87 return CB_SUCCESS;
88 }
89 #endif