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