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/dev/gfb/gfb_pci.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
    3  * All rights reserved.
    4  *
    5  * Author: Chris G. Demetriou
    6  * 
    7  * Permission to use, copy, modify and distribute this software and
    8  * its documentation is hereby granted, provided that both the copyright
    9  * notice and this permission notice appear in all copies of the
   10  * software, derivative works or modified versions, and any portions
   11  * thereof, and that both notices appear in supporting documentation.
   12  * 
   13  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
   14  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
   15  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   16  * 
   17  * Carnegie Mellon requests users of this software to return to
   18  *
   19  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   20  *  School of Computer Science
   21  *  Carnegie Mellon University
   22  *  Pittsburgh PA 15213-3890
   23  *
   24  * any improvements or extensions that they make and grant Carnegie the
   25  * rights to redistribute these changes.
   26  *
   27  * Copyright (c) 2000 Andrew Miklic, Andrew Gallatin, and Thomas V. Crimi
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: releng/5.2/sys/dev/gfb/gfb_pci.c 120465 2003-09-26 10:41:44Z phk $");
   32 
   33 #include "opt_fb.h"
   34 
   35 #include <sys/cdefs.h>
   36 __FBSDID("$FreeBSD: releng/5.2/sys/dev/gfb/gfb_pci.c 120465 2003-09-26 10:41:44Z phk $");
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/kernel.h>
   41 #include <sys/conf.h>
   42 #include <sys/proc.h>
   43 #include <sys/fcntl.h>
   44 #include <sys/malloc.h>
   45 #include <sys/fbio.h>
   46 
   47 #include <vm/vm.h>
   48 #include <vm/vm_param.h>
   49 #include <vm/pmap.h>
   50 
   51 #include <machine/md_var.h>
   52 #include <machine/pc/bios.h>
   53 #include <machine/clock.h>
   54 #include <machine/bus_memio.h>
   55 #include <machine/bus.h>
   56 #include <machine/pc/vesa.h>
   57 #include <machine/resource.h>
   58 
   59 #include <sys/bus.h>
   60 #include <sys/rman.h>
   61 
   62 #include <dev/pci/pcireg.h>
   63 #include <dev/pci/pcivar.h>
   64 
   65 #include <dev/fb/fbreg.h>
   66 #include <dev/fb/gfb.h>
   67 #include <dev/gfb/gfb_pci.h>
   68 
   69 #ifdef __alpha__
   70 
   71 #include <machine/rpb.h>
   72 #include <machine/cpu.h>
   73 
   74 #endif /* __alpha__ */
   75 
   76 #if 0
   77 static devclass_t gfb_devclass;
   78 #endif
   79 
   80 #ifdef __alpha__
   81 
   82 extern void sccnattach(void);
   83 
   84 #endif /* __alpha__ */
   85 
   86 extern struct gfb_font bold8x16;
   87 extern struct gfb_softc *gfb_device_softcs[2][16];
   88 
   89 int
   90 pcigfb_attach(device_t dev)
   91 {
   92         int s;
   93         gfb_softc_t sc;
   94         video_adapter_t *adp;
   95         int unit, flags, error, rid, va_index;
   96 #ifdef __alpha__
   97         struct ctb *ctb;
   98 #endif /* __alpha__ */
   99 
  100         s = splimp();
  101         error = 0;
  102         unit = device_get_unit(dev);
  103         flags = device_get_flags(dev);
  104         sc = device_get_softc(dev);
  105         sc->rev = pci_get_revid(dev);
  106         rid = GFB_MEM_BASE_RID;
  107         sc->res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 1,
  108             RF_ACTIVE|PCI_RF_DENSE);
  109         if(sc->res == NULL) {
  110                 device_printf(dev, "couldn't map memory\n");
  111                 goto fail;
  112         }
  113         sc->btag = rman_get_bustag(sc->res);
  114         sc->bhandle = rman_get_bushandle(sc->res);
  115 
  116         /* Allocate interrupt (irq)... */
  117         rid = 0x0;
  118         sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
  119             RF_SHAREABLE|RF_ACTIVE);
  120         if(sc->irq == NULL) {
  121                 device_printf(dev, "Couldn't map interrupt\n");
  122                 goto fail;
  123         }
  124         if((va_index = vid_find_adapter(sc->driver_name, unit)) < 0) {
  125                 sc->adp = (video_adapter_t *)malloc(sizeof(video_adapter_t),
  126                     M_DEVBUF, M_NOWAIT);
  127                 adp = sc->adp;
  128                 bzero(adp, sizeof(video_adapter_t));
  129                 vid_init_struct(adp, sc->driver_name, sc->type, unit);
  130                 if(vid_register(adp) < 0) {
  131                         free(sc->adp, M_DEVBUF);
  132                         goto fail;
  133                 }
  134                 adp->va_flags |= V_ADP_REGISTERED;
  135                 adp->va_model = sc->model;
  136                 adp->va_mem_base = (vm_offset_t)rman_get_virtual(sc->res);
  137                 adp->va_mem_size = rman_get_end(sc->res) -
  138                     rman_get_start(sc->res);
  139                 adp->va_io_base = NULL;
  140                 adp->va_io_size = 0;
  141                 adp->va_crtc_addr = NULL;
  142                 gfb_device_softcs[sc->model][unit] = sc;
  143                 sc->gfbc = (struct gfb_conf *)malloc(sizeof(struct gfb_conf),
  144                     M_DEVBUF, M_NOWAIT);
  145                 bzero(sc->gfbc, sizeof(struct gfb_conf));
  146                 if((*vidsw[adp->va_index]->init)(unit, adp, flags)) {
  147                         device_printf(dev, "Couldn't initialize adapter\n");
  148                         vid_unregister(adp);
  149                         gfb_device_softcs[sc->model][unit] = NULL;
  150                         free(sc->gfbc, M_DEVBUF);
  151                         free(sc->adp, M_DEVBUF);
  152                         goto fail;
  153                 }
  154                 sc->gfbc->palette.red =
  155                     (u_char *)malloc(sc->gfbc->palette.count, M_DEVBUF,
  156                     M_NOWAIT);
  157                 sc->gfbc->palette.green =
  158                     (u_char *)malloc(sc->gfbc->palette.count, M_DEVBUF,
  159                     M_NOWAIT);
  160                 sc->gfbc->palette.blue =
  161                     (u_char *)malloc(sc->gfbc->palette.count, M_DEVBUF,
  162                     M_NOWAIT);
  163                 sc->gfbc->cursor_palette.red =
  164                     (u_char *)malloc(sc->gfbc->cursor_palette.count, M_DEVBUF,
  165                     M_NOWAIT);
  166                 sc->gfbc->cursor_palette.green =
  167                     (u_char *)malloc(sc->gfbc->cursor_palette.count, M_DEVBUF,
  168                     M_NOWAIT);
  169                 sc->gfbc->cursor_palette.blue =
  170                     (u_char *)malloc(sc->gfbc->cursor_palette.count, M_DEVBUF,
  171                     M_NOWAIT);
  172                 if(gfb_init(unit, adp, flags)) {
  173                         device_printf(dev, "Couldn't initialize framebuffer\n");
  174                         vid_unregister(adp);
  175                         gfb_device_softcs[sc->model][unit] = NULL;
  176                         free(sc->gfbc->cursor_palette.blue, M_DEVBUF);
  177                         free(sc->gfbc->cursor_palette.green, M_DEVBUF);
  178                         free(sc->gfbc->cursor_palette.red, M_DEVBUF);
  179                         free(sc->gfbc->palette.blue, M_DEVBUF);
  180                         free(sc->gfbc->palette.green, M_DEVBUF);
  181                         free(sc->gfbc->palette.red, M_DEVBUF);
  182                         free(sc->gfbc, M_DEVBUF);
  183                         free(sc->adp, M_DEVBUF);
  184                         goto fail;
  185                 }
  186         } else {
  187                 (*vidsw[va_index]->probe)(unit, &adp, (void *)sc->driver_name,
  188                     flags);
  189                 sc->adp = adp;
  190                 sc->gfbc = gfb_device_softcs[sc->model][unit]->gfbc;
  191                 gfb_device_softcs[sc->model][unit] = sc;
  192         }
  193 
  194         /*
  195            This is a back-door for PCI devices--since FreeBSD no longer supports
  196            PCI configuration-space accesses during the *configure() phase for
  197            video adapters, we cannot identify a PCI device as the console during
  198            the first call to sccnattach(). There must be a second chance for PCI
  199            adapters to be recognized as the console, and this is it...
  200         */
  201 #ifdef __alpha__
  202         ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
  203         if (ctb->ctb_term_type == 3) /* Display adapter */
  204                 sccnattach();
  205 #endif /* __alpha__ */
  206 
  207         device_printf(dev, "Board type %s\n", sc->gfbc->name);
  208         device_printf(dev, "%d x %d, %dbpp, %s RAMDAC\n",
  209                sc->adp->va_info.vi_width, sc->adp->va_info.vi_height,
  210                sc->adp->va_info.vi_depth, sc->gfbc->ramdac_name);
  211 #ifdef FB_INSTALL_CDEV
  212         /* attach a virtual frame buffer device */
  213         error = fb_attach(unit, sc->adp, sc->cdevsw);
  214         if(error)
  215                 goto fail;
  216         if(bootverbose)
  217                 (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose);
  218 #if experimental
  219         device_add_child(dev, "fb", -1);
  220         bus_generic_attach(dev);
  221 #endif /*experimental*/
  222 #endif /*FB_INSTALL_CDEV*/
  223         goto done;
  224 fail:
  225         if(sc->intrhand != NULL) {
  226                 bus_teardown_intr(dev, sc->irq, sc->intrhand);
  227                 sc->intrhand = NULL;
  228         }
  229         if(sc->irq != NULL) {
  230                 rid = 0x0;
  231                 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->irq);
  232                 sc->irq = NULL;
  233         }
  234         if(sc->res != NULL) {
  235                 rid = GFB_MEM_BASE_RID;
  236                 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res);
  237                 sc->res = NULL;
  238         }
  239         error = ENXIO;
  240 done:
  241         splx(s);
  242         return(error);
  243 }
  244 
  245 int
  246 pcigfb_detach(device_t dev)
  247 {
  248         struct gfb_softc *sc;
  249         int rid;
  250 
  251         sc = device_get_softc(dev);
  252         bus_teardown_intr(dev, sc->irq, sc->intrhand);
  253         rid = 0x0;
  254         bus_release_resource(dev, SYS_RES_IRQ, rid, sc->irq);
  255         rid = GFB_MEM_BASE_RID;
  256         bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res);
  257         return(0);
  258 }
  259 
  260 #ifdef FB_INSTALL_CDEV
  261 
  262 int
  263 pcigfb_open(dev_t dev, int flag, int mode, struct thread *td)
  264 {
  265         struct gfb_softc *sc;
  266         int error;
  267 
  268         sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev));
  269 
  270         if(sc == NULL)
  271                 error = ENXIO;
  272         else if(mode & (O_CREAT | O_APPEND | O_TRUNC))
  273                 error = ENODEV;
  274         else
  275                 error = genfbopen(&sc->gensc, sc->adp, flag, mode, td);
  276         return(error);
  277 }
  278 
  279 int
  280 pcigfb_close(dev_t dev, int flag, int mode, struct thread *td)
  281 {
  282         struct gfb_softc *sc;
  283 
  284         sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev));
  285         return genfbclose(&sc->gensc, sc->adp, flag, mode, td);
  286 }
  287 
  288 int
  289 pcigfb_read(dev_t dev, struct uio *uio, int flag)
  290 {
  291         struct gfb_softc *sc;
  292 
  293         sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev));
  294         return genfbread(&sc->gensc, sc->adp, uio, flag);
  295 }
  296 
  297 int
  298 pcigfb_write(dev_t dev, struct uio *uio, int flag)
  299 {
  300         struct gfb_softc *sc;
  301 
  302         sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev));
  303         return genfbwrite(&sc->gensc, sc->adp, uio, flag);
  304 }
  305 
  306 int
  307 pcigfb_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
  308 {
  309         struct gfb_softc *sc;
  310 
  311         sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev));
  312         return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td);
  313 }
  314 
  315 int
  316 pcigfb_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int prot)
  317 {
  318         struct gfb_softc *sc;
  319 
  320         sc = (struct gfb_softc *)devclass_get_softc(gfb_devclass, minor(dev));
  321         return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot);
  322 }
  323 
  324 #endif /*FB_INSTALL_CDEV*/

Cache object: f3a97e87040429a8c8b8f7945940cb24


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