1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/machine/platform.h>
6 #ifdef METAL_SIFIVE_LOCAL_EXTERNAL_INTERRUPTS0
9 #include <metal/drivers/sifive_local-external-interrupts0.h>
10 #include <metal/machine.h>
12 void __metal_driver_sifive_local_external_interrupt_init(struct metal_interrupt *controller)
14 struct __metal_driver_sifive_local_external_interrupts0 *local0;
16 local0 = (struct __metal_driver_sifive_local_external_interrupts0 *)(controller);
17 if ( !local0->init_done ) {
18 struct metal_interrupt *intc =
19 __metal_driver_sifive_local_external_interrupts0_interrupt_parent(controller);
22 /* Register its interruptswith with parent controller, aka all external to default isr */
24 i < __metal_driver_sifive_local_external_interrupts0_num_interrupts(controller);
26 intc->vtable->interrupt_register(intc,
27 __metal_driver_sifive_local_external_interrupts0_interrupt_lines(controller, i),
30 local0->init_done = 1;
35 int __metal_driver_sifive_local_external_interrupt_register(struct metal_interrupt *controller,
36 int id, metal_interrupt_handler_t isr,
42 struct metal_interrupt *intc =
43 __metal_driver_sifive_local_external_interrupts0_interrupt_parent(controller);
45 /* Enable its interrupts with parent controller */
47 rc = intc->vtable->interrupt_register(intc, id, isr, priv);
53 int __metal_driver_sifive_local_external_interrupt_enable(struct metal_interrupt *controller, int id)
58 struct metal_interrupt *intc =
59 __metal_driver_sifive_local_external_interrupts0_interrupt_parent(controller);
61 /* Enable its interrupts with parent controller */
63 rc = intc->vtable->interrupt_enable(intc, id);
69 int __metal_driver_sifive_local_external_interrupt_disable(struct metal_interrupt *controller, int id)
74 struct metal_interrupt *intc =
75 __metal_driver_sifive_local_external_interrupts0_interrupt_parent(controller);
77 /* Enable its interrupts with parent controller */
79 rc = intc->vtable->interrupt_disable(intc, id);
85 int __metal_driver_sifive_local_external_command_request (struct metal_interrupt *controller,
86 int command, void *data)
92 case METAL_MAX_INTERRUPT_GET:
93 rc = __metal_driver_sifive_local_external_interrupts0_num_interrupts(controller);
95 case METAL_INDEX_INTERRUPT_GET:
99 rc = __metal_driver_sifive_local_external_interrupts0_interrupt_lines(controller, idx);
109 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_local_external_interrupts0) = {
110 .local0_vtable.interrupt_init = __metal_driver_sifive_local_external_interrupt_init,
111 .local0_vtable.interrupt_register = __metal_driver_sifive_local_external_interrupt_register,
112 .local0_vtable.interrupt_enable = __metal_driver_sifive_local_external_interrupt_enable,
113 .local0_vtable.interrupt_disable = __metal_driver_sifive_local_external_interrupt_disable,
114 .local0_vtable.command_request = __metal_driver_sifive_local_external_command_request,