Jonny Svärd | 9fc527b | 2020-11-16 16:18:07 +0100 | [diff] [blame] | 1 | /* |
Anton Moberg | e348f8f | 2021-03-31 11:08:58 +0200 | [diff] [blame] | 2 | * Copyright (c) 2020-2021 Arm Limited. All rights reserved. |
Jonny Svärd | 9fc527b | 2020-11-16 16:18:07 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | * not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <mhu_juno.hpp> |
| 20 | |
| 21 | #include <cassert> |
| 22 | #include <cstddef> |
| 23 | #include <cstdint> |
| 24 | #include <cstdio> |
| 25 | #include <cstring> |
| 26 | |
| 27 | namespace Mailbox { |
| 28 | |
| 29 | MHUJuno::MHUJuno(const uint32_t baseAddress) { |
| 30 | baseAddr = reinterpret_cast<volatile uint32_t *>(baseAddress); |
| 31 | } |
| 32 | |
| 33 | void MHUJuno::handleMessage() { |
| 34 | clearMessage(); |
| 35 | notify(); |
| 36 | } |
| 37 | |
| 38 | MHUJuno::~MHUJuno() {} |
| 39 | |
| 40 | // Doorbell only |
| 41 | bool MHUJuno::sendMessage() { |
| 42 | write(CPU1_INTR_SET, 1); |
| 43 | return true; |
| 44 | } |
| 45 | // Doorbell only |
| 46 | void MHUJuno::clearMessage() { |
| 47 | write(CPU0_INTR_CLR, 0xF); |
| 48 | } |
| 49 | |
| 50 | bool MHUJuno::verifyHardware() { |
| 51 | uint32_t pidr0 = read(PIDR0); |
| 52 | uint32_t pidr1 = read(PIDR1); |
| 53 | uint32_t pidr2 = read(PIDR2); |
| 54 | uint32_t pidr3 = read(PIDR3); |
| 55 | uint32_t pidr4 = read(PIDR4); |
| 56 | uint32_t cidr0 = read(CIDR0); |
| 57 | uint32_t cidr1 = read(CIDR1); |
| 58 | uint32_t cidr2 = read(CIDR2); |
| 59 | uint32_t cidr3 = read(CIDR3); |
| 60 | |
| 61 | if (pidr0 != 0x56 || pidr1 != 0xb8 || pidr2 != 0x0b || pidr3 != 0x00 || pidr4 != 0x04 || cidr0 != 0x0d || |
| 62 | cidr1 != 0xf0 || cidr2 != 0x05 || cidr3 != 0xb1) { |
| 63 | return false; |
| 64 | } |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | void MHUJuno::write(const uint32_t offset, const uint32_t value) { |
| 69 | write32(baseAddr, offset, value); |
| 70 | } |
| 71 | |
| 72 | uint32_t MHUJuno::read(const uint32_t offset) { |
| 73 | return read32(baseAddr, offset); |
| 74 | } |
| 75 | |
| 76 | } // namespace Mailbox |