blob: 7b07072789632346022564654ec03cb55cafee74 [file] [log] [blame]
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +00001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +00003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +00007 */
8
9#pragma once
10
11#include <stdbool.h>
12#include <stddef.h>
13
14#include "hf/spinlock.h"
15
16struct mpool {
17 struct spinlock lock;
18 size_t entry_size;
19 struct mpool_chunk *chunk_list;
20 struct mpool_entry *entry_list;
Andrew Scull63d1f3f2018-12-06 13:29:10 +000021 struct mpool *fallback;
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000022};
23
24void mpool_enable_locks(void);
25void mpool_init(struct mpool *p, size_t entry_size);
26void mpool_init_from(struct mpool *p, struct mpool *from);
Andrew Scull63d1f3f2018-12-06 13:29:10 +000027void mpool_init_with_fallback(struct mpool *p, struct mpool *fallback);
28void mpool_fini(struct mpool *p);
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000029bool mpool_add_chunk(struct mpool *p, void *begin, size_t size);
30void *mpool_alloc(struct mpool *p);
31void *mpool_alloc_contiguous(struct mpool *p, size_t count, size_t align);
32void mpool_free(struct mpool *p, void *ptr);