Home | History | Annotate | Line # | Download | only in pci
vga_pci.c revision 1.5
      1 /* $NetBSD: vga_pci.c,v 1.5 2001/09/14 01:10:12 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/param.h>
     31 #include <sys/systm.h>
     32 #include <sys/kernel.h>
     33 #include <sys/device.h>
     34 #include <sys/malloc.h>
     35 
     36 #include <dev/pci/pcireg.h>
     37 #include <dev/pci/pcivar.h>
     38 #include <dev/pci/pcidevs.h>
     39 
     40 #include <dev/ic/mc6845reg.h>
     41 #include <dev/ic/pcdisplayvar.h>
     42 #include <dev/ic/vgareg.h>
     43 #include <dev/ic/vgavar.h>
     44 #include <dev/pci/vga_pcivar.h>
     45 
     46 #include <dev/wscons/wsconsio.h>
     47 #include <dev/wscons/wsdisplayvar.h>
     48 
     49 struct vga_pci_softc {
     50 	struct vga_softc sc_vga;
     51 
     52 	pcitag_t sc_pcitag;
     53 };
     54 
     55 int	vga_pci_match __P((struct device *, struct cfdata *, void *));
     56 void	vga_pci_attach __P((struct device *, struct device *, void *));
     57 
     58 struct cfattach vga_pci_ca = {
     59 	sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach,
     60 };
     61 
     62 int
     63 vga_pci_match(parent, match, aux)
     64 	struct device *parent;
     65 	struct cfdata *match;
     66 	void *aux;
     67 {
     68 	struct pci_attach_args *pa = aux;
     69 	int potential;
     70 
     71 	potential = 0;
     72 
     73 	/*
     74 	 * If it's prehistoric/vga or display/vga, we might match.
     75 	 * For the console device, this is jut a sanity check.
     76 	 */
     77 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC &&
     78 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
     79 		potential = 1;
     80 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
     81 	     PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
     82 		potential = 1;
     83 
     84 	if (!potential)
     85 		return (0);
     86 
     87 	/* check whether it is disabled by firmware */
     88 	if ((pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG)
     89 	    & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
     90 	    != (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
     91 		return (0);
     92 
     93 	/* If it's the console, we have a winner! */
     94 	if (vga_is_console(pa->pa_iot, WSDISPLAY_TYPE_PCIVGA))
     95 		return (1);
     96 
     97 	/*
     98 	 * If we might match, make sure that the card actually looks OK.
     99 	 */
    100 	if (!vga_common_probe(pa->pa_iot, pa->pa_memt))
    101 		return (0);
    102 
    103 	return (1);
    104 }
    105 
    106 void
    107 vga_pci_attach(parent, self, aux)
    108 	struct device *parent, *self;
    109 	void *aux;
    110 {
    111 	struct vga_pci_softc *psc = (void *) self;
    112 	struct vga_softc *sc = &psc->sc_vga;
    113 	struct pci_attach_args *pa = aux;
    114 	char devinfo[256];
    115 
    116 	psc->sc_pcitag = pa->pa_tag;
    117 
    118 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    119 	printf(": %s (rev. 0x%02x)\n", devinfo,
    120 	    PCI_REVISION(pa->pa_class));
    121 
    122 	vga_common_attach(sc, pa->pa_iot, pa->pa_memt, WSDISPLAY_TYPE_PCIVGA,
    123 	    NULL);
    124 }
    125 
    126 int
    127 vga_pci_cnattach(iot, memt, pc, bus, device, function)
    128 	bus_space_tag_t iot, memt;
    129 	pci_chipset_tag_t pc;
    130 	int bus, device, function;
    131 {
    132 	return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_PCIVGA, 0));
    133 }
    134