Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Samarth Parikh | a427785 | 2017-11-23 14:23:21 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame^] | 8 | |
Soby Mathew | b12a2b4 | 2016-10-21 11:34:59 +0100 | [diff] [blame] | 9 | #include <platform_def.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame^] | 10 | |
| 11 | #include <arch_helpers.h> |
| 12 | #include <lib/bakery_lock.h> |
| 13 | #include <lib/mmio.h> |
| 14 | |
| 15 | #include <css_def.h> |
| 16 | #include <plat_arm.h> |
| 17 | |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 18 | #include "css_mhu.h" |
| 19 | |
| 20 | /* SCP MHU secure channel registers */ |
| 21 | #define SCP_INTR_S_STAT 0x200 |
| 22 | #define SCP_INTR_S_SET 0x208 |
| 23 | #define SCP_INTR_S_CLEAR 0x210 |
| 24 | |
| 25 | /* CPU MHU secure channel registers */ |
| 26 | #define CPU_INTR_S_STAT 0x300 |
| 27 | #define CPU_INTR_S_SET 0x308 |
| 28 | #define CPU_INTR_S_CLEAR 0x310 |
| 29 | |
Jeenu Viswambharan | 1958316 | 2017-08-23 14:12:59 +0100 | [diff] [blame] | 30 | ARM_INSTANTIATE_LOCK; |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 31 | |
| 32 | /* Weak definition may be overridden in specific CSS based platform */ |
| 33 | #pragma weak plat_arm_pwrc_setup |
| 34 | |
| 35 | |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 36 | /* |
| 37 | * Slot 31 is reserved because the MHU hardware uses this register bit to |
| 38 | * indicate a non-secure access attempt. The total number of available slots is |
| 39 | * therefore 31 [30:0]. |
| 40 | */ |
| 41 | #define MHU_MAX_SLOT_ID 30 |
| 42 | |
| 43 | void mhu_secure_message_start(unsigned int slot_id) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 44 | { |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 45 | assert(slot_id <= MHU_MAX_SLOT_ID); |
| 46 | |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 47 | arm_lock_get(); |
| 48 | |
| 49 | /* Make sure any previous command has finished */ |
Vikram Kanigiri | ecf70f7 | 2016-01-21 14:08:15 +0000 | [diff] [blame] | 50 | while (mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) & |
| 51 | (1 << slot_id)) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 52 | ; |
| 53 | } |
| 54 | |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 55 | void mhu_secure_message_send(unsigned int slot_id) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 56 | { |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 57 | assert(slot_id <= MHU_MAX_SLOT_ID); |
Vikram Kanigiri | ecf70f7 | 2016-01-21 14:08:15 +0000 | [diff] [blame] | 58 | assert(!(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) & |
| 59 | (1 << slot_id))); |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 60 | |
| 61 | /* Send command to SCP */ |
Vikram Kanigiri | ecf70f7 | 2016-01-21 14:08:15 +0000 | [diff] [blame] | 62 | mmio_write_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_SET, 1 << slot_id); |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | uint32_t mhu_secure_message_wait(void) |
| 66 | { |
| 67 | /* Wait for response from SCP */ |
| 68 | uint32_t response; |
Vikram Kanigiri | ecf70f7 | 2016-01-21 14:08:15 +0000 | [diff] [blame] | 69 | while (!(response = mmio_read_32(PLAT_CSS_MHU_BASE + SCP_INTR_S_STAT))) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 70 | ; |
| 71 | |
| 72 | return response; |
| 73 | } |
| 74 | |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 75 | void mhu_secure_message_end(unsigned int slot_id) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 76 | { |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 77 | assert(slot_id <= MHU_MAX_SLOT_ID); |
| 78 | |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 79 | /* |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 80 | * Clear any response we got by writing one in the relevant slot bit to |
| 81 | * the CLEAR register |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 82 | */ |
Vikram Kanigiri | ecf70f7 | 2016-01-21 14:08:15 +0000 | [diff] [blame] | 83 | mmio_write_32(PLAT_CSS_MHU_BASE + SCP_INTR_S_CLEAR, 1 << slot_id); |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 84 | |
| 85 | arm_lock_release(); |
| 86 | } |
| 87 | |
Daniel Boulby | 4d010d0 | 2018-09-18 13:26:03 +0100 | [diff] [blame] | 88 | void __init mhu_secure_init(void) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 89 | { |
| 90 | arm_lock_init(); |
| 91 | |
| 92 | /* |
Sandrine Bailleux | e234ba0 | 2015-03-18 14:52:53 +0000 | [diff] [blame] | 93 | * The STAT register resets to zero. Ensure it is in the expected state, |
| 94 | * as a stale or garbage value would make us think it's a message we've |
| 95 | * already sent. |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 96 | */ |
Vikram Kanigiri | ecf70f7 | 2016-01-21 14:08:15 +0000 | [diff] [blame] | 97 | assert(mmio_read_32(PLAT_CSS_MHU_BASE + CPU_INTR_S_STAT) == 0); |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Daniel Boulby | 4d010d0 | 2018-09-18 13:26:03 +0100 | [diff] [blame] | 100 | void __init plat_arm_pwrc_setup(void) |
Dan Handley | b431530 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 101 | { |
| 102 | mhu_secure_init(); |
| 103 | } |