initterm-r0drv-linux.c revision 1d78e6358c47c7fe42af63c999c6308b11325a1a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/* $Id$ */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/** @file
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * IPRT - Initialization & Termination, R0 Driver, Linux.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright (C) 2006-2011 Oracle Corporation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * available from http://www.virtualbox.org. This file is free software;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * General Public License (GPL) as published by the Free Software
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file may alternatively be used under the terms
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * of the Common Development and Distribution License Version 1.0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * VirtualBox OSE distribution, in which case the provisions of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL are applicable instead of those of the GPL.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may elect to license modified versions of this file under the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * terms and conditions of either the GPL or the CDDL or both.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*******************************************************************************
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync* Header Files *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync*******************************************************************************/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "the-linux-kernel.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "internal/iprt.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <iprt/err.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <iprt/assert.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include "internal/initterm.h"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*******************************************************************************
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync* Global Variables *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync*******************************************************************************/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/** The IPRT work queue. */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct workqueue_struct *g_prtR0LnxWorkQueue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic DECLARE_TASK_QUEUE(g_rtR0LnxWorkQueue);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*******************************************************************************
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync* Internal Functions *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync*******************************************************************************/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef RT_ARCH_AMD64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/* in alloc-r0drv0-linux.c */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncDECLHIDDEN(void) rtR0MemExecCleanup(void);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/**
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Pushes an item onto the IPRT work queue.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * @param pWork The work item.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * @param pfnWorker The callback function. It will be called back
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * with @a pWork as argument.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncDECLHIDDEN(void) rtR0LnxWorkqueuePush(RTR0LNXWORKQUEUEITEM *pWork, void (*pfnWorker)(RTR0LNXWORKQUEUEITEM *))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync INIT_WORK(pWork, pfnWorker);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync INIT_WORK(pWork, pfnWorker, pWork);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync queue_work(g_prtR0LnxWorkQueue, pWork);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync INIT_TQUEUE(pWork, (void (*)(void *))pfnWorker, pWork);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync queue_task(pWork, &g_rtR0LnxWorkQueue);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/**
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Flushes all items in the IPRT work queue.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * @remarks This is mostly for 2.4.x compatability. Must not be called from
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * atomic contexts or with unncessary locks held.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncDECLHIDDEN(void) rtR0LnxWorkqueueFlush(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync flush_workqueue(g_prtR0LnxWorkQueue);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync run_task_queue(&g_rtR0LnxWorkQueue);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncDECLHIDDEN(int) rtR0InitNative(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync g_prtR0LnxWorkQueue = create_workqueue("iprt");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!g_prtR0LnxWorkQueue)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return VERR_NO_MEMORY;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return VINF_SUCCESS;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncDECLHIDDEN(void) rtR0TermNative(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rtR0LnxWorkqueueFlush();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync destroy_workqueue(g_prtR0LnxWorkQueue);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync g_prtR0LnxWorkQueue = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef RT_ARCH_AMD64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rtR0MemExecCleanup();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync