xref: /aosp_15_r20/external/OpenCSD/decoder/include/mem_acc/trc_mem_acc_mapper.h (revision 02ca8ccacfba7e0df68f3332a95f3180334d6649)
1 /*
2  * \file       trc_mem_acc_mapper.h
3  * \brief      OpenCSD :
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 /*
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ARM_TRC_MEM_ACC_MAPPER_H_INCLUDED
36 #define ARM_TRC_MEM_ACC_MAPPER_H_INCLUDED
37 
38 #include <vector>
39 
40 #include "opencsd/ocsd_if_types.h"
41 #include "interfaces/trc_tgt_mem_access_i.h"
42 #include "interfaces/trc_error_log_i.h"
43 #include "mem_acc/trc_mem_acc_base.h"
44 #include "mem_acc/trc_mem_acc_cache.h"
45 
46 typedef enum _memacc_mapper_t {
47     MEMACC_MAP_GLOBAL,
48 } memacc_mapper_t;
49 
50 class TrcMemAccMapper : public ITargetMemAccess
51 {
52 public:
53     TrcMemAccMapper();
54     TrcMemAccMapper(bool using_trace_id);
55     virtual ~TrcMemAccMapper();
56 
57 // decoder memory access interface
58     virtual ocsd_err_t ReadTargetMemory(   const ocsd_vaddr_t address,
59                                             const uint8_t cs_trace_id,
60                                             const ocsd_mem_space_acc_t mem_space,
61                                             uint32_t *num_bytes,
62                                             uint8_t *p_buffer);
63 
64     virtual void InvalidateMemAccCache(const uint8_t cs_trace_id);
65 
66 // mapper memory area configuration interface
67 
68     // add an accessor to this map
69     virtual ocsd_err_t AddAccessor(TrcMemAccessorBase *p_accessor, const uint8_t cs_trace_id) = 0;
70 
71     // remove a specific accessor
72     virtual ocsd_err_t RemoveAccessor(const TrcMemAccessorBase *p_accessor) = 0;
73 
74 
75     // clear all attached accessors from the map
76     void RemoveAllAccessors();
77 
78     // remove a single accessor based on address.
79     ocsd_err_t RemoveAccessorByAddress(const ocsd_vaddr_t st_address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id = 0);
80 
81     // set the error log.
82     void setErrorLog(ITraceErrorLog *err_log_i);
83 
84     // print out the ranges in this mapper.
85     virtual void logMappedRanges() = 0;
86 
87     // control memory access caching at runtime
88     ocsd_err_t enableCaching(bool bEnable);
89 
90     // set cache page size and number of pages (max 16k size, 256 pages) -
91     // optionally error if outside limits - otherwise set to max / min automatically
92     ocsd_err_t setCacheSizes(uint16_t page_size, int num_pages, const bool err_on_limit = false);
93 
94 protected:
95     virtual bool findAccessor(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id) = 0;     // set m_acc_curr if found valid range, leave unchanged if not.
96     virtual bool readFromCurrent(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id) = 0;
97     virtual TrcMemAccessorBase *getFirstAccessor() = 0;
98     virtual TrcMemAccessorBase *getNextAccessor() = 0;
99     virtual void clearAccessorList() = 0;
100 
101     void LogMessage(const std::string &msg);
102     void LogWarn(const ocsd_err_t err, const std::string &msg);
103 
104     TrcMemAccessorBase *m_acc_curr;     // most recently used - try this first.
105     uint8_t m_trace_id_curr;            // trace ID for the current accessor
106     const bool m_using_trace_id;        // true if we are using separate memory spaces by TraceID.
107     ITraceErrorLog *m_err_log;          // error log to print out mappings on request.
108     TrcMemAccCache m_cache;             // memory accessor caching.
109 };
110 
111 
112 // address spaces common to all sources using this mapper.
113 // trace id unused when differentiating accessors - may be used by underlying read operations.
114 class TrcMemAccMapGlobalSpace : public TrcMemAccMapper
115 {
116 public:
117     TrcMemAccMapGlobalSpace();
118     virtual ~TrcMemAccMapGlobalSpace();
119 
120     // mapper creation interface - prevent overlaps
121     virtual ocsd_err_t AddAccessor(TrcMemAccessorBase *p_accessor, const uint8_t cs_trace_id);
122 
123     // print out the ranges in this mapper.
124     virtual void logMappedRanges();
125 
126 protected:
127     virtual bool findAccessor(const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t cs_trace_id);
128     virtual bool readFromCurrent(const ocsd_vaddr_t address,const ocsd_mem_space_acc_t mem_space,  const uint8_t cs_trace_id);
129     virtual TrcMemAccessorBase *getFirstAccessor();
130     virtual TrcMemAccessorBase *getNextAccessor();
131     virtual void clearAccessorList();
132     virtual ocsd_err_t RemoveAccessor(const TrcMemAccessorBase *p_accessor);
133 
134     std::vector<TrcMemAccessorBase *> m_acc_global;
135     std::vector<TrcMemAccessorBase *>::iterator m_acc_it;
136 };
137 
138 #endif // ARM_TRC_MEM_ACC_MAPPER_H_INCLUDED
139 
140 /* End of File trc_mem_acc_mapper.h */
141