ffb_mainbus.c revision 1.4 1 1.4 heas /* $NetBSD: ffb_mainbus.c,v 1.4 2004/05/21 21:45:04 heas 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.4 heas __KERNEL_RCSID(0, "$NetBSD: ffb_mainbus.c,v 1.4 2004/05/21 21:45:04 heas 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.1 petrov #include <machine/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.1 petrov #include <dev/wscons/wsdisplayvar.h>
51 1.1 petrov #include <dev/wscons/wscons_raster.h>
52 1.1 petrov #include <dev/rasops/rasops.h>
53 1.1 petrov
54 1.1 petrov #include <sparc64/dev/ffbreg.h>
55 1.1 petrov #include <sparc64/dev/ffbvar.h>
56 1.1 petrov
57 1.3 petrov extern int prom_stdout_node;
58 1.3 petrov
59 1.1 petrov int ffb_mainbus_match(struct device *, struct cfdata *, void *);
60 1.1 petrov void ffb_mainbus_attach(struct device *, struct device *, void *);
61 1.1 petrov
62 1.1 petrov CFATTACH_DECL(ffb_mainbus, sizeof(struct ffb_softc),
63 1.1 petrov ffb_mainbus_match, ffb_mainbus_attach, NULL, NULL);
64 1.1 petrov
65 1.1 petrov int
66 1.1 petrov ffb_mainbus_match(parent, match, aux)
67 1.1 petrov struct device *parent;
68 1.1 petrov struct cfdata *match;
69 1.1 petrov void *aux;
70 1.1 petrov {
71 1.1 petrov struct mainbus_attach_args *ma = aux;
72 1.1 petrov
73 1.1 petrov if (strcmp(ma->ma_name, "SUNW,ffb") == 0 ||
74 1.1 petrov strcmp(ma->ma_name, "SUNW,afb") == 0)
75 1.1 petrov return (1);
76 1.1 petrov return (0);
77 1.1 petrov }
78 1.1 petrov
79 1.1 petrov void
80 1.1 petrov ffb_mainbus_attach(parent, self, aux)
81 1.1 petrov struct device *parent, *self;
82 1.1 petrov void *aux;
83 1.1 petrov {
84 1.1 petrov struct ffb_softc *sc = (struct ffb_softc *)self;
85 1.1 petrov struct mainbus_attach_args *ma = aux;
86 1.1 petrov int i, nregs;
87 1.1 petrov
88 1.1 petrov sc->sc_bt = ma->ma_bustag;
89 1.1 petrov
90 1.1 petrov nregs = min(ma->ma_nreg, FFB_NREGS);
91 1.1 petrov
92 1.1 petrov if (nregs < FFB_REG_DFB24) {
93 1.1 petrov printf(": no dfb24 regs found\n");
94 1.1 petrov goto fail1;
95 1.1 petrov }
96 1.1 petrov
97 1.1 petrov if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_DFB24].ur_paddr,
98 1.1 petrov ma->ma_reg[FFB_REG_DFB24].ur_len, BUS_SPACE_MAP_LINEAR,
99 1.1 petrov &sc->sc_pixel_h)) {
100 1.1 petrov printf(": failed to map dfb24\n");
101 1.1 petrov goto fail1;
102 1.1 petrov }
103 1.1 petrov
104 1.1 petrov if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_FBC].ur_paddr,
105 1.1 petrov ma->ma_reg[FFB_REG_FBC].ur_len, 0, &sc->sc_fbc_h)) {
106 1.1 petrov printf(": failed to map fbc\n");
107 1.4 heas goto unmap_dfb24;
108 1.4 heas }
109 1.4 heas
110 1.4 heas if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_DAC].ur_paddr,
111 1.4 heas ma->ma_reg[FFB_REG_DAC].ur_len, BUS_SPACE_MAP_LINEAR,
112 1.4 heas &sc->sc_dac_h)) {
113 1.4 heas printf(": failed to map dac\n");
114 1.4 heas goto unmap_fbc;
115 1.1 petrov }
116 1.1 petrov
117 1.1 petrov for (i = 0; i < nregs; i++) {
118 1.1 petrov sc->sc_addrs[i] = ma->ma_reg[i].ur_paddr;
119 1.1 petrov sc->sc_sizes[i] = ma->ma_reg[i].ur_len;
120 1.1 petrov }
121 1.1 petrov sc->sc_nreg = nregs;
122 1.1 petrov
123 1.3 petrov sc->sc_console = (prom_stdout_node == ma->ma_node);
124 1.1 petrov sc->sc_node = ma->ma_node;
125 1.1 petrov
126 1.1 petrov if (strcmp(ma->ma_name, "SUNW,afb") == 0)
127 1.1 petrov sc->sc_type = FFB_AFB;
128 1.1 petrov
129 1.1 petrov ffb_attach(sc);
130 1.1 petrov
131 1.1 petrov return;
132 1.1 petrov
133 1.4 heas #if notyet
134 1.4 heas unmap_dac:
135 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_dac_h,
136 1.4 heas ma->ma_reg[FFB_REG_DAC].ur_len);
137 1.4 heas #endif
138 1.4 heas unmap_fbc:
139 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_fbc_h,
140 1.1 petrov ma->ma_reg[FFB_REG_FBC].ur_len);
141 1.4 heas unmap_dfb24:
142 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_pixel_h,
143 1.1 petrov ma->ma_reg[FFB_REG_DFB24].ur_len);
144 1.1 petrov fail1:
145 1.1 petrov return;
146 1.1 petrov }
147