ReactOS  0.4.13-dev-687-g023794c
hardware.c
Go to the documentation of this file.
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
25  IN ULONG Offset,
26  IN PVOID Buffer,
27  IN ULONG Length)
28 {
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
43  IN ULONG Offset,
44  IN PVOID Buffer,
45  IN ULONG Length)
46 {
48  /* Slot number is ignored. */
49  return HalSetBusDataByOffset(PCIConfiguration, WrapperContext->BusNumber,
50  WrapperContext->SlotNumber, Buffer, Offset, Length);
51 }
52 
53 /*
54  * @implemented
55  */
57 EXPORT
61  OUT PNDIS_RESOURCE_LIST *AssignedResources)
62 {
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  */
82 EXPORT
84  IN NDIS_HANDLE NdisMacHandle,
85  IN NDIS_HANDLE NdisWrapperHandle,
88  OUT PNDIS_RESOURCE_LIST *AssignedResources)
89 {
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
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 {
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"));
133  return;
134  }
135 
136  ResourceListSize =
137  FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
138  Adapter->NdisMiniportBlock.AllocatedResources->List[0].PartialResourceList.Count *
140 
141  if (*BufferSize >= ResourceListSize)
142  {
144  &Adapter->NdisMiniportBlock.AllocatedResources->List[0].PartialResourceList,
145  ResourceListSize);
146  *BufferSize = ResourceListSize;
148  }
149  else
150  {
151  *BufferSize = ResourceListSize;
153  }
154 }
155 
156 
157 /*
158  * @implemented
159  */
161 EXPORT
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 {
172 }
173 
174 
175 /*
176  * @implemented
177  */
178 ULONG
179 EXPORT
181  IN NDIS_HANDLE NdisAdapterHandle,
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. */
190  Adapter->NdisMiniportBlock.BusNumber, Adapter->NdisMiniportBlock.SlotNumber,
191  Buffer, Offset, Length);
192 }
193 
194 /*
195  * @implemented
196  */
197 ULONG
198 EXPORT
200  IN NDIS_HANDLE NdisAdapterHandle,
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. */
209  Adapter->NdisMiniportBlock.BusNumber, Adapter->NdisMiniportBlock.SlotNumber,
210  Buffer, Offset, Length);
211 }
212 
213 
214 /*
215  * @implemented
216  */
217 VOID
218 EXPORT
224 {
226  ULONG Ret;
227  PVOID Buffer;
228 
229  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
230 
231  /* We are called only at PASSIVE_LEVEL */
233  if (!Buffer) {
234  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
236  return;
237  }
238 
240  Wrapper->BusNumber,
241  Wrapper->SlotNumber,
242  Buffer,
244 
245  if (Ret == 0 || Ret == 2) {
246  NDIS_DbgPrint(MIN_TRACE, ("HalGetBusData failed.\n"));
249  return;
250  }
251 
252  *SlotNumber = Wrapper->SlotNumber;
253 
255 
257 
259 }
260 
261 
262 /*
263  * @implemented
264  */
265 ULONG
266 EXPORT
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 
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
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 
314  Adapter->NdisMiniportBlock.BusNumber,
315  Adapter->NdisMiniportBlock.SlotNumber,
316  Buffer,
317  Offset,
318  Length);
319 }
320 
321 /*
322  * @implemented
323  */
324 VOID
325 EXPORT
330 /*
331  * FUNCTION:
332  * ARGUMENTS:
333  * NOTES:
334  * NDIS 4.0
335  */
336 {
339 
340  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
341 
342  Wrapper->BusNumber = BusNumber;
343 
344  if (Adapter)
346 }
347 
348 /* EOF */
NDIS_STATUS EXPORT NdisPciAssignResources(IN NDIS_HANDLE NdisMacHandle, IN NDIS_HANDLE NdisWrapperHandle, IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG SlotNumber, OUT PNDIS_RESOURCE_LIST *AssignedResources)
Definition: hardware.c:83
ULONG EXPORT NdisReadPcmciaAttributeMemory(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:267
#define IN
Definition: typedefs.h:38
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID EXPORT NdisMQueryAdapterResources(OUT PNDIS_STATUS Status, IN NDIS_HANDLE WrapperConfigurationContext, OUT PNDIS_RESOURCE_LIST ResourceList, IN OUT PUINT BufferSize)
Definition: hardware.c:103
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:156
* PNDIS_STATUS
Definition: ndis.h:45
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
VOID EXPORT NdisOverrideBusNumber(IN NDIS_HANDLE WrapperConfigurationContext, IN NDIS_HANDLE MiniportAdapterHandle OPTIONAL, IN ULONG BusNumber)
Definition: hardware.c:326
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _In_ NDIS_HANDLE WrapperConfigurationContext
Definition: ndis.h:3944
#define PAGED_CODE()
Definition: video.h:57
int NDIS_STATUS
Definition: ntddndis.h:445
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID EXPORT NdisReadEisaSlotInformation(OUT PNDIS_STATUS Status, IN NDIS_HANDLE WrapperConfigurationContext, OUT PUINT SlotNumber, OUT PNDIS_EISA_FUNCTION_INFORMATION EisaData)
Definition: hardware.c:219
PDEVICE_OBJECT DeviceObject
Definition: miniport.h:79
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
ULONG EXPORT NdisImmediateWritePciSlotInformation(IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:40
NTHALAPI ULONG NTAPI HalGetBusData(BUS_DATA_TYPE, ULONG, ULONG, PVOID, ULONG)
#define BufferSize
Definition: classpnp.h:419
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
ULONG EXPORT NdisWritePcmciaAttributeMemory(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:297
NDIS_STATUS EXPORT NdisMPciAssignResources(IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG SlotNumber, OUT PNDIS_RESOURCE_LIST *AssignedResources)
Definition: hardware.c:58
Status
Definition: gdiplustypes.h:24
ULONG EXPORT NdisReadPciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:180
#define MAX_TRACE
Definition: debug.h:16
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
struct _NDIS_WRAPPER_CONTEXT * PNDIS_WRAPPER_CONTEXT
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
enum _NDIS_INTERFACE_TYPE NDIS_INTERFACE_TYPE
NDIS_STATUS EXPORT NdisQueryMapRegisterCount(IN NDIS_INTERFACE_TYPE BusType, OUT PUINT MapRegisterCount)
Definition: hardware.c:162
ULONG EXPORT NdisImmediateReadPciSlotInformation(IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:22
#define OUT
Definition: typedefs.h:39
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
ULONG NTAPI HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:123
ULONG EXPORT NdisWritePciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:199
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
unsigned int * PUINT
Definition: ndis.h:50
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68