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>
64 #define VGA_ID 0x0009d041 /* PNP0900 */
66 static struct isa_pnp_id vga_ids[] = {
67 { VGA_ID, NULL }, /* PNP0900 */
72 vga_suspend(device_t dev)
77 sc = device_get_softc(dev);
79 /* Save the video state across the suspend. */
80 if (sc->state_buf != NULL)
82 nbytes = vidd_save_state(sc->adp, NULL, 0);
85 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT);
86 if (sc->state_buf == NULL)
89 device_printf(dev, "saving %d bytes of video state\n", nbytes);
90 if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) {
91 device_printf(dev, "failed to save state (nbytes=%d)\n",
93 free(sc->state_buf, M_TEMP);
98 /* Save the color palette across the suspend. */
99 if (sc->pal_buf != NULL)
101 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT);
102 if (sc->pal_buf == NULL)
105 device_printf(dev, "saving color palette\n");
106 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) {
107 device_printf(dev, "failed to save palette\n");
108 free(sc->pal_buf, M_TEMP);
114 vga_resume(device_t dev)
118 sc = device_get_softc(dev);
120 if (sc->state_buf != NULL) {
121 if (vidd_load_state(sc->adp, sc->state_buf) != 0)
122 device_printf(dev, "failed to reload state\n");
123 free(sc->state_buf, M_TEMP);
124 sc->state_buf = NULL;
126 if (sc->pal_buf != NULL) {
127 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0)
128 device_printf(dev, "failed to reload palette\n");
129 free(sc->pal_buf, M_TEMP);
135 isavga_identify(driver_t *driver, device_t parent)
137 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
141 isavga_probe(device_t dev)
147 if (isa_get_vendorid(dev))
150 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
152 device_set_desc(dev, "Generic ISA VGA");
153 bus_set_resource(dev, SYS_RES_IOPORT, 0,
154 adp.va_io_base, adp.va_io_size);
155 bus_set_resource(dev, SYS_RES_MEMORY, 0,
156 adp.va_mem_base, adp.va_mem_size);
157 isa_set_vendorid(dev, VGA_ID);
158 isa_set_logicalid(dev, VGA_ID);
160 isa_set_port(dev, adp.va_io_base);
161 isa_set_portsize(dev, adp.va_io_size);
162 isa_set_maddr(dev, adp.va_mem_base);
163 isa_set_msize(dev, adp.va_mem_size);
170 isavga_attach(device_t dev)
177 unit = device_get_unit(dev);
178 sc = device_get_softc(dev);
181 bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
182 RF_ACTIVE | RF_SHAREABLE);
184 bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
185 RF_ACTIVE | RF_SHAREABLE);
187 error = vga_attach_unit(unit, sc, device_get_flags(dev));
191 if (0 && bootverbose)
192 vidd_diag(sc->adp, bootverbose);
194 #if 0 /* experimental */
195 device_add_child(dev, "fb", -1);
196 bus_generic_attach(dev);
203 isavga_suspend(device_t dev)
207 error = bus_generic_suspend(dev);
216 isavga_resume(device_t dev)
221 return (bus_generic_resume(dev));
224 static device_method_t isavga_methods[] = {
225 DEVMETHOD(device_identify, isavga_identify),
226 DEVMETHOD(device_probe, isavga_probe),
227 DEVMETHOD(device_attach, isavga_attach),
228 DEVMETHOD(device_suspend, isavga_suspend),
229 DEVMETHOD(device_resume, isavga_resume),
234 static driver_t isavga_driver = {
240 DRIVER_MODULE(vga, isa, isavga_driver, 0, 0);
243 vgapm_identify(driver_t *driver, device_t parent)
246 if (device_get_flags(parent) != 0)
247 device_add_child(parent, "vgapm", 0);
251 vgapm_probe(device_t dev)
254 device_set_desc(dev, "VGA suspend/resume");
257 return (BUS_PROBE_DEFAULT);
261 vgapm_attach(device_t dev)
264 bus_generic_probe(dev);
265 bus_generic_attach(dev);
271 vgapm_suspend(device_t dev)
276 error = bus_generic_suspend(dev);
279 vga_dev = devclass_get_device(devclass_find(VGA_DRIVER_NAME), 0);
282 vga_suspend(vga_dev);
288 vgapm_resume(device_t dev)
292 vga_dev = devclass_get_device(devclass_find(VGA_DRIVER_NAME), 0);
296 return (bus_generic_resume(dev));
299 static device_method_t vgapm_methods[] = {
300 DEVMETHOD(device_identify, vgapm_identify),
301 DEVMETHOD(device_probe, vgapm_probe),
302 DEVMETHOD(device_attach, vgapm_attach),
303 DEVMETHOD(device_suspend, vgapm_suspend),
304 DEVMETHOD(device_resume, vgapm_resume),
308 static driver_t vgapm_driver = {
314 DRIVER_MODULE(vgapm, vgapci, vgapm_driver, 0, 0);
315 ISA_PNP_INFO(vga_ids);