Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:07

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSImplClassicIntr
0007  *
0008  * @brief This source file contains the implementation of
0009  *   rtems_interrupt_get_affinity() and rtems_interrupt_set_affinity().
0010  */
0011 
0012 /*
0013  * Copyright (C) 2017, 2022 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <bsp/irq-generic.h>
0038 
0039 #include <rtems/score/smpimpl.h>
0040 
0041 rtems_status_code rtems_interrupt_set_affinity(
0042   rtems_vector_number  vector,
0043   size_t               affinity_size,
0044   const cpu_set_t     *affinity
0045 )
0046 {
0047   Processor_mask             set;
0048   Processor_mask_Copy_status status;
0049 
0050   if ( affinity == NULL ) {
0051     return RTEMS_INVALID_ADDRESS;
0052   }
0053 
0054   if ( !bsp_interrupt_is_valid_vector( vector ) ) {
0055     return RTEMS_INVALID_ID;
0056   }
0057 
0058   status = _Processor_mask_From_cpu_set_t( &set, affinity_size, affinity );
0059   if ( !_Processor_mask_Is_at_most_partial_loss( status ) ) {
0060     return RTEMS_INVALID_NUMBER;
0061   }
0062 
0063   _Processor_mask_And( &set, _SMP_Get_online_processors(), &set );
0064   if ( _Processor_mask_Is_zero( &set ) ) {
0065     return RTEMS_INVALID_NUMBER;
0066   }
0067 
0068 #if defined(BSP_IRQ_HAVE_GET_SET_AFFINITY)
0069   return bsp_interrupt_set_affinity( vector, &set );
0070 #else
0071   return RTEMS_SUCCESSFUL;
0072 #endif
0073 }
0074 
0075 rtems_status_code rtems_interrupt_get_affinity(
0076   rtems_vector_number  vector,
0077   size_t               affinity_size,
0078   cpu_set_t           *affinity
0079 )
0080 {
0081   rtems_status_code          sc;
0082   Processor_mask             set;
0083   Processor_mask_Copy_status status;
0084 
0085   if ( affinity == NULL ) {
0086     return RTEMS_INVALID_ADDRESS;
0087   }
0088 
0089   _Processor_mask_Zero( &set );
0090 
0091   if ( bsp_interrupt_is_valid_vector( vector ) ) {
0092 #if defined(BSP_IRQ_HAVE_GET_SET_AFFINITY)
0093     sc = bsp_interrupt_get_affinity( vector, &set );
0094 #else
0095     _Processor_mask_From_index( &set, 0 );
0096     sc = RTEMS_SUCCESSFUL;
0097 #endif
0098   } else {
0099     sc = RTEMS_INVALID_ID;
0100   }
0101 
0102   status = _Processor_mask_To_cpu_set_t( &set, affinity_size, affinity );
0103   if ( sc == RTEMS_SUCCESSFUL && status != PROCESSOR_MASK_COPY_LOSSLESS ) {
0104     return RTEMS_INVALID_SIZE;
0105   }
0106 
0107   return sc;
0108 }