1 1.7 thorpej /* $NetBSD: sbdio.c,v 1.7 2021/08/07 16:18:53 thorpej Exp $ */ 2 1.1 tsutsui 3 1.1 tsutsui /*- 4 1.1 tsutsui * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc. 5 1.1 tsutsui * All rights reserved. 6 1.1 tsutsui * 7 1.1 tsutsui * This code is derived from software contributed to The NetBSD Foundation 8 1.1 tsutsui * by UCHIYAMA Yasushi. 9 1.1 tsutsui * 10 1.1 tsutsui * Redistribution and use in source and binary forms, with or without 11 1.1 tsutsui * modification, are permitted provided that the following conditions 12 1.1 tsutsui * are met: 13 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright 14 1.1 tsutsui * notice, this list of conditions and the following disclaimer. 15 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the 17 1.1 tsutsui * documentation and/or other materials provided with the distribution. 18 1.1 tsutsui * 19 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 tsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 tsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 tsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 tsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 tsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 tsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 tsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 tsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 tsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE. 30 1.1 tsutsui */ 31 1.1 tsutsui 32 1.1 tsutsui #include <sys/cdefs.h> 33 1.7 thorpej __KERNEL_RCSID(0, "$NetBSD: sbdio.c,v 1.7 2021/08/07 16:18:53 thorpej Exp $"); 34 1.5 matt 35 1.5 matt #define _EWS4800MIPS_BUS_DMA_PRIVATE 36 1.1 tsutsui 37 1.1 tsutsui #include <sys/param.h> 38 1.5 matt #include <sys/bus.h> 39 1.5 matt #include <sys/device.h> 40 1.1 tsutsui #include <sys/systm.h> 41 1.5 matt 42 1.5 matt #include <mips/locore.h> 43 1.1 tsutsui 44 1.1 tsutsui #include <machine/autoconf.h> 45 1.1 tsutsui #include <machine/sbdvar.h> 46 1.1 tsutsui #include <machine/sbdiovar.h> 47 1.1 tsutsui 48 1.1 tsutsui #include "ioconf.h" 49 1.1 tsutsui 50 1.1 tsutsui struct sbdio_softc { 51 1.2 tsutsui device_t sc_dev; 52 1.1 tsutsui struct ews4800mips_bus_space sc_bus_tag; 53 1.1 tsutsui struct ews4800mips_bus_dma_tag sc_dma_tag; 54 1.1 tsutsui }; 55 1.1 tsutsui 56 1.2 tsutsui static int sbdio_match(device_t, cfdata_t, void *); 57 1.2 tsutsui static void sbdio_attach(device_t, device_t, void *); 58 1.2 tsutsui static int sbdio_print(void *, const char *); 59 1.1 tsutsui 60 1.2 tsutsui CFATTACH_DECL_NEW(sbdio, sizeof(struct sbdio_softc), 61 1.1 tsutsui sbdio_match, sbdio_attach, NULL, NULL); 62 1.1 tsutsui 63 1.1 tsutsui static int sbdio_found; 64 1.1 tsutsui 65 1.1 tsutsui int 66 1.2 tsutsui sbdio_match(device_t parent, cfdata_t cf, void *aux) 67 1.1 tsutsui { 68 1.1 tsutsui struct mainbus_attach_args *ma = aux; 69 1.1 tsutsui 70 1.1 tsutsui if (sbdio_found != 0) 71 1.1 tsutsui return 0; 72 1.1 tsutsui 73 1.1 tsutsui if (strcmp(ma->ma_name, sbdio_cd.cd_name) != 0) 74 1.1 tsutsui return 0; 75 1.1 tsutsui 76 1.1 tsutsui if (platform.sbdiodevs == NULL) 77 1.1 tsutsui return 0; 78 1.1 tsutsui 79 1.1 tsutsui return 1; 80 1.1 tsutsui } 81 1.1 tsutsui 82 1.1 tsutsui void 83 1.2 tsutsui sbdio_attach(device_t parent, device_t self, void *aux) 84 1.1 tsutsui { 85 1.2 tsutsui struct sbdio_softc *sc = device_private(self); 86 1.1 tsutsui struct sbdio_attach_args sa; 87 1.1 tsutsui const struct sbdiodevdesc *sd; 88 1.1 tsutsui 89 1.1 tsutsui sbdio_found = 1; 90 1.1 tsutsui 91 1.2 tsutsui sc->sc_dev = self; 92 1.2 tsutsui aprint_normal("\n"); 93 1.1 tsutsui 94 1.1 tsutsui /* structure assignment */ 95 1.1 tsutsui sc->sc_dma_tag = ews4800mips_default_bus_dma_tag; 96 1.1 tsutsui 97 1.2 tsutsui bus_space_create(&sc->sc_bus_tag, device_xname(sc->sc_dev), 98 1.1 tsutsui MIPS_KSEG1_START, MIPS_KSEG2_START - MIPS_KSEG1_START); /* XXX */ 99 1.1 tsutsui 100 1.1 tsutsui for (sd = platform.sbdiodevs; sd->sd_name != NULL; sd++) { 101 1.1 tsutsui sa.sa_name = sd->sd_name; 102 1.1 tsutsui sa.sa_bust = &sc->sc_bus_tag; 103 1.1 tsutsui sa.sa_dmat = &sc->sc_dma_tag; 104 1.1 tsutsui sa.sa_addr1 = sd->sd_addr1; 105 1.1 tsutsui sa.sa_addr2 = sd->sd_addr2; 106 1.1 tsutsui sa.sa_irq = sd->sd_irq; 107 1.1 tsutsui sa.sa_flags = sd->sd_flags; 108 1.7 thorpej config_found(self, &sa, sbdio_print, CFARGS_NONE); 109 1.1 tsutsui } 110 1.1 tsutsui } 111 1.1 tsutsui 112 1.1 tsutsui int 113 1.1 tsutsui sbdio_print(void *aux, const char *pnp) 114 1.1 tsutsui { 115 1.2 tsutsui struct sbdio_attach_args *sa = aux; 116 1.2 tsutsui 117 1.2 tsutsui if (sa->sa_addr1 != (paddr_t)-1) { 118 1.4 matt aprint_normal(" at %#"PRIxPADDR, sa->sa_addr1); 119 1.2 tsutsui if (sa->sa_addr2 != (paddr_t)-1) 120 1.4 matt aprint_normal(", %#"PRIxPADDR, sa->sa_addr2); 121 1.2 tsutsui } 122 1.2 tsutsui if (sa->sa_irq != -1) 123 1.2 tsutsui aprint_normal(" irq %d", sa->sa_irq); 124 1.1 tsutsui 125 1.1 tsutsui return pnp ? QUIET : UNCONF; 126 1.1 tsutsui } 127