lebuffer.c revision 1.4
1/* $NetBSD: lebuffer.c,v 1.4 1998/07/29 18:33:27 pk Exp $ */ 2 3/*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Paul Kranenburg. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/types.h> 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/errno.h> 44#include <sys/ioctl.h> 45#include <sys/device.h> 46#include <sys/malloc.h> 47#include <sys/buf.h> 48#include <sys/proc.h> 49#include <sys/user.h> 50 51#include <machine/bus.h> 52#include <machine/autoconf.h> 53#include <machine/cpu.h> 54 55#include <dev/sbus/sbusvar.h> 56#include <dev/sbus/lebuffervar.h> 57 58int lebufprint __P((void *, const char *)); 59int lebufmatch __P((struct device *, struct cfdata *, void *)); 60void lebufattach __P((struct device *, struct device *, void *)); 61 62struct cfattach lebuffer_ca = { 63 sizeof(struct lebuf_softc), lebufmatch, lebufattach 64}; 65 66int 67lebufprint(aux, busname) 68 void *aux; 69 const char *busname; 70{ 71 struct sbus_attach_args *sa = aux; 72 bus_space_tag_t t = sa->sa_bustag; 73 struct lebuf_softc *sc = t->cookie; 74 75 sa->sa_bustag = sc->sc_bustag; /* XXX */ 76 sbus_print(aux, busname); /* XXX */ 77 sa->sa_bustag = t; /* XXX */ 78 return (UNCONF); 79} 80 81int 82lebufmatch(parent, cf, aux) 83 struct device *parent; 84 struct cfdata *cf; 85 void *aux; 86{ 87 struct sbus_attach_args *sa = aux; 88 89 return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0); 90} 91 92/* 93 * Attach all the sub-devices we can find 94 */ 95void 96lebufattach(parent, self, aux) 97 struct device *parent, *self; 98 void *aux; 99{ 100 struct sbus_attach_args *sa = aux; 101 struct lebuf_softc *sc = (void *)self; 102 int node; 103 int sbusburst; 104 bus_space_tag_t sbt; 105 bus_space_handle_t bh; 106 struct bootpath *bp; 107 108 sc->sc_bustag = sa->sa_bustag; 109 sc->sc_dmatag = sa->sa_dmatag; 110 111 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 112 sa->sa_offset, 113 sa->sa_size, 114 0, 0, &bh) != 0) { 115 printf("%s: attach: cannot map registers\n", self->dv_xname); 116 return; 117 } 118 119 /* 120 * This device's "register space" is just a buffer where the 121 * Lance ring-buffers can be stored. Note the buffer's location 122 * and size, so the `le' driver can pick them up. 123 */ 124 sc->sc_buffer = (caddr_t)bh; 125 sc->sc_bufsiz = sa->sa_size; 126 127 node = sc->sc_node = sa->sa_node; 128 129 /* 130 * Get transfer burst size from PROM 131 */ 132 sbusburst = ((struct sbus_softc *)parent)->sc_burst; 133 if (sbusburst == 0) 134 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */ 135 136 sc->sc_burst = getpropint(node, "burst-sizes", -1); 137 if (sc->sc_burst == -1) 138 /* take SBus burst sizes */ 139 sc->sc_burst = sbusburst; 140 141 /* Clamp at parent's burst sizes */ 142 sc->sc_burst &= sbusburst; 143 144 sbus_establish(&sc->sc_sd, &sc->sc_dev); 145 146 /* Propagate bootpath */ 147 if (sa->sa_bp != NULL) 148 bp = sa->sa_bp + 1; 149 else 150 bp = NULL; 151 152 /* Allocate a bus tag */ 153 sbt = (bus_space_tag_t) 154 malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT); 155 if (sbt == NULL) { 156 printf("%s: attach: out of memory\n", self->dv_xname); 157 return; 158 } 159 160 printf(": %dK memory\n", sc->sc_bufsiz / 1024); 161 162 bzero(sbt, sizeof *sbt); 163 sbt->cookie = sc; 164 sbt->parent = sc->sc_bustag; 165 166 /* search through children */ 167 for (node = firstchild(node); node; node = nextsibling(node)) { 168 struct sbus_attach_args sa; 169 sbus_setup_attach_args((struct sbus_softc *)parent, 170 sbt, sc->sc_dmatag, node, bp, &sa); 171 (void)config_found(&sc->sc_dev, (void *)&sa, lebufprint); 172 sbus_destroy_attach_args(&sa); 173 } 174} 175