root/dev/pci/vga_pci.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. vga_pci_match
  2. vga_pci_attach
  3. vga_pci_mmap
  4. vga_pci_cnattach
  5. vga_pci_ioctl
  6. vga_pci_close

    1 /* $OpenBSD: vga_pci.c,v 1.26 2007/01/28 20:28:50 gwk Exp $ */
    2 /* $NetBSD: vga_pci.c,v 1.3 1998/06/08 06:55:58 thorpej Exp $ */
    3 
    4 /*
    5  * Copyright (c) 2001 Wasabi Systems, Inc.
    6  * All rights reserved.
    7  *
    8  * Written by Frank van der Linden for Wasabi Systems, Inc.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed for the NetBSD Project by
   21  *      Wasabi Systems, Inc.
   22  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
   23  *    or promote products derived from this software without specific prior
   24  *    written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
   27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 /*
   39  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
   40  * All rights reserved.
   41  *
   42  * Author: Chris G. Demetriou
   43  *
   44  * Permission to use, copy, modify and distribute this software and
   45  * its documentation is hereby granted, provided that both the copyright
   46  * notice and this permission notice appear in all copies of the
   47  * software, derivative works or modified versions, and any portions
   48  * thereof, and that both notices appear in supporting documentation.
   49  *
   50  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   51  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
   52  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   53  *
   54  * Carnegie Mellon requests users of this software to return to
   55  *
   56  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   57  *  School of Computer Science
   58  *  Carnegie Mellon University
   59  *  Pittsburgh PA 15213-3890
   60  *
   61  * any improvements or extensions that they make and grant Carnegie the
   62  * rights to redistribute these changes.
   63  */
   64 
   65 #include "vga.h"
   66 
   67 #include <sys/param.h>
   68 #include <sys/systm.h>
   69 #include <sys/kernel.h>
   70 #include <sys/device.h>
   71 #include <sys/malloc.h>
   72 #include <sys/agpio.h>
   73 
   74 #include <uvm/uvm.h>
   75 
   76 #include <machine/bus.h>
   77 
   78 #include <dev/pci/pcireg.h>
   79 #include <dev/pci/pcivar.h>
   80 #include <dev/pci/pcidevs.h>
   81 
   82 #include <dev/ic/mc6845reg.h>
   83 #include <dev/ic/pcdisplayvar.h>
   84 #include <dev/ic/vgareg.h>
   85 #include <dev/ic/vgavar.h>
   86 #include <dev/pci/vga_pcivar.h>
   87 
   88 
   89 #include <dev/wscons/wsconsio.h>
   90 #include <dev/wscons/wsdisplayvar.h>
   91 
   92 #ifdef VESAFB
   93 #include <dev/vesa/vesabiosvar.h>
   94 #endif
   95 
   96 int     vga_pci_match(struct device *, void *, void *);
   97 void    vga_pci_attach(struct device *, struct device *, void *);
   98 paddr_t vga_pci_mmap(void* v, off_t off, int prot);
   99 
  100 #ifdef VESAFB
  101 int vesafb_putcmap(struct vga_pci_softc *, struct wsdisplay_cmap *);
  102 int vesafb_getcmap(struct vga_pci_softc *, struct wsdisplay_cmap *);
  103 #endif
  104 
  105 struct cfattach vga_pci_ca = {
  106         sizeof(struct vga_pci_softc), vga_pci_match, vga_pci_attach,
  107 };
  108 
  109 int
  110 vga_pci_match(struct device *parent, void *match, void *aux)
  111 {
  112         struct pci_attach_args *pa = aux;
  113         int potential;
  114 
  115         potential = 0;
  116 
  117         /*
  118          * If it's prehistoric/vga or display/vga, we might match.
  119          * For the console device, this is jut a sanity check.
  120          */
  121         if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PREHISTORIC &&
  122             PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
  123                 potential = 1;
  124         if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
  125              PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
  126                 potential = 1;
  127 
  128         if (!potential)
  129                 return (0);
  130 
  131         /* check whether it is disabled by firmware */
  132         if ((pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG)
  133             & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
  134             != (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE))
  135                 return (0);
  136 
  137         /* If it's the console, we have a winner! */
  138         if (vga_is_console(pa->pa_iot, WSDISPLAY_TYPE_PCIVGA))
  139                 return (1);
  140 
  141         /*
  142          * If we might match, make sure that the card actually looks OK.
  143          */
  144         if (!vga_common_probe(pa->pa_iot, pa->pa_memt))
  145                 return (0);
  146 
  147         return (1);
  148 }
  149 
  150 void
  151 vga_pci_attach(struct device *parent, struct device *self, void *aux)
  152 {
  153         struct pci_attach_args *pa = aux;
  154         pcireg_t reg;
  155 #ifdef VESAFB
  156         struct vga_pci_softc *sc = (struct vga_pci_softc *)self;
  157 #endif
  158 
  159         /*
  160          * Enable bus master; X might need this for accelerated graphics.
  161          */
  162         reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
  163         reg |= PCI_COMMAND_MASTER_ENABLE;
  164         pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
  165 
  166 #ifdef PCIAGP
  167         agp_attach(parent, self, aux);
  168 #endif
  169 #ifdef VESAFB
  170         if (vesabios_softc != NULL && vesabios_softc->sc_nmodes > 0) {
  171                 sc->sc_textmode = vesafb_get_mode(sc);
  172                 printf(", vesafb\n");
  173                 vga_extended_attach(self, pa->pa_iot, pa->pa_memt,
  174                     WSDISPLAY_TYPE_PCIVGA, vga_pci_mmap);
  175                 return;
  176         }
  177 #endif
  178         printf("\n");
  179         vga_common_attach(self, pa->pa_iot, pa->pa_memt,
  180             WSDISPLAY_TYPE_PCIVGA);
  181 }
  182 
  183 paddr_t
  184 vga_pci_mmap(void *v, off_t off, int prot)
  185 {
  186 #ifdef VESAFB
  187         struct vga_config *vc = (struct vga_config *)v;
  188         struct vga_pci_softc *sc = (struct vga_pci_softc *)vc->vc_softc;
  189 
  190         if (sc->sc_mode == WSDISPLAYIO_MODE_DUMBFB) {
  191                 if (off < 0 || off > vesabios_softc->sc_size)
  192                         return (-1);
  193                 return atop(sc->sc_base + off);
  194         }
  195 #endif
  196 #ifdef PCIAGP
  197         return agp_mmap(v, off, prot);
  198 #else
  199         return -1;
  200 #endif
  201 }
  202 
  203 int
  204 vga_pci_cnattach(bus_space_tag_t iot, bus_space_tag_t memt,
  205     pci_chipset_tag_t pc, int bus, int device, int function)
  206 {
  207         return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_PCIVGA, 0));
  208 }
  209 
  210 int
  211 vga_pci_ioctl(void *v, u_long cmd, caddr_t addr, int flag, struct proc *pb)
  212 {
  213         int error = 0;
  214 #ifdef VESAFB
  215         struct vga_config *vc = (struct vga_config *)v;
  216         struct vga_pci_softc *sc = (struct vga_pci_softc *)vc->vc_softc;
  217         struct wsdisplay_fbinfo *wdf;
  218         struct wsdisplay_gfx_mode *gfxmode;
  219         int mode;
  220 #endif
  221 
  222         switch (cmd) {
  223 #ifdef VESAFB
  224         case WSDISPLAYIO_SMODE:
  225                 mode = *(u_int *)addr;
  226                 switch (mode) {
  227                 case WSDISPLAYIO_MODE_EMUL:
  228                         /* back to text mode */
  229                         vesafb_set_mode(sc, sc->sc_textmode);
  230                         sc->sc_mode = mode;
  231                         break;
  232                 case WSDISPLAYIO_MODE_DUMBFB:
  233                         if (sc->sc_gfxmode == -1)
  234                                 return (-1);
  235                         vesafb_set_mode(sc, sc->sc_gfxmode);
  236                         sc->sc_mode = mode;
  237                         break;
  238                 default:
  239                         error = -1;
  240                 }
  241                 break;
  242         case WSDISPLAYIO_GINFO:
  243                 if (sc->sc_gfxmode == -1)
  244                         return (-1);
  245                 wdf = (void *)addr;
  246                 wdf->height = sc->sc_height;
  247                 wdf->width = sc->sc_width;
  248                 wdf->depth = sc->sc_depth;
  249                 wdf->cmsize = 256;
  250                 break;
  251 
  252         case WSDISPLAYIO_LINEBYTES:
  253                 if (sc->sc_gfxmode == -1)
  254                         return (-1);
  255                 *(u_int *)addr = sc->sc_linebytes;
  256                 break;
  257 
  258         case WSDISPLAYIO_SVIDEO:
  259         case WSDISPLAYIO_GVIDEO:
  260                 break;
  261         case WSDISPLAYIO_GETCMAP:
  262                 if (sc->sc_depth == 8)
  263                         error = vesafb_getcmap(sc,
  264                             (struct wsdisplay_cmap *)addr);
  265                 break;
  266 
  267         case WSDISPLAYIO_PUTCMAP:
  268                 if (sc->sc_depth == 8)
  269                         error = vesafb_putcmap(sc,
  270                             (struct wsdisplay_cmap *)addr);
  271                 break;
  272 
  273         case WSDISPLAYIO_GETSUPPORTEDDEPTH:
  274                 *(int *)addr = vesafb_get_supported_depth(sc);
  275                 break;
  276                 
  277         case WSDISPLAYIO_SETGFXMODE:
  278                 gfxmode = (struct wsdisplay_gfx_mode *)addr;
  279                 sc->sc_gfxmode = vesafb_find_mode(sc, gfxmode->width,
  280                     gfxmode->height, gfxmode->depth);
  281                 if (sc->sc_gfxmode == -1) 
  282                         error = -1;
  283                 break;
  284 
  285 #endif
  286 #ifdef PCIAGP
  287         case AGPIOC_INFO:
  288         case AGPIOC_ACQUIRE:
  289         case AGPIOC_RELEASE:
  290         case AGPIOC_SETUP:
  291         case AGPIOC_ALLOCATE:
  292         case AGPIOC_DEALLOCATE:
  293         case AGPIOC_BIND:
  294         case AGPIOC_UNBIND:
  295                 error = agp_ioctl(v, cmd, addr, flag, pb);
  296                 break;
  297 #endif
  298         default:
  299                 error = ENOTTY;
  300         }
  301 
  302         return (error);
  303 }
  304 
  305 #ifdef notyet
  306 void
  307 vga_pci_close(void *v)
  308 {
  309 #ifdef PCIAGP
  310         agp_close(v);
  311 #endif
  312 }
  313 #endif

/* [<][>][^][v][top][bottom][index][help] */