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_command_request (struct metal_interrupt *controller,
88 int command, void *data)
94 case METAL_MAX_INTERRUPT_GET:
95 rc = __metal_driver_sifive_global_external_interrupts0_num_interrupts(controller);
97 case METAL_INDEX_INTERRUPT_GET:
101 rc = __metal_driver_sifive_global_external_interrupts0_interrupt_lines(controller, idx);
111 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_global_external_interrupts0) = {
112 .global0_vtable.interrupt_init = __metal_driver_sifive_global_external_interrupt_init,
113 .global0_vtable.interrupt_register = __metal_driver_sifive_global_external_interrupt_register,
114 .global0_vtable.interrupt_enable = __metal_driver_sifive_global_external_interrupt_enable,
115 .global0_vtable.interrupt_disable = __metal_driver_sifive_global_external_interrupt_disable,
116 .global0_vtable.command_request = __metal_driver_sifive_global_external_command_request,