2021-02-28 02:18:39 +01:00
|
|
|
/* 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)
|
|
|
|
{
|
2021-02-28 01:28:07 +01:00
|
|
|
struct dmabuf *buf = kent_to_dmabuf(kent);
|
2021-02-03 04:30:46 +01:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dmabuf *dmabuf_create(struct device *dev, size_t len)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct dmabuf *buf = malloc(sizeof(*buf) + len);
|
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2021-02-28 01:28:07 +01:00
|
|
|
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
|
|
|
|
2021-02-28 01:28:07 +01:00
|
|
|
err = kent_init(&buf->kent);
|
|
|
|
if (err) {
|
2021-02-03 04:30:46 +01:00
|
|
|
free(buf);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-02-28 02:18:39 +01:00
|
|
|
* This file is part of Ardix.
|
|
|
|
* Copyright (c) 2020, 2021 Felix Kopp <owo@fef.moe>.
|
2021-02-03 04:30:46 +01:00
|
|
|
*
|
2021-05-10 16:19:38 +02: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
|
|
|
*
|
2021-05-10 16:19:38 +02: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
|
|
|
*/
|