Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 4 | * Copyright (C) 2016 Google Inc. |
| 5 | * Copyright (C) 2018 Intel Corporation. |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 22 | #include <intelblocks/p2sb.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 23 | #include <soc/iomap.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 24 | #include <soc/p2sb.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 25 | #include <soc/pci_devs.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 26 | #include <string.h> |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 27 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 28 | #define PCH_P2SB_EPMASK(mask_number) (PCH_P2SB_EPMASK0 + ((mask_number) * 4)) |
| 29 | |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 30 | #define HIDE_BIT (1 << 0) |
| 31 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 32 | #if defined(__SIMPLE_DEVICE__) |
| 33 | static pci_devfn_t p2sb_get_device(void) |
| 34 | { |
| 35 | int devfn = PCH_DEVFN_P2SB; |
| 36 | pci_devfn_t dev = PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn)); |
| 37 | |
| 38 | if (dev == PCI_DEV_INVALID) |
| 39 | die("PCH_DEV_P2SB not found!\n"); |
| 40 | |
| 41 | return dev; |
| 42 | } |
| 43 | #else |
| 44 | static struct device *p2sb_get_device(void) |
| 45 | { |
| 46 | struct device *dev = PCH_DEV_P2SB; |
| 47 | if (!dev) |
| 48 | die("PCH_DEV_P2SB not found!\n"); |
| 49 | |
| 50 | return dev; |
| 51 | } |
| 52 | #endif |
| 53 | |
| 54 | #define P2SB_GET_DEV p2sb_get_device() |
| 55 | |
| 56 | void p2sb_enable_bar(void) |
| 57 | { |
| 58 | /* Enable PCR Base address in PCH */ |
| 59 | pci_write_config32(P2SB_GET_DEV, PCI_BASE_ADDRESS_0, P2SB_BAR); |
| 60 | pci_write_config32(P2SB_GET_DEV, PCI_BASE_ADDRESS_1, 0); |
| 61 | |
| 62 | /* Enable P2SB MSE */ |
| 63 | pci_write_config8(P2SB_GET_DEV, PCI_COMMAND, |
| 64 | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Enable decoding for HPET range. |
| 69 | * This is needed for FspMemoryInit to store and retrieve a global data |
| 70 | * pointer. |
| 71 | */ |
| 72 | void p2sb_configure_hpet(void) |
| 73 | { |
| 74 | /* |
| 75 | * Enable decoding for HPET memory address range. |
| 76 | * HPTC_OFFSET(0x60) bit 7, when set the P2SB will decode |
| 77 | * the High Performance Timer memory address range |
| 78 | * selected by bits 1:0 |
| 79 | */ |
| 80 | pci_write_config8(P2SB_GET_DEV, HPTC_OFFSET, HPTC_ADDR_ENABLE_BIT); |
| 81 | } |
| 82 | |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 83 | static void p2sb_set_hide_bit(int hide) |
| 84 | { |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 85 | const uint16_t reg = PCH_P2SB_E0 + 1; |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 86 | const uint8_t mask = HIDE_BIT; |
| 87 | uint8_t val; |
| 88 | |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 89 | val = pci_read_config8(P2SB_GET_DEV, reg); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 90 | val &= ~mask; |
| 91 | if (hide) |
| 92 | val |= mask; |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 93 | pci_write_config8(P2SB_GET_DEV, reg, val); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void p2sb_unhide(void) |
| 97 | { |
| 98 | p2sb_set_hide_bit(0); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 99 | |
| 100 | if (pci_read_config16(P2SB_GET_DEV, PCI_VENDOR_ID) != |
| 101 | PCI_VENDOR_ID_INTEL) |
| 102 | die("Unable to unhide PCH_DEV_P2SB device !\n"); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void p2sb_hide(void) |
| 106 | { |
| 107 | p2sb_set_hide_bit(1); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 108 | |
| 109 | if (pci_read_config16(P2SB_GET_DEV, PCI_VENDOR_ID) != |
| 110 | 0xFFFF) |
| 111 | die("Unable to hide PCH_DEV_P2SB device !\n"); |
| 112 | } |
| 113 | |
| 114 | static void p2sb_configure_endpoints(int epmask_id, uint32_t mask) |
| 115 | { |
| 116 | uint32_t reg32; |
| 117 | |
| 118 | reg32 = pci_read_config32(P2SB_GET_DEV, PCH_P2SB_EPMASK(epmask_id)); |
| 119 | pci_write_config32(P2SB_GET_DEV, PCH_P2SB_EPMASK(epmask_id), |
| 120 | reg32 | mask); |
| 121 | } |
| 122 | |
| 123 | static void p2sb_lock_endpoints(void) |
| 124 | { |
| 125 | uint8_t reg8; |
| 126 | |
| 127 | /* Set the "Endpoint Mask Lock!", P2SB PCI offset E2h bit[1] to 1. */ |
| 128 | reg8 = pci_read_config8(P2SB_GET_DEV, PCH_P2SB_E0 + 2); |
| 129 | pci_write_config8(P2SB_GET_DEV, PCH_P2SB_E0 + 2, |
| 130 | reg8 | P2SB_E0_MASKLOCK); |
| 131 | } |
| 132 | |
| 133 | void p2sb_disable_sideband_access(void) |
| 134 | { |
| 135 | uint32_t ep_mask[P2SB_EP_MASK_MAX_REG]; |
| 136 | int i; |
| 137 | |
| 138 | memset(ep_mask, 0, sizeof(ep_mask)); |
| 139 | |
| 140 | p2sb_soc_get_sb_mask(ep_mask, ARRAY_SIZE(ep_mask)); |
| 141 | |
| 142 | /* Remove the host accessing right to PSF register range. */ |
| 143 | for (i = 0; i < P2SB_EP_MASK_MAX_REG; i++) |
| 144 | p2sb_configure_endpoints(i, ep_mask[i]); |
| 145 | |
| 146 | p2sb_lock_endpoints(); |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void read_resources(struct device *dev) |
| 150 | { |
| 151 | /* |
| 152 | * There's only one resource on the P2SB device. It's also already |
| 153 | * manually set to a fixed address in earlier boot stages. |
| 154 | */ |
| 155 | mmio_resource(dev, PCI_BASE_ADDRESS_0, P2SB_BAR / KiB, P2SB_SIZE / KiB); |
| 156 | } |
| 157 | |
| 158 | static const struct device_operations device_ops = { |
| 159 | .read_resources = read_resources, |
| 160 | .set_resources = DEVICE_NOOP, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 161 | .ops_pci = &pci_dev_ops_pci, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static const unsigned short pci_device_ids[] = { |
| 165 | PCI_DEVICE_ID_INTEL_APL_P2SB, |
| 166 | PCI_DEVICE_ID_INTEL_GLK_P2SB, |
| 167 | PCI_DEVICE_ID_INTEL_CNL_P2SB, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 168 | PCI_DEVICE_ID_INTEL_CNP_H_P2SB, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 169 | PCI_DEVICE_ID_INTEL_ICL_P2SB, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 170 | PCI_DEVICE_ID_INTEL_CMP_P2SB, |
Lijian Zhao | a3cbbf7 | 2017-10-26 11:59:14 -0700 | [diff] [blame] | 171 | 0, |
| 172 | }; |
| 173 | |
| 174 | static const struct pci_driver pmc __pci_driver = { |
| 175 | .ops = &device_ops, |
| 176 | .vendor = PCI_VENDOR_ID_INTEL, |
| 177 | .devices = pci_device_ids, |
| 178 | }; |