blob: 465503e7b90239e98fc0476a8fdb41c55874ce7f [file] [log] [blame]
Jonny Svärd44398c82020-10-06 14:18:28 +02001/*
2 * Copyright (c) 2020 Arm Limited. All rights reserved.
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#ifndef MAILBOX_HPP
20#define MAILBOX_HPP
21
Jonny Svärd44398c82020-10-06 14:18:28 +020022#include <cstddef>
Kristofer Jonsson73ebc482020-10-12 11:17:04 +020023#include <cstdint>
Jonny Svärd44398c82020-10-06 14:18:28 +020024#include <list>
25
26namespace Mailbox {
27
28class Mailbox {
29public:
30 Mailbox();
31 virtual ~Mailbox();
Kristofer Jonsson73ebc482020-10-12 11:17:04 +020032 virtual bool sendMessage() = 0;
Jonny Svärd44398c82020-10-06 14:18:28 +020033 virtual void handleMessage() = 0;
34 virtual bool verifyHardware();
35 typedef void (*CallbackFptr)(void *userArg);
36 void registerCallback(CallbackFptr callback, void *userArg);
37 void deregisterCallback(CallbackFptr callback, void *userArg);
38
39protected:
40 void notify();
41 uint32_t read32(volatile uint32_t *baseAddr, const uint32_t offset);
42 void write32(volatile uint32_t *baseAddr, const uint32_t offset, const uint32_t value);
43
44private:
45 struct Callback {
46 bool operator==(const Callback &b) const;
47 CallbackFptr callback;
48 void *userArg;
49 };
50
51 std::list<Callback> callbacks;
52};
53
54} // namespace Mailbox
55
56#endif