xref: /openbsd-src/sys/arch/octeon/dev/octpip.c (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /*	$OpenBSD: octpip.c,v 1.2 2019/09/28 22:20:25 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 2019 Visa Hankala
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/param.h>
20 #include <sys/systm.h>
21 #include <sys/device.h>
22 
23 #include <dev/ofw/fdt.h>
24 #include <dev/ofw/openfirm.h>
25 
26 #include <machine/fdt.h>
27 
28 #include <octeon/dev/iobusvar.h>
29 #include <octeon/dev/cn30xxgmxreg.h>
30 
31 struct octpip_softc {
32 	struct device		 sc_dev;
33 };
34 
35 int	 octpip_match(struct device *, void *, void *);
36 void	 octpip_attach(struct device *, struct device *, void *);
37 int	 octpip_print(void *, const char *);
38 
39 const struct cfattach octpip_ca = {
40 	sizeof(struct octpip_softc), octpip_match, octpip_attach
41 };
42 
43 struct cfdriver octpip_cd = {
44 	NULL, "octpip", DV_DULL
45 };
46 
47 int
48 octpip_match(struct device *parent, void *match, void *aux)
49 {
50 	struct fdt_attach_args *faa = aux;
51 
52 	return OF_is_compatible(faa->fa_node, "cavium,octeon-3860-pip");
53 }
54 
55 void
56 octpip_attach(struct device *parent, struct device *self, void *aux)
57 {
58 	struct iobus_attach_args iaa;
59 	struct fdt_attach_args *faa = aux;
60 	uint32_t ifindex;
61 	int node;
62 
63 	printf("\n");
64 
65 	for (node = OF_child(faa->fa_node); node != 0; node = OF_peer(node)) {
66 		if (!OF_is_compatible(node, "cavium,octeon-3860-pip-interface"))
67 			continue;
68 		ifindex = OF_getpropint(node, "reg", (uint32_t)-1);
69 		if (ifindex >= 16)
70 			continue;
71 		memset(&iaa, 0, sizeof(iaa));
72 		iaa.aa_name = "octgmx";
73 		iaa.aa_bust = faa->fa_iot;
74 		iaa.aa_dmat = faa->fa_dmat;
75 		iaa.aa_addr = GMX0_BASE_PORT0 + GMX_BLOCK_SIZE * ifindex;
76 		iaa.aa_irq = -1;
77 		iaa.aa_unitno = ifindex;
78 		config_found(self, &iaa, octpip_print);
79 	}
80 }
81 
82 int
83 octpip_print(void *aux, const char *parentname)
84 {
85 	struct iobus_attach_args *iaa = aux;
86 
87 	if (parentname != NULL)
88 		printf("%s at %s", iaa->aa_name, parentname);
89 	printf(" interface %d", iaa->aa_unitno);
90 
91 	return UNCONF;
92 }
93