1 /* $OpenBSD: autoconf.c,v 1.16 2024/11/10 06:51:59 jsg Exp $ */
2 /*
3 * Copyright (c) 2009 Miodrag Vallat.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <sys/param.h>
19 #include <sys/device.h>
20 #include <sys/disklabel.h>
21 #include <sys/reboot.h>
22 #include <sys/hibernate.h>
23 #include <sys/systm.h>
24 #include <uvm/uvm_extern.h>
25
26 #if defined(NFSCLIENT)
27 #include <net/if.h>
28 #include <net/if_types.h>
29 #include <netinet/in.h>
30 #include <netinet/if_ether.h>
31 #endif
32
33 #ifdef CRYPTO
34 void cryptox_setup(void);
35 extern int arm64_has_aes;
36 #endif
37
38 #include <machine/bootconfig.h>
39
40 extern void dumpconf(void);
41
42 void
unmap_startup(void)43 unmap_startup(void)
44 {
45 extern void *_start, *endboot;
46 vaddr_t p = (vaddr_t)&_start;
47
48 do {
49 pmap_kremove(p, PAGE_SIZE);
50 p += PAGE_SIZE;
51 } while (p < (vaddr_t)&endboot);
52 }
53
54 void
cpu_configure(void)55 cpu_configure(void)
56 {
57 splhigh();
58
59 softintr_init();
60 config_rootfound("mainbus", NULL);
61
62 unmap_startup();
63
64 cpu_identify_cleanup();
65
66 #ifdef CRYPTO
67 if (arm64_has_aes)
68 cryptox_setup();
69 #endif
70
71 cold = 0;
72 spl0();
73 }
74
75 void
diskconf(void)76 diskconf(void)
77 {
78 #if defined(NFSCLIENT)
79 extern uint8_t *bootmac;
80 dev_t tmpdev = NODEV;
81 #endif
82 struct device *bootdv = NULL;
83 int part = 0;
84
85 #if defined(NFSCLIENT)
86 if (bootmac) {
87 struct ifnet *ifp;
88
89 TAILQ_FOREACH(ifp, &ifnetlist, if_list) {
90 if (ifp->if_type == IFT_ETHER &&
91 memcmp(bootmac, ((struct arpcom *)ifp)->ac_enaddr,
92 ETHER_ADDR_LEN) == 0)
93 break;
94 }
95 if (ifp)
96 bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname),
97 0, &tmpdev);
98 }
99 #endif
100
101 setroot(bootdv, part, RB_USERREQ);
102 dumpconf();
103
104 #ifdef HIBERNATE
105 hibernate_resume();
106 #endif /* HIBERNATE */
107 }
108
109 void
device_register(struct device * dev,void * aux)110 device_register(struct device *dev, void *aux)
111 {
112 }
113
114 const struct nam2blk nam2blk[] = {
115 { "wd", 0 },
116 { "sd", 4 },
117 { "cd", 6 },
118 { "vnd", 14 },
119 { "rd", 17 },
120 { NULL, -1 }
121 };
122