coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpmr.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <intelblocks/gpmr.h>
5 #include <intelblocks/pcr.h>
6 #include <soc/pcr_ids.h>
7 
8 /* GPMR Register read given offset */
10 {
11  return pcr_read32(PID_DMI, offset);
12 }
13 
14 /* GPMR Register write given offset and val */
16 {
17  return pcr_write32(PID_DMI, offset, val);
18 }
19 
21 {
22  return pcr_or32(PID_DMI, offset, ordata);
23 }
24 
25 /* Check for available free gpmr */
26 static int get_available_gpmr(void)
27 {
28  int i;
29  uint32_t val;
30 
31  for (i = 0; i < MAX_GPMR_REGS; i++) {
33  if (!(val & GPMR_EN))
34  return i;
35  }
36  printk(BIOS_ERR, "%s: No available free gpmr found\n", __func__);
37  return CB_ERR;
38 }
39 
40 /* Configure GPMR for the given base and size of extended BIOS Region */
41 enum cb_err enable_gpmr(uint32_t base, uint32_t size, uint32_t dest_id)
42 {
43  int gpmr_num;
44  uint32_t limit;
45 
46  if (base & ~(GPMR_BASE_MASK << GPMR_BASE_SHIFT)) {
47  printk(BIOS_ERR, "base is not 64-KiB aligned!\n");
48  return CB_ERR;
49  }
50 
51  limit = base + (size - 1);
52 
53  if (limit < base) {
54  printk(BIOS_ERR, "Invalid limit: limit cannot be less than base!\n");
55  return CB_ERR;
56  }
57 
58  if ((limit & ~GPMR_LIMIT_MASK) != 0xffff) {
59  printk(BIOS_ERR, "limit does not end on a 64-KiB boundary!\n");
60  return CB_ERR;
61  }
62 
63  /* Get available free GPMR */
64  gpmr_num = get_available_gpmr();
65  if (gpmr_num == CB_ERR)
66  return CB_ERR;
67 
68  /* Program Range for the given decode window */
69  gpmr_write32(GPMR_OFFSET(gpmr_num), (limit & GPMR_LIMIT_MASK) |
71 
72  /* Program source decode enable bit and the Destination ID */
73  gpmr_write32(GPMR_DID_OFFSET(gpmr_num), dest_id | GPMR_EN);
74 
75  return CB_SUCCESS;
76 }
#define PID_DMI
Definition: pcr_ids.h:23
cb_err
coreboot error codes
Definition: cb_err.h:15
@ CB_ERR
Generic error code.
Definition: cb_err.h:17
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
void pcr_write32(uint8_t pid, uint16_t offset, uint32_t indata)
Definition: pcr.c:124
uint32_t pcr_read32(uint8_t pid, uint16_t offset)
Definition: pcr.c:89
void pcr_or32(uint8_t pid, uint16_t offset, uint32_t ordata)
Definition: pcr.c:184
#define printk(level,...)
Definition: stdlib.h:16
static size_t offset
Definition: flashconsole.c:16
static int get_available_gpmr(void)
Definition: gpmr.c:26
void gpmr_write32(uint16_t offset, uint32_t val)
Definition: gpmr.c:15
void gpmr_or32(uint16_t offset, uint32_t ordata)
Definition: gpmr.c:20
enum cb_err enable_gpmr(uint32_t base, uint32_t size, uint32_t dest_id)
Definition: gpmr.c:41
uint32_t gpmr_read32(uint16_t offset)
Definition: gpmr.c:9
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define GPMR_OFFSET(x)
Definition: pcr_gpmr.h:19
#define GPMR_BASE_SHIFT
Definition: pcr_gpmr.h:21
#define GPMR_BASE_MASK
Definition: pcr_gpmr.h:22
#define GPMR_EN
Definition: pcr_gpmr.h:25
#define GPMR_LIMIT_MASK
Definition: pcr_gpmr.h:20
#define MAX_GPMR_REGS
Definition: pcr_gpmr.h:17
#define GPMR_DID_OFFSET(x)
Definition: pcr_gpmr.h:24
uintptr_t base
Definition: uart.c:17
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
u8 val
Definition: sys.c:300