ffb_mainbus.c revision 1.6 1 1.6 martin /* $NetBSD: ffb_mainbus.c,v 1.6 2005/05/04 10:01:32 martin 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.6 martin __KERNEL_RCSID(0, "$NetBSD: ffb_mainbus.c,v 1.6 2005/05/04 10:01:32 martin 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.6 martin ffb_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
67 1.1 petrov {
68 1.1 petrov struct mainbus_attach_args *ma = aux;
69 1.1 petrov
70 1.1 petrov if (strcmp(ma->ma_name, "SUNW,ffb") == 0 ||
71 1.1 petrov strcmp(ma->ma_name, "SUNW,afb") == 0)
72 1.1 petrov return (1);
73 1.1 petrov return (0);
74 1.1 petrov }
75 1.1 petrov
76 1.1 petrov void
77 1.6 martin ffb_mainbus_attach(struct device *parent, struct device *self, void *aux)
78 1.1 petrov {
79 1.1 petrov struct ffb_softc *sc = (struct ffb_softc *)self;
80 1.1 petrov struct mainbus_attach_args *ma = aux;
81 1.1 petrov int i, nregs;
82 1.1 petrov
83 1.1 petrov sc->sc_bt = ma->ma_bustag;
84 1.1 petrov
85 1.1 petrov nregs = min(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 if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_DFB24].ur_paddr,
93 1.1 petrov ma->ma_reg[FFB_REG_DFB24].ur_len, BUS_SPACE_MAP_LINEAR,
94 1.1 petrov &sc->sc_pixel_h)) {
95 1.1 petrov printf(": failed to map dfb24\n");
96 1.1 petrov goto fail1;
97 1.1 petrov }
98 1.1 petrov
99 1.1 petrov if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_FBC].ur_paddr,
100 1.1 petrov ma->ma_reg[FFB_REG_FBC].ur_len, 0, &sc->sc_fbc_h)) {
101 1.1 petrov printf(": failed to map fbc\n");
102 1.4 heas goto unmap_dfb24;
103 1.4 heas }
104 1.4 heas
105 1.4 heas if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_DAC].ur_paddr,
106 1.5 heas ma->ma_reg[FFB_REG_DAC].ur_len, 0, &sc->sc_dac_h)) {
107 1.4 heas printf(": failed to map dac\n");
108 1.4 heas goto unmap_fbc;
109 1.1 petrov }
110 1.1 petrov
111 1.1 petrov for (i = 0; i < nregs; i++) {
112 1.1 petrov sc->sc_addrs[i] = ma->ma_reg[i].ur_paddr;
113 1.1 petrov sc->sc_sizes[i] = ma->ma_reg[i].ur_len;
114 1.1 petrov }
115 1.1 petrov sc->sc_nreg = nregs;
116 1.1 petrov
117 1.3 petrov sc->sc_console = (prom_stdout_node == ma->ma_node);
118 1.1 petrov sc->sc_node = ma->ma_node;
119 1.1 petrov
120 1.1 petrov if (strcmp(ma->ma_name, "SUNW,afb") == 0)
121 1.1 petrov sc->sc_type = FFB_AFB;
122 1.1 petrov
123 1.1 petrov ffb_attach(sc);
124 1.1 petrov
125 1.1 petrov return;
126 1.1 petrov
127 1.4 heas #if notyet
128 1.4 heas unmap_dac:
129 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_dac_h,
130 1.4 heas ma->ma_reg[FFB_REG_DAC].ur_len);
131 1.4 heas #endif
132 1.4 heas unmap_fbc:
133 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_fbc_h,
134 1.1 petrov ma->ma_reg[FFB_REG_FBC].ur_len);
135 1.4 heas unmap_dfb24:
136 1.4 heas bus_space_unmap(sc->sc_bt, sc->sc_pixel_h,
137 1.1 petrov ma->ma_reg[FFB_REG_DFB24].ur_len);
138 1.1 petrov fail1:
139 1.1 petrov return;
140 1.1 petrov }
141