diff mbox

[Xen-devel,v2,35/41] arm : acpi add helper function to calculate crc32

Message ID 1431893048-5214-36-git-send-email-parth.dixit@linaro.org
State New
Headers show

Commit Message

Parth Dixit May 17, 2015, 8:04 p.m. UTC
Add helper functions for calculating crc32.
This is required for computing crc of efi table.
These functions are copied from here
http://mirrors.neusoft.edu.cn/rpi-kernel/lib/xz/xz_crc32.c
Original author's are  Lasse Collin and Igor Pavlov.

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
---
 xen/arch/arm/domain_build.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Parth Dixit July 5, 2015, 1:33 p.m. UTC | #1
+shannon

On 8 June 2015 at 22:29, Julien Grall <julien.grall@citrix.com> wrote:
> Hi,
>
> On 17/05/2015 21:04, Parth Dixit wrote:
>>
>> Add helper functions for calculating crc32.
>> This is required for computing crc of efi table.
>> These functions are copied from here
>> http://mirrors.neusoft.edu.cn/rpi-kernel/lib/xz/xz_crc32.c
>> Original author's are  Lasse Collin and Igor Pavlov.
>
>
> I'm nearly sure this patch will break compilation during bisection...
>
> Anyway, the function xz_crc32_* already exist in the tree. Please use them.
>
> Regards,
>
> --
> Julien Grall
diff mbox

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 36b072b..0ad70c1 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1227,6 +1227,39 @@  static int handle_node(struct domain *d, struct kernel_info *kinfo,
 }
 #ifdef CONFIG_ACPI
 
+static uint32_t xz_crc32_table[256];
+
+static void xz_crc32_init(void)
+{
+	const uint32_t poly = 0xEDB88320;
+
+	uint32_t i;
+	uint32_t j;
+	uint32_t r;
+
+	for (i = 0; i < 256; ++i) {
+		r = i;
+		for (j = 0; j < 8; ++j)
+			r = (r >> 1) ^ (poly & ~((r & 1) - 1));
+
+		xz_crc32_table[i] = r;
+	}
+
+	return;
+}
+
+static uint32_t xz_crc32(uint8_t *buf, size_t size, uint32_t crc)
+{
+	crc = ~crc;
+
+	while (size != 0) {
+		crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
+		--size;
+	}
+
+	return ~crc;
+}
+
 static int create_xen_acpi_tables(struct kernel_info *kinfo, struct domain *d,
                                   struct membank tbl_add[])
 {