summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/rosetta_map/rosetta_map.H
blob: 6e6771f73fa08f22fa1df5d45197f9168f17dd0b (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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/rosetta_map/rosetta_map.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,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                                                     */

///
/// @file rosetta_map.H
/// @brief Mapping functions for module C4 pin names to PHY instance names
///
// *HWP HWP Owner: Louis Stermole <stermole@us.ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#ifndef _MSS_ROSETTA_MAP_H_
#define _MSS_ROSETTA_MAP_H_

#include <vector>
#include <algorithm>
#include <fapi2.H>

#include <lib/mss_attribute_accessors.H>
#include <lib/shared/mss_const.H>

namespace mss
{

///
/// @brief Types of signals/pins mapped by the rosetta_map
///
enum rosetta_type
{
    DQ,
    DQS,
    ADDRESS,
    CLOCK,
    WE,
    RAS,
    CAS,
    CS,
    CKE,
    ODT,
    BA,
    BG,
    CID,
    ACTN
};

///
/// @brief c_str specialization for rosetta_type
/// @param[in] i_input - input you want the const char * for
/// @return const char * representation of given rosetta_type
///
inline const char* c_str( const rosetta_type& i_input )
{
    switch (i_input)
    {
        case DQ:
            sprintf(c_str_storage, "DQ");
            break;

        case DQS:
            sprintf(c_str_storage, "DQS");
            break;

        case ADDRESS:
            sprintf(c_str_storage, "ADDRESS");
            break;

        case CLOCK:
            sprintf(c_str_storage, "CLOCK");
            break;

        case WE:
            sprintf(c_str_storage, "WE");
            break;

        case RAS:
            sprintf(c_str_storage, "RAS");
            break;

        case CAS:
            sprintf(c_str_storage, "CAS");
            break;

        case CS:
            sprintf(c_str_storage, "CS");
            break;

        case CKE:
            sprintf(c_str_storage, "CKE");
            break;

        case ODT:
            sprintf(c_str_storage, "ODT");
            break;

        case BA:
            sprintf(c_str_storage, "BA");
            break;

        case BG:
            sprintf(c_str_storage, "BG");
            break;

        case CID:
            sprintf(c_str_storage, "CID");
            break;

        case ACTN:
            sprintf(c_str_storage, "ACTN");
            break;

        default:
            sprintf(c_str_storage, "ERROR");
            break;
    }

    return c_str_storage;
}

namespace rosetta_map
{

// PhyMap is an alias for the mapping table for each pin type mapped in the rosetta_map
using PhyMap = std::vector<std::vector<std::pair<uint64_t, uint64_t>>>;

} // close namespace rosetta_map

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the module C4 to PHY pin mapping
/// @tparam T fapi2::TargetType representing the PHY
/// @tparam R rosetta_type enumeration of signal/pin to map
///
template< fapi2::TargetType T, rosetta_type R >
class rosettaTraits;

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for DQ
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, DQ>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for DQS
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, DQS>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for ADDRESS
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, ADDRESS>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for CLOCK
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, CLOCK>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for WE
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, WE>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for RAS
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, RAS>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for CAS
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, CAS>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for CS
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, CS>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for CKE
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, CKE>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for ODT
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, ODT>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for BA
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, BA>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for BG
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, BG>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for CID
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, CID>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

///
/// @class rosettaTraits
/// @brief a collection of traits associated with the Nimbus module c4 pin to PHY instance mapping for ACTN
///
template<>
class rosettaTraits<fapi2::TARGET_TYPE_MCA, ACTN>
{
    public:
        // Each pin type has a table of vector<vector<pair>>, indexed by [port][c4bit]-->{block, lane}
        static const rosetta_map::PhyMap C4_TO_PHY;
};

namespace rosetta_map
{

///
/// @brief Given a module C4 pin index, return the PHY DP16 instance and lane
/// @tparam R rosetta_type enumeration of signal/pin to map
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to rosettaTraits<T, R>
/// @param[in] i_target the fapi2 target of the port
/// @param[in] i_c4_pin the index of the module C4 pin
/// @param[out] o_dp the DP instance
/// @param[out] o_lane the lane index
/// @return FAPI2_RC_SUCCESS iff ok
///
template< rosetta_type R, fapi2::TargetType T, typename TT = rosettaTraits<T, R> >
fapi2::ReturnCode c4_to_phy( const fapi2::Target<T>& i_target,
                             const uint64_t i_c4_pin,
                             uint64_t& o_dp,
                             uint64_t& o_lane )
{
    const auto l_pos = mss::pos(i_target);
    const auto& l_mapping = TT::C4_TO_PHY[l_pos];
    char l_str_buffer[fapi2::MAX_ECMD_STRING_LEN] = {};

    // Make a copy of c_str(R) so it doesn't get overwritten by mss::c_str(i_target)
    strcpy(l_str_buffer, c_str(R));

    FAPI_ASSERT(i_c4_pin < l_mapping.size(),
                fapi2::MSS_C4_PIN_OUT_OF_RANGE()
                .set_MCA_TARGET(i_target)
                .set_TYPE(R)
                .set_INDEX(i_c4_pin),
                "%s Module C4 pin type %s, index %d is beyond maximum value %d", mss::c_str(i_target), l_str_buffer, i_c4_pin,
                (l_mapping.size() - 1) );

    o_dp   = l_mapping[i_c4_pin].first;
    o_lane = l_mapping[i_c4_pin].second;

    return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Given a PHY DP16 instance and lane, return the corresponding module C4 pin index
/// @tparam R rosetta_type enumeration of signal/pin to map
/// @tparam T fapi2 Target Type - derived
/// @tparam TT traits type defaults to rosettaTraits<T, R>
/// @param[in] i_target the fapi2 target of the port
/// @param[in] i_dp the DP instance
/// @param[in] i_lane the lane index
/// @param[out] o_c4_pin the index of the module C4 pin
/// @return FAPI2_RC_SUCCESS iff ok
///
template< rosetta_type R, fapi2::TargetType T, typename TT = rosettaTraits<T, R> >
fapi2::ReturnCode phy_to_c4( const fapi2::Target<T>& i_target,
                             const uint64_t i_dp,
                             const uint64_t i_lane,
                             uint64_t& o_c4_pin )
{
    const auto l_pos = mss::pos(i_target);
    const auto& l_mapping = TT::C4_TO_PHY[l_pos];
    char l_str_buffer[fapi2::MAX_ECMD_STRING_LEN] = {};

    // Make a copy of c_str(R) so it doesn't get overwritten by mss::c_str(i_target)
    strcpy(l_str_buffer, c_str(R));

    const auto l_it = std::find(l_mapping.begin(), l_mapping.end(), std::make_pair(i_dp, i_lane));

    FAPI_ASSERT(l_it != l_mapping.end(),
                fapi2::MSS_NO_C4_PIN_MAPPING()
                .set_MCA_TARGET(i_target)
                .set_TYPE(R)
                .set_DP(i_dp)
                .set_LANE(i_lane),
                "%s No module C4 pin mapping found for type %s, DP %d, lane %d", mss::c_str(i_target), l_str_buffer, i_dp, i_lane );

    o_c4_pin = l_it - l_mapping.begin();

    return fapi2::FAPI2_RC_SUCCESS;

fapi_try_exit:
    return fapi2::current_err;
}

} // close namespace rosetta_map
} // close namespace mss

#endif
OpenPOWER on IntegriCloud