rk3399_pcie.c revision 1.1.4.2 1 1.1.4.2 christos /* $NetBSD: rk3399_pcie.c,v 1.1.4.2 2019/06/10 22:05:55 christos Exp $ */
2 1.1.4.2 christos /*
3 1.1.4.2 christos * Copyright (c) 2018 Mark Kettenis <kettenis (at) openbsd.org>
4 1.1.4.2 christos *
5 1.1.4.2 christos * Permission to use, copy, modify, and distribute this software for any
6 1.1.4.2 christos * purpose with or without fee is hereby granted, provided that the above
7 1.1.4.2 christos * copyright notice and this permission notice appear in all copies.
8 1.1.4.2 christos *
9 1.1.4.2 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 1.1.4.2 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 1.1.4.2 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 1.1.4.2 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 1.1.4.2 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 1.1.4.2 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 1.1.4.2 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 1.1.4.2 christos */
17 1.1.4.2 christos
18 1.1.4.2 christos #include <sys/cdefs.h>
19 1.1.4.2 christos
20 1.1.4.2 christos __KERNEL_RCSID(1, "$NetBSD: rk3399_pcie.c,v 1.1.4.2 2019/06/10 22:05:55 christos Exp $");
21 1.1.4.2 christos
22 1.1.4.2 christos #include <sys/param.h>
23 1.1.4.2 christos #include <sys/systm.h>
24 1.1.4.2 christos #include <sys/bitops.h>
25 1.1.4.2 christos #include <sys/device.h>
26 1.1.4.2 christos #include <sys/extent.h>
27 1.1.4.2 christos #include <sys/kmem.h>
28 1.1.4.2 christos
29 1.1.4.2 christos #include <machine/intr.h>
30 1.1.4.2 christos #include <sys/bus.h>
31 1.1.4.2 christos #include <dev/fdt/fdtvar.h>
32 1.1.4.2 christos #include <dev/fdt/syscon.h>
33 1.1.4.2 christos #include <arm/cpufunc.h>
34 1.1.4.2 christos
35 1.1.4.2 christos #include <dev/pci/pcidevs.h>
36 1.1.4.2 christos #include <dev/pci/pcireg.h>
37 1.1.4.2 christos #include <dev/pci/pcivar.h>
38 1.1.4.2 christos #include <dev/pci/pciconf.h>
39 1.1.4.2 christos
40 1.1.4.2 christos #include <arm/fdt/pcihost_fdtvar.h>
41 1.1.4.2 christos #include <sys/gpio.h>
42 1.1.4.2 christos
43 1.1.4.2 christos #define SETREG(m, v) ((m)<<16|__SHIFTIN((v), (m)))
44 1.1.4.2 christos #define GETREG(m, v) (__SHIFTOUT((v), (m)))
45 1.1.4.2 christos
46 1.1.4.2 christos /* APB region */
47 1.1.4.2 christos #define PCIE_CLIENT_BASE 0x000000
48 1.1.4.2 christos #define PCIE_CLIENT_BASIC_STRAP_CONF 0x0000
49 1.1.4.2 christos #define PCBSC_PCIE_GEN_SEL __BIT(7)
50 1.1.4.2 christos #define PCBSC_PGS_GEN1 SETREG(PCBSC_PCIE_GEN_SEL, 0)
51 1.1.4.2 christos #define PCBSC_PGS_GEN2 SETREG(PCBSC_PCIE_GEN_SEL, 1)
52 1.1.4.2 christos #define PCBSC_MODE_SELECT __BIT(6)
53 1.1.4.2 christos #define PCBSC_MS_ENDPOINT SETREG(PCBSC_MODE_SELECT, 0)
54 1.1.4.2 christos #define PCBSC_MS_ROOTPORT SETREG(PCBSC_MODE_SELECT, 1)
55 1.1.4.2 christos #define PCBSC_LANE_COUNT __BITS(5,4)
56 1.1.4.2 christos #define PCBSC_LC(x) SETREG(PCBSC_LANE_COUNT, ilog2(x)) /* valid for x1,2,4 */
57 1.1.4.2 christos #define PCBSC_ARI_EN SETREG(__BIT(3), 1) /* Alternate Routing ID Enable */
58 1.1.4.2 christos #define PCBSC_SR_IOV_EN SETREG(__BIT(2), 1)
59 1.1.4.2 christos #define PCBSC_LINK_TRAIN_EN SETREG(__BIT(1), 1)
60 1.1.4.2 christos #define PCBSC_CONF_EN SETREG(__BIT(0), 1) /* Config enable */
61 1.1.4.2 christos #define PCIE_CLIENT_DEBUG_OUT_0 0x003c
62 1.1.4.2 christos #define PCIE_CLIENT_DEBUG_OUT_1 0x0040
63 1.1.4.2 christos #define PCIE_CLIENT_BASIC_STATUS0 0x0044
64 1.1.4.2 christos #define PCIE_CLIENT_BASIC_STATUS1 0x0048
65 1.1.4.2 christos #define PCBS1_LINK_ST(x) (u_int)__SHIFTOUT((x), __BITS(21,20))
66 1.1.4.2 christos #define PCBS1_LS_NO_RECV 0 /* no receivers */
67 1.1.4.2 christos #define PCBS1_LS_TRAINING 1 /* link training */
68 1.1.4.2 christos #define PCBS1_LS_DL_INIT 2 /* link up, DL init progressing */
69 1.1.4.2 christos #define PCBS1_LS_DL_DONE 3 /* link up, DL init complete */
70 1.1.4.2 christos #define PCIE_CLIENT_INT_MASK 0x004c
71 1.1.4.2 christos #define PCIM_INTx_MASK(x) SETREG(__BIT((x)+5), 1)
72 1.1.4.2 christos #define PCIM_INTx_ENAB(x) SETREG(__BIT((x)+5), 0)
73 1.1.4.2 christos
74 1.1.4.2 christos #define PCIE_CORE_BASE 0x800000
75 1.1.4.2 christos #define PCIE_RC_NORMAL_BASE (PCIE_CORE_BASE + 0x00000)
76 1.1.4.2 christos
77 1.1.4.2 christos #define PCIE_LM_BASE 0x900000
78 1.1.4.2 christos #define PCIE_LM_CORE_CTRL (PCIE_LM_BASE + 0x00)
79 1.1.4.2 christos #define PCIE_CORE_PL_CONF_SPEED_5G 0x00000008
80 1.1.4.2 christos #define PCIE_CORE_PL_CONF_SPEED_MASK 0x00000018
81 1.1.4.2 christos #define PCIE_CORE_PL_CONF_LANE_MASK 0x00000006
82 1.1.4.2 christos #define PCIE_CORE_PL_CONF_LANE_SHIFT 1
83 1.1.4.2 christos #define PCIE_LM_PLC1 (PCIE_LM_BASE + 0x04)
84 1.1.4.2 christos #define PCIE_LM_PLC1_FTS_MASK __BITS(23, 8)
85 1.1.4.2 christos #define PCIE_LM_VENDOR_ID (PCIE_LM_BASE + 0x44)
86 1.1.4.2 christos #define PCIE_LM_LINKWIDTH (PCIE_LM_BASE + 0x50)
87 1.1.4.2 christos #define PCIE_LM_LANEMAP (PCIE_LM_BASE + 0x200)
88 1.1.4.2 christos #define PCIE_LM_DEBUG_MUX_CONTROL (PCIE_LM_BASE + 0x208)
89 1.1.4.2 christos #define PCIE_LM_RCBAR (PCIE_LM_BASE + 0x300)
90 1.1.4.2 christos #define PCIE_LM_RCBARPME __BIT(17)
91 1.1.4.2 christos #define PCIE_LM_RCBARPMS __BIT(18)
92 1.1.4.2 christos #define PCIE_LM_RCBARPIE __BIT(19)
93 1.1.4.2 christos #define PCIE_LM_RCBARPIS __BIT(20)
94 1.1.4.2 christos
95 1.1.4.2 christos #define PCIE_RC_BASE 0xa00000
96 1.1.4.2 christos #define PCIE_RC_CONFIG_DCSR (PCIE_RC_BASE + 0x0c0 + PCIE_DCSR)
97 1.1.4.2 christos #define PCIE_RC_PCIE_LCAP (PCIE_RC_BASE + 0x0c0 + PCIE_LCAP)
98 1.1.4.2 christos #define PCIE_RC_CONFIG_LCSR (PCIE_RC_BASE + 0x0c0 + PCIE_LCSR)
99 1.1.4.2 christos #define PCIE_RC_CONFIG_THP_CAP (PCIE_RC_BASE + 0x274)
100 1.1.4.2 christos #define PCIE_RC_CONFIG_THP_CAP_NEXT_MASK __BITS(31, 20)
101 1.1.4.2 christos
102 1.1.4.2 christos
103 1.1.4.2 christos #define PCIE_ATR_BASE 0xc00000
104 1.1.4.2 christos #define PCIE_ATR_OB_ADDR0(i) (PCIE_ATR_BASE + 0x000 + (i) * 0x20)
105 1.1.4.2 christos #define PCIE_ATR_OB_ADDR1(i) (PCIE_ATR_BASE + 0x004 + (i) * 0x20)
106 1.1.4.2 christos #define PCIE_ATR_OB_DESC0(i) (PCIE_ATR_BASE + 0x008 + (i) * 0x20)
107 1.1.4.2 christos #define PCIE_ATR_OB_DESC1(i) (PCIE_ATR_BASE + 0x00c + (i) * 0x20)
108 1.1.4.2 christos #define PCIE_ATR_IB_ADDR0(i) (PCIE_ATR_BASE + 0x800 + (i) * 0x8)
109 1.1.4.2 christos #define PCIE_ATR_IB_ADDR1(i) (PCIE_ATR_BASE + 0x804 + (i) * 0x8)
110 1.1.4.2 christos #define PCIE_ATR_HDR_MEM 0x2
111 1.1.4.2 christos #define PCIE_ATR_HDR_IO 0x6
112 1.1.4.2 christos #define PCIE_ATR_HDR_CFG_TYPE0 0xa
113 1.1.4.2 christos #define PCIE_ATR_HDR_CFG_TYPE1 0xb
114 1.1.4.2 christos #define PCIE_ATR_HDR_RID __BIT(23)
115 1.1.4.2 christos
116 1.1.4.2 christos /* AXI region */
117 1.1.4.2 christos #define PCIE_ATR_OB_REGION0_SIZE (32 * 1024 * 1024)
118 1.1.4.2 christos #define PCIE_ATR_OB_REGION_SIZE (1 * 1024 * 1024)
119 1.1.4.2 christos
120 1.1.4.2 christos #define HREAD4(sc, reg) \
121 1.1.4.2 christos (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg)))
122 1.1.4.2 christos #define HWRITE4(sc, reg, val) \
123 1.1.4.2 christos bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
124 1.1.4.2 christos
125 1.1.4.2 christos struct rkpcie_softc {
126 1.1.4.2 christos struct pcihost_softc sc_phsc;
127 1.1.4.2 christos bus_space_tag_t sc_iot;
128 1.1.4.2 christos bus_space_handle_t sc_ioh;
129 1.1.4.2 christos bus_space_handle_t sc_bus_cfgh[32];
130 1.1.4.2 christos bus_addr_t sc_axi_addr;
131 1.1.4.2 christos bus_addr_t sc_apb_addr;
132 1.1.4.2 christos bus_size_t sc_axi_size;
133 1.1.4.2 christos bus_size_t sc_apb_size;
134 1.1.4.2 christos
135 1.1.4.2 christos struct extent *sc_regionex;
136 1.1.4.2 christos };
137 1.1.4.2 christos
138 1.1.4.2 christos static int rkpcie_match(device_t, cfdata_t, void *);
139 1.1.4.2 christos static void rkpcie_attach(device_t, device_t, void *);
140 1.1.4.2 christos
141 1.1.4.2 christos CFATTACH_DECL_NEW(rkpcie, sizeof(struct rkpcie_softc),
142 1.1.4.2 christos rkpcie_match, rkpcie_attach, NULL, NULL);
143 1.1.4.2 christos
144 1.1.4.2 christos static int
145 1.1.4.2 christos rkpcie_match(device_t parent, cfdata_t cf, void *aux)
146 1.1.4.2 christos {
147 1.1.4.2 christos const char * const compatible[] = {
148 1.1.4.2 christos "rockchip,rk3399-pcie",
149 1.1.4.2 christos NULL
150 1.1.4.2 christos };
151 1.1.4.2 christos struct fdt_attach_args *faa = aux;
152 1.1.4.2 christos
153 1.1.4.2 christos return of_match_compatible(faa->faa_phandle, compatible);
154 1.1.4.2 christos }
155 1.1.4.2 christos
156 1.1.4.2 christos static void rkpcie_atr_init(struct rkpcie_softc *);
157 1.1.4.2 christos
158 1.1.4.2 christos static int rkpcie_bus_maxdevs(void *, int);
159 1.1.4.2 christos static pcitag_t rkpcie_make_tag(void *, int, int, int);
160 1.1.4.2 christos static void rkpcie_decompose_tag(void *, pcitag_t, int *, int *, int *);
161 1.1.4.2 christos static pcireg_t rkpcie_conf_read(void *, pcitag_t, int);
162 1.1.4.2 christos static void rkpcie_conf_write(void *, pcitag_t, int, pcireg_t);
163 1.1.4.2 christos static int rkpcie_conf_hook(void *, int, int, int, pcireg_t);
164 1.1.4.2 christos
165 1.1.4.2 christos static struct fdtbus_interrupt_controller_func rkpcie_intrfuncs;
166 1.1.4.2 christos
167 1.1.4.2 christos static inline int
168 1.1.4.2 christos OF_getpropintarray(int handle, const char *prop, uint32_t *buf, int buflen)
169 1.1.4.2 christos {
170 1.1.4.2 christos int len;
171 1.1.4.2 christos int i;
172 1.1.4.2 christos
173 1.1.4.2 christos len = OF_getprop(handle, prop, buf, buflen);
174 1.1.4.2 christos if (len < 0 || (len % sizeof(uint32_t)))
175 1.1.4.2 christos return -1;
176 1.1.4.2 christos
177 1.1.4.2 christos for (i = 0; i < len / sizeof(uint32_t); i++)
178 1.1.4.2 christos buf[i] = be32toh(buf[i]);
179 1.1.4.2 christos
180 1.1.4.2 christos return len;
181 1.1.4.2 christos }
182 1.1.4.2 christos
183 1.1.4.2 christos static inline void
184 1.1.4.2 christos clock_enable_all(int phandle)
185 1.1.4.2 christos {
186 1.1.4.2 christos for (u_int i = 0; i < 4; i++) {
187 1.1.4.2 christos struct clk * clk = fdtbus_clock_get_index(phandle, i);
188 1.1.4.2 christos if (clk == NULL)
189 1.1.4.2 christos continue;
190 1.1.4.2 christos if (clk_enable(clk) != 0)
191 1.1.4.2 christos continue;
192 1.1.4.2 christos }
193 1.1.4.2 christos }
194 1.1.4.2 christos
195 1.1.4.2 christos static inline void
196 1.1.4.2 christos clock_enable(int phandle, const char *name)
197 1.1.4.2 christos {
198 1.1.4.2 christos struct clk * clk = fdtbus_clock_get(phandle, name);
199 1.1.4.2 christos if (clk == NULL)
200 1.1.4.2 christos return;
201 1.1.4.2 christos if (clk_enable(clk) != 0)
202 1.1.4.2 christos return;
203 1.1.4.2 christos }
204 1.1.4.2 christos
205 1.1.4.2 christos static void
206 1.1.4.2 christos reset_assert(int phandle, const char *name)
207 1.1.4.2 christos {
208 1.1.4.2 christos struct fdtbus_reset *rst;
209 1.1.4.2 christos
210 1.1.4.2 christos rst = fdtbus_reset_get(phandle, name);
211 1.1.4.2 christos fdtbus_reset_assert(rst);
212 1.1.4.2 christos fdtbus_reset_put(rst);
213 1.1.4.2 christos }
214 1.1.4.2 christos
215 1.1.4.2 christos static void
216 1.1.4.2 christos reset_deassert(int phandle, const char *name)
217 1.1.4.2 christos {
218 1.1.4.2 christos struct fdtbus_reset *rst;
219 1.1.4.2 christos
220 1.1.4.2 christos rst = fdtbus_reset_get(phandle, name);
221 1.1.4.2 christos fdtbus_reset_deassert(rst);
222 1.1.4.2 christos fdtbus_reset_put(rst);
223 1.1.4.2 christos }
224 1.1.4.2 christos
225 1.1.4.2 christos static void
226 1.1.4.2 christos rkpcie_attach(device_t parent, device_t self, void *aux)
227 1.1.4.2 christos {
228 1.1.4.2 christos struct rkpcie_softc *sc = device_private(self);
229 1.1.4.2 christos struct pcihost_softc * const phsc = &sc->sc_phsc;
230 1.1.4.2 christos struct fdt_attach_args *faa = aux;
231 1.1.4.2 christos //struct pcibus_attach_args pba;
232 1.1.4.2 christos struct fdtbus_gpio_pin *ep_gpio;
233 1.1.4.2 christos uint32_t bus_range[2];
234 1.1.4.2 christos uint32_t status;
235 1.1.4.2 christos bool retry = false;
236 1.1.4.2 christos int timo;
237 1.1.4.2 christos
238 1.1.4.2 christos phsc->sc_dev = self;
239 1.1.4.2 christos phsc->sc_bst = faa->faa_bst;
240 1.1.4.2 christos phsc->sc_dmat = faa->faa_dmat;
241 1.1.4.2 christos sc->sc_iot = phsc->sc_bst;
242 1.1.4.2 christos phsc->sc_phandle = faa->faa_phandle;
243 1.1.4.2 christos const int phandle = phsc->sc_phandle;
244 1.1.4.2 christos
245 1.1.4.2 christos if (fdtbus_get_reg_byname(faa->faa_phandle, "axi-base", &sc->sc_axi_addr, &sc->sc_axi_size) != 0) {
246 1.1.4.2 christos aprint_error(": couldn't get axi registers\n");
247 1.1.4.2 christos return;
248 1.1.4.2 christos }
249 1.1.4.2 christos if (fdtbus_get_reg_byname(faa->faa_phandle, "apb-base", &sc->sc_apb_addr, &sc->sc_apb_size) != 0) {
250 1.1.4.2 christos aprint_error(": couldn't get apb registers\n");
251 1.1.4.2 christos sc->sc_axi_size = 0;
252 1.1.4.2 christos return;
253 1.1.4.2 christos }
254 1.1.4.2 christos
255 1.1.4.2 christos if (bus_space_map(sc->sc_iot, sc->sc_apb_addr,
256 1.1.4.2 christos sc->sc_apb_size, 0, &sc->sc_ioh)) {
257 1.1.4.2 christos printf(": can't map registers\n");
258 1.1.4.2 christos sc->sc_axi_size = 0;
259 1.1.4.2 christos sc->sc_apb_size = 0;
260 1.1.4.2 christos return;
261 1.1.4.2 christos }
262 1.1.4.2 christos
263 1.1.4.2 christos aprint_naive("\n");
264 1.1.4.2 christos aprint_normal(": RK3399 PCIe\n");
265 1.1.4.2 christos
266 1.1.4.2 christos struct fdtbus_regulator *regulator;
267 1.1.4.2 christos regulator = fdtbus_regulator_acquire(phandle, "vpcie3v3-supply");
268 1.1.4.2 christos fdtbus_regulator_enable(regulator);
269 1.1.4.2 christos fdtbus_regulator_release(regulator);
270 1.1.4.2 christos
271 1.1.4.2 christos fdtbus_clock_assign(phandle);
272 1.1.4.2 christos clock_enable_all(phandle);
273 1.1.4.2 christos
274 1.1.4.2 christos ep_gpio = fdtbus_gpio_acquire(phandle, "ep-gpios", GPIO_PIN_OUTPUT);
275 1.1.4.2 christos //retry = true;
276 1.1.4.2 christos again:
277 1.1.4.2 christos fdtbus_gpio_write(ep_gpio, 0);
278 1.1.4.2 christos
279 1.1.4.2 christos reset_assert(phandle, "aclk");
280 1.1.4.2 christos reset_assert(phandle, "pclk");
281 1.1.4.2 christos reset_assert(phandle, "pm");
282 1.1.4.2 christos
283 1.1.4.2 christos //device_printf(self, "%s phy0\n", __func__);
284 1.1.4.2 christos struct fdtbus_phy *phy[4];
285 1.1.4.2 christos memset(phy, 0, sizeof(phy));
286 1.1.4.2 christos phy[0] = fdtbus_phy_get(phandle, "pcie-phy-0");
287 1.1.4.2 christos //device_printf(self, "%s phy1 %p\n", __func__, phy[0]);
288 1.1.4.2 christos if (phy[0] == NULL) {
289 1.1.4.2 christos phy[0] = fdtbus_phy_get(phandle, "pcie-phy");
290 1.1.4.2 christos device_printf(self, "%s phy2 %p\n", __func__, phy);
291 1.1.4.2 christos } else {
292 1.1.4.2 christos /* XXX */
293 1.1.4.2 christos phy[1] = fdtbus_phy_get(phandle, "pcie-phy-1");
294 1.1.4.2 christos phy[2] = fdtbus_phy_get(phandle, "pcie-phy-2");
295 1.1.4.2 christos phy[3] = fdtbus_phy_get(phandle, "pcie-phy-3");
296 1.1.4.2 christos }
297 1.1.4.2 christos
298 1.1.4.2 christos reset_assert(phandle, "core");
299 1.1.4.2 christos reset_assert(phandle, "mgmt");
300 1.1.4.2 christos reset_assert(phandle, "mgmt-sticky");
301 1.1.4.2 christos reset_assert(phandle, "pipe");
302 1.1.4.2 christos
303 1.1.4.2 christos delay(10);
304 1.1.4.2 christos
305 1.1.4.2 christos reset_deassert(phandle, "pm");
306 1.1.4.2 christos reset_deassert(phandle, "aclk");
307 1.1.4.2 christos reset_deassert(phandle, "pclk");
308 1.1.4.2 christos
309 1.1.4.2 christos if (retry)
310 1.1.4.2 christos HWRITE4(sc, PCIE_CLIENT_BASIC_STRAP_CONF, PCBSC_PGS_GEN1);
311 1.1.4.2 christos else
312 1.1.4.2 christos HWRITE4(sc, PCIE_CLIENT_BASIC_STRAP_CONF, PCBSC_PGS_GEN2);
313 1.1.4.2 christos
314 1.1.4.2 christos /* Switch into Root Complex mode. */
315 1.1.4.2 christos HWRITE4(sc, PCIE_CLIENT_BASIC_STRAP_CONF,
316 1.1.4.2 christos PCBSC_MS_ROOTPORT | PCBSC_CONF_EN | PCBSC_LC(4));
317 1.1.4.2 christos //printf("%s PCBSC %x\n", __func__, HREAD4(sc, PCIE_CLIENT_BASIC_STRAP_CONF));
318 1.1.4.2 christos
319 1.1.4.2 christos if (phy[3] && fdtbus_phy_enable(phy[3], true) != 0) {
320 1.1.4.2 christos aprint_error(": couldn't enable phy3\n");
321 1.1.4.2 christos }
322 1.1.4.2 christos if (phy[2] && fdtbus_phy_enable(phy[2], true) != 0) {
323 1.1.4.2 christos aprint_error(": couldn't enable phy2\n");
324 1.1.4.2 christos }
325 1.1.4.2 christos if (phy[1] && fdtbus_phy_enable(phy[1], true) != 0) {
326 1.1.4.2 christos aprint_error(": couldn't enable phy1\n");
327 1.1.4.2 christos }
328 1.1.4.2 christos if (phy[0] && fdtbus_phy_enable(phy[0], true) != 0) {
329 1.1.4.2 christos aprint_error(": couldn't enable phy0\n");
330 1.1.4.2 christos }
331 1.1.4.2 christos
332 1.1.4.2 christos reset_deassert(phandle, "mgmt-sticky");
333 1.1.4.2 christos reset_deassert(phandle, "core");
334 1.1.4.2 christos reset_deassert(phandle, "mgmt");
335 1.1.4.2 christos reset_deassert(phandle, "pipe");
336 1.1.4.2 christos
337 1.1.4.2 christos /* FTS count */
338 1.1.4.2 christos HWRITE4(sc, PCIE_LM_PLC1, HREAD4(sc, PCIE_LM_PLC1) | PCIE_LM_PLC1_FTS_MASK);
339 1.1.4.2 christos
340 1.1.4.2 christos /* XXX Advertise power limits? */
341 1.1.4.2 christos
342 1.1.4.2 christos /* common clock */
343 1.1.4.2 christos HWRITE4(sc, PCIE_RC_CONFIG_LCSR, HREAD4(sc, PCIE_RC_CONFIG_LCSR) | PCIE_LCSR_COMCLKCFG);
344 1.1.4.2 christos /* 128 RCB */
345 1.1.4.2 christos HWRITE4(sc, PCIE_RC_CONFIG_LCSR, HREAD4(sc, PCIE_RC_CONFIG_LCSR) | PCIE_LCSR_RCB);
346 1.1.4.2 christos
347 1.1.4.2 christos /* Start link training. */
348 1.1.4.2 christos HWRITE4(sc, PCIE_CLIENT_BASIC_STRAP_CONF, PCBSC_LINK_TRAIN_EN);
349 1.1.4.2 christos
350 1.1.4.2 christos fdtbus_gpio_write(ep_gpio, 1);
351 1.1.4.2 christos
352 1.1.4.2 christos for (timo = 500; timo > 0; timo--) {
353 1.1.4.2 christos status = HREAD4(sc, PCIE_CLIENT_BASIC_STATUS1);
354 1.1.4.2 christos if (PCBS1_LINK_ST(status) == PCBS1_LS_DL_DONE)
355 1.1.4.2 christos break;
356 1.1.4.2 christos delay(1000);
357 1.1.4.2 christos }
358 1.1.4.2 christos if (timo == 0) {
359 1.1.4.2 christos device_printf(self, "link training timeout (link_st %u)\n",
360 1.1.4.2 christos PCBS1_LINK_ST(status));
361 1.1.4.2 christos if (!retry) {
362 1.1.4.2 christos retry = true;
363 1.1.4.2 christos goto again;
364 1.1.4.2 christos }
365 1.1.4.2 christos return;
366 1.1.4.2 christos }
367 1.1.4.2 christos
368 1.1.4.2 christos if (!retry) {
369 1.1.4.2 christos HWRITE4(sc, PCIE_RC_CONFIG_LCSR, HREAD4(sc, PCIE_RC_CONFIG_LCSR) | PCIE_LCSR_RETRAIN);
370 1.1.4.2 christos for (timo = 500; timo > 0; timo--) {
371 1.1.4.2 christos status = HREAD4(sc, PCIE_LM_CORE_CTRL);
372 1.1.4.2 christos if ((status & PCIE_CORE_PL_CONF_SPEED_MASK) == PCIE_CORE_PL_CONF_SPEED_5G)
373 1.1.4.2 christos break;
374 1.1.4.2 christos delay(1000);
375 1.1.4.2 christos }
376 1.1.4.2 christos if (timo == 0) {
377 1.1.4.2 christos device_printf(self, "Gen2 link training timeout\n");
378 1.1.4.2 christos retry = true;
379 1.1.4.2 christos goto again;
380 1.1.4.2 christos }
381 1.1.4.2 christos }
382 1.1.4.2 christos
383 1.1.4.2 christos #if 0
384 1.1.4.2 christos printf("%s CBS0 %x\n", __func__, HREAD4(sc, PCIE_CLIENT_BASIC_STATUS1));
385 1.1.4.2 christos HWRITE4(sc, PCIE_LM_DEBUG_MUX_CONTROL, (HREAD4(sc, PCIE_LM_DEBUG_MUX_CONTROL) & ~0xf) | 0);
386 1.1.4.2 christos printf("%s CDO0 %x\n", __func__, HREAD4(sc, PCIE_CLIENT_DEBUG_OUT_0));
387 1.1.4.2 christos HWRITE4(sc, PCIE_LM_DEBUG_MUX_CONTROL, (HREAD4(sc, PCIE_LM_DEBUG_MUX_CONTROL) & ~0xf) | 1);
388 1.1.4.2 christos printf("%s CDO0 %x\n", __func__, HREAD4(sc, PCIE_CLIENT_DEBUG_OUT_0));
389 1.1.4.2 christos HWRITE4(sc, PCIE_LM_DEBUG_MUX_CONTROL, (HREAD4(sc, PCIE_LM_DEBUG_MUX_CONTROL) & ~0xf) | 4);
390 1.1.4.2 christos printf("%s CDO0 %x\n", __func__, HREAD4(sc, PCIE_CLIENT_DEBUG_OUT_0));
391 1.1.4.2 christos HWRITE4(sc, PCIE_LM_DEBUG_MUX_CONTROL, (HREAD4(sc, PCIE_LM_DEBUG_MUX_CONTROL) & ~0xf) | 5);
392 1.1.4.2 christos printf("%s CDO0 %x\n", __func__, HREAD4(sc, PCIE_CLIENT_DEBUG_OUT_0));
393 1.1.4.2 christos printf("%s LINKWIDTH %x\n", __func__, HREAD4(sc, PCIE_LM_LINKWIDTH));
394 1.1.4.2 christos //HWRITE4(sc, PCIE_LM_LINKWIDTH, 0x1000f);
395 1.1.4.2 christos //printf("%s LINKWIDTH %x\n", __func__, HREAD4(sc, PCIE_LM_LINKWIDTH));
396 1.1.4.2 christos printf("%s LANEMAP %x\n", __func__, HREAD4(sc, PCIE_LM_LANEMAP));
397 1.1.4.2 christos #endif
398 1.1.4.2 christos
399 1.1.4.2 christos fdtbus_gpio_release(ep_gpio);
400 1.1.4.2 christos
401 1.1.4.2 christos HWRITE4(sc, PCIE_RC_BASE + PCI_CLASS_REG,
402 1.1.4.2 christos PCI_CLASS_BRIDGE << PCI_CLASS_SHIFT |
403 1.1.4.2 christos PCI_SUBCLASS_BRIDGE_PCI << PCI_SUBCLASS_SHIFT);
404 1.1.4.2 christos
405 1.1.4.2 christos /* Initialize Root Complex registers. */
406 1.1.4.2 christos HWRITE4(sc, PCIE_LM_VENDOR_ID, PCI_VENDOR_ROCKCHIP);
407 1.1.4.2 christos HWRITE4(sc, PCIE_RC_BASE + PCI_CLASS_REG,
408 1.1.4.2 christos PCI_CLASS_BRIDGE << PCI_CLASS_SHIFT |
409 1.1.4.2 christos PCI_SUBCLASS_BRIDGE_PCI << PCI_SUBCLASS_SHIFT);
410 1.1.4.2 christos HWRITE4(sc, PCIE_LM_RCBAR, PCIE_LM_RCBARPIE | PCIE_LM_RCBARPIS | PCIE_LM_RCBARPME | PCIE_LM_RCBARPMS);
411 1.1.4.2 christos
412 1.1.4.2 christos /* remove L1 substate cap */
413 1.1.4.2 christos status = HREAD4(sc, PCIE_RC_CONFIG_THP_CAP);
414 1.1.4.2 christos status &= ~PCIE_RC_CONFIG_THP_CAP_NEXT_MASK;
415 1.1.4.2 christos HWRITE4(sc, PCIE_RC_CONFIG_THP_CAP, status);
416 1.1.4.2 christos
417 1.1.4.2 christos if (OF_getproplen(phandle, "aspm-no-l0s") == 0) {
418 1.1.4.2 christos status = HREAD4(sc, PCIE_RC_PCIE_LCAP);
419 1.1.4.2 christos status &= ~__SHIFTIN(1, PCIE_LCAP_ASPM);
420 1.1.4.2 christos HWRITE4(sc, PCIE_RC_PCIE_LCAP, status);
421 1.1.4.2 christos }
422 1.1.4.2 christos
423 1.1.4.2 christos status = HREAD4(sc, PCIE_RC_CONFIG_DCSR);
424 1.1.4.2 christos status &= ~PCIE_DCSR_MAX_PAYLOAD;
425 1.1.4.2 christos status |= __SHIFTIN(1, PCIE_DCSR_MAX_PAYLOAD);
426 1.1.4.2 christos HWRITE4(sc, PCIE_RC_CONFIG_DCSR, status);
427 1.1.4.2 christos
428 1.1.4.2 christos /* Create extents for our address space. */
429 1.1.4.2 christos sc->sc_regionex = extent_create("rkpcie", sc->sc_axi_addr,
430 1.1.4.2 christos sc->sc_axi_addr - 1 + 64 * 1048576, NULL, 0, EX_WAITOK);
431 1.1.4.2 christos
432 1.1.4.2 christos /* Set up bus range. */
433 1.1.4.2 christos if (OF_getpropintarray(phandle, "bus-range", bus_range,
434 1.1.4.2 christos sizeof(bus_range)) != sizeof(bus_range) ||
435 1.1.4.2 christos bus_range[0] >= 32 || bus_range[1] >= 32) {
436 1.1.4.2 christos bus_range[0] = 0;
437 1.1.4.2 christos bus_range[1] = 31;
438 1.1.4.2 christos }
439 1.1.4.2 christos sc->sc_phsc.sc_bus_min = bus_range[0];
440 1.1.4.2 christos sc->sc_phsc.sc_bus_max = bus_range[1];
441 1.1.4.2 christos
442 1.1.4.2 christos if (sc->sc_phsc.sc_bus_min != 0) {
443 1.1.4.2 christos aprint_error_dev(self, "bus-range doesn't start at 0\n");
444 1.1.4.2 christos return;
445 1.1.4.2 christos }
446 1.1.4.2 christos
447 1.1.4.2 christos /* Configure Address Translation. */
448 1.1.4.2 christos rkpcie_atr_init(sc);
449 1.1.4.2 christos
450 1.1.4.2 christos fdtbus_register_interrupt_controller(self, OF_child(sc->sc_phsc.sc_phandle),
451 1.1.4.2 christos &rkpcie_intrfuncs);
452 1.1.4.2 christos
453 1.1.4.2 christos sc->sc_phsc.sc_type = PCIHOST_ECAM;
454 1.1.4.2 christos pcihost_init(&sc->sc_phsc.sc_pc, sc);
455 1.1.4.2 christos sc->sc_phsc.sc_pc.pc_bus_maxdevs = rkpcie_bus_maxdevs;
456 1.1.4.2 christos sc->sc_phsc.sc_pc.pc_make_tag = rkpcie_make_tag;
457 1.1.4.2 christos sc->sc_phsc.sc_pc.pc_decompose_tag = rkpcie_decompose_tag;
458 1.1.4.2 christos sc->sc_phsc.sc_pc.pc_conf_read = rkpcie_conf_read;
459 1.1.4.2 christos sc->sc_phsc.sc_pc.pc_conf_write = rkpcie_conf_write;
460 1.1.4.2 christos sc->sc_phsc.sc_pc.pc_conf_hook = rkpcie_conf_hook;
461 1.1.4.2 christos pcihost_init2(&sc->sc_phsc);
462 1.1.4.2 christos }
463 1.1.4.2 christos
464 1.1.4.2 christos static void
465 1.1.4.2 christos rkpcie_atr_init(struct rkpcie_softc *sc)
466 1.1.4.2 christos {
467 1.1.4.2 christos uint32_t *ranges = NULL;
468 1.1.4.2 christos struct extent * const ex = sc->sc_regionex;
469 1.1.4.2 christos bus_addr_t aaddr;
470 1.1.4.2 christos bus_addr_t addr;
471 1.1.4.2 christos bus_size_t size, offset;
472 1.1.4.2 christos uint32_t type;
473 1.1.4.2 christos int len, region;
474 1.1.4.2 christos int i;
475 1.1.4.2 christos
476 1.1.4.2 christos /* get root bus's config space out of the APB space */
477 1.1.4.2 christos bus_space_subregion(sc->sc_iot, sc->sc_ioh, PCIE_RC_NORMAL_BASE, PCI_EXTCONF_SIZE * 8, &sc->sc_bus_cfgh[0]);
478 1.1.4.2 christos
479 1.1.4.2 christos len = OF_getproplen(sc->sc_phsc.sc_phandle, "ranges");
480 1.1.4.2 christos if (len <= 0 || (len % (7 * sizeof(uint32_t))) != 0)
481 1.1.4.2 christos goto fail;
482 1.1.4.2 christos ranges = kmem_zalloc(len, KM_SLEEP);
483 1.1.4.2 christos OF_getpropintarray(sc->sc_phsc.sc_phandle, "ranges", ranges, len);
484 1.1.4.2 christos
485 1.1.4.2 christos for (i = 0; i < len / sizeof(uint32_t); i += 7) {
486 1.1.4.2 christos /* Handle IO and MMIO. */
487 1.1.4.2 christos switch (ranges[i] & 0x03000000) {
488 1.1.4.2 christos case 0x00000000:
489 1.1.4.2 christos type = PCIE_ATR_HDR_CFG_TYPE0;
490 1.1.4.2 christos break;
491 1.1.4.2 christos case 0x01000000:
492 1.1.4.2 christos type = PCIE_ATR_HDR_IO;
493 1.1.4.2 christos break;
494 1.1.4.2 christos case 0x02000000:
495 1.1.4.2 christos case 0x03000000:
496 1.1.4.2 christos type = PCIE_ATR_HDR_MEM;
497 1.1.4.2 christos break;
498 1.1.4.2 christos default:
499 1.1.4.2 christos continue;
500 1.1.4.2 christos }
501 1.1.4.2 christos
502 1.1.4.2 christos addr = ((uint64_t)ranges[i + 1] << 32) + ranges[i + 2];
503 1.1.4.2 christos aaddr = ((uint64_t)ranges[i + 3] << 32) + ranges[i + 4];
504 1.1.4.2 christos size = (uint64_t)ranges[i+5] << 32 | ranges[i + 6];
505 1.1.4.2 christos
506 1.1.4.2 christos if (type == PCIE_ATR_HDR_CFG_TYPE0) {
507 1.1.4.2 christos addr = __SHIFTOUT(ranges[i], PHYS_HI_BUS) << 20;
508 1.1.4.2 christos }
509 1.1.4.2 christos
510 1.1.4.2 christos /* Only support mappings aligned on a region boundary. */
511 1.1.4.2 christos if (addr & (PCIE_ATR_OB_REGION_SIZE - 1))
512 1.1.4.2 christos goto fail;
513 1.1.4.2 christos if (aaddr & (PCIE_ATR_OB_REGION_SIZE - 1))
514 1.1.4.2 christos goto fail;
515 1.1.4.2 christos if (size & (PCIE_ATR_OB_REGION_SIZE - 1))
516 1.1.4.2 christos goto fail;
517 1.1.4.2 christos
518 1.1.4.2 christos /* Mappings should lie in AXI region. */
519 1.1.4.2 christos if (aaddr < sc->sc_axi_addr)
520 1.1.4.2 christos goto fail;
521 1.1.4.2 christos if (aaddr + size > sc->sc_axi_addr + 64*1024*1024)
522 1.1.4.2 christos goto fail;
523 1.1.4.2 christos
524 1.1.4.2 christos while (size > 0) {
525 1.1.4.2 christos offset = aaddr - sc->sc_axi_addr;
526 1.1.4.2 christos region = (offset / PCIE_ATR_OB_REGION_SIZE);
527 1.1.4.2 christos if (region >= 0x20)
528 1.1.4.2 christos region -= 0x1f;
529 1.1.4.2 christos if (region > 32)
530 1.1.4.2 christos continue;
531 1.1.4.2 christos u_long regionsize = region ?
532 1.1.4.2 christos PCIE_ATR_OB_REGION_SIZE : PCIE_ATR_OB_REGION0_SIZE;
533 1.1.4.2 christos uint32_t regionbits = ilog2(regionsize);
534 1.1.4.2 christos
535 1.1.4.2 christos //printf("%s %lx %lx %lx\n", __func__, addr, aaddr, regionsize);
536 1.1.4.2 christos if (extent_alloc_region(ex, aaddr, regionsize, EX_WAITOK) != 0)
537 1.1.4.2 christos goto fail;
538 1.1.4.2 christos if (type == PCIE_ATR_HDR_CFG_TYPE0) {
539 1.1.4.2 christos const uint32_t bus = (addr >> 20) & 0xff;
540 1.1.4.2 christos if (bus == 0 ||
541 1.1.4.2 christos bus >= __arraycount(sc->sc_bus_cfgh))
542 1.1.4.2 christos continue;
543 1.1.4.2 christos bus_space_map(sc->sc_iot, aaddr, regionsize, 0, &sc->sc_bus_cfgh[bus]);
544 1.1.4.2 christos if (bus > 1)
545 1.1.4.2 christos type = PCIE_ATR_HDR_CFG_TYPE1;
546 1.1.4.2 christos }
547 1.1.4.2 christos HWRITE4(sc, PCIE_ATR_OB_ADDR0(region),
548 1.1.4.2 christos addr | (regionbits-1));
549 1.1.4.2 christos HWRITE4(sc, PCIE_ATR_OB_ADDR1(region), addr >> 32);
550 1.1.4.2 christos HWRITE4(sc, PCIE_ATR_OB_DESC0(region),
551 1.1.4.2 christos type | PCIE_ATR_HDR_RID);
552 1.1.4.2 christos HWRITE4(sc, PCIE_ATR_OB_DESC1(region), 0);
553 1.1.4.2 christos
554 1.1.4.2 christos aaddr += regionsize;
555 1.1.4.2 christos addr += regionsize;
556 1.1.4.2 christos size -= regionsize;
557 1.1.4.2 christos }
558 1.1.4.2 christos }
559 1.1.4.2 christos kmem_free(ranges, len);
560 1.1.4.2 christos
561 1.1.4.2 christos /* Passthrought inbound translations unmodified. */
562 1.1.4.2 christos HWRITE4(sc, PCIE_ATR_IB_ADDR0(2), 32 - 1);
563 1.1.4.2 christos HWRITE4(sc, PCIE_ATR_IB_ADDR1(2), 0);
564 1.1.4.2 christos
565 1.1.4.2 christos return;
566 1.1.4.2 christos
567 1.1.4.2 christos fail:
568 1.1.4.2 christos extent_print(ex);
569 1.1.4.2 christos device_printf(sc->sc_phsc.sc_dev, "can't map ranges\n");
570 1.1.4.2 christos kmem_free(ranges, len);
571 1.1.4.2 christos }
572 1.1.4.2 christos
573 1.1.4.2 christos int
574 1.1.4.2 christos rkpcie_bus_maxdevs(void *v, int bus)
575 1.1.4.2 christos {
576 1.1.4.2 christos struct rkpcie_softc *rksc = v;
577 1.1.4.2 christos struct pcihost_softc *sc = &rksc->sc_phsc;
578 1.1.4.2 christos
579 1.1.4.2 christos if (bus == sc->sc_bus_min)
580 1.1.4.2 christos return 1;
581 1.1.4.2 christos return 32;
582 1.1.4.2 christos }
583 1.1.4.2 christos
584 1.1.4.2 christos pcitag_t
585 1.1.4.2 christos rkpcie_make_tag(void *v, int bus, int device, int function)
586 1.1.4.2 christos {
587 1.1.4.2 christos /* Return ECAM address. */
588 1.1.4.2 christos return ((bus << 20) | (device << 15) | (function << 12));
589 1.1.4.2 christos }
590 1.1.4.2 christos
591 1.1.4.2 christos void
592 1.1.4.2 christos rkpcie_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
593 1.1.4.2 christos {
594 1.1.4.2 christos if (bp != NULL)
595 1.1.4.2 christos *bp = (tag >> 20) & 0xff;
596 1.1.4.2 christos if (dp != NULL)
597 1.1.4.2 christos *dp = (tag >> 15) & 0x1f;
598 1.1.4.2 christos if (fp != NULL)
599 1.1.4.2 christos *fp = (tag >> 12) & 0x7;
600 1.1.4.2 christos }
601 1.1.4.2 christos
602 1.1.4.2 christos pcireg_t
603 1.1.4.2 christos rkpcie_conf_read(void *v, pcitag_t tag, int reg)
604 1.1.4.2 christos {
605 1.1.4.2 christos struct rkpcie_softc *sc = v;
606 1.1.4.2 christos struct pcihost_softc *phsc = &sc->sc_phsc;
607 1.1.4.2 christos int bus, dev, fn;
608 1.1.4.2 christos bus_size_t offset;
609 1.1.4.2 christos uint32_t data;
610 1.1.4.2 christos
611 1.1.4.2 christos KASSERT(reg >= 0);
612 1.1.4.2 christos KASSERT(reg < PCI_EXTCONF_SIZE);
613 1.1.4.2 christos
614 1.1.4.2 christos rkpcie_decompose_tag(sc, tag, &bus, &dev, &fn);
615 1.1.4.2 christos if (bus > phsc->sc_bus_max)
616 1.1.4.2 christos return 0xffffffff;
617 1.1.4.2 christos if (bus == phsc->sc_bus_min + 1 && dev > 0)
618 1.1.4.2 christos return 0xffffffff;
619 1.1.4.2 christos offset = dev << 15 | fn << 12 | reg;
620 1.1.4.2 christos if (bus_space_peek_4(sc->sc_iot, sc->sc_bus_cfgh[bus], offset, &data) == 0)
621 1.1.4.2 christos return data;
622 1.1.4.2 christos
623 1.1.4.2 christos return 0xffffffff;
624 1.1.4.2 christos }
625 1.1.4.2 christos
626 1.1.4.2 christos void
627 1.1.4.2 christos rkpcie_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
628 1.1.4.2 christos {
629 1.1.4.2 christos struct rkpcie_softc *sc = v;
630 1.1.4.2 christos struct pcihost_softc *phsc = &sc->sc_phsc;
631 1.1.4.2 christos int bus, dev, fn;
632 1.1.4.2 christos bus_size_t offset;
633 1.1.4.2 christos
634 1.1.4.2 christos KASSERT(reg >= 0);
635 1.1.4.2 christos KASSERT(reg < PCI_EXTCONF_SIZE);
636 1.1.4.2 christos
637 1.1.4.2 christos rkpcie_decompose_tag(sc, tag, &bus, &dev, &fn);
638 1.1.4.2 christos if (bus > phsc->sc_bus_max)
639 1.1.4.2 christos return;
640 1.1.4.2 christos if (bus == phsc->sc_bus_min + 1 && dev > 0)
641 1.1.4.2 christos return;
642 1.1.4.2 christos offset = dev << 15 | fn << 12 | reg;
643 1.1.4.2 christos bus_space_poke_4(sc->sc_iot, sc->sc_bus_cfgh[bus], offset, data);
644 1.1.4.2 christos }
645 1.1.4.2 christos
646 1.1.4.2 christos static int
647 1.1.4.2 christos rkpcie_conf_hook(void *v, int b, int d, int f, pcireg_t id)
648 1.1.4.2 christos {
649 1.1.4.2 christos return (PCI_CONF_DEFAULT & ~PCI_CONF_ENABLE_BM) | PCI_CONF_MAP_ROM;
650 1.1.4.2 christos }
651 1.1.4.2 christos
652 1.1.4.2 christos /* INTx interrupt controller */
653 1.1.4.2 christos static void *
654 1.1.4.2 christos rkpcie_intx_establish(device_t dev, u_int *specifier, int ipl, int flags,
655 1.1.4.2 christos int (*func)(void *), void *arg)
656 1.1.4.2 christos {
657 1.1.4.2 christos struct rkpcie_softc *sc = device_private(dev);
658 1.1.4.2 christos void *cookie;
659 1.1.4.2 christos
660 1.1.4.2 christos const u_int pin = be32toh(specifier[0]);
661 1.1.4.2 christos device_printf(sc->sc_phsc.sc_dev, "%s pin %u\n", __func__, pin);
662 1.1.4.2 christos
663 1.1.4.2 christos /* Unmask legacy interrupts. */
664 1.1.4.2 christos HWRITE4(sc, PCIE_CLIENT_INT_MASK,
665 1.1.4.2 christos PCIM_INTx_ENAB(0) | PCIM_INTx_ENAB(1) |
666 1.1.4.2 christos PCIM_INTx_ENAB(2) | PCIM_INTx_ENAB(3));
667 1.1.4.2 christos
668 1.1.4.2 christos cookie = fdtbus_intr_establish_byname(sc->sc_phsc.sc_phandle, "legacy", ipl, flags, func, arg);
669 1.1.4.2 christos
670 1.1.4.2 christos return cookie;
671 1.1.4.2 christos }
672 1.1.4.2 christos
673 1.1.4.2 christos static void
674 1.1.4.2 christos rkpcie_intx_disestablish(device_t dev, void *ih)
675 1.1.4.2 christos {
676 1.1.4.2 christos struct rkpcie_softc *sc = device_private(dev);
677 1.1.4.2 christos device_printf(dev, "%s\n", __func__);
678 1.1.4.2 christos fdtbus_intr_disestablish(sc->sc_phsc.sc_phandle, ih);
679 1.1.4.2 christos }
680 1.1.4.2 christos
681 1.1.4.2 christos static bool
682 1.1.4.2 christos rkpcie_intx_intrstr(device_t dev, u_int *specifier, char *buf, size_t buflen)
683 1.1.4.2 christos {
684 1.1.4.2 christos struct rkpcie_softc *sc = device_private(dev);
685 1.1.4.2 christos
686 1.1.4.2 christos fdtbus_intr_str(sc->sc_phsc.sc_phandle, 1, buf, buflen);
687 1.1.4.2 christos
688 1.1.4.2 christos return true;
689 1.1.4.2 christos }
690 1.1.4.2 christos
691 1.1.4.2 christos static struct fdtbus_interrupt_controller_func rkpcie_intrfuncs = {
692 1.1.4.2 christos .establish = rkpcie_intx_establish,
693 1.1.4.2 christos .disestablish = rkpcie_intx_disestablish,
694 1.1.4.2 christos .intrstr = rkpcie_intx_intrstr,
695 1.1.4.2 christos };
696