Debian Codegraph @

windows/netuio/netuio_drv.c

raw symbols SCIP
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Microsoft Corporation.
3 */
4
5 #include "netuio_drv.h"
6
7 #ifdef ALLOC_PRAGMA
8 #pragma alloc_text (INIT, DriverEntry)
9 #pragma alloc_text (PAGE, netuio_evt_device_add)
10 #endif
11
12 /*
13 Routine Description:
14 DriverEntry initializes the driver and is the first routine called by the
15 system after the driver is loaded. DriverEntry specifies the other entry
16 points in the function driver, such as EvtDevice and DriverUnload.
17
18 Return Value:
19 STATUS_SUCCESS if successful,
20 STATUS_UNSUCCESSFUL otherwise.
21 */
22 NTSTATUS
23 DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
24 {
25 WDF_DRIVER_CONFIG config;
26 NTSTATUS status;
27 WDF_OBJECT_ATTRIBUTES attributes;
28
29 WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
30 WDF_DRIVER_CONFIG_INIT(&config, netuio_evt_device_add);
31
32 status = WdfDriverCreate(DriverObject, RegistryPath,
33 &attributes, &config,
34 WDF_NO_HANDLE);
35
36 if (!NT_SUCCESS(status)) {
37 return status;
38 }
39
40 return status;
41 }
42
43 /*
44 Routine Description:
45 netuio_evt_device_add is called by the framework in response to AddDevice
46 call from the PnP manager. We create and initialize a device object to
47 represent a new instance of the device.
48
49 Return Value:
50 NTSTATUS
51 */
52 _Use_decl_annotations_
53 NTSTATUS
54 netuio_evt_device_add(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit)
55 {
56 UNREFERENCED_PARAMETER(Driver);
57 return netuio_create_device(DeviceInit);
58 }
59
60 /*
61 Routine Description :
62 Maps HW resources and retrieves the PCI BAR address(es) of the device
63
64 Return Value :
65 STATUS_SUCCESS is successful.
66 STATUS_<ERROR> otherwise
67 -*/
68 _Use_decl_annotations_
69 NTSTATUS
70 netuio_evt_prepare_hw(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST ResourcesTranslated)
71 {
72 NTSTATUS status;
73
74 status = netuio_map_hw_resources(Device, Resources, ResourcesTranslated);
75 if (!NT_SUCCESS(status)) {
76 return status;
77 }
78
79 PNETUIO_CONTEXT_DATA ctx = netuio_get_context_data(Device);
80 DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_NETUIO_INFO_LEVEL, "netUIO Driver loaded...on device (B:D:F) %04d:%02d:%02d\n",
81 ctx->addr.bus_num, ctx->addr.dev_num, ctx->addr.func_num);
82
83 return status;
84 }
85
86 /*
87 Routine Description :
88 Releases the resource mapped by netuio_evt_prepare_hw
89
90 Return Value :
91 STATUS_SUCCESS always.
92 -*/
93 _Use_decl_annotations_
94 NTSTATUS
95 netuio_evt_release_hw(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated)
96 {
97 UNREFERENCED_PARAMETER(ResourcesTranslated);
98
99 netuio_free_hw_resources(Device);
100
101 return STATUS_SUCCESS;
102 }
103
104 /*
105 Routine Description :
106 EVT_WDF_FILE_CLEANUP callback, called when user process handle is closed.
107
108 Undoes IOCTL_NETUIO_MAP_HW_INTO_USERSPACE.
109
110 Return value :
111 None
112 -*/
113 _Use_decl_annotations_
114 VOID
115 netuio_evt_file_cleanup(WDFFILEOBJECT FileObject)
116 {
117 PNETUIO_FILE_CONTEXT_DATA file_ctx;
118
119 file_ctx = netuio_get_file_object_context_data(FileObject);
120
121 if (file_ctx->bMapped == TRUE)
122 {
123 WDFDEVICE device;
124 PNETUIO_CONTEXT_DATA ctx;
125
126 device = WdfFileObjectGetDevice(FileObject);
127 ctx = netuio_get_context_data(device);
128 netuio_unmap_address_from_user_process(ctx);
129 file_ctx->bMapped = FALSE;
130 }
131 }