From patchwork Wed Jan 18 20:50:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 45485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2559439wrn; Wed, 18 Jan 2023 13:00:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXvao8a8Md+cVu29SsCLPkRDqcY0x5s1Qg55VyPzGYhYOa2RT0PlLJWu/N7Gr3B/g3Bq9wqP X-Received: by 2002:a17:907:c618:b0:868:b2b6:ee71 with SMTP id ud24-20020a170907c61800b00868b2b6ee71mr9142610ejc.6.1674075609084; Wed, 18 Jan 2023 13:00:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674075609; cv=none; d=google.com; s=arc-20160816; b=00UuQ2GDgbI0lOmj0J6oS/mgp368VlA5X40ez2g0UoDjf/XrqgVbeIQ/H3VqkiWnVr /Qj2x29kHdWNZvdl39gHyr1M33VHGy9zP84fPuptYMC0wdBb44boPPR7Q+KFsl13xh1+ FmzX5oUIp/otln41qcDZoSoltPkCIMSgjLIMGMpEuI1Jr187hJ93I1B5k1wLc01x9OcB dk9WD8szbqcKbWXhxR1JzwzfEEQWxG0eRj9PfDKdRpyNqzRTnw5eb9R07VR4IwLoUcjG QT7M05wUqc1kmNt11/cOkLY/ngKjhfFoVS4Q2hnkQx6fdJpt4/kh7U/Zq5D+i1y4mhXM apNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qzT0jb/KBLe37WNWM6jT6vofr8zH3Na0qkg0c9qPk5Y=; b=NuMjXymoaVtlZsd18aFm8+h7Kft3Umr0akAyAKwW4uV8VepAyzv4NX6d7Fupi2ir5v Qfh/H5usJ+YBXVsoaYkuG/PVGpL7igpNbgysxQ3R+58lw+ZKF1CxhtNRtRrS1OCQRhKe 1kb8Me4uLihZk+DLKT0iJ39yNLT3fw5G8P6Vn4jdqDPnIYElG+oF8LPd16vUTSFYRW7H P2XZ60t3lvZODn5a6MAZo42Cc81nBMGq1etZIprhhGpHQVuh36pAR7ddviQPF2Z7R12B MXXeQYWsBXPmwLVjr9rAyP82VqUmohNbioNr8W/2MHEwvSxFuYxHJlRWg4qpqnbWD0IG 3IJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BFUgbNEW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du1-20020a17090772c100b0080f0493b9c8si41354908ejc.536.2023.01.18.12.59.41; Wed, 18 Jan 2023 13:00:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BFUgbNEW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229568AbjARUuj (ORCPT + 99 others); Wed, 18 Jan 2023 15:50:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230099AbjARUu3 (ORCPT ); Wed, 18 Jan 2023 15:50:29 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77325470A9 for ; Wed, 18 Jan 2023 12:50:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674075028; x=1705611028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wKXXJ+m3tEvR8w1YatVl7Ut7WalvD7GwpQ7ajuSMxXM=; b=BFUgbNEWa4j3jq6T6CyWYkJKoxBLh1QSL2Bz0KKz7zzws9jrxlYtOfr7 ZMx/rftZZXyX7GLGOYbI6rTVVJpqS5hSaIWbw+r1hY2jaQo9xVqykzT+n J5KBt5W3L7KhEAwTWEhP0/AmcK82Q3zk8dQwCxCowSVIsH8Z5s3OgYQzM pDXtA41KqCKX/qhUaDumM7Q5cvJO+QLFn4AtGj1/ZB+slGkWY7zzDwBpc z8CyA78r5k6KMptdbTyhT7HjFRCtBrh9QPwrBdsRGMJR+MAGPY62Sy96A WSlsQgisaOcPvIKW+BeiWpOlCP6B5Dqb9W/nEcCnwKbk91IdLdowk0/g3 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10594"; a="323784133" X-IronPort-AV: E=Sophos;i="5.97,226,1669104000"; d="scan'208";a="323784133" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2023 12:50:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10594"; a="833739568" X-IronPort-AV: E=Sophos;i="5.97,226,1669104000"; d="scan'208";a="833739568" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga005.jf.intel.com with ESMTP; 18 Jan 2023 12:50:26 -0800 From: kan.liang@linux.intel.com To: joro@8bytes.org, will@kernel.org, baolu.lu@linux.intel.com, dwmw2@infradead.org, robin.murphy@arm.com, robert.moore@intel.com, rafael.j.wysocki@intel.com, lenb@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Kan Liang Subject: [PATCH V2 1/7] iommu/vt-d: Support size of the register set in DRHD Date: Wed, 18 Jan 2023 12:50:00 -0800 Message-Id: <20230118205006.3182907-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230118205006.3182907-1-kan.liang@linux.intel.com> References: <20230118205006.3182907-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755395505462893090?= X-GMAIL-MSGID: =?utf-8?q?1755395505462893090?= From: Kan Liang A new field, which indicates the size of the remapping hardware register set for this remapping unit, is introduced in the DMA-remapping hardware unit definition (DRHD) structure with the VT-d Spec 4.0. With the information, SW doesn't need to 'guess' the size of the register set anymore. Update the struct acpi_dmar_hardware_unit to reflect the field. Store the size of the register set in struct dmar_drhd_unit for each dmar device. The 'size' information is ResvZ for the old BIOS and platforms. Fall back to the old guessing method. There is nothing changed. Signed-off-by: Kan Liang --- drivers/iommu/intel/dmar.c | 11 +++++++---- include/acpi/actbl1.h | 2 +- include/linux/dmar.h | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index b00a0ceb2d13..3a40fef1ec1b 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -427,6 +427,8 @@ static int dmar_parse_one_drhd(struct acpi_dmar_header *header, void *arg) memcpy(dmaru->hdr, header, header->length); dmaru->reg_base_addr = drhd->address; dmaru->segment = drhd->segment; + /* The size of the register set is 2 ^ N 4 KB pages. */ + dmaru->reg_size = 1UL << (drhd->size + 12); dmaru->include_all = drhd->flags & 0x1; /* BIT0: INCLUDE_ALL */ dmaru->devices = dmar_alloc_dev_scope((void *)(drhd + 1), ((void *)drhd) + drhd->header.length, @@ -956,17 +958,18 @@ static void unmap_iommu(struct intel_iommu *iommu) /** * map_iommu: map the iommu's registers * @iommu: the iommu to map - * @phys_addr: the physical address of the base resgister + * @drhd: DMA remapping hardware definition structure * * Memory map the iommu's registers. Start w/ a single page, and * possibly expand if that turns out to be insufficent. */ -static int map_iommu(struct intel_iommu *iommu, u64 phys_addr) +static int map_iommu(struct intel_iommu *iommu, struct dmar_drhd_unit *drhd) { + u64 phys_addr = drhd->reg_base_addr; int map_size, err=0; iommu->reg_phys = phys_addr; - iommu->reg_size = VTD_PAGE_SIZE; + iommu->reg_size = drhd->reg_size; if (!request_mem_region(iommu->reg_phys, iommu->reg_size, iommu->name)) { pr_err("Can't reserve memory\n"); @@ -1050,7 +1053,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) } sprintf(iommu->name, "dmar%d", iommu->seq_id); - err = map_iommu(iommu, drhd->reg_base_addr); + err = map_iommu(iommu, drhd); if (err) { pr_err("Failed to map %s\n", iommu->name); goto error_free_seq_id; diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 4175dce3967c..bdded0ac46eb 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -802,7 +802,7 @@ struct acpi_dmar_pci_path { struct acpi_dmar_hardware_unit { struct acpi_dmar_header header; u8 flags; - u8 reserved; + u8 size; /* Size of the register set */ u16 segment; u64 address; /* Register Base Address */ }; diff --git a/include/linux/dmar.h b/include/linux/dmar.h index d81a51978d01..725d5e6acec0 100644 --- a/include/linux/dmar.h +++ b/include/linux/dmar.h @@ -39,6 +39,7 @@ struct dmar_drhd_unit { struct list_head list; /* list of drhd units */ struct acpi_dmar_header *hdr; /* ACPI header */ u64 reg_base_addr; /* register base address*/ + unsigned long reg_size; /* size of register set */ struct dmar_dev_scope *devices;/* target device array */ int devices_cnt; /* target device count */ u16 segment; /* PCI domain */