Amd64/misc 64bit fixes (#236)
[reactos.git] / drivers / network / ndis / ndis / hardware.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
4 * FILE: ndis/hardware.c
5 * PURPOSE: Hardware related routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Vizzini (vizzini@plasmic.com)
8 * REVISIONS:
9 * CSH 01/08-2000 Created
10 * 25 Aug 2003 Vizzini - NDIS4/5 and PnP additions
11 * 3 Oct 2003 Vizzini - formatting and minor bugfixes
12 *
13 */
14
15 #include "ndissys.h"
16
17 /*
18 * @implemented
19 */
20 ULONG
21 EXPORT
22 NdisImmediateReadPciSlotInformation(
23 IN NDIS_HANDLE WrapperConfigurationContext,
24 IN ULONG SlotNumber,
25 IN ULONG Offset,
26 IN PVOID Buffer,
27 IN ULONG Length)
28 {
29 PNDIS_WRAPPER_CONTEXT WrapperContext = (PNDIS_WRAPPER_CONTEXT)WrapperConfigurationContext;
30 /* Slot number is ignored. */
31 return HalGetBusDataByOffset(PCIConfiguration, WrapperContext->BusNumber,
32 WrapperContext->SlotNumber, Buffer, Offset, Length);
33 }
34
35 /*
36 * @implemented
37 */
38 ULONG
39 EXPORT
40 NdisImmediateWritePciSlotInformation(
41 IN NDIS_HANDLE WrapperConfigurationContext,
42 IN ULONG SlotNumber,
43 IN ULONG Offset,
44 IN PVOID Buffer,
45 IN ULONG Length)
46 {
47 PNDIS_WRAPPER_CONTEXT WrapperContext = (PNDIS_WRAPPER_CONTEXT)WrapperConfigurationContext;
48 /* Slot number is ignored. */
49 return HalSetBusDataByOffset(PCIConfiguration, WrapperContext->BusNumber,
50 WrapperContext->SlotNumber, Buffer, Offset, Length);
51 }
52
53 /*
54 * @implemented
55 */
56 NDIS_STATUS
57 EXPORT
58 NdisMPciAssignResources(
59 IN NDIS_HANDLE MiniportAdapterHandle,
60 IN ULONG SlotNumber,
61 OUT PNDIS_RESOURCE_LIST *AssignedResources)
62 {
63 PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
64
65 if (Adapter->NdisMiniportBlock.BusType != NdisInterfacePci ||
66 Adapter->NdisMiniportBlock.AllocatedResources == NULL)
67 {
68 NDIS_DbgPrint(MIN_TRACE, ("Bad bus type or no resources\n"));
69 *AssignedResources = NULL;
70 return NDIS_STATUS_FAILURE;
71 }
72
73 *AssignedResources = &Adapter->NdisMiniportBlock.AllocatedResources->List[0].PartialResourceList;
74
75 return NDIS_STATUS_SUCCESS;
76 }
77
78 /*
79 * @implemented
80 */
81 NDIS_STATUS
82 EXPORT
83 NdisPciAssignResources(
84 IN NDIS_HANDLE NdisMacHandle,
85 IN NDIS_HANDLE NdisWrapperHandle,
86 IN NDIS_HANDLE WrapperConfigurationContext,
87 IN ULONG SlotNumber,
88 OUT PNDIS_RESOURCE_LIST *AssignedResources)
89 {
90 PNDIS_WRAPPER_CONTEXT WrapperContext = (PNDIS_WRAPPER_CONTEXT)WrapperConfigurationContext;
91 PLOGICAL_ADAPTER Adapter = WrapperContext->DeviceObject->DeviceExtension;
92
93 return NdisMPciAssignResources(Adapter,
94 SlotNumber,
95 AssignedResources);
96 }
97
98 /*
99 * @implemented
100 */
101 VOID
102 EXPORT
103 NdisMQueryAdapterResources(
104 OUT PNDIS_STATUS Status,
105 IN NDIS_HANDLE WrapperConfigurationContext,
106 OUT PNDIS_RESOURCE_LIST ResourceList,
107 IN OUT PUINT BufferSize)
108 /*
109 * FUNCTION: returns a nic's hardware resources
110 * ARGUMENTS:
111 * Status: on return, contains the status of the operation
112 * WrapperConfigurationContext: handle input to MiniportInitialize
113 * ResourceList: on return, contains the list of resources for the nic
114 * BufferSize: size of ResourceList
115 * NOTES:
116 * - Caller must allocate Status and ResourceList
117 * - Must be called at IRQL = PASSIVE_LEVEL;
118 */
119 {
120 PNDIS_WRAPPER_CONTEXT WrapperContext = (PNDIS_WRAPPER_CONTEXT)WrapperConfigurationContext;
121 PLOGICAL_ADAPTER Adapter = WrapperContext->DeviceObject->DeviceExtension;
122 ULONG ResourceListSize;
123
124 PAGED_CODE();
125 ASSERT((Status && ResourceList) || (BufferSize && *BufferSize == 0));
126
127 NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
128
129 if (Adapter->NdisMiniportBlock.AllocatedResources == NULL)
130 {
131 NDIS_DbgPrint(MIN_TRACE, ("No allocated resources!\n"));
132 *Status = NDIS_STATUS_FAILURE;
133 return;
134 }
135
136 ResourceListSize =
137 FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
138 Adapter->NdisMiniportBlock.AllocatedResources->List[0].PartialResourceList.Count *
139 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
140
141 if (*BufferSize >= ResourceListSize)
142 {
143 RtlCopyMemory(ResourceList,
144 &Adapter->NdisMiniportBlock.AllocatedResources->List[0].PartialResourceList,
145 ResourceListSize);
146 *BufferSize = ResourceListSize;
147 *Status = NDIS_STATUS_SUCCESS;
148 }
149 else
150 {
151 *BufferSize = ResourceListSize;
152 *Status = NDIS_STATUS_RESOURCES;
153 }
154 }
155
156
157 /*
158 * @implemented
159 */
160 NDIS_STATUS
161 EXPORT
162 NdisQueryMapRegisterCount(
163 IN NDIS_INTERFACE_TYPE BusType,
164 OUT PUINT MapRegisterCount)
165 /*
166 * On X86 (and all other current hardware), map registers aren't real hardware,
167 * and there is no real limit to the number that can be allocated.
168 * As such, we do what microsoft does on the x86 hals and return as follows
169 */
170 {
171 return NDIS_STATUS_NOT_SUPPORTED;
172 }
173
174
175 /*
176 * @implemented
177 */
178 ULONG
179 EXPORT
180 NdisReadPciSlotInformation(
181 IN NDIS_HANDLE NdisAdapterHandle,
182 IN ULONG SlotNumber,
183 IN ULONG Offset,
184 IN PVOID Buffer,
185 IN ULONG Length)
186 {
187 PLOGICAL_ADAPTER Adapter = NdisAdapterHandle;
188 /* Slot number is ignored since W2K for all NDIS drivers. */
189 return HalGetBusDataByOffset(PCIConfiguration,
190 Adapter->NdisMiniportBlock.BusNumber, Adapter->NdisMiniportBlock.SlotNumber,
191 Buffer, Offset, Length);
192 }
193
194 /*
195 * @implemented
196 */
197 ULONG
198 EXPORT
199 NdisWritePciSlotInformation(
200 IN NDIS_HANDLE NdisAdapterHandle,
201 IN ULONG SlotNumber,
202 IN ULONG Offset,
203 IN PVOID Buffer,
204 IN ULONG Length)
205 {
206 PLOGICAL_ADAPTER Adapter = NdisAdapterHandle;
207 /* Slot number is ignored since W2K for all NDIS drivers. */
208 return HalSetBusDataByOffset(PCIConfiguration,
209 Adapter->NdisMiniportBlock.BusNumber, Adapter->NdisMiniportBlock.SlotNumber,
210 Buffer, Offset, Length);
211 }
212
213
214 /*
215 * @implemented
216 */
217 VOID
218 EXPORT
219 NdisReadEisaSlotInformation(
220 OUT PNDIS_STATUS Status,
221 IN NDIS_HANDLE WrapperConfigurationContext,
222 OUT PUINT SlotNumber,
223 OUT PNDIS_EISA_FUNCTION_INFORMATION EisaData)
224 {
225 PNDIS_WRAPPER_CONTEXT Wrapper = WrapperConfigurationContext;
226 ULONG Ret;
227 PVOID Buffer;
228
229 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
230
231 /* We are called only at PASSIVE_LEVEL */
232 Buffer = ExAllocatePool(PagedPool, sizeof(NDIS_EISA_FUNCTION_INFORMATION));
233 if (!Buffer) {
234 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
235 *Status = NDIS_STATUS_RESOURCES;
236 return;
237 }
238
239 Ret = HalGetBusData(EisaConfiguration,
240 Wrapper->BusNumber,
241 Wrapper->SlotNumber,
242 Buffer,
243 sizeof(NDIS_EISA_FUNCTION_INFORMATION));
244
245 if (Ret == 0 || Ret == 2) {
246 NDIS_DbgPrint(MIN_TRACE, ("HalGetBusData failed.\n"));
247 ExFreePool(Buffer);
248 *Status = NDIS_STATUS_FAILURE;
249 return;
250 }
251
252 *SlotNumber = Wrapper->SlotNumber;
253
254 RtlCopyMemory(EisaData, Buffer, sizeof(NDIS_EISA_FUNCTION_INFORMATION));
255
256 ExFreePool(Buffer);
257
258 *Status = NDIS_STATUS_SUCCESS;
259 }
260
261
262 /*
263 * @implemented
264 */
265 ULONG
266 EXPORT
267 NdisReadPcmciaAttributeMemory(
268 IN NDIS_HANDLE NdisAdapterHandle,
269 IN ULONG Offset,
270 IN PVOID Buffer,
271 IN ULONG Length)
272 /*
273 * FUNCTION:
274 * ARGUMENTS:
275 * NOTES:
276 * NDIS 5.0
277 */
278 {
279 PLOGICAL_ADAPTER Adapter = NdisAdapterHandle;
280
281 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
282
283 return HalGetBusDataByOffset(PCMCIAConfiguration,
284 Adapter->NdisMiniportBlock.BusNumber,
285 Adapter->NdisMiniportBlock.SlotNumber,
286 Buffer,
287 Offset,
288 Length);
289 }
290
291
292 /*
293 * @implemented
294 */
295 ULONG
296 EXPORT
297 NdisWritePcmciaAttributeMemory(
298 IN NDIS_HANDLE NdisAdapterHandle,
299 IN ULONG Offset,
300 IN PVOID Buffer,
301 IN ULONG Length)
302 /*
303 * FUNCTION:
304 * ARGUMENTS:
305 * NOTES:
306 * NDIS 5.0
307 */
308 {
309 PLOGICAL_ADAPTER Adapter = NdisAdapterHandle;
310
311 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
312
313 return HalSetBusDataByOffset(PCMCIAConfiguration,
314 Adapter->NdisMiniportBlock.BusNumber,
315 Adapter->NdisMiniportBlock.SlotNumber,
316 Buffer,
317 Offset,
318 Length);
319 }
320
321 /*
322 * @implemented
323 */
324 VOID
325 EXPORT
326 NdisOverrideBusNumber(
327 IN NDIS_HANDLE WrapperConfigurationContext,
328 IN NDIS_HANDLE MiniportAdapterHandle OPTIONAL,
329 IN ULONG BusNumber)
330 /*
331 * FUNCTION:
332 * ARGUMENTS:
333 * NOTES:
334 * NDIS 4.0
335 */
336 {
337 PNDIS_WRAPPER_CONTEXT Wrapper = WrapperConfigurationContext;
338 PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
339
340 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
341
342 Wrapper->BusNumber = BusNumber;
343
344 if (Adapter)
345 Adapter->NdisMiniportBlock.BusNumber = BusNumber;
346 }
347
348 /* EOF */