xref: /csrg-svn/sys/luna68k/include/pmap.h (revision 65041)
153975Sfujita /*
253975Sfujita  * Copyright (c) 1987 Carnegie-Mellon University
353975Sfujita  * Copyright (c) 1992 OMRON Corporation.
463194Sbostic  * Copyright (c) 1991, 1992, 1993
563194Sbostic  *	The Regents of the University of California.  All rights reserved.
653975Sfujita  *
753975Sfujita  * This code is derived from software contributed to Berkeley by
853975Sfujita  * the Systems Programming Group of the University of Utah Computer
953975Sfujita  * Science Department.
1053975Sfujita  *
1153975Sfujita  * %sccs.include.redist.c%
1253975Sfujita  *
13*65041Sakito  * from: hp300/include/pmap.h	7.13 (Berkeley) 6/2/93
1453975Sfujita  *
15*65041Sakito  *	@(#)pmap.h	8.2 (Berkeley) 12/06/93
1653975Sfujita  */
1753975Sfujita 
1853975Sfujita #ifndef	_PMAP_MACHINE_
1953975Sfujita #define	_PMAP_MACHINE_
2053975Sfujita 
2153975Sfujita #define LUNA_PAGE_SIZE	NBPG
2259944Sakito #if defined(LUNA2)
2359944Sakito #define LUNA_SEG_SIZE	(mmutype == MMU_68040 ? 0x40000 : NBSEG)
2459944Sakito #else
2553975Sfujita #define LUNA_SEG_SIZE	NBSEG
2659944Sakito #endif
2753975Sfujita 
2853975Sfujita #define luna_trunc_seg(x)	(((unsigned)(x)) & ~(LUNA_SEG_SIZE-1))
2953975Sfujita #define luna_round_seg(x)	luna_trunc_seg((unsigned)(x) + LUNA_SEG_SIZE-1)
3053975Sfujita 
3153975Sfujita /*
3253975Sfujita  * Pmap stuff
3353975Sfujita  */
3453975Sfujita struct pmap {
3553975Sfujita 	struct pte		*pm_ptab;	/* KVA of page table */
3653975Sfujita 	struct ste		*pm_stab;	/* KVA of segment table */
3753975Sfujita 	int			pm_stchanged;	/* ST changed */
3853975Sfujita 	int			pm_stfree;	/* 040: free lev2 blocks */
3953975Sfujita 	struct ste		*pm_stpa;	/* 040: ST phys addr */
4053975Sfujita 	short			pm_sref;	/* segment table ref count */
4153975Sfujita 	short			pm_count;	/* pmap reference count */
4253975Sfujita 	simple_lock_data_t	pm_lock;	/* lock on pmap */
4353975Sfujita 	struct pmap_statistics	pm_stats;	/* pmap statistics */
4453975Sfujita 	long			pm_ptpages;	/* more stats: PT pages */
4553975Sfujita };
4653975Sfujita 
4753975Sfujita typedef struct pmap	*pmap_t;
4853975Sfujita 
4953975Sfujita extern struct pmap	kernel_pmap_store;
5053975Sfujita 
5157396Sakito #define kernel_pmap	(&kernel_pmap_store)
5257396Sakito #define	active_pmap(pm) \
5357396Sakito 	((pm) == kernel_pmap || (pm) == curproc->p_vmspace->vm_map.pmap)
5457396Sakito 
5553975Sfujita /*
5653975Sfujita  * On the 040 we keep track of which level 2 blocks are already in use
5753975Sfujita  * with the pm_stfree mask.  Bits are arranged from LSB (block 0) to MSB
5853975Sfujita  * (block 31).  For convenience, the level 1 table is considered to be
5953975Sfujita  * block 0.
6053975Sfujita  *
6153975Sfujita  * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed.
6253975Sfujita  * for the kernel and users.  8 implies only the initial "segment table"
6353975Sfujita  * page is used.  WARNING: don't change MAXUL2SIZE unless you can allocate
6453975Sfujita  * physically contiguous pages for the ST in pmap.c!
6553975Sfujita  */
6653975Sfujita #define	MAXKL2SIZE	16
6753975Sfujita #define MAXUL2SIZE	8
6853975Sfujita #define l2tobm(n)	(1 << (n))
6953975Sfujita #define	bmtol2(n)	(ffs(n) - 1)
7053975Sfujita 
7153975Sfujita /*
7253975Sfujita  * Macros for speed
7353975Sfujita  */
7453975Sfujita #define PMAP_ACTIVATE(pmapp, pcbp, iscurproc) \
7553975Sfujita 	if ((pmapp) != NULL && (pmapp)->pm_stchanged) { \
7654577Sfujita 		(pcbp)->pcb_ustp = luna_btop((vm_offset_t)(pmapp)->pm_stpa); \
7753975Sfujita 		if (iscurproc) \
7853975Sfujita 			loadustp((pcbp)->pcb_ustp); \
7953975Sfujita 		(pmapp)->pm_stchanged = FALSE; \
8053975Sfujita 	}
8153975Sfujita #define PMAP_DEACTIVATE(pmapp, pcbp)
8253975Sfujita 
8353975Sfujita /*
8453975Sfujita  * For each vm_page_t, there is a list of all currently valid virtual
8553975Sfujita  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
8653975Sfujita  */
8753975Sfujita typedef struct pv_entry {
8853975Sfujita 	struct pv_entry	*pv_next;	/* next pv_entry */
8953975Sfujita 	struct pmap	*pv_pmap;	/* pmap where mapping lies */
9053975Sfujita 	vm_offset_t	pv_va;		/* virtual address for mapping */
9153975Sfujita 	struct ste	*pv_ptste;	/* non-zero if VA maps a PT page */
9253975Sfujita 	struct pmap	*pv_ptpmap;	/* if pv_ptste, pmap for PT page */
9353975Sfujita 	int		pv_flags;	/* flags */
9453975Sfujita } *pv_entry_t;
9553975Sfujita 
9657396Sakito #define	PV_CI		0x01	/* header: all entries are cache inhibited */
9757396Sakito #define PV_PTPAGE	0x02	/* header: entry maps a page table page */
9853975Sfujita 
9953975Sfujita #ifdef	KERNEL
10057396Sakito 
10153975Sfujita pv_entry_t	pv_table;		/* array of entries, one per page */
10253975Sfujita 
10353975Sfujita #define pa_index(pa)		atop(pa - vm_first_phys)
10453975Sfujita #define pa_to_pvh(pa)		(&pv_table[pa_index(pa)])
10553975Sfujita 
10653975Sfujita #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
10760999Shibler #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
10853975Sfujita 
10953975Sfujita extern	struct pte *Sysmap;
11053975Sfujita extern	char *vmmap;			/* map for mem, dumps, etc. */
11153975Sfujita 
11253975Sfujita /*
11353975Sfujita  * definitions LUNA IO space mapping
11453975Sfujita  */
11553975Sfujita struct physmap {
11653975Sfujita 	int pm_phys;
11753975Sfujita 	int pm_size;
11853975Sfujita 	int pm_cache;
11953975Sfujita } ;
12053975Sfujita 
121*65041Sakito #endif /* KERNEL */
12253975Sfujita 
123*65041Sakito #endif /* _PMAP_MACHINE_ */
124