11.41Sthorpej/* $NetBSD: lebuffer.c,v 1.41 2022/09/25 18:03:04 thorpej Exp $ */ 21.1Smrg 31.3Spk/*- 41.3Spk * Copyright (c) 1998 The NetBSD Foundation, Inc. 51.3Spk * All rights reserved. 61.3Spk * 71.3Spk * This code is derived from software contributed to The NetBSD Foundation 81.3Spk * by Paul Kranenburg. 91.1Smrg * 101.1Smrg * Redistribution and use in source and binary forms, with or without 111.1Smrg * modification, are permitted provided that the following conditions 121.1Smrg * are met: 131.1Smrg * 1. Redistributions of source code must retain the above copyright 141.1Smrg * notice, this list of conditions and the following disclaimer. 151.1Smrg * 2. Redistributions in binary form must reproduce the above copyright 161.1Smrg * notice, this list of conditions and the following disclaimer in the 171.1Smrg * documentation and/or other materials provided with the distribution. 181.1Smrg * 191.3Spk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.3Spk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.3Spk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.3Spk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.3Spk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.3Spk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.3Spk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.3Spk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.3Spk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.3Spk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.3Spk * POSSIBILITY OF SUCH DAMAGE. 301.1Smrg */ 311.9Slukem 321.9Slukem#include <sys/cdefs.h> 331.41Sthorpej__KERNEL_RCSID(0, "$NetBSD: lebuffer.c,v 1.41 2022/09/25 18:03:04 thorpej Exp $"); 341.1Smrg 351.1Smrg#include <sys/param.h> 361.1Smrg#include <sys/systm.h> 371.1Smrg#include <sys/kernel.h> 381.1Smrg#include <sys/errno.h> 391.1Smrg#include <sys/device.h> 401.1Smrg 411.26Sad#include <sys/bus.h> 421.1Smrg#include <machine/autoconf.h> 431.26Sad#include <sys/cpu.h> 441.1Smrg 451.2Spk#include <dev/sbus/sbusvar.h> 461.1Smrg#include <dev/sbus/lebuffervar.h> 471.1Smrg 481.23Sperryint lebufprint(void *, const char *); 491.32Sceggerint lebufmatch(device_t, cfdata_t, void *); 501.32Sceggervoid lebufattach(device_t, device_t, void *); 511.1Smrg 521.35StsutsuiCFATTACH_DECL_NEW(lebuffer, sizeof(struct lebuf_softc), 531.18Sthorpej lebufmatch, lebufattach, NULL, NULL); 541.1Smrg 551.1Smrgint 561.29Sdsllebufprint(void *aux, const char *busname) 571.1Smrg{ 581.1Smrg 591.22Spk sbus_print(aux, busname); 601.1Smrg return (UNCONF); 611.1Smrg} 621.1Smrg 631.1Smrgint 641.32Sceggerlebufmatch(device_t parent, cfdata_t cf, void *aux) 651.1Smrg{ 661.1Smrg struct sbus_attach_args *sa = aux; 671.1Smrg 681.14Sthorpej return (strcmp(cf->cf_name, sa->sa_name) == 0); 691.1Smrg} 701.1Smrg 711.1Smrg/* 721.1Smrg * Attach all the sub-devices we can find 731.1Smrg */ 741.1Smrgvoid 751.32Sceggerlebufattach(device_t parent, device_t self, void *aux) 761.1Smrg{ 771.1Smrg struct sbus_attach_args *sa = aux; 781.35Stsutsui struct lebuf_softc *sc = device_private(self); 791.33Stsutsui struct sbus_softc *sbsc = device_private(parent); 801.1Smrg int node; 811.1Smrg int sbusburst; 821.22Spk bus_space_tag_t bt = sa->sa_bustag; 831.22Spk bus_dma_tag_t dt = sa->sa_dmatag; 841.1Smrg bus_space_handle_t bh; 851.1Smrg 861.35Stsutsui sc->sc_dev = self; 871.35Stsutsui 881.22Spk if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset, sa->sa_size, 891.12Spk BUS_SPACE_MAP_LINEAR, &bh) != 0) { 901.36Stsutsui aprint_error(": cannot map registers\n"); 911.1Smrg return; 921.1Smrg } 931.1Smrg 941.1Smrg /* 951.1Smrg * This device's "register space" is just a buffer where the 961.1Smrg * Lance ring-buffers can be stored. Note the buffer's location 971.1Smrg * and size, so the `le' driver can pick them up. 981.1Smrg */ 991.22Spk sc->sc_buffer = bus_space_vaddr(bt, bh); 1001.1Smrg sc->sc_bufsiz = sa->sa_size; 1011.1Smrg 1021.1Smrg node = sc->sc_node = sa->sa_node; 1031.1Smrg 1041.1Smrg /* 1051.1Smrg * Get transfer burst size from PROM 1061.1Smrg */ 1071.33Stsutsui sbusburst = sbsc->sc_burst; 1081.1Smrg if (sbusburst == 0) 1091.1Smrg sbusburst = SBUS_BURST_32 - 1; /* 1->16 */ 1101.1Smrg 1111.19Spk sc->sc_burst = prom_getpropint(node, "burst-sizes", -1); 1121.1Smrg if (sc->sc_burst == -1) 1131.1Smrg /* take SBus burst sizes */ 1141.1Smrg sc->sc_burst = sbusburst; 1151.1Smrg 1161.1Smrg /* Clamp at parent's burst sizes */ 1171.1Smrg sc->sc_burst &= sbusburst; 1181.1Smrg 1191.1Smrg printf(": %dK memory\n", sc->sc_bufsiz / 1024); 1201.1Smrg 1211.1Smrg /* search through children */ 1221.40Sthorpej devhandle_t selfh = device_handle(self); 1231.1Smrg for (node = firstchild(node); node; node = nextsibling(node)) { 1241.24Schristos struct sbus_attach_args sax; 1251.33Stsutsui sbus_setup_attach_args(sbsc, 1261.24Schristos bt, dt, node, &sax); 1271.38Sthorpej (void)config_found(self, (void *)&sax, lebufprint, 1281.40Sthorpej CFARGS(.devhandle = prom_node_to_devhandle(selfh, node))); 1291.24Schristos sbus_destroy_attach_args(&sax); 1301.1Smrg } 1311.1Smrg} 132