source: rtems/bsps/riscv/griscv/irq/irq.c @ c7b4eca7

Last change on this file since c7b4eca7 was c7b4eca7, checked in by Sebastian Huber <sebastian.huber@…>, on 07/27/21 at 07:58:43

bsps/irq: bsp_interrupt_facility_initialize()

Do not return a status code in bsp_interrupt_facility_initialize() since this
leads to unreachable code in bsp_interrupt_initialize(). Use RTEMS_DEBUG
assertions in bsp_interrupt_facility_initialize() if necessary.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup riscv_interrupt
5 *
6 * @brief Interrupt support.
7 */
8
9/*
10 * Copyright (c) 2018 embedded brains GmbH
11 *
12 * Copyright (c) 2015 University of York.
13 * Hesham Almatary <hesham@alumni.york.ac.uk>
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <bsp/irq.h>
38#include <bsp/fatal.h>
39#include <bsp/irq-generic.h>
40#include <amba.h>
41
42#include <rtems/score/percpu.h>
43#include <rtems/score/riscv-utility.h>
44#include <rtems/score/smpimpl.h>
45
46#if defined(RTEMS_SMP)
47/* Interrupt to CPU map. Default to CPU0 since in BSS. */
48const unsigned char GRLIB_irq_to_cpu[32] __attribute__((weak));
49
50/* On SMP use map table above relative to SMP Boot CPU (normally CPU0) */
51static inline int bsp_irq_cpu(int irq)
52{
53  /* protect from bad user configuration, default to boot cpu */
54  if (rtems_configuration_get_maximum_processors() <= GRLIB_irq_to_cpu[irq])
55    return GRLIB_Cpu_Index;
56  else
57    return GRLIB_Cpu_Index + GRLIB_irq_to_cpu[irq];
58}
59#else
60/* when not SMP the local CPU is returned */
61static inline int bsp_irq_cpu(int irq)
62{
63  return read_csr(mhartid);
64}
65#endif
66
67void _RISCV_Interrupt_dispatch(uintptr_t mcause, Per_CPU_Control *cpu_self)
68{
69  if (mcause & 0x80000000) {
70
71    bsp_interrupt_handler_dispatch(mcause & 0xf);
72
73  } else {
74    bsp_fatal(RISCV_FATAL_UNEXPECTED_INTERRUPT_EXCEPTION);
75  }
76}
77
78void bsp_interrupt_facility_initialize(void)
79{
80
81  /*
82   * External M-mode interrupts on secondary processors are enabled in
83   * bsp_start_on_secondary_processor().
84   */
85  set_csr(mie, MIP_MEIP);
86}
87
88rtems_status_code bsp_interrupt_get_attributes(
89  rtems_vector_number         vector,
90  rtems_interrupt_attributes *attributes
91)
92{
93  return RTEMS_SUCCESSFUL;
94}
95
96rtems_status_code bsp_interrupt_is_pending(
97  rtems_vector_number vector,
98  bool               *pending
99)
100{
101  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
102  bsp_interrupt_assert(pending != NULL);
103  *pending = false;
104  return RTEMS_UNSATISFIED;
105}
106
107rtems_status_code bsp_interrupt_raise(rtems_vector_number vector)
108{
109  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
110  return RTEMS_UNSATISFIED;
111}
112
113#if defined(RTEMS_SMP)
114rtems_status_code bsp_interrupt_raise_on(
115  rtems_vector_number vector,
116  uint32_t            cpu_index
117)
118{
119  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
120  return RTEMS_UNSATISFIED;
121}
122#endif
123
124rtems_status_code bsp_interrupt_clear(rtems_vector_number vector)
125{
126  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
127  return RTEMS_UNSATISFIED;
128}
129
130rtems_status_code bsp_interrupt_vector_is_enabled(
131  rtems_vector_number vector,
132  bool               *enabled
133)
134{
135  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
136  bsp_interrupt_assert(enabled != NULL);
137  *enabled = false;
138  return RTEMS_UNSATISFIED;
139}
140
141rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)
142{
143  int irq = (int)vector;
144  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
145  GRLIB_Cpu_Unmask_interrupt(irq, bsp_irq_cpu(irq));
146  return RTEMS_SUCCESSFUL;
147}
148
149rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)
150{
151  int irq = (int)vector;
152  bsp_interrupt_assert(bsp_interrupt_is_valid_vector(vector));
153  GRLIB_Cpu_Mask_interrupt(irq, bsp_irq_cpu(irq));
154  return RTEMS_SUCCESSFUL;
155}
156
157rtems_status_code bsp_interrupt_get_affinity(
158  rtems_vector_number vector,
159  Processor_mask *affinity
160)
161{
162  uint32_t cpu_count = rtems_scheduler_get_processor_maximum();
163  uint32_t cpu_index;
164
165  _Processor_mask_Zero(affinity);
166
167  for (cpu_index = 0; cpu_index < cpu_count; ++cpu_index) {
168    if (!BSP_Cpu_Is_interrupt_masked(vector, cpu_index)) {
169      _Processor_mask_Set(affinity, cpu_index);
170    }
171  }
172
173  return RTEMS_SUCCESSFUL;
174}
175
176rtems_status_code bsp_interrupt_set_affinity(
177  rtems_vector_number vector,
178  const Processor_mask *affinity
179)
180{
181  uint32_t unmasked = 0;
182  uint32_t cpu_count = rtems_scheduler_get_processor_maximum();
183  uint32_t cpu_index;
184
185  for (cpu_index = 0; cpu_index < cpu_count; ++cpu_index) {
186    if (_Processor_mask_Is_set(affinity, cpu_index)) {
187      GRLIB_Cpu_Unmask_interrupt(vector, cpu_index);
188      ++unmasked;
189    }
190  }
191
192  if (unmasked > 1) {
193    GRLIB_Enable_interrupt_broadcast(vector);
194  } else {
195    GRLIB_Disable_interrupt_broadcast(vector);
196  }
197
198  return RTEMS_SUCCESSFUL;
199}
Note: See TracBrowser for help on using the repository browser.