File: rstctrl.c

package info (click to toggle)
optee-os 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,960 kB
  • sloc: ansic: 444,388; asm: 12,922; python: 3,719; makefile: 1,681; sh: 238
file content (50 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download | duplicates (2)
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);
}