summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiPlatHwAccess.C
blob: 5d372b48e6b2d15e239d4dc7c48eb5ed95b77987 (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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/plat/fapiPlatHwAccess.C $                        */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
//  This is an automatically generated prolog.
//
//  $Source: src/usr/hwpf/plat/fapiPlatHwAccess.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END_TAG
/**
 *  @file fapiPlatHwAccess.C
 *
 *  @brief Implements the fapiHwAccess.H functions.
 *
 *  Note that platform code must provide the implementation.
 */

#include <fapiHwAccess.H>
#include <fapiPlatTrace.H>
#include <fapiPlatHwAccess.H>
#include <hwpf/hwpf_reasoncodes.H>
#include <errl/errlentry.H>
#include <devicefw/userif.H>
#include <ecmdDataBufferBase.H>
#include <targeting/common/predicates/predicates.H>
#include <targeting/common/targetservice.H>
#include <scan/scanif.H>

extern "C"
{

// Function prototypes
uint64_t platGetDDScanMode(const uint32_t i_ringMode);


//******************************************************************************
// platGetScom function, the platform implementation
//******************************************************************************
fapi::ReturnCode platGetScom(const fapi::Target& i_target,
                             const uint64_t i_address,
                             ecmdDataBufferBase & o_data)
{
    FAPI_DBG(ENTER_MRK "platGetScom");

    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;
    uint32_t l_ecmdRc = ECMD_DBUF_SUCCESS;

    // Extract the component pointer
    TARGETING::Target* l_target =
            reinterpret_cast<TARGETING::Target*>(i_target.get());

    // Perform SCOM read
    uint64_t l_data = 0;
    size_t l_size = sizeof(uint64_t);

    l_err = deviceRead(l_target,
                       &l_data,
                       l_size,
                       DEVICE_SCOM_ADDRESS(i_address));
    if (l_err)
    {
        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatError(reinterpret_cast<void *> (l_err));
    }
    else
    {
        // Set buffer to 64-bit long to store data
        l_ecmdRc = o_data.setBitLength(64);
        if (l_ecmdRc == ECMD_DBUF_SUCCESS)
        {
            l_ecmdRc = o_data.setDoubleWord(0, l_data);
        }

        if (l_ecmdRc)
        {
            FAPI_ERR("platGetScom: ecmdDataBufferBase setBitLength() or setDoubleWord() returns error, ecmdRc 0x%.8X",
                    l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);
        }
    }

    FAPI_DBG(EXIT_MRK "platGetScom");
    return l_rc;
}

//******************************************************************************
// platPutScom function
//******************************************************************************
fapi::ReturnCode platPutScom(const fapi::Target& i_target,
                             const uint64_t i_address,
                             ecmdDataBufferBase & i_data)
{
    FAPI_DBG(ENTER_MRK "platPutScom");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;

    // Extract the component pointer
    TARGETING::Target* l_target =
            reinterpret_cast<TARGETING::Target*>(i_target.get());

    // Perform SCOM write
    uint64_t l_data = i_data.getDoubleWord(0);
    size_t l_size = sizeof(uint64_t);
    l_err = deviceWrite(l_target,
                        &l_data,
                        l_size,
                        DEVICE_SCOM_ADDRESS(i_address));
    if (l_err)
    {
        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatError(reinterpret_cast<void *> (l_err));
    }

    FAPI_DBG(EXIT_MRK "platPutScom");
    return l_rc;
}

//******************************************************************************
// platPutScomUnderMask function
//******************************************************************************
fapi::ReturnCode platPutScomUnderMask(const fapi::Target& i_target,
                                      const uint64_t i_address,
                                      ecmdDataBufferBase & i_data,
                                      ecmdDataBufferBase & i_mask)
{
    FAPI_DBG(ENTER_MRK "platPutScomUnderMask");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;

    // Extract the component pointer
    TARGETING::Target* l_target =
            reinterpret_cast<TARGETING::Target*>(i_target.get());

    do
    {
        // Get current value from HW
        uint64_t l_data = 0;
        size_t l_size = sizeof(uint64_t);
        l_err = deviceRead(l_target,
                           &l_data,
                           l_size,
                           DEVICE_SCOM_ADDRESS(i_address));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Calculate new value to write to reg
        uint64_t l_inData = i_data.getDoubleWord(0); // Data to write
        uint64_t l_inMask = i_mask.getDoubleWord(0); // Write mask
        uint64_t l_inMaskInverted = ~(l_inMask);     // Write mask inverted
        uint64_t l_newMask = (l_inData & l_inMask);  // Retain set data bits

        // l_data = current data set bits
        l_data &= l_inMaskInverted;

        // l_data = current data set bit + set mask bits
        l_data |= l_newMask;

        // Write new value
        l_err = deviceWrite(l_target,
                            &l_data,
                            l_size,
                            DEVICE_SCOM_ADDRESS(i_address));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

    }
    while(0);

    FAPI_DBG(EXIT_MRK "platPutScomUnderMask");
    return l_rc;
}

/****************************************************************************
 *  @brief Verify target of a cfam access
 *         We can't access the cfam engine of the master processor; therefore,
 *         we should not allow a cfam access on any processor in any position
 *         from a FAPI standpoint
 *         This function will return an error if the input target is of
 *         processor type.
 *
 *  @param[in]  i_target        The target where cfam access is called on.
 *
 *  @return errlHndl_t if target is a processor, NULL otherwise.
 ****************************************************************************/
static errlHndl_t verifyCfamAccessTarget(const fapi::Target& i_target)
{
    errlHndl_t l_err = NULL;

    // Can't access cfam engine on processors
    if (i_target.getType() == fapi::TARGET_TYPE_PROC_CHIP)
    {
        // Add the error log pointer as data to the ReturnCode
        FAPI_ERR("verifyCfamAccessTarget: Attempt to access CFAM register on a processor chip");

        /*@
         * @errortype
         * @moduleid     fapi::MOD_VERIFY_CFAM_ACCESS_TARGET
         * @reasoncode   fapi::RC_CFAM_ACCESS_ON_PROC_ERR
         * @userdata1    Target type
         * @devdesc      Attempt to access CFAM register on a processor chip
         */
        l_err = new ERRORLOG::ErrlEntry(
                    ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                    fapi::MOD_VERIFY_CFAM_ACCESS_TARGET,
                    fapi::RC_CFAM_ACCESS_ON_PROC_ERR,
                    i_target.getType());
    }

    return l_err;
}

/****************************************************************************
 *  @brief Get chip target for cfam access
 *         HW procedures may pass in non-chip targets (such as MBA or
 *         MBS as a target), so we need to find the parent chip in order
 *         to pass it to the device driver.
 *
 *  @param[in]  i_target        The target as passed in by the procedure.
 *
 *  @return errlHndl_t if can't find parent, NULL otherwise.
 ****************************************************************************/
static errlHndl_t getCfamChipTarget(const TARGETING::Target* i_target,
                                    TARGETING::Target*& o_chipTarget)
{
    errlHndl_t l_err = NULL;

    // Default to input target
    o_chipTarget = const_cast<TARGETING::Target*>(i_target);

    // Check to see if this is a chiplet
    if (i_target->getAttr<TARGETING::ATTR_CLASS>() == TARGETING::CLASS_UNIT)
    {
        // Look for its chip parent
        TARGETING::PredicateCTM l_chipClass(TARGETING::CLASS_CHIP);
        TARGETING::TargetHandleList l_list;
        TARGETING::TargetService& l_targetService = TARGETING::targetService();
        (void) l_targetService.getAssociated(
                l_list,
                i_target,
                TARGETING::TargetService::PARENT,
                TARGETING::TargetService::ALL,
                &l_chipClass);

        if ( l_list.size() == 1 )
        {
            o_chipTarget = l_list[0];
        }
        else
        {
            // Something is wrong here, can't have more than one parent chip
            FAPI_ERR("getCfamChipTarget: Invalid number of parent chip for this target chiplet - # parent chips %d", l_list.size());
            /*@
             * @errortype
             * @moduleid     fapi::MOD_GET_CFAM_CHIP_TARGET
             * @reasoncode   fapi::RC_INVALID_NUM_PARENT_CHIP
             * @userdata1    Number of parent chip found
             * @devdesc      Invalid num of parent chip found for input CFAM target chiplet
             */
            l_err = new ERRORLOG::ErrlEntry(
                        ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                        fapi::MOD_GET_CFAM_CHIP_TARGET,
                        fapi::RC_INVALID_NUM_PARENT_CHIP,
                        l_list.size());
        }
    }
    return l_err;
}

//******************************************************************************
// platGetCfamRegister function
//******************************************************************************
fapi::ReturnCode platGetCfamRegister(const fapi::Target& i_target,
                                     const uint32_t i_address,
                                     ecmdDataBufferBase & o_data)
{
    FAPI_DBG(ENTER_MRK "platGetCfamRegister");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;
    uint32_t l_ecmdRc = ECMD_DBUF_SUCCESS;

    do
    {
        // Can't access cfam engine on processors
        l_err = verifyCfamAccessTarget(i_target);
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Extract the component pointer
        TARGETING::Target* l_target =
                reinterpret_cast<TARGETING::Target*>(i_target.get());

        // Get the chip target if l_target is not a chip
        TARGETING::Target* l_myChipTarget = NULL;
        l_err = getCfamChipTarget(l_target, l_myChipTarget);
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Perform CFAM read via FSI
        // Address needs to be multiply by 4 because register addresses are word
        // offsets but the FSI addresses are byte offsets.
        // However, we need to preserve the engine's offset of 0x0C00 and 0x1000.
        uint64_t l_addr = ((i_address & 0x003F) << 2) | (i_address & 0xFF00);
        uint32_t l_data = 0;
        size_t l_size = sizeof(uint32_t);
        l_err = deviceRead(l_myChipTarget,
                           &l_data,
                           l_size,
                           DEVICE_FSI_ADDRESS(l_addr));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Set buffer to 32-bit long to store data
        l_ecmdRc = o_data.setBitLength(32);
        if (l_ecmdRc == ECMD_DBUF_SUCCESS)
        {
            l_ecmdRc = o_data.setWord(0, l_data);
        }
        if (l_ecmdRc)
        {
            FAPI_ERR("platGetCfamRegister: ecmdDataBufferBase setBitLength()"
                     " or setWord() returns error, ecmdRc 0x%.8X",
                     l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);
        }

    } while(0);

    FAPI_DBG(EXIT_MRK "platGetCfamRegister");
    return l_rc;
}

//******************************************************************************
// platPutCfamRegister function
//******************************************************************************
fapi::ReturnCode platPutCfamRegister(const fapi::Target& i_target,
                                     const uint32_t i_address,
                                     ecmdDataBufferBase & i_data)
{
    FAPI_DBG(ENTER_MRK "platPutCfamRegister");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;

    do
    {
        // Can't access cfam engine on processors
        l_err = verifyCfamAccessTarget(i_target);
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Extract the component pointer
        TARGETING::Target* l_target =
                reinterpret_cast<TARGETING::Target*>(i_target.get());

        TARGETING::Target* l_myChipTarget = NULL;
        // Get the chip target if l_target is not a chip
        l_err = getCfamChipTarget(l_target, l_myChipTarget);
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Perform CFAM write via FSI
        // Address needs to be multiply by 4 because register addresses are word
        // offsets but the FSI addresses are byte offsets
        // However, we need to preserve the engine's offset of 0x0C00 and 0x1000.
        uint64_t l_addr = ((i_address & 0x003F) << 2) | (i_address & 0xFF00);
        uint32_t l_data = i_data.getWord(0);
        size_t l_size = sizeof(uint32_t);
        l_err = deviceWrite(l_myChipTarget,
                            &l_data,
                            l_size,
                            DEVICE_FSI_ADDRESS(l_addr));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

    } while (0);

    FAPI_DBG(EXIT_MRK "platPutCfamRegister");
    return l_rc;
}

/****************************************************************************
 * @brief   Modifying input 32-bit data with the specified mode
 *
 * This method modify 32-bit input data (io_modifiedData) by applying the
 * specified modify mode along with the input data (i_origData).
 *
 * @param[in]  i_modifyMode         Modification mode
 * @param[in]  i_origData           32-bit data to be used for modification
 * @param[out] io_modifiedData      32-bit data to be modified
 *
 * @return void
 *
 ****************************************************************************/
void platProcess32BitModifyMode(const fapi::ChipOpModifyMode i_modifyMode,
                                const uint32_t i_origDataBuf,
                                uint32_t& io_modifiedData)
{

    // OR operation
    if (fapi::CHIP_OP_MODIFY_MODE_OR == i_modifyMode)
    {
        io_modifiedData |= i_origDataBuf;
    }
    // AND operation
    else if (fapi::CHIP_OP_MODIFY_MODE_AND == i_modifyMode)
    {
        io_modifiedData &= i_origDataBuf;
    }
    // Must be XOR operation
    else
    {
        io_modifiedData ^= i_origDataBuf;
    }

    return;
}

//******************************************************************************
// platModifyCfamRegister function
//******************************************************************************
fapi::ReturnCode platModifyCfamRegister(const fapi::Target& i_target,
                                    const uint32_t i_address,
                                    ecmdDataBufferBase& i_data,
                                    const fapi::ChipOpModifyMode i_modifyMode)
{
    FAPI_DBG(ENTER_MRK "platModifyCfamRegister");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;

    do
    {
        // Can't access cfam engine on processors
        l_err = verifyCfamAccessTarget(i_target);
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Extract the component pointer
        TARGETING::Target* l_target =
                reinterpret_cast<TARGETING::Target*>(i_target.get());

        // Get the chip target if l_target is not a chip
        TARGETING::Target* l_myChipTarget = NULL;
        l_err = getCfamChipTarget(l_target, l_myChipTarget);
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Read current value
        // Address needs to be multiply by 4 because register addresses are word
        // offsets but the FSI addresses are byte offsets.
        // However, we need to preserve the engine's offset of 0x0C00 and 0x1000.
        uint64_t l_addr = ((i_address & 0x003F) << 2) | (i_address & 0xFF00);
        uint32_t l_data = 0;
        size_t l_size = sizeof(uint32_t);
        l_err = deviceRead(l_myChipTarget,
                           &l_data,
                           l_size,
                           DEVICE_FSI_ADDRESS(l_addr));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

        // Applying modification
        platProcess32BitModifyMode(i_modifyMode, i_data.getWord(0), l_data);

        // Write back
        l_err = deviceWrite(l_target,
                            &l_data,
                            l_size,
                            DEVICE_FSI_ADDRESS(l_addr));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
            break;
        }

    } while (0);

    FAPI_DBG(EXIT_MRK "platModifyCfamRegister");
    return l_rc;
}

//******************************************************************************
// platGetRing function, the platform implementation
//******************************************************************************
fapi::ReturnCode platGetRing(const fapi::Target& i_target,
                             const uint32_t i_address,
                             ecmdDataBufferBase & o_data,
                             const uint32_t i_ringMode)
{
    FAPI_DBG(ENTER_MRK "platGetRing");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;

    // Extract the component pointer
    TARGETING::Target* l_target =
            reinterpret_cast<TARGETING::Target*>(i_target.get());

    // Output buffer must be set to ring's len by user
    uint64_t l_ringLen = o_data.getBitLength();
    uint64_t l_flag = platGetDDScanMode(i_ringMode);
    size_t l_size = o_data.getByteLength();
    l_err = deviceRead(l_target,
                 ecmdDataBufferBaseImplementationHelper::getDataPtr(&o_data),
                 l_size,
                 DEVICE_SCAN_ADDRESS(i_address, l_ringLen, l_flag));
    if (l_err)
    {
        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatError(reinterpret_cast<void *> (l_err));
    }

    FAPI_DBG(EXIT_MRK "platGetRing");
    return l_rc;
}

//******************************************************************************
// platPutRing function
//******************************************************************************
fapi::ReturnCode platPutRing(const fapi::Target& i_target,
                             const uint32_t i_address,
                             ecmdDataBufferBase & i_data,
                             const uint32_t i_ringMode)
{

    FAPI_DBG(ENTER_MRK "platPutRing");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;

    // Extract the component pointer
    TARGETING::Target* l_target =
            reinterpret_cast<TARGETING::Target*>(i_target.get());

    // Output buffer must be set to ring's len by user
    uint64_t l_ringLen = i_data.getBitLength();
    uint64_t l_flag = platGetDDScanMode(i_ringMode);
    size_t l_size = i_data.getByteLength();
    l_err = deviceWrite(l_target,
                 ecmdDataBufferBaseImplementationHelper::getDataPtr(&i_data),
                 l_size,
                 DEVICE_SCAN_ADDRESS(i_address, l_ringLen, l_flag));
    if (l_err)
    {
        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatError(reinterpret_cast<void *> (l_err));
    }

    FAPI_DBG(EXIT_MRK "platPutRing");
    return l_rc;
}

//******************************************************************************
// platModifyRing function
//******************************************************************************
fapi::ReturnCode platModifyRing(const fapi::Target& i_target,
                             const uint32_t i_address,
                             ecmdDataBufferBase & i_data,
                             const fapi::ChipOpModifyMode i_modifyMode,
                             const uint32_t i_ringMode)
{
    FAPI_DBG(ENTER_MRK "platModifyRing");
    fapi::ReturnCode l_rc;
    errlHndl_t l_err = NULL;
    uint32_t l_ecmdRc = ECMD_DBUF_SUCCESS;

    do
    {
        // Extract the component pointer
        TARGETING::Target* l_target =
                reinterpret_cast<TARGETING::Target*>(i_target.get());

        // --------------------
        // Read current value
        // --------------------
        uint64_t l_ringLen = i_data.getBitLength();
        ecmdDataBufferBase l_modifiedRingBuffer(l_ringLen);
        uint64_t l_flag = platGetDDScanMode(i_ringMode);
        size_t l_size = l_modifiedRingBuffer.getByteLength();
        l_err = deviceRead(l_target,
                     ecmdDataBufferBaseImplementationHelper::getDataPtr(
                                     &l_modifiedRingBuffer),
                     l_size,
                     DEVICE_SCAN_ADDRESS(i_address, l_ringLen, l_flag));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
        }

        // ----------------------
        // Applying modification
        // ----------------------
        if (fapi::CHIP_OP_MODIFY_MODE_OR == i_modifyMode)
        {
            l_ecmdRc = l_modifiedRingBuffer.setOr(i_data, 0, l_ringLen);
        }
        else if (fapi::CHIP_OP_MODIFY_MODE_AND == i_modifyMode)
        {
            l_ecmdRc = l_modifiedRingBuffer.setAnd(i_data, 0, l_ringLen);
        }
        else
        {
            l_ecmdRc = l_modifiedRingBuffer.setXor(i_data, 0, l_ringLen);
        }

        if (l_ecmdRc)
        {
            FAPI_ERR("platModifyRing: ecmdDataBufferBase operation returns error, ecmdRc 0x%.8X",
                     l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);
            break;
        }

        // ---------------
        // Write back
        // ---------------
        l_err = deviceWrite(l_target,
                      ecmdDataBufferBaseImplementationHelper::getDataPtr(
                              &l_modifiedRingBuffer),
                      l_size,
                      DEVICE_SCAN_ADDRESS(i_address, l_ringLen, l_flag));
        if (l_err)
        {
            // Add the error log pointer as data to the ReturnCode
            l_rc.setPlatError(reinterpret_cast<void *> (l_err));
        }

    } while (0);

    FAPI_DBG(EXIT_MRK "platModifyRing");
    return l_rc;
}

//******************************************************************************
// platPutRing function
//******************************************************************************
uint64_t platGetDDScanMode(const uint32_t i_ringMode)
{
    fapi::ReturnCode l_rc;
    uint32_t l_scanMode = 0;

    // Set Pulse
    if (i_ringMode & fapi::RING_MODE_SET_PULSE)
    {
        l_scanMode |= SCAN::SET_PULSE;
    }

    // Header Check
    if (i_ringMode & fapi::RING_MODE_NO_HEADER_CHECK)
    {
        l_scanMode |= SCAN::NO_HEADER_CHECK;
    }

    return l_scanMode;
}



} // extern "C"
OpenPOWER on IntegriCloud