Skip to content

Commit 7329cf0

Browse files
author
Ingo Molnar
committed
Merge branch 'amd-iommu/2.6.36' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu into x86/urgent
2 parents 74b3c44 + 04e0463 commit 7329cf0

File tree

5 files changed

+69
-23
lines changed

5 files changed

+69
-23
lines changed

arch/x86/include/asm/amd_iommu_proto.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ static inline void amd_iommu_stats_init(void) { }
3838

3939
#endif /* !CONFIG_AMD_IOMMU_STATS */
4040

41+
static inline bool is_rd890_iommu(struct pci_dev *pdev)
42+
{
43+
return (pdev->vendor == PCI_VENDOR_ID_ATI) &&
44+
(pdev->device == PCI_DEVICE_ID_RD890_IOMMU);
45+
}
46+
4147
#endif /* _ASM_X86_AMD_IOMMU_PROTO_H */

arch/x86/include/asm/amd_iommu_types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ struct amd_iommu {
368368
/* capabilities of that IOMMU read from ACPI */
369369
u32 cap;
370370

371+
/* flags read from acpi table */
372+
u8 acpi_flags;
373+
371374
/*
372375
* Capability pointer. There could be more than one IOMMU per PCI
373376
* device function if there are more than one AMD IOMMU capability
@@ -411,6 +414,15 @@ struct amd_iommu {
411414

412415
/* default dma_ops domain for that IOMMU */
413416
struct dma_ops_domain *default_dom;
417+
418+
/*
419+
* This array is required to work around a potential BIOS bug.
420+
* The BIOS may miss to restore parts of the PCI configuration
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+
*/
425+
u32 cache_cfg[4];
414426
};
415427

416428
/*

arch/x86/kernel/amd_iommu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,13 +1953,15 @@ static void __unmap_single(struct dma_ops_domain *dma_dom,
19531953
size_t size,
19541954
int dir)
19551955
{
1956+
dma_addr_t flush_addr;
19561957
dma_addr_t i, start;
19571958
unsigned int pages;
19581959

19591960
if ((dma_addr == DMA_ERROR_CODE) ||
19601961
(dma_addr + size > dma_dom->aperture_size))
19611962
return;
19621963

1964+
flush_addr = dma_addr;
19631965
pages = iommu_num_pages(dma_addr, size, PAGE_SIZE);
19641966
dma_addr &= PAGE_MASK;
19651967
start = dma_addr;
@@ -1974,7 +1976,7 @@ static void __unmap_single(struct dma_ops_domain *dma_dom,
19741976
dma_ops_free_addresses(dma_dom, dma_addr, pages);
19751977

19761978
if (amd_iommu_unmap_flush || dma_dom->need_flush) {
1977-
iommu_flush_pages(&dma_dom->domain, dma_addr, size);
1979+
iommu_flush_pages(&dma_dom->domain, flush_addr, size);
19781980
dma_dom->need_flush = false;
19791981
}
19801982
}

arch/x86/kernel/amd_iommu_init.c

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,13 @@ static void __init init_iommu_from_pci(struct amd_iommu *iommu)
632632
iommu->last_device = calc_devid(MMIO_GET_BUS(range),
633633
MMIO_GET_LD(range));
634634
iommu->evt_msi_num = MMIO_MSI_NUM(misc);
635+
636+
if (is_rd890_iommu(iommu->dev)) {
637+
pci_read_config_dword(iommu->dev, 0xf0, &iommu->cache_cfg[0]);
638+
pci_read_config_dword(iommu->dev, 0xf4, &iommu->cache_cfg[1]);
639+
pci_read_config_dword(iommu->dev, 0xf8, &iommu->cache_cfg[2]);
640+
pci_read_config_dword(iommu->dev, 0xfc, &iommu->cache_cfg[3]);
641+
}
635642
}
636643

637644
/*
@@ -649,29 +656,9 @@ static void __init init_iommu_from_acpi(struct amd_iommu *iommu,
649656
struct ivhd_entry *e;
650657

651658
/*
652-
* First set the recommended feature enable bits from ACPI
653-
* into the IOMMU control registers
659+
* First save the recommended feature enable bits from ACPI
654660
*/
655-
h->flags & IVHD_FLAG_HT_TUN_EN_MASK ?
656-
iommu_feature_enable(iommu, CONTROL_HT_TUN_EN) :
657-
iommu_feature_disable(iommu, CONTROL_HT_TUN_EN);
658-
659-
h->flags & IVHD_FLAG_PASSPW_EN_MASK ?
660-
iommu_feature_enable(iommu, CONTROL_PASSPW_EN) :
661-
iommu_feature_disable(iommu, CONTROL_PASSPW_EN);
662-
663-
h->flags & IVHD_FLAG_RESPASSPW_EN_MASK ?
664-
iommu_feature_enable(iommu, CONTROL_RESPASSPW_EN) :
665-
iommu_feature_disable(iommu, CONTROL_RESPASSPW_EN);
666-
667-
h->flags & IVHD_FLAG_ISOC_EN_MASK ?
668-
iommu_feature_enable(iommu, CONTROL_ISOC_EN) :
669-
iommu_feature_disable(iommu, CONTROL_ISOC_EN);
670-
671-
/*
672-
* make IOMMU memory accesses cache coherent
673-
*/
674-
iommu_feature_enable(iommu, CONTROL_COHERENT_EN);
661+
iommu->acpi_flags = h->flags;
675662

