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: releng/8.3/sys/isa/vga_isa.c 230714 2012-01-29 01:22:48Z marius $");
   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 static void
   63 vga_suspend(device_t dev)
   64 {
   65         vga_softc_t *sc;
   66         int nbytes;
   67 
   68         sc = device_get_softc(dev);
   69 
   70         /* Save the video state across the suspend. */
   71         if (sc->state_buf != NULL)
   72                 goto save_palette;
   73         nbytes = vidd_save_state(sc->adp, NULL, 0);
   74         if (nbytes <= 0)
   75                 goto save_palette;
   76         sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT);
   77         if (sc->state_buf == NULL)
   78                 goto save_palette;
   79         if (bootverbose)
   80                 device_printf(dev, "saving %d bytes of video state\n", nbytes);
   81         if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) {
   82                 device_printf(dev, "failed to save state (nbytes=%d)\n",
   83                     nbytes);
   84                 free(sc->state_buf, M_TEMP);
   85                 sc->state_buf = NULL;
   86         }
   87 
   88 save_palette:
   89         /* Save the color palette across the suspend. */
   90         if (sc->pal_buf != NULL)
   91                 return;
   92         sc->pal_buf = malloc(256 * 3, M_TEMP, M_NOWAIT);
   93         if (sc->pal_buf == NULL)
   94                 return;
   95         if (bootverbose)
   96                 device_printf(dev, "saving color palette\n");
   97         if (vidd_save_palette(sc->adp, sc->pal_buf) != 0) {
   98                 device_printf(dev, "failed to save palette\n");
   99                 free(sc->pal_buf, M_TEMP);
  100                 sc->pal_buf = NULL;
  101         }
  102 }
  103 
  104 static void
  105 vga_resume(device_t dev)
  106 {
  107         vga_softc_t *sc;
  108 
  109         sc = device_get_softc(dev);
  110 
  111         if (sc->state_buf != NULL) {
  112                 if (vidd_load_state(sc->adp, sc->state_buf) != 0)
  113                         device_printf(dev, "failed to reload state\n");
  114                 free(sc->state_buf, M_TEMP);
  115                 sc->state_buf = NULL;
  116         }
  117         if (sc->pal_buf != NULL) {
  118                 if (vidd_load_palette(sc->adp, sc->pal_buf) != 0)
  119                         device_printf(dev, "failed to reload palette\n");
  120                 free(sc->pal_buf, M_TEMP);
  121                 sc->pal_buf = NULL;
  122         }
  123 }
  124 
  125 #define VGA_SOFTC(unit)         \
  126         ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit))
  127 
  128 static devclass_t       isavga_devclass;
  129 
  130 #ifdef FB_INSTALL_CDEV
  131 
  132 static d_open_t         isavga_open;
  133 static d_close_t        isavga_close;
  134 static d_read_t         isavga_read;
  135 static d_write_t        isavga_write;
  136 static d_ioctl_t        isavga_ioctl;
  137 static d_mmap_t         isavga_mmap;
  138 
  139 static struct cdevsw isavga_cdevsw = {
  140         .d_version =    D_VERSION,
  141         .d_flags =      D_NEEDGIANT,
  142         .d_open =       isavga_open,
  143         .d_close =      isavga_close,
  144         .d_read =       isavga_read,
  145         .d_write =      isavga_write,
  146         .d_ioctl =      isavga_ioctl,
  147         .d_mmap =       isavga_mmap,
  148         .d_name =       VGA_DRIVER_NAME,
  149 };
  150 
  151 #endif /* FB_INSTALL_CDEV */
  152 
  153 static void
  154 isavga_identify(driver_t *driver, device_t parent)
  155 {
  156         BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0);
  157 }
  158 
  159 static int
  160 isavga_probe(device_t dev)
  161 {
  162         video_adapter_t adp;
  163         int error;
  164 
  165         /* No pnp support */
  166         if (isa_get_vendorid(dev))
  167                 return (ENXIO);
  168 
  169         error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev));
  170         if (error == 0) {
  171                 device_set_desc(dev, "Generic ISA VGA");
  172                 bus_set_resource(dev, SYS_RES_IOPORT, 0,
  173                                  adp.va_io_base, adp.va_io_size);
  174                 bus_set_resource(dev, SYS_RES_MEMORY, 0,
  175                                  adp.va_mem_base, adp.va_mem_size);
  176 #if 0
  177                 isa_set_port(dev, adp.va_io_base);
  178                 isa_set_portsize(dev, adp.va_io_size);
  179                 isa_set_maddr(dev, adp.va_mem_base);
  180                 isa_set_msize(dev, adp.va_mem_size);
  181 #endif
  182         }
  183         return (error);
  184 }
  185 
  186 static int
  187 isavga_attach(device_t dev)
  188 {
  189         vga_softc_t *sc;
  190         int unit;
  191         int rid;
  192         int error;
  193 
  194         unit = device_get_unit(dev);
  195         sc = device_get_softc(dev);
  196 
  197         rid = 0;
  198         bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
  199                                   0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
  200         rid = 0;
  201         bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
  202                                  0, ~0, 0, RF_ACTIVE | RF_SHAREABLE);
  203 
  204         error = vga_attach_unit(unit, sc, device_get_flags(dev));
  205         if (error)
  206                 return (error);
  207 
  208 #ifdef FB_INSTALL_CDEV
  209         /* attach a virtual frame buffer device */
  210         error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw);
  211         if (error)
  212                 return (error);
  213 #endif /* FB_INSTALL_CDEV */
  214 
  215         if (0 && bootverbose)
  216                 vidd_diag(sc->adp, bootverbose);
  217 
  218 #if 0 /* experimental */
  219         device_add_child(dev, "fb", -1);
  220         bus_generic_attach(dev);
  221 #endif
  222 
  223         return (0);
  224 }
  225 
  226 static int
  227 isavga_suspend(device_t dev)
  228 {
  229         int error;
  230 
  231         error = bus_generic_suspend(dev);
  232         if (error != 0)
  233                 return (error);
  234         vga_suspend(dev);
  235 
  236         return (error);
  237 }
  238 
  239 static int
  240 isavga_resume(device_t dev)
  241 {
  242 
  243         vga_resume(dev);
  244 
  245         return (bus_generic_resume(dev));
  246 }
  247 
  248 #ifdef FB_INSTALL_CDEV
  249 
  250 static int
  251 isavga_open(struct cdev *dev, int flag, int mode, struct thread *td)
  252 {
  253         return (vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
  254 }
  255 
  256 static int
  257 isavga_close(struct cdev *dev, int flag, int mode, struct thread *td)
  258 {
  259         return (vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td));
  260 }
  261 
  262 static int
  263 isavga_read(struct cdev *dev, struct uio *uio, int flag)
  264 {
  265         return (vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
  266 }
  267 
  268 static int
  269 isavga_write(struct cdev *dev, struct uio *uio, int flag)
  270 {
  271         return (vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag));
  272 }
  273 
  274 static int
  275 isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
  276 {
  277         return (vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td));
  278 }
  279 
  280 static int
  281 isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
  282 {
  283         return (vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot));
  284 }
  285 
  286 #endif /* FB_INSTALL_CDEV */
  287 
  288 static device_method_t isavga_methods[] = {
  289         DEVMETHOD(device_identify,      isavga_identify),
  290         DEVMETHOD(device_probe,         isavga_probe),
  291         DEVMETHOD(device_attach,        isavga_attach),
  292         DEVMETHOD(device_suspend,       isavga_suspend),
  293         DEVMETHOD(device_resume,        isavga_resume),
  294 
  295         DEVMETHOD_END
  296 };
  297 
  298 static driver_t isavga_driver = {
  299         VGA_DRIVER_NAME,
  300         isavga_methods,
  301         sizeof(vga_softc_t),
  302 };
  303 
  304 DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0);
  305 
  306 static devclass_t       vgapm_devclass;
  307 
  308 static void
  309 vgapm_identify(driver_t *driver, device_t parent)
  310 {
  311 
  312         if (device_get_flags(parent) != 0)
  313                 device_add_child(parent, "vgapm", 0);
  314 }
  315 
  316 static int
  317 vgapm_probe(device_t dev)
  318 {
  319 
  320         device_set_desc(dev, "VGA suspend/resume");
  321         device_quiet(dev);
  322 
  323         return (BUS_PROBE_DEFAULT);
  324 }
  325 
  326 static int
  327 vgapm_attach(device_t dev)
  328 {
  329 
  330         bus_generic_probe(dev);
  331         bus_generic_attach(dev);
  332 
  333         return (0);
  334 }
  335 
  336 static int
  337 vgapm_suspend(device_t dev)
  338 {
  339         device_t vga_dev;
  340         int error;
  341 
  342         error = bus_generic_suspend(dev);
  343         if (error != 0)
  344                 return (error);
  345         vga_dev = devclass_get_device(isavga_devclass, 0);
  346         if (vga_dev == NULL)
  347                 return (0);
  348         vga_suspend(vga_dev);
  349 
  350         return (0);
  351 }
  352 
  353 static int
  354 vgapm_resume(device_t dev)
  355 {
  356         device_t vga_dev;
  357 
  358         vga_dev = devclass_get_device(isavga_devclass, 0);
  359         if (vga_dev != NULL)
  360                 vga_resume(vga_dev);
  361 
  362         return (bus_generic_resume(dev));
  363 }
  364 
  365 static device_method_t vgapm_methods[] = {
  366         DEVMETHOD(device_identify,      vgapm_identify),
  367         DEVMETHOD(device_probe,         vgapm_probe),
  368         DEVMETHOD(device_attach,        vgapm_attach),
  369         DEVMETHOD(device_suspend,       vgapm_suspend),
  370         DEVMETHOD(device_resume,        vgapm_resume),
  371         { 0, 0 }
  372 };
  373 
  374 static driver_t vgapm_driver = {
  375         "vgapm",
  376         vgapm_methods,
  377         0
  378 };
  379 
  380 DRIVER_MODULE(vgapm, vgapci, vgapm_driver, vgapm_devclass, 0, 0);

Cache object: 4ed26b276d792e724a8c768ee1256162


[ 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.