1 /* $OpenBSD: octpip.c,v 1.3 2020/09/08 13:54:48 visa 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 paddr_t addr; 61 uint32_t ifindex; 62 int node; 63 64 printf("\n"); 65 66 for (node = OF_child(faa->fa_node); node != 0; node = OF_peer(node)) { 67 if (!OF_is_compatible(node, "cavium,octeon-3860-pip-interface")) 68 continue; 69 70 ifindex = OF_getpropint(node, "reg", (uint32_t)-1); 71 if (ifindex < 2) 72 addr = GMX0_BASE_PORT0 + GMX_BLOCK_SIZE * ifindex; 73 else if (ifindex == 4) 74 addr = AGL_BASE; 75 else 76 continue; 77 78 memset(&iaa, 0, sizeof(iaa)); 79 iaa.aa_name = "octgmx"; 80 iaa.aa_bust = faa->fa_iot; 81 iaa.aa_dmat = faa->fa_dmat; 82 iaa.aa_addr = addr; 83 iaa.aa_irq = -1; 84 iaa.aa_unitno = ifindex; 85 config_found(self, &iaa, octpip_print); 86 } 87 } 88 89 int 90 octpip_print(void *aux, const char *parentname) 91 { 92 struct iobus_attach_args *iaa = aux; 93 94 if (parentname != NULL) 95 printf("%s at %s", iaa->aa_name, parentname); 96 printf(" interface %d", iaa->aa_unitno); 97 98 return UNCONF; 99 } 100