xref: /csrg-svn/sys/luna68k/include/pmap.h (revision 57396)
153975Sfujita /*
253975Sfujita  * Copyright (c) 1987 Carnegie-Mellon University
353975Sfujita  * Copyright (c) 1992 OMRON Corporation.
453975Sfujita  * Copyright (c) 1991, 1992 Regents of the University of California.
553975Sfujita  * 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*57396Sakito  * from: hp300/include/pmap.h	7.11 (Berkeley) 12/27/92
1453975Sfujita  *
15*57396Sakito  *	@(#)pmap.h	7.3 (Berkeley) 01/02/93
1653975Sfujita  */
1753975Sfujita 
1853975Sfujita #ifndef	_PMAP_MACHINE_
1953975Sfujita #define	_PMAP_MACHINE_
2053975Sfujita 
2153975Sfujita #define LUNA_PAGE_SIZE	NBPG
2253975Sfujita #define LUNA_SEG_SIZE	NBSEG
2353975Sfujita 
2453975Sfujita #define luna_trunc_seg(x)	(((unsigned)(x)) & ~(LUNA_SEG_SIZE-1))
2553975Sfujita #define luna_round_seg(x)	luna_trunc_seg((unsigned)(x) + LUNA_SEG_SIZE-1)
2653975Sfujita 
2753975Sfujita /*
2853975Sfujita  * Pmap stuff
2953975Sfujita  */
3053975Sfujita struct pmap {
3153975Sfujita 	struct pte		*pm_ptab;	/* KVA of page table */
3253975Sfujita 	struct ste		*pm_stab;	/* KVA of segment table */
3353975Sfujita 	int			pm_stchanged;	/* ST changed */
3453975Sfujita 	int			pm_stfree;	/* 040: free lev2 blocks */
3553975Sfujita 	struct ste		*pm_stpa;	/* 040: ST phys addr */
3653975Sfujita 	short			pm_sref;	/* segment table ref count */
3753975Sfujita 	short			pm_count;	/* pmap reference count */
3853975Sfujita 	simple_lock_data_t	pm_lock;	/* lock on pmap */
3953975Sfujita 	struct pmap_statistics	pm_stats;	/* pmap statistics */
4053975Sfujita 	long			pm_ptpages;	/* more stats: PT pages */
4153975Sfujita };
4253975Sfujita 
4353975Sfujita typedef struct pmap	*pmap_t;
4453975Sfujita 
4553975Sfujita extern struct pmap	kernel_pmap_store;
4653975Sfujita 
47*57396Sakito #define kernel_pmap	(&kernel_pmap_store)
48*57396Sakito #define	active_pmap(pm) \
49*57396Sakito 	((pm) == kernel_pmap || (pm) == curproc->p_vmspace->vm_map.pmap)
50*57396Sakito 
5153975Sfujita /*
5253975Sfujita  * On the 040 we keep track of which level 2 blocks are already in use
5353975Sfujita  * with the pm_stfree mask.  Bits are arranged from LSB (block 0) to MSB
5453975Sfujita  * (block 31).  For convenience, the level 1 table is considered to be
5553975Sfujita  * block 0.
5653975Sfujita  *
5753975Sfujita  * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed.
5853975Sfujita  * for the kernel and users.  8 implies only the initial "segment table"
5953975Sfujita  * page is used.  WARNING: don't change MAXUL2SIZE unless you can allocate
6053975Sfujita  * physically contiguous pages for the ST in pmap.c!
6153975Sfujita  */
6253975Sfujita #define	MAXKL2SIZE	16
6353975Sfujita #define MAXUL2SIZE	8
6453975Sfujita #define l2tobm(n)	(1 << (n))
6553975Sfujita #define	bmtol2(n)	(ffs(n) - 1)
6653975Sfujita 
6753975Sfujita /*
6853975Sfujita  * Macros for speed
6953975Sfujita  */
7053975Sfujita #define PMAP_ACTIVATE(pmapp, pcbp, iscurproc) \
7153975Sfujita 	if ((pmapp) != NULL && (pmapp)->pm_stchanged) { \
7254577Sfujita 		(pcbp)->pcb_ustp = luna_btop((vm_offset_t)(pmapp)->pm_stpa); \
7353975Sfujita 		if (iscurproc) \
7453975Sfujita 			loadustp((pcbp)->pcb_ustp); \
7553975Sfujita 		(pmapp)->pm_stchanged = FALSE; \
7653975Sfujita 	}
7753975Sfujita #define PMAP_DEACTIVATE(pmapp, pcbp)
7853975Sfujita 
7953975Sfujita /*
8053975Sfujita  * For each vm_page_t, there is a list of all currently valid virtual
8153975Sfujita  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
8253975Sfujita  */
8353975Sfujita typedef struct pv_entry {
8453975Sfujita 	struct pv_entry	*pv_next;	/* next pv_entry */
8553975Sfujita 	struct pmap	*pv_pmap;	/* pmap where mapping lies */
8653975Sfujita 	vm_offset_t	pv_va;		/* virtual address for mapping */
8753975Sfujita 	struct ste	*pv_ptste;	/* non-zero if VA maps a PT page */
8853975Sfujita 	struct pmap	*pv_ptpmap;	/* if pv_ptste, pmap for PT page */
8953975Sfujita 	int		pv_flags;	/* flags */
9053975Sfujita } *pv_entry_t;
9153975Sfujita 
92*57396Sakito #define	PV_CI		0x01	/* header: all entries are cache inhibited */
93*57396Sakito #define PV_PTPAGE	0x02	/* header: entry maps a page table page */
9453975Sfujita 
9553975Sfujita #ifdef	KERNEL
96*57396Sakito 
9753975Sfujita pv_entry_t	pv_table;		/* array of entries, one per page */
9853975Sfujita 
9953975Sfujita #define pa_index(pa)		atop(pa - vm_first_phys)
10053975Sfujita #define pa_to_pvh(pa)		(&pv_table[pa_index(pa)])
10153975Sfujita 
10253975Sfujita #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
10353975Sfujita 
10453975Sfujita extern	struct pte *Sysmap;
10553975Sfujita extern	char *vmmap;			/* map for mem, dumps, etc. */
10653975Sfujita 
10753975Sfujita /*
10853975Sfujita  * definitions LUNA IO space mapping
10953975Sfujita  */
11053975Sfujita struct physmap {
11153975Sfujita 	int pm_phys;
11253975Sfujita 	int pm_size;
11353975Sfujita 	int pm_cache;
11453975Sfujita } ;
11553975Sfujita 
11653975Sfujita #endif
11753975Sfujita 
11853975Sfujita #endif	_PMAP_MACHINE_
119