Home | History | Annotate | Line # | Download | only in arm32
sys_machdep.c revision 1.22.4.1
      1  1.22.4.1   bouyer /*	$NetBSD: sys_machdep.c,v 1.22.4.1 2017/04/21 16:53:23 bouyer Exp $	*/
      2       1.1     matt 
      3       1.1     matt /*
      4       1.1     matt  * Copyright (c) 1995-1997 Mark Brinicombe.
      5       1.1     matt  * All rights reserved.
      6       1.1     matt  *
      7       1.1     matt  * Redistribution and use in source and binary forms, with or without
      8       1.1     matt  * modification, are permitted provided that the following conditions
      9       1.1     matt  * are met:
     10       1.1     matt  * 1. Redistributions of source code must retain the above copyright
     11       1.1     matt  *    notice, this list of conditions and the following disclaimer.
     12       1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     14       1.1     matt  *    documentation and/or other materials provided with the distribution.
     15       1.1     matt  * 3. All advertising materials mentioning features or use of this software
     16       1.1     matt  *    must display the following acknowledgement:
     17       1.1     matt  *	This product includes software developed by Mark Brinicombe
     18       1.1     matt  * 4. The name of the company nor the name of the author may be used to
     19       1.1     matt  *    endorse or promote products derived from this software without specific
     20       1.1     matt  *    prior written permission.
     21       1.1     matt  *
     22       1.1     matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     23       1.1     matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     24       1.1     matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25       1.1     matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     26       1.1     matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27       1.1     matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28       1.1     matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.1     matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30       1.1     matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31       1.1     matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.1     matt  * SUCH DAMAGE.
     33       1.1     matt  *
     34       1.1     matt  * RiscBSD kernel project
     35       1.1     matt  *
     36       1.1     matt  * sys_machdep.c
     37       1.1     matt  *
     38      1.13      wiz  * Machine dependent syscalls
     39       1.1     matt  *
     40       1.1     matt  * Created      : 10/01/96
     41       1.1     matt  */
     42       1.6    lukem 
     43       1.6    lukem #include <sys/cdefs.h>
     44  1.22.4.1   bouyer __KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.22.4.1 2017/04/21 16:53:23 bouyer Exp $");
     45       1.1     matt 
     46       1.1     matt #include <sys/param.h>
     47       1.1     matt #include <sys/systm.h>
     48       1.1     matt #include <sys/proc.h>
     49       1.1     matt #include <sys/mbuf.h>
     50       1.1     matt #include <sys/mount.h>
     51      1.11      chs #include <sys/cpu.h>
     52       1.1     matt #include <uvm/uvm_extern.h>
     53       1.1     matt #include <sys/sysctl.h>
     54       1.1     matt #include <sys/syscallargs.h>
     55       1.1     matt 
     56       1.1     matt #include <machine/sysarch.h>
     57      1.15     matt #include <machine/pcb.h>
     58      1.15     matt #include <arm/vfpreg.h>
     59      1.17     matt #include <arm/locore.h>
     60       1.2    chris 
     61       1.2    chris /* Prototypes */
     62      1.10     matt static int arm32_sync_icache(struct lwp *, const void *, register_t *);
     63      1.10     matt static int arm32_drain_writebuf(struct lwp *, const void *, register_t *);
     64      1.15     matt static int arm32_vfp_fpscr(struct lwp *, const void *, register_t *);
     65      1.16     matt static int arm32_fpu_used(struct lwp *, const void *, register_t *);
     66       1.1     matt 
     67       1.1     matt static int
     68      1.10     matt arm32_sync_icache(struct lwp *l, const void *args, register_t *retval)
     69       1.1     matt {
     70       1.4  thorpej 	struct arm_sync_icache_args ua;
     71       1.1     matt 	int error;
     72       1.1     matt 
     73       1.1     matt 	if ((error = copyin(args, &ua, sizeof(ua))) != 0)
     74       1.1     matt 		return (error);
     75       1.1     matt 
     76      1.10     matt 	pmap_icache_sync_range(vm_map_pmap(&l->l_proc->p_vmspace->vm_map),
     77      1.10     matt 	    ua.addr, ua.addr + ua.len);
     78       1.1     matt 
     79       1.1     matt 	*retval = 0;
     80       1.1     matt 	return(0);
     81       1.1     matt }
     82       1.1     matt 
     83       1.1     matt static int
     84      1.10     matt arm32_drain_writebuf(struct lwp *l, const void *args, register_t *retval)
     85       1.1     matt {
     86       1.1     matt 	/* No args. */
     87       1.1     matt 
     88       1.1     matt 	cpu_drain_writebuf();
     89       1.1     matt 
     90       1.1     matt 	*retval = 0;
     91       1.1     matt 	return(0);
     92       1.1     matt }
     93       1.1     matt 
     94      1.15     matt static int
     95      1.15     matt arm32_vfp_fpscr(struct lwp *l, const void *uap, register_t *retval)
     96      1.15     matt {
     97      1.15     matt 	struct pcb * const pcb = lwp_getpcb(l);
     98      1.15     matt 
     99      1.15     matt #ifdef FPU_VFP
    100      1.15     matt 	/*
    101      1.15     matt 	 * Save the current VFP state (to make sure the FPSCR copy is
    102      1.15     matt 	 * up to date).
    103      1.15     matt 	 */
    104  1.22.4.1   bouyer 	vfp_savecontext(l);
    105      1.15     matt #endif
    106      1.15     matt 
    107      1.15     matt 	retval[0] = pcb->pcb_vfp.vfp_fpscr;
    108      1.15     matt 	if (uap) {
    109      1.20     matt 		extern uint32_t vfp_fpscr_changable;
    110      1.15     matt 		struct arm_vfp_fpscr_args ua;
    111      1.15     matt 		int error;
    112      1.15     matt 		if ((error = copyin(uap, &ua, sizeof(ua))) != 0)
    113      1.15     matt 			return (error);
    114      1.20     matt 		if ((ua.fpscr_clear|ua.fpscr_set) & ~vfp_fpscr_changable)
    115      1.15     matt 			return EINVAL;
    116      1.15     matt 		pcb->pcb_vfp.vfp_fpscr &= ~ua.fpscr_clear;
    117      1.15     matt 		pcb->pcb_vfp.vfp_fpscr |= ua.fpscr_set;
    118      1.15     matt 	}
    119      1.15     matt 
    120      1.15     matt 	return 0;
    121      1.15     matt }
    122      1.15     matt 
    123      1.16     matt static int
    124      1.16     matt arm32_fpu_used(struct lwp *l, const void *uap, register_t *retval)
    125      1.16     matt {
    126      1.16     matt 	/* No args */
    127      1.19     matt #ifdef FPU_VFP
    128  1.22.4.1   bouyer 	retval[0] = vfp_used_p(l);
    129      1.19     matt #else
    130      1.19     matt 	retval[0] = false;
    131      1.19     matt #endif
    132      1.16     matt 	return 0;
    133      1.16     matt }
    134      1.16     matt 
    135       1.1     matt int
    136       1.9      dsl sys_sysarch(struct lwp *l, const struct sys_sysarch_args *uap, register_t *retval)
    137       1.1     matt {
    138       1.9      dsl 	/* {
    139       1.1     matt 		syscallarg(int) op;
    140       1.1     matt 		syscallarg(void *) parms;
    141       1.9      dsl 	} */
    142       1.1     matt 	int error = 0;
    143       1.1     matt 
    144       1.1     matt 	switch(SCARG(uap, op)) {
    145       1.4  thorpej 	case ARM_SYNC_ICACHE :
    146      1.10     matt 		error = arm32_sync_icache(l, SCARG(uap, parms), retval);
    147       1.1     matt 		break;
    148       1.1     matt 
    149       1.4  thorpej 	case ARM_DRAIN_WRITEBUF :
    150      1.10     matt 		error = arm32_drain_writebuf(l, SCARG(uap, parms), retval);
    151       1.1     matt 		break;
    152       1.1     matt 
    153      1.15     matt 	case ARM_VFP_FPSCR :
    154      1.15     matt 		error = arm32_vfp_fpscr(l, SCARG(uap, parms), retval);
    155      1.15     matt 		break;
    156      1.15     matt 
    157      1.16     matt 	case ARM_FPU_USED :
    158      1.16     matt 		error = arm32_fpu_used(l, SCARG(uap, parms), retval);
    159      1.16     matt 		break;
    160      1.16     matt 
    161       1.1     matt 	default:
    162       1.1     matt 		error = EINVAL;
    163       1.1     matt 		break;
    164       1.1     matt 	}
    165       1.1     matt 	return (error);
    166       1.1     matt }
    167       1.1     matt 
    168      1.11      chs int
    169      1.11      chs cpu_lwp_setprivate(lwp_t *l, void *addr)
    170      1.11      chs {
    171      1.11      chs #ifdef _ARM_ARCH_6
    172      1.12     matt 	if (l == curlwp) {
    173      1.22    skrll 		u_int val = (u_int)addr;
    174      1.12     matt 		kpreempt_disable();
    175      1.22    skrll 		armreg_tpidruro_write(val);
    176      1.12     matt 		kpreempt_enable();
    177      1.12     matt 	}
    178      1.11      chs 	return 0;
    179      1.11      chs #else
    180      1.14    joerg 	return 0;
    181      1.11      chs #endif
    182      1.11      chs }
    183