1*c7fb772bSthorpej /* $NetBSD: octeon_iobus.c,v 1.7 2021/08/07 16:18:59 thorpej Exp $ */
2f693c922Shikaru
3f693c922Shikaru /*
4f693c922Shikaru * Copyright (c) 2007
5f693c922Shikaru * Internet Initiative Japan, Inc. All rights reserved.
6f693c922Shikaru *
7f693c922Shikaru * Redistribution and use in source and binary forms, with or without
8f693c922Shikaru * modification, are permitted provided that the following conditions
9f693c922Shikaru * are met:
10f693c922Shikaru * 1. Redistributions of source code must retain the above copyright
11f693c922Shikaru * notice, this list of conditions and the following disclaimer.
12f693c922Shikaru * 2. Redistributions in binary form must reproduce the above copyright
13f693c922Shikaru * notice, this list of conditions and the following disclaimer in the
14f693c922Shikaru * documentation and/or other materials provided with the distribution.
15f693c922Shikaru *
16f693c922Shikaru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17f693c922Shikaru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f693c922Shikaru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f693c922Shikaru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20f693c922Shikaru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f693c922Shikaru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f693c922Shikaru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f693c922Shikaru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f693c922Shikaru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f693c922Shikaru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f693c922Shikaru * SUCH DAMAGE.
27f693c922Shikaru */
28f693c922Shikaru
29f693c922Shikaru #include <sys/cdefs.h>
30*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: octeon_iobus.c,v 1.7 2021/08/07 16:18:59 thorpej Exp $");
31f693c922Shikaru
32f693c922Shikaru #include "locators.h"
33f693c922Shikaru
34f693c922Shikaru #include <sys/param.h>
35f693c922Shikaru #include <sys/systm.h>
36f693c922Shikaru #include <sys/device.h>
37f693c922Shikaru
38f693c922Shikaru #define _MIPS_BUS_DMA_PRIVATE
39f693c922Shikaru #include <sys/bus.h>
40f693c922Shikaru
41f693c922Shikaru #include <mips/cavium/include/iobusvar.h>
42f693c922Shikaru
4361ff6cfaSjmcneill #include <dev/fdt/fdtvar.h>
4461ff6cfaSjmcneill
45f693c922Shikaru struct iobus_softc {
46f693c922Shikaru device_t sc_dev;
47f693c922Shikaru
48f693c922Shikaru /* XXX load/IOBDMA/store operations */
49f693c922Shikaru bus_space_handle_t sc_ops_bush;
50f693c922Shikaru };
51f693c922Shikaru
52f693c922Shikaru static int iobus_match(device_t, struct cfdata *, void *);
53f693c922Shikaru static void iobus_attach(device_t, device_t, void *);
54eb61b502Ssimonb static int iobus_submatch(device_t, struct cfdata *, const int *, void *);
55f693c922Shikaru static int iobus_print(void *, const char *);
56f693c922Shikaru static void iobus_init(struct iobus_softc *);
57f693c922Shikaru static void iobus_init_map(struct iobus_softc *);
58f693c922Shikaru static void iobus_init_local(struct iobus_softc *);
59f693c922Shikaru static void iobus_init_local_pow(struct iobus_softc *);
60f693c922Shikaru static void iobus_init_local_fpa(struct iobus_softc *);
61f693c922Shikaru
62f693c922Shikaru static void iobus_bus_io_init(bus_space_tag_t, void *);
63f693c922Shikaru
64f693c922Shikaru static struct mips_bus_space *iobus_bust;
65f693c922Shikaru static struct mips_bus_dma_tag *iobus_dmat;
66f693c922Shikaru
67f693c922Shikaru void
iobus_bootstrap(struct octeon_config * mcp)68f693c922Shikaru iobus_bootstrap(struct octeon_config *mcp)
69f693c922Shikaru {
70f693c922Shikaru iobus_bus_io_init(&mcp->mc_iobus_bust, mcp);
71f693c922Shikaru
72f693c922Shikaru iobus_bust = &mcp->mc_iobus_bust;
73f693c922Shikaru iobus_dmat = &mcp->mc_iobus_dmat;
74f693c922Shikaru }
75f693c922Shikaru
76f693c922Shikaru /* ---- autoconf */
77f693c922Shikaru
78eb61b502Ssimonb CFATTACH_DECL_NEW(iobus, sizeof(struct iobus_softc),
79eb61b502Ssimonb iobus_match, iobus_attach, NULL, NULL);
80f693c922Shikaru
81f693c922Shikaru static int
iobus_match(device_t parent,struct cfdata * match,void * aux)82f693c922Shikaru iobus_match(device_t parent, struct cfdata *match, void *aux)
83f693c922Shikaru {
84f693c922Shikaru return 1;
85f693c922Shikaru }
86f693c922Shikaru
87f693c922Shikaru static void
iobus_attach(device_t parent,device_t self,void * aux)88f693c922Shikaru iobus_attach(device_t parent, device_t self, void *aux)
89f693c922Shikaru {
90f693c922Shikaru struct iobus_softc *sc = device_private(self);
91f693c922Shikaru const struct iobus_dev *dev;
92f693c922Shikaru struct iobus_attach_args aa;
9361ff6cfaSjmcneill const bool fdt_p = fdtbus_get_data() != NULL;
94f693c922Shikaru int i, j;
95f693c922Shikaru
96f693c922Shikaru sc->sc_dev = self;
97f693c922Shikaru
98f693c922Shikaru aprint_normal("\n");
99f693c922Shikaru
100f693c922Shikaru iobus_init(sc);
101f693c922Shikaru
102eb61b502Ssimonb /* XXX should only attach Octeon 1 and Octeon Plus drivers */
103f693c922Shikaru for (i = 0; i < (int)iobus_ndevs; i++) {
104f693c922Shikaru dev = iobus_devs[i];
105f693c922Shikaru for (j = 0; j < dev->nunits; j++) {
10661ff6cfaSjmcneill if (fdt_p && (dev->flags & IOBUS_DEV_FDT) == 0)
10761ff6cfaSjmcneill continue;
10861ff6cfaSjmcneill
109f693c922Shikaru aa.aa_name = dev->name;
110f693c922Shikaru aa.aa_unitno = j;
111f693c922Shikaru aa.aa_unit = &dev->units[j];
112f693c922Shikaru aa.aa_bust = iobus_bust;
113f693c922Shikaru aa.aa_dmat = iobus_dmat;
114f693c922Shikaru
1152685996bSthorpej config_found(self, &aa, iobus_print,
116*c7fb772bSthorpej CFARGS(.submatch = iobus_submatch));
117f693c922Shikaru }
118f693c922Shikaru }
119f693c922Shikaru }
120f693c922Shikaru
121f693c922Shikaru static int
iobus_submatch(device_t parent,struct cfdata * cf,const int * ldesc,void * aux)122eb61b502Ssimonb iobus_submatch(device_t parent, struct cfdata *cf, const int *ldesc, void *aux)
123f693c922Shikaru {
124eb61b502Ssimonb
125f693c922Shikaru return config_match(parent, cf, aux);
126f693c922Shikaru }
127f693c922Shikaru
128f693c922Shikaru static int
iobus_print(void * aux,const char * pnp)129f693c922Shikaru iobus_print(void *aux, const char *pnp)
130f693c922Shikaru {
131f693c922Shikaru struct iobus_attach_args *aa = aux;
132f693c922Shikaru
133f693c922Shikaru if (pnp)
134f693c922Shikaru aprint_normal("%s at %s", aa->aa_name, pnp);
135f693c922Shikaru
1362d299731Smatt aprint_normal(" address 0x%016" PRIx64, aa->aa_unit->addr);
137f693c922Shikaru
138f693c922Shikaru return UNCONF;
139f693c922Shikaru }
140f693c922Shikaru
141f693c922Shikaru /* ---- */
142f693c922Shikaru
143f693c922Shikaru void
iobus_init(struct iobus_softc * sc)144f693c922Shikaru iobus_init(struct iobus_softc *sc)
145f693c922Shikaru {
146eb61b502Ssimonb
147f693c922Shikaru iobus_init_map(sc);
148f693c922Shikaru iobus_init_local(sc);
149f693c922Shikaru }
150f693c922Shikaru
151f693c922Shikaru void
iobus_init_map(struct iobus_softc * sc)152f693c922Shikaru iobus_init_map(struct iobus_softc *sc)
153f693c922Shikaru {
154eb61b502Ssimonb
155f693c922Shikaru /* XXX map all ``operations'' space at once */
156f693c922Shikaru bus_space_map(
157f693c922Shikaru iobus_bust,
158f693c922Shikaru 0x0001280000000000ULL,
159f693c922Shikaru 0x0001800000000000ULL - 0x0001280000000000ULL,
160f693c922Shikaru 0,
161f693c922Shikaru &sc->sc_ops_bush);
162f693c922Shikaru }
163f693c922Shikaru
164f693c922Shikaru void
iobus_init_local(struct iobus_softc * sc)165f693c922Shikaru iobus_init_local(struct iobus_softc *sc)
166f693c922Shikaru {
167eb61b502Ssimonb
168f693c922Shikaru iobus_init_local_pow(sc);
169f693c922Shikaru iobus_init_local_fpa(sc);
170f693c922Shikaru }
171f693c922Shikaru
172f693c922Shikaru extern struct octeon_config octeon_configuration;
173f693c922Shikaru
174f693c922Shikaru void
iobus_init_local_pow(struct iobus_softc * sc)175f693c922Shikaru iobus_init_local_pow(struct iobus_softc *sc)
176f693c922Shikaru {
177eb61b502Ssimonb
1783f508e4dSsimonb void octpow_bootstrap(struct octeon_config *);
179f693c922Shikaru
180f693c922Shikaru aprint_normal("%s: initializing POW\n", device_xname(sc->sc_dev));
181f693c922Shikaru
1823f508e4dSsimonb octpow_bootstrap(&octeon_configuration);
183f693c922Shikaru }
184f693c922Shikaru
185f693c922Shikaru void
iobus_init_local_fpa(struct iobus_softc * sc)186f693c922Shikaru iobus_init_local_fpa(struct iobus_softc *sc)
187f693c922Shikaru {
188eb61b502Ssimonb
1893f508e4dSsimonb void octfpa_bootstrap(struct octeon_config *);
190f693c922Shikaru
191f693c922Shikaru aprint_normal("%s: initializing FPA\n", device_xname(sc->sc_dev));
192f693c922Shikaru
1933f508e4dSsimonb octfpa_bootstrap(&octeon_configuration);
194f693c922Shikaru }
195f693c922Shikaru
196f693c922Shikaru /* ---- bus_space(9) */
197f693c922Shikaru
198f693c922Shikaru #define CHIP iobus
199f693c922Shikaru #define CHIP_IO
200f693c922Shikaru #define CHIP_ACCESS_SIZE 8
201f693c922Shikaru
202f693c922Shikaru /* CIU and GPIO NCB type CSRs */
203f693c922Shikaru #define CHIP_W1_BUS_START(v) 0x0001070000000000ULL
204f693c922Shikaru #define CHIP_W1_BUS_END(v) 0x00010700ffffffffULL
205f693c922Shikaru #define CHIP_W1_SYS_START(v) 0x8001070000000000ULL
206f693c922Shikaru #define CHIP_W1_SYS_END(v) 0x80010700ffffffffULL
207f693c922Shikaru
208f693c922Shikaru /* a number of RSL type CSRs */
209f693c922Shikaru #define CHIP_W2_BUS_START(v) 0x0001180000000000ULL
210f693c922Shikaru #define CHIP_W2_BUS_END(v) 0x000118ffffffffffULL
211f693c922Shikaru #define CHIP_W2_SYS_START(v) 0x8001180000000000ULL
212f693c922Shikaru #define CHIP_W2_SYS_END(v) 0x800118ffffffffffULL
213f693c922Shikaru
214f693c922Shikaru /* load/IOBDMA/store operations */
215f693c922Shikaru #define CHIP_W3_BUS_START(v) 0x0001280000000000ULL
216f693c922Shikaru #define CHIP_W3_BUS_END(v) 0x00017fffffffffffULL
217f693c922Shikaru #define CHIP_W3_SYS_START(v) 0x8001280000000000ULL
218f693c922Shikaru #define CHIP_W3_SYS_END(v) 0x80017fffffffffffULL
219f693c922Shikaru
220f693c922Shikaru #include <mips/mips/bus_space_alignstride_chipdep.c>
221