sg: add sg_list
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
105bdb4464
commit
1620f28e71
1 changed files with 26 additions and 0 deletions
26
kernel/sg.c
Normal file
26
kernel/sg.c
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue