Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2017 Intel Corporation. |
| 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> |
| 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 | |
| 41 | static 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 | |
| 52 | static 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 | |
| 61 | static 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 | |
| 70 | static 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 | |
| 88 | void 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 | |
| 97 | static 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 Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 102 | .ops_pci = &pci_dev_ops_pci, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 103 | .scan_bus = &scan_lpc_bus, |
| 104 | }; |
| 105 | |
| 106 | static 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 | |
| 114 | static const struct pci_driver pch_lpc __pci_driver = { |
| 115 | .ops = &device_ops, |
| 116 | .vendor = PCI_VENDOR_ID_INTEL, |
| 117 | .devices = pci_device_ids, |
| 118 | }; |