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.
26 * $FreeBSD: src/sys/isa/vga_isa.c,v 1.17 2000/01/29 15:08:56 peter Exp $
27 * $DragonFly: src/sys/bus/isa/vga_isa.c,v 1.9 2005/07/10 13:06:18 swildner Exp $
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>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
50 #include <machine/md_var.h>
51 #include <machine/pc/bios.h>
53 #include <dev/video/fb/fbreg.h>
54 #include <dev/video/fb/vgareg.h>
59 #define VGA_SOFTC(unit) \
60 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
62 static devclass_t isavga_devclass;
64 static int isavga_probe(device_t dev);
65 static int isavga_attach(device_t dev);
66 static int isavga_suspend(device_t dev);
67 static int isavga_resume(device_t dev);
69 static device_method_t isavga_methods[] = {
70 DEVMETHOD(device_probe, isavga_probe),
71 DEVMETHOD(device_attach, isavga_attach),
72 DEVMETHOD(device_suspend, isavga_suspend),
73 DEVMETHOD(device_resume, isavga_resume),
75 DEVMETHOD(bus_print_child, bus_generic_print_child),
79 static driver_t isavga_driver = {
85 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
87 #ifdef FB_INSTALL_CDEV
89 static d_open_t isavga_open;
90 static d_close_t isavga_close;
91 static d_read_t isavga_read;
92 static d_write_t isavga_write;
93 static d_ioctl_t isavga_ioctl;
94 static d_mmap_t isavga_mmap;
96 static struct cdevsw isavga_cdevsw = {
97 /* name */ VGA_DRIVER_NAME,
103 /* open */ isavga_open,
104 /* close */ isavga_close,
105 /* read */ isavga_read,
106 /* write */ isavga_write,
107 /* ioctl */ isavga_ioctl,
109 /* mmap */ isavga_mmap,
110 /* strategy */ nostrategy,
115 #endif /* FB_INSTALL_CDEV */
118 isavga_probe(device_t dev)
125 if (isa_get_vendorid(dev))
128 device_set_desc(dev, "Generic ISA VGA");
129 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
131 bus = device_get_parent(dev);
132 bus_set_resource(dev, SYS_RES_IOPORT, 0,
133 adp.va_io_base, adp.va_io_size);
134 bus_set_resource(dev, SYS_RES_MEMORY, 0,
135 adp.va_mem_base, adp.va_mem_size);
137 isa_set_port(dev, adp.va_io_base);
138 isa_set_portsize(dev, adp.va_io_size);
139 isa_set_maddr(dev, adp.va_mem_base);
140 isa_set_msize(dev, adp.va_mem_size);
147 isavga_attach(device_t dev)
150 struct resource *port;
151 struct resource *mem;
156 unit = device_get_unit(dev);
157 sc = device_get_softc(dev);
160 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
161 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
163 mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
164 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
166 error = vga_attach_unit(unit, sc, device_get_flags(dev));
170 #ifdef FB_INSTALL_CDEV
171 /* attach a virtual frame buffer device */
172 cdevsw_add(&isavga_cdevsw, VGA_MKMINOR(-1), VGA_MKMINOR(unit));
173 sc->devt = make_dev(&isavga_cdevsw, VGA_MKMINOR(unit), 0, 0, 02660, "vga%x", VGA_MKMINOR(unit));
174 reference_dev(sc->devt);
175 error = fb_attach(sc->devt, sc->adp);
178 #endif /* FB_INSTALL_CDEV */
181 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
184 device_add_child(dev, "fb", -1);
185 bus_generic_attach(dev);
192 isavga_suspend(device_t dev)
197 sc = device_get_softc(dev);
198 err = bus_generic_suspend(dev);
202 /* Save the video state across the suspend. */
203 if (sc->state_buf != NULL) {
204 free(sc->state_buf, M_TEMP);
205 sc->state_buf = NULL;
207 nbytes = (*vidsw[sc->adp->va_index]->save_state)(sc->adp, NULL, 0);
210 sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT | M_ZERO);
211 if (sc->state_buf == NULL)
214 device_printf(dev, "saving %d bytes of video state\n", nbytes);
215 if ((*vidsw[sc->adp->va_index]->save_state)(sc->adp, sc->state_buf,
217 device_printf(dev, "failed to save state (nbytes=%d)\n",
219 free(sc->state_buf, M_TEMP);
220 sc->state_buf = NULL;
226 isavga_resume(device_t dev)
230 sc = device_get_softc(dev);
231 if (sc->state_buf != NULL) {
232 if ((*vidsw[sc->adp->va_index]->load_state)(sc->adp,
234 device_printf(dev, "failed to reload state\n");
235 free(sc->state_buf, M_TEMP);
236 sc->state_buf = NULL;
239 bus_generic_resume(dev);
243 #ifdef FB_INSTALL_CDEV
246 isavga_open(dev_t dev, int flag, int mode, struct thread *td)
248 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
252 isavga_close(dev_t dev, int flag, int mode, struct thread *td)
254 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
258 isavga_read(dev_t dev, struct uio *uio, int flag)
260 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
264 isavga_write(dev_t dev, struct uio *uio, int flag)
266 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
270 isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
272 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td);
276 isavga_mmap(dev_t dev, vm_offset_t offset, int prot)
278 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, prot);
281 #endif /* FB_INSTALL_CDEV */