quic/qbox
Loading...
Searching...
No Matches
exclusive-access.h
1/*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _GREENSOCS_GSUTILS_TLM_EXTENSIONS_EXCLUSIVE_ACCESS_H
9#define _GREENSOCS_GSUTILS_TLM_EXTENSIONS_EXCLUSIVE_ACCESS_H
10
11#include <vector>
12
13#include <tlm>
14
35class ExclusiveAccessTlmExtension : public tlm::tlm_extension<ExclusiveAccessTlmExtension>
36{
37public:
38 enum ExclusiveStoreStatus { EXCLUSIVE_STORE_NA = 0, EXCLUSIVE_STORE_SUCCESS, EXCLUSIVE_STORE_FAILURE };
39
41 {
42 private:
43 std::vector<int> m_id;
44
45 public:
46 void add_hop(int id) { m_id.push_back(id); }
47
48 bool operator<(const InitiatorId& o) const
49 {
50 if (m_id.size() != o.m_id.size()) {
51 return m_id.size() < o.m_id.size();
52 }
53
54 auto it0 = m_id.begin();
55 auto it1 = o.m_id.begin();
56 for (; it0 != m_id.end(); it0++, it1++) {
57 if (*it0 != *it1) {
58 return *it0 < *it1;
59 }
60 }
61
62 return false;
63 }
64
65 bool operator==(const InitiatorId& o) const
66 {
67 if (m_id.size() != o.m_id.size()) {
68 return false;
69 }
70
71 auto it0 = m_id.begin();
72 auto it1 = o.m_id.begin();
73 for (; it0 != m_id.end(); it0++, it1++) {
74 if (*it0 != *it1) {
75 return false;
76 }
77 }
78
79 return true;
80 }
81
82 bool operator!=(const InitiatorId& o) const { return !(*this == o); }
83 };
84
85private:
86 InitiatorId m_id;
87 ExclusiveStoreStatus m_store_sta = EXCLUSIVE_STORE_NA;
88
89public:
92
93 virtual tlm_extension_base* clone() const override { return new ExclusiveAccessTlmExtension(*this); }
94
95 virtual void copy_from(const tlm_extension_base& ext) override
96 {
98
99 m_id = other.m_id;
100 m_store_sta = other.m_store_sta;
101 }
102
103 void set_exclusive_store_success() { m_store_sta = EXCLUSIVE_STORE_SUCCESS; }
104
105 void set_exclusive_store_failure() { m_store_sta = EXCLUSIVE_STORE_FAILURE; }
106
107 ExclusiveStoreStatus get_exclusive_store_status() const { return m_store_sta; }
108
109 void add_hop(int id) { m_id.add_hop(id); }
110
111 const InitiatorId& get_initiator_id() const { return m_id; }
112};
113
114#endif
Definition exclusive-access.h:41
Exclusive load/store TLM extension.
Definition exclusive-access.h:36
Definition target.h:160