Received: by 2002:ac8:1418:0:b0:3ab:920c:4c8b with SMTP id k24csp3125653qtj; Wed, 18 Jan 2023 13:27:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXuXpP+Xm0kLj0zEEfirqCiqW9HQrjzF/WXIrgBdChOTI+v8J3KENB5DLSMqWqUx5YAtP73N X-Received: by 2002:a17:90a:de05:b0:226:e1a0:6596 with SMTP id m5-20020a17090ade0500b00226e1a06596mr8528542pjv.12.1674077226046; Wed, 18 Jan 2023 13:27:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674077226; cv=none; d=google.com; s=arc-20160816; b=Z6NIDYQmv9mo/zt77sFH6aQxkZ4ceahlW/jShWCec6IdRkWVZutZAkL5RNMKMq2L7Z Gfo39pXlHdmZFZidwIbooI0/Q3KtAwldl0RpdNOcOKLPeMli2uq/OuhGQ+RdNKOM6Fzc zb92/hgjiI9GpUC1/uKTRS0xFLg5RGm8TFzRzXSOxVptH6M7QOYCLxVPO/KLNg+Ws+WO n/ffVynWuQBjbd+PlmwUL9Bn7VP7Yg6Dy9aDW/fKmA2sB4jh6UCh8yVv1jD7HD3CqVVd u8Z8xWGv/OH6e5gLhzkGve7oxQ/w2+Bhqk7fQAXinplzHJBjMKOTTrQ0UnKA8IdH3MHQ TAYA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v24-20020a631518000000b004615836deeasi12703095pgl.860.2023.01.18.13.27.00; Wed, 18 Jan 2023 13:27:06 -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 + 45 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 Content-Transfer-Encoding: 8bit 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 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 */ -- 2.35.1