kvm-guest-drivers-windows
99 строк · 3.6 Кб
1/*
2* Main driver file containing DriverEntry and driver related functions
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
30#include "precomp.h"
31#include "vioinput.h"
32
33#if defined(EVENT_TRACING)
34#include "Driver.tmh"
35#endif
36
37DRIVER_INITIALIZE DriverEntry;
38
39// Context cleanup callbacks generally run at IRQL <= DISPATCH_LEVEL but
40// WDFDRIVER context cleanup is guaranteed to run at PASSIVE_LEVEL.
41// Annotate the prototype to make static analysis happy.
42EVT_WDF_OBJECT_CONTEXT_CLEANUP _IRQL_requires_(PASSIVE_LEVEL) VIOInputEvtDriverContextCleanup;
43
44#ifdef ALLOC_PRAGMA
45#pragma alloc_text (INIT, DriverEntry)
46#pragma alloc_text (PAGE, VIOInputEvtDriverContextCleanup)
47#endif
48
49NTSTATUS
50DriverEntry(
51IN PDRIVER_OBJECT DriverObject,
52IN PUNICODE_STRING RegistryPath)
53{
54NTSTATUS status = STATUS_SUCCESS;
55WDF_DRIVER_CONFIG config;
56WDF_OBJECT_ATTRIBUTES attributes;
57WDFDRIVER driver;
58
59ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
60
61InitializeDebugPrints(DriverObject, RegistryPath);
62
63TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT,
64"Virtio-input driver started...built on %s %s\n", __DATE__, __TIME__);
65
66WDF_DRIVER_CONFIG_INIT(&config,VIOInputEvtDeviceAdd);
67config.DriverPoolTag = VIOINPUT_DRIVER_MEMORY_TAG;
68
69WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
70attributes.EvtCleanupCallback = VIOInputEvtDriverContextCleanup;
71
72status = WdfDriverCreate(DriverObject,
73RegistryPath,
74&attributes,
75&config,
76&driver);
77
78if (!NT_SUCCESS(status))
79{
80TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
81"WdfDriverCreate failed - 0x%x\n", status);
82WPP_CLEANUP(DriverObject);
83return status;
84}
85
86TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__);
87return status;
88}
89
90VOID
91VIOInputEvtDriverContextCleanup(
92IN WDFOBJECT Driver)
93{
94PAGED_CODE();
95
96TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<--> %s\n", __FUNCTION__);
97
98WPP_CLEANUP(WdfDriverWdmGetDriverObject((WDFDRIVER)Driver));
99}
100