vga_isa.c revision 120465
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 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: head/sys/isa/vga_isa.c 120465 2003-09-26 10:41:44Z phk $"); 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#ifdef __i386__ 51#include <machine/pc/bios.h> 52#endif 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 63static devclass_t isavga_devclass; 64 65#ifdef FB_INSTALL_CDEV 66 67static d_open_t isavga_open; 68static d_close_t isavga_close; 69static d_read_t isavga_read; 70static d_write_t isavga_write; 71static d_ioctl_t isavga_ioctl; 72static d_mmap_t isavga_mmap; 73 74static struct cdevsw isavga_cdevsw = { 75 .d_open = isavga_open, 76 .d_close = isavga_close, 77 .d_read = isavga_read, 78 .d_write = isavga_write, 79 .d_ioctl = isavga_ioctl, 80 .d_mmap = isavga_mmap, 81 .d_name = VGA_DRIVER_NAME, 82 .d_maj = -1, 83}; 84 85#endif /* FB_INSTALL_CDEV */ 86 87static void 88isavga_identify(driver_t *driver, device_t parent) 89{ 90 BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); 91} 92 93static int 94isavga_probe(device_t dev) 95{ 96 video_adapter_t adp; 97 int error; 98 99 /* No pnp support */ 100 if (isa_get_vendorid(dev)) 101 return (ENXIO); 102 103 device_set_desc(dev, "Generic ISA VGA"); 104 error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); 105 if (error == 0) { 106 bus_set_resource(dev, SYS_RES_IOPORT, 0, 107 adp.va_io_base, adp.va_io_size); 108 bus_set_resource(dev, SYS_RES_MEMORY, 0, 109 adp.va_mem_base, adp.va_mem_size); 110#if 0 111 isa_set_port(dev, adp.va_io_base); 112 isa_set_portsize(dev, adp.va_io_size); 113 isa_set_maddr(dev, adp.va_mem_base); 114 isa_set_msize(dev, adp.va_mem_size); 115#endif 116 } 117 return error; 118} 119 120static int 121isavga_attach(device_t dev) 122{ 123 vga_softc_t *sc; 124 int unit; 125 int rid; 126 int error; 127 128 unit = device_get_unit(dev); 129 sc = device_get_softc(dev); 130 131 rid = 0; 132 bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 133 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 134 rid = 0; 135 bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 136 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); 137 138 error = vga_attach_unit(unit, sc, device_get_flags(dev)); 139 if (error) 140 return error; 141 142#ifdef FB_INSTALL_CDEV 143 /* attach a virtual frame buffer device */ 144 error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw); 145 if (error) 146 return error; 147#endif /* FB_INSTALL_CDEV */ 148 149 if (bootverbose) 150 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); 151 152#if experimental 153 device_add_child(dev, "fb", -1); 154 bus_generic_attach(dev); 155#endif 156 157 return 0; 158} 159 160#ifdef FB_INSTALL_CDEV 161 162static int 163isavga_open(dev_t dev, int flag, int mode, struct thread *td) 164{ 165 return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 166} 167 168static int 169isavga_close(dev_t dev, int flag, int mode, struct thread *td) 170{ 171 return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); 172} 173 174static int 175isavga_read(dev_t dev, struct uio *uio, int flag) 176{ 177 return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 178} 179 180static int 181isavga_write(dev_t dev, struct uio *uio, int flag) 182{ 183 return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); 184} 185 186static int 187isavga_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) 188{ 189 return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); 190} 191 192static int 193isavga_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) 194{ 195 return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); 196} 197 198#endif /* FB_INSTALL_CDEV */ 199 200static device_method_t isavga_methods[] = { 201 DEVMETHOD(device_identify, isavga_identify), 202 DEVMETHOD(device_probe, isavga_probe), 203 DEVMETHOD(device_attach, isavga_attach), 204 205 DEVMETHOD(bus_print_child, bus_generic_print_child), 206 { 0, 0 } 207}; 208 209static driver_t isavga_driver = { 210 VGA_DRIVER_NAME, 211 isavga_methods, 212 sizeof(vga_softc_t), 213}; 214 215DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); 216