NDIS calls a miniport driver's MiniportInitializeEx function to initialize a miniport adapter for network I/O operations.
Syntax
MINIPORT_INITIALIZE MiniportInitialize;
NDIS_STATUS MiniportInitialize(
[in] NDIS_HANDLE NdisMiniportHandle,
[in] NDIS_HANDLE MiniportDriverContext,
[in] PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters
)
{...}
Parameters
[in] NdisMiniportHandle
一个 NDIS 提供的句柄,用于标识微型端口驱动程序应初始化的微型端口适配器。
[in] MiniportDriverContext
驱动程序分配的上下文区域的句柄,其中驱动程序维护状态和配置信息。 微型端口驱动程序将此上下文区域传递给 NdisMRegisterMiniportDriver function.
[in] MiniportInitParameters
指向 NDIS_MINIPORT_INIT_PARAMETERS structure that defines the initialization parameters for the miniport adapter.
Return value
MiniportInitializeEx can return one of the following status values:
| Return code | Description |
|---|---|
|
MiniportInitializeEx configured and set up the miniport adapter, and allocated all the resources that the driver must have to perform network I/O operations. |
|
MiniportInitializeEx could not get the miniport adapter to accept the configuration parameters that MiniportInitializeEx obtained from the registry. |
|
MiniportInitializeEx could not allocate resources to perform network I/O operations. MiniportInitializeEx should call the NdisWriteErrorLogEntry function to identify the resource conflict (for example, I/O port range, interrupt vector, device memory range, as appropriate). 提供错误日志记录可为用户提供或系统管理员信息,这些信息可用于重新配置计算机以避免此类硬件资源冲突。 |
|
MiniportInitializeEx failed for reasons other than those in the preceding list. The driver should call NdisWriteErrorLogEntry with parameters that specify the reason for the failure. |
Remarks
NDIS calls MiniportInitializeEx as part of a system PnP operation. Drivers specify the MiniportInitializeEx entry point by calling the NdisMRegisterMiniportDriver function from the DriverEntry routine. NDIS can call MiniportInitializeEx after DriverEntry returns. 有关详细信息,请参阅 NDIS 微型端口驱动程序的 DriverEntry。
For NDIS intermediate drivers, NDIS can call MiniportInitializeEx in the context of the NdisIMInitializeDeviceInstanceEx function or after it returns. Such a driver's ProtocolBindAdapterEx function usually calls NdisIMInitializeDeviceInstanceEx.
Drivers can register as a combined miniport driver and intermediate driver (see NdisMRegisterMiniportDriver). 此类微型端口-中间驱动程序的功能类似于分层于物理微型端口驱动程序的中间驱动程序。 For each virtual or physical device instance of a miniport-intermediate driver, if the IMMiniport registry key is set to DWORD:0x0000001, NDIS calls the MiniportInitializeEx function that the driver registered for the virtual device. Otherwise, NDIS calls the driver's MiniportInitializeEx function that the driver registered for the physical device.
Until MiniportInitializeEx returns, NDIS submits no requests for the miniport adapter being initialized. The miniport adapter is in the initializing state.
To obtain configuration information for the miniport adapter, a driver calls the NdisOpenConfigurationEx and NdisReadConfiguration functions. The driver can call the NdisMGetBusData function to obtain bus-specific information.
微型端口驱动程序必须调用 NdisMSetMiniportAttributes function and provide an NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES structure which contains the following attributes:
- 驱动程序分配的上下文区域的句柄。
- 相应的属性标志。
- 调用它的超时间隔 MiniportCheckForHangEx function.
- 接口类型。
微型端口驱动程序必须在 NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES structure after they set the registration attributes in the NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES structure and before they set any additional attributes.
MiniportInitializeEx can also allocate resources such as the following:
- 非分页池内存
-
NET_BUFFER and NET_BUFFER_LIST structure pools
- Spin locks
- Timers
- IO ports
- DMA
- Shared memory
- Interrupts
If driver functions, other than the MiniportInterrupt function, share resources, MiniportInitializeEx should call the NdisAllocateSpinLock function to set up any spin locks necessary to synchronize access to such shared resources. Resources that other driver functions share with MiniportInterrupt, such as NIC registers, are protected by the interrupt object that the driver set up with the
NdisMRegisterInterruptEx function. 驱动程序函数通过调用
MiniportInitializeEx can call the NdisAllocateTimerObject function with a driver-supplied NetTimerCallback function and a pointer to driver-allocated memory for a timer object. Drivers can set up multiple NetTimerCallback functions, each with its own timer object. A driver can call the NdisSetTimerObject function to enable a periodic NetTimerCallback function. A driver can also call the NdisSetTimerObject function to enable a one-time NetTimerCallback function.
MiniportInitializeEx must call the NdisMSetMiniportAttributes function before it calls any NdisMXxx function, such as the NdisMRegisterIoPortRange or NdisMMapIoSpace functions, that claims hardware resources for the miniport adapter. MiniportInitializeEx must call NdisMSetMiniportAttributes before it tries to allocate resources for DMA operations.
If the device supports bus-master DMA, MiniportInitializeEx must call the NdisMRegisterScatterGatherDma function after it calls NdisMSetMiniportAttributes and before it calls the NdisMAllocateSharedMemory function. If the device supports subordinate DMA, MiniportInitializeEx must call NdisMSetMiniportAttributes before it calls the NdisMRegisterDmaChannel function.
After MiniportInitializeEx calls the NdisMRegisterInterruptEx function, NDIS can call the driver's MiniportInterrupt function. NDIS calls MiniportInterrupt if the NIC generates an interrupt or if any other device with which the NIC shares an interrupt generates an interrupt. Note that a miniport driver can get an interrupt as soon as it calls NdisMRegisterInterruptEx and keeps getting interrupts until its call to the NdisMDeregisterInterruptEx function returns.
MiniportInitializeEx should test the NIC to make sure that the hardware is configured correctly. If the driver must wait for state changes to occur in the hardware, MiniportInitializeEx can use the NdisWaitEvent function or the NdisMSleep function.
After MiniportInitializeEx returns successfully, the miniport adapter is in the Paused state. NDIS can call the MiniportRestart function to transition the miniport adapter to the Running state.
If MiniportInitializeEx returns NDIS_STATUS_SUCCESS, the driver should release all the resources for the miniport adapter in the MiniportHaltEx function.
The driver must call NdisMSetMiniportAttributes and set the GeneralAttributes in the NDIS_MINIPORT_ADAPTER_ATTRIBUTES structure if it returns NDIS_STATUS_SUCCESS.
If MiniportInitializeEx failed, MiniportInitializeEx must release all resources that it allocated before it returns and the miniport adapter returns to the Halted state.
NDIS calls MiniportInitializeEx at IRQL = PASSIVE_LEVEL.
示例
To define a MiniportInitializeEx function, you must first provide a function declaration that identifies the type of function you're defining. Windows 为驱动程序提供了一组函数类型。 使用函数类型声明函数有助于 驱动程序代码分析、静态驱动程序验证程序(SDV)和其他验证工具查找错误,这是为 Windows作系统编写驱动程序的要求。For example, to define a MiniportInitializeEx function that is named "MyInitializeEx", use the MINIPORT_INITIALIZE type as shown in this code example:
MINIPORT_INITIALIZE MyInitializeEx;
然后,按如下所示实现函数:
_Use_decl_annotations_
NDIS_STATUS
MyInitializeEx(
NDIS_HANDLE NdisMiniportHandle,
NDIS_HANDLE MiniportDriverContext,
PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters
)
{...}
The MINIPORT_INITIALIZE function type is defined in the Ndis.h header file. To more accurately identify errors when you run the code analysis tools, be sure to add the Use_decl_annotations annotation to your function definition. The Use_decl_annotations annotation ensures that the annotations that are applied to the MINIPORT_INITIALIZE function type in the header file are used. 有关函数声明要求的详细信息,请参阅 使用 NDIS 驱动程序的函数角色类型声明函数。
For information about Use_decl_annotations, see Annotating Function Behavior.
Requirements
| Requirement | Value |
|---|---|
| 最低支持的客户端 | NDIS 6.0 及更高版本中受支持。 |
| Target Platform | Windows |
| Header | ndis.h (包括 Ndis.h) |
| IRQL | PASSIVE_LEVEL |