Changeset d3b840b8 in rtems


Ignore:
Timestamp:
Dec 3, 2007, 10:39:46 PM (13 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.9, master
Children:
8dc42d3
Parents:
2ae35c2
Message:

2007-12-03 Joel Sherrill <joel.sherrill@…>

  • shared/irq/irq.c: Spacing.
Location:
c/src/lib/libbsp/powerpc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/powerpc/ChangeLog

    r2ae35c2 rd3b840b8  
     12007-12-03      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * shared/irq/irq.c: Spacing.
     4
    152007-12-03      Joel Sherrill <joel.sherrill@OARcorp.com>
    26
  • c/src/lib/libbsp/powerpc/shared/irq/irq.c

    r2ae35c2 rd3b840b8  
    11/*
    22 *
    3  *  This file contains the PIC-independent implementation of the functions described in irq.h
     3 *  This file contains the PIC-independent implementation of the
     4 *  functions described in irq.h
    45 *
    56 *  Copyright (C) 1998, 1999 valette@crf.canon.fr
     
    3233 * default handler connected on each irq after bsp initialization
    3334 */
    34 static rtems_irq_connect_data   default_rtems_entry;
     35static rtems_irq_connect_data  default_rtems_entry;
    3536
    3637/*
     
    3839 * management.
    3940 */
    40 static rtems_irq_global_settings*       internal_config;
    41 static rtems_irq_connect_data*          rtems_hdl_tbl;
     41static rtems_irq_global_settings*   internal_config;
     42static rtems_irq_connect_data*    rtems_hdl_tbl;
    4243
    4344/*
     
    5253static int isValidInterrupt(int irq)
    5354{
    54   if ( (irq < internal_config->irqBase) || (irq >= internal_config->irqBase + internal_config->irqNb))
    55     return 0;
    56   return 1;
    57 }
    58 
    59 /*
    60  * ------------------------ RTEMS Shared Irq Handler Mngt Routines ----------------
     55  if ( (irq < internal_config->irqBase) ||
     56       (irq >= internal_config->irqBase + internal_config->irqNb))
     57    return 0;
     58  return 1;
     59}
     60
     61/*
     62 * ------------------- RTEMS Shared Irq Handler Mngt Routines ------------
    6163 */
    6264int BSP_install_rtems_shared_irq_handler  (const rtems_irq_connect_data* irq)
    6365{
    64     rtems_interrupt_level   level;
    65     rtems_irq_connect_data* vchain;
    66 
    67     if (!isValidInterrupt(irq->name)) {
    68       printk("Invalid interrupt vector %d\n",irq->name);
     66  rtems_interrupt_level   level;
     67  rtems_irq_connect_data* vchain;
     68
     69  if (!isValidInterrupt(irq->name)) {
     70    printk("Invalid interrupt vector %d\n",irq->name);
     71    return 0;
     72  }
     73
     74  rtems_interrupt_disable(level);
     75
     76  if ( (int)rtems_hdl_tbl[irq->name].next_handler  == -1 ) {
     77    rtems_interrupt_enable(level);
     78    printk(
     79      "IRQ vector %d already connected to an unshared handler\n",
     80      irq->name
     81    );
     82    return 0;
     83  }
     84
     85   vchain = (rtems_irq_connect_data*)malloc(sizeof(rtems_irq_connect_data));
     86
     87  /* save off topmost handler */
     88  vchain[0]= rtems_hdl_tbl[irq->name];
     89
     90  /*
     91   * store the data provided by user
     92   */
     93  rtems_hdl_tbl[irq->name] = *irq;
     94
     95  /* link chain to new topmost handler */
     96  rtems_hdl_tbl[irq->name].next_handler = (void *)vchain;
     97
     98  /*
     99   * enable_irq_at_pic is supposed to ignore
     100   * requests to disable interrupts outside
     101   * of the range handled by the PIC
     102   */
     103  BSP_enable_irq_at_pic(irq->name);
     104
     105  /*
     106   * Enable interrupt on device
     107   */
     108  if (irq->on)
     109    irq->on(irq);
     110
     111  rtems_interrupt_enable(level);
     112
     113  return 1;
     114}
     115
     116/*
     117 * ------------------- RTEMS Single Irq Handler Mngt Routines ------------
     118 */
     119
     120int BSP_install_rtems_irq_handler  (const rtems_irq_connect_data* irq)
     121{
     122  rtems_interrupt_level  level;
     123
     124  if (!isValidInterrupt(irq->name)) {
     125    printk("Invalid interrupt vector %d\n",irq->name);
     126    return 0;
     127  }
     128  /*
     129   * Check if default handler is actually connected. If not issue an error.
     130   * You must first get the current handler via i386_get_current_idt_entry
     131   * and then disconnect it using i386_delete_idt_entry.
     132   * RATIONALE : to always have the same transition by forcing the user
     133   * to get the previous handler before accepting to disconnect.
     134   */
     135  rtems_interrupt_disable(level);
     136  if (rtems_hdl_tbl[irq->name].hdl != default_rtems_entry.hdl) {
     137    rtems_interrupt_enable(level);
     138    printk("IRQ vector %d already connected\n",irq->name);
     139    return 0;
     140  }
     141
     142  /*
     143   * store the data provided by user
     144   */
     145  rtems_hdl_tbl[irq->name] = *irq;
     146  rtems_hdl_tbl[irq->name].next_handler = (void *)-1;
     147
     148  /*
     149   * enable_irq_at_pic is supposed to ignore
     150   * requests to disable interrupts outside
     151   * of the range handled by the PIC
     152   */
     153  BSP_enable_irq_at_pic(irq->name);
     154
     155  /*
     156   * Enable interrupt on device
     157   */
     158  if (irq->on)
     159    irq->on(irq);
     160
     161  rtems_interrupt_enable(level);
     162
     163  return 1;
     164}
     165
     166int BSP_get_current_rtems_irq_handler  (rtems_irq_connect_data* irq)
     167{
     168  rtems_interrupt_level       level;
     169
     170  if (!isValidInterrupt(irq->name)) {
     171    return 0;
     172  }
     173  rtems_interrupt_disable(level);
     174  *irq = rtems_hdl_tbl[irq->name];
     175  rtems_interrupt_enable(level);
     176  return 1;
     177}
     178
     179int BSP_remove_rtems_irq_handler  (const rtems_irq_connect_data* irq)
     180{
     181  rtems_irq_connect_data *pchain= NULL, *vchain = NULL;
     182  rtems_interrupt_level   level;
     183
     184  if (!isValidInterrupt(irq->name)) {
     185    return 0;
     186  }
     187  /*
     188   * Check if default handler is actually connected. If not issue an error.
     189   * You must first get the current handler via i386_get_current_idt_entry
     190   * and then disconnect it using i386_delete_idt_entry.
     191   * RATIONALE : to always have the same transition by forcing the user
     192   * to get the previous handler before accepting to disconnect.
     193   */
     194  rtems_interrupt_disable(level);
     195  if (rtems_hdl_tbl[irq->name].hdl != irq->hdl) {
     196    rtems_interrupt_enable(level);
     197    return 0;
     198  }
     199
     200  if ( (int)rtems_hdl_tbl[irq->name].next_handler != -1 ) {
     201    int found = 0;
     202
     203    for( (pchain= NULL, vchain = &rtems_hdl_tbl[irq->name]);
     204         (vchain->hdl != default_rtems_entry.hdl);
     205         (pchain= vchain,
     206          vchain = (rtems_irq_connect_data*)vchain->next_handler) ) {
     207      if ( vchain->hdl == irq->hdl ) {
     208        found =  -1;
     209        break;
     210      }
     211    }
     212
     213    if ( !found ) {
     214      rtems_interrupt_enable(level);
    69215      return 0;
    70216    }
    71 
    72     rtems_interrupt_disable(level);
    73 
    74     if ( (int)rtems_hdl_tbl[irq->name].next_handler  == -1 ) {
    75       rtems_interrupt_enable(level);
    76       printk("IRQ vector %d already connected to an unshared handler\n",irq->name);
    77       return 0;
    78     }
    79 
    80      vchain = (rtems_irq_connect_data*)malloc(sizeof(rtems_irq_connect_data));
    81 
    82     /* save off topmost handler */
    83     vchain[0]= rtems_hdl_tbl[irq->name];
    84 
    85     /*
    86      * store the data provided by user
    87      */
    88     rtems_hdl_tbl[irq->name] = *irq;
    89 
    90     /* link chain to new topmost handler */
    91     rtems_hdl_tbl[irq->name].next_handler = (void *)vchain;
    92 
    93         /*
    94          * enable_irq_at_pic is supposed to ignore
    95          * requests to disable interrupts outside
    96          * of the range handled by the PIC
    97          */
    98         BSP_enable_irq_at_pic(irq->name);
    99 
    100     /*
    101      * Enable interrupt on device
    102      */
    103         if (irq->on)
    104         irq->on(irq);
    105 
    106     rtems_interrupt_enable(level);
    107 
    108     return 1;
    109 }
    110 
    111 /*
    112  * ------------------------ RTEMS Single Irq Handler Mngt Routines ----------------
    113  */
    114 
    115 int BSP_install_rtems_irq_handler  (const rtems_irq_connect_data* irq)
    116 {
    117     rtems_interrupt_level  level;
    118 
    119     if (!isValidInterrupt(irq->name)) {
    120       printk("Invalid interrupt vector %d\n",irq->name);
    121       return 0;
    122     }
    123     /*
    124      * Check if default handler is actually connected. If not issue an error.
    125      * You must first get the current handler via i386_get_current_idt_entry
    126      * and then disconnect it using i386_delete_idt_entry.
    127      * RATIONALE : to always have the same transition by forcing the user
    128      * to get the previous handler before accepting to disconnect.
    129      */
    130     rtems_interrupt_disable(level);
    131     if (rtems_hdl_tbl[irq->name].hdl != default_rtems_entry.hdl) {
    132       rtems_interrupt_enable(level);
    133       printk("IRQ vector %d already connected\n",irq->name);
    134       return 0;
    135     }
    136 
    137     /*
    138      * store the data provided by user
    139      */
    140     rtems_hdl_tbl[irq->name] = *irq;
    141     rtems_hdl_tbl[irq->name].next_handler = (void *)-1;
    142 
    143         /*
    144          * enable_irq_at_pic is supposed to ignore
    145          * requests to disable interrupts outside
    146          * of the range handled by the PIC
    147          */
    148         BSP_enable_irq_at_pic(irq->name);
    149 
    150     /*
    151      * Enable interrupt on device
    152      */
    153         if (irq->on)
    154         irq->on(irq);
    155 
    156     rtems_interrupt_enable(level);
    157 
    158     return 1;
    159 }
    160 
    161 int BSP_get_current_rtems_irq_handler   (rtems_irq_connect_data* irq)
    162 {
    163     rtems_interrupt_level       level;
    164 
    165     if (!isValidInterrupt(irq->name)) {
    166       return 0;
    167     }
    168     rtems_interrupt_disable(level);
    169       *irq = rtems_hdl_tbl[irq->name];
    170     rtems_interrupt_enable(level);
    171     return 1;
    172 }
    173 
    174 int BSP_remove_rtems_irq_handler  (const rtems_irq_connect_data* irq)
    175 {
    176     rtems_irq_connect_data *pchain= NULL, *vchain = NULL;
    177     rtems_interrupt_level   level;
    178 
    179     if (!isValidInterrupt(irq->name)) {
    180       return 0;
    181     }
    182     /*
    183      * Check if default handler is actually connected. If not issue an error.
    184      * You must first get the current handler via i386_get_current_idt_entry
    185      * and then disconnect it using i386_delete_idt_entry.
    186      * RATIONALE : to always have the same transition by forcing the user
    187      * to get the previous handler before accepting to disconnect.
    188      */
    189     rtems_interrupt_disable(level);
     217  } else {
    190218    if (rtems_hdl_tbl[irq->name].hdl != irq->hdl) {
    191219      rtems_interrupt_enable(level);
    192220      return 0;
    193221    }
    194 
    195     if( (int)rtems_hdl_tbl[irq->name].next_handler != -1 )
    196     {
    197        int found = 0;
    198 
    199        for( (pchain= NULL, vchain = &rtems_hdl_tbl[irq->name]);
    200             (vchain->hdl != default_rtems_entry.hdl);
    201             (pchain= vchain, vchain = (rtems_irq_connect_data*)vchain->next_handler) )
    202        {
    203           if( vchain->hdl == irq->hdl )
    204           {
    205              found= -1; break;
    206           }
    207        }
    208 
    209        if( !found )
    210        {
    211           rtems_interrupt_enable(level);
    212           return 0;
    213        }
    214     }
    215     else
    216     {
    217        if (rtems_hdl_tbl[irq->name].hdl != irq->hdl)
    218        {
    219           rtems_interrupt_enable(level);
    220          return 0;
    221        }
    222     }
    223 
    224         /*
    225          * disable_irq_at_pic is supposed to ignore
    226          * requests to disable interrupts outside
    227          * of the range handled by the PIC
    228          */
    229         BSP_disable_irq_at_pic(irq->name);
    230 
    231     /*
    232      * Disable interrupt on device
    233      */
    234         if (irq->off)
    235         irq->off(irq);
    236 
    237     /*
    238      * restore the default irq value
    239      */
    240     if( !vchain )
    241     {
    242        /* single handler vector... */
    243        rtems_hdl_tbl[irq->name] = default_rtems_entry;
    244     }
    245     else
    246     {
    247        if( pchain )
    248        {
    249           /* non-first handler being removed */
    250           pchain->next_handler = vchain->next_handler;
    251        }
    252        else
    253        {
    254           /* first handler isn't malloc'ed, so just overwrite it.  Since
    255           the contents of vchain are being struct copied, vchain itself
    256           goes away */
    257           vchain = vchain->next_handler;
    258           rtems_hdl_tbl[irq->name]= *vchain;
    259        }
    260        free(vchain);
    261     }
     222  }
     223
     224  /*
     225   * disable_irq_at_pic is supposed to ignore
     226   * requests to disable interrupts outside
     227   * of the range handled by the PIC
     228   */
     229  BSP_disable_irq_at_pic(irq->name);
     230
     231  /*
     232   * Disable interrupt on device
     233   */
     234  if (irq->off)
     235    irq->off(irq);
     236
     237  /*
     238   * restore the default irq value
     239   */
     240  if( !vchain ) {
     241     /* single handler vector... */
     242     rtems_hdl_tbl[irq->name] = default_rtems_entry;
     243  } else {
     244    if ( pchain ) {
     245       /* non-first handler being removed */
     246       pchain->next_handler = vchain->next_handler;
     247    } else {
     248       /* first handler isn't malloc'ed, so just overwrite it.  Since
     249        * the contents of vchain are being struct copied, vchain itself
     250        * goes away
     251        */
     252       vchain = vchain->next_handler;
     253       rtems_hdl_tbl[irq->name]= *vchain;
     254    }
     255    free(vchain);
     256  }
     257
     258  rtems_interrupt_enable(level);
     259
     260  return 1;
     261}
     262
     263/*
     264 * RTEMS Global Interrupt Handler Management Routines
     265 */
     266
     267int BSP_rtems_irq_mngt_set(rtems_irq_global_settings* config)
     268{
     269  int                           i;
     270  rtems_interrupt_level         level;
     271  rtems_irq_connect_data*       vchain;
     272  rtems_raw_except_connect_data vectorDesc;
     273
     274  /*
     275   * Store various code accelerators
     276   */
     277  internal_config     = config;
     278  default_rtems_entry   = config->defaultEntry;
     279  rtems_hdl_tbl     = config->irqHdlTbl;
     280
     281  rtems_interrupt_disable(level);
     282
     283  if ( !BSP_setup_the_pic(config) ) {
     284    printk("PIC setup failed; leaving IRQs OFF\n");
     285    return 0;
     286  }
     287
     288  for ( i = config->irqBase; i < config->irqBase + config->irqNb; i++ ) {
     289    for( vchain = &rtems_hdl_tbl[i];
     290         ((int)vchain != -1 && vchain->hdl != default_rtems_entry.hdl);
     291         vchain = (rtems_irq_connect_data*)vchain->next_handler ) {
     292      if (vchain->on)
     293        vchain->on(vchain);
     294    }
     295  }
    262296
    263297    rtems_interrupt_enable(level);
    264298
    265     return 1;
    266 }
    267 
    268 /*
    269  * RTEMS Global Interrupt Handler Management Routines
    270  */
    271 
    272 int BSP_rtems_irq_mngt_set(rtems_irq_global_settings* config)
    273 {
    274     int                           i;
    275     rtems_interrupt_level         level;
    276     rtems_irq_connect_data*       vchain;
    277     rtems_raw_except_connect_data vectorDesc;
    278 
    279     /*
    280      * Store various code accelerators
    281      */
    282     internal_config             = config;
    283     default_rtems_entry         = config->defaultEntry;
    284     rtems_hdl_tbl               = config->irqHdlTbl;
    285 
    286     rtems_interrupt_disable(level);
    287 
    288         if ( !BSP_setup_the_pic(config) ) {
    289                 printk("PIC setup failed; leaving IRQs OFF\n");
    290                 return 0;
    291         }
    292 
    293         for ( i = config->irqBase; i < config->irqBase + config->irqNb; i++ ) {
    294                 for( vchain = &rtems_hdl_tbl[i];
    295                      ((int)vchain != -1 && vchain->hdl != default_rtems_entry.hdl);
    296                      vchain = (rtems_irq_connect_data*)vchain->next_handler )
    297                 {
    298                         if (vchain->on)
    299               vchain->on(vchain);
    300                 }
    301         }
    302 
    303     rtems_interrupt_enable(level);
    304 
    305         /*
    306          * We must connect the raw irq handler for the two
    307          * expected interrupt sources : decrementer and external interrupts.
    308          */
    309     vectorDesc.exceptIndex      =       ASM_DEC_VECTOR;
    310     vectorDesc.hdl.vector       =       ASM_DEC_VECTOR;
    311     vectorDesc.hdl.raw_hdl      =       decrementer_exception_vector_prolog_code;
    312     vectorDesc.hdl.raw_hdl_size =       (unsigned) decrementer_exception_vector_prolog_code_size;
    313     vectorDesc.on               =       0;
    314     vectorDesc.off              =       0;
    315     vectorDesc.isOn             =       0;
    316     if (!ppc_set_exception (&vectorDesc)) {
    317       BSP_panic("Unable to initialize RTEMS decrementer raw exception\n");
    318     }
    319     vectorDesc.exceptIndex      =       ASM_EXT_VECTOR;
    320     vectorDesc.hdl.vector       =       ASM_EXT_VECTOR;
    321     vectorDesc.hdl.raw_hdl      =       external_exception_vector_prolog_code;
    322     vectorDesc.hdl.raw_hdl_size =       (unsigned) external_exception_vector_prolog_code_size;
    323     if (!ppc_set_exception (&vectorDesc)) {
    324       BSP_panic("Unable to initialize RTEMS external raw exception\n");
    325     }
    326     return 1;
     299  /*
     300   * We must connect the raw irq handler for the two
     301   * expected interrupt sources : decrementer and external interrupts.
     302   */
     303  vectorDesc.exceptIndex       =  ASM_DEC_VECTOR;
     304  vectorDesc.hdl.vector        =  ASM_DEC_VECTOR;
     305  vectorDesc.hdl.raw_hdl       =  decrementer_exception_vector_prolog_code;
     306  vectorDesc.hdl.raw_hdl_size  =
     307       (unsigned) decrementer_exception_vector_prolog_code_size;
     308  vectorDesc.on     =  0;
     309  vectorDesc.off    =  0;
     310  vectorDesc.isOn   =  0;
     311  if (!ppc_set_exception (&vectorDesc)) {
     312    BSP_panic("Unable to initialize RTEMS decrementer raw exception\n");
     313  }
     314
     315  vectorDesc.exceptIndex       =  ASM_EXT_VECTOR;
     316  vectorDesc.hdl.vector        =  ASM_EXT_VECTOR;
     317  vectorDesc.hdl.raw_hdl       =  external_exception_vector_prolog_code;
     318  vectorDesc.hdl.raw_hdl_size  =
     319       (unsigned) external_exception_vector_prolog_code_size;
     320  if (!ppc_set_exception (&vectorDesc)) {
     321    BSP_panic("Unable to initialize RTEMS external raw exception\n");
     322  }
     323  return 1;
    327324}
    328325
    329326int BSP_rtems_irq_mngt_get(rtems_irq_global_settings** config)
    330327{
    331     *config = internal_config;
    332     return 0;
     328  *config = internal_config;
     329  return 0;
    333330}
    334331
Note: See TracChangeset for help on using the changeset viewer.