1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2021, Linaro Limited
*/
#include <assert.h>
#include <drivers/rstctrl.h>
#include <io.h>
#include <kernel/spinlock.h>
#include <libfdt.h>
#include <stdint.h>
/* Global reset controller access lock */
TEE_Result rstctrl_get_exclusive(struct rstctrl *rstctrl)
{
uint32_t exceptions = 0;
TEE_Result res = TEE_ERROR_ACCESS_CONFLICT;
static unsigned int rstctrl_lock = SPINLOCK_UNLOCK;
exceptions = cpu_spin_lock_xsave(&rstctrl_lock);
if (!rstctrl->exclusive) {
rstctrl->exclusive = true;
res = TEE_SUCCESS;
}
cpu_spin_unlock_xrestore(&rstctrl_lock, exceptions);
return res;
}
void rstctrl_put_exclusive(struct rstctrl *rstctrl)
{
assert(rstctrl->exclusive);
WRITE_ONCE(rstctrl->exclusive, false);
}
TEE_Result rstctrl_dt_get_by_name(const void *fdt, int nodeoffset,
const char *name, struct rstctrl **rstctrl)
{
int index = 0;
index = fdt_stringlist_search(fdt, nodeoffset, "reset-names", name);
if (index < 0)
return TEE_ERROR_ITEM_NOT_FOUND;
return rstctrl_dt_get_by_index(fdt, nodeoffset, index, rstctrl);
}
|