1 /* $OpenBSD: vga_pci.c,v 1.7 1998/01/05 13:35:27 deraadt Exp $ */ 2 /* $NetBSD: vga_pci.c,v 1.4 1996/12/05 01:39:38 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/kernel.h> 34 #include <sys/device.h> 35 #include <sys/malloc.h> 36 37 #ifndef i386 38 #include <machine/autoconf.h> 39 #endif 40 #include <machine/pte.h> 41 42 #include <dev/pci/pcireg.h> 43 #include <dev/pci/pcivar.h> 44 #include <dev/pci/pcidevs.h> 45 46 #include <dev/ic/vgavar.h> 47 #include <dev/pci/vga_pcivar.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 struct vga_config *sc_vc; /* VGA configuration */ 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 int vgapcimmap __P((void *, off_t, int)); 64 int vgapciioctl __P((void *, u_long, caddr_t, int, struct proc *)); 65 66 struct cfattach vga_pci_ca = { 67 sizeof(struct vga_pci_softc), (cfmatch_t)vga_pci_match, vga_pci_attach, 68 }; 69 70 pcitag_t vga_pci_console_tag; 71 struct vga_config vga_pci_console_vc; 72 73 int 74 vga_pci_match(parent, match, aux) 75 struct device *parent; 76 #ifdef __BROKEN_INDIRECT_CONFIG 77 void *match; 78 #else 79 struct cfdata *match; 80 #endif 81 void *aux; 82 { 83 struct pci_attach_args *pa = aux; 84 int potential; 85 86 potential = 0; 87 88 /* 89 * If it's prehistoric/vga or display/vga, we might match. 90 * For the console device, this is jut a sanity check. 91 */ 92 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC && 93 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA) 94 potential = 1; 95 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY && 96 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA) 97 potential = 1; 98 99 if (!potential) 100 return (0); 101 102 /* If it's the console, we have a winner! */ 103 if (!bcmp(&pa->pa_tag, &vga_pci_console_tag, sizeof(pa->pa_tag))) 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 struct vga_config *vc; 123 int console; 124 125 console = (!bcmp(&pa->pa_tag, &vga_pci_console_tag, sizeof(pa->pa_tag))); 126 if (console) 127 vc = sc->sc_vc = &vga_pci_console_vc; 128 else { 129 vc = sc->sc_vc = (struct vga_config *) 130 malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK); 131 132 /* set up bus-independent VGA configuration */ 133 vga_common_setup(pa->pa_iot, pa->pa_memt, vc); 134 } 135 vc->vc_mmap = vgapcimmap; 136 vc->vc_ioctl = vgapciioctl; 137 138 sc->sc_pcitag = pa->pa_tag; 139 140 printf("\n"); 141 142 vga_wscons_attach(self, vc, console); 143 } 144 145 void 146 vga_pci_console(iot, memt, pc, bus, device, function) 147 bus_space_tag_t iot, memt; 148 pci_chipset_tag_t pc; 149 int bus, device, function; 150 { 151 struct vga_config *vc = &vga_pci_console_vc; 152 153 /* for later recognition */ 154 vga_pci_console_tag = pci_make_tag(pc, bus, device, function); 155 156 /* set up bus-independent VGA configuration */ 157 vga_common_setup(iot, memt, vc); 158 159 vga_wscons_console(vc); 160 } 161 162 int 163 vgapciioctl(v, cmd, data, flag, p) 164 void *v; 165 u_long cmd; 166 caddr_t data; 167 int flag; 168 struct proc *p; 169 { 170 struct vga_pci_softc *sc = v; 171 172 return (vgaioctl(sc->sc_vc, cmd, data, flag, p)); 173 } 174 175 int 176 vgapcimmap(v, offset, prot) 177 void *v; 178 off_t offset; 179 int prot; 180 { 181 struct vga_pci_softc *sc = v; 182 183 return (vgammap(sc->sc_vc, offset, prot)); 184 } 185