Home | History | Annotate | Line # | Download | only in oea
      1  1.20       rin /*	$NetBSD: bat.h,v 1.20 2020/07/06 10:31:23 rin Exp $	*/
      2   1.1      matt 
      3   1.1      matt /*-
      4   1.1      matt  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5   1.1      matt  * All rights reserved.
      6   1.1      matt  *
      7   1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      matt  * by Jason R. Thorpe.
      9   1.1      matt  *
     10   1.1      matt  * Redistribution and use in source and binary forms, with or without
     11   1.1      matt  * modification, are permitted provided that the following conditions
     12   1.1      matt  * are met:
     13   1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14   1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15   1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      matt  *    documentation and/or other materials provided with the distribution.
     18   1.1      matt  *
     19   1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1      matt  */
     31   1.1      matt 
     32   1.1      matt /*
     33   1.1      matt  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     34   1.1      matt  * Copyright (C) 1995, 1996 TooLs GmbH.
     35   1.1      matt  * All rights reserved.
     36   1.1      matt  *
     37   1.1      matt  * Redistribution and use in source and binary forms, with or without
     38   1.1      matt  * modification, are permitted provided that the following conditions
     39   1.1      matt  * are met:
     40   1.1      matt  * 1. Redistributions of source code must retain the above copyright
     41   1.1      matt  *    notice, this list of conditions and the following disclaimer.
     42   1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     43   1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     44   1.1      matt  *    documentation and/or other materials provided with the distribution.
     45   1.1      matt  * 3. All advertising materials mentioning features or use of this software
     46   1.1      matt  *    must display the following acknowledgement:
     47   1.1      matt  *	This product includes software developed by TooLs GmbH.
     48   1.1      matt  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     49   1.1      matt  *    derived from this software without specific prior written permission.
     50   1.1      matt  *
     51   1.1      matt  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     52   1.1      matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     53   1.1      matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     54   1.1      matt  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     55   1.1      matt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     56   1.1      matt  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     57   1.1      matt  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     58   1.1      matt  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     59   1.1      matt  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     60   1.1      matt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     61   1.1      matt  */
     62   1.1      matt 
     63   1.1      matt #ifndef	_POWERPC_OEA_BAT_H_
     64   1.1      matt #define	_POWERPC_OEA_BAT_H_
     65   1.1      matt 
     66  1.13  nisimura #if defined(_KERNEL) && !defined(_LOCORE)
     67  1.19       rin 
     68  1.20       rin #ifdef _KERNEL_OPT
     69  1.20       rin #include "opt_ppcarch.h"
     70  1.20       rin #endif
     71  1.20       rin 
     72  1.14      matt #include <powerpc/psl.h>
     73  1.14      matt 
     74   1.1      matt struct bat {
     75   1.2      matt 	register_t batu;
     76   1.2      matt 	register_t batl;
     77  1.18       mrg } __aligned(8);
     78   1.5      matt #endif
     79   1.1      matt 
     80   1.1      matt /* Lower BAT bits (all but PowerPC 601): */
     81   1.3      matt #define	BAT_RPN		(~0x1ffff)	/* physical block start */
     82   1.6      matt #define	BAT_XPN		0x00000e00	/* eXtended physical page number (0-2) */
     83   1.1      matt #define	BAT_W		0x00000040	/* 1 = write-through, 0 = write-back */
     84   1.1      matt #define	BAT_I		0x00000020	/* cache inhibit */
     85   1.1      matt #define	BAT_M		0x00000010	/* memory coherency enable */
     86   1.1      matt #define	BAT_G		0x00000008	/* guarded region (not on 601) */
     87   1.6      matt #define	BAT_X		0x00000004	/* eXtended physical page number (3) */
     88  1.10      matt #define	BAT_WIMG	0x00000078	/* WIMG mask */
     89   1.6      matt 
     90   1.6      matt /*
     91   1.6      matt  * BAT_XPN and BAT_X are only used when HID0[XAEN] == 1 and are used
     92   1.6      matt  * to generate the 4 MSB of physical address
     93   1.6      matt  */
     94   1.1      matt 
     95   1.2      matt #define	BAT_PP		0x00000003	/* PP mask */
     96   1.1      matt #define	BAT_PP_NONE	0x00000000	/* no access permission */
     97   1.1      matt #define	BAT_PP_RO_S	0x00000001	/* read-only (soft) */
     98   1.1      matt #define	BAT_PP_RW	0x00000002	/* read/write */
     99   1.1      matt #define	BAT_PP_RO	0x00000003	/* read-only */
    100   1.1      matt 
    101   1.1      matt /* Upper BAT bits (all but PowerPC 601): */
    102   1.3      matt #define	BAT_EPI		(~0x1ffffL)	/* effective block start */
    103   1.1      matt #define	BAT_BL		0x00001ffc	/* block length */
    104   1.1      matt #define	BAT_Vs		0x00000002	/* valid in supervisor mode */
    105   1.1      matt #define	BAT_Vu		0x00000001	/* valid in user mode */
    106   1.1      matt 
    107   1.6      matt #define	BAT_XBL		0x0001e000	/* eXtended Block Length (*) */
    108   1.6      matt #define	BAT_XBL_512M	0x00002000	/* XBL for 512MB */
    109   1.6      matt #define	BAT_XBL_1G	0x00006000	/* XBL for 1GB */
    110   1.6      matt #define	BAT_XBL_2G	0x0000e000	/* XBL for 2GB */
    111   1.6      matt #define	BAT_XBL_4G	0x0001e000	/* XBL for 4GB */
    112   1.6      matt 
    113   1.1      matt #define	BAT_V		(BAT_Vs|BAT_Vu)
    114   1.1      matt 
    115   1.1      matt /* Block Length encoding (all but PowerPC 601): */
    116   1.1      matt #define	BAT_BL_128K	0x00000000
    117   1.1      matt #define	BAT_BL_256K	0x00000004
    118   1.1      matt #define	BAT_BL_512K	0x0000000c
    119   1.1      matt #define	BAT_BL_1M	0x0000001c
    120   1.1      matt #define	BAT_BL_2M	0x0000003c
    121   1.1      matt #define	BAT_BL_4M	0x0000007c
    122   1.1      matt #define	BAT_BL_8M	0x000000fc
    123   1.1      matt #define	BAT_BL_16M	0x000001fc
    124   1.1      matt #define	BAT_BL_32M	0x000003fc
    125   1.1      matt #define	BAT_BL_64M	0x000007fc
    126   1.1      matt #define	BAT_BL_128M	0x00000ffc
    127   1.1      matt #define	BAT_BL_256M	0x00001ffc
    128  1.10      matt /* Extended Block Lengths (7455+) */
    129  1.10      matt #define	BAT_BL_512M	0x00003ffc
    130  1.10      matt #define	BAT_BL_1G	0x00007ffc
    131  1.10      matt #define	BAT_BL_2G	0x0000fffc
    132  1.10      matt #define	BAT_BL_4G	0x0001fffc
    133   1.1      matt 
    134  1.15      matt #define	BAT_BL_TO_SIZE(bl)	(((bl)+4) << 15)
    135  1.15      matt 
    136   1.1      matt #define	BATU(va, len, v)						\
    137  1.16      matt 	(((va) & BAT_EPI) | ((len) & (BAT_BL|BAT_XBL)) | ((v) & BAT_V))
    138   1.1      matt 
    139   1.1      matt #define	BATL(pa, wimg, pp)						\
    140   1.2      matt 	(((pa) & BAT_RPN) | (wimg) | (pp))
    141   1.1      matt 
    142   1.1      matt #define BAT_VA_MATCH_P(batu,va) \
    143  1.17  macallan   (((~(((batu)&(BAT_BL|BAT_XBL))<<15))&(va)&BAT_EPI)==((batu)&BAT_EPI))
    144   1.1      matt 
    145   1.5      matt #define BAT_PA_MATCH_P(batu,batl,pa) \
    146  1.17  macallan   (((~(((batu)&(BAT_BL|BAT_XBL))<<15))&(pa)&BAT_RPN)==((batl)&BAT_RPN))
    147   1.5      matt 
    148   1.1      matt #define BAT_VALID_P(batu, msr) \
    149   1.1      matt   (((msr)&PSL_PR)?(((batu)&BAT_Vu)==BAT_Vu):(((batu)&BAT_Vs)==BAT_Vs))
    150   1.1      matt 
    151   1.1      matt /* Lower BAT bits (PowerPC 601): */
    152   1.1      matt #define	BAT601_PBN	0xfffe0000	/* physical block number */
    153   1.1      matt #define	BAT601_V	0x00000040	/* valid */
    154   1.1      matt #define	BAT601_BSM	0x0000003f	/* block size mask */
    155   1.1      matt 
    156   1.1      matt /* Upper BAT bits (PowerPC 601): */
    157   1.1      matt #define	BAT601_BLPI	0xfffe0000	/* block logical page index */
    158   1.1      matt #define	BAT601_W	0x00000040	/* 1 = write-through, 0 = write-back */
    159   1.1      matt #define	BAT601_I	0x00000020	/* cache inhibit */
    160   1.1      matt #define	BAT601_M	0x00000010	/* memory coherency enable */
    161   1.1      matt #define	BAT601_Ks	0x00000008	/* key-supervisor */
    162   1.1      matt #define	BAT601_Ku	0x00000004	/* key-user */
    163   1.1      matt 
    164   1.1      matt /*
    165   1.1      matt  * Permission bits on the PowerPC 601 are modified by the appropriate
    166   1.1      matt  * Key bit:
    167   1.1      matt  *
    168   1.1      matt  *	Key	PP	Access
    169   1.1      matt  *	0	NONE	read/write
    170   1.1      matt  *	0	RO_S	read/write
    171   1.1      matt  *	0	RW	read/write
    172   1.1      matt  *	0	RO	read-only
    173   1.1      matt  *
    174   1.1      matt  *	1	NONE	none
    175   1.1      matt  *	1	RO_S	read-only
    176   1.1      matt  *	1	RW	read/write
    177   1.1      matt  *	1	RO	read-only
    178   1.1      matt  */
    179   1.1      matt #define	BAT601_PP	0x00000003
    180   1.1      matt #define	BAT601_PP_NONE	0x00000000	/* no access permission */
    181   1.1      matt #define	BAT601_PP_RO_S	0x00000001	/* read-only (soft) */
    182   1.1      matt #define	BAT601_PP_RW	0x00000002	/* read/write */
    183   1.1      matt #define	BAT601_PP_RO	0x00000003	/* read-only */
    184   1.1      matt 
    185   1.1      matt /* Block Size Mask encoding (PowerPC 601): */
    186   1.1      matt #define	BAT601_BSM_128K	0x00000000
    187   1.1      matt #define	BAT601_BSM_256K	0x00000001
    188   1.1      matt #define	BAT601_BSM_512K	0x00000003
    189   1.1      matt #define	BAT601_BSM_1M	0x00000007
    190   1.1      matt #define	BAT601_BSM_2M	0x0000000f
    191   1.1      matt #define	BAT601_BSM_4M	0x0000001f
    192   1.1      matt #define	BAT601_BSM_8M	0x0000003f
    193   1.1      matt 
    194   1.1      matt #define	BATU601(va, wim, key, pp)					\
    195   1.1      matt 	(((va) & BAT601_BLPI) | (wim) | (key) | (pp))
    196   1.1      matt 
    197   1.1      matt #define	BATL601(pa, size, v)						\
    198   1.1      matt 	(((pa) & BAT601_PBN) | (v) | (size))
    199   1.1      matt 
    200   1.1      matt #define	BAT601_VA_MATCH_P(batu, batl, va)				\
    201   1.1      matt 	(((~(((batl)&BAT601_BSM)<<17))&(va)&BAT601_BLPI)==((batu)&BAT601_BLPI))
    202   1.1      matt 
    203   1.1      matt #define	BAT601_VALID_P(batl) \
    204   1.1      matt 	((batl) & BAT601_V)
    205   1.1      matt 
    206  1.15      matt #define	BAT_VA2IDX(va)	((va) / (8*1024*1024))
    207  1.15      matt #define	BAT_IDX2VA(i)	((i) * (8*1024*1024))
    208  1.11      matt 
    209  1.13  nisimura #if defined(_KERNEL) && !defined(_LOCORE)
    210   1.1      matt void oea_batinit(paddr_t, ...);
    211   1.1      matt void oea_iobat_add(paddr_t, register_t);
    212   1.4      matt void oea_iobat_remove(paddr_t);
    213   1.8   sanjayl 
    214   1.9   garbled #if !defined (PPC_OEA64)
    215   1.1      matt extern struct bat battable[];
    216   1.8   sanjayl #endif /* PPC_OEA */
    217   1.5      matt #endif
    218   1.1      matt 
    219   1.1      matt #endif	/* _POWERPC_OEA_BAT_H_ */
    220