1 // Copyright 2016 The Fuchsia Authors
2 // Copyright (c) 2013, Google Inc. All rights reserved.
3 //
4 // Use of this source code is governed by a MIT-style
5 // license that can be found in the LICENSE file or at
6 // https://opensource.org/licenses/MIT
7 
8 #pragma once
9 
10 #include <vm/pmm.h>
11 #include <zircon/types.h>
12 
13 // GIC HW interface
14 struct arm_gic_hw_interface_ops {
15     void (*write_gich_hcr)(uint32_t val);
16     uint32_t (*read_gich_vtr)();
17     uint32_t (*default_gich_vmcr)();
18     uint32_t (*read_gich_vmcr)();
19     void (*write_gich_vmcr)(uint32_t val);
20     uint32_t (*read_gich_misr)();
21     uint64_t (*read_gich_elrsr)();
22     uint32_t (*read_gich_apr)(uint32_t idx);
23     void (*write_gich_apr)(uint32_t idx, uint32_t val);
24     uint64_t (*read_gich_lr)(uint32_t idx);
25     void (*write_gich_lr)(uint32_t idx, uint64_t val);
26     zx_status_t (*get_gicv)(paddr_t* gicv_paddr);
27     uint64_t (*get_lr_from_vector)(bool hw, uint8_t prio, uint32_t vector);
28     uint32_t (*get_vector_from_lr)(uint64_t lr);
29     uint32_t (*get_num_pres)();
30     uint32_t (*get_num_lrs)();
31 };
32 
33 // Writes to the GICH_HCR register.
34 void gic_write_gich_hcr(uint32_t val);
35 
36 // Returns the GICH_VTR value.
37 uint32_t gic_read_gich_vtr();
38 
39 // Returns the default GICH_VMCR value. Used to initialize GICH_VMCR.
40 uint32_t gic_default_gich_vmcr();
41 
42 // Returns the GICH_VMCR value.
43 uint32_t gic_read_gich_vmcr();
44 
45 // Writes to the GICH_VMCR register.
46 void gic_write_gich_vmcr(uint32_t val);
47 
48 // Returns the GICH_MISR value.
49 uint32_t gic_read_gich_misr();
50 
51 // Returns the GICH_ELRS value.
52 uint64_t gic_read_gich_elrsr();
53 
54 // Returns the GICH_APR value.
55 uint32_t gic_read_gich_apr(uint32_t idx);
56 
57 // Writes to the GICH_APR register.
58 void gic_write_gich_apr(uint32_t idx, uint32_t val);
59 
60 // Returns the GICH_LRn value.
61 uint64_t gic_read_gich_lr(uint32_t idx);
62 
63 // Writes to the GICH_LR register.
64 void gic_write_gich_lr(uint32_t idx, uint64_t val);
65 
66 // Get the GICV physical address.
67 zx_status_t gic_get_gicv(paddr_t* gicv_paddr);
68 
69 // Returns a list register based on the given interrupt vector.
70 uint64_t gic_get_lr_from_vector(bool hw, uint8_t prio, uint32_t vector);
71 
72 // Returns an interrupt vector based on the given list register.
73 uint32_t gic_get_vector_from_lr(uint64_t lr);
74 
75 // Returns the number of preemption bits.
76 uint32_t gic_get_num_pres();
77 
78 // Returns the number of list registers.
79 uint32_t gic_get_num_lrs();
80 
81 // Registers the ops of the GIC driver initialized with HW interface layer.
82 void arm_gic_hw_interface_register(const struct arm_gic_hw_interface_ops* ops);
83 
84 bool arm_gic_is_registered();
85