blob: e1f2a3508c2a85cb4e45ffa899c6f5c11a673c69 [file] [log] [blame]
Subrata Banik2153ea52017-11-22 15:38:19 +05301/*
2 * This file is part of the coreboot project.
3 *
Subrata Banik2153ea52017-11-22 15:38:19 +05304 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <arch/acpi.h>
16#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Subrata Banik2153ea52017-11-22 15:38:19 +053018#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 */
Aaron Durbin64031672018-04-21 14:45:32 -060028__weak int pmc_soc_get_resources(
Subrata Banik2153ea52017-11-22 15:38:19 +053029 struct pmc_resource_config *cfg)
30{
31 /* no-op */
32 return -1;
33}
34
35/* SoC override PMC initialization */
Aaron Durbin64031672018-04-21 14:45:32 -060036__weak void pmc_soc_init(struct device *dev)
Subrata Banik2153ea52017-11-22 15:38:19 +053037{
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);
Julius Wernercd49cce2019-03-05 16:53:33 -080068 if (CONFIG(PMC_INVALID_READ_AFTER_WRITE)) {
Hannah Williams1177bf52017-12-13 12:44:26 -080069 /*
70 * The ACPI IO BAR (offset 0x20) is not PCI compliant. We've
71 * observed cases where the BAR reads back as 0, but the IO
72 * window is open. This also means that it will not respond
73 * to PCI probing.
74 */
75 pci_write_config16(dev, cfg->abase_offset, cfg->abase_addr);
76 /*
77 * In pci_dev_enable_resources, reading IO SPACE ACCESS bit in
78 * STATUSCOMMAND register does not read back the written
79 * value correctly, hence IO access gets disabled. This is
80 * seen in some PMC devices, hence this code makes sure
81 * IO access is available.
82 */
83 dev->command |= PCI_COMMAND_IO;
84 }
Subrata Banik2153ea52017-11-22 15:38:19 +053085}
86
87static void pch_pmc_read_resources(struct device *dev)
88{
89 struct pmc_resource_config pmc_cfg;
90 struct pmc_resource_config *config = &pmc_cfg;
91
92 if (pmc_soc_get_resources(config) < 0)
Keith Short15588b02019-05-09 11:40:34 -060093 die_with_post_code(POST_HW_INIT_FAILURE,
94 "Unable to get PMC controller resource information!");
Subrata Banik2153ea52017-11-22 15:38:19 +053095
96 /* Get the normal PCI resources of this device. */
97 pci_dev_read_resources(dev);
98
99 /* Add non-standard MMIO resources. */
100 pch_pmc_add_mmio_resources(dev, config);
101
102 /* Add IO resources. */
103 pch_pmc_add_io_resources(dev, config);
104}
105
106void pmc_set_acpi_mode(void)
107{
Julius Wernercd49cce2019-03-05 16:53:33 -0800108 if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
Subrata Banik2153ea52017-11-22 15:38:19 +0530109 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
110 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
111 printk(BIOS_DEBUG, "done.\n");
112 }
113}
114
115static struct device_operations device_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100116 .read_resources = pch_pmc_read_resources,
117 .set_resources = pci_dev_set_resources,
118 .enable_resources = pci_dev_enable_resources,
119 .init = pmc_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530120 .ops_pci = &pci_dev_ops_pci,
Nico Huber51b75ae2019-03-14 16:02:05 +0100121 .scan_bus = scan_static_bus,
Subrata Banik2153ea52017-11-22 15:38:19 +0530122};
123
124static const unsigned short pci_device_ids[] = {
125 PCI_DEVICE_ID_INTEL_SPT_LP_PMC,
V Sowmya7c150472018-01-23 14:44:45 +0530126 PCI_DEVICE_ID_INTEL_SPT_H_PMC,
Maxim Polyakov571d07d2019-08-22 13:11:32 +0300127 PCI_DEVICE_ID_INTEL_LWB_PMC,
128 PCI_DEVICE_ID_INTEL_LWB_PMC_SUPER,
V Sowmyaacc2a482018-01-23 15:27:23 +0530129 PCI_DEVICE_ID_INTEL_KBP_H_PMC,
Subrata Banik2153ea52017-11-22 15:38:19 +0530130 PCI_DEVICE_ID_INTEL_APL_PMC,
131 PCI_DEVICE_ID_INTEL_GLK_PMC,
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +0800132 PCI_DEVICE_ID_INTEL_CNP_H_PMC,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530133 PCI_DEVICE_ID_INTEL_ICP_PMC,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +0530134 PCI_DEVICE_ID_INTEL_CMP_PMC,
Gaggery Tsai12a651c2019-12-05 11:23:20 -0800135 PCI_DEVICE_ID_INTEL_CMP_H_PMC,
Ravi Sarawadi6b5bf402019-10-21 22:25:04 -0700136 PCI_DEVICE_ID_INTEL_TGP_PMC,
Tan, Lean Sheng26136092020-01-20 19:13:56 -0800137 PCI_DEVICE_ID_INTEL_MCC_PMC,
Meera Ravindranath3f4af0d2020-02-12 16:01:22 +0530138 PCI_DEVICE_ID_INTEL_JSP_PMC,
Subrata Banik2153ea52017-11-22 15:38:19 +0530139 0
140};
141
Subrata Banik88852062018-01-10 10:51:50 +0530142static const struct pci_driver pch_pmc __pci_driver = {
Subrata Banik2153ea52017-11-22 15:38:19 +0530143 .ops = &device_ops,
144 .vendor = PCI_VENDOR_ID_INTEL,
145 .devices = pci_device_ids,
146};