blob: 6a68dff13a0bc17318b475db7ed3f5c1335a87d6 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi2efc8802012-11-06 11:03:53 +01002
3#include <stdint.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01004
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01006#include <device/pci_def.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01007
8#include "gm45.h"
9
Elyes HAOUASeb9e63f2022-01-25 11:51:43 +010010void init_iommu(void)
Patrick Georgi2efc8802012-11-06 11:03:53 +010011{
12 /* FIXME: proper test? */
13 int me_active = pci_read_config8(PCI_DEV(0, 3, 0), PCI_CLASS_REVISION) != 0xff;
14 int stepping = pci_read_config8(PCI_DEV(0, 0, 0), PCI_CLASS_REVISION);
15
Angel Pons3f1f8ef2021-03-27 13:52:43 +010016 mchbar_write32(0x28, IOMMU_BASE1 | 1); /* HDA @ 0:1b.0 */
Patrick Georgi2efc8802012-11-06 11:03:53 +010017 if (stepping != STEPPING_B2) {
18 /* The official workaround is to run SMM every 64ms.
19 The only winning move is not to play. */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010020 mchbar_write32(0x18, IOMMU_BASE2 | 1); /* IGD @ 0:2.0-1 */
Patrick Georgi2efc8802012-11-06 11:03:53 +010021 } else {
22 /* write-once, so lock it down */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010023 mchbar_write32(0x18, 0); /* disable IOMMU for IGD @ 0:2.0-1 */
Patrick Georgi2efc8802012-11-06 11:03:53 +010024 }
25 if (me_active) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010026 mchbar_write32(0x10, IOMMU_BASE3 | 1); /* ME @ 0:3.0-3 */
Damien Zammit88af3722016-08-27 00:35:48 +100027 } else {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010028 mchbar_write32(0x10, 0); /* disable IOMMU for ME */
Patrick Georgi2efc8802012-11-06 11:03:53 +010029 }
Angel Pons3f1f8ef2021-03-27 13:52:43 +010030 mchbar_write32(0x20, IOMMU_BASE4 | 1); /* all other DMA sources */
Patrick Georgi2efc8802012-11-06 11:03:53 +010031
Patrick Georgi2efc8802012-11-06 11:03:53 +010032 if (stepping == STEPPING_B3) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010033 mchbar_setbits8(0xffc, 1 << 4);
Elyes HAOUASd13bd052020-04-22 16:39:20 +020034 const pci_devfn_t peg = PCI_DEV(0, 1, 0);
Angel Ponsb0535832020-06-08 11:46:58 +020035
Patrick Georgi2efc8802012-11-06 11:03:53 +010036 /* FIXME: proper test? */
Angel Ponsb0535832020-06-08 11:46:58 +020037 if (pci_read_config8(peg, PCI_CLASS_REVISION) != 0xff)
38 pci_or_config32(peg, 0xfc, 1 << 15);
Patrick Georgi2efc8802012-11-06 11:03:53 +010039 }
40
41 /* final */
Angel Pons3f1f8ef2021-03-27 13:52:43 +010042 mchbar_setbits8(0x94, 1 << 3);
Patrick Georgi2efc8802012-11-06 11:03:53 +010043}