xref: /freebsd/sys/arm/arm/sys_machdep.c (revision 4a144410)
16fc729afSOlivier Houchard /*-
26fc729afSOlivier Houchard  * Copyright (c) 1990 The Regents of the University of California.
36fc729afSOlivier Houchard  * All rights reserved.
46fc729afSOlivier Houchard  *
56fc729afSOlivier Houchard  * Redistribution and use in source and binary forms, with or without
66fc729afSOlivier Houchard  * modification, are permitted provided that the following conditions
76fc729afSOlivier Houchard  * are met:
86fc729afSOlivier Houchard  * 1. Redistributions of source code must retain the above copyright
96fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer.
106fc729afSOlivier Houchard  * 2. Redistributions in binary form must reproduce the above copyright
116fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer in the
126fc729afSOlivier Houchard  *    documentation and/or other materials provided with the distribution.
13f04f6877SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
146fc729afSOlivier Houchard  *    may be used to endorse or promote products derived from this software
156fc729afSOlivier Houchard  *    without specific prior written permission.
166fc729afSOlivier Houchard  *
176fc729afSOlivier Houchard  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
186fc729afSOlivier Houchard  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
196fc729afSOlivier Houchard  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
206fc729afSOlivier Houchard  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
216fc729afSOlivier Houchard  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
226fc729afSOlivier Houchard  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
236fc729afSOlivier Houchard  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
246fc729afSOlivier Houchard  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
256fc729afSOlivier Houchard  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
266fc729afSOlivier Houchard  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
276fc729afSOlivier Houchard  * SUCH DAMAGE.
286fc729afSOlivier Houchard  *
296fc729afSOlivier Houchard  *	from: @(#)sys_machdep.c	5.5 (Berkeley) 1/19/91
306fc729afSOlivier Houchard  */
316fc729afSOlivier Houchard 
326fc729afSOlivier Houchard #include <sys/cdefs.h>
336fc729afSOlivier Houchard __FBSDID("$FreeBSD$");
346fc729afSOlivier Houchard 
3524c1c3bfSJonathan Anderson #include "opt_capsicum.h"
3674b5505eSRobert Watson 
376fc729afSOlivier Houchard #include <sys/param.h>
386fc729afSOlivier Houchard #include <sys/systm.h>
394a144410SRobert Watson #include <sys/capsicum.h>
406fc729afSOlivier Houchard #include <sys/proc.h>
416fc729afSOlivier Houchard #include <sys/sysproto.h>
426fc729afSOlivier Houchard #include <sys/syscall.h>
436fc729afSOlivier Houchard #include <sys/sysent.h>
446fc729afSOlivier Houchard 
45371853e5SOlivier Houchard #include <machine/sysarch.h>
46371853e5SOlivier Houchard 
476fc729afSOlivier Houchard #ifndef _SYS_SYSPROTO_H_
486fc729afSOlivier Houchard struct sysarch_args {
496fc729afSOlivier Houchard 	int op;
506fc729afSOlivier Houchard 	char *parms;
516fc729afSOlivier Houchard };
526fc729afSOlivier Houchard #endif
536fc729afSOlivier Houchard 
54371853e5SOlivier Houchard /* Prototypes */
55371853e5SOlivier Houchard static int arm32_sync_icache (struct thread *, void *);
56371853e5SOlivier Houchard static int arm32_drain_writebuf(struct thread *, void *);
57371853e5SOlivier Houchard 
58371853e5SOlivier Houchard static int
59371853e5SOlivier Houchard arm32_sync_icache(struct thread *td, void *args)
60371853e5SOlivier Houchard {
61371853e5SOlivier Houchard 	struct arm_sync_icache_args ua;
62371853e5SOlivier Houchard 	int error;
63371853e5SOlivier Houchard 
64371853e5SOlivier Houchard 	if ((error = copyin(args, &ua, sizeof(ua))) != 0)
65371853e5SOlivier Houchard 		return (error);
66371853e5SOlivier Houchard 
67371853e5SOlivier Houchard 	cpu_icache_sync_range(ua.addr, ua.len);
68371853e5SOlivier Houchard 
69371853e5SOlivier Houchard 	td->td_retval[0] = 0;
70371853e5SOlivier Houchard 	return (0);
71371853e5SOlivier Houchard }
72371853e5SOlivier Houchard 
73371853e5SOlivier Houchard static int
74371853e5SOlivier Houchard arm32_drain_writebuf(struct thread *td, void *args)
75371853e5SOlivier Houchard {
76371853e5SOlivier Houchard 	/* No args. */
77371853e5SOlivier Houchard 
78371853e5SOlivier Houchard 	td->td_retval[0] = 0;
79371853e5SOlivier Houchard 	cpu_drain_writebuf();
80371853e5SOlivier Houchard 	return (0);
81371853e5SOlivier Houchard }
82371853e5SOlivier Houchard 
83a74985cdSOlivier Houchard static int
84a74985cdSOlivier Houchard arm32_set_tp(struct thread *td, void *args)
85a74985cdSOlivier Houchard {
86a74985cdSOlivier Houchard 
87cf1a573fSOleksandr Tymoshenko 	if (td != curthread)
88ae5b8077SWarner Losh 		td->td_md.md_tp = (register_t)args;
89cf1a573fSOleksandr Tymoshenko 	else
90cf1a573fSOleksandr Tymoshenko #ifndef ARM_TP_ADDRESS
91cf1a573fSOleksandr Tymoshenko 		set_tls(args);
92cf1a573fSOleksandr Tymoshenko #else
93cf1a573fSOleksandr Tymoshenko 		*(register_t *)ARM_TP_ADDRESS = (register_t)args;
94cf1a573fSOleksandr Tymoshenko #endif
95a74985cdSOlivier Houchard 	return (0);
96a74985cdSOlivier Houchard }
97a74985cdSOlivier Houchard 
98a74985cdSOlivier Houchard static int
99a74985cdSOlivier Houchard arm32_get_tp(struct thread *td, void *args)
100a74985cdSOlivier Houchard {
101a74985cdSOlivier Houchard 
102cf1a573fSOleksandr Tymoshenko 	if (td != curthread)
103ae5b8077SWarner Losh 		td->td_retval[0] = td->td_md.md_tp;
104cf1a573fSOleksandr Tymoshenko 	else
105cf1a573fSOleksandr Tymoshenko #ifndef ARM_TP_ADDRESS
106cf1a573fSOleksandr Tymoshenko 		td->td_retval[0] = (register_t)get_tls();
107cf1a573fSOleksandr Tymoshenko #else
108cf1a573fSOleksandr Tymoshenko 		td->td_retval[0] = *(register_t *)ARM_TP_ADDRESS;
109cf1a573fSOleksandr Tymoshenko #endif
110a74985cdSOlivier Houchard 	return (0);
111a74985cdSOlivier Houchard }
112a74985cdSOlivier Houchard 
1136fc729afSOlivier Houchard int
1146fc729afSOlivier Houchard sysarch(td, uap)
1156fc729afSOlivier Houchard 	struct thread *td;
1166fc729afSOlivier Houchard 	register struct sysarch_args *uap;
1176fc729afSOlivier Houchard {
118371853e5SOlivier Houchard 	int error;
119371853e5SOlivier Houchard 
12024c1c3bfSJonathan Anderson #ifdef CAPABILITY_MODE
12174b5505eSRobert Watson 	/*
12212bc222eSJonathan Anderson 	 * When adding new operations, add a new case statement here to
12312bc222eSJonathan Anderson 	 * explicitly indicate whether or not the operation is safe to
12412bc222eSJonathan Anderson 	 * perform in capability mode.
12574b5505eSRobert Watson 	 */
12674b5505eSRobert Watson 	if (IN_CAPABILITY_MODE(td)) {
12774b5505eSRobert Watson 		switch (uap->op) {
12874b5505eSRobert Watson 		case ARM_SYNC_ICACHE:
12974b5505eSRobert Watson 		case ARM_DRAIN_WRITEBUF:
13074b5505eSRobert Watson 		case ARM_SET_TP:
13174b5505eSRobert Watson 		case ARM_GET_TP:
13274b5505eSRobert Watson 			break;
13374b5505eSRobert Watson 
13474b5505eSRobert Watson 		default:
135a417d4a4SDag-Erling Smørgrav #ifdef KTRACE
136a417d4a4SDag-Erling Smørgrav 			if (KTRPOINT(td, KTR_CAPFAIL))
1373fded357SPawel Jakub Dawidek 				ktrcapfail(CAPFAIL_SYSCALL, NULL, NULL);
138a417d4a4SDag-Erling Smørgrav #endif
13974b5505eSRobert Watson 			return (ECAPMODE);
14074b5505eSRobert Watson 		}
14174b5505eSRobert Watson 	}
14274b5505eSRobert Watson #endif
14374b5505eSRobert Watson 
144371853e5SOlivier Houchard 	switch (uap->op) {
145371853e5SOlivier Houchard 	case ARM_SYNC_ICACHE:
146371853e5SOlivier Houchard 		error = arm32_sync_icache(td, uap->parms);
147371853e5SOlivier Houchard 		break;
148371853e5SOlivier Houchard 	case ARM_DRAIN_WRITEBUF:
149371853e5SOlivier Houchard 		error = arm32_drain_writebuf(td, uap->parms);
150371853e5SOlivier Houchard 		break;
151a74985cdSOlivier Houchard 	case ARM_SET_TP:
152a74985cdSOlivier Houchard 		error = arm32_set_tp(td, uap->parms);
153a74985cdSOlivier Houchard 		break;
154a74985cdSOlivier Houchard 	case ARM_GET_TP:
155a74985cdSOlivier Houchard 		error = arm32_get_tp(td, uap->parms);
156a74985cdSOlivier Houchard 		break;
157371853e5SOlivier Houchard 	default:
158371853e5SOlivier Houchard 		error = EINVAL;
159371853e5SOlivier Houchard 		break;
160371853e5SOlivier Houchard 	}
161371853e5SOlivier Houchard 	return (error);
1626fc729afSOlivier Houchard }
163