xref: /rk3399_ARM-atf/plat/xilinx/common/pm_service/pm_ipi.c (revision 01a326abeb1726b7756ef21a3c7188ca79a30e2e)
165c80d60SJolly Shah /*
2619bc13eSMichal Simek  * Copyright (c) 2013-2020, Arm Limited and Contributors. All rights reserved.
328ba1400SRajan Vaja  * Copyright (c) 2019-2022, Xilinx, Inc. All rights reserved.
4de7ed953SPrasad Kummari  * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
565c80d60SJolly Shah  *
665c80d60SJolly Shah  * SPDX-License-Identifier: BSD-3-Clause
765c80d60SJolly Shah  */
865c80d60SJolly Shah 
965c80d60SJolly Shah 
1065c80d60SJolly Shah #include <arch_helpers.h>
1165c80d60SJolly Shah #include <lib/bakery_lock.h>
1265c80d60SJolly Shah #include <lib/mmio.h>
130b3a2cf0SJay Buddhabhatti #include <lib/spinlock.h>
14*01a326abSPrasad Kummari #include <plat/common/platform.h>
15*01a326abSPrasad Kummari 
1665c80d60SJolly Shah #include <ipi.h>
1765c80d60SJolly Shah #include <plat_ipi.h>
1865c80d60SJolly Shah #include <plat_private.h>
1928ba1400SRajan Vaja #include "pm_defs.h"
2065c80d60SJolly Shah #include "pm_ipi.h"
2165c80d60SJolly Shah 
2215dc3e4fSHariBabu Gattem #define ERROR_CODE_MASK		(0xFFFFU)
23590519a8SHariBabu Gattem #define PM_OFFSET		(0U)
24addc4e96SRavi Patel 
250b3a2cf0SJay Buddhabhatti /*
260b3a2cf0SJay Buddhabhatti  * ARM v8.2, the cache will turn off automatically when cpu
270b3a2cf0SJay Buddhabhatti  * power down. Therefore, there is no doubt to use the spin_lock here.
280b3a2cf0SJay Buddhabhatti  */
290b3a2cf0SJay Buddhabhatti #if !HW_ASSISTED_COHERENCY
3065c80d60SJolly Shah DEFINE_BAKERY_LOCK(pm_secure_lock);
310b3a2cf0SJay Buddhabhatti static inline void pm_ipi_lock_get(void)
320b3a2cf0SJay Buddhabhatti {
330b3a2cf0SJay Buddhabhatti 	bakery_lock_get(&pm_secure_lock);
340b3a2cf0SJay Buddhabhatti }
350b3a2cf0SJay Buddhabhatti 
360b3a2cf0SJay Buddhabhatti static inline void pm_ipi_lock_release(void)
370b3a2cf0SJay Buddhabhatti {
380b3a2cf0SJay Buddhabhatti 	bakery_lock_release(&pm_secure_lock);
390b3a2cf0SJay Buddhabhatti }
400b3a2cf0SJay Buddhabhatti #else
410b3a2cf0SJay Buddhabhatti spinlock_t pm_secure_lock;
420b3a2cf0SJay Buddhabhatti static inline void pm_ipi_lock_get(void)
430b3a2cf0SJay Buddhabhatti {
440b3a2cf0SJay Buddhabhatti 	spin_lock(&pm_secure_lock);
450b3a2cf0SJay Buddhabhatti }
460b3a2cf0SJay Buddhabhatti 
470b3a2cf0SJay Buddhabhatti static inline void pm_ipi_lock_release(void)
480b3a2cf0SJay Buddhabhatti {
490b3a2cf0SJay Buddhabhatti 	spin_unlock(&pm_secure_lock);
500b3a2cf0SJay Buddhabhatti }
510b3a2cf0SJay Buddhabhatti #endif
5265c80d60SJolly Shah 
5365c80d60SJolly Shah /**
5465c80d60SJolly Shah  * pm_ipi_init() - Initialize IPI peripheral for communication with
55de7ed953SPrasad Kummari  *                 remote processor.
56de7ed953SPrasad Kummari  * @proc: Pointer to the processor who is initiating request.
5765c80d60SJolly Shah  *
58de7ed953SPrasad Kummari  * Return: On success, the initialization function must return 0.
5965c80d60SJolly Shah  *         Any other return value will cause the framework to ignore
60de7ed953SPrasad Kummari  *         the service.
6165c80d60SJolly Shah  *
62de7ed953SPrasad Kummari  * Called from pm_setup initialization function.
6365c80d60SJolly Shah  */
64590519a8SHariBabu Gattem void pm_ipi_init(const struct pm_proc *proc)
6565c80d60SJolly Shah {
6665c80d60SJolly Shah 	ipi_mb_open(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id);
6765c80d60SJolly Shah }
6865c80d60SJolly Shah 
6965c80d60SJolly Shah /**
70de7ed953SPrasad Kummari  * pm_ipi_send_common() - Sends IPI request to the remote processor.
71de7ed953SPrasad Kummari  * @proc: Pointer to the processor who is initiating request.
72de7ed953SPrasad Kummari  * @payload: API id and call arguments to be written in IPI buffer.
73de7ed953SPrasad Kummari  * @is_blocking: if to trigger the notification in blocking mode or not.
7465c80d60SJolly Shah  *
7565c80d60SJolly Shah  * Send an IPI request to the power controller. Caller needs to hold
7665c80d60SJolly Shah  * the 'pm_secure_lock' lock.
7765c80d60SJolly Shah  *
78de7ed953SPrasad Kummari  * Return: Returns status, either success or error+reason.
79de7ed953SPrasad Kummari  *
8065c80d60SJolly Shah  */
8165c80d60SJolly Shah static enum pm_ret_status pm_ipi_send_common(const struct pm_proc *proc,
8265c80d60SJolly Shah 					     uint32_t payload[PAYLOAD_ARG_CNT],
8365c80d60SJolly Shah 					     uint32_t is_blocking)
8465c80d60SJolly Shah {
85590519a8SHariBabu Gattem 	uint32_t offset = PM_OFFSET;
8665c80d60SJolly Shah 	uintptr_t buffer_base = proc->ipi->buffer_base +
8765c80d60SJolly Shah 					IPI_BUFFER_TARGET_REMOTE_OFFSET +
8865c80d60SJolly Shah 					IPI_BUFFER_REQ_OFFSET;
89d7758354SVenkatesh Yadav Abbarapu #if IPI_CRC_CHECK
90fe550edeSVenkatesh Yadav Abbarapu 	payload[PAYLOAD_CRC_POS] = calculate_crc(payload, IPI_W0_TO_W6_SIZE);
91fe550edeSVenkatesh Yadav Abbarapu #endif
9265c80d60SJolly Shah 
9365c80d60SJolly Shah 	/* Write payload into IPI buffer */
9465c80d60SJolly Shah 	for (size_t i = 0; i < PAYLOAD_ARG_CNT; i++) {
9565c80d60SJolly Shah 		mmio_write_32(buffer_base + offset, payload[i]);
9665c80d60SJolly Shah 		offset += PAYLOAD_ARG_SIZE;
9765c80d60SJolly Shah 	}
9865c80d60SJolly Shah 
9965c80d60SJolly Shah 	/* Generate IPI to remote processor */
10062f9134dSVenkatesh Yadav Abbarapu 	ipi_mb_notify(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id,
10165c80d60SJolly Shah 		      is_blocking);
10265c80d60SJolly Shah 
10362f9134dSVenkatesh Yadav Abbarapu 	return PM_RET_SUCCESS;
1044d9b9b23STejas Patel }
1054d9b9b23STejas Patel 
10665c80d60SJolly Shah /**
10765c80d60SJolly Shah  * pm_ipi_send_non_blocking() - Sends IPI request to the remote processor
108de7ed953SPrasad Kummari  *                              without blocking notification.
109de7ed953SPrasad Kummari  * @proc: Pointer to the processor who is initiating request.
110de7ed953SPrasad Kummari  * @payload: API id and call arguments to be written in IPI buffer.
11165c80d60SJolly Shah  *
11265c80d60SJolly Shah  * Send an IPI request to the power controller.
11365c80d60SJolly Shah  *
114de7ed953SPrasad Kummari  * Return: Returns status, either success or error+reason.
115de7ed953SPrasad Kummari  *
11665c80d60SJolly Shah  */
11765c80d60SJolly Shah enum pm_ret_status pm_ipi_send_non_blocking(const struct pm_proc *proc,
11865c80d60SJolly Shah 					    uint32_t payload[PAYLOAD_ARG_CNT])
11965c80d60SJolly Shah {
12065c80d60SJolly Shah 	enum pm_ret_status ret;
12165c80d60SJolly Shah 
1220b3a2cf0SJay Buddhabhatti 	pm_ipi_lock_get();
12365c80d60SJolly Shah 
12465c80d60SJolly Shah 	ret = pm_ipi_send_common(proc, payload, IPI_NON_BLOCKING);
12565c80d60SJolly Shah 
1260b3a2cf0SJay Buddhabhatti 	pm_ipi_lock_release();
12765c80d60SJolly Shah 
12865c80d60SJolly Shah 	return ret;
12965c80d60SJolly Shah }
13065c80d60SJolly Shah 
13165c80d60SJolly Shah /**
132de7ed953SPrasad Kummari  * pm_ipi_send() - Sends IPI request to the remote processor.
133de7ed953SPrasad Kummari  * @proc: Pointer to the processor who is initiating request.
134de7ed953SPrasad Kummari  * @payload: API id and call arguments to be written in IPI buffer.
13565c80d60SJolly Shah  *
13665c80d60SJolly Shah  * Send an IPI request to the power controller.
13765c80d60SJolly Shah  *
138de7ed953SPrasad Kummari  * Return: Returns status, either success or error+reason.
139de7ed953SPrasad Kummari  *
14065c80d60SJolly Shah  */
14165c80d60SJolly Shah enum pm_ret_status pm_ipi_send(const struct pm_proc *proc,
14265c80d60SJolly Shah 			       uint32_t payload[PAYLOAD_ARG_CNT])
14365c80d60SJolly Shah {
14465c80d60SJolly Shah 	enum pm_ret_status ret;
14565c80d60SJolly Shah 
1460b3a2cf0SJay Buddhabhatti 	pm_ipi_lock_get();
14765c80d60SJolly Shah 
14865c80d60SJolly Shah 	ret = pm_ipi_send_common(proc, payload, IPI_BLOCKING);
14965c80d60SJolly Shah 
1500b3a2cf0SJay Buddhabhatti 	pm_ipi_lock_release();
15165c80d60SJolly Shah 
15265c80d60SJolly Shah 	return ret;
15365c80d60SJolly Shah }
15465c80d60SJolly Shah 
15565c80d60SJolly Shah 
15665c80d60SJolly Shah /**
15765c80d60SJolly Shah  * pm_ipi_buff_read() - Reads IPI response after remote processor has handled
158de7ed953SPrasad Kummari  *                      interrupt.
159de7ed953SPrasad Kummari  * @proc: Pointer to the processor who is waiting and reading response.
160de7ed953SPrasad Kummari  * @value: Used to return value from IPI buffer element (optional).
161de7ed953SPrasad Kummari  * @count: Number of values to return in @value.
16265c80d60SJolly Shah  *
163de7ed953SPrasad Kummari  * Return: Returns status, either success or error+reason.
164de7ed953SPrasad Kummari  *
16565c80d60SJolly Shah  */
16665c80d60SJolly Shah static enum pm_ret_status pm_ipi_buff_read(const struct pm_proc *proc,
167ffa91031SVenkatesh Yadav Abbarapu 					   uint32_t *value, size_t count)
16865c80d60SJolly Shah {
16965c80d60SJolly Shah 	size_t i;
1705e92be51SNaman Trivedi Manojbhai 	enum pm_ret_status ret;
171d7758354SVenkatesh Yadav Abbarapu #if IPI_CRC_CHECK
1725e92be51SNaman Trivedi Manojbhai 	uint32_t *payload_ptr = value;
173fe550edeSVenkatesh Yadav Abbarapu 	size_t j;
174ffa91031SVenkatesh Yadav Abbarapu 	uint32_t response_payload[PAYLOAD_ARG_CNT];
175fe550edeSVenkatesh Yadav Abbarapu #endif
17665c80d60SJolly Shah 	uintptr_t buffer_base = proc->ipi->buffer_base +
17765c80d60SJolly Shah 				IPI_BUFFER_TARGET_REMOTE_OFFSET +
17865c80d60SJolly Shah 				IPI_BUFFER_RESP_OFFSET;
17965c80d60SJolly Shah 
18065c80d60SJolly Shah 	/*
18165c80d60SJolly Shah 	 * Read response from IPI buffer
18265c80d60SJolly Shah 	 * buf-0: success or error+reason
18365c80d60SJolly Shah 	 * buf-1: value
18465c80d60SJolly Shah 	 * buf-2: unused
18565c80d60SJolly Shah 	 * buf-3: unused
18665c80d60SJolly Shah 	 */
18765c80d60SJolly Shah 	for (i = 1; i <= count; i++) {
18865c80d60SJolly Shah 		*value = mmio_read_32(buffer_base + (i * PAYLOAD_ARG_SIZE));
18965c80d60SJolly Shah 		value++;
19065c80d60SJolly Shah 	}
1915e92be51SNaman Trivedi Manojbhai 
1925e92be51SNaman Trivedi Manojbhai 	ret = mmio_read_32(buffer_base);
193d7758354SVenkatesh Yadav Abbarapu #if IPI_CRC_CHECK
194eb0d2b17SVenkatesh Yadav Abbarapu 	for (j = 0; j < PAYLOAD_ARG_CNT; j++) {
195fe550edeSVenkatesh Yadav Abbarapu 		response_payload[j] = mmio_read_32(buffer_base +
196fe550edeSVenkatesh Yadav Abbarapu 						(j * PAYLOAD_ARG_SIZE));
197eb0d2b17SVenkatesh Yadav Abbarapu 	}
198fe550edeSVenkatesh Yadav Abbarapu 
199fe550edeSVenkatesh Yadav Abbarapu 	if (response_payload[PAYLOAD_CRC_POS] !=
200eb0d2b17SVenkatesh Yadav Abbarapu 			calculate_crc(response_payload, IPI_W0_TO_W6_SIZE)) {
201fe550edeSVenkatesh Yadav Abbarapu 		NOTICE("ERROR in CRC response payload value:0x%x\n",
202fe550edeSVenkatesh Yadav Abbarapu 					response_payload[PAYLOAD_CRC_POS]);
2035e92be51SNaman Trivedi Manojbhai 		ret = PM_RET_ERROR_INVALID_CRC;
2045e92be51SNaman Trivedi Manojbhai 		/* Payload data is invalid as CRC validation failed
2055e92be51SNaman Trivedi Manojbhai 		 * Clear the payload to avoid leakage of data to upper layers
2065e92be51SNaman Trivedi Manojbhai 		 */
2075e92be51SNaman Trivedi Manojbhai 		memset(payload_ptr, 0, count);
208eb0d2b17SVenkatesh Yadav Abbarapu 	}
209fe550edeSVenkatesh Yadav Abbarapu #endif
21065c80d60SJolly Shah 
2115e92be51SNaman Trivedi Manojbhai 	return ret;
21265c80d60SJolly Shah }
21365c80d60SJolly Shah 
21465c80d60SJolly Shah /**
215b96065a0SNaman Patel  * pm_ipi_buff_read_callb() - Callback function that reads value from
216de7ed953SPrasad Kummari  *                            ipi response buffer.
217de7ed953SPrasad Kummari  * @value: Used to return value from IPI buffer element.
218de7ed953SPrasad Kummari  * @count: Number of values to return in @value.
21965c80d60SJolly Shah  *
220b96065a0SNaman Patel  * This callback function fills requested data in @value from ipi response
221b96065a0SNaman Patel  * buffer.
222de7ed953SPrasad Kummari  *
223de7ed953SPrasad Kummari  * Return: Returns status, either success or error.
224de7ed953SPrasad Kummari  *
22565c80d60SJolly Shah  */
2266173d914SNaman Trivedi Manojbhai enum pm_ret_status pm_ipi_buff_read_callb(uint32_t *value, size_t count)
22765c80d60SJolly Shah {
22865c80d60SJolly Shah 	size_t i;
229d7758354SVenkatesh Yadav Abbarapu #if IPI_CRC_CHECK
2306173d914SNaman Trivedi Manojbhai 	uint32_t *payload_ptr = value;
231fe550edeSVenkatesh Yadav Abbarapu 	size_t j;
232590519a8SHariBabu Gattem 	unsigned int response_payload[PAYLOAD_ARG_CNT] = {0};
233fe550edeSVenkatesh Yadav Abbarapu #endif
23465c80d60SJolly Shah 	uintptr_t buffer_base = IPI_BUFFER_REMOTE_BASE +
23565c80d60SJolly Shah 				IPI_BUFFER_TARGET_LOCAL_OFFSET +
23665c80d60SJolly Shah 				IPI_BUFFER_REQ_OFFSET;
2376173d914SNaman Trivedi Manojbhai 	enum pm_ret_status ret = PM_RET_SUCCESS;
23865c80d60SJolly Shah 
239eb0d2b17SVenkatesh Yadav Abbarapu 	if (count > IPI_BUFFER_MAX_WORDS) {
24065c80d60SJolly Shah 		count = IPI_BUFFER_MAX_WORDS;
241eb0d2b17SVenkatesh Yadav Abbarapu 	}
24265c80d60SJolly Shah 
24365c80d60SJolly Shah 	for (i = 0; i <= count; i++) {
24465c80d60SJolly Shah 		*value = mmio_read_32(buffer_base + (i * PAYLOAD_ARG_SIZE));
24565c80d60SJolly Shah 		value++;
24665c80d60SJolly Shah 	}
247d7758354SVenkatesh Yadav Abbarapu #if IPI_CRC_CHECK
248eb0d2b17SVenkatesh Yadav Abbarapu 	for (j = 0; j < PAYLOAD_ARG_CNT; j++) {
249fe550edeSVenkatesh Yadav Abbarapu 		response_payload[j] = mmio_read_32(buffer_base +
250fe550edeSVenkatesh Yadav Abbarapu 						(j * PAYLOAD_ARG_SIZE));
251eb0d2b17SVenkatesh Yadav Abbarapu 	}
252fe550edeSVenkatesh Yadav Abbarapu 
253fe550edeSVenkatesh Yadav Abbarapu 	if (response_payload[PAYLOAD_CRC_POS] !=
254eb0d2b17SVenkatesh Yadav Abbarapu 			calculate_crc(response_payload, IPI_W0_TO_W6_SIZE)) {
255fe550edeSVenkatesh Yadav Abbarapu 		NOTICE("ERROR in CRC response payload value:0x%x\n",
256fe550edeSVenkatesh Yadav Abbarapu 					response_payload[PAYLOAD_CRC_POS]);
2576173d914SNaman Trivedi Manojbhai 		ret = PM_RET_ERROR_INVALID_CRC;
2586173d914SNaman Trivedi Manojbhai 		/* Payload data is invalid as CRC validation failed
2596173d914SNaman Trivedi Manojbhai 		 * Clear the payload to avoid leakage of data to upper layers
2606173d914SNaman Trivedi Manojbhai 		 */
2616173d914SNaman Trivedi Manojbhai 		memset(payload_ptr, 0, count);
262eb0d2b17SVenkatesh Yadav Abbarapu 	}
263fe550edeSVenkatesh Yadav Abbarapu #endif
2646173d914SNaman Trivedi Manojbhai 	return ret;
26565c80d60SJolly Shah }
26665c80d60SJolly Shah 
26765c80d60SJolly Shah /**
268de7ed953SPrasad Kummari  * pm_ipi_send_sync() - Sends IPI request to the remote processor.
269de7ed953SPrasad Kummari  * @proc: Pointer to the processor who is initiating request.
270de7ed953SPrasad Kummari  * @payload: API id and call arguments to be written in IPI buffer.
271de7ed953SPrasad Kummari  * @value: Used to return value from IPI buffer element (optional).
272de7ed953SPrasad Kummari  * @count: Number of values to return in @value.
27365c80d60SJolly Shah  *
27465c80d60SJolly Shah  * Send an IPI request to the power controller and wait for it to be handled.
27565c80d60SJolly Shah  *
276de7ed953SPrasad Kummari  * Return: Returns status, either success or error+reason and, optionally,
277de7ed953SPrasad Kummari  *         @value.
278de7ed953SPrasad Kummari  *
27965c80d60SJolly Shah  */
28065c80d60SJolly Shah enum pm_ret_status pm_ipi_send_sync(const struct pm_proc *proc,
28165c80d60SJolly Shah 				    uint32_t payload[PAYLOAD_ARG_CNT],
282ffa91031SVenkatesh Yadav Abbarapu 				    uint32_t *value, size_t count)
28365c80d60SJolly Shah {
28465c80d60SJolly Shah 	enum pm_ret_status ret;
28565c80d60SJolly Shah 
2860b3a2cf0SJay Buddhabhatti 	pm_ipi_lock_get();
28765c80d60SJolly Shah 
28865c80d60SJolly Shah 	ret = pm_ipi_send_common(proc, payload, IPI_BLOCKING);
289eb0d2b17SVenkatesh Yadav Abbarapu 	if (ret != PM_RET_SUCCESS) {
29065c80d60SJolly Shah 		goto unlock;
291eb0d2b17SVenkatesh Yadav Abbarapu 	}
29265c80d60SJolly Shah 
293addc4e96SRavi Patel 	ret = ERROR_CODE_MASK & (pm_ipi_buff_read(proc, value, count));
29465c80d60SJolly Shah 
29565c80d60SJolly Shah unlock:
2960b3a2cf0SJay Buddhabhatti 	pm_ipi_lock_release();
29765c80d60SJolly Shah 
29865c80d60SJolly Shah 	return ret;
29965c80d60SJolly Shah }
30065c80d60SJolly Shah 
30165c80d60SJolly Shah void pm_ipi_irq_enable(const struct pm_proc *proc)
30265c80d60SJolly Shah {
30365c80d60SJolly Shah 	ipi_mb_enable_irq(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id);
30465c80d60SJolly Shah }
30565c80d60SJolly Shah 
30665c80d60SJolly Shah void pm_ipi_irq_clear(const struct pm_proc *proc)
30765c80d60SJolly Shah {
30865c80d60SJolly Shah 	ipi_mb_ack(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id);
30965c80d60SJolly Shah }
31065c80d60SJolly Shah 
31165c80d60SJolly Shah uint32_t pm_ipi_irq_status(const struct pm_proc *proc)
31265c80d60SJolly Shah {
313ffa91031SVenkatesh Yadav Abbarapu 	int32_t ret;
31465c80d60SJolly Shah 
31565c80d60SJolly Shah 	ret = ipi_mb_enquire_status(proc->ipi->local_ipi_id,
31665c80d60SJolly Shah 				    proc->ipi->remote_ipi_id);
317eb0d2b17SVenkatesh Yadav Abbarapu 	if (ret & IPI_MB_STATUS_RECV_PENDING) {
31865c80d60SJolly Shah 		return 1;
319eb0d2b17SVenkatesh Yadav Abbarapu 	} else {
32065c80d60SJolly Shah 		return 0;
32165c80d60SJolly Shah 	}
322eb0d2b17SVenkatesh Yadav Abbarapu }
323fe550edeSVenkatesh Yadav Abbarapu 
324d7758354SVenkatesh Yadav Abbarapu #if IPI_CRC_CHECK
32581333eacSVenkatesh Yadav Abbarapu uint32_t calculate_crc(uint32_t payload[PAYLOAD_ARG_CNT], uint32_t bufsize)
326fe550edeSVenkatesh Yadav Abbarapu {
327fe550edeSVenkatesh Yadav Abbarapu 	uint32_t crcinit = CRC_INIT_VALUE;
328fe550edeSVenkatesh Yadav Abbarapu 	uint32_t order   = CRC_ORDER;
329fe550edeSVenkatesh Yadav Abbarapu 	uint32_t polynom = CRC_POLYNOM;
330fe550edeSVenkatesh Yadav Abbarapu 	uint32_t i, j, c, bit, datain, crcmask, crchighbit;
331fe550edeSVenkatesh Yadav Abbarapu 	uint32_t crc = crcinit;
332fe550edeSVenkatesh Yadav Abbarapu 
333fe550edeSVenkatesh Yadav Abbarapu 	crcmask = ((uint32_t)((1U << (order - 1U)) - 1U) << 1U) | 1U;
334fe550edeSVenkatesh Yadav Abbarapu 	crchighbit = (uint32_t)(1U << (order - 1U));
335fe550edeSVenkatesh Yadav Abbarapu 
336fe550edeSVenkatesh Yadav Abbarapu 	for (i = 0U; i < bufsize; i++) {
337fe550edeSVenkatesh Yadav Abbarapu 		datain = mmio_read_8((unsigned long)payload + i);
338fe550edeSVenkatesh Yadav Abbarapu 		c = datain;
339fe550edeSVenkatesh Yadav Abbarapu 		j = 0x80U;
340fe550edeSVenkatesh Yadav Abbarapu 		while (j != 0U) {
341fe550edeSVenkatesh Yadav Abbarapu 			bit = crc & crchighbit;
342fe550edeSVenkatesh Yadav Abbarapu 			crc <<= 1U;
343fe550edeSVenkatesh Yadav Abbarapu 			if (0U != (c & j))
344fe550edeSVenkatesh Yadav Abbarapu 				bit ^= crchighbit;
345fe550edeSVenkatesh Yadav Abbarapu 			if (bit != 0U)
346fe550edeSVenkatesh Yadav Abbarapu 				crc ^= polynom;
347fe550edeSVenkatesh Yadav Abbarapu 			j >>= 1U;
348fe550edeSVenkatesh Yadav Abbarapu 		}
349fe550edeSVenkatesh Yadav Abbarapu 		crc &= crcmask;
350fe550edeSVenkatesh Yadav Abbarapu 	}
351fe550edeSVenkatesh Yadav Abbarapu 	return crc;
352fe550edeSVenkatesh Yadav Abbarapu }
353fe550edeSVenkatesh Yadav Abbarapu #endif
354