Merge sync of head
[freebsd.git] / sys / arm64 / arm64 / gic_v3_var.h
1 /*-
2  * Copyright (c) 2015 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Semihalf under
6  * the sponsorship of the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #ifndef _GIC_V3_VAR_H_
33 #define _GIC_V3_VAR_H_
34
35 #define GIC_V3_DEVSTR   "ARM Generic Interrupt Controller v3.0"
36
37 DECLARE_CLASS(gic_v3_driver);
38
39 struct gic_redists {
40         /*
41          * Re-Distributor region description.
42          * We will have few of those depending
43          * on the #redistributor-regions property in FDT.
44          */
45         struct resource **      regions;
46         /* Number of Re-Distributor regions */
47         u_int                   nregions;
48         /* Per-CPU Re-Distributor handler */
49         struct resource *       pcpu[MAXCPU];
50 };
51
52 struct gic_v3_softc {
53         device_t                dev;
54         struct resource **      gic_res;
55         struct mtx              gic_mtx;
56         /* Distributor */
57         struct resource *       gic_dist;
58         /* Re-Distributors */
59         struct gic_redists      gic_redists;
60
61         u_int                   gic_nirqs;
62         u_int                   gic_idbits;
63
64         boolean_t               gic_registered;
65 };
66
67 MALLOC_DECLARE(M_GIC_V3);
68
69 /* Device methods */
70 int gic_v3_attach(device_t dev);
71 int gic_v3_detach(device_t dev);
72
73 /*
74  * GIC Distributor accessors.
75  * Notice that only GIC sofc can be passed.
76  */
77 #define gic_d_read(sc, len, reg)                \
78 ({                                              \
79         bus_read_##len(sc->gic_dist, reg);      \
80 })
81
82 #define gic_d_write(sc, len, reg, val)          \
83 ({                                              \
84         bus_write_##len(sc->gic_dist, reg, val);\
85 })
86
87 /* GIC Re-Distributor accessors (per-CPU) */
88 #define gic_r_read(sc, len, reg)                \
89 ({                                              \
90         u_int cpu = PCPU_GET(cpuid);            \
91                                                 \
92         bus_read_##len(                         \
93             sc->gic_redists.pcpu[cpu],          \
94             reg);                               \
95 })
96
97 #define gic_r_write(sc, len, reg, val)          \
98 ({                                              \
99         u_int cpu = PCPU_GET(cpuid);            \
100                                                 \
101         bus_write_##len(                        \
102             sc->gic_redists.pcpu[cpu],          \
103             reg, val);                          \
104 })
105
106 #endif /* _GIC_V3_VAR_H_ */