xref: /dragonfly/sys/bus/isa/vga_isa.c (revision 1de703da)
1 /*-
2  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
14  *
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.
25  *
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.2 2003/06/17 04:28:40 dillon Exp $
28  */
29 
30 #include "opt_vga.h"
31 #include "opt_fb.h"
32 #include "opt_syscons.h"	/* should be removed in the future, XXX */
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/conf.h>
38 #include <sys/bus.h>
39 #include <sys/fbio.h>
40 
41 #include <machine/bus.h>
42 #include <machine/resource.h>
43 
44 #include <sys/rman.h>
45 
46 #include <vm/vm.h>
47 #include <vm/pmap.h>
48 
49 #include <machine/md_var.h>
50 #include <machine/pc/bios.h>
51 
52 #include <dev/fb/fbreg.h>
53 #include <dev/fb/vgareg.h>
54 
55 #include <isa/isareg.h>
56 #include <isa/isavar.h>
57 
58 #define VGA_SOFTC(unit)		\
59 	((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
60 
61 static devclass_t	isavga_devclass;
62 
63 static int		isavga_probe(device_t dev);
64 static int		isavga_attach(device_t dev);
65 
66 static device_method_t isavga_methods[] = {
67 	DEVMETHOD(device_probe,		isavga_probe),
68 	DEVMETHOD(device_attach,	isavga_attach),
69 
70 	DEVMETHOD(bus_print_child,	bus_generic_print_child),
71 	{ 0, 0 }
72 };
73 
74 static driver_t isavga_driver = {
75 	VGA_DRIVER_NAME,
76 	isavga_methods,
77 	sizeof(vga_softc_t),
78 };
79 
80 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
81 
82 #ifdef FB_INSTALL_CDEV
83 
84 static d_open_t		isavga_open;
85 static d_close_t	isavga_close;
86 static d_read_t		isavga_read;
87 static d_write_t	isavga_write;
88 static d_ioctl_t	isavga_ioctl;
89 static d_mmap_t		isavga_mmap;
90 
91 static struct cdevsw isavga_cdevsw = {
92 	/* open */	isavga_open,
93 	/* close */	isavga_close,
94 	/* read */	isavga_read,
95 	/* write */	isavga_write,
96 	/* ioctl */	isavga_ioctl,
97 	/* poll */	nopoll,
98 	/* mmap */	isavga_mmap,
99 	/* strategy */	nostrategy,
100 	/* name */	VGA_DRIVER_NAME,
101 	/* maj */	-1,
102 	/* dump */	nodump,
103 	/* psize */	nopsize,
104 	/* flags */	0,
105 	/* bmaj */	-1
106 };
107 
108 #endif /* FB_INSTALL_CDEV */
109 
110 static int
111 isavga_probe(device_t dev)
112 {
113 	video_adapter_t adp;
114 	device_t bus;
115 	int error;
116 
117 	/* No pnp support */
118 	if (isa_get_vendorid(dev))
119 		return (ENXIO);
120 
121 	device_set_desc(dev, "Generic ISA VGA");
122 	error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
123 	if (error == 0) {
124 		bus = device_get_parent(dev);
125 		bus_set_resource(dev, SYS_RES_IOPORT, 0,
126 				 adp.va_io_base, adp.va_io_size);
127 		bus_set_resource(dev, SYS_RES_MEMORY, 0,
128 				 adp.va_mem_base, adp.va_mem_size);
129 #if 0
130 		isa_set_port(dev, adp.va_io_base);
131 		isa_set_portsize(dev, adp.va_io_size);
132 		isa_set_maddr(dev, adp.va_mem_base);
133 		isa_set_msize(dev, adp.va_mem_size);
134 #endif
135 	}
136 	return error;
137 }
138 
139 static int
140 isavga_attach(device_t dev)
141 {
142 	vga_softc_t *sc;
143 	struct resource *port;
144 	struct resource *mem;
145 	int unit;
146 	int rid;
147 	int error;
148 
149 	unit = device_get_unit(dev);
150 	sc = device_get_softc(dev);
151 
152 	rid = 0;
153 	port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
154 				  0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
155 	rid = 0;
156 	mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
157 				 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
158 
159 	error = vga_attach_unit(unit, sc, device_get_flags(dev));
160 	if (error)
161 		return error;
162 
163 #ifdef FB_INSTALL_CDEV
164 	/* attach a virtual frame buffer device */
165 	error = fb_attach(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw);
166 	if (error)
167 		return error;
168 #endif /* FB_INSTALL_CDEV */
169 
170 	if (bootverbose)
171 		(*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
172 
173 #if experimental
174 	device_add_child(dev, "fb", -1);
175 	bus_generic_attach(dev);
176 #endif
177 
178 	return 0;
179 }
180 
181 #ifdef FB_INSTALL_CDEV
182 
183 static int
184 isavga_open(dev_t dev, int flag, int mode, struct proc *p)
185 {
186 	return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p);
187 }
188 
189 static int
190 isavga_close(dev_t dev, int flag, int mode, struct proc *p)
191 {
192 	return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p);
193 }
194 
195 static int
196 isavga_read(dev_t dev, struct uio *uio, int flag)
197 {
198 	return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
199 }
200 
201 static int
202 isavga_write(dev_t dev, struct uio *uio, int flag)
203 {
204 	return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
205 }
206 
207 static int
208 isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
209 {
210 	return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, p);
211 }
212 
213 static int
214 isavga_mmap(dev_t dev, vm_offset_t offset, int prot)
215 {
216 	return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, prot);
217 }
218 
219 #endif /* FB_INSTALL_CDEV */
220