blob: e5950f0711ba706a9cb16bf428bea72837cbf71c [file] [log] [blame]
Jonny Svärd44398c82020-10-06 14:18:28 +02001/*
Anton Moberge348f8f2021-03-31 11:08:58 +02002 * Copyright (c) 2020-2021 Arm Limited. All rights reserved.
Jonny Svärd44398c82020-10-06 14:18:28 +02003 *
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 <mailbox.hpp>
20
Jonny Svärd44398c82020-10-06 14:18:28 +020021#include <cassert>
Kristofer Jonsson73ebc482020-10-12 11:17:04 +020022#include <cstddef>
Jonny Svärd44398c82020-10-06 14:18:28 +020023
24namespace Mailbox {
25
26Mailbox::Mailbox() {}
27Mailbox::~Mailbox() {}
28
29bool Mailbox::verifyHardware() {
30 return true;
31}
32
33void Mailbox::registerCallback(CallbackFptr callback, void *userArg) {
34 callbacks.push_back({callback, userArg});
35}
36
37void Mailbox::deregisterCallback(CallbackFptr callback, void *userArg) {
38 callbacks.remove({callback, userArg});
39}
40
41void Mailbox::notify() {
42 for (auto &it : callbacks) {
43 it.callback(it.userArg);
44 }
45}
46
47uint32_t Mailbox::read32(volatile uint32_t *baseAddr, const uint32_t offset) {
48 assert(offset % 4 == 0);
49 volatile uint32_t *addr = baseAddr + (offset / 4);
50
51 return *addr;
52}
53
54void Mailbox::write32(volatile uint32_t *baseAddr, const uint32_t offset, const uint32_t value) {
55 assert(offset % 4 == 0);
56 volatile uint32_t *addr = baseAddr + (offset / 4);
57
58 *addr = value;
59}
60
61bool Mailbox::Callback::operator==(const Callback &b) const {
62 return (callback == b.callback && userArg == b.userArg);
63}
64
65} // namespace Mailbox