API Reference
Header Map
Section titled “Header Map”| Header | Purpose |
|---|---|
include/kdal/types.h |
Core types, enums, structs |
include/kdal/api/common.h |
Feature flags, status codes |
include/kdal/api/driver.h |
Conventional driver contract |
include/kdal/api/accel.h |
Accelerator contract |
include/kdal/backend.h |
Backend operations table |
include/kdal/ioctl.h |
Userspace ABI definitions |
include/kdal/core/kdal.h |
Lifecycle, registration, lookup, the resource demand (kdal_demand_format) |
include/kdal/core/version.h |
Version constants |
Lifecycle Functions
Section titled “Lifecycle Functions”int kdal_core_init(void); /* Module init cascade */void kdal_core_exit(void); /* Module exit cascade */int kdal_chardev_init(void); /* Register /dev/kdal */void kdal_chardev_exit(void); /* Deregister /dev/kdal */int kdal_debugfs_init(void); /* Create debugfs tree */void kdal_debugfs_exit(void); /* Remove debugfs tree */Registry Functions
Section titled “Registry Functions”/* Backend registration */int kdal_register_backend(struct kdal_backend *backend);void kdal_unregister_backend(struct kdal_backend *backend);
/* Driver registration */int kdal_register_driver(struct kdal_driver *driver);void kdal_unregister_driver(struct kdal_driver *driver);
/* Device registration */int kdal_register_device(struct kdal_device *device);void kdal_unregister_device(struct kdal_device *device);
/* Attachment */int kdal_attach_driver(struct kdal_device *device, struct kdal_driver *driver);void kdal_detach_driver(struct kdal_device *device);
/* Lookup */struct kdal_backend *kdal_find_backend(const char *name);struct kdal_driver *kdal_find_driver(enum kdal_device_class class_id);struct kdal_device *kdal_find_device(const char *name);
/* Introspection */void kdal_get_registry_snapshot(struct kdal_registry_snapshot *snapshot);int kdal_for_each_device(kdal_device_iter_fn fn, void *data);Resource Demand
Section titled “Resource Demand”A device that points to a struct kdal_demand (types.h) is part of the
resource demand KDAL reports: one device region (base, size, read/write
attributes), its interrupts (GIC INTIDs), and its SMMU and stream IDs, in
the vocabulary of Arm’s FF-A partition manifest.
size_t kdal_demand_format(char *buf, size_t len); /* JSON into buf */The same report is in debugfs (/sys/kernel/debug/kdal/demand); HAVEN’s
demand check compares it with the partition’s grant.
Event Functions
Section titled “Event Functions”int kdal_emit_event(enum kdal_event_type type, const char *device_name, u32 data);int kdal_poll_event(struct kdal_event *out); /* -EAGAIN if empty */void kdal_event_shutdown(void); /* Reset event log */Power Management
Section titled “Power Management”int kdal_set_device_power(struct kdal_device *device, enum kdal_power_state state);Calls the driver’s set_power_state op if available, updates
device->power_state, and emits a KDAL_EVENT_POWER_CHANGE event.
Driver Contract
Section titled “Driver Contract”struct kdal_driver_ops { int (*probe)(struct kdal_device *device); void (*remove)(struct kdal_device *device); ssize_t (*read)(struct kdal_device *device, char __user *buf, size_t count, loff_t *ppos); ssize_t (*write)(struct kdal_device *device, const char __user *buf, size_t count, loff_t *ppos); long (*ioctl)(struct kdal_device *device, unsigned int cmd, unsigned long arg); int (*set_power_state)(struct kdal_device *device, enum kdal_power_state state);};probe is required: binding a driver without it fails with -EINVAL
(src/core/kdal.c). The others are optional: through /dev/kdal, a
missing read or write gives -EOPNOTSUPP, and an ioctl command the
character device does not handle gives -ENOTTY.
Accelerator Contract
Section titled “Accelerator Contract”struct kdal_accel_ops { int (*queue_create)(struct kdal_device *device, struct kdal_accel_queue *queue); void (*queue_destroy)(struct kdal_device *device, struct kdal_accel_queue *queue); int (*buffer_map)(struct kdal_device *device, struct kdal_accel_buffer *buffer); void (*buffer_unmap)(struct kdal_device *device, struct kdal_accel_buffer *buffer); int (*submit)(struct kdal_device *device, struct kdal_accel_queue *queue, const void *cmd, size_t cmd_len);};Used by GPU and NPU class drivers for compute workloads.
Backend Contract
Section titled “Backend Contract”struct kdal_backend_ops { int (*init)(struct kdal_backend *backend); void (*exit)(struct kdal_backend *backend); int (*enumerate)(struct kdal_backend *backend); ssize_t (*read)(struct kdal_device *device, char *buf, size_t count); ssize_t (*write)(struct kdal_device *device, const char *buf, size_t count); long (*ioctl)(struct kdal_device *device, unsigned int cmd, unsigned long arg);};Userspace ioctl ABI
Section titled “Userspace ioctl ABI”All commands use magic number 'K' (0x4B).
| Command | Direction | Payload | Description |
|---|---|---|---|
KDAL_IOCTL_GET_VERSION |
_IOR |
kdal_ioctl_version |
Module version |
KDAL_IOCTL_GET_INFO |
_IOWR |
kdal_ioctl_info |
Device info (by name or selected) |
KDAL_IOCTL_SET_POWER |
_IOW |
__u32 |
Power state (0=off, 1=on, 2=suspend) |
KDAL_IOCTL_LIST_DEVICES |
_IOR |
kdal_ioctl_list |
All registered device names |
KDAL_IOCTL_POLL_EVENT |
_IOR |
kdal_ioctl_event |
Defined, not yet dispatched: returns -ENOTTY |
KDAL_IOCTL_SELECT_DEV |
_IOW |
kdal_ioctl_devname |
Select device for read/write |
Enumerations
Section titled “Enumerations”enum kdal_device_class { KDAL_DEV_CLASS_UNSPEC = 0, KDAL_DEV_CLASS_UART, KDAL_DEV_CLASS_I2C, KDAL_DEV_CLASS_SPI, KDAL_DEV_CLASS_GPIO, KDAL_DEV_CLASS_GPU, KDAL_DEV_CLASS_NPU,};
enum kdal_power_state { KDAL_POWER_OFF, KDAL_POWER_ON, KDAL_POWER_SUSPEND,};
enum kdal_event_type { KDAL_EVENT_NONE, KDAL_EVENT_DEVICE_ADDED, KDAL_EVENT_DEVICE_REMOVED, KDAL_EVENT_IO_READY, KDAL_EVENT_POWER_CHANGE, KDAL_EVENT_ACCEL_COMPLETE, KDAL_EVENT_FAULT,};Feature Flags
Section titled “Feature Flags”#define KDAL_FEAT_EVENT_PUSH BIT(0) /* Backend supports event push */#define KDAL_FEAT_POWER_MGMT BIT(1) /* Backend supports power mgmt */#define KDAL_FEAT_SHARED_MEM BIT(2) /* Backend supports shared memory */#define KDAL_FEAT_ACCEL_QUEUE BIT(3) /* Backend supports accel queues */Compiler API
Section titled “Compiler API”The compiler is also built as a C library (libkdalc.a, installed with
the kdalc binary); its header is compiler/include/codegen.h in the
repository, installed as include/kdalc/codegen.h. The language and
compiler are frozen since 2026-11-01.
#include <kdalc/codegen.h>
/* Full pipeline: .kdc file -> generated .c + Makefile.kbuild */int kdal_compile_file(const char *src_path, const kdal_codegen_opts_t *opts);
/* Individual stages */int kdal_lex(kdal_arena_t *arena, const char *src, size_t src_len, kdal_token_t **out_tokens, const char *filename);kdal_file_node_t *kdal_parse(kdal_arena_t *arena, const kdal_token_t *tokens, int ntokens, const char *filename);int kdal_sema(kdal_file_node_t *file, const char *filename);int kdal_generate(const kdal_file_node_t *file_node, const char *src_path, const kdal_codegen_opts_t *opts);Code Generation Options
Section titled “Code Generation Options”typedef struct { const char *output_dir; /* directory to write .c and Makefile.kbuild */ const char *kernel_dir; /* KERNEL_DIR for the generated Makefile.kbuild */ const char *cross_compile; /* CROSS_COMPILE prefix, may be NULL */ int verbose;} kdal_codegen_opts_t;The generated module does not build yet (open finding O7 in KDAL’s
docs/open-findings-20261121.md).