1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
/*********************************************************************************************
Initialisation function : call by system when driver load
DO :
create the device object with our extention (LOCAL_DEVICE_INFO)
try to find the PCI adapter
report ressource (IRQ and port to NT system)
initialise AMCC chip
connect the interrupt to our ISR
create symbolink link
IF FAIL write to WinDbg, free ressources and return STATUS_error_code
**********************************************************************************************/
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT [b]DriverObject[/b],
IN PUNICODE_STRING RegistryPath
)
{
PDEVICE_OBJECT deviceObject = NULL;
NTSTATUS status;
UNICODE_STRING uniNtNameString;
UNICODE_STRING uniWin32NameString;
LOCAL_DEVICE_INFO *pDev;
BOOLEAN bResConflict;
PHYSICAL_ADDRESS PortAddress;
PHYSICAL_ADDRESS MappedAddress;
ULONG MemType;
KdPrint( ("OceDrv: Entered the Load/Unload driver!\n") );
//
// Create counted string version of our device name.
//
RtlInitUnicodeString( &uniNtNameString, NT_DEVICE_NAME );
//
// Create the device object
//
status = IoCreateDevice(
[b]DriverObject[/b],
sizeof(LOCAL_DEVICE_INFO), // Our private extension (in DeviceExtension of
// DeviceObject)
&uniNtNameString,
OCE_TYPE, // Our defined Device Type
0, // No standard device characteristics
FALSE, // Not exclusive device
&deviceObject
);
if (! NT_SUCCESS(status) )
{
KdPrint( ("OceDrv : can't create the device\n") );
return(status);
}
deviceObject->Flags |= DO_DIRECT_IO; // method direct I/O for read/write
pDev = (LOCAL_DEVICE_INFO *) deviceObject->DeviceExtension;
pDev->DeviceObject = deviceObject;
pDev->DeviceType = OCE_TYPE;
pDev->PortCount = PCI_NBRPORT * 4;
pDev->OpenCount = 0;
pDev->TimerRead = pDev->TimerWrite = -1;
// Try to find the PCI Adapter
status = pOceGetBus(deviceObject,PCI_VID,PCI_DID);
if(! status)
{
KdPrint( ("OceDrv: Couldn't find adapter\n") );
status = STATUS_UNSUCCESSFUL;
IoDeleteDevice( DriverObject->DeviceObject );
return(status);
}
pDev->Pbase = (pDev->PciConf.u.type0.BaseAddresses[0] & ~1); // base port of AMCC
// we mask bit 0 because it's just the I/O indicator
pDev->Irq = pDev->PciConf.u.type0.InterruptLine; // Irq of AMCC
pDev->isIrq = FALSE;
PortAddress.LowPart = pDev->Pbase;
PortAddress.HighPart = 0;
// Convert the IO port address into a form NT likes.
MemType = 1; // located in IO space
HalTranslateBusAddress( PCIBus,
0,
PortAddress,
&MemType,
&MappedAddress );
if (MemType == 0)
{
// Port is accessed through memory space - so get a virtual address
pDev->PortWasMapped = TRUE;
pDev->PortBase = MmMapIoSpace(MappedAddress, pDev->PortCount, FALSE);
}
else
{
pDev->PortWasMapped = FALSE;
pDev->PortBase = (PVOID)MappedAddress.LowPart;
}
PortAddress.LowPart = (ULONG) pDev->PortBase;
// report the status to NT system
if(! pOceReportUsage(DriverObject,PortAddress,pDev->PortCount,pDev->Irq,&bResConflict))
{
status = STATUS_DEVICE_CONFIGURATION_ERROR;
KdPrint( ("Resource reporting problem %8X", status) );
pOceUnMap(DriverObject);
IoDeleteDevice( DriverObject->DeviceObject );
return status;
}
// Init our Irq
if(! pOceConnectInterrupt(pDev,pDev->Irq))
{
status = STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT;
KdPrint( ("Interrupt Not connected %8X", status) );
pOceUnMap(DriverObject);
pOceUnreport(DriverObject);
IoDeleteDevice( DriverObject->DeviceObject );
return(status);
}
//
// Create dispatch points for create/open, close, unload.
//
[b]DriverObject[/b]->MajorFunction[IRP_MJ_CREATE] = OceOpen;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = OceClose;
DriverObject->MajorFunction[IRP_MJ_READ] = OceRead; // Read
DriverObject->MajorFunction[IRP_MJ_WRITE] = OceWrite; // Write
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = OceDispatch; // Ioctl
DriverObject->DriverStartIo = OceStartIo;
DriverObject->DriverUnload = OceUnload;
//
// Create counted string version of our Win32 device name.
//
RtlInitUnicodeString( &uniWin32NameString, DOS_DEVICE_NAME );
//
// Create a link from our device name to a name in the Win32 namespace.
//
status = IoCreateSymbolicLink( &uniWin32NameString, &uniNtNameString );
if (!NT_SUCCESS(status))
{
KdPrint( ("OceDrv: Couldn't create the symbolic link\n") );
pOceUnMap(DriverObject);
pOceDiscInterrupt(DriverObject);
pOceUnreport(DriverObject);
IoDeleteDevice( DriverObject->DeviceObject );
}
/************/
if(! pOceInitTimer(deviceObject))
{
KdPrint( ("OceDrv: Can't create timer\n") );
status = STATUS_INSUFFICIENT_RESOURCES;
pOceUnMap(DriverObject);
pOceDiscInterrupt(DriverObject);
pOceUnreport(DriverObject);
IoDeleteSymbolicLink(&uniWin32NameString);
IoDeleteDevice( DriverObject->DeviceObject );
}
else
{
pOceGetAdapter(pDev);
// init our event for pOceAdapterControl
KeInitializeEvent(&(pDev->AdapterChannelEvent),NotificationEvent,FALSE );
// init our event for pOceDpcForIsr()
KeInitializeEvent(&(pDev->ReadInterruptEvent),SynchronizationEvent,FALSE);
KeInitializeEvent(&(pDev->WriteInterruptEvent),SynchronizationEvent,FALSE);
// init our DPC for ISR
IoInitializeDpcRequest(deviceObject,pOceDpcForIsr);
AMCC_LoadRegister(&(pDev->DrvPort),pDev->PortBase);
bidon(pDev);
pOceInitDma(&(pDev->DrvPort));
KdPrint( ("OceDrv: All initialized!\n") );
}
return status;
} |