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/twa/tw_osl_inline.h

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) 2004-07 Applied Micro Circuits Corporation.
    3  * Copyright (c) 2004-05 Vinod Kashyap.
    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  *      $FreeBSD: releng/9.2/sys/dev/twa/tw_osl_inline.h 208969 2010-06-09 21:40:38Z delphij $
   28  */
   29 
   30 /*
   31  * AMCC'S 3ware driver for 9000 series storage controllers.
   32  *
   33  * Author: Vinod Kashyap
   34  * Modifications by: Adam Radford
   35  */
   36 
   37 
   38 
   39 #ifndef TW_OSL_INLINE_H
   40 
   41 #define TW_OSL_INLINE_H
   42 
   43 
   44 /*
   45  * Inline functions shared between OSL and CL, and defined by OSL.
   46  */
   47 
   48 
   49 #include <dev/twa/tw_osl.h>
   50 
   51 
   52 
   53 /*
   54  * Function name:       tw_osl_init_lock
   55  * Description:         Initializes a lock.
   56  *
   57  * Input:               ctlr_handle     -- ptr to controller handle
   58  *                      lock_name       -- string indicating name of the lock
   59  * Output:              lock            -- ptr to handle to the initialized lock
   60  * Return value:        None
   61  */
   62 #define tw_osl_init_lock(ctlr_handle, lock_name, lock)  \
   63         mtx_init(lock, lock_name, NULL, MTX_SPIN)
   64 
   65 
   66 
   67 /*
   68  * Function name:       tw_osl_destroy_lock
   69  * Description:         Destroys a previously initialized lock.
   70  *
   71  * Input:               ctlr_handle     -- ptr to controller handle
   72  *                      lock            -- ptr to handle to the lock to be
   73  *                                              destroyed
   74  * Output:              None
   75  * Return value:        None
   76  */
   77 #define tw_osl_destroy_lock(ctlr_handle, lock)  \
   78         mtx_destroy(lock)
   79 
   80 
   81 
   82 /*
   83  * Function name:       tw_osl_get_lock
   84  * Description:         Acquires the specified lock.
   85  *
   86  * Input:               ctlr_handle     -- ptr to controller handle
   87  *                      lock            -- ptr to handle to the lock to be
   88  *                                              acquired
   89  * Output:              None
   90  * Return value:        None
   91  */
   92 #define tw_osl_get_lock(ctlr_handle, lock)      \
   93         mtx_lock_spin(lock)
   94 
   95 
   96 
   97 /*
   98  * Function name:       tw_osl_free_lock
   99  * Description:         Frees a previously acquired lock.
  100  *
  101  * Input:               ctlr_handle     -- ptr to controller handle
  102  *                      lock            -- ptr to handle to the lock to be freed
  103  * Output:              None
  104  * Return value:        None
  105  */
  106 #define tw_osl_free_lock(ctlr_handle, lock)     \
  107         mtx_unlock_spin(lock)
  108 
  109 
  110 
  111 #ifdef TW_OSL_DEBUG
  112 
  113 /*
  114  * Function name:       tw_osl_dbg_printf
  115  * Description:         Prints passed info (prefixed by ctlr name)to syslog
  116  *
  117  * Input:               ctlr_handle -- controller handle
  118  *                      fmt -- format string for the arguments to follow
  119  *                      ... -- variable number of arguments, to be printed
  120  *                              based on the fmt string
  121  * Output:              None
  122  * Return value:        Number of bytes printed
  123  */
  124 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...)                    \
  125         twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
  126 
  127 #endif /* TW_OSL_DEBUG */
  128 
  129 
  130 
  131 /*
  132  * Function name:       tw_osl_notify_event
  133  * Description:         Prints passed event info (prefixed by ctlr name)
  134  *                      to syslog
  135  *
  136  * Input:               ctlr_handle -- controller handle
  137  *                      event -- ptr to a packet describing the event/error
  138  * Output:              None
  139  * Return value:        None
  140  */
  141 #define tw_osl_notify_event(ctlr_handle, event)                         \
  142         twa_printf((ctlr_handle->osl_ctlr_ctxt),                        \
  143                 "%s: (0x%02X: 0x%04X): %s: %s\n",                       \
  144                 event->severity_str,                                    \
  145                 event->event_src,                                       \
  146                 event->aen_code,                                        \
  147                 event->parameter_data +                                 \
  148                         strlen(event->parameter_data) + 1,              \
  149                 event->parameter_data)
  150 
  151 
  152 
  153 /*
  154  * Function name:       tw_osl_read_reg
  155  * Description:         Reads a register on the controller
  156  *
  157  * Input:               ctlr_handle -- controller handle
  158  *                      offset -- offset from Base Address
  159  *                      size -- # of bytes to read
  160  * Output:              None
  161  * Return value:        Value read
  162  */
  163 #define tw_osl_read_reg         tw_osl_read_reg_inline
  164 static __inline TW_UINT32
  165 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
  166         TW_INT32 offset, TW_INT32 size)
  167 {
  168         bus_space_tag_t         bus_tag =
  169                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
  170         bus_space_handle_t      bus_handle =
  171                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
  172 
  173         if (size == 4)
  174                 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
  175                         offset));
  176         else if (size == 2)
  177                 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
  178                         offset));
  179         else
  180                 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
  181                         offset));
  182 }
  183 
  184 
  185 
  186 /*
  187  * Function name:       tw_osl_write_reg
  188  * Description:         Writes to a register on the controller
  189  *
  190  * Input:               ctlr_handle -- controller handle
  191  *                      offset -- offset from Base Address
  192  *                      value -- value to write
  193  *                      size -- # of bytes to write
  194  * Output:              None
  195  * Return value:        None
  196  */
  197 #define tw_osl_write_reg        tw_osl_write_reg_inline
  198 static __inline TW_VOID
  199 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
  200         TW_INT32 offset, TW_INT32 value, TW_INT32 size)
  201 {
  202         bus_space_tag_t         bus_tag =
  203                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
  204         bus_space_handle_t      bus_handle =
  205                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
  206 
  207         if (size == 4)
  208                 bus_space_write_4(bus_tag, bus_handle, offset, value);
  209         else if (size == 2)
  210                 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
  211         else
  212                 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
  213 }
  214 
  215 
  216 
  217 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
  218 
  219 /*
  220  * Function name:       tw_osl_read_pci_config
  221  * Description:         Reads from the PCI config space.
  222  *
  223  * Input:               sc      -- ptr to per ctlr structure
  224  *                      offset  -- register offset
  225  *                      size    -- # of bytes to be read
  226  * Output:              None
  227  * Return value:        Value read
  228  */
  229 #define tw_osl_read_pci_config(ctlr_handle, offset, size)               \
  230         pci_read_config(                                                \
  231                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
  232                 offset, size)
  233 
  234 
  235 
  236 /*
  237  * Function name:       tw_osl_write_pci_config
  238  * Description:         Writes to the PCI config space.
  239  *
  240  * Input:               sc      -- ptr to per ctlr structure
  241  *                      offset  -- register offset
  242  *                      value   -- value to write
  243  *                      size    -- # of bytes to be written
  244  * Output:              None
  245  * Return value:        None
  246  */
  247 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size)       \
  248         pci_write_config(                                               \
  249                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
  250                 offset/*PCIR_STATUS*/, value, size)
  251 
  252 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
  253 
  254 
  255 
  256 /*
  257  * Function name:       tw_osl_get_local_time
  258  * Description:         Gets the local time
  259  *
  260  * Input:               None
  261  * Output:              None
  262  * Return value:        local time
  263  */
  264 #define tw_osl_get_local_time()                                         \
  265         (time_second - utc_offset())
  266 
  267 
  268 /*
  269  * Function name:       tw_osl_delay
  270  * Description:         Spin for the specified time
  271  *
  272  * Input:               usecs -- micro-seconds to spin
  273  * Output:              None
  274  * Return value:        None
  275  */
  276 #define tw_osl_delay(usecs)     DELAY(usecs)
  277 
  278 
  279 
  280 #ifdef TW_OSL_CAN_SLEEP
  281 
  282 /*
  283  * Function name:       tw_osl_sleep
  284  * Description:         Sleep for the specified time, or until woken up
  285  *
  286  * Input:               ctlr_handle -- controller handle
  287  *                      sleep_handle -- handle to sleep on
  288  *                      timeout -- time period (in ms) to sleep
  289  * Output:              None
  290  * Return value:        0 -- successfully woken up
  291  *                      EWOULDBLOCK -- time out
  292  *                      ERESTART -- woken up by a signal
  293  */
  294 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout)                \
  295         tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
  296 
  297 
  298 
  299 /*
  300  * Function name:       tw_osl_wakeup
  301  * Description:         Wake up a sleeping process
  302  *
  303  * Input:               ctlr_handle -- controller handle
  304  *                      sleep_handle -- handle of sleeping process to be
  305                                         woken up
  306  * Output:              None
  307  * Return value:        None
  308  */
  309 #define tw_osl_wakeup(ctlr_handle, sleep_handle)                        \
  310         wakeup_one(sleep_handle)
  311 
  312 #endif /* TW_OSL_CAN_SLEEP */
  313 
  314 
  315 
  316 /* Allows setting breakpoints in the CL code for debugging purposes. */
  317 #define tw_osl_breakpoint()             breakpoint()
  318 
  319 
  320 /* Text name of current function. */
  321 #define tw_osl_cur_func()               __func__
  322 
  323 
  324 /* Copy 'size' bytes from 'src' to 'dest'. */
  325 #define tw_osl_memcpy(dest, src, size)  bcopy(src, dest, size)
  326 
  327 
  328 /* Zero 'size' bytes starting at 'addr'. */
  329 #define tw_osl_memzero                  bzero
  330 
  331 
  332 /* Standard sprintf. */
  333 #define tw_osl_sprintf                  sprintf
  334 
  335 
  336 /* Copy string 'src' to 'dest'. */
  337 #define tw_osl_strcpy                   strcpy
  338 
  339 
  340 /* Return length of string pointed at by 'str'. */
  341 #define tw_osl_strlen                   strlen
  342 
  343 
  344 /* Standard vsprintf. */
  345 #define tw_osl_vsprintf                 vsprintf
  346 
  347 
  348 
  349 #endif /* TW_OSL_INLINE_H */

Cache object: 3d40ecedc6f242e96515eb2f729bad74


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