Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6388476ybf; Thu, 5 Mar 2020 19:45:09 -0800 (PST) X-Google-Smtp-Source: ADFU+vvWY0Zx/NndsulULMNnVZLPnm24ZFWZxfqiVlq2kaxDyRyXbUhrT2U/uKt6cIKe5qykX9xi X-Received: by 2002:a05:6830:15d8:: with SMTP id j24mr965258otr.258.1583466309741; Thu, 05 Mar 2020 19:45:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583466309; cv=none; d=google.com; s=arc-20160816; b=mFUGFmJ62VNV4FSB/IfznXQW2xEYuHMF7pVhF/fAJWImEVN1vhmfudynndZw7Z8pBa uxSG/NIgu3GQnDfuISIfNZ1LqjvbvMTzc8JLhB97q5O+K+IoJjKhAn1b8L9j+OMYeF96 dw9Quzs1WljA3CQB22DnnkNp2g1HbX9zG0tvvKUwjofBix07S5LnPbaXSpHqQ4uchsBC 7fKyXaGI8j5Sj3gOtGN7sJ2J7guOfBFVhHblStkHdbbmp9ms2qTHHz3uBUBzK1FtCLQ7 YdzR12Q3+rcWdUJmcIyTksmp15NkwVR+WzxeWNgMGmwrrarXXQFqXTbeABResFUKHN0S GG3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=rCT2btE0s8rgsyroB2co0RIS64ofHS4oSEfAf33EaLQ=; b=OetW1aZLiZ+D7k3DXFlaevb1MBlP+mrhjrh++OPX5wQnk+nm2d3liDlHwWtQta/MQ9 ueYhn2sR/x5idURX8cGwQWi3D9bHLT7eF9QEGMlWWX5YNZmWCjmnFH2PmRLhigv6bgOq 8N6RncUOlpRrR/mqGjmsYzsVLVEVzu6+kYL0Pm2f1YCTD+6DJqOSq5s2mGKpw1BXj5KW 8LgGuAdYMc1kvRrMb45vVld3QXtgHXuyfAlDB6xjyYG1cTAHflngwIIVxRT4AJ4Pbjet DWtJART/WxLHNnlQXbnxmPySOkQkq18z7lRViSlQY1kYoLeSO0uWyE92QjdbTmJP5+JW d/7A== 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 l8si604688oii.249.2020.03.05.19.44.57; Thu, 05 Mar 2020 19:45:09 -0800 (PST) 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 S1726378AbgCFDnm (ORCPT + 99 others); Thu, 5 Mar 2020 22:43:42 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11179 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726251AbgCFDnm (ORCPT ); Thu, 5 Mar 2020 22:43:42 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7A5B81D8692CED9F8EA4; Fri, 6 Mar 2020 11:43:40 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Fri, 6 Mar 2020 11:43:33 +0800 From: Tian Tao To: , , , , , , , , , CC: Subject: [PATCH 3/4] drm/hisilicon: Add the load and unload for hibmc_driver Date: Fri, 6 Mar 2020 11:43:03 +0800 Message-ID: <1583466184-7060-6-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1583466184-7060-1-git-send-email-tiantao6@hisilicon.com> References: <1583466184-7060-1-git-send-email-tiantao6@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org using the load and unload function provided by drm framework instead of doing the same work in the hibmc_pci_probe and do some code cleanup. Signed-off-by: Tian Tao Signed-off-by: Gong junjie --- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 62 +++++++++---------------- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c index 79a180a..51f1c70 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c @@ -23,7 +23,7 @@ #include #include #include - +#include #include "hibmc_drm_drv.h" #include "hibmc_drm_regs.h" @@ -49,6 +49,8 @@ static irqreturn_t hibmc_drm_interrupt(int irq, void *arg) static struct drm_driver hibmc_driver = { .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, + .load = hibmc_load, + .unload = hibmc_unload, .fops = &hibmc_fops, .name = "hibmc", .date = "20160828", @@ -232,6 +234,21 @@ static int hibmc_hw_map(struct hibmc_drm_private *priv) return 0; } +static void hibmc_hw_unmap(struct hibmc_drm_private *priv) +{ + struct drm_device *dev = priv->dev; + + if (priv->mmio) { + devm_iounmap(dev->dev, priv->mmio); + priv->mmio = NULL; + } + + if (priv->fb_map) { + devm_iounmap(dev->dev, priv->fb_map); + priv->fb_map = NULL; + } +} + static int hibmc_hw_init(struct hibmc_drm_private *priv) { int ret; @@ -245,7 +262,7 @@ static int hibmc_hw_init(struct hibmc_drm_private *priv) return 0; } -static int hibmc_unload(struct drm_device *dev) +void hibmc_unload(struct drm_device *dev) { struct hibmc_drm_private *priv = dev->dev_private; @@ -258,11 +275,12 @@ static int hibmc_unload(struct drm_device *dev) hibmc_kms_fini(priv); hibmc_mm_fini(priv); + hibmc_hw_unmap(priv); dev->dev_private = NULL; return 0; } -static int hibmc_load(struct drm_device *dev) +int hibmc_load(struct drm_device *dev, unsigned long flags) { struct hibmc_drm_private *priv; int ret; @@ -332,43 +350,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev, if (ret) return ret; - dev = drm_dev_alloc(&hibmc_driver, &pdev->dev); - if (IS_ERR(dev)) { - DRM_ERROR("failed to allocate drm_device\n"); - return PTR_ERR(dev); - } - - dev->pdev = pdev; - pci_set_drvdata(pdev, dev); - - ret = pci_enable_device(pdev); - if (ret) { - DRM_ERROR("failed to enable pci device: %d\n", ret); - goto err_free; - } - - ret = hibmc_load(dev); - if (ret) { - DRM_ERROR("failed to load hibmc: %d\n", ret); - goto err_disable; - } - - ret = drm_dev_register(dev, 0); - if (ret) { - DRM_ERROR("failed to register drv for userspace access: %d\n", - ret); - goto err_unload; - } - return 0; - -err_unload: - hibmc_unload(dev); -err_disable: - pci_disable_device(pdev); -err_free: - drm_dev_put(dev); - - return ret; + return drm_get_pci_dev(pdev, ent, &hibmc_driver); } static void hibmc_pci_remove(struct pci_dev *pdev) diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h index 50a0c1f..4e89cd7 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h @@ -37,6 +37,8 @@ void hibmc_set_power_mode(struct hibmc_drm_private *priv, void hibmc_set_current_gate(struct hibmc_drm_private *priv, unsigned int gate); +int hibmc_load(struct drm_device *dev, unsigned long flags); +void hibmc_unload(struct drm_device *dev); int hibmc_de_init(struct hibmc_drm_private *priv); int hibmc_vdac_init(struct hibmc_drm_private *priv); -- 2.7.4