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/module.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
50 #include <machine/md_var.h>
52 #include <machine/pc/bios.h>
55 #include <dev/fb/fbreg.h>
56 #include <dev/fb/vgareg.h>
58 #include <isa/isareg.h>
59 #include <isa/isavar.h>
61 #define VGA_SOFTC(unit) \
62 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
64 static devclass_t isavga_devclass;
66 #ifdef FB_INSTALL_CDEV
68 static d_open_t isavga_open;
69 static d_close_t isavga_close;
70 static d_read_t isavga_read;
71 static d_write_t isavga_write;
72 static d_ioctl_t isavga_ioctl;
73 static d_mmap_t isavga_mmap;
75 static struct cdevsw isavga_cdevsw = {
76 .d_version = D_VERSION,
77 .d_flags = D_NEEDGIANT,
78 .d_open = isavga_open,
79 .d_close = isavga_close,
80 .d_read = isavga_read,
81 .d_write = isavga_write,
82 .d_ioctl = isavga_ioctl,
83 .d_mmap = isavga_mmap,
84 .d_name = VGA_DRIVER_NAME,
88 #endif /* FB_INSTALL_CDEV */
91 isavga_identify(driver_t *driver, device_t parent)
93 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
97 isavga_probe(device_t dev)
103 if (isa_get_vendorid(dev))
106 device_set_desc(dev, "Generic ISA VGA");
107 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
109 bus_set_resource(dev, SYS_RES_IOPORT, 0,
110 adp.va_io_base, adp.va_io_size);
111 bus_set_resource(dev, SYS_RES_MEMORY, 0,
112 adp.va_mem_base, adp.va_mem_size);
114 isa_set_port(dev, adp.va_io_base);
115 isa_set_portsize(dev, adp.va_io_size);
116 isa_set_maddr(dev, adp.va_mem_base);
117 isa_set_msize(dev, adp.va_mem_size);
124 isavga_attach(device_t dev)
131 unit = device_get_unit(dev);
132 sc = device_get_softc(dev);
135 bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
136 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
138 bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
139 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
141 error = vga_attach_unit(unit, sc, device_get_flags(dev));
145 #ifdef FB_INSTALL_CDEV
146 /* attach a virtual frame buffer device */
147 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw);
150 #endif /* FB_INSTALL_CDEV */
153 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
156 device_add_child(dev, "fb", -1);
157 bus_generic_attach(dev);
163 #ifdef FB_INSTALL_CDEV
166 isavga_open(struct cdev *dev, int flag, int mode, struct thread *td)
168 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
172 isavga_close(struct cdev *dev, int flag, int mode, struct thread *td)
174 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
178 isavga_read(struct cdev *dev, struct uio *uio, int flag)
180 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
184 isavga_write(struct cdev *dev, struct uio *uio, int flag)
186 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
190 isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
192 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td);
196 isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
198 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot);
201 #endif /* FB_INSTALL_CDEV */
203 static device_method_t isavga_methods[] = {
204 DEVMETHOD(device_identify, isavga_identify),
205 DEVMETHOD(device_probe, isavga_probe),
206 DEVMETHOD(device_attach, isavga_attach),
208 DEVMETHOD(bus_print_child, bus_generic_print_child),
212 static driver_t isavga_driver = {
218 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);