Home | History | Annotate | Line # | Download | only in ofw
vga_ofbus.c revision 1.10
      1  1.10      jmmv /* $NetBSD: vga_ofbus.c,v 1.10 2007/07/30 13:02:01 jmmv Exp $ */
      2   1.1   thorpej 
      3   1.1   thorpej /*
      4   1.1   thorpej  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * Author: Chris G. Demetriou
      8   1.1   thorpej  *
      9   1.1   thorpej  * Permission to use, copy, modify and distribute this software and
     10   1.1   thorpej  * its documentation is hereby granted, provided that both the copyright
     11   1.1   thorpej  * notice and this permission notice appear in all copies of the
     12   1.1   thorpej  * software, derivative works or modified versions, and any portions
     13   1.1   thorpej  * thereof, and that both notices appear in supporting documentation.
     14   1.1   thorpej  *
     15   1.1   thorpej  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16   1.1   thorpej  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17   1.1   thorpej  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18   1.1   thorpej  *
     19   1.1   thorpej  * Carnegie Mellon requests users of this software to return to
     20   1.1   thorpej  *
     21   1.1   thorpej  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22   1.1   thorpej  *  School of Computer Science
     23   1.1   thorpej  *  Carnegie Mellon University
     24   1.1   thorpej  *  Pittsburgh PA 15213-3890
     25   1.1   thorpej  *
     26   1.1   thorpej  * any improvements or extensions that they make and grant Carnegie the
     27   1.1   thorpej  * rights to redistribute these changes.
     28   1.1   thorpej  */
     29   1.5     lukem 
     30   1.5     lukem #include <sys/cdefs.h>
     31  1.10      jmmv __KERNEL_RCSID(0, "$NetBSD: vga_ofbus.c,v 1.10 2007/07/30 13:02:01 jmmv Exp $");
     32   1.1   thorpej 
     33   1.1   thorpej #include <sys/param.h>
     34   1.1   thorpej #include <sys/systm.h>
     35   1.1   thorpej #include <sys/kernel.h>
     36   1.1   thorpej #include <sys/device.h>
     37   1.1   thorpej #include <sys/malloc.h>
     38   1.1   thorpej 
     39   1.1   thorpej #include <dev/isa/isavar.h>
     40   1.1   thorpej 
     41   1.1   thorpej #include <dev/ic/mc6845reg.h>
     42   1.1   thorpej #include <dev/ic/pcdisplayvar.h>
     43   1.1   thorpej #include <dev/ic/vgareg.h>
     44   1.1   thorpej #include <dev/ic/vgavar.h>
     45   1.1   thorpej 
     46   1.1   thorpej #include <dev/wscons/wsconsio.h>
     47   1.1   thorpej #include <dev/wscons/wsdisplayvar.h>
     48   1.1   thorpej 
     49   1.1   thorpej #include <dev/ofw/openfirm.h>
     50   1.6   tsutsui 
     51   1.6   tsutsui #include <shark/ofw/vga_ofbusvar.h>
     52   1.1   thorpej 
     53   1.1   thorpej struct vga_ofbus_softc {
     54   1.1   thorpej 	struct vga_softc sc_vga;
     55   1.1   thorpej 
     56   1.1   thorpej 	int sc_phandle;
     57   1.1   thorpej };
     58   1.1   thorpej 
     59  1.10      jmmv #if defined(SHARK) && (NPC > 0)
     60  1.10      jmmv /* For consistency with the conditionals used in ofw.c. */
     61  1.10      jmmv #elif (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
     62   1.9  macallan extern int console_ihandle;
     63  1.10      jmmv #endif
     64   1.9  macallan 
     65   1.1   thorpej int	vga_ofbus_match (struct device *, struct cfdata *, void *);
     66   1.1   thorpej void	vga_ofbus_attach (struct device *, struct device *, void *);
     67   1.1   thorpej 
     68   1.3   thorpej CFATTACH_DECL(vga_ofbus, sizeof(struct vga_ofbus_softc),
     69   1.4   thorpej     vga_ofbus_match, vga_ofbus_attach, NULL, NULL);
     70   1.1   thorpej 
     71   1.1   thorpej static const char *compat_strings[] = { "pnpPNP,900", 0 };
     72   1.1   thorpej 
     73   1.1   thorpej int
     74   1.1   thorpej vga_ofbus_match(struct device *parent, struct cfdata *match, void *aux)
     75   1.1   thorpej {
     76   1.1   thorpej 	struct ofbus_attach_args *oba = aux;
     77   1.1   thorpej 
     78   1.1   thorpej 	if (of_compatible(oba->oba_phandle, compat_strings) == -1)
     79   1.1   thorpej 		return (0);
     80   1.1   thorpej 
     81   1.1   thorpej 	if (!vga_is_console(&isa_io_bs_tag, WSDISPLAY_TYPE_ISAVGA) &&
     82   1.1   thorpej 	    !vga_common_probe(&isa_io_bs_tag, &isa_mem_bs_tag))
     83   1.1   thorpej 		return (0);
     84   1.1   thorpej 
     85   1.1   thorpej 	return (2);	/* more than generic pcdisplay */
     86   1.1   thorpej }
     87   1.1   thorpej 
     88   1.1   thorpej void
     89   1.1   thorpej vga_ofbus_attach(struct device *parent, struct device *self, void *aux)
     90   1.1   thorpej {
     91   1.1   thorpej 	struct vga_ofbus_softc *osc = (void *) self;
     92   1.1   thorpej 	struct vga_softc *sc = &osc->sc_vga;
     93   1.1   thorpej 	struct ofbus_attach_args *oba = aux;
     94   1.1   thorpej 
     95   1.1   thorpej 	printf("\n");
     96   1.1   thorpej 	osc->sc_phandle = oba->oba_phandle;
     97   1.1   thorpej 
     98   1.1   thorpej 	vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag,
     99   1.6   tsutsui 	    WSDISPLAY_TYPE_ISAVGA, 0, NULL);
    100   1.1   thorpej }
    101   1.1   thorpej 
    102   1.1   thorpej int
    103   1.6   tsutsui vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt)
    104   1.1   thorpej {
    105   1.6   tsutsui 	int chosen_phandle;
    106   1.9  macallan 	int stdout_ihandle, stdout_phandle, ret;
    107   1.6   tsutsui 	char buf[128];
    108   1.6   tsutsui 
    109   1.6   tsutsui 	stdout_phandle = 0;
    110   1.6   tsutsui 
    111   1.6   tsutsui 	/*
    112   1.6   tsutsui 	 * Find out whether the firmware's chosen stdout is
    113   1.6   tsutsui 	 * a display.  If so, use the existing ihandle so the firmware
    114   1.6   tsutsui 	 * doesn't become Unhappy.  If not, just open it.
    115   1.6   tsutsui 	 */
    116   1.6   tsutsui 	if ((chosen_phandle = OF_finddevice("/chosen")) == -1 ||
    117   1.6   tsutsui 	    OF_getprop(chosen_phandle, "stdout", &stdout_ihandle,
    118   1.6   tsutsui 	    sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) {
    119   1.7   tsutsui 		return ENXIO;
    120   1.6   tsutsui 	}
    121   1.6   tsutsui 	stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle);
    122   1.6   tsutsui 	if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 ||
    123   1.6   tsutsui 	    OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) {
    124   1.7   tsutsui 		return ENXIO;
    125   1.6   tsutsui 	}
    126   1.6   tsutsui 
    127   1.6   tsutsui 	if (strcmp(buf, "display") != 0) {
    128   1.6   tsutsui 		/* The display is not stdout device. */
    129   1.7   tsutsui 		return ENXIO;
    130   1.6   tsutsui 	}
    131   1.6   tsutsui 
    132   1.6   tsutsui 	if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) {
    133   1.1   thorpej 		printf("vga_ofbus_match: text-mode3 method invocation on VGA "
    134   1.1   thorpej 		       "screen device failed\n");
    135   1.1   thorpej 	}
    136   1.1   thorpej 
    137   1.9  macallan 	ret = vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1);
    138  1.10      jmmv #if defined(SHARK) && (NPC > 0)
    139  1.10      jmmv /* For consistency with the conditionals used in ofw.c. */
    140  1.10      jmmv #elif (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
    141   1.9  macallan 	if (ret == 0)
    142   1.9  macallan 		console_ihandle = stdout_ihandle;
    143  1.10      jmmv #endif
    144   1.9  macallan 
    145   1.9  macallan 	return ret;
    146   1.1   thorpej }
    147