File Index
Files and directories
Sign in
FILE

memcpy.c

File preview with syntax highlighting.

linux-6.19.14/arch/parisc/lib/memcpy.c C
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 *    Optimized memory copy routines.
 4 *
 5 *    Copyright (C) 2004 Randolph Chung <tausq@debian.org>
 6 *    Copyright (C) 2013-2017 Helge Deller <deller@gmx.de>
 7 *
 8 *    Portions derived from the GNU C Library
 9 *    Copyright (C) 1991, 1997, 2003 Free Software Foundation, Inc.
10 */
11
12#include <linux/module.h>
13#include <linux/compiler.h>
14#include <linux/uaccess.h>
15#include <linux/mm.h>
16
17#define get_user_space()	mfsp(SR_USER)
18#define get_kernel_space()	SR_KERNEL
19
20/* Returns 0 for success, otherwise, returns number of bytes not transferred. */
21extern unsigned long pa_memcpy(void *dst, const void *src,
22				unsigned long len);
23
24unsigned long raw_copy_to_user(void __user *dst, const void *src,
25			       unsigned long len)
26{
27	mtsp(get_kernel_space(), SR_TEMP1);
28	mtsp(get_user_space(), SR_TEMP2);
29	return pa_memcpy((void __force *)dst, src, len);
30}
31EXPORT_SYMBOL(raw_copy_to_user);
32
33unsigned long raw_copy_from_user(void *dst, const void __user *src,
34			       unsigned long len)
35{
36	unsigned long start = (unsigned long) src;
37	unsigned long end = start + len;
38	unsigned long newlen = len;
39
40	mtsp(get_user_space(), SR_TEMP1);
41	mtsp(get_kernel_space(), SR_TEMP2);
42
43	/* Check region is user accessible */
44	while (start < end) {
45		if (!prober_user(SR_TEMP1, start)) {
46			newlen = (start - (unsigned long) src);
47			break;
48		}
49		start += PAGE_SIZE;
50		/* align to page boundry which may have different permission */
51		start = PAGE_ALIGN_DOWN(start);
52	}
53	return len - newlen + pa_memcpy(dst, (void __force *)src, newlen);
54}
55EXPORT_SYMBOL(raw_copy_from_user);
56
57void * memcpy(void * dst,const void *src, size_t count)
58{
59	mtsp(get_kernel_space(), SR_TEMP1);
60	mtsp(get_kernel_space(), SR_TEMP2);
61	pa_memcpy(dst, src, count);
62	return dst;
63}
64
65EXPORT_SYMBOL(memcpy);
66
67bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
68{
69	if ((unsigned long)unsafe_src < PAGE_SIZE)
70		return false;
71	/* check for I/O space F_EXTEND(0xfff00000) access as well? */
72	return true;
73}
~/ Read-only file preview.