The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/isa/vga_isa.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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$");
   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/malloc.h>
   38 #include <sys/module.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 #ifdef __i386__
   53 #include <machine/pc/bios.h>
   54 #endif
   55 
   56 #include <dev/fb/fbreg.h>
   57 #include <dev/fb/vgareg.h>
   58 
   59 #include <isa/isareg.h>
   60 #include <isa/isavar.h>
   61 
   62 #define VGA_SOFTC(unit)         \
   63         ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
   64 
   65 static devclass_t       isavga_devclass;
   66 
   67 #ifdef FB_INSTALL_CDEV
   68 
   69 static d_open_t         isavga_open;
   70 static d_close_t        isavga_close;
   71 static d_read_t         isavga_read;
   72 static d_write_t        isavga_write;
   73 static d_ioctl_t        isavga_ioctl;
   74 static d_mmap_t         isavga_mmap;
   75 
   76 static struct cdevsw isavga_cdevsw = {
   77         .d_version =    D_VERSION,
   78         .d_flags =      D_NEEDGIANT,
   79         .d_open =       isavga_open,
   80         .d_close =      isavga_close,
   81         .d_read =       isavga_read,
   82         .d_write =      isavga_write,
   83         .d_ioctl =      isavga_ioctl,
   84         .d_mmap =       isavga_mmap,
   85         .d_name =       VGA_DRIVER_NAME,
   86         .d_maj =        -1,
   87 };
   88 
   89 #endif /* FB_INSTALL_CDEV */
   90 
   91 static void
   92 isavga_identify(driver_t *driver, device_t parent)
   93 {
   94         BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
   95 }
   96 
   97 static int
   98 isavga_probe(device_t dev)
   99 {
  100         video_adapter_t adp;
  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_set_resource(dev, SYS_RES_IOPORT, 0,
  111                                  adp.va_io_base, adp.va_io_size);
  112                 bus_set_resource(dev, SYS_RES_MEMORY, 0,
  113                                  adp.va_mem_base, adp.va_mem_size);
  114 #if 0
  115                 isa_set_port(dev, adp.va_io_base);
  116                 isa_set_portsize(dev, adp.va_io_size);
  117                 isa_set_maddr(dev, adp.va_mem_base);
  118                 isa_set_msize(dev, adp.va_mem_size);
  119 #endif
  120         }
  121         return error;
  122 }
  123 
  124 static int
  125 isavga_attach(device_t dev)
  126 {
  127         vga_softc_t *sc;
  128         int unit;
  129         int rid;
  130         int error;
  131 
  132         unit = device_get_unit(dev);
  133         sc = device_get_softc(dev);
  134 
  135         rid = 0;
  136         bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
  137                                   0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
  138         rid = 0;
  139         bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
  140                                  0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
  141 
  142         error = vga_attach_unit(unit, sc, device_get_flags(dev));
  143         if (error)
  144                 return error;
  145 
  146 #ifdef FB_INSTALL_CDEV
  147         /* attach a virtual frame buffer device */
  148         error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw);
  149         if (error)
  150                 return error;
  151 #endif /* FB_INSTALL_CDEV */
  152 
  153         if (bootverbose)
  154                 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
  155 
  156 #if experimental
  157         device_add_child(dev, "fb", -1);
  158         bus_generic_attach(dev);
  159 #endif
  160 
  161         return 0;
  162 }
  163 
  164 static int
  165 isavga_suspend(device_t dev)
  166 {
  167         vga_softc_t *sc;
  168         int err, nbytes;
  169 
  170         sc = device_get_softc(dev);
  171         err = bus_generic_suspend(dev);
  172         if (err)
  173                 return (err);
  174 
  175         /* Save the video state across the suspend. */
  176         if (sc->state_buf != NULL) {
  177                 free(sc->state_buf, M_TEMP);
  178                 sc->state_buf = NULL;
  179         }
  180         nbytes = (*vidsw[sc->adp->va_index]->save_state)(sc->adp, NULL, 0);
  181         if (nbytes <= 0)
  182                 return (0);
  183         sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT | M_ZERO);
  184         if (sc->state_buf == NULL)
  185                 return (0);
  186         if (bootverbose)
  187                 device_printf(dev, "saving %d bytes of video state\n", nbytes);
  188         if ((*vidsw[sc->adp->va_index]->save_state)(sc->adp, sc->state_buf,
  189             nbytes) != 0) {
  190                 device_printf(dev, "failed to save state (nbytes=%d)\n",
  191                     nbytes);
  192                 free(sc->state_buf, M_TEMP);
  193                 sc->state_buf = NULL;
  194         }
  195         return (0);
  196 }
  197 
  198 static int
  199 isavga_resume(device_t dev)
  200 {
  201         vga_softc_t *sc;
  202 
  203         sc = device_get_softc(dev);
  204         if (sc->state_buf != NULL) {
  205                 if ((*vidsw[sc->adp->va_index]->load_state)(sc->adp,
  206                     sc->state_buf) != 0)
  207                         device_printf(dev, "failed to reload state\n");
  208                 free(sc->state_buf, M_TEMP);
  209                 sc->state_buf = NULL;
  210         }
  211 
  212         bus_generic_resume(dev);
  213         return 0;
  214 }
  215 
  216 #ifdef FB_INSTALL_CDEV
  217 
  218 static int
  219 isavga_open(struct cdev *dev, int flag, int mode, struct thread *td)
  220 {
  221         return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
  222 }
  223 
  224 static int
  225 isavga_close(struct cdev *dev, int flag, int mode, struct thread *td)
  226 {
  227         return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td);
  228 }
  229 
  230 static int
  231 isavga_read(struct cdev *dev, struct uio *uio, int flag)
  232 {
  233         return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
  234 }
  235 
  236 static int
  237 isavga_write(struct cdev *dev, struct uio *uio, int flag)
  238 {
  239         return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag);
  240 }
  241 
  242 static int
  243 isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
  244 {
  245         return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td);
  246 }
  247 
  248 static int
  249 isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
  250 {
  251         return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot);
  252 }
  253 
  254 #endif /* FB_INSTALL_CDEV */
  255 
  256 static device_method_t isavga_methods[] = {
  257         DEVMETHOD(device_identify,      isavga_identify),
  258         DEVMETHOD(device_probe,         isavga_probe),
  259         DEVMETHOD(device_attach,        isavga_attach),
  260         DEVMETHOD(device_suspend,       isavga_suspend),
  261         DEVMETHOD(device_resume,        isavga_resume),
  262 
  263         DEVMETHOD(bus_print_child,      bus_generic_print_child),
  264         { 0, 0 }
  265 };
  266 
  267 static driver_t isavga_driver = {
  268         VGA_DRIVER_NAME,
  269         isavga_methods,
  270         sizeof(vga_softc_t),
  271 };
  272 
  273 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);

Cache object: 94299821ccb5825e5baa26c7b3366348


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.