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$ 27 */ 28 29 #include "vga.h" 30 #include "opt_vga.h" 31 #include "opt_fb.h" 32 #include "opt_syscons.h" /* should be removed in the future, XXX */ 33 34 #if NVGA > 0 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/conf.h> 40 #include <sys/bus.h> 41 #include <sys/fbio.h> 42 43 #include <machine/bus.h> 44 #include <machine/resource.h> 45 46 #include <sys/rman.h> 47 48 #include <vm/vm.h> 49 #include <vm/pmap.h> 50 51 #include <machine/md_var.h> 52 #include <machine/pc/bios.h> 53 54 #include <dev/fb/fbreg.h> 55 #include <dev/fb/vgareg.h> 56 57 #include <isa/isareg.h> 58 #include <isa/isavar.h> 59 60 #define VGA_SOFTC(unit) \ 61 ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) 62 63 static devclass_t isavga_devclass; 64 65 static int isavga_probe(device_t dev); 66 static int isavga_attach(device_t dev); 67 68 static device_method_t isavga_methods[] = { 69 DEVMETHOD(device_probe, isavga_probe), 70 DEVMETHOD(device_attach, isavga_attach), 71 72 DEVMETHOD(bus_print_child, bus_generic_print_child), 73 { 0, 0 } 74 }; 75 76 static driver_t isavga_driver = { 77 VGA_DRIVER_NAME, 78 isavga_methods, 79 sizeof(vga_softc_t), 80 }; 81 82 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); 83 84 #ifdef FB_INSTALL_CDEV 85 86 static d_open_t isavga_open; 87 static d_close_t isavga_close; 88 static d_read_t isavga_read; 89 static d_write_t isavga_write; 90 static d_ioctl_t isavga_ioctl; 91 static d_mmap_t isavga_mmap; 92 93 static struct cdevsw isavga_cdevsw = { 94 /* open */ isavga_open, 95 /* close */ isavga_close, 96 /* read */ isavga_read, 97 /* write */ isavga_write, 98 /* ioctl */ isavga_ioctl, 99 /* poll */ nopoll, 100 /* mmap */ isavga_mmap, 101 /* strategy */ nostrategy, 102 /* name */ VGA_DRIVER_NAME, 103 /* maj */ -1, 104 /* dump */ nodump, 105 /* psize */ nopsize, 106 /* flags */ 0, 107 /* bmaj */ -1 108 }; 109 110 #endif /* FB_INSTALL_CDEV */ 111 112 static int 113 isavga_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 141 static int 142 isavga_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 */ 167 error = fb_attach(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw); 168 if (error) 169 return error; 170 #endif /* FB_INSTALL_CDEV */ 171 172 if (bootverbose) 173 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); 174 175 #if experimental 176 device_add_child(dev, "fb", -1, NULL); 177 bus_generic_attach(dev); 178 #endif 179 180 return 0; 181 } 182 183 #ifdef FB_INSTALL_CDEV 184 185 static int 186 isavga_open(dev_t dev, int flag, int mode, struct proc *p) 187 { 188 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p); 189 } 190 191 static int 192 isavga_close(dev_t dev, int flag, int mode, struct proc *p) 193 { 194 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p); 195 } 196 197 static int 198 isavga_read(dev_t dev, struct uio *uio, int flag) 199 { 200 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 201 } 202 203 static int 204 isavga_write(dev_t dev, struct uio *uio, int flag) 205 { 206 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 207 } 208 209 static int 210 isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p) 211 { 212 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, p); 213 } 214 215 static int 216 isavga_mmap(dev_t dev, vm_offset_t offset, int prot) 217 { 218 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, prot); 219 } 220 221 #endif /* FB_INSTALL_CDEV */ 222 223 #endif /* NVGA > 0 */ 224