diff options
author | Jon Smirl <jonsmirl@yahoo.com> | 2005-06-24 22:48:16 +0000 |
---|---|---|
committer | Jon Smirl <jonsmirl@yahoo.com> | 2005-06-24 22:48:16 +0000 |
commit | 9deb276a0680a79540f05c1547a9d703e9c08190 (patch) | |
tree | 038d7230cd455fe49f951cb87c31cdd20dcb2051 | |
parent | 2b845f25c5c3a36ed6e49b9145e38a4738ce2572 (diff) |
Ref count the sysdev class to support multiple DRM cards
-rw-r--r-- | linux-core/drm_pm.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/linux-core/drm_pm.c b/linux-core/drm_pm.c index f0dc4db6..b37cced1 100644 --- a/linux-core/drm_pm.c +++ b/linux-core/drm_pm.c @@ -67,7 +67,7 @@ static int shutdown(struct sys_device *sysdev) return 0; } -static int sysdev_loaded = 0; +static atomic_t sysdev_loaded = ATOMIC_INIT(-1); static struct sysdev_class drm_sysdev_class = { set_kset_name("drm"), .resume = drm_resume, @@ -124,14 +124,27 @@ int drm_pm_init(void) int rc; DRM_DEBUG("\n"); - if (!(rc = sysdev_class_register(&drm_sysdev_class))) - sysdev_loaded = 1; + /* triggers on -1 to 0 transition */ + if (!atomic_inc_and_test(&sysdev_loaded)) + return 0; + + if ((rc = sysdev_class_register(&drm_sysdev_class))) { + /* reset it back to -1 */ + atomic_dec(&sysdev_loaded); + } else { + /* inc it up to 1 so that unload will trigger on 1->0 */ + atomic_inc(&sysdev_loaded); + DRM_DEBUG("registered\n"); + } return rc; } void __exit drm_pm_exit(void) { DRM_DEBUG("\n"); - if (sysdev_loaded) + /* triggers on the 1 to 0 transistion */ + if (atomic_dec_and_test(&sysdev_loaded)) { sysdev_class_unregister(&drm_sysdev_class); + DRM_DEBUG("unregisted\n"); + } } |