coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_setup.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _HUDSON_EARLY_SETUP_C_
4 #define _HUDSON_EARLY_SETUP_C_
5 
6 #include <assert.h>
7 #include <stdint.h>
8 #include <amdblocks/acpimmio.h>
9 #include <device/mmio.h>
10 #include <device/pci_ops.h>
11 
12 #include "hudson.h"
13 #include "pci_devs.h"
14 #include <Fch/Fch.h>
15 
17 {
18  u8 byte;
19  pci_devfn_t dev;
20 
21  /* P2P Bridge */
22  dev = PCI_DEV(0, 0x14, 4);
23 
24  /* Chip Control: Enable subtractive decoding */
25  byte = pci_read_config8(dev, 0x40);
26  byte |= 1 << 5;
27  pci_write_config8(dev, 0x40, byte);
28 
29  /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
30  byte = pci_read_config8(dev, 0x4B);
31  byte |= 1 << 7;
32  pci_write_config8(dev, 0x4B, byte);
33 
34  /* The same IO Base and IO Limit here is meaningful because we set the
35  * bridge to be subtractive. During early setup stage, we have to make
36  * sure that data can go through port 0x80.
37  */
38  /* IO Base: 0xf000 */
39  byte = pci_read_config8(dev, 0x1C);
40  byte |= 0xF << 4;
41  pci_write_config8(dev, 0x1C, byte);
42 
43  /* IO Limit: 0xf000 */
44  byte = pci_read_config8(dev, 0x1D);
45  byte |= 0xF << 4;
46  pci_write_config8(dev, 0x1D, byte);
47 
48  /* PCI Command: Enable IO response */
49  byte = pci_read_config8(dev, 0x04);
50  byte |= 1 << 0;
51  pci_write_config8(dev, 0x04, byte);
52 
53  /* LPC controller */
54  dev = PCI_DEV(0, 0x14, 3);
55 
56  byte = pci_read_config8(dev, 0x4A);
57  byte &= ~(1 << 5); /* disable lpc port 80 */
58  pci_write_config8(dev, 0x4A, byte);
59 }
60 
62 {
63  u8 byte;
64 
65  /* Enable port 80 LPC decode in pci function 3 configuration space. */
66  const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
67  byte = pci_read_config8(dev, 0x4a);
68  byte |= 1 << 5; /* enable port 80 */
69  pci_write_config8(dev, 0x4a, byte);
70 }
71 
73 {
74  u32 tmp;
75 
76  /* Enable LPC controller */
77  pm_write8(0xec, pm_read8(0xec) | 0x01);
78 
79  const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
80  /* Serial port enumeration on Hudson:
81  * PORT0 - 0x3f8
82  * PORT1 - 0x2f8
83  * PORT5 - 0x2e8
84  * PORT7 - 0x3e8
85  */
88 
90 }
91 
92 static void enable_wideio(uint8_t port, uint16_t size)
93 {
94  uint32_t wideio_enable[] = {
98  };
99  uint32_t alt_wideio_enable[] = {
103  };
104  const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
105  uint32_t tmp;
106 
107  /* Only allow port 0-2 */
108  assert(port <= ARRAY_SIZE(wideio_enable));
109 
110  if (size == 16) {
112  tmp |= alt_wideio_enable[port];
114  } else { /* 512 */
116  tmp &= ~alt_wideio_enable[port];
118  }
119 
120  /* Enable the range */
122  tmp |= wideio_enable[port];
124 }
125 
126 /*
127  * lpc_wideio_window() may be called any point in romstage, but take
128  * care that AGESA doesn't overwrite the range this function used.
129  * The function checks if there is an empty range and if all ranges are
130  * used the function throws an assert. The function doesn't check for a
131  * duplicate range, for ranges that can be merged into a single
132  * range, or ranges that overlap.
133  *
134  * The developer is expected to ensure that there are no conflicts.
135  */
137 {
138  const pci_devfn_t dev = PCI_DEV(0, PCU_DEV, LPC_FUNC);
139  u32 tmp;
140 
141  /* Support 512 or 16 bytes per range */
142  assert(size == 512 || size == 16);
143 
144  /* Find and open Base Register and program it */
146 
147  if ((tmp & 0xFFFF) == 0) { /* WIDEIO0 */
148  tmp |= base;
150  enable_wideio(0, size);
151  } else if ((tmp & 0xFFFF0000) == 0) { /* WIDEIO1 */
152  tmp |= (base << 16);
154  enable_wideio(1, size);
155  } else { /* Check WIDEIO2 register */
157  if ((tmp & 0xFFFF) == 0) { /* WIDEIO2 */
158  tmp |= base;
160  enable_wideio(2, size);
161  } else { /* All WIDEIO locations used*/
162  BUG();
163  }
164  }
165 }
166 
168 {
169  assert(IS_ALIGNED(base, 512));
170  lpc_wideio_window(base, 512);
171 }
172 
174 {
175  assert(IS_ALIGNED(base, 16));
176  lpc_wideio_window(base, 16);
177 }
178 
180 {
181  u32 ctrl;
182 
183  /*
184  * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
185  * 48Mhz will be on ball AP13 (FT3b package)
186  */
187  ctrl = misc_read32(FCH_MISC_REG40);
188 
189  /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
190  ctrl &= (u32)~(1<<2);
191  misc_write32(FCH_MISC_REG40, ctrl);
192 }
193 
195 {
196  /* Make sure the base address is predictable */
197  const pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
198 
200  & 0xfffffff0;
201  if (!base){
204  | SPI_ROM_ENABLE);
205  /* PCI_COMMAND_MEMORY is read-only and enabled. */
206  }
207  return (uintptr_t)base;
208 }
209 
210 void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
211 {
213  write16((void *)(base + SPI100_SPEED_CONFIG),
214  (norm << SPI_NORM_SPEED_NEW_SH) |
215  (fast << SPI_FAST_SPEED_NEW_SH) |
216  (alt << SPI_ALT_SPEED_NEW_SH) |
217  (tpm << SPI_TPM_SPEED_NEW_SH));
219  read16((void *)(base + SPI100_ENABLE)));
220 }
221 
223 {
226  read16((void *)(base + SPI100_HOST_PREF_CONFIG))
227  & ~SPI_RD4DW_EN_HOST);
228 }
229 
230 /* Hudson 1-3 only. For Hudson 1, call with fast=1 */
231 void hudson_set_readspeed(u16 norm, u16 fast)
232 {
234  write16((void *)(base + SPI_CNTRL1),
235  (read16((void *)(base + SPI_CNTRL1))
237  | (norm << SPI_NORM_SPEED_SH)
238  | (fast << SPI_FAST_SPEED_SH));
239 }
240 
242 {
244  write32((void *)(base + SPI_CNTRL0),
245  (read32((void *)(base + SPI_CNTRL0))
246  & ~SPI_READ_MODE_MASK) | mode);
247 }
248 
250 {
251  const pci_devfn_t dev = PCI_DEV(0, 0x14, 3); /* LPC device */
252 
255  | ROUTE_TPM_2_SPI);
256 }
257 
258 #endif
static uint8_t pm_read8(uint8_t reg)
Definition: acpimmio.h:166
static uint32_t misc_read32(uint8_t reg)
Definition: acpimmio.h:266
static void misc_write32(uint8_t reg, uint32_t value)
Definition: acpimmio.h:281
static void pm_write8(uint8_t reg, uint8_t value)
Definition: acpimmio.h:181
void hudson_pci_port80(void)
Definition: early_setup.c:12
void hudson_lpc_decode(void)
Definition: early_setup.c:68
void hudson_lpc_port80(void)
Definition: early_setup.c:57
#define SPIROM_BASE_ADDRESS_REGISTER
Definition: hudson.h:75
#define SPI_BASE_ADDRESS
Definition: iomap.h:8
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint16_t read16(const void *addr)
Definition: mmio.h:17
static uint32_t read32(const void *addr)
Definition: mmio.h:22
static void write16(void *addr, uint16_t val)
Definition: mmio.h:35
#define BUG()
Definition: assert.h:65
#define assert(statement)
Definition: assert.h:74
#define IS_ALIGNED(x, a)
Definition: helpers.h:19
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define SPI_CNTRL1
Definition: fch_spi_ctrl.c:19
port
Definition: i915.h:29
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
void hudson_read_mode(u32 mode)
Definition: early_setup.c:241
void hudson_clk_output_48Mhz(void)
Definition: early_setup.c:179
void hudson_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
Definition: early_setup.c:210
static uintptr_t hudson_spibase(void)
Definition: early_setup.c:194
static void lpc_wideio_window(uint16_t base, uint16_t size)
Definition: early_setup.c:136
void hudson_disable_4dw_burst(void)
Definition: early_setup.c:222
void hudson_tpm_decode_spi(void)
Definition: early_setup.c:249
void lpc_wideio_16_window(uint16_t base)
Definition: early_setup.c:173
static void enable_wideio(uint8_t port, uint16_t size)
Definition: early_setup.c:92
void hudson_set_readspeed(u16 norm, u16 fast)
Definition: early_setup.c:231
void lpc_wideio_512_window(uint16_t base)
Definition: early_setup.c:167
#define SPI_FAST_SPEED_NEW_SH
Definition: hudson.h:143
#define SPI_TPM_SPEED_NEW_SH
Definition: hudson.h:145
#define SPI_CNTRL1_SPEED_MASK
Definition: hudson.h:128
#define SPI_NORM_SPEED_NEW_SH
Definition: hudson.h:142
#define SPI_NORM_SPEED_SH
Definition: hudson.h:129
#define SPI_FAST_SPEED_SH
Definition: hudson.h:130
#define SPI_ALT_SPEED_NEW_SH
Definition: hudson.h:144
#define ROUTE_TPM_2_SPI
Definition: lpc.h:16
#define SPI_ROM_ENABLE
Definition: lpc.h:18
#define LPC_FUNC
Definition: pci_devs.h:122
#define PCU_DEV
Definition: pci_devs.h:121
uintptr_t base
Definition: uart.c:17
#define LPC_ALT_WIDEIO0_ENABLE
Definition: lpc.h:95
#define LPC_WIDEIO1_ENABLE
Definition: lpc.h:52
#define LPC_WIDEIO2_ENABLE
Definition: lpc.h:51
#define LPC_IO_PORT_DECODE_ENABLE
Definition: lpc.h:16
#define DECODE_ENABLE_SERIAL_PORT7
Definition: lpc.h:30
#define LPC_WIDEIO_GENERIC_PORT
Definition: lpc.h:85
#define LPC_WIDEIO0_ENABLE
Definition: lpc.h:65
#define LPC_WIDEIO2_GENERIC_PORT
Definition: lpc.h:106
#define LPC_ALT_WIDEIO2_ENABLE
Definition: lpc.h:93
#define LPC_ALT_WIDEIO1_ENABLE
Definition: lpc.h:94
#define DECODE_ENABLE_SERIAL_PORT1
Definition: lpc.h:24
#define LPC_ALT_WIDEIO_RANGE_ENABLE
Definition: lpc.h:92
#define LPC_IO_OR_MEM_DECODE_ENABLE
Definition: lpc.h:50
#define DECODE_ENABLE_SERIAL_PORT5
Definition: lpc.h:28
#define DECODE_ENABLE_SERIAL_PORT0
Definition: lpc.h:23
#define SPI_READ_MODE_MASK
Definition: spi.h:26
#define SPI_USE_SPI100
Definition: spi.h:34
#define SPI_CNTRL0
Definition: spi.h:9
#define SPI100_SPEED_CONFIG
Definition: spi.h:43
#define SPI_RD4DW_EN_HOST
Definition: spi.h:71
#define SPI100_HOST_PREF_CONFIG
Definition: spi.h:70
#define SPI100_ENABLE
Definition: spi.h:33
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8