blob: 04b13525b9cf5c8efdd9b8c3fea38d29525eb4e0 [file] [log] [blame]
Jonny Svärd9fc527b2020-11-16 16:18:07 +01001/*
Anton Moberge348f8f2021-03-31 11:08:58 +02002 * Copyright (c) 2020-2021 Arm Limited. All rights reserved.
Jonny Svärd9fc527b2020-11-16 16:18:07 +01003 *
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
27namespace Mailbox {
28
29MHUJuno::MHUJuno(const uint32_t baseAddress) {
30 baseAddr = reinterpret_cast<volatile uint32_t *>(baseAddress);
31}
32
33void MHUJuno::handleMessage() {
34 clearMessage();
35 notify();
36}
37
38MHUJuno::~MHUJuno() {}
39
40// Doorbell only
41bool MHUJuno::sendMessage() {
42 write(CPU1_INTR_SET, 1);
43 return true;
44}
45// Doorbell only
46void MHUJuno::clearMessage() {
47 write(CPU0_INTR_CLR, 0xF);
48}
49
50bool 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
68void MHUJuno::write(const uint32_t offset, const uint32_t value) {
69 write32(baseAddr, offset, value);
70}
71
72uint32_t MHUJuno::read(const uint32_t offset) {
73 return read32(baseAddr, offset);
74}
75
76} // namespace Mailbox