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

Cache object: 16d33019c4e2f726b1bd409c57a2ed1c


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