coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
iosf.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _SOC_IOSF_H_
4 #define _SOC_IOSF_H_
5 
6 #include <stdint.h>
7 #if ENV_RAMSTAGE
8 #include <device/device.h>
9 #include <reg_script.h>
10 #endif /* ENV_RAMSTAGE */
11 #include <soc/pci_devs.h>
12 
13 /*
14  * The SoC has a message network called IOSF Sideband. The access
15  * routines are through 3 registers in PCI config space of 00:00.0:
16  * MCR - control register
17  * MDR - data register
18  * MCRX - control register extension
19  * The extension register is only used for addresses that don't fit
20  * into the 8 bit register address.
21  */
22 
23 #ifndef PCI_DEV
24 #define PCI_DEV(SEGBUS, DEV, FN) ( \
25  (((SEGBUS) & 0xFFF) << 20) | \
26  (((DEV) & 0x1F) << 15) | \
27  (((FN) & 0x07) << 12))
28 #endif
29 #define IOSF_PCI_DEV PCI_DEV(0, SOC_DEV, SOC_FUNC)
30 
31 #define MCR_REG 0xd0
32 #define IOSF_OPCODE(x) ((x) << 24)
33 #define IOSF_PORT(x) ((0xff & (x)) << 16)
34 #define IOSF_REG(x) ((0xff & (x)) << 8)
35 #define IOSF_REG_UPPER(x) (((~0xff) & (x)))
36 #define IOSF_BYTE_EN_0 0x10
37 #define IOSF_BYTE_EN_1 0x20
38 #define IOSF_BYTE_EN_2 0x40
39 #define IOSF_BYTE_EN_3 0x80
40 #define IOSF_BYTE_EN \
41  (IOSF_BYTE_EN_0 | IOSF_BYTE_EN_1 | IOSF_BYTE_EN_2 | IOSF_BYTE_EN_3)
42 #define MDR_REG 0xd4
43 #define MCRX_REG 0xd8
44 
45 uint32_t iosf_bunit_read(int reg);
46 void iosf_bunit_write(int reg, uint32_t val);
47 uint32_t iosf_punit_read(int reg);
48 void iosf_punit_write(int reg, uint32_t val);
49 uint32_t iosf_score_read(int reg);
50 void iosf_score_write(int reg, uint32_t val);
51 uint32_t iosf_lpss_read(int reg);
52 void iosf_lpss_write(int reg, uint32_t val);
53 uint32_t iosf_port58_read(int reg);
54 void iosf_port58_write(int reg, uint32_t val);
55 uint32_t iosf_scc_read(int reg);
56 void iosf_scc_write(int reg, uint32_t val);
57 uint32_t iosf_usbphy_read(int reg);
58 void iosf_usbphy_write(int reg, uint32_t val);
59 
60 #if ENV_RAMSTAGE
61 uint64_t reg_script_read_iosf(struct reg_script_context *ctx);
62 void reg_script_write_iosf(struct reg_script_context *ctx);
63 #endif /* ENV_RAMSTAGE */
64 
65 /* IOSF ports. */
66 #define IOSF_PORT_AUNIT 0x00 /* IO Arbiter unit */
67 #define IOSF_PORT_CPU_BUS 0x02 /* CPU Bus Interface Controller */
68 #define IOSF_PORT_BUNIT 0x03 /* System Memory Arbiter/Bunit */
69 #define IOSF_PORT_PMC 0x04 /* Power Management Controller */
70 #define IOSF_PORT_SEC 0x44 /* SEC */
71 #define IOSF_PORT_0x45 0x45
72 #define IOSF_PORT_0x46 0x46
73 #define IOSF_PORT_0x47 0x47
74 #define IOSF_PORT_SCORE 0x48 /* SCORE */
75 #define IOSF_PORT_0x55 0x55
76 #define IOSF_PORT_0x58 0x58
77 #define IOSF_PORT_0x59 0x59
78 #define IOSF_PORT_0x5a 0x5a
79 #define IOSF_PORT_USHPHY 0x61 /* USB XHCI PHY */
80 #define IOSF_PORT_SCC 0x63 /* Storage Control Cluster */
81 #define IOSF_PORT_USBPHY 0x43 /* USB PHY */
82 #define IOSF_PORT_LPSS 0xa0 /* LPSS - Low Power Subsystem */
83 #define IOSF_PORT_0xa2 0xa2
84 #define IOSF_PORT_SSUS 0xa8 /* SUS */
85 #define IOSF_PORT_CCU 0xa9 /* Clock control unit. */
86 
87 /* Read and write opcodes differ per port. */
88 #define IOSF_OP_READ_BUNIT 0x10
89 #define IOSF_OP_WRITE_BUNIT (IOSF_OP_READ_BUNIT | 1)
90 #define IOSF_OP_READ_PMC 0x06
91 #define IOSF_OP_WRITE_PMC (IOSF_OP_READ_PMC | 1)
92 #define IOSF_OP_READ_SCORE 0x06
93 #define IOSF_OP_WRITE_SCORE (IOSF_OP_READ_SCORE | 1)
94 #define IOSF_OP_READ_LPSS 0x06
95 #define IOSF_OP_WRITE_LPSS (IOSF_OP_READ_LPSS | 1)
96 #define IOSF_OP_READ_0x58 0x06
97 #define IOSF_OP_WRITE_0x58 (IOSF_OP_READ_0x58 | 1)
98 #define IOSF_OP_READ_SCC 0x06
99 #define IOSF_OP_WRITE_SCC (IOSF_OP_READ_SCC | 1)
100 #define IOSF_OP_READ_USBPHY 0x06
101 #define IOSF_OP_WRITE_USBPHY (IOSF_OP_READ_USBPHY | 1)
102 
103 /*
104  * BUNIT Registers.
105  */
106 
107 /* BMBOUND has a 128MiB granularity. Highest address is 0xf8000000. */
108 #define BUNIT_BMBOUND 0x25
109 /*
110  * BMBOUND_HI describes the available RAM above 4GiB. It has a
111  * 256MiB granularity. Physical address bits 35:28 are compared with 31:24
112  * bits in the BMBOUND_HI register. Also note that since BMBOUND has 128MiB
113  * granularity care needs to be taken with the e820 map to account for a hole
114  * in the RAM.
115  */
116 #define BUNIT_BMBOUND_HI 0x26
117 #define BUNIT_MMCONF_REG 0x27
118 #define BUNIT_BMISC 0x28
119 /* The SMMRR registers define the SMM region in MiB granularity. */
120 #define BUNIT_SMRWAC 0x2d
121 #define BUNIT_SMRRL 0x2e
122 #define BUNIT_SMRRH 0x2f
123 
124 /* SA ID bits. */
125 #define SAI_IA_UNTRUSTED (1 << 0)
126 #define SAI_IA_SMM (1 << 2)
127 #define SAI_IA_BOOT (1 << 4)
128 
129 /*
130  * LPSS Registers
131  */
132 #define LPSS_SIO_DMA1_CTL 0x280
133 #define LPSS_I2C1_CTL 0x288
134 #define LPSS_I2C2_CTL 0x290
135 #define LPSS_I2C3_CTL 0x298
136 #define LPSS_I2C4_CTL 0x2a0
137 #define LPSS_I2C5_CTL 0x2a8
138 #define LPSS_I2C6_CTL 0x2b0
139 #define LPSS_I2C7_CTL 0x2b8
140 #define LPSS_SIO_DMA2_CTL 0x240
141 #define LPSS_PWM1_CTL 0x248
142 #define LPSS_PWM2_CTL 0x250
143 #define LPSS_HSUART1_CTL 0x258
144 #define LPSS_HSUART2_CTL 0x260
145 #define LPSS_SPI_CTL 0x268
146 # define LPSS_CTL_ACPI_INT_EN (1 << 21)
147 # define LPSS_CTL_PCI_CFG_DIS (1 << 20)
148 # define LPSS_CTL_SNOOP (1 << 18)
149 # define LPSS_CTL_NOSNOOP (1 << 19)
150 # define LPSS_CTL_PM_CAP_PRSNT (1 << 1)
151 
152 /*
153  * SCC Registers
154  */
155 #define SCC_SD_CTL 0x504
156 #define SCC_SDIO_CTL 0x508
157 #define SCC_MMC_CTL 0x500
158 # define SCC_CTL_PCI_CFG_DIS (1 << 0)
159 # define SCC_CTL_ACPI_INT_EN (1 << 1)
160 
161 /*
162  * LPE Registers
163  */
164 #define LPE_PCICFGCTR1 0x0500
165 # define LPE_PCICFGCTR1_PCI_CFG_DIS (1 << 0)
166 # define LPE_PCICFGCTR1_ACPI_INT_EN (1 << 1)
167 
168 /*
169  * USBPHY Registers
170  */
171 #define USBPHY_COMPBG 0x7f04
172 
173 /*
174  * IO Sideband Function
175  */
176 
177 #if ENV_RAMSTAGE
178 #define REG_SCRIPT_IOSF(cmd_, unit_, reg_, mask_, value_, timeout_) \
179  _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \
180  REG_SCRIPT_TYPE_IOSF, \
181  REG_SCRIPT_SIZE_32, \
182  reg_, mask_, value_, timeout_, unit_)
183 #define REG_IOSF_READ(unit_, reg_) \
184  REG_SCRIPT_IOSF(READ, unit_, reg_, 0, 0, 0)
185 #define REG_IOSF_WRITE(unit_, reg_, value_) \
186  REG_SCRIPT_IOSF(WRITE, unit_, reg_, 0, value_, 0)
187 #define REG_IOSF_RMW(unit_, reg_, mask_, value_) \
188  REG_SCRIPT_IOSF(RMW, unit_, reg_, mask_, value_, 0)
189 #define REG_IOSF_OR(unit_, reg_, value_) \
190  REG_IOSF_RMW(unit_, reg_, 0xffffffff, value_)
191 #define REG_IOSF_POLL(unit_, reg_, mask_, value_, timeout_) \
192  REG_SCRIPT_IOSF(POLL, unit_, reg_, mask_, value_, timeout_)
193 #endif /* ENV_RAMSTAGE */
194 
195 #endif /* _SOC_IOSF_H_ */
uint32_t iosf_score_read(int reg)
Definition: iosf.c:131
uint32_t iosf_lpss_read(int reg)
Definition: iosf.c:111
void iosf_lpss_write(int reg, uint32_t val)
Definition: iosf.c:116
void iosf_punit_write(int reg, uint32_t val)
Definition: iosf.c:86
uint32_t iosf_punit_read(int reg)
Definition: iosf.c:81
uint32_t iosf_scc_read(int reg)
Definition: iosf.c:141
uint32_t iosf_bunit_read(int reg)
Definition: iosf.c:39
uint32_t iosf_usbphy_read(int reg)
Definition: iosf.c:91
void iosf_usbphy_write(int reg, uint32_t val)
Definition: iosf.c:96
void iosf_port58_write(int reg, uint32_t val)
Definition: iosf.c:226
void iosf_score_write(int reg, uint32_t val)
Definition: iosf.c:136
void iosf_scc_write(int reg, uint32_t val)
Definition: iosf.c:146
void iosf_bunit_write(int reg, uint32_t val)
Definition: iosf.c:44
uint32_t iosf_port58_read(int reg)
Definition: iosf.c:221
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
u8 val
Definition: sys.c:300