sg: add sg_list

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-14 19:03:34 -04:00
commit 1620f28e71

26
kernel/sg.c Normal file
View file

@ -0,0 +1,26 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <kernel/sg.h>
void sg_init(struct sg_list *sg, struct sg_entry *buf, size_t n)
{
sg->entries = buf;
sg->count = 0;
sg->max_count = n;
}
int sg_append(struct sg_list *sg, paddr_t paddr, size_t len)
{
if (sg->count >= sg->max_count)
return -ENOSPC;
sg->entries[sg->count].paddr = paddr;
sg->entries[sg->count].len = len;
sg->count++;
return 0;
}
void sg_reset(struct sg_list *sg)
{
sg->count = 0;
}