css_mhu.c 2.22 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
 */

#include <arch_helpers.h>
8
#include <assert.h>
9
10
11
12
#include <bakery_lock.h>
#include <css_def.h>
#include <mmio.h>
#include <plat_arm.h>
13
#include <platform_def.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "css_mhu.h"

/* SCP MHU secure channel registers */
#define SCP_INTR_S_STAT		0x200
#define SCP_INTR_S_SET		0x208
#define SCP_INTR_S_CLEAR	0x210

/* CPU MHU secure channel registers */
#define CPU_INTR_S_STAT		0x300
#define CPU_INTR_S_SET		0x308
#define CPU_INTR_S_CLEAR	0x310

ARM_INSTANTIATE_LOCK

/* Weak definition may be overridden in specific CSS based platform */
#pragma weak plat_arm_pwrc_setup


32
33
34
35
36
37
38
39
/*
 * Slot 31 is reserved because the MHU hardware uses this register bit to
 * indicate a non-secure access attempt. The total number of available slots is
 * therefore 31 [30:0].
 */
#define MHU_MAX_SLOT_ID		30

void mhu_secure_message_start(unsigned int slot_id)
40
{
41
42
	assert(slot_id <= MHU_MAX_SLOT_ID);

43
44
45
	arm_lock_get();

	/* Make sure any previous command has finished */
46
47
	while (mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) &
							(1 << slot_id))
48
49
50
		;
}

51
void mhu_secure_message_send(unsigned int slot_id)
52
{
53
	assert(slot_id <= MHU_MAX_SLOT_ID);
54
55
	assert(!(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) &
							(1 << slot_id)));
56
57

	/* Send command to SCP */
58
	mmio_write_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_SET, 1 << slot_id);
59
60
61
62
63
64
}

uint32_t mhu_secure_message_wait(void)
{
	/* Wait for response from SCP */
	uint32_t response;
65
	while (!(response = mmio_read_32(PLAT_CSS_MHU_BASE + SCP_INTR_S_STAT)))
66
67
68
69
70
		;

	return response;
}

71
void mhu_secure_message_end(unsigned int slot_id)
72
{
73
74
	assert(slot_id <= MHU_MAX_SLOT_ID);

75
	/*
76
77
	 * Clear any response we got by writing one in the relevant slot bit to
	 * the CLEAR register
78
	 */
79
	mmio_write_32(PLAT_CSS_MHU_BASE + SCP_INTR_S_CLEAR, 1 << slot_id);
80
81
82
83
84
85
86
87
88

	arm_lock_release();
}

void mhu_secure_init(void)
{
	arm_lock_init();

	/*
89
90
91
	 * The STAT register resets to zero. Ensure it is in the expected state,
	 * as a stale or garbage value would make us think it's a message we've
	 * already sent.
92
	 */
93
	assert(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) == 0);
94
95
96
97
98
99
}

void plat_arm_pwrc_setup(void)
{
	mhu_secure_init();
}