xref: /original-bsd/sys/hp300/hp300/vm_machdep.c (revision ba762ddc)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: vm_machdep.c 1.18 89/08/23$
13  *
14  *	@(#)vm_machdep.c	7.8 (Berkeley) 04/20/91
15  */
16 
17 #include "param.h"
18 #include "systm.h"
19 #include "proc.h"
20 #include "malloc.h"
21 #include "buf.h"
22 
23 #include "../include/cpu.h"
24 
25 #include "vm/vm.h"
26 #include "vm/pmap.h"
27 #include "pte.h"
28 
29 /*
30  * Move pages from one kernel virtual address to another.
31  * Both addresses are assumed to reside in the Sysmap,
32  * and size must be a multiple of CLSIZE.
33  */
34 pagemove(from, to, size)
35 	register caddr_t from, to;
36 	int size;
37 {
38 	register struct pte *fpte, *tpte;
39 
40 	if (size % CLBYTES)
41 		panic("pagemove");
42 	fpte = kvtopte(from);
43 	tpte = kvtopte(to);
44 	while (size > 0) {
45 		*tpte++ = *fpte;
46 		*(int *)fpte++ = PG_NV;
47 		TBIS(from);
48 		TBIS(to);
49 		from += NBPG;
50 		to += NBPG;
51 		size -= NBPG;
52 	}
53 	/* buffer pages not CI with new VM */
54 	DCIS();
55 }
56 
57 /*
58  * Set a red zone in the kernel stack after the u. area.
59  * We don't support a redzone right now.  It really isn't clear
60  * that it is a good idea since, if the kernel stack were to roll
61  * into a write protected page, the processor would lock up (since
62  * it cannot create an exception frame) and we would get no useful
63  * post-mortem info.  Currently, under the DEBUG option, we just
64  * check at every clock interrupt to see if the current k-stack has
65  * gone too far (i.e. into the "redzone" page) and if so, panic.
66  * Look at _lev6intr in locore.s for more details.
67  */
68 /*ARGSUSED*/
69 setredzone(pte, vaddr)
70 	struct pte *pte;
71 	caddr_t vaddr;
72 {
73 }
74 
75 /*
76  * Convert kernel VA to physical address
77  */
78 kvtop(addr)
79 	register caddr_t addr;
80 {
81 	vm_offset_t va;
82 
83 	va = pmap_extract(kernel_pmap, (vm_offset_t)addr);
84 	if (va == 0)
85 		panic("kvtop: zero page frame");
86 	return((int)va);
87 }
88 
89 extern vm_map_t phys_map;
90 
91 /*
92  * Map an IO request into kernel virtual address space.  Requests fall into
93  * one of five catagories:
94  *
95  *	B_PHYS|B_UAREA:	User u-area swap.
96  *			Address is relative to start of u-area (p_addr).
97  *	B_PHYS|B_PAGET:	User page table swap.
98  *			Address is a kernel VA in usrpt (Usrptmap).
99  *	B_PHYS|B_DIRTY:	Dirty page push.
100  *			Address is a VA in proc2's address space.
101  *	B_PHYS|B_PGIN:	Kernel pagein of user pages.
102  *			Address is VA in user's address space.
103  *	B_PHYS:		User "raw" IO request.
104  *			Address is VA in user's address space.
105  *
106  * All requests are (re)mapped into kernel VA space via the useriomap
107  * (a name with only slightly more meaning than "kernelmap")
108  */
109 vmapbuf(bp)
110 	register struct buf *bp;
111 {
112 	register int npf;
113 	register caddr_t addr;
114 	register long flags = bp->b_flags;
115 	struct proc *p;
116 	int off;
117 	vm_offset_t kva;
118 	register vm_offset_t pa;
119 
120 	if ((flags & B_PHYS) == 0)
121 		panic("vmapbuf");
122 	addr = bp->b_saveaddr = bp->b_un.b_addr;
123 	off = (int)addr & PGOFSET;
124 	p = bp->b_proc;
125 	npf = btoc(round_page(bp->b_bcount + off));
126 	kva = kmem_alloc_wait(phys_map, ctob(npf));
127 	bp->b_un.b_addr = (caddr_t) (kva + off);
128 	while (npf--) {
129 		pa = pmap_extract(vm_map_pmap(&p->p_vmspace->vm_map),
130 		    (vm_offset_t)addr);
131 		if (pa == 0)
132 			panic("vmapbuf: null page frame");
133 		pmap_enter(vm_map_pmap(phys_map), kva, trunc_page(pa),
134 			   VM_PROT_READ|VM_PROT_WRITE, TRUE);
135 		addr += PAGE_SIZE;
136 		kva += PAGE_SIZE;
137 	}
138 }
139 
140 /*
141  * Free the io map PTEs associated with this IO operation.
142  * We also invalidate the TLB entries and restore the original b_addr.
143  */
144 vunmapbuf(bp)
145 	register struct buf *bp;
146 {
147 	register int npf;
148 	register caddr_t addr = bp->b_un.b_addr;
149 	vm_offset_t kva;
150 
151 	if ((bp->b_flags & B_PHYS) == 0)
152 		panic("vunmapbuf");
153 	npf = btoc(round_page(bp->b_bcount + ((int)addr & PGOFSET)));
154 	kva = (vm_offset_t)((int)addr & ~PGOFSET);
155 	kmem_free_wakeup(phys_map, kva, ctob(npf));
156 	bp->b_un.b_addr = bp->b_saveaddr;
157 	bp->b_saveaddr = NULL;
158 }
159