This source file includes following definitions.
- vga_pci_match
- vga_pci_attach
- vga_pci_mmap
- vga_pci_cnattach
- vga_pci_ioctl
- vga_pci_close
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 #include "vga.h"
66
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/kernel.h>
70 #include <sys/device.h>
71 #include <sys/malloc.h>
72 #include <sys/agpio.h>
73
74 #include <uvm/uvm.h>
75
76 #include <machine/bus.h>
77
78 #include <dev/pci/pcireg.h>
79 #include <dev/pci/pcivar.h>
80 #include <dev/pci/pcidevs.h>
81
82 #include <dev/ic/mc6845reg.h>
83 #include <dev/ic/pcdisplayvar.h>
84 #include <dev/ic/vgareg.h>
85 #include <dev/ic/vgavar.h>
86 #include <dev/pci/vga_pcivar.h>
87
88
89 #include <dev/wscons/wsconsio.h>
90 #include <dev/wscons/wsdisplayvar.h>
91
92 #ifdef VESAFB
93 #include <dev/vesa/vesabiosvar.h>
94 #endif
95
96 int vga_pci_match(struct device *, void *, void *);
97 void vga_pci_attach(struct device *, struct device *, void *);
98 paddr_t vga_pci_mmap(void* v, off_t off, int prot);
99
100 #ifdef VESAFB
101 int vesafb_putcmap(struct vga_pci_softc *, struct wsdisplay_cmap *);
102 int vesafb_getcmap(struct vga_pci_softc *, struct wsdisplay_cmap *);
103 #endif
104
105 struct cfattach vga_pci_ca = {
106 sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach,
107 };
108
109 int
110 vga_pci_match(struct device *parent, void *match, void *aux)
111 {
112 struct pci_attach_args *pa = aux;
113 int potential;
114
115 potential = 0;
116
117
118
119
120
121 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC &&
122 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
123 potential = 1;
124 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
125 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
126 potential = 1;
127
128 if (!potential)
129 return (0);
130
131
132 if ((pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG)
133 & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
134 != (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
135 return (0);
136
137
138 if (vga_is_console(pa->pa_iot, WSDISPLAY_TYPE_PCIVGA))
139 return (1);
140
141
142
143
144 if (!vga_common_probe(pa->pa_iot, pa->pa_memt))
145 return (0);
146
147 return (1);
148 }
149
150 void
151 vga_pci_attach(struct device *parent, struct device *self, void *aux)
152 {
153 struct pci_attach_args *pa = aux;
154 pcireg_t reg;
155 #ifdef VESAFB
156 struct vga_pci_softc *sc = (struct vga_pci_softc *)self;
157 #endif
158
159
160
161
162 reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
163 reg |= PCI_COMMAND_MASTER_ENABLE;
164 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
165
166 #ifdef PCIAGP
167 agp_attach(parent, self, aux);
168 #endif
169 #ifdef VESAFB
170 if (vesabios_softc != NULL && vesabios_softc->sc_nmodes > 0) {
171 sc->sc_textmode = vesafb_get_mode(sc);
172 printf(", vesafb\n");
173 vga_extended_attach(self, pa->pa_iot, pa->pa_memt,
174 WSDISPLAY_TYPE_PCIVGA, vga_pci_mmap);
175 return;
176 }
177 #endif
178 printf("\n");
179 vga_common_attach(self, pa->pa_iot, pa->pa_memt,
180 WSDISPLAY_TYPE_PCIVGA);
181 }
182
183 paddr_t
184 vga_pci_mmap(void *v, off_t off, int prot)
185 {
186 #ifdef VESAFB
187 struct vga_config *vc = (struct vga_config *)v;
188 struct vga_pci_softc *sc = (struct vga_pci_softc *)vc->vc_softc;
189
190 if (sc->sc_mode == WSDISPLAYIO_MODE_DUMBFB) {
191 if (off < 0 || off > vesabios_softc->sc_size)
192 return (-1);
193 return atop(sc->sc_base + off);
194 }
195 #endif
196 #ifdef PCIAGP
197 return agp_mmap(v, off, prot);
198 #else
199 return -1;
200 #endif
201 }
202
203 int
204 vga_pci_cnattach(bus_space_tag_t iot, bus_space_tag_t memt,
205 pci_chipset_tag_t pc, int bus, int device, int function)
206 {
207 return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_PCIVGA, 0));
208 }
209
210 int
211 vga_pci_ioctl(void *v, u_long cmd, caddr_t addr, int flag, struct proc *pb)
212 {
213 int error = 0;
214 #ifdef VESAFB
215 struct vga_config *vc = (struct vga_config *)v;
216 struct vga_pci_softc *sc = (struct vga_pci_softc *)vc->vc_softc;
217 struct wsdisplay_fbinfo *wdf;
218 struct wsdisplay_gfx_mode *gfxmode;
219 int mode;
220 #endif
221
222 switch (cmd) {
223 #ifdef VESAFB
224 case WSDISPLAYIO_SMODE:
225 mode = *(u_int *)addr;
226 switch (mode) {
227 case WSDISPLAYIO_MODE_EMUL:
228
229 vesafb_set_mode(sc, sc->sc_textmode);
230 sc->sc_mode = mode;
231 break;
232 case WSDISPLAYIO_MODE_DUMBFB:
233 if (sc->sc_gfxmode == -1)
234 return (-1);
235 vesafb_set_mode(sc, sc->sc_gfxmode);
236 sc->sc_mode = mode;
237 break;
238 default:
239 error = -1;
240 }
241 break;
242 case WSDISPLAYIO_GINFO:
243 if (sc->sc_gfxmode == -1)
244 return (-1);
245 wdf = (void *)addr;
246 wdf->height = sc->sc_height;
247 wdf->width = sc->sc_width;
248 wdf->depth = sc->sc_depth;
249 wdf->cmsize = 256;
250 break;
251
252 case WSDISPLAYIO_LINEBYTES:
253 if (sc->sc_gfxmode == -1)
254 return (-1);
255 *(u_int *)addr = sc->sc_linebytes;
256 break;
257
258 case WSDISPLAYIO_SVIDEO:
259 case WSDISPLAYIO_GVIDEO:
260 break;
261 case WSDISPLAYIO_GETCMAP:
262 if (sc->sc_depth == 8)
263 error = vesafb_getcmap(sc,
264 (struct wsdisplay_cmap *)addr);
265 break;
266
267 case WSDISPLAYIO_PUTCMAP:
268 if (sc->sc_depth == 8)
269 error = vesafb_putcmap(sc,
270 (struct wsdisplay_cmap *)addr);
271 break;
272
273 case WSDISPLAYIO_GETSUPPORTEDDEPTH:
274 *(int *)addr = vesafb_get_supported_depth(sc);
275 break;
276
277 case WSDISPLAYIO_SETGFXMODE:
278 gfxmode = (struct wsdisplay_gfx_mode *)addr;
279 sc->sc_gfxmode = vesafb_find_mode(sc, gfxmode->width,
280 gfxmode->height, gfxmode->depth);
281 if (sc->sc_gfxmode == -1)
282 error = -1;
283 break;
284
285 #endif
286 #ifdef PCIAGP
287 case AGPIOC_INFO:
288 case AGPIOC_ACQUIRE:
289 case AGPIOC_RELEASE:
290 case AGPIOC_SETUP:
291 case AGPIOC_ALLOCATE:
292 case AGPIOC_DEALLOCATE:
293 case AGPIOC_BIND:
294 case AGPIOC_UNBIND:
295 error = agp_ioctl(v, cmd, addr, flag, pb);
296 break;
297 #endif
298 default:
299 error = ENOTTY;
300 }
301
302 return (error);
303 }
304
305 #ifdef notyet
306 void
307 vga_pci_close(void *v)
308 {
309 #ifdef PCIAGP
310 agp_close(v);
311 #endif
312 }
313 #endif