2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <console/console.h>
22 #include <device/pci_def.h>
24 #include <device/device.h>
25 #include <device/pci.h>
30 int pch_silicon_revision(void)
32 static int pch_revision_id
= -1;
34 #ifdef __SIMPLE_DEVICE__
36 dev
= PCI_DEV(0, 0x1f, 0);
39 dev
= dev_find_slot(0, PCI_DEVFN(0x1f, 0));
42 if (pch_revision_id
< 0)
43 pch_revision_id
= pci_read_config8(dev
, PCI_REVISION_ID
);
44 return pch_revision_id
;
47 int pch_silicon_type(void)
49 static int pch_type
= -1;
51 #ifdef __SIMPLE_DEVICE__
53 dev
= PCI_DEV(0, 0x1f, 0);
56 dev
= dev_find_slot(0, PCI_DEVFN(0x1f, 0));
60 pch_type
= pci_read_config8(dev
, PCI_DEVICE_ID
+ 1);
64 int pch_silicon_supported(int type
, int rev
)
66 int cur_type
= pch_silicon_type();
67 int cur_rev
= pch_silicon_revision();
71 /* CougarPoint minimum revision */
72 if (cur_type
== PCH_TYPE_CPT
&& cur_rev
>= rev
)
74 /* PantherPoint any revision */
75 if (cur_type
== PCH_TYPE_PPT
)
80 /* PantherPoint minimum revision */
81 if (cur_type
== PCH_TYPE_PPT
&& cur_rev
>= rev
)
89 #define IOBP_RETRY 1000
90 static inline int iobp_poll(void)
92 unsigned try = IOBP_RETRY
;
102 printk(BIOS_ERR
, "IOBP timeout\n");
106 void pch_iobp_update(u32 address
, u32 andvalue
, u32 orvalue
)
110 /* Set the address */
111 RCBA32(IOBPIRI
) = address
;
114 if (pch_silicon_supported(PCH_TYPE_CPT
, PCH_STEP_B0
))
115 RCBA32(IOBPS
) = IOBPS_RW_BX
;
117 RCBA32(IOBPS
) = IOBPS_READ_AX
;
122 data
= RCBA32(IOBPD
);
126 /* Check for successful transaction */
127 if ((RCBA32(IOBPS
) & 0x6) != 0) {
128 printk(BIOS_ERR
, "IOBP read 0x%08x failed\n", address
);
132 /* Update the data */
137 if (pch_silicon_supported(PCH_TYPE_CPT
, PCH_STEP_B0
))
138 RCBA32(IOBPS
) = IOBPS_RW_BX
;
140 RCBA32(IOBPS
) = IOBPS_WRITE_AX
;
144 /* Write IOBP data */
145 RCBA32(IOBPD
) = data
;
151 /* Set bit in Function Disble register to hide this device */
152 static void pch_hide_devfn(unsigned devfn
)
155 case PCI_DEVFN(22, 0): /* MEI #1 */
156 RCBA32_OR(FD2
, PCH_DISABLE_MEI1
);
158 case PCI_DEVFN(22, 1): /* MEI #2 */
159 RCBA32_OR(FD2
, PCH_DISABLE_MEI2
);
161 case PCI_DEVFN(22, 2): /* IDE-R */
162 RCBA32_OR(FD2
, PCH_DISABLE_IDER
);
164 case PCI_DEVFN(22, 3): /* KT */
165 RCBA32_OR(FD2
, PCH_DISABLE_KT
);
167 case PCI_DEVFN(25, 0): /* Gigabit Ethernet */
168 RCBA32_OR(BUC
, PCH_DISABLE_GBE
);
170 case PCI_DEVFN(26, 0): /* EHCI #2 */
171 RCBA32_OR(FD
, PCH_DISABLE_EHCI2
);
173 case PCI_DEVFN(27, 0): /* HD Audio Controller */
174 RCBA32_OR(FD
, PCH_DISABLE_HD_AUDIO
);
176 case PCI_DEVFN(28, 0): /* PCI Express Root Port 1 */
177 case PCI_DEVFN(28, 1): /* PCI Express Root Port 2 */
178 case PCI_DEVFN(28, 2): /* PCI Express Root Port 3 */
179 case PCI_DEVFN(28, 3): /* PCI Express Root Port 4 */
180 case PCI_DEVFN(28, 4): /* PCI Express Root Port 5 */
181 case PCI_DEVFN(28, 5): /* PCI Express Root Port 6 */
182 case PCI_DEVFN(28, 6): /* PCI Express Root Port 7 */
183 case PCI_DEVFN(28, 7): /* PCI Express Root Port 8 */
184 RCBA32_OR(FD
, PCH_DISABLE_PCIE(PCI_FUNC(devfn
)));
186 case PCI_DEVFN(29, 0): /* EHCI #1 */
187 RCBA32_OR(FD
, PCH_DISABLE_EHCI1
);
189 case PCI_DEVFN(30, 0): /* PCI-to-PCI Bridge */
190 RCBA32_OR(FD
, PCH_DISABLE_P2P
);
192 case PCI_DEVFN(31, 0): /* LPC */
193 RCBA32_OR(FD
, PCH_DISABLE_LPC
);
195 case PCI_DEVFN(31, 2): /* SATA #1 */
196 RCBA32_OR(FD
, PCH_DISABLE_SATA1
);
198 case PCI_DEVFN(31, 3): /* SMBUS */
199 RCBA32_OR(FD
, PCH_DISABLE_SMBUS
);
201 case PCI_DEVFN(31, 5): /* SATA #22 */
202 RCBA32_OR(FD
, PCH_DISABLE_SATA2
);
204 case PCI_DEVFN(31, 6): /* Thermal Subsystem */
205 RCBA32_OR(FD
, PCH_DISABLE_THERMAL
);
210 /* Check if any port in set X to X+3 is enabled */
211 static int pch_pcie_check_set_enabled(struct device
*dev
)
215 int dev_func
= PCI_FUNC(dev
->path
.pci
.devfn
);
217 printk(BIOS_DEBUG
, "%s: check set enabled\n", dev_path(dev
));
219 /* Go through static device tree list of devices
220 * because enumeration is still in progress */
221 for (port
= all_devices
; port
; port
= port
->next
) {
222 /* Only care about PCIe root ports */
223 if (PCI_SLOT(port
->path
.pci
.devfn
) !=
224 PCI_SLOT(dev
->path
.pci
.devfn
))
227 /* Check if port is in range and enabled */
228 port_func
= PCI_FUNC(port
->path
.pci
.devfn
);
229 if (port_func
>= dev_func
&&
230 port_func
< (dev_func
+ 4) &&
235 /* None of the ports in this set are enabled */
239 /* RPFN is a write-once register so keep a copy until it is written */
242 /* Swap function numbers assigned to two PCIe Root Ports */
243 static void pch_pcie_function_swap(u8 old_fn
, u8 new_fn
)
245 u32 old_rpfn
= new_rpfn
;
247 printk(BIOS_DEBUG
, "PCH: Remap PCIe function %d to %d\n",
250 new_rpfn
&= ~(RPFN_FNMASK(old_fn
) | RPFN_FNMASK(new_fn
));
252 /* Old function set to new function and disabled */
253 new_rpfn
|= RPFN_FNSET(old_fn
, RPFN_FNGET(old_rpfn
, new_fn
));
254 new_rpfn
|= RPFN_FNSET(new_fn
, RPFN_FNGET(old_rpfn
, old_fn
));
257 /* Update devicetree with new Root Port function number assignment */
258 static void pch_pcie_devicetree_update(
259 struct southbridge_intel_bd82x6x_config
*config
)
264 * hotplug map should also be updated along with their
267 u8 new_hotplug_map
[sizeof(config
->pcie_hotplug_map
)];
270 * Slots that didn't move need the hotplug setting copied too,
271 * so "new_hotplug_map" is initialized with the values of the old map.
273 memcpy(new_hotplug_map
, config
->pcie_hotplug_map
,
274 sizeof(new_hotplug_map
));
276 /* Update the function numbers in the static devicetree */
277 for (dev
= all_devices
; dev
; dev
= dev
->next
) {
280 /* Only care about PCH PCIe root ports */
281 if (PCI_SLOT(dev
->path
.pci
.devfn
) !=
285 /* Determine the new devfn for this port */
286 new_devfn
= PCI_DEVFN(PCH_PCIE_DEV_SLOT
,
288 PCI_FUNC(dev
->path
.pci
.devfn
)));
290 if (dev
->path
.pci
.devfn
!= new_devfn
) {
292 "PCH: PCIe map %02x.%1x -> %02x.%1x\n",
293 PCI_SLOT(dev
->path
.pci
.devfn
),
294 PCI_FUNC(dev
->path
.pci
.devfn
),
295 PCI_SLOT(new_devfn
), PCI_FUNC(new_devfn
));
298 * Copy the flag to its new position along with
299 * the corresponding port
301 new_hotplug_map
[PCI_FUNC(new_devfn
)] =
302 config
->pcie_hotplug_map
303 [PCI_FUNC(dev
->path
.pci
.devfn
)];
305 dev
->path
.pci
.devfn
= new_devfn
;
309 /* Copy the updated map back to its place */
310 memcpy(config
->pcie_hotplug_map
, new_hotplug_map
,
311 sizeof(new_hotplug_map
));
314 /* Special handling for PCIe Root Port devices */
315 static void pch_pcie_enable(struct device
*dev
)
317 struct southbridge_intel_bd82x6x_config
*config
= dev
->chip_info
;
324 * Save a copy of the Root Port Function Number map when
325 * starting to walk the list of PCIe Root Ports so it can
326 * be updated locally and written out when the last port
327 * has been processed.
329 if (PCI_FUNC(dev
->path
.pci
.devfn
) == 0) {
330 new_rpfn
= RCBA32(RPFN
);
333 * Enable Root Port coalescing if the first port is disabled
334 * or the other devices will not be enumerated by the OS.
337 config
->pcie_port_coalesce
= 1;
339 if (config
->pcie_port_coalesce
)
341 "PCH: PCIe Root Port coalescing is enabled\n");
345 printk(BIOS_DEBUG
, "%s: Disabling device\n", dev_path(dev
));
348 * PCIE Power Savings for PantherPoint and CougarPoint/B1+
350 * If PCIe 0-3 disabled set Function 0 0xE2[0] = 1
351 * If PCIe 4-7 disabled set Function 4 0xE2[0] = 1
353 * This check is done here instead of pcie driver
354 * because the pcie driver enable() handler is not
355 * called unless the device is enabled.
357 if ((PCI_FUNC(dev
->path
.pci
.devfn
) == 0 ||
358 PCI_FUNC(dev
->path
.pci
.devfn
) == 4)) {
359 /* Handle workaround for PPT and CPT/B1+ */
360 if (pch_silicon_supported(PCH_TYPE_CPT
, PCH_STEP_B1
) &&
361 !pch_pcie_check_set_enabled(dev
)) {
362 u8 reg8
= pci_read_config8(dev
, 0xe2);
364 pci_write_config8(dev
, 0xe2, reg8
);
368 * Enable Clock Gating for shared PCIe resources
369 * before disabling this particular port.
371 pci_write_config8(dev
, 0xe1, 0x3c);
374 /* Ensure memory, io, and bus master are all disabled */
375 reg32
= pci_read_config32(dev
, PCI_COMMAND
);
376 reg32
&= ~(PCI_COMMAND_MASTER
|
377 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
);
378 pci_write_config32(dev
, PCI_COMMAND
, reg32
);
380 /* Do not claim downstream transactions for PCIe ports */
381 new_rpfn
|= RPFN_HIDE(PCI_FUNC(dev
->path
.pci
.devfn
));
383 /* Hide this device if possible */
384 pch_hide_devfn(dev
->path
.pci
.devfn
);
389 * Check if there is a lower disabled port to swap with this
390 * port in order to maintain linear order starting at zero.
392 if (config
->pcie_port_coalesce
) {
393 for (fn
=0; fn
< PCI_FUNC(dev
->path
.pci
.devfn
); fn
++) {
394 if (!(new_rpfn
& RPFN_HIDE(fn
)))
397 /* Swap places with this function */
398 pch_pcie_function_swap(
399 PCI_FUNC(dev
->path
.pci
.devfn
), fn
);
405 reg32
= pci_read_config32(dev
, PCI_COMMAND
);
406 reg32
|= PCI_COMMAND_SERR
;
407 pci_write_config32(dev
, PCI_COMMAND
, reg32
);
411 * When processing the last PCIe root port we can now
412 * update the Root Port Function Number and Hide register.
414 if (PCI_FUNC(dev
->path
.pci
.devfn
) == 7) {
415 printk(BIOS_SPEW
, "PCH: RPFN 0x%08x -> 0x%08x\n",
416 RCBA32(RPFN
), new_rpfn
);
417 RCBA32(RPFN
) = new_rpfn
;
419 /* Update static devictree with new function numbers */
420 if (config
->pcie_port_coalesce
)
421 pch_pcie_devicetree_update(config
);
425 void pch_enable(struct device
*dev
)
429 /* PCH PCIe Root Ports get special handling */
430 if (PCI_SLOT(dev
->path
.pci
.devfn
) == PCH_PCIE_DEV_SLOT
)
431 return pch_pcie_enable(dev
);
434 printk(BIOS_DEBUG
, "%s: Disabling device\n", dev_path(dev
));
436 /* Ensure memory, io, and bus master are all disabled */
437 reg32
= pci_read_config32(dev
, PCI_COMMAND
);
438 reg32
&= ~(PCI_COMMAND_MASTER
|
439 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
);
440 pci_write_config32(dev
, PCI_COMMAND
, reg32
);
442 /* Hide this device if possible */
443 pch_hide_devfn(dev
->path
.pci
.devfn
);
446 reg32
= pci_read_config32(dev
, PCI_COMMAND
);
447 reg32
|= PCI_COMMAND_SERR
;
448 pci_write_config32(dev
, PCI_COMMAND
, reg32
);
452 struct chip_operations southbridge_intel_bd82x6x_ops
= {
453 CHIP_NAME("Intel Series 6/7 (Cougar Point/Panther Point) Southbridge")
454 .enable_dev
= pch_enable
,