Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <string.h> |
| 5 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 7 | #include <device/pci_def.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 8 | |
| 9 | #include "gm45.h" |
| 10 | |
Elyes HAOUAS | eb9e63f | 2022-01-25 11:51:43 +0100 | [diff] [blame] | 11 | void init_iommu(void) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 12 | { |
| 13 | /* FIXME: proper test? */ |
| 14 | int me_active = pci_read_config8(PCI_DEV(0, 3, 0), PCI_CLASS_REVISION) != 0xff; |
| 15 | int stepping = pci_read_config8(PCI_DEV(0, 0, 0), PCI_CLASS_REVISION); |
| 16 | |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 17 | mchbar_write32(0x28, IOMMU_BASE1 | 1); /* HDA @ 0:1b.0 */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 18 | if (stepping != STEPPING_B2) { |
| 19 | /* The official workaround is to run SMM every 64ms. |
| 20 | The only winning move is not to play. */ |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 21 | mchbar_write32(0x18, IOMMU_BASE2 | 1); /* IGD @ 0:2.0-1 */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 22 | } else { |
| 23 | /* write-once, so lock it down */ |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 24 | mchbar_write32(0x18, 0); /* disable IOMMU for IGD @ 0:2.0-1 */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 25 | } |
| 26 | if (me_active) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 27 | mchbar_write32(0x10, IOMMU_BASE3 | 1); /* ME @ 0:3.0-3 */ |
Damien Zammit | 88af372 | 2016-08-27 00:35:48 +1000 | [diff] [blame] | 28 | } else { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 29 | mchbar_write32(0x10, 0); /* disable IOMMU for ME */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 30 | } |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 31 | mchbar_write32(0x20, IOMMU_BASE4 | 1); /* all other DMA sources */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 32 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 33 | if (stepping == STEPPING_B3) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 34 | mchbar_setbits8(0xffc, 1 << 4); |
Elyes HAOUAS | d13bd05 | 2020-04-22 16:39:20 +0200 | [diff] [blame] | 35 | const pci_devfn_t peg = PCI_DEV(0, 1, 0); |
Angel Pons | b053583 | 2020-06-08 11:46:58 +0200 | [diff] [blame] | 36 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 37 | /* FIXME: proper test? */ |
Angel Pons | b053583 | 2020-06-08 11:46:58 +0200 | [diff] [blame] | 38 | if (pci_read_config8(peg, PCI_CLASS_REVISION) != 0xff) |
| 39 | pci_or_config32(peg, 0xfc, 1 << 15); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* final */ |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 43 | mchbar_setbits8(0x94, 1 << 3); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 44 | } |