2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
34 #include "opt_syscons.h" /* should be removed in the future, XXX */
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
45 #include <machine/bus.h>
46 #include <machine/resource.h>
53 #include <machine/md_var.h>
55 #include <machine/pc/bios.h>
58 #include <dev/fb/fbreg.h>
59 #include <dev/fb/vgareg.h>
61 #include <isa/isareg.h>
62 #include <isa/isavar.h>
65 vga_suspend(device_t dev)
70 sc = device_get_softc(dev);
72 /* Save the video state across the suspend. */
73 if (sc->state_buf != NULL)
75 nbytes = vidd_save_state(sc->adp, NULL, 0);
78 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT);
79 if (sc->state_buf == NULL)
82 device_printf(dev, "saving %d bytes of video state\n", nbytes);
83 if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) {
84 device_printf(dev, "failed to save state (nbytes=%d)\n",
86 free(sc->state_buf, M_TEMP);
91 /* Save the color palette across the suspend. */
92 if (sc->pal_buf != NULL)
94 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT);
95 if (sc->pal_buf == NULL)
98 device_printf(dev, "saving color palette\n");
99 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) {
100 device_printf(dev, "failed to save palette\n");
101 free(sc->pal_buf, M_TEMP);
107 vga_resume(device_t dev)
111 sc = device_get_softc(dev);
113 if (sc->state_buf != NULL) {
114 if (vidd_load_state(sc->adp, sc->state_buf) != 0)
115 device_printf(dev, "failed to reload state\n");
116 free(sc->state_buf, M_TEMP);
117 sc->state_buf = NULL;
119 if (sc->pal_buf != NULL) {
120 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0)
121 device_printf(dev, "failed to reload palette\n");
122 free(sc->pal_buf, M_TEMP);
127 #define VGA_SOFTC(unit) \
128 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
130 static devclass_t isavga_devclass;
132 #ifdef FB_INSTALL_CDEV
134 static d_open_t isavga_open;
135 static d_close_t isavga_close;
136 static d_read_t isavga_read;
137 static d_write_t isavga_write;
138 static d_ioctl_t isavga_ioctl;
139 static d_mmap_t isavga_mmap;
141 static struct cdevsw isavga_cdevsw = {
142 .d_version = D_VERSION,
143 .d_flags = D_NEEDGIANT,
144 .d_open = isavga_open,
145 .d_close = isavga_close,
146 .d_read = isavga_read,
147 .d_write = isavga_write,
148 .d_ioctl = isavga_ioctl,
149 .d_mmap = isavga_mmap,
150 .d_name = VGA_DRIVER_NAME,
153 #endif /* FB_INSTALL_CDEV */
156 isavga_identify(driver_t *driver, device_t parent)
158 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
162 isavga_probe(device_t dev)
168 if (isa_get_vendorid(dev))
171 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
173 device_set_desc(dev, "Generic ISA VGA");
174 bus_set_resource(dev, SYS_RES_IOPORT, 0,
175 adp.va_io_base, adp.va_io_size);
176 bus_set_resource(dev, SYS_RES_MEMORY, 0,
177 adp.va_mem_base, adp.va_mem_size);
178 isa_set_vendorid(dev, PNP_EISAID("PNP0900"));
180 isa_set_port(dev, adp.va_io_base);
181 isa_set_portsize(dev, adp.va_io_size);
182 isa_set_maddr(dev, adp.va_mem_base);
183 isa_set_msize(dev, adp.va_mem_size);
190 isavga_attach(device_t dev)
197 unit = device_get_unit(dev);
198 sc = device_get_softc(dev);
201 bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
202 RF_ACTIVE | RF_SHAREABLE);
204 bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
205 RF_ACTIVE | RF_SHAREABLE);
207 error = vga_attach_unit(unit, sc, device_get_flags(dev));
211 #ifdef FB_INSTALL_CDEV
212 /* attach a virtual frame buffer device */
213 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw);
216 #endif /* FB_INSTALL_CDEV */
218 if (0 && bootverbose)
219 vidd_diag(sc->adp, bootverbose);
221 #if 0 /* experimental */
222 device_add_child(dev, "fb", -1);
223 bus_generic_attach(dev);
230 isavga_suspend(device_t dev)
234 error = bus_generic_suspend(dev);
243 isavga_resume(device_t dev)
248 return (bus_generic_resume(dev));
251 #ifdef FB_INSTALL_CDEV
254 isavga_open(struct cdev *dev, int flag, int mode, struct thread *td)
256 return (vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
260 isavga_close(struct cdev *dev, int flag, int mode, struct thread *td)
262 return (vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
266 isavga_read(struct cdev *dev, struct uio *uio, int flag)
268 return (vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
272 isavga_write(struct cdev *dev, struct uio *uio, int flag)
274 return (vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
278 isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
280 return (vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td));
284 isavga_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
285 int prot, vm_memattr_t *memattr)
287 return (vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot,
291 #endif /* FB_INSTALL_CDEV */
293 static device_method_t isavga_methods[] = {
294 DEVMETHOD(device_identify, isavga_identify),
295 DEVMETHOD(device_probe, isavga_probe),
296 DEVMETHOD(device_attach, isavga_attach),
297 DEVMETHOD(device_suspend, isavga_suspend),
298 DEVMETHOD(device_resume, isavga_resume),
303 static driver_t isavga_driver = {
309 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
311 static devclass_t vgapm_devclass;
314 vgapm_identify(driver_t *driver, device_t parent)
317 if (device_get_flags(parent) != 0)
318 device_add_child(parent, "vgapm", 0);
322 vgapm_probe(device_t dev)
325 device_set_desc(dev, "VGA suspend/resume");
328 return (BUS_PROBE_DEFAULT);
332 vgapm_attach(device_t dev)
335 bus_generic_probe(dev);
336 bus_generic_attach(dev);
342 vgapm_suspend(device_t dev)
347 error = bus_generic_suspend(dev);
350 vga_dev = devclass_get_device(isavga_devclass, 0);
353 vga_suspend(vga_dev);
359 vgapm_resume(device_t dev)
363 vga_dev = devclass_get_device(isavga_devclass, 0);
367 return (bus_generic_resume(dev));
370 static device_method_t vgapm_methods[] = {
371 DEVMETHOD(device_identify, vgapm_identify),
372 DEVMETHOD(device_probe, vgapm_probe),
373 DEVMETHOD(device_attach, vgapm_attach),
374 DEVMETHOD(device_suspend, vgapm_suspend),
375 DEVMETHOD(device_resume, vgapm_resume),
379 static driver_t vgapm_driver = {
385 DRIVER_MODULE(vgapm, vgapci, vgapm_driver, vgapm_devclass, 0, 0);