📄 adapter.cpp
字号:
/*****************************************************************************
* adapter.cpp - SB16 adapter driver implementation.
*****************************************************************************
* Copyright (c) 1997-2000 Microsoft Corporation. All rights reserved.
*
* This files does setup and resource allocation/verification for the SB16
* card. It controls which miniports are started and which resources are
* given to each miniport. It also deals with interrupt sharing between
* miniports by hooking the interrupt and calling the correct DPC.
*/
//
// All the GUIDS for all the miniports end up in this object.
//
#define PUT_GUIDS_HERE
#define STR_MODULENAME "sb16Adapter: "
#include "common.h"
/*****************************************************************************
* Defines
*/
#define MAX_MINIPORTS 5
#if (DBG)
#define SUCCEEDS(s) ASSERT(NT_SUCCESS(s))
#else
#define SUCCEEDS(s) (s)
#endif
/*****************************************************************************
* Externals
*/
NTSTATUS
CreateMiniportWaveCyclicSB16
(
OUT PUNKNOWN * Unknown,
IN REFCLSID,
IN PUNKNOWN UnknownOuter OPTIONAL,
IN POOL_TYPE PoolType
);
NTSTATUS
CreateMiniportTopologySB16
(
OUT PUNKNOWN * Unknown,
IN REFCLSID,
IN PUNKNOWN UnknownOuter OPTIONAL,
IN POOL_TYPE PoolType
);
/*****************************************************************************
* Referenced forward
*/
extern "C"
NTSTATUS
AddDevice
(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
);
NTSTATUS
StartDevice
(
IN PDEVICE_OBJECT DeviceObject, // Device object.
IN PIRP Irp, // IO request packet.
IN PRESOURCELIST ResourceList // List of hardware resources.
);
NTSTATUS
AssignResources
(
IN PRESOURCELIST ResourceList, // All resources.
OUT PRESOURCELIST * ResourceListWave, // Wave resources.
OUT PRESOURCELIST * ResourceListWaveTable, // Wave table resources.
OUT PRESOURCELIST * ResourceListFmSynth, // FM synth resources.
OUT PRESOURCELIST * ResourceListUart, // UART resources.
OUT PRESOURCELIST * ResourceListAdapter // a copy needed by the adapter
);
#ifdef DO_RESOURCE_FILTERING
extern "C"
NTSTATUS
AdapterDispatchPnp
(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);
#endif
DWORD DeterminePlatform(PPORTTOPOLOGY Port);
#pragma code_seg("INIT")
/*****************************************************************************
* DriverEntry()
*****************************************************************************
* This function is called by the operating system when the driver is loaded.
* All adapter drivers can use this code without change.
*/
extern "C"
NTSTATUS
DriverEntry
(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPathName
)
{
PAGED_CODE();
//
// Tell the class driver to initialize the driver.
//
NTSTATUS ntStatus = PcInitializeAdapterDriver( DriverObject,
RegistryPathName,
AddDevice );
#ifdef DO_RESOURCE_FILTERING
//
// We want to do resource filtering, so we'll install our own PnP IRP handler.
//
if(NT_SUCCESS(ntStatus))
{
DriverObject->MajorFunction[IRP_MJ_PNP] = AdapterDispatchPnp;
}
#endif
return ntStatus;
}
#pragma code_seg("PAGE")
/*****************************************************************************
* AddDevice()
*****************************************************************************
* This function is called by the operating system when the device is added.
* All adapter drivers can use this code without change.
*/
extern "C"
NTSTATUS
AddDevice
(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
PAGED_CODE();
//
// Tell the class driver to add the device.
//
return PcAddAdapterDevice( DriverObject,
PhysicalDeviceObject,
PCPFNSTARTDEVICE( StartDevice ),
MAX_MINIPORTS,
0 );
}
/*****************************************************************************
* InstallSubdevice()
*****************************************************************************
* This function creates and registers a subdevice consisting of a port
* driver, a minport driver and a set of resources bound together. It will
* also optionally place a pointer to an interface on the port driver in a
* specified location before initializing the port driver. This is done so
* that a common ISR can have access to the port driver during initialization,
* when the ISR might fire.
*/
NTSTATUS
InstallSubdevice
(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PWCHAR Name,
IN REFGUID PortClassId,
IN REFGUID MiniportClassId,
IN PFNCREATEINSTANCE MiniportCreate OPTIONAL,
IN PUNKNOWN UnknownAdapter OPTIONAL,
IN PRESOURCELIST ResourceList,
IN REFGUID PortInterfaceId,
OUT PUNKNOWN * OutPortInterface OPTIONAL,
OUT PUNKNOWN * OutPortUnknown OPTIONAL
)
{
PAGED_CODE();
_DbgPrintF(DEBUGLVL_VERBOSE, ("InstallSubdevice"));
ASSERT(DeviceObject);
ASSERT(Irp);
ASSERT(Name);
//
// Create the port driver object
//
PPORT port;
NTSTATUS ntStatus = PcNewPort(&port,PortClassId);
if (NT_SUCCESS(ntStatus))
{
//
// Deposit the port somewhere if it's needed.
//
if (OutPortInterface)
{
//
// Failure here doesn't cause the entire routine to fail.
//
(void) port->QueryInterface
(
PortInterfaceId,
(PVOID *) OutPortInterface
);
}
PUNKNOWN miniport;
//
// Create the miniport object
//
if (MiniportCreate)
{
ntStatus = MiniportCreate
(
&miniport,
MiniportClassId,
NULL,
NonPagedPool
);
}
else
{
ntStatus = PcNewMiniport((PMINIPORT*) &miniport,MiniportClassId);
}
if (NT_SUCCESS(ntStatus))
{
//
// Init the port driver and miniport in one go.
//
ntStatus = port->Init( DeviceObject,
Irp,
miniport,
UnknownAdapter,
ResourceList );
if (NT_SUCCESS(ntStatus))
{
//
// Register the subdevice (port/miniport combination).
//
ntStatus = PcRegisterSubdevice( DeviceObject,
Name,
port );
if (!(NT_SUCCESS(ntStatus)))
{
_DbgPrintF(DEBUGLVL_TERSE, ("StartDevice: PcRegisterSubdevice failed"));
}
}
else
{
_DbgPrintF(DEBUGLVL_TERSE, ("InstallSubdevice: port->Init failed"));
}
//
// We don't need the miniport any more. Either the port has it,
// or we've failed, and it should be deleted.
//
miniport->Release();
}
else
{
_DbgPrintF(DEBUGLVL_TERSE, ("InstallSubdevice: PcNewMiniport failed"));
}
if (NT_SUCCESS(ntStatus))
{
//
// Deposit the port as an unknown if it's needed.
//
if (OutPortUnknown)
{
//
// Failure here doesn't cause the entire routine to fail.
//
(void) port->QueryInterface
(
IID_IUnknown,
(PVOID *) OutPortUnknown
);
}
}
else
{
//
// Retract previously delivered port interface.
//
if (OutPortInterface && (*OutPortInterface))
{
(*OutPortInterface)->Release();
*OutPortInterface = NULL;
}
}
//
// Release the reference which existed when PcNewPort() gave us the
// pointer in the first place. This is the right thing to do
// regardless of the outcome.
//
port->Release();
}
else
{
_DbgPrintF(DEBUGLVL_TERSE, ("InstallSubdevice: PcNewPort failed"));
}
return ntStatus;
}
/*****************************************************************************
* StartDevice()
*****************************************************************************
* This function is called by the operating system when the device is started.
* It is responsible for starting the miniports. This code is specific to
* the adapter because it calls out miniports for functions that are specific
* to the adapter.
*/
NTSTATUS
StartDevice
(
IN PDEVICE_OBJECT DeviceObject, // Device object.
IN PIRP Irp, // IO request packet.
IN PRESOURCELIST ResourceList // List of hardware resources.
)
{
PAGED_CODE();
ASSERT(DeviceObject);
ASSERT(Irp);
ASSERT(ResourceList);
//
// These are the sub-lists of resources that will be handed to the
// miniports.
//
PRESOURCELIST resourceListWave = NULL;
PRESOURCELIST resourceListWaveTable = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -