Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6389112ybf; Thu, 5 Mar 2020 19:46:12 -0800 (PST) X-Google-Smtp-Source: ADFU+vse8rBqZsx7qEniUYxOd8SN6JmBb+tR1KssHM8o75VSZb52cJEJ2FQnNDye4KRUsv6NyA4u X-Received: by 2002:a05:6830:186:: with SMTP id q6mr907974ota.10.1583466372210; Thu, 05 Mar 2020 19:46:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583466372; cv=none; d=google.com; s=arc-20160816; b=fpeEGFFOMiOIRyQ+B82C7KaWorkNcwf9MrkWoE4Zl/yFzwdGeSTnFvhwFvP0EJd4mg 0/G2bx2IK5g4WU+L0blFtr3ykC1Yb0HZ+64Ws4qNZygR+TmIyNKP3p9lF3PZW3DOqF4a D6WU4DwAFJxWkZLJaXUFVw1t+85wFPihb14p6fomBiHO2dRtiBXL/b9U64SktZr0dx3a nJNEuuLFth1ALxcFwlmjB2lagvXgATdoYy/s15Py6LpoZSc0/0ZJ3MJGUMOTxmGbLQ3b IKr8Fi2rz5VPROmP2xpxCkuZODj29/mCgrn/DENjsUb9u0Qujl7lkJy1MzDT18RZYlqp 9sOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=rCT2btE0s8rgsyroB2co0RIS64ofHS4oSEfAf33EaLQ=; b=e3SYy0Ww2cVVLJ+1Tw7vCrjykBd6z4lNl5sO9Tg8jDWw3HmUKnlD6vIJKhlFHYYk7y xTWey18rvImcCSHP0dn34zwFIW86t2mYw+RB4+PpVoUo3Hp3CQ3bTR3m3fOTPf/tkVE+ 3X4h3NLziDipxltRxb6tnaR77ktHmzVBjFP6p5xMJQihrZSADeAunQlHxWsGUN6glnQ1 XowVfvOiLLbRniQlKLo16WUCPtTGRQKn0IU+7Fb/qfvxn6grAP83MJ5UBWt21eXXBzik VzYaxcaRgc/3Y+1zQ6tLHVV23stIowJ4smpxg3IyNCNJczF6LrJMIfFpQjYx9hnHTFyY 60dw== 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 l11si618379oth.235.2020.03.05.19.45.59; Thu, 05 Mar 2020 19:46:12 -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 S1727070AbgCFDnz (ORCPT + 99 others); Thu, 5 Mar 2020 22:43:55 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11178 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726317AbgCFDnn (ORCPT ); Thu, 5 Mar 2020 22:43:43 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7FCBC9CC80129CB05B7A; 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:31 +0800 From: Tian Tao To: , , , , , , , , , CC: Subject: [PATCH] drm/hisilicon: Add the load and unload for hibmc_driver Date: Fri, 6 Mar 2020 11:42:58 +0800 Message-ID: <1583466184-7060-1-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 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