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/sparc64/isa/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 /*-
    2  * Copyright (c) 1998 Doug Rabson
    3  * Copyright (c) 2001 Thomas Moestl <tmm@FreeBSD.org>
    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  *      from: FreeBSD: src/sys/alpha/isa/isa.c,v 1.26 2001/07/11
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD$");
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/bus.h>
   36 
   37 #include <machine/bus.h>
   38 
   39 #include <sys/rman.h>
   40 
   41 #include <isa/isareg.h>
   42 #include <isa/isavar.h>
   43 #include <isa/isa_common.h>
   44 
   45 #include <dev/ofw/ofw_bus.h>
   46 #include <dev/ofw/openfirm.h>
   47 
   48 #include <machine/resource.h>
   49 
   50 #include <dev/pci/pcireg.h>
   51 #include <dev/pci/pcivar.h>
   52 
   53 #include <sparc64/pci/ofw_pci.h>
   54 #include <sparc64/isa/ofw_isa.h>
   55 
   56 /* There can be only one ISA bus, so it is safe to use globals. */
   57 static u_int64_t isa_io_base;
   58 static u_int64_t isa_io_limit;
   59 static u_int64_t isa_mem_base;
   60 static u_int64_t isa_mem_limit;
   61 
   62 device_t isa_bus_device;
   63 
   64 static phandle_t isab_node;
   65 static struct isa_ranges *isab_ranges;
   66 static int isab_nrange;
   67 static ofw_pci_intr_t isa_ino[8];
   68 static struct ofw_bus_iinfo isa_iinfo;
   69 
   70 /*
   71  * XXX: This is really partly PCI-specific, but unfortunately is
   72  * differently enough to have to duplicate it here...
   73  */
   74 #define ISAB_RANGE_PHYS(r)                                              \
   75         (((u_int64_t)(r)->phys_mid << 32) | (u_int64_t)(r)->phys_lo)
   76 #define ISAB_RANGE_SPACE(r)     (((r)->phys_hi >> 24) & 0x03)
   77 
   78 #define ISAR_SPACE_IO           0x01
   79 #define ISAR_SPACE_MEM          0x02
   80 
   81 #define INRANGE(x, start, end)  ((x) >= (start) && (x) <= (end))
   82 
   83 static void     isa_setup_children(device_t, phandle_t);
   84 
   85 intrmask_t
   86 isa_irq_pending(void)
   87 {
   88         intrmask_t pending;
   89         int i;
   90 
   91         /* XXX: Is this correct? */
   92         for (i = 7, pending = 0; i >= 0; i--) {
   93                 pending <<= 1;
   94                 if (isa_ino[i] != PCI_INVALID_IRQ) {
   95                         pending |= (OFW_PCI_INTR_PENDING(isa_bus_device,
   96                             isa_ino[i]) == 0) ? 0 : 1;
   97                 }
   98         }
   99         return (pending);
  100 }
  101 
  102 void
  103 isa_init(device_t dev)
  104 {
  105         device_t bridge;
  106         int i;
  107 
  108         /* The parent of the bus must be a PCI-ISA bridge. */
  109         bridge = device_get_parent(dev);
  110         isab_node = ofw_bus_get_node(bridge);
  111         isab_nrange = OF_getprop_alloc(isab_node, "ranges",
  112             sizeof(*isab_ranges), (void **)&isab_ranges);
  113         if (isab_nrange <= 0)
  114                 panic("isa_init: cannot get bridge range property");
  115 
  116         ofw_bus_setup_iinfo(isab_node, &isa_iinfo, sizeof(ofw_isa_intr_t));
  117 
  118         /*
  119          * This is really a bad kludge; however, it is needed to provide
  120          * isa_irq_pending(), which is unfortunately still used by some
  121          * drivers.
  122          * XXX: The only driver still using isa_irq_pending() is sio(4)
  123          *      which we don't use on sparc64. Should we just drop support
  124          *      for isa_irq_pending()?
  125          */
  126         for (i = 0; i < 8; i++)
  127                 isa_ino[i] = PCI_INVALID_IRQ;
  128 
  129         isa_setup_children(dev, isab_node);
  130 
  131         for (i = isab_nrange - 1; i >= 0; i--) {
  132                 switch(ISAB_RANGE_SPACE(&isab_ranges[i])) {
  133                 case ISAR_SPACE_IO:
  134                         /* This is probably always 0. */
  135                         isa_io_base = ISAB_RANGE_PHYS(&isab_ranges[i]);
  136                         isa_io_limit = isab_ranges[i].size;
  137                         break;
  138                 case ISAR_SPACE_MEM:
  139                         /* This is probably always 0. */
  140                         isa_mem_base = ISAB_RANGE_PHYS(&isab_ranges[i]);
  141                         isa_mem_limit = isab_ranges[i].size;
  142                         break;
  143                 }
  144         }
  145 }
  146 
  147 static const struct {
  148         const char      *name;
  149         uint32_t        id;
  150 } ofw_isa_pnp_map[] = {
  151         { "SUNW,lomh",  0x0000ae4e }, /* SUN0000 */
  152         { "dma",        0x0002d041 }, /* PNP0200 */
  153         { "floppy",     0x0007d041 }, /* PNP0700 */
  154         { "rtc",        0x000bd041 }, /* PNP0B00 */
  155         { "flashprom",  0x0100ae4e }, /* SUN0001 */
  156         { "parallel",   0x0104d041 }, /* PNP0401 */
  157         { "serial",     0x0105d041 }, /* PNP0501 */
  158         { "i2c",        0x0200ae4e }, /* SUN0002 */
  159         { "rmc-comm",   0x0300ae4e }, /* SUN0003 */
  160         { "kb_ps2",     0x0303d041 }, /* PNP0303 */
  161         { "kdmouse",    0x030fd041 }, /* PNP0F03 */
  162         { "power",      0x0c0cd041 }, /* PNP0C0C */
  163         { NULL,         0x0 }
  164 };
  165 
  166 static void
  167 isa_setup_children(device_t dev, phandle_t parent)
  168 {
  169         struct isa_regs *regs;
  170         struct resource_list *rl;
  171         device_t cdev;
  172         u_int64_t end, start;
  173         ofw_isa_intr_t *intrs, rintr;
  174         phandle_t node;
  175         uint32_t *drqs, *regidx;
  176         int i, ndrq, nintr, nreg, nregidx, rid, rtype;
  177         char *name;
  178 
  179         /*
  180          * Loop through children and fake up PnP devices for them.
  181          * Their resources are added as fully mapped and specified because
  182          * adjusting the resources and the resource list entries respectively
  183          * in isa_alloc_resource() causes trouble with drivers which use
  184          * rman_get_start(), pass-through or allocate and release resources
  185          * multiple times, etc. Adjusting the resources might be better off
  186          * in a bus_activate_resource method but the common ISA code doesn't
  187          * allow for an isa_activate_resource().
  188          */
  189         for (node = OF_child(parent); node != 0; node = OF_peer(node)) {
  190                 if ((OF_getprop_alloc(node, "name", 1, (void **)&name)) == -1)
  191                         continue;
  192 
  193                 /*
  194                  * Keyboard and mouse controllers hang off of the `8042'
  195                  * node but we have no real use for the `8042' itself.
  196                  */
  197                 if (strcmp(name, "8042") == 0) {
  198                         isa_setup_children(dev, node);
  199                         free(name, M_OFWPROP);
  200                         continue;
  201                 }
  202 
  203                 for (i = 0; ofw_isa_pnp_map[i].name != NULL; i++)
  204                         if (strcmp(ofw_isa_pnp_map[i].name, name) == 0)
  205                                 break;
  206                 if (ofw_isa_pnp_map[i].name == NULL) {
  207                         printf("isa_setup_children: no PnP map entry for node "
  208                             "0x%lx: %s\n", (unsigned long)node, name);
  209                         free(name, M_OFWPROP);
  210                         continue;
  211                 }
  212 
  213                 if ((cdev = BUS_ADD_CHILD(dev, ISA_ORDER_PNPBIOS, NULL, -1)) ==
  214                     NULL)
  215                         panic("isa_setup_children: BUS_ADD_CHILD failed");
  216                 isa_set_logicalid(cdev, ofw_isa_pnp_map[i].id);
  217                 isa_set_vendorid(cdev, ofw_isa_pnp_map[i].id);
  218 
  219                 rl = BUS_GET_RESOURCE_LIST(dev, cdev);
  220                 nreg = OF_getprop_alloc(node, "reg", sizeof(*regs),
  221                     (void **)&regs);
  222                 for (i = 0; i < nreg; i++) {
  223                         start = ISA_REG_PHYS(&regs[i]);
  224                         end = start + regs[i].size - 1;
  225                         rtype = ofw_isa_range_map(isab_ranges, isab_nrange,
  226                             &start, &end, NULL);
  227                         rid = 0;
  228                         while (resource_list_find(rl, rtype, rid) != NULL)
  229                                 rid++;
  230                         bus_set_resource(cdev, rtype, rid, start,
  231                             end - start + 1);
  232                 }
  233                 if (nreg == -1 && parent != isab_node) {
  234                         /*
  235                          * The "reg" property still might be an index into
  236                          * the set of registers of the parent device like
  237                          * with the nodes hanging off of the `8042' node.
  238                          */
  239                         nregidx = OF_getprop_alloc(node, "reg", sizeof(*regidx),
  240                             (void **)&regidx);
  241                         if (nregidx > 2)
  242                                 panic("isa_setup_children: impossible number "
  243                                     "of register indices");
  244                         if (nregidx != -1 && (nreg = OF_getprop_alloc(parent,
  245                             "reg", sizeof(*regs), (void **)&regs)) >= nregidx) {
  246                                 for (i = 0; i < nregidx; i++) {
  247                                         start = ISA_REG_PHYS(&regs[regidx[i]]);
  248                                         end = start + regs[regidx[i]].size - 1;
  249                                         rtype = ofw_isa_range_map(isab_ranges,
  250                                             isab_nrange, &start, &end, NULL);
  251                                         rid = 0;
  252                                         while (resource_list_find(rl, rtype,
  253                                             rid) != NULL)
  254                                                 rid++;
  255                                         bus_set_resource(cdev, rtype, rid,
  256                                             start, end - start + 1);
  257                                 }
  258                         }
  259                         if (regidx != NULL)
  260                                 free(regidx, M_OFWPROP);
  261                 }
  262                 if (regs != NULL)
  263                         free(regs, M_OFWPROP);
  264 
  265                 nintr = OF_getprop_alloc(node, "interrupts", sizeof(*intrs),
  266                     (void **)&intrs);
  267                 for (i = 0; i < nintr; i++) {
  268                         if (intrs[i] > 7)
  269                                 panic("isa_setup_children: intr too large");
  270                         rintr = ofw_isa_route_intr(device_get_parent(dev), node,
  271                             &isa_iinfo, intrs[i]);
  272                         if (rintr == PCI_INVALID_IRQ)
  273                                 panic("isa_setup_children: could not map ISA "
  274                                     "interrupt %d", intrs[i]);
  275                         isa_ino[intrs[i]] = rintr;
  276                         bus_set_resource(cdev, SYS_RES_IRQ, i, rintr, 1);
  277                 }
  278                 if (intrs != NULL)
  279                         free(intrs, M_OFWPROP);
  280 
  281                 ndrq = OF_getprop_alloc(node, "dma-channel", sizeof(*drqs),
  282                     (void **)&drqs);
  283                 for (i = 0; i < ndrq; i++)
  284                         bus_set_resource(cdev, SYS_RES_DRQ, i, drqs[i], 1);
  285                 if (drqs != NULL)
  286                         free(drqs, M_OFWPROP);
  287 
  288                 /*
  289                  * Devices using DMA hang off of the `dma' node instead of
  290                  * directly from the ISA bridge node.
  291                  */
  292                 if (strcmp(name, "dma") == 0)
  293                         isa_setup_children(dev, node);
  294 
  295                 free(name, M_OFWPROP);
  296         }
  297 }
  298 
  299 struct resource *
  300 isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
  301                    u_long start, u_long end, u_long count, u_int flags)
  302 {
  303         /*
  304          * Consider adding a resource definition.
  305          */
  306         int passthrough = (device_get_parent(child) != bus);
  307         int isdefault = (start == 0UL && end == ~0UL);
  308         struct resource_list *rl;
  309         struct resource_list_entry *rle;
  310         u_long base, limit;
  311 
  312         rl = BUS_GET_RESOURCE_LIST(bus, child);
  313         if (!passthrough && !isdefault) {
  314                 rle = resource_list_find(rl, type, *rid);
  315                 if (!rle) {
  316                         if (*rid < 0)
  317                                 return (NULL);
  318                         switch (type) {
  319                         case SYS_RES_IRQ:
  320                                 if (*rid >= ISA_NIRQ)
  321                                         return (NULL);
  322                                 break;
  323                         case SYS_RES_DRQ:
  324                                 if (*rid >= ISA_NDRQ)
  325                                         return (NULL);
  326                                 break;
  327                         case SYS_RES_MEMORY:
  328                                 if (*rid >= ISA_NMEM)
  329                                         return (NULL);
  330                                 break;
  331                         case SYS_RES_IOPORT:
  332                                 if (*rid >= ISA_NPORT)
  333                                         return (NULL);
  334                                 break;
  335                         default:
  336                                 return (NULL);
  337                         }
  338                         resource_list_add(rl, type, *rid, start, end, count);
  339                 }
  340         }
  341 
  342         /*
  343          * Sanity check if the resource in the respective entry is fully
  344          * mapped and specified and its type allocable. A driver could
  345          * have added an out of range resource on its own.
  346          */
  347         if (!passthrough) {
  348                 if ((rle = resource_list_find(rl, type, *rid)) == NULL)
  349                         return (NULL);
  350                 base = limit = 0;
  351                 switch (type) {
  352                 case SYS_RES_MEMORY:
  353                         base = isa_mem_base;
  354                         limit = base + isa_mem_limit;
  355                         break;
  356                 case SYS_RES_IOPORT:
  357                         base = isa_io_base;
  358                         limit = base + isa_io_limit;
  359                         break;
  360                 case SYS_RES_IRQ:
  361                         if (rle->start != rle->end || rle->start <= 7)
  362                                 return (NULL);
  363                         break;
  364                 case SYS_RES_DRQ:
  365                         break;
  366                 default:
  367                         return (NULL);
  368                 }
  369                 if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
  370                         if (!INRANGE(rle->start, base, limit) ||
  371                             !INRANGE(rle->end, base, limit))
  372                                 return (NULL);
  373                 }
  374         }
  375 
  376         return (resource_list_alloc(rl, bus, child, type, rid, start, end,
  377             count, flags));
  378 }
  379 
  380 int
  381 isa_release_resource(device_t bus, device_t child, int type, int rid,
  382                      struct resource *res)
  383 {
  384 
  385         return (bus_generic_rl_release_resource(bus, child, type, rid, res));
  386 }
  387 
  388 int
  389 isa_setup_intr(device_t dev, device_t child,
  390                struct resource *irq, int flags, driver_filter_t *filter, 
  391                driver_intr_t *intr, void *arg, void **cookiep)         
  392 {
  393 
  394         /*
  395          * Just pass through. This is going to be handled by either
  396          * one of the parent PCI buses or the nexus device.
  397          * The interrupt had been routed before it was added to the
  398          * resource list of the child.
  399          */
  400         return (BUS_SETUP_INTR(device_get_parent(dev), child, irq, flags,
  401             filter, intr, arg, cookiep));
  402 }
  403 
  404 int
  405 isa_teardown_intr(device_t dev, device_t child,
  406                   struct resource *irq, void *cookie)
  407 {
  408 
  409         return (BUS_TEARDOWN_INTR(device_get_parent(dev), child, irq, cookie));
  410 }

Cache object: 01a048ff0123029f7bc2ffed3e113f5a


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