1 /*        $NetBSD: pmap_bootstrap.c,v 1.11 2023/12/20 00:40:42 thorpej Exp $    */
2 /*-
3  * Copyright (c) 1999 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Jason R. Thorpe.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*
32  * Copyright (c) 1991 Regents of the University of California.
33  * All rights reserved.
34  *
35  * This code is derived from software contributed to Berkeley by
36  * the Systems Programming Group of the University of Utah Computer
37  * Science Department.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  * 3. Neither the name of the University nor the names of its contributors
48  *    may be used to endorse or promote products derived from this software
49  *    without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61  * SUCH DAMAGE.
62  *
63  *        @(#)pmap.c          7.5 (Berkeley) 5/10/91
64  */
65 
66 #include <sys/cdefs.h>
67 
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/proc.h>
71 
72 #include <uvm/uvm.h>
73 
74 #include <machine/pte.h>
75 #include <machine/cpu.h>
76 #include <machine/vmparam.h>
77 
78 #include <m68k/cacheops.h>
79 
80 struct memseg       boot_segs[NMEM_SEGS];
81 struct memseg       usable_segs[NMEM_SEGS];
82 
83 extern paddr_t      avail_start;
84 extern paddr_t      avail_end;
85 
86 extern paddr_t      msgbufpa;
87 
88 /*
89  * All those kernel PT submaps that BSD is so fond of
90  */
91 void                *CADDR1, *CADDR2;
92 char                *vmmap;
93 
94 /*
95  *        Bootstrap the system enough to run with virtual memory.
96  *
97  *        This is called after mapping has already been enabled
98  *        and just syncs the pmap module with what has already been done.
99  */
100 void
pmap_bootstrap(vaddr_t vstart)101 pmap_bootstrap(vaddr_t vstart)
102 {
103           vaddr_t   va;
104           int       i;
105 
106           /*
107            * Announce page-size to the VM-system
108            */
109           uvmexp.pagesize = NBPG;
110           uvm_md_init();
111 
112           /*
113            * Setup physical address ranges
114            */
115           for (i = 0; i < NMEM_SEGS && usable_segs[i].start; i++)
116                     continue;
117           /* XXX: allow for msgbuf */
118           usable_segs[i - 1].end -= m68k_round_page(MSGBUFSIZE);
119           msgbufpa = usable_segs[i - 1].end;
120 
121           /*
122            * Count physical memory
123            */
124           mem_size = 0;
125           for (i = 0; i < NMEM_SEGS; i++) {
126                     if (boot_segs[i].start == boot_segs[i].end)
127                               break;
128                     mem_size += boot_segs[i].end - boot_segs[i].start;
129           }
130 
131           /*
132            * Announce available memory to the VM-system
133            */
134           for (i = 0; i < NMEM_SEGS && usable_segs[i].start; i++)
135                     uvm_page_physload(atop(usable_segs[i].start),
136                                          atop(usable_segs[i].end),
137                                          atop(usable_segs[i].start),
138                                          atop(usable_segs[i].end),
139                                          usable_segs[i].free_list);
140 
141           avail_start = usable_segs[0].start;
142           avail_end   = usable_segs[i - 1].end;
143 
144           virtual_avail = vstart;
145           virtual_end   = VM_MAX_KERNEL_ADDRESS;
146 
147           /*
148            * Allocate all the submaps we need
149            */
150 #define   SYSMAP(c, v, n)     \
151           v = (c)va; va += ((n)*PAGE_SIZE);
152 
153           va = virtual_avail;
154 
155           SYSMAP(void *   ,CADDR1       ,1                            )
156           SYSMAP(void *   ,CADDR2       ,1                            )
157           SYSMAP(void *   ,vmmap        ,1                            )
158           SYSMAP(void *       ,msgbufaddr ,btoc(MSGBUFSIZE) )
159 
160           DCIS();
161 
162           virtual_avail = reserve_dumppages(va);
163 }
164