Home | History | Annotate | Line # | Download | only in cavium
      1  1.3  thorpej /*	$NetBSD: octeon_bootbus.c,v 1.3 2021/08/07 16:18:59 thorpej Exp $	*/
      2  1.1   hikaru 
      3  1.1   hikaru /*
      4  1.1   hikaru  * Copyright (c) 2007
      5  1.1   hikaru  *      Internet Initiative Japan, Inc.  All rights reserved.
      6  1.1   hikaru  *
      7  1.1   hikaru  * Redistribution and use in source and binary forms, with or without
      8  1.1   hikaru  * modification, are permitted provided that the following conditions
      9  1.1   hikaru  * are met:
     10  1.1   hikaru  * 1. Redistributions of source code must retain the above copyright
     11  1.1   hikaru  *    notice, this list of conditions and the following disclaimer.
     12  1.1   hikaru  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1   hikaru  *    notice, this list of conditions and the following disclaimer in the
     14  1.1   hikaru  *    documentation and/or other materials provided with the distribution.
     15  1.1   hikaru  *
     16  1.1   hikaru  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     17  1.1   hikaru  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1   hikaru  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1   hikaru  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     20  1.1   hikaru  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1   hikaru  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1   hikaru  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1   hikaru  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1   hikaru  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1   hikaru  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1   hikaru  * SUCH DAMAGE.
     27  1.1   hikaru  */
     28  1.1   hikaru 
     29  1.1   hikaru #include <sys/cdefs.h>
     30  1.3  thorpej __KERNEL_RCSID(0, "$NetBSD: octeon_bootbus.c,v 1.3 2021/08/07 16:18:59 thorpej Exp $");
     31  1.1   hikaru 
     32  1.1   hikaru #include "locators.h"
     33  1.1   hikaru 
     34  1.1   hikaru #include <sys/param.h>
     35  1.1   hikaru #include <sys/systm.h>
     36  1.1   hikaru #include <sys/device.h>
     37  1.1   hikaru 
     38  1.1   hikaru #define _MIPS_BUS_DMA_PRIVATE
     39  1.1   hikaru #include <sys/bus.h>
     40  1.1   hikaru 
     41  1.1   hikaru #include <mips/cavium/octeonvar.h>
     42  1.1   hikaru #include <mips/cavium/include/bootbusvar.h>
     43  1.1   hikaru 
     44  1.1   hikaru static int	bootbus_match(device_t, struct cfdata *, void *);
     45  1.1   hikaru static void	bootbus_attach(device_t, device_t, void *);
     46  1.1   hikaru static int      bootbus_submatch(device_t, struct cfdata *,
     47  1.1   hikaru 		    const int *, void *);
     48  1.1   hikaru static int	bootbus_print(void *, const char *);
     49  1.1   hikaru static void	bootbus_init(void);
     50  1.1   hikaru 
     51  1.1   hikaru static void	bootbus_bus_io_init(bus_space_tag_t, void *);
     52  1.1   hikaru 
     53  1.1   hikaru static struct mips_bus_space	*bootbus_bust;
     54  1.1   hikaru static struct mips_bus_dma_tag	*bootbus_dmat;
     55  1.1   hikaru 
     56  1.1   hikaru void
     57  1.1   hikaru bootbus_bootstrap(struct octeon_config *mcp)
     58  1.1   hikaru {
     59  1.1   hikaru 
     60  1.1   hikaru 	bootbus_bus_io_init(&mcp->mc_bootbus_bust, mcp);
     61  1.1   hikaru 
     62  1.1   hikaru 	bootbus_bust = &mcp->mc_bootbus_bust;
     63  1.1   hikaru 	bootbus_dmat = &mcp->mc_bootbus_dmat;
     64  1.1   hikaru }
     65  1.1   hikaru 
     66  1.1   hikaru /* ---- autoconf */
     67  1.1   hikaru 
     68  1.1   hikaru CFATTACH_DECL_NEW(bootbus, sizeof(device_t), bootbus_match, bootbus_attach, NULL,
     69  1.1   hikaru     NULL);
     70  1.1   hikaru 
     71  1.1   hikaru static int
     72  1.1   hikaru bootbus_match(device_t parent, struct cfdata *match, void *aux)
     73  1.1   hikaru {
     74  1.1   hikaru 
     75  1.1   hikaru 	return 1;
     76  1.1   hikaru }
     77  1.1   hikaru 
     78  1.1   hikaru static void
     79  1.1   hikaru bootbus_attach(device_t parent, device_t self, void *aux)
     80  1.1   hikaru {
     81  1.1   hikaru 	const struct bootbus_dev *dev;
     82  1.1   hikaru 	struct bootbus_attach_args aa;
     83  1.1   hikaru 	int i, j;
     84  1.1   hikaru 
     85  1.1   hikaru 	aprint_normal("\n");
     86  1.1   hikaru 
     87  1.1   hikaru 	bootbus_init();
     88  1.1   hikaru 
     89  1.1   hikaru 	for (i = 0; i < (int)bootbus_ndevs; i++) {
     90  1.1   hikaru 		dev = bootbus_devs[i];
     91  1.1   hikaru 		for (j = 0; j < dev->nunits; j++) {
     92  1.1   hikaru 			aa.aa_name = dev->name;
     93  1.1   hikaru 			aa.aa_unitno = j;
     94  1.1   hikaru 			aa.aa_unit = &dev->units[j];
     95  1.1   hikaru 			aa.aa_bust = bootbus_bust;
     96  1.1   hikaru 			aa.aa_dmat = bootbus_dmat;
     97  1.1   hikaru 
     98  1.2  thorpej 			config_found(self, &aa, bootbus_print,
     99  1.3  thorpej 			    CFARGS(.submatch = bootbus_submatch));
    100  1.1   hikaru 		}
    101  1.1   hikaru 	}
    102  1.1   hikaru }
    103  1.1   hikaru 
    104  1.1   hikaru static int
    105  1.1   hikaru bootbus_submatch(device_t parent, struct cfdata *cf,
    106  1.1   hikaru     const int *ldesc, void *aux)
    107  1.1   hikaru {
    108  1.1   hikaru 
    109  1.1   hikaru 	return config_match(parent, cf, aux);
    110  1.1   hikaru }
    111  1.1   hikaru 
    112  1.1   hikaru static int
    113  1.1   hikaru bootbus_print(void *aux, const char *pnp)
    114  1.1   hikaru {
    115  1.1   hikaru 	struct bootbus_attach_args *aa = aux;
    116  1.1   hikaru 
    117  1.1   hikaru 	if (pnp)
    118  1.1   hikaru 		aprint_normal("%s at %s", aa->aa_name, pnp);
    119  1.1   hikaru 
    120  1.1   hikaru 	aprint_normal(": address=0x%016" PRIx64, aa->aa_unit->addr);
    121  1.1   hikaru 
    122  1.1   hikaru 	return UNCONF;
    123  1.1   hikaru }
    124  1.1   hikaru 
    125  1.1   hikaru static void
    126  1.1   hikaru bootbus_init(void)
    127  1.1   hikaru {
    128  1.1   hikaru 
    129  1.1   hikaru }
    130  1.1   hikaru 
    131  1.1   hikaru 
    132  1.1   hikaru /* ---- bus_space(9) */
    133  1.1   hikaru 
    134  1.1   hikaru #define	CHIP	bootbus
    135  1.1   hikaru #define	CHIP_IO
    136  1.1   hikaru #define	CHIP_ACCESS_SIZE	8
    137  1.1   hikaru 
    138  1.1   hikaru #define	CHIP_W1_BUS_START(v)	0x0000000000000000ULL
    139  1.1   hikaru #define	CHIP_W1_BUS_END(v)	0x000000001fffffffULL
    140  1.1   hikaru #define	CHIP_W1_SYS_START(v)	0x00000000a0000000ULL
    141  1.1   hikaru #define	CHIP_W1_SYS_END(v)	0x00000000bfffffffULL
    142  1.1   hikaru 
    143  1.1   hikaru #include <mips/mips/bus_space_alignstride_chipdep.c>
    144