ffb_mainbus.c revision 1.15 1 1.15 riastrad /* $NetBSD: ffb_mainbus.c,v 1.15 2018/09/03 16:29:27 riastradh Exp $ */
2 1.1 petrov /* $OpenBSD: creator_mainbus.c,v 1.4 2002/07/26 16:39:04 jason Exp $ */
3 1.1 petrov
4 1.1 petrov /*
5 1.1 petrov * Copyright (c) 2002 Jason L. Wright (jason (at) thought.net),
6 1.1 petrov * Federico G. Schwindt (fgsch (at) openbsd.org)
7 1.1 petrov * All rights reserved.
8 1.1 petrov *
9 1.1 petrov * Redistribution and use in source and binary forms, with or without
10 1.1 petrov * modification, are permitted provided that the following conditions
11 1.1 petrov * are met:
12 1.1 petrov * 1. Redistributions of source code must retain the above copyright
13 1.1 petrov * notice, this list of conditions and the following disclaimer.
14 1.1 petrov * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 petrov * notice, this list of conditions and the following disclaimer in the
16 1.1 petrov * documentation and/or other materials provided with the distribution.
17 1.1 petrov * 3. All advertising materials mentioning features or use of this software
18 1.1 petrov * must display the following acknowledgement:
19 1.1 petrov * This product includes software developed by Jason L. Wright
20 1.1 petrov * 4. The name of the author may not be used to endorse or promote products
21 1.1 petrov * derived from this software without specific prior written permission.
22 1.1 petrov *
23 1.1 petrov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 petrov * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 1.1 petrov * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 1.1 petrov * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27 1.1 petrov * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 1.1 petrov * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 1.1 petrov * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 petrov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 1.1 petrov * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 1.1 petrov * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 petrov * POSSIBILITY OF SUCH DAMAGE.
34 1.1 petrov */
35 1.2 lukem
36 1.2 lukem #include <sys/cdefs.h>
37 1.15 riastrad __KERNEL_RCSID(0, "$NetBSD: ffb_mainbus.c,v 1.15 2018/09/03 16:29:27 riastradh Exp $");
38 1.1 petrov
39 1.1 petrov #include <sys/types.h>
40 1.1 petrov #include <sys/param.h>
41 1.1 petrov #include <sys/systm.h>
42 1.1 petrov #include <sys/kernel.h>
43 1.1 petrov #include <sys/device.h>
44 1.1 petrov
45 1.11 dyoung #include <sys/bus.h>
46 1.1 petrov #include <machine/autoconf.h>
47 1.1 petrov #include <machine/openfirm.h>
48 1.1 petrov
49 1.1 petrov #include <dev/wscons/wsconsio.h>
50 1.7 martin #include <dev/sun/fbio.h>
51 1.7 martin #include <dev/sun/fbvar.h>
52 1.1 petrov
53 1.1 petrov #include <sparc64/dev/ffbreg.h>
54 1.1 petrov #include <sparc64/dev/ffbvar.h>
55 1.1 petrov
56 1.3 petrov extern int prom_stdout_node;
57 1.3 petrov
58 1.10 christos int ffb_mainbus_match(device_t, cfdata_t, void *);
59 1.10 christos void ffb_mainbus_attach(device_t, device_t, void *);
60 1.1 petrov
61 1.10 christos CFATTACH_DECL_NEW(ffb_mainbus, sizeof(struct ffb_softc),
62 1.10 christos ffb_mainbus_match, ffb_mainbus_attach, NULL, NULL);
63 1.1 petrov
64 1.1 petrov int
65 1.10 christos ffb_mainbus_match(device_t parent, cfdata_t match, void *aux)
66 1.1 petrov {
67 1.1 petrov struct mainbus_attach_args *ma = aux;
68 1.1 petrov
69 1.1 petrov if (strcmp(ma->ma_name, "SUNW,ffb") == 0 ||
70 1.1 petrov strcmp(ma->ma_name, "SUNW,afb") == 0)
71 1.10 christos return 1;
72 1.10 christos return 0;
73 1.1 petrov }
74 1.1 petrov
75 1.1 petrov void
76 1.10 christos ffb_mainbus_attach(device_t parent, device_t self, void *aux)
77 1.1 petrov {
78 1.10 christos struct ffb_softc *sc = device_private(self);
79 1.1 petrov struct mainbus_attach_args *ma = aux;
80 1.1 petrov int i, nregs;
81 1.1 petrov
82 1.10 christos sc->sc_dev = self;
83 1.1 petrov sc->sc_bt = ma->ma_bustag;
84 1.1 petrov
85 1.15 riastrad nregs = uimin(ma->ma_nreg, FFB_NREGS);
86 1.1 petrov
87 1.1 petrov if (nregs < FFB_REG_DFB24) {
88 1.1 petrov printf(": no dfb24 regs found\n");
89 1.1 petrov goto fail1;
90 1.1 petrov }
91 1.1 petrov
92 1.1 petrov
93 1.1 petrov if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_FBC].ur_paddr,
94 1.1 petrov ma->ma_reg[FFB_REG_FBC].ur_len, 0, &sc->sc_fbc_h)) {
95 1.1 petrov printf(": failed to map fbc\n");
96 1.9 macallan goto fail1;
97 1.4 heas }
98 1.4 heas
99 1.4 heas if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_DAC].ur_paddr,
100 1.5 heas ma->ma_reg[FFB_REG_DAC].ur_len, 0, &sc->sc_dac_h)) {
101 1.4 heas printf(": failed to map dac\n");
102 1.4 heas goto unmap_fbc;
103 1.1 petrov }
104 1.1 petrov
105 1.13 macallan if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_SFB32].ur_paddr,
106 1.14 macallan ma->ma_reg[FFB_REG_SFB32].ur_len,
107 1.14 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE,
108 1.13 macallan &sc->sc_sfb32_h)) {
109 1.13 macallan panic(": failed to map SFB32\n");
110 1.13 macallan goto unmap_dac;
111 1.13 macallan }
112 1.13 macallan sc->sc_sfb32 = bus_space_vaddr(sc->sc_bt, sc->sc_sfb32_h);
113 1.13 macallan
114 1.1 petrov for (i = 0; i < nregs; i++) {
115 1.1 petrov sc->sc_addrs[i] = ma->ma_reg[i].ur_paddr;
116 1.1 petrov sc->sc_sizes[i] = ma->ma_reg[i].ur_len;
117 1.1 petrov }
118 1.1 petrov sc->sc_nreg = nregs;
119 1.1 petrov
120 1.3 petrov sc->sc_console = (prom_stdout_node == ma->ma_node);
121 1.1 petrov sc->sc_node = ma->ma_node;
122 1.1 petrov
123 1.1 petrov if (strcmp(ma->ma_name, "SUNW,afb") == 0)
124 1.1 petrov sc->sc_type = FFB_AFB;
125 1.1 petrov
126 1.12 jdc ffb_attach(self);
127 1.1 petrov
128 1.1 petrov return;
129 1.1 petrov
130 1.4 heas unmap_dac:
131 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_dac_h,
132 1.4 heas ma->ma_reg[FFB_REG_DAC].ur_len);
133 1.13 macallan
134 1.4 heas unmap_fbc:
135 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_fbc_h,
136 1.1 petrov ma->ma_reg[FFB_REG_FBC].ur_len);
137 1.1 petrov fail1:
138 1.1 petrov return;
139 1.1 petrov }
140