summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyril.bur@au1.ibm.com>2018-03-07 17:04:57 +1100
committerStewart Smith <stewart@linux.ibm.com>2018-04-09 03:45:23 -0500
commitf7713517d90a14853dc9cfb66ee33dbc084e6ddf (patch)
treec506168dc46997e30a8c75548c014bed276c0d60
parent07c4573d06785b06ce36fd8feab28e153f4756f7 (diff)
downloadtalos-skiboot-f7713517d90a14853dc9cfb66ee33dbc084e6ddf.tar.gz
talos-skiboot-f7713517d90a14853dc9cfb66ee33dbc084e6ddf.zip
libflash/ecc: Add helpers to align a position within an ecc buffer
As part of ongoing work to make ECC invisible to higher levels up the stack this function converts a 'position' which should be ECC agnostic to the equivalent position within an ECC region starting at a specified location. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
-rw-r--r--libflash/ecc.h5
-rw-r--r--libflash/test/test-ecc.c31
2 files changed, 36 insertions, 0 deletions
diff --git a/libflash/ecc.h b/libflash/ecc.h
index 2ce22152..bd669484 100644
--- a/libflash/ecc.h
+++ b/libflash/ecc.h
@@ -67,4 +67,9 @@ static inline uint64_t ecc_buffer_size_minus_ecc(uint64_t len)
return len * BYTES_PER_ECC / (BYTES_PER_ECC + 1);
}
+static inline uint64_t ecc_buffer_align(uint64_t start, uint64_t pos)
+{
+ return pos - ((pos - start) % (BYTES_PER_ECC + 1));
+}
+
#endif
diff --git a/libflash/test/test-ecc.c b/libflash/test/test-ecc.c
index fb6ee64e..5ce4c571 100644
--- a/libflash/test/test-ecc.c
+++ b/libflash/test/test-ecc.c
@@ -487,5 +487,36 @@ int main(void)
free(buf);
free(ret_buf);
+
+ /* Check that unaligned address become aligned */
+ if (ecc_buffer_align(0, 5) != 0) {
+ ERR("ecc_buffer_align(0, 5) not 0 -> %ld\n", ecc_buffer_align(0, 5));
+ exit(1);
+ }
+
+ if (ecc_buffer_align(0, 8) != 0) {
+ ERR("ecc_buffer_align(0, 8) not 0 -> %ld\n", ecc_buffer_align(0, 8));
+ exit(1);
+ }
+ if (ecc_buffer_align(0, 9) != 9) {
+ ERR("ecc_buffer_align(0, 9) not 9 -> %ld\n", ecc_buffer_align(0, 9));
+ exit(1);
+ }
+ if (ecc_buffer_align(0, 15) != 9) {
+ ERR("ecc_buffer_align(0, 15) not 9 -> %ld\n", ecc_buffer_align(0, 15));
+ exit(1);
+ }
+ if (ecc_buffer_align(5, 10) != 5) {
+ ERR("ecc_buffer_align(5, 10) not 5 -> %ld\n", ecc_buffer_align(5, 10));
+ exit(1);
+ }
+ if (ecc_buffer_align(5, 18) != 14) {
+ ERR("ecc_buffer_align(5, 18) not 14 -> %ld\n", ecc_buffer_align(5, 18));
+ exit(1);
+ }
+ if (ecc_buffer_align(0, 50) != 45) {
+ ERR("ecc_buffer_align(0, 50) not 45 -> %ld\n", ecc_buffer_align(0, 50));
+ exit(1);
+ }
return 0;
}
OpenPOWER on IntegriCloud