ardix/kernel/dma.c

65 lines
1.4 KiB
C
Raw Normal View History

/* See the end of this file for copyright, license, and warranty information. */
2021-02-03 04:30:46 +01:00
#include <ardix/device.h>
#include <ardix/dma.h>
#include <ardix/kent.h>
#include <ardix/malloc.h>
#include <ardix/types.h>
#include <ardix/util.h>
#include <stddef.h>
static void dmabuf_destroy(struct kent *kent)
{
struct dmabuf *buf = kent_to_dmabuf(kent);
kfree(buf);
2021-02-03 04:30:46 +01:00
}
struct dmabuf *dmabuf_create(struct device *dev, size_t len)
{
int err = 0;
2021-08-10 18:07:55 +02:00
/*
* allocation needs to be atomic because the buffer might be
* free()d from within an irq handler which cannot sleep
*/
struct dmabuf *buf = atomic_kmalloc(sizeof(*buf) + len);
2021-02-03 04:30:46 +01:00
if (buf == NULL)
return NULL;
buf->kent.parent = &dev->kent;
2021-07-31 15:58:29 +02:00
buf->kent.destroy = dmabuf_destroy;
2021-02-03 04:30:46 +01:00
err = kent_init(&buf->kent);
if (err) {
kfree(buf);
2021-02-03 04:30:46 +01:00
return NULL;
}
buf->len = len;
return buf;
}
void dmabuf_get(struct dmabuf *buf)
{
kent_get(&buf->kent);
}
void dmabuf_put(struct dmabuf *buf)
{
kent_put(&buf->kent);
}
/*
* This file is part of Ardix.
* Copyright (c) 2020, 2021 Felix Kopp <owo@fef.moe>.
2021-02-03 04:30:46 +01:00
*
* Ardix is non-violent software: you may only use, redistribute,
* and/or modify it under the terms of the CNPLv6+ as found in
* the LICENSE file in the source code root directory or at
* <https://git.pixie.town/thufie/CNPL>.
2021-02-03 04:30:46 +01:00
*
* Ardix comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPLv6+ for details.
2021-02-03 04:30:46 +01:00
*/