coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/io.h>
4 #include <device/pci_ops.h>
5 #include <device/smbus_host.h>
7 #include "i82801ix.h"
8 #include "chip.h"
9 
11 {
12  const pci_devfn_t d31f0 = PCI_DEV(0, 0x1f, 0);
13  const struct device *dev = pcidev_on_root(0x1f, 0);
15 
16  /* Configure serial IRQs.*/
18  /*
19  * Enable some common LPC IO ranges:
20  * - 0x2e/0x2f, 0x4e/0x4f often SuperIO
21  * - 0x60/0x64, 0x62/0x66 often KBC/EC
22  * - 0x3f0-0x3f5/0x3f7 FDD
23  * - 0x378-0x37f and 0x778-0x77f LPT
24  * - 0x2f8-0x2ff COMB
25  * - 0x3f8-0x3ff COMA
26  * - 0x208-0x20f GAMEH
27  * - 0x200-0x207 GAMEL
28  */
29  pci_write_config16(d31f0, D31F0_LPC_IODEC, 0x0010);
34 
35  /* Set up generic decode ranges */
36  if (!dev || !dev->chip_info)
37  return;
38  config = dev->chip_info;
39 
40  pci_write_config32(d31f0, D31F0_GEN1_DEC, config->gen1_dec);
41  pci_write_config32(d31f0, D31F0_GEN2_DEC, config->gen2_dec);
42  pci_write_config32(d31f0, D31F0_GEN3_DEC, config->gen3_dec);
43  pci_write_config32(d31f0, D31F0_GEN4_DEC, config->gen4_dec);
44 }
45 
47 {
48  const pci_devfn_t d31f0 = PCI_DEV(0, 0x1f, 0);
49 
50  if (ENV_ROMSTAGE)
51  enable_smbus();
52 
53  /* Set up RCBA. */
54  pci_write_config32(d31f0, RCBA, CONFIG_FIXED_RCBA_MMIO_BASE | 1);
55 
56  /* Set up PMBASE. */
58  /* Enable PMBASE. */
59  pci_write_config8(d31f0, D31F0_ACPI_CNTL, 0x80);
60 
61  /* Set up GPIOBASE. */
63  /* Enable GPIO. */
64  pci_or_config8(d31f0, D31F0_GPIO_CNTL, 0x10);
65 
66  /* Reset watchdog. */
67  outw(0x0008, DEFAULT_TCOBASE + 0x04); /* R/WC, clear TCO caused SMI. */
68  outw(0x0002, DEFAULT_TCOBASE + 0x06); /* R/WC, clear second timeout. */
69 
70  /* Enable upper 128bytes of CMOS. */
71  RCBA32(0x3400) = (1 << 2);
72 
73  /* Initialize power management initialization
74  register early as it affects reboot behavior. */
75  /* Bit 20 activates global reset of host and ME on cf9 writes of 0x6
76  and 0xe (required if ME is disabled but present), bit 31 locks it.
77  The other bits are 'must write'. */
78  u8 reg8 = pci_read_config8(d31f0, 0xac);
79 
80  /* FIXME: It's a 8-bit variable!!! */
81  reg8 |= (1 << 31) | (1 << 30) | (1 << 20) | (3 << 8);
82  pci_write_config8(d31f0, 0xac, reg8);
83 
84  /* TODO: If RTC power failed, reset RTC state machine
85  (set, then reset RTC 0x0b bit7) */
86 
87  /* TODO: Check power state bits in GEN_PMCON_2 (D31F0 0xa2)
88  before they get cleared. */
89 }
void outw(u16 val, u16 port)
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
#define D31F0_GPIO_BASE
Definition: i82801ix.h:42
#define D31F0_LPC_IODEC
Definition: i82801ix.h:53
#define DEFAULT_TCOBASE
Definition: i82801ix.h:20
#define D31F0_GEN4_DEC
Definition: i82801ix.h:68
#define D31F0_GPIO_CNTL
Definition: i82801ix.h:43
#define D31F0_LPC_EN
Definition: i82801ix.h:54
#define D31F0_SERIRQ_CNTL
Definition: i82801ix.h:48
#define D31F0_GEN2_DEC
Definition: i82801ix.h:66
#define D31F0_GEN1_DEC
Definition: i82801ix.h:65
#define D31F0_ACPI_CNTL
Definition: i82801ix.h:41
#define D31F0_GEN3_DEC
Definition: i82801ix.h:67
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_or_config8(const struct device *dev, u16 reg, u8 ormask)
Definition: pci_ops.h:169
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 DEFAULT_PMBASE
Definition: iomap.h:14
enum board_config config
Definition: memory.c:448
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
#define D31F0_PMBASE
Definition: pmutil.h:8
#define ENV_ROMSTAGE
Definition: rules.h:149
static void enable_smbus(void)
Definition: smbus_host.h:34
#define RCBA
Definition: lpc.h:17
#define FDD_LPC_EN
Definition: lpc.h:43
#define GAMEL_LPC_EN
Definition: lpc.h:42
#define LPT_LPC_EN
Definition: lpc.h:44
#define GAMEH_LPC_EN
Definition: lpc.h:41
#define COMB_LPC_EN
Definition: lpc.h:45
#define KBC_LPC_EN
Definition: lpc.h:40
#define MC_LPC_EN
Definition: lpc.h:39
#define COMA_LPC_EN
Definition: lpc.h:46
#define CNF2_LPC_EN
Definition: lpc.h:37
#define CNF1_LPC_EN
Definition: lpc.h:38
#define DEFAULT_GPIOBASE
Definition: pch.h:22
#define RCBA32(x)
Definition: rcba.h:14
void i82801ix_early_init(void)
Definition: early_init.c:46
void i82801ix_lpc_setup(void)
Definition: early_init.c:10
uint8_t u8
Definition: stdint.h:45
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164