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/amr/amr_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) 1999,2000 Michael Smith
    3  * Copyright (c) 2000 BSDi
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 /*-
   28  * Copyright (c) 2002 Eric Moore
   29  * Copyright (c) 2002, 2004 LSI Logic Corporation
   30  * All rights reserved.
   31  *
   32  * Redistribution and use in source and binary forms, with or without
   33  * modification, are permitted provided that the following conditions
   34  * are met:
   35  * 1. Redistributions of source code must retain the above copyright
   36  *    notice, this list of conditions and the following disclaimer.
   37  * 2. Redistributions in binary form must reproduce the above copyright
   38  *    notice, this list of conditions and the following disclaimer in the
   39  *    documentation and/or other materials provided with the distribution.
   40  * 3. The party using or redistributing the source code and binary forms
   41  *    agrees to the disclaimer below and the terms and conditions set forth
   42  *    herein.
   43  *
   44  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   45  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   46  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   47  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   48  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   49  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   50  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   51  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   52  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   53  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   54  * SUCH DAMAGE.
   55  */
   56 
   57 #include <sys/cdefs.h>
   58 __FBSDID("$FreeBSD: releng/6.0/sys/dev/amr/amr_pci.c 146734 2005-05-29 04:42:30Z nyan $");
   59 
   60 #include <sys/param.h>
   61 #include <sys/systm.h>
   62 #include <sys/kernel.h>
   63 #include <sys/module.h>
   64 
   65 #include <dev/amr/amr_compat.h>
   66 #include <sys/bus.h>
   67 #include <sys/conf.h>
   68 
   69 #include <machine/bus.h>
   70 #include <machine/resource.h>
   71 #include <sys/rman.h>
   72 
   73 #include <dev/pci/pcireg.h>
   74 #include <dev/pci/pcivar.h>
   75 
   76 #include <dev/amr/amrio.h>
   77 #include <dev/amr/amrreg.h>
   78 #include <dev/amr/amrvar.h>
   79 
   80 static int              amr_pci_probe(device_t dev);
   81 static int              amr_pci_attach(device_t dev);
   82 static int              amr_pci_detach(device_t dev);
   83 static int              amr_pci_shutdown(device_t dev);
   84 static int              amr_pci_suspend(device_t dev);
   85 static int              amr_pci_resume(device_t dev);
   86 static void             amr_pci_intr(void *arg);
   87 static void             amr_pci_free(struct amr_softc *sc);
   88 static void             amr_sglist_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error);
   89 static int              amr_sglist_map(struct amr_softc *sc);
   90 static void             amr_setup_mbox_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error);
   91 static int              amr_setup_mbox(struct amr_softc *sc);
   92 
   93 static device_method_t amr_methods[] = {
   94     /* Device interface */
   95     DEVMETHOD(device_probe,     amr_pci_probe),
   96     DEVMETHOD(device_attach,    amr_pci_attach),
   97     DEVMETHOD(device_detach,    amr_pci_detach),
   98     DEVMETHOD(device_shutdown,  amr_pci_shutdown),
   99     DEVMETHOD(device_suspend,   amr_pci_suspend),
  100     DEVMETHOD(device_resume,    amr_pci_resume),
  101 
  102     DEVMETHOD(bus_print_child,  bus_generic_print_child),
  103     DEVMETHOD(bus_driver_added, bus_generic_driver_added),
  104     { 0, 0 }
  105 };
  106 
  107 static driver_t amr_pci_driver = {
  108         "amr",
  109         amr_methods,
  110         sizeof(struct amr_softc)
  111 };
  112 
  113 static devclass_t       amr_devclass;
  114 DRIVER_MODULE(amr, pci, amr_pci_driver, amr_devclass, 0, 0);
  115 
  116 static struct
  117 {
  118     int         vendor;
  119     int         device;
  120     int         flag;
  121 #define PROBE_SIGNATURE (1<<0)
  122 } amr_device_ids[] = {
  123     {0x101e, 0x9010, 0},
  124     {0x101e, 0x9060, 0},
  125     {0x8086, 0x1960, PROBE_SIGNATURE},/* generic i960RD, check for signature */
  126     {0x101e, 0x1960, 0},
  127     {0x1000, 0x1960, PROBE_SIGNATURE},
  128     {0x1000, 0x0407, 0},
  129     {0x1000, 0x0408, 0},
  130     {0x1000, 0x0409, 0},
  131     {0x1028, 0x000e, PROBE_SIGNATURE}, /* perc4/di i960 */
  132     {0x1028, 0x000f, 0}, /* perc4/di Verde*/
  133     {0x1028, 0x0013, 0}, /* perc4/di */
  134     {0, 0, 0}
  135 };
  136 
  137 static int
  138 amr_pci_probe(device_t dev)
  139 {
  140     int         i, sig;
  141 
  142     debug_called(1);
  143 
  144     for (i = 0; amr_device_ids[i].vendor != 0; i++) {
  145         if ((pci_get_vendor(dev) == amr_device_ids[i].vendor) &&
  146             (pci_get_device(dev) == amr_device_ids[i].device)) {
  147 
  148             /* do we need to test for a signature? */
  149             if (amr_device_ids[i].flag & PROBE_SIGNATURE) {
  150                 sig = pci_read_config(dev, AMR_CFG_SIG, 2);
  151                 if ((sig != AMR_SIGNATURE_1) && (sig != AMR_SIGNATURE_2))
  152                     continue;
  153             }
  154             device_set_desc(dev, LSI_DESC_PCI);
  155             return(BUS_PROBE_DEFAULT);
  156         }
  157     }
  158     return(ENXIO);
  159 }
  160 
  161 static int
  162 amr_pci_attach(device_t dev)
  163 {
  164     struct amr_softc    *sc;
  165     int                 rid, rtype, error;
  166     u_int32_t           command;
  167 
  168     debug_called(1);
  169 
  170     /*
  171      * Initialise softc.
  172      */
  173     sc = device_get_softc(dev);
  174     bzero(sc, sizeof(*sc));
  175     sc->amr_dev = dev;
  176     mtx_init(&sc->amr_io_lock, "AMR IO Lock", NULL, MTX_DEF);
  177 
  178     /* assume failure is 'not configured' */
  179     error = ENXIO;
  180 
  181     /*
  182      * Determine board type.
  183      */
  184     command = pci_read_config(dev, PCIR_COMMAND, 1);
  185     if ((pci_get_device(dev) == 0x1960) || (pci_get_device(dev) == 0x0407) ||
  186         (pci_get_device(dev) == 0x0408) || (pci_get_device(dev) == 0x0409) ||
  187         (pci_get_device(dev) == 0x000e) || (pci_get_device(dev) == 0x000f) ||
  188         (pci_get_device(dev) == 0x0013)) {
  189         /*
  190          * Make sure we are going to be able to talk to this board.
  191          */
  192         if ((command & PCIM_CMD_MEMEN) == 0) {
  193             device_printf(dev, "memory window not available\n");
  194             goto out;
  195         }
  196         sc->amr_type |= AMR_TYPE_QUARTZ;
  197 
  198     } else {
  199         /*
  200          * Make sure we are going to be able to talk to this board.
  201          */
  202         if ((command & PCIM_CMD_PORTEN) == 0) {
  203             device_printf(dev, "I/O window not available\n");
  204             goto out;
  205         }
  206     }
  207 
  208     /* force the busmaster enable bit on */
  209     if (!(command & PCIM_CMD_BUSMASTEREN)) {
  210         device_printf(dev, "busmaster bit not set, enabling\n");
  211         command |= PCIM_CMD_BUSMASTEREN;
  212         pci_write_config(dev, PCIR_COMMAND, command, 2);
  213     }
  214 
  215     /*
  216      * Allocate the PCI register window.
  217      */
  218     rid = PCIR_BAR(0);
  219     rtype = AMR_IS_QUARTZ(sc) ? SYS_RES_MEMORY : SYS_RES_IOPORT;
  220     sc->amr_reg = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE);
  221     if (sc->amr_reg == NULL) {
  222         device_printf(sc->amr_dev, "can't allocate register window\n");
  223         goto out;
  224     }
  225     sc->amr_btag = rman_get_bustag(sc->amr_reg);
  226     sc->amr_bhandle = rman_get_bushandle(sc->amr_reg);
  227 
  228     /*
  229      * Allocate and connect our interrupt.
  230      */
  231     rid = 0;
  232     sc->amr_irq = bus_alloc_resource_any(sc->amr_dev, SYS_RES_IRQ, &rid,
  233         RF_SHAREABLE | RF_ACTIVE);
  234     if (sc->amr_irq == NULL) {
  235         device_printf(sc->amr_dev, "can't allocate interrupt\n");
  236         goto out;
  237     }
  238     if (bus_setup_intr(sc->amr_dev, sc->amr_irq, INTR_TYPE_BIO | INTR_ENTROPY | INTR_MPSAFE, amr_pci_intr, sc, &sc->amr_intr)) {
  239         device_printf(sc->amr_dev, "can't set up interrupt\n");
  240         goto out;
  241     }
  242 
  243     debug(2, "interrupt attached");
  244 
  245     /* assume failure is 'out of memory' */
  246     error = ENOMEM;
  247 
  248     /*
  249      * Allocate the parent bus DMA tag appropriate for PCI.
  250      */
  251     if (bus_dma_tag_create(NULL,                        /* parent */
  252                            1, 0,                        /* alignment, boundary */
  253                            BUS_SPACE_MAXADDR_32BIT,     /* lowaddr */
  254                            BUS_SPACE_MAXADDR,           /* highaddr */
  255                            NULL, NULL,                  /* filter, filterarg */
  256                            MAXBSIZE, AMR_NSEG,          /* maxsize, nsegments */
  257                            BUS_SPACE_MAXSIZE_32BIT,     /* maxsegsize */
  258                            0,                           /* flags */
  259                            NULL, NULL,                  /* lockfunc, lockarg */
  260                            &sc->amr_parent_dmat)) {
  261         device_printf(dev, "can't allocate parent DMA tag\n");
  262         goto out;
  263     }
  264 
  265     /*
  266      * Create DMA tag for mapping buffers into controller-addressable space.
  267      */
  268     if (bus_dma_tag_create(sc->amr_parent_dmat,         /* parent */
  269                            1, 0,                        /* alignment, boundary */
  270                            BUS_SPACE_MAXADDR_32BIT,     /* lowaddr */
  271                            BUS_SPACE_MAXADDR,           /* highaddr */
  272                            NULL, NULL,                  /* filter, filterarg */
  273                            MAXBSIZE, AMR_NSEG,          /* maxsize, nsegments */
  274                            MAXBSIZE,                    /* maxsegsize */
  275                            BUS_DMA_ALLOCNOW,            /* flags */
  276                            busdma_lock_mutex, &sc->amr_io_lock, /* lockfunc, lockarg */
  277                            &sc->amr_buffer_dmat)) {
  278         device_printf(sc->amr_dev, "can't allocate buffer DMA tag\n");
  279         goto out;
  280     }
  281 
  282     debug(2, "dma tag done");
  283 
  284     /*
  285      * Allocate and set up mailbox in a bus-visible fashion.
  286      */
  287     if ((error = amr_setup_mbox(sc)) != 0)
  288         goto out;
  289 
  290     debug(2, "mailbox setup");
  291 
  292     /*
  293      * Build the scatter/gather buffers.
  294      */
  295     if (amr_sglist_map(sc))
  296         goto out;
  297 
  298     debug(2, "s/g list mapped");
  299 
  300     /*
  301      * Do bus-independant initialisation, bring controller online.
  302      */
  303     error = amr_attach(sc);
  304 
  305 out:
  306     if (error)
  307         amr_pci_free(sc);
  308     return(error);
  309 }
  310 
  311 /********************************************************************************
  312  * Disconnect from the controller completely, in preparation for unload.
  313  */
  314 static int
  315 amr_pci_detach(device_t dev)
  316 {
  317     struct amr_softc    *sc = device_get_softc(dev);
  318     int                 error;
  319 
  320     debug_called(1);
  321 
  322     if (sc->amr_state & AMR_STATE_OPEN)
  323         return(EBUSY);
  324 
  325     if ((error = amr_pci_shutdown(dev)))
  326         return(error);
  327 
  328     amr_pci_free(sc);
  329 
  330     return(0);
  331 }
  332 
  333 /********************************************************************************
  334  * Bring the controller down to a dormant state and detach all child devices.
  335  *
  336  * This function is called before detach, system shutdown, or before performing
  337  * an operation which may add or delete system disks.  (Call amr_startup to
  338  * resume normal operation.)
  339  *
  340  * Note that we can assume that the bioq on the controller is empty, as we won't
  341  * allow shutdown if any device is open.
  342  */
  343 static int
  344 amr_pci_shutdown(device_t dev)
  345 {
  346     struct amr_softc    *sc = device_get_softc(dev);
  347     int                 i,error,s;
  348 
  349     debug_called(1);
  350 
  351     /* mark ourselves as in-shutdown */
  352     sc->amr_state |= AMR_STATE_SHUTDOWN;
  353 
  354 
  355     /* flush controller */
  356     device_printf(sc->amr_dev, "flushing cache...");
  357     printf("%s\n", amr_flush(sc) ? "failed" : "done");
  358 
  359     s = splbio();
  360     error = 0;
  361 
  362     /* delete all our child devices */
  363     for(i = 0 ; i < AMR_MAXLD; i++) {
  364         if( sc->amr_drive[i].al_disk != 0) {
  365             if((error = device_delete_child(sc->amr_dev,sc->amr_drive[i].al_disk)) != 0)
  366                 goto shutdown_out;
  367             sc->amr_drive[i].al_disk = 0;
  368         }
  369     }
  370 
  371     /* XXX disable interrupts? */
  372 
  373 shutdown_out:
  374     splx(s);
  375     return(error);
  376 }
  377 
  378 /********************************************************************************
  379  * Bring the controller to a quiescent state, ready for system suspend.
  380  */
  381 static int
  382 amr_pci_suspend(device_t dev)
  383 {
  384     struct amr_softc    *sc = device_get_softc(dev);
  385 
  386     debug_called(1);
  387 
  388     sc->amr_state |= AMR_STATE_SUSPEND;
  389 
  390     /* flush controller */
  391     device_printf(sc->amr_dev, "flushing cache...");
  392     printf("%s\n", amr_flush(sc) ? "failed" : "done");
  393     
  394     /* XXX disable interrupts? */
  395 
  396     return(0);
  397 }
  398 
  399 /********************************************************************************
  400  * Bring the controller back to a state ready for operation.
  401  */
  402 static int
  403 amr_pci_resume(device_t dev)
  404 {
  405     struct amr_softc    *sc = device_get_softc(dev);
  406 
  407     debug_called(1);
  408 
  409     sc->amr_state &= ~AMR_STATE_SUSPEND;
  410 
  411     /* XXX enable interrupts? */
  412 
  413     return(0);
  414 }
  415 
  416 /*******************************************************************************
  417  * Take an interrupt, or be poked by other code to look for interrupt-worthy
  418  * status.
  419  */
  420 static void
  421 amr_pci_intr(void *arg)
  422 {
  423     struct amr_softc    *sc = (struct amr_softc *)arg;
  424 
  425     debug_called(2);
  426 
  427     /* collect finished commands, queue anything waiting */
  428     mtx_lock(&sc->amr_io_lock);
  429     amr_done(sc);
  430     mtx_unlock(&sc->amr_io_lock);
  431 }
  432 
  433 /********************************************************************************
  434  * Free all of the resources associated with (sc)
  435  *
  436  * Should not be called if the controller is active.
  437  */
  438 static void
  439 amr_pci_free(struct amr_softc *sc)
  440 {
  441     u_int8_t                    *p;
  442     
  443     debug_called(1);
  444 
  445     amr_free(sc);
  446 
  447     /* destroy data-transfer DMA tag */
  448     if (sc->amr_buffer_dmat)
  449         bus_dma_tag_destroy(sc->amr_buffer_dmat);
  450 
  451     /* free and destroy DMA memory and tag for s/g lists */
  452     if (sc->amr_sgtable)
  453         bus_dmamem_free(sc->amr_sg_dmat, sc->amr_sgtable, sc->amr_sg_dmamap);
  454     if (sc->amr_sg_dmat)
  455         bus_dma_tag_destroy(sc->amr_sg_dmat);
  456 
  457     /* free and destroy DMA memory and tag for mailbox */
  458     if (sc->amr_mailbox) {
  459         p = (u_int8_t *)(uintptr_t)(volatile void *)sc->amr_mailbox;
  460         bus_dmamem_free(sc->amr_mailbox_dmat, p - 16, sc->amr_mailbox_dmamap);
  461     }
  462     if (sc->amr_mailbox_dmat)
  463         bus_dma_tag_destroy(sc->amr_mailbox_dmat);
  464 
  465     /* disconnect the interrupt handler */
  466     if (sc->amr_intr)
  467         bus_teardown_intr(sc->amr_dev, sc->amr_irq, sc->amr_intr);
  468     if (sc->amr_irq != NULL)
  469         bus_release_resource(sc->amr_dev, SYS_RES_IRQ, 0, sc->amr_irq);
  470 
  471     /* destroy the parent DMA tag */
  472     if (sc->amr_parent_dmat)
  473         bus_dma_tag_destroy(sc->amr_parent_dmat);
  474 
  475     /* release the register window mapping */
  476     if (sc->amr_reg != NULL)
  477         bus_release_resource(sc->amr_dev,
  478                              AMR_IS_QUARTZ(sc) ? SYS_RES_MEMORY : SYS_RES_IOPORT,
  479                              PCIR_BAR(0), sc->amr_reg);
  480 }
  481 
  482 /********************************************************************************
  483  * Allocate and map the scatter/gather table in bus space.
  484  */
  485 static void
  486 amr_sglist_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  487 {
  488     struct amr_softc    *sc = (struct amr_softc *)arg;
  489 
  490     debug_called(1);
  491 
  492     /* save base of s/g table's address in bus space */
  493     sc->amr_sgbusaddr = segs->ds_addr;
  494 }
  495 
  496 static int
  497 amr_sglist_map(struct amr_softc *sc)
  498 {
  499     size_t      segsize;
  500     int         error;
  501 
  502     debug_called(1);
  503 
  504     /*
  505      * Create a single tag describing a region large enough to hold all of
  506      * the s/g lists we will need.
  507      *
  508      * Note that we could probably use AMR_LIMITCMD here, but that may become tunable.
  509      */
  510     segsize = sizeof(struct amr_sgentry) * AMR_NSEG * AMR_MAXCMD;
  511     error = bus_dma_tag_create(sc->amr_parent_dmat,     /* parent */
  512                                1, 0,                    /* alignment, boundary */
  513                                BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  514                                BUS_SPACE_MAXADDR,       /* highaddr */
  515                                NULL, NULL,              /* filter, filterarg */
  516                                segsize, 1,              /* maxsize, nsegments */
  517                                BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
  518                                0,                       /* flags */
  519                                busdma_lock_mutex,       /* lockfunc */
  520                                &Giant,                  /* lockarg */
  521                                &sc->amr_sg_dmat);
  522     if (error != 0) {
  523         device_printf(sc->amr_dev, "can't allocate scatter/gather DMA tag\n");
  524         return(ENOMEM);
  525     }
  526 
  527     /*
  528      * Allocate enough s/g maps for all commands and permanently map them into
  529      * controller-visible space.
  530      *  
  531      * XXX this assumes we can get enough space for all the s/g maps in one 
  532      * contiguous slab.  We may need to switch to a more complex arrangement where
  533      * we allocate in smaller chunks and keep a lookup table from slot to bus address.
  534      *
  535      * XXX HACK ALERT: at least some controllers don't like the s/g memory being
  536      *                 allocated below 0x2000.  We leak some memory if we get some
  537      *                 below this mark and allocate again.  We should be able to
  538      *                 avoid this with the tag setup, but that does't seem to work.
  539      */
  540 retry:
  541     error = bus_dmamem_alloc(sc->amr_sg_dmat, (void **)&sc->amr_sgtable, BUS_DMA_NOWAIT, &sc->amr_sg_dmamap);
  542     if (error) {
  543         device_printf(sc->amr_dev, "can't allocate s/g table\n");
  544         return(ENOMEM);
  545     }
  546     bus_dmamap_load(sc->amr_sg_dmat, sc->amr_sg_dmamap, sc->amr_sgtable, segsize, amr_sglist_map_helper, sc, 0);
  547     if (sc->amr_sgbusaddr < 0x2000) {
  548         debug(1, "s/g table too low (0x%x), reallocating\n", sc->amr_sgbusaddr);
  549         goto retry;
  550     }
  551     return(0);
  552 }
  553 
  554 /********************************************************************************
  555  * Allocate and set up mailbox areas for the controller (sc)
  556  *
  557  * The basic mailbox structure should be 16-byte aligned.  This means that the
  558  * mailbox64 structure has 4 bytes hanging off the bottom.
  559  */
  560 static void
  561 amr_setup_mbox_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  562 {
  563     struct amr_softc    *sc = (struct amr_softc *)arg;
  564     
  565     debug_called(1);
  566 
  567     /* save phsyical base of the basic mailbox structure */
  568     sc->amr_mailboxphys = segs->ds_addr + 16;
  569 }
  570 
  571 static int
  572 amr_setup_mbox(struct amr_softc *sc)
  573 {
  574     int         error;
  575     u_int8_t    *p;
  576     
  577     debug_called(1);
  578 
  579     /*
  580      * Create a single tag describing a region large enough to hold the entire
  581      * mailbox.
  582      */
  583     error = bus_dma_tag_create(sc->amr_parent_dmat,     /* parent */
  584                                16, 0,                   /* alignment, boundary */
  585                                BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  586                                BUS_SPACE_MAXADDR,       /* highaddr */
  587                                NULL, NULL,              /* filter, filterarg */
  588                                sizeof(struct amr_mailbox) + 16, 1, /* maxsize, nsegments */
  589                                BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
  590                                0,                       /* flags */
  591                                busdma_lock_mutex,       /* lockfunc */
  592                                &Giant,                  /* lockarg */
  593                                &sc->amr_mailbox_dmat);
  594     if (error != 0) {
  595         device_printf(sc->amr_dev, "can't allocate mailbox tag\n");
  596         return(ENOMEM);
  597     }
  598 
  599     /*
  600      * Allocate the mailbox structure and permanently map it into
  601      * controller-visible space.
  602      */
  603     error = bus_dmamem_alloc(sc->amr_mailbox_dmat, (void **)&p, BUS_DMA_NOWAIT,
  604                              &sc->amr_mailbox_dmamap);
  605     if (error) {
  606         device_printf(sc->amr_dev, "can't allocate mailbox memory\n");
  607         return(ENOMEM);
  608     }
  609     bus_dmamap_load(sc->amr_mailbox_dmat, sc->amr_mailbox_dmamap, p,
  610                     sizeof(struct amr_mailbox64), amr_setup_mbox_helper, sc, 0);
  611     /*
  612      * Conventional mailbox is inside the mailbox64 region.
  613      */
  614     bzero(p, sizeof(struct amr_mailbox64));
  615     sc->amr_mailbox64 = (struct amr_mailbox64 *)(p + 12);
  616     sc->amr_mailbox = (struct amr_mailbox *)(p + 16);
  617 
  618     return(0);
  619 }

Cache object: c70e33ad6e1a7716cb39e1f0abeb4543


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