summaryrefslogtreecommitdiffstats
path: root/src/sbefw/core/sbeMemAccessInterface.C
blob: 8b42137e6df25e22bfb1c8a3b8ca22f9f2cdd7ca (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/sbefw/core/sbeMemAccessInterface.C $                      */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2018                        */
/* [+] 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                                                     */
#include "sbeMemAccessInterface.H"

#ifdef HOST_INTERFACE_AVAILABLE

#ifdef SEEPROM_IMAGE
// Using Function pointer to force long call
p9_adu_access_FP_t p9_adu_access_hwp = &p9_adu_access;
p9_adu_setup_FP_t p9_adu_setup_hwp = &p9_adu_setup;
#endif

using namespace fapi2;

void MEM_AVAILABLE_CHECK(uint32_t &io_available_len,uint32_t &io_len_to_send,bool &io_is_last_access)
{
    if(io_len_to_send > io_available_len)
    {
        SBE_INFO(SBE_FUNC" Allocated memory is less, truncating the access");
        io_len_to_send = io_available_len;
        io_is_last_access = true;
    }
    io_available_len -= io_len_to_send;
}

ReturnCode sbeMemAccessInterface::setup()
{
#define SBE_FUNC "sbeMemAccessInterface::setup"
    SBE_ENTER(SBE_FUNC);
    ReturnCode fapiRc = FAPI2_RC_SUCCESS;

    // Reset the current granule count
    iv_currGranule = 0;
    iv_intfCleanedUp = false;
    SBE_INFO("iv_addr [0x%08x%08x]", SBE::higher32BWord(iv_addr), SBE::lower32BWord(iv_addr));
    if(iv_interface == SBE_MEM_ACCESS_PBA)
    {
        // Call the PBA setup HWP
        SBE_EXEC_HWP(fapiRc,
                     p9_pba_setup,
                     plat_getChipTarget(),
                     iv_ex,
                     iv_addr,
                     (iv_mode == SBE_MEM_ACCESS_READ),
                     ((p9_PBA_oper_flag*)iv_flags)->setFlag(),
                     iv_maxGranule);
    }
    if(iv_interface == SBE_MEM_ACCESS_ADU)
    {
        // Call the ADU setup HWP
        SBE_EXEC_HWP(fapiRc,
                     p9_adu_setup_hwp,
                     plat_getChipTarget(),
                     iv_addr,
                     (iv_mode == SBE_MEM_ACCESS_READ),
                     ((p9_ADU_oper_flag*)iv_flags)->setFlag(),
                     iv_maxGranule)
    }
    // if setup returns error
    if(fapiRc != FAPI2_RC_SUCCESS)
    {
        SBE_ERROR(SBE_FUNC" setup Failed");
    }
    else
    {
        // Assumption is Hwp won't return zero for Num Granules
        assert(0 != iv_maxGranule);

        SBE_INFO(SBE_FUNC "Hwp returned iv_maxGranule=[0x%08X]",
                                             iv_maxGranule);
    }
    return fapiRc;
#undef SBE_FUNC
}

ReturnCode sbeMemAccessInterface::accessGranule(const bool i_isLastAccess)
{
#define SBE_FUNC "sbeMemAccessInterface::accessGranule"
    SBE_DEBUG(SBE_FUNC);
    ReturnCode fapiRc = FAPI2_RC_SUCCESS;

    do
    {
        // Check if we need to do a setup before access
        if(iv_intfCleanedUp)
        {
            fapiRc = setup();
            // if setup returns error
            if( fapiRc != FAPI2_RC_SUCCESS )
            {
                break;
            }
        }
        iv_intfCleanedUp = (i_isLastAccess || (iv_maxGranule == 1));
        if(iv_interface == SBE_MEM_ACCESS_PBA)
        {
            // Call PBA access for read/write
            SBE_EXEC_HWP(fapiRc,
                         p9_pba_access,
                         plat_getChipTarget(),
                         iv_addr,
                         (iv_mode == SBE_MEM_ACCESS_READ),
                         ((p9_PBA_oper_flag*)iv_flags)->setFlag(),
                         (iv_currGranule == 0),
                         iv_intfCleanedUp,
                         (uint8_t *)&iv_buffer);
        }
        if(iv_interface == SBE_MEM_ACCESS_ADU)
        {
            // Call ADU access HWP for ADU write/read request
            SBE_EXEC_HWP(fapiRc,
                     p9_adu_access_hwp,
                     plat_getChipTarget(),
                     iv_addr,
                     (iv_mode == SBE_MEM_ACCESS_READ),
                     ((p9_ADU_oper_flag*)iv_flags)->setFlag(),
                     (iv_currGranule == 0),
                     iv_intfCleanedUp,
                     (uint8_t *)&iv_buffer)
        }
        if(fapiRc != FAPI2_RC_SUCCESS)
        {
            SBE_ERROR(SBE_FUNC" access HWP failed");
            break;
        }
        iv_maxGranule--;
        iv_currGranule++;
        // Advance the address
        iv_addr += iv_granuleSize;
        iv_iterator = (iv_mode == SBE_MEM_ACCESS_READ)?
                        iv_granuleSize : 0;
    } while(false);

    return fapiRc;
#undef SBE_FUNC
}

ReturnCode sbeMemAccessInterface::accessWithBuffer(const void *io_buffer,
                                                   const uint32_t i_len,
                                                   const bool i_isLastAccess)
{
#define SBE_FUNC "sbeMemAccessInterface::accessWithBuffer"
    SBE_DEBUG(SBE_FUNC" len[%d]",i_len);
    ReturnCode fapiRc = FAPI2_RC_SUCCESS;
    uint32_t iterator = 0;
    bool is_lastGranule = false;

    do
    {
        if(iv_mode == SBE_MEM_ACCESS_WRITE)
        {
            // Fill buffer
            while((iv_iterator < iv_granuleSize) && (iterator < i_len))
            {
                iv_buffer[iv_iterator++] = ((char*)io_buffer)[iterator++];
            }
            // If Adu, put the ecc and itag applicable bytes
            if(iv_interface == SBE_MEM_ACCESS_ADU)
            {
                if(((p9_ADU_oper_flag*)iv_flags)->getEccMode())
                {
                    iv_buffer[iv_iterator++] = ((char*)io_buffer)[iterator++];
                }
                if(((p9_ADU_oper_flag*)iv_flags)->getItagMode())
                {
                    iv_buffer[iv_iterator++] = ((char*)io_buffer)[iterator++];
                }
            }
        }

        if(i_isLastAccess)
        {
            if((iv_mode == SBE_MEM_ACCESS_WRITE) &&
                        (iterator >= i_len))
            {
                is_lastGranule = true;
                alignAccessWithBuffer();
            }
            else if((iv_mode == SBE_MEM_ACCESS_READ) &&
                        ((i_len - iterator) <= iv_granuleSize))
            {
                is_lastGranule = true;
                iv_iterator = 0;
            }
        }
        if(((iv_mode == SBE_MEM_ACCESS_WRITE) &&
            (iv_iterator >= iv_granuleSize))
           ||
           ((iv_mode == SBE_MEM_ACCESS_READ) &&
            (iv_iterator == 0)))
        {
            fapiRc = accessGranule(is_lastGranule);
            // Break out on error
            if(fapiRc != FAPI2_RC_SUCCESS)
            {
                break;
            }
        }

        if(iv_mode == SBE_MEM_ACCESS_READ)
        {
            // Fill the buffer
            while((iv_iterator > 0) && (iterator < i_len))
            {
                ((char*)io_buffer)[iterator++] =
                        iv_buffer[iv_granuleSize - iv_iterator];
                iv_iterator--;
            }
            // If Adu, get the ecc and itag applicable bytes
            if(iv_interface == SBE_MEM_ACCESS_ADU)
            {
                uint32_t index = iv_granuleSize;
                if(((p9_ADU_oper_flag*)iv_flags)->getEccMode())
                {
                    ((char*)io_buffer)[iterator++] =
                                            iv_buffer[index++];
                }
                if(((p9_ADU_oper_flag*)iv_flags)->getItagMode())
                {
                    ((char*)io_buffer)[iterator++] =
                                            iv_buffer[index];
                }
            }
        }

        // data is completely processed
        if(iterator >= i_len)
        {
            break;
        }
    } while(true);

    return fapiRc;
#undef SBE_FUNC
}

void sbeMemAccessInterface::alignAccessWithBuffer()
{
#define SBE_FUNC "sbeMemAccessInterface::alignAccessWithBuffer"
    SBE_DEBUG(SBE_FUNC);
    // Required to fill zeroes only if the iv_buffer is partially occupied
    if(iv_iterator != 0)
    {
        // zero filling
        while(iv_iterator < iv_granuleSize)
        {
            iv_buffer[iv_iterator++] = 0;
        }
    }
#undef SBE_FUNC
}

#endif
OpenPOWER on IntegriCloud