1 /* $NetBSD: lebuffer.c,v 1.28 2008/04/28 20:23:57 martin 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 * 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: lebuffer.c,v 1.28 2008/04/28 20:23:57 martin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/errno.h> 39 #include <sys/device.h> 40 #include <sys/malloc.h> 41 42 #include <sys/bus.h> 43 #include <machine/autoconf.h> 44 #include <sys/cpu.h> 45 46 #include <dev/sbus/sbusvar.h> 47 #include <dev/sbus/lebuffervar.h> 48 49 int lebufprint(void *, const char *); 50 int lebufmatch(struct device *, struct cfdata *, void *); 51 void lebufattach(struct device *, struct device *, void *); 52 53 CFATTACH_DECL(lebuffer, sizeof(struct lebuf_softc), 54 lebufmatch, lebufattach, NULL, NULL); 55 56 int 57 lebufprint(aux, busname) 58 void *aux; 59 const char *busname; 60 { 61 62 sbus_print(aux, busname); 63 return (UNCONF); 64 } 65 66 int 67 lebufmatch(parent, cf, aux) 68 struct device *parent; 69 struct cfdata *cf; 70 void *aux; 71 { 72 struct sbus_attach_args *sa = aux; 73 74 return (strcmp(cf->cf_name, sa->sa_name) == 0); 75 } 76 77 /* 78 * Attach all the sub-devices we can find 79 */ 80 void 81 lebufattach(parent, self, aux) 82 struct device *parent, *self; 83 void *aux; 84 { 85 struct sbus_attach_args *sa = aux; 86 struct lebuf_softc *sc = (void *)self; 87 int node; 88 int sbusburst; 89 bus_space_tag_t bt = sa->sa_bustag; 90 bus_dma_tag_t dt = sa->sa_dmatag; 91 bus_space_handle_t bh; 92 93 if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset, sa->sa_size, 94 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 95 aprint_error_dev(self, "attach: cannot map registers\n"); 96 return; 97 } 98 99 /* 100 * This device's "register space" is just a buffer where the 101 * Lance ring-buffers can be stored. Note the buffer's location 102 * and size, so the `le' driver can pick them up. 103 */ 104 sc->sc_buffer = bus_space_vaddr(bt, bh); 105 sc->sc_bufsiz = sa->sa_size; 106 107 node = sc->sc_node = sa->sa_node; 108 109 /* 110 * Get transfer burst size from PROM 111 */ 112 sbusburst = ((struct sbus_softc *)parent)->sc_burst; 113 if (sbusburst == 0) 114 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */ 115 116 sc->sc_burst = prom_getpropint(node, "burst-sizes", -1); 117 if (sc->sc_burst == -1) 118 /* take SBus burst sizes */ 119 sc->sc_burst = sbusburst; 120 121 /* Clamp at parent's burst sizes */ 122 sc->sc_burst &= sbusburst; 123 124 sbus_establish(&sc->sc_sd, &sc->sc_dev); 125 126 printf(": %dK memory\n", sc->sc_bufsiz / 1024); 127 128 /* search through children */ 129 for (node = firstchild(node); node; node = nextsibling(node)) { 130 struct sbus_attach_args sax; 131 sbus_setup_attach_args((struct sbus_softc *)parent, 132 bt, dt, node, &sax); 133 (void)config_found(&sc->sc_dev, (void *)&sax, lebufprint); 134 sbus_destroy_attach_args(&sax); 135 } 136 } 137