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