coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pmc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "chip.h"
4 #include <console/console.h>
5 #include <device/mmio.h>
6 #include <device/device.h>
7 #include <device/pci.h>
8 #include <intelblocks/pmc.h>
9 #include <intelblocks/pmclib.h>
10 #include <soc/iomap.h>
11 #include <soc/pm.h>
12 #include <timer.h>
13 
14 /* Fill up PMC resource structure */
16 {
23 
24  return 0;
25 }
26 
27 static int choose_slp_s3_assertion_width(int width_usecs)
28 {
29  int i;
30  static const struct {
31  int max_width;
32  int value;
33  } slp_s3_settings[] = {
34  {
35  .max_width = 60,
36  .value = SLP_S3_ASSERT_60_USEC,
37  },
38  {
39  .max_width = 1 * USECS_PER_MSEC,
40  .value = SLP_S3_ASSERT_1_MSEC,
41  },
42  {
43  .max_width = 50 * USECS_PER_MSEC,
44  .value = SLP_S3_ASSERT_50_MSEC,
45  },
46  {
47  .max_width = 2 * USECS_PER_SEC,
48  .value = SLP_S3_ASSERT_2_SEC,
49  },
50  };
51 
52  for (i = 0; i < ARRAY_SIZE(slp_s3_settings); i++) {
53  if (width_usecs <= slp_s3_settings[i].max_width)
54  break;
55  }
56 
57  /* Provide conservative default if nothing set in devicetree
58  * or requested assertion width too large. */
59  if (width_usecs <= 0 || i == ARRAY_SIZE(slp_s3_settings))
60  i = ARRAY_SIZE(slp_s3_settings) - 1;
61 
62  printk(BIOS_DEBUG, "SLP S3 assertion width: %d usecs\n",
63  slp_s3_settings[i].max_width);
64 
65  return slp_s3_settings[i].value;
66 }
67 
68 static void set_slp_s3_assertion_width(int width_usecs)
69 {
70  uint32_t reg;
71  uintptr_t gen_pmcon3 = soc_read_pmc_base() + GEN_PMCON3;
72  int setting = choose_slp_s3_assertion_width(width_usecs);
73 
74  reg = read32p(gen_pmcon3);
75  reg &= ~SLP_S3_ASSERT_MASK;
76  reg |= setting << SLP_S3_ASSERT_WIDTH_SHIFT;
77  write32p(gen_pmcon3, reg);
78 }
79 
80 void pmc_soc_init(struct device *dev)
81 {
82  const struct soc_intel_apollolake_config *cfg = config_of(dev);
83 
84  /* Set up GPE configuration */
85  pmc_gpe_init();
87 
88  if (cfg != NULL)
90 
91  /* Log power state */
92  pch_log_state();
93 
94  /* Now that things have been logged clear out the PMC state. */
96 
98 }
#define SLP_S3_ASSERT_MASK
Definition: pm.h:170
#define SLP_S3_ASSERT_50_MSEC
Definition: pm.h:173
#define SLP_S3_ASSERT_WIDTH_SHIFT
Definition: pm.h:169
#define SLP_S3_ASSERT_1_MSEC
Definition: pm.h:172
#define SLP_S3_ASSERT_2_SEC
Definition: pm.h:174
#define SLP_S3_ASSERT_60_USEC
Definition: pm.h:171
#define GEN_PMCON3
Definition: pm.h:168
int pmc_soc_get_resources(struct pmc_resource_config *cfg)
Definition: pmc.c:15
void pmc_soc_init(struct device *dev)
Definition: pmc.c:80
static int choose_slp_s3_assertion_width(int width_usecs)
Definition: pmc.c:27
static void set_slp_s3_assertion_width(int width_usecs)
Definition: pmc.c:68
pte_t value
Definition: mmu.c:91
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
static DEVTREE_CONST void * config_of(const struct device *dev)
Definition: device.h:382
static __always_inline uint32_t read32p(const uintptr_t addr)
Definition: mmio.h:220
static __always_inline void write32p(const uintptr_t addr, const uint32_t value)
Definition: mmio.h:240
#define USECS_PER_SEC
Definition: timer.h:8
#define USECS_PER_MSEC
Definition: timer.h:10
#define PCH_PWRM_BASE_ADDRESS
Definition: iomap.h:70
#define ACPI_BASE_ADDRESS
Definition: iomap.h:99
#define ACPI_BASE_SIZE
Definition: iomap.h:100
#define PMC_BAR0_SIZE
Definition: iomap.h:28
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_BASE_ADDRESS_4
Definition: pci_def.h:67
static void pch_log_state(void *unused)
Definition: elog.c:193
uintptr_t soc_read_pmc_base(void)
Definition: pmutil.c:147
void pmc_set_power_failure_state(bool target_on)
Definition: pmclib.c:623
void pmc_set_acpi_mode(void)
Definition: pmclib.c:754
void pmc_clear_prsts(void)
Definition: pmclib.c:366
void pmc_gpe_init(void)
Definition: pmclib.c:535
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
Definition: device.h:107
uint8_t abase_offset
Definition: pmc.h:18
size_t abase_size
Definition: pmc.h:22
uintptr_t pwrmbase_addr
Definition: pmc.h:14
uintptr_t abase_addr
Definition: pmc.h:20
size_t pwrmbase_size
Definition: pmc.h:16
uint8_t pwrmbase_offset
Definition: pmc.h:12