Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2008-2009 PetaLogix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2007 John Williams
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Reasonably optimised generic C-code for memcpy on Microblaze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This is generic C code to do efficient, alignment-aware memcpy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * http://www.embedded.com/showArticle.jhtml?articleID=19205567
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Attempts were made, unsuccessfully, to contact the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * author of this code (Michael Morrow, Intel).  Below is the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * copyright notice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * This software has been developed by Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Intel specifically disclaims all warranties, express or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * implied, and all liability, including consequential and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * other indirect damages, for the use of this program, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * liability for infringement of any proprietary rights,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * and including the warranties of merchantability and fitness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * for a particular purpose. Intel does not assume any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * responsibility for and errors which may appear in this program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * not any responsibility to update it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #ifdef __HAVE_ARCH_MEMCPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #ifndef CONFIG_OPT_LIB_FUNCTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) void *memcpy(void *v_dst, const void *v_src, __kernel_size_t c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	const char *src = v_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	char *dst = v_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* Simple, byte oriented memcpy. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	while (c--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return v_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #else /* CONFIG_OPT_LIB_FUNCTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) void *memcpy(void *v_dst, const void *v_src, __kernel_size_t c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	const char *src = v_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	char *dst = v_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/* The following code tries to optimize the copy by using unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * alignment. This will work fine if both source and destination are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 * aligned on the same boundary. However, if they are aligned on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * different boundaries shifts will be necessary. This might result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * bad performance on MicroBlaze systems without a barrel shifter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	const uint32_t *i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	uint32_t *i_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (likely(c >= 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		unsigned  value, buf_hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		/* Align the destination to a word boundary. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		/* This is done in an endian independent manner. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		switch ((unsigned long)dst & 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			--c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			--c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			--c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		i_dst = (void *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		/* Choose a copy scheme based on the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		/* alignment relative to destination. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		switch ((unsigned long)src & 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		case 0x0:	/* Both byte offsets are aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			i_src  = (const void *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			for (; c >= 4; c -= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				*i_dst++ = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			src  = (const void *)i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		case 0x1:	/* Unaligned - Off by 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			/* Word align the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			i_src = (const void *) ((unsigned)src & ~3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #ifndef __MICROBLAZEEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			/* Load the holding buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			buf_hold = *i_src++ << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			for (; c >= 4; c -= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				value = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				*i_dst++ = buf_hold | value >> 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				buf_hold = value << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			/* Load the holding buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			buf_hold = (*i_src++ & 0xFFFFFF00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			for (; c >= 4; c -= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				value = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				*i_dst++ = buf_hold | ((value & 0xFF) << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				buf_hold = (value & 0xFFFFFF00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			/* Realign the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			src = (const void *)i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			src -= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		case 0x2:	/* Unaligned - Off by 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			/* Word align the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			i_src = (const void *) ((unsigned)src & ~3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #ifndef __MICROBLAZEEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			/* Load the holding buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			buf_hold = *i_src++ << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			for (; c >= 4; c -= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				value = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				*i_dst++ = buf_hold | value >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				buf_hold = value << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			/* Load the holding buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			buf_hold = (*i_src++ & 0xFFFF0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			for (; c >= 4; c -= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				value = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				*i_dst++ = buf_hold | ((value & 0xFFFF) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				buf_hold = (value & 0xFFFF0000) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			/* Realign the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			src = (const void *)i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			src -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		case 0x3:	/* Unaligned - Off by 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			/* Word align the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			i_src = (const void *) ((unsigned)src & ~3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #ifndef __MICROBLAZEEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			/* Load the holding buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			buf_hold = *i_src++ << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			for (; c >= 4; c -= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				value = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				*i_dst++ = buf_hold | value >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				buf_hold = value << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			/* Load the holding buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			buf_hold = (*i_src++ & 0xFF000000) >> 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			for (; c >= 4; c -= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				value = *i_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				*i_dst++ = buf_hold | ((value & 0xFFFFFF) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				buf_hold = (value & 0xFF000000) >> 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			/* Realign the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			src = (const void *)i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			src -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		dst = (void *)i_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Finish off any remaining bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* simple fast copy, ... unless a cache boundary is crossed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	switch (c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	return v_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #endif /* CONFIG_OPT_LIB_FUNCTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) EXPORT_SYMBOL(memcpy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #endif /* __HAVE_ARCH_MEMCPY */