96 lines
3.7 KiB
C
96 lines
3.7 KiB
C
#pragma once
|
|
// ke_irp.h - I/O Request Packet
|
|
//
|
|
// This header intentionally includes only ke_list.h, ke_spinlock.h, and
|
|
// ke_status.h — all of which are pure-inline / macro headers with no
|
|
// external symbol references. ke_event.h and ke_semaphore.h are forward-
|
|
// declared here so the HAL layer (hal_disk.c, io_driver.h) can include this
|
|
// header without dragging in kernel sync-object link dependencies.
|
|
//
|
|
// Files that actually call KeEventCreate / KeSignalEvent / KeWaitForEvent
|
|
// (ke_irp.c, ahci.c) include ke_event.h and ke_semaphore.h themselves.
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <ke_list.h>
|
|
#include <ke_spinlock.h>
|
|
#include <ke_status.h>
|
|
|
|
// Forward declarations — full types live in ke_event.h / ke_semaphore.h.
|
|
// We only ever hold pointers in IRP and IRP_QUEUE, so a forward decl suffices.
|
|
struct EVENT;
|
|
struct SEMAPHORE;
|
|
|
|
// -------------------------------------------------------------------------
|
|
// IRP flags
|
|
// -------------------------------------------------------------------------
|
|
|
|
#define IRP_FLAG_WRITE (1u << 0) // direction: write to device
|
|
#define IRP_FLAG_PRIORITY (1u << 1) // insert at head of queue (elevated)
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Forward declaration (IRP is self-referential via CompletionFn)
|
|
// -------------------------------------------------------------------------
|
|
|
|
typedef struct IRP IRP;
|
|
|
|
// Completion callback: invoked in driver worker context; must not block.
|
|
typedef void (*IRP_COMPLETION_FN)(IRP *irp, void *ctx);
|
|
|
|
// -------------------------------------------------------------------------
|
|
// I/O Request Packet
|
|
// -------------------------------------------------------------------------
|
|
|
|
typedef struct IRP {
|
|
// Embedded list node — driver-internal; do not touch after submit.
|
|
LIST_ENTRY Link;
|
|
|
|
// ---- Request parameters (caller fills before IoSubmitIrp) ------------
|
|
|
|
uint8_t DriveIndex;
|
|
uint32_t Flags; // IRP_FLAG_*
|
|
uint64_t Lba;
|
|
uint32_t SectorCount;
|
|
void *Buffer; // kernel VA; valid until completion
|
|
|
|
// ---- Completion (caller fills before submit; driver writes Status) ----
|
|
|
|
volatile KSTATUS Status;
|
|
|
|
// Forward-declared pointer: callers that create events include ke_event.h.
|
|
struct EVENT *CompletionEvent;
|
|
|
|
IRP_COMPLETION_FN CompletionFn;
|
|
void *CompletionCtx;
|
|
|
|
// ---- Driver-internal --------------------------------------------------
|
|
|
|
uint8_t HwSlot;
|
|
void *DriverCtx;
|
|
} IRP;
|
|
|
|
// -------------------------------------------------------------------------
|
|
// IRP_QUEUE (per-device, driver-internal)
|
|
// -------------------------------------------------------------------------
|
|
|
|
typedef struct IRP_QUEUE {
|
|
SPINLOCK Lock;
|
|
LIST_ENTRY Head;
|
|
struct SEMAPHORE *Semaphore; // forward-declared pointer
|
|
} IRP_QUEUE;
|
|
|
|
// Non-inline: defined in ke_irp.c, which can pull in ke_semaphore.h safely.
|
|
__declspec(dllexport) void IrpQueueInit (IRP_QUEUE *q, struct SEMAPHORE *sem);
|
|
__declspec(dllexport) void IrpQueueEnqueue (IRP_QUEUE *q, IRP *irp);
|
|
__declspec(dllexport) IRP *IrpQueueDequeue (IRP_QUEUE *q);
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Public dispatch API — implemented in kernel/ke_irp.c
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Submit asynchronously. Returns STATUS_PENDING on success.
|
|
__declspec(dllexport) KSTATUS IoSubmitIrp (IRP *irp);
|
|
|
|
// Submit and block until complete. Returns irp->Status.
|
|
__declspec(dllexport) KSTATUS IoSubmitIrpSync(IRP *irp);
|