soc/amd/common/block/lpc: Use standard pci_dev_ops_pci
[coreboot.git] / src / commonlib / mem_pool.c
blob39bfe71cda7a8b187090d597c3b9e1b10a55f0c0
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* This file is part of the coreboot project. */
4 #include <commonlib/helpers.h>
5 #include <commonlib/mem_pool.h>
7 void *mem_pool_alloc(struct mem_pool *mp, size_t sz)
9 void *p;
11 /* Make all allocations be at least 8 byte aligned. */
12 sz = ALIGN_UP(sz, 8);
14 /* Determine if any space available. */
15 if ((mp->size - mp->free_offset) < sz)
16 return NULL;
18 p = &mp->buf[mp->free_offset];
20 mp->free_offset += sz;
21 mp->last_alloc = p;
23 return p;
26 void mem_pool_free(struct mem_pool *mp, void *p)
28 /* Determine if p was the most recent allocation. */
29 if (p == NULL || mp->last_alloc != p)
30 return;
32 mp->free_offset = mp->last_alloc - mp->buf;
33 /* No way to track allocation before this one. */
34 mp->last_alloc = NULL;