/* * Intel QV Linux kernel driver * Copyright (c) 1999 - 2017, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * */ /* * * Module Name: * linuxnaldriver.c * * Abstract: * This contains the functions necessary for the Linux Driver * component of NAL to function as a driver. This includes the * driver entry point and all Linux specific ring 0 functions. * * */ #include #include #include #include #include #include #include #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) #include #else #include #endif #include "naltypes.h" #include "nalioctl.h" #include "linuxnaldriver.h" int init_module(void); void cleanup_module(void); extern spinlock_t Global_AtomicTestSetSpinLock; static char Global_NalDeviceName[] = NAL_OS_SPEC_QV_DRIVER_NAME; static int Global_NalMajor = 0; NAL_OS_SPEC_ADAPTER_IN_USE_TABLE Global_AdapterInUse[NAL_OS_SPEC_MAX_PCI_DEVICES]; UINT32 Global_DriverReferenceCount = 0; static struct file_operations Global_NalFops = { owner: THIS_MODULE, #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) ioctl: NalDeviceControl, #endif #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,10) unlocked_ioctl: NalDeviceControlUnlockedIoctl, #endif open: NalOpen, release: NalRelease, mmap: NalMmap }; MODULE_AUTHOR(NAL_OS_SPEC_DRIVER_COMPANYNAME); MODULE_DESCRIPTION(NAL_OS_SPEC_DRIVER_DESCRIPTION); MODULE_LICENSE("GPL"); MODULE_VERSION(NAL_OS_SPEC_DRIVER_VERSION); int init_module(void) { int Result = 0; UINT32 i = 0; printk(KERN_DEBUG "Intel Pro Diagnostic Driver loading (v. %s)\n", NAL_OS_SPEC_DRIVER_VERSION); Result = register_chrdev(0, Global_NalDeviceName, &Global_NalFops); if(Result < 0) { Result = -ENODEV; } else { Global_NalMajor = Result; Result = 0; } for(i=0; ivm_start, Vma->vm_pgoff, Vma->vm_end - Vma->vm_start, Vma->vm_page_prot)) { return -EAGAIN; } return 0; } UINT32 _NalDriverGetReferenceCount( VOID ) { return Global_DriverReferenceCount; } VOID _NalDriverIncrementReferenceCount( VOID ) { spin_lock(&Global_AtomicTestSetSpinLock); Global_DriverReferenceCount++; spin_unlock(&Global_AtomicTestSetSpinLock); } VOID _NalDriverDecrementReferenceCount( VOID ) { spin_lock(&Global_AtomicTestSetSpinLock); if(Global_DriverReferenceCount > 0) { Global_DriverReferenceCount--; } spin_unlock(&Global_AtomicTestSetSpinLock); } VOID _NalDriverGetVersion( OUT CHAR* Version ) { sprintf(Version, "%d.%d.%d.%d", NAL_OS_SPEC_DRIVER_MAJOR_VERSION , NAL_OS_SPEC_DRIVER_MINOR_VERSION , NAL_OS_SPEC_DRIVER_BUILD_VERSION , NAL_OS_SPEC_DRIVER_FIX_VERSION ); }