Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2118997pxa; Mon, 17 Aug 2020 00:55:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6/oe6m97R82eJzSuqxBbFAzq2n+xXvSrVXZ7p967kseQXs4vpCkU4QKOC3IzxsyQnbySU X-Received: by 2002:aa7:c6c2:: with SMTP id b2mr14294036eds.173.1597650931367; Mon, 17 Aug 2020 00:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597650931; cv=none; d=google.com; s=arc-20160816; b=Gszcj6GvppWacEaDdA27v1I4FKTOl4tS14YacqiH08OGu/Zg6p1JB0IpYPTEpeeyFt RXu7xS4YtqVLVGhb6H4L0vPusl/UQhOEng312KXROriu28yV6ka6DiB4nt5Hree8n0P+ 8Njl5g4eKxIe8OPR534dBBKZKE6PJvDGB0nTPNhoYR90yN12zYdDX7OV4C+kOVJ71eKV LrglhghDq0HJkVjqg4sVzWxeIYDAPbuJTqAAqKPo/iROzUCp3CeVoNJ+CKI2xByXlr2N l6eLHtqp9ZNqwg2J2RO9crl4jYmh7bKS2No+UrQMnyMYlAJBZI4IgQK5ZkUkCq6/opGO t/lw== 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=zsfqKbs96H9Pp6tGMWuKYuw84EKyZmEviZS2B3wdzFs=; b=vLwpJgAtoiREa6ZpkDnncEZc/Tg2mq20CwbUfP2TRVZDhhU8e3gk6x8m89iD5YiPBS GMCFvw2FSrnX1AlHbgrZ3e86c5nrn6N4rdGq0RQvgJrPUDekj4jj7+33XXYA+Ru3fmLd 5mI66p7DBXaj45dq2wIW4dg8IDHGEn2jiHsAG3VHaPcMd6qXOgkMQeBCKPp+BHqKlY04 d5vey1//ooRh/zxToUxU2X44bCnLoFjOaQhyNfVxq8gMF/VLAnJxQtR45EVyk6jhQ9h+ ekIKuV/e7MJ51L/TP97x1lYy1kiurAHv5VUv/48RJLIxLFjai4Xu1q8+6hEIvwwwaw4O cJ4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dYc0scDV; 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 v19si11010923ejy.697.2020.08.17.00.55.08; Mon, 17 Aug 2020 00:55:31 -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=dYc0scDV; 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 S1727871AbgHQHv1 (ORCPT + 99 others); Mon, 17 Aug 2020 03:51:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:45256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbgHQHuU (ORCPT ); Mon, 17 Aug 2020 03:50:20 -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 D2F10207FF; Mon, 17 Aug 2020 07:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597650620; bh=9rVRnfdHuh2duUuMaNM8qY59mJH954NFLvyCvlD6FKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dYc0scDVdbDSS4WWpo3huWSIdSoBko9+r4RTaFI5bAbu6GkMGQRqKi32Xny5dJUCd lmVrfcS4a3hfQCtO16DdTPnuUbhzjkUO+4sVLgJ/XZt9/QWs8e8cHfcI/SmYmjqAIh hJ4XFsUQPH8lyIyi8rGEvJAC98kBbxS6aNLT/y+c= Received: from mchehab by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1k7ZuM-00Bfc0-07; 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 04/16] iommu: hisi_smmu_lpae: rebase it to work with upstream Date: Mon, 17 Aug 2020 09:50:03 +0200 Message-Id: <01f0e50095605755d105d5cbc3fc0ac7850e5906.1597650455.git.mchehab+huawei@kernel.org> 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 Currently, this driver OOPSes. It turns that this driver needs to be updated in order to work with the current iommu kAPI. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hisi_smmu.h | 2 + drivers/staging/hikey9xx/hisi_smmu_lpae.c | 81 ++++++++++++++++++++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi_smmu.h b/drivers/staging/hikey9xx/hisi_smmu.h index 4637244dba6b..bd3ee53735bd 100644 --- a/drivers/staging/hikey9xx/hisi_smmu.h +++ b/drivers/staging/hikey9xx/hisi_smmu.h @@ -89,6 +89,8 @@ struct hisi_smmu_device_lpae { unsigned long va_pgtable_addr; phys_addr_t smmu_phy_pgtable_addr; smmu_pgd_t *smmu_pgd; + + struct iommu_device iommu; }; struct hisi_map_tile_position_lpae { diff --git a/drivers/staging/hikey9xx/hisi_smmu_lpae.c b/drivers/staging/hikey9xx/hisi_smmu_lpae.c index b411ca97f2c2..5acde3ddbd99 100644 --- a/drivers/staging/hikey9xx/hisi_smmu_lpae.c +++ b/drivers/staging/hikey9xx/hisi_smmu_lpae.c @@ -724,30 +724,73 @@ static size_t hisi_smmu_unmap_tile_lpae(struct iommu_domain *domain, return hisi_smmu_unmap_lpae(domain, iova, size, NULL); } +static bool hisi_smmu_capable(enum iommu_cap cap) +{ + return false; +} + +static int hisi_smmu_add_device(struct device *dev) +{ + struct hisi_smmu_device_lpae *iommu = hisi_smmu_dev; + struct iommu_group *group; + + if (iommu) + iommu_device_link(&iommu->iommu, dev); + else + return -ENODEV; + + group = iommu_group_get_for_dev(dev); + if (IS_ERR(group)) + return PTR_ERR(group); + + iommu_group_put(group); + + return 0; +} + +static void hisi_smmu_remove_device(struct device *dev) +{ + struct hisi_smmu_device_lpae *iommu = hisi_smmu_dev; + + if (iommu) + iommu_device_unlink(&iommu->iommu, dev); + + iommu_group_remove_device(dev); +} + static struct iommu_ops hisi_smmu_ops = { + .capable = hisi_smmu_capable, .domain_alloc = hisi_smmu_domain_alloc_lpae, .domain_free = hisi_smmu_domain_free_lpae, + .attach_dev = hisi_attach_dev_lpae, + .detach_dev = hisi_detach_dev_lpae, .map = hisi_smmu_map_lpae, .unmap = hisi_smmu_unmap_lpae, - .attach_dev = hisi_attach_dev_lpae, - .detach_dev = hisi_detach_dev_lpae, .iova_to_phys = hisi_smmu_iova_to_phys_lpae, + .add_device = hisi_smmu_add_device, + .remove_device = hisi_smmu_remove_device, + .device_group = generic_device_group, .pgsize_bitmap = SMMU_PAGE_SIZE, - .map_tile = hisi_smmu_map_tile_lpae, - .unmap_tile = hisi_smmu_unmap_tile_lpae, + .map_tile = hisi_smmu_map_tile_lpae, + .unmap_tile = hisi_smmu_unmap_tile_lpae, }; static int hisi_smmu_probe_lpae(struct platform_device *pdev) { struct device *dev = &pdev->dev; + int ret; dbg("enter %s\n", __func__); hisi_smmu_dev = devm_kzalloc(dev, sizeof(struct hisi_smmu_device_lpae), GFP_KERNEL); - hisi_smmu_dev->smmu_pgd = devm_kzalloc(dev, SZ_64, GFP_KERNEL | __GFP_DMA); - if (!hisi_smmu_dev) + hisi_smmu_dev->smmu_pgd = devm_kzalloc(dev, SZ_64, + GFP_KERNEL | __GFP_DMA); + if (!hisi_smmu_dev) { + ret = -ENOMEM; goto smmu_device_error; + } + hisi_smmu_dev->dev = dev; INIT_LIST_HEAD(&hisi_smmu_dev->domain_list); spin_lock_init(&hisi_smmu_dev->lock); @@ -756,18 +799,39 @@ static int hisi_smmu_probe_lpae(struct platform_device *pdev) hisi_smmu_dev->smmu_phy_pgtable_addr = virt_to_phys(hisi_smmu_dev->smmu_pgd); - printk(KERN_ERR "%s, smmu_phy_pgtable_addr is = %llx\n", __func__, hisi_smmu_dev->smmu_phy_pgtable_addr); + dev_info(&pdev->dev, "%s, smmu_phy_pgtable_addr is = 0x%llx\n", + __func__, hisi_smmu_dev->smmu_phy_pgtable_addr); hisi_smmu_dev->va_pgtable_addr = (unsigned long)(hisi_smmu_dev->smmu_pgd); + + ret = iommu_device_sysfs_add(&hisi_smmu_dev->iommu, NULL, NULL, + "hisi-iommu"); + if (ret) + goto fail_register; + + iommu_device_set_ops(&hisi_smmu_dev->iommu, &hisi_smmu_ops); + + ret = iommu_device_register(&hisi_smmu_dev->iommu); + if (ret) { + dev_info(&pdev->dev, "Could not register hisi-smmu\n"); + goto fail_register; + } + bus_set_iommu(&platform_bus_type, &hisi_smmu_ops); return 0; +fail_register: + iommu_device_sysfs_remove(&hisi_smmu_dev->iommu); + smmu_device_error: - return -ENOMEM; + return ret; } static int hisi_smmu_remove_lpae(struct platform_device *pdev) { + iommu_device_unregister(&hisi_smmu_dev->iommu); + iommu_device_sysfs_remove(&hisi_smmu_dev->iommu); + return 0; } @@ -779,7 +843,6 @@ MODULE_DEVICE_TABLE(of, hisi_smmu_of_match_lpae); static struct platform_driver hisi_smmu_driver_lpae = { .driver = { - .owner = THIS_MODULE, .name = "hisi-smmu-lpae", .of_match_table = of_match_ptr(hisi_smmu_of_match_lpae), }, -- 2.26.2