summaryrefslogtreecommitdiffstats
path: root/src/include/usr/pnor/ecc.H
blob: 80c993c960e30e98b98c6712aa42934880f1fc77 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/pnor/ecc.H $                                  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,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 __PNOR_ECC_H
#define __PNOR_ECC_H

#include <stdint.h>

#ifdef __HOSTBOOT_MODULE
#include <assert.h>
#endif

/** @file ecc.H
 *  @brief Interfaces for the P8 8-byte ECC algorithm.
 */

namespace PNOR
{
namespace ECC
{
    /** Status for the ECC removal function. */
    enum eccStatus
    {
        CLEAN,          //< No ECC Error was detected.
        CORRECTED,      //< ECC error detected and corrected.
        UNCORRECTABLE   //< ECC error detected and uncorrectable.
    };

    /** Bit field identifiers for syndrome calculations. */
    enum eccBitfields
    {
        GD = 0xff,      //< Good, ECC matches.
        UE = 0xfe,      //< Uncorrectable.
        E0 = 71,        //< Error in ECC bit 0
        E1 = 70,        //< Error in ECC bit 1
        E2 = 69,        //< Error in ECC bit 2
        E3 = 68,        //< Error in ECC bit 3
        E4 = 67,        //< Error in ECC bit 4
        E5 = 66,        //< Error in ECC bit 5
        E6 = 65,        //< Error in ECC bit 6
        E7 = 64         //< Error in ECC bit 7
    };

    /** Inject ECC into a data stream.
     *
     *  @param[in] i_src - Source data to create ECC on.
     *  @param[in] i_srcSz - Size in bytes of source data.
     *  @param[out] o_dst - Destination buffer of data+ECC.
     *
     *  @note i_srcSz must be a multiple of 8 bytes.
     */
    void injectECC(const uint8_t* i_src, size_t i_srcSz,
                   uint8_t* o_dst);

    /** Remove ECC from a data stream.
     *
     *  @param[in,out] io_src - Source data+ECC stream.
     *  @param[out] o_dst - Destination buffer for data only.
     *  @param[in] i_dstSz - Size in bytes of destination ((srcSz / 9) * 8).
     *
     *  @note i_dstSz must be a multiple of 8 bytes.
     */
    eccStatus removeECC(uint8_t* io_src,
                        uint8_t* o_dst, size_t i_dstSz);

#ifdef __HOSTBOOT_MODULE
    /** Given the size of Data, return the size of Data+ECC
     *
     *  @param[in] i_sizeWithoutEcc Size in bytes of data without ECC
     *
     *  @note i_sizeWithoutEcc must be a multiple of 8 bytes or will assert
     *
     * @return size of data with ECC
     */
    inline size_t sizeWithEcc(const size_t i_sizeWithoutEcc)
    {
        bool noRemainder = (i_sizeWithoutEcc % 8) == 0 ? true : false;
        assert (noRemainder, "PNOR::ECC::sizeWithEcc: input needs to be multiple of 8 bytes");
        return (i_sizeWithoutEcc * 9) / 8;
    }
#endif

}
}

#endif
OpenPOWER on IntegriCloud