xref: /openbsd-src/sys/dev/pci/vga_pci.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /* $OpenBSD: vga_pci.c,v 1.10 2001/05/08 16:16:11 mickey Exp $ */
2 /* $NetBSD: vga_pci.c,v 1.3 1998/06/08 06:55:58 thorpej 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 "vga.h"
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/device.h>
37 #include <sys/malloc.h>
38 
39 #include <dev/pci/pcireg.h>
40 #include <dev/pci/pcivar.h>
41 #include <dev/pci/pcidevs.h>
42 
43 #include <dev/ic/mc6845reg.h>
44 #include <dev/ic/pcdisplayvar.h>
45 #include <dev/ic/vgareg.h>
46 #include <dev/ic/vgavar.h>
47 #include <dev/pci/vga_pcivar.h>
48 
49 #include <dev/wscons/wsconsio.h>
50 #include <dev/wscons/wsdisplayvar.h>
51 
52 struct vga_pci_softc {
53 	struct device sc_dev;
54 
55 	pcitag_t sc_pcitag;		/* PCI tag, in case we need it. */
56 #if 0
57 	struct vga_config *sc_vc;	/* VGA configuration */
58 #endif
59 };
60 
61 int	vga_pci_match __P((struct device *, void *, void *));
62 void	vga_pci_attach __P((struct device *, struct device *, void *));
63 
64 struct cfattach vga_pci_ca = {
65 	sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach,
66 };
67 
68 int
69 vga_pci_match(parent, match, aux)
70 	struct device *parent;
71 	void *match;
72 	void *aux;
73 {
74 	struct pci_attach_args *pa = aux;
75 	int potential;
76 
77 	potential = 0;
78 
79 	/*
80 	 * If it's prehistoric/vga or display/vga, we might match.
81 	 * For the console device, this is jut a sanity check.
82 	 */
83 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC &&
84 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
85 		potential = 1;
86 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
87 	     PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
88 		potential = 1;
89 
90 	if (!potential)
91 		return (0);
92 
93 	/* check whether it is disabled by firmware */
94 	if ((pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG)
95 	    & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
96 	    != (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
97 		return (0);
98 
99 	/* If it's the console, we have a winner! */
100 	if (vga_is_console(pa->pa_iot, WSDISPLAY_TYPE_PCIVGA))
101 		return (1);
102 
103 	/*
104 	 * If we might match, make sure that the card actually looks OK.
105 	 */
106 	if (!vga_common_probe(pa->pa_iot, pa->pa_memt))
107 		return (0);
108 
109 	return (1);
110 }
111 
112 void
113 vga_pci_attach(parent, self, aux)
114 	struct device *parent, *self;
115 	void *aux;
116 {
117 	struct pci_attach_args *pa = aux;
118 	struct vga_pci_softc *sc = (struct vga_pci_softc *)self;
119 	char devinfo[256];
120 
121 	sc->sc_pcitag = pa->pa_tag;
122 
123 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
124 	printf("\n");
125 
126 	vga_common_attach(self, pa->pa_iot, pa->pa_memt,
127 			  WSDISPLAY_TYPE_PCIVGA);
128 }
129 
130 int
131 vga_pci_cnattach(iot, memt, pc, bus, device, function)
132 	bus_space_tag_t iot, memt;
133 	pci_chipset_tag_t pc;
134 	int bus, device, function;
135 {
136 	return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_PCIVGA, 0));
137 }
138 
139 int
140 vga_pci_ioctl(v, cmd, addr, flag, p)
141 	void *v;
142 	u_long cmd;
143 	caddr_t addr;
144 	int flag;
145 	struct proc *p;
146 {
147 	return (ENOTTY);
148 }
149