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/isa/i82365_isa.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 /*      $OpenBSD: i82365_isa.c,v 1.25 2022/04/06 18:59:28 naddy Exp $   */
    2 /*      $NetBSD: i82365_isa.c,v 1.11 1998/06/09 07:25:00 thorpej Exp $  */
    3 
    4 /*
    5  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *      This product includes software developed by Marc Horowitz.
   18  * 4. The name of the author may not be used to endorse or promote products
   19  *    derived from this software without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/kernel.h>
   36 #include <sys/device.h>
   37 #include <sys/extent.h>
   38 #include <sys/malloc.h>
   39 
   40 #include <machine/bus.h>
   41 #include <machine/intr.h>
   42 
   43 #include <dev/isa/isareg.h>
   44 #include <dev/isa/isavar.h>
   45 
   46 #include <dev/pcmcia/pcmciareg.h>
   47 #include <dev/pcmcia/pcmciavar.h>
   48 #include <dev/pcmcia/pcmciachip.h>
   49 
   50 #include <dev/ic/i82365reg.h>
   51 #include <dev/ic/i82365var.h>
   52 #include <dev/isa/i82365_isavar.h>
   53 
   54 #ifdef PCICISADEBUG
   55 #define DPRINTF(arg)    printf arg;
   56 #else
   57 #define DPRINTF(arg)
   58 #endif
   59 
   60 int     pcic_isa_probe(struct device *, void *, void *);
   61 void    pcic_isa_attach(struct device *, struct device *, void *);
   62 
   63 const struct cfattach pcic_isa_ca = {
   64         sizeof(struct pcic_softc), pcic_isa_probe, pcic_isa_attach
   65 };
   66 
   67 static struct pcmcia_chip_functions pcic_isa_functions = {
   68         pcic_chip_mem_alloc,
   69         pcic_chip_mem_free,
   70         pcic_chip_mem_map,
   71         pcic_chip_mem_unmap,
   72 
   73         pcic_chip_io_alloc,
   74         pcic_chip_io_free,
   75         pcic_chip_io_map,
   76         pcic_chip_io_unmap,
   77 
   78         pcic_isa_chip_intr_establish,
   79         pcic_isa_chip_intr_disestablish,
   80         pcic_isa_chip_intr_string,
   81 
   82         pcic_chip_socket_enable,
   83         pcic_chip_socket_disable,
   84 };
   85 
   86 int
   87 pcic_isa_probe(struct device *parent, void *match, void *aux)
   88 {
   89         struct isa_attach_args *ia = aux;
   90         bus_space_tag_t memt = ia->ia_memt, iot = ia->ia_iot;
   91         bus_space_handle_t ioh, memh;
   92         bus_size_t msize;
   93         int val, found;
   94 
   95         /* Disallow wildcarded i/o address. */
   96         if (ia->ia_iobase == -1 /* ISACF_PORT_DEFAULT */)
   97                 return (0);
   98 
   99         if (bus_space_map(iot, ia->ia_iobase, PCIC_IOSIZE, 0, &ioh))
  100                 return (0);
  101 
  102         if (ia->ia_msize == -1)
  103                 ia->ia_msize = PCIC_MEMSIZE;
  104 
  105         msize = ia->ia_msize;
  106         if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize, 0, &memh)) {
  107                 if (ia->ia_msize > PCIC_MEMSIZE &&
  108                     !bus_space_map(memt, ia->ia_maddr, PCIC_MEMSIZE, 0, &memh))
  109                         msize = PCIC_MEMSIZE;
  110                 else
  111                         return (0);
  112         }
  113         found = 0;
  114 
  115         /*
  116          * this could be done with a loop, but it would violate the
  117          * abstraction
  118          */
  119 
  120         bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
  121         val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
  122         if (pcic_ident_ok(val))
  123                 found++;
  124 
  125         bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SB + PCIC_IDENT);
  126         val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
  127         if (pcic_ident_ok(val))
  128                 found++;
  129 
  130         bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SA + PCIC_IDENT);
  131         val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
  132         if (pcic_ident_ok(val))
  133                 found++;
  134 
  135         bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SB + PCIC_IDENT);
  136         val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
  137         if (pcic_ident_ok(val))
  138                 found++;
  139 
  140         bus_space_unmap(iot, ioh, PCIC_IOSIZE);
  141         bus_space_unmap(memt, memh, msize);
  142 
  143         if (!found)
  144                 return (0);
  145         ia->ia_iosize = PCIC_IOSIZE;
  146         ia->ia_msize = msize;
  147         return (1);
  148 }
  149 
  150 void
  151 pcic_isa_attach(struct device *parent, struct device *self, void *aux)
  152 {
  153         struct pcic_softc *sc = (void *)self;
  154         struct pcic_handle *h;
  155         struct isa_attach_args *ia = aux;
  156         isa_chipset_tag_t ic = ia->ia_ic;
  157         bus_space_tag_t iot = ia->ia_iot;
  158         bus_space_tag_t memt = ia->ia_memt;
  159         bus_space_handle_t ioh;
  160         bus_space_handle_t memh;
  161         int irq, i;
  162 
  163         /* Map i/o space. */
  164         if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
  165                 printf(": can't map i/o space\n");
  166                 return;
  167         }
  168 
  169         /* Map mem space. */
  170         if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize, 0, &memh)) {
  171                 printf(": can't map mem space\n");
  172                 return;
  173         }
  174 
  175         sc->membase = ia->ia_maddr;
  176         sc->subregionmask = (1 << (ia->ia_msize / PCIC_MEM_PAGESIZE)) - 1;
  177 
  178         sc->intr_est = ic;
  179         sc->pct = (pcmcia_chipset_tag_t)&pcic_isa_functions;
  180 
  181         sc->iot = iot;
  182         sc->ioh = ioh;
  183         sc->memt = memt;
  184         sc->memh = memh;
  185 
  186         printf("\n");
  187 
  188         pcic_attach(sc);
  189         pcic_isa_bus_width_probe(sc, iot, ioh, ia->ia_iobase, ia->ia_iosize);
  190         pcic_attach_sockets(sc);
  191 
  192         /*
  193          * Allocate an irq.  It will be used by both controllers.  I could
  194          * use two different interrupts, but interrupts are relatively
  195          * scarce, shareable, and for PCIC controllers, very infrequent.
  196          */
  197         irq = ia->ia_irq;
  198         if (irq == IRQUNK)
  199                 irq = pcic_intr_find(sc, IST_EDGE);
  200 
  201         if (irq) {
  202                 sc->ih = isa_intr_establish(ic, irq, IST_EDGE, IPL_TTY,
  203                     pcic_intr, sc, sc->dev.dv_xname);
  204                 if (!sc->ih)
  205                         irq = 0;
  206         }
  207         sc->irq = irq;
  208 
  209         if (irq) {
  210                 printf("%s: irq %d, ", sc->dev.dv_xname, irq);
  211 
  212                 /* Set up the pcic to interrupt on card detect. */
  213                 for (i = 0; i < PCIC_NSLOTS; i++) {
  214                         h = &sc->handle[i];
  215                         if (h->flags & PCIC_FLAG_SOCKETP) {
  216                                 pcic_write(h, PCIC_CSC_INTR,
  217                                     (sc->irq << PCIC_CSC_INTR_IRQ_SHIFT) |
  218                                     PCIC_CSC_INTR_CD_ENABLE);
  219                         }
  220                 }
  221         } else
  222                 printf("%s: no irq, ", sc->dev.dv_xname);
  223 
  224         printf("polling enabled\n");
  225         if (sc->poll_established == 0) {
  226                 timeout_set(&sc->poll_timeout, pcic_poll_intr, sc);
  227                 timeout_add_msec(&sc->poll_timeout, 500);
  228                 sc->poll_established = 1;
  229         }
  230 }

Cache object: 8194ac0226330381b58c479779342a66


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