kvm-guest-drivers-windows
128 строк · 3.8 Кб
1/*
2* This file contains various vioinput driver routines
3*
4* Copyright (c) 2016-2017 Red Hat, Inc.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions
8* are met :
9* 1. Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* 2. Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and / or other materials provided with the distribution.
14* 3. Neither the names of the copyright holders nor the names of their contributors
15* may be used to endorse or promote products derived from this software
16* without specific prior written permission.
17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27* SUCH DAMAGE.
28*/
29#include "precomp.h"30#include "vioinput.h"31
32#if defined(EVENT_TRACING)33#include "utils.tmh"34#endif35
36#define TEMP_BUFFER_SIZE 25637
38// Global debug printout level and enable\disable flag
39int virtioDebugLevel;40int bDebugPrint;41int driverDebugLevel;42ULONG driverDebugFlags;43
44#if defined(COM_DEBUG)45
46#define RHEL_DEBUG_PORT ((PUCHAR)0x3F8)47
48static void DebugPrintFuncSerial(const char *format, ...)49{
50char buf[TEMP_BUFFER_SIZE];51NTSTATUS status;52size_t len;53va_list list;54va_start(list, format);55status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);56if (status == STATUS_SUCCESS)57{58len = strlen(buf);59}60else61{62len = 2;63buf[0] = 'O';64buf[1] = '\n';65}66if (len)67{68WRITE_PORT_BUFFER_UCHAR(RHEL_DEBUG_PORT, (PUCHAR)buf, len);69WRITE_PORT_UCHAR(RHEL_DEBUG_PORT, '\r');70}71va_end(list);72}
73#endif74
75#if defined(PRINT_DEBUG)76static void DebugPrintFunc(const char *format, ...)77{
78va_list list;79va_start(list, format);80vDbgPrintEx(DPFLTR_DEFAULT_ID, 9 | DPFLTR_MASK, format, list);81va_end(list);82}
83#endif84
85static void DebugPrintFuncWPP(const char *format, ...)86{
87char buf[256];88NTSTATUS status;89va_list list;90va_start(list, format);91status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list);92if (status == STATUS_SUCCESS)93{94TraceEvents(TRACE_LEVEL_WARNING, DBG_HW_ACCESS, "%s", buf);95}96va_end(list);97}
98
99static void NoDebugPrintFunc(const char *format, ...)100{
101UNREFERENCED_PARAMETER(format);102}
103
104
105void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)106{
107WPP_INIT_TRACING(DriverObject, RegistryPath);108//TODO - Read nDebugLevel and bDebugPrint from the registry109#if defined(EVENT_TRACING)110VirtioDebugPrintProc = DebugPrintFuncWPP;111#elif defined(PRINT_DEBUG)112VirtioDebugPrintProc = DebugPrintFunc;113#elif defined(COM_DEBUG)114VirtioDebugPrintProc = DebugPrintFuncSerial;115#else116VirtioDebugPrintProc = NoDebugPrintFunc;117#endif118driverDebugFlags = 0xffffffff;119
120UNREFERENCED_PARAMETER(DriverObject);121UNREFERENCED_PARAMETER(RegistryPath);122
123bDebugPrint = 1;124driverDebugLevel = TRACE_LEVEL_INFORMATION;125virtioDebugLevel = 1;126}
127
128tDebugPrintFunc VirtioDebugPrintProc;129