blob: 24f3a69d0e468f1b1d24b6705308c8b31daf9ff1 [file] [log] [blame]
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -07001/*
2 * This file is part of the coreboot project.
3 *
Subrata Banik7837c202018-05-07 17:13:40 +05304 * Copyright (C) 2016 Google Inc.
5 * Copyright (C) 2018 Intel Corporation.
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -07006 *
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 Banik7837c202018-05-07 17:13:40 +053022#include <intelblocks/p2sb.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070023#include <soc/iomap.h>
Subrata Banik7837c202018-05-07 17:13:40 +053024#include <soc/p2sb.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070025#include <soc/pci_devs.h>
Subrata Banik7837c202018-05-07 17:13:40 +053026#include <string.h>
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070027
Subrata Banik7837c202018-05-07 17:13:40 +053028#define PCH_P2SB_EPMASK(mask_number) (PCH_P2SB_EPMASK0 + ((mask_number) * 4))
29
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070030#define HIDE_BIT (1 << 0)
31
Subrata Banik7837c202018-05-07 17:13:40 +053032#if defined(__SIMPLE_DEVICE__)
33static 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
44static 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
56void 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 */
72void 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 Zhaoa3cbbf72017-10-26 11:59:14 -070083static void p2sb_set_hide_bit(int hide)
84{
Subrata Banik7837c202018-05-07 17:13:40 +053085 const uint16_t reg = PCH_P2SB_E0 + 1;
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070086 const uint8_t mask = HIDE_BIT;
87 uint8_t val;
88
Subrata Banik7837c202018-05-07 17:13:40 +053089 val = pci_read_config8(P2SB_GET_DEV, reg);
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070090 val &= ~mask;
91 if (hide)
92 val |= mask;
Subrata Banik7837c202018-05-07 17:13:40 +053093 pci_write_config8(P2SB_GET_DEV, reg, val);
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -070094}
95
96void p2sb_unhide(void)
97{
98 p2sb_set_hide_bit(0);
Subrata Banik7837c202018-05-07 17:13:40 +053099
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 Zhaoa3cbbf72017-10-26 11:59:14 -0700103}
104
105void p2sb_hide(void)
106{
107 p2sb_set_hide_bit(1);
Subrata Banik7837c202018-05-07 17:13:40 +0530108
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
114static 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
123static 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
133void 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 Zhaoa3cbbf72017-10-26 11:59:14 -0700147}
148
149static 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
158static const struct device_operations device_ops = {
159 .read_resources = read_resources,
160 .set_resources = DEVICE_NOOP,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530161 .ops_pci = &pci_dev_ops_pci,
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700162};
163
164static 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 praneshe26c4a42018-09-20 03:49:45 +0800168 PCI_DEVICE_ID_INTEL_CNP_H_P2SB,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530169 PCI_DEVICE_ID_INTEL_ICL_P2SB,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +0530170 PCI_DEVICE_ID_INTEL_CMP_P2SB,
Lijian Zhaoa3cbbf72017-10-26 11:59:14 -0700171 0,
172};
173
174static const struct pci_driver pmc __pci_driver = {
175 .ops = &device_ops,
176 .vendor = PCI_VENDOR_ID_INTEL,
177 .devices = pci_device_ids,
178};