blob: b6541a8873e8cc8ca95aead4adbf50413a7c2cd6 [file] [log] [blame]
Sandrine Bailleux798140d2014-07-17 16:06:39 +01001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch_helpers.h>
32#include <bakery_lock.h>
33#include <mmio.h>
34#include "juno_def.h"
35#include "mhu.h"
36
37/* SCP MHU secure channel registers */
38#define SCP_INTR_S_STAT 0x200
39#define SCP_INTR_S_SET 0x208
40#define SCP_INTR_S_CLEAR 0x210
41
42/* CPU MHU secure channel registers */
43#define CPU_INTR_S_STAT 0x300
44#define CPU_INTR_S_SET 0x308
45#define CPU_INTR_S_CLEAR 0x310
46
47
48static bakery_lock_t mhu_secure_lock __attribute__ ((section("tzfw_coherent_mem")));
49
50
51void mhu_secure_message_start(void)
52{
53 bakery_lock_get(&mhu_secure_lock);
54
55 /* Make sure any previous command has finished */
56 while (mmio_read_32(MHU_BASE + CPU_INTR_S_STAT) != 0)
57 ;
58}
59
60void mhu_secure_message_send(uint32_t command)
61{
62 /* Send command to SCP and wait for it to pick it up */
63 mmio_write_32(MHU_BASE + CPU_INTR_S_SET, command);
64 while (mmio_read_32(MHU_BASE + CPU_INTR_S_STAT) != 0)
65 ;
66}
67
68uint32_t mhu_secure_message_wait(void)
69{
70 /* Wait for response from SCP */
71 uint32_t response;
72 while (!(response = mmio_read_32(MHU_BASE + SCP_INTR_S_STAT)))
73 ;
74
75 return response;
76}
77
78void mhu_secure_message_end(void)
79{
80 /* Clear any response we got by writing all ones to the CLEAR register */
81 mmio_write_32(MHU_BASE + SCP_INTR_S_CLEAR, 0xffffffffu);
82
83 bakery_lock_release(&mhu_secure_lock);
84}
85
86void mhu_secure_init(void)
87{
88 bakery_lock_init(&mhu_secure_lock);
89
90 /*
91 * Clear the CPU's INTR register to make sure we don't see a stale
92 * or garbage value and think it's a message we've already sent.
93 */
94 mmio_write_32(MHU_BASE + CPU_INTR_S_CLEAR, 0xffffffffu);
95}