summaryrefslogtreecommitdiffstats
path: root/src/sbefw/sbeMemAccessInterface.H
blob: b0ec3067f0eaa08758d7af517e9e384832e0824e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/sbefw/sbeMemAccessInterface.H $                           */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2017                        */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __SBE_MEM_ACCESS_INTERFACE_H
#define __SBE_MEM_ACCESS_INTERFACE_H

#include "fapi2.H"

#include "p9_pba_coherent_utils.H"
#include "p9_pba_setup.H"
#include "p9_pba_access.H"

#include "p9_adu_setup.H"
#include "p9_adu_access.H"
#include "p9_adu_coherent_utils.H"

constexpr uint32_t PBA_GRANULE_SIZE_BYTES = 128;
constexpr uint32_t ADU_GRANULE_SIZE_BYTES  = 8;

/* @brief Enum for read or write interface
 * */
enum sbeMemAccessMode
{
    SBE_MEM_ACCESS_READ = 1,
    SBE_MEM_ACCESS_WRITE = 2,
};

/* @brief Enum for PBA or ADU interface
 * */
enum sbeMemAccessInterfaceType
{
    SBE_MEM_ACCESS_PBA,
    SBE_MEM_ACCESS_ADU,
};

class sbeMemAccessInterface
{
    private:
        // Address to start read/write from
        uint64_t iv_addr;
        // Interface type - PBA/ADU
        sbeMemAccessInterfaceType iv_interface;
        // Pointer to procedure flags - p9_PBA_oper_flag/p9_ADU_oper_flag
        void *iv_flags;
        // Read or Write mode
        sbeMemAccessMode iv_mode;
        // Ex target used in PBA interface, not applicable for ADU
        fapi2::Target<fapi2::TARGET_TYPE_EX > iv_ex;
        // Number of granule that can be sent before calling setup again
        uint32_t iv_maxGranule;
        // Iterator to track the current depth of iv_buffer
        uint32_t iv_iterator;
        // Number of granules sent after the setup
        uint32_t iv_currGranule;
        // Granule size based on interface - PBA/ADU
        uint32_t iv_granuleSize;
        // Buffer size is bigger of the two granules
        char iv_buffer[PBA_GRANULE_SIZE_BYTES];
        // Last granule for access
        bool iv_lastGranule;

        /* @brief Wrapper function to call setup procedures
         *        for the interface. This private API is used
         *        internally as per the state of the object,
         *        i.e., whenever the iv_maxGranule
         *        becomes 0, while using interface access APIs
         *
         * @return fapi rc
         */
        fapi2::ReturnCode setup();

        /* @brief Align and finalize the accessWithBuffer calls - useful in case
         *        the data to be read/written is not aligned to the
         *        granule sizes of the interfaces
         *
         * @return fapi rc
         */
         void alignAccessWithBuffer();

    public:
        /* @brief Constructor
         *
         * @param[in] i_addr    Address to read/write from
         * @param[in] i_flags   Pointer to PBA/ADU flags
         * @param[in] i_mode    Read/Write mode
         * @param[in] i_ex      EX target[Optional in case of ADU]
         */
        sbeMemAccessInterface(
                        sbeMemAccessInterfaceType i_interface,
                        uint64_t i_addr,
                        void *i_flags,
                        sbeMemAccessMode i_mode,
                        uint32_t i_granuleSize = 0,
                        fapi2::Target<fapi2::TARGET_TYPE_EX> i_ex
                        = fapi2::Target<fapi2::TARGET_TYPE_EX>()):
                        iv_addr(i_addr),
                        iv_interface(i_interface),
                        iv_flags(i_flags),
                        iv_mode(i_mode),
                        iv_ex(i_ex),
                        iv_maxGranule(0),
                        iv_iterator(0),
                        iv_currGranule(0),
                        iv_granuleSize(i_granuleSize),
                        iv_lastGranule(0)
        {
        }

        void * getBuffer()
        {
            iv_iterator = iv_granuleSize;
            return &iv_buffer;
        }

        /* @brief  Read/Write a single granule on PBA/ADU interface
         *
         * @return fapi rc
         */
        fapi2::ReturnCode accessGranule();

        /* @brief Read/Write on PBA/ADU interface with the given buffer.
         *
         * @param[in] io_buffer         Pointer to the data to read/write
         * @param[in] i_len             Length of the data to read/write in bytes
         * @param[in] i_isLastAccess    Is this a last access call on the interface 
         *
         * @return fapi rc
         */
        fapi2::ReturnCode accessWithBuffer(const void *io_buffer,
                                           const uint32_t i_len,
                                           const bool i_isLastAccess = false);

};
#endif //__SBE_MEM_ACCESS_INTERFACE_H
OpenPOWER on IntegriCloud