Home | History | Annotate | Line # | Download | only in vme
leo.c revision 1.3
      1  1.3  simonb /*	$NetBSD: leo.c,v 1.3 2000/06/26 04:55:35 simonb Exp $	*/
      2  1.1     leo 
      3  1.1     leo /*-
      4  1.1     leo  * Copyright (c) 1997 maximum entropy <entropy (at) zippy.bernstein.com>
      5  1.1     leo  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      6  1.1     leo  * All rights reserved.
      7  1.1     leo  *
      8  1.1     leo  * Redistribution and use in source and binary forms, with or without
      9  1.1     leo  * modification, are permitted provided that the following conditions
     10  1.1     leo  * are met:
     11  1.1     leo  * 1. Redistributions of source code must retain the above copyright
     12  1.1     leo  *    notice, this list of conditions and the following disclaimer.
     13  1.1     leo  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1     leo  *    notice, this list of conditions and the following disclaimer in the
     15  1.1     leo  *    documentation and/or other materials provided with the distribution.
     16  1.1     leo  * 3. All advertising materials mentioning features or use of this software
     17  1.1     leo  *    must display the following acknowledgement:
     18  1.1     leo  *        This product includes software developed by the NetBSD
     19  1.1     leo  *        Foundation, Inc. and its contributors.
     20  1.1     leo  * 4. Neither the name of The NetBSD Foundation nor the names of its
     21  1.1     leo  *    contributors may be used to endorse or promote products derived
     22  1.1     leo  *    from this software without specific prior written permission.
     23  1.1     leo  *
     24  1.1     leo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  1.1     leo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  1.1     leo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  1.1     leo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  1.1     leo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  1.1     leo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  1.1     leo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  1.1     leo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  1.1     leo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  1.1     leo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  1.1     leo  * POSSIBILITY OF SUCH DAMAGE.
     35  1.1     leo  */
     36  1.1     leo 
     37  1.1     leo /*
     38  1.1     leo  * Driver for the Circad Leonardo 1.2 from Lexicor, a 24-bit true color
     39  1.1     leo  * VME graphics card based on the Texas Instruments TMS34061.
     40  1.1     leo  *
     41  1.1     leo  * Written by maximum entropy <entropy (at) zippy.bernstein.com>, December 5, 1997.
     42  1.1     leo  *
     43  1.1     leo  * This driver was written from scratch, but I referred to several other
     44  1.1     leo  * drivers in the NetBSD distribution as examples.  The file I referred to
     45  1.1     leo  * the most was /sys/arch/atari/vme/if_le_vme.c.  Due credits:
     46  1.1     leo  * Copyright (c) 1997 Leo Weppelman.  All rights reserved.
     47  1.1     leo  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
     48  1.1     leo  * Copyright (c) 1992, 1993
     49  1.1     leo  *	The Regents of the University of California.  All rights reserved.
     50  1.1     leo  * This code is derived from software contributed to Berkeley by
     51  1.1     leo  * 	Ralph Campbell and Rick Macklem.
     52  1.1     leo  * This product includes software developed by the University of
     53  1.1     leo  *	California, Berkeley and its contributors.
     54  1.1     leo  */
     55  1.1     leo 
     56  1.1     leo #include <sys/param.h>
     57  1.1     leo #include <sys/systm.h>
     58  1.1     leo #include <sys/proc.h>
     59  1.1     leo #include <sys/errno.h>
     60  1.1     leo #include <sys/device.h>
     61  1.1     leo #include <sys/conf.h>
     62  1.1     leo #include <sys/ioctl.h>
     63  1.1     leo #include <machine/cpu.h>
     64  1.1     leo #include <machine/bus.h>
     65  1.1     leo #include <machine/iomap.h>
     66  1.1     leo #include <machine/scu.h>
     67  1.1     leo #include <atari/vme/vmevar.h>
     68  1.1     leo #include <atari/vme/leovar.h>
     69  1.1     leo #include <atari/vme/leoioctl.h>
     70  1.1     leo 
     71  1.1     leo static struct leo_addresses {
     72  1.1     leo 	u_long reg_addr;
     73  1.1     leo 	u_int reg_size;
     74  1.1     leo 	u_long mem_addr;
     75  1.1     leo 	u_int mem_size;
     76  1.1     leo } leostd[] = {
     77  1.1     leo 	{ 0xfed90000, 0x100, 0xfec00000, 0x100000 }
     78  1.1     leo };
     79  1.1     leo 
     80  1.1     leo #define NLEOSTD (sizeof(leostd) / sizeof(leostd[0]))
     81  1.1     leo 
     82  1.1     leo struct leo_softc {
     83  1.1     leo 	struct device sc_dev;		/* XXX what goes here? */
     84  1.1     leo 	bus_space_tag_t sc_iot;
     85  1.1     leo 	bus_space_tag_t sc_memt;
     86  1.1     leo 	bus_space_handle_t sc_ioh;
     87  1.1     leo 	bus_space_handle_t sc_memh;
     88  1.1     leo 	int sc_flags;
     89  1.1     leo 	int sc_maddr;
     90  1.1     leo 	u_int sc_msize;
     91  1.1     leo };
     92  1.1     leo 
     93  1.1     leo #define LEO_SC_FLAGS_INUSE 1
     94  1.1     leo 
     95  1.1     leo static int leo_match __P((struct device *, struct cfdata *, void *));
     96  1.1     leo static void leo_attach __P((struct device *, struct device *, void *));
     97  1.1     leo static int leo_probe __P((bus_space_tag_t *, bus_space_tag_t *,
     98  1.1     leo 			  bus_space_handle_t *, bus_space_handle_t *,
     99  1.1     leo 			  u_int, u_int));
    100  1.1     leo static int leo_init __P((struct leo_softc *, int));
    101  1.1     leo static int leo_scroll __P((struct leo_softc *, int));
    102  1.1     leo static int leomove __P((dev_t, struct uio *, int));
    103  1.1     leo 
    104  1.1     leo dev_decl(leo,open);
    105  1.1     leo dev_decl(leo,close);
    106  1.1     leo dev_decl(leo,read);
    107  1.1     leo dev_decl(leo,write);
    108  1.1     leo dev_decl(leo,ioctl);
    109  1.1     leo dev_decl(leo,mmap);
    110  1.1     leo 
    111  1.1     leo struct cfattach leo_ca = {
    112  1.1     leo 	sizeof(struct leo_softc), leo_match, leo_attach
    113  1.1     leo };
    114  1.1     leo 
    115  1.1     leo extern struct cfdriver leo_cd;
    116  1.1     leo 
    117  1.1     leo static int
    118  1.1     leo leo_match(parent, cfp, aux)
    119  1.1     leo 	struct device *parent;
    120  1.1     leo 	struct cfdata *cfp;
    121  1.1     leo 	void *aux;
    122  1.1     leo {
    123  1.1     leo 	struct vme_attach_args *va = aux;
    124  1.1     leo 	int i;
    125  1.1     leo 	bus_space_tag_t iot;
    126  1.1     leo 	bus_space_tag_t memt;
    127  1.1     leo 	bus_space_handle_t ioh;
    128  1.1     leo 	bus_space_handle_t memh;
    129  1.1     leo 
    130  1.1     leo 	/*
    131  1.1     leo 	 * We are passed our configuration in the attachment arguments.
    132  1.1     leo 	 * The configuration information may be partially unspecified.
    133  1.1     leo 	 * For any unspecified configuration parameters, we fill in those
    134  1.1     leo 	 * parameters with data for a "standard" configuration.
    135  1.1     leo 	 * Once we have a fully specified configuration, we try to probe
    136  1.1     leo 	 * a card with that configuration.
    137  1.1     leo 	 * The Leonardo only has one configuration and it isn't likely
    138  1.1     leo 	 * to change, but this routine doesn't assume that's the case.
    139  1.1     leo 	 */
    140  1.1     leo 	iot = va->va_iot;
    141  1.1     leo 	memt = va->va_memt;
    142  1.1     leo 	for (i = 0; i < NLEOSTD; i++) {
    143  1.1     leo 		struct leo_addresses *leo_ap = &leostd[i];
    144  1.1     leo 		int found = 0;
    145  1.1     leo 		struct vme_attach_args vat = *va;
    146  1.1     leo 
    147  1.1     leo 		if (vat.va_irq != VMECF_IRQ_DEFAULT) {
    148  1.1     leo 			printf("leo_match: config error: no irq support\n");
    149  1.1     leo 			return 0;
    150  1.1     leo 		}
    151  1.1     leo 		if (vat.va_iobase == VMECF_IOPORT_DEFAULT)
    152  1.1     leo 			vat.va_iobase = leo_ap->reg_addr;
    153  1.1     leo 		if (vat.va_maddr == VMECF_MEM_DEFAULT)
    154  1.1     leo 			vat.va_maddr = leo_ap->mem_addr;
    155  1.1     leo 		if (vat.va_iosize == VMECF_IOSIZE_DEFAULT)
    156  1.1     leo 			vat.va_iosize = leo_ap->reg_size;
    157  1.1     leo 		if (vat.va_msize == VMECF_MEMSIZ_DEFAULT)
    158  1.1     leo 			vat.va_msize = leo_ap->mem_size;
    159  1.1     leo 		if (bus_space_map(iot, vat.va_iobase, vat.va_iosize, 0, &ioh)) {
    160  1.1     leo 			printf("leo_match: cannot map io area\n");
    161  1.1     leo 			return 0;
    162  1.1     leo 		}
    163  1.1     leo 		if (bus_space_map(memt, vat.va_maddr, vat.va_msize,
    164  1.1     leo 			  	  BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE,
    165  1.1     leo 			  	  &memh)) {
    166  1.2     leo 			bus_space_unmap(iot, ioh, vat.va_iosize);
    167  1.1     leo 			printf("leo_match: cannot map memory area\n");
    168  1.1     leo 			return 0;
    169  1.1     leo 		}
    170  1.1     leo 		found = leo_probe(&iot, &memt, &ioh, &memh,
    171  1.1     leo 				  vat.va_iosize, vat.va_msize);
    172  1.2     leo 		bus_space_unmap(iot, ioh, vat.va_iosize);
    173  1.2     leo 		bus_space_unmap(memt, memh, vat.va_msize);
    174  1.1     leo 		if (found) {
    175  1.1     leo 			*va = vat;
    176  1.1     leo 			return 1;
    177  1.1     leo 		}
    178  1.1     leo 	}
    179  1.1     leo 	return 0;
    180  1.1     leo }
    181  1.1     leo 
    182  1.1     leo static int
    183  1.1     leo leo_probe(iot, memt, ioh, memh, iosize, msize)
    184  1.1     leo 	bus_space_tag_t *iot, *memt;
    185  1.1     leo 	bus_space_handle_t *ioh, *memh;
    186  1.1     leo 	u_int iosize, msize;
    187  1.1     leo {
    188  1.1     leo 
    189  1.1     leo 	/* Test that our highest register is within the io range. */
    190  1.1     leo 	if (0xca > iosize) /* XXX */
    191  1.1     leo 		return 0;
    192  1.1     leo 	/* Test if we can peek each register. */
    193  1.1     leo 	if (!bus_space_peek_1(*iot, *ioh, LEO_REG_MSBSCROLL))
    194  1.1     leo 		return 0;
    195  1.1     leo 	if (!bus_space_peek_1(*iot, *ioh, LEO_REG_LSBSCROLL))
    196  1.1     leo 		return 0;
    197  1.1     leo 	/*
    198  1.1     leo 	 * Write a test pattern at the start and end of the memory region,
    199  1.1     leo 	 * and test if the pattern can be read back.  If so, the region is
    200  1.1     leo 	 * backed by memory (i.e. the card is present).
    201  1.1     leo 	 * On the Leonardo, the first byte of each longword isn't backed by
    202  1.1     leo 	 * physical memory, so we only compare the three low-order bytes
    203  1.1     leo 	 * with the test pattern.
    204  1.1     leo 	 */
    205  1.1     leo 	bus_space_write_4(*memt, *memh, 0, 0xa5a5a5a5);
    206  1.1     leo 	if ((bus_space_read_4(*memt, *memh, 0) & 0xffffff) != 0xa5a5a5)
    207  1.1     leo 		return 0;
    208  1.1     leo 	bus_space_write_4(*memt, *memh, msize - 4, 0xa5a5a5a5);
    209  1.1     leo 	if ((bus_space_read_4(*memt, *memh, msize - 4) & 0xffffff)
    210  1.1     leo 		!= 0xa5a5a5)
    211  1.1     leo 		return 0;
    212  1.1     leo 	return 1;
    213  1.1     leo }
    214  1.1     leo 
    215  1.1     leo static void
    216  1.1     leo leo_attach(parent, self, aux)
    217  1.1     leo 	struct device *parent, *self;
    218  1.1     leo 	void *aux;
    219  1.1     leo {
    220  1.1     leo 	struct leo_softc *sc = (struct leo_softc *)self;
    221  1.1     leo 	struct vme_attach_args *va = aux;
    222  1.1     leo 	bus_space_handle_t ioh;
    223  1.1     leo 	bus_space_handle_t memh;
    224  1.1     leo #ifndef SET_REGION
    225  1.1     leo 	int i;
    226  1.1     leo #endif
    227  1.1     leo 
    228  1.1     leo 	printf("\n");
    229  1.1     leo 	if (bus_space_map(va->va_iot, va->va_iobase, va->va_iosize, 0, &ioh))
    230  1.1     leo 		panic("leo_attach: cannot map io area\n");
    231  1.1     leo 	if (bus_space_map(va->va_memt, va->va_maddr, va->va_msize,
    232  1.1     leo 			  BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE, &memh))
    233  1.1     leo 		panic("leo_attach: cannot map memory area\n");
    234  1.1     leo #ifdef SET_REGION /* XXX seems to be unimplemented on atari? */
    235  1.1     leo 	bus_space_set_region_4(va->va_memt, memh, 0, 0, va->va_msize >> 2);
    236  1.1     leo #else
    237  1.1     leo 	for (i = 0; i < (va->va_msize >> 2); i++)
    238  1.1     leo 		bus_space_write_4(va->va_memt, memh, i << 2, 0);
    239  1.1     leo #endif
    240  1.1     leo 	sc->sc_iot = va->va_iot;
    241  1.1     leo 	sc->sc_ioh = ioh;
    242  1.1     leo 	sc->sc_memt = va->va_memt;
    243  1.1     leo 	sc->sc_memh = memh;
    244  1.1     leo 	sc->sc_flags = 0;
    245  1.1     leo 	sc->sc_maddr = va->va_maddr;
    246  1.1     leo 	sc->sc_msize = va->va_msize;
    247  1.1     leo 	leo_init(sc, 512);
    248  1.1     leo 	leo_scroll(sc, 0);
    249  1.1     leo }
    250  1.1     leo 
    251  1.1     leo int
    252  1.1     leo leoopen(dev, flags, devtype, p)
    253  1.1     leo 	dev_t dev;
    254  1.1     leo 	int flags, devtype;
    255  1.1     leo 	struct proc *p;
    256  1.1     leo {
    257  1.1     leo 	int unit = minor(dev);
    258  1.1     leo 	struct leo_softc *sc;
    259  1.1     leo 	int r;
    260  1.1     leo 
    261  1.1     leo 	if (unit >= leo_cd.cd_ndevs)
    262  1.1     leo 		return ENXIO;
    263  1.1     leo 	sc = leo_cd.cd_devs[unit];
    264  1.1     leo 	if (!sc)
    265  1.1     leo 		return ENXIO;
    266  1.1     leo 	if (sc->sc_flags & LEO_SC_FLAGS_INUSE)
    267  1.1     leo 		return EBUSY;
    268  1.1     leo 	r = leo_init(sc, 512);
    269  1.1     leo 	if (r != 0)
    270  1.1     leo 		return r;
    271  1.1     leo 	r = leo_scroll(sc, 0);
    272  1.1     leo 	if (r != 0)
    273  1.1     leo 		return r;
    274  1.1     leo 	sc->sc_flags |= LEO_SC_FLAGS_INUSE;
    275  1.1     leo 	return 0;
    276  1.1     leo }
    277  1.1     leo 
    278  1.1     leo static int
    279  1.1     leo leo_init(sc, ysize)
    280  1.1     leo 	struct leo_softc *sc;
    281  1.1     leo 	int ysize;
    282  1.1     leo {
    283  1.1     leo 
    284  1.1     leo 	if ((ysize != 256) && (ysize != 384) && (ysize != 512))
    285  1.1     leo 		return EINVAL;
    286  1.1     leo 	/* XXX */
    287  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x00, 0x6);
    288  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x08, 0x0);
    289  1.1     leo 	if (ysize == 384)
    290  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x10, 0x10);
    291  1.1     leo 	else
    292  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x10, 0x11);
    293  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x18, 0x0);
    294  1.1     leo 	if (ysize == 384)
    295  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x20, 0x50);
    296  1.1     leo 	else
    297  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x20, 0x51);
    298  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x28, 0x0);
    299  1.1     leo 	if (ysize == 384)
    300  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x30, 0x56);
    301  1.1     leo 	else
    302  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x30, 0x57);
    303  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x38, 0x0);
    304  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x40, 0x6);
    305  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x48, 0x0);
    306  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x50, 0x25);
    307  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x58, 0x0);
    308  1.1     leo 	if (ysize == 256) {
    309  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x60, 0x1f);
    310  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x68, 0x1);
    311  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x70, 0x29);
    312  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x78, 0x1);
    313  1.1     leo 	} else if (ysize == 384) {
    314  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x60, 0xa5);
    315  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x68, 0x1);
    316  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x70, 0xa7);
    317  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x78, 0x1);
    318  1.1     leo 	} else {
    319  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x60, 0x1d);
    320  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x68, 0x2);
    321  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x70, 0x27);
    322  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x78, 0x2);
    323  1.1     leo 	}
    324  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xb8, 0x10);
    325  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xb0, 0x10);
    326  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0x80, 0x4);
    327  1.1     leo 	if (ysize == 384)
    328  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xc8, 0x21);
    329  1.1     leo 	else
    330  1.1     leo 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xc8, 0x20);
    331  1.1     leo 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0xc0, 0x40);
    332  1.1     leo 	return 0;
    333  1.1     leo }
    334  1.1     leo 
    335  1.1     leo static int
    336  1.1     leo leo_scroll(sc, scroll)
    337  1.1     leo 	struct leo_softc *sc;
    338  1.1     leo 	int scroll;
    339  1.1     leo {
    340  1.1     leo 
    341  1.1     leo 	if ((scroll < 0) || (scroll > 255))
    342  1.1     leo 		return EINVAL;
    343  1.1     leo         bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_MSBSCROLL,
    344  1.1     leo 			  (scroll >> 6) && 0xff);
    345  1.1     leo         bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_LSBSCROLL,
    346  1.1     leo 			  (scroll << 2) && 0xff);
    347  1.1     leo 	return 0;
    348  1.1     leo }
    349  1.1     leo 
    350  1.1     leo int
    351  1.1     leo leoclose(dev, flags, devtype, p)
    352  1.1     leo 	dev_t dev;
    353  1.1     leo 	int flags, devtype;
    354  1.1     leo 	struct proc *p;
    355  1.1     leo {
    356  1.1     leo 	struct leo_softc *sc;
    357  1.1     leo 
    358  1.1     leo 	sc = leo_cd.cd_devs[minor(dev)];
    359  1.1     leo 	sc->sc_flags &= ~LEO_SC_FLAGS_INUSE;
    360  1.1     leo 	return 0;
    361  1.1     leo }
    362  1.1     leo 
    363  1.1     leo #define SMALLBSIZE      32
    364  1.1     leo 
    365  1.1     leo static int
    366  1.1     leo leomove(dev, uio, flags)
    367  1.1     leo         dev_t dev;
    368  1.1     leo         struct uio *uio;
    369  1.1     leo         int flags;
    370  1.1     leo {
    371  1.1     leo         struct leo_softc *sc;
    372  1.1     leo         int length, size, error;
    373  1.1     leo         u_int8_t smallbuf[SMALLBSIZE];
    374  1.1     leo 	off_t offset;
    375  1.1     leo 
    376  1.1     leo         sc = leo_cd.cd_devs[minor(dev)];
    377  1.1     leo         if (uio->uio_offset > sc->sc_msize)
    378  1.1     leo                 return 0;
    379  1.1     leo         length = sc->sc_msize - uio->uio_offset;
    380  1.1     leo         if (length > uio->uio_resid)
    381  1.1     leo                 length = uio->uio_resid;
    382  1.1     leo         while (length > 0) {
    383  1.1     leo                 size = length;
    384  1.1     leo                 if (size > SMALLBSIZE)
    385  1.1     leo                         size = SMALLBSIZE;
    386  1.1     leo                 length -= size;
    387  1.1     leo 		offset = uio->uio_offset;
    388  1.1     leo                 if (uio->uio_rw == UIO_READ)
    389  1.1     leo                         bus_space_read_region_1(sc->sc_memt, sc->sc_memh,
    390  1.1     leo                                         offset, smallbuf, size);
    391  1.1     leo                 if ((error = uiomove((caddr_t)smallbuf, size, uio)))
    392  1.1     leo                         return (error);
    393  1.1     leo                 if (uio->uio_rw == UIO_WRITE)
    394  1.1     leo                         bus_space_write_region_1(sc->sc_memt, sc->sc_memh,
    395  1.1     leo                                         offset, smallbuf, size);
    396  1.1     leo         }
    397  1.1     leo         return 0;
    398  1.1     leo }
    399  1.1     leo 
    400  1.1     leo int
    401  1.1     leo leoread(dev, uio, flags)
    402  1.1     leo 	dev_t dev;
    403  1.1     leo 	struct uio *uio;
    404  1.1     leo 	int flags;
    405  1.1     leo {
    406  1.1     leo 
    407  1.1     leo 	return leomove(dev, uio, flags);
    408  1.1     leo }
    409  1.1     leo 
    410  1.1     leo int
    411  1.1     leo leowrite(dev, uio, flags)
    412  1.1     leo 	dev_t dev;
    413  1.1     leo 	struct uio *uio;
    414  1.1     leo 	int flags;
    415  1.1     leo {
    416  1.1     leo 
    417  1.1     leo 	return leomove(dev, uio, flags);
    418  1.1     leo }
    419  1.1     leo 
    420  1.1     leo int
    421  1.1     leo leoioctl(dev, cmd, data, flags, p)
    422  1.1     leo 	dev_t dev;
    423  1.1     leo 	u_long cmd;
    424  1.1     leo 	caddr_t data;
    425  1.1     leo 	int flags;
    426  1.1     leo 	struct proc *p;
    427  1.1     leo {
    428  1.1     leo 	struct leo_softc *sc;
    429  1.1     leo 
    430  1.1     leo 	sc = leo_cd.cd_devs[minor(dev)];
    431  1.1     leo         switch (cmd) {
    432  1.1     leo         case LIOCYRES:
    433  1.1     leo 		return leo_init(sc, *(int *)data);
    434  1.1     leo 		break;
    435  1.1     leo         case LIOCSCRL:
    436  1.1     leo 		return leo_scroll(sc, *(int *)data);
    437  1.1     leo 		break;
    438  1.1     leo 	default:
    439  1.1     leo 		return EINVAL;
    440  1.1     leo 		break;
    441  1.1     leo 	}
    442  1.1     leo }
    443  1.1     leo 
    444  1.3  simonb paddr_t
    445  1.1     leo leommap(dev, offset, prot)
    446  1.1     leo 	dev_t dev;
    447  1.3  simonb 	off_t offset;
    448  1.1     leo 	int prot;
    449  1.1     leo {
    450  1.1     leo 	struct leo_softc *sc;
    451  1.1     leo 
    452  1.1     leo 	sc = leo_cd.cd_devs[minor(dev)];
    453  1.1     leo 	if (offset >= 0 && offset < sc->sc_msize)
    454  1.1     leo 		return m68k_btop(sc->sc_maddr + offset);
    455  1.1     leo 	return -1;
    456  1.1     leo }
    457