1 /* $NetBSD: pci_machdep.c,v 1.15 2001/07/16 00:55:17 elric 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 /* 31 * Machine-specific functions for PCI autoconfiguration. 32 */ 33 34 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 35 36 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.15 2001/07/16 00:55:17 elric Exp $"); 37 38 #include <sys/types.h> 39 #include <sys/param.h> 40 #include <sys/time.h> 41 #include <sys/systm.h> 42 #include <sys/errno.h> 43 #include <sys/device.h> 44 45 #include <uvm/uvm_extern.h> 46 47 #include <dev/isa/isavar.h> 48 #include <dev/pci/pcireg.h> 49 #include <dev/pci/pcivar.h> 50 #include <dev/pci/pcidevs.h> 51 52 #include "vga_pci.h" 53 #if NVGA_PCI 54 #include <dev/ic/mc6845reg.h> 55 #include <dev/ic/pcdisplayvar.h> 56 #include <dev/pci/vga_pcivar.h> 57 #endif 58 59 #include "tga.h" 60 #if NTGA 61 #include <dev/pci/tgavar.h> 62 #endif 63 64 void 65 pci_display_console(iot, memt, pc, bus, device, function) 66 bus_space_tag_t iot, memt; 67 pci_chipset_tag_t pc; 68 int bus, device, function; 69 { 70 pcitag_t tag; 71 pcireg_t id, class; 72 int match, nmatch; 73 int (*fn) __P((bus_space_tag_t, bus_space_tag_t, pci_chipset_tag_t, 74 int, int, int)); 75 76 tag = pci_make_tag(pc, bus, device, function); 77 id = pci_conf_read(pc, tag, PCI_ID_REG); 78 if (id == 0 || id == 0xffffffff) 79 panic("pci_display_console: no device at %d/%d/%d", 80 bus, device, function); 81 class = pci_conf_read(pc, tag, PCI_CLASS_REG); 82 83 nmatch = match = 0; /* XXX really only if we've got FBs configured */ 84 fn = NULL; 85 86 #if NVGA_PCI 87 nmatch = DEVICE_IS_VGA_PCI(class, id); 88 if (nmatch > match) { 89 match = nmatch; 90 fn = vga_pci_cnattach; 91 } 92 #endif 93 #if NTGA 94 nmatch = DEVICE_IS_TGA(class, id); 95 if (nmatch > match) 96 nmatch = tga_cnmatch(iot, memt, pc, tag); 97 if (nmatch > match) { 98 match = nmatch; 99 fn = tga_cnattach; 100 } 101 #endif 102 103 if (fn != NULL) 104 (*fn)(iot, memt, pc, bus, device, function); 105 else 106 panic("pci_display_console: unconfigured device at %d/%d/%d", 107 bus, device, function); 108 } 109