Received: by 10.192.165.156 with SMTP id m28csp1134396imm; Mon, 16 Apr 2018 14:51:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/gQj/HybDZytGJhTE/HCSQGgxgFHmI/UPo796TU+TOn3+XFmpujHVBWfq8QNeBuTPVuYWc X-Received: by 2002:a17:902:b786:: with SMTP id e6-v6mr17367290pls.246.1523915502845; Mon, 16 Apr 2018 14:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523915502; cv=none; d=google.com; s=arc-20160816; b=ZTIb6WrRCHXE7Ff9YNc3CnF8r/gC/VpMnyB60SzxUSVRoeI+eiMVnleIFvlyfQuPJB 7sqweaEiU/QHXsR00Xa2xSFMFbQXBT25jD1xQzu6rX0Zfhow8zzFt2Wn0pPRzr61OU1T Z/Cv2D8Ff/v336j2GnCQfgZzyhYGMbqM/C8DXBuLnrfD2IBgOqcU3jbsuKQMINFQhDiI S8bP7WBBv/qYNIUzV9OhTycFAffbBiW9O1wsjAKy5V2XdA0YI9AFDGM36UD6CGihujZA bpchQFkBprypJJ59XrvVCMl9zNyCClIOk+6sQF/coXv12032QA20akO9fafH/e2tv7Gf k5Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=BczkwraTvtAo7yZIZ2RGyKw7kQA00uoT2prq0ySpQRA=; b=DQdxG+zpY5LDXPAsasN3dzRbUaleUy5rEvkFFr/c6MI/XO8wBEVfmg4NsMLo8+GozM sHoDa37xPh/foTHkDm0t6YaS7IJO3oaNkqGJ2CxNGGMINVCxZbLj4mEwptiG41bsMgIs H2T+Nhpe/EfqEPRaXw7+1dH4uoKj4vEuueazTII4BDVNCot5IwSqqusCVSmsEZeCHMJk 6Sb84R+Mm3yFYSjoBSHTwbRBEdgfLUFFf+oZ0X2Z/vI6JPlMQGBHm29jTW7Gijq5kDTm wc0xmJOomKVUQWioTEUwgfdIerZmn08PI7iK6jTleqGhIDmfFf0ImWie4O7g0wZgYKOc TYEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si10489642pgo.122.2018.04.16.14.51.28; Mon, 16 Apr 2018 14:51:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753219AbeDPVrl (ORCPT + 99 others); Mon, 16 Apr 2018 17:47:41 -0400 Received: from mga09.intel.com ([134.134.136.24]:12290 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752915AbeDPVqu (ORCPT ); Mon, 16 Apr 2018 17:46:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 14:46:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,460,1517904000"; d="scan'208";a="34740197" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 16 Apr 2018 14:46:43 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson , Jean-Philippe Brucker Cc: Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Jean Delvare , "Christoph Hellwig" , "Lu Baolu" , Jacob Pan Subject: [PATCH v4 20/22] iommu/vt-d: add intel iommu page response function Date: Mon, 16 Apr 2018 14:49:09 -0700 Message-Id: <1523915351-54415-21-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds page response support for Intel VT-d. Generic response data is taken from the IOMMU API then parsed into VT-d specific response descriptor format. Signed-off-by: Jacob Pan --- drivers/iommu/intel-iommu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/intel-iommu.h | 3 +++ 2 files changed, 50 insertions(+) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index a6ea67d..38f76d4 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -5142,6 +5142,52 @@ static int intel_iommu_sva_invalidate(struct iommu_domain *domain, return ret; } +static int intel_iommu_page_response(struct device *dev, struct page_response_msg *msg) +{ + struct qi_desc resp; + struct intel_iommu *iommu; + struct pci_dev *pdev; + u8 bus, devfn; + u16 rid; + u64 desc; + + pdev = to_pci_dev(dev); + iommu = device_to_iommu(dev, &bus, &devfn); + if (!iommu) { + dev_err(dev, "No IOMMU for device to unbind PASID table\n"); + return -ENODEV; + } + + pci_dev_get(pdev); + rid = ((u16)bus << 8) | devfn; + /* Iommu private data contains preserved page request descriptor, so we + * inspect the SRR bit for response type then queue response with only + * the private data [54:32]. + */ + desc = msg->private_data; + if (desc & QI_PRQ_SRR) { + /* Page Stream Response */ + resp.low = QI_PSTRM_IDX(msg->page_req_group_id) | + (desc & QI_PRQ_PRIV) | QI_PSTRM_BUS(PCI_BUS_NUM(pdev->bus->number)) | + QI_PSTRM_PASID(msg->pasid) | QI_PSTRM_RESP_TYPE; + resp.high = QI_PSTRM_ADDR(msg->addr) | QI_PSTRM_DEVFN(pdev->devfn & 0xff) | + QI_PSTRM_RESP_CODE(msg->resp_code); + } else { + /* Page Group Response */ + resp.low = QI_PGRP_PASID(msg->pasid) | + QI_PGRP_DID(rid) | + QI_PGRP_PASID_P(msg->pasid_present) | + QI_PGRP_RESP_TYPE; + resp.high = QI_PGRP_IDX(msg->page_req_group_id) | + (desc & QI_PRQ_PRIV) | QI_PGRP_RESP_CODE(msg->resp_code); + + } + qi_submit_sync(&resp, iommu); + pci_dev_put(pdev); + + return 0; +} + static int intel_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t hpa, size_t size, int iommu_prot) @@ -5568,6 +5614,7 @@ const struct iommu_ops intel_iommu_ops = { .bind_pasid_table = intel_iommu_bind_pasid_table, .unbind_pasid_table = intel_iommu_unbind_pasid_table, .sva_invalidate = intel_iommu_sva_invalidate, + .page_response = intel_iommu_page_response, #endif .map = intel_iommu_map, .unmap = intel_iommu_unmap, diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index dbe8c93..ed2883a 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -337,6 +337,9 @@ enum { #define QI_PSTRM_BUS(bus) (((u64)(bus)) << 24) #define QI_PSTRM_PASID(pasid) (((u64)(pasid)) << 4) +#define QI_PRQ_SRR BIT_ULL(0) +#define QI_PRQ_PRIV GENMASK_ULL(54, 32) + #define QI_RESP_SUCCESS 0x0 #define QI_RESP_INVALID 0x1 #define QI_RESP_FAILURE 0xf -- 2.7.4