Last change
on this file since 39916d6 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago |
Replace some license headers with SPDX identifier
Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.
|
-
Property mode
set to
100644
|
File size:
971 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * SPDX-FileCopyrightText: 2006 Jakub Jermar
|
---|
3 | *
|
---|
4 | * SPDX-License-Identifier: BSD-3-Clause
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <balloc.h>
|
---|
8 | #include <stdalign.h>
|
---|
9 | #include <stddef.h>
|
---|
10 | #include <align.h>
|
---|
11 |
|
---|
12 | static ballocs_t *ballocs;
|
---|
13 | static uintptr_t phys_base;
|
---|
14 | static size_t max_size;
|
---|
15 |
|
---|
16 | void balloc_init(ballocs_t *ball, void *base, uintptr_t kernel_base,
|
---|
17 | size_t size)
|
---|
18 | {
|
---|
19 | ballocs = ball;
|
---|
20 | phys_base = (uintptr_t) base;
|
---|
21 | max_size = size;
|
---|
22 | ballocs->base = kernel_base;
|
---|
23 | ballocs->size = 0;
|
---|
24 | }
|
---|
25 |
|
---|
26 | void *balloc(size_t size, size_t alignment)
|
---|
27 | {
|
---|
28 | if (alignment == 0)
|
---|
29 | return NULL;
|
---|
30 |
|
---|
31 | /* Enforce minimal alignment. */
|
---|
32 | alignment = ALIGN_UP(alignment, alignof(max_align_t));
|
---|
33 |
|
---|
34 | uintptr_t addr = phys_base + ALIGN_UP(ballocs->size, alignment);
|
---|
35 |
|
---|
36 | if (ALIGN_UP(ballocs->size, alignment) + size >= max_size)
|
---|
37 | return NULL;
|
---|
38 |
|
---|
39 | ballocs->size = ALIGN_UP(ballocs->size, alignment) + size;
|
---|
40 |
|
---|
41 | return (void *) addr;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void *balloc_rebase(void *ptr)
|
---|
45 | {
|
---|
46 | return (void *) (((uintptr_t) ptr - phys_base) + ballocs->base);
|
---|
47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.