Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Subrata Banik | 8885206 | 2018-01-10 10:51:50 +0530 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Intel Corporation. |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 5 | * |
| 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älkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 18 | #include <device/pci_ops.h> |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 19 | #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 Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 29 | __weak int pmc_soc_get_resources( |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 30 | struct pmc_resource_config *cfg) |
| 31 | { |
| 32 | /* no-op */ |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | /* SoC override PMC initialization */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 37 | __weak void pmc_soc_init(struct device *dev) |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 38 | { |
| 39 | /* no-op */ |
| 40 | } |
| 41 | |
| 42 | static 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 | |
| 53 | static 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 | |
| 62 | static 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 69 | if (CONFIG(PMC_INVALID_READ_AFTER_WRITE)) { |
Hannah Williams | 1177bf5 | 2017-12-13 12:44:26 -0800 | [diff] [blame] | 70 | /* |
| 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 Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static 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 Short | 15588b0 | 2019-05-09 11:40:34 -0600 | [diff] [blame] | 94 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 95 | "Unable to get PMC controller resource information!"); |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 96 | |
| 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 | |
| 107 | void pmc_set_acpi_mode(void) |
| 108 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 109 | if (CONFIG(HAVE_SMI_HANDLER) && !acpi_is_wakeup_s3()) { |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 110 | 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 | |
| 116 | static struct device_operations device_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 117 | .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 Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 121 | .ops_pci = &pci_dev_ops_pci, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame^] | 122 | .scan_bus = scan_static_bus, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static const unsigned short pci_device_ids[] = { |
| 126 | PCI_DEVICE_ID_INTEL_SPT_LP_PMC, |
V Sowmya | 7c15047 | 2018-01-23 14:44:45 +0530 | [diff] [blame] | 127 | PCI_DEVICE_ID_INTEL_SPT_H_PMC, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 128 | PCI_DEVICE_ID_INTEL_LWB_PMC, |
| 129 | PCI_DEVICE_ID_INTEL_LWB_PMC_SUPER, |
V Sowmya | acc2a48 | 2018-01-23 15:27:23 +0530 | [diff] [blame] | 130 | PCI_DEVICE_ID_INTEL_KBP_H_PMC, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 131 | PCI_DEVICE_ID_INTEL_APL_PMC, |
| 132 | PCI_DEVICE_ID_INTEL_GLK_PMC, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 133 | PCI_DEVICE_ID_INTEL_CNP_H_PMC, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 134 | PCI_DEVICE_ID_INTEL_ICP_PMC, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 135 | PCI_DEVICE_ID_INTEL_CMP_PMC, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 136 | 0 |
| 137 | }; |
| 138 | |
Subrata Banik | 8885206 | 2018-01-10 10:51:50 +0530 | [diff] [blame] | 139 | static const struct pci_driver pch_pmc __pci_driver = { |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 140 | .ops = &device_ops, |
| 141 | .vendor = PCI_VENDOR_ID_INTEL, |
| 142 | .devices = pci_device_ids, |
| 143 | }; |