Files
nt-lite/code/kernel/include/kernel/dm_config.h
T

86 lines
2.2 KiB
C

// Kernel driver configuration and dependency graph contract.
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define DM_MAX_DRIVERS 64u
#define DM_MAX_CLASSES 32u
#define DM_MAX_EDGES 16u
#define DM_ID_MAX 64u
#define DM_IMAGE_MAX 64u
#define DM_CONFIG_MAX_BYTES (64u * 1024u)
typedef enum DM_START_PHASE {
DmStartBoot,
DmStartRuntime,
DmStartDisabled,
} DM_START_PHASE;
typedef enum DM_DEPENDENCY_KIND {
DmDependencyClass,
DmDependencyDriver,
} DM_DEPENDENCY_KIND;
typedef struct DM_DEPENDENCY {
DM_DEPENDENCY_KIND Kind;
char Id[DM_ID_MAX];
} DM_DEPENDENCY;
typedef struct DM_EDGES {
DM_DEPENDENCY Items[DM_MAX_EDGES];
uint32_t Count;
} DM_EDGES;
typedef enum DM_RUN_STATE {
DmRunWaiting,
DmRunStarted,
DmRunFailed,
DmRunBlocked,
DmRunDisabled,
} DM_RUN_STATE;
typedef struct DM_DRIVER_CONFIG {
char Id[DM_ID_MAX];
char Image[DM_IMAGE_MAX];
char Class[DM_ID_MAX];
DM_EDGES Requires;
DM_EDGES After;
DM_START_PHASE Phase;
DM_RUN_STATE State;
bool Critical;
uint8_t Present;
} DM_DRIVER_CONFIG;
typedef struct DM_CLASS_CONFIG {
char Id[DM_ID_MAX];
DM_EDGES Requires;
DM_EDGES After;
uint8_t Present;
} DM_CLASS_CONFIG;
typedef struct DM_CONFIG {
DM_DRIVER_CONFIG Drivers[DM_MAX_DRIVERS];
DM_CLASS_CONFIG Classes[DM_MAX_CLASSES];
uint32_t DriverCount;
uint32_t ClassCount;
DM_START_PHASE ActivePhase;
} DM_CONFIG;
// Parses and validates a complete immutable configuration before any driver starts.
// Empty optional values and omitted optional keys have identical semantics.
bool DmConfigParse(DM_CONFIG* config, const char* bytes, size_t size,
char* error, size_t errorCapacity);
// Returns true once every configured provider in this class has reached a terminal state.
bool DmClassSettled(const DM_CONFIG* config, const char* classId);
bool DmClassAvailable(const DM_CONFIG* config, const char* classId);
// Tests the current requirements/ordering gates for a single waiting module.
bool DmDriverCanStart(const DM_CONFIG* config, uint32_t index);
// Returns true once a waiting driver's required dependency cannot become available.
bool DmDriverIsBlocked(const DM_CONFIG* config, uint32_t index);