Skip to content

Porting Guide

Porting KDAL to a new platform means implementing a backend adapter; the driver layer and the userspace interface are meant to stay unchanged. KDAL runs on QEMU only so far: no port to real hardware has been done, so this page describes the intended path.

Create a new directory under src/backends/<platform>/ with a backend source file implementing struct kdal_backend_ops:

static const struct kdal_backend_ops myplatform_ops = {
.init = myplatform_init,
.exit = myplatform_exit,
.enumerate = myplatform_enumerate,
.read = myplatform_read,
.write = myplatform_write,
.ioctl = myplatform_ioctl,
};
static struct kdal_backend myplatform_backend = {
.name = "my-platform",
.feature_flags = KDAL_FEAT_POWER_MGMT,
.ops = &myplatform_ops,
};

The read/write ops provide the data transport path. On real hardware these access MMIO registers, DMA buffers, or a bus controller:

static ssize_t myplatform_read(struct kdal_device *device,
char *buf, size_t count)
{
void __iomem *base = device->priv;
size_t i;
for (i = 0; i < count; i++)
buf[i] = kdal_mmio_read8(base, 0x00); /* a data register */
return i;
}

The MMIO helpers (kdal_mmio_read8/16/32, kdal_mmio_write8/16/32) are declared in include/kdal/core/internal.h and defined in src/backends/qemu/mmio.c; there is no bulk helper.

During enumerate(), scan platform resources (Device Tree, ACPI, PCI) and create kdal_device instances:

static int myplatform_enumerate(struct kdal_backend *backend)
{
/* create and register this platform's kdal_device instances */
return 0;
}

Device Tree nodes with compatible = "kdal,device" are already scanned by the core (kdal_devicetree_scan(), src/backends/generic/devicetree.c, called from kdal_core_init), so a DT-described platform may need no enumeration of its own.

Add init/exit functions and call them from kdal_core_init() and kdal_core_exit() in src/core/kdal.c, next to the backends already there:

int kdal_myplatform_backend_init(void);
void kdal_myplatform_backend_exit(void);

Add the new .o files to the kdal-y list in Makefile (the QEMU backend and the example drivers are in kdal-$(CONFIG_KDAL_QEMU_BACKEND) and kdal-$(CONFIG_KDAL_EXAMPLE_DRIVERS), both y by default); CMake’s module target runs the same kbuild Makefile.

  1. Build with the new backend
  2. Load module on target hardware
  3. Verify cat /sys/kernel/debug/kdal/devices shows enumerated devices
  4. Test with kdality list and kdality info <device>
  5. Run write/read loopback verification
  • Backend ops fully implemented (no NULL function pointers)
  • Backend registered with unique name
  • enumerate() creates correctly typed kdal_device instances
  • Devices have backend pointer set before driver attachment
  • priv pointer holds per-device hardware state
  • Read/write ops handle partial transfers correctly
  • Error codes follow Linux kernel conventions (negative errno)
  • No platform-specific types in public headers
  • KUnit tests added for new backend
  • Documentation updated with platform notes

The QEMU backend (src/backends/qemu/qemubackend.c) serves as the reference implementation. It uses a software ring buffer to emulate hardware I/O:

  1. init() - logs and returns 0
  2. enumerate() - logs and returns 0: the example drivers create their own devices
  3. read()/write() - go through the device’s qemu_dev_ring (in priv) under its spinlock
  4. exit() - logs

The thesis board is the Orange Pi 6 Plus (CIX P1 SoC), planned for the end of 2026; the Radxa Orion O6 / O6N and Orange Pi 6 are reference variants of the same SoC (KDAL’s README, Target Platforms). The intended path is the generic backend: Device Tree enumeration and MMIO register access through the kernel’s platform_driver framework. KDAL does not yet run inside a HAVEN partition: that needs a Linux guest under HAVEN on the board.