1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/machine/platform.h>
6 #ifdef METAL_SIFIVE_GLOBAL_EXTERNAL_INTERRUPTS0
9 #include <metal/shutdown.h>
10 #include <metal/drivers/sifive_global-external-interrupts0.h>
11 #include <metal/machine.h>
13 void __metal_driver_sifive_global_external_interrupt_init(struct metal_interrupt *controller)
15 struct __metal_driver_sifive_global_external_interrupts0 *global0;
17 global0 = (struct __metal_driver_sifive_global_external_interrupts0 *)(controller);
18 if ( !global0->init_done ) {
19 struct metal_interrupt *intc =
20 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
23 intc->vtable->interrupt_init(intc);
24 /* Register its interrupts with with parent controller */
26 i < __metal_driver_sifive_global_external_interrupts0_num_interrupts(controller);
28 intc->vtable->interrupt_register(intc,
29 __metal_driver_sifive_global_external_interrupts0_interrupt_lines(controller, i),
32 global0->init_done = 1;
37 int __metal_driver_sifive_global_external_interrupt_register(struct metal_interrupt *controller,
38 int id, metal_interrupt_handler_t isr,
44 struct metal_interrupt *intc =
45 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
47 /* Enable its interrupts with parent controller */
49 rc = intc->vtable->interrupt_register(intc, id, isr, priv);
55 int __metal_driver_sifive_global_external_interrupt_enable(struct metal_interrupt *controller, int id)
60 struct metal_interrupt *intc =
61 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
63 /* Enable its interrupts with parent controller */
65 rc = intc->vtable->interrupt_enable(intc, id);
71 int __metal_driver_sifive_global_external_interrupt_disable(struct metal_interrupt *controller, int id)
76 struct metal_interrupt *intc =
77 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
79 /* Enable its interrupts with parent controller */
81 rc = intc->vtable->interrupt_disable(intc, id);
87 int __metal_driver_sifive_global_external_interrupt_set_threshold(struct metal_interrupt *controller,
88 unsigned int threshold)
90 struct metal_interrupt *intc =
91 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
93 return intc->vtable->interrupt_set_threshold(intc, threshold);
98 unsigned int __metal_driver_sifive_global_external_interrupt_get_threshold(struct metal_interrupt *controller)
100 struct metal_interrupt *intc =
101 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
104 return intc->vtable->interrupt_get_threshold(intc);
109 int __metal_driver_sifive_global_external_interrupt_set_priority(struct metal_interrupt *controller,
110 int id, unsigned int priority)
112 struct metal_interrupt *intc =
113 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
115 return intc->vtable->interrupt_set_priority(intc, id, priority);
120 unsigned int __metal_driver_sifive_global_external_interrupt_get_priority(struct metal_interrupt *controller, int id)
122 struct metal_interrupt *intc =
123 __metal_driver_sifive_global_external_interrupts0_interrupt_parent(controller);
126 return intc->vtable->interrupt_get_priority(intc, id);
131 int __metal_driver_sifive_global_external_command_request (struct metal_interrupt *controller,
132 int command, void *data)
138 case METAL_MAX_INTERRUPT_GET:
139 rc = __metal_driver_sifive_global_external_interrupts0_num_interrupts(controller);
141 case METAL_INDEX_INTERRUPT_GET:
145 rc = __metal_driver_sifive_global_external_interrupts0_interrupt_lines(controller, idx);
155 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_global_external_interrupts0) = {
156 .global0_vtable.interrupt_init = __metal_driver_sifive_global_external_interrupt_init,
157 .global0_vtable.interrupt_register = __metal_driver_sifive_global_external_interrupt_register,
158 .global0_vtable.interrupt_enable = __metal_driver_sifive_global_external_interrupt_enable,
159 .global0_vtable.interrupt_disable = __metal_driver_sifive_global_external_interrupt_disable,
160 .global0_vtable.interrupt_get_threshold = __metal_driver_sifive_global_external_interrupt_get_threshold,
161 .global0_vtable.interrupt_set_threshold = __metal_driver_sifive_global_external_interrupt_set_threshold,
162 .global0_vtable.interrupt_get_priority = __metal_driver_sifive_global_external_interrupt_get_priority,
163 .global0_vtable.interrupt_set_priority = __metal_driver_sifive_global_external_interrupt_set_priority,
164 .global0_vtable.command_request = __metal_driver_sifive_global_external_command_request,
169 typedef int no_empty_translation_units;