Skip to content

Commit 313ef75

Browse files
committed
Merge: Turin: IOMMU: Add support for up to 2048 IRTEs
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6750 JIRA: https://issues.redhat.com/browse/RHEL-22785 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Depends: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6414 Turin: IOMMU: Add support for up to 2048 IRTEs In this MR the following commits were cherry-picked and applied on top of !6414: ``` 1c608b0 iommu/amd: Introduce generic function to set multibit feature value eaf717f iommu/amd: Replace slab cache allocator with page allocator 950865c iommu/amd: Rename DTE_INTTABLEN* and MAX_IRQS_PER_TABLE macro 19e5cc1 iommu/amd: Enable support for up to 2K interrupts per function ``` Signed-off-by: Eder Zulian <ezulian@redhat.com> Approved-by: Donald Dutile <ddutile@redhat.com> Approved-by: Jerry Snitselaar <jsnitsel@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents c9f9820 + 329ca72 commit 313ef75

File tree

3 files changed

+93
-70
lines changed

3 files changed

+93
-70
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
#define FEATURE_SNPAVICSUP_GAM(x) \
113113
(FIELD_GET(FEATURE_SNPAVICSUP, x) == 0x1)
114114

115+
#define FEATURE_NUM_INT_REMAP_SUP GENMASK_ULL(9, 8)
116+
#define FEATURE_NUM_INT_REMAP_SUP_2K(x) \
117+
(FIELD_GET(FEATURE_NUM_INT_REMAP_SUP, x) == 0x1)
118+
115119
/* Note:
116120
* The current driver only support 16-bit PASID.
117121
* Currently, hardware only implement upto 16-bit PASID
@@ -175,13 +179,16 @@
175179
#define CONTROL_GAM_EN 25
176180
#define CONTROL_GALOG_EN 28
177181
#define CONTROL_GAINT_EN 29
182+
#define CONTROL_NUM_INT_REMAP_MODE 43
183+
#define CONTROL_NUM_INT_REMAP_MODE_MASK 0x03
184+
#define CONTROL_NUM_INT_REMAP_MODE_2K 0x01
178185
#define CONTROL_EPH_EN 45
179186
#define CONTROL_XT_EN 50
180187
#define CONTROL_INTCAPXT_EN 51
181188
#define CONTROL_IRTCACHEDIS 59
182189
#define CONTROL_SNPAVIC_EN 61
183190

184-
#define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT)
191+
#define CTRL_INV_TO_MASK 7
185192
#define CTRL_INV_TO_NONE 0
186193
#define CTRL_INV_TO_1MS 1
187194
#define CTRL_INV_TO_10MS 2
@@ -309,15 +316,13 @@
309316
#define DTE_IRQ_REMAP_INTCTL (2ULL << 60)
310317
#define DTE_IRQ_REMAP_ENABLE 1ULL
311318

312-
/*
313-
* AMD IOMMU hardware only support 512 IRTEs despite
314-
* the architectural limitation of 2048 entries.
315-
*/
316-
#define DTE_INTTAB_ALIGNMENT 128
317-
#define DTE_INTTABLEN_VALUE 9ULL
318-
#define DTE_INTTABLEN (DTE_INTTABLEN_VALUE << 1)
319319
#define DTE_INTTABLEN_MASK (0xfULL << 1)
320-
#define MAX_IRQS_PER_TABLE (1 << DTE_INTTABLEN_VALUE)
320+
#define DTE_INTTABLEN_VALUE_512 9ULL
321+
#define DTE_INTTABLEN_512 (DTE_INTTABLEN_VALUE_512 << 1)
322+
#define MAX_IRQS_PER_TABLE_512 BIT(DTE_INTTABLEN_VALUE_512)
323+
#define DTE_INTTABLEN_VALUE_2K 11ULL
324+
#define DTE_INTTABLEN_2K (DTE_INTTABLEN_VALUE_2K << 1)
325+
#define MAX_IRQS_PER_TABLE_2K BIT(DTE_INTTABLEN_VALUE_2K)
321326

