Chris Cant - Writing Windows WDM Device Drivers

Здесь есть возможность читать онлайн «Chris Cant - Writing Windows WDM Device Drivers» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Lawrence, Kansas 66046, ISBN: , Издательство: R & D Books, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Writing Windows WDM Device Drivers: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Writing Windows WDM Device Drivers»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Writing Windows WDM Device Drivers — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Writing Windows WDM Device Drivers», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

INTERFACE_TYPE InterfaceType; // unused for WDM

ULONG BusNumber; // unused for WDM

CM_PARTIAL_RESOURCE_LIST PartialResourceList;

} CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;

typedef struct _CM_PARTIAL_RESOURCE_LIST {

USHORT Version;

USHORT Revision;

ULONG Count;

CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];

} CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;

typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {

UCHAR Type;

UCHAR ShareDisposition;

USHORT Flags;

union {

// …

} u;

} CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;

The PHDIo driver deals with only the first instance of the ISA bus, so it needs only one Full Resource Descriptor. It always has one Partial Resource Descriptor for the I/O port. It can also have a second Partial Resource Descriptor for the interrupt, if one was specified.

ClaimResources, in Listing 18.4, builds a resource list structure and passes it to IoReportResourceUsage .

As you can guess, it is quite a job building the resource list correctly. The correct size for the whole structure must be determined first. A suitably sized block of paged memory is allocated and zeroed.

ClaimResources gradually fills the resource list. The resource list Count is set to one, as there is only one Full Resource Descriptor. The Full Resource Descriptor InterfaceType field is set to Isa and the BusNumber is set to 0. The Partial Resource List Count is set to 1 or 2, depending on how many resources are declared. The Partial Resource Descriptor for the I/O port is generated, then the one for the interrupt, if required. Whew!

There is a final complication to calling IoReportResourceUsage . You must either specify the resource list as belonging to the whole driver, or associate the resource list with an individual device. PHDIo says that the resources belong to the whole driver. If PHDIo were enhanced to provide more than one device, it would make sense to allocate resources on a per-device basis. One call to IoReportResourceUsage per device would be needed in this case.

Listing 18.4 ClaimResources routine

NTSTATUS ClaimResources(IN PDEVICE_OBJECT phddo) {

PPHDIO_DEVICE_EXTENSION dx = (PPHDIO_DEVICE_EXTENSION)phddo->DeviceExtension;

// Get resource count: either 1 (IOport) or 2 (IOport&IRQ)

ULONG PartialResourceCount = 1;

if (dx->GotInterrupt) PartialResourceCount++;

// Get size of required CM_RESOURCE_LIST

ULONG ListSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0]);

ListSize += sizeof(CM_FULL_RESOURCE_DESCRIPTOR) + ((PartialResourceCount-1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));

// Allocate CM_RESOURCE_LIST

PCM_RESOURCE_LIST ResourceList = (PCM_RESOURCE_LIST)ExAllocatePool(PagedPool, ListSize);

if (ResourceList==NULL) {

DebugPrintMsg("Cannot allocate memory for ResourceList");

return STATUS_INSUFFICIENT_RESOURCES;

}

RtlZeroMemory(ResourceList, ListSize);

// Only one Full Resource Descriptor needed, for ISA

ResourceList->Count = 1;

// Initialise Full Resource Descriptor

PCM_FULL_RESOURCE_DESCRIPTOR FullRD = &ResourceList->List[0];

FullRD->InterfaceType = Isa;

FullRD->BusNumber = 0;

FullRD->PartialResourceList.Count = PartialResourceCount;

// Initialise Partial Resource Descriptor for IO port

PCM_PARTIAL_RESOURCE_DESCRIPTOR resource = &FullRD->PartialResourceList.PartialDescriptors[0];

resource->Type = CmResourceTypePort;

resource->ShareDisposition = CmResourceShareDriverExciusive;

resource->Flags = CM_RESOURCE_PORT_IO;

resource->u.Port.Start = dx->PortStartAddress;

resource->u.Port.Length = dx->PortLength;

// Initialise Partial Resource Descriptor for Interrupt

if (dx->GotInterrupt) {

resource++;

resource->Type = CmResourceTypeInterrupt;

resource->ShareDisposition = CmResourceShareDriverExclusive;

if (dx->Mode==Latched) resource->Flags = CM_RESOURCE_INTERRUPT_LATCHED;

else resource->F1ags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;

resource->u.Interrupt.Level = dx->Irql;

resource->u.Interrupt.Vector = dx->Irql;

resource->u.Interrupt.Affinity = 1;

}

// Ask for resources for the driver

DebugPrint("Allocating %d resources", PartialResourceCount);

DebugPrint("phddo->DriverObject %x", phddo->DriverObject);

if (dx->ResourceOverride) DebugPrintMsg("Resource override conflict");

BOOLEAN ConflictDetected;

NTSTATUS status = IoReportResourceUsage(NULL,

phddo->DriverObject, ResourceList, ListSize, // Driver resources

NULL, NULL, 0, // Device resources

dx->ResourceOverride, &ConflictDetected);

// Cope (or override) if resource conflict found

if (ConflictDetected) {

DebugPrintMsg("ConflictDetected");

if (dx->ResourceOverride) {

DebugPrintMsg("Conflict detected and overridden");

status = STATUS_SUCCESS;

}

}

// Free allocated memory

ExFreePool(ResourceList);

return status;

}

Table 18.1 shows the parameters for IoReportResourceUsage . If you are allocating resources for the whole driver, use the DriverObject, DriverList, and DriverListSize parameters; otherwise, set these to NULL. Do the same for the per-device parameters, DeviceObject, DeviceList, and DeviceListSize.

In the NT and Windows 2000 platforms, the resource assignments end up in the registry in the HKLM\HARDWARE\RESOURCEMAP key [45] I do not know where they go in Windows 98. . If you specify a DriverClassName parameter, this string is used as a subkey to hold the resource assignments. Otherwise, in NT 4 and NT 3.51, the resource assignments end up in the "OtherDrivers" subkey. In W2000, the resource assignments are in the "PnP Manager" subkey. You can use RegEdt32 to inspect the raw and translated resource assignments. In NT 3.51 and NT 4 this is the only way to view the resources used by the system. In Windows 2000 and Windows 98, the Device Manager properties for a device shows its resource usage; in W2000, the PHDIo device can be found if you opt to show hidden devices.

IoReportResourceUsage checks for resource conflicts and, if none, assigns the new resources. The OverrideConflict parameter can be used to force the storage of the new resource list, even if there were conflicts. The output ConflictDetected BOOLEAN says whether a conflict was detected. If its ResourceOverride field is true, PHDIo ignores a resource conflict and forces a STATUS_SUCCESS return.

Table 18.1 IoReportResourceUsage function

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Writing Windows WDM Device Drivers»

Представляем Вашему вниманию похожие книги на «Writing Windows WDM Device Drivers» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Writing Windows WDM Device Drivers»

Обсуждение, отзывы о книге «Writing Windows WDM Device Drivers» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x