diff options
| -rw-r--r-- | arch/x86/include/asm/amd_iommu_types.h | 21 | ||||
| -rw-r--r-- | arch/x86/kernel/amd_iommu_init.c | 122 |
2 files changed, 123 insertions, 20 deletions
diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h index 08616180deaf..bdd20c8891e8 100644 --- a/arch/x86/include/asm/amd_iommu_types.h +++ b/arch/x86/include/asm/amd_iommu_types.h | |||
| @@ -416,13 +416,22 @@ struct amd_iommu { | |||
| 416 | struct dma_ops_domain *default_dom; | 416 | struct dma_ops_domain *default_dom; |
| 417 | 417 | ||
| 418 | /* | 418 | /* |
| 419 | * This array is required to work around a potential BIOS bug. | 419 | * We can't rely on the BIOS to restore all values on reinit, so we |
| 420 | * The BIOS may miss to restore parts of the PCI configuration | 420 | * need to stash them |
| 421 | * space when the system resumes from S3. The result is that the | ||
| 422 | * IOMMU does not execute commands anymore which leads to system | ||
| 423 | * failure. | ||
| 424 | */ | 421 | */ |
| 425 | u32 cache_cfg[4]; | 422 | |
| 423 | /* The iommu BAR */ | ||
| 424 | u32 stored_addr_lo; | ||
| 425 | u32 stored_addr_hi; | ||
| 426 | |||
| 427 | /* | ||
| 428 | * Each iommu has 6 l1s, each of which is documented as having 0x12 | ||
| 429 | * registers | ||
| 430 | */ | ||
| 431 | u32 stored_l1[6][0x12]; | ||
| 432 | |||
| 433 | /* The l2 indirect registers */ | ||
| 434 | u32 stored_l2[0x83]; | ||
| 426 | }; | 435 | }; |
| 427 | 436 | ||
| 428 | /* | 437 | /* |
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c index 5a170cbbbed8..44710d86a431 100644 --- a/arch/x86/kernel/amd_iommu_init.c +++ b/arch/x86/kernel/amd_iommu_init.c | |||
| @@ -194,6 +194,39 @@ static inline unsigned long tbl_size(int entry_size) | |||
| 194 | return 1UL << shift; | 194 | return 1UL << shift; |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | /* Access to l1 and l2 indexed register spaces */ | ||
| 198 | |||
| 199 | static u32 iommu_read_l1(struct amd_iommu *iommu, u16 l1, u8 address) | ||
| 200 | { | ||
| 201 | u32 val; | ||
| 202 | |||
| 203 | pci_write_config_dword(iommu->dev, 0xf8, (address | l1 << 16)); | ||
| 204 | pci_read_config_dword(iommu->dev, 0xfc, &val); | ||
| 205 | return val; | ||
| 206 | } | ||
| 207 | |||
| 208 | static void iommu_write_l1(struct amd_iommu *iommu, u16 l1, u8 address, u32 val) | ||
| 209 | { | ||
| 210 | pci_write_config_dword(iommu->dev, 0xf8, (address | l1 << 16 | 1 << 31)); | ||
| 211 | pci_write_config_dword(iommu->dev, 0xfc, val); | ||
| 212 | pci_write_config_dword(iommu->dev, 0xf8, (address | l1 << 16)); | ||
| 213 | } | ||
| 214 | |||
| 215 | static u32 iommu_read_l2(struct amd_iommu *iommu, u8 address) | ||
| 216 | { | ||
| 217 | u32 val; | ||
| 218 | |||
| 219 | pci_write_config_dword(iommu->dev, 0xf0, address); | ||
| 220 | pci_read_config_dword(iommu->dev, 0xf4, &val); | ||
| 221 | return val; | ||
| 222 | } | ||
| 223 | |||
| 224 | static void iommu_write_l2(struct amd_iommu *iommu, u8 address, u32 val) | ||
| 225 | { | ||
| 226 | pci_write_config_dword(iommu->dev, 0xf0, (address | 1 << 8)); | ||
| 227 | pci_write_config_dword(iommu->dev, 0xf4, val); | ||
| 228 | } | ||
| 229 | |||
| 197 | /**************************************************************************** | 230 | /**************************************************************************** |
| 198 | * | 231 | * |
| 199 | * AMD IOMMU MMIO register space handling functions | 232 | * AMD IOMMU MMIO register space handling functions |
| @@ -619,6 +652,7 @@ static void __init init_iommu_from_pci(struct amd_iommu *iommu) | |||
| 619 | { | 652 | { |
| 620 | int cap_ptr = iommu->cap_ptr; | 653 | int cap_ptr = iommu->cap_ptr; |
| 621 | u32 range, misc; | 654 | u32 range, misc; |
| 655 | int i, j; | ||
| 622 | 656 | ||
| 623 | pci_read_config_dword(iommu->dev, cap_ptr + MMIO_CAP_HDR_OFFSET, | 657 | pci_read_config_dword(iommu->dev, cap_ptr + MMIO_CAP_HDR_OFFSET, |
| 624 | &iommu->cap); | 658 | &iommu->cap); |
| @@ -633,12 +667,29 @@ static void __init init_iommu_from_pci(struct amd_iommu *iommu) | |||
| 633 | MMIO_GET_LD(range)); | 667 | MMIO_GET_LD(range)); |
| 634 | iommu->evt_msi_num = MMIO_MSI_NUM(misc); | 668 | iommu->evt_msi_num = MMIO_MSI_NUM(misc); |
| 635 | 669 | ||
| 636 | if (is_rd890_iommu(iommu->dev)) { | 670 | if (!is_rd890_iommu(iommu->dev)) |
| 637 | pci_read_config_dword(iommu->dev, 0xf0, &iommu->cache_cfg[0]); | 671 | return; |
| 638 | pci_read_config_dword(iommu->dev, 0xf4, &iommu->cache_cfg[1]); | 672 | |
| 639 | pci_read_config_dword(iommu->dev, 0xf8, &iommu->cache_cfg[2]); | 673 | /* |
| 640 | pci_read_config_dword(iommu->dev, 0xfc, &iommu->cache_cfg[3]); | 674 | * Some rd890 systems may not be fully reconfigured by the BIOS, so |
| 641 | } | 675 | * it's necessary for us to store this information so it can be |
| 676 | * reprogrammed on resume | ||
| 677 | */ | ||
| 678 | |||
| 679 | pci_read_config_dword(iommu->dev, iommu->cap_ptr + 4, | ||
| 680 | &iommu->stored_addr_lo); | ||
| 681 | pci_read_config_dword(iommu->dev, iommu->cap_ptr + 8, | ||
| 682 | &iommu->stored_addr_hi); | ||
| 683 | |||
| 684 | /* Low bit locks writes to configuration space */ | ||
| 685 | iommu->stored_addr_lo &= ~1; | ||
| 686 | |||
| 687 | for (i = 0; i < 6; i++) | ||
| 688 | for (j = 0; j < 0x12; j++) | ||
| 689 | iommu->stored_l1[i][j] = iommu_read_l1(iommu, i, j); | ||
| 690 | |||
| 691 | for (i = 0; i < 0x83; i++) | ||
| 692 | iommu->stored_l2[i] = iommu_read_l2(iommu, i); | ||
| 642 | } | 693 | } |
| 643 | 694 | ||
| 644 | /* | 695 | /* |
| @@ -1127,14 +1178,53 @@ static void iommu_init_flags(struct amd_iommu *iommu) | |||
| 1127 | iommu_feature_enable(iommu, CONTROL_COHERENT_EN); | 1178 | iommu_feature_enable(iommu, CONTROL_COHERENT_EN); |
| 1128 | } | 1179 | } |
| 1129 | 1180 | ||
| 1130 | static void iommu_apply_quirks(struct amd_iommu *iommu) | 1181 | static void iommu_apply_resume_quirks(struct amd_iommu *iommu) |
| 1131 | { | 1182 | { |
| 1132 | if (is_rd890_iommu(iommu->dev)) { | 1183 | int i, j; |
| 1133 | pci_write_config_dword(iommu->dev, 0xf0, iommu->cache_cfg[0]); | 1184 | u32 ioc_feature_control; |
| 1134 | pci_write_config_dword(iommu->dev, 0xf4, iommu->cache_cfg[1]); | 1185 | struct pci_dev *pdev = NULL; |
| 1135 | pci_write_config_dword(iommu->dev, 0xf8, iommu->cache_cfg[2]); | 1186 | |
| 1136 | pci_write_config_dword(iommu->dev, 0xfc, iommu->cache_cfg[3]); | 1187 | /* RD890 BIOSes may not have completely reconfigured the iommu */ |
| 1137 | } | 1188 | if (!is_rd890_iommu(iommu->dev)) |
| 1189 | return; | ||
| 1190 | |||
| 1191 | /* | ||
| 1192 | * First, we need to ensure that the iommu is enabled. This is | ||
| 1193 | * controlled by a register in the northbridge | ||
| 1194 | */ | ||
| 1195 | pdev = pci_get_bus_and_slot(iommu->dev->bus->number, PCI_DEVFN(0, 0)); | ||
| 1196 | |||
| 1197 | if (!pdev) | ||
| 1198 | return; | ||
| 1199 | |||
| 1200 | /* Select Northbridge indirect register 0x75 and enable writing */ | ||
| 1201 | pci_write_config_dword(pdev, 0x60, 0x75 | (1 << 7)); | ||
| 1202 | pci_read_config_dword(pdev, 0x64, &ioc_feature_control); | ||
| 1203 | |||
| 1204 | /* Enable the iommu */ | ||
| 1205 | if (!(ioc_feature_control & 0x1)) | ||
| 1206 | pci_write_config_dword(pdev, 0x64, ioc_feature_control | 1); | ||
| 1207 | |||
| 1208 | pci_dev_put(pdev); | ||
| 1209 | |||
| 1210 | /* Restore the iommu BAR */ | ||
| 1211 | pci_write_config_dword(iommu->dev, iommu->cap_ptr + 4, | ||
| 1212 | iommu->stored_addr_lo); | ||
| 1213 | pci_write_config_dword(iommu->dev, iommu->cap_ptr + 8, | ||
| 1214 | iommu->stored_addr_hi); | ||
| 1215 | |||
| 1216 | /* Restore the l1 indirect regs for each of the 6 l1s */ | ||
| 1217 | for (i = 0; i < 6; i++) | ||
| 1218 | for (j = 0; j < 0x12; j++) | ||
| 1219 | iommu_write_l1(iommu, i, j, iommu->stored_l1[i][j]); | ||
| 1220 | |||
| 1221 | /* Restore the l2 indirect regs */ | ||
| 1222 | for (i = 0; i < 0x83; i++) | ||
| 1223 | iommu_write_l2(iommu, i, iommu->stored_l2[i]); | ||
| 1224 | |||
| 1225 | /* Lock PCI setup registers */ | ||
| 1226 | pci_write_config_dword(iommu->dev, iommu->cap_ptr + 4, | ||
| 1227 | iommu->stored_addr_lo | 1); | ||
| 1138 | } | 1228 | } |
| 1139 | 1229 | ||
| 1140 | /* | 1230 | /* |
| @@ -1147,7 +1237,6 @@ static void enable_iommus(void) | |||
| 1147 | 1237 | ||
| 1148 | for_each_iommu(iommu) { | 1238 | for_each_iommu(iommu) { |
| 1149 | iommu_disable(iommu); | 1239 | iommu_disable(iommu); |
| 1150 | iommu_apply_quirks(iommu); | ||
| 1151 | iommu_init_flags(iommu); | 1240 | iommu_init_flags(iomm |
