4e0b37e18230c60eb39d136b0a1b618a643b79cd
[reactos.git] / drivers / storage / port / storport / miniport.c
1 /*
2 * PROJECT: ReactOS Storport Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Miniport interface code
5 * COPYRIGHT: Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
6 */
7
8 /* INCLUDES *******************************************************************/
9
10 #include "precomp.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15
16 /* FUNCTIONS ******************************************************************/
17
18 NTSTATUS
19 MiniportInitialize(
20 _In_ PMINIPORT Miniport,
21 _In_ PFDO_DEVICE_EXTENSION DeviceExtension,
22 _In_ PHW_INITIALIZATION_DATA InitData)
23 {
24 PMINIPORT_DEVICE_EXTENSION MiniportExtension;
25 ULONG Size;
26
27 DPRINT1("MiniportInitialize(%p %p %p)\n",
28 Miniport, DeviceExtension, InitData);
29
30 Miniport->DeviceExtension = DeviceExtension;
31 Miniport->InitData = InitData;
32
33 /* Calculate the miniport device extension size */
34 Size = sizeof(MINIPORT_DEVICE_EXTENSION) +
35 Miniport->InitData->DeviceExtensionSize;
36
37 /* Allocate and initialize the miniport device extension */
38 MiniportExtension = ExAllocatePoolWithTag(NonPagedPool,
39 Size,
40 TAG_MINIPORT_DATA);
41 if (MiniportExtension == NULL)
42 return STATUS_NO_MEMORY;
43
44 RtlZeroMemory(MiniportExtension, Size);
45
46 MiniportExtension->Miniport = Miniport;
47 Miniport->MiniportExtension = MiniportExtension;
48
49 return STATUS_SUCCESS;
50 }
51
52
53 NTSTATUS
54 MiniportFindAdapter(
55 _In_ PMINIPORT Miniport)
56 {
57 BOOLEAN Reserved = FALSE;
58 ULONG Result;
59 NTSTATUS Status;
60
61 DPRINT1("MiniportFindAdapter(%p)\n", Miniport);
62
63 /* Call the miniport HwFindAdapter routine */
64 Result = Miniport->InitData->HwFindAdapter(&Miniport->MiniportExtension->HwDeviceExtension,
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 &Reserved);
70 DPRINT1("HwFindAdapter() returned %lu\n", Result);
71
72 switch (Result)
73 {
74 case SP_RETURN_NOT_FOUND:
75 DPRINT1("SP_RETURN_NOT_FOUND\n");
76 Status = STATUS_NOT_FOUND;
77 break;
78
79 case SP_RETURN_FOUND:
80 DPRINT1("SP_RETURN_FOUND\n");
81 Status = STATUS_SUCCESS;
82 break;
83
84 case SP_RETURN_ERROR:
85 DPRINT1("SP_RETURN_ERROR\n");
86 Status = STATUS_ADAPTER_HARDWARE_ERROR;
87 break;
88
89 case SP_RETURN_BAD_CONFIG:
90 DPRINT1("SP_RETURN_BAD_CONFIG\n");
91 Status = STATUS_DEVICE_CONFIGURATION_ERROR;
92 break;
93
94 default:
95 DPRINT1("Unknown result: %lu\n", Result);
96 Status = STATUS_INTERNAL_ERROR;
97 break;
98 }
99
100 return Status;
101 }
102
103
104 NTSTATUS
105 MiniportHwInitialize(
106 _In_ PMINIPORT Miniport)
107 {
108 NTSTATUS Status;
109
110 DPRINT1("MiniportHwInitialize(%p)\n", Miniport);
111
112 /* Call the miniport HwInitialize routine */
113 Status = Miniport->InitData->HwInitialize(&Miniport->MiniportExtension->HwDeviceExtension);
114 DPRINT1("HwInitialize() returned 0x%08lx\n", Status);
115
116 return Status;
117 }
118
119 /* EOF */