2005-12-11 15:16:03 +03:00
|
|
|
/* $NetBSD: satlink.c,v 1.26 2005/12/11 12:22:03 christos Exp $ */
|
1998-01-12 12:39:57 +03:00
|
|
|
|
1997-07-13 23:09:46 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Canada Connect Corp.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
1997-10-09 11:57:17 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1997-07-13 23:09:46 +04:00
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device driver for SatLink interface.
|
|
|
|
*
|
|
|
|
* This thing is really simple. We essentially DMA into a ring buffer
|
|
|
|
* which the user then reads from, and provide an ioctl interface to
|
|
|
|
* reset the card, etc.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 11:01:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-12-11 15:16:03 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: satlink.c,v 1.26 2005/12/11 12:22:03 christos Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
1997-07-13 23:09:46 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1997-07-13 23:09:46 +04:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
|
|
|
|
|
|
|
#include <dev/isa/satlinkreg.h>
|
|
|
|
#include <dev/isa/satlinkio.h>
|
|
|
|
|
|
|
|
struct satlink_softc {
|
|
|
|
struct device sc_dev; /* device glue */
|
|
|
|
bus_space_tag_t sc_iot; /* space tag */
|
|
|
|
bus_space_handle_t sc_ioh; /* space handle */
|
1998-06-09 04:05:44 +04:00
|
|
|
isa_chipset_tag_t sc_ic; /* ISA chipset info */
|
1997-07-13 23:09:46 +04:00
|
|
|
int sc_drq; /* the DRQ we're using */
|
2000-02-08 01:07:27 +03:00
|
|
|
bus_size_t sc_bufsize; /* DMA buffer size */
|
1997-07-13 23:09:46 +04:00
|
|
|
caddr_t sc_buf; /* ring buffer for incoming data */
|
|
|
|
int sc_uptr; /* user index into ring buffer */
|
|
|
|
int sc_sptr; /* satlink index into ring buffer */
|
|
|
|
int sc_flags; /* misc. flags. */
|
|
|
|
int sc_lastresid; /* residual */
|
|
|
|
struct selinfo sc_selq; /* our select/poll queue */
|
|
|
|
struct satlink_id sc_id; /* ID cached at attach time */
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout sc_ch; /* callout pseudo-interrupt */
|
1997-07-13 23:09:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* sc_flags */
|
|
|
|
#define SATF_ISOPEN 0x01 /* device is open */
|
|
|
|
#define SATF_DATA 0x02 /* waiting for data */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our pesudo-interrupt. Since up to 328 bytes can arrive in 1/100 of
|
|
|
|
* a second, this gives us 3280 bytes per timeout.
|
|
|
|
*/
|
2000-02-08 01:07:27 +03:00
|
|
|
#define SATLINK_TIMEOUT (hz/10)
|
1997-07-13 23:09:46 +04:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int satlinkprobe(struct device *, struct cfdata *, void *);
|
|
|
|
void satlinkattach(struct device *, struct device *, void *);
|
|
|
|
void satlinktimeout(void *);
|
1997-07-13 23:09:46 +04:00
|
|
|
|
2002-10-02 06:00:07 +04:00
|
|
|
CFATTACH_DECL(satlink, sizeof(struct satlink_softc),
|
2002-10-02 07:10:45 +04:00
|
|
|
satlinkprobe, satlinkattach, NULL, NULL);
|
1997-07-13 23:09:46 +04:00
|
|
|
|
1998-01-12 12:39:57 +03:00
|
|
|
extern struct cfdriver satlink_cd;
|
1997-07-13 23:09:46 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(satlinkopen);
|
|
|
|
dev_type_close(satlinkclose);
|
|
|
|
dev_type_read(satlinkread);
|
|
|
|
dev_type_ioctl(satlinkioctl);
|
|
|
|
dev_type_poll(satlinkpoll);
|
2002-10-23 13:10:23 +04:00
|
|
|
dev_type_kqfilter(satlinkkqfilter);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct cdevsw satlink_cdevsw = {
|
|
|
|
satlinkopen, satlinkclose, satlinkread, nowrite, satlinkioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, satlinkpoll, nommap, satlinkkqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
satlinkprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
int rv = 0;
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_ndrq < 1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return (0);
|
|
|
|
|
1997-07-13 23:09:46 +04:00
|
|
|
/* Don't allow wildcarding of iobase or drq. */
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
1997-07-13 23:09:46 +04:00
|
|
|
return (0);
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ)
|
1997-07-13 23:09:46 +04:00
|
|
|
return (0);
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, SATLINK_IOSIZE, 0, &ioh))
|
1997-07-13 23:09:46 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Should check manufacturer ID here, or something.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rv = 1;
|
2002-01-08 00:46:56 +03:00
|
|
|
|
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = SATLINK_IOSIZE;
|
|
|
|
|
|
|
|
ia->ia_ndrq = 1;
|
|
|
|
|
|
|
|
ia->ia_nirq = 0;
|
|
|
|
ia->ia_niomem = 0;
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
bus_space_unmap(iot, ioh, SATLINK_IOSIZE);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
satlinkattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct satlink_softc *sc = (struct satlink_softc *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
bus_addr_t ringaddr;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Map the card. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, SATLINK_IOSIZE, 0, &ioh)) {
|
1997-07-13 23:09:46 +04:00
|
|
|
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
1998-06-09 04:05:44 +04:00
|
|
|
sc->sc_ic = ia->ia_ic;
|
2002-01-08 00:46:56 +03:00
|
|
|
sc->sc_drq = ia->ia_drq[0].ir_drq;
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
/* Reset the card. */
|
|
|
|
bus_space_write_1(iot, ioh, SATLINK_COMMAND, SATLINK_CMD_RESET);
|
|
|
|
|
|
|
|
/* Read ID from the card. */
|
|
|
|
sc->sc_id.sid_mfrid =
|
|
|
|
bus_space_read_1(iot, ioh, SATLINK_MFRID_L) |
|
|
|
|
(bus_space_read_1(iot, ioh, SATLINK_MFRID_H) << 8);
|
|
|
|
sc->sc_id.sid_grpid = bus_space_read_1(iot, ioh, SATLINK_GRPID);
|
|
|
|
sc->sc_id.sid_userid =
|
|
|
|
bus_space_read_1(iot, ioh, SATLINK_USERID_L) |
|
|
|
|
(bus_space_read_1(iot, ioh, SATLINK_USERID_H) << 8);
|
|
|
|
sc->sc_id.sid_serial =
|
|
|
|
bus_space_read_1(iot, ioh, SATLINK_SER_L) |
|
|
|
|
(bus_space_read_1(iot, ioh, SATLINK_SER_M0) << 8) |
|
|
|
|
(bus_space_read_1(iot, ioh, SATLINK_SER_M1) << 16) |
|
|
|
|
(bus_space_read_1(iot, ioh, SATLINK_SER_H) << 24);
|
|
|
|
|
|
|
|
printf("%s: mfrid 0x%x, grpid 0x%x, userid 0x%x, serial %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_id.sid_mfrid,
|
|
|
|
sc->sc_id.sid_grpid, sc->sc_id.sid_userid,
|
|
|
|
sc->sc_id.sid_serial);
|
|
|
|
|
2000-05-16 03:56:49 +04:00
|
|
|
callout_init(&sc->sc_ch);
|
2000-03-23 10:01:25 +03:00
|
|
|
|
2000-02-08 01:07:27 +03:00
|
|
|
sc->sc_bufsize = isa_dmamaxsize(sc->sc_ic, sc->sc_drq);
|
|
|
|
|
1997-07-13 23:09:46 +04:00
|
|
|
/* Allocate and map the ring buffer. */
|
2000-02-08 01:07:27 +03:00
|
|
|
if (isa_dmamem_alloc(sc->sc_ic, sc->sc_drq, sc->sc_bufsize,
|
1997-07-13 23:09:46 +04:00
|
|
|
&ringaddr, BUS_DMA_NOWAIT)) {
|
|
|
|
printf("%s: can't allocate ring buffer\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
2000-02-08 01:07:27 +03:00
|
|
|
if (isa_dmamem_map(sc->sc_ic, sc->sc_drq, ringaddr, sc->sc_bufsize,
|
1998-02-04 03:32:55 +03:00
|
|
|
&sc->sc_buf, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
|
1997-07-13 23:09:46 +04:00
|
|
|
printf("%s: can't map ring buffer\n", sc->sc_dev.dv_xname);
|
1998-06-09 04:05:44 +04:00
|
|
|
isa_dmamem_free(sc->sc_ic, sc->sc_drq, ringaddr,
|
2000-02-08 01:07:27 +03:00
|
|
|
sc->sc_bufsize);
|
1997-07-13 23:09:46 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-10 03:51:25 +04:00
|
|
|
if (isa_drq_alloc(sc->sc_ic, sc->sc_drq) != 0) {
|
|
|
|
printf("%s: can't reserve drq %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_drq);
|
|
|
|
isa_dmamem_unmap(sc->sc_ic, sc->sc_drq, sc->sc_buf,
|
|
|
|
sc->sc_bufsize);
|
|
|
|
isa_dmamem_free(sc->sc_ic, sc->sc_drq, ringaddr,
|
|
|
|
sc->sc_bufsize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-07-13 23:09:46 +04:00
|
|
|
/* Create the DMA map. */
|
2000-02-08 01:07:27 +03:00
|
|
|
if (isa_dmamap_create(sc->sc_ic, sc->sc_drq, sc->sc_bufsize,
|
2003-05-10 03:51:25 +04:00
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
|
1997-07-13 23:09:46 +04:00
|
|
|
printf("%s: can't create DMA map\n", sc->sc_dev.dv_xname);
|
1998-06-09 04:05:44 +04:00
|
|
|
isa_dmamem_unmap(sc->sc_ic, sc->sc_drq, sc->sc_buf,
|
2000-02-08 01:07:27 +03:00
|
|
|
sc->sc_bufsize);
|
1998-06-09 04:05:44 +04:00
|
|
|
isa_dmamem_free(sc->sc_ic, sc->sc_drq, ringaddr,
|
2000-02-08 01:07:27 +03:00
|
|
|
sc->sc_bufsize);
|
1997-07-13 23:09:46 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
satlinkopen(dev, flags, fmt, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, fmt;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct satlink_softc *sc;
|
2000-07-06 06:02:48 +04:00
|
|
|
int error;
|
1997-07-13 23:09:46 +04:00
|
|
|
|
2000-07-06 06:02:48 +04:00
|
|
|
sc = device_lookup(&satlink_cd, minor(dev));
|
|
|
|
if (sc == NULL)
|
1997-07-13 23:09:46 +04:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (sc->sc_flags & SATF_ISOPEN)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, SATLINK_COMMAND,
|
|
|
|
SATLINK_CMD_RESET);
|
|
|
|
|
|
|
|
/* Reset the ring buffer, and start the DMA loop. */
|
2005-02-27 03:26:58 +03:00
|
|
|
sc->sc_uptr = 0;
|
|
|
|
sc->sc_sptr = 0;
|
2000-02-08 01:07:27 +03:00
|
|
|
sc->sc_lastresid = sc->sc_bufsize;
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(sc->sc_buf, 0, sc->sc_bufsize);
|
1998-06-09 04:05:44 +04:00
|
|
|
error = isa_dmastart(sc->sc_ic, sc->sc_drq, sc->sc_buf,
|
2000-02-08 01:07:27 +03:00
|
|
|
sc->sc_bufsize, NULL, DMAMODE_READ|DMAMODE_LOOP, BUS_DMA_WAITOK);
|
1997-07-13 23:09:46 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
sc->sc_flags |= SATF_ISOPEN;
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_ch, SATLINK_TIMEOUT, satlinktimeout, sc);
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
satlinkclose(dev, flags, fmt, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, fmt;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
2000-07-06 06:02:48 +04:00
|
|
|
struct satlink_softc *sc = device_lookup(&satlink_cd, minor(dev));
|
1997-07-13 23:09:46 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splsoftclock();
|
|
|
|
sc->sc_flags &= ~SATF_ISOPEN;
|
|
|
|
splx(s);
|
|
|
|
|
1998-06-09 04:05:44 +04:00
|
|
|
isa_dmaabort(sc->sc_ic, sc->sc_drq);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_ch);
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
satlinkread(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
|
|
|
{
|
2000-07-06 06:02:48 +04:00
|
|
|
struct satlink_softc *sc = device_lookup(&satlink_cd, minor(dev));
|
1997-07-13 23:09:46 +04:00
|
|
|
int error, s, count, sptr;
|
|
|
|
int wrapcnt, oresid;
|
|
|
|
|
|
|
|
s = splsoftclock();
|
|
|
|
|
|
|
|
/* Wait for data to be available. */
|
|
|
|
while (sc->sc_sptr == sc->sc_uptr) {
|
|
|
|
if (flags & O_NONBLOCK) {
|
|
|
|
splx(s);
|
|
|
|
return (EWOULDBLOCK);
|
|
|
|
}
|
|
|
|
sc->sc_flags |= SATF_DATA;
|
|
|
|
if ((error = tsleep(sc, TTIPRI | PCATCH, "satio", 0)) != 0) {
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sptr = sc->sc_sptr;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* Compute number of readable bytes. */
|
|
|
|
if (sptr > sc->sc_uptr)
|
|
|
|
count = sptr - sc->sc_uptr;
|
|
|
|
else
|
2000-02-08 01:07:27 +03:00
|
|
|
count = sc->sc_bufsize - sc->sc_uptr + sptr;
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
if (count > uio->uio_resid)
|
|
|
|
count = uio->uio_resid;
|
|
|
|
|
|
|
|
/* Send data out to user. */
|
|
|
|
if (sptr > sc->sc_uptr) {
|
|
|
|
/*
|
|
|
|
* Easy case - no wrap-around.
|
|
|
|
*/
|
|
|
|
error = uiomove(&sc->sc_buf[sc->sc_uptr], count, uio);
|
|
|
|
if (error == 0) {
|
|
|
|
sc->sc_uptr += count;
|
2000-02-08 01:07:27 +03:00
|
|
|
if (sc->sc_uptr == sc->sc_bufsize)
|
1997-07-13 23:09:46 +04:00
|
|
|
sc->sc_uptr = 0;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We wrap around. Copy to the end of the ring...
|
|
|
|
*/
|
2000-02-08 01:07:27 +03:00
|
|
|
wrapcnt = sc->sc_bufsize - sc->sc_uptr;
|
1997-07-13 23:09:46 +04:00
|
|
|
oresid = uio->uio_resid;
|
|
|
|
if (wrapcnt > uio->uio_resid)
|
|
|
|
wrapcnt = uio->uio_resid;
|
|
|
|
error = uiomove(&sc->sc_buf[sc->sc_uptr], wrapcnt, uio);
|
|
|
|
sc->sc_uptr = 0;
|
|
|
|
if (error != 0 || wrapcnt == oresid)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* ...and the rest. */
|
|
|
|
count -= wrapcnt;
|
|
|
|
error = uiomove(sc->sc_buf, count, uio);
|
|
|
|
sc->sc_uptr += count;
|
2000-02-08 01:07:27 +03:00
|
|
|
if (sc->sc_uptr == sc->sc_bufsize)
|
1997-07-13 23:09:46 +04:00
|
|
|
sc->sc_uptr = 0;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
satlinkioctl(dev, cmd, data, flags, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flags;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
2000-07-06 06:02:48 +04:00
|
|
|
struct satlink_softc *sc = device_lookup(&satlink_cd, minor(dev));
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SATIORESET:
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, SATLINK_COMMAND,
|
|
|
|
SATLINK_CMD_RESET);
|
1998-06-09 04:05:44 +04:00
|
|
|
sc->sc_uptr = isa_dmacount(sc->sc_ic, sc->sc_drq);
|
1997-07-13 23:09:46 +04:00
|
|
|
sc->sc_sptr = sc->sc_uptr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SATIOGID:
|
2001-07-19 00:52:47 +04:00
|
|
|
memcpy(data, &sc->sc_id, sizeof(sc->sc_id));
|
1997-07-13 23:09:46 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
satlinkpoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
2000-07-06 06:02:48 +04:00
|
|
|
struct satlink_softc *sc = device_lookup(&satlink_cd, minor(dev));
|
1997-07-13 23:09:46 +04:00
|
|
|
int s, revents;
|
|
|
|
|
|
|
|
revents = events & (POLLOUT | POLLWRNORM);
|
|
|
|
|
|
|
|
/* Attempt to save some work. */
|
|
|
|
if ((events & (POLLIN | POLLRDNORM)) == 0)
|
|
|
|
return (revents);
|
|
|
|
|
|
|
|
/* We're timeout-driven, so must block the clock. */
|
|
|
|
s = splsoftclock();
|
|
|
|
if (sc->sc_uptr != sc->sc_sptr)
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
else
|
|
|
|
selrecord(p, &sc->sc_selq);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
static void
|
|
|
|
filt_satlinkrdetach(struct knote *kn)
|
|
|
|
{
|
|
|
|
struct satlink_softc *sc = kn->kn_hook;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splsoftclock();
|
2002-11-26 21:49:40 +03:00
|
|
|
SLIST_REMOVE(&sc->sc_selq.sel_klist, kn, knote, kn_selnext);
|
2002-10-23 13:10:23 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_satlinkread(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
struct satlink_softc *sc = kn->kn_hook;
|
|
|
|
|
|
|
|
if (sc->sc_uptr == sc->sc_sptr)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (sc->sc_sptr > sc->sc_uptr)
|
|
|
|
kn->kn_data = sc->sc_sptr - sc->sc_uptr;
|
|
|
|
else
|
|
|
|
kn->kn_data = (sc->sc_bufsize - sc->sc_uptr) +
|
|
|
|
sc->sc_sptr;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct filterops satlinkread_filtops =
|
|
|
|
{ 1, NULL, filt_satlinkrdetach, filt_satlinkread };
|
|
|
|
|
|
|
|
static const struct filterops satlink_seltrue_filtops =
|
|
|
|
{ 1, NULL, filt_satlinkrdetach, filt_seltrue };
|
|
|
|
|
|
|
|
int
|
|
|
|
satlinkkqfilter(dev_t dev, struct knote *kn)
|
|
|
|
{
|
|
|
|
struct satlink_softc *sc = device_lookup(&satlink_cd, minor(dev));
|
|
|
|
struct klist *klist;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
switch (kn->kn_filter) {
|
|
|
|
case EVFILT_READ:
|
2002-11-26 21:49:40 +03:00
|
|
|
klist = &sc->sc_selq.sel_klist;
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_fop = &satlinkread_filtops;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVFILT_WRITE:
|
2002-11-26 21:49:40 +03:00
|
|
|
klist = &sc->sc_selq.sel_klist;
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_fop = &satlink_seltrue_filtops;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
kn->kn_hook = sc;
|
|
|
|
|
|
|
|
s = splsoftclock();
|
|
|
|
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-07-13 23:09:46 +04:00
|
|
|
void
|
|
|
|
satlinktimeout(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct satlink_softc *sc = arg;
|
|
|
|
bus_size_t resid;
|
|
|
|
int newidx;
|
|
|
|
|
|
|
|
if ((sc->sc_flags & SATF_ISOPEN) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current residual count from the DMA controller
|
|
|
|
* and compute the satlink's index into the ring buffer.
|
|
|
|
*/
|
1998-06-09 04:05:44 +04:00
|
|
|
resid = isa_dmacount(sc->sc_ic, sc->sc_drq);
|
2000-02-08 01:07:27 +03:00
|
|
|
newidx = sc->sc_bufsize - resid;
|
|
|
|
if (newidx == sc->sc_bufsize)
|
1997-07-13 23:09:46 +04:00
|
|
|
newidx = 0;
|
|
|
|
|
|
|
|
if (newidx == sc->sc_sptr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sc->sc_sptr = newidx;
|
|
|
|
|
|
|
|
/* Wake up anyone blocked in read... */
|
|
|
|
if (sc->sc_flags & SATF_DATA) {
|
|
|
|
sc->sc_flags &= ~SATF_DATA;
|
|
|
|
wakeup(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wake up anyone blocked in poll... */
|
2002-10-23 13:10:23 +04:00
|
|
|
selnotify(&sc->sc_selq, 0);
|
1997-07-13 23:09:46 +04:00
|
|
|
|
|
|
|
out:
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_ch, SATLINK_TIMEOUT, satlinktimeout, sc);
|
1997-07-13 23:09:46 +04:00
|
|
|
}
|