coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_thermal.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <device/mmio.h>
4 #include <device/pci_ops.h>
5 #include "pch.h"
7 #include <cpu/x86/msr.h>
8 
9 /* Temporary address for the thermal BAR */
10 #define TBARB_TEMP 0x40000000
11 
12 /* Early thermal init, must be done prior to giving ME its memory
13  which is done at the end of raminit */
15 {
16  const pci_devfn_t dev = PCH_THERMAL_DEV;
17 
18  /* Program address for temporary BAR */
19  pci_write_config32(dev, 0x40, TBARB_TEMP);
20  pci_write_config32(dev, 0x44, 0x0);
21 
22  /* Activate temporary BAR */
23  pci_or_config32(dev, 0x40, 5);
24 
25  write16p(TBARB_TEMP + 0x04, 0x3a2b);
26 
27  write8p(TBARB_TEMP + 0x0c, 0xff);
28  write8p(TBARB_TEMP + 0x0d, 0x00);
29  write8p(TBARB_TEMP + 0x0e, 0x40);
30  write8p(TBARB_TEMP + 0x82, 0x00);
31  write8p(TBARB_TEMP + 0x01, 0xba);
32 
33  /* Perform init */
34  /* Configure TJmax */
35  const msr_t msr = rdmsr(MSR_TEMPERATURE_TARGET);
36  write16p(TBARB_TEMP + 0x12, ((msr.lo >> 16) & 0xff) << 6);
37  /* Northbridge temperature slope and offset */
38  write16p(TBARB_TEMP + 0x16, 0x808c);
39 
40  write16p(TBARB_TEMP + 0x14, 0xde87);
41 
42  /* Enable thermal data reporting, processor, PCH and northbridge */
43  write16p(TBARB_TEMP + 0x1a, (read16p(TBARB_TEMP + 0x1a) & ~0xf) | 0x10f0);
44 
45  /* Disable temporary BAR */
46  pci_and_config32(dev, 0x40, ~1);
47 
48  pci_write_config32(dev, 0x40, 0);
49 
50  RCBA32_AND_OR(0x38b0, 0xffff8003, 0x403c);
51 }
void early_thermal_init(void)
Definition: early_thermal.c:14
#define TBARB_TEMP
Definition: early_thermal.c:10
#define MSR_TEMPERATURE_TARGET
Definition: haswell.h:50
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
static __always_inline void write8p(const uintptr_t addr, const uint8_t value)
Definition: mmio.h:230
static __always_inline void write16p(const uintptr_t addr, const uint16_t value)
Definition: mmio.h:235
static __always_inline uint16_t read16p(const uintptr_t addr)
Definition: mmio.h:215
static __always_inline void pci_or_config32(const struct device *dev, u16 reg, u32 ormask)
Definition: pci_ops.h:191
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_and_config32(const struct device *dev, u16 reg, u32 andmask)
Definition: pci_ops.h:158
u32 pci_devfn_t
Definition: pci_type.h:8
#define PCH_THERMAL_DEV
Definition: pch.h:80
#define RCBA32_AND_OR(x, and, or)
Definition: rcba.h:21
unsigned int lo
Definition: msr.h:111