aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorManish V Badarkhe <Manish.Badarkhe@arm.com>2021-04-22 14:41:27 +0100
committerManish V Badarkhe <Manish.Badarkhe@arm.com>2021-05-19 19:34:34 +0100
commita1cedadf73863ff103fecd64fa188334e1541337 (patch)
tree4e8b51fdf8bab46f4f4d8d488cbfef1e45d330ff /common
parent1e13c500a0351ac4b55d09a63f7008e2438550f8 (diff)
downloadarm-trusted-firmware-a1cedadf73863ff103fecd64fa188334e1541337.tar.gz
feat(hw_crc): add support for HW computed CRC
Added support for HW computed CRC using Arm ACLE intrinsics. These are built-in intrinsics available for ARMv8.1-A, and onwards. These intrinsics are enabled via '-march=armv8-a+crc' compile switch for ARMv8-A (supports CRC instructions optionally). HW CRC support is enabled unconditionally in BL2 for all Arm platforms. HW CRC calculation is verified offline to ensure a similar result as its respective ZLib utility function. HW CRC calculation support will be used in the upcoming firmware update patches. Change-Id: Ia2ae801f62d2003e89a9c3e6d77469b5312614b3 Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
Diffstat (limited to 'common')
-rw-r--r--common/hw_crc32.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/common/hw_crc32.c b/common/hw_crc32.c
new file mode 100644
index 000000000..a8731da17
--- /dev/null
+++ b/common/hw_crc32.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdarg.h>
+#include <assert.h>
+
+#include <arm_acle.h>
+#include <common/debug.h>
+
+/* hw_crc32 - compute CRC using Arm intrinsic function
+ *
+ * This function is useful for the platforms with the CPU ARMv8.0
+ * (with CRC instructions supported), and onwards.
+ * Platforms with CPU ARMv8.0 should make sure to add a compile switch
+ * '-march=armv8-a+crc" for successful compilation of this file.
+ *
+ * @crc: previous accumulated CRC
+ * @buf: buffer base address
+ * @size: the size of the buffer
+ *
+ * Return calculated CRC value
+ */
+uint32_t hw_crc32(uint32_t crc, const unsigned char *buf, size_t size)
+{
+ assert(buf != NULL);
+
+ uint32_t calc_crc = ~crc;
+ const unsigned char *local_buf = buf;
+ size_t local_size = size;
+
+ /*
+ * calculate CRC over byte data
+ */
+ while (local_size != 0UL) {
+ calc_crc = __crc32b(calc_crc, *local_buf);
+ local_buf++;
+ local_size--;
+ }
+
+ return ~calc_crc;
+}