1 /* $NetBSD: mainbus.c,v 1.8 2023/12/20 15:29:06 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.8 2023/12/20 15:29:06 thorpej Exp $");
34
35 #include <sys/param.h>
36 #include <sys/extent.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/bus.h>
40
41 #include <machine/autoconf.h>
42 #include <powerpc/pio.h>
43
44 #include "mca.h"
45
46 #if NMCA > 0
47 #include <dev/mca/mcavar.h>
48 #endif
49
50 int mainbus_match(device_t, cfdata_t, void *);
51 void mainbus_attach(device_t, device_t, void *);
52
53 CFATTACH_DECL_NEW(mainbus, 0,
54 mainbus_match, mainbus_attach, NULL, NULL);
55
56 int mainbus_print(void *, const char *);
57
58 union mainbus_attach_args {
59 const char *mba_busname; /* first elem of all */
60 #if NMCA > 0
61 struct mcabus_attach_args mba_mba;
62 #endif
63 };
64
65 /* There can be only one. */
66 int mainbus_found = 0;
67
68 /*
69 * Probe for the mainbus; always succeeds.
70 */
71 int
mainbus_match(device_t parent,cfdata_t match,void * aux)72 mainbus_match(device_t parent, cfdata_t match, void *aux)
73 {
74
75 if (mainbus_found)
76 return 0;
77 return 1;
78 }
79
80 /*
81 * Attach the mainbus.
82 */
83 void
mainbus_attach(device_t parent,device_t self,void * aux)84 mainbus_attach(device_t parent, device_t self, void *aux)
85 {
86 union mainbus_attach_args mba;
87 struct confargs ca;
88 #if DEBUG
89 int slot;
90 #endif
91 mainbus_found = 1;
92
93 aprint_normal("\n");
94
95 ca.ca_name = "cpu";
96 ca.ca_node = 0;
97 config_found(self, &ca, mainbus_print,
98 CFARGS(.iattr = "mainbus"));
99
100 #if DEBUG
101 printf("scanning MCA bus\n");
102 for (slot=0; slot < 16; slot++) {
103 printf("slot %d == %x%x\n", slot,
104 inb(0xc0400100 + 1 + (slot<<16)),
105 inb(0xc0400100 + 0 + (slot<<16)));
106 }
107 printf("done\n");
108
109 printf(" CFG reg (1)= %x\n", inl(0xc0010080));
110 printf(" TCE reg (1)= %x\n", inl(0xc001009c));
111 #endif
112
113 mba.mba_mba.mba_iot = &rs6000_iocc0_io_space_tag;
114 mba.mba_mba.mba_memt = &rs6000_iocc0_io_space_tag; /* XXX ??? */
115 mba.mba_mba.mba_dmat = NULL; /*&mca_bus_dma_tag;*/
116 mba.mba_mba.mba_mc = NULL;
117 mba.mba_mba.mba_bus = 0;
118 config_found(self, &mba.mba_mba, mcabusprint,
119 CFARGS(.iattr = "mcabus"));
120 }
121
122 int
mainbus_print(void * aux,const char * pnp)123 mainbus_print(void *aux, const char *pnp)
124 {
125 union mainbus_attach_args *mba = aux;
126
127 if (pnp)
128 aprint_normal("%s at %s", mba->mba_busname, pnp);
129
130 return (UNCONF);
131 }
132