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 "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 60 static devclass_t isavga_devclass; 61 62 #ifdef FB_INSTALL_CDEV 63 64 static d_open_t isavga_open; 65 static d_close_t isavga_close; 66 static d_read_t isavga_read; 67 static d_write_t isavga_write; 68 static d_ioctl_t isavga_ioctl; 69 static d_mmap_t isavga_mmap; 70 71 static struct cdevsw isavga_cdevsw = { 72 /* open */ isavga_open, 73 /* close */ isavga_close, 74 /* read */ isavga_read, 75 /* write */ isavga_write, 76 /* ioctl */ isavga_ioctl, 77 /* poll */ nopoll, 78 /* mmap */ isavga_mmap, 79 /* strategy */ nostrategy, 80 /* name */ VGA_DRIVER_NAME, 81 /* maj */ -1, 82 /* dump */ nodump, 83 /* psize */ nopsize, 84 /* flags */ 0, 85 /* bmaj */ -1 86 }; 87 88 #endif /* FB_INSTALL_CDEV */ 89 90 static void 91 isavga_identify(driver_t *driver, device_t parent) 92 { 93 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); 94 } 95 96 static int 97 isavga_probe(device_t dev) 98 { 99 video_adapter_t adp; 100 device_t bus; 101 int error; 102 103 /* No pnp support */ 104 if (isa_get_vendorid(dev)) 105 return (ENXIO); 106 107 device_set_desc(dev, "Generic ISA VGA"); 108 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 109 if (error == 0) { 110 bus = device_get_parent(dev); 111 bus_set_resource(dev, SYS_RES_IOPORT, 0, 112 adp.va_io_base, adp.va_io_size); 113 bus_set_resource(dev, SYS_RES_MEMORY, 0, 114 adp.va_mem_base, adp.va_mem_size); 115 #if 0 116 isa_set_port(dev, adp.va_io_base); 117 isa_set_portsize(dev, adp.va_io_size); 118 isa_set_maddr(dev, adp.va_mem_base); 119 isa_set_msize(dev, adp.va_mem_size); 120 #endif 121 } 122 return error; 123 } 124 125 static int 126 isavga_attach(device_t dev) 127 { 128 vga_softc_t *sc; 129 struct resource *port; 130 struct resource *mem; 131 int unit; 132 int rid; 133 int error; 134 135 unit = device_get_unit(dev); 136 sc = device_get_softc(dev); 137 138 rid = 0; 139 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 140 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 141 rid = 0; 142 mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 143 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 144 145 error = vga_attach_unit(unit, sc, device_get_flags(dev)); 146 if (error) 147 return error; 148 149 #ifdef FB_INSTALL_CDEV 150 /* attach a virtual frame buffer device */ 151 error = fb_attach(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw); 152 if (error) 153 return error; 154 #endif /* FB_INSTALL_CDEV */ 155 156 if (bootverbose) 157 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); 158 159 #if experimental 160 device_add_child(dev, "fb", -1); 161 bus_generic_attach(dev); 162 #endif 163 164 return 0; 165 } 166 167 #ifdef FB_INSTALL_CDEV 168 169 static int 170 isavga_open(dev_t dev, int flag, int mode, struct proc *p) 171 { 172 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p); 173 } 174 175 static int 176 isavga_close(dev_t dev, int flag, int mode, struct proc *p) 177 { 178 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, p); 179 } 180 181 static int 182 isavga_read(dev_t dev, struct uio *uio, int flag) 183 { 184 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 185 } 186 187 static int 188 isavga_write(dev_t dev, struct uio *uio, int flag) 189 { 190 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 191 } 192 193 static int 194 isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p) 195 { 196 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, p); 197 } 198 199 static int 200 isavga_mmap(dev_t dev, vm_offset_t offset, int prot) 201 { 202 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, prot); 203 } 204 205 #endif /* FB_INSTALL_CDEV */ 206 207 static device_method_t isavga_methods[] = { 208 DEVMETHOD(device_identify, isavga_identify), 209 DEVMETHOD(device_probe, isavga_probe), 210 DEVMETHOD(device_attach, isavga_attach), 211 212 DEVMETHOD(bus_print_child, bus_generic_print_child), 213 { 0, 0 } 214 }; 215 216 static driver_t isavga_driver = { 217 VGA_DRIVER_NAME, 218 isavga_methods, 219 sizeof(vga_softc_t), 220 }; 221 222 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); 223