From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44DA2C3B186 for ; Tue, 11 Feb 2020 14:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B6FD20848 for ; Tue, 11 Feb 2020 14:20:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="GIQ8GjOq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730036AbgBKOUC (ORCPT ); Tue, 11 Feb 2020 09:20:02 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52760 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729590AbgBKOUC (ORCPT ); Tue, 11 Feb 2020 09:20:02 -0500 Received: by mail-wm1-f67.google.com with SMTP id p9so3767276wmc.2 for ; Tue, 11 Feb 2020 06:19:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=Wnr+//oGH4uXMO6GDB7TwubX/nxe1+x76Hvs2NVGFuc=; b=GIQ8GjOqJrhLYKdgtLRlfIIfitARQxNz4LODBM0XdoUf+DS+VdY2Y9sLMV4cFvXUqg eDscMY7wgT8H5Jsa2+kdwu0cfcTeX/rUVrc8rw4U8dyqHg7XynQ7Bo4W4Qi0yNelAk05 JPspZp/zNtqJX4ZkZieNqJdpzqmVjUwIPtOfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=Wnr+//oGH4uXMO6GDB7TwubX/nxe1+x76Hvs2NVGFuc=; b=mPWJSuoOUfSx7bz3fqaE7BPsNLHbpHYaTv1KI+Bq7qol0RrjU6UuM1jywhrj1NIoS3 UtNqOJw2x4y/WRlUCekBBHJ4LtA3tBUqMhJCndUWyfAm5C5WClXUpQoqOJfM0TkPdLsH 4x/1NHDsKocxKue3/HY6jbmCmG+fs4hZoeTn5axM9pGyZU1mei31M5VmVgD4oqUeUYi5 2JpN+/xHFuCNX7RrD++APgZM+fHevE/ZL4+rbmDtjZWpNTBpEo2OQpoj91EzPwQRwTh1 qewlh7u6MUeY+FoptVJnLgowuHEABImwk8CeW3gFXkV1RB88dTTiTGHuxJ2DzD+vnWTJ BzBw== X-Gm-Message-State: APjAAAX5RpHdxx5owvMff7rU/FGt9LMNPZTh8xHzDwuwz2AD5g/nnh93 BB1u1PL4AvvWOhBUEHI+enyYpg== X-Google-Smtp-Source: APXvYqy6L5KPAi1i0sPrc30Ft7+bqgWt2Wm5wPwnLY5tKsWvuzgkp0nY4PgfSjs3STKYXkE0grFKJA== X-Received: by 2002:a05:600c:34b:: with SMTP id u11mr5830687wmd.69.1581430799258; Tue, 11 Feb 2020 06:19:59 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q14sm5394758wrj.81.2020.02.11.06.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 06:19:58 -0800 (PST) Date: Tue, 11 Feb 2020 15:19:56 +0100 From: Daniel Vetter To: Gerd Hoffmann Cc: dri-devel@lists.freedesktop.org, daniel@ffwll.ch, David Airlie , "open list:DRM DRIVER FOR BOCHS VIRTUAL GPU" , open list Subject: Re: [PATCH v4] drm/bochs: add drm_driver.release callback. Message-ID: <20200211141956.GC2363188@phenom.ffwll.local> Mail-Followup-To: Gerd Hoffmann , dri-devel@lists.freedesktop.org, David Airlie , "open list:DRM DRIVER FOR BOCHS VIRTUAL GPU" , open list References: <20200211135218.22871-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200211135218.22871-1-kraxel@redhat.com> X-Operating-System: Linux phenom 5.3.0-3-amd64 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2020 at 02:52:18PM +0100, Gerd Hoffmann wrote: > Call bochs_unload via drm_driver.release to make sure we release stuff > when it is safe to do so. Use drm_dev_{enter,exit,unplug} to avoid > touching hardware after device removal. Tidy up here and there. > > v4: add changelog. > v3: use drm_dev_*(). > v2: move hardware deinit to pci_remove(). > > Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel Vetter Btw I checked around whether there's anything else that obviously needs a drm_dev_enter/exit, and I spotted the !bochs->mmio check in bochs_hw_load_edid. That one looks like cargo-cult, there's a single caller in the init path, so either mmio works at that point or this is dead code ... slightly confusing. -Daniel > --- > drivers/gpu/drm/bochs/bochs_drv.c | 6 +++--- > drivers/gpu/drm/bochs/bochs_hw.c | 24 +++++++++++++++++++++++- > 2 files changed, 26 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/bochs/bochs_drv.c b/drivers/gpu/drm/bochs/bochs_drv.c > index 10460878414e..addb0568c1af 100644 > --- a/drivers/gpu/drm/bochs/bochs_drv.c > +++ b/drivers/gpu/drm/bochs/bochs_drv.c > @@ -23,7 +23,6 @@ static void bochs_unload(struct drm_device *dev) > > bochs_kms_fini(bochs); > bochs_mm_fini(bochs); > - bochs_hw_fini(dev); > kfree(bochs); > dev->dev_private = NULL; > } > @@ -69,6 +68,7 @@ static struct drm_driver bochs_driver = { > .major = 1, > .minor = 0, > DRM_GEM_VRAM_DRIVER, > + .release = bochs_unload, > }; > > /* ---------------------------------------------------------------------- */ > @@ -148,9 +148,9 @@ static void bochs_pci_remove(struct pci_dev *pdev) > { > struct drm_device *dev = pci_get_drvdata(pdev); > > + drm_dev_unplug(dev); > drm_atomic_helper_shutdown(dev); > - drm_dev_unregister(dev); > - bochs_unload(dev); > + bochs_hw_fini(dev); > drm_dev_put(dev); > } > > diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c > index b615b7dfdd9d..952199cc0462 100644 > --- a/drivers/gpu/drm/bochs/bochs_hw.c > +++ b/drivers/gpu/drm/bochs/bochs_hw.c > @@ -4,6 +4,7 @@ > > #include > > +#include > #include > > #include "bochs.h" > @@ -194,6 +195,8 @@ void bochs_hw_fini(struct drm_device *dev) > { > struct bochs_device *bochs = dev->dev_private; > > + /* TODO: shot down existing vram mappings */ > + > if (bochs->mmio) > iounmap(bochs->mmio); > if (bochs->ioports) > @@ -207,6 +210,11 @@ void bochs_hw_fini(struct drm_device *dev) > void bochs_hw_setmode(struct bochs_device *bochs, > struct drm_display_mode *mode) > { > + int idx; > + > + if (!drm_dev_enter(bochs->dev, &idx)) > + return; > + > bochs->xres = mode->hdisplay; > bochs->yres = mode->vdisplay; > bochs->bpp = 32; > @@ -232,11 +240,18 @@ void bochs_hw_setmode(struct bochs_device *bochs, > > bochs_dispi_write(bochs, VBE_DISPI_INDEX_ENABLE, > VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED); > + > + drm_dev_exit(idx); > } > > void bochs_hw_setformat(struct bochs_device *bochs, > const struct drm_format_info *format) > { > + int idx; > + > + if (!drm_dev_enter(bochs->dev, &idx)) > + return; > + > DRM_DEBUG_DRIVER("format %c%c%c%c\n", > (format->format >> 0) & 0xff, > (format->format >> 8) & 0xff, > @@ -256,13 +271,18 @@ void bochs_hw_setformat(struct bochs_device *bochs, > __func__, format->format); > break; > } > + > + drm_dev_exit(idx); > } > > void bochs_hw_setbase(struct bochs_device *bochs, > int x, int y, int stride, u64 addr) > { > unsigned long offset; > - unsigned int vx, vy, vwidth; > + unsigned int vx, vy, vwidth, idx; > + > + if (!drm_dev_enter(bochs->dev, &idx)) > + return; > > bochs->stride = stride; > offset = (unsigned long)addr + > @@ -277,4 +297,6 @@ void bochs_hw_setbase(struct bochs_device *bochs, > bochs_dispi_write(bochs, VBE_DISPI_INDEX_VIRT_WIDTH, vwidth); > bochs_dispi_write(bochs, VBE_DISPI_INDEX_X_OFFSET, vx); > bochs_dispi_write(bochs, VBE_DISPI_INDEX_Y_OFFSET, vy); > + > + drm_dev_exit(idx); > } > -- > 2.18.2 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch