2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include "opt_syscons.h" /* should be removed in the future, XXX */
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
43 #include <machine/bus.h>
44 #include <machine/resource.h>
51 #include <machine/md_var.h>
53 #include <machine/pc/bios.h>
56 #include <dev/fb/fbreg.h>
57 #include <dev/fb/vgareg.h>
59 #include <isa/isareg.h>
60 #include <isa/isavar.h>
63 vga_suspend(device_t dev)
68 sc = device_get_softc(dev);
70 /* Save the video state across the suspend. */
71 if (sc->state_buf != NULL)
73 nbytes = vidd_save_state(sc->adp, NULL, 0);
76 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT);
77 if (sc->state_buf == NULL)
80 device_printf(dev, "saving %d bytes of video state\n", nbytes);
81 if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) {
82 device_printf(dev, "failed to save state (nbytes=%d)\n",
84 free(sc->state_buf, M_TEMP);
89 /* Save the color palette across the suspend. */
90 if (sc->pal_buf != NULL)
92 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT);
93 if (sc->pal_buf == NULL)
96 device_printf(dev, "saving color palette\n");
97 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) {
98 device_printf(dev, "failed to save palette\n");
99 free(sc->pal_buf, M_TEMP);
105 vga_resume(device_t dev)
109 sc = device_get_softc(dev);
111 if (sc->state_buf != NULL) {
112 if (vidd_load_state(sc->adp, sc->state_buf) != 0)
113 device_printf(dev, "failed to reload state\n");
114 free(sc->state_buf, M_TEMP);
115 sc->state_buf = NULL;
117 if (sc->pal_buf != NULL) {
118 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0)
119 device_printf(dev, "failed to reload palette\n");
120 free(sc->pal_buf, M_TEMP);
125 #define VGA_SOFTC(unit) \
126 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
128 static devclass_t isavga_devclass;
130 #ifdef FB_INSTALL_CDEV
132 static d_open_t isavga_open;
133 static d_close_t isavga_close;
134 static d_read_t isavga_read;
135 static d_write_t isavga_write;
136 static d_ioctl_t isavga_ioctl;
137 static d_mmap_t isavga_mmap;
139 static struct cdevsw isavga_cdevsw = {
140 .d_version = D_VERSION,
141 .d_flags = D_NEEDGIANT,
142 .d_open = isavga_open,
143 .d_close = isavga_close,
144 .d_read = isavga_read,
145 .d_write = isavga_write,
146 .d_ioctl = isavga_ioctl,
147 .d_mmap = isavga_mmap,
148 .d_name = VGA_DRIVER_NAME,
151 #endif /* FB_INSTALL_CDEV */
154 isavga_identify(driver_t *driver, device_t parent)
156 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
160 isavga_probe(device_t dev)
166 if (isa_get_vendorid(dev))
169 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
171 device_set_desc(dev, "Generic ISA VGA");
172 bus_set_resource(dev, SYS_RES_IOPORT, 0,
173 adp.va_io_base, adp.va_io_size);
174 bus_set_resource(dev, SYS_RES_MEMORY, 0,
175 adp.va_mem_base, adp.va_mem_size);
177 isa_set_port(dev, adp.va_io_base);
178 isa_set_portsize(dev, adp.va_io_size);
179 isa_set_maddr(dev, adp.va_mem_base);
180 isa_set_msize(dev, adp.va_mem_size);
187 isavga_attach(device_t dev)
194 unit = device_get_unit(dev);
195 sc = device_get_softc(dev);
198 bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
199 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
201 bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
202 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
204 error = vga_attach_unit(unit, sc, device_get_flags(dev));
208 #ifdef FB_INSTALL_CDEV
209 /* attach a virtual frame buffer device */
210 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw);
213 #endif /* FB_INSTALL_CDEV */
215 if (0 && bootverbose)
216 vidd_diag(sc->adp, bootverbose);
218 #if 0 /* experimental */
219 device_add_child(dev, "fb", -1);
220 bus_generic_attach(dev);
227 isavga_suspend(device_t dev)
231 error = bus_generic_suspend(dev);
240 isavga_resume(device_t dev)
245 return (bus_generic_resume(dev));
248 #ifdef FB_INSTALL_CDEV
251 isavga_open(struct cdev *dev, int flag, int mode, struct thread *td)
253 return (vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
257 isavga_close(struct cdev *dev, int flag, int mode, struct thread *td)
259 return (vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
263 isavga_read(struct cdev *dev, struct uio *uio, int flag)
265 return (vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
269 isavga_write(struct cdev *dev, struct uio *uio, int flag)
271 return (vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
275 isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
277 return (vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td));
281 isavga_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
282 int prot, vm_memattr_t *memattr)
284 return (vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot,
288 #endif /* FB_INSTALL_CDEV */
290 static device_method_t isavga_methods[] = {
291 DEVMETHOD(device_identify, isavga_identify),
292 DEVMETHOD(device_probe, isavga_probe),
293 DEVMETHOD(device_attach, isavga_attach),
294 DEVMETHOD(device_suspend, isavga_suspend),
295 DEVMETHOD(device_resume, isavga_resume),
300 static driver_t isavga_driver = {
306 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
308 static devclass_t vgapm_devclass;
311 vgapm_identify(driver_t *driver, device_t parent)
314 if (device_get_flags(parent) != 0)
315 device_add_child(parent, "vgapm", 0);
319 vgapm_probe(device_t dev)
322 device_set_desc(dev, "VGA suspend/resume");
325 return (BUS_PROBE_DEFAULT);
329 vgapm_attach(device_t dev)
332 bus_generic_probe(dev);
333 bus_generic_attach(dev);
339 vgapm_suspend(device_t dev)
344 error = bus_generic_suspend(dev);
347 vga_dev = devclass_get_device(isavga_devclass, 0);
350 vga_suspend(vga_dev);
356 vgapm_resume(device_t dev)
360 vga_dev = devclass_get_device(isavga_devclass, 0);
364 return (bus_generic_resume(dev));
367 static device_method_t vgapm_methods[] = {
368 DEVMETHOD(device_identify, vgapm_identify),
369 DEVMETHOD(device_probe, vgapm_probe),
370 DEVMETHOD(device_attach, vgapm_attach),
371 DEVMETHOD(device_suspend, vgapm_suspend),
372 DEVMETHOD(device_resume, vgapm_resume),
376 static driver_t vgapm_driver = {
382 DRIVER_MODULE(vgapm, vgapci, vgapm_driver, vgapm_devclass, 0, 0);