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