replace ad hoc driver loading with a proper driver manager, new DDK, new PnP manager with device matching, asynchronous startup, resource ownership and removal, add shared PCI capability helpers, replace typed, rigid services with a proper service manager, implement proper system shutdown and restart, shutting down unloads drivers and shuts down services, add simple power button, remove heavyweight boot self-tests and SMP stress runs, add monotonic timestamps to kernel debug output, fruitless USB and PS/2 fixes, make test builds opt in.

This commit is contained in:
maksw committed 2026-10-26 10:08:03 +01:00
1 parent c0ad63c27f
commit d36f19509c
160 files changed
+6563 -7366

No files matched your search

+20 -25
View File
@@ -1,8 +1,8 @@
#include <ntlite/ddk/module.h>
// Realtek RTL8139 network driver. This file owns PCI attachment, MMIO setup, RX/TX rings, and net-device registration.
#include "rtl8139.h"
const NTL_DDK* gRtl8139Ddk;
static DRIVER_OBJECT gRtl8139Driver;
static RTL8139_DEVICE* gRtl8139Devices[RTL8139_MAX_DEVICES];
static uint32_t gRtl8139DeviceCount;
@@ -69,8 +69,7 @@ static KSTATUS Rtl8139Reset(RTL8139_DEVICE* r) {
for (uint32_t i = 0; i < 1000; i++) {
if ((Rtl8139Read8(r, RTL8139_REG_CMD) & RTL8139_CMD_RST) == 0)
return NTLSTATUS_SUCCESS;
if (gRtl8139Ddk->Timer->Stall)
gRtl8139Ddk->Timer->Stall(1000);
KeStallExecution(1000);
}
return NTLSTATUS_TIMEOUT;
}
@@ -100,17 +99,17 @@ static void Rtl8139StopDma(RTL8139_DEVICE* r) {
// Releases the common buffers and adapter owned by one RTL8139 device.
static void Rtl8139ReleaseDma(RTL8139_DEVICE* r) {
if (!r || !gRtl8139Ddk || !gRtl8139Ddk->Dma)
if (!r)
return;
gRtl8139Ddk->Dma->FreeCommonBuffer(r->TxDma);
gRtl8139Ddk->Dma->FreeCommonBuffer(r->RxDma);
IoDmaFreeCommonBuffer(r->TxDma);
IoDmaFreeCommonBuffer(r->RxDma);
r->TxDma = (IO_DMA_BUFFER*)0;
r->RxDma = (IO_DMA_BUFFER*)0;
r->TxBuffers = (uint8_t*)0;
r->RxBuffer = (uint8_t*)0;
r->TxDeviceAddress = 0;
r->RxDeviceAddress = 0;
gRtl8139Ddk->Dma->PutAdapter(r->DmaAdapter);
IoDmaPutAdapter(r->DmaAdapter);
r->DmaAdapter = (IO_DMA_ADAPTER*)0;
}
@@ -123,13 +122,13 @@ static KSTATUS Rtl8139AllocateDma(RTL8139_DEVICE* r) {
requirements.MaximumSegmentLength = RTL8139_TX_BUF_SIZE;
requirements.MaximumSegments = 1;
KSTATUS status = gRtl8139Ddk->Dma->GetAdapter(r->Fdo,
KSTATUS status = IoDmaGetAdapter(r->Fdo,
&requirements,
&r->DmaAdapter);
if (!KSUCCESS(status))
return status;
status = gRtl8139Ddk->Dma->AllocateCommonBuffer(r->DmaAdapter,
status = IoDmaAllocateCommonBuffer(r->DmaAdapter,
RTL8139_RX_ALLOC_SIZE,
PAGE_SIZE,
&r->RxDma);
@@ -138,7 +137,7 @@ static KSTATUS Rtl8139AllocateDma(RTL8139_DEVICE* r) {
return status;
}
status = gRtl8139Ddk->Dma->AllocateCommonBuffer(r->DmaAdapter,
status = IoDmaAllocateCommonBuffer(r->DmaAdapter,
RTL8139_TX_SLOTS * RTL8139_TX_BUF_SIZE,
PAGE_SIZE,
&r->TxDma);
@@ -147,10 +146,10 @@ static KSTATUS Rtl8139AllocateDma(RTL8139_DEVICE* r) {
return status;
}
r->RxBuffer = (uint8_t*)gRtl8139Ddk->Dma->GetCommonBufferAddress(r->RxDma);
r->TxBuffers = (uint8_t*)gRtl8139Ddk->Dma->GetCommonBufferAddress(r->TxDma);
r->RxDeviceAddress = gRtl8139Ddk->Dma->GetCommonBufferDeviceAddress(r->RxDma);
r->TxDeviceAddress = gRtl8139Ddk->Dma->GetCommonBufferDeviceAddress(r->TxDma);
r->RxBuffer = (uint8_t*)IoDmaGetCommonBufferAddress(r->RxDma);
r->TxBuffers = (uint8_t*)IoDmaGetCommonBufferAddress(r->TxDma);
r->RxDeviceAddress = IoDmaGetCommonBufferDeviceAddress(r->RxDma);
r->TxDeviceAddress = IoDmaGetCommonBufferDeviceAddress(r->TxDma);
DbgPrint("RTL8139: rx=0x%016llX tx=0x%016llX\n",
(unsigned long long)r->RxDeviceAddress,
@@ -603,14 +602,11 @@ KSTATUS Rtl8139AddDevice(DRIVER_OBJECT* driver, DEVICE_OBJECT* physicalDeviceObj
return NTLSTATUS_SUCCESS;
}
// Implements the driver Entry operation.
KSTATUS DriverEntry(const NTL_DDK* ddk, NTL_DRIVER_INIT* init) {
(void)init;
if (!ddk || !ddk->Dma || !ddk->Timer)
return NTLSTATUS_INVALID_PARAMETER;
static KSTATUS DriverInitialize(NTL_MODULE* module) {
(void)module;
DbgPrint("RTL8139: driver loading...\n");
gRtl8139Ddk = ddk;
gRtl8139DeviceCount = 0;
memset(&gRtl8139Driver, 0, sizeof(gRtl8139Driver));
@@ -618,9 +614,8 @@ KSTATUS DriverEntry(const NTL_DDK* ddk, NTL_DRIVER_INIT* init) {
gRtl8139Driver.IdTable = &gRtl8139IdTable;
gRtl8139Driver.DriverAddDevice = Rtl8139AddDevice;
gRtl8139Driver.MajorFunction[IRP_MJ_PNP] = Rtl8139DispatchPnp;
KSTATUS st = IoRegisterDriverObject(&gRtl8139Driver);
if (!KSUCCESS(st))
DbgPrint("RTL8139: IoRegisterDriverObject failed: 0x%x\n", st);
return st;
return NTLSTATUS_SUCCESS;
}
static DRIVER_OBJECT* const gModuleIoDrivers[] = { &gRtl8139Driver };
NTL_DECLARE_IO_MODULE(DriverInitialize, gModuleIoDrivers);