1*c5465e91Sskrll /* $NetBSD: autoconf.c,v 1.21 2022/09/29 06:47:06 skrll Exp $ */
2a7b8789dSchris
3a7b8789dSchris /*
4a7b8789dSchris * Copyright (c) 1994-1998 Mark Brinicombe.
5a7b8789dSchris * Copyright (c) 1994 Brini.
6a7b8789dSchris * All rights reserved.
7a7b8789dSchris *
8a7b8789dSchris * Redistribution and use in source and binary forms, with or without
9a7b8789dSchris * modification, are permitted provided that the following conditions
10a7b8789dSchris * are met:
11a7b8789dSchris * 1. Redistributions of source code must retain the above copyright
12a7b8789dSchris * notice, this list of conditions and the following disclaimer.
13a7b8789dSchris * 2. Redistributions in binary form must reproduce the above copyright
14a7b8789dSchris * notice, this list of conditions and the following disclaimer in the
15a7b8789dSchris * documentation and/or other materials provided with the distribution.
16a7b8789dSchris * 3. All advertising materials mentioning features or use of this software
17a7b8789dSchris * must display the following acknowledgement:
18a7b8789dSchris * This product includes software developed by Mark Brinicombe for
19a7b8789dSchris * the NetBSD project.
20a7b8789dSchris * 4. The name of the company nor the name of the author may be used to
21a7b8789dSchris * endorse or promote products derived from this software without specific
22a7b8789dSchris * prior written permission.
23a7b8789dSchris *
24a7b8789dSchris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25a7b8789dSchris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26a7b8789dSchris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27a7b8789dSchris * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28a7b8789dSchris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29a7b8789dSchris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30a7b8789dSchris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31a7b8789dSchris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32a7b8789dSchris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33a7b8789dSchris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34a7b8789dSchris * SUCH DAMAGE.
35a7b8789dSchris *
36a7b8789dSchris * RiscBSD kernel project
37a7b8789dSchris *
38a7b8789dSchris * autoconf.c
39a7b8789dSchris *
40a7b8789dSchris * Autoconfiguration functions
41a7b8789dSchris */
42a7b8789dSchris
43e803bea7Slukem #include <sys/cdefs.h>
44*c5465e91Sskrll __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.21 2022/09/29 06:47:06 skrll Exp $");
45e803bea7Slukem
46a7b8789dSchris #include "opt_md.h"
47a7b8789dSchris
48a7b8789dSchris #include <sys/param.h>
49a7b8789dSchris #include <sys/systm.h>
50a7b8789dSchris #include <sys/reboot.h>
51a7b8789dSchris #include <sys/disklabel.h>
52a7b8789dSchris #include <sys/device.h>
53a7b8789dSchris #include <sys/conf.h>
54a7b8789dSchris #include <sys/kernel.h>
55a7b8789dSchris #include <machine/bootconfig.h>
56792b7ebdSmatt #include <machine/intr.h>
57736004cfSchris #include <dev/pci/pcivar.h>
58a7b8789dSchris
59a7b8789dSchris #include "isa.h"
60a7b8789dSchris
61a7b8789dSchris void isa_intr_init(void);
62a7b8789dSchris
63f483ac7aSchris static void get_device(const char *name);
64f483ac7aSchris static void set_root_device(void);
65a7b8789dSchris
66a7b8789dSchris /* Decode a device name to a major and minor number */
67a7b8789dSchris
68a7b8789dSchris static void
get_device(const char * name)69f483ac7aSchris get_device(const char *name)
70a7b8789dSchris {
7177a6b82bSgehenna int unit, part;
72e69482d4Sjoerg char devname[16];
73f483ac7aSchris const char *cp;
74e69482d4Sjoerg device_t dv;
75a7b8789dSchris
76a7b8789dSchris if (strncmp(name, "/dev/", 5) == 0)
77a7b8789dSchris name += 5;
78a7b8789dSchris
7977a6b82bSgehenna if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
8077a6b82bSgehenna return;
8177a6b82bSgehenna
8277a6b82bSgehenna name += strlen(devname);
83a7b8789dSchris unit = part = 0;
84a7b8789dSchris
85a7b8789dSchris cp = name;
86a7b8789dSchris while (*cp >= '0' && *cp <= '9')
87a7b8789dSchris unit = (unit * 10) + (*cp++ - '0');
88a7b8789dSchris if (cp == name)
89a7b8789dSchris return;
90a7b8789dSchris
91a7b8789dSchris if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
92a7b8789dSchris part = *cp - 'a';
93a7b8789dSchris else if (*cp != '\0' && *cp != ' ')
94a7b8789dSchris return;
95e69482d4Sjoerg
96e69482d4Sjoerg if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
97a7b8789dSchris booted_device = dv;
98a7b8789dSchris booted_partition = part;
99a7b8789dSchris }
100a7b8789dSchris }
101a7b8789dSchris
102a7b8789dSchris static void
set_root_device(void)103df7f595eScegger set_root_device(void)
104a7b8789dSchris {
105a7b8789dSchris char *ptr;
106a7b8789dSchris
107a7b8789dSchris if (boot_file)
108a7b8789dSchris get_device(boot_file);
109a7b8789dSchris if (boot_args &&
110a7b8789dSchris get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr))
111a7b8789dSchris get_device(ptr);
112a7b8789dSchris }
113a7b8789dSchris
114a7b8789dSchris /*
115a7b8789dSchris * Set up the root device from the boot args
116a7b8789dSchris */
117a7b8789dSchris void
cpu_rootconf(void)118a7b8789dSchris cpu_rootconf(void)
119a7b8789dSchris {
120a7b8789dSchris set_root_device();
121a7b8789dSchris printf("boot device: %s\n",
122cbab9cadSchs booted_device != NULL ? device_xname(booted_device) : "<unknown>");
1238ce44338Smlelstv rootconf();
124a7b8789dSchris }
125a7b8789dSchris
126a7b8789dSchris
127a7b8789dSchris /*
128a7b8789dSchris * void cpu_configure()
129a7b8789dSchris *
130a7b8789dSchris * Configure all the root devices
131a7b8789dSchris * The root devices are expected to configure their own children
132a7b8789dSchris */
13361578bc3Schris extern int footbridge_imask[NIPL];
13461578bc3Schris
135a7b8789dSchris void
cpu_configure(void)136a7b8789dSchris cpu_configure(void)
137a7b8789dSchris {
1387094c090Smatt footbridge_intr_evcnt_attach();
139a7b8789dSchris /*
140a7b8789dSchris * Since various PCI interrupts could be routed via the ICU
141a7b8789dSchris * (for PCI devices in the bridge) we need to set up the ICU
142a7b8789dSchris * now so that these interrupts can be established correctly
143a7b8789dSchris * i.e. This is a hack.
144a7b8789dSchris */
145a7b8789dSchris isa_intr_init();
146a7b8789dSchris
14761578bc3Schris
148a7b8789dSchris config_rootfound("mainbus", NULL);
149a7b8789dSchris
1503e495310Sjmmv #if defined(DEBUG)
151a7b8789dSchris /* Debugging information */
152452a8fdaSthorpej printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n",
15361578bc3Schris footbridge_imask[IPL_BIO], footbridge_imask[IPL_NET],
154452a8fdaSthorpej footbridge_imask[IPL_TTY], footbridge_imask[IPL_VM]);
155a7b8789dSchris printf("ipl_audio=%08x ipl_imp=%08x ipl_high=%08x ipl_serial=%08x\n",
15661578bc3Schris footbridge_imask[IPL_AUDIO], footbridge_imask[IPL_CLOCK],
15761578bc3Schris footbridge_imask[IPL_HIGH], footbridge_imask[IPL_SERIAL]);
1583e495310Sjmmv #endif /* defined(DEBUG) */
159a7b8789dSchris
160a7b8789dSchris /* Time to start taking interrupts so lets open the flood gates .... */
161a7b8789dSchris (void)spl0();
162a7b8789dSchris }
163a7b8789dSchris
164a7b8789dSchris void
device_register(device_t dev,void * aux)165cbab9cadSchs device_register(device_t dev, void *aux)
166a7b8789dSchris {
167cbab9cadSchs device_t pdev;
168cbab9cadSchs
169736004cfSchris if ((pdev = device_parent(dev)) != NULL &&
170736004cfSchris device_is_a(pdev, "pci")) {
171736004cfSchris /*
172736004cfSchris * cats builtin aceride is on 0:16:0
173736004cfSchris */
174736004cfSchris struct pci_attach_args *pa = aux;
175736004cfSchris if (((pa)->pa_bus == 0
176736004cfSchris && (pa)->pa_device == 16
177736004cfSchris && (pa)->pa_function == 0)) {
178736004cfSchris if (prop_dictionary_set_bool(device_properties(dev),
179736004cfSchris "ali1543-ide-force-compat-mode",
180736004cfSchris true) == false) {
181736004cfSchris printf("WARNING: unable to set "
182736004cfSchris "ali1543-ide-force-compat-mode "
183cbab9cadSchs "property for %s\n", device_xname(dev));
184736004cfSchris }
185736004cfSchris }
186736004cfSchris }
187a7b8789dSchris }
188a7b8789dSchris /* End of autoconf.c */
189