blob: 3784f90e6ee955f0ca4e186f2dde6eb9ee823851 (
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
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
registers.c
Abstract:
Memory mapping the controller's registers
Environment:
Kernel mode
--*/
#include "device.h"
#include "registers.h"
#include "registers.tmh"
#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, RegistersCreate)
#endif
_Must_inspect_result_
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
RegistersCreate(
_In_ WDFDEVICE Device,
_In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR RegistersResource
)
/*++
Routine Description:
Helper function to map the memory resources to the HW registers.
Arguments:
Device - Wdf device object corresponding to the FDO
RegisterResource - Raw resource for the memory
Return Value:
Appropriate NTSTATUS value
--*/
{
NTSTATUS Status;
PREGISTERS_CONTEXT Context;
WDF_OBJECT_ATTRIBUTES Attributes;
TraceEntry();
PAGED_CODE();
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&Attributes, REGISTERS_CONTEXT);
Status = WdfObjectAllocateContext(Device, &Attributes, &Context);
if (Status == STATUS_OBJECT_NAME_EXISTS) {
//
// In the case of a resource rebalance, the context allocated
// previously still exists.
//
Status = STATUS_SUCCESS;
RtlZeroMemory(Context, sizeof(*Context));
}
CHK_NT_MSG(Status, "Failed to allocate context for registers");
Context->RegisterBase = MmMapIoSpaceEx(
RegistersResource->u.Memory.Start,
RegistersResource->u.Memory.Length,
PAGE_NOCACHE | PAGE_READWRITE);
if (Context->RegisterBase == NULL) {
Status = STATUS_INSUFFICIENT_RESOURCES;
CHK_NT_MSG(Status, "MmMapIoSpaceEx failed");
}
Context->RegistersLength = RegistersResource->u.Memory.Length;
End:
TraceExit();
return Status;
}
|