1 /* $NetBSD: vga_pci.c,v 1.4 2000/08/14 20:14:51 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@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 device sc_dev; 51 52 pcitag_t sc_pcitag; /* PCI tag, in case we need it. */ 53 #if 0 54 struct vga_config *sc_vc; /* VGA configuration */ 55 #endif 56 }; 57 58 int vga_pci_match __P((struct device *, struct cfdata *, void *)); 59 void vga_pci_attach __P((struct device *, struct device *, void *)); 60 61 struct cfattach vga_pci_ca = { 62 sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach, 63 }; 64 65 int 66 vga_pci_match(parent, match, aux) 67 struct device *parent; 68 struct cfdata *match; 69 void *aux; 70 { 71 struct pci_attach_args *pa = aux; 72 int potential; 73 74 potential = 0; 75 76 /* 77 * If it's prehistoric/vga or display/vga, we might match. 78 * For the console device, this is jut a sanity check. 79 */ 80 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC && 81 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA) 82 potential = 1; 83 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY && 84 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA) 85 potential = 1; 86 87 if (!potential) 88 return (0); 89 90 /* check whether it is disabled by firmware */ 91 if ((pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) 92 & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE)) 93 != (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE)) 94 return (0); 95 96 /* If it's the console, we have a winner! */ 97 if (vga_is_console(pa->pa_iot, WSDISPLAY_TYPE_PCIVGA)) 98 return (1); 99 100 /* 101 * If we might match, make sure that the card actually looks OK. 102 */ 103 if (!vga_common_probe(pa->pa_iot, pa->pa_memt)) 104 return (0); 105 106 return (1); 107 } 108 109 void 110 vga_pci_attach(parent, self, aux) 111 struct device *parent, *self; 112 void *aux; 113 { 114 struct pci_attach_args *pa = aux; 115 struct vga_pci_softc *sc = (struct vga_pci_softc *)self; 116 char devinfo[256]; 117 118 sc->sc_pcitag = pa->pa_tag; 119 120 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 121 printf(": %s (rev. 0x%02x)\n", devinfo, 122 PCI_REVISION(pa->pa_class)); 123 124 vga_common_attach(self, pa->pa_iot, pa->pa_memt, 125 WSDISPLAY_TYPE_PCIVGA, NULL); 126 } 127 128 int 129 vga_pci_cnattach(iot, memt, pc, bus, device, function) 130 bus_space_tag_t iot, memt; 131 pci_chipset_tag_t pc; 132 int bus, device, function; 133 { 134 return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_PCIVGA, 0)); 135 } 136