Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2118648pxa; Mon, 17 Aug 2020 00:54:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT1cmIZyQ5sHwwCkMRD6imNp8yrJHmD1dM8zNnCdk47D5oEv1v/yR9/XwKg6XWpUUpSOc6 X-Received: by 2002:aa7:dc44:: with SMTP id g4mr14001895edu.273.1597650876325; Mon, 17 Aug 2020 00:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597650876; cv=none; d=google.com; s=arc-20160816; b=RmdFgS+zXdh4fJVqkGa+tzkfYMQV60alCqbFcTElWamL1L/sZ9WzUFnScqS25Onks7 fB4xIlpw2QbF15Dkeh6uNX7l4rzbMhgYHyRIvRsTFwDAWJMo/HtenII8AimS8hWHIJ8a MRt9367UWfVVV6rYy5YoBH+EuyaZnDoCQjeOAYQrwZkeRxIQzTe3L6KylMU+KI8sZzWp JTjnRaN1qrvZaQQF3BG28fJEh9fV3AJ7v7wackApG8T1VM+3JGQUXj5pgdaMSueFYAQE x/DqBmNWklvJtUNPVRbONvObQMdnTMQNOyGUYZooa4Sqe7jkPg42+3HezMmjV5hXbVFk FkCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2wkTVXHFxt9WEYWP+Lj6SLwzHp96UJfcWiTeOYiUB5E=; b=wXHQU8drGT7b4N2Eb77ourrpSrllbUKliwi1dmMdDob6lto65oY0t6btLP8P1YyX2E i9gIKIof7RfzGLPPAZN5Afr2muakufMKDk6xTwVvTh4ycSuiAt7I0w0lWZFPrS4DpJuP y4TtOHyoQiU4wGg99f3brQ4nmpMlSwHqeHXGtw6qzIcIGTFK2yxcoouBdhAUws2tV5k6 xZthswAHGDSWB37s5M0uaYVxB/MS5+wGT1Y0yJvlOSgoSIubGMwUizStPy4yj/xDGh03 DJC2Ix6X2TaH1jp8ZHiGSZcAR5HFsczam+S3GD/gr446yXK7jyaBOYbv2nepxqIc11vN H+/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wX5lDi8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si10963197ejs.414.2020.08.17.00.54.13; Mon, 17 Aug 2020 00:54:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wX5lDi8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbgHQHvF (ORCPT + 99 others); Mon, 17 Aug 2020 03:51:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:45500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbgHQHuW (ORCPT ); Mon, 17 Aug 2020 03:50:22 -0400 Received: from mail.kernel.org (ip5f5ad5a3.dynamic.kabel-deutschland.de [95.90.213.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27AD8221E2; Mon, 17 Aug 2020 07:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597650620; bh=85lPGrCLwvRTJq/O/2q3um9Agh51fUJDSP4KusDSmGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wX5lDi8M/3gvXmo+bB9cz2VpwZqZ6ZqiUr/cyd6G4MzLXO+fxtBcXQxEBe/Eot4rM 54UlfbNJcwTV/p1vGaMHNGJGixMkKLM/vSa+7KdkJkZwBShKNABit4GYTFpGFWs8RA kJFEXzN5a1EiIMZcL4tbSJkbVoxr1ihBySBCRjAs= Received: from mchehab by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1k7ZuM-00BfcG-8n; Mon, 17 Aug 2020 09:50:18 +0200 From: Mauro Carvalho Chehab To: Greg Kroah-Hartman Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , John Stultz , Manivannan Sadhasivam , linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org Subject: [PATCH 09/16] iommu: hisi_smmu_lpae: use the right code to get domain-priv data Date: Mon, 17 Aug 2020 09:50:08 +0200 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The downstream code needed to use a priv data within the domain struct. Change it to work like other iommu drivers: use dev_iommu_priv_get() and dev_iommu_priv_set() instead. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hisi_smmu.h | 17 ++++++++-- drivers/staging/hikey9xx/hisi_smmu_lpae.c | 38 +++++++++++++---------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi_smmu.h b/drivers/staging/hikey9xx/hisi_smmu.h index b2d32ec6cb84..290f2e11c3be 100644 --- a/drivers/staging/hikey9xx/hisi_smmu.h +++ b/drivers/staging/hikey9xx/hisi_smmu.h @@ -94,7 +94,7 @@ struct hisi_smmu_device_lpae { struct iommu_device iommu; }; -struct iommu_domain_data { +struct hisi_smmu_domain_data { unsigned int iova_start; unsigned int iova_size; phys_addr_t phy_pgd_base; @@ -102,13 +102,24 @@ struct iommu_domain_data { struct list_head list; }; +struct hisi_smmu_domain { + struct iommu_domain domain; + struct hisi_smmu_domain_data *iommu_info; +}; + +static struct hisi_smmu_domain_data *to_smmu(struct iommu_domain *dom) +{ + struct hisi_smmu_domain *hisi_dom; + + hisi_dom = container_of(dom, struct hisi_smmu_domain, domain); + return hisi_dom->iommu_info; +} + struct hisi_map_tile_position_lpae { struct scatterlist *sg; unsigned long offset; }; -extern struct hisi_smmu_device_lpae *hisi_smmu_dev; - static inline unsigned int smmu_pgd_none_lpae(smmu_pgd_t pgd) { return !(pgd ? pgd : 0); diff --git a/drivers/staging/hikey9xx/hisi_smmu_lpae.c b/drivers/staging/hikey9xx/hisi_smmu_lpae.c index a55b5a35b339..1fe57c10e745 100644 --- a/drivers/staging/hikey9xx/hisi_smmu_lpae.c +++ b/drivers/staging/hikey9xx/hisi_smmu_lpae.c @@ -28,7 +28,7 @@ #include #include "hisi_smmu.h" -struct hisi_smmu_device_lpae *hisi_smmu_dev; +static struct hisi_smmu_device_lpae *hisi_smmu_dev; /* transfer 64bit pte table pointer to struct page */ static pgtable_t smmu_pgd_to_pte_lpae(unsigned int ppte_table) @@ -57,7 +57,7 @@ static pgtable_t smmu_pmd_to_pte_lpae(unsigned long ppte_table) } static int get_domain_data_lpae(struct device_node *np, - struct iommu_domain_data *data) + struct hisi_smmu_domain_data *data) { unsigned long long align; struct device_node *node = NULL; @@ -103,14 +103,16 @@ static int get_domain_data_lpae(struct device_node *np, static struct iommu_domain *hisi_smmu_domain_alloc_lpae(unsigned int iommu_domain_type) { - struct iommu_domain *domain; + struct hisi_smmu_domain *hisi_dom; if (iommu_domain_type != IOMMU_DOMAIN_UNMANAGED) return NULL; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); + hisi_dom = kzalloc(sizeof(*hisi_dom), GFP_KERNEL); - return domain; + pr_debug("%s: domain allocated\n", __func__); + + return &hisi_dom->domain; } static void hisi_smmu_flush_pgtable_lpae(void *addr, size_t size) @@ -336,13 +338,13 @@ static int hisi_smmu_map_lpae(struct iommu_domain *domain, gfp_t gfp) { unsigned long max_iova; - struct iommu_domain_data *data; + struct hisi_smmu_domain_data *data; if (!domain) { dbg("domain is null\n"); return -ENODEV; } - data = domain->priv; + data = to_smmu(domain); max_iova = data->iova_start + data->iova_size; if (iova < data->iova_start) { dbg("iova failed: iova = 0x%lx, start = 0x%8x\n", @@ -429,13 +431,13 @@ static size_t hisi_smmu_unmap_lpae(struct iommu_domain *domain, { unsigned long max_iova; unsigned int ret; - struct iommu_domain_data *data; + struct hisi_smmu_domain_data *data; if (!domain) { dbg("domain is null\n"); return -ENODEV; } - data = domain->priv; + data = to_smmu(domain); /*calculate the max io virtual address */ max_iova = data->iova_start + data->iova_size; /*check the iova */ @@ -490,28 +492,32 @@ static int hisi_attach_dev_lpae(struct iommu_domain *domain, struct device *dev) { struct device_node *np = dev->of_node; int ret = 0; - struct iommu_domain_data *iommu_info = NULL; + struct hisi_smmu_domain_data *iommu_info = NULL; + struct hisi_smmu_domain *hisi_dom; iommu_info = kzalloc(sizeof(*iommu_info), GFP_KERNEL); if (!iommu_info) { - dbg("alloc iommu_domain_data fail\n"); + dbg("alloc hisi_smmu_domain_data fail\n"); return -EINVAL; } list_add(&iommu_info->list, &hisi_smmu_dev->domain_list); - domain->priv = iommu_info; - ret = get_domain_data_lpae(np, domain->priv); + + hisi_dom = container_of(domain, struct hisi_smmu_domain, domain); + hisi_dom->iommu_info = iommu_info; + dev_iommu_priv_set(dev, iommu_info); + ret = get_domain_data_lpae(np, iommu_info); return ret; } static void hisi_detach_dev_lpae(struct iommu_domain *domain, struct device *dev) { - struct iommu_domain_data *data; + struct hisi_smmu_domain_data *data; - data = (struct iommu_domain_data *)domain->priv; + data = dev_iommu_priv_get(dev); if (data) { list_del(&data->list); - domain->priv = NULL; + dev_iommu_priv_set(dev, NULL); kfree(data); } else { dbg("%s:error! data entry has been delected\n", __func__); -- 2.26.2