css_mhu.c 2.22 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2018, 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 <assert.h>
8
9
10
11
12
13
14

#include <platform_def.h>

#include <arch_helpers.h>
#include <lib/bakery_lock.h>
#include <lib/mmio.h>

15
#include <plat_arm.h>
16

17
18
19
20
21
22
23
24
25
26
27
28
#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

29
ARM_INSTANTIATE_LOCK;
30
31
32
33
34

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


35
36
37
38
39
40
41
42
/*
 * 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)
43
{
44
45
	assert(slot_id <= MHU_MAX_SLOT_ID);

46
47
48
	arm_lock_get();

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

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

	/* Send command to SCP */
61
	mmio_write_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_SET, 1 << slot_id);
62
63
64
65
66
67
}

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

	return response;
}

74
void mhu_secure_message_end(unsigned int slot_id)
75
{
76
77
	assert(slot_id <= MHU_MAX_SLOT_ID);

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

	arm_lock_release();
}

87
void __init mhu_secure_init(void)
88
89
90
91
{
	arm_lock_init();

	/*
92
93
94
	 * 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.
95
	 */
96
	assert(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) == 0);
97
98
}

99
void __init plat_arm_pwrc_setup(void)
100
101
102
{
	mhu_secure_init();
}