mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
lib: Move sbi core library to lib/sbi
Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
59
lib/sbi/sbi_scratch.c
Normal file
59
lib/sbi/sbi_scratch.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_locks.h>
|
||||
#include <sbi/sbi_scratch.h>
|
||||
|
||||
static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER;
|
||||
static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET;
|
||||
|
||||
unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
|
||||
/*
|
||||
* We have a simple brain-dead allocator which never expects
|
||||
* anything to be free-ed hence it keeps incrementing the
|
||||
* next allocation offset until it runs-out of space.
|
||||
*
|
||||
* In future, we will have more sophisticated allocator which
|
||||
* will allow us to re-claim free-ed space.
|
||||
*/
|
||||
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
while (size & (__SIZEOF_POINTER__ - 1))
|
||||
size++;
|
||||
|
||||
spin_lock(&extra_lock);
|
||||
|
||||
if (SBI_SCRATCH_SIZE < (extra_offset + size))
|
||||
goto done;
|
||||
|
||||
ret = extra_offset;
|
||||
extra_offset += size;
|
||||
|
||||
done:
|
||||
spin_unlock(&extra_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void sbi_scratch_free_offset(unsigned long offset)
|
||||
{
|
||||
if ((offset < SBI_SCRATCH_EXTRA_SPACE_OFFSET) ||
|
||||
(SBI_SCRATCH_SIZE <= offset))
|
||||
return;
|
||||
|
||||
/*
|
||||
* We don't actually free-up because it's a simple
|
||||
* brain-dead allocator.
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user