coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
p2sblib.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #define __SIMPLE_DEVICE__
4 
5 #include <console/console.h>
6 #include <device/pci.h>
7 #include <device/pci_ids.h>
8 #include <intelblocks/p2sb.h>
9 #include <intelblocks/p2sblib.h>
10 #include <intelblocks/pcr.h>
11 #include <soc/pci_devs.h>
12 
14 {
15  /* Enable PCR Base addresses */
18 
19  /* Enable P2SB MSE */
21 }
22 
24 {
25  const uint16_t pci_vid = pci_read_config16(dev, PCI_VENDOR_ID);
26 
27  if (pci_vid == 0xffff)
28  return true;
29  if (pci_vid == PCI_VID_INTEL)
30  return false;
31  printk(BIOS_ERR, "P2SB PCI_VENDOR_ID is invalid, unknown if hidden\n");
32  return true;
33 }
34 
35 static void p2sb_dev_set_hide_bit(pci_devfn_t dev, int hide)
36 {
37  const uint16_t reg = P2SBC + 1;
38  const uint8_t mask = P2SBC_HIDE_BIT;
39  uint8_t val;
40 
41  val = pci_read_config8(dev, reg);
42  val &= ~mask;
43  if (hide)
44  val |= mask;
45  pci_write_config8(dev, reg, val);
46 }
47 
49 {
50  p2sb_dev_set_hide_bit(dev, 0);
51 
52  if (p2sb_dev_is_hidden(dev))
54  "Unable to unhide the P2SB device!\n");
55 }
56 
58 {
59  p2sb_dev_set_hide_bit(dev, 1);
60 
61  if (!p2sb_dev_is_hidden(dev))
63  "Unable to hide the P2SB device!\n");
64 }
65 
67  uint16_t reg, uint32_t *data)
68 {
69  struct pcr_sbi_msg msg = {
70  .pid = pid,
71  .offset = reg,
72  .opcode = cmd,
73  .is_posted = false,
74  .fast_byte_enable = 0xF,
75  .bar = 0,
76  .fid = 0
77  };
78  uint8_t response;
79  int status;
80 
81  /* Unhide the P2SB device */
82  p2sb_dev_unhide(dev);
83 
84  status = pcr_execute_sideband_msg(dev, &msg, data, &response);
85  if (status || response)
86  printk(BIOS_ERR, "Fail to execute p2sb sideband access\n");
87 
88  /* Hide the P2SB device */
89  p2sb_dev_hide(dev);
90 }
91 
93 {
94  uint32_t val = 0;
96  return val;
97 }
98 
100 {
102 }
int pcr_execute_sideband_msg(pci_devfn_t dev, struct pcr_sbi_msg *msg, uint32_t *data, uint8_t *response)
Definition: pcr.c:243
@ PCR_READ
Definition: pcr.h:35
@ PCR_WRITE
Definition: pcr.h:36
#define printk(level,...)
Definition: stdlib.h:16
#define die_with_post_code(value, fmt,...)
Definition: console.h:21
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
bool p2sb_dev_is_hidden(pci_devfn_t dev)
Definition: p2sblib.c:23
uint32_t p2sb_dev_sbi_read(pci_devfn_t dev, uint8_t pid, uint16_t reg)
Definition: p2sblib.c:92
void p2sb_dev_unhide(pci_devfn_t dev)
Definition: p2sblib.c:48
void p2sb_dev_enable_bar(pci_devfn_t dev, uint64_t bar)
Definition: p2sblib.c:13
static void p2sb_execute_sideband_access(pci_devfn_t dev, uint8_t cmd, uint8_t pid, uint16_t reg, uint32_t *data)
Definition: p2sblib.c:66
static void p2sb_dev_set_hide_bit(pci_devfn_t dev, int hide)
Definition: p2sblib.c:35
void p2sb_dev_sbi_write(pci_devfn_t dev, uint8_t pid, uint16_t reg, uint32_t val)
Definition: p2sblib.c:99
void p2sb_dev_hide(pci_devfn_t dev)
Definition: p2sblib.c:57
#define P2SBC_HIDE_BIT
Definition: p2sblib.h:11
#define P2SBC
Definition: p2sblib.h:10
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_COMMAND_MEMORY
Definition: pci_def.h:12
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_COMMAND
Definition: pci_def.h:10
#define PCI_VENDOR_ID
Definition: pci_def.h:8
#define PCI_BASE_ADDRESS_1
Definition: pci_def.h:64
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
u32 pci_devfn_t
Definition: pci_type.h:8
#define POST_HW_INIT_FAILURE
Hardware initialization failure.
Definition: post_codes.h:353
static const int mask[4]
Definition: gpio.c:308
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
uint8_t pid
Definition: pcr.h:41
u8 val
Definition: sys.c:300