Home | History | Annotate | Line # | Download | only in include
cpufunc.h revision 1.8.18.1
      1 /*	$NetBSD: cpufunc.h,v 1.8.18.1 2008/01/06 05:00:55 wrstuden Exp $	*/
      2 
      3 /*	$OpenBSD: cpufunc.h,v 1.17 2000/05/15 17:22:40 mickey Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1998,2000 Michael Shalayeff
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by Michael Shalayeff.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 /*
     35  *  (c) Copyright 1988 HEWLETT-PACKARD COMPANY
     36  *
     37  *  To anyone who acknowledges that this file is provided "AS IS"
     38  *  without any express or implied warranty:
     39  *      permission to use, copy, modify, and distribute this file
     40  *  for any purpose is hereby granted without fee, provided that
     41  *  the above copyright notice and this notice appears in all
     42  *  copies, and that the name of Hewlett-Packard Company not be
     43  *  used in advertising or publicity pertaining to distribution
     44  *  of the software without specific, written prior permission.
     45  *  Hewlett-Packard Company makes no representations about the
     46  *  suitability of this software for any purpose.
     47  */
     48 /*
     49  * Copyright (c) 1990,1994 The University of Utah and
     50  * the Computer Systems Laboratory (CSL).  All rights reserved.
     51  *
     52  * THE UNIVERSITY OF UTAH AND CSL PROVIDE THIS SOFTWARE IN ITS "AS IS"
     53  * CONDITION, AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
     54  * WHATSOEVER RESULTING FROM ITS USE.
     55  *
     56  * CSL requests users of this software to return to csl-dist (at) cs.utah.edu any
     57  * improvements that they make and grant CSL redistribution rights.
     58  *
     59  * 	Utah $Hdr: c_support.s 1.8 94/12/14$
     60  *	Author: Bob Wheeler, University of Utah CSL
     61  */
     62 
     63 #ifndef _HPPA_CPUFUNC_H_
     64 #define _HPPA_CPUFUNC_H_
     65 
     66 #include <machine/psl.h>
     67 #include <machine/pte.h>
     68 
     69 #define tlbbtop(b) ((b) >> (PGSHIFT - 5))
     70 #define tlbptob(p) ((p) << (PGSHIFT - 5))
     71 
     72 #define hptbtop(b) ((b) >> 17)
     73 
     74 /* Get space register for an address */
     75 static __inline register_t ldsid(vaddr_t p) {
     76 	register_t ret;
     77 	__asm volatile("ldsid (%1),%0" : "=r" (ret) : "r" (p));
     78 	return ret;
     79 }
     80 
     81 #define mtctl(v,r) __asm volatile("mtctl %0,%1":: "r" (v), "i" (r))
     82 #define mfctl(r,v) __asm volatile("mfctl %1,%0": "=r" (v): "i" (r))
     83 
     84 #define mfcpu(r,v)	/* XXX for the lack of the mnemonics */		\
     85 	__asm volatile("diag  %1\n\t"					\
     86 			 "copy  %%r22, %0"				\
     87 	: "=r" (v) : "i" ((0x1400 | ((r) << 21) | (22))) : "r22")
     88 
     89 #define mtsp(v,r) __asm volatile("mtsp %0,%1":: "r" (v), "i" (r))
     90 #define mfsp(r,v) __asm volatile("mfsp %1,%0": "=r" (v): "i" (r))
     91 
     92 #define ssm(v,r) __asm volatile("ssm %1,%0": "=r" (r): "i" (v))
     93 #define rsm(v,r) __asm volatile("rsm %1,%0": "=r" (r): "i" (v))
     94 
     95 /* Move to system mask. Old value of system mask is returned. */
     96 static __inline register_t mtsm(register_t mask) {
     97 	register_t ret;
     98 	__asm volatile("ssm 0,%0\n\t"
     99 			 "mtsm %1": "=&r" (ret) : "r" (mask));
    100 	return ret;
    101 }
    102 
    103 #define	fdce(sp,off) __asm volatile("fdce 0(%0,%1)":: "i" (sp), "r" (off))
    104 #define	fice(sp,off) __asm volatile("fice 0(%0,%1)":: "i" (sp), "r" (off))
    105 #define sync_caches() \
    106     __asm volatile("sync\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop":::"memory")
    107 
    108 static __inline void
    109 iitlba(u_int pg, pa_space_t sp, vaddr_t va)
    110 {
    111 	mtsp(sp, 1);
    112 	__asm volatile("iitlba %0,(%%sr1, %1)":: "r" (pg), "r" (va));
    113 }
    114 
    115 static __inline void
    116 idtlba(u_int pg, pa_space_t sp, vaddr_t va)
    117 {
    118 	mtsp(sp, 1);
    119 	__asm volatile("idtlba %0,(%%sr1, %1)":: "r" (pg), "r" (va));
    120 }
    121 
    122 static __inline void
    123 iitlbp(u_int prot, pa_space_t sp, vaddr_t va)
    124 {
    125 	mtsp(sp, 1);
    126 	__asm volatile("iitlbp %0,(%%sr1, %1)":: "r" (prot), "r" (va));
    127 }
    128 
    129 static __inline void
    130 idtlbp(u_int prot, pa_space_t sp, vaddr_t va)
    131 {
    132 	mtsp(sp, 1);
    133 	__asm volatile("idtlbp %0,(%%sr1, %1)":: "r" (prot), "r" (va));
    134 }
    135 
    136 static __inline void
    137 pitlb(pa_space_t sp, vaddr_t va)
    138 {
    139 	mtsp(sp, 1);
    140 	__asm volatile("pitlb %%r0(%%sr1, %0)":: "r" (va));
    141 }
    142 
    143 static __inline void
    144 pdtlb(pa_space_t sp, vaddr_t va)
    145 {
    146 	mtsp(sp, 1);
    147 	__asm volatile("pdtlb %%r0(%%sr1, %0)":: "r" (va));
    148 }
    149 
    150 static __inline void
    151 pitlbe(pa_space_t sp, vaddr_t va)
    152 {
    153 	mtsp(sp, 1);
    154 	__asm volatile("pitlbe %%r0(%%sr1, %0)":: "r" (va));
    155 }
    156 
    157 static __inline void
    158 pdtlbe(pa_space_t sp, vaddr_t va)
    159 {
    160 	mtsp(sp, 1);
    161 	__asm volatile("pdtlbe %%r0(%%sr1, %0)":: "r" (va));
    162 }
    163 
    164 #ifdef _KERNEL
    165 void ficache __P((pa_space_t sp, vaddr_t va, vsize_t size));
    166 void fdcache __P((pa_space_t sp, vaddr_t va, vsize_t size));
    167 void pdcache __P((pa_space_t sp, vaddr_t va, vsize_t size));
    168 void fcacheall __P((void));
    169 void ptlball __P((void));
    170 hppa_hpa_t cpu_gethpa __P((int n));
    171 
    172 #define PCXL2_ACCEL_IO_START		0xf4000000
    173 #define PCXL2_ACCEL_IO_END		(0xfc000000 - 1)
    174 #define PCXL2_ACCEL_IO_ADDR2MASK(a)	(0x8 >> ((((a) >> 25) - 2) & 3))
    175 void eaio_l2(int);
    176 
    177 /*
    178  * These flush or purge the data cache for a item whose total
    179  * size is <= the size of a data cache line, however they don't
    180  * check this constraint.
    181  */
    182 static __inline void
    183 fdcache_small(pa_space_t sp, vaddr_t va, vsize_t size)
    184 {
    185 	__asm volatile(
    186 		"	mtsp	%0,%%sr1		\n"
    187 		"	fdc	%%r0(%%sr1, %1)		\n"
    188 		"	fdc	%2(%%sr1, %1)		\n"
    189 		"	sync				\n"
    190 		"	syncdma				\n"
    191 		:
    192 		: "r" (sp), "r" (va), "r" (size - 1));
    193 }
    194 static __inline void
    195 pdcache_small(pa_space_t sp, vaddr_t va, vsize_t size)
    196 {
    197 	__asm volatile(
    198 		"	mtsp	%0,%%sr1		\n"
    199 		"	pdc	%%r0(%%sr1, %1)		\n"
    200 		"	pdc	%2(%%sr1, %1)		\n"
    201 		"	sync				\n"
    202 		"	syncdma				\n"
    203 		:
    204 		: "r" (sp), "r" (va), "r" (size - 1));
    205 }
    206 
    207 #endif /* _KERNEL */
    208 
    209 #endif /* _HPPA_CPUFUNC_H_ */
    210