summaryrefslogtreecommitdiff
path: root/usb/ufxclientsample/device.h
blob: 7df5a4a39eb8392c83a91fd8624d3a539f817814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*++

Module Name:

    device.h

Abstract:

    This file contains the device definitions.

Environment:

    Kernel-mode Driver Framework

--*/
#pragma once

#include "driver.h"
#include "transfer.h"
#include "registers.h"
#include "ufxdevice.h"
#include <ntstrsafe.h>

#define UFXCLIENT_TAG ('CXFU') // UFXC

#define TEST_BIT(value, bitNumber) ((value) & (1<<(bitNumber))) ? TRUE : FALSE

#define MAX_DMA_LENGTH 0x1000

#define UFX_CLIENT_ALIGNMENT 128

//
// Time interval to wait after being suspended and before requesting remote
// wakeup request 
//
#define REMOTE_WAKEUP_TIMEOUT_INTERVAL_MS 1

//
// Context space for WDFDEVICE object representing the controller
//
typedef struct _CONTROLLER_CONTEXT {

    UFXDEVICE UfxDevice;

    WDFINTERRUPT DeviceInterrupt;

    WDFINTERRUPT WakeInterrupt;

    WDFINTERRUPT AttachDetachInterrupt;

    KEVENT DetachEvent;

    WDFDMAENABLER DmaEnabler;

    //
    // This variable tells us if we have indicated to UFX, via UfxDeviceNotifyAttach, that we are
    // attached.
    //
    BOOLEAN WasAttached;

    //
    // This variable tracks what the hardware thinks about the current
    // attachment status. It is updated right away based on incoming notifications.
    //
    volatile BOOLEAN Attached;

    //
    // This variable tracks whether there was some change, possibly transient, in the attachment
    // status. Simply inspecting "Attached", one may conclude that there was no change at all, but
    // this variable will tell us if there was a rapid attach-detach or detach-attach event.
    BOOLEAN GotAttachOrDetach;

    WDFSPINLOCK DpcLock;

    BOOLEAN RemoteWakeupRequested;

    BOOLEAN StopPending;

    BOOLEAN Connect;

    BOOLEAN Suspended;

    USB_DEVICE_SPEED Speed;

    WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS IdleSettings;

    BOOLEAN InitializeDefaultEndpoint;

    WDFWAITLOCK InitializeDefaultEndpointLock;

} CONTROLLER_CONTEXT, *PCONTROLLER_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(CONTROLLER_CONTEXT, DeviceGetControllerContext)


typedef enum _UFX_CLIENT_EXCEPTION_CODE {
    ExceptionDisconnectTimeout = 0,
    ExceptionMaximum
} UFX_CLIENT_EXCEPTION_CODE, *PUFX_CLIENT_EXCEPTION_CODE;

typedef struct _HARDWARE_FAILURE_CONTEXT {
    ULONG Size;
    UFX_CLIENT_EXCEPTION_CODE ExceptionCode;
    CONTROLLER_CONTEXT ControllerContext;
    UFXDEVICE_CONTEXT DeviceContext;
} HARDWARE_FAILURE_CONTEXT, *PHARDWARE_FAILURE_CONTEXT;

//
// Function to initialize the device and its callbacks
//
_Must_inspect_result_
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
UfxClientDeviceCreate (
    _In_ WDFDRIVER Driver,
    _In_ PWDFDEVICE_INIT DeviceInit
    );

_IRQL_requires_max_(DISPATCH_LEVEL)
VOID
DevicePerformSoftReset (
    _In_ WDFDEVICE Device
    );

_IRQL_requires_max_(DISPATCH_LEVEL)
VOID
DeviceHardwareFailure (
    _In_ WDFDEVICE Device,
    _In_ ULONG ExceptionCode
    );

VOID
DeviceVendorReset (
    _In_ WDFDEVICE Device
    );

_IRQL_requires_max_(PASSIVE_LEVEL)
VOID
DeviceInitializeDefaultEndpoint (
    _In_ WDFDEVICE Device
    );