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/pci/agp_sis.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) 2000 Doug Rabson
    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.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/5.3/sys/pci/agp_sis.c 134195 2004-08-23 05:23:16Z imp $");
   29 
   30 #include "opt_bus.h"
   31 #ifndef PC98
   32 #include "opt_agp.h"
   33 #endif
   34 
   35 #include <sys/param.h>
   36 #include <sys/systm.h>
   37 #include <sys/malloc.h>
   38 #include <sys/kernel.h>
   39 #include <sys/module.h>
   40 #include <sys/bus.h>
   41 #include <sys/lock.h>
   42 #include <sys/mutex.h>
   43 #include <sys/proc.h>
   44 
   45 #include <dev/pci/pcivar.h>
   46 #include <dev/pci/pcireg.h>
   47 #include <pci/agppriv.h>
   48 #include <pci/agpreg.h>
   49 
   50 #include <vm/vm.h>
   51 #include <vm/vm_object.h>
   52 #include <vm/pmap.h>
   53 
   54 struct agp_sis_softc {
   55         struct agp_softc agp;
   56         u_int32_t       initial_aperture; /* aperture size at startup */
   57         struct agp_gatt *gatt;
   58 };
   59 
   60 static const char*
   61 agp_sis_match(device_t dev)
   62 {
   63         if (pci_get_class(dev) != PCIC_BRIDGE
   64             || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
   65                 return NULL;
   66 
   67         if (agp_find_caps(dev) == 0)
   68                 return NULL;
   69 
   70         switch (pci_get_devid(dev)) {
   71         case 0x00011039:
   72                 return ("SiS 5591 host to AGP bridge");
   73         case 0x05301039:
   74                 return ("SiS 530 host to AGP bridge");
   75         case 0x05401039:
   76                 return ("SiS 540 host to AGP bridge");
   77         case 0x05501039:
   78                 return ("SiS 550 host to AGP bridge");
   79         case 0x06201039:
   80                 return ("SiS 620 host to AGP bridge");
   81         case 0x06301039:
   82                 return ("SiS 630 host to AGP bridge");
   83         case 0x06451039:
   84                 return ("SiS 645 host to AGP bridge");
   85         case 0x06461039:
   86                 return ("SiS 645DX host to AGP bridge");
   87         case 0x06481039:
   88                 return ("SiS 648 host to AGP bridge");
   89         case 0x06501039:
   90                 return ("SiS 650 host to AGP bridge");
   91         case 0x06511039:
   92                 return ("SiS 651 host to AGP bridge");
   93         case 0x06551039:
   94                 return ("SiS 655 host to AGP bridge");
   95         case 0x06611039:
   96                 return ("SiS 661 host to AGP bridge");
   97         case 0x07301039:
   98                 return ("SiS 730 host to AGP bridge");
   99         case 0x07351039:
  100                 return ("SiS 735 host to AGP bridge");
  101         case 0x07401039:
  102                 return ("SiS 740 host to AGP bridge");
  103         case 0x07411039:
  104                 return ("SiS 741 host to AGP bridge");
  105         case 0x07451039:
  106                 return ("SiS 745 host to AGP bridge");
  107         case 0x07461039:
  108                 return ("SiS 746 host to AGP bridge");
  109         case 0x07601039:
  110                 return ("SiS 760 host to AGP bridge");
  111 #if defined(__amd64__) || defined(AGP_AMD64_GART)
  112         case 0x10221039:        /* AMD64 */
  113                 return NULL;
  114 #endif
  115         };
  116 
  117         if (pci_get_vendor(dev) == 0x1039)
  118                 return ("SIS Generic host to PCI bridge");
  119 
  120         return NULL;
  121 }
  122 
  123 static int
  124 agp_sis_probe(device_t dev)
  125 {
  126         const char *desc;
  127 
  128         if (resource_disabled("agp", device_get_unit(dev)))
  129                 return (ENXIO);
  130         desc = agp_sis_match(dev);
  131         if (desc) {
  132                 device_verbose(dev);
  133                 device_set_desc(dev, desc);
  134                 return 0;
  135         }
  136 
  137         return ENXIO;
  138 }
  139 
  140 static int
  141 agp_sis_attach(device_t dev)
  142 {
  143         struct agp_sis_softc *sc = device_get_softc(dev);
  144         struct agp_gatt *gatt;
  145         int error;
  146 
  147         error = agp_generic_attach(dev);
  148         if (error)
  149                 return error;
  150 
  151         sc->initial_aperture = AGP_GET_APERTURE(dev);
  152 
  153         for (;;) {
  154                 gatt = agp_alloc_gatt(dev);
  155                 if (gatt)
  156                         break;
  157 
  158                 /*
  159                  * Probably contigmalloc failure. Try reducing the
  160                  * aperture so that the gatt size reduces.
  161                  */
  162                 if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
  163                         agp_generic_detach(dev);
  164                         return ENOMEM;
  165                 }
  166         }
  167         sc->gatt = gatt;
  168 
  169         /* Install the gatt. */
  170         pci_write_config(dev, AGP_SIS_ATTBASE, gatt->ag_physical, 4);
  171         
  172         /* Enable the aperture. */
  173         pci_write_config(dev, AGP_SIS_WINCTRL,
  174                          pci_read_config(dev, AGP_SIS_WINCTRL, 1) | 3, 1);
  175 
  176         /*
  177          * Enable the TLB and make it automatically invalidate entries
  178          * when the GATT is written.
  179          */
  180         pci_write_config(dev, AGP_SIS_TLBCTRL, 0x05, 1);
  181 
  182         return 0;
  183 }
  184 
  185 static int
  186 agp_sis_detach(device_t dev)
  187 {
  188         struct agp_sis_softc *sc = device_get_softc(dev);
  189         int error;
  190 
  191         error = agp_generic_detach(dev);
  192         if (error)
  193                 return error;
  194 
  195         /* Disable the aperture.. */
  196         pci_write_config(dev, AGP_SIS_WINCTRL,
  197                          pci_read_config(dev, AGP_SIS_WINCTRL, 1) & ~3, 1);
  198 
  199         /* and the TLB. */
  200         pci_write_config(dev, AGP_SIS_TLBCTRL, 0, 1);
  201 
  202         /* Put the aperture back the way it started. */
  203         AGP_SET_APERTURE(dev, sc->initial_aperture);
  204 
  205         agp_free_gatt(sc->gatt);
  206         return 0;
  207 }
  208 
  209 static u_int32_t
  210 agp_sis_get_aperture(device_t dev)
  211 {
  212         int gws;
  213 
  214         /*
  215          * The aperture size is equal to 4M<<gws.
  216          */
  217         gws = (pci_read_config(dev, AGP_SIS_WINCTRL, 1) & 0x70) >> 4;
  218         return (4*1024*1024) << gws;
  219 }
  220 
  221 static int
  222 agp_sis_set_aperture(device_t dev, u_int32_t aperture)
  223 {
  224         int gws;
  225 
  226         /*
  227          * Check for a power of two and make sure its within the
  228          * programmable range.
  229          */
  230         if (aperture & (aperture - 1)
  231             || aperture < 4*1024*1024
  232             || aperture > 256*1024*1024)
  233                 return EINVAL;
  234 
  235         gws = ffs(aperture / 4*1024*1024) - 1;
  236         
  237         pci_write_config(dev, AGP_SIS_WINCTRL,
  238                          ((pci_read_config(dev, AGP_SIS_WINCTRL, 1) & ~0x70)
  239                           | gws << 4), 1);
  240 
  241         return 0;
  242 }
  243 
  244 static int
  245 agp_sis_bind_page(device_t dev, int offset, vm_offset_t physical)
  246 {
  247         struct agp_sis_softc *sc = device_get_softc(dev);
  248 
  249         if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
  250                 return EINVAL;
  251 
  252         sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical;
  253         return 0;
  254 }
  255 
  256 static int
  257 agp_sis_unbind_page(device_t dev, int offset)
  258 {
  259         struct agp_sis_softc *sc = device_get_softc(dev);
  260 
  261         if (offset < 0 || offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
  262                 return EINVAL;
  263 
  264         sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
  265         return 0;
  266 }
  267 
  268 static void
  269 agp_sis_flush_tlb(device_t dev)
  270 {
  271         pci_write_config(dev, AGP_SIS_TLBFLUSH, 0x02, 1);
  272 }
  273 
  274 static device_method_t agp_sis_methods[] = {
  275         /* Device interface */
  276         DEVMETHOD(device_probe,         agp_sis_probe),
  277         DEVMETHOD(device_attach,        agp_sis_attach),
  278         DEVMETHOD(device_detach,        agp_sis_detach),
  279         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  280         DEVMETHOD(device_suspend,       bus_generic_suspend),
  281         DEVMETHOD(device_resume,        bus_generic_resume),
  282 
  283         /* AGP interface */
  284         DEVMETHOD(agp_get_aperture,     agp_sis_get_aperture),
  285         DEVMETHOD(agp_set_aperture,     agp_sis_set_aperture),
  286         DEVMETHOD(agp_bind_page,        agp_sis_bind_page),
  287         DEVMETHOD(agp_unbind_page,      agp_sis_unbind_page),
  288         DEVMETHOD(agp_flush_tlb,        agp_sis_flush_tlb),
  289         DEVMETHOD(agp_enable,           agp_generic_enable),
  290         DEVMETHOD(agp_alloc_memory,     agp_generic_alloc_memory),
  291         DEVMETHOD(agp_free_memory,      agp_generic_free_memory),
  292         DEVMETHOD(agp_bind_memory,      agp_generic_bind_memory),
  293         DEVMETHOD(agp_unbind_memory,    agp_generic_unbind_memory),
  294 
  295         { 0, 0 }
  296 };
  297 
  298 static driver_t agp_sis_driver = {
  299         "agp",
  300         agp_sis_methods,
  301         sizeof(struct agp_sis_softc),
  302 };
  303 
  304 static devclass_t agp_devclass;
  305 
  306 DRIVER_MODULE(agp_sis, pci, agp_sis_driver, agp_devclass, 0, 0);
  307 MODULE_DEPEND(agp_sis, agp, 1, 1, 1);
  308 MODULE_DEPEND(agp_sis, pci, 1, 1, 1);

Cache object: baf3af44ff59e3d0a7dfc985b6722bf2


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