Device layer rollup commit.
[dragonfly.git] / sys / bus / isa / vga_isa.c
CommitLineData
984263bc
MD
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 $
e4c9c0c8 27 * $DragonFly: src/sys/bus/isa/vga_isa.c,v 1.8 2004/05/19 22:52:38 dillon Exp $
984263bc
MD
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
1f2de5d4
MD
52#include <dev/video/fb/fbreg.h>
53#include <dev/video/fb/vgareg.h>
984263bc 54
1f2de5d4
MD
55#include "isareg.h"
56#include "isavar.h"
984263bc
MD
57
58#define VGA_SOFTC(unit) \
59 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
60
61static devclass_t isavga_devclass;
62
63static int isavga_probe(device_t dev);
64static int isavga_attach(device_t dev);
65
66static 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
74static driver_t isavga_driver = {
75 VGA_DRIVER_NAME,
76 isavga_methods,
77 sizeof(vga_softc_t),
78};
79
80DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
81
82#ifdef FB_INSTALL_CDEV
83
84static d_open_t isavga_open;
85static d_close_t isavga_close;
86static d_read_t isavga_read;
87static d_write_t isavga_write;
88static d_ioctl_t isavga_ioctl;
89static d_mmap_t isavga_mmap;
90
91static struct cdevsw isavga_cdevsw = {
fabb8ceb
MD
92 /* name */ VGA_DRIVER_NAME,
93 /* maj */ -1,
94 /* flags */ 0,
95 /* port */ NULL,
455fcd7e 96 /* clone */ NULL,
fabb8ceb 97
984263bc
MD
98 /* open */ isavga_open,
99 /* close */ isavga_close,
100 /* read */ isavga_read,
101 /* write */ isavga_write,
102 /* ioctl */ isavga_ioctl,
103 /* poll */ nopoll,
104 /* mmap */ isavga_mmap,
105 /* strategy */ nostrategy,
984263bc 106 /* dump */ nodump,
fabb8ceb 107 /* psize */ nopsize
984263bc
MD
108};
109
110#endif /* FB_INSTALL_CDEV */
111
112static int
113isavga_probe(device_t dev)
114{
115 video_adapter_t adp;
116 device_t bus;
117 int error;
118
119 /* No pnp support */
120 if (isa_get_vendorid(dev))
121 return (ENXIO);
122
123 device_set_desc(dev, "Generic ISA VGA");
124 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
125 if (error == 0) {
126 bus = device_get_parent(dev);
127 bus_set_resource(dev, SYS_RES_IOPORT, 0,
128 adp.va_io_base, adp.va_io_size);
129 bus_set_resource(dev, SYS_RES_MEMORY, 0,
130 adp.va_mem_base, adp.va_mem_size);
131#if 0
132 isa_set_port(dev, adp.va_io_base);
133 isa_set_portsize(dev, adp.va_io_size);
134 isa_set_maddr(dev, adp.va_mem_base);
135 isa_set_msize(dev, adp.va_mem_size);
136#endif
137 }
138 return error;
139}
140
141static int
142isavga_attach(device_t dev)
143{
144 vga_softc_t *sc;
145 struct resource *port;
146 struct resource *mem;
147 int unit;
148 int rid;
149 int error;
150
151 unit = device_get_unit(dev);
152 sc = device_get_softc(dev);
153
154 rid = 0;
155 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
156 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
157 rid = 0;
158 mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
159 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
160
161 error = vga_attach_unit(unit, sc, device_get_flags(dev));
162 if (error)
163 return error;
164
165#ifdef FB_INSTALL_CDEV
166 /* attach a virtual frame buffer device */
e4c9c0c8 167 cdevsw_add(&isavga_cdevsw, VGA_MKMINOR(-1), VGA_MKMINOR(unit));
335dda38 168 sc->devt = make_dev(&isavga_cdevsw, VGA_MKMINOR(unit), 0, 0, 02660, "vga%x", VGA_MKMINOR(unit));
e4c9c0c8 169 reference_dev(sc->devt);
335dda38 170 error = fb_attach(sc->devt, sc->adp);
984263bc
MD
171 if (error)
172 return error;
173#endif /* FB_INSTALL_CDEV */
174
175 if (bootverbose)
176 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
177
178#if experimental
179 device_add_child(dev, "fb", -1);
180 bus_generic_attach(dev);
181#endif
182
183 return 0;
184}
185
186#ifdef FB_INSTALL_CDEV
187
188static int
7b95be2a 189isavga_open(dev_t dev, int flag, int mode, struct thread *td)
984263bc 190{
7b95be2a 191 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
984263bc
MD
192}
193
194static int
7b95be2a 195isavga_close(dev_t dev, int flag, int mode, struct thread *td)
984263bc 196{
7b95be2a 197 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
984263bc
MD
198}
199
200static int
201isavga_read(dev_t dev, struct uio *uio, int flag)
202{
203 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
204}
205
206static int
207isavga_write(dev_t dev, struct uio *uio, int flag)
208{
209 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
210}
211
212static int
7b95be2a 213isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
984263bc 214{
7b95be2a 215 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td);
984263bc
MD
216}
217
218static int
219isavga_mmap(dev_t dev, vm_offset_t offset, int prot)
220{
221 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, prot);
222}
223
224#endif /* FB_INSTALL_CDEV */