css_mhu.c 2.25 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

#include <platform_def.h>

#include <arch_helpers.h>
12
#include <drivers/arm/css/css_mhu.h>
13
14
#include <lib/bakery_lock.h>
#include <lib/mmio.h>
15
#include <plat/arm/common/plat_arm.h>
16

17
18
19
20
21
22
23
24
25
26
/* 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

27
ARM_INSTANTIATE_LOCK;
28
29
30
31
32

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


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

44
45
46
	arm_lock_get();

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

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

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

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

	return response;
}

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

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

	arm_lock_release();
}

85
void __init mhu_secure_init(void)
86
87
88
89
{
	arm_lock_init();

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

97
void __init plat_arm_pwrc_setup(void)
98
99
100
{
	mhu_secure_init();
}