blob: f668ea01fd66becb3671b00580b400c775fc4dde [file] [log] [blame]
Subrata Banik2153ea52017-11-22 15:38:19 +05301/*
2 * This file is part of the coreboot project.
3 *
Subrata Banik88852062018-01-10 10:51:50 +05304 * Copyright (C) 2017-2018 Intel Corporation.
Subrata Banik2153ea52017-11-22 15:38:19 +05305 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi.h>
17#include <arch/io.h>
18#include <console/console.h>
19#include <cpu/x86/smm.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include <intelblocks/pmc.h>
23#include <soc/pci_devs.h>
24
25/* SoC overrides */
26
27/* Fill up PMC resource structure inside SoC directory */
28__attribute__((weak)) int pmc_soc_get_resources(
29 struct pmc_resource_config *cfg)
30{
31 /* no-op */
32 return -1;
33}
34
35/* SoC override PMC initialization */
36__attribute__((weak)) void pmc_soc_init(struct device *dev)
37{
38 /* no-op */
39}
40
41static void pch_pmc_add_new_resource(struct device *dev,
42 uint8_t offset, uintptr_t base, size_t size,
43 unsigned long flags)
44{
45 struct resource *res;
46 res = new_resource(dev, offset);
47 res->base = base;
48 res->size = size;
49 res->flags = flags;
50}
51
52static void pch_pmc_add_mmio_resources(struct device *dev,
53 const struct pmc_resource_config *cfg)
54{
55 pch_pmc_add_new_resource(dev, cfg->pwrmbase_offset,
56 cfg->pwrmbase_addr, cfg->pwrmbase_size,
57 IORESOURCE_MEM | IORESOURCE_ASSIGNED |
58 IORESOURCE_FIXED | IORESOURCE_RESERVE);
59}
60
61static void pch_pmc_add_io_resources(struct device *dev,
62 const struct pmc_resource_config *cfg)
63{
64 pch_pmc_add_new_resource(dev, cfg->abase_offset,
65 cfg->abase_addr, cfg->abase_size,
66 IORESOURCE_IO | IORESOURCE_ASSIGNED |
67 IORESOURCE_FIXED);
68}
69
70static void pch_pmc_read_resources(struct device *dev)
71{
72 struct pmc_resource_config pmc_cfg;
73 struct pmc_resource_config *config = &pmc_cfg;
74
75 if (pmc_soc_get_resources(config) < 0)
76 die("Unable to get PMC controller resource information!");
77
78 /* Get the normal PCI resources of this device. */
79 pci_dev_read_resources(dev);
80
81 /* Add non-standard MMIO resources. */
82 pch_pmc_add_mmio_resources(dev, config);
83
84 /* Add IO resources. */
85 pch_pmc_add_io_resources(dev, config);
86}
87
88void pmc_set_acpi_mode(void)
89{
90 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
91 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
92 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
93 printk(BIOS_DEBUG, "done.\n");
94 }
95}
96
97static struct device_operations device_ops = {
98 .read_resources = &pch_pmc_read_resources,
99 .set_resources = &pci_dev_set_resources,
100 .enable_resources = &pci_dev_enable_resources,
101 .init = &pmc_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530102 .ops_pci = &pci_dev_ops_pci,
Subrata Banik2153ea52017-11-22 15:38:19 +0530103 .scan_bus = &scan_lpc_bus,
104};
105
106static const unsigned short pci_device_ids[] = {
107 PCI_DEVICE_ID_INTEL_SPT_LP_PMC,
108 PCI_DEVICE_ID_INTEL_KBP_H_PMC,
109 PCI_DEVICE_ID_INTEL_APL_PMC,
110 PCI_DEVICE_ID_INTEL_GLK_PMC,
111 0
112};
113
Subrata Banik88852062018-01-10 10:51:50 +0530114static const struct pci_driver pch_pmc __pci_driver = {
Subrata Banik2153ea52017-11-22 15:38:19 +0530115 .ops = &device_ops,
116 .vendor = PCI_VENDOR_ID_INTEL,
117 .devices = pci_device_ids,
118};