drm/bochs: add drm_driver.release callback.
Subsystems (3)
PATCH v2 1/1 drm/bochs: add drm_driver.release callback.
Call drm_dev_unregister() first in bochs_pci_remove(). Hook bochs_unload() into the new .release callback, to make sure cleanup is done when all users are gone.
Add ready bool to state struct and move bochs_hw_fini() call from bochs_unload() to bochs_pci_remove() to make sure hardware is not touched after bochs_pci_remove returns.
--- drivers/gpu/drm/bochs/bochs.h | 1 + drivers/gpu/drm/bochs/bochs_drv.c | 6 +++--- drivers/gpu/drm/bochs/bochs_hw.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/bochs/bochs.h +1 -0
@@ -57,6 +57,7 @@ struct bochs_device {unsigned long fb_base;unsigned long fb_size;unsigned long qext_size; +bool ready;/* mode */ u16 xres;
drivers/gpu/drm/bochs/bochs_drv.c +3 -3
@@ -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_atomic_helper_shutdown (dev);drm_dev_unregister (dev); -bochs_unload (dev); +drm_atomic_helper_shutdown (dev); +bochs_hw_fini (dev);drm_dev_put (dev); }
drivers/gpu/drm/bochs/bochs_hw.c +14 -0
@@ -168,6 +168,7 @@ int bochs_hw_init(struct drm_device *dev) } bochs->fb_base = addr; bochs->fb_size = size; + bochs->ready = true;DRM_INFO ("Found bochs VGA, ID 0x%x.\n" , id); DRM_INFO("Framebuffer size %ld kB @ 0x%lx, %s @ 0x%lx.\n",
@@ -194,6 +195,10 @@ void bochs_hw_fini(struct drm_device *dev) {struct bochs_device *bochs = dev->dev_private; + bochs->ready = false; + +/* TODO: shot down existing vram mappings */ +if (bochs->mmio)iounmap (bochs->mmio);if (bochs->ioports)
@@ -207,6 +212,9 @@ void bochs_hw_fini(struct drm_device *dev)void bochs_hw_setmode (struct bochs_device *bochs,struct drm_display_mode *mode) { +if (!bochs->ready) +return ; + bochs->xres = mode->hdisplay; bochs->yres = mode->vdisplay; bochs->bpp =32 ;
@@ -237,6 +245,9 @@ void bochs_hw_setmode(struct bochs_device *bochs,void bochs_hw_setformat (struct bochs_device *bochs,const struct drm_format_info *format) { +if (!bochs->ready) +return ; + DRM_DEBUG_DRIVER("format %c%c%c%c\n", (format->format >> 0) & 0xff, (format->format >> 8) & 0xff,
@@ -264,6 +275,9 @@ void bochs_hw_setbase(struct bochs_device *bochs,unsigned long offset;unsigned int vx, vy, vwidth; +if (!bochs->ready) +return ; + bochs->stride = stride; offset = (unsigned long )addr + y * bochs->stride +
Signature · 1 line
2.18.1
Quoted 72 lines · Gerd Hoffmann
Call
drm_dev_unregister()first inbochs_pci_remove(). Hookbochs_unload()into the new .release callback, to make sure cleanup is done when all users are gone.Add ready bool to state struct and move
bochs_hw_fini()call frombochs_unload()tobochs_pci_remove()to make sure hardware is not touched afterbochs_pci_removereturns.Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/bochs/bochs.h | 1 + drivers/gpu/drm/bochs/bochs_drv.c | 6 +++--- drivers/gpu/drm/bochs/bochs_hw.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-)drivers/gpu/drm/bochs/bochs.h +1
-0@@ -57,6 +57,7 @@ struct bochs_device {unsigned long fb_base;unsigned long fb_size;unsigned long qext_size; +bool ready;/* mode */ u16 xres;drivers/gpu/drm/bochs/bochs_drv.c +3
-3@@ -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_atomic_helper_shutdown (dev);drm_dev_unregister (dev); -bochs_unload (dev); +drm_atomic_helper_shutdown (dev); +bochs_hw_fini (dev);drm_dev_put (dev); }drivers/gpu/drm/bochs/bochs_hw.c +1
-0@@ -168,6 +168,7 @@ int bochs_hw_init(struct drm_device *dev) } bochs->fb_base = addr; bochs->fb_size = size; + bochs->ready = true;DRM_INFO ("Found bochs VGA, ID 0x%x.\n" , id); DRM_INFO("Framebuffer size %ld kB @ 0x%lx, %s @ 0x%lx.\n",
drivers/gpu/drm/bochs/bochs_hw.c void bochs_hw_fini(struct drm_device *dev) · line 200
Quoted 6 lines
drivers/gpu/drm/bochs/bochs_hw.c +3
-0@@ -194,6 +195,10 @@ void bochs_hw_fini(struct drm_device *dev) {struct bochs_device *bochs = dev->dev_private; + bochs->ready = false; + +/* TODO: shot down existing vram mappings */
Aside: I'm mildly hopefull that we could do this with a generic helper, both punching out all current ptes and replacing them with something dummy. Since replacing them with nothing and refusing to fault stuff is probably not going to work out well - userspace will crash&burn too much.
drivers/gpu/drm/bochs/bochs_hw.c void bochs_hw_fini(struct drm_device *dev) · line 216
Quoted 10 lines
drivers/gpu/drm/bochs/bochs_hw.c +3
-0+if (bochs->mmio)iounmap (bochs->mmio);if (bochs->ioports)@@ -207,6 +212,9 @@ void bochs_hw_fini(struct drm_device *dev)void bochs_hw_setmode (struct bochs_device *bochs,struct drm_display_mode *mode) { +if (!bochs->ready) +return ;
drm_dev_enter/exit is the primitive you're looking for I think. Don't hand roll your own racy version of this. btw changelog in the patch missing. Personally I'd split out the drm_dev_enter/exit in a 2nd patch, but up to you.
The remove/release split looks correct to me now.
-Daniel
Quoted 27 lines
drivers/gpu/drm/bochs/bochs_hw.c +7
-0+ bochs->xres = mode->hdisplay; bochs->yres = mode->vdisplay; bochs->bpp =32 ;@@ -237,6 +245,9 @@ void bochs_hw_setmode(struct bochs_device *bochs,void bochs_hw_setformat (struct bochs_device *bochs,const struct drm_format_info *format) { +if (!bochs->ready) +return ; + DRM_DEBUG_DRIVER("format %c%c%c%c\n", (format->format >> 0) & 0xff, (format->format >> 8) & 0xff,@@ -264,6 +275,9 @@ void bochs_hw_setbase(struct bochs_device *bochs,unsigned long offset;unsigned int vx, vy, vwidth; +if (!bochs->ready) +return ; + bochs->stride = stride; offset = (unsigned long )addr + y * bochs->stride +Signature · 1 line
2.18.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch