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