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/sound/isa/gusc.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 Seigo Tanimura
    3  * Copyright (c) 1999 Ville-Pertti Keinonen
    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 #include <sys/param.h>
   29 #include <sys/systm.h>
   30 #include <sys/kernel.h>
   31 #include <sys/bus.h>
   32 #include <sys/malloc.h>
   33 #include <sys/module.h>
   34 #include <machine/resource.h>
   35 #include <machine/bus.h>
   36 #include <sys/rman.h>
   37 #include <sys/soundcard.h>
   38 #include <dev/sound/pcm/sound.h>
   39 #include <dev/sound/chip.h>
   40 #include "bus_if.h"
   41 
   42 #include <isa/isavar.h>
   43 #include <isa/isa_common.h>
   44 #ifdef __alpha__                /* XXX workaround a stupid warning */
   45 #include <alpha/isa/isavar.h>
   46 #endif
   47 
   48 SND_DECLARE_FILE("$FreeBSD: stable/4/sys/dev/sound/isa/gusc.c 95264 2002-04-22 15:49:36Z cg $");
   49 
   50 #define LOGICALID_NOPNP 0
   51 #define LOGICALID_PCM   0x0000561e
   52 #define LOGICALID_OPL   0x0300561e
   53 #define LOGICALID_MIDI  0x0400561e
   54 
   55 /* PnP IDs */
   56 static struct isa_pnp_id gusc_ids[] = {
   57         {LOGICALID_PCM,  "GRV0000 Gravis UltraSound PnP PCM"},  /* GRV0000 */
   58         {LOGICALID_OPL,  "GRV0003 Gravis UltraSound PnP OPL"},  /* GRV0003 */
   59         {LOGICALID_MIDI, "GRV0004 Gravis UltraSound PnP MIDI"}, /* GRV0004 */
   60 };
   61 
   62 /* Interrupt handler.  */
   63 struct gusc_ihandler {
   64         void (*intr)(void *);
   65         void *arg;
   66 };
   67 
   68 /* Here is the parameter structure per a device. */
   69 struct gusc_softc {
   70         device_t dev; /* device */
   71         int io_rid[3]; /* io port rids */
   72         struct resource *io[3]; /* io port resources */
   73         int io_alloced[3]; /* io port alloc flag */
   74         int irq_rid; /* irq rids */
   75         struct resource *irq; /* irq resources */
   76         int irq_alloced; /* irq alloc flag */
   77         int drq_rid[2]; /* drq rids */
   78         struct resource *drq[2]; /* drq resources */
   79         int drq_alloced[2]; /* drq alloc flag */
   80 
   81         /* Interrupts are shared (XXX non-PnP only?) */
   82         struct gusc_ihandler midi_intr;
   83         struct gusc_ihandler pcm_intr;
   84 };
   85 
   86 typedef struct gusc_softc *sc_p;
   87 
   88 static int gusc_probe(device_t dev);
   89 static int gusc_attach(device_t dev);
   90 static int gusisa_probe(device_t dev);
   91 static void gusc_intr(void *);
   92 static struct resource *gusc_alloc_resource(device_t bus, device_t child, int type, int *rid,
   93                                               u_long start, u_long end, u_long count, u_int flags);
   94 static int gusc_release_resource(device_t bus, device_t child, int type, int rid,
   95                                    struct resource *r);
   96 
   97 static device_t find_masterdev(sc_p scp);
   98 static int alloc_resource(sc_p scp);
   99 static int release_resource(sc_p scp);
  100 
  101 static devclass_t gusc_devclass;
  102 
  103 static int
  104 gusc_probe(device_t dev)
  105 {
  106         device_t child;
  107         u_int32_t logical_id;
  108         char *s;
  109         struct sndcard_func *func;
  110         int ret;
  111 
  112         logical_id = isa_get_logicalid(dev);
  113         s = NULL;
  114 
  115         /* Check isapnp ids */
  116         if (logical_id != 0 && (ret = ISA_PNP_PROBE(device_get_parent(dev), dev, gusc_ids)) != 0)
  117                 return (ret);
  118         else {
  119                 if (logical_id == 0)
  120                         return gusisa_probe(dev);
  121         }
  122 
  123         switch (logical_id) {
  124         case LOGICALID_PCM:
  125                 s = "Gravis UltraSound Plug & Play PCM";
  126                 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO);
  127                 if (func == NULL)
  128                         return (ENOMEM);
  129                 func->func = SCF_PCM;
  130                 child = device_add_child(dev, "pcm", -1);
  131                 device_set_ivars(child, func);
  132                 break;
  133         case LOGICALID_OPL:
  134                 s = "Gravis UltraSound Plug & Play OPL";
  135                 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO);
  136                 if (func == NULL)
  137                         return (ENOMEM);
  138                 func->func = SCF_SYNTH;
  139                 child = device_add_child(dev, "midi", -1);
  140                 device_set_ivars(child, func);
  141                 break;
  142         case LOGICALID_MIDI:
  143                 s = "Gravis UltraSound Plug & Play MIDI";
  144                 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO);
  145                 if (func == NULL)
  146                         return (ENOMEM);
  147                 func->func = SCF_MIDI;
  148                 child = device_add_child(dev, "midi", -1);
  149                 device_set_ivars(child, func);
  150                 break;
  151         }
  152 
  153         if (s != NULL) {
  154                 device_set_desc(dev, s);
  155                 return (0);
  156         }
  157 
  158         return (ENXIO);
  159 }
  160 
  161 static void
  162 port_wr(struct resource *r, int i, unsigned char v)
  163 {
  164         bus_space_write_1(rman_get_bustag(r), rman_get_bushandle(r), i, v);
  165 }
  166 
  167 static int
  168 port_rd(struct resource *r, int i)
  169 {
  170         return bus_space_read_1(rman_get_bustag(r), rman_get_bushandle(r), i);
  171 }
  172 
  173 /*
  174  * Probe for an old (non-PnP) GUS card on the ISA bus.
  175  */
  176 
  177 static int
  178 gusisa_probe(device_t dev)
  179 {
  180         device_t child;
  181         struct resource *res, *res2;
  182         int base, rid, rid2, s, flags;
  183         unsigned char val;
  184 
  185         base = isa_get_port(dev);
  186         flags = device_get_flags(dev);
  187         rid = 1;
  188         res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, base + 0x100,
  189                                  base + 0x107, 8, RF_ACTIVE);
  190 
  191         if (res == NULL)
  192                 return ENXIO;
  193 
  194         res2 = NULL;
  195 
  196         /*
  197          * Check for the presence of some GUS card.  Reset the card,
  198          * then see if we can access the memory on it.
  199          */
  200 
  201         port_wr(res, 3, 0x4c);
  202         port_wr(res, 5, 0);
  203         DELAY(30 * 1000);
  204 
  205         port_wr(res, 3, 0x4c);
  206         port_wr(res, 5, 1);
  207         DELAY(30 * 1000);
  208 
  209         s = splhigh();
  210 
  211         /* Write to DRAM.  */
  212 
  213         port_wr(res, 3, 0x43);          /* Register select */
  214         port_wr(res, 4, 0);             /* Low addr */
  215         port_wr(res, 5, 0);             /* Med addr */
  216 
  217         port_wr(res, 3, 0x44);          /* Register select */
  218         port_wr(res, 4, 0);             /* High addr */
  219         port_wr(res, 7, 0x55);          /* DRAM */
  220 
  221         /* Read from DRAM.  */
  222 
  223         port_wr(res, 3, 0x43);          /* Register select */
  224         port_wr(res, 4, 0);             /* Low addr */
  225         port_wr(res, 5, 0);             /* Med addr */
  226 
  227         port_wr(res, 3, 0x44);          /* Register select */
  228         port_wr(res, 4, 0);             /* High addr */
  229         val = port_rd(res, 7);          /* DRAM */
  230 
  231         splx(s);
  232 
  233         if (val != 0x55)
  234                 goto fail;
  235 
  236         rid2 = 0;
  237         res2 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid2, base, base, 1,
  238                                   RF_ACTIVE);
  239 
  240         if (res2 == NULL)
  241                 goto fail;
  242 
  243         s = splhigh();
  244         port_wr(res2, 0x0f, 0x20);
  245         val = port_rd(res2, 0x0f);
  246         splx(s);
  247 
  248         if (val == 0xff || (val & 0x06) == 0)
  249                 val = 0;
  250         else {
  251                 val = port_rd(res2, 0x506);     /* XXX Out of range.  */
  252                 if (val == 0xff)
  253                         val = 0;
  254         }
  255 
  256         bus_release_resource(dev, SYS_RES_IOPORT, rid2, res2);
  257         bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
  258 
  259         if (val >= 10) {
  260                 struct sndcard_func *func;
  261 
  262                 /* Looks like a GUS MAX.  Set the rest of the resources.  */
  263 
  264                 bus_set_resource(dev, SYS_RES_IOPORT, 2, base + 0x10c, 8);
  265 
  266                 if (flags & DV_F_DUAL_DMA)
  267                         bus_set_resource(dev, SYS_RES_DRQ, 1,
  268                                          flags & DV_F_DRQ_MASK, 1);
  269 
  270                 /* We can support the CS4231 and MIDI devices.  */
  271 
  272                 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO);
  273                 if (func == NULL)
  274                         return ENOMEM;
  275                 func->func = SCF_MIDI;
  276                 child = device_add_child(dev, "midi", -1);
  277                 device_set_ivars(child, func);
  278 
  279                 func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO);
  280                 if (func == NULL)
  281                         printf("xxx: gus pcm not attached, out of memory\n");
  282                 else {
  283                         func->func = SCF_PCM;
  284                         child = device_add_child(dev, "pcm", -1);
  285                         device_set_ivars(child, func);
  286                 }
  287                 device_set_desc(dev, "Gravis UltraSound MAX");
  288                 return 0;
  289         } else {
  290 
  291                 /*
  292                  * TODO: Support even older GUS cards.  MIDI should work on
  293                  * all models.
  294                  */
  295                 return ENXIO;
  296         }
  297 
  298 fail:
  299         bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
  300         return ENXIO;
  301 }
  302 
  303 static int
  304 gusc_attach(device_t dev)
  305 {
  306         sc_p scp;
  307         int unit;
  308         void *ih;
  309 
  310         scp = device_get_softc(dev);
  311         unit = device_get_unit(dev);
  312 
  313         bzero(scp, sizeof(*scp));
  314 
  315         scp->dev = dev;
  316         if (alloc_resource(scp)) {
  317                 release_resource(scp);
  318                 return (ENXIO);
  319         }
  320 
  321         if (scp->irq != NULL)
  322                 bus_setup_intr(dev, scp->irq, INTR_TYPE_AV, gusc_intr, scp, &ih);
  323         bus_generic_attach(dev);
  324 
  325         return (0);
  326 }
  327 
  328 /*
  329  * Handle interrupts on GUS devices until there aren't any left.
  330  */
  331 static void
  332 gusc_intr(void *arg)
  333 {
  334         sc_p scp = (sc_p)arg;
  335         int did_something;
  336 
  337         do {
  338                 did_something = 0;
  339                 if (scp->pcm_intr.intr != NULL &&
  340                     (port_rd(scp->io[2], 2) & 1)) {
  341                         (*scp->pcm_intr.intr)(scp->pcm_intr.arg);
  342                         did_something = 1;
  343                 }
  344                 if (scp->midi_intr.intr != NULL &&
  345                     (port_rd(scp->io[1], 0) & 0x80)) {
  346                         (*scp->midi_intr.intr)(scp->midi_intr.arg);
  347                         did_something = 1;
  348                 }
  349         } while (did_something != 0);
  350 }
  351 
  352 static struct resource *
  353 gusc_alloc_resource(device_t bus, device_t child, int type, int *rid,
  354                       u_long start, u_long end, u_long count, u_int flags)
  355 {
  356         sc_p scp;
  357         int *alloced, rid_max, alloced_max;
  358         struct resource **res;
  359 
  360         scp = device_get_softc(bus);
  361         switch (type) {
  362         case SYS_RES_IOPORT:
  363                 alloced = scp->io_alloced;
  364                 res = scp->io;
  365                 rid_max = 2;
  366                 alloced_max = 2; /* pcm + midi (more to include synth) */
  367                 break;
  368         case SYS_RES_IRQ:
  369                 alloced = &scp->irq_alloced;
  370                 res = &scp->irq;
  371                 rid_max = 0;
  372                 alloced_max = 2; /* pcm and midi share the single irq. */
  373                 break;
  374         case SYS_RES_DRQ:
  375                 alloced = scp->drq_alloced;
  376                 res = scp->drq;
  377                 rid_max = 1;
  378                 alloced_max = 1;
  379                 break;
  380         default:
  381                 return (NULL);
  382         }
  383 
  384         if (*rid > rid_max || alloced[*rid] == alloced_max)
  385                 return (NULL);
  386 
  387         alloced[*rid]++;
  388         return (res[*rid]);
  389 }
  390 
  391 static int
  392 gusc_release_resource(device_t bus, device_t child, int type, int rid,
  393                         struct resource *r)
  394 {
  395         sc_p scp;
  396         int *alloced, rid_max;
  397 
  398         scp = device_get_softc(bus);
  399         switch (type) {
  400         case SYS_RES_IOPORT:
  401                 alloced = scp->io_alloced;
  402                 rid_max = 2;
  403                 break;
  404         case SYS_RES_IRQ:
  405                 alloced = &scp->irq_alloced;
  406                 rid_max = 0;
  407                 break;
  408         case SYS_RES_DRQ:
  409                 alloced = scp->drq_alloced;
  410                 rid_max = 1;
  411                 break;
  412         default:
  413                 return (1);
  414         }
  415 
  416         if (rid > rid_max || alloced[rid] == 0)
  417                 return (1);
  418 
  419         alloced[rid]--;
  420         return (0);
  421 }
  422 
  423 static int
  424 gusc_setup_intr(device_t dev, device_t child, struct resource *irq,
  425                 int flags, driver_intr_t *intr, void *arg, void **cookiep)
  426 {
  427         sc_p scp = (sc_p)device_get_softc(dev);
  428         devclass_t devclass;
  429 
  430         devclass = device_get_devclass(child);
  431         if (strcmp(devclass_get_name(devclass), "midi") == 0) {
  432                 scp->midi_intr.intr = intr;
  433                 scp->midi_intr.arg = arg;
  434                 return 0;
  435         } else if (strcmp(devclass_get_name(devclass), "pcm") == 0) {
  436                 scp->pcm_intr.intr = intr;
  437                 scp->pcm_intr.arg = arg;
  438                 return 0;
  439         }
  440         return bus_generic_setup_intr(dev, child, irq, flags, intr,
  441                                       arg, cookiep);
  442 }
  443 
  444 static device_t
  445 find_masterdev(sc_p scp)
  446 {
  447         int i, units;
  448         devclass_t devclass;
  449         device_t dev;
  450 
  451         devclass = device_get_devclass(scp->dev);
  452         units = devclass_get_maxunit(devclass);
  453         dev = NULL;
  454         for (i = 0 ; i < units ; i++) {
  455                 dev = devclass_get_device(devclass, i);
  456                 if (isa_get_vendorid(dev) == isa_get_vendorid(scp->dev)
  457                     && isa_get_logicalid(dev) == LOGICALID_PCM
  458                     && isa_get_serial(dev) == isa_get_serial(scp->dev))
  459                         break;
  460         }
  461         if (i == units)
  462                 return (NULL);
  463 
  464         return (dev);
  465 }
  466 
  467 static int io_range[3]  = {0x10, 0x8  , 0x4  };
  468 static int io_offset[3] = {0x0 , 0x100, 0x10c};
  469 static int
  470 alloc_resource(sc_p scp)
  471 {
  472         int i, base, lid, flags;
  473         device_t dev;
  474 
  475         flags = 0;
  476         if (isa_get_vendorid(scp->dev))
  477                 lid = isa_get_logicalid(scp->dev);
  478         else {
  479                 lid = LOGICALID_NOPNP;
  480                 flags = device_get_flags(scp->dev);
  481         }
  482         switch(lid) {
  483         case LOGICALID_PCM:
  484         case LOGICALID_NOPNP:           /* XXX Non-PnP */
  485                 if (lid == LOGICALID_NOPNP)
  486                         base = isa_get_port(scp->dev);
  487                 else
  488                         base = 0;
  489                 for (i = 0 ; i < sizeof(scp->io) / sizeof(*scp->io) ; i++) {
  490                         if (scp->io[i] == NULL) {
  491                                 scp->io_rid[i] = i;
  492                                 if (base == 0)
  493                                         scp->io[i] = bus_alloc_resource(scp->dev, SYS_RES_IOPORT, &scp->io_rid[i],
  494                                                                         0, ~0, io_range[i], RF_ACTIVE);
  495                                 else
  496                                         scp->io[i] = bus_alloc_resource(scp->dev, SYS_RES_IOPORT, &scp->io_rid[i],
  497                                                                         base + io_offset[i],
  498                                                                         base + io_offset[i] + io_range[i] - 1
  499                                                                         , io_range[i], RF_ACTIVE);
  500                                 if (scp->io[i] == NULL)
  501                                         return (1);
  502                                 scp->io_alloced[i] = 0;
  503                         }
  504                 }
  505                 if (scp->irq == NULL) {
  506                         scp->irq_rid = 0;
  507                         scp->irq = bus_alloc_resource(scp->dev, SYS_RES_IRQ, &scp->irq_rid,
  508                                                       0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
  509                         if (scp->irq == NULL)
  510                                 return (1);
  511                         scp->irq_alloced = 0;
  512                 }
  513                 for (i = 0 ; i < sizeof(scp->drq) / sizeof(*scp->drq) ; i++) {
  514                         if (scp->drq[i] == NULL) {
  515                                 scp->drq_rid[i] = i;
  516                                 if (base == 0 || i == 0)
  517                                         scp->drq[i] = bus_alloc_resource(scp->dev, SYS_RES_DRQ, &scp->drq_rid[i],
  518                                                                          0, ~0, 1, RF_ACTIVE);
  519                                 else if ((flags & DV_F_DUAL_DMA) != 0)
  520                                         /* XXX The secondary drq is specified in the flag. */
  521                                         scp->drq[i] = bus_alloc_resource(scp->dev, SYS_RES_DRQ, &scp->drq_rid[i],
  522                                                                          flags & DV_F_DRQ_MASK,
  523                                                                          flags & DV_F_DRQ_MASK, 1, RF_ACTIVE);
  524                                 if (scp->drq[i] == NULL)
  525                                         return (1);
  526                                 scp->drq_alloced[i] = 0;
  527                         }
  528                 }
  529                 break;
  530         case LOGICALID_OPL:
  531                 if (scp->io[0] == NULL) {
  532                         scp->io_rid[0] = 0;
  533                         scp->io[0] = bus_alloc_resource(scp->dev, SYS_RES_IOPORT, &scp->io_rid[0],
  534                                                         0, ~0, io_range[0], RF_ACTIVE);
  535                         if (scp->io[0] == NULL)
  536                                 return (1);
  537                         scp->io_alloced[0] = 0;
  538                 }
  539                 break;
  540         case LOGICALID_MIDI:
  541                 if (scp->io[0] == NULL) {
  542                         scp->io_rid[0] = 0;
  543                         scp->io[0] = bus_alloc_resource(scp->dev, SYS_RES_IOPORT, &scp->io_rid[0],
  544                                                         0, ~0, io_range[0], RF_ACTIVE);
  545                         if (scp->io[0] == NULL)
  546                                 return (1);
  547                         scp->io_alloced[0] = 0;
  548                 }
  549                 if (scp->irq == NULL) {
  550                         /* The irq is shared with pcm audio. */
  551                         dev = find_masterdev(scp);
  552                         if (dev == NULL)
  553                                 return (1);
  554                         scp->irq_rid = 0;
  555                         scp->irq = BUS_ALLOC_RESOURCE(dev, NULL, SYS_RES_IRQ, &scp->irq_rid,
  556                                                       0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
  557                         if (scp->irq == NULL)
  558                                 return (1);
  559                         scp->irq_alloced = 0;
  560                 }
  561                 break;
  562         }
  563         return (0);
  564 }
  565 
  566 static int
  567 release_resource(sc_p scp)
  568 {
  569         int i, lid, flags;
  570         device_t dev;
  571 
  572         flags = 0;
  573         if (isa_get_vendorid(scp->dev))
  574                 lid = isa_get_logicalid(scp->dev);
  575         else {
  576                 lid = LOGICALID_NOPNP;
  577                 flags = device_get_flags(scp->dev);
  578         }
  579         switch(lid) {
  580         case LOGICALID_PCM:
  581         case LOGICALID_NOPNP:           /* XXX Non-PnP */
  582                 for (i = 0 ; i < sizeof(scp->io) / sizeof(*scp->io) ; i++) {
  583                         if (scp->io[i] != NULL) {
  584                                 bus_release_resource(scp->dev, SYS_RES_IOPORT, scp->io_rid[i], scp->io[i]);
  585                                 scp->io[i] = NULL;
  586                         }
  587                 }
  588                 if (scp->irq != NULL) {
  589                         bus_release_resource(scp->dev, SYS_RES_IRQ, scp->irq_rid, scp->irq);
  590                         scp->irq = NULL;
  591                 }
  592                 for (i = 0 ; i < sizeof(scp->drq) / sizeof(*scp->drq) ; i++) {
  593                         if (scp->drq[i] != NULL) {
  594                                 bus_release_resource(scp->dev, SYS_RES_DRQ, scp->drq_rid[i], scp->drq[i]);
  595                                 scp->drq[i] = NULL;
  596                         }
  597                 }
  598                 break;
  599         case LOGICALID_OPL:
  600                 if (scp->io[0] != NULL) {
  601                         bus_release_resource(scp->dev, SYS_RES_IOPORT, scp->io_rid[0], scp->io[0]);
  602                         scp->io[0] = NULL;
  603                 }
  604                 break;
  605         case LOGICALID_MIDI:
  606                 if (scp->io[0] != NULL) {
  607                         bus_release_resource(scp->dev, SYS_RES_IOPORT, scp->io_rid[0], scp->io[0]);
  608                         scp->io[0] = NULL;
  609                 }
  610                 if (scp->irq != NULL) {
  611                         /* The irq is shared with pcm audio. */
  612                         dev = find_masterdev(scp);
  613                         if (dev == NULL)
  614                                 return (1);
  615                         BUS_RELEASE_RESOURCE(dev, NULL, SYS_RES_IOPORT, scp->irq_rid, scp->irq);
  616                         scp->irq = NULL;
  617                 }
  618                 break;
  619         }
  620         return (0);
  621 }
  622 
  623 static device_method_t gusc_methods[] = {
  624         /* Device interface */
  625         DEVMETHOD(device_probe,         gusc_probe),
  626         DEVMETHOD(device_attach,        gusc_attach),
  627         DEVMETHOD(device_detach,        bus_generic_detach),
  628         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  629         DEVMETHOD(device_suspend,       bus_generic_suspend),
  630         DEVMETHOD(device_resume,        bus_generic_resume),
  631 
  632         /* Bus interface */
  633         DEVMETHOD(bus_print_child,      bus_generic_print_child),
  634         DEVMETHOD(bus_alloc_resource,   gusc_alloc_resource),
  635         DEVMETHOD(bus_release_resource, gusc_release_resource),
  636         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
  637         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
  638         DEVMETHOD(bus_setup_intr,       gusc_setup_intr),
  639         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
  640 
  641         { 0, 0 }
  642 };
  643 
  644 static driver_t gusc_driver = {
  645         "gusc",
  646         gusc_methods,
  647         sizeof(struct gusc_softc),
  648 };
  649 
  650 /*
  651  * gusc can be attached to an isa bus.
  652  */
  653 DRIVER_MODULE(snd_gusc, isa, gusc_driver, gusc_devclass, 0, 0);
  654 MODULE_DEPEND(snd_gusc, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
  655 MODULE_VERSION(snd_gusc, 1);
  656 
  657 

Cache object: 34f2be2ebce107f02d6e3ed688b4c1ce


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