VirtualBox

Changeset 13924

Show
Ignore:
Timestamp:
11/06/08 16:50:56 (2 months ago)
Author:
vboxsync
Message:

vboxdrv: R0 suspend/resume notifier

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r13865 r13924  
    4646#include <iprt/err.h> 
    4747#include <iprt/mem.h> 
     48#include <iprt/power.h> 
    4849#include <VBox/log.h> 
    4950#include <iprt/mp.h> 
     
    6162#  include <asm/nmi.h> 
    6263# endif 
     64#endif 
     65#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) 
     66# include <linux/suspend.h> 
    6367#endif 
    6468 
     
    229233static int      VBoxDrvLinuxIOCtlSlow(struct file *pFilp, unsigned int uCmd, unsigned long ulArg); 
    230234static int      VBoxDrvLinuxErr2LinuxErr(int); 
     235#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) 
     236static int      VBoxDrvSuspendNotifier(struct notifier_block *pBlock, unsigned long uEvent, void *dummy); 
     237#endif 
    231238 
    232239 
     
    258265#endif 
    259266 
    260  
     267#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) 
     268/** Suspend/resume notifier. */ 
     269static struct notifier_block gSuspendNotifierBlock = 
     270
     271    .notifier_call = VBoxDrvSuspendNotifier, 
     272}; 
     273#endif 
    261274 
    262275 
     
    556569            if (RT_SUCCESS(rc)) 
    557570                rc = supdrvInitDevExt(&g_DevExt); 
    558             if (!rc
     571            if (RT_SUCCESS(rc)
    559572            { 
    560                 printk(KERN_INFO DEVICE_NAME ": TSC mode is %s, kernel timer mode is " 
     573#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) 
     574                /* 
     575                 * Register the suspend/resume notifier. 
     576                 */ 
     577                rc = register_pm_notifier(&gSuspendNotifierBlock); 
     578                if (rc == 0) 
     579#endif 
     580                { 
     581                    printk(KERN_INFO DEVICE_NAME ": TSC mode is %s, kernel timer mode is " 
    561582#ifdef VBOX_HRTIMER 
    562                        "'high-res'" 
     583                           "'high-res'" 
    563584#else 
    564                        "'normal'" 
    565 #endif 
    566                        ".\n", 
    567                        g_DevExt.pGip->u32Mode == SUPGIPMODE_SYNC_TSC ? "'synchronous'" : "'asynchronous'"); 
    568                 LogFlow(("VBoxDrv::ModuleInit returning %#x\n", rc)); 
    569                 printk(KERN_DEBUG DEVICE_NAME ": Successfully loaded version " 
    570                        VBOX_VERSION_STRING " (interface " xstr(SUPDRV_IOC_VERSION) ").\n"); 
    571                 return rc; 
     585                           "'normal'" 
     586#endif 
     587                           ".\n", 
     588                           g_DevExt.pGip->u32Mode == SUPGIPMODE_SYNC_TSC ? "'synchronous'" : "'asynchronous'"); 
     589                    LogFlow(("VBoxDrv::ModuleInit returning %#x\n", rc)); 
     590                    printk(KERN_DEBUG DEVICE_NAME ": Successfully loaded version " 
     591                            VBOX_VERSION_STRING " (interface " xstr(SUPDRV_IOC_VERSION) ").\n"); 
     592                    return rc; 
     593                } 
    572594            } 
    573595 
     
    605627    NOREF(rc); 
    606628 
     629#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) 
     630    /* 
     631     * Unregister the suspend/resume notifier. 
     632     */ 
     633    unregister_pm_notifier(&gSuspendNotifierBlock); 
     634#endif 
     635 
    607636    /* 
    608637     * I Don't think it's possible to unload a driver which processes have 
     
    612641    rc = misc_deregister(&gMiscDevice); 
    613642    if (rc < 0) 
    614     { 
    615643        dprintf(("misc_deregister failed with rc=%#x\n", rc)); 
    616     } 
    617644#else  /* !CONFIG_VBOXDRV_AS_MISC */ 
    618645# ifdef CONFIG_DEVFS_FS 
     
    689716    return 0; 
    690717} 
     718 
     719 
     720#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) 
     721/** 
     722 * Suspend/resume callback. 
     723 * 
     724 * @param   pNotifier 
     725 * @param   uEvent      event type 
     726 * @param   dummy 
     727 */ 
     728static int VBoxDrvSuspendNotifier(struct notifier_block *pBlock, unsigned long uEvent, void *dummy) 
     729{ 
     730    switch (uEvent) 
     731    { 
     732        case PM_SUSPEND_PREPARE: 
     733        case PM_POST_SUSPEND: 
     734            RTPowerSignalEvent(uEvent == PM_SUSPEND_PREPARE ? RTPOWEREVENT_SUSPEND 
     735                                                            : RTPOWEREVENT_RESUME); 
     736            break; 
     737    } 
     738    return 0; 
     739} 
     740#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) */ 
    691741 
    692742 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy