From 6cfaa3ba1015c6ac9cc4a06f878b4289022cff54 Mon Sep 17 00:00:00 2001 From: Michael Neuling Date: Fri, 20 Feb 2015 11:37:50 +1100 Subject: libffs: Add ECC checking code Add ECC checking code. This code is based on the hostboot code. Unused currently, but will be soon. This uses __builtin_parityl() hence adding libgcc linking previously. Signed-off-by: Michael Neuling Signed-off-by: Stewart Smith --- include/ecc.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 include/ecc.h (limited to 'include') diff --git a/include/ecc.h b/include/ecc.h new file mode 100644 index 0000000..d5c30cb --- /dev/null +++ b/include/ecc.h @@ -0,0 +1,53 @@ +/* Copyright 2013-2014 IBM 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. + */ + +/* This is based on the hostboot ecc code */ + +#ifndef __ECC_H +#define __ECC_H + +#include +#include + +/* 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 +}; + +extern uint8_t eccmemcpy(uint64_t *dst, uint64_t *src, uint32_t len); + +/* + * Calculate the size of a buffer if ECC is added + * + * We add 1 byte of ecc for every 8 bytes of data. So we need to round up to 8 + * bytes length and then add 1/8 + */ +#define ECC_SIZE(len) (ALIGN_UP((len), 8) >> 3) +#define ECC_BUFFER_SIZE(len) (ALIGN_UP((len), 8) + ECC_SIZE(len)) +#define ECC_BUFFER_SIZE_CHECK(len) ((len) % 9) +#define BUFFER_SIZE_MINUS_ECC(len) ((len) * 8 / 9) + +#endif -- cgit v1.1