blob: 2fd064d57cda996a4f75866828fe2b9e6bc50ee0 [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
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000011#include <stddef.h>
12
13#include "hf/spinlock.h"
14
15struct mpool {
16 struct spinlock lock;
17 size_t entry_size;
18 struct mpool_chunk *chunk_list;
19 struct mpool_entry *entry_list;
Andrew Scull63d1f3f2018-12-06 13:29:10 +000020 struct mpool *fallback;
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000021};
22
23void mpool_enable_locks(void);
24void mpool_init(struct mpool *p, size_t entry_size);
25void mpool_init_from(struct mpool *p, struct mpool *from);
Andrew Scull63d1f3f2018-12-06 13:29:10 +000026void mpool_init_with_fallback(struct mpool *p, struct mpool *fallback);
27void mpool_fini(struct mpool *p);
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000028bool mpool_add_chunk(struct mpool *p, void *begin, size_t size);
29void *mpool_alloc(struct mpool *p);
30void *mpool_alloc_contiguous(struct mpool *p, size_t count, size_t align);
31void mpool_free(struct mpool *p, void *ptr);