2 * SPDX-License-Identifier: BSD-2-Clause
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>
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>
62 #define VGA_ID 0x0009d041 /* PNP0900 */
64 static struct isa_pnp_id vga_ids[] = {
65 { VGA_ID, NULL }, /* PNP0900 */
70 vga_suspend(device_t dev)
75 sc = device_get_softc(dev);
77 /* Save the video state across the suspend. */
78 if (sc->state_buf != NULL)
80 nbytes = vidd_save_state(sc->adp, NULL, 0);
83 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT);
84 if (sc->state_buf == NULL)
87 device_printf(dev, "saving %d bytes of video state\n", nbytes);
88 if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) {
89 device_printf(dev, "failed to save state (nbytes=%d)\n",
91 free(sc->state_buf, M_TEMP);
96 /* Save the color palette across the suspend. */
97 if (sc->pal_buf != NULL)
99 sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT);
100 if (sc->pal_buf == NULL)
103 device_printf(dev, "saving color palette\n");
104 if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) {
105 device_printf(dev, "failed to save palette\n");
106 free(sc->pal_buf, M_TEMP);
112 vga_resume(device_t dev)
116 sc = device_get_softc(dev);
118 if (sc->state_buf != NULL) {
119 if (vidd_load_state(sc->adp, sc->state_buf) != 0)
120 device_printf(dev, "failed to reload state\n");
121 free(sc->state_buf, M_TEMP);
122 sc->state_buf = NULL;
124 if (sc->pal_buf != NULL) {
125 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0)
126 device_printf(dev, "failed to reload palette\n");
127 free(sc->pal_buf, M_TEMP);
132 #define VGA_SOFTC(unit) \
133 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
135 static devclass_t isavga_devclass;
137 #ifdef FB_INSTALL_CDEV
139 static d_open_t isavga_open;
140 static d_close_t isavga_close;
141 static d_read_t isavga_read;
142 static d_write_t isavga_write;
143 static d_ioctl_t isavga_ioctl;
144 static d_mmap_t isavga_mmap;
146 static struct cdevsw isavga_cdevsw = {
147 .d_version = D_VERSION,
148 .d_flags = D_NEEDGIANT,
149 .d_open = isavga_open,
150 .d_close = isavga_close,
151 .d_read = isavga_read,
152 .d_write = isavga_write,
153 .d_ioctl = isavga_ioctl,
154 .d_mmap = isavga_mmap,
155 .d_name = VGA_DRIVER_NAME,
158 #endif /* FB_INSTALL_CDEV */
161 isavga_identify(driver_t *driver, device_t parent)
163 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
167 isavga_probe(device_t dev)
173 if (isa_get_vendorid(dev))
176 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
178 device_set_desc(dev, "Generic ISA VGA");
179 bus_set_resource(dev, SYS_RES_IOPORT, 0,
180 adp.va_io_base, adp.va_io_size);
181 bus_set_resource(dev, SYS_RES_MEMORY, 0,
182 adp.va_mem_base, adp.va_mem_size);
183 isa_set_vendorid(dev, VGA_ID);
184 isa_set_logicalid(dev, VGA_ID);
186 isa_set_port(dev, adp.va_io_base);
187 isa_set_portsize(dev, adp.va_io_size);
188 isa_set_maddr(dev, adp.va_mem_base);
189 isa_set_msize(dev, adp.va_mem_size);
196 isavga_attach(device_t dev)
203 unit = device_get_unit(dev);
204 sc = device_get_softc(dev);
207 bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
208 RF_ACTIVE | RF_SHAREABLE);
210 bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
211 RF_ACTIVE | RF_SHAREABLE);
213 error = vga_attach_unit(unit, sc, device_get_flags(dev));
217 #ifdef FB_INSTALL_CDEV
218 /* attach a virtual frame buffer device */
219 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw);
222 #endif /* FB_INSTALL_CDEV */
224 if (0 && bootverbose)
225 vidd_diag(sc->adp, bootverbose);
227 #if 0 /* experimental */
228 device_add_child(dev, "fb", -1);
229 bus_generic_attach(dev);
236 isavga_suspend(device_t dev)
240 error = bus_generic_suspend(dev);
249 isavga_resume(device_t dev)
254 return (bus_generic_resume(dev));
257 #ifdef FB_INSTALL_CDEV
260 isavga_open(struct cdev *dev, int flag, int mode, struct thread *td)
262 return (vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
266 isavga_close(struct cdev *dev, int flag, int mode, struct thread *td)
268 return (vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
272 isavga_read(struct cdev *dev, struct uio *uio, int flag)
274 return (vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
278 isavga_write(struct cdev *dev, struct uio *uio, int flag)
280 return (vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
284 isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
286 return (vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td));
290 isavga_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
291 int prot, vm_memattr_t *memattr)
293 return (vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot,
297 #endif /* FB_INSTALL_CDEV */
299 static device_method_t isavga_methods[] = {
300 DEVMETHOD(device_identify, isavga_identify),
301 DEVMETHOD(device_probe, isavga_probe),
302 DEVMETHOD(device_attach, isavga_attach),
303 DEVMETHOD(device_suspend, isavga_suspend),
304 DEVMETHOD(device_resume, isavga_resume),
309 static driver_t isavga_driver = {
315 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
317 static devclass_t vgapm_devclass;
320 vgapm_identify(driver_t *driver, device_t parent)
323 if (device_get_flags(parent) != 0)
324 device_add_child(parent, "vgapm", 0);
328 vgapm_probe(device_t dev)
331 device_set_desc(dev, "VGA suspend/resume");
334 return (BUS_PROBE_DEFAULT);
338 vgapm_attach(device_t dev)
341 bus_generic_probe(dev);
342 bus_generic_attach(dev);
348 vgapm_suspend(device_t dev)
353 error = bus_generic_suspend(dev);
356 vga_dev = devclass_get_device(isavga_devclass, 0);
359 vga_suspend(vga_dev);
365 vgapm_resume(device_t dev)
369 vga_dev = devclass_get_device(isavga_devclass, 0);
373 return (bus_generic_resume(dev));
376 static device_method_t vgapm_methods[] = {
377 DEVMETHOD(device_identify, vgapm_identify),
378 DEVMETHOD(device_probe, vgapm_probe),
379 DEVMETHOD(device_attach, vgapm_attach),
380 DEVMETHOD(device_suspend, vgapm_suspend),
381 DEVMETHOD(device_resume, vgapm_resume),
385 static driver_t vgapm_driver = {
391 DRIVER_MODULE(vgapm, vgapci, vgapm_driver, vgapm_devclass, 0, 0);
392 ISA_PNP_INFO(vga_ids);