summaryrefslogtreecommitdiffstats
path: root/src/sbefw/sbeMemAccessInterface.H
blob: 6e268b01c01eceddbc836eb3ad129627ea10eefc (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/sbefw/sbeMemAccessInterface.H $                           */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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"

/* @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,
};

// Helper functions
/*
 * @brief function to check if the length to send can be
 * accomodated in the available memory, else make it a last
 * access on the interface
 */
void MEM_AVAILABLE_CHECK(uint32_t &io_available_len,
                         uint32_t &io_len_to_send,
                         bool &io_is_last_access);

class sbeMemAccessInterface
{
    private:
        // Bigger of PBA/ADU granules
        static constexpr uint32_t MEM_INTERFACE_SIZE_BYTES = 128;

        // 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[MEM_INTERFACE_SIZE_BYTES];
        // Interface cleaned up - indicates if the underlying
        // HWP cleanup is done for the interface.
        // A new object assumes interface is in cleaned up
        // state.
        // If the interface is in cleaned up state,
        // next access will happen only after the setup.
        bool iv_intfCleanedUp;

        /* @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:
        //Default EX Target ChipletId to be used in PBA by default
        static constexpr uint32_t PBA_DEFAULT_EX_CHIPLET_ID = 0x20;

        // PBA / ADU Granule size as per the HWP Requirement
        static constexpr uint32_t PBA_GRAN_SIZE_BYTES  = 128;
        static constexpr uint32_t ADU_GRAN_SIZE_BYTES  = 8;

        /* @brief Constructor
         *
         * @param[in] i_interface   Type of the interface
         * @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_granuleSize Granule size of the interface type
         * @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,
                        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_intfCleanedUp(true)
        {
        }

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

        /* @brief  Read/Write a single granule on PBA/ADU interface
         *
         * @param[in] i_isLastAccess    Should the interface be cleaned up
         *                              after this access
         *
         * @return fapi rc
         */
        fapi2::ReturnCode accessGranule(const bool i_isLastAccess = false);

        /* @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    Should the interface be cleaned up
         *                              after this access
         *
         * @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