322327
#define PAGE_MODE_NONE 0x00
323328
#define PAGE_MODE_1_LEVEL 0x01
@@ -492,9 +497,6 @@ extern const struct iommu_ops amd_iommu_ops;
492497
/* IVRS indicates that pre-boot remapping was enabled */
493498
extern bool amdr_ivrs_remap_support;
494499

495-
/* kmem_cache to get tables with 128 byte alignement */
496-
extern struct kmem_cache *amd_iommu_irq_cache;
497-
498500
#define PCI_SBDF_TO_SEGID(sbdf) (((sbdf) >> 16) & 0xffff)
499501
#define PCI_SBDF_TO_DEVID(sbdf) ((sbdf) & 0xffff)
500502
#define PCI_SEG_DEVID_TO_SBDF(seg, devid) ((((u32)(seg) & 0xffff) << 16) | \
@@ -851,6 +853,7 @@ struct iommu_dev_data {
851853
struct device *dev;
852854
u16 devid; /* PCI Device ID */
853855

856+
unsigned int max_irqs; /* Maximum IRQs supported by device */
854857
u32 max_pasids; /* Max supported PASIDs */
855858
u32 flags; /* Holds AMD_IOMMU_DEVICE_FLAG_<*> */
856859
int ats_qdep;

drivers/iommu/amd/init.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/acpi.h>
1313
#include <linux/list.h>
1414
#include <linux/bitmap.h>
15-
#include <linux/slab.h>
1615
#include <linux/syscore_ops.h>
1716
#include <linux/interrupt.h>
1817
#include <linux/msi.h>
@@ -412,33 +411,26 @@ static void iommu_set_device_table(struct amd_iommu *iommu)
412411
&entry, sizeof(entry));
413412
}
414413

415-
/* Generic functions to enable/disable certain features of the IOMMU. */
416-
void iommu_feature_enable(struct amd_iommu *iommu, u8 bit)
414+
static void iommu_feature_set(struct amd_iommu *iommu, u64 val, u64 mask, u8 shift)
417415
{
418416
u64 ctrl;
419417

420418
ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
421-
ctrl |= (1ULL << bit);
419+
mask <<= shift;
420+
ctrl &= ~mask;
421+
ctrl |= (val << shift) & mask;
422422
writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
423423
}
424424

425-
static void iommu_feature_disable(struct amd_iommu *iommu, u8 bit)
425+
/* Generic functions to enable/disable certain features of the IOMMU. */
426+
void iommu_feature_enable(struct amd_iommu *iommu, u8 bit)
426427
{
427-
u64 ctrl;
428-
429-
ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
430-
ctrl &= ~(1ULL << bit);
431-
writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
428+
iommu_feature_set(iommu, 1ULL, 1ULL, bit);
432429
}
433430

434-
static void iommu_set_inv_tlb_timeout(struct amd_iommu *iommu, int timeout)
431+
static void iommu_feature_disable(struct amd_iommu *iommu, u8 bit)
435432
{
436-
u64 ctrl;
437-
438-
ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
439-
ctrl &= ~CTRL_INV_TO_MASK;
440-
ctrl |= (timeout << CONTROL_INV_TIMEOUT) & CTRL_INV_TO_MASK;
441-
writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
433+
iommu_feature_set(iommu, 0ULL, 1ULL, bit);
442434
}
443435

444436
/* Function to enable the hardware */
@@ -1069,7 +1061,8 @@ static bool __copy_device_table(struct amd_iommu *iommu)
10691061
int_tab_len = old_devtb[devid].data[2] & DTE_INTTABLEN_MASK;
10701062
if (irq_v && (int_ctl || int_tab_len)) {
10711063
if ((int_ctl != DTE_IRQ_REMAP_INTCTL) ||
1072-
(int_tab_len != DTE_INTTABLEN)) {
1064+
(int_tab_len != DTE_INTTABLEN_512 &&
1065+
int_tab_len != DTE_INTTABLEN_2K)) {
10731066
pr_err("Wrong old irq remapping flag: %#x\n", devid);
10741067
memunmap(old_devtb);
10751068
return false;
@@ -2652,7 +2645,7 @@ static void iommu_init_flags(struct amd_iommu *iommu)
26522645
iommu_feature_enable(iommu, CONTROL_COHERENT_EN);
26532646

26542647
/* Set IOTLB invalidation timeout to 1s */
2655-
iommu_set_inv_tlb_timeout(iommu, CTRL_INV_TO_1S);
2648+
iommu_feature_set(iommu, CTRL_INV_TO_1S, CTRL_INV_TO_MASK, CONTROL_INV_TIMEOUT);
26562649

26572650
/* Enable Enhanced Peripheral Page Request Handling */
26582651
if (check_feature(FEATURE_EPHSUP))
@@ -2745,6 +2738,17 @@ static void iommu_enable_irtcachedis(struct amd_iommu *iommu)
27452738
iommu->irtcachedis_enabled ? "disabled" : "enabled");
27462739
}
27472740

2741+
static void iommu_enable_2k_int(struct amd_iommu *iommu)
2742+
{
2743+
if (!FEATURE_NUM_INT_REMAP_SUP_2K(amd_iommu_efr2))
2744+
return;
2745+
2746+
iommu_feature_set(iommu,
2747+
CONTROL_NUM_INT_REMAP_MODE_2K,
2748+
CONTROL_NUM_INT_REMAP_MODE_MASK,
2749+
CONTROL_NUM_INT_REMAP_MODE);
2750+
}
2751+
27482752
static void early_enable_iommu(struct amd_iommu *iommu)
27492753
{
27502754
iommu_disable(iommu);
@@ -2757,6 +2761,7 @@ static void early_enable_iommu(struct amd_iommu *iommu)
27572761
iommu_enable_ga(iommu);
27582762
iommu_enable_xt(iommu);
27592763
iommu_enable_irtcachedis(iommu);
2764+
iommu_enable_2k_int(iommu);
27602765
iommu_enable(iommu);
27612766
amd_iommu_flush_all_caches(iommu);
27622767
}
@@ -2813,6 +2818,7 @@ static void early_enable_iommus(void)
28132818
iommu_enable_ga(iommu);
28142819
iommu_enable_xt(iommu);
28152820
iommu_enable_irtcachedis(iommu);
2821+
iommu_enable_2k_int(iommu);
28162822
iommu_set_device_table(iommu);
28172823
amd_iommu_flush_all_caches(iommu);
28182824
}
@@ -2939,9 +2945,6 @@ static struct syscore_ops amd_iommu_syscore_ops = {
29392945

29402946
static void __init free_iommu_resources(void)
29412947
{
2942-
kmem_cache_destroy(amd_iommu_irq_cache);
2943-
amd_iommu_irq_cache = NULL;
2944-
29452948
free_iommu_all();
29462949
free_pci_segments();
29472950
}
@@ -3040,7 +3043,7 @@ static void __init ivinfo_init(void *ivrs)
30403043
static int __init early_amd_iommu_init(void)
30413044
{
30423045
struct acpi_table_header *ivrs_base;
3043-
int remap_cache_sz, ret;
3046+
int ret;
30443047
acpi_status status;
30453048

30463049
if (!amd_iommu_detected)
@@ -3102,22 +3105,7 @@ static int __init early_amd_iommu_init(void)
31023105

31033106
if (amd_iommu_irq_remap) {
31043107
struct amd_iommu_pci_seg *pci_seg;
3105-
/*
3106-
* Interrupt remapping enabled, create kmem_cache for the
3107-
* remapping tables.
3108-
*/
31093108
ret = -ENOMEM;
3110-
if (!AMD_IOMMU_GUEST_IR_GA(amd_iommu_guest_ir))
3111-
remap_cache_sz = MAX_IRQS_PER_TABLE * sizeof(u32);
3112-
else
3113-
remap_cache_sz = MAX_IRQS_PER_TABLE * (sizeof(u64) * 2);
3114-
amd_iommu_irq_cache = kmem_cache_create("irq_remap_cache",
3115-
remap_cache_sz,
3116-
DTE_INTTAB_ALIGNMENT,
3117-
0, NULL);
3118-
if (!amd_iommu_irq_cache)
3119-
goto out;
3120-
31213109
for_each_pci_segment(pci_seg) {
31223110
if (alloc_irq_lookup_table(pci_seg))
31233111
goto out;

0 commit comments

Comments
 (0)