1/* $NetBSD: plumisa_machdep.c,v 1.14 2021/08/07 16:18:54 thorpej Exp $ */ 2 3/*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 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: plumisa_machdep.c,v 1.14 2021/08/07 16:18:54 thorpej Exp $"); 34 35#include <sys/param.h> 36#include <sys/systm.h> 37 38#include <machine/bus.h> 39 40#include <dev/isa/isavar.h> 41#include <dev/isa/isareg.h> 42 43#include <machine/platid.h> 44#include <machine/platid_mask.h> 45 46#include <hpcmips/tx/tx39var.h> 47#include <hpcmips/dev/plumvar.h> 48#include <hpcmips/dev/plumicuvar.h> 49#include <hpcmips/dev/plumiobusvar.h> 50 51#include "locators.h" 52 53int plumisabprint(void *, const char *); 54int plumisabmatch(device_t, cfdata_t, void *); 55void plumisabattach(device_t, device_t, void *); 56 57struct plumisab_softc { 58 plum_chipset_tag_t sc_pc; 59 bus_space_tag_t sc_iot; 60 int sc_irq; 61 void *sc_ih; 62}; 63 64CFATTACH_DECL_NEW(plumisab, sizeof(struct plumisab_softc), 65 plumisabmatch, plumisabattach, NULL, NULL); 66 67int 68plumisabmatch(device_t parent, cfdata_t match, void *aux) 69{ 70 struct plumiobus_attach_args *pba = aux; 71 platid_mask_t mask; 72 73 if (strcmp(pba->pba_busname, match->cf_name)) { 74 return (0); 75 } 76 77 if (match->cf_loc[PLUMIOBUSIFCF_PLATFORM] == 78 PLUMIOBUSIFCF_PLATFORM_DEFAULT) { 79 return (1); 80 } 81 82 mask = PLATID_DEREF(match->cf_loc[PLUMIOBUSIFCF_PLATFORM]); 83 if (platid_match(&platid, &mask)) { 84 return (2); 85 } 86 87 return (0); 88} 89 90void 91plumisabattach(device_t parent, device_t self, void *aux) 92{ 93 struct plumiobus_attach_args *pba = aux; 94 struct plumisab_softc *sc = device_private(self); 95 struct isabus_attach_args iba; 96 97 printf("\n"); 98 sc->sc_pc = pba->pba_pc; 99 sc->sc_iot = pba->pba_iot; 100 sc->sc_irq = pba->pba_irq; 101 printf(" base=%#x irq=%d\n", sc->sc_iot->t_base, sc->sc_irq); 102#if 0 103 /* Reset I/O bus */ 104 plum_power_ioreset(sc->sc_pc); 105#endif 106 /* Dump I/O port */ 107 if (0) { 108 bus_space_handle_t ioh; 109 int i; 110 bus_space_map(sc->sc_iot, 0, 0x400, 0, &ioh); 111 for(i = 0; i < 0x400; i += 4) { 112 printf("[%03x]%02x", i, bus_space_read_1(sc->sc_iot, ioh, i + 3)); 113 printf("%02x", bus_space_read_1(sc->sc_iot, ioh, i + 2)); 114 printf("%02x", bus_space_read_1(sc->sc_iot, ioh, i + 1)); 115 printf("%02x", bus_space_read_1(sc->sc_iot, ioh, i + 0)); 116 } 117 bus_space_unmap(sc->sc_iot, ioh, 0x400); 118 } 119 120 iba.iba_ic = sc; 121 /* Plum ISA-bus don't have memory space! */ 122 /* Plum ISA port space */ 123 iba.iba_iot = sc->sc_iot; 124 config_found(self, &iba, plumisabprint, CFARGS_NONE); 125} 126 127int 128plumisabprint(void *aux, const char *pnp) 129{ 130 131 return (pnp ? QUIET : UNCONF); 132} 133 134void 135isa_attach_hook(device_t parent, device_t self, 136 struct isabus_attach_args *iba) 137{ 138 139} 140 141void 142isa_detach_hook(isa_chipset_tag_t, device_t self) 143{ 144} 145 146void * 147isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level, 148 int (*ih_fun)(void *), void *ih_arg) 149{ 150 struct plumisab_softc *sc = (void*)ic; 151 152 sc->sc_ih = plum_intr_establish(sc->sc_pc, sc->sc_irq, type, level, 153 ih_fun, ih_arg); 154 return (sc->sc_ih); 155} 156 157void 158isa_intr_disestablish(isa_chipset_tag_t ic, void *arg) 159{ 160 struct plumisab_softc *sc = (void*)ic; 161 162 plum_intr_disestablish(sc->sc_pc, arg); 163} 164 165int 166isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq) 167{ 168 struct plumisab_softc *sc = (void*)ic; 169 170 *irq = sc->sc_irq; 171 172 return (0); 173} 174