summaryrefslogtreecommitdiffstats
path: root/sbe/hwpf/src/plat_ring_traverse.C
blob: 0309bfd5e9c20e602e4e933a4eb8ea488ce4c5be (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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: sbe/hwpf/src/plat_ring_traverse.C $                           */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016                             */
/* [+] 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 <plat_ring_traverse.H>

#include <p9_putRingUtils.H> // for RS4 decompression utilities
#include <sbeXipUtils.H>
#include <fapi2AttributeService.H> // for FAPI_ATTR_GET
#include <plat_target_utils.H> // for plat_getChipTarget

// SEEPROM start address
const uint32_t g_seepromAddr = SBE_SEEPROM_BASE_ORIGIN;
using namespace RING_TYPES;

///
/// @brief This is a plat pecific (SBE Plat) function that locates the
///        Ring Container in the image and calls the functin to decompress the
///        RS4 string and apply it to the hardware.
/// @param i_target The target of Ring apply.
/// @param i_ringID The Ring ID that identifies the ring to be applied.
/// @return FAPI2_RC_SUCCESS on success, else error code.
///
fapi2::ReturnCode findRS4InImageAndApply(
                        const fapi2::Target<fapi2::TARGET_TYPE_ALL>& i_target,
                        const RingID i_ringID,
                        const fapi2::RingMode i_ringMode)
{
    SBE_TRACE(">> findRS4InImageAndApply");

    fapi2::ReturnCode l_rc = fapi2::FAPI2_RC_SUCCESS;

    do
    {
        // Determine the Offset ID and Ring Type for the given Ring ID.
        uint32_t l_torOffset = 0;
        RINGTYPE l_ringType = COMMON_RING;
        CHIPLET_TYPE l_chipLetType;

        getRingProperties(i_ringID, l_torOffset, l_ringType,l_chipLetType);
        if(INVALID_RING == l_torOffset)
        {
            SBE_TRACE("Invalid Ring ID - %d", i_ringID);
            l_rc = fapi2::FAPI2_RC_INVALID_PARAMETER;
            break;
        }

        // Get the address of the Section-TOR
        P9XipHeader *l_hdr = getXipHdr();
        P9XipSection *l_section = &(l_hdr->iv_section[P9_XIP_SECTION_SBE_RINGS]);
        SectionTOR *l_sectionTOR = (SectionTOR *)(g_seepromAddr + 
                                    l_section->iv_offset);

        CHIPLET_DATA l_chipletData;
        l_chipletData.iv_base_chiplet_number = 0;
        l_chipletData.iv_num_common_rings = 0;
        l_chipletData.iv_num_instance_rings = 0;

        uint8_t l_chipletID = i_target.getChipletNumber();
        uint16_t l_cpltRingVariantSz = 0;
        uint32_t l_sectionOffset = 0;
        switch(l_chipLetType)
        {
            case PERV_TYPE: // PERV
                l_chipletData = PERV::g_pervData;
                l_cpltRingVariantSz = sizeof(PERV::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);
                    
                l_sectionOffset = l_sectionTOR->TOC_PERV_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_PERV_INSTANCE_RING;
                }

                break;

            case N0_TYPE: // Nest - N0
                l_chipletData = N0::g_n0Data;
                l_cpltRingVariantSz = sizeof(N0::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_N0_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_N0_INSTANCE_RING;
                }

                break;

            case N1_TYPE: // Nest - N1
                l_chipletData = N1::g_n1Data;
                l_cpltRingVariantSz = sizeof(N1::RingVariants) /
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_N1_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_N1_INSTANCE_RING;
                }

                break;

            case N2_TYPE: // Nest - N2
                l_chipletData = N2::g_n2Data;
                l_cpltRingVariantSz = sizeof(N2::RingVariants) /
                                     sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_N2_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_N2_INSTANCE_RING;
                }

                break;

            case N3_TYPE: // Nest - N3
                l_chipletData = N3::g_n3Data;
                l_cpltRingVariantSz = sizeof(N3::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_N3_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_N3_INSTANCE_RING;
                }

                break;

            case XB_TYPE: // XB - XBus2
                l_chipletData = XB::g_xbData;
                l_cpltRingVariantSz = sizeof(XB::RingVariants) /
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_XB_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_XB_INSTANCE_RING;
                }

                break;

            case MC_TYPE: // MC - MC23
                l_chipletData = MC::g_mcData;
                l_cpltRingVariantSz = sizeof(MC::RingVariants)/ 
                                    sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_MC_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_MC_INSTANCE_RING;
                }

                break;

            case OB_TYPE: // OB - OB2
                l_chipletData = OB::g_obData;
                l_cpltRingVariantSz = sizeof(OB::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_OB_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_OB_INSTANCE_RING;
                }

                break;

            case PCI0_TYPE: // PCI - PCI0
                l_chipletData = PCI0::g_pci0Data;
                l_cpltRingVariantSz = sizeof(PCI0::RingVariants) /
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_PCI0_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_PCI0_INSTANCE_RING;
                }

                break;

            case PCI1_TYPE: // PCI - PCI1
                l_chipletData = PCI1::g_pci1Data;
                l_cpltRingVariantSz = sizeof(PCI1::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_PCI1_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_PCI1_INSTANCE_RING;
                }

                break;

            case PCI2_TYPE: // PCI - PCI2
                l_chipletData = PCI2::g_pci2Data;
                l_cpltRingVariantSz = sizeof(PCI2::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_PCI2_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_PCI2_INSTANCE_RING;
                }

                break;

            case EQ_TYPE: // EQ - Quad 0 - Quad 5
                l_chipletData = EQ::g_eqData;
                l_cpltRingVariantSz = sizeof(EQ::RingVariants) / 
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_EQ_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_EQ_INSTANCE_RING;
                }

                break;

            case EC_TYPE: // EC - Core 0 - 23
                l_chipletData = EC::g_ecData;
                l_cpltRingVariantSz = sizeof(EC::RingVariants) /
                                        sizeof(l_cpltRingVariantSz);

                l_sectionOffset = l_sectionTOR->TOC_EC_COMMON_RING;
                if(INSTANCE_RING == l_ringType)
                {
                    l_sectionOffset = l_sectionTOR->TOC_EC_INSTANCE_RING;
                }

                break;

            default:
                SBE_TRACE("Invalid Target/ChipletID - %d", l_chipletID);
                l_rc = fapi2::FAPI2_RC_INVALID_PARAMETER;
                break;

        } // end of switch(l_chipletID)

        FAPI_INF("l_sectionOffset %08x",l_sectionOffset);
        // Determine the section TOR address for the ring
        uint32_t *l_sectionAddr = reinterpret_cast<uint32_t *>(g_seepromAddr + 
                                  l_section->iv_offset + l_sectionOffset);

        SBE_TRACE ("l_sectionAddr %08X",l_sectionAddr);
        SBE_TRACE("l_section->iv_offset %08X",l_section->iv_offset);


        if(INSTANCE_RING == l_ringType)
        {
            if ( l_chipletID > l_chipletData.iv_base_chiplet_number)
            {
                uint8_t l_chipletOffset =
                    (l_chipletID - l_chipletData.iv_base_chiplet_number);
                l_sectionAddr += (l_chipletOffset * 
                   (l_chipletData.iv_num_instance_rings * l_cpltRingVariantSz));
            }
            else
            {
                l_sectionAddr +=
                   (l_chipletData.iv_num_instance_rings * l_cpltRingVariantSz);
            }
        }

        // The ring variants in section TOR are expected to be in the sequence -
        // 1. Base
        // 2. Cache-Contained
        // 3. Risk Level

        SBE_TRACE ("l_sectionAddr %08X",l_sectionAddr);

        // TOR records of Ring TOR are 2 bytes in size.
        uint16_t *l_ringTorAddr = reinterpret_cast<uint16_t *>(l_sectionAddr) + 
                    (l_torOffset * l_cpltRingVariantSz);        
        SBE_TRACE ("ring tor address %04X\n",l_ringTorAddr);

        // If there are non-base variants of the ring, we'll have to check
        // attributes to determine the sequence of ring apply.
        if( l_cpltRingVariantSz > 1)
        {
            // Check if this is cache-contained IPL
            uint8_t l_iplPhase;
            FAPI_ATTR_GET(fapi2::ATTR_SYSTEM_IPL_PHASE,
                          fapi2::Target<fapi2::TARGET_TYPE_SYSTEM> (),
                          l_iplPhase);

            // 4 : Cache Contained mode
            if(4 == l_iplPhase)
            {
                l_ringTorAddr += 1;
            }
            else
            {
#if 0
                // Check if this is risk-level IPL
                uint8_t l_riskLevel;
                FAPI_ATTR_GET(fapi2::ATTR_RISK_LEVEL,
                              fapi2::plat_getChipTarget(),
                              l_riskLevel);
                if(1 == l_riskLevel)
                {
                    l_ringTorAddr += 2;
                }
#endif
            }
        }

        SBE_TRACE("l_ringTorAddr %u",*l_ringTorAddr);
        if(*l_ringTorAddr != 0)
        {
            uint8_t *l_addr = reinterpret_cast<uint8_t *>(l_sectionAddr);
            uint8_t *l_rs4Address = reinterpret_cast<uint8_t *>(l_addr + *l_ringTorAddr);
            l_rc = applyRS4_SS(i_target, l_rs4Address, i_ringMode);
            if(l_rc != fapi2::FAPI2_RC_SUCCESS)
            {
                SBE_TRACE("Error from applyRS4_SS");
                break;
            }
        }
        else
        {
            l_rc = fapi2::FAPI2_RC_PLAT_RING_ID_NOT_FOUND_IN_RS4_IMAGE;
            SBE_TRACE("Ring image is not found for this is ringId %u",i_ringID);
        }
    }while(0);

    SBE_TRACE("<< findRS4InImageAndApply Exit");
    return l_rc;
}

OpenPOWER on IntegriCloud