From 465857f028489c7d3b009de37f1ec63c3ffb38e9 Mon Sep 17 00:00:00 2001 From: tsutsui Date: Fri, 11 Dec 2009 17:53:22 +0000 Subject: [PATCH] Refactoring MD segment related definitions on m68k ports: - move macro SEGSHIFT, NBSEG, and SEGOFSET from to where they should belong - also simplify NBSEG macro for both 020/030 and 040/060 cases - also move m68k_trunc_seg(), m68k_round_seg(), and m68k_seg_offset() (that use SEGOFSET) from to - add comments about each segment size value used on pmap_motorola implementation - add TIA_SIZE, TIA_SHIFT, TIB_SIZE, and TIB_SHIFT macro which can be used for ste/pte index sizes - use proper vaddr_t cast instead of unsigned for SEGOFSET/PGOFSET macro Tested on atari, hp300, and news68k. --- sys/arch/amiga/include/param.h | 9 +---- sys/arch/atari/include/param.h | 9 +---- sys/arch/cesfic/include/param.h | 13 +------ sys/arch/hp300/include/param.h | 13 +------ sys/arch/luna68k/include/param.h | 13 +------ sys/arch/m68k/include/param.h | 15 +++----- sys/arch/m68k/include/pmap_motorola.h | 53 ++++++++++++++++++++++++++- sys/arch/mac68k/include/param.h | 13 +------ sys/arch/mvme68k/include/param.h | 13 +------ sys/arch/news68k/include/param.h | 14 +------ sys/arch/next68k/include/param.h | 13 +------ sys/arch/x68k/include/param.h | 13 +------ 12 files changed, 68 insertions(+), 123 deletions(-) diff --git a/sys/arch/amiga/include/param.h b/sys/arch/amiga/include/param.h index eaaf5b2fec73..c2e5102c85ab 100644 --- a/sys/arch/amiga/include/param.h +++ b/sys/arch/amiga/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.46 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.47 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -88,13 +88,6 @@ #define PGSHIFT 13 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 24 /* LOG2(NBSEG) [68030 value] */ - -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) - /* bytes/segment */ -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include diff --git a/sys/arch/atari/include/param.h b/sys/arch/atari/include/param.h index a122fc07b6b4..0aa2c5bf2292 100644 --- a/sys/arch/atari/include/param.h +++ b/sys/arch/atari/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.32 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.33 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -88,13 +88,6 @@ #define PGSHIFT 13 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 24 /* LOG2(NBSEG) [68030 value] */ - -#define NBSEG ((mmutype == MMU_68040) \ - ? (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) - /* bytes/segment */ -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include diff --git a/sys/arch/cesfic/include/param.h b/sys/arch/cesfic/include/param.h index fd67b3e56266..e9ee7d5b9d26 100644 --- a/sys/arch/cesfic/include/param.h +++ b/sys/arch/cesfic/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.9 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.10 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -97,17 +97,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define NPTEPG (NBPG/(sizeof (pt_entry_t))) -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define KERNBASE 0x00002000 /* start of kernel virtual */ #define UPAGES 2 /* pages of u-area */ diff --git a/sys/arch/hp300/include/param.h b/sys/arch/hp300/include/param.h index 22204541fbea..ef4c9655debf 100644 --- a/sys/arch/hp300/include/param.h +++ b/sys/arch/hp300/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.50 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.51 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -88,17 +88,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include diff --git a/sys/arch/luna68k/include/param.h b/sys/arch/luna68k/include/param.h index d3a5c73d1555..e336c437d1ab 100644 --- a/sys/arch/luna68k/include/param.h +++ b/sys/arch/luna68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.9 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.10 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -85,17 +85,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include diff --git a/sys/arch/m68k/include/param.h b/sys/arch/m68k/include/param.h index 26417bb0c9fb..19b90bd6ac53 100644 --- a/sys/arch/m68k/include/param.h +++ b/sys/arch/m68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.15 2006/08/28 13:43:35 yamt Exp $ */ +/* $NetBSD: param.h,v 1.16 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -156,13 +156,10 @@ /* * Mach-derived conversion macros */ -#define m68k_round_seg(x) ((((unsigned)(x)) + SEGOFSET) & ~SEGOFSET) -#define m68k_trunc_seg(x) ((unsigned)(x) & ~SEGOFSET) -#define m68k_seg_offset(x) ((unsigned)(x) & SEGOFSET) -#define m68k_round_page(x) ((((unsigned)(x)) + PGOFSET) & ~PGOFSET) -#define m68k_trunc_page(x) ((unsigned)(x) & ~PGOFSET) -#define m68k_page_offset(x) ((unsigned)(x) & PGOFSET) -#define m68k_btop(x) ((unsigned)(x) >> PGSHIFT) -#define m68k_ptob(x) ((unsigned)(x) << PGSHIFT) +#define m68k_round_page(x) ((((vaddr_t)(x)) + PGOFSET) & ~PGOFSET) +#define m68k_trunc_page(x) ((vaddr_t)(x) & ~PGOFSET) +#define m68k_page_offset(x) ((vaddr_t)(x) & PGOFSET) +#define m68k_btop(x) ((vaddr_t)(x) >> PGSHIFT) +#define m68k_ptob(x) ((vaddr_t)(x) << PGSHIFT) #endif /* !_M68K_PARAM_H_ */ diff --git a/sys/arch/m68k/include/pmap_motorola.h b/sys/arch/m68k/include/pmap_motorola.h index 268e32b4dd1d..090bc1db6260 100644 --- a/sys/arch/m68k/include/pmap_motorola.h +++ b/sys/arch/m68k/include/pmap_motorola.h @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_motorola.h,v 1.25 2009/12/08 15:32:01 tsutsui Exp $ */ +/* $NetBSD: pmap_motorola.h,v 1.26 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1991, 1993 @@ -95,6 +95,57 @@ struct pmap { int pm_ptpages; /* more stats: PT pages */ }; +/* + * MMU specific segment values + * + * We are using following segment layout in m68k pmap_motorola.c: + * 68020/030 4KB/page: l1,l2,page == 10,10,12 (%tc = 0x82c0aa00) + * 68020/030 8KB/page: l1,l2,page == 8,11,13 (%tc = 0x82d08b00) + * 68040/060 4KB/page: l1,l2,l3,page == 7,7,6,12 + * 68040/060 8KB/page: l1,l2,l3,page == 7,7,5,13 + * + * 68020/030 l2 size is chosen per NPTEPG, a number of page table entries + * per page, to use one whole page for PTEs per one segment table entry, + * and maybe also because 68020 HP MMU machines use simlar structures. + * + * 68040/060 layout is defined by hardware design and not configurable, + * as defined in . + * + * Even on 68040/060, we still appropriate 2-level ste-pte pmap structures + * for 68020/030 (derived from 4.4BSD/hp300) to handle 040's 3-level MMU. + * TIA_SIZE and TIB_SIZE are used to represent such pmap structures and + * they are also refered on 040/060. + * + * NBSEG and SEGOFSET are used to check l2 STE of the specified VA, + * so they have different values between 020/030 and 040/060. + */ + /* 8KB / 4KB */ +#define TIB_SHIFT (PG_SHIFT - 2) /* 11 / 10 */ +#define TIB_SIZE (1U << TIB_SHIFT) /* 2048 / 1024 */ +#define TIA_SHIFT (32 - TIB_SHIFT - PG_SHIFT) /* 8 / 10 */ +#define TIA_SIZE (1U << TIA_SHIFT) /* 256 / 1024 */ + +#define SEGSHIFT (TIB_SHIFT + PG_SHIFT) /* 24 / 22 */ + +#define NBSEG30 (1U << SEGSHIFT) +#define NBSEG40 (1U << SG4_SHIFT2) + +#if ( defined(M68020) || defined(M68030)) && \ + (!defined(M68040) && !defined(M68060)) +#define NBSEG NBSEG30 +#elif ( defined(M68040) || defined(M68060)) && \ + (!defined(M68020) && !defined(M68030)) +#define NBSEG NBSEG40 +#else +#define NBSEG ((mmutype == MMU_68040) ? NBSEG40 : NBSEG30) +#endif + +#define SEGOFSET (NBSEG - 1) /* byte offset into segment */ + +#define m68k_round_seg(x) ((((vaddr_t)(x)) + SEGOFSET) & ~SEGOFSET) +#define m68k_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET) +#define m68k_seg_offset(x) ((vaddr_t)(x) & SEGOFSET) + /* * On the 040, we keep track of which level 2 blocks are already in use * with the pm_stfree mask. Bits are arranged from LSB (block 0) to MSB diff --git a/sys/arch/mac68k/include/param.h b/sys/arch/mac68k/include/param.h index 0895a13041bd..c57fad7991d3 100644 --- a/sys/arch/mac68k/include/param.h +++ b/sys/arch/mac68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.42 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.43 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1990 The Regents of the University of California. @@ -123,17 +123,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 3 /* pages of u-area */ #include diff --git a/sys/arch/mvme68k/include/param.h b/sys/arch/mvme68k/include/param.h index a0d79aeb51f8..49d4f3398f25 100644 --- a/sys/arch/mvme68k/include/param.h +++ b/sys/arch/mvme68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.30 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.31 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -95,17 +95,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include diff --git a/sys/arch/news68k/include/param.h b/sys/arch/news68k/include/param.h index 2f92792df2e1..11b3a0f984d7 100644 --- a/sys/arch/news68k/include/param.h +++ b/sys/arch/news68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.13 2009/12/09 12:21:58 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.14 2009/12/11 17:53:22 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -89,18 +89,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ - -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include diff --git a/sys/arch/next68k/include/param.h b/sys/arch/next68k/include/param.h index 50287e1e90f7..338371e03da2 100644 --- a/sys/arch/next68k/include/param.h +++ b/sys/arch/next68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.9 2009/12/09 12:21:59 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.10 2009/12/11 17:53:23 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -88,17 +88,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 3 /* pages of u-area */ #include diff --git a/sys/arch/x68k/include/param.h b/sys/arch/x68k/include/param.h index 03e20075fcaa..ec294939d81d 100644 --- a/sys/arch/x68k/include/param.h +++ b/sys/arch/x68k/include/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.25 2009/12/09 12:21:59 tsutsui Exp $ */ +/* $NetBSD: param.h,v 1.26 2009/12/11 17:53:23 tsutsui Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -88,17 +88,6 @@ #define PGSHIFT 12 /* LOG2(NBPG) */ #define KERNBASE 0x00000000 /* start of kernel virtual */ -#define SEGSHIFT 22 /* LOG2(NBSEG) */ -#if defined(M68030) && !defined(M68040) && !defined(M68060) -#define NBSEG (1 << SEGSHIFT) /* bytes/segment */ -#elif (defined(M68040) || defined(M68060)) && !defined(M68030) -#define NBSEG (1 << 18 /* SG4_SHIFT2 */) -#else -#define NBSEG ((mmutype == MMU_68040) ? \ - (1 << 18 /* SG4_SHIFT2 */) : (1 << SEGSHIFT)) -#endif -#define SEGOFSET (NBSEG-1) /* byte offset into segment */ - #define UPAGES 2 /* pages of u-area */ #include