xref: /netbsd-src/sys/arch/alpha/gbus/gbus.c (revision 8eb9eddb6415754b60dfa083b7fd9886f5bb92e2)
1*8eb9eddbSthorpej /* $NetBSD: gbus.c,v 1.2 2024/03/06 05:33:09 thorpej Exp $ */
2e6333d48Sthorpej 
3e6333d48Sthorpej /*
4e6333d48Sthorpej  * Copyright (c) 1997 by Matthew Jacob
5e6333d48Sthorpej  * NASA AMES Research Center.
6e6333d48Sthorpej  * All rights reserved.
7e6333d48Sthorpej  *
8e6333d48Sthorpej  * Redistribution and use in source and binary forms, with or without
9e6333d48Sthorpej  * modification, are permitted provided that the following conditions
10e6333d48Sthorpej  * are met:
11e6333d48Sthorpej  * 1. Redistributions of source code must retain the above copyright
12e6333d48Sthorpej  *    notice immediately at the beginning of the file, without modification,
13e6333d48Sthorpej  *    this list of conditions, and the following disclaimer.
14e6333d48Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
15e6333d48Sthorpej  *    notice, this list of conditions and the following disclaimer in the
16e6333d48Sthorpej  *    documentation and/or other materials provided with the distribution.
17e6333d48Sthorpej  * 3. The name of the author may not be used to endorse or promote products
18e6333d48Sthorpej  *    derived from this software without specific prior written permission.
19e6333d48Sthorpej  *
20e6333d48Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21e6333d48Sthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22e6333d48Sthorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23e6333d48Sthorpej  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24e6333d48Sthorpej  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25e6333d48Sthorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26e6333d48Sthorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27e6333d48Sthorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28e6333d48Sthorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29e6333d48Sthorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30e6333d48Sthorpej  * SUCH DAMAGE.
31e6333d48Sthorpej  */
32e6333d48Sthorpej 
33e6333d48Sthorpej /*
34e6333d48Sthorpej  * Autoconfiguration and support routines for the Gbus: the internal
35e6333d48Sthorpej  * bus on AlphaServer CPU modules.
36e6333d48Sthorpej  */
37e6333d48Sthorpej 
38e6333d48Sthorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
39e6333d48Sthorpej 
40*8eb9eddbSthorpej __KERNEL_RCSID(0, "$NetBSD: gbus.c,v 1.2 2024/03/06 05:33:09 thorpej Exp $");
41e6333d48Sthorpej 
42e6333d48Sthorpej #include <sys/param.h>
43e6333d48Sthorpej #include <sys/systm.h>
44e6333d48Sthorpej #include <sys/device.h>
45e6333d48Sthorpej 
46e6333d48Sthorpej #include <machine/rpb.h>
47e6333d48Sthorpej #include <machine/pte.h>
48e6333d48Sthorpej 
49e6333d48Sthorpej #include <alpha/gbus/gbusreg.h>
50e6333d48Sthorpej #include <alpha/gbus/gbusvar.h>
51e6333d48Sthorpej 
52e6333d48Sthorpej #include <alpha/tlsb/tlsbreg.h>
53e6333d48Sthorpej #include <alpha/tlsb/tlsbvar.h>
54e6333d48Sthorpej 
55e6333d48Sthorpej #include "locators.h"
56e6333d48Sthorpej 
57e6333d48Sthorpej #define KV(_addr)	((void *)ALPHA_PHYS_TO_K0SEG((_addr)))
58e6333d48Sthorpej 
59e6333d48Sthorpej struct gbus_softc {
60e6333d48Sthorpej 	device_t	sc_dev;
61e6333d48Sthorpej 	int		sc_tlsbnode;	/* node on the TurboLaser */
62e6333d48Sthorpej };
63e6333d48Sthorpej 
64e6333d48Sthorpej static int	gbusmatch(device_t, cfdata_t, void *);
65e6333d48Sthorpej static void	gbusattach(device_t, device_t, void *);
66e6333d48Sthorpej 
67e6333d48Sthorpej CFATTACH_DECL_NEW(gbus, sizeof(struct gbus_softc),
68e6333d48Sthorpej     gbusmatch, gbusattach, NULL, NULL);
69e6333d48Sthorpej 
70e6333d48Sthorpej static int	gbusprint(void *, const char *);
71e6333d48Sthorpej 
72e6333d48Sthorpej static const struct gbus_attach_args gbus_children[] = {
73*8eb9eddbSthorpej 	{ "zsc",	NULL,	GBUS_DUART0_OFFSET },
74*8eb9eddbSthorpej 	{ "zsc",	NULL,	GBUS_DUART1_OFFSET },
75*8eb9eddbSthorpej 	{ "mcclock",	NULL,	GBUS_CLOCK_OFFSET },
76*8eb9eddbSthorpej 	{ NULL,		NULL,	0 },
77e6333d48Sthorpej };
78e6333d48Sthorpej 
79e6333d48Sthorpej static int
gbusprint(void * aux,const char * pnp)80e6333d48Sthorpej gbusprint(void *aux, const char *pnp)
81e6333d48Sthorpej {
82e6333d48Sthorpej 	struct gbus_attach_args *ga = aux;
83e6333d48Sthorpej 
84e6333d48Sthorpej 	if (pnp)
85e6333d48Sthorpej 		aprint_normal("%s at %s", ga->ga_name, pnp);
86e6333d48Sthorpej 	aprint_normal(" offset 0x%lx", ga->ga_offset);
87e6333d48Sthorpej 	return (UNCONF);
88e6333d48Sthorpej }
89e6333d48Sthorpej 
90e6333d48Sthorpej static int
gbusmatch(device_t parent,cfdata_t cf,void * aux)91e6333d48Sthorpej gbusmatch(device_t parent, cfdata_t cf, void *aux)
92e6333d48Sthorpej {
93e6333d48Sthorpej 	struct tlsb_dev_attach_args *ta = aux;
94e6333d48Sthorpej 
95e6333d48Sthorpej 	/*
96e6333d48Sthorpej 	 * Make sure we're looking for a Gbus.  The Gbus only
97e6333d48Sthorpej 	 * "exists" on the CPU module that holds the primary CPU.
98e6333d48Sthorpej 	 *
99e6333d48Sthorpej 	 * Compute which node this should exist on by dividing the
100e6333d48Sthorpej 	 * primary CPU by 2 (since there are up to 2 CPUs per CPU
101e6333d48Sthorpej 	 * module).
102e6333d48Sthorpej 	 */
103e6333d48Sthorpej 	if (TLDEV_ISCPU(ta->ta_dtype) &&
104e6333d48Sthorpej 	    ta->ta_node == (hwrpb->rpb_primary_cpu_id / 2))
105e6333d48Sthorpej 		return (1);
106e6333d48Sthorpej 
107e6333d48Sthorpej 	return (0);
108e6333d48Sthorpej }
109e6333d48Sthorpej 
110e6333d48Sthorpej static void
gbusattach(device_t parent,device_t self,void * aux)111e6333d48Sthorpej gbusattach(device_t parent, device_t self, void *aux)
112e6333d48Sthorpej {
113e6333d48Sthorpej 	struct gbus_softc *sc = device_private(self);
114e6333d48Sthorpej 	struct tlsb_dev_attach_args *ta = aux;
115e6333d48Sthorpej 	const struct gbus_attach_args *ga;
116*8eb9eddbSthorpej 	bus_space_tag_t iot = gbus_io_init(TLSB_GBUS_BASE);
117e6333d48Sthorpej 	int locs[GBUSCF_NLOCS];
118e6333d48Sthorpej 
119e6333d48Sthorpej 	aprint_normal("\n");
120e6333d48Sthorpej 
121e6333d48Sthorpej 	sc->sc_dev = self;
122e6333d48Sthorpej 	sc->sc_tlsbnode = ta->ta_node;
123e6333d48Sthorpej 
124e6333d48Sthorpej 	/* Attach the children. */
125e6333d48Sthorpej 	for (ga = gbus_children; ga->ga_name != NULL; ga++) {
126e6333d48Sthorpej 		struct gbus_attach_args gaa = *ga;
127*8eb9eddbSthorpej 		gaa.ga_iot = iot;
128e6333d48Sthorpej 		locs[GBUSCF_OFFSET] = gaa.ga_offset;
129e6333d48Sthorpej 		config_found(self, &gaa, gbusprint,
130e6333d48Sthorpej 		    CFARGS(.submatch = config_stdsubmatch,
131e6333d48Sthorpej 			   .locators = locs));
132e6333d48Sthorpej 	}
133e6333d48Sthorpej }
134