Home | History | Annotate | Line # | Download | only in xscale
      1 /*	$NetBSD: ixp425_ixme.c,v 1.7 2021/08/07 16:18:46 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Steve C. Woodford.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: ixp425_ixme.c,v 1.7 2021/08/07 16:18:46 thorpej Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/device.h>
     39 
     40 #define _ARM32_BUS_DMA_PRIVATE
     41 #include <sys/bus.h>
     42 
     43 #include <arm/xscale/ixp425var.h>
     44 #include <arm/xscale/ixp425_qmgr.h>
     45 #include <arm/xscale/ixp425_ixmevar.h>
     46 
     47 #include "locators.h"
     48 
     49 static int	ixme_match(device_t, cfdata_t, void *);
     50 static void	ixme_attach(device_t, device_t, void *);
     51 static int	ixme_search(device_t, cfdata_t, const int *, void *);
     52 static int	ixme_print(void *, const char *);
     53 
     54 struct ixme_softc {
     55 	struct arm32_dma_range sc_dr;
     56 	struct arm32_bus_dma_tag sc_dt;
     57 	void *sc_qmgr;
     58 };
     59 
     60 CFATTACH_DECL_NEW(ixme, sizeof(struct ixme_softc),
     61     ixme_match, ixme_attach, NULL, NULL);
     62 
     63 static int
     64 ixme_match(device_t parent, cfdata_t self, void *arg)
     65 {
     66 
     67 	return (1);
     68 }
     69 
     70 static void
     71 ixme_attach(device_t parent, device_t self, void *arg)
     72 {
     73 	struct ixme_softc *sc = device_private(self);
     74 	extern paddr_t physical_start, physical_end;
     75 
     76 	aprint_naive("\n");
     77 	aprint_normal(": IXP4xx MicroEngine Support\n");
     78 
     79 	sc->sc_qmgr = ixpqmgr_init(&ixp425_bs_tag);
     80 	if (sc->sc_qmgr == NULL) {
     81 		panic("%s: ixme_attach: Failed to init Queue Manager",
     82 		    device_xname(self));
     83 	}
     84 
     85 	sc->sc_dr.dr_sysbase = physical_start;
     86 	sc->sc_dr.dr_busbase = 0;
     87 	sc->sc_dr.dr_len = physical_end - physical_start;
     88 	sc->sc_dt._ranges = &sc->sc_dr;
     89 	sc->sc_dt._nranges = 1;
     90 
     91 	sc->sc_dt._dmamap_create = _bus_dmamap_create;
     92 	sc->sc_dt._dmamap_destroy = _bus_dmamap_destroy;
     93 	sc->sc_dt._dmamap_load = _bus_dmamap_load;
     94 	sc->sc_dt._dmamap_load_mbuf = _bus_dmamap_load_mbuf;
     95 	sc->sc_dt._dmamap_load_uio = _bus_dmamap_load_uio;
     96 	sc->sc_dt._dmamap_load_raw = _bus_dmamap_load_raw;
     97 	sc->sc_dt._dmamap_unload = _bus_dmamap_unload;
     98 	sc->sc_dt._dmamap_sync_pre = _bus_dmamap_sync;
     99 	sc->sc_dt._dmamap_sync_post = NULL;
    100 
    101 	sc->sc_dt._dmamem_alloc = _bus_dmamem_alloc;
    102 	sc->sc_dt._dmamem_free = _bus_dmamem_free;
    103 	sc->sc_dt._dmamem_map = _bus_dmamem_map;
    104 	sc->sc_dt._dmamem_unmap = _bus_dmamem_unmap;
    105 	sc->sc_dt._dmamem_mmap = _bus_dmamem_mmap;
    106 
    107 	sc->sc_dt._dmatag_subregion = _bus_dmatag_subregion;
    108 	sc->sc_dt._dmatag_destroy = _bus_dmatag_destroy;
    109 
    110 	config_search(self, NULL,
    111 	    CFARGS(.search = ixme_search));
    112 }
    113 
    114 static int
    115 ixme_search(device_t parent, cfdata_t cf, const int *ldesc, void *arg)
    116 {
    117 	struct ixme_softc *sc = device_private(parent);
    118 	struct ixme_attach_args ixa;
    119 
    120 	if (cf->cf_loc[IXMECF_NPE] < 0 || cf->cf_loc[IXMECF_NPE] > 2)
    121 		return (0);
    122 
    123 	ixa.ixa_iot = &ixp425_bs_tag;
    124 	ixa.ixa_dt = &sc->sc_dt;
    125 	ixa.ixa_npe = cf->cf_loc[IXMECF_NPE];
    126 
    127 	if (config_probe(parent, cf, &ixa)) {
    128 		config_attach(parent, cf, &ixa, ixme_print, CFARGS_NONE);
    129 		return (1);
    130 	}
    131 
    132 	return (0);
    133 }
    134 
    135 static int
    136 ixme_print(void *arg, const char *name)
    137 {
    138 	struct ixme_attach_args *ixa = arg;
    139 
    140 	aprint_normal(" NPE-%c", 'A' + ixa->ixa_npe);
    141 
    142 	return (UNCONF);
    143 }
    144