676663
/*
677664
* Done. Now parse the device entries
@@ -1116,6 +1103,40 @@ static void init_device_table(void)
11161103
}
11171104
}
11181105

1106+
static void iommu_init_flags(struct amd_iommu *iommu)
1107+
{
1108+
iommu->acpi_flags & IVHD_FLAG_HT_TUN_EN_MASK ?
1109+
iommu_feature_enable(iommu, CONTROL_HT_TUN_EN) :
1110+
iommu_feature_disable(iommu, CONTROL_HT_TUN_EN);
1111+
1112+
iommu->acpi_flags & IVHD_FLAG_PASSPW_EN_MASK ?
1113+
iommu_feature_enable(iommu, CONTROL_PASSPW_EN) :
1114+
iommu_feature_disable(iommu, CONTROL_PASSPW_EN);
1115+
1116+
iommu->acpi_flags & IVHD_FLAG_RESPASSPW_EN_MASK ?
1117+
iommu_feature_enable(iommu, CONTROL_RESPASSPW_EN) :
1118+
iommu_feature_disable(iommu, CONTROL_RESPASSPW_EN);
1119+
1120+
iommu->acpi_flags & IVHD_FLAG_ISOC_EN_MASK ?
1121+
iommu_feature_enable(iommu, CONTROL_ISOC_EN) :
1122+
iommu_feature_disable(iommu, CONTROL_ISOC_EN);
1123+
1124+
/*
1125+
* make IOMMU memory accesses cache coherent
1126+
*/
1127+
iommu_feature_enable(iommu, CONTROL_COHERENT_EN);
1128+
}
1129+
1130+
static void iommu_apply_quirks(struct amd_iommu *iommu)
1131+
{
1132+
if (is_rd890_iommu(iommu->dev)) {
1133+
pci_write_config_dword(iommu->dev, 0xf0, iommu->cache_cfg[0]);
1134+
pci_write_config_dword(iommu->dev, 0xf4, iommu->cache_cfg[1]);
1135+
pci_write_config_dword(iommu->dev, 0xf8, iommu->cache_cfg[2]);
1136+
pci_write_config_dword(iommu->dev, 0xfc, iommu->cache_cfg[3]);
1137+
}
1138+
}
1139+
11191140
/*
11201141
* This function finally enables all IOMMUs found in the system after
11211142
* they have been initialized
@@ -1126,6 +1147,8 @@ static void enable_iommus(void)
11261147

11271148
for_each_iommu(iommu) {
11281149
iommu_disable(iommu);
1150+
iommu_apply_quirks(iommu);
1151+
iommu_init_flags(iommu);
11291152
iommu_set_device_table(iommu);
11301153
iommu_enable_command_buffer(iommu);
11311154
iommu_enable_event_buffer(iommu);

include/linux/pci_ids.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@
393393
#define PCI_DEVICE_ID_VLSI_82C147 0x0105
394394
#define PCI_DEVICE_ID_VLSI_VAS96011 0x0702
395395

396+
/* AMD RD890 Chipset */
397+
#define PCI_DEVICE_ID_RD890_IOMMU 0x5a23
398+
396399
#define PCI_VENDOR_ID_ADL 0x1005
397400
#define PCI_DEVICE_ID_ADL_2301 0x2301
398401

0 commit comments

Comments
 (0)