mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00

a connector is leaked upon module unload, it seems that we should do similar to sample driver as suggested in drm_drv.c. Adding drm_atomic_helper_shutdown() in ast_pci_remove to prevent leaking. [ 153.822134] WARNING: CPU: 0 PID: 173 at drivers/gpu/drm/drm_mode_config.c:504 drm_mode_config_cle0 [ 153.822698] Modules linked in: ast(-) drm_vram_helper drm_ttm_helper ttm [last unloaded: ttm] [ 153.823197] CPU: 0 PID: 173 Comm: modprobe Tainted: G W 5.11.0-03615-g55f62bc873474 [ 153.823708] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-48-gd9c812dda519-4 [ 153.824333] RIP: 0010:drm_mode_config_cleanup+0x418/0x470 [ 153.824637] Code: 0c 00 00 00 00 48 8b 84 24 a8 00 00 00 65 48 33 04 25 28 00 00 00 75 65 48 81 c0 [ 153.825668] RSP: 0018:ffff888103c9fb70 EFLAGS: 00010212 [ 153.825962] RAX: ffff888102b0d100 RBX: ffff888102b0c298 RCX: ffffffff818d8b2b [ 153.826356] RDX: dffffc0000000000 RSI: 000000007fffffff RDI: ffff888102b0c298 [ 153.826748] RBP: ffff888103c9fba0 R08: 0000000000000001 R09: ffffed1020561857 [ 153.827146] R10: ffff888102b0c2b7 R11: ffffed1020561856 R12: ffff888102b0c000 [ 153.827538] R13: ffff888102b0c2d8 R14: ffff888102b0c2d8 R15: 1ffff11020793f70 [ 153.827935] FS: 00007f24bff456a0(0000) GS:ffff88815b400000(0000) knlGS:0000000000000000 [ 153.828380] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 153.828697] CR2: 0000000001c39018 CR3: 0000000103c90000 CR4: 00000000000006f0 [ 153.829096] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 153.829486] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 153.829883] Call Trace: [ 153.830024] ? drmm_mode_config_init+0x930/0x930 [ 153.830281] ? cpumask_next+0x16/0x20 [ 153.830488] ? mnt_get_count+0x66/0x80 [ 153.830699] ? drm_mode_config_cleanup+0x470/0x470 [ 153.830972] drm_managed_release+0xed/0x1c0 [ 153.831208] drm_dev_release+0x3a/0x50 [ 153.831420] release_nodes+0x39e/0x410 [ 153.831631] ? devres_release+0x40/0x40 [ 153.831852] device_release_driver_internal+0x158/0x270 [ 153.832143] driver_detach+0x76/0xe0 [ 153.832344] bus_remove_driver+0x7e/0x100 [ 153.832568] pci_unregister_driver+0x28/0xf0 [ 153.832821] __x64_sys_delete_module+0x268/0x300 [ 153.833086] ? __ia32_sys_delete_module+0x300/0x300 [ 153.833357] ? call_rcu+0x372/0x4f0 [ 153.833553] ? fpregs_assert_state_consistent+0x4d/0x60 [ 153.833840] ? exit_to_user_mode_prepare+0x2f/0x130 [ 153.834118] do_syscall_64+0x33/0x40 [ 153.834317] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 153.834597] RIP: 0033:0x7f24bfec7cf7 [ 153.834797] Code: 48 89 57 30 48 8b 04 24 48 89 47 38 e9 1d a0 02 00 48 89 f8 48 89 f7 48 89 d6 41 [ 153.835812] RSP: 002b:00007fff72e6cb58 EFLAGS: 00000202 ORIG_RAX: 00000000000000b0 [ 153.836234] RAX: ffffffffffffffda RBX: 00007f24bff45690 RCX: 00007f24bfec7cf7 [ 153.836623] RDX: 00000000ffffffff RSI: 0000000000000080 RDI: 0000000001c2fb10 [ 153.837018] RBP: 0000000001c2fac0 R08: 2f2f2f2f2f2f2f2f R09: 0000000001c2fac0 [ 153.837408] R10: fefefefefefefeff R11: 0000000000000202 R12: 0000000001c2fac0 [ 153.837798] R13: 0000000001c2f9d0 R14: 0000000000000000 R15: 0000000000000001 [ 153.838194] ---[ end trace b92031513bbe596c ]--- [ 153.838441] [drm:drm_mode_config_cleanup] *ERROR* connector VGA-1 leaked! Signed-off-by: Tong Zhang <ztong0001@gmail.com> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Link: https://patchwork.freedesktop.org/patch/msgid/20210222023322.984885-1-ztong0001@gmail.com
256 lines
5.8 KiB
C
256 lines
5.8 KiB
C
/*
|
|
* Copyright 2012 Red Hat Inc.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the
|
|
* "Software"), to deal in the Software without restriction, including
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The above copyright notice and this permission notice (including the
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
* of the Software.
|
|
*
|
|
*/
|
|
/*
|
|
* Authors: Dave Airlie <airlied@redhat.com>
|
|
*/
|
|
|
|
#include <linux/console.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_crtc_helper.h>
|
|
#include <drm/drm_drv.h>
|
|
#include <drm/drm_fb_helper.h>
|
|
#include <drm/drm_gem_vram_helper.h>
|
|
#include <drm/drm_probe_helper.h>
|
|
|
|
#include "ast_drv.h"
|
|
|
|
int ast_modeset = -1;
|
|
|
|
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
|
|
module_param_named(modeset, ast_modeset, int, 0400);
|
|
|
|
/*
|
|
* DRM driver
|
|
*/
|
|
|
|
DEFINE_DRM_GEM_FOPS(ast_fops);
|
|
|
|
static const struct drm_driver ast_driver = {
|
|
.driver_features = DRIVER_ATOMIC |
|
|
DRIVER_GEM |
|
|
DRIVER_MODESET,
|
|
|
|
.fops = &ast_fops,
|
|
.name = DRIVER_NAME,
|
|
.desc = DRIVER_DESC,
|
|
.date = DRIVER_DATE,
|
|
.major = DRIVER_MAJOR,
|
|
.minor = DRIVER_MINOR,
|
|
.patchlevel = DRIVER_PATCHLEVEL,
|
|
|
|
DRM_GEM_VRAM_DRIVER
|
|
};
|
|
|
|
/*
|
|
* PCI driver
|
|
*/
|
|
|
|
#define PCI_VENDOR_ASPEED 0x1a03
|
|
|
|
#define AST_VGA_DEVICE(id, info) { \
|
|
.class = PCI_BASE_CLASS_DISPLAY << 16, \
|
|
.class_mask = 0xff0000, \
|
|
.vendor = PCI_VENDOR_ASPEED, \
|
|
.device = id, \
|
|
.subvendor = PCI_ANY_ID, \
|
|
.subdevice = PCI_ANY_ID, \
|
|
.driver_data = (unsigned long) info }
|
|
|
|
static const struct pci_device_id ast_pciidlist[] = {
|
|
AST_VGA_DEVICE(PCI_CHIP_AST2000, NULL),
|
|
AST_VGA_DEVICE(PCI_CHIP_AST2100, NULL),
|
|
{0, 0, 0},
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, ast_pciidlist);
|
|
|
|
static void ast_kick_out_firmware_fb(struct pci_dev *pdev)
|
|
{
|
|
struct apertures_struct *ap;
|
|
bool primary = false;
|
|
|
|
ap = alloc_apertures(1);
|
|
if (!ap)
|
|
return;
|
|
|
|
ap->ranges[0].base = pci_resource_start(pdev, 0);
|
|
ap->ranges[0].size = pci_resource_len(pdev, 0);
|
|
|
|
#ifdef CONFIG_X86
|
|
primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
|
|
#endif
|
|
drm_fb_helper_remove_conflicting_framebuffers(ap, "astdrmfb", primary);
|
|
kfree(ap);
|
|
}
|
|
|
|
static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
|
{
|
|
struct ast_private *ast;
|
|
struct drm_device *dev;
|
|
int ret;
|
|
|
|
ast_kick_out_firmware_fb(pdev);
|
|
|
|
ret = pcim_enable_device(pdev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ast = ast_device_create(&ast_driver, pdev, ent->driver_data);
|
|
if (IS_ERR(ast))
|
|
return PTR_ERR(ast);
|
|
dev = &ast->base;
|
|
|
|
ret = drm_dev_register(dev, ent->driver_data);
|
|
if (ret)
|
|
return ret;
|
|
|
|
drm_fbdev_generic_setup(dev, 32);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void ast_pci_remove(struct pci_dev *pdev)
|
|
{
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
drm_dev_unregister(dev);
|
|
drm_atomic_helper_shutdown(dev);
|
|
}
|
|
|
|
static int ast_drm_freeze(struct drm_device *dev)
|
|
{
|
|
int error;
|
|
|
|
error = drm_mode_config_helper_suspend(dev);
|
|
if (error)
|
|
return error;
|
|
pci_save_state(to_pci_dev(dev->dev));
|
|
return 0;
|
|
}
|
|
|
|
static int ast_drm_thaw(struct drm_device *dev)
|
|
{
|
|
ast_post_gpu(dev);
|
|
|
|
return drm_mode_config_helper_resume(dev);
|
|
}
|
|
|
|
static int ast_drm_resume(struct drm_device *dev)
|
|
{
|
|
int ret;
|
|
|
|
if (pci_enable_device(to_pci_dev(dev->dev)))
|
|
return -EIO;
|
|
|
|
ret = ast_drm_thaw(dev);
|
|
if (ret)
|
|
return ret;
|
|
return 0;
|
|
}
|
|
|
|
static int ast_pm_suspend(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *ddev = pci_get_drvdata(pdev);
|
|
int error;
|
|
|
|
error = ast_drm_freeze(ddev);
|
|
if (error)
|
|
return error;
|
|
|
|
pci_disable_device(pdev);
|
|
pci_set_power_state(pdev, PCI_D3hot);
|
|
return 0;
|
|
}
|
|
|
|
static int ast_pm_resume(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *ddev = pci_get_drvdata(pdev);
|
|
return ast_drm_resume(ddev);
|
|
}
|
|
|
|
static int ast_pm_freeze(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *ddev = pci_get_drvdata(pdev);
|
|
return ast_drm_freeze(ddev);
|
|
}
|
|
|
|
static int ast_pm_thaw(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *ddev = pci_get_drvdata(pdev);
|
|
return ast_drm_thaw(ddev);
|
|
}
|
|
|
|
static int ast_pm_poweroff(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *ddev = pci_get_drvdata(pdev);
|
|
|
|
return ast_drm_freeze(ddev);
|
|
}
|
|
|
|
static const struct dev_pm_ops ast_pm_ops = {
|
|
.suspend = ast_pm_suspend,
|
|
.resume = ast_pm_resume,
|
|
.freeze = ast_pm_freeze,
|
|
.thaw = ast_pm_thaw,
|
|
.poweroff = ast_pm_poweroff,
|
|
.restore = ast_pm_resume,
|
|
};
|
|
|
|
static struct pci_driver ast_pci_driver = {
|
|
.name = DRIVER_NAME,
|
|
.id_table = ast_pciidlist,
|
|
.probe = ast_pci_probe,
|
|
.remove = ast_pci_remove,
|
|
.driver.pm = &ast_pm_ops,
|
|
};
|
|
|
|
static int __init ast_init(void)
|
|
{
|
|
if (vgacon_text_force() && ast_modeset == -1)
|
|
return -EINVAL;
|
|
|
|
if (ast_modeset == 0)
|
|
return -EINVAL;
|
|
return pci_register_driver(&ast_pci_driver);
|
|
}
|
|
static void __exit ast_exit(void)
|
|
{
|
|
pci_unregister_driver(&ast_pci_driver);
|
|
}
|
|
|
|
module_init(ast_init);
|
|
module_exit(ast_exit);
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
MODULE_LICENSE("GPL and additional rights");
|