From mboxrd@z Thu Jan 1 00:00:00 1970 From: Parth Dixit Subject: [PATCH v2 35/41] arm : acpi add helper function to calculate crc32 Date: Mon, 18 May 2015 01:34:02 +0530 Message-ID: <1431893048-5214-36-git-send-email-parth.dixit@linaro.org> References: <1431893048-5214-1-git-send-email-parth.dixit@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1431893048-5214-1-git-send-email-parth.dixit@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: keir@xen.org, ian.campbell@citrix.com, andrew.cooper3@citrix.com, tim@xen.org, julien.grall@citrix.com, stefano.stabellini@citrix.com, jbeulich@suse.com, parth.dixit@linaro.org, christoffer.dall@linaro.org List-Id: xen-devel@lists.xenproject.org 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 --- xen/arch/arm/domain_build.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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[]) { -- 1.9.1