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/i386/isa/isa.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) 1998 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$");
   29 
   30 /*-
   31  * Modifications for Intel architecture by Garrett A. Wollman.
   32  * Copyright 1998 Massachusetts Institute of Technology
   33  *
   34  * Permission to use, copy, modify, and distribute this software and
   35  * its documentation for any purpose and without fee is hereby
   36  * granted, provided that both the above copyright notice and this
   37  * permission notice appear in all copies, that both the above
   38  * copyright notice and this permission notice appear in all
   39  * supporting documentation, and that the name of M.I.T. not be used
   40  * in advertising or publicity pertaining to distribution of the
   41  * software without specific, written prior permission.  M.I.T. makes
   42  * no representations about the suitability of this software for any
   43  * purpose.  It is provided "as is" without express or implied
   44  * warranty.
   45  * 
   46  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
   47  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
   48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   49  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
   50  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   51  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   52  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   53  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   54  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   55  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   56  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   57  * SUCH DAMAGE.
   58  */
   59 
   60 #include <sys/param.h>
   61 #include <sys/bus.h>
   62 #include <sys/kernel.h>
   63 #include <sys/malloc.h>
   64 #include <sys/module.h>
   65 #include <machine/bus.h>
   66 #include <sys/rman.h>
   67 #ifdef PC98
   68 #include <sys/systm.h>
   69 #endif
   70 
   71 #include <machine/resource.h>
   72 
   73 #include <isa/isavar.h>
   74 #include <isa/isa_common.h>
   75 
   76 void
   77 isa_init(device_t dev)
   78 {
   79 }
   80 
   81 /*
   82  * This implementation simply passes the request up to the parent
   83  * bus, which in our case is the special i386 nexus, substituting any
   84  * configured values if the caller defaulted.  We can get away with
   85  * this because there is no special mapping for ISA resources on an Intel
   86  * platform.  When porting this code to another architecture, it may be
   87  * necessary to interpose a mapping layer here.
   88  */
   89 struct resource *
   90 isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
   91                    u_long start, u_long end, u_long count, u_int flags)
   92 {
   93         /*
   94          * Consider adding a resource definition.
   95          */
   96         int passthrough = (device_get_parent(child) != bus);
   97         int isdefault = (start == 0UL && end == ~0UL);
   98         struct isa_device* idev = DEVTOISA(child);
   99         struct resource_list *rl = &idev->id_resources;
  100         struct resource_list_entry *rle;
  101         
  102         if (!passthrough && !isdefault) {
  103                 rle = resource_list_find(rl, type, *rid);
  104                 if (!rle) {
  105                         if (*rid < 0)
  106                                 return 0;
  107                         switch (type) {
  108                         case SYS_RES_IRQ:
  109                                 if (*rid >= ISA_NIRQ)
  110                                         return 0;
  111                                 break;
  112                         case SYS_RES_DRQ:
  113                                 if (*rid >= ISA_NDRQ)
  114                                         return 0;
  115                                 break;
  116                         case SYS_RES_MEMORY:
  117                                 if (*rid >= ISA_NMEM)
  118                                         return 0;
  119                                 break;
  120                         case SYS_RES_IOPORT:
  121                                 if (*rid >= ISA_NPORT)
  122                                         return 0;
  123                                 break;
  124                         default:
  125                                 return 0;
  126                         }
  127                         resource_list_add(rl, type, *rid, start, end, count);
  128                 }
  129         }
  130 
  131         return resource_list_alloc(rl, bus, child, type, rid,
  132                                    start, end, count, flags);
  133 }
  134 
  135 #ifdef PC98
  136 /*
  137  * Indirection support.  The type of bus_space_handle_t is
  138  * defined in sys/i386/include/bus_pc98.h.
  139  */
  140 struct resource *
  141 isa_alloc_resourcev(device_t child, int type, int *rid,
  142                     bus_addr_t *res, bus_size_t count, u_int flags)
  143 {
  144         struct isa_device* idev = DEVTOISA(child);
  145         struct resource_list *rl = &idev->id_resources;
  146 
  147         device_t        bus = device_get_parent(child);
  148         bus_addr_t      start;
  149         bus_space_handle_t bh;
  150         struct resource *re;
  151         struct resource **bsre;
  152         int             i, j, k, linear_cnt, ressz, bsrid;
  153 
  154         start = bus_get_resource_start(child, type, *rid);
  155 
  156         linear_cnt = count;
  157         ressz = 1;
  158         for (i = 1; i < count; ++i) {
  159                 if (res[i] != res[i - 1] + 1) {
  160                         if (i < linear_cnt)
  161                                 linear_cnt = i;
  162                         ++ressz;
  163                 }
  164         }
  165 
  166         re = isa_alloc_resource(bus, child, type, rid,
  167                                 start + res[0], start + res[linear_cnt - 1],
  168                                 linear_cnt, flags);
  169         if (re == NULL)
  170                 return NULL;
  171 
  172         bsre = malloc(sizeof (struct resource *) * ressz, M_DEVBUF, M_NOWAIT);
  173         if (bsre == NULL) {
  174                 resource_list_release(rl, bus, child, type, *rid, re);
  175                 return NULL;
  176         }
  177         bsre[0] = re;
  178 
  179         for (i = linear_cnt, k = 1; i < count; i = j, k++) {
  180                 for (j = i + 1; j < count; j++) {
  181                         if (res[j] != res[j - 1] + 1)
  182                                 break;
  183                 }
  184                 bsrid = *rid + k;
  185                 bsre[k] = isa_alloc_resource(bus, child, type, &bsrid,
  186                         start + res[i], start + res[j - 1], j - i, flags);
  187                 if (bsre[k] == NULL) {
  188                         for (k--; k >= 0; k--)
  189                                 resource_list_release(rl, bus, child, type,
  190                                                       *rid + k, bsre[k]);
  191                         free(bsre, M_DEVBUF);
  192                         return NULL;
  193                 }
  194         }
  195 
  196         bh = rman_get_bushandle(re);
  197         bh->bsh_res = bsre;
  198         bh->bsh_ressz = ressz;
  199 
  200         return re;
  201 }
  202 
  203 int
  204 isa_load_resourcev(struct resource *re, bus_addr_t *res, bus_size_t count)
  205 {
  206         bus_addr_t      start;
  207         bus_space_handle_t bh;
  208         int             i;
  209 
  210         bh = rman_get_bushandle(re);
  211         if (count > bh->bsh_maxiatsz) {
  212                 printf("isa_load_resourcev: map size too large\n");
  213                 return EINVAL;
  214         }
  215 
  216         start = rman_get_start(re);
  217         for (i = 0; i < bh->bsh_maxiatsz; i++) {
  218                 if (i < count)
  219                         bh->bsh_iat[i] = start + res[i];
  220                 else
  221                         bh->bsh_iat[i] = start;
  222         }
  223 
  224         bh->bsh_iatsz = count;
  225         bh->bsh_bam = rman_get_bustag(re)->bs_ra;       /* relocate access */
  226 
  227         return 0;
  228 }
  229 #endif  /* PC98 */
  230 
  231 int
  232 isa_release_resource(device_t bus, device_t child, int type, int rid,
  233                      struct resource *r)
  234 {
  235         struct isa_device* idev = DEVTOISA(child);
  236         struct resource_list *rl = &idev->id_resources;
  237 #ifdef PC98
  238         /*
  239          * Indirection support.  The type of bus_space_handle_t is
  240          * defined in sys/i386/include/bus_pc98.h.
  241          */
  242         int     i;
  243         bus_space_handle_t bh;
  244 
  245         if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
  246                 bh = rman_get_bushandle(r);
  247                 if (bh != NULL) {
  248                         for (i = 1; i < bh->bsh_ressz; i++)
  249                                 resource_list_release(rl, bus, child, type,
  250                                                       rid + i, bh->bsh_res[i]);
  251                         if (bh->bsh_res != NULL)
  252                                 free(bh->bsh_res, M_DEVBUF);
  253                 }
  254         }
  255 #endif
  256         return resource_list_release(rl, bus, child, type, rid, r);
  257 }
  258 
  259 /*
  260  * We can't use the bus_generic_* versions of these methods because those
  261  * methods always pass the bus param as the requesting device, and we need
  262  * to pass the child (the i386 nexus knows about this and is prepared to
  263  * deal).
  264  */
  265 int
  266 isa_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
  267                driver_filter_t filter, void (*ihand)(void *), void *arg,
  268                void **cookiep)
  269 {
  270         return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
  271                                filter, ihand, arg, cookiep));
  272 }
  273 
  274 int
  275 isa_teardown_intr(device_t bus, device_t child, struct resource *r,
  276                   void *cookie)
  277 {
  278         return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie));
  279 }
  280 
  281 /*
  282  * On this platform, isa can also attach to the legacy bus.
  283  */
  284 DRIVER_MODULE(isa, legacy, isa_driver, isa_devclass, 0, 0);

Cache object: 00735ec7c763e783b0f5612a9cef3458


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