From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D096CC433EF for ; Mon, 4 Apr 2022 09:43:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 826AC8176A; Mon, 4 Apr 2022 09:43:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F_sr_kuXGeAk; Mon, 4 Apr 2022 09:43:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 3BFEB81819; Mon, 4 Apr 2022 09:43:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 15317C002C; Mon, 4 Apr 2022 09:43:57 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 065C0C0012 for ; Mon, 4 Apr 2022 09:43:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3D3F660D88 for ; Mon, 4 Apr 2022 09:43:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=amd.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FyV-ZI2ovfsc for ; Mon, 4 Apr 2022 09:43:54 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20624.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::624]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5526160C1C for ; Mon, 4 Apr 2022 09:43:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JJcakzziiOHoGZjx1LC/OfUHJp0KM9ZSET+kSWLFuYL4qCWKYNDxamiQ/HLZ9xpmboBU1HB5zsPu6newvEaDdb64AaVAHHDs7Jt7/u/5sP5VDstwE/JSAj199Bii6pNNYBWc5r+4HY+SH6p4bNbuK7E7KwpXLb/NDXFpxbJOuQV/66gM/mw8bZA7GPsHwDrWenAIKXZIlOSS1QJe2VgGedmRl7Qk7WXKJH/iBCaxXpux5jtv8owf9veqRj9iZTGZ42fsx0nZSVaolDQ86O46S/KJ8nQuTbTrETxwY+wKMzVpGyvvWyRawD9lFMfgYNULKvWPa+uC+0U87bwhX8ecGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5hAShbvAxP/kmQOTrvrhfnRRCTAMrhbvTwuzvj2K57U=; b=KsWKCZgDVm10H4rlk5J2sgnXdTr/lpZOsTm2/dkrxQo+fJwfqq8Mg+bbBC/5f1i0ykEYj0CwTgcWRCoPfh8NQjHxBuCAVrbpPWvXMD7KLVXoCDyZg5D0rsHM3n5UlWbmY8i17XMyC2nh6AjtssnafDinqS0JH1iFYQ4eyEN9sCP6Jk5wj+ALtsN65/BCeDuFcfRPloQHQ+KeGjumdKia7SQJ/JQFmodJP0+2ZJl9QrKsk6688nxjkKF4pyBLEOhEBlmoCTqO5c9E9jpxXFvplZpEbEFfIBPMM3/LRaN3FNAqlQCgXXDUhTla8KECgPl5bVq+e1OYrUXSMWE3fnnDnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.linux-foundation.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5hAShbvAxP/kmQOTrvrhfnRRCTAMrhbvTwuzvj2K57U=; b=b45RddKGuaeooTR5pNnZ5MU8KDW0v3KmHaLjPywbXPa/skgdU8vsgYl/dQolNflkxdByQlxiLvlRJ1UcF5SOXSa4uztXVRugnenpfTB+rgIEnwhEt7F/8w6NQOlK9vYpOuTTAWhh9bbBxIR8hamY53yJLIC2waLNqOT69vNgmDA= Received: from MW4PR04CA0235.namprd04.prod.outlook.com (2603:10b6:303:87::30) by DM6PR12MB3898.namprd12.prod.outlook.com (2603:10b6:5:1c6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Mon, 4 Apr 2022 09:43:50 +0000 Received: from CO1NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:303:87:cafe::b4) by MW4PR04CA0235.outlook.office365.com (2603:10b6:303:87::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31 via Frontend Transport; Mon, 4 Apr 2022 09:43:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT037.mail.protection.outlook.com (10.13.174.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5123.19 via Frontend Transport; Mon, 4 Apr 2022 09:43:48 +0000 Received: from kali.amdval.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 4 Apr 2022 04:43:45 -0500 To: , Subject: [PATCH v1 02/37] iommu/amd: Introduce pci segment structure Date: Mon, 4 Apr 2022 15:10:54 +0530 Message-ID: <20220404094129.323642-3-vasant.hegde@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220404094129.323642-1-vasant.hegde@amd.com> References: <20220404094129.323642-1-vasant.hegde@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 973cb7f5-e20a-4a6d-3489-08da161f9e66 X-MS-TrafficTypeDiagnostic: DM6PR12MB3898:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fh05BexVRE/W6Y1y310coCIMvnrkhwieFVhmr3+vLTmiN6nQGtFL1Ixbl9pa0jd5YCffdC5cfAUFBLIMjfnE5W4IpMKI/s4tEVcpUxwFuVBv/TnAYgSLaqA2pWFOjVnwRNmkaYjXEtwdG2BL9q21eO6hSmhbmXU+7bcIrl/9H3vfduervsYXrCGzDFaZgSI4srKrM5v2RlwDZLbWbw4daB0THwHIMniDAqoj0CsD65a5R4WGejKEShvFqNentL4T4+WQzdG9ZXJSHH/fwvuuBx5v1/XZqlHPIfsUQ8oJKUmuN8yWtTWjxMrK1hVGCnyzF2sT0LzqAl4nb/cwr70lEbPHVT2vwQ3VA78GSljAuMWSN48dfAPbEdZmnrBuDcbcr/crc7xpTU8Fb3V/JMDPTwqzosfUxBpanjY+HBm/WSoEOAvmc0tjuYi1PZWPpnL032c1uWEiHnHuodN86FcfmD94sQAZXIFpfozT9FcUitB5S3oOqZnEcfjCNsvzyOgHzIZSDBKDllLXFfjgiyApsPezMMqKHHIJTudosowXJqjmdO7YpAGUm1XeDROoWFY2ZxldM9YuGjk07AB6bvyPrynEUO/eRxBQ5zjCFLShmXDT3r25m+xE7uDntvfxp1R2gtEyyGO4fSCH2srs64MWk3ffw0oydnGIvjoqpZK9YgUngqi6d2LcZeeJXjSEHg73uYsAEdyIWqYge1SlGy34kg== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(44832011)(8936002)(40460700003)(356005)(508600001)(36756003)(54906003)(6666004)(5660300002)(81166007)(2906002)(110136005)(316002)(8676002)(70586007)(70206006)(86362001)(83380400001)(47076005)(36860700001)(16526019)(26005)(4326008)(336012)(186003)(82310400004)(2616005)(1076003)(426003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2022 09:43:48.1767 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 973cb7f5-e20a-4a6d-3489-08da161f9e66 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3898 Cc: Vasant Hegde X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vasant Hegde via iommu Reply-To: Vasant Hegde Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" Newer AMD systems can support multiple PCI segments, where each segment contains one or more IOMMU instances. However, an IOMMU instance can only support a single PCI segment. Current code assumes that system contains only one pci segment (segment 0) and creates global data structures such as device table, rlookup table, etc. Introducing per PCI segment data structure, which contains segment specific data structures. This will eventually replace the global data structures. Also update `amd_iommu->pci_seg` variable to point to PCI segment structure instead of PCI segment ID. Co-developed-by: Suravee Suthikulpanit Signed-off-by: Suravee Suthikulpanit Signed-off-by: Vasant Hegde --- drivers/iommu/amd/amd_iommu_types.h | 23 ++++++++++++++- drivers/iommu/amd/init.c | 46 ++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 06235b7cb13d..62442d88978f 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -452,6 +452,11 @@ extern bool amd_iommu_irq_remap; /* kmem_cache to get tables with 128 byte alignement */ extern struct kmem_cache *amd_iommu_irq_cache; +/* Make iterating over all pci segment easier */ +#define for_each_pci_segment(pci_seg) \ + list_for_each_entry((pci_seg), &amd_iommu_pci_seg_list, list) +#define for_each_pci_segment_safe(pci_seg, next) \ + list_for_each_entry_safe((pci_seg), (next), &amd_iommu_pci_seg_list, list) /* * Make iterating over all IOMMUs easier */ @@ -526,6 +531,16 @@ struct protection_domain { unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */ }; +/* + * This structure contains information about one PCI segment in the system. + */ +struct amd_iommu_pci_seg { + struct list_head list; + + /* PCI segment number */ + u16 id; +}; + /* * Structure where we save information about one hardware AMD IOMMU in the * system. @@ -577,7 +592,7 @@ struct amd_iommu { u16 cap_ptr; /* pci domain of this IOMMU */ - u16 pci_seg; + struct amd_iommu_pci_seg *pci_seg; /* start of exclusion range of that IOMMU */ u64 exclusion_start; @@ -705,6 +720,12 @@ extern struct list_head ioapic_map; extern struct list_head hpet_map; extern struct list_head acpihid_map; +/* + * List with all PCI segments in the system. This list is not locked because + * it is only written at driver initialization time + */ +extern struct list_head amd_iommu_pci_seg_list; + /* * List with all IOMMUs in the system. This list is not locked because it is * only written and read at driver initialization or suspend time diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index b4a798c7b347..e01eae9dcbc1 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -165,6 +165,7 @@ u16 amd_iommu_last_bdf; /* largest PCI device id we have LIST_HEAD(amd_iommu_unity_map); /* a list of required unity mappings we find in ACPI */ +LIST_HEAD(amd_iommu_pci_seg_list); /* list of all PCI segments */ LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the system */ @@ -1456,6 +1457,43 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, return 0; } +/* Allocate PCI segment data structure */ +static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id) +{ + struct amd_iommu_pci_seg *pci_seg; + + pci_seg = kzalloc(sizeof(struct amd_iommu_pci_seg), GFP_KERNEL); + if (pci_seg == NULL) + return NULL; + + pci_seg->id = id; + list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list); + + return pci_seg; +} + +static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id) +{ + struct amd_iommu_pci_seg *pci_seg; + + for_each_pci_segment(pci_seg) { + if (pci_seg->id == id) + return pci_seg; + } + + return alloc_pci_segment(id); +} + +static void __init free_pci_segment(void) +{ + struct amd_iommu_pci_seg *pci_seg, *next; + + for_each_pci_segment_safe(pci_seg, next) { + list_del(&pci_seg->list); + kfree(pci_seg); + } +} + static void __init free_iommu_one(struct amd_iommu *iommu) { free_cwwb_sem(iommu); @@ -1542,8 +1580,14 @@ static void amd_iommu_ats_write_check_workaround(struct amd_iommu *iommu) */ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) { + struct amd_iommu_pci_seg *pci_seg; int ret; + pci_seg = get_pci_segment(h->pci_seg); + if (pci_seg == NULL) + return -ENOMEM; + iommu->pci_seg = pci_seg; + raw_spin_lock_init(&iommu->lock); iommu->cmd_sem_val = 0; @@ -1564,7 +1608,6 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) */ iommu->devid = h->devid; iommu->cap_ptr = h->cap_ptr; - iommu->pci_seg = h->pci_seg; iommu->mmio_phys = h->mmio_phys; switch (h->type) { @@ -2610,6 +2653,7 @@ static void __init free_iommu_resources(void) amd_iommu_dev_table = NULL; free_iommu_all(); + free_pci_segment(); } /* SB IOAPIC is always on this device in AMD systems */ -- 2.27.0 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu