blob: b7faf7ed9e8b87cb149a22f22f4257193308ec8a [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Samarth Parikh59cfa132017-11-23 14:23:21 +05302 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6
Sandrine Bailleux04b66d82015-03-18 14:52:53 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <platform_def.h>
10
11#include <arch_helpers.h>
Antonio Nino Diaz1b0c6f12019-01-23 21:08:43 +000012#include <drivers/arm/css/css_mhu.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/bakery_lock.h>
14#include <lib/mmio.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000015#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016
Dan Handley9df48042015-03-19 18:58:55 +000017/* SCP MHU secure channel registers */
18#define SCP_INTR_S_STAT 0x200
19#define SCP_INTR_S_SET 0x208
20#define SCP_INTR_S_CLEAR 0x210
21
22/* CPU MHU secure channel registers */
23#define CPU_INTR_S_STAT 0x300
24#define CPU_INTR_S_SET 0x308
25#define CPU_INTR_S_CLEAR 0x310
26
Jeenu Viswambharan749d25b2017-08-23 14:12:59 +010027ARM_INSTANTIATE_LOCK;
Dan Handley9df48042015-03-19 18:58:55 +000028
29/* Weak definition may be overridden in specific CSS based platform */
30#pragma weak plat_arm_pwrc_setup
31
32
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000033/*
34 * Slot 31 is reserved because the MHU hardware uses this register bit to
35 * indicate a non-secure access attempt. The total number of available slots is
36 * therefore 31 [30:0].
37 */
38#define MHU_MAX_SLOT_ID 30
39
40void mhu_secure_message_start(unsigned int slot_id)
Dan Handley9df48042015-03-19 18:58:55 +000041{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000042 assert(slot_id <= MHU_MAX_SLOT_ID);
43
Dan Handley9df48042015-03-19 18:58:55 +000044 arm_lock_get();
45
46 /* Make sure any previous command has finished */
Vikram Kanigiri5d86f2e2016-01-21 14:08:15 +000047 while (mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) &
48 (1 << slot_id))
Dan Handley9df48042015-03-19 18:58:55 +000049 ;
50}
51
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000052void mhu_secure_message_send(unsigned int slot_id)
Dan Handley9df48042015-03-19 18:58:55 +000053{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000054 assert(slot_id <= MHU_MAX_SLOT_ID);
Vikram Kanigiri5d86f2e2016-01-21 14:08:15 +000055 assert(!(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) &
56 (1 << slot_id)));
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000057
58 /* Send command to SCP */
Vikram Kanigiri5d86f2e2016-01-21 14:08:15 +000059 mmio_write_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_SET, 1 << slot_id);
Dan Handley9df48042015-03-19 18:58:55 +000060}
61
62uint32_t mhu_secure_message_wait(void)
63{
64 /* Wait for response from SCP */
65 uint32_t response;
Vikram Kanigiri5d86f2e2016-01-21 14:08:15 +000066 while (!(response = mmio_read_32(PLAT_CSS_MHU_BASE + SCP_INTR_S_STAT)))
Dan Handley9df48042015-03-19 18:58:55 +000067 ;
68
69 return response;
70}
71
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000072void mhu_secure_message_end(unsigned int slot_id)
Dan Handley9df48042015-03-19 18:58:55 +000073{
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000074 assert(slot_id <= MHU_MAX_SLOT_ID);
75
Dan Handley9df48042015-03-19 18:58:55 +000076 /*
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000077 * Clear any response we got by writing one in the relevant slot bit to
78 * the CLEAR register
Dan Handley9df48042015-03-19 18:58:55 +000079 */
Vikram Kanigiri5d86f2e2016-01-21 14:08:15 +000080 mmio_write_32(PLAT_CSS_MHU_BASE + SCP_INTR_S_CLEAR, 1 << slot_id);
Dan Handley9df48042015-03-19 18:58:55 +000081
82 arm_lock_release();
83}
84
Daniel Boulbyf45a4bb2018-09-18 13:26:03 +010085void __init mhu_secure_init(void)
Dan Handley9df48042015-03-19 18:58:55 +000086{
87 arm_lock_init();
88
89 /*
Sandrine Bailleux04b66d82015-03-18 14:52:53 +000090 * The STAT register resets to zero. Ensure it is in the expected state,
91 * as a stale or garbage value would make us think it's a message we've
92 * already sent.
Dan Handley9df48042015-03-19 18:58:55 +000093 */
Vikram Kanigiri5d86f2e2016-01-21 14:08:15 +000094 assert(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) == 0);
Dan Handley9df48042015-03-19 18:58:55 +000095}
96
Daniel Boulbyf45a4bb2018-09-18 13:26:03 +010097void __init plat_arm_pwrc_setup(void)
Dan Handley9df48042015-03-19 18:58:55 +000098{
99 mhu_secure_init();
100}