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/mips/cavium/obio.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 /*      $NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $  */
    2 
    3 /*-
    4  * SPDX-License-Identifier: BSD-4-Clause
    5  *
    6  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
    7  * All rights reserved.
    8  *
    9  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. All advertising materials mentioning features or use of this software
   20  *    must display the following acknowledgement:
   21  *      This product includes software developed for the NetBSD Project by
   22  *      Wasabi Systems, Inc.
   23  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
   24  *    or promote products derived from this software without specific prior
   25  *    written permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
   28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
   31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   37  * POSSIBILITY OF SUCH DAMAGE.
   38  */
   39 
   40 /*
   41  * On-board device autoconfiguration support for Cavium OCTEON 1 family of
   42  * SoC devices.
   43  */
   44 
   45 #include <sys/cdefs.h>
   46 __FBSDID("$FreeBSD$");
   47 
   48 #include <sys/param.h>
   49 #include <sys/systm.h>
   50 #include <sys/bus.h>
   51 #include <sys/kernel.h>
   52 #include <sys/module.h>
   53 #include <sys/rman.h>
   54 #include <sys/malloc.h>
   55 
   56 #include <machine/bus.h>
   57 
   58 #include <mips/cavium/octeon_pcmap_regs.h>
   59 #include <mips/cavium/obiovar.h>
   60 
   61 #include <contrib/octeon-sdk/cvmx.h>
   62 #include <mips/cavium/octeon_irq.h>
   63 
   64 extern struct bus_space octeon_uart_tag;
   65 
   66 static void     obio_identify(driver_t *, device_t);
   67 static int      obio_probe(device_t);
   68 static int      obio_attach(device_t);
   69 
   70 static void
   71 obio_identify(driver_t *drv, device_t parent)
   72 {
   73         BUS_ADD_CHILD(parent, 0, "obio", 0);
   74 }
   75 
   76 static int
   77 obio_probe(device_t dev)
   78 {
   79         if (device_get_unit(dev) != 0)
   80                 return (ENXIO);
   81         return (0);
   82 }
   83 
   84 static int
   85 obio_attach(device_t dev)
   86 {
   87         struct obio_softc *sc = device_get_softc(dev);
   88 
   89         sc->oba_st = mips_bus_space_generic;
   90         /*
   91          * XXX
   92          * Here and elsewhere using RBR as a base address because it kind of
   93          * is, but that feels pretty sloppy.  Should consider adding a define
   94          * that's more semantic, at least.
   95          */
   96         sc->oba_addr = CVMX_MIO_UARTX_RBR(0);
   97         sc->oba_size = 0x10000;
   98         sc->oba_rman.rm_type = RMAN_ARRAY;
   99         sc->oba_rman.rm_descr = "OBIO I/O";
  100         if (rman_init(&sc->oba_rman) != 0 ||
  101             rman_manage_region(&sc->oba_rman,
  102             sc->oba_addr, sc->oba_addr + sc->oba_size) != 0)
  103                 panic("obio_attach: failed to set up I/O rman");
  104         sc->oba_irq_rman.rm_type = RMAN_ARRAY;
  105         sc->oba_irq_rman.rm_descr = "OBIO IRQ";
  106 
  107         /* 
  108          * This module is intended for UART purposes only and
  109          * manages IRQs for UART0 and UART1.
  110          */
  111         if (rman_init(&sc->oba_irq_rman) != 0 ||
  112             rman_manage_region(&sc->oba_irq_rman, OCTEON_IRQ_UART0, OCTEON_IRQ_UART1) != 0)
  113                 panic("obio_attach: failed to set up IRQ rman");
  114 
  115         device_add_child(dev, "uart", 1);  /* Setup Uart-1 first. */
  116         device_add_child(dev, "uart", 0);  /* Uart-0 next. So it is first in console list */
  117         bus_generic_probe(dev);
  118         bus_generic_attach(dev);
  119         return (0);
  120 }
  121 
  122 static struct resource *
  123 obio_alloc_resource(device_t bus, device_t child, int type, int *rid,
  124     rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
  125 {
  126         struct resource *rv;
  127         struct rman *rm;
  128         bus_space_tag_t bt = 0;
  129         bus_space_handle_t bh = 0;
  130         struct obio_softc *sc = device_get_softc(bus);
  131 
  132         switch (type) {
  133         case SYS_RES_IRQ:
  134                 switch (device_get_unit(child)) {
  135                 case 0:
  136                         start = end = OCTEON_IRQ_UART0;
  137                         break;
  138                 case 1:
  139                         start = end = OCTEON_IRQ_UART1;
  140                         break;
  141                 default:
  142                         return (NULL);
  143                 }
  144                 rm = &sc->oba_irq_rman;
  145                 break;
  146         case SYS_RES_MEMORY:
  147                 return (NULL);
  148         case SYS_RES_IOPORT:
  149                 rm = &sc->oba_rman;
  150                 bt = &octeon_uart_tag;
  151                 bh = CVMX_MIO_UARTX_RBR(device_get_unit(child));
  152                 start = bh;
  153                 break;
  154         default:
  155                 return (NULL);
  156         }
  157 
  158         rv = rman_reserve_resource(rm, start, end, count, flags, child);
  159         if (rv == NULL)  {
  160                 return (NULL);
  161         }
  162         if (type == SYS_RES_IRQ) {
  163                 return (rv);
  164         }
  165         rman_set_rid(rv, *rid);
  166         rman_set_bustag(rv, bt);
  167         rman_set_bushandle(rv, bh);
  168 
  169         if (0) {
  170                 if (bus_activate_resource(child, type, *rid, rv)) {
  171                         rman_release_resource(rv);
  172                         return (NULL);
  173                 }
  174         }
  175         return (rv);
  176 
  177 }
  178 
  179 static int
  180 obio_activate_resource(device_t bus, device_t child, int type, int rid,
  181     struct resource *r)
  182 {
  183         return (0);
  184 }
  185 static device_method_t obio_methods[] = {
  186         /* Device methods */
  187         DEVMETHOD(device_identify,      obio_identify),
  188         DEVMETHOD(device_probe,         obio_probe),
  189         DEVMETHOD(device_attach,        obio_attach),
  190 
  191         /* Bus methods */
  192         DEVMETHOD(bus_alloc_resource,   obio_alloc_resource),
  193         DEVMETHOD(bus_activate_resource,obio_activate_resource),
  194         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
  195         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
  196 
  197         DEVMETHOD(bus_add_child,        bus_generic_add_child),
  198 
  199         {0, 0},
  200 };
  201 
  202 static driver_t obio_driver = {
  203         "obio",
  204         obio_methods,
  205         sizeof(struct obio_softc),
  206 };
  207 static devclass_t obio_devclass;
  208 
  209 DRIVER_MODULE(obio, ciu, obio_driver, obio_devclass, 0, 0);

Cache object: 1b6dc54f46d8f029ef6209f93b6ce35e


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