mainbus.c revision 1.2
1/* $NetBSD: mainbus.c,v 1.2 2020/07/16 11:49:37 jmcneill Exp $ */ 2 3/* 4 * Copyright (c) 2007 5 * Internet Initiative Japan, Inc. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> 30__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2020/07/16 11:49:37 jmcneill Exp $"); 31 32#define _MIPS_BUS_DMA_PRIVATE 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/device.h> 37#include <sys/bus.h> 38 39#include <mips/cavium/include/mainbusvar.h> 40 41#include <dev/fdt/fdtvar.h> 42 43static int mainbus_match(device_t, struct cfdata *, void *); 44static void mainbus_attach(device_t, device_t, void *); 45static void mainbus_attach_static(device_t); 46static void mainbus_attach_devicetree(device_t); 47static int mainbus_submatch(device_t, cfdata_t, const int *, void *); 48static int mainbus_print(void *, const char *); 49 50static void simplebus_bus_io_init(bus_space_tag_t, void *); 51 52CFATTACH_DECL_NEW(mainbus, sizeof(device_t), mainbus_match, mainbus_attach, 53 NULL, NULL); 54 55static struct mips_bus_space simplebus_bus_tag; 56 57static struct mips_bus_dma_tag simplebus_dma_tag = { 58 ._cookie = NULL, 59 ._wbase = 0, 60 ._bounce_alloc_lo = 0, 61 ._bounce_alloc_hi = 0, 62 ._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER, 63 ._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER, 64 ._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER, 65}; 66 67static int 68mainbus_match(device_t parent, struct cfdata *match, void *aux) 69{ 70 static int once = 0; 71 72 if (once != 0) 73 return 0; 74 once = 1; 75 76 return 1; 77} 78 79static void 80mainbus_attach(device_t parent, device_t self, void *aux) 81{ 82 aprint_normal("\n"); 83 84 if (fdtbus_get_data() != NULL) { 85 mainbus_attach_devicetree(self); 86 } else { 87 mainbus_attach_static(self); 88 } 89} 90 91static void 92mainbus_attach_static(device_t self) 93{ 94 struct mainbus_attach_args aa; 95 int i; 96 97 for (i = 0; i < (int)mainbus_ndevs; i++) { 98 aa.aa_name = mainbus_devs[i]; 99 config_found_sm_loc(self, "mainbus", NULL, &aa, 100 mainbus_print, mainbus_submatch); 101 } 102} 103 104extern struct octeon_config octeon_configuration; 105extern void octpow_bootstrap(struct octeon_config *); 106extern void octfpa_bootstrap(struct octeon_config *); 107 108static void 109mainbus_attach_devicetree(device_t self) 110{ 111 struct mainbus_attach_args aa; 112 struct fdt_attach_args faa; 113 114 aa.aa_name = "cpunode"; 115 config_found_sm_loc(self, "mainbus", NULL, &aa, mainbus_print, 116 mainbus_submatch); 117 118 octpow_bootstrap(&octeon_configuration); 119 octfpa_bootstrap(&octeon_configuration); 120 121 simplebus_bus_io_init(&simplebus_bus_tag, NULL); 122 123 faa.faa_bst = &simplebus_bus_tag; 124 faa.faa_a4x_bst = NULL; /* XXX */ 125 faa.faa_dmat = &simplebus_dma_tag; 126 faa.faa_name = ""; 127 faa.faa_phandle = OF_peer(0); 128 config_found(self, &faa, NULL); 129} 130 131static int 132mainbus_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux) 133{ 134 struct mainbus_attach_args *aa = aux; 135 136 if (strcmp(cf->cf_name, aa->aa_name) != 0) 137 return 0; 138 139 return config_match(parent, cf, aux); 140} 141 142static int 143mainbus_print(void *aux, const char *pnp) 144{ 145 struct mainbus_attach_args *aa = aux; 146 147 if (pnp != 0) 148 return QUIET; 149 150 if (pnp) 151 aprint_normal("%s at %s", aa->aa_name, pnp); 152 153 return UNCONF; 154} 155 156/* ---- bus_space(9) */ 157#define CHIP simplebus 158#define CHIP_IO 159#define CHIP_ACCESS_SIZE 8 160 161#define CHIP_W1_BUS_START(v) 0x0000000000000000ULL 162#define CHIP_W1_BUS_END(v) 0x7fffffffffffffffULL 163#define CHIP_W1_SYS_START(v) 0x8000000000000000ULL 164#define CHIP_W1_SYS_END(v) 0xffffffffffffffffULL 165 166#include <mips/mips/bus_space_alignstride_chipdep.c> 167