blob: eaaf1252eac51db96d2b88892d56bc451def90d1 [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>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Subrata Banik2153ea52017-11-22 15:38:19 +053019#include <console/console.h>
20#include <cpu/x86/smm.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <intelblocks/pmc.h>
24#include <soc/pci_devs.h>
25
26/* SoC overrides */
27
28/* Fill up PMC resource structure inside SoC directory */
Aaron Durbin64031672018-04-21 14:45:32 -060029__weak int pmc_soc_get_resources(
Subrata Banik2153ea52017-11-22 15:38:19 +053030 struct pmc_resource_config *cfg)
31{
32 /* no-op */
33 return -1;
34}
35
36/* SoC override PMC initialization */
Aaron Durbin64031672018-04-21 14:45:32 -060037__weak void pmc_soc_init(struct device *dev)
Subrata Banik2153ea52017-11-22 15:38:19 +053038{
39 /* no-op */
40}
41
42static void pch_pmc_add_new_resource(struct device *dev,
43 uint8_t offset, uintptr_t base, size_t size,
44 unsigned long flags)
45{
46 struct resource *res;
47 res = new_resource(dev, offset);
48 res->base = base;
49 res->size = size;
50 res->flags = flags;
51}
52
53static void pch_pmc_add_mmio_resources(struct device *dev,
54 const struct pmc_resource_config *cfg)
55{
56 pch_pmc_add_new_resource(dev, cfg->pwrmbase_offset,
57 cfg->pwrmbase_addr, cfg->pwrmbase_size,
58 IORESOURCE_MEM | IORESOURCE_ASSIGNED |
59 IORESOURCE_FIXED | IORESOURCE_RESERVE);
60}
61
62static void pch_pmc_add_io_resources(struct device *dev,
63 const struct pmc_resource_config *cfg)
64{
65 pch_pmc_add_new_resource(dev, cfg->abase_offset,
66 cfg->abase_addr, cfg->abase_size,
67 IORESOURCE_IO | IORESOURCE_ASSIGNED |
68 IORESOURCE_FIXED);
Julius Wernercd49cce2019-03-05 16:53:33 -080069 if (CONFIG(PMC_INVALID_READ_AFTER_WRITE)) {
Hannah Williams1177bf52017-12-13 12:44:26 -080070 /*
71 * The ACPI IO BAR (offset 0x20) is not PCI compliant. We've
72 * observed cases where the BAR reads back as 0, but the IO
73 * window is open. This also means that it will not respond
74 * to PCI probing.
75 */
76 pci_write_config16(dev, cfg->abase_offset, cfg->abase_addr);
77 /*
78 * In pci_dev_enable_resources, reading IO SPACE ACCESS bit in
79 * STATUSCOMMAND register does not read back the written
80 * value correctly, hence IO access gets disabled. This is
81 * seen in some PMC devices, hence this code makes sure
82 * IO access is available.
83 */
84 dev->command |= PCI_COMMAND_IO;
85 }
Subrata Banik2153ea52017-11-22 15:38:19 +053086}
87
88static void pch_pmc_read_resources(struct device *dev)
89{
90 struct pmc_resource_config pmc_cfg;
91 struct pmc_resource_config *config = &pmc_cfg;
92
93 if (pmc_soc_get_resources(config) < 0)
Keith Short15588b02019-05-09 11:40:34 -060094 die_with_post_code(POST_HW_INIT_FAILURE,
95 "Unable to get PMC controller resource information!");
Subrata Banik2153ea52017-11-22 15:38:19 +053096
97 /* Get the normal PCI resources of this device. */
98 pci_dev_read_resources(dev);
99
100 /* Add non-standard MMIO resources. */
101 pch_pmc_add_mmio_resources(dev, config);
102
103 /* Add IO resources. */
104 pch_pmc_add_io_resources(dev, config);
105}
106
107void pmc_set_acpi_mode(void)
108{
Julius Wernercd49cce2019-03-05 16:53:33 -0800109 if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) {
Subrata Banik2153ea52017-11-22 15:38:19 +0530110 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
111 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
112 printk(BIOS_DEBUG, "done.\n");
113 }
114}
115
116static struct device_operations device_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100117 .read_resources = pch_pmc_read_resources,
118 .set_resources = pci_dev_set_resources,
119 .enable_resources = pci_dev_enable_resources,
120 .init = pmc_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530121 .ops_pci = &pci_dev_ops_pci,
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100122 .scan_bus = scan_lpc_bus,
Subrata Banik2153ea52017-11-22 15:38:19 +0530123};
124
125static const unsigned short pci_device_ids[] = {
126 PCI_DEVICE_ID_INTEL_SPT_LP_PMC,
V Sowmya7c150472018-01-23 14:44:45 +0530127 PCI_DEVICE_ID_INTEL_SPT_H_PMC,
V Sowmyaacc2a482018-01-23 15:27:23 +0530128 PCI_DEVICE_ID_INTEL_KBP_H_PMC,
Subrata Banik2153ea52017-11-22 15:38:19 +0530129 PCI_DEVICE_ID_INTEL_APL_PMC,
130 PCI_DEVICE_ID_INTEL_GLK_PMC,
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +0800131 PCI_DEVICE_ID_INTEL_CNP_H_PMC,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530132 PCI_DEVICE_ID_INTEL_ICP_PMC,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +0530133 PCI_DEVICE_ID_INTEL_CMP_PMC,
Subrata Banik2153ea52017-11-22 15:38:19 +0530134 0
135};
136
Subrata Banik88852062018-01-10 10:51:50 +0530137static const struct pci_driver pch_pmc __pci_driver = {
Subrata Banik2153ea52017-11-22 15:38:19 +0530138 .ops = &device_ops,
139 .vendor = PCI_VENDOR_ID_INTEL,
140 .devices = pci_device_ids,
141};