xref: /original-bsd/sys/luna68k/include/pmap.h (revision 044d1bee)
1 /*
2  * Copyright (c) 1987 Carnegie-Mellon University
3  * Copyright (c) 1992 OMRON Corporation.
4  * Copyright (c) 1991, 1992 Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department.
10  *
11  * %sccs.include.redist.c%
12  *
13  * from: hp300/include/pmap.h	7.11 (Berkeley) 12/27/92
14  *
15  *	@(#)pmap.h	7.3 (Berkeley) 01/02/93
16  */
17 
18 #ifndef	_PMAP_MACHINE_
19 #define	_PMAP_MACHINE_
20 
21 #define LUNA_PAGE_SIZE	NBPG
22 #define LUNA_SEG_SIZE	NBSEG
23 
24 #define luna_trunc_seg(x)	(((unsigned)(x)) & ~(LUNA_SEG_SIZE-1))
25 #define luna_round_seg(x)	luna_trunc_seg((unsigned)(x) + LUNA_SEG_SIZE-1)
26 
27 /*
28  * Pmap stuff
29  */
30 struct pmap {
31 	struct pte		*pm_ptab;	/* KVA of page table */
32 	struct ste		*pm_stab;	/* KVA of segment table */
33 	int			pm_stchanged;	/* ST changed */
34 	int			pm_stfree;	/* 040: free lev2 blocks */
35 	struct ste		*pm_stpa;	/* 040: ST phys addr */
36 	short			pm_sref;	/* segment table ref count */
37 	short			pm_count;	/* pmap reference count */
38 	simple_lock_data_t	pm_lock;	/* lock on pmap */
39 	struct pmap_statistics	pm_stats;	/* pmap statistics */
40 	long			pm_ptpages;	/* more stats: PT pages */
41 };
42 
43 typedef struct pmap	*pmap_t;
44 
45 extern struct pmap	kernel_pmap_store;
46 
47 #define kernel_pmap	(&kernel_pmap_store)
48 #define	active_pmap(pm) \
49 	((pm) == kernel_pmap || (pm) == curproc->p_vmspace->vm_map.pmap)
50 
51 /*
52  * On the 040 we keep track of which level 2 blocks are already in use
53  * with the pm_stfree mask.  Bits are arranged from LSB (block 0) to MSB
54  * (block 31).  For convenience, the level 1 table is considered to be
55  * block 0.
56  *
57  * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed.
58  * for the kernel and users.  8 implies only the initial "segment table"
59  * page is used.  WARNING: don't change MAXUL2SIZE unless you can allocate
60  * physically contiguous pages for the ST in pmap.c!
61  */
62 #define	MAXKL2SIZE	16
63 #define MAXUL2SIZE	8
64 #define l2tobm(n)	(1 << (n))
65 #define	bmtol2(n)	(ffs(n) - 1)
66 
67 /*
68  * Macros for speed
69  */
70 #define PMAP_ACTIVATE(pmapp, pcbp, iscurproc) \
71 	if ((pmapp) != NULL && (pmapp)->pm_stchanged) { \
72 		(pcbp)->pcb_ustp = luna_btop((vm_offset_t)(pmapp)->pm_stpa); \
73 		if (iscurproc) \
74 			loadustp((pcbp)->pcb_ustp); \
75 		(pmapp)->pm_stchanged = FALSE; \
76 	}
77 #define PMAP_DEACTIVATE(pmapp, pcbp)
78 
79 /*
80  * For each vm_page_t, there is a list of all currently valid virtual
81  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
82  */
83 typedef struct pv_entry {
84 	struct pv_entry	*pv_next;	/* next pv_entry */
85 	struct pmap	*pv_pmap;	/* pmap where mapping lies */
86 	vm_offset_t	pv_va;		/* virtual address for mapping */
87 	struct ste	*pv_ptste;	/* non-zero if VA maps a PT page */
88 	struct pmap	*pv_ptpmap;	/* if pv_ptste, pmap for PT page */
89 	int		pv_flags;	/* flags */
90 } *pv_entry_t;
91 
92 #define	PV_CI		0x01	/* header: all entries are cache inhibited */
93 #define PV_PTPAGE	0x02	/* header: entry maps a page table page */
94 
95 #ifdef	KERNEL
96 
97 pv_entry_t	pv_table;		/* array of entries, one per page */
98 
99 #define pa_index(pa)		atop(pa - vm_first_phys)
100 #define pa_to_pvh(pa)		(&pv_table[pa_index(pa)])
101 
102 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
103 
104 extern	struct pte *Sysmap;
105 extern	char *vmmap;			/* map for mem, dumps, etc. */
106 
107 /*
108  * definitions LUNA IO space mapping
109  */
110 struct physmap {
111 	int pm_phys;
112 	int pm_size;
113 	int pm_cache;
114 } ;
115 
116 #endif
117 
118 #endif	_PMAP_MACHINE_
119