diff options
Diffstat (limited to 'sys/i386/isa')
67 files changed, 2462 insertions, 32076 deletions
diff --git a/sys/i386/isa/aha1542.c b/sys/i386/isa/aha1542.c deleted file mode 100644 index 1a1ae56..0000000 --- a/sys/i386/isa/aha1542.c +++ /dev/null @@ -1,1583 +0,0 @@ -/* - * (Mostly) Written by Julian Elischer (julian@tfs.com) - * for TRW Financial Systems for use under the MACH(2.5) operating system. - * - * TRW Financial Systems, in accordance with their agreement with Carnegie - * Mellon University, makes this software available to CMU to distribute - * or use in any manner that they see fit as long as this message is kept with - * the software. For this reason TFS also grants any other persons or - * organisations permission to use or modify this software. - * - * TFS supplies this software to be publicly redistributed - * on the understanding that TFS is not responsible for the correct - * functioning of this software in any circumstances. - * - * $Id: aha1542.c,v 1.11 1993/10/15 09:43:51 rgrimes Exp $ - */ - -/* - * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 - */ - -/* - * a FEW lines in this driver come from a MACH adaptec-disk driver - * so the copyright below is included: - * - * Copyright 1990 by Open Software Foundation, - * Grenoble, FRANCE - * - * All Rights Reserved - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation, and that the name of OSF or Open Software - * Foundation not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, - * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, - * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include <sys/types.h> -#include <aha.h> - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/errno.h> -#include <sys/ioctl.h> -#include <sys/buf.h> -#include <sys/proc.h> -#include <sys/user.h> - -#ifdef MACH /* EITHER CMU OR OSF */ -#include <i386/ipl.h> -#include <i386at/scsi.h> -#include <i386at/scsiconf.h> - -#ifdef OSF /* OSF ONLY */ -#include <sys/table.h> -#include <i386/handler.h> -#include <i386/dispatcher.h> -#include <i386/AT386/atbus.h> - -#else OSF /* CMU ONLY */ -#include <i386at/atbus.h> -#include <i386/pio.h> -#endif OSF -#endif MACH /* end of MACH specific */ - -#ifdef __386BSD__ /* 386BSD specific */ -#define isa_dev isa_device -#define dev_unit id_unit -#define dev_addr id_iobase - -#include <i386/isa/isa_device.h> -#include <scsi/scsi_all.h> -#include <scsi/scsiconf.h> -#endif __386BSD__ - - -#ifdef __386BSD__ -#include "ddb.h" -#if NDDB > 0 -int Debugger(); -#else NDDB -#define Debugger() panic("should call debugger here (adaptec.c)") -#endif NDDB -#endif __386BSD__ -extern int hz; -extern int delaycount; /* from clock setup code */ - -/************************** board definitions *******************************/ -/* - * I/O Port Interface - */ - -#define AHA_BASE aha_base[unit] -#define AHA_CTRL_STAT_PORT (AHA_BASE + 0x0) /* control & status */ -#define AHA_CMD_DATA_PORT (AHA_BASE + 0x1) /* cmds and datas */ -#define AHA_INTR_PORT (AHA_BASE + 0x2) /* Intr. stat */ - -/* - * AHA_CTRL_STAT bits (write) - */ - -#define AHA_HRST 0x80 /* Hardware reset */ -#define AHA_SRST 0x40 /* Software reset */ -#define AHA_IRST 0x20 /* Interrupt reset */ -#define AHA_SCRST 0x10 /* SCSI bus reset */ - -/* - * AHA_CTRL_STAT bits (read) - */ - -#define AHA_STST 0x80 /* Self test in Progress */ -#define AHA_DIAGF 0x40 /* Diagnostic Failure */ -#define AHA_INIT 0x20 /* Mbx Init required */ -#define AHA_IDLE 0x10 /* Host Adapter Idle */ -#define AHA_CDF 0x08 /* cmd/data out port full */ -#define AHA_DF 0x04 /* Data in port full */ -#define AHA_INVDCMD 0x01 /* Invalid command */ - -/* - * AHA_CMD_DATA bits (write) - */ - -#define AHA_NOP 0x00 /* No operation */ -#define AHA_MBX_INIT 0x01 /* Mbx initialization */ -#define AHA_START_SCSI 0x02 /* start scsi command */ -#define AHA_START_BIOS 0x03 /* start bios command */ -#define AHA_INQUIRE 0x04 /* Adapter Inquiry */ -#define AHA_MBO_INTR_EN 0x05 /* Enable MBO available interrupt */ -#define AHA_SEL_TIMEOUT_SET 0x06 /* set selection time-out */ -#define AHA_BUS_ON_TIME_SET 0x07 /* set bus-on time */ -#define AHA_BUS_OFF_TIME_SET 0x08 /* set bus-off time */ -#define AHA_SPEED_SET 0x09 /* set transfer speed */ -#define AHA_DEV_GET 0x0a /* return installed devices */ -#define AHA_CONF_GET 0x0b /* return configuration data */ -#define AHA_TARGET_EN 0x0c /* enable target mode */ -#define AHA_SETUP_GET 0x0d /* return setup data */ -#define AHA_WRITE_CH2 0x1a /* write channel 2 buffer */ -#define AHA_READ_CH2 0x1b /* read channel 2 buffer */ -#define AHA_WRITE_FIFO 0x1c /* write fifo buffer */ -#define AHA_READ_FIFO 0x1d /* read fifo buffer */ -#define AHA_ECHO 0x1e /* Echo command data */ -#define AHA_EXT_BIOS 0x28 /* return extended bios info */ -#define AHA_MBX_ENABLE 0x29 /* enable mail box interface */ - -struct aha_cmd_buf { - u_char byte[16]; -}; - -/* - * AHA_INTR_PORT bits (read) - */ - -#define AHA_ANY_INTR 0x80 /* Any interrupt */ -#define AHA_SCRD 0x08 /* SCSI reset detected */ -#define AHA_HACC 0x04 /* Command complete */ -#define AHA_MBOA 0x02 /* MBX out empty */ -#define AHA_MBIF 0x01 /* MBX in full */ - -/* - * Mail box defs - */ - -#define AHA_MBX_SIZE 16 /* mail box size */ - -struct aha_mbx { - struct aha_mbx_out { - unsigned char cmd; - unsigned char ccb_addr[3]; - } mbo [AHA_MBX_SIZE]; - struct aha_mbx_in{ - unsigned char stat; - unsigned char ccb_addr[3]; - } mbi[AHA_MBX_SIZE]; -}; - -/* - * mbo.cmd values - */ - -#define AHA_MBO_FREE 0x0 /* MBO entry is free */ -#define AHA_MBO_START 0x1 /* MBO activate entry */ -#define AHA_MBO_ABORT 0x2 /* MBO abort entry */ - -#define AHA_MBI_FREE 0x0 /* MBI entry is free */ -#define AHA_MBI_OK 0x1 /* completed without error */ -#define AHA_MBI_ABORT 0x2 /* aborted ccb */ -#define AHA_MBI_UNKNOWN 0x3 /* Tried to abort invalid CCB */ -#define AHA_MBI_ERROR 0x4 /* Completed with error */ - -extern struct aha_mbx aha_mbx[]; - -/* FOR OLD VERSIONS OF THE !%$@ this may have to be 16 (yuk) */ -#define AHA_NSEG 17 /* Number of scatter gather segments <= 16 */ - /* allow 64 K i/o (min) */ - -struct aha_ccb { - unsigned char opcode; - unsigned char lun:3; - unsigned char data_in:1; /* must be 0 */ - unsigned char data_out:1; /* must be 0 */ - unsigned char target:3; - unsigned char scsi_cmd_length; - unsigned char req_sense_length; - unsigned char data_length[3]; - unsigned char data_addr[3]; - unsigned char link_addr[3]; - unsigned char link_id; - unsigned char host_stat; - unsigned char target_stat; - unsigned char reserved[2]; - struct scsi_generic scsi_cmd; - struct scsi_sense_data scsi_sense; - struct aha_scat_gath { - unsigned char seg_len[3]; - unsigned char seg_addr[3]; - } scat_gath[AHA_NSEG]; - struct aha_ccb *next; - struct scsi_xfer *xfer; /* the scsi_xfer for this cmd */ - struct aha_mbx_out *mbx; /* pointer to mail box */ - int flags; -#define CCB_FREE 0 -#define CCB_ACTIVE 1 -#define CCB_ABORTED 2 - -}; - - -/* - * opcode fields - */ - -#define AHA_INITIATOR_CCB 0x00 /* SCSI Initiator CCB */ -#define AHA_TARGET_CCB 0x01 /* SCSI Target CCB */ -#define AHA_INIT_SCAT_GATH_CCB 0x02 /* SCSI Initiator with scattter gather*/ -#define AHA_RESET_CCB 0x81 /* SCSI Bus reset */ - - -/* - * aha_ccb.host_stat values - */ - -#define AHA_OK 0x00 /* cmd ok */ -#define AHA_LINK_OK 0x0a /* Link cmd ok */ -#define AHA_LINK_IT 0x0b /* Link cmd ok + int */ -#define AHA_SEL_TIMEOUT 0x11 /* Selection time out */ -#define AHA_OVER_UNDER 0x12 /* Data over/under run */ -#define AHA_BUS_FREE 0x13 /* Bus dropped at unexpected time */ -#define AHA_INV_BUS 0x14 /* Invalid bus phase/sequence */ -#define AHA_BAD_MBO 0x15 /* Incorrect MBO cmd */ -#define AHA_BAD_CCB 0x16 /* Incorrect ccb opcode */ -#define AHA_BAD_LINK 0x17 /* Not same values of LUN for links */ -#define AHA_INV_TARGET 0x18 /* Invalid target direction */ -#define AHA_CCB_DUP 0x19 /* Duplicate CCB received */ -#define AHA_INV_CCB 0x1a /* Invalid CCB or segment list */ -#define AHA_ABORTED 42 - - - - -struct aha_setup -{ - u_char sync_neg:1; - u_char parity:1; - u_char :6; - u_char speed; - u_char bus_on; - u_char bus_off; - u_char num_mbx; - u_char mbx[3]; - struct - { - u_char offset:4; - u_char period:3; - u_char valid:1; - }sync[8]; - u_char disc_sts; -}; - -struct aha_config -{ - u_char chan; - u_char intr; - u_char scsi_dev:3; - u_char :5; -}; - -struct aha_inquire -{ - u_char boardid; /* type of board */ - /* 0x20 = BusLogic 545, but it gets - the command wrong, only returns - one byte */ - /* 0x31 = AHA-1540 */ - /* 0x41 = AHA-1540A/1542A/1542B */ - /* 0x42 = AHA-1640 */ - /* 0x43 = AHA-1542C */ - /* 0x44 = AHA-1542CF */ - u_char spec_opts; /* special options ID */ - /* 0x41 = Board is standard model */ - u_char revision_1; /* firmware revision [0-9A-Z] */ - u_char revision_2; /* firmware revision [0-9A-Z] */ -}; - -struct aha_extbios -{ - u_char flags; /* Bit 3 == 1 extended bios enabled */ - u_char mailboxlock; /* mail box lock code to unlock it */ -}; - -#define INT9 0x01 -#define INT10 0x02 -#define INT11 0x04 -#define INT12 0x08 -#define INT14 0x20 -#define INT15 0x40 - -#define CHAN0 0x01 -#define CHAN5 0x20 -#define CHAN6 0x40 -#define CHAN7 0x80 - - -/*********************************** end of board definitions***************/ - - -#ifdef MACH -#define PHYSTOKV(x) phystokv(x) -#define KVTOPHYS(x) kvtophys(x) -#else MACH -#ifdef __386BSD__ -#define KVTOPHYS(x) vtophys(x) -#else __386BSD__ -#endif __386BSD__ -#endif MACH -#define AHA_DMA_PAGES AHA_NSEG - -#define PAGESIZ 4096 -#define INVALIDATE_CACHE {asm volatile( ".byte 0x0F ;.byte 0x08" ); } - - -u_char aha_scratch_buf[256]; -#ifdef MACH -caddr_t aha_base[NAHA]; /* base port for each board */ -#else -short aha_base[NAHA]; /* base port for each board */ -#endif -struct aha_mbx aha_mbx[NAHA]; -struct aha_ccb *aha_ccb_free[NAHA]; -struct aha_ccb aha_ccb[NAHA][AHA_MBX_SIZE]; -struct scsi_xfer aha_scsi_xfer[NAHA]; -struct isa_dev *ahainfo[NAHA]; -struct aha_ccb *aha_get_ccb(); -int aha_int[NAHA]; -int aha_dma[NAHA]; -int aha_scsi_dev[NAHA]; -int aha_initialized[NAHA]; -#ifdef OSF -int aha_attached[NAHA]; -#endif OSF -#ifdef AHADEBUG -int aha_debug = 1; -#endif /*AHADEBUG*/ - -int ahaprobe(), ahaattach(), ahaintr(); -#ifdef MACH -struct isa_driver ahadriver = { ahaprobe, 0, ahaattach, "aha", 0, 0, 0}; -int (*ahaintrs[])() = {ahaintr, 0}; -#endif -#ifdef __386BSD__ -struct isa_driver ahadriver = { ahaprobe, ahaattach, "aha",}; -#endif __386BSD__ -static int ahaunit = 0; - - -#define aha_abortmbx(mbx) \ - (mbx)->cmd = AHA_MBO_ABORT; \ - outb(AHA_CMD_DATA_PORT, AHA_START_SCSI); -#define aha_startmbx(mbx) \ - (mbx)->cmd = AHA_MBO_START; \ - outb(AHA_CMD_DATA_PORT, AHA_START_SCSI); - - - -int aha_scsi_cmd(); -int aha_timeout(); -void ahaminphys(); -long int aha_adapter_info(); - -struct scsi_switch aha_switch = -{ - aha_scsi_cmd, - ahaminphys, - 0, - 0, - aha_adapter_info, - "aha", - 0,0 -}; -#define AHA_CMD_TIMEOUT_FUDGE 200 /* multiplied to get Secs */ -#define AHA_RESET_TIMEOUT 1000000 /* time to wait for reset */ -#define AHA_SCSI_TIMEOUT_FUDGE 20 /* divided by for mSecs */ - - -/***********************************************************************\ -* aha_cmd(unit,icnt, ocnt,wait, retval, opcode, args) * -* Activate Adapter command * -* icnt: number of args (outbound bytes written after opcode) * -* ocnt: number of expected returned bytes * -* wait: number of seconds to wait for response * -* retval: buffer where to place returned bytes * -* opcode: opcode AHA_NOP, AHA_MBX_INIT, AHA_START_SCSI ... * -* args: parameters * -* * -* Performs an adapter command through the ports. Not to be confused * -* with a scsi command, which is read in via the dma * -* One of the adapter commands tells it to read in a scsi command * -\***********************************************************************/ - - -aha_cmd(unit,icnt, ocnt, wait,retval, opcode, args) - -u_char *retval; -unsigned opcode; -u_char args; -{ - unsigned *ic = &opcode; - u_char oc; - register i; - int sts; - - /*******************************************************\ - * multiply the wait argument by a big constant * - * zero defaults to 1 * - \*******************************************************/ - if(!wait) - wait = AHA_CMD_TIMEOUT_FUDGE * delaycount; - else - wait *= AHA_CMD_TIMEOUT_FUDGE * delaycount; - /*******************************************************\ - * Wait for the adapter to go idle, unless it's one of * - * the commands which don't need this * - \*******************************************************/ - if (opcode != AHA_MBX_INIT && opcode != AHA_START_SCSI) - { - i = AHA_CMD_TIMEOUT_FUDGE * delaycount; /* 1 sec?*/ - while (--i) - { - sts = inb(AHA_CTRL_STAT_PORT); - if (sts & AHA_IDLE) - { - break; - } - } - if (!i) - { - printf("aha%d: aha_cmd, host not idle(0x%x)\n", - unit,sts); - return(ENXIO); - } - } - /*******************************************************\ - * Now that it is idle, if we expect output, preflush the* - * queue feeding to us. * - \*******************************************************/ - if (ocnt) - { - while((inb(AHA_CTRL_STAT_PORT)) & AHA_DF) - inb(AHA_CMD_DATA_PORT); - } - - /*******************************************************\ - * Output the command and the number of arguments given * - * for each byte, first check the port is empty. * - \*******************************************************/ - icnt++; /* include the command */ - while (icnt--) - { - sts = inb(AHA_CTRL_STAT_PORT); - for (i=0; i< wait; i++) - { - sts = inb(AHA_CTRL_STAT_PORT); - if (!(sts & AHA_CDF)) - break; - } - if (i >= wait) - { - printf("aha%d: aha_cmd, cmd/data port full\n",unit); - outb(AHA_CTRL_STAT_PORT, AHA_SRST); - return(ENXIO); - } - outb(AHA_CMD_DATA_PORT, (u_char)(*ic++)); - } - /*******************************************************\ - * If we expect input, loop that many times, each time, * - * looking for the data register to have valid data * - \*******************************************************/ - while (ocnt--) - { - sts = inb(AHA_CTRL_STAT_PORT); - for (i=0; i< wait; i++) - { - sts = inb(AHA_CTRL_STAT_PORT); - if (sts & AHA_DF) - break; - } - if (i >= wait) - { - printf("aha%d: aha_cmd, cmd/data port empty %d\n", - unit,ocnt); - return(ENXIO); - } - oc = inb(AHA_CMD_DATA_PORT); - if (retval) - *retval++ = oc; - } - /*******************************************************\ - * Wait for the board to report a finised instruction * - \*******************************************************/ - i=AHA_CMD_TIMEOUT_FUDGE * delaycount; /* 1 sec? */ - while (--i) - { - sts = inb(AHA_INTR_PORT); - if (sts & AHA_HACC) - { - break; - } - } - if (!i) - { - printf("aha%d: aha_cmd, host not finished(0x%x)\n",unit,sts); - return(ENXIO); - } - outb(AHA_CTRL_STAT_PORT, AHA_IRST); - return(0); -} - -/*******************************************************\ -* Check if the device can be found at the port given * -* and if so, set it up ready for further work * -* as an argument, takes the isa_dev structure from * -* autoconf.c * -\*******************************************************/ -ahaprobe(dev) -struct isa_dev *dev; -{ - int unit = ahaunit; -#if defined(OSF) - static ihandler_t aha_handler[NAHA]; - static ihandler_id_t *aha_handler_id[NAHA]; - register ihandler_t *chp = &aha_handler[unit];; -#endif /* defined(OSF) */ - - /***********************************************\ - /***********************************************\ - * find unit and check we have that many defined * - \***********************************************/ - dev->dev_unit = unit; - aha_base[unit] = dev->dev_addr; - if(unit >= NAHA) - { - printf("aha%d: unit number too high\n",unit); - return(0); - } - /***********************************************\ - * Try initialise a unit at this location * - * sets up dma and bus speed, loads aha_int[unit]* - \***********************************************/ - if (aha_init(unit) != 0) - { - return(0); - } - - /***********************************************\ - * If it's there, put in it's interrupt vectors * - \***********************************************/ -#if !defined(OSF) -#if defined MACH - iunit[aha_int[unit]] =unit; - ivect[aha_int[unit]] = ahaintr; - intpri[aha_int[unit]] = dev->dev_spl; - form_pic_mask(); - /*take_dev_irq(dev);*/ -#else -#ifdef __386BSD__ - dev->id_irq = (1 << aha_int[unit]); - dev->id_drq = aha_dma[unit]; -#endif __386BSD__ -#endif -#else /* !defined(OSF) */ - - dev->dev_pic = aha_dma[unit]; - chp->ih_level = dev->dev_pic; - chp->ih_handler = dev->dev_intr[0]; - chp->ih_resolver = i386_resolver; - chp->ih_rdev = dev; - chp->ih_stats.intr_type = INTR_DEVICE; - chp->ih_stats.intr_cnt = 0; - chp->ih_hparam[0].intparam = unit; - if ((aha_handler_id[unit] = handler_add(chp)) != NULL) - handler_enable(aha_handler_id[unit]); - else - panic("Unable to add aha interrupt handler"); -#endif /* !defined(OSF) */ -#ifndef __386BSD__ - printf("port=%x spl=%d\n", dev->dev_addr, dev->dev_spl); -#endif __386BSD__ - ahaunit ++; - return(1); -} - -/***********************************************\ -* Attach all the sub-devices we can find * -\***********************************************/ -ahaattach(dev) -struct isa_dev *dev; -{ - int unit = dev->dev_unit; - - /***********************************************\ - * ask the adapter what subunits are present * - \***********************************************/ - scsi_attachdevs( unit, aha_scsi_dev[unit], &aha_switch); -#if defined(OSF) - aha_attached[unit]=1; -#endif /* defined(OSF) */ - return; -} - -/***********************************************\ -* Return some information to the caller about * -* the adapter and it's capabilities * -\***********************************************/ -long int aha_adapter_info(unit) -int unit; -{ - return(2); /* 2 outstanding requests at a time per device */ -} - -/***********************************************\ -* Catch an interrupt from the adaptor * -\***********************************************/ -ahaintr(unit) -{ - struct aha_ccb *ccb; - unsigned char stat; - register i; - -#ifdef AHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("ahaintr "); -#endif /*AHADEBUG*/ - /***********************************************\ - * First acknowlege the interrupt, Then if it's * - * not telling about a completed operation * - * just return. * - \***********************************************/ - stat = inb(AHA_INTR_PORT); - outb(AHA_CTRL_STAT_PORT, AHA_IRST); -#ifdef AHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("int "); -#endif /*AHADEBUG*/ - if (! (stat & AHA_MBIF)) - return(1); -#ifdef AHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("b "); -#endif /*AHADEBUG*/ -#if defined(OSF) - if (!aha_attached[unit]) - { - return(1); - } -#endif /* defined(OSF) */ - /***********************************************\ - * If it IS then process the competed operation * - \***********************************************/ - for (i = 0; i < AHA_MBX_SIZE; i++) - { - if (aha_mbx[unit].mbi[i].stat != AHA_MBI_FREE) - { - ccb = (struct aha_ccb *)PHYSTOKV( - (_3btol(aha_mbx[unit].mbi[i].ccb_addr))); - - if((stat = aha_mbx[unit].mbi[i].stat) != AHA_MBI_OK) - { - switch(stat) - { - case AHA_MBI_ABORT: -#ifdef AHADEBUG - if(aha_debug) - printf("abort"); -#endif /*AHADEBUG*/ - ccb->host_stat = AHA_ABORTED; - break; - - case AHA_MBI_UNKNOWN: - ccb = (struct aha_ccb *)0; -#ifdef AHADEBUG - if(aha_debug) - printf("unknown ccb for abort "); -#endif /*AHADEBUG*/ - /* may have missed it */ - /* no such ccb known for abort */ - - case AHA_MBI_ERROR: - break; - - default: - panic("Impossible mbxi status"); - - } -#ifdef AHADEBUG - if( aha_debug && ccb ) - { - u_char *cp; - cp = (u_char *)(&(ccb->scsi_cmd)); - printf("op=%x %x %x %x %x %x\n", - cp[0], cp[1], cp[2], - cp[3], cp[4], cp[5]); - printf("stat %x for mbi[%d]\n" - , aha_mbx[unit].mbi[i].stat, i); - printf("addr = 0x%x\n", ccb); - } -#endif /*AHADEBUG*/ - } - if(ccb) - { - untimeout(aha_timeout,ccb); - aha_done(unit,ccb); - } - aha_mbx[unit].mbi[i].stat = AHA_MBI_FREE; - } - } - return(1); -} - -/***********************************************\ -* A ccb (and hence a mbx-out is put onto the * -* free list. * -\***********************************************/ -aha_free_ccb(unit,ccb, flags) -struct aha_ccb *ccb; -{ - unsigned int opri; - -#ifdef AHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("ccb%d(0x%x)> ",unit,flags); -#endif /*AHADEBUG*/ - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - - ccb->next = aha_ccb_free[unit]; - aha_ccb_free[unit] = ccb; - ccb->flags = CCB_FREE; - /***********************************************\ - * If there were none, wake abybody waiting for * - * one to come free, starting with queued entries* - \***********************************************/ - if (!ccb->next) { - wakeup(&aha_ccb_free[unit]); - } - if (!(flags & SCSI_NOMASK)) - splx(opri); -} - -/***********************************************\ -* Get a free ccb (and hence mbox-out entry) * -\***********************************************/ -struct aha_ccb * -aha_get_ccb(unit,flags) -{ - unsigned opri; - struct aha_ccb *rc; - -#ifdef AHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("<ccb%d(0x%x) ",unit,flags); -#endif /*AHADEBUG*/ - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - /***********************************************\ - * If we can and have to, sleep waiting for one * - * to come free * - \***********************************************/ - while ((!(rc = aha_ccb_free[unit])) && (!(flags & SCSI_NOSLEEP))) - { - sleep(&aha_ccb_free[unit], PRIBIO); - } - if (rc) - { - aha_ccb_free[unit] = aha_ccb_free[unit]->next; - rc->flags = CCB_ACTIVE; - } - if (!(flags & SCSI_NOMASK)) - splx(opri); - return(rc); -} - - -/***********************************************\ -* We have a ccb which has been processed by the * -* adaptor, now we look to see how the operation * -* went. Wake up the owner if waiting * -\***********************************************/ -aha_done(unit,ccb) -struct aha_ccb *ccb; -{ - struct scsi_sense_data *s1,*s2; - struct scsi_xfer *xs = ccb->xfer; - -#ifdef AHADEBUG - if(scsi_debug & PRINTROUTINES ) - printf("aha_done "); -#endif /*AHADEBUG*/ - /***********************************************\ - * Otherwise, put the results of the operation * - * into the xfer and call whoever started it * - \***********************************************/ - if(!(xs->flags & INUSE)) - { - printf("aha%d: exiting but not in use!\n",unit); - Debugger(); - } - if ( ( ccb->host_stat != AHA_OK - || ccb->target_stat != SCSI_OK) - && (!(xs->flags & SCSI_ERR_OK))) - { - s1 = (struct scsi_sense_data *)(((char *)(&ccb->scsi_cmd)) - + ccb->scsi_cmd_length); - s2 = &(xs->sense); - - if(ccb->host_stat) - { - switch(ccb->host_stat) - { - case AHA_ABORTED: - case AHA_SEL_TIMEOUT: /* No response */ - xs->error = XS_TIMEOUT; - break; - default: /* Other scsi protocol messes */ - xs->error = XS_DRIVER_STUFFUP; -#ifdef AHADEBUG - if (aha_debug > 1) - { - printf("host_stat%x\n", - ccb->host_stat); - } -#endif /*AHADEBUG*/ - } - - } - else - { - switch(ccb->target_stat) - { - case 0x02: - /* structure copy!!!!!*/ - *s2=*s1; - xs->error = XS_SENSE; - break; - case 0x08: - xs->error = XS_BUSY; - break; - default: -#ifdef AHADEBUG - if (aha_debug > 1) - { - printf("target_stat%x\n", - ccb->target_stat); - } -#endif /*AHADEBUG*/ - xs->error = XS_DRIVER_STUFFUP; - } - } - } - else /* All went correctly OR errors expected */ - { - xs->resid = 0; - } - xs->flags |= ITSDONE; - aha_free_ccb(unit,ccb, xs->flags); - if(xs->when_done) - (*(xs->when_done))(xs->done_arg,xs->done_arg2); -} - - -/***********************************************\ -* Start the board, ready for normal operation * -\***********************************************/ -aha_init(unit) -int unit; -{ - unsigned char ad[3]; - volatile int i,sts; - struct aha_config conf; - struct aha_inquire inquire; - struct aha_extbios extbios; - - /***********************************************\ - * reset board, If it doesn't respond, assume * - * that it's not there.. good for the probe * - \***********************************************/ - - outb(AHA_CTRL_STAT_PORT, AHA_HRST|AHA_SRST); - - for (i=0; i < AHA_RESET_TIMEOUT; i++) - { - sts = inb(AHA_CTRL_STAT_PORT) ; - if ( sts == (AHA_IDLE | AHA_INIT)) - break; - } - if (i >= AHA_RESET_TIMEOUT) - { -#ifdef AHADEBUG - if (aha_debug) - printf("aha_init: No answer from adaptec board\n"); -#endif /*AHADEBUG*/ - return(ENXIO); - } - /* - * Assume we have a board at this stage, do an adapter inquire - * to find out what type of controller it is - */ - aha_cmd(unit, 0, sizeof(inquire), 1 ,&inquire, AHA_INQUIRE); -#ifdef AHADEBUG - printf("aha%d: inquire %x, %x, %x, %x\n", - unit, - inquire.boardid, inquire.spec_opts, - inquire.revision_1, inquire.revision_2); -#endif /* AHADEBUG */ - /* - * XXX The Buslogic 545S gets the AHA_INQUIRE command wrong, - * they only return one byte which causes us to print an error, - * so if the boardid comes back as 0x20, tell the user why they - * get the "cmd/data port empty" message - */ - if (inquire.boardid == 0x20) { - /* looks like a Buslogic 545 */ - printf ("aha%d: above cmd/data port empty do to Buslogic 545\n", - unit); - } - /* - * If we are on a 1542C or 1542CF find out if the extended bios - * is enabled, if it is disable it, or else it will screw us up later - */ - if ((inquire.boardid == 0x43) || (inquire.boardid == 0x44)) { - aha_cmd(unit, 0, sizeof(extbios), 0, &extbios, AHA_EXT_BIOS); -#ifdef AHADEBUG - printf("aha%d: extended bios flags %x\n", unit, extbios.flags); -#endif /* AHADEBUG */ - if (extbios.flags & 0x8) { - printf("aha%d: disabling bios enhanced features\n"); - aha_cmd(unit, 2, 0, 0, 0, AHA_MBX_ENABLE, - 0, extbios.mailboxlock); - } - } - /***********************************************\ - * Setup dma channel from jumpers and save int * - * level * - \***********************************************/ -#ifdef __386BSD__ - printf("aha%d: reading board settings, ",unit); -#define PRNT(x) printf(x) -#else __386BSD__ - printf("aha%d:",unit); -#define PRNT(x) printf(x) -#endif __386BSD__ - DELAY(10000); /* for Bustek 545 */ - aha_cmd(unit,0, sizeof(conf), 0 ,&conf, AHA_CONF_GET); - switch(conf.chan) - { - case CHAN0: - outb(0x0b, 0x0c); - outb(0x0a, 0x00); - aha_dma[unit] = 0; - PRNT("dma=0 "); - break; - case CHAN5: - outb(0xd6, 0xc1); - outb(0xd4, 0x01); - aha_dma[unit] = 5; - PRNT("dma=5 "); - break; - case CHAN6: - outb(0xd6, 0xc2); - outb(0xd4, 0x02); - aha_dma[unit] = 6; - PRNT("dma=6 "); - break; - case CHAN7: - outb(0xd6, 0xc3); - outb(0xd4, 0x03); - aha_dma[unit] = 7; - PRNT("dma=7 "); - break; - default: - printf("illegal dma jumper setting\n"); - return(EIO); - } - switch(conf.intr) - { - case INT9: - aha_int[unit] = 9; - PRNT("int=9 "); - break; - case INT10: - aha_int[unit] = 10; - PRNT("int=10 "); - break; - case INT11: - aha_int[unit] = 11; - PRNT("int=11 "); - break; - case INT12: - aha_int[unit] = 12; - PRNT("int=12 "); - break; - case INT14: - aha_int[unit] = 14; - PRNT("int=14 "); - break; - case INT15: - aha_int[unit] = 15; - PRNT("int=15 "); - break; - default: - printf("illegal int jumper setting\n"); - return(EIO); - } - /* who are we on the scsi bus */ - aha_scsi_dev[unit] = conf.scsi_dev; - - - /***********************************************\ - * Initialize memory transfer speed * - \***********************************************/ -/* - * XXX This code seems to BREAK more boards than it makes - * work right, we are just going to NOP this here... - */ -#if 0 - if(!(aha_set_bus_speed(unit))) - { - return(EIO); - } -#else - printf ("\n"); -#endif - - - /***********************************************\ - * Initialize mail box * - \***********************************************/ - - lto3b(KVTOPHYS(&aha_mbx[unit]), ad); - - aha_cmd(unit,4, 0, 0, 0, AHA_MBX_INIT, - AHA_MBX_SIZE, - ad[0], - ad[1], - ad[2]); - - - /***********************************************\ - * link the ccb's with the mbox-out entries and * - * into a free-list * - \***********************************************/ - for (i=0; i < AHA_MBX_SIZE; i++) { - aha_ccb[unit][i].next = aha_ccb_free[unit]; - aha_ccb_free[unit] = &aha_ccb[unit][i]; - aha_ccb_free[unit]->flags = CCB_FREE; - aha_ccb_free[unit]->mbx = &aha_mbx[unit].mbo[i]; - lto3b(KVTOPHYS(aha_ccb_free[unit]), aha_mbx[unit].mbo[i].ccb_addr); - } - - /***********************************************\ - * Note that we are going and return (to probe) * - \***********************************************/ - aha_initialized[unit]++; - return(0); -} - - - - - -void ahaminphys(bp) -struct buf *bp; -{ -#ifdef MACH -#if !defined(OSF) - bp->b_flags |= B_NPAGES; /* can support scat/gather */ -#endif /* !defined(OSF) */ -#endif MACH -/* aha seems to explode with 17 segs (64k may require 17 segs) */ -/* on old boards so use a max of 16 segs if you have problems here*/ - if(bp->b_bcount > ((AHA_NSEG - 1) * PAGESIZ)) - { - bp->b_bcount = ((AHA_NSEG - 1) * PAGESIZ); - } -} - -/***********************************************\ -* start a scsi operation given the command and * -* the data address. Also needs the unit, target * -* and lu * -\***********************************************/ -int aha_scsi_cmd(xs) -struct scsi_xfer *xs; -{ - struct scsi_sense_data *s1,*s2; - struct aha_ccb *ccb; - struct aha_scat_gath *sg; - int seg; /* scatter gather seg being worked on */ - int i = 0; - int rc = 0; - int thiskv; - int thisphys,nextphys; - int unit =xs->adapter; - int bytes_this_seg,bytes_this_page,datalen,flags; - struct iovec *iovp; - int s; - -#ifdef AHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("aha_scsi_cmd "); -#endif /*AHADEBUG*/ - /***********************************************\ - * get a ccb (mbox-out) to use. If the transfer * - * is from a buf (possibly from interrupt time) * - * then we can't allow it to sleep * - \***********************************************/ - flags = xs->flags; - if(!(flags & INUSE)) - { - printf("aha%d: not in use!\n",unit); - Debugger(); - xs->flags |= INUSE; - } - if(flags & ITSDONE) - { - printf("aha%d: Already done! check device retry code\n",unit); - Debugger(); - xs->flags &= ~ITSDONE; - } - if(xs->bp) flags |= (SCSI_NOSLEEP); /* just to be sure */ - if (!(ccb = aha_get_ccb(unit,flags))) - { - xs->error = XS_DRIVER_STUFFUP; - return(TRY_AGAIN_LATER); - } - - if (ccb->mbx->cmd != AHA_MBO_FREE) - printf("aha%d: MBO not free\n",unit); - - /***********************************************\ - * Put all the arguments for the xfer in the ccb * - \***********************************************/ - ccb->xfer = xs; - if(flags & SCSI_RESET) - { - ccb->opcode = AHA_RESET_CCB; - } - else - { - /* can't use S/G if zero length */ - ccb->opcode = (xs->datalen? - AHA_INIT_SCAT_GATH_CCB - :AHA_INITIATOR_CCB); - } - ccb->target = xs->targ;; - ccb->data_out = 0; - ccb->data_in = 0; - ccb->lun = xs->lu; - ccb->scsi_cmd_length = xs->cmdlen; - ccb->req_sense_length = sizeof(ccb->scsi_sense); - - if((xs->datalen) && (!(flags & SCSI_RESET))) - { /* can use S/G only if not zero length */ - lto3b(KVTOPHYS(ccb->scat_gath), ccb->data_addr ); - sg = ccb->scat_gath ; - seg = 0; - if(flags & SCSI_DATA_UIO) - { - iovp = ((struct uio *)xs->data)->uio_iov; - datalen = ((struct uio *)xs->data)->uio_iovcnt; - while ((datalen) && (seg < AHA_NSEG)) - { - lto3b(iovp->iov_base,&(sg->seg_addr)); - lto3b(iovp->iov_len,&(sg->seg_len)); -#ifdef AHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x@0x%x)" - ,iovp->iov_len - ,iovp->iov_base); -#endif /*AHADEBUG*/ - sg++; - iovp++; - seg++; - datalen--; - } - } - else - { - /***********************************************\ - * Set up the scatter gather block * - \***********************************************/ - -#ifdef AHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("%d @0x%x:- ",xs->datalen,xs->data); -#endif /*AHADEBUG*/ - datalen = xs->datalen; - thiskv = (int)xs->data; - thisphys = KVTOPHYS(thiskv); - - while ((datalen) && (seg < AHA_NSEG)) - { - bytes_this_seg = 0; - - /* put in the base address */ - lto3b(thisphys,&(sg->seg_addr)); - -#ifdef AHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("0x%x",thisphys); -#endif /*AHADEBUG*/ - - /* do it at least once */ - nextphys = thisphys; - while ((datalen) && (thisphys == nextphys)) - /***************************************\ - * This page is contiguous (physically) * - * with the the last, just extend the * - * length * - \***************************************/ - { - /** how far to the end of the page ***/ - nextphys = (thisphys & (~(PAGESIZ - 1))) - + PAGESIZ; - bytes_this_page = nextphys - thisphys; - /**** or the data ****/ - bytes_this_page = min(bytes_this_page - ,datalen); - bytes_this_seg += bytes_this_page; - datalen -= bytes_this_page; - - /**** get more ready for the next page ****/ - thiskv = (thiskv & (~(PAGESIZ - 1))) - + PAGESIZ; - if(datalen) - thisphys = KVTOPHYS(thiskv); - } - /***************************************\ - * next page isn't contiguous, finish the seg* - \***************************************/ -#ifdef AHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x)",bytes_this_seg); -#endif /*AHADEBUG*/ - lto3b(bytes_this_seg,&(sg->seg_len)); - sg++; - seg++; - } - } - lto3b(seg * sizeof(struct aha_scat_gath),ccb->data_length); -#ifdef AHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("\n"); -#endif /*AHADEBUG*/ - if (datalen) - { /* there's still data, must have run out of segs! */ - printf("aha%d: aha_scsi_cmd, more than %d DMA segs\n", - unit,AHA_NSEG); - xs->error = XS_DRIVER_STUFFUP; - aha_free_ccb(unit,ccb,flags); - return(HAD_ERROR); - } - - } - else - { /* No data xfer, use non S/G values */ - lto3b(0, ccb->data_addr ); - lto3b(0,ccb->data_length); - } - lto3b(0, ccb->link_addr ); - /***********************************************\ - * Put the scsi command in the ccb and start it * - \***********************************************/ - if(!(flags & SCSI_RESET)) - bcopy(xs->cmd, &ccb->scsi_cmd, ccb->scsi_cmd_length); -#ifdef AHADEBUG - if(scsi_debug & SHOWCOMMANDS) - { - u_char *b = (u_char *)&ccb->scsi_cmd; - if(!(flags & SCSI_RESET)) - { - int i = 0; - printf("aha%d:%d:%d-" - ,unit - ,ccb->target - ,ccb->lun ); - while(i < ccb->scsi_cmd_length ) - { - if(i) printf(","); - printf("%x",b[i++]); - } - } - else - { - printf("aha%d:%d:%d-RESET- " - ,unit - ,ccb->target - ,ccb->lun - ); - } - } -#endif /*AHADEBUG*/ - if (!(flags & SCSI_NOMASK)) - { - s= splbio(); /* stop instant timeouts */ - timeout(aha_timeout,ccb,(xs->timeout * hz) / 1000); - aha_startmbx(ccb->mbx); - /***********************************************\ - * Usually return SUCCESSFULLY QUEUED * - \***********************************************/ - splx(s); -#ifdef AHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("sent "); -#endif /*AHADEBUG*/ - return(SUCCESSFULLY_QUEUED); - } - aha_startmbx(ccb->mbx); -#ifdef AHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("cmd_sent, waiting "); -#endif /*AHADEBUG*/ - /***********************************************\ - * If we can't use interrupts, poll on completion* - \***********************************************/ - { - int done = 0; - int count = delaycount * xs->timeout / AHA_SCSI_TIMEOUT_FUDGE; - while((!done) && count) - { - i=0; - while ( (!done) && i<AHA_MBX_SIZE) - { - if ((aha_mbx[unit].mbi[i].stat != AHA_MBI_FREE ) - && (PHYSTOKV(_3btol(aha_mbx[unit].mbi[i].ccb_addr) - == (int)ccb))) - { - aha_mbx[unit].mbi[i].stat = AHA_MBI_FREE; - aha_done(unit,ccb); - done++; - } - i++; - } - count--; - } - if (!count) - { - if (!(xs->flags & SCSI_SILENT)) - printf("aha%d: cmd fail\n",unit); - aha_abortmbx(ccb->mbx); - count = delaycount * 2000 / AHA_SCSI_TIMEOUT_FUDGE; - while((!done) && count) - { - i=0; - while ( (!done) && i<AHA_MBX_SIZE) - { - if ((aha_mbx[unit].mbi[i].stat != AHA_MBI_FREE ) - && (PHYSTOKV(_3btol(aha_mbx[unit].mbi[i].ccb_addr) - == (int)ccb))) - { - aha_mbx[unit].mbi[i].stat = AHA_MBI_FREE; - aha_done(unit,ccb); - done++; - } - i++; - } - count--; - } - if(!count) - { - printf("aha%d: abort failed in wait\n",unit); - ccb->mbx->cmd = AHA_MBO_FREE; - } - aha_free_ccb(unit,ccb,flags); - ahaintr(unit); - xs->error = XS_DRIVER_STUFFUP; - return(HAD_ERROR); - } - ahaintr(unit); - if(xs->error) return(HAD_ERROR); - return(COMPLETE); - - } -} -/***************************************************************\ -* try each speed in turn, when we find one that works, use * -* the NEXT one for a safety margin, unless that doesn't exist * -* or doesn't work. returns the nSEC value of the time used * -* or 0 if it could get a working speed ( or the NEXT speed * -* failed) * -\***************************************************************/ - -int aha_set_bus_speed(unit) -int unit; -{ - int speed; - int retval,retval2; - -#ifdef EISA - speed = 0; /* start at the fastest */ -#else EISA - speed = 1; /* 100 ns can crash some ISA busses (!?!) */ -#endif EISA - while (1) - { - retval = aha_bus_speed_check(unit,speed); - if(retval == HAD_ERROR) - { - printf("no working bus speed!!!\n"); - return(0); - } - if(retval == 0) - { - speed++; - } - else /* Go one slower to be safe */ - { /* unless eisa at 100 ns.. trust it */ - if(speed != 0) - { - speed++; - } - printf("%d nSEC ok, using ",retval); - retval2 = aha_bus_speed_check(unit,speed); - if(retval2 == HAD_ERROR) /* retval is slowest already */ - { - printf("marginal "); - retval2 = retval; - } - if(retval2) - { - printf("%d nSEC\n",retval2); - return(retval2); - } - else - { - printf(".. slower failed, abort\n",retval); - return(0); - } - - } - } -} - -/***************************************************************\ -* Set the DMA speed to the Nth speed and try an xfer. If it * -* fails return 0, if it succeeds return the nSec value selected * -* If there is no such speed return HAD_ERROR. * -\***************************************************************/ -static struct bus_speed -{ - char arg; - int nsecs; -}aha_bus_speeds[] = -{ - {0x88,100}, - {0x99,150}, - {0xaa,200}, - {0xbb,250}, - {0xcc,300}, - {0xdd,350}, - {0xee,400}, - {0xff,450} -}; -static char aha_test_string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz!@"; - -int aha_bus_speed_check(unit,speed) -int unit,speed; -{ - int numspeeds = sizeof(aha_bus_speeds)/sizeof(struct bus_speed); - u_char ad[3]; - - /*******************************************************\ - * Check we have such an entry * - \*******************************************************/ - if(speed >= numspeeds) return(HAD_ERROR); /* illegal speed */ - - /*******************************************************\ - * Set the dma-speed * - \*******************************************************/ - aha_cmd(unit,1, 0, 0, 0, AHA_SPEED_SET,aha_bus_speeds[speed].arg); - - /*******************************************************\ - * put the test data into the buffer and calculate * - * it's address. Read it onto the board * - \*******************************************************/ - strcpy(aha_scratch_buf,aha_test_string); - lto3b(KVTOPHYS(aha_scratch_buf),ad); - - aha_cmd(unit,3, 0, 0, 0, AHA_WRITE_FIFO, ad[0], ad[1], ad[2]); - - /*******************************************************\ - * clear the buffer then copy the contents back from the * - * board. * - \*******************************************************/ - bzero(aha_scratch_buf,54); /* 54 bytes transfered by test */ - - aha_cmd(unit,3, 0, 0, 0, AHA_READ_FIFO, ad[0], ad[1], ad[2]); - - /*******************************************************\ - * Compare the original data and the final data and * - * return the correct value depending upon the result * - \*******************************************************/ - if(strcmp(aha_test_string,aha_scratch_buf)) - { /* copy failed.. assume too fast */ - return(0); - } - else - { /* copy succeded assume speed ok */ - return(aha_bus_speeds[speed].nsecs); - } -} - - - -aha_timeout(struct aha_ccb *ccb) -{ - int unit; - int s = splbio(); - - unit = ccb->xfer->adapter; - printf("aha%d: device %d timed out ",unit ,ccb->xfer->targ); - - /***************************************\ - * If The ccb's mbx is not free, then * - * the board has gone south * - \***************************************/ - if(ccb->mbx->cmd != AHA_MBO_FREE) - { - printf("aha%d: not taking commands!\n",unit); - Debugger(); - } - /***************************************\ - * If it has been through before, then * - * a previous abort has failed, don't * - * try abort again * - \***************************************/ - if(ccb->flags == CCB_ABORTED) /* abort timed out */ - { - printf(" AGAIN\n"); - ccb->xfer->retries = 0; /* I MEAN IT ! */ - ccb->host_stat = AHA_ABORTED; - aha_done(unit,ccb); - } - else /* abort the operation that has timed out */ - { - printf("\n"); - aha_abortmbx(ccb->mbx); - /* 2 secs for the abort */ - timeout(aha_timeout,ccb,2 * hz); - ccb->flags = CCB_ABORTED; - } - splx(s); -} diff --git a/sys/i386/isa/aha1742.c b/sys/i386/isa/aha1742.c deleted file mode 100644 index 1e3e154..0000000 --- a/sys/i386/isa/aha1742.c +++ /dev/null @@ -1,1322 +0,0 @@ -/* - * Written by Julian Elischer (julian@tfs.com) - * for TRW Financial Systems for use under the MACH(2.5) operating system. - * - * TRW Financial Systems, in accordance with their agreement with Carnegie - * Mellon University, makes this software available to CMU to distribute - * or use in any manner that they see fit as long as this message is kept with - * the software. For this reason TFS also grants any other persons or - * organisations permission to use or modify this software. - * - * TFS supplies this software to be publicly redistributed - * on the understanding that TFS is not responsible for the correct - * functioning of this software in any circumstances. - * - * commenced: Sun Sep 27 18:14:01 PDT 1992 - * - * $Id: aha1742.c,v 1.9 1993/08/28 03:07:40 rgrimes Exp $ - */ - -#include <sys/types.h> -#include <ahb.h> - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/errno.h> -#include <sys/ioctl.h> -#include <sys/buf.h> -#include <sys/proc.h> -#include <sys/user.h> - -#ifdef MACH /* EITHER CMU OR OSF */ -#include <i386/ipl.h> -#include <i386at/scsi.h> -#include <i386at/scsiconf.h> - -#ifdef OSF /* OSF ONLY */ -#include <sys/table.h> -#include <i386/handler.h> -#include <i386/dispatcher.h> -#include <i386/AT386/atbus.h> - -#else OSF /* CMU ONLY */ -#include <i386at/atbus.h> -#include <i386/pio.h> -#endif OSF -#endif MACH /* end of MACH specific */ - -#ifdef __386BSD__ /* 386BSD specific */ -#define isa_dev isa_device -#define dev_unit id_unit -#define dev_addr id_iobase - -#include <i386/include/pio.h> -#include <i386/isa/isa_device.h> -#include <scsi/scsi_all.h> -#include <scsi/scsiconf.h> -#endif __386BSD__ - -/**/ - -#ifdef __386BSD__ -#include "ddb.h" -#if NDDB > 0 -int Debugger(); -#else NDDB -#define Debugger() panic("should call debugger here (adaptec.c)") -#endif NDDB -#endif __386BSD__ - -#ifdef MACH -int Debugger(); -#endif MACH - -typedef unsigned long int physaddr; -extern int hz; - -#ifdef MACH -extern physaddr kvtophys(); -#define PHYSTOKV(x) phystokv(x) -#define KVTOPHYS(x) kvtophys(x) -#endif MACH - -#ifdef __386BSD__ -#define KVTOPHYS(x) vtophys(x) -#endif __386BSD__ - -extern int delaycount; /* from clock setup code */ -#define NUM_CONCURRENT 16 /* number of concurrent ops per board */ -#define AHB_NSEG 33 /* number of dma segments supported */ -#define FUDGE(X) (X>>1) /* our loops are slower than spinwait() */ -/**/ -/***********************************************************************\ -* AHA1740 standard EISA Host ID regs (Offset from slot base) * -\***********************************************************************/ -#define HID0 0xC80 /* 0,1: msb of ID2, 3-7: ID1 */ -#define HID1 0xC81 /* 0-4: ID3, 4-7: LSB ID2 */ -#define HID2 0xC82 /* product, 0=174[20] 1 = 1744 */ -#define HID3 0xC83 /* firmware revision */ - -#define CHAR1(B1,B2) (((B1>>2) & 0x1F) | '@') -#define CHAR2(B1,B2) (((B1<<3) & 0x18) | ((B2>>5) & 0x7)|'@') -#define CHAR3(B1,B2) ((B2 & 0x1F) | '@') - -/* AHA1740 EISA board control registers (Offset from slot base) */ -#define EBCTRL 0xC84 -#define CDEN 0x01 -/***********************************************************************\ -* AHA1740 EISA board mode registers (Offset from slot base) * -\***********************************************************************/ -#define PORTADDR 0xCC0 -#define PORTADDR_ENHANCED 0x80 -#define BIOSADDR 0xCC1 -#define INTDEF 0xCC2 -#define SCSIDEF 0xCC3 -#define BUSDEF 0xCC4 -#define RESV0 0xCC5 -#define RESV1 0xCC6 -#define RESV2 0xCC7 -/**** bit definitions for INTDEF ****/ -#define INT9 0x00 -#define INT10 0x01 -#define INT11 0x02 -#define INT12 0x03 -#define INT14 0x05 -#define INT15 0x06 -#define INTHIGH 0x08 /* int high=ACTIVE (else edge) */ -#define INTEN 0x10 -/**** bit definitions for SCSIDEF ****/ -#define HSCSIID 0x0F /* our SCSI ID */ -#define RSTPWR 0x10 /* reset scsi bus on power up or reset */ -/**** bit definitions for BUSDEF ****/ -#define B0uS 0x00 /* give up bus immediatly */ -#define B4uS 0x01 /* delay 4uSec. */ -#define B8uS 0x02 -/***********************************************************************\ -* AHA1740 ENHANCED mode mailbox control regs (Offset from slot base) * -\***********************************************************************/ -#define MBOXOUT0 0xCD0 -#define MBOXOUT1 0xCD1 -#define MBOXOUT2 0xCD2 -#define MBOXOUT3 0xCD3 - -#define ATTN 0xCD4 -#define G2CNTRL 0xCD5 -#define G2INTST 0xCD6 -#define G2STAT 0xCD7 - -#define MBOXIN0 0xCD8 -#define MBOXIN1 0xCD9 -#define MBOXIN2 0xCDA -#define MBOXIN3 0xCDB - -#define G2STAT2 0xCDC - -/*******************************************************\ -* Bit definitions for the 5 control/status registers * -\*******************************************************/ -#define ATTN_TARGET 0x0F -#define ATTN_OPCODE 0xF0 -#define OP_IMMED 0x10 -#define AHB_TARG_RESET 0x80 -#define OP_START_ECB 0x40 -#define OP_ABORT_ECB 0x50 - -#define G2CNTRL_SET_HOST_READY 0x20 -#define G2CNTRL_CLEAR_EISA_INT 0x40 -#define G2CNTRL_HARD_RESET 0x80 - -#define G2INTST_TARGET 0x0F -#define G2INTST_INT_STAT 0xF0 -#define AHB_ECB_OK 0x10 -#define AHB_ECB_RECOVERED 0x50 -#define AHB_HW_ERR 0x70 -#define AHB_IMMED_OK 0xA0 -#define AHB_ECB_ERR 0xC0 -#define AHB_ASN 0xD0 /* for target mode */ -#define AHB_IMMED_ERR 0xE0 - -#define G2STAT_BUSY 0x01 -#define G2STAT_INT_PEND 0x02 -#define G2STAT_MBOX_EMPTY 0x04 - -#define G2STAT2_HOST_READY 0x01 -/**/ - -struct ahb_dma_seg -{ - physaddr addr; - long len; -}; - -struct ahb_ecb_status -{ - u_short status; -# define ST_DON 0x0001 -# define ST_DU 0x0002 -# define ST_QF 0x0008 -# define ST_SC 0x0010 -# define ST_DO 0x0020 -# define ST_CH 0x0040 -# define ST_INT 0x0080 -# define ST_ASA 0x0100 -# define ST_SNS 0x0200 -# define ST_INI 0x0800 -# define ST_ME 0x1000 -# define ST_ECA 0x4000 - u_char ha_status; -# define HS_OK 0x00 -# define HS_CMD_ABORTED_HOST 0x04 -# define HS_CMD_ABORTED_ADAPTER 0x05 -# define HS_TIMED_OUT 0x11 -# define HS_HARDWARE_ERR 0x20 -# define HS_SCSI_RESET_ADAPTER 0x22 -# define HS_SCSI_RESET_INCOMING 0x23 - u_char targ_status; -# define TS_OK 0x00 -# define TS_CHECK_CONDITION 0x02 -# define TS_BUSY 0x08 - u_long resid_count; - u_long resid_addr; - u_short addit_status; - u_char sense_len; - u_char unused[9]; - u_char cdb[6]; -}; - -/**/ - -struct ecb -{ - u_char opcode; -# define ECB_SCSI_OP 0x01 - u_char :4; - u_char options:3; - u_char :1; - short opt1; -# define ECB_CNE 0x0001 -# define ECB_DI 0x0080 -# define ECB_SES 0x0400 -# define ECB_S_G 0x1000 -# define ECB_DSB 0x4000 -# define ECB_ARS 0x8000 - short opt2; -# define ECB_LUN 0x0007 -# define ECB_TAG 0x0008 -# define ECB_TT 0x0030 -# define ECB_ND 0x0040 -# define ECB_DAT 0x0100 -# define ECB_DIR 0x0200 -# define ECB_ST 0x0400 -# define ECB_CHK 0x0800 -# define ECB_REC 0x4000 -# define ECB_NRB 0x8000 - u_short unused1; - physaddr data; - u_long datalen; - physaddr status; - physaddr chain; - short unused2; - short unused3; - physaddr sense; - u_char senselen; - u_char cdblen; - short cksum; - u_char cdb[12]; - /*-----------------end of hardware supported fields----------------*/ - struct ecb *next; /* in free list */ - struct scsi_xfer *xs; /* the scsi_xfer for this cmd */ - int flags; -#define ECB_FREE 0 -#define ECB_ACTIVE 1 -#define ECB_ABORTED 2 -#define ECB_IMMED 4 -#define ECB_IMMED_FAIL 8 - struct ahb_dma_seg ahb_dma[AHB_NSEG]; - struct ahb_ecb_status ecb_status; - struct scsi_sense_data ecb_sense; -}; - -/**/ - -struct ahb_data -{ - int flags; -#define AHB_INIT 0x01; - int baseport; - struct ecb ecbs[NUM_CONCURRENT]; - struct ecb *free_ecb; - int our_id; /* our scsi id */ - int vect; - struct ecb *immed_ecb; /* an outstanding immediete command */ -} ahb_data[NAHB]; - -int ahbprobe(); -int ahb_attach(); -int ahbintr(); -int ahb_scsi_cmd(); -int ahb_timeout(); -struct ecb *cheat; -void ahbminphys(); -long int ahb_adapter_info(); - -#ifdef MACH -struct isa_driver ahbdriver = { ahbprobe, 0, ahb_attach, "ahb", 0, 0, 0}; -int (*ahbintrs[])() = {ahbintr, 0}; -#endif MACH - -#ifdef __386BSD__ -struct isa_driver ahbdriver = { ahbprobe, ahb_attach, "ahb"}; -#endif __386BSD__ - -#define MAX_SLOTS 8 -static ahb_slot = 0; /* slot last board was found in */ -static ahb_unit = 0; -int ahb_debug = 0; -#define AHB_SHOWECBS 0x01 -#define AHB_SHOWINTS 0x02 -#define AHB_SHOWCMDS 0x04 -#define AHB_SHOWMISC 0x08 -#define FAIL 1 -#define SUCCESS 0 -#define PAGESIZ 4096 - -struct scsi_switch ahb_switch = -{ - ahb_scsi_cmd, - ahbminphys, - 0, - 0, - ahb_adapter_info, - "ahb", - 0,0 -}; - -/**/ -/***********************************************************************\ -* Function to send a command out through a mailbox * -\***********************************************************************/ -ahb_send_mbox( int unit - ,int opcode - ,int target - ,struct ecb *ecb) -{ - int port = ahb_data[unit].baseport; - int spincount = FUDGE(delaycount) * 1; /* 1ms should be enough */ - int s = splbio(); - int stport = port + G2STAT; - - while( ((inb(stport) & (G2STAT_BUSY | G2STAT_MBOX_EMPTY)) - != (G2STAT_MBOX_EMPTY)) - && (spincount--)); - if(spincount == -1) - { - printf("ahb%d: board not responding\n",unit); - Debugger(); - } - - outl(port + MBOXOUT0,KVTOPHYS(ecb)); /* don't know this will work */ - outb(port + ATTN, opcode|target); - - splx(s); -} - -/***********************************************************************\ -* Function to poll for command completion when in poll mode * -\***********************************************************************/ -ahb_poll(int unit ,int wait) /* in msec */ -{ - int port = ahb_data[unit].baseport; - int spincount = FUDGE(delaycount) * wait; /* in msec */ - int stport = port + G2STAT; -int start = spincount; - -retry: - while( (spincount--) && (!(inb(stport) & G2STAT_INT_PEND))); - if(spincount == -1) - { - printf("ahb%d: board not responding\n",unit); - return(EIO); - } -if ((int)cheat != PHYSTOKV(inl(port + MBOXIN0))) -{ - printf("discarding %x ",inl(port + MBOXIN0)); - outb(port + G2CNTRL, G2CNTRL_CLEAR_EISA_INT); - spinwait(50); - goto retry; -}/* don't know this will work */ - ahbintr(unit); - return(0); -} -/***********************************************************************\ -* Function to send an immediate type command to the adapter * -\***********************************************************************/ -ahb_send_immed( int unit - ,int target - ,u_long cmd) -{ - int port = ahb_data[unit].baseport; - int spincount = FUDGE(delaycount) * 1; /* 1ms should be enough */ - int s = splbio(); - int stport = port + G2STAT; - - while( ((inb(stport) & (G2STAT_BUSY | G2STAT_MBOX_EMPTY)) - != (G2STAT_MBOX_EMPTY)) - && (spincount--)); - if(spincount == -1) - { - printf("ahb%d: board not responding\n",unit); - Debugger(); - } - - outl(port + MBOXOUT0,cmd); /* don't know this will work */ - outb(port + G2CNTRL, G2CNTRL_SET_HOST_READY); - outb(port + ATTN, OP_IMMED | target); - splx(s); -} - -/**/ - -/*******************************************************\ -* Check the slots looking for a board we recognise * -* If we find one, note it's address (slot) and call * -* the actual probe routine to check it out. * -\*******************************************************/ -ahbprobe(dev) -struct isa_dev *dev; -{ - int port; - u_char byte1,byte2,byte3; - ahb_slot++; - while (ahb_slot<8) - { - port = 0x1000 * ahb_slot; - byte1 = inb(port + HID0); - byte2 = inb(port + HID1); - byte3 = inb(port + HID2); - if(byte1 == 0xff) - { - ahb_slot++; - continue; - } - if ((CHAR1(byte1,byte2) == 'A') - && (CHAR2(byte1,byte2) == 'D') - && (CHAR3(byte1,byte2) == 'P') - && ((byte3 == 0 ) || (byte3 == 1))) - { - dev->dev_addr = port; - return(ahbprobe1(dev)); - } - ahb_slot++; - } - return(0); -} -/*******************************************************\ -* Check if the device can be found at the port given * -* and if so, set it up ready for further work * -* as an argument, takes the isa_dev structure from * -* autoconf.c * -\*******************************************************/ -ahbprobe1(dev) -struct isa_dev *dev; -{ - /***********************************************\ - * find unit and check we have that many defined * - \***********************************************/ - int unit = ahb_unit; -#if defined(OSF) - static ihandler_t ahb_handler[NAHB]; - static ihandler_id_t *ahb_handler_id[NAHB]; - register ihandler_t *chp = &ahb_handler[unit];; -#endif /* defined(OSF) */ - - dev->dev_unit = unit; - ahb_data[unit].baseport = dev->dev_addr; - if(unit >= NAHB) - { - printf("ahb: unit number (%d) too high\n",unit); - return(0); - } - /***********************************************\ - * Try initialise a unit at this location * - * sets up dma and bus speed, loads ahb_data[unit].vect* - \***********************************************/ - if (ahb_init(unit) != 0) - { - return(0); - } - - /***********************************************\ - * If it's there, put in it's interrupt vectors * - \***********************************************/ -#ifdef MACH - dev->dev_pic = ahb_data[unit].vect; -#if defined(OSF) /* OSF */ - chp->ih_level = dev->dev_pic; - chp->ih_handler = dev->dev_intr[0]; - chp->ih_resolver = i386_resolver; - chp->ih_rdev = dev; - chp->ih_stats.intr_type = INTR_DEVICE; - chp->ih_stats.intr_cnt = 0; - chp->ih_hparam[0].intparam = unit; - if ((ahb_handler_id[unit] = handler_add(chp)) != NULL) - handler_enable(ahb_handler_id[unit]); - else - panic("Unable to add ahb interrupt handler"); -#else /* CMU */ - take_dev_irq(dev); -#endif /* !defined(OSF) */ - printf("port=%x spl=%d\n", dev->dev_addr, dev->dev_spl); -#endif MACH -#ifdef __386BSD__ /* 386BSD */ - dev->id_irq = (1 << ahb_data[unit].vect); - dev->id_drq = -1; /* use EISA dma */ -#endif __386BSD__ - - ahb_unit++; - return(1); -} - -/***********************************************\ -* Attach all the sub-devices we can find * -\***********************************************/ -ahb_attach(dev) -struct isa_dev *dev; -{ - int unit = dev->dev_unit; - - /***********************************************\ - * ask the adapter what subunits are present * - \***********************************************/ - scsi_attachdevs( unit, ahb_data[unit].our_id, &ahb_switch); -#if defined(OSF) - ahb_attached[unit]=1; -#endif /* defined(OSF) */ - return; -} - -/***********************************************\ -* Return some information to the caller about * -* the adapter and it's capabilities * -\***********************************************/ -long int ahb_adapter_info(unit) -int unit; -{ - return(2); /* 2 outstanding requests at a time per device */ -} - -/***********************************************\ -* Catch an interrupt from the adaptor * -\***********************************************/ -ahbintr(unit) -{ - struct ecb *ecb; - unsigned char stat; - register i; - u_char ahbstat; - int target; - long int mboxval; - - int port = ahb_data[unit].baseport; - -#ifdef AHBDEBUG - if(scsi_debug & PRINTROUTINES) - printf("ahbintr "); -#endif /*AHBDEBUG*/ - -#if defined(OSF) - if (!ahb_attached[unit]) - { - return(1); - } -#endif /* defined(OSF) */ - while(inb(port + G2STAT) & G2STAT_INT_PEND) - { - /***********************************************\ - * First get all the information and then * - * acknowlege the interrupt * - \***********************************************/ - ahbstat = inb(port + G2INTST); - target = ahbstat & G2INTST_TARGET; - stat = ahbstat & G2INTST_INT_STAT; - mboxval = inl(port + MBOXIN0);/* don't know this will work */ - outb(port + G2CNTRL, G2CNTRL_CLEAR_EISA_INT); -#ifdef AHBDEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("status = 0x%x ",stat); -#endif /*AHBDEBUG*/ - /***********************************************\ - * Process the completed operation * - \***********************************************/ - - if(stat == AHB_ECB_OK) /* common case is fast */ - { - ecb = (struct ecb *)PHYSTOKV(mboxval); - } - else - { - switch(stat) - { - case AHB_IMMED_OK: - ecb = ahb_data[unit].immed_ecb; - ahb_data[unit].immed_ecb = 0; - break; - case AHB_IMMED_ERR: - ecb = ahb_data[unit].immed_ecb; - ecb->flags |= ECB_IMMED_FAIL; - ahb_data[unit].immed_ecb = 0; - break; - case AHB_ASN: /* for target mode */ - printf("ahb%d: Unexpected ASN interrupt(%x)\n", - unit, mboxval); - ecb = 0; - break; - case AHB_HW_ERR: - printf("ahb%d: Hardware error interrupt(%x)\n", - unit, mboxval); - ecb = 0; - break; - case AHB_ECB_RECOVERED: - ecb = (struct ecb *)PHYSTOKV(mboxval); - break; - case AHB_ECB_ERR: - ecb = (struct ecb *)PHYSTOKV(mboxval); - break; - default: - printf(" Unknown return from ahb%d(%x)\n",unit,ahbstat); - ecb=0; - } - } - if(ecb) - { -#ifdef AHBDEBUG - if(ahb_debug & AHB_SHOWCMDS ) - { - ahb_show_scsi_cmd(ecb->xs); - } - if((ahb_debug & AHB_SHOWECBS) && ecb) - printf("<int ecb(%x)>",ecb); -#endif /*AHBDEBUG*/ - untimeout(ahb_timeout,ecb); - ahb_done(unit,ecb,((stat == AHB_ECB_OK)?SUCCESS:FAIL)); - } - } - return(1); -} - -/***********************************************\ -* We have a ecb which has been processed by the * -* adaptor, now we look to see how the operation * -* went. * -\***********************************************/ -ahb_done(unit,ecb,state) -int unit,state; -struct ecb *ecb; -{ - struct ahb_ecb_status *stat = &ecb->ecb_status; - struct scsi_sense_data *s1,*s2; - struct scsi_xfer *xs = ecb->xs; - -#ifdef AHBDEBUG - if(scsi_debug & (PRINTROUTINES | TRACEINTERRUPTS)) - printf("ahb_done "); -#endif /*AHBDEBUG*/ - /***********************************************\ - * Otherwise, put the results of the operation * - * into the xfer and call whoever started it * - \***********************************************/ - if(ecb->flags & ECB_IMMED) - { - if(ecb->flags & ECB_IMMED_FAIL) - { - xs->error = XS_DRIVER_STUFFUP; - } - goto done; - } - if ( (state == SUCCESS) || (xs->flags & SCSI_ERR_OK)) - { /* All went correctly OR errors expected */ - xs->resid = 0; - xs->error = 0; - } - else - { - - s1 = &(ecb->ecb_sense); - s2 = &(xs->sense); - - if(stat->ha_status) - { - switch(stat->ha_status) - { - case HS_SCSI_RESET_ADAPTER: - break; - case HS_SCSI_RESET_INCOMING: - break; - case HS_CMD_ABORTED_HOST: /* No response */ - case HS_CMD_ABORTED_ADAPTER: /* No response */ - break; - case HS_TIMED_OUT: /* No response */ -#ifdef AHBDEBUG - if (ahb_debug & AHB_SHOWMISC) - { - printf("timeout reported back\n"); - } -#endif /*AHBDEBUG*/ - xs->error = XS_TIMEOUT; - break; - default: /* Other scsi protocol messes */ - xs->error = XS_DRIVER_STUFFUP; -#ifdef AHBDEBUG - if (ahb_debug & AHB_SHOWMISC) - { - printf("unexpected ha_status: %x\n", - stat->ha_status); - } -#endif /*AHBDEBUG*/ - } - - } - else - { - switch(stat->targ_status) - { - case TS_CHECK_CONDITION: - /* structure copy!!!!!*/ - *s2=*s1; - xs->error = XS_SENSE; - break; - case TS_BUSY: - xs->error = XS_BUSY; - break; - default: -#ifdef AHBDEBUG - if (ahb_debug & AHB_SHOWMISC) - { - printf("unexpected targ_status: %x\n", - stat->targ_status); - } -#endif /*AHBDEBUG*/ - xs->error = XS_DRIVER_STUFFUP; - } - } - } -done: xs->flags |= ITSDONE; - ahb_free_ecb(unit,ecb, xs->flags); - if(xs->when_done) - (*(xs->when_done))(xs->done_arg,xs->done_arg2); -} - -/***********************************************\ -* A ecb (and hence a mbx-out is put onto the * -* free list. * -\***********************************************/ -ahb_free_ecb(unit,ecb, flags) -struct ecb *ecb; -{ - unsigned int opri; - -#ifdef AHBDEBUG - if(scsi_debug & PRINTROUTINES) - printf("ecb%d(0x%x)> ",unit,flags); -#endif /*AHBDEBUG*/ - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - - ecb->next = ahb_data[unit].free_ecb; - ahb_data[unit].free_ecb = ecb; - ecb->flags = ECB_FREE; - /***********************************************\ - * If there were none, wake abybody waiting for * - * one to come free, starting with queued entries* - \***********************************************/ - if (!ecb->next) { - wakeup(&ahb_data[unit].free_ecb); - } - if (!(flags & SCSI_NOMASK)) - splx(opri); -} - -/***********************************************\ -* Get a free ecb (and hence mbox-out entry) * -\***********************************************/ -struct ecb * -ahb_get_ecb(unit,flags) -{ - unsigned opri; - struct ecb *rc; - -#ifdef AHBDEBUG - if(scsi_debug & PRINTROUTINES) - printf("<ecb%d(0x%x) ",unit,flags); -#endif /*AHBDEBUG*/ - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - /***********************************************\ - * If we can and have to, sleep waiting for one * - * to come free * - \***********************************************/ - while ((!(rc = ahb_data[unit].free_ecb)) && (!(flags & SCSI_NOSLEEP))) - { - sleep(&ahb_data[unit].free_ecb, PRIBIO); - } - if (rc) - { - ahb_data[unit].free_ecb = rc->next; - rc->flags = ECB_ACTIVE; - } - if (!(flags & SCSI_NOMASK)) - splx(opri); - return(rc); -} - - - -/***********************************************\ -* Start the board, ready for normal operation * -\***********************************************/ -ahb_init(unit) -int unit; -{ - int port = ahb_data[unit].baseport; - int intdef; - int spincount = FUDGE(delaycount) * 1000; /* 1 sec enough? */ - int i; - int stport = port + G2STAT; -#define NO_NO 1 -#ifdef NO_NO - /***********************************************\ - * reset board, If it doesn't respond, assume * - * that it's not there.. good for the probe * - \***********************************************/ - outb(port + EBCTRL,CDEN); /* enable full card */ - outb(port + PORTADDR,PORTADDR_ENHANCED); - - outb(port + G2CNTRL,G2CNTRL_HARD_RESET); - spinwait(1); - outb(port + G2CNTRL,0); - spinwait(10); - while( ((inb(stport) & G2STAT_BUSY )) - && (spincount--)); - if(spincount == -1) - { -#ifdef AHBDEBUG - if (ahb_debug & AHB_SHOWMISC) - printf("ahb_init: No answer from bt742a board\n"); -#endif /*AHBDEBUG*/ - return(ENXIO); - } - i = inb(port + MBOXIN0) & 0xff; - if(i) - { - printf("self test failed, val = 0x%x\n",i); - return(EIO); - } -#endif - while( inb(stport) & G2STAT_INT_PEND) - { - printf("."); - outb(port + G2CNTRL, G2CNTRL_CLEAR_EISA_INT); - spinwait(10); - } - outb(port + EBCTRL,CDEN); /* enable full card */ - outb(port + PORTADDR,PORTADDR_ENHANCED); - /***********************************************\ - * Assume we have a board at this stage * - * setup dma channel from jumpers and save int * - * level * - \***********************************************/ -#ifdef __386BSD__ - printf("ahb%d: reading board settings, ",unit); -#else __386BSD__ - printf("ahb%d:",unit); -#endif __386BSD__ - - intdef = inb(port + INTDEF); - switch(intdef & 0x07) - { - case INT9: - ahb_data[unit].vect = 9; - break; - case INT10: - ahb_data[unit].vect = 10; - break; - case INT11: - ahb_data[unit].vect = 11; - break; - case INT12: - ahb_data[unit].vect = 12; - break; - case INT14: - ahb_data[unit].vect = 14; - break; - case INT15: - ahb_data[unit].vect = 15; - break; - default: - printf("illegal int setting\n"); - return(EIO); - } -#ifdef __386BSD__ - printf("int=%d\n",ahb_data[unit].vect); -#else __386BSD__ - printf("int=%d ",ahb_data[unit].vect); -#endif __386BSD__ - - outb(port + INTDEF ,(intdef | INTEN)); /* make sure we can interrupt */ - /* who are we on the scsi bus */ - ahb_data[unit].our_id = (inb(port + SCSIDEF) & HSCSIID); - - /***********************************************\ - * link up all our ECBs into a free list * - \***********************************************/ - for (i=0; i < NUM_CONCURRENT; i++) - { - ahb_data[unit].ecbs[i].next = ahb_data[unit].free_ecb; - ahb_data[unit].free_ecb = &ahb_data[unit].ecbs[i]; - ahb_data[unit].free_ecb->flags = ECB_FREE; - } - - /***********************************************\ - * Note that we are going and return (to probe) * - \***********************************************/ - ahb_data[unit].flags |= AHB_INIT; - return( 0 ); -} - - -#ifndef min -#define min(x,y) (x < y ? x : y) -#endif min - - -void ahbminphys(bp) -struct buf *bp; -{ -#ifdef MACH -#if !defined(OSF) - bp->b_flags |= B_NPAGES; /* can support scat/gather */ -#endif /* defined(OSF) */ -#endif MACH - if(bp->b_bcount > ((AHB_NSEG-1) * PAGESIZ)) - { - bp->b_bcount = ((AHB_NSEG-1) * PAGESIZ); - } -} - -/***********************************************\ -* start a scsi operation given the command and * -* the data address. Also needs the unit, target * -* and lu * -\***********************************************/ -int ahb_scsi_cmd(xs) -struct scsi_xfer *xs; -{ - struct scsi_sense_data *s1,*s2; - struct ecb *ecb; - struct ahb_dma_seg *sg; - int seg; /* scatter gather seg being worked on */ - int i = 0; - int rc = 0; - int thiskv; - physaddr thisphys,nextphys; - int unit =xs->adapter; - int bytes_this_seg,bytes_this_page,datalen,flags; - struct iovec *iovp; - int s; -#ifdef AHBDEBUG - if(scsi_debug & PRINTROUTINES) - printf("ahb_scsi_cmd "); -#endif /*AHBDEBUG*/ - /***********************************************\ - * get a ecb (mbox-out) to use. If the transfer * - * is from a buf (possibly from interrupt time) * - * then we can't allow it to sleep * - \***********************************************/ - flags = xs->flags; - if(xs->bp) flags |= (SCSI_NOSLEEP); /* just to be sure */ - if(flags & ITSDONE) - { - printf("ahb%d: Already done?",unit); - xs->flags &= ~ITSDONE; - } - if(!(flags & INUSE)) - { - printf("ahb%d: Not in use?",unit); - xs->flags |= INUSE; - } - if (!(ecb = ahb_get_ecb(unit,flags))) - { - xs->error = XS_DRIVER_STUFFUP; - return(TRY_AGAIN_LATER); - } - -cheat = ecb; -#ifdef AHBDEBUG - if(ahb_debug & AHB_SHOWECBS) - printf("<start ecb(%x)>",ecb); - if(scsi_debug & SHOWCOMMANDS) - { - ahb_show_scsi_cmd(xs); - } -#endif /*AHBDEBUG*/ - ecb->xs = xs; - /***********************************************\ - * If it's a reset, we need to do an 'immediate' * - * command, and store it's ccb for later * - * if there is already an immediate waiting, * - * then WE must wait * - \***********************************************/ - if(flags & SCSI_RESET) - { - ecb->flags |= ECB_IMMED; - if(ahb_data[unit].immed_ecb) - { - return(TRY_AGAIN_LATER); - } - ahb_data[unit].immed_ecb = ecb; - if (!(flags & SCSI_NOMASK)) - { - s = splbio(); - ahb_send_immed(unit,xs->targ,AHB_TARG_RESET); - timeout(ahb_timeout,ecb,(xs->timeout * hz)/1000); - splx(s); - return(SUCCESSFULLY_QUEUED); - } - else - { - ahb_send_immed(unit,xs->targ,AHB_TARG_RESET); - /***********************************************\ - * If we can't use interrupts, poll on completion* - \***********************************************/ -#ifdef AHBDEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("wait "); -#endif /*AHBDEBUG*/ - if( ahb_poll(unit,xs->timeout)) - { - ahb_free_ecb(unit,ecb,flags); - xs->error = XS_TIMEOUT; - return(HAD_ERROR); - } - return(COMPLETE); - } - } - /***********************************************\ - * Put all the arguments for the xfer in the ecb * - \***********************************************/ - ecb->opcode = ECB_SCSI_OP; - ecb->opt1 = ECB_SES|ECB_DSB|ECB_ARS; - if(xs->datalen) - { - ecb->opt1 |= ECB_S_G; - } - ecb->opt2 = xs->lu | ECB_NRB; - ecb->cdblen = xs->cmdlen; - ecb->sense = KVTOPHYS(&(ecb->ecb_sense)); - ecb->senselen = sizeof(ecb->ecb_sense); - ecb->status = KVTOPHYS(&(ecb->ecb_status)); - - if(xs->datalen) - { /* should use S/G only if not zero length */ - ecb->data = KVTOPHYS(ecb->ahb_dma); - sg = ecb->ahb_dma ; - seg = 0; - if(flags & SCSI_DATA_UIO) - { - iovp = ((struct uio *)xs->data)->uio_iov; - datalen = ((struct uio *)xs->data)->uio_iovcnt; - xs->datalen = 0; - while ((datalen) && (seg < AHB_NSEG)) - { - sg->addr = (physaddr)iovp->iov_base; - xs->datalen += sg->len = iovp->iov_len; -#ifdef AHBDEBUG - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x@0x%x)" - ,iovp->iov_len - ,iovp->iov_base); -#endif /*AHBDEBUG*/ - sg++; - iovp++; - seg++; - datalen--; - } - } - else - { - /***********************************************\ - * Set up the scatter gather block * - \***********************************************/ - -#ifdef AHBDEBUG - if(scsi_debug & SHOWSCATGATH) - printf("%d @0x%x:- ",xs->datalen,xs->data); -#endif /*AHBDEBUG*/ - datalen = xs->datalen; - thiskv = (int)xs->data; - thisphys = KVTOPHYS(thiskv); - - while ((datalen) && (seg < AHB_NSEG)) - { - bytes_this_seg = 0; - - /* put in the base address */ - sg->addr = thisphys; - -#ifdef AHBDEBUG - if(scsi_debug & SHOWSCATGATH) - printf("0x%x",thisphys); -#endif /*AHBDEBUG*/ - - /* do it at least once */ - nextphys = thisphys; - while ((datalen) && (thisphys == nextphys)) - /*********************************************\ - * This page is contiguous (physically) with * - * the the last, just extend the length * - \*********************************************/ - { - /* how far to the end of the page */ - nextphys= (thisphys & (~(PAGESIZ - 1))) - + PAGESIZ; - bytes_this_page = nextphys - thisphys; - /**** or the data ****/ - bytes_this_page = min(bytes_this_page - ,datalen); - bytes_this_seg += bytes_this_page; - datalen -= bytes_this_page; - - /* get more ready for the next page */ - thiskv = (thiskv & (~(PAGESIZ - 1))) - + PAGESIZ; - if(datalen) - thisphys = KVTOPHYS(thiskv); - } - /********************************************\ - * next page isn't contiguous, finish the seg * - \********************************************/ -#ifdef AHBDEBUG - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x)",bytes_this_seg); -#endif /*AHBDEBUG*/ - sg->len = bytes_this_seg; - sg++; - seg++; - } - } /*end of iov/kv decision */ - ecb->datalen = seg * sizeof(struct ahb_dma_seg); -#ifdef AHBDEBUG - if(scsi_debug & SHOWSCATGATH) - printf("\n"); -#endif /*AHBDEBUG*/ - if (datalen) - { /* there's still data, must have run out of segs! */ - printf("ahb_scsi_cmd%d: more than %d DMA segs\n", - unit,AHB_NSEG); - xs->error = XS_DRIVER_STUFFUP; - ahb_free_ecb(unit,ecb,flags); - return(HAD_ERROR); - } - - } - else - { /* No data xfer, use non S/G values */ - ecb->data = (physaddr)0; - ecb->datalen = 0; - } - ecb->chain = (physaddr)0; - /***********************************************\ - * Put the scsi command in the ecb and start it * - \***********************************************/ - bcopy(xs->cmd, ecb->cdb, xs->cmdlen); - /***********************************************\ - * Usually return SUCCESSFULLY QUEUED * - \***********************************************/ - if (!(flags & SCSI_NOMASK)) - { - s = splbio(); - ahb_send_mbox(unit,OP_START_ECB,xs->targ,ecb); - timeout(ahb_timeout,ecb,(xs->timeout * hz)/1000); - splx(s); -#ifdef AHBDEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("cmd_sent "); -#endif /*AHBDEBUG*/ - return(SUCCESSFULLY_QUEUED); - } - /***********************************************\ - * If we can't use interrupts, poll on completion* - \***********************************************/ - ahb_send_mbox(unit,OP_START_ECB,xs->targ,ecb); -#ifdef AHBDEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("cmd_wait "); -#endif /*AHBDEBUG*/ - do - { - if(ahb_poll(unit,xs->timeout)) - { - if (!(xs->flags & SCSI_SILENT)) printf("cmd fail\n"); - ahb_send_mbox(unit,OP_ABORT_ECB,xs->targ,ecb); - if(ahb_poll(unit,2000)) - { - printf("abort failed in wait\n"); - ahb_free_ecb(unit,ecb,flags); - } - xs->error = XS_DRIVER_STUFFUP; - return(HAD_ERROR); - } - } while (!(xs->flags & ITSDONE));/* something (?) else finished */ - if(xs->error) - { - return(HAD_ERROR); - } - return(COMPLETE); -} - - -ahb_timeout(struct ecb *ecb) -{ - int unit; - int s = splbio(); - - unit = ecb->xs->adapter; - printf("ahb%d:%d device timed out\n",unit - ,ecb->xs->targ); -#ifdef AHBDEBUG - if(ahb_debug & AHB_SHOWECBS) - ahb_print_active_ecb(unit); -#endif /*AHBDEBUG*/ - - /***************************************\ - * If it's immediate, don't try abort it * - \***************************************/ - if(ecb->flags & ECB_IMMED) - { - ecb->xs->retries = 0; /* I MEAN IT ! */ - ecb->flags |= ECB_IMMED_FAIL; - ahb_done(unit,ecb,FAIL); - splx(s); - return; - } - /***************************************\ - * If it has been through before, then * - * a previous abort has failed, don't * - * try abort again * - \***************************************/ - if(ecb->flags == ECB_ABORTED) /* abort timed out */ - { - printf("AGAIN"); - ecb->xs->retries = 0; /* I MEAN IT ! */ - ecb->ecb_status.ha_status = HS_CMD_ABORTED_HOST; - ahb_done(unit,ecb,FAIL); - } - else /* abort the operation that has timed out */ - { - printf("\n"); - ahb_send_mbox(unit,OP_ABORT_ECB,ecb->xs->targ,ecb); - /* 2 secs for the abort */ - timeout(ahb_timeout,ecb,2 * hz); - ecb->flags = ECB_ABORTED; - } - splx(s); -} - -#ifdef AHBDEBUG -ahb_show_scsi_cmd(struct scsi_xfer *xs) -{ - u_char *b = (u_char *)xs->cmd; - int i = 0; - if(!(xs->flags & SCSI_RESET)) - { - printf("ahb%d:%d:%d-" - ,xs->adapter - ,xs->targ - ,xs->lu); - while(i < xs->cmdlen ) - { - if(i) printf(","); - printf("%x",b[i++]); - } - printf("-\n"); - } - else - { - printf("ahb%d:%d:%d-RESET-\n" - ,xs->adapter - ,xs->targ - ,xs->lu - ); - } -} -ahb_print_ecb(ecb) -struct ecb *ecb; -{ - printf("ecb:%x op:%x cmdlen:%d senlen:%d\n" - ,ecb - ,ecb->opcode - ,ecb->cdblen - ,ecb->senselen); - printf(" datlen:%d hstat:%x tstat:%x flags:%x\n" - ,ecb->datalen - ,ecb->ecb_status.ha_status - ,ecb->ecb_status.targ_status - ,ecb->flags); - ahb_show_scsi_cmd(ecb->xs); -} - -ahb_print_active_ecb(int unit) -{ - struct ecb *ecb = ahb_data[unit].ecbs; - int i = NUM_CONCURRENT; - - while(i--) - { - if(ecb->flags != ECB_FREE) - { - ahb_print_ecb(ecb); - } - ecb++; - } -} -#endif /*AHBDEBUG */ diff --git a/sys/i386/isa/bt742a.c b/sys/i386/isa/bt742a.c deleted file mode 100644 index 0e25091..0000000 --- a/sys/i386/isa/bt742a.c +++ /dev/null @@ -1,1617 +0,0 @@ -/* - * Written by Julian Elischer (julian@tfs.com) - * for TRW Financial Systems for use under the MACH(2.5) operating system. - * - * TRW Financial Systems, in accordance with their agreement with Carnegie - * Mellon University, makes this software available to CMU to distribute - * or use in any manner that they see fit as long as this message is kept with - * the software. For this reason TFS also grants any other persons or - * organisations permission to use or modify this software. - * - * TFS supplies this software to be publicly redistributed - * on the understanding that TFS is not responsible for the correct - * functioning of this software in any circumstances. - * - * $Id: bt742a.c,v 1.7 1993/08/28 03:07:42 rgrimes Exp $ - */ - -/* - * bt742a SCSI driver - */ - -#include <sys/types.h> -#include <bt.h> - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/errno.h> -#include <sys/ioctl.h> -#include <sys/buf.h> -#include <sys/proc.h> -#include <sys/user.h> - -#ifdef MACH /* EITHER CMU OR OSF */ -#include <i386/ipl.h> -#include <i386at/scsi.h> -#include <i386at/scsiconf.h> - -#ifdef OSF /* OSF ONLY */ -#include <sys/table.h> -#include <i386/handler.h> -#include <i386/dispatcher.h> -#include <i386/AT386/atbus.h> - -#else OSF /* CMU ONLY */ -#include <i386at/atbus.h> -#include <i386/pio.h> -#endif OSF -#endif MACH /* end of MACH specific */ - -#ifdef __386BSD__ /* 386BSD specific */ -#define isa_dev isa_device -#define dev_unit id_unit -#define dev_addr id_iobase - -#include <i386/isa/isa_device.h> -#include <scsi/scsi_all.h> -#include <scsi/scsiconf.h> -#endif __386BSD__ - - -#ifdef __386BSD__ -#include "ddb.h" -#if NDDB > 0 -int Debugger(); -#else NDDB -#define Debugger() panic("should call debugger here (bt742a.c)") -#endif NDDB -#endif __386BSD__ - -#ifdef MACH -int Debugger(); -#endif MACH - -extern int hz; -extern int delaycount; /* from clock setup code */ -typedef unsigned long int physaddr; - -/* - * I/O Port Interface - */ - -#define BT_BASE bt_base[unit] -#define BT_CTRL_STAT_PORT (BT_BASE + 0x0) /* control & status */ -#define BT_CMD_DATA_PORT (BT_BASE + 0x1) /* cmds and datas */ -#define BT_INTR_PORT (BT_BASE + 0x2) /* Intr. stat */ - -/* - * BT_CTRL_STAT bits (write) - */ - -#define BT_HRST 0x80 /* Hardware reset */ -#define BT_SRST 0x40 /* Software reset */ -#define BT_IRST 0x20 /* Interrupt reset */ -#define BT_SCRST 0x10 /* SCSI bus reset */ - -/* - * BT_CTRL_STAT bits (read) - */ - -#define BT_STST 0x80 /* Self test in Progress */ -#define BT_DIAGF 0x40 /* Diagnostic Failure */ -#define BT_INIT 0x20 /* Mbx Init required */ -#define BT_IDLE 0x10 /* Host Adapter Idle */ -#define BT_CDF 0x08 /* cmd/data out port full */ -#define BT_DF 0x04 /* Data in port full */ -#define BT_INVDCMD 0x01 /* Invalid command */ - -/* - * BT_CMD_DATA bits (write) - */ - -#define BT_NOP 0x00 /* No operation */ -#define BT_MBX_INIT 0x01 /* Mbx initialization */ -#define BT_START_SCSI 0x02 /* start scsi command */ -#define BT_START_BIOS 0x03 /* start bios command */ -#define BT_INQUIRE 0x04 /* Adapter Inquiry */ -#define BT_MBO_INTR_EN 0x05 /* Enable MBO available interrupt */ -#define BT_SEL_TIMEOUT_SET 0x06 /* set selection time-out */ -#define BT_BUS_ON_TIME_SET 0x07 /* set bus-on time */ -#define BT_BUS_OFF_TIME_SET 0x08 /* set bus-off time */ -#define BT_SPEED_SET 0x09 /* set transfer speed */ -#define BT_DEV_GET 0x0a /* return installed devices */ -#define BT_CONF_GET 0x0b /* return configuration data */ -#define BT_TARGET_EN 0x0c /* enable target mode */ -#define BT_SETUP_GET 0x0d /* return setup data */ -#define BT_WRITE_CH2 0x1a /* write channel 2 buffer */ -#define BT_READ_CH2 0x1b /* read channel 2 buffer */ -#define BT_WRITE_FIFO 0x1c /* write fifo buffer */ -#define BT_READ_FIFO 0x1d /* read fifo buffer */ -#define BT_ECHO 0x1e /* Echo command data */ -#define BT_MBX_INIT_EXTENDED 0x81 /* Mbx initialization */ -#define BT_INQUIRE_EXTENDED 0x8D /* Adapter Setup Inquiry */ - -/* Follows command appeared at FirmWare 3.31 */ -#define BT_ROUND_ROBIN 0x8f /* Enable/Disable(default) round robin */ -#define BT_DISABLE 0x00 /* Parameter value for Disable */ -#define BT_ENABLE 0x01 /* Parameter value for Enable */ - -struct bt_cmd_buf { - u_char byte[16]; -}; - -/* - * BT_INTR_PORT bits (read) - */ - -#define BT_ANY_INTR 0x80 /* Any interrupt */ -#define BT_SCRD 0x08 /* SCSI reset detected */ -#define BT_HACC 0x04 /* Command complete */ -#define BT_MBOA 0x02 /* MBX out empty */ -#define BT_MBIF 0x01 /* MBX in full */ - -/* - * Mail box defs - */ - -#define BT_MBX_SIZE 255 /* mail box size (MAX 255 MBxs) */ -#define BT_CCB_SIZE 32 /* store up to 32CCBs at any one time */ - /* in bt742a H/W ( Not MAX ? ) */ - -#define bt_nextmbx( wmb, mbx, mbio ) \ - if ( (wmb) == &((mbx)->mbio[BT_MBX_SIZE - 1 ]) ) { \ - (wmb) = &((mbx)->mbio[0]); \ - } else { \ - (wmb)++; \ - } - - -typedef struct bt_mbx_out { - physaddr ccb_addr; - unsigned char dummy[3]; - unsigned char cmd; -} BT_MBO; - -typedef struct bt_mbx_in{ - physaddr ccb_addr; - unsigned char btstat; - unsigned char sdstat; - unsigned char dummy; - unsigned char stat; -} BT_MBI; - -struct bt_mbx -{ - BT_MBO mbo[BT_MBX_SIZE]; - BT_MBI mbi[BT_MBX_SIZE]; - BT_MBO *tmbo; /* Target Mail Box out */ - BT_MBI *tmbi; /* Target Mail Box in */ -}; - -/* - * mbo.cmd values - */ - -#define BT_MBO_FREE 0x0 /* MBO entry is free */ -#define BT_MBO_START 0x1 /* MBO activate entry */ -#define BT_MBO_ABORT 0x2 /* MBO abort entry */ - -#define BT_MBI_FREE 0x0 /* MBI entry is free */ -#define BT_MBI_OK 0x1 /* completed without error */ -#define BT_MBI_ABORT 0x2 /* aborted ccb */ -#define BT_MBI_UNKNOWN 0x3 /* Tried to abort invalid CCB */ -#define BT_MBI_ERROR 0x4 /* Completed with error */ - -extern struct bt_mbx bt_mbx[]; - -#if defined(BIG_DMA) -/* #define BT_NSEG 8192 /* Number of scatter gather segments - to much vm */ -#define BT_NSEG 512 -#else -#define BT_NSEG 33 -#endif /* BIG_DMA */ -struct bt_scat_gath - { - unsigned long seg_len; - physaddr seg_addr; - }; - -struct bt_ccb { - unsigned char opcode; - unsigned char :3,data_in:1,data_out:1,:3; - unsigned char scsi_cmd_length; - unsigned char req_sense_length; - /*------------------------------------longword boundary */ - unsigned long data_length; - /*------------------------------------longword boundary */ - physaddr data_addr; - /*------------------------------------longword boundary */ - unsigned char dummy[2]; - unsigned char host_stat; - unsigned char target_stat; - /*------------------------------------longword boundary */ - unsigned char target; - unsigned char lun; - unsigned char scsi_cmd[12]; /* 12 bytes (bytes only)*/ - unsigned char dummy2[1]; - unsigned char link_id; - /*------------------------------------4 longword boundary */ - physaddr link_addr; - /*------------------------------------longword boundary */ - physaddr sense_ptr; - /*------------------------------------longword boundary */ - struct scsi_sense_data scsi_sense; - /*------------------------------------longword boundary */ - struct bt_scat_gath scat_gath[BT_NSEG]; - /*------------------------------------longword boundary */ - struct bt_ccb *next; - /*------------------------------------longword boundary */ - struct scsi_xfer *xfer; /* the scsi_xfer for this cmd */ - /*------------------------------------longword boundary */ - struct bt_mbx_out *mbx; /* pointer to mail box */ - /*------------------------------------longword boundary */ - int flags; -#define CCB_FREE 0 -#define CCB_ACTIVE 1 -#define CCB_ABORTED 2 -}; - -/* - * opcode fields - */ - -#define BT_INITIATOR_CCB 0x00 /* SCSI Initiator CCB */ -#define BT_TARGET_CCB 0x01 /* SCSI Target CCB */ -#define BT_INIT_SCAT_GATH_CCB 0x02 /* SCSI Initiator with scattter gather*/ -#define BT_RESET_CCB 0x81 /* SCSI Bus reset */ - - -/* - * bt_ccb.host_stat values - */ - -#define BT_OK 0x00 /* cmd ok */ -#define BT_LINK_OK 0x0a /* Link cmd ok */ -#define BT_LINK_IT 0x0b /* Link cmd ok + int */ -#define BT_SEL_TIMEOUT 0x11 /* Selection time out */ -#define BT_OVER_UNDER 0x12 /* Data over/under run */ -#define BT_BUS_FREE 0x13 /* Bus dropped at unexpected time */ -#define BT_INV_BUS 0x14 /* Invalid bus phase/sequence */ -#define BT_BAD_MBO 0x15 /* Incorrect MBO cmd */ -#define BT_BAD_CCB 0x16 /* Incorrect ccb opcode */ -#define BT_BAD_LINK 0x17 /* Not same values of LUN for links */ -#define BT_INV_TARGET 0x18 /* Invalid target direction */ -#define BT_CCB_DUP 0x19 /* Duplicate CCB received */ -#define BT_INV_CCB 0x1a /* Invalid CCB or segment list */ -#define BT_ABORTED 42 /* pseudo value from driver */ - -struct bt_boardID -{ - u_char board_type; - u_char custom_feture; - char firm_revision; - u_char firm_version; -}; - -struct bt_setup -{ - u_char sync_neg:1; - u_char parity:1; - u_char :6; - u_char speed; - u_char bus_on; - u_char bus_off; - u_char num_mbx; - u_char mbx[3]; - struct { - u_char offset:4; - u_char period:3; - u_char valid:1; - }sync[8]; - u_char disc_sts; -}; - -struct bt_config -{ - u_char chan; - u_char intr; - u_char scsi_dev:3; - u_char :5; -}; - -#define INT9 0x01 -#define INT10 0x02 -#define INT11 0x04 -#define INT12 0x08 -#define INT14 0x20 -#define INT15 0x40 - -#define EISADMA 0x00 -#define CHAN0 0x01 -#define CHAN5 0x20 -#define CHAN6 0x40 -#define CHAN7 0x80 - - - - -#ifdef MACH -extern physaddr kvtophys(); -#define PHYSTOKV(x) phystokv(x) -#define KVTOPHYS(x) kvtophys(x) -#endif MACH - -#ifdef __386BSD__ -#define KVTOPHYS(x) vtophys(x) -#endif __386BSD__ - - - -#define PAGESIZ 4096 -#define INVALIDATE_CACHE {asm volatile( ".byte 0x0F ;.byte 0x08" ); } - - -u_char bt_scratch_buf[256]; -#ifdef MACH -caddr_t bt_base[NBT]; /* base port for each board */ -#else MACH -short bt_base[NBT]; /* base port for each board */ -#endif MACH -struct bt_mbx bt_mbx[NBT]; -struct bt_ccb *bt_ccb_free[NBT]; -struct bt_ccb bt_ccb[NBT][BT_CCB_SIZE]; -struct scsi_xfer bt_scsi_xfer[NBT]; -struct isa_dev *btinfo[NBT]; -struct bt_ccb *bt_get_ccb(); -int bt_int[NBT]; -int bt_dma[NBT]; -int bt_scsi_dev[NBT]; -int bt_initialized[NBT]; -#if defined(OSF) -int bt_attached[NBT]; -#endif /* defined(OSF) */ - -/***********debug values *************/ -#define BT_SHOWCCBS 0x01 -#define BT_SHOWINTS 0x02 -#define BT_SHOWCMDS 0x04 -#define BT_SHOWMISC 0x08 -int bt_debug = 0; - - -int btprobe(), btattach(); -int btintr(); - -#ifdef MACH -struct isa_driver btdriver = { btprobe, 0, btattach, "bt", 0, 0, 0}; -int (*btintrs[])() = {btintr, 0}; -#endif MACH - -#ifdef __386BSD__ -struct isa_driver btdriver = { btprobe, btattach, "bt"}; -#endif __386BSD__ - -static int btunit = 0; - -int bt_scsi_cmd(); -int bt_timeout(); -void btminphys(); -long int bt_adapter_info(); - -struct scsi_switch bt_switch = -{ - bt_scsi_cmd, - btminphys, - 0, - 0, - bt_adapter_info, - "bt", - 0,0 -}; -#define BT_CMD_TIMEOUT_FUDGE 200 /* multiplied to get Secs */ -#define BT_RESET_TIMEOUT 1000000 -#define BT_SCSI_TIMEOUT_FUDGE 20 /* divided by for mSecs */ - - -/***********************************************************************\ -* bt_cmd(unit,icnt, ocnt,wait, retval, opcode, args) * -* Activate Adapter command * -* icnt: number of args (outbound bytes written after opcode) * -* ocnt: number of expected returned bytes * -* wait: number of seconds to wait for response * -* retval: buffer where to place returned bytes * -* opcode: opcode BT_NOP, BT_MBX_INIT, BT_START_SCSI ... * -* args: parameters * -* * -* Performs an adapter command through the ports. Not to be confused * -* with a scsi command, which is read in via the dma * -* One of the adapter commands tells it to read in a scsi command * -\***********************************************************************/ -bt_cmd(unit,icnt, ocnt, wait,retval, opcode, args) - -u_char *retval; -unsigned opcode; -u_char args; -{ - unsigned *ic = &opcode; - u_char oc; - register i; - int sts; - - /*******************************************************\ - * multiply the wait argument by a big constant * - * zero defaults to 1 * - \*******************************************************/ - if(!wait) - wait = BT_CMD_TIMEOUT_FUDGE * delaycount; - else - wait *= BT_CMD_TIMEOUT_FUDGE * delaycount; - /*******************************************************\ - * Wait for the adapter to go idle, unless it's one of * - * the commands which don't need this * - \*******************************************************/ - if (opcode != BT_MBX_INIT && opcode != BT_START_SCSI) - { - i = BT_CMD_TIMEOUT_FUDGE * delaycount; /* 1 sec?*/ - while (--i) - { - sts = inb(BT_CTRL_STAT_PORT); - if (sts & BT_IDLE) - { - break; - } - } - if (!i) - { - printf("bt%d: bt_cmd, host not idle(0x%x)\n",unit,sts); - return(ENXIO); - } - } - /*******************************************************\ - * Now that it is idle, if we expect output, preflush the* - * queue feeding to us. * - \*******************************************************/ - if (ocnt) - { - while((inb(BT_CTRL_STAT_PORT)) & BT_DF) - inb(BT_CMD_DATA_PORT); - } - - /*******************************************************\ - * Output the command and the number of arguments given * - * for each byte, first check the port is empty. * - \*******************************************************/ - icnt++; /* include the command */ - while (icnt--) - { - sts = inb(BT_CTRL_STAT_PORT); - for (i=0; i< wait; i++) - { - sts = inb(BT_CTRL_STAT_PORT); - if (!(sts & BT_CDF)) - break; - } - if (i >= wait) - { - printf("bt%d: bt_cmd, cmd/data port full\n",unit); - outb(BT_CTRL_STAT_PORT, BT_SRST); - return(ENXIO); - } - outb(BT_CMD_DATA_PORT, (u_char)(*ic++)); - } - /*******************************************************\ - * If we expect input, loop that many times, each time, * - * looking for the data register to have valid data * - \*******************************************************/ - while (ocnt--) - { - sts = inb(BT_CTRL_STAT_PORT); - for (i=0; i< wait; i++) - { - sts = inb(BT_CTRL_STAT_PORT); - if (sts & BT_DF) - break; - } - if (i >= wait) - { - printf("bt%d: bt_cmd, cmd/data port empty %d\n", - unit,ocnt); - return(ENXIO); - } - oc = inb(BT_CMD_DATA_PORT); - if (retval) - *retval++ = oc; - } - /*******************************************************\ - * Wait for the board to report a finised instruction * - \*******************************************************/ - i=BT_CMD_TIMEOUT_FUDGE * delaycount; /* 1 sec? */ - while (--i) - { - sts = inb(BT_INTR_PORT); - if (sts & BT_HACC) - { - break; - } - } - if (!i) - { - printf("bt%d: bt_cmd, host not finished(0x%x)\n",unit,sts); - return(ENXIO); - } - outb(BT_CTRL_STAT_PORT, BT_IRST); - return(0); -} - -/*******************************************************\ -* Check if the device can be found at the port given * -* and if so, set it up ready for further work * -* as an argument, takes the isa_dev structure from * -* autoconf.c * -\*******************************************************/ - -btprobe(dev) -struct isa_dev *dev; -{ - /***********************************************\ - * find unit and check we have that many defined * - \***********************************************/ - int unit = btunit; -#if defined(OSF) - static ihandler_t bt_handler[NBT]; - static ihandler_id_t *bt_handler_id[NBT]; - register ihandler_t *chp = &bt_handler[unit];; -#endif /* defined(OSF) */ - - dev->dev_unit = unit; - bt_base[unit] = dev->dev_addr; - if(unit >= NBT) - { - printf("bt%d: unit number too high\n",unit); - return(0); - } - /***********************************************\ - * Try initialise a unit at this location * - * sets up dma and bus speed, loads bt_int[unit]* - \***********************************************/ - if (bt_init(unit) != 0) - { - return(0); - } - - /***********************************************\ - * If it's there, put in it's interrupt vectors * - \***********************************************/ -#ifdef MACH - dev->dev_pic = bt_int[unit]; -#if defined(OSF) /* OSF */ - chp->ih_level = dev->dev_pic; - chp->ih_handler = dev->dev_intr[0]; - chp->ih_resolver = i386_resolver; - chp->ih_rdev = dev; - chp->ih_stats.intr_type = INTR_DEVICE; - chp->ih_stats.intr_cnt = 0; - chp->ih_hparam[0].intparam = unit; - if ((bt_handler_id[unit] = handler_add(chp)) != NULL) - handler_enable(bt_handler_id[unit]); - else - panic("Unable to add bt interrupt handler"); -#else /* CMU */ - take_dev_irq(dev); -#endif /* !defined(OSF) */ - printf("port=%x spl=%d\n", dev->dev_addr, dev->dev_spl); -#endif MACH -#ifdef __386BSD__ /* 386BSD */ - dev->id_irq = (1 << bt_int[unit]); - dev->id_drq = bt_dma[unit]; -#endif __386BSD__ - - btunit++; - return(1); -} - -/***********************************************\ -* Attach all the sub-devices we can find * -\***********************************************/ -btattach(dev) -struct isa_dev *dev; -{ - int unit = dev->dev_unit; - - - /***********************************************\ - * ask the adapter what subunits are present * - \***********************************************/ - scsi_attachdevs( unit, bt_scsi_dev[unit], &bt_switch); -#if defined(OSF) - bt_attached[unit]=1; -#endif /* defined(OSF) */ - return; -} - -/***********************************************\ -* Return some information to the caller about * -* the adapter and it's capabilities * -\***********************************************/ -long int bt_adapter_info(unit) -int unit; -{ - return(2); /* 2 outstanding requests at a time per device */ -} - -/***********************************************\ -* Catch an interrupt from the adaptor * -\***********************************************/ -btintr(unit) -{ - BT_MBI *wmbi; - struct bt_mbx *wmbx; - struct bt_ccb *ccb; - unsigned char stat; - int i,wait; - int found = 0; - -#ifdef UTEST - if(scsi_debug & PRINTROUTINES) - printf("btintr "); -#endif - /***********************************************\ - * First acknowlege the interrupt, Then if it's * - * not telling about a completed operation * - * just return. * - \***********************************************/ - stat = inb(BT_INTR_PORT); - - /* Mail Box out empty ? */ - if ( stat & BT_MBOA ) { - printf("bt%d: Available Free mbo post\n",unit); - /* Disable MBO available interrupt */ - outb(BT_CMD_DATA_PORT,BT_MBO_INTR_EN); - wait = BT_CMD_TIMEOUT_FUDGE * delaycount; - for (i=0; i< wait; i++) - { - if (!(inb(BT_CTRL_STAT_PORT) & BT_CDF)) - break; - } - if (i >= wait) - { - printf("bt%d: bt_intr, cmd/data port full\n",unit); - outb(BT_CTRL_STAT_PORT, BT_SRST); - return 1; - } - outb(BT_CMD_DATA_PORT, 0x00); /* Disable */ - wakeup(&bt_mbx[unit]); - outb(BT_CTRL_STAT_PORT, BT_IRST); - return 1; - } - if (! (stat & BT_MBIF)) { - outb(BT_CTRL_STAT_PORT, BT_IRST); - return 1; - } -#if defined(OSF) - if (!bt_attached[unit]) - { - return(1); - } -#endif /* defined(OSF) */ - /***********************************************\ - * If it IS then process the competed operation * - \***********************************************/ - wmbx = &bt_mbx[unit]; - wmbi = wmbx->tmbi; -AGAIN: - while ( wmbi->stat != BT_MBI_FREE ) { - found++; - ccb = (struct bt_ccb *)PHYSTOKV((wmbi->ccb_addr)); - if((stat = wmbi->stat) != BT_MBI_OK) - { - switch(stat) - { - case BT_MBI_ABORT: -#ifdef UTEST - if(bt_debug & BT_SHOWMISC) - printf("abort "); -#endif - ccb->host_stat = BT_ABORTED; - break; - - case BT_MBI_UNKNOWN: - ccb = (struct bt_ccb *)0; -#ifdef UTEST - if(bt_debug & BT_SHOWMISC) - printf("unknown ccb for abort"); -#endif - break; - - case BT_MBI_ERROR: - break; - - default: - panic("Impossible mbxi status"); - - } -#ifdef UTEST - if((bt_debug & BT_SHOWCMDS ) && ccb) - { - u_char *cp; - cp = ccb->scsi_cmd; - printf("op=%x %x %x %x %x %x\n", - cp[0], cp[1], cp[2], - cp[3], cp[4], cp[5]); - printf("stat %x for mbi addr = 0x%08x\n" - , wmbi->stat, wmbi ); - printf("addr = 0x%x\n", ccb); - } -#endif - } - wmbi->stat = BT_MBI_FREE; - if(ccb) - { - untimeout(bt_timeout,ccb); - bt_done(unit,ccb); - } - - /* Set the IN mail Box pointer for next */ - bt_nextmbx( wmbi, wmbx, mbi ); - } - if ( !found ) { - for ( i = 0; i < BT_MBX_SIZE; i++) { - if ( wmbi->stat != BT_MBI_FREE ) { - found ++; - break; - } - bt_nextmbx( wmbi, wmbx, mbi ); - } - if ( !found ) { - printf("bt%d: mbi at 0x%08x should be found, stat=%02x..resync\n", - unit, wmbi, stat ); - } else { - found = 0; - goto AGAIN; - } - } - wmbx->tmbi = wmbi; - outb(BT_CTRL_STAT_PORT, BT_IRST); - return(1); -} - -/***********************************************\ -* A ccb (and hence a mbx-out is put onto the * -* free list. * -\***********************************************/ -bt_free_ccb(unit,ccb, flags) -struct bt_ccb *ccb; -{ - unsigned int opri; - -#ifdef UTEST - if(scsi_debug & PRINTROUTINES) - printf("ccb%d(0x%x)> ",unit,flags); -#endif - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - - ccb->next = bt_ccb_free[unit]; - bt_ccb_free[unit] = ccb; - ccb->flags = CCB_FREE; - /***********************************************\ - * If there were none, wake abybody waiting for * - * one to come free, starting with queued entries* - \***********************************************/ - if (!ccb->next) { - wakeup(&bt_ccb_free[unit]); - } - if (!(flags & SCSI_NOMASK)) - splx(opri); -} - -/***********************************************\ -* Get a free ccb * -\***********************************************/ -struct bt_ccb * -bt_get_ccb(unit,flags) -{ - unsigned opri; - struct bt_ccb *rc; - struct bt_mbx *wmbx; /* Mail Box pointer specified unit */ - BT_MBO *wmbo; /* Out Mail Box pointer */ - -#ifdef UTEST - if(scsi_debug & PRINTROUTINES) - printf("<ccb%d(0x%x) ",unit,flags); -#endif - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - /***********************************************\ - * If we can and have to, sleep waiting for one * - * to come free * - \***********************************************/ - while ((!(rc = bt_ccb_free[unit])) && (!(flags & SCSI_NOSLEEP))) - { - sleep(&bt_ccb_free[unit], PRIBIO); - } - if (rc) - { - /* Get CCB from from free list */ - bt_ccb_free[unit] = rc->next; - rc->flags = CCB_ACTIVE; -#ifdef HE - /* Get the Target OUT mail Box pointer */ - wmbx = &bt_mbx[unit]; - wmbo = wmbx->tmbo; - while ( wmbo->cmd != BT_MBO_FREE ) { - /* Enable MBO available interrupt */ - outb(BT_CMD_DATA_PORT,BT_MBO_INTR_EN); - printf("Wait free mbo.."); /* AMURAI */ - sleep( wmbx, PRIBIO); - printf("Got free mbo\n"); /* AMURAI */ - } - - /* Link CCB to the Mail Box */ - rc->mbx = wmbo; - wmbo->ccb_addr = KVTOPHYS(rc); - - /* Set the OUT mail Box pointer for next */ - bt_nextmbx( wmbo, wmbx, mbo ); - wmbx->tmbo = wmbo; -#endif - } - if (!(flags & SCSI_NOMASK)) - splx(opri); - - return(rc); -} -/***********************************************\ -* Get a MBO and then Send it * -\***********************************************/ -BT_MBO *bt_send_mbo( int unit, - int flags, - int cmd, - struct bt_ccb *ccb ) -{ - unsigned opri; - BT_MBO *wmbo; /* Mail Box Out pointer */ - struct bt_mbx *wmbx; /* Mail Box pointer specified unit */ - int i, wait; - - wmbx = &bt_mbx[unit]; - - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - - /* Get the Target OUT mail Box pointer and move to Next */ - wmbo = wmbx->tmbo; - wmbx->tmbo = ( wmbo == &( wmbx->mbo[BT_MBX_SIZE - 1 ] ) ? - &(wmbx->mbo[0]) : wmbo + 1 ); - - /* - * Check the outmail box is free or not - * Note: Under the normal operation, it shuld NOT happen to wait. - */ - while ( wmbo->cmd != BT_MBO_FREE ) { - - wait = BT_CMD_TIMEOUT_FUDGE * delaycount; - /* Enable MBO available interrupt */ - outb(BT_CMD_DATA_PORT,BT_MBO_INTR_EN); - for (i=0; i< wait; i++) - { - if (!(inb(BT_CTRL_STAT_PORT) & BT_CDF)) - break; - } - if (i >= wait) - { - printf("bt%d: bt_send_mbo, cmd/data port full\n",unit); - outb(BT_CTRL_STAT_PORT, BT_SRST); - return( (BT_MBO *)0 ); - } - outb(BT_CMD_DATA_PORT, 0x01); /* Enable */ - sleep( wmbx, PRIBIO); - } - - /* Link CCB to the Mail Box */ - wmbo->ccb_addr = KVTOPHYS(ccb); - ccb->mbx = wmbo; - wmbo->cmd = cmd; - - /* Send it ! */ - outb(BT_CMD_DATA_PORT, BT_START_SCSI); - - if (!(flags & SCSI_NOMASK)) - splx(opri); - - return(wmbo); -} -/***********************************************\ -* We have a ccb which has been processed by the * -* adaptor, now we look to see how the operation * -* went. Wake up the owner if waiting * -\***********************************************/ -bt_done(unit,ccb) -struct bt_ccb *ccb; -{ - struct scsi_sense_data *s1,*s2; - struct scsi_xfer *xs = ccb->xfer; - -#ifdef UTEST - if(scsi_debug & (PRINTROUTINES | TRACEINTERRUPTS)) - printf("bt_done "); -#endif - /***********************************************\ - * Otherwise, put the results of the operation * - * into the xfer and call whoever started it * - \***********************************************/ - if ( ( ccb->host_stat != BT_OK - || ccb->target_stat != SCSI_OK) - && (!(xs->flags & SCSI_ERR_OK))) - { - - s1 = &(ccb->scsi_sense); - s2 = &(xs->sense); - - if(ccb->host_stat) - { - switch(ccb->host_stat) - { - case BT_ABORTED: /* No response */ - case BT_SEL_TIMEOUT: /* No response */ -#ifdef UTEST - if (bt_debug & BT_SHOWMISC) - { - printf("timeout reported back\n"); - } -#endif - xs->error = XS_TIMEOUT; - break; - default: /* Other scsi protocol messes */ - xs->error = XS_DRIVER_STUFFUP; -#ifdef UTEST - if (bt_debug & BT_SHOWMISC) - { - printf("unexpected host_stat: %x\n", - ccb->host_stat); - } -#endif - } - - } - else - { - switch(ccb->target_stat) - { - case 0x02: - /* structure copy!!!!!*/ - *s2=*s1; - xs->error = XS_SENSE; - break; - case 0x08: - xs->error = XS_BUSY; - break; - default: -#ifdef UTEST - if (bt_debug & BT_SHOWMISC) - { - printf("unexpected target_stat: %x\n", - ccb->target_stat); - } -#endif - xs->error = XS_DRIVER_STUFFUP; - } - } - } - else /* All went correctly OR errors expected */ - { - xs->resid = 0; - } - xs->flags |= ITSDONE; - bt_free_ccb(unit,ccb, xs->flags); - if(xs->when_done) - (*(xs->when_done))(xs->done_arg,xs->done_arg2); -} - -/***********************************************\ -* Start the board, ready for normal operation * -\***********************************************/ -bt_init(unit) -int unit; -{ - unsigned char ad[4]; - volatile int i,sts; - struct bt_config conf; - - /***********************************************\ - * reset board, If it doesn't respond, assume * - * that it's not there.. good for the probe * - \***********************************************/ - - outb(BT_CTRL_STAT_PORT, BT_HRST|BT_SRST); - - for (i=0; i < BT_RESET_TIMEOUT; i++) - { - sts = inb(BT_CTRL_STAT_PORT) ; - if ( sts == (BT_IDLE | BT_INIT)) - break; - } - if (i >= BT_RESET_TIMEOUT) - { -#ifdef UTEST - if (bt_debug & BT_SHOWMISC) - printf("bt_init: No answer from bt742a board\n"); -#endif - return(ENXIO); - } - - /***********************************************\ - * Assume we have a board at this stage * - * setup dma channel from jumpers and save int * - * level * - \***********************************************/ -#ifdef __386BSD__ - printf("bt%d: reading board settings, ",unit); -#else __386BSD__ - printf("bt%d:",unit); -#endif __386BSD__ - - bt_cmd(unit,0, sizeof(conf), 0 ,&conf, BT_CONF_GET); - switch(conf.chan) - { - case EISADMA: - bt_dma[unit] = -1; - break; - case CHAN0: - outb(0x0b, 0x0c); - outb(0x0a, 0x00); - bt_dma[unit] = 0; - break; - case CHAN5: - outb(0xd6, 0xc1); - outb(0xd4, 0x01); - bt_dma[unit] = 5; - break; - case CHAN6: - outb(0xd6, 0xc2); - outb(0xd4, 0x02); - bt_dma[unit] = 6; - break; - case CHAN7: - outb(0xd6, 0xc3); - outb(0xd4, 0x03); - bt_dma[unit] = 7; - break; - default: - printf("illegal dma setting %x\n",conf.chan); - return(EIO); - } - if (bt_dma[unit] == -1) - printf("eisa dma, "); - else - printf("dma=%d, ",bt_dma[unit]); - - switch(conf.intr) - { - case INT9: - bt_int[unit] = 9; - break; - case INT10: - bt_int[unit] = 10; - break; - case INT11: - bt_int[unit] = 11; - break; - case INT12: - bt_int[unit] = 12; - break; - case INT14: - bt_int[unit] = 14; - break; - case INT15: - bt_int[unit] = 15; - break; - default: - printf("illegal int setting\n"); - return(EIO); - } -#ifdef __386BSD__ - printf("int=%d\n",bt_int[unit]); -#else - printf("int=%d ",bt_int[unit]); -#endif __386BSD__ - - /* who are we on the scsi bus */ - bt_scsi_dev[unit] = conf.scsi_dev; - /***********************************************\ - * Initialize mail box * - \***********************************************/ - *((physaddr *)ad) = KVTOPHYS(&bt_mbx[unit]); - bt_cmd(unit,5, 0, 0, 0, BT_MBX_INIT_EXTENDED - , BT_MBX_SIZE - , ad[0] - , ad[1] - , ad[2] - , ad[3]); - - /***********************************************\ - * Set Pointer chain null for just in case * - * Link the ccb's into a free-list W/O mbox * - * Initilize Mail Box stat to Free * - \***********************************************/ - if ( bt_ccb_free[unit] != (struct bt_ccb *)0 ) { - printf("bt%d: bt_ccb_free is NOT initialized but init here\n", - unit); - bt_ccb_free[unit] = (struct bt_ccb *)0; - } - for (i=0; i < BT_CCB_SIZE; i++) { - bt_ccb[unit][i].next = bt_ccb_free[unit]; - bt_ccb_free[unit] = &bt_ccb[unit][i]; - bt_ccb_free[unit]->flags = CCB_FREE; - } - for (i=0; i < BT_MBX_SIZE; i++) { - bt_mbx[unit].mbo[i].cmd = BT_MBO_FREE; - bt_mbx[unit].mbi[i].stat = BT_MBI_FREE; - } - - /***********************************************\ - * Set up Initial mail box for round-robin * - \***********************************************/ - bt_mbx[unit].tmbo = &bt_mbx[unit].mbo[0]; - bt_mbx[unit].tmbi = &bt_mbx[unit].mbi[0]; - bt_inquire_setup_information( unit ); - - /* Enable round-robin scheme - appeared at FirmWare 3.31 */ - bt_cmd(unit, 1, 0, 0, 0, BT_ROUND_ROBIN, BT_ENABLE ); - - /***********************************************\ - * Note that we are going and return (to probe) * - \***********************************************/ - bt_initialized[unit]++; - return( 0 ); -} -bt_inquire_setup_information( unit ) -int unit; -{ - struct bt_setup setup; - struct bt_boardID bID; - int i; - - /* Inquire Board ID to Bt742 for FirmWare Version */ - bt_cmd(unit, 0, sizeof(bID), 0, &bID, BT_INQUIRE ); - printf("bt%d: version %c.%c, ", - unit, bID.firm_revision, bID.firm_version ); - - /* Ask setup information to Bt742 */ - bt_cmd(unit, 1, sizeof(setup), 0, &setup, BT_SETUP_GET, sizeof(setup) ); - - if ( setup.sync_neg ) { - printf("sync, "); - } else { - printf("async, "); - } - - if ( setup.parity ) { - printf("parity, "); - } else { - printf("no parity, "); - } - - printf("%d mbxs, %d ccbs\n", setup.num_mbx, - sizeof(bt_ccb)/(sizeof(struct bt_ccb) * NBT) ); - - for ( i = 0; i < 8; i++ ) { - if( !setup.sync[i].offset && - !setup.sync[i].period && - !setup.sync[i].valid ) - continue; - - printf("bt%d: dev%02d Offset=%d,Transfer period=%d, Synchronous? %s", - unit, i, - setup.sync[i].offset, setup.sync[i].period, - setup.sync[i].valid ? "Yes" : "No" ); - } - -} - - -#ifndef min -#define min(x,y) (x < y ? x : y) -#endif min - - -void btminphys(bp) -struct buf *bp; -{ -#ifdef MACH -#if !defined(OSF) - bp->b_flags |= B_NPAGES; /* can support scat/gather */ -#endif /* defined(OSF) */ -#endif MACH - if(bp->b_bcount > ((BT_NSEG-1) * PAGESIZ)) - { - bp->b_bcount = ((BT_NSEG-1) * PAGESIZ); - } -} - -/***********************************************\ -* start a scsi operation given the command and * -* the data address. Also needs the unit, target * -* and lu * -\***********************************************/ -int bt_scsi_cmd(xs) -struct scsi_xfer *xs; -{ - struct scsi_sense_data *s1,*s2; - struct bt_ccb *ccb; - struct bt_scat_gath *sg; - int seg; /* scatter gather seg being worked on */ - int i = 0; - int rc = 0; - int thiskv; - physaddr thisphys,nextphys; - int unit =xs->adapter; - int bytes_this_seg,bytes_this_page,datalen,flags; - struct iovec *iovp; - BT_MBO *mbo; - -#ifdef UTEST - if(scsi_debug & PRINTROUTINES) - printf("bt_scsi_cmd "); -#endif - /***********************************************\ - * get a ccb (mbox-out) to use. If the transfer * - * is from a buf (possibly from interrupt time) * - * then we can't allow it to sleep * - \***********************************************/ - flags = xs->flags; - if(xs->bp) flags |= (SCSI_NOSLEEP); /* just to be sure */ - if(flags & ITSDONE) - { - printf("bt%d: Already done?\n",unit); - xs->flags &= ~ITSDONE; - } - if(!(flags & INUSE)) - { - printf("bt%d: Not in use?\n",unit); - xs->flags |= INUSE; - } - if (!(ccb = bt_get_ccb(unit,flags))) - { - xs->error = XS_DRIVER_STUFFUP; - return(TRY_AGAIN_LATER); - } -#ifdef UTEST - if(bt_debug & BT_SHOWCCBS) - printf("<start ccb(%x)>",ccb); -#endif - /***********************************************\ - * Put all the arguments for the xfer in the ccb * - \***********************************************/ - ccb->xfer = xs; - if(flags & SCSI_RESET) - { - ccb->opcode = BT_RESET_CCB; - } - else - { - /* can't use S/G if zero length */ - ccb->opcode = (xs->datalen? - BT_INIT_SCAT_GATH_CCB - :BT_INITIATOR_CCB); - } - ccb->target = xs->targ;; - ccb->data_out = 0; - ccb->data_in = 0; - ccb->lun = xs->lu; - ccb->scsi_cmd_length = xs->cmdlen; - ccb->sense_ptr = KVTOPHYS(&(ccb->scsi_sense)); - ccb->req_sense_length = sizeof(ccb->scsi_sense); - - if((xs->datalen) && (!(flags & SCSI_RESET))) - { /* can use S/G only if not zero length */ - ccb->data_addr = KVTOPHYS(ccb->scat_gath); - sg = ccb->scat_gath ; - seg = 0; - if(flags & SCSI_DATA_UIO) - { - iovp = ((struct uio *)xs->data)->uio_iov; - datalen = ((struct uio *)xs->data)->uio_iovcnt; - xs->datalen = 0; - while ((datalen) && (seg < BT_NSEG)) - { - sg->seg_addr = (physaddr)iovp->iov_base; - xs->datalen += sg->seg_len = iovp->iov_len; -#ifdef UTEST - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x@0x%x)" - ,iovp->iov_len - ,iovp->iov_base); -#endif - sg++; - iovp++; - seg++; - datalen--; - } - } - else - { - /***********************************************\ - * Set up the scatter gather block * - \***********************************************/ - -#ifdef UTEST - if(scsi_debug & SHOWSCATGATH) - printf("%d @0x%x:- ",xs->datalen,xs->data); -#endif - datalen = xs->datalen; - thiskv = (int)xs->data; - thisphys = KVTOPHYS(thiskv); - - while ((datalen) && (seg < BT_NSEG)) - { - bytes_this_seg = 0; - - /* put in the base address */ - sg->seg_addr = thisphys; - -#ifdef UTEST - if(scsi_debug & SHOWSCATGATH) - printf("0x%x",thisphys); -#endif - - /* do it at least once */ - nextphys = thisphys; - while ((datalen) && (thisphys == nextphys)) - /*********************************************\ - * This page is contiguous (physically) with * - * the the last, just extend the length * - \*********************************************/ - { - /* how far to the end of the page */ - nextphys= (thisphys & (~(PAGESIZ - 1))) - + PAGESIZ; - bytes_this_page = nextphys - thisphys; - /**** or the data ****/ - bytes_this_page = min(bytes_this_page - ,datalen); - bytes_this_seg += bytes_this_page; - datalen -= bytes_this_page; - - /* get more ready for the next page */ - thiskv = (thiskv & (~(PAGESIZ - 1))) - + PAGESIZ; - if(datalen) - thisphys = KVTOPHYS(thiskv); - } - /********************************************\ - * next page isn't contiguous, finish the seg * - \********************************************/ -#ifdef UTEST - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x)",bytes_this_seg); -#endif - sg->seg_len = bytes_this_seg; - sg++; - seg++; - } - } /*end of iov/kv decision */ - ccb->data_length = seg * sizeof(struct bt_scat_gath); -#ifdef UTEST - if(scsi_debug & SHOWSCATGATH) - printf("\n"); -#endif - if (datalen) - { /* there's still data, must have run out of segs! */ - printf("bt%d: bt_scsi_cmd, more than %d DMA segs\n", - unit,BT_NSEG); - xs->error = XS_DRIVER_STUFFUP; - bt_free_ccb(unit,ccb,flags); - return(HAD_ERROR); - } - - } - else - { /* No data xfer, use non S/G values */ - ccb->data_addr = (physaddr)0; - ccb->data_length = 0; - } - ccb->link_id = 0; - ccb->link_addr = (physaddr)0; - /***********************************************\ - * Put the scsi command in the ccb and start it * - \***********************************************/ - if(!(flags & SCSI_RESET)) - { - bcopy(xs->cmd, ccb->scsi_cmd, ccb->scsi_cmd_length); - } -#ifdef UTEST - if(scsi_debug & SHOWCOMMANDS) - { - u_char *b = ccb->scsi_cmd; - if(!(flags & SCSI_RESET)) - { - int i = 0; - printf("bt%d:%d:%d-" - ,unit - ,ccb->target - ,ccb->lun); - while(i < ccb->scsi_cmd_length ) - { - if(i) printf(","); - printf("%x",b[i++]); - } - printf("-\n"); - } - else - { - printf("bt%d:%d:%d-RESET- " - ,unit - ,ccb->target - ,ccb->lun - ); - } - } -#endif - if ( bt_send_mbo( unit, flags, BT_MBO_START, ccb ) == (BT_MBO *)0 ) - { - xs->error = XS_DRIVER_STUFFUP; - bt_free_ccb(unit,ccb,flags); - return(TRY_AGAIN_LATER); - } - /***********************************************\ - * Usually return SUCCESSFULLY QUEUED * - \***********************************************/ -#ifdef UTEST - if(scsi_debug & TRACEINTERRUPTS) - printf("cmd_sent "); -#endif - if (!(flags & SCSI_NOMASK)) - { - timeout(bt_timeout,ccb,(xs->timeout * hz) / 1000); - return(SUCCESSFULLY_QUEUED); - } else - /***********************************************\ - * If we can't use interrupts, poll on completion* - \***********************************************/ - { - int done = 0; - int count = delaycount * xs->timeout / BT_SCSI_TIMEOUT_FUDGE; - struct bt_mbx *wmbx = &bt_mbx[unit]; - BT_MBI *wmbi = wmbx->tmbi; - unsigned char stat; -#ifdef UTEST - if(scsi_debug & TRACEINTERRUPTS) - printf("wait "); -#endif - while((!done) && count) - { - stat = inb(BT_INTR_PORT) & (BT_ANY_INTR | BT_MBIF ); - if ( !( stat & BT_ANY_INTR ) || - ( wmbi->stat == BT_MBI_FREE )|| - (PHYSTOKV(wmbi->ccb_addr) - != (int)ccb ) ) { - count--; - continue; - } - wmbi->stat = BT_MBI_FREE; - bt_done(unit,ccb); - done ++; - outb(BT_CTRL_STAT_PORT, BT_IRST); - /* Set the IN mail Box pointer for next */ - bt_nextmbx( wmbi, wmbx, mbi ); - wmbx->tmbi = wmbi; - } - if (!count && !done) - { -#ifdef UTEST - if (!(xs->flags & SCSI_SILENT)) - printf("cmd fail\n"); -#endif - bt_send_mbo( unit, flags, BT_MBO_ABORT, ccb ); - count = delaycount * 2000 / BT_SCSI_TIMEOUT_FUDGE; - while((!done) && count) - { - if ( !( stat & BT_ANY_INTR ) || - ( wmbi->stat == BT_MBI_FREE )|| - ( PHYSTOKV(wmbi->ccb_addr ) - != (int)ccb ) ) { - count--; - continue; - } - wmbi->stat = BT_MBI_FREE; - bt_done(unit,ccb); - done ++; - outb(BT_CTRL_STAT_PORT, BT_IRST); - /* Set the IN mail Box pointer for next */ - bt_nextmbx( wmbi, wmbx, mbi ); - wmbx->tmbi = wmbi; - } - if(!count && !done) - { - printf("bt%d: abort failed in wait\n", unit); - ccb->mbx->cmd = BT_MBO_FREE; - } - bt_free_ccb(unit,ccb,flags); - xs->error = XS_DRIVER_STUFFUP; - return(HAD_ERROR); - } - if(xs->error) return(HAD_ERROR); - return(COMPLETE); - } -} - - -bt_timeout(struct bt_ccb *ccb) -{ - int unit; - int s = splbio(); - - unit = ccb->xfer->adapter; - printf("bt%d: %d device timed out\n",unit - ,ccb->xfer->targ); -#ifdef UTEST - if(bt_debug & BT_SHOWCCBS) - bt_print_active_ccbs(unit); -#endif - - /***************************************\ - * If The ccb's mbx is not free, then * - * the board has gone Far East ? * - \***************************************/ - if((struct bt_ccb *)PHYSTOKV(ccb->mbx->ccb_addr)==ccb && - ccb->mbx->cmd != BT_MBO_FREE ) - { - printf("bt%d: not taking commands!\n" - ,unit); - Debugger(); - } - /***************************************\ - * If it has been through before, then * - * a previous abort has failed, don't * - * try abort again * - \***************************************/ - if(ccb->flags == CCB_ABORTED) /* abort timed out */ - { - printf("bt%d: Abort Operation has timed out\n",unit); - ccb->xfer->retries = 0; /* I MEAN IT ! */ - ccb->host_stat = BT_ABORTED; - bt_done(unit,ccb); - } - else /* abort the operation that has timed out */ - { - printf("bt%d: Try to abort\n",unit); - bt_send_mbo( unit, ~SCSI_NOMASK, - BT_MBO_ABORT, ccb ); - /* 2 secs for the abort */ - timeout(bt_timeout,ccb,2 * hz); - ccb->flags = CCB_ABORTED; - } - splx(s); -} - -#ifdef UTEST -bt_print_ccb(ccb) -struct bt_ccb *ccb; -{ - printf("ccb:%x op:%x cmdlen:%d senlen:%d\n" - ,ccb - ,ccb->opcode - ,ccb->scsi_cmd_length - ,ccb->req_sense_length); - printf(" datlen:%d hstat:%x tstat:%x flags:%x\n" - ,ccb->data_length - ,ccb->host_stat - ,ccb->target_stat - ,ccb->flags); -} - -bt_print_active_ccbs(int unit) -{ - struct bt_ccb *ccb; - ccb = &(bt_ccb[unit][0]); - int i = BT_CCB_SIZE; - - while(i--) - { - if(ccb->flags != CCB_FREE) - bt_print_ccb(ccb); - ccb++; - } -} -#endif /*UTEST*/ diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c deleted file mode 100644 index 53497c8..0000000 --- a/sys/i386/isa/clock.c +++ /dev/null @@ -1,252 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz and Don Ahn. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id$ - */ - -/* - * Primitive clock interrupt routines. - */ -#include "param.h" -#include "systm.h" -#include "time.h" -#include "kernel.h" -#include "machine/segments.h" -#include "i386/isa/icu.h" -#include "i386/isa/isa.h" -#include "i386/isa/rtc.h" -#include "i386/isa/timerreg.h" - -#define DAYST 119 -#define DAYEN 303 - -/* X-tals being what they are, it's nice to be able to fudge this one... */ -/* Note, the name changed here from XTALSPEED to TIMER_FREQ rgrimes 4/26/93 */ -#ifndef TIMER_FREQ -#define TIMER_FREQ 1193182 /* XXX - should be in isa.h */ -#endif - -startrtclock() { - int s; - - findcpuspeed(); /* use the clock (while it's free) - to find the cpu speed */ - /* initialize 8253 clock */ - outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT); - - /* Correct rounding will buy us a better precision in timekeeping */ - outb (IO_TIMER1, (TIMER_FREQ+hz/2)/hz); - outb (IO_TIMER1, ((TIMER_FREQ+hz/2)/hz)/256); - - /* initialize brain-dead battery powered clock */ - outb (IO_RTC, RTC_STATUSA); - outb (IO_RTC+1, 0x26); - outb (IO_RTC, RTC_STATUSB); - outb (IO_RTC+1, 2); - - outb (IO_RTC, RTC_DIAG); - if (s = inb (IO_RTC+1)) - printf("RTC BIOS diagnostic error %b\n", s, RTCDG_BITS); - outb (IO_RTC, RTC_DIAG); - outb (IO_RTC+1, 0); -} - -unsigned int delaycount; /* calibrated loop variable (1 millisecond) */ - -#define FIRST_GUESS 0x2000 -findcpuspeed() -{ - unsigned char low; - unsigned int remainder; - - /* Put counter in count down mode */ - outb(IO_TIMER1+3, 0x34); - outb(IO_TIMER1, 0xff); - outb(IO_TIMER1, 0xff); - delaycount = FIRST_GUESS; - spinwait(1); - /* Read the value left in the counter */ - low = inb(IO_TIMER1); /* least siginifcant */ - remainder = inb(IO_TIMER1); /* most significant */ - remainder = (remainder<<8) + low ; - /* Formula for delaycount is : - * (loopcount * timer clock speed)/ (counter ticks * 1000) - */ - delaycount = (FIRST_GUESS * (TIMER_FREQ/1000)) / (0xffff-remainder); -} - - -/* convert 2 digit BCD number */ -bcd(i) -int i; -{ - return ((i/16)*10 + (i%16)); -} - -/* convert years to seconds (from 1970) */ -unsigned long -ytos(y) -int y; -{ - int i; - unsigned long ret; - - ret = 0; - for(i = 1970; i < y; i++) { - if (i % 4) ret += 365*24*60*60; - else ret += 366*24*60*60; - } - return ret; -} - -/* convert months to seconds */ -unsigned long -mtos(m,leap) -int m,leap; -{ - int i; - unsigned long ret; - - ret = 0; - for(i=1;i<m;i++) { - switch(i){ - case 1: case 3: case 5: case 7: case 8: case 10: case 12: - ret += 31*24*60*60; break; - case 4: case 6: case 9: case 11: - ret += 30*24*60*60; break; - case 2: - if (leap) ret += 29*24*60*60; - else ret += 28*24*60*60; - } - } - return ret; -} - - -/* - * Initialize the time of day register, based on the time base which is, e.g. - * from a filesystem. - */ -inittodr(base) - time_t base; -{ - unsigned long sec; - int leap,day_week,t,yd; - int sa,s; - - /* do we have a realtime clock present? (otherwise we loop below) */ - sa = rtcin(RTC_STATUSA); - if (sa == 0xff || sa == 0) return; - - /* ready for a read? */ - while ((sa&RTCSA_TUP) == RTCSA_TUP) - sa = rtcin(RTC_STATUSA); - - sec = bcd(rtcin(RTC_YEAR)) + 1900; - if (sec < 1970) - sec += 100; - leap = !(sec % 4); sec = ytos(sec); /* year */ - yd = mtos(bcd(rtcin(RTC_MONTH)),leap); sec += yd; /* month */ - t = (bcd(rtcin(RTC_DAY))-1) * 24*60*60; sec += t; yd += t; /* date */ - day_week = rtcin(RTC_WDAY); /* day */ - sec += bcd(rtcin(RTC_HRS)) * 60*60; /* hour */ - sec += bcd(rtcin(RTC_MIN)) * 60; /* minutes */ - sec += bcd(rtcin(RTC_SEC)); /* seconds */ - - /* XXX off by one? Need to calculate DST on SUNDAY */ - /* Perhaps we should have the RTC hold GMT time to save */ - /* us the bother of converting. */ - yd = yd / (24*60*60); - if ((yd >= DAYST) && ( yd <= DAYEN)) { - sec -= 60*60; - } - sec += tz.tz_minuteswest * 60; - - time.tv_sec = sec; -} - -#ifdef garbage -/* - * Initialze the time of day register, based on the time base which is, e.g. - * from a filesystem. - */ -test_inittodr(base) - time_t base; -{ - - outb(IO_RTC,9); /* year */ - printf("%d ",bcd(inb(IO_RTC+1))); - outb(IO_RTC,8); /* month */ - printf("%d ",bcd(inb(IO_RTC+1))); - outb(IO_RTC,7); /* day */ - printf("%d ",bcd(inb(IO_RTC+1))); - outb(IO_RTC,4); /* hour */ - printf("%d ",bcd(inb(IO_RTC+1))); - outb(IO_RTC,2); /* minutes */ - printf("%d ",bcd(inb(IO_RTC+1))); - outb(IO_RTC,0); /* seconds */ - printf("%d\n",bcd(inb(IO_RTC+1))); - - time.tv_sec = base; -} -#endif - -/* - * Restart the clock. - */ -resettodr() -{ -} - -/* - * Wire clock interrupt in. - */ -#define V(s) __CONCAT(V, s) -extern V(clk)(); -enablertclock() { - setidt(ICU_OFFSET+0, &V(clk), SDT_SYS386IGT, SEL_KPL); - INTREN(IRQ0); -} - -/* - * Delay for some number of milliseconds. - */ -void -spinwait(millisecs) - int millisecs; -{ - DELAY(1000 * millisecs); -} diff --git a/sys/i386/isa/fd.c b/sys/i386/isa/fd.c deleted file mode 100644 index c287ef1..0000000 --- a/sys/i386/isa/fd.c +++ /dev/null @@ -1,977 +0,0 @@ -/*#define DEBUG 1*/ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Don Ahn. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 - * $Id: fd.c,v 1.5 1993/09/15 23:27:45 rgrimes Exp $ - * - */ - -#include "fd.h" -#if NFD > 0 - -#include "param.h" -#include "dkbad.h" -#include "systm.h" -#include "conf.h" -#include "file.h" -#include "ioctl.h" -#include "disklabel.h" -#include "buf.h" -#include "uio.h" -#include "syslog.h" -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/fdreg.h" -#include "i386/isa/icu.h" -#include "i386/isa/rtc.h" -#undef NFD -#define NFD 2 - -#define FDUNIT(s) ((s>>3)&1) -#define FDTYPE(s) ((s)&7) - -#define b_cylin b_resid -#define FDBLK 512 -#define NUMTYPES 4 - -struct fd_type { - int sectrac; /* sectors per track */ - int secsize; /* size code for sectors */ - int datalen; /* data len when secsize = 0 */ - int gap; /* gap len between sectors */ - int tracks; /* total num of tracks */ - int size; /* size of disk in sectors */ - int steptrac; /* steps per cylinder */ - int trans; /* transfer speed code */ - int heads; /* number of heads */ -}; - -struct fd_type fd_types[NUMTYPES] = -{ - { 18,2,0xFF,0x1B,80,2880,1,0,2 }, /* 1.44 meg HD 3.5in floppy */ - { 15,2,0xFF,0x1B,80,2400,1,0,2 }, /* 1.2 meg HD floppy */ - { 9,2,0xFF,0x23,40,720,2,1,2 }, /* 360k floppy in 1.2meg drive */ - { 9,2,0xFF,0x2A,40,720,1,1,2 }, /* 360k floppy in DD drive */ -}; - -#define DRVS_PER_CTLR 2 -/***********************************************************************\ -* Per controller structure. * -\***********************************************************************/ -struct fdc_data -{ - int fdcu; /* our unit number */ - int baseport; - int dmachan; - int flags; -#define FDC_ATTACHED 0x01 - struct fd_data *fd; - int fdu; /* the active drive */ - struct buf head; /* Head of buf chain */ - struct buf rhead; /* Raw head of buf chain */ - int state; - int retry; - int status[7]; /* copy of the registers */ -}fdc_data[(NFD+1)/DRVS_PER_CTLR]; - -/***********************************************************************\ -* Per drive structure. * -* N per controller (presently 2) (DRVS_PER_CTLR) * -\***********************************************************************/ -struct fd_data { - struct fdc_data *fdc; - int fdu; /* this unit number */ - int fdsu; /* this units number on this controller */ - int type; /* Drive type (HD, DD */ - struct fd_type *ft; /* pointer to the type descriptor */ - int flags; -#define FD_OPEN 0x01 /* it's open */ -#define FD_ACTIVE 0x02 /* it's active */ -#define FD_MOTOR 0x04 /* motor should be on */ -#define FD_MOTOR_WAIT 0x08 /* motor coming up */ - int skip; - int hddrv; - int track; /* where we think the head is */ -} fd_data[NFD]; - -/***********************************************************************\ -* Throughout this file the following conventions will be used: * -* fd is a pointer to the fd_data struct for the drive in question * -* fdc is a pointer to the fdc_data struct for the controller * -* fdu is the floppy drive unit number * -* fdcu is the floppy controller unit number * -* fdsu is the floppy drive unit number on that controller. (sub-unit) * -\***********************************************************************/ -typedef int fdu_t; -typedef int fdcu_t; -typedef int fdsu_t; -typedef struct fd_data *fd_p; -typedef struct fdc_data *fdc_p; - -#define DEVIDLE 0 -#define FINDWORK 1 -#define DOSEEK 2 -#define SEEKCOMPLETE 3 -#define IOCOMPLETE 4 -#define RECALCOMPLETE 5 -#define STARTRECAL 6 -#define RESETCTLR 7 -#define SEEKWAIT 8 -#define RECALWAIT 9 -#define MOTORWAIT 10 -#define IOTIMEDOUT 11 - -#ifdef DEBUG -char *fdstates[] = -{ -"DEVIDLE", -"FINDWORK", -"DOSEEK", -"SEEKCOMPLETE", -"IOCOMPLETE", -"RECALCOMPLETE", -"STARTRECAL", -"RESETCTLR", -"SEEKWAIT", -"RECALWAIT", -"MOTORWAIT", -"IOTIMEDOUT" -}; - - -int fd_debug = 1; -#define TRACE0(arg) if(fd_debug) printf(arg) -#define TRACE1(arg1,arg2) if(fd_debug) printf(arg1,arg2) -#else DEBUG -#define TRACE0(arg) -#define TRACE1(arg1,arg2) -#endif DEBUG - -extern int hz; -/* state needed for current transfer */ - -/****************************************************************************/ -/* autoconfiguration stuff */ -/****************************************************************************/ -int fdprobe(), fdattach(), fd_turnoff(); - -struct isa_driver fddriver = { - fdprobe, fdattach, "fd", -}; - -/* - * probe for existance of controller - */ -fdprobe(dev) -struct isa_device *dev; -{ - fdcu_t fdcu = dev->id_unit; - if(fdc_data[fdcu].flags & FDC_ATTACHED) - { - printf("fdc: same unit (%d) used multiple times\n",fdcu); - return 0; - } - - fdc_data[fdcu].baseport = dev->id_iobase; - - /* see if it can handle a command */ - if (out_fdc(fdcu,NE7CMD_SPECIFY) < 0) - { - return(0); - } - out_fdc(fdcu,0xDF); - out_fdc(fdcu,2); - return (IO_FDCSIZE); -} - -/* - * wire controller into system, look for floppy units - */ -fdattach(dev) -struct isa_device *dev; -{ - unsigned fdt,st0, cyl; - int hdr; - fdu_t fdu; - fdcu_t fdcu = dev->id_unit; - fdc_p fdc = fdc_data + fdcu; - fd_p fd; - int fdsu; - - fdc->fdcu = fdcu; - fdc->flags |= FDC_ATTACHED; - fdc->dmachan = dev->id_drq; - fdc->state = DEVIDLE; - - fdt = rtcin(RTC_FDISKETTE); - hdr = 0; - - /* check for each floppy drive */ - for (fdu = (fdcu * DRVS_PER_CTLR),fdsu = 0; - ((fdu < NFD) && (fdsu < DRVS_PER_CTLR)); - fdu++,fdsu++) - { - /* is there a unit? */ - if ((fdt & 0xf0) == RTCFDT_NONE) { -#define NO_TYPE NUMTYPES - fd_data[fdu].type = NO_TYPE; - continue; - } - -#ifdef notyet - /* select it */ - fd_turnon1(fdu); - spinwait(1000); /* 1 sec */ - out_fdc(fdcu,NE7CMD_RECAL); /* Recalibrate Function */ - out_fdc(fdcu,fdsu); - spinwait(1000); /* 1 sec */ - - /* anything responding */ - out_fdc(fdcu,NE7CMD_SENSEI); - st0 = in_fdc(fdcu); - cyl = in_fdc(fdcu); - if (st0 & 0xd0) - continue; - -#endif - fd_data[fdu].track = -2; - fd_data[fdu].fdc = fdc; - fd_data[fdu].fdsu = fdsu; - printf("fd%d: unit %d type ", fdcu, fdu); - - if ((fdt & 0xf0) == RTCFDT_12M) { - printf("1.2MB 5.25in\n"); - fd_data[fdu].type = 1; - fd_data[fdu].ft = fd_types + 1; - - } - if ((fdt & 0xf0) == RTCFDT_144M) { - printf("1.44MB 3.5in\n"); - fd_data[fdu].type = 0; - fd_data[fdu].ft = fd_types + 0; - } - - fdt <<= 4; - fd_turnoff(fdu); - hdr = 1; - } - - /* Set transfer to 500kbps */ - outb(fdc->baseport+fdctl,0); /*XXX*/ -} - -int -fdsize(dev) -dev_t dev; -{ - return(0); -} - -/****************************************************************************/ -/* fdstrategy */ -/****************************************************************************/ -fdstrategy(bp) - register struct buf *bp; /* IO operation to perform */ -{ - register struct buf *dp,*dp0,*dp1; - long nblocks,blknum; - int s; - fdcu_t fdcu; - fdu_t fdu; - fdc_p fdc; - fd_p fd; - - fdu = FDUNIT(minor(bp->b_dev)); - fd = &fd_data[fdu]; - fdc = fd->fdc; - fdcu = fdc->fdcu; - /*type = FDTYPE(minor(bp->b_dev));*/ - - if ((fdu >= NFD) || (bp->b_blkno < 0)) { - printf("fdstrat: fdu = %d, blkno = %d, bcount = %d\n", - fdu, bp->b_blkno, bp->b_bcount); - pg("fd:error in fdstrategy"); - bp->b_error = EINVAL; - bp->b_flags |= B_ERROR; - goto bad; - } - /* - * Set up block calculations. - */ - blknum = (unsigned long) bp->b_blkno * DEV_BSIZE/FDBLK; - nblocks = fd->ft->size; - if (blknum + (bp->b_bcount / FDBLK) > nblocks) { - if (blknum == nblocks) { - bp->b_resid = bp->b_bcount; - } else { - bp->b_error = ENOSPC; - bp->b_flags |= B_ERROR; - } - goto bad; - } - bp->b_cylin = blknum / (fd->ft->sectrac * fd->ft->heads); - dp = &(fdc->head); - s = splbio(); - disksort(dp, bp); - untimeout(fd_turnoff,fdu); /* a good idea */ - fdstart(fdcu); - splx(s); - return; - -bad: - biodone(bp); -} - -/****************************************************************************/ -/* motor control stuff */ -/* remember to not deselect the drive we're working on */ -/****************************************************************************/ -set_motor(fdcu, fdu, reset) - fdcu_t fdcu; - fdu_t fdu; - int reset; -{ - int m0,m1; - int selunit; - fd_p fd; - if(fd = fdc_data[fdcu].fd)/* yes an assign! */ - { - selunit = fd->fdsu; - } - else - { - selunit = 0; - } - m0 = fd_data[fdcu * DRVS_PER_CTLR + 0].flags & FD_MOTOR; - m1 = fd_data[fdcu * DRVS_PER_CTLR + 1].flags & FD_MOTOR; - outb(fdc_data[fdcu].baseport+fdout, - selunit - | (reset ? 0 : (FDO_FRST|FDO_FDMAEN)) - | (m0 ? FDO_MOEN0 : 0) - | (m1 ? FDO_MOEN1 : 0)); - TRACE1("[0x%x->fdout]",( - selunit - | (reset ? 0 : (FDO_FRST|FDO_FDMAEN)) - | (m0 ? FDO_MOEN0 : 0) - | (m1 ? FDO_MOEN1 : 0))); -} - -fd_turnoff(fdu) - fdu_t fdu; -{ - int s; - - fd_p fd = fd_data + fdu; - s = splbio(); - fd->flags &= ~FD_MOTOR; - set_motor(fd->fdc->fdcu,fd->fdsu,0); - splx(s); -} - -fd_motor_on(fdu) - fdu_t fdu; -{ - int s; - - fd_p fd = fd_data + fdu; - s = splbio(); - fd->flags &= ~FD_MOTOR_WAIT; - if((fd->fdc->fd == fd) && (fd->fdc->state == MOTORWAIT)) - { - fdintr(fd->fdc->fdcu); - } - splx(s); -} - -fd_turnon(fdu) - fdu_t fdu; -{ - fd_p fd = fd_data + fdu; - if(!(fd->flags & FD_MOTOR)) - { - fd_turnon1(fdu); - fd->flags |= FD_MOTOR_WAIT; - timeout(fd_motor_on,fdu,hz); /* in 1 sec its ok */ - } -} - -fd_turnon1(fdu) - fdu_t fdu; -{ - fd_p fd = fd_data + fdu; - fd->flags |= FD_MOTOR; - set_motor(fd->fdc->fdcu,fd->fdsu,0); -} - -/****************************************************************************/ -/* fdc in/out */ -/****************************************************************************/ -int -in_fdc(fdcu) - fdcu_t fdcu; -{ - int baseport = fdc_data[fdcu].baseport; - int i, j = 100000; - while ((i = inb(baseport+fdsts) & (NE7_DIO|NE7_RQM)) - != (NE7_DIO|NE7_RQM) && j-- > 0) - if (i == NE7_RQM) return -1; - if (j <= 0) - return(-1); -#ifdef DEBUG - i = inb(baseport+fddata); - TRACE1("[fddata->0x%x]",(unsigned char)i); - return(i); -#else - return inb(baseport+fddata); -#endif -} - -out_fdc(fdcu, x) - fdcu_t fdcu; - int x; -{ - int baseport = fdc_data[fdcu].baseport; - int i; - - /* Check that the direction bit is set */ - i = 100000; - while ((inb(baseport+fdsts) & NE7_DIO) && i-- > 0); - if (i <= 0) return (-1); /* Floppy timed out */ - - /* Check that the floppy controller is ready for a command */ - i = 100000; - while ((inb(baseport+fdsts) & NE7_RQM) == 0 && i-- > 0); - if (i <= 0) return (-1); /* Floppy timed out */ - - /* Send the command and return */ - outb(baseport+fddata,x); - TRACE1("[0x%x->fddata]",x); - return (0); -} - -/****************************************************************************/ -/* fdopen/fdclose */ -/****************************************************************************/ -Fdopen(dev, flags) - dev_t dev; - int flags; -{ - fdu_t fdu = FDUNIT(minor(dev)); - /*int type = FDTYPE(minor(dev));*/ - int s; - - /* check bounds */ - if (fdu >= NFD || fd_data[fdu].type == NO_TYPE) return(ENXIO); - /*if (type >= NUMTYPES) return(ENXIO);*/ - fd_data[fdu].flags |= FD_OPEN; - - return 0; -} - -fdclose(dev, flags) - dev_t dev; -{ - fdu_t fdu = FDUNIT(minor(dev)); - fd_data[fdu].flags &= ~FD_OPEN; - return(0); -} - - -/***************************************************************\ -* fdstart * -* We have just queued something.. if the controller is not busy * -* then simulate the case where it has just finished a command * -* So that it (the interrupt routine) looks on the queue for more* -* work to do and picks up what we just added. * -* If the controller is already busy, we need do nothing, as it * -* will pick up our work when the present work completes * -\***************************************************************/ -fdstart(fdcu) - fdcu_t fdcu; -{ - register struct buf *dp,*bp; - int s; - fdu_t fdu; - - s = splbio(); - if(fdc_data[fdcu].state == DEVIDLE) - { - fdintr(fdcu); - } - splx(s); -} - -fd_timeout(fdcu) - fdcu_t fdcu; -{ - fdu_t fdu = fdc_data[fdcu].fdu; - int st0, st3, cyl; - struct buf *dp,*bp; - int s; - - dp = &fdc_data[fdcu].head; - s = splbio(); - bp = dp->b_actf; - - out_fdc(fdcu,NE7CMD_SENSED); - out_fdc(fdcu,fd_data[fdu].hddrv); - st3 = in_fdc(fdcu); - - out_fdc(fdcu,NE7CMD_SENSEI); - st0 = in_fdc(fdcu); - cyl = in_fdc(fdcu); - printf("fd%d: Operation timeout ST0 %b cyl %d ST3 %b\n", - fdu, - st0, - NE7_ST0BITS, - cyl, - st3, - NE7_ST3BITS); - - if (bp) - { - retrier(fdcu); - fdc_data[fdcu].status[0] = 0xc0; - fdc_data[fdcu].state = IOTIMEDOUT; - if( fdc_data[fdcu].retry < 6) - fdc_data[fdcu].retry = 6; - } - else - { - fdc_data[fdcu].fd = (fd_p) 0; - fdc_data[fdcu].fdu = -1; - fdc_data[fdcu].state = DEVIDLE; - } - fdintr(fdcu); - splx(s); -} - -/* just ensure it has the right spl */ -fd_pseudointr(fdcu) - fdcu_t fdcu; -{ - int s; - s = splbio(); - fdintr(fdcu); - splx(s); -} - -/***********************************************************************\ -* fdintr * -* keep calling the state machine until it returns a 0 * -* ALWAYS called at SPLBIO * -\***********************************************************************/ -fdintr(fdcu) - fdcu_t fdcu; -{ - fdc_p fdc = fdc_data + fdcu; - while(fdstate(fdcu, fdc)); -} - -/***********************************************************************\ -* The controller state machine. * -* if it returns a non zero value, it should be called again immediatly * -\***********************************************************************/ -int fdstate(fdcu, fdc) - fdcu_t fdcu; - fdc_p fdc; -{ - int read,head,trac,sec,i,s,sectrac,cyl,st0; - unsigned long blknum; - fdu_t fdu = fdc->fdu; - fd_p fd; - register struct buf *dp,*bp; - - dp = &(fdc->head); - bp = dp->b_actf; - if(!bp) - { - /***********************************************\ - * nothing left for this controller to do * - * Force into the IDLE state, * - \***********************************************/ - fdc->state = DEVIDLE; - if(fdc->fd) - { - printf("unexpected valid fd pointer (fdu = %d)\n" - ,fdc->fdu); - fdc->fd = (fd_p) 0; - fdc->fdu = -1; - } - TRACE1("[fdc%d IDLE]",fdcu); - return(0); - } - fdu = FDUNIT(minor(bp->b_dev)); - fd = fd_data + fdu; - if (fdc->fd && (fd != fdc->fd)) - { - printf("confused fd pointers\n"); - } - read = bp->b_flags & B_READ; - TRACE1("fd%d",fdu); - TRACE1("[%s]",fdstates[fdc->state]); - TRACE1("(0x%x)",fd->flags); - untimeout(fd_turnoff, fdu); - timeout(fd_turnoff,fdu,4 * hz); - switch (fdc->state) - { - case DEVIDLE: - case FINDWORK: /* we have found new work */ - fdc->retry = 0; - fd->skip = 0; - fdc->fd = fd; - fdc->fdu = fdu; - /*******************************************************\ - * If the next drive has a motor startup pending, then * - * it will start up in it's own good time * - \*******************************************************/ - if(fd->flags & FD_MOTOR_WAIT) - { - fdc->state = MOTORWAIT; - return(0); /* come back later */ - } - /*******************************************************\ - * Maybe if it's not starting, it SHOULD be starting * - \*******************************************************/ - if (!(fd->flags & FD_MOTOR)) - { - fdc->state = MOTORWAIT; - fd_turnon(fdu); - return(0); - } - else /* at least make sure we are selected */ - { - set_motor(fdcu,fd->fdsu,0); - } - fdc->state = DOSEEK; - break; - case DOSEEK: - if (bp->b_cylin == fd->track) - { - fdc->state = SEEKCOMPLETE; - break; - } - out_fdc(fdcu,NE7CMD_SEEK); /* Seek function */ - out_fdc(fdcu,fd->fdsu); /* Drive number */ - out_fdc(fdcu,bp->b_cylin * fd->ft->steptrac); - fd->track = -2; - fdc->state = SEEKWAIT; - timeout(fd_timeout,fdcu,2 * hz); - return(0); /* will return later */ - case SEEKWAIT: - untimeout(fd_timeout,fdcu); - /* allow heads to settle */ - timeout(fd_pseudointr,fdcu,hz/50); - fdc->state = SEEKCOMPLETE; - return(0); /* will return later */ - break; - - case SEEKCOMPLETE : /* SEEK DONE, START DMA */ - /* Make sure seek really happened*/ - if(fd->track == -2) - { - int descyl = bp->b_cylin * fd->ft->steptrac; - out_fdc(fdcu,NE7CMD_SENSEI); - i = in_fdc(fdcu); - cyl = in_fdc(fdcu); - if (cyl != descyl) - { - printf("fd%d: Seek to cyl %d failed; am at cyl %d (ST0 = 0x%x)\n", fdu, - descyl, cyl, i, NE7_ST0BITS); - return(retrier(fdcu)); - } - } - - fd->track = bp->b_cylin; - isa_dmastart(bp->b_flags, bp->b_un.b_addr+fd->skip, - FDBLK, fdc->dmachan); - blknum = (unsigned long)bp->b_blkno*DEV_BSIZE/FDBLK - + fd->skip/FDBLK; - sectrac = fd->ft->sectrac; - sec = blknum % (sectrac * fd->ft->heads); - head = sec / sectrac; - sec = sec % sectrac + 1; -/*XXX*/ fd->hddrv = ((head&1)<<2)+fdu; - - if (read) - { - out_fdc(fdcu,NE7CMD_READ); /* READ */ - } - else - { - out_fdc(fdcu,NE7CMD_WRITE); /* WRITE */ - } - out_fdc(fdcu,head << 2 | fdu); /* head & unit */ - out_fdc(fdcu,fd->track); /* track */ - out_fdc(fdcu,head); - out_fdc(fdcu,sec); /* sector XXX +1? */ - out_fdc(fdcu,fd->ft->secsize); /* sector size */ - out_fdc(fdcu,sectrac); /* sectors/track */ - out_fdc(fdcu,fd->ft->gap); /* gap size */ - out_fdc(fdcu,fd->ft->datalen); /* data length */ - fdc->state = IOCOMPLETE; - timeout(fd_timeout,fdcu,2 * hz); - return(0); /* will return later */ - case IOCOMPLETE: /* IO DONE, post-analyze */ - untimeout(fd_timeout,fdcu); - for(i=0;i<7;i++) - { - fdc->status[i] = in_fdc(fdcu); - } - case IOTIMEDOUT: /*XXX*/ - isa_dmadone(bp->b_flags, bp->b_un.b_addr+fd->skip, - FDBLK, fdc->dmachan); - if (fdc->status[0]&0xF8) - { - return(retrier(fdcu)); - } - /* All OK */ - fd->skip += FDBLK; - if (fd->skip < bp->b_bcount) - { - /* set up next transfer */ - blknum = (unsigned long)bp->b_blkno*DEV_BSIZE/FDBLK - + fd->skip/FDBLK; - bp->b_cylin = (blknum / (fd->ft->sectrac * fd->ft->heads)); - fdc->state = DOSEEK; - } - else - { - /* ALL DONE */ - fd->skip = 0; - bp->b_resid = 0; - dp->b_actf = bp->av_forw; - biodone(bp); - fdc->fd = (fd_p) 0; - fdc->fdu = -1; - fdc->state = FINDWORK; - } - return(1); - case RESETCTLR: - /* Try a reset, keep motor on */ - set_motor(fdcu,fd->fdsu,1); - DELAY(100); - set_motor(fdcu,fd->fdsu,0); - outb(fdc->baseport+fdctl,fd->ft->trans); - TRACE1("[0x%x->fdctl]",fd->ft->trans); - fdc->retry++; - fdc->state = STARTRECAL; - break; - case STARTRECAL: - out_fdc(fdcu,NE7CMD_SPECIFY); /* specify command */ - out_fdc(fdcu,0xDF); - out_fdc(fdcu,2); - out_fdc(fdcu,NE7CMD_RECAL); /* Recalibrate Function */ - out_fdc(fdcu,fdu); - fdc->state = RECALWAIT; - return(0); /* will return later */ - case RECALWAIT: - /* allow heads to settle */ - timeout(fd_pseudointr,fdcu,hz/30); - fdc->state = RECALCOMPLETE; - return(0); /* will return later */ - case RECALCOMPLETE: - out_fdc(fdcu,NE7CMD_SENSEI); - st0 = in_fdc(fdcu); - cyl = in_fdc(fdcu); - if (cyl != 0) - { - printf("fd%d: recal failed ST0 %b cyl %d\n", fdu, - st0, NE7_ST0BITS, cyl); - return(retrier(fdcu)); - } - fd->track = 0; - /* Seek (probably) necessary */ - fdc->state = DOSEEK; - return(1); /* will return immediatly */ - case MOTORWAIT: - if(fd->flags & FD_MOTOR_WAIT) - { - return(0); /* time's not up yet */ - } - fdc->state = DOSEEK; - return(1); /* will return immediatly */ - default: - printf("Unexpected FD int->"); - out_fdc(fdcu,NE7CMD_SENSEI); - st0 = in_fdc(fdcu); - cyl = in_fdc(fdcu); - printf("ST0 = %lx, PCN = %lx\n",i,sec); - out_fdc(fdcu,0x4A); - out_fdc(fdcu,fd->fdsu); - for(i=0;i<7;i++) { - fdc->status[i] = in_fdc(fdcu); - } - printf("intr status :%lx %lx %lx %lx %lx %lx %lx ", - fdc->status[0], - fdc->status[1], - fdc->status[2], - fdc->status[3], - fdc->status[4], - fdc->status[5], - fdc->status[6] ); - return(0); - } - return(1); /* Come back immediatly to new state */ -} - -retrier(fdcu) - fdcu_t fdcu; -{ - fdc_p fdc = fdc_data + fdcu; - register struct buf *dp,*bp; - - dp = &(fdc->head); - bp = dp->b_actf; - - switch(fdc->retry) - { - case 0: case 1: case 2: - fdc->state = SEEKCOMPLETE; - break; - case 3: case 4: case 5: - fdc->state = STARTRECAL; - break; - case 6: - fdc->state = RESETCTLR; - break; - case 7: - break; - default: - { - diskerr(bp, "fd", "hard error", LOG_PRINTF, - fdc->fd->skip, (struct disklabel *)NULL); - printf(" (ST0 %b ", fdc->status[0], NE7_ST0BITS); - printf(" ST1 %b ", fdc->status[1], NE7_ST1BITS); - printf(" ST2 %b ", fdc->status[2], NE7_ST2BITS); - printf("cyl %d hd %d sec %d)\n", - fdc->status[3], fdc->status[4], fdc->status[5]); - } - bp->b_flags |= B_ERROR; - bp->b_error = EIO; - bp->b_resid = bp->b_bcount - fdc->fd->skip; - dp->b_actf = bp->av_forw; - fdc->fd->skip = 0; - biodone(bp); - fdc->state = FINDWORK; - fdc->fd = (fd_p) 0; - fdc->fdu = -1; - /* XXX abort current command, if any. */ - return(1); - } - fdc->retry++; - return(1); -} - -/* - * fdioctl() from jc@irbs.UUCP (John Capo) - * i386/i386/conf.c needs to have fdioctl() declared and remove the line that - * defines fdioctl to be enxio. - * - * TODO: Reformat. - * Think about allocating buffer off stack. - * Don't pass uncast 0's and NULL's to read/write/setdisklabel(). - * Watch out for NetBSD's different *disklabel() interface. - */ - -int -fdioctl (dev, cmd, addr, flag) -dev_t dev; -int cmd; -caddr_t addr; -int flag; -{ - struct fd_type *fdt; - struct disklabel *dl; - char buffer[DEV_BSIZE]; - int error; - - error = 0; - - switch (cmd) - { - case DIOCGDINFO: - bzero(buffer, sizeof (buffer)); - dl = (struct disklabel *)buffer; - dl->d_secsize = FDBLK; - fdt = fd_data[FDUNIT(minor(dev))].ft; - dl->d_secpercyl = fdt->size / fdt->tracks; - dl->d_type = DTYPE_FLOPPY; - - if (readdisklabel(dev, fdstrategy, dl, NULL, 0, 0) == NULL) - error = 0; - else - error = EINVAL; - - *(struct disklabel *)addr = *dl; - break; - - case DIOCSDINFO: - - if ((flag & FWRITE) == 0) - error = EBADF; - - break; - - case DIOCWLABEL: - if ((flag & FWRITE) == 0) - error = EBADF; - - break; - - case DIOCWDINFO: - if ((flag & FWRITE) == 0) - { - error = EBADF; - break; - } - - dl = (struct disklabel *)addr; - - if (error = setdisklabel ((struct disklabel *)buffer, dl, 0, NULL)) - break; - - error = writedisklabel(dev, fdstrategy, (struct disklabel *)buffer, NULL); - break; - - default: - error = EINVAL; - break; - } - return (error); -} - -#endif diff --git a/sys/i386/isa/fdreg.h b/sys/i386/isa/fdreg.h deleted file mode 100644 index 84dbf75..0000000 --- a/sys/i386/isa/fdreg.h +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)fdreg.h 7.1 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * AT floppy controller registers and bitfields - */ - -/* uses NEC765 controller */ -#include "../i386/isa/ic/nec765.h" - -/* registers */ -#define fdout 2 /* Digital Output Register (W) */ -#define FDO_FDSEL 0x03 /* floppy device select */ -#define FDO_FRST 0x04 /* floppy controller reset */ -#define FDO_FDMAEN 0x08 /* enable floppy DMA and Interrupt */ -#define FDO_MOEN0 0x10 /* motor enable drive 0 */ -#define FDO_MOEN1 0x20 /* motor enable drive 1 */ -#define FDO_MOEN2 0x30 /* motor enable drive 2 */ -#define FDO_MOEN3 0x40 /* motor enable drive 3 */ - -#define fdsts 4 /* NEC 765 Main Status Register (R) */ -#define fddata 5 /* NEC 765 Data Register (R/W) */ - -#define fdctl 7 /* Control Register (W) */ -#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ -#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ -#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ -#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ - -#define fdin 7 /* Digital Input Register (R) */ -#define FDI_DCHG 0x80 /* diskette has been changed */ - - diff --git a/sys/i386/isa/ic/i8042.h b/sys/i386/isa/ic/i8042.h deleted file mode 100644 index 84ee90f..0000000 --- a/sys/i386/isa/ic/i8042.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * $Id$ - */ - -#define KBSTATP 0x64 /* kbd controller status port (I) */ -#define KBS_DIB 0x01 /* kbd data in buffer */ -#define KBS_IBF 0x02 /* kbd input buffer low */ -#define KBS_WARM 0x04 /* kbd input buffer low */ -#define KBS_OCMD 0x08 /* kbd output buffer has command */ -#define KBS_NOSEC 0x10 /* kbd security lock not engaged */ -#define KBS_TERR 0x20 /* kbd transmission error */ -#define KBS_RERR 0x40 /* kbd receive error */ -#define KBS_PERR 0x80 /* kbd parity error */ - -#define KBCMDP 0x64 /* kbd controller port (O) */ -#define KBDATAP 0x60 /* kbd data port (I) */ -#define KBOUTP 0x60 /* kbd data port (O) */ - -#define K_LDCMDBYTE 0x60 - -#define KC8_TRANS 0x40 /* convert to old scan codes */ -#define KC8_OLDPC 0x20 /* old 9bit codes instead of new 11bit */ -#define KC8_DISABLE 0x10 /* disable keyboard */ -#define KC8_IGNSEC 0x08 /* ignore security lock */ -#define KC8_CPU 0x04 /* exit from protected mode reset */ -#define KC8_IEN 0x01 /* enable interrupt */ -#define CMDBYTE (KC8_TRANS|KC8_IGNSEC|KC8_CPU|KC8_IEN) diff --git a/sys/i386/isa/ic/i8237.h b/sys/i386/isa/ic/i8237.h deleted file mode 100644 index 2199e73..0000000 --- a/sys/i386/isa/ic/i8237.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Intel 8237 DMA Controller - * - * $Id$ - */ - -#define DMA37MD_SINGLE 0x40 /* single pass mode */ -#define DMA37MD_CASCADE 0xc0 /* cascade mode */ -#define DMA37MD_WRITE 0x04 /* read the device, write memory operation */ -#define DMA37MD_READ 0x08 /* write the device, read memory operation */ - diff --git a/sys/i386/isa/ic/i82586.h b/sys/i386/isa/ic/i82586.h deleted file mode 100644 index 577313d..0000000 --- a/sys/i386/isa/ic/i82586.h +++ /dev/null @@ -1,325 +0,0 @@ -/*- - * Copyright (c) 1992, University of Vermont and State Agricultural College. - * Copyright (c) 1992, Garrett A. Wollman. - * All rights reserved. - * - * 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 University of - * Vermont and State Agricultural College and Garrett A. Wollman. - * 4. Neither the name of the University nor the name of the author - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHOR BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * $Id$ - */ - -/* - * Intel 82586 Ethernet chip - * Register, bit, and structure definitions. - * - * Written by GAW with reference to the Clarkson Packet Driver code for this - * chip written by Russ Nelson and others. - */ - -struct ie_en_addr { - u_char data[6]; -}; - -/* - * This is the master configuration block. It tells the hardware where all - * the rest of the stuff is. - */ -struct ie_sys_conf_ptr { - u_short mbz; /* must be zero */ - u_char ie_bus_use; /* true if 8-bit only */ - u_char mbz2[5]; /* must be zero */ - caddr_t ie_iscp_ptr; /* 24-bit physaddr of ISCP */ -}; - -/* - * Note that this is wired in hardware; the SCP is always located here, no - * matter what. - */ -#define IE_SCP_ADDR 0xfffff4 - -/* - * The tells the hardware where all the rest of the stuff is, too. - * FIXME: some of these should be re-commented after we figure out their - * REAL function. - */ -struct ie_int_sys_conf_ptr { - u_char ie_busy; /* zeroed after init */ - u_char mbz; - u_short ie_scb_offset; /* 16-bit physaddr of next struct */ - caddr_t ie_base; /* 24-bit physaddr for all 16-bit vars */ -}; - -/* - * This FINALLY tells the hardware what to do and where to put it. - */ -struct ie_sys_ctl_block { - u_short ie_status; /* status word */ - u_short ie_command; /* command word */ - u_short ie_command_list; /* 16-pointer to command block list */ - u_short ie_recv_list; /* 16-pointer to receive frame list */ - u_short ie_err_crc; /* CRC errors */ - u_short ie_err_align; /* Alignment errors */ - u_short ie_err_resource; /* Resource errors */ - u_short ie_err_overrun; /* Overrun errors */ -}; - -/* Command values */ -#define IE_RU_COMMAND 0x0070 /* mask for RU command */ -#define IE_RU_NOP 0 /* for completeness */ -#define IE_RU_START 0x0010 /* start receive unit command */ -#define IE_RU_ENABLE 0x0020 /* enable receiver command */ -#define IE_RU_DISABLE 0x0030 /* disable receiver command */ -#define IE_RU_ABORT 0x0040 /* abort current receive operation */ - -#define IE_CU_COMMAND 0x0700 /* mask for CU command */ -#define IE_CU_NOP 0 /* included for completeness */ -#define IE_CU_START 0x0100 /* do-command command */ -#define IE_CU_RESUME 0x0200 /* resume a suspended cmd list */ -#define IE_CU_STOP 0x0300 /* SUSPEND was already taken */ -#define IE_CU_ABORT 0x0400 /* abort current command */ - -#define IE_ACK_COMMAND 0xf000 /* mask for ACK command */ -#define IE_ACK_CX 0x8000 /* ack IE_ST_DONE */ -#define IE_ACK_FR 0x4000 /* ack IE_ST_RECV */ -#define IE_ACK_CNA 0x2000 /* ack IE_ST_ALLDONE */ -#define IE_ACK_RNR 0x1000 /* ack IE_ST_RNR */ - -#define IE_ACTION_COMMAND(x) (((x) & IE_CU_COMMAND) == IE_CU_START) - /* is this command an action command? */ - -/* Status values */ -#define IE_ST_WHENCE 0xf000 /* mask for cause of interrupt */ -#define IE_ST_DONE 0x8000 /* command with I bit completed */ -#define IE_ST_RECV 0x4000 /* frame received */ -#define IE_ST_ALLDONE 0x2000 /* all commands completed */ -#define IE_ST_RNR 0x1000 /* receive not ready */ - -#define IE_CU_STATUS 0x700 /* mask for command unit status */ -#define IE_CU_ACTIVE 0x200 /* command unit is active */ -#define IE_CU_SUSPEND 0x100 /* command unit is suspended */ - -#define IE_RU_STATUS 0x70 /* mask for receiver unit status */ -#define IE_RU_SUSPEND 0x10 /* receiver is suspended */ -#define IE_RU_NOSPACE 0x20 /* receiver has no resources */ -#define IE_RU_READY 0x40 /* reveiver is ready */ - -/* - * This is filled in partially by the chip, partially by us. - */ -struct ie_recv_frame_desc { - u_short ie_fd_status; /* status for this frame */ - u_short ie_fd_last; /* end of frame list flag */ - u_short ie_fd_next; /* 16-pointer to next RFD */ - u_short ie_fd_buf_desc; /* 16-pointer to list of buffer desc's */ - struct ie_en_addr dest; /* destination ether */ - struct ie_en_addr src; /* source ether */ - u_short ie_length; /* 802 length/Ether type */ - u_short mbz; /* must be zero */ -}; - -#define IE_FD_LAST 0x8000 /* last rfd in list */ -#define IE_FD_SUSP 0x4000 /* suspend RU after receipt */ - -#define IE_FD_COMPLETE 0x8000 /* frame is complete */ -#define IE_FD_BUSY 0x4000 /* frame is busy */ -#define IE_FD_OK 0x2000 /* frame is bad */ -#define IE_FD_RNR 0x0200 /* receiver out of resources here */ - -/* - * linked list of buffers... - */ -struct ie_recv_buf_desc { - u_short ie_rbd_actual; /* status for this buffer */ - u_short ie_rbd_next; /* 16-pointer to next RBD */ - caddr_t ie_rbd_buffer; /* 24-pointer to buffer for this RBD */ - u_short ie_rbd_length; /* length of the buffer */ - u_short mbz; /* must be zero */ -}; - -#define IE_RBD_LAST 0x8000 /* last buffer */ -#define IE_RBD_USED 0x4000 /* this buffer has data */ -/* - * All commands share this in common. - */ -struct ie_cmd_common { - u_short ie_cmd_status; /* status of this command */ - u_short ie_cmd_cmd; /* command word */ - u_short ie_cmd_link; /* link to next command */ -}; - -#define IE_STAT_COMPL 0x8000 /* command is completed */ -#define IE_STAT_BUSY 0x4000 /* command is running now */ -#define IE_STAT_OK 0x2000 /* command completed successfully */ - -#define IE_CMD_NOP 0x0000 /* NOP */ -#define IE_CMD_IASETUP 0x0001 /* initial address setup */ -#define IE_CMD_CONFIG 0x0002 /* configure command */ -#define IE_CMD_MCAST 0x0003 /* multicast setup command */ -#define IE_CMD_XMIT 0x0004 /* transmit command */ -#define IE_CMD_TDR 0x0005 /* time-domain reflectometer command */ -#define IE_CMD_DUMP 0x0006 /* dump command */ -#define IE_CMD_DIAGNOSE 0x0007 /* diagnostics command */ - -#define IE_CMD_LAST 0x8000 /* this is the last command in the list */ -#define IE_CMD_SUSPEND 0x4000 /* suspend CU after this command */ -#define IE_CMD_INTR 0x2000 /* post an interrupt after completion */ - -/* - * This is the command to transmit a frame. - */ -struct ie_xmit_cmd { - struct ie_cmd_common com; /* common part */ -#define ie_xmit_status com.ie_cmd_status - - u_short ie_xmit_desc; /* 16-pointer to buffer descriptor */ - struct ie_en_addr ie_xmit_addr; /* destination address */ - - u_short ie_xmit_length; /* 802.3 length/Ether type field */ -}; - -#define IE_XS_MAXCOLL 0x000f /* number of collisions during transmit */ -#define IE_XS_EXCMAX 0x0020 /* exceeded maximum number of collisions */ -#define IE_XS_SQE 0x0040 /* SQE positive */ -#define IE_XS_DEFERRED 0x0080 /* transmission deferred */ -#define IE_XS_UNDERRUN 0x0100 /* DMA underrun */ -#define IE_XS_LOSTCTS 0x0200 /* Lost CTS */ -#define IE_XS_NOCARRIER 0x0400 /* No Carrier */ -#define IE_XS_LATECOLL 0x0800 /* Late collision */ - -/* - * This is a buffer descriptor for a frame to be transmitted. - */ - -struct ie_xmit_buf { - u_short ie_xmit_flags; /* see below */ - u_short ie_xmit_next; /* 16-pointer to next desc. */ - caddr_t ie_xmit_buf; /* 24-pointer to the actual buffer */ -}; - -#define IE_XMIT_LAST 0x8000 /* this TBD is the last one */ -/* The rest of the `flags' word is actually the length. */ - -/* - * Multicast setup command. - */ - -#define MAXMCAST 50 /* must fit in transmit buffer */ - -struct ie_mcast_cmd { - struct ie_cmd_common com; /* common part */ -#define ie_mcast_status com.ie_cmd_status - - u_short ie_mcast_bytes; /* size (in bytes) of multicast addresses */ - struct ie_en_addr ie_mcast_addrs[MAXMCAST + 1]; /* space for them */ -}; - -/* - * Time Domain Reflectometer command. - */ - -struct ie_tdr_cmd { - struct ie_cmd_common com; /* common part */ -#define ie_tdr_status com.ie_cmd_status - - u_short ie_tdr_time; /* error bits and time */ -}; - -#define IE_TDR_SUCCESS 0x8000 /* TDR succeeded without error */ -#define IE_TDR_XCVR 0x4000 /* detected a transceiver problem */ -#define IE_TDR_OPEN 0x2000 /* detected an open */ -#define IE_TDR_SHORT 0x1000 /* TDR detected a short */ -#define IE_TDR_TIME 0x07ff /* mask for reflection time */ - -/* - * Initial Address Setup command - */ -struct ie_iasetup_cmd { - struct ie_cmd_common com; -#define ie_iasetup_status com.ie_cmd_status - - struct ie_en_addr ie_address; -}; - -/* - * Configuration command - */ -struct ie_config_cmd { - struct ie_cmd_common com; /* common part */ -#define ie_config_status com.ie_cmd_status - - u_char ie_config_count; /* byte count (0x0c) */ - u_char ie_fifo; /* fifo (8) */ - u_char ie_save_bad; /* save bad frames (0x40) */ - u_char ie_addr_len; /* address length (0x2e) (AL-LOC == 1) */ - u_char ie_priority; /* priority and backoff (0x0) */ - u_char ie_ifs; /* inter-frame spacing (0x60) */ - u_char ie_slot_low; /* slot time, LSB (0x0) */ - u_char ie_slot_high; /* slot time, MSN, and retries (0xf2) */ - u_char ie_promisc; /* 1 if promiscuous, else 0 */ - u_char ie_crs_cdt; /* CSMA/CD parameters (0x0) */ - u_char ie_min_len; /* min frame length (0x40) */ - u_char ie_junk; /* stuff for 82596 (0xff) */ -}; - -/* - * Here are a few useful functions. We could have done these as macros, - * but since we have the inline facility, it makes sense to use that - * instead. - */ -inline void -ie_setup_config(volatile struct ie_config_cmd *cmd, - int promiscuous, int manchester) { - cmd->ie_config_count = 0x0c; - cmd->ie_fifo = 8; - cmd->ie_save_bad = 0x40; - cmd->ie_addr_len = 0x2e; - cmd->ie_priority = 0; - cmd->ie_ifs = 0x60; - cmd->ie_slot_low = 0; - cmd->ie_slot_high = 0xf2; - cmd->ie_promisc = !!promiscuous | manchester << 2; - cmd->ie_crs_cdt = 0; - cmd->ie_min_len = 64; - cmd->ie_junk = 0xff; -} - -inline caddr_t -Align(caddr_t ptr) { - unsigned long l = (unsigned long)ptr; - l = (l + 3) & ~3L; - return (caddr_t)l; -} - -inline void -ie_ack(volatile struct ie_sys_ctl_block *scb, - u_int mask, int unit, - void (*ca)(int)) { - scb->ie_command = scb->ie_status & mask; - (*ca)(unit); -} diff --git a/sys/i386/isa/ic/nec765.h b/sys/i386/isa/ic/nec765.h deleted file mode 100644 index 1895db7..0000000 --- a/sys/i386/isa/ic/nec765.h +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)nec765.h 7.1 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * Nec 765 floppy disc controller definitions - */ - -/* Main status register */ -#define NE7_DAB 0x01 /* Diskette drive A is seeking, thus busy */ -#define NE7_DBB 0x02 /* Diskette drive B is seeking, thus busy */ -#define NE7_CB 0x10 /* Diskette Controller Busy */ -#define NE7_NDM 0x20 /* Diskette Controller in Non Dma Mode */ -#define NE7_DIO 0x40 /* Diskette Controller Data register I/O */ -#define NE7_RQM 0x80 /* Diskette Controller ReQuest for Master */ - -/* Status register ST0 */ -#define NE7_ST0BITS "\020\010invld\007abnrml\006seek_cmplt\005drv_chck\004drive_rdy\003top_head" - -/* Status register ST1 */ -#define NE7_ST1BITS "\020\010end_of_cyl\006bad_crc\005data_overrun\003sec_not_fnd\002write_protect\001no_am" - -/* Status register ST2 */ -#define NE7_ST2BITS "\020\007ctrl_mrk\006bad_crc\005wrong_cyl\004scn_eq\003scn_not_fnd\002bad_cyl\001no_dam" - -/* Status register ST3 */ -#define NE7_ST3BITS "\020\010fault\007write_protect\006drdy\005tk0\004two_side\003side_sel\002" - -/* Commands */ -#define NE7CMD_SPECIFY 3 /* specify drive parameters - requires unit - parameters byte */ -#define NE7CMD_SENSED 4 /* sense drive - requires unit select byte */ -#define NE7CMD_WRITE 0xc5 /* write - requires eight additional bytes */ -#define NE7CMD_READ 0xe6 /* read - requires eight additional bytes */ -#define NE7CMD_FORMAT 0x4c /* format - requires five additional bytes */ -#define NE7CMD_RECAL 7 /* recalibrate drive - requires - unit select byte */ -#define NE7CMD_SENSEI 8 /* sense controller interrupt status */ -#define NE7CMD_SEEK 15 /* seek drive - requires unit select byte - and new cyl byte */ diff --git a/sys/i386/isa/ic/ns16450.h b/sys/i386/isa/ic/ns16450.h deleted file mode 100644 index aa6280d..0000000 --- a/sys/i386/isa/ic/ns16450.h +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)ns16450.h 7.1 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * NS16450 UART registers - */ - -#define com_data 0 /* data register (R/W) */ -#define com_dlbl 0 /* divisor latch low (W) */ -#define com_dlbh 1 /* divisor latch high (W) */ -#define com_ier 1 /* interrupt enable (W) */ -#define com_iir 2 /* interrupt identification (R) */ -#define com_lctl 3 /* line control register (R/W) */ -#define com_cfcr 3 /* line control register (R/W) */ -#define com_mcr 4 /* modem control register (R/W) */ -#define com_lsr 5 /* line status register (R/W) */ -#define com_msr 6 /* modem status register (R/W) */ diff --git a/sys/i386/isa/ic/ns16550.h b/sys/i386/isa/ic/ns16550.h deleted file mode 100644 index ff59757..0000000 --- a/sys/i386/isa/ic/ns16550.h +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)ns16550.h 7.1 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * NS16550 UART registers - */ - -#define com_data 0 /* data register (R/W) */ -#define com_dlbl 0 /* divisor latch low (W) */ -#define com_dlbh 1 /* divisor latch high (W) */ -#define com_ier 1 /* interrupt enable (W) */ -#define com_iir 2 /* interrupt identification (R) */ -#define com_fifo 2 /* FIFO control (W) */ -#define com_lctl 3 /* line control register (R/W) */ -#define com_cfcr 3 /* line control register (R/W) */ -#define com_mcr 4 /* modem control register (R/W) */ -#define com_lsr 5 /* line status register (R/W) */ -#define com_msr 6 /* modem status register (R/W) */ diff --git a/sys/i386/isa/icu.h b/sys/i386/isa/icu.h deleted file mode 100644 index 488ad3e..0000000 --- a/sys/i386/isa/icu.h +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)icu.h 5.6 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * AT/386 Interrupt Control constants - * W. Jolitz 8/89 - */ - -#ifndef __ICU__ -#define __ICU__ - -#ifndef LOCORE - -/* - * Interrupt "level" mechanism variables, masks, and macros - */ -extern unsigned imen; /* interrupt mask enable */ -extern unsigned cpl; /* current priority level mask */ - -extern unsigned highmask; /* group of interrupts masked with splhigh() */ -extern unsigned ttymask; /* group of interrupts masked with spltty() */ -extern unsigned biomask; /* group of interrupts masked with splbio() */ -extern unsigned netmask; /* group of interrupts masked with splimp() */ - -#define INTREN(s) (imen &= ~(s), SET_ICUS()) -#define INTRDIS(s) (imen |= (s), SET_ICUS()) -#define INTRMASK(msk,s) (msk |= (s)) -#if 0 -#define SET_ICUS() (outb(IO_ICU1 + 1, imen), outb(IU_ICU2 + 1, imen >> 8)) -#else -/* - * XXX - IO_ICU* are defined in isa.h, not icu.h, and nothing much bothers to - * include isa.h, while too many things include icu.h. - */ -#define SET_ICUS() (outb(0x21, imen), outb(0xa1, imen >> 8)) -#endif - -#endif - -/* - * Interrupt enable bits -- in order of priority - */ -#define IRQ0 0x0001 /* highest priority - timer */ -#define IRQ1 0x0002 -#define IRQ_SLAVE 0x0004 -#define IRQ8 0x0100 -#define IRQ9 0x0200 -#define IRQ2 IRQ9 -#define IRQ10 0x0400 -#define IRQ11 0x0800 -#define IRQ12 0x1000 -#define IRQ13 0x2000 -#define IRQ14 0x4000 -#define IRQ15 0x8000 -#define IRQ3 0x0008 -#define IRQ4 0x0010 -#define IRQ5 0x0020 -#define IRQ6 0x0040 -#define IRQ7 0x0080 /* lowest - parallel printer */ - -/* - * Interrupt Control offset into Interrupt descriptor table (IDT) - */ -#define ICU_OFFSET 32 /* 0-31 are processor exceptions */ -#define ICU_LEN 16 /* 32-47 are ISA interrupts */ - -#endif __ICU__ diff --git a/sys/i386/isa/icu.s b/sys/i386/isa/icu.s deleted file mode 100644 index 22cec58..0000000 --- a/sys/i386/isa/icu.s +++ /dev/null @@ -1,377 +0,0 @@ -/*- - * Copyright (c) 1989, 1990 William F. Jolitz. - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * @(#)icu.s 7.2 (Berkeley) 5/21/91 - * - * $Id$ - */ - -/* - * AT/386 - * Vector interrupt control section - */ - -/* - * XXX - this file is now misnamed. All spls are now soft and the only thing - * related to the hardware icu is that the bit numbering is the same in the - * soft priority masks as in the hard ones. - */ - -#include "sio.h" -#define HIGHMASK 0xffff -#define SOFTCLOCKMASK 0x8000 - - .data - .globl _cpl -_cpl: .long 0xffff # current priority (all off) - .globl _imen -_imen: .long 0xffff # interrupt mask enable (all off) -/* .globl _highmask */ -_highmask: .long HIGHMASK - .globl _ttymask -_ttymask: .long 0 - .globl _biomask -_biomask: .long 0 - .globl _netmask -_netmask: .long 0 - .globl _ipending -_ipending: .long 0 -vec: - .long vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7 - .long vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15 - -#define GENSPL(name, mask, event) \ - .globl _spl/**/name ; \ - ALIGN_TEXT ; \ -_spl/**/name: ; \ - COUNT_EVENT(_intrcnt_spl, event) ; \ - movl _cpl,%eax ; \ - movl %eax,%edx ; \ - orl mask,%edx ; \ - movl %edx,_cpl ; \ - SHOW_CPL ; \ - ret - -#define FASTSPL(mask) \ - movl mask,_cpl ; \ - SHOW_CPL - -#define FASTSPL_VARMASK(varmask) \ - movl varmask,%eax ; \ - movl %eax,_cpl ; \ - SHOW_CPL - - .text - - ALIGN_TEXT -unpend_v: - COUNT_EVENT(_intrcnt_spl, 0) - bsfl %eax,%eax # slow, but not worth optimizing - btrl %eax,_ipending - jnc unpend_v_next # some intr cleared the in-memory bit - SHOW_IPENDING - movl Vresume(,%eax,4),%eax - testl %eax,%eax - je noresume - jmp %eax - - ALIGN_TEXT -/* - * XXX - must be some fastintr, need to register those too. - */ -noresume: -#if NSIO > 0 - call _softsio1 -#endif -unpend_v_next: - movl _cpl,%eax - movl %eax,%edx - notl %eax - andl _ipending,%eax - je none_to_unpend - jmp unpend_v - -/* - * Handle return from interrupt after device handler finishes - */ - ALIGN_TEXT -doreti: - COUNT_EVENT(_intrcnt_spl, 1) - addl $4,%esp # discard unit arg - popl %eax # get previous priority -/* - * Now interrupt frame is a trap frame! - * - * XXX - setting up the interrupt frame to be almost a stack frame is mostly - * a waste of time. - */ - movl %eax,_cpl - SHOW_CPL - movl %eax,%edx - notl %eax - andl _ipending,%eax - jne unpend_v -none_to_unpend: - testl %edx,%edx # returning to zero priority? - jne 1f # nope, going to non-zero priority - movl _netisr,%eax - testl %eax,%eax # check for softint s/traps - jne 2f # there are some - jmp test_resched # XXX - schedule jumps better - COUNT_EVENT(_intrcnt_spl, 2) # XXX - - ALIGN_TEXT # XXX -1: # XXX - COUNT_EVENT(_intrcnt_spl, 3) - popl %es - popl %ds - popal - addl $8,%esp - iret - -#include "../net/netisr.h" - -#define DONET(s, c, event) ; \ - .globl c ; \ - btrl $s,_netisr ; \ - jnc 1f ; \ - COUNT_EVENT(_intrcnt_spl, event) ; \ - call c ; \ -1: - - ALIGN_TEXT -2: - COUNT_EVENT(_intrcnt_spl, 4) -/* - * XXX - might need extra locking while testing reg copy of netisr, but - * interrupt routines setting it would not cause any new problems (since we - * don't loop, fresh bits will not be processed until the next doreti or spl0). - */ - testl $~((1 << NETISR_SCLK) | (1 << NETISR_AST)),%eax - je test_ASTs # no net stuff, just temporary AST's - FASTSPL_VARMASK(_netmask) - DONET(NETISR_RAW, _rawintr, 5) - -#ifdef INET - DONET(NETISR_IP, _ipintr, 6) -#endif /* INET */ - -#ifdef IMP - DONET(NETISR_IMP, _impintr, 7) -#endif /* IMP */ - -#ifdef NS - DONET(NETISR_NS, _nsintr, 8) -#endif /* NS */ - -#ifdef ISO - DONET(NETISR_ISO, _clnlintr, 9) -#endif /* ISO */ - - FASTSPL($0) -test_ASTs: - btrl $NETISR_SCLK,_netisr - jnc test_resched - COUNT_EVENT(_intrcnt_spl, 10) - FASTSPL($SOFTCLOCKMASK) -/* - * Back to an interrupt frame for a moment. - */ - pushl $0 # previous cpl (probably not used) - pushl $0x7f # dummy unit number - call _softclock - addl $8,%esp # discard dummies - FASTSPL($0) -test_resched: -#ifdef notused1 - btrl $NETISR_AST,_netisr - jnc 2f -#endif -#ifdef notused2 - cmpl $0,_want_resched - je 2f -#endif - cmpl $0,_astpending # XXX - put it back in netisr to - je 2f # reduce the number of tests - testb $SEL_RPL_MASK,TRAPF_CS_OFF(%esp) - # to non-kernel (i.e., user)? - je 2f # nope, leave - COUNT_EVENT(_intrcnt_spl, 11) - movl $0,_astpending - call _trap -2: - COUNT_EVENT(_intrcnt_spl, 12) - popl %es - popl %ds - popal - addl $8,%esp - iret - -/* - * Interrupt priority mechanism - * -- soft splXX masks with group mechanism (cpl) - * -- h/w masks for currently active or unused interrupts (imen) - * -- ipending = active interrupts currently masked by cpl - */ - - GENSPL(bio, _biomask, 13) - GENSPL(clock, $HIGHMASK, 14) /* splclock == splhigh ex for count */ - GENSPL(high, $HIGHMASK, 15) - GENSPL(imp, _netmask, 16) /* splimp == splnet except for count */ - GENSPL(net, _netmask, 17) - GENSPL(softclock, $SOFTCLOCKMASK, 18) - GENSPL(tty, _ttymask, 19) - - .globl _splnone - .globl _spl0 - ALIGN_TEXT -_splnone: -_spl0: - COUNT_EVENT(_intrcnt_spl, 20) -in_spl0: - movl _cpl,%eax - pushl %eax # save old priority - testl $(1 << NETISR_RAW) | (1 << NETISR_IP),_netisr - je over_net_stuff_for_spl0 - movl _netmask,%eax # mask off those network devices - movl %eax,_cpl # set new priority - SHOW_CPL -/* - * XXX - what about other net intrs? - */ - DONET(NETISR_RAW, _rawintr, 21) - -#ifdef INET - DONET(NETISR_IP, _ipintr, 22) -#endif /* INET */ - -#ifdef IMP - DONET(NETISR_IMP, _impintr, 23) -#endif /* IMP */ - -#ifdef NS - DONET(NETISR_NS, _nsintr, 24) -#endif /* NS */ - -#ifdef ISO - DONET(NETISR_ISO, _clnlintr, 25) -#endif /* ISO */ - -over_net_stuff_for_spl0: - movl $0,_cpl # set new priority - SHOW_CPL - movl _ipending,%eax - testl %eax,%eax - jne unpend_V - popl %eax # return old priority - ret - - .globl _splx - ALIGN_TEXT -_splx: - COUNT_EVENT(_intrcnt_spl, 26) - movl 4(%esp),%eax # new priority - testl %eax,%eax - je in_spl0 # going to "zero level" is special - COUNT_EVENT(_intrcnt_spl, 27) - movl _cpl,%edx # save old priority - movl %eax,_cpl # set new priority - SHOW_CPL - notl %eax - andl _ipending,%eax - jne unpend_V_result_edx - movl %edx,%eax # return old priority - ret - - ALIGN_TEXT -unpend_V_result_edx: - pushl %edx -unpend_V: - COUNT_EVENT(_intrcnt_spl, 28) - bsfl %eax,%eax - btrl %eax,_ipending - jnc unpend_V_next - SHOW_IPENDING - movl Vresume(,%eax,4),%edx - testl %edx,%edx - je noresumeV -/* - * We would prefer to call the intr handler directly here but that doesn't - * work for badly behaved handlers that want the interrupt frame. Also, - * there's a problem determining the unit number. We should change the - * interface so that the unit number is not determined at config time. - */ - jmp *vec(,%eax,4) - - ALIGN_TEXT -/* - * XXX - must be some fastintr, need to register those too. - */ -noresumeV: -#if NSIO > 0 - call _softsio1 -#endif -unpend_V_next: - movl _cpl,%eax - notl %eax - andl _ipending,%eax - jne unpend_V - popl %eax - ret - -#define BUILD_VEC(irq_num) \ - ALIGN_TEXT ; \ -vec/**/irq_num: ; \ - int $ICU_OFFSET + (irq_num) ; \ - popl %eax ; \ - ret - - BUILD_VEC(0) - BUILD_VEC(1) - BUILD_VEC(2) - BUILD_VEC(3) - BUILD_VEC(4) - BUILD_VEC(5) - BUILD_VEC(6) - BUILD_VEC(7) - BUILD_VEC(8) - BUILD_VEC(9) - BUILD_VEC(10) - BUILD_VEC(11) - BUILD_VEC(12) - BUILD_VEC(13) - BUILD_VEC(14) - BUILD_VEC(15) diff --git a/sys/i386/isa/if_ed.c b/sys/i386/isa/if_ed.c deleted file mode 100644 index 91eb929..0000000 --- a/sys/i386/isa/if_ed.c +++ /dev/null @@ -1,2375 +0,0 @@ -/* - * Device driver for National Semiconductor DS8390/WD83C690 based ethernet - * adapters. By David Greenman, 29-April-1993 - * - * Copyright (C) 1993, David Greenman. This software may be used, modified, - * copied, distributed, and sold, in both source and binary form provided - * that the above copyright and these terms are retained. Under no - * circumstances is the author responsible for the proper functioning - * of this software, nor does the author assume any responsibility - * for damages incurred with its use. - * - * Currently supports the Western Digital/SMC 8003 and 8013 series, - * the 3Com 3c503, the NE1000 and NE2000, and a variety of similar - * clones. - * - * Thanks to Charles Hannum for proving to me with example code that the - * NE1000/2000 support could be added with minimal impact. Without - * this, I wouldn't have proceeded in this direction. - * - */ - -/* - * $Id: if_ed.c,v 2.11 1993/10/23 04:21:03 davidg Exp davidg $ - */ - -/* - * Modification history - * - * Revision 2.11 1993/10/23 04:21:03 davidg - * Novell probe changed to be invasive because of too many complaints - * about some clone boards not being reset properly and thus not - * found on a warmboot. Yuck. - * - * Revision 2.10 1993/10/23 04:07:12 davidg - * increment output errors if the device times out (done via watchdog) - * - * Revision 2.9 1993/10/23 04:01:45 davidg - * increment input error counter if a packet with a bad length is - * detected. - * - * Revision 2.8 1993/10/15 10:59:56 davidg - * increase maximum time to wait for transmit DMA to complete to 120us. - * call ed_reset() if the time limit is reached instead of trying - * to abort the remote DMA. - * - * Revision 2.7 1993/10/15 10:49:10 davidg - * minor change to way the mbuf pointer temp variable is assigned in - * ed_start (slightly improves code readability) - * - * Revision 2.6 93/10/02 01:12:20 davidg - * use ETHER_ADDR_LEN in NE probe rather than '6'. - * - * Revision 2.5 93/09/30 17:44:14 davidg - * patch from vak@zebub.msk.su (Serge V.Vakulenko) to work around - * a hardware bug in cheap WD clone boards where the PROM checksum - * byte is always zero - * - * Revision 2.4 93/09/29 21:24:30 davidg - * Added software NIC reset in NE probe to work around a problem - * with some NE boards where the 8390 doesn't reset properly on - * power-up. Remove initialization of IMR/ISR in the NE probe - * because this is inherent in the reset. - * - * Revision 2.3 93/09/29 15:10:16 davidg - * credit Charles Hannum - * - * Revision 2.2 93/09/29 13:23:25 davidg - * added no multi-buffer override for 3c503 - * - * Revision 2.1 93/09/29 12:32:12 davidg - * changed multi-buffer count for 16bit 3c503's from 5 to 2 after - * noticing that the transmitter becomes idle because of so many - * packets to load. - * - * Revision 2.0 93/09/29 00:00:19 davidg - * many changes, rewrites, additions, etc. Now supports the - * NE1000, NE2000, WD8003, WD8013, 3C503, 16bit 3C503, and - * a variety of similar clones. 16bit 3c503 now does multi - * transmit buffers. Nearly every part of the driver has - * changed in some way since rev 1.30. - * - * Revision 1.1 93/06/14 22:21:24 davidg - * Beta release of device driver for SMC/WD80x3 and 3C503 ethernet boards. - * - */ - -#include "ed.h" -#if NED > 0 -/* bpfilter included here in case it is needed in future net includes */ -#include "bpfilter.h" - -#include "param.h" -#include "systm.h" -#include "errno.h" -#include "ioctl.h" -#include "mbuf.h" -#include "socket.h" -#include "syslog.h" - -#include "net/if.h" -#include "net/if_dl.h" -#include "net/if_types.h" -#include "net/netisr.h" - -#ifdef INET -#include "netinet/in.h" -#include "netinet/in_systm.h" -#include "netinet/in_var.h" -#include "netinet/ip.h" -#include "netinet/if_ether.h" -#endif - -#ifdef NS -#include "netns/ns.h" -#include "netns/ns_if.h" -#endif - -#if NBPFILTER > 0 -#include "net/bpf.h" -#include "net/bpfdesc.h" -#endif - -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/icu.h" -#include "i386/isa/if_edreg.h" - -#include "i386/include/pio.h" - -/* For backwards compatibility */ -#ifndef IFF_ALTPHYS -#define IFF_ALTPHYS IFF_LLC0 -#endif - -/* - * ed_softc: per line info and status - */ -struct ed_softc { - struct arpcom arpcom; /* ethernet common */ - - char *type_str; /* pointer to type string */ - u_char vendor; /* interface vendor */ - u_char type; /* interface type code */ - - u_short asic_addr; /* ASIC I/O bus address */ - u_short nic_addr; /* NIC (DS8390) I/O bus address */ - -/* - * The following 'proto' variable is part of a work-around for 8013EBT asics - * being write-only. It's sort of a prototype/shadow of the real thing. - */ - u_char wd_laar_proto; - u_char isa16bit; /* width of access to card 0=8 or 1=16 */ - - caddr_t bpf; /* BPF "magic cookie" */ - caddr_t mem_start; /* NIC memory start address */ - caddr_t mem_end; /* NIC memory end address */ - u_long mem_size; /* total NIC memory size */ - caddr_t mem_ring; /* start of RX ring-buffer (in NIC mem) */ - - u_char mem_shared; /* NIC memory is shared with host */ - u_char xmit_busy; /* transmitter is busy */ - u_char txb_cnt; /* number of transmit buffers */ - u_char txb_inuse; /* number of TX buffers currently in-use*/ - - u_char txb_new; /* pointer to where new buffer will be added */ - u_char txb_next_tx; /* pointer to next buffer ready to xmit */ - u_short txb_len[8]; /* buffered xmit buffer lengths */ - u_char tx_page_start; /* first page of TX buffer area */ - u_char rec_page_start; /* first page of RX ring-buffer */ - u_char rec_page_stop; /* last page of RX ring-buffer */ - u_char next_packet; /* pointer to next unread RX packet */ -} ed_softc[NED]; - -int ed_attach(), ed_init(), edintr(), ed_ioctl(), ed_probe(), - ed_start(), ed_reset(), ed_watchdog(); - -static void ed_stop(); - -static inline void ed_rint(); -static inline void ed_xmit(); -static inline char *ed_ring_copy(); - -void ed_pio_readmem(), ed_pio_writemem(); -u_short ed_pio_write_mbufs(); - -extern int ether_output(); - -struct trailer_header { - u_short ether_type; - u_short ether_residual; -}; - -struct isa_driver eddriver = { - ed_probe, - ed_attach, - "ed" -}; -/* - * Interrupt conversion table for WD/SMC ASIC - * (IRQ* are defined in icu.h) - */ -static unsigned short ed_intr_mask[] = { - IRQ9, - IRQ3, - IRQ5, - IRQ7, - IRQ10, - IRQ11, - IRQ15, - IRQ4 -}; - -#define ETHER_MIN_LEN 64 -#define ETHER_MAX_LEN 1518 -#define ETHER_ADDR_LEN 6 -#define ETHER_HDR_SIZE 14 - -/* - * Determine if the device is present - * - * on entry: - * a pointer to an isa_device struct - * on exit: - * NULL if device not found - * or # of i/o addresses used (if found) - */ -int -ed_probe(isa_dev) - struct isa_device *isa_dev; -{ - struct ed_softc *sc = &ed_softc[isa_dev->id_unit]; - int nports; - - if (nports = ed_probe_WD80x3(isa_dev)) - return (nports); - - if (nports = ed_probe_3Com(isa_dev)) - return (nports); - - if (nports = ed_probe_Novell(isa_dev)) - return (nports); -} - -/* - * Generic probe routine for testing for the existance of a DS8390. - * Must be called after the NIC has just been reset. This routine - * works by looking at certain register values that are gauranteed - * to be initialized a certain way after power-up or reset. Seems - * not to currently work on the 83C690. - * - * Specifically: - * - * Register reset bits set bits - * Command Register (CR) TXP, STA RD2, STP - * Interrupt Status (ISR) RST - * Interrupt Mask (IMR) All bits - * Data Control (DCR) LAS - * Transmit Config. (TCR) LB1, LB0 - * - * We only look at the CR and ISR registers, however, because looking at - * the others would require changing register pages (which would be - * intrusive if this isn't an 8390). - * - * Return 1 if 8390 was found, 0 if not. - */ - -int -ed_probe_generic8390(sc) - struct ed_softc *sc; -{ - if ((inb(sc->nic_addr + ED_P0_CR) & - (ED_CR_RD2|ED_CR_TXP|ED_CR_STA|ED_CR_STP)) != - (ED_CR_RD2|ED_CR_STP)) - return (0); - if ((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RST) != ED_ISR_RST) - return (0); - - return(1); -} - -/* - * Probe and vendor-specific initialization routine for SMC/WD80x3 boards - */ -int -ed_probe_WD80x3(isa_dev) - struct isa_device *isa_dev; -{ - struct ed_softc *sc = &ed_softc[isa_dev->id_unit]; - int i; - u_int memsize; - u_char iptr, isa16bit, sum; - - sc->asic_addr = isa_dev->id_iobase; - sc->nic_addr = sc->asic_addr + ED_WD_NIC_OFFSET; - - /* - * Attempt to do a checksum over the station address PROM. - * If it fails, it's probably not a SMC/WD board. There - * is a problem with this, though: some clone WD boards - * don't pass the checksum test. Danpex boards for one. - */ - for (sum = 0, i = 0; i < 8; ++i) - sum += inb(sc->asic_addr + ED_WD_PROM + i); - - if (sum != ED_WD_ROM_CHECKSUM_TOTAL) { - /* - * Checksum is invalid. This often happens with cheap - * WD8003E clones. In this case, the checksum byte - * (the eighth byte) seems to always be zero. - */ - if (inb(sc->asic_addr + ED_WD_CARD_ID) != ED_TYPE_WD8003E || - inb(sc->asic_addr + ED_WD_PROM + 7) != 0) - return(0); - } - - /* reset card to force it into a known state. */ - outb(sc->asic_addr + ED_WD_MSR, ED_WD_MSR_RST); - DELAY(100); - outb(sc->asic_addr + ED_WD_MSR, inb(sc->asic_addr + ED_WD_MSR) & ~ED_WD_MSR_RST); - /* wait in the case this card is reading it's EEROM */ - DELAY(5000); - - sc->vendor = ED_VENDOR_WD_SMC; - sc->type = inb(sc->asic_addr + ED_WD_CARD_ID); - - /* - * Set initial values for width/size. - */ - switch (sc->type) { - case ED_TYPE_WD8003S: - sc->type_str = "WD8003S"; - memsize = 8192; - isa16bit = 0; - break; - case ED_TYPE_WD8003E: - sc->type_str = "WD8003E"; - memsize = 8192; - isa16bit = 0; - break; - case ED_TYPE_WD8013EBT: - sc->type_str = "WD8013EBT"; - memsize = 16384; - isa16bit = 1; - break; - case ED_TYPE_WD8013EP: /* also WD8003EP */ - if (inb(sc->asic_addr + ED_WD_ICR) - & ED_WD_ICR_16BIT) { - isa16bit = 1; - memsize = 16384; - sc->type_str = "WD8013EP"; - } else { - isa16bit = 0; - memsize = 8192; - sc->type_str = "WD8003EP"; - } - break; - case ED_TYPE_WD8013WC: - sc->type_str = "WD8013WC"; - memsize = 16384; - isa16bit = 1; - break; - case ED_TYPE_WD8013EBP: - sc->type_str = "WD8013EBP"; - memsize = 16384; - isa16bit = 1; - break; - case ED_TYPE_WD8013EPC: - sc->type_str = "WD8013EPC"; - memsize = 16384; - isa16bit = 1; - break; - default: - sc->type_str = ""; - memsize = 8192; - isa16bit = 0; - break; - } - /* - * Make some adjustments to initial values depending on what is - * found in the ICR. - */ - if (isa16bit && (sc->type != ED_TYPE_WD8013EBT) - && ((inb(sc->asic_addr + ED_WD_ICR) & ED_WD_ICR_16BIT) == 0)) { - isa16bit = 0; - memsize = 8192; - } - -#if ED_DEBUG - printf("type=%s isa16bit=%d memsize=%d id_msize=%d\n", - sc->type_str,isa16bit,memsize,isa_dev->id_msize); - for (i=0; i<8; i++) - printf("%x -> %x\n", i, inb(sc->asic_addr + i)); -#endif - /* - * Allow the user to override the autoconfiguration - */ - if (isa_dev->id_msize) - memsize = isa_dev->id_msize; - /* - * (note that if the user specifies both of the following flags - * that '8bit' mode intentionally has precedence) - */ - if (isa_dev->id_flags & ED_FLAGS_FORCE_16BIT_MODE) - isa16bit = 1; - if (isa_dev->id_flags & ED_FLAGS_FORCE_8BIT_MODE) - isa16bit = 0; - - /* - * Check 83C584 interrupt configuration register if this board has one - * XXX - we could also check the IO address register. But why - * bother...if we get past this, it *has* to be correct. - */ - if (sc->type & ED_WD_SOFTCONFIG) { - /* - * Assemble together the encoded interrupt number. - */ - iptr = (inb(isa_dev->id_iobase + ED_WD_ICR) & ED_WD_ICR_IR2) | - ((inb(isa_dev->id_iobase + ED_WD_IRR) & - (ED_WD_IRR_IR0 | ED_WD_IRR_IR1)) >> 5); - /* - * Translate it using translation table, and check for correctness. - */ - if (ed_intr_mask[iptr] != isa_dev->id_irq) { - printf("ed%d: kernel configured irq %d doesn't match board configured irq %d\n", - isa_dev->id_unit, ffs(isa_dev->id_irq) - 1, ffs(ed_intr_mask[iptr]) - 1); - return(0); - } - /* - * Enable the interrupt. - */ - outb(isa_dev->id_iobase + ED_WD_IRR, - inb(isa_dev->id_iobase + ED_WD_IRR) | ED_WD_IRR_IEN); - } - - sc->isa16bit = isa16bit; - -#ifdef notyet /* XXX - I'm not sure if PIO mode is even possible on WD/SMC boards */ - /* - * The following allows the WD/SMC boards to be used in Programmed I/O - * mode - without mapping the NIC memory shared. ...Not the prefered - * way, but it might be the only way. - */ - if (isa_dev->id_flags & ED_FLAGS_FORCE_PIO) { - sc->mem_shared = 0; - isa_dev->id_maddr = 0; - } else { - sc->mem_shared = 1; - } -#else - sc->mem_shared = 1; -#endif - isa_dev->id_msize = memsize; - - sc->mem_start = (caddr_t)isa_dev->id_maddr; - - /* - * allocate one xmit buffer if < 16k, two buffers otherwise - */ - if ((memsize < 16384) || (isa_dev->id_flags & ED_FLAGS_NO_MULTI_BUFFERING)) { - sc->mem_ring = sc->mem_start + (ED_PAGE_SIZE * ED_TXBUF_SIZE); - sc->txb_cnt = 1; - sc->rec_page_start = ED_TXBUF_SIZE; - } else { - sc->mem_ring = sc->mem_start + (ED_PAGE_SIZE * ED_TXBUF_SIZE * 2); - sc->txb_cnt = 2; - sc->rec_page_start = ED_TXBUF_SIZE * 2; - } - sc->mem_size = memsize; - sc->mem_end = sc->mem_start + memsize; - sc->rec_page_stop = memsize / ED_PAGE_SIZE; - sc->tx_page_start = ED_WD_PAGE_OFFSET; - - /* - * Get station address from on-board ROM - */ - for (i = 0; i < ETHER_ADDR_LEN; ++i) - sc->arpcom.ac_enaddr[i] = inb(sc->asic_addr + ED_WD_PROM + i); - - if (sc->mem_shared) { - /* - * Set address and enable interface shared memory. - */ - outb(sc->asic_addr + ED_WD_MSR, ((kvtop(sc->mem_start) >> 13) & - ED_WD_MSR_ADDR) | ED_WD_MSR_MENB); - - /* - * Set upper address bits and 8/16 bit access to shared memory - */ - if (isa16bit) { - outb(sc->asic_addr + ED_WD_LAAR, (sc->wd_laar_proto = - ED_WD_LAAR_L16EN | ED_WD_LAAR_M16EN | - ((kvtop(sc->mem_start) >> 19) & ED_WD_LAAR_ADDRHI))); - } else { - if ((sc->type & ED_WD_SOFTCONFIG) || (sc->type == ED_TYPE_WD8013EBT)) { - outb(sc->asic_addr + ED_WD_LAAR, (sc->wd_laar_proto = - ((kvtop(sc->mem_start) >> 19) & ED_WD_LAAR_ADDRHI))); - } - } - - /* - * Now zero memory and verify that it is clear - */ - bzero(sc->mem_start, memsize); - - for (i = 0; i < memsize; ++i) - if (sc->mem_start[i]) { - printf("ed%d: failed to clear shared memory at %x - check configuration\n", - isa_dev->id_unit, kvtop(sc->mem_start + i)); - - /* - * Disable 16 bit access to shared memory - */ - if (isa16bit) - outb(sc->asic_addr + ED_WD_LAAR, (sc->wd_laar_proto &= - ~ED_WD_LAAR_M16EN)); - - return(0); - } - - /* - * Disable 16bit access to shared memory - we leave it disabled so - * that 1) machines reboot properly when the board is set - * 16 bit mode and there are conflicting 8bit devices/ROMS - * in the same 128k address space as this boards shared - * memory. and 2) so that other 8 bit devices with shared - * memory can be used in this 128k region, too. - */ - if (isa16bit) - outb(sc->asic_addr + ED_WD_LAAR, (sc->wd_laar_proto &= - ~ED_WD_LAAR_M16EN)); - - } - - return (ED_WD_IO_PORTS); -} - -/* - * Probe and vendor-specific initialization routine for 3Com 3c503 boards - */ -int -ed_probe_3Com(isa_dev) - struct isa_device *isa_dev; -{ - struct ed_softc *sc = &ed_softc[isa_dev->id_unit]; - int i; - u_int memsize; - u_char isa16bit, sum; - - sc->asic_addr = isa_dev->id_iobase + ED_3COM_ASIC_OFFSET; - sc->nic_addr = isa_dev->id_iobase + ED_3COM_NIC_OFFSET; - - /* - * Verify that the kernel configured I/O address matches the board - * configured address - */ - switch (inb(sc->asic_addr + ED_3COM_BCFR)) { - case ED_3COM_BCFR_300: - if (isa_dev->id_iobase != 0x300) - return(0); - break; - case ED_3COM_BCFR_310: - if (isa_dev->id_iobase != 0x310) - return(0); - break; - case ED_3COM_BCFR_330: - if (isa_dev->id_iobase != 0x330) - return(0); - break; - case ED_3COM_BCFR_350: - if (isa_dev->id_iobase != 0x350) - return(0); - break; - case ED_3COM_BCFR_250: - if (isa_dev->id_iobase != 0x250) - return(0); - break; - case ED_3COM_BCFR_280: - if (isa_dev->id_iobase != 0x280) - return(0); - break; - case ED_3COM_BCFR_2A0: - if (isa_dev->id_iobase != 0x2a0) - return(0); - break; - case ED_3COM_BCFR_2E0: - if (isa_dev->id_iobase != 0x2e0) - return(0); - break; - default: - return(0); - } - - /* - * Verify that the kernel shared memory address matches the - * board configured address. - */ - switch (inb(sc->asic_addr + ED_3COM_PCFR)) { - case ED_3COM_PCFR_DC000: - if (kvtop(isa_dev->id_maddr) != 0xdc000) - return(0); - break; - case ED_3COM_PCFR_D8000: - if (kvtop(isa_dev->id_maddr) != 0xd8000) - return(0); - break; - case ED_3COM_PCFR_CC000: - if (kvtop(isa_dev->id_maddr) != 0xcc000) - return(0); - break; - case ED_3COM_PCFR_C8000: - if (kvtop(isa_dev->id_maddr) != 0xc8000) - return(0); - break; - default: - return(0); - } - - - /* - * Reset NIC and ASIC. Enable on-board transceiver throughout reset - * sequence because it'll lock up if the cable isn't connected - * if we don't. - */ - outb(sc->asic_addr + ED_3COM_CR, ED_3COM_CR_RST | ED_3COM_CR_XSEL); - - /* - * Wait for a while, then un-reset it - */ - DELAY(50); - /* - * The 3Com ASIC defaults to rather strange settings for the CR after - * a reset - it's important to set it again after the following - * outb (this is done when we map the PROM below). - */ - outb(sc->asic_addr + ED_3COM_CR, ED_3COM_CR_XSEL); - - /* - * Wait a bit for the NIC to recover from the reset - */ - DELAY(5000); - - sc->vendor = ED_VENDOR_3COM; - sc->type_str = "3c503"; - - sc->mem_shared = 1; - - /* - * Hmmm...a 16bit 3Com board has 16k of memory, but only an 8k - * window to it. - */ - memsize = 8192; - - /* - * Get station address from on-board ROM - */ - /* - * First, map ethernet address PROM over the top of where the NIC - * registers normally appear. - */ - outb(sc->asic_addr + ED_3COM_CR, ED_3COM_CR_EALO | ED_3COM_CR_XSEL); - - for (i = 0; i < ETHER_ADDR_LEN; ++i) - sc->arpcom.ac_enaddr[i] = inb(sc->nic_addr + i); - - /* - * Unmap PROM - select NIC registers. The proper setting of the - * tranceiver is set in ed_init so that the attach code - * is given a chance to set the default based on a compile-time - * config option - */ - outb(sc->asic_addr + ED_3COM_CR, ED_3COM_CR_XSEL); - - /* - * Determine if this is an 8bit or 16bit board - */ - - /* - * select page 0 registers - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STP); - - /* - * Attempt to clear WTS bit. If it doesn't clear, then this is a - * 16bit board. - */ - outb(sc->nic_addr + ED_P0_DCR, 0); - - /* - * select page 2 registers - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_PAGE_2|ED_CR_RD2|ED_CR_STP); - - /* - * The 3c503 forces the WTS bit to a one if this is a 16bit board - */ - if (inb(sc->nic_addr + ED_P2_DCR) & ED_DCR_WTS) - isa16bit = 1; - else - isa16bit = 0; - - /* - * select page 0 registers - */ - outb(sc->nic_addr + ED_P2_CR, ED_CR_RD2|ED_CR_STP); - - sc->mem_start = (caddr_t)isa_dev->id_maddr; - sc->mem_size = memsize; - sc->mem_end = sc->mem_start + memsize; - - /* - * We have an entire 8k window to put the transmit buffers on the - * 16bit boards. But since the 16bit 3c503's shared memory - * is only fast enough to overlap the loading of one full-size - * packet, trying to load more than 2 buffers can actually - * leave the transmitter idle during the load. So 2 seems - * the best value. (Although a mix of variable-sized packets - * might change this assumption. Nonetheless, we optimize for - * linear transfers of same-size packets.) - */ - if (isa16bit) { - if (isa_dev->id_flags & ED_FLAGS_NO_MULTI_BUFFERING) - sc->txb_cnt = 1; - else - sc->txb_cnt = 2; - - sc->tx_page_start = ED_3COM_TX_PAGE_OFFSET_16BIT; - sc->rec_page_start = ED_3COM_RX_PAGE_OFFSET_16BIT; - sc->rec_page_stop = memsize / ED_PAGE_SIZE + - ED_3COM_RX_PAGE_OFFSET_16BIT; - sc->mem_ring = sc->mem_start; - } else { - sc->txb_cnt = 1; - sc->tx_page_start = ED_3COM_TX_PAGE_OFFSET_8BIT; - sc->rec_page_start = ED_TXBUF_SIZE + ED_3COM_TX_PAGE_OFFSET_8BIT; - sc->rec_page_stop = memsize / ED_PAGE_SIZE + - ED_3COM_TX_PAGE_OFFSET_8BIT; - sc->mem_ring = sc->mem_start + (ED_PAGE_SIZE * ED_TXBUF_SIZE); - } - - sc->isa16bit = isa16bit; - - /* - * Initialize GA page start/stop registers. Probably only needed - * if doing DMA, but what the hell. - */ - outb(sc->asic_addr + ED_3COM_PSTR, sc->rec_page_start); - outb(sc->asic_addr + ED_3COM_PSPR, sc->rec_page_stop); - - /* - * Set IRQ. 3c503 only allows a choice of irq 2-5. - */ - switch (isa_dev->id_irq) { - case IRQ2: - outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ2); - break; - case IRQ3: - outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ3); - break; - case IRQ4: - outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ4); - break; - case IRQ5: - outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ5); - break; - default: - printf("ed%d: Invalid irq configuration (%d) must be 2-5 for 3c503\n", - isa_dev->id_unit, ffs(isa_dev->id_irq) - 1); - return(0); - } - - /* - * Initialize GA configuration register. Set bank and enable shared mem. - */ - outb(sc->asic_addr + ED_3COM_GACFR, ED_3COM_GACFR_RSEL | - ED_3COM_GACFR_MBS0); - - /* - * Initialize "Vector Pointer" registers. These gawd-awful things - * are compared to 20 bits of the address on ISA, and if they - * match, the shared memory is disabled. We set them to - * 0xffff0...allegedly the reset vector. - */ - outb(sc->asic_addr + ED_3COM_VPTR2, 0xff); - outb(sc->asic_addr + ED_3COM_VPTR1, 0xff); - outb(sc->asic_addr + ED_3COM_VPTR0, 0x00); - - /* - * Zero memory and verify that it is clear - */ - bzero(sc->mem_start, memsize); - - for (i = 0; i < memsize; ++i) - if (sc->mem_start[i]) { - printf("ed%d: failed to clear shared memory at %x - check configuration\n", - isa_dev->id_unit, kvtop(sc->mem_start + i)); - return(0); - } - - isa_dev->id_msize = memsize; - return(ED_3COM_IO_PORTS); -} - -/* - * Probe and vendor-specific initialization routine for NE1000/2000 boards - */ -int -ed_probe_Novell(isa_dev) - struct isa_device *isa_dev; -{ - struct ed_softc *sc = &ed_softc[isa_dev->id_unit]; - u_int memsize, n; - u_char romdata[16], isa16bit = 0, tmp; - static char test_pattern[32] = "THIS is A memory TEST pattern"; - char test_buffer[32]; - - sc->asic_addr = isa_dev->id_iobase + ED_NOVELL_ASIC_OFFSET; - sc->nic_addr = isa_dev->id_iobase + ED_NOVELL_NIC_OFFSET; - - /* XXX - do Novell-specific probe here */ - - /* Reset the board */ - tmp = inb(sc->asic_addr + ED_NOVELL_RESET); - -#if 0 - /* - * This total and completely screwy thing is to work around braindamage - * in some NE compatible boards. Why it works, I have *no* idea. - * It appears that the boards watch the ISA bus for an outb, and - * will lock up the ISA bus if they see an inb first. Weird. - */ - outb(0x84, 0); -#endif - - /* - * I don't know if this is necessary; probably cruft leftover from - * Clarkson packet driver code. Doesn't do a thing on the boards - * I've tested. -DG [note that a outb(0x84, 0) seems to work - * here, and is non-invasive...but some boards don't seem to reset - * and I don't have complete documentation on what the 'right' - * thing to do is...so we do the invasive thing for now. Yuck.] - */ - outb(sc->asic_addr + ED_NOVELL_RESET, tmp); - DELAY(5000); - - /* - * This is needed because some NE clones apparently don't reset the - * NIC properly (or the NIC chip doesn't reset fully on power-up) - * XXX - this makes the probe invasive! ...Done against my better - * judgement. -DLG - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STP); - - DELAY(5000); - - /* Make sure that we really have an 8390 based board */ - if (!ed_probe_generic8390(sc)) - return(0); - - sc->vendor = ED_VENDOR_NOVELL; - sc->mem_shared = 0; - isa_dev->id_maddr = 0; - - /* - * Test the ability to read and write to the NIC memory. This has - * the side affect of determining if this is an NE1000 or an NE2000. - */ - - /* - * This prevents packets from being stored in the NIC memory when - * the readmem routine turns on the start bit in the CR. - */ - outb(sc->nic_addr + ED_P0_RCR, ED_RCR_MON); - - /* Temporarily initialize DCR for byte operations */ - outb(sc->nic_addr + ED_P0_DCR, ED_DCR_FT1|ED_DCR_LS); - - outb(sc->nic_addr + ED_P0_PSTART, 8192 / ED_PAGE_SIZE); - outb(sc->nic_addr + ED_P0_PSTOP, 16384 / ED_PAGE_SIZE); - - sc->isa16bit = 0; - - /* - * Write a test pattern in byte mode. If this fails, then there - * probably isn't any memory at 8k - which likely means - * that the board is an NE2000. - */ - ed_pio_writemem(sc, test_pattern, 8192, sizeof(test_pattern)); - ed_pio_readmem(sc, 8192, test_buffer, sizeof(test_pattern)); - - if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) { - /* not an NE1000 - try NE2000 */ - - outb(sc->nic_addr + ED_P0_DCR, - ED_DCR_WTS|ED_DCR_FT1|ED_DCR_LS); - outb(sc->nic_addr + ED_P0_PSTART, 16384 / ED_PAGE_SIZE); - outb(sc->nic_addr + ED_P0_PSTOP, 32768 / ED_PAGE_SIZE); - - sc->isa16bit = 1; - /* - * Write a test pattern in word mode. If this also fails, then - * we don't know what this board is. - */ - ed_pio_writemem(sc, test_pattern, 16384, sizeof(test_pattern)); - ed_pio_readmem(sc, 16384, test_buffer, sizeof(test_pattern)); - - if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) - return(0); /* not an NE2000 either */ - - sc->type = ED_TYPE_NE2000; - sc->type_str = "NE2000"; - } else { - sc->type = ED_TYPE_NE1000; - sc->type_str = "NE1000"; - } - - /* 8k of memory plus an additional 8k if 16bit */ - memsize = 8192 + sc->isa16bit * 8192; - -#if 0 /* probably not useful - NE boards only come two ways */ - /* allow kernel config file overrides */ - if (isa_dev->id_msize) - memsize = isa_dev->id_msize; -#endif - - sc->mem_size = memsize; - - /* NIC memory doesn't start at zero on an NE board */ - /* The start address is tied to the bus width */ - sc->mem_start = (char *) 8192 + sc->isa16bit * 8192; - sc->mem_end = sc->mem_start + memsize; - sc->tx_page_start = memsize / ED_PAGE_SIZE; - - /* - * Use one xmit buffer if < 16k, two buffers otherwise (if not told - * otherwise). - */ - if ((memsize < 16384) || (isa_dev->id_flags & ED_FLAGS_NO_MULTI_BUFFERING)) - sc->txb_cnt = 1; - else - sc->txb_cnt = 2; - - sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE; - sc->rec_page_stop = sc->tx_page_start + memsize / ED_PAGE_SIZE; - - sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE; - - ed_pio_readmem(sc, 0, romdata, 16); - for (n = 0; n < ETHER_ADDR_LEN; n++) - sc->arpcom.ac_enaddr[n] = romdata[n*(sc->isa16bit+1)]; - - /* clear any pending interrupts that might have occurred above */ - outb(sc->nic_addr + ED_P0_ISR, 0xff); - - return(ED_NOVELL_IO_PORTS); -} - -/* - * Install interface into kernel networking data structures - */ -int -ed_attach(isa_dev) - struct isa_device *isa_dev; -{ - struct ed_softc *sc = &ed_softc[isa_dev->id_unit]; - struct ifnet *ifp = &sc->arpcom.ac_if; - struct ifaddr *ifa; - struct sockaddr_dl *sdl; - - /* - * Set interface to stopped condition (reset) - */ - ed_stop(isa_dev->id_unit); - - /* - * Initialize ifnet structure - */ - ifp->if_unit = isa_dev->id_unit; - ifp->if_name = "ed" ; - ifp->if_mtu = ETHERMTU; - ifp->if_init = ed_init; - ifp->if_output = ether_output; - ifp->if_start = ed_start; - ifp->if_ioctl = ed_ioctl; - ifp->if_reset = ed_reset; - ifp->if_watchdog = ed_watchdog; - - /* - * Set default state for ALTPHYS flag (used to disable the tranceiver - * for AUI operation), based on compile-time config option. - */ - if (isa_dev->id_flags & ED_FLAGS_DISABLE_TRANCEIVER) - ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS - | IFF_ALTPHYS); - else - ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS); - - /* - * Attach the interface - */ - if_attach(ifp); - - /* - * Search down the ifa address list looking for the AF_LINK type entry - */ - ifa = ifp->if_addrlist; - while ((ifa != 0) && (ifa->ifa_addr != 0) && - (ifa->ifa_addr->sa_family != AF_LINK)) - ifa = ifa->ifa_next; - /* - * If we find an AF_LINK type entry we fill in the hardware address. - * This is useful for netstat(1) to keep track of which interface - * is which. - */ - if ((ifa != 0) && (ifa->ifa_addr != 0)) { - /* - * Fill in the link-level address for this interface - */ - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = ETHER_ADDR_LEN; - sdl->sdl_slen = 0; - bcopy(sc->arpcom.ac_enaddr, LLADDR(sdl), ETHER_ADDR_LEN); - } - - /* - * Print additional info when attached - */ - printf("ed%d: address %s, ", isa_dev->id_unit, - ether_sprintf(sc->arpcom.ac_enaddr)); - - if (sc->type_str && (*sc->type_str != 0)) - printf("type %s ", sc->type_str); - else - printf("type unknown (0x%x) ", sc->type); - - printf("%s ",sc->isa16bit ? "(16 bit)" : "(8 bit)"); - - printf("%s\n", ((sc->vendor == ED_VENDOR_3COM) && - (ifp->if_flags & IFF_ALTPHYS)) ? "tranceiver disabled" : ""); - - /* - * If BPF is in the kernel, call the attach for it - */ -#if NBPFILTER > 0 - bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); -#endif - -} - -/* - * Reset interface. - */ -int -ed_reset(unit) - int unit; -{ - int s; - - s = splnet(); - - /* - * Stop interface and re-initialize. - */ - ed_stop(unit); - ed_init(unit); - - (void) splx(s); -} - -/* - * Take interface offline. - */ -void -ed_stop(unit) - int unit; -{ - struct ed_softc *sc = &ed_softc[unit]; - int n = 5000; - - /* - * Stop everything on the interface, and select page 0 registers. - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STP); - - /* - * Wait for interface to enter stopped state, but limit # of checks - * to 'n' (about 5ms). It shouldn't even take 5us on modern - * DS8390's, but just in case it's an old one. - */ - while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RST) == 0) && --n); - -} - -/* - * Device timeout/watchdog routine. Entered if the device neglects to - * generate an interrupt after a transmit has been started on it. - */ -int -ed_watchdog(unit) - int unit; -{ - struct ed_softc *sc = &ed_softc[unit]; - - log(LOG_ERR, "ed%d: device timeout\n", unit); - ++sc->arpcom.ac_if.if_oerrors; - - ed_reset(unit); -} - -/* - * Initialize device. - */ -ed_init(unit) - int unit; -{ - struct ed_softc *sc = &ed_softc[unit]; - struct ifnet *ifp = &sc->arpcom.ac_if; - int i, s; - u_char command; - - - /* address not known */ - if (ifp->if_addrlist == (struct ifaddr *)0) return; - - /* - * Initialize the NIC in the exact order outlined in the NS manual. - * This init procedure is "mandatory"...don't change what or when - * things happen. - */ - s = splnet(); - - /* reset transmitter flags */ - sc->xmit_busy = 0; - sc->arpcom.ac_if.if_timer = 0; - - sc->txb_inuse = 0; - sc->txb_new = 0; - sc->txb_next_tx = 0; - - /* This variable is used below - don't move this assignment */ - sc->next_packet = sc->rec_page_start + 1; - - /* - * Set interface for page 0, Remote DMA complete, Stopped - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STP); - - if (sc->isa16bit) { - /* - * Set FIFO threshold to 8, No auto-init Remote DMA, - * byte order=80x86, word-wide DMA xfers, - */ - outb(sc->nic_addr + ED_P0_DCR, ED_DCR_FT1|ED_DCR_WTS|ED_DCR_LS); - } else { - /* - * Same as above, but byte-wide DMA xfers - */ - outb(sc->nic_addr + ED_P0_DCR, ED_DCR_FT1|ED_DCR_LS); - } - - /* - * Clear Remote Byte Count Registers - */ - outb(sc->nic_addr + ED_P0_RBCR0, 0); - outb(sc->nic_addr + ED_P0_RBCR1, 0); - - /* - * Enable reception of broadcast packets - */ - outb(sc->nic_addr + ED_P0_RCR, ED_RCR_AB); - - /* - * Place NIC in internal loopback mode - */ - outb(sc->nic_addr + ED_P0_TCR, ED_TCR_LB0); - - /* - * Initialize transmit/receive (ring-buffer) Page Start - */ - outb(sc->nic_addr + ED_P0_TPSR, sc->tx_page_start); - outb(sc->nic_addr + ED_P0_PSTART, sc->rec_page_start); - - /* - * Initialize Receiver (ring-buffer) Page Stop and Boundry - */ - outb(sc->nic_addr + ED_P0_PSTOP, sc->rec_page_stop); - outb(sc->nic_addr + ED_P0_BNRY, sc->rec_page_start); - - /* - * Clear all interrupts. A '1' in each bit position clears the - * corresponding flag. - */ - outb(sc->nic_addr + ED_P0_ISR, 0xff); - - /* - * Enable the following interrupts: receive/transmit complete, - * receive/transmit error, and Receiver OverWrite. - * - * Counter overflow and Remote DMA complete are *not* enabled. - */ - outb(sc->nic_addr + ED_P0_IMR, - ED_IMR_PRXE|ED_IMR_PTXE|ED_IMR_RXEE|ED_IMR_TXEE|ED_IMR_OVWE); - - /* - * Program Command Register for page 1 - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_PAGE_1|ED_CR_RD2|ED_CR_STP); - - /* - * Copy out our station address - */ - for (i = 0; i < ETHER_ADDR_LEN; ++i) - outb(sc->nic_addr + ED_P1_PAR0 + i, sc->arpcom.ac_enaddr[i]); - -#if NBPFILTER > 0 - /* - * Initialize multicast address hashing registers to accept - * all multicasts (only used when in promiscuous mode) - */ - for (i = 0; i < 8; ++i) - outb(sc->nic_addr + ED_P1_MAR0 + i, 0xff); -#endif - - /* - * Set Current Page pointer to next_packet (initialized above) - */ - outb(sc->nic_addr + ED_P1_CURR, sc->next_packet); - - /* - * Set Command Register for page 0, Remote DMA complete, - * and interface Start. - */ - outb(sc->nic_addr + ED_P1_CR, ED_CR_RD2|ED_CR_STA); - - /* - * Take interface out of loopback - */ - outb(sc->nic_addr + ED_P0_TCR, 0); - - /* - * If this is a 3Com board, the tranceiver must be software enabled - * (there is no settable hardware default). - */ - if (sc->vendor == ED_VENDOR_3COM) { - if (ifp->if_flags & IFF_ALTPHYS) { - outb(sc->asic_addr + ED_3COM_CR, 0); - } else { - outb(sc->asic_addr + ED_3COM_CR, ED_3COM_CR_XSEL); - } - } - - /* - * Set 'running' flag, and clear output active flag. - */ - ifp->if_flags |= IFF_RUNNING; - ifp->if_flags &= ~IFF_OACTIVE; - - /* - * ...and attempt to start output - */ - ed_start(ifp); - - (void) splx(s); -} - -/* - * This routine actually starts the transmission on the interface - */ -static inline void ed_xmit(ifp) - struct ifnet *ifp; -{ - struct ed_softc *sc = &ed_softc[ifp->if_unit]; - unsigned short len; - - len = sc->txb_len[sc->txb_next_tx]; - - /* - * Set NIC for page 0 register access - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - /* - * Set TX buffer start page - */ - outb(sc->nic_addr + ED_P0_TPSR, sc->tx_page_start + - sc->txb_next_tx * ED_TXBUF_SIZE); - - /* - * Set TX length - */ - outb(sc->nic_addr + ED_P0_TBCR0, len); - outb(sc->nic_addr + ED_P0_TBCR1, len >> 8); - - /* - * Set page 0, Remote DMA complete, Transmit Packet, and *Start* - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_TXP|ED_CR_STA); - - sc->xmit_busy = 1; - - /* - * Point to next transmit buffer slot and wrap if necessary. - */ - sc->txb_next_tx++; - if (sc->txb_next_tx == sc->txb_cnt) - sc->txb_next_tx = 0; - - /* - * Set a timer just in case we never hear from the board again - */ - ifp->if_timer = 2; -} - -/* - * Start output on interface. - * We make two assumptions here: - * 1) that the current priority is set to splnet _before_ this code - * is called *and* is returned to the appropriate priority after - * return - * 2) that the IFF_OACTIVE flag is checked before this code is called - * (i.e. that the output part of the interface is idle) - */ -int -ed_start(ifp) - struct ifnet *ifp; -{ - struct ed_softc *sc = &ed_softc[ifp->if_unit]; - struct mbuf *m0, *m; - caddr_t buffer; - int len; - -outloop: - /* - * First, see if there are buffered packets and an idle - * transmitter - should never happen at this point. - */ - if (sc->txb_inuse && (sc->xmit_busy == 0)) { - printf("ed: packets buffers, but transmitter idle\n"); - ed_xmit(ifp); - } - - /* - * See if there is room to put another packet in the buffer. - */ - if (sc->txb_inuse == sc->txb_cnt) { - /* - * No room. Indicate this to the outside world - * and exit. - */ - ifp->if_flags |= IFF_OACTIVE; - return; - } - - IF_DEQUEUE(&sc->arpcom.ac_if.if_snd, m); - if (m == 0) { - /* - * We are using the !OACTIVE flag to indicate to the outside - * world that we can accept an additional packet rather than - * that the transmitter is _actually_ active. Indeed, the - * transmitter may be active, but if we haven't filled all - * the buffers with data then we still want to accept more. - */ - ifp->if_flags &= ~IFF_OACTIVE; - return; - } - - /* - * Copy the mbuf chain into the transmit buffer - */ - - m0 = m; - - /* txb_new points to next open buffer slot */ - buffer = sc->mem_start + (sc->txb_new * ED_TXBUF_SIZE * ED_PAGE_SIZE); - - if (sc->mem_shared) { - /* - * Special case setup for 16 bit boards... - */ - if (sc->isa16bit) { - switch (sc->vendor) { - /* - * For 16bit 3Com boards (which have 16k of memory), - * we have the xmit buffers in a different page - * of memory ('page 0') - so change pages. - */ - case ED_VENDOR_3COM: - outb(sc->asic_addr + ED_3COM_GACFR, - ED_3COM_GACFR_RSEL); - break; - /* - * Enable 16bit access to shared memory on WD/SMC boards - * Don't update wd_laar_proto because we want to restore the - * previous state (because an arp reply in the input code - * may cause a call-back to ed_start) - * XXX - the call-back to 'start' is a bug, IMHO. - */ - case ED_VENDOR_WD_SMC: - outb(sc->asic_addr + ED_WD_LAAR, - (sc->wd_laar_proto | ED_WD_LAAR_M16EN)); - } - } - - for (len = 0; m != 0; m = m->m_next) { - bcopy(mtod(m, caddr_t), buffer, m->m_len); - buffer += m->m_len; - len += m->m_len; - } - - /* - * Restore previous shared memory access - */ - if (sc->isa16bit) { - switch (sc->vendor) { - case ED_VENDOR_3COM: - outb(sc->asic_addr + ED_3COM_GACFR, - ED_3COM_GACFR_RSEL | ED_3COM_GACFR_MBS0); - break; - case ED_VENDOR_WD_SMC: - outb(sc->asic_addr + ED_WD_LAAR, sc->wd_laar_proto); - break; - } - } - } else { - len = ed_pio_write_mbufs(sc, m, buffer); - } - - sc->txb_len[sc->txb_new] = MAX(len, ETHER_MIN_LEN); - - sc->txb_inuse++; - - /* - * Point to next buffer slot and wrap if necessary. - */ - sc->txb_new++; - if (sc->txb_new == sc->txb_cnt) - sc->txb_new = 0; - - if (sc->xmit_busy == 0) - ed_xmit(ifp); - /* - * If there is BPF support in the configuration, tap off here. - * The following has support for converting trailer packets - * back to normal. - * XXX - support for trailer packets in BPF should be moved into - * the bpf code proper to avoid code duplication in all of - * the drivers. - */ -#if NBPFILTER > 0 - if (sc->bpf) { - u_short etype; - int off, datasize, resid; - struct ether_header *eh; - struct trailer_header trailer_header; - char ether_packet[ETHER_MAX_LEN]; - char *ep; - - ep = ether_packet; - - /* - * We handle trailers below: - * Copy ether header first, then residual data, - * then data. Put all this in a temporary buffer - * 'ether_packet' and send off to bpf. Since the - * system has generated this packet, we assume - * that all of the offsets in the packet are - * correct; if they're not, the system will almost - * certainly crash in m_copydata. - * We make no assumptions about how the data is - * arranged in the mbuf chain (i.e. how much - * data is in each mbuf, if mbuf clusters are - * used, etc.), which is why we use m_copydata - * to get the ether header rather than assume - * that this is located in the first mbuf. - */ - /* copy ether header */ - m_copydata(m0, 0, sizeof(struct ether_header), ep); - eh = (struct ether_header *) ep; - ep += sizeof(struct ether_header); - etype = ntohs(eh->ether_type); - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - datasize = ((etype - ETHERTYPE_TRAIL) << 9); - off = datasize + sizeof(struct ether_header); - - /* copy trailer_header into a data structure */ - m_copydata(m0, off, sizeof(struct trailer_header), - &trailer_header.ether_type); - - /* copy residual data */ - m_copydata(m0, off+sizeof(struct trailer_header), - resid = ntohs(trailer_header.ether_residual) - - sizeof(struct trailer_header), ep); - ep += resid; - - /* copy data */ - m_copydata(m0, sizeof(struct ether_header), - datasize, ep); - ep += datasize; - - /* restore original ether packet type */ - eh->ether_type = trailer_header.ether_type; - - bpf_tap(sc->bpf, ether_packet, ep - ether_packet); - } else - bpf_mtap(sc->bpf, m0); - } -#endif - - m_freem(m0); - - /* - * Loop back to the top to possibly buffer more packets - */ - goto outloop; -} - -/* - * Ethernet interface receiver interrupt. - */ -static inline void -ed_rint(unit) - int unit; -{ - register struct ed_softc *sc = &ed_softc[unit]; - u_char boundry, current; - u_short len; - struct ed_ring packet_hdr; - char *packet_ptr; - - /* - * Set NIC to page 1 registers to get 'current' pointer - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_PAGE_1|ED_CR_RD2|ED_CR_STA); - - /* - * 'sc->next_packet' is the logical beginning of the ring-buffer - i.e. - * it points to where new data has been buffered. The 'CURR' - * (current) register points to the logical end of the ring-buffer - * - i.e. it points to where additional new data will be added. - * We loop here until the logical beginning equals the logical - * end (or in other words, until the ring-buffer is empty). - */ - while (sc->next_packet != inb(sc->nic_addr + ED_P1_CURR)) { - - /* get pointer to this buffer's header structure */ - packet_ptr = sc->mem_ring + - (sc->next_packet - sc->rec_page_start) * ED_PAGE_SIZE; - - /* - * The byte count includes the FCS - Frame Check Sequence (a - * 32 bit CRC). - */ - if (sc->mem_shared) - packet_hdr = *(struct ed_ring *)packet_ptr; - else - ed_pio_readmem(sc, packet_ptr, (char *) &packet_hdr, - sizeof(packet_hdr)); - len = packet_hdr.count; - if ((len >= ETHER_MIN_LEN) && (len <= ETHER_MAX_LEN)) { - /* - * Go get packet. len - 4 removes CRC from length. - */ - ed_get_packet(sc, packet_ptr + 4, len - 4); - ++sc->arpcom.ac_if.if_ipackets; - } else { - /* - * Really BAD...probably indicates that the ring pointers - * are corrupted. Also seen on early rev chips under - * high load - the byte order of the length gets switched. - */ - log(LOG_ERR, - "ed%d: NIC memory corrupt - invalid packet length %d\n", - unit, len); - ++sc->arpcom.ac_if.if_ierrors; - ed_reset(unit); - return; - } - - /* - * Update next packet pointer - */ - sc->next_packet = packet_hdr.next_packet; - - /* - * Update NIC boundry pointer - being careful to keep it - * one buffer behind. (as recommended by NS databook) - */ - boundry = sc->next_packet - 1; - if (boundry < sc->rec_page_start) - boundry = sc->rec_page_stop - 1; - - /* - * Set NIC to page 0 registers to update boundry register - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - outb(sc->nic_addr + ED_P0_BNRY, boundry); - - /* - * Set NIC to page 1 registers before looping to top (prepare to - * get 'CURR' current pointer) - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_PAGE_1|ED_CR_RD2|ED_CR_STA); - } -} - -/* - * Ethernet interface interrupt processor - */ -int -edintr(unit) - int unit; -{ - struct ed_softc *sc = &ed_softc[unit]; - u_char isr; - - /* - * Set NIC to page 0 registers - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - /* - * loop until there are no more new interrupts - */ - while (isr = inb(sc->nic_addr + ED_P0_ISR)) { - - /* - * reset all the bits that we are 'acknowledging' - * by writing a '1' to each bit position that was set - * (writing a '1' *clears* the bit) - */ - outb(sc->nic_addr + ED_P0_ISR, isr); - - /* - * Handle transmitter interrupts. Handle these first - * because the receiver will reset the board under - * some conditions. - */ - if (isr & (ED_ISR_PTX|ED_ISR_TXE)) { - u_char collisions = inb(sc->nic_addr + ED_P0_NCR); - - /* - * Check for transmit error. If a TX completed with an - * error, we end up throwing the packet away. Really - * the only error that is possible is excessive - * collisions, and in this case it is best to allow the - * automatic mechanisms of TCP to backoff the flow. Of - * course, with UDP we're screwed, but this is expected - * when a network is heavily loaded. - */ - if (isr & ED_ISR_TXE) { - - /* - * Excessive collisions (16) - */ - if ((inb(sc->nic_addr + ED_P0_TSR) & ED_TSR_ABT) - && (collisions == 0)) { - /* - * When collisions total 16, the - * P0_NCR will indicate 0, and the - * TSR_ABT is set. - */ - collisions = 16; - } - - /* - * update output errors counter - */ - ++sc->arpcom.ac_if.if_oerrors; - } else { - /* - * Update total number of successfully - * transmitted packets. - */ - ++sc->arpcom.ac_if.if_opackets; - } - - /* - * reset tx busy and output active flags - */ - sc->xmit_busy = 0; - sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; - - /* - * clear watchdog timer - */ - sc->arpcom.ac_if.if_timer = 0; - - /* - * Add in total number of collisions on last - * transmission. - */ - sc->arpcom.ac_if.if_collisions += collisions; - - /* - * Decrement buffer in-use count if not zero (can only - * be zero if a transmitter interrupt occured while - * not actually transmitting). - * If data is ready to transmit, start it transmitting, - * otherwise defer until after handling receiver - */ - if (sc->txb_inuse && --sc->txb_inuse) - ed_xmit(&sc->arpcom.ac_if); - } - - /* - * Handle receiver interrupts - */ - if (isr & (ED_ISR_PRX|ED_ISR_RXE|ED_ISR_OVW)) { - /* - * Overwrite warning. In order to make sure that a lockup - * of the local DMA hasn't occurred, we reset and - * re-init the NIC. The NSC manual suggests only a - * partial reset/re-init is necessary - but some - * chips seem to want more. The DMA lockup has been - * seen only with early rev chips - Methinks this - * bug was fixed in later revs. -DG - */ - if (isr & ED_ISR_OVW) { - ++sc->arpcom.ac_if.if_ierrors; -#ifdef DIAGNOSTIC - log(LOG_WARNING, - "ed%d: warning - receiver ring buffer overrun\n", - unit); -#endif - /* - * Stop/reset/re-init NIC - */ - ed_reset(unit); - } else { - - /* - * Receiver Error. One or more of: CRC error, frame - * alignment error FIFO overrun, or missed packet. - */ - if (isr & ED_ISR_RXE) { - ++sc->arpcom.ac_if.if_ierrors; -#ifdef ED_DEBUG - printf("ed%d: receive error %x\n", unit, - inb(sc->nic_addr + ED_P0_RSR)); -#endif - } - - /* - * Go get the packet(s) - * XXX - Doing this on an error is dubious - * because there shouldn't be any data to - * get (we've configured the interface to - * not accept packets with errors). - */ - - /* - * Enable 16bit access to shared memory first - * on WD/SMC boards. - */ - if (sc->isa16bit && - (sc->vendor == ED_VENDOR_WD_SMC)) { - - outb(sc->asic_addr + ED_WD_LAAR, - (sc->wd_laar_proto |= - ED_WD_LAAR_M16EN)); - } - - ed_rint (unit); - - /* disable 16bit access */ - if (sc->isa16bit && - (sc->vendor == ED_VENDOR_WD_SMC)) { - - outb(sc->asic_addr + ED_WD_LAAR, - (sc->wd_laar_proto &= - ~ED_WD_LAAR_M16EN)); - } - } - } - - /* - * If it looks like the transmitter can take more data, - * attempt to start output on the interface. - * This is done after handling the receiver to - * give the receiver priority. - */ - if ((sc->arpcom.ac_if.if_flags & IFF_OACTIVE) == 0) - ed_start(&sc->arpcom.ac_if); - - /* - * return NIC CR to standard state: page 0, remote DMA complete, - * start (toggling the TXP bit off, even if was just set - * in the transmit routine, is *okay* - it is 'edge' - * triggered from low to high) - */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - /* - * If the Network Talley Counters overflow, read them to - * reset them. It appears that old 8390's won't - * clear the ISR flag otherwise - resulting in an - * infinite loop. - */ - if (isr & ED_ISR_CNT) { - (void) inb(sc->nic_addr + ED_P0_CNTR0); - (void) inb(sc->nic_addr + ED_P0_CNTR1); - (void) inb(sc->nic_addr + ED_P0_CNTR2); - } - } -} - -/* - * Process an ioctl request. This code needs some work - it looks - * pretty ugly. - */ -int -ed_ioctl(ifp, command, data) - register struct ifnet *ifp; - int command; - caddr_t data; -{ - register struct ifaddr *ifa = (struct ifaddr *)data; - struct ed_softc *sc = &ed_softc[ifp->if_unit]; - struct ifreq *ifr = (struct ifreq *)data; - int s, error = 0; - - s = splnet(); - - switch (command) { - - case SIOCSIFADDR: - ifp->if_flags |= IFF_UP; - - switch (ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - ed_init(ifp->if_unit); /* before arpwhohas */ - /* - * See if another station has *our* IP address. - * i.e.: There is an address conflict! If a - * conflict exists, a message is sent to the - * console. - */ - ((struct arpcom *)ifp)->ac_ipaddr = - IA_SIN(ifa)->sin_addr; - arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); - break; -#endif -#ifdef NS - /* - * XXX - This code is probably wrong - */ - case AF_NS: - { - register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); - - if (ns_nullhost(*ina)) - ina->x_host = - *(union ns_host *)(sc->arpcom.ac_enaddr); - else { - /* - * - */ - bcopy((caddr_t)ina->x_host.c_host, - (caddr_t)sc->arpcom.ac_enaddr, - sizeof(sc->arpcom.ac_enaddr)); - } - /* - * Set new address - */ - ed_init(ifp->if_unit); - break; - } -#endif - default: - ed_init(ifp->if_unit); - break; - } - break; - - case SIOCSIFFLAGS: - /* - * If interface is marked down and it is running, then stop it - */ - if (((ifp->if_flags & IFF_UP) == 0) && - (ifp->if_flags & IFF_RUNNING)) { - ed_stop(ifp->if_unit); - ifp->if_flags &= ~IFF_RUNNING; - } else { - /* - * If interface is marked up and it is stopped, then start it - */ - if ((ifp->if_flags & IFF_UP) && - ((ifp->if_flags & IFF_RUNNING) == 0)) - ed_init(ifp->if_unit); - } -#if NBPFILTER > 0 - if (ifp->if_flags & IFF_PROMISC) { - /* - * Set promiscuous mode on interface. - * XXX - for multicasts to work, we would need to - * write 1's in all bits of multicast - * hashing array. For now we assume that - * this was done in ed_init(). - */ - outb(sc->nic_addr + ED_P0_RCR, - ED_RCR_PRO|ED_RCR_AM|ED_RCR_AB); - } else { - /* - * XXX - for multicasts to work, we would need to - * rewrite the multicast hashing array with the - * proper hash (would have been destroyed above). - */ - outb(sc->nic_addr + ED_P0_RCR, ED_RCR_AB); - } -#endif - /* - * An unfortunate hack to provide the (required) software control - * of the tranceiver for 3Com boards. The ALTPHYS flag disables - * the tranceiver if set. - */ - if (sc->vendor == ED_VENDOR_3COM) { - if (ifp->if_flags & IFF_ALTPHYS) { - outb(sc->asic_addr + ED_3COM_CR, 0); - } else { - outb(sc->asic_addr + ED_3COM_CR, ED_3COM_CR_XSEL); - } - } - - break; - - default: - error = EINVAL; - } - (void) splx(s); - return (error); -} - -/* - * Macro to calculate a new address within shared memory when given an offset - * from an address, taking into account ring-wrap. - */ -#define ringoffset(sc, start, off, type) \ - ((type)( ((caddr_t)(start)+(off) >= (sc)->mem_end) ? \ - (((caddr_t)(start)+(off))) - (sc)->mem_end \ - + (sc)->mem_ring: \ - ((caddr_t)(start)+(off)) )) - -/* - * Retreive packet from shared memory and send to the next level up via - * ether_input(). If there is a BPF listener, give a copy to BPF, too. - */ -ed_get_packet(sc, buf, len) - struct ed_softc *sc; - char *buf; - u_short len; -{ - struct ether_header *eh; - struct mbuf *m, *head, *ed_ring_to_mbuf(); - u_short off; - int resid; - u_short etype; - struct trailer_header trailer_header; - - /* Allocate a header mbuf */ - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - goto bad; - m->m_pkthdr.rcvif = &sc->arpcom.ac_if; - m->m_pkthdr.len = len; - m->m_len = 0; - head = m; - - /* The following sillines is to make NFS happy */ -#define EROUND ((sizeof(struct ether_header) + 3) & ~3) -#define EOFF (EROUND - sizeof(struct ether_header)) - - /* - * The following assumes there is room for - * the ether header in the header mbuf - */ - head->m_data += EOFF; - eh = mtod(head, struct ether_header *); - - if (sc->mem_shared) - bcopy(buf, mtod(head, caddr_t), sizeof(struct ether_header)); - else - ed_pio_readmem(sc, buf, mtod(head, caddr_t), - sizeof(struct ether_header)); - buf += sizeof(struct ether_header); - head->m_len += sizeof(struct ether_header); - len -= sizeof(struct ether_header); - - etype = ntohs((u_short)eh->ether_type); - - /* - * Deal with trailer protocol: - * If trailer protocol, calculate the datasize as 'off', - * which is also the offset to the trailer header. - * Set resid to the amount of packet data following the - * trailer header. - * Finally, copy residual data into mbuf chain. - */ - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - - off = (etype - ETHERTYPE_TRAIL) << 9; - if ((off + sizeof(struct trailer_header)) > len) - goto bad; /* insanity */ - - /* - * If we have shared memory, we can get info directly from the - * stored packet, otherwise we must get a local copy - * of the trailer header using PIO. - */ - if (sc->mem_shared) { - eh->ether_type = *ringoffset(sc, buf, off, u_short *); - resid = ntohs(*ringoffset(sc, buf, off+2, u_short *)); - } else { - struct trailer_header trailer_header; - ed_pio_readmem(sc, - ringoffset(sc, buf, off, caddr_t), - (char *) &trailer_header, - sizeof(trailer_header)); - eh->ether_type = trailer_header.ether_type; - resid = trailer_header.ether_residual; - } - - if ((off + resid) > len) goto bad; /* insanity */ - - resid -= sizeof(struct trailer_header); - if (resid < 0) goto bad; /* insanity */ - - m = ed_ring_to_mbuf(sc, ringoffset(sc, buf, off+4, char *), head, resid); - if (m == 0) goto bad; - - len = off; - head->m_pkthdr.len -= 4; /* subtract trailer header */ - } - - /* - * Pull packet off interface. Or if this was a trailer packet, - * the data portion is appended. - */ - m = ed_ring_to_mbuf(sc, buf, m, len); - if (m == 0) goto bad; - -#if NBPFILTER > 0 - /* - * Check if there's a BPF listener on this interface. - * If so, hand off the raw packet to bpf. - */ - if (sc->bpf) { - bpf_mtap(sc->bpf, head); - - /* - * Note that the interface cannot be in promiscuous mode if - * there are no BPF listeners. And if we are in promiscuous - * mode, we have to check if this packet is really ours. - * - * XXX This test does not support multicasts. - */ - if ((sc->arpcom.ac_if.if_flags & IFF_PROMISC) && - bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr, - sizeof(eh->ether_dhost)) != 0 && - bcmp(eh->ether_dhost, etherbroadcastaddr, - sizeof(eh->ether_dhost)) != 0) { - - m_freem(head); - return; - } - } -#endif - - /* - * Fix up data start offset in mbuf to point past ether header - */ - m_adj(head, sizeof(struct ether_header)); - - /* - * silly ether_input routine needs 'type' in host byte order - */ - eh->ether_type = ntohs(eh->ether_type); - - ether_input(&sc->arpcom.ac_if, eh, head); - return; - -bad: if (head) - m_freem(head); - return; -} - -/* - * Supporting routines - */ - -/* - * Given a NIC memory source address and a host memory destination - * address, copy 'amount' from NIC to host using Programmed I/O. - * The 'amount' is rounded up to a word - okay as long as mbufs - * are word sized. - * This routine is currently Novell-specific. - */ -void -ed_pio_readmem(sc,src,dst,amount) - struct ed_softc *sc; - unsigned short src; - unsigned char *dst; - unsigned short amount; -{ - unsigned short tmp_amount; - - /* select page 0 registers */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - /* round up to a word */ - tmp_amount = amount; - if (amount & 1) ++amount; - - /* set up DMA byte count */ - outb(sc->nic_addr + ED_P0_RBCR0, amount); - outb(sc->nic_addr + ED_P0_RBCR1, amount>>8); - - /* set up source address in NIC mem */ - outb(sc->nic_addr + ED_P0_RSAR0, src); - outb(sc->nic_addr + ED_P0_RSAR1, src>>8); - - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD0 | ED_CR_STA); - - if (sc->isa16bit) { - insw(sc->asic_addr + ED_NOVELL_DATA, dst, amount/2); - } else - insb(sc->asic_addr + ED_NOVELL_DATA, dst, amount); - -} - -/* - * Stripped down routine for writing a linear buffer to NIC memory. - * Only used in the probe routine to test the memory. 'len' must - * be even. - */ -void -ed_pio_writemem(sc,src,dst,len) - struct ed_softc *sc; - char *src; - unsigned short dst; - unsigned short len; -{ - int maxwait=100; /* about 120us */ - - /* select page 0 registers */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - /* reset remote DMA complete flag */ - outb(sc->nic_addr + ED_P0_ISR, ED_ISR_RDC); - - /* set up DMA byte count */ - outb(sc->nic_addr + ED_P0_RBCR0, len); - outb(sc->nic_addr + ED_P0_RBCR1, len>>8); - - /* set up destination address in NIC mem */ - outb(sc->nic_addr + ED_P0_RSAR0, dst); - outb(sc->nic_addr + ED_P0_RSAR1, dst>>8); - - /* set remote DMA write */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD1 | ED_CR_STA); - - if (sc->isa16bit) - outsw(sc->asic_addr + ED_NOVELL_DATA, src, len/2); - else - outsb(sc->asic_addr + ED_NOVELL_DATA, src, len); - /* - * Wait for remote DMA complete. This is necessary because on the - * transmit side, data is handled internally by the NIC in bursts - * and we can't start another remote DMA until this one completes. - * Not waiting causes really bad things to happen - like the NIC - * irrecoverably jamming the ISA bus. - */ - while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait); -} - -/* - * Write an mbuf chain to the destination NIC memory address using - * programmed I/O. - */ -u_short -ed_pio_write_mbufs(sc,m,dst) - struct ed_softc *sc; - struct mbuf *m; - unsigned short dst; -{ - unsigned short len, mb_offset; - struct mbuf *mp; - unsigned char residual[2]; - int maxwait=100; /* about 120us */ - - /* First, count up the total number of bytes to copy */ - for (len = 0, mp = m; mp; mp = mp->m_next) - len += mp->m_len; - - /* select page 0 registers */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2|ED_CR_STA); - - /* reset remote DMA complete flag */ - outb(sc->nic_addr + ED_P0_ISR, ED_ISR_RDC); - - /* set up DMA byte count */ - outb(sc->nic_addr + ED_P0_RBCR0, len); - outb(sc->nic_addr + ED_P0_RBCR1, len>>8); - - /* set up destination address in NIC mem */ - outb(sc->nic_addr + ED_P0_RSAR0, dst); - outb(sc->nic_addr + ED_P0_RSAR1, dst>>8); - - /* set remote DMA write */ - outb(sc->nic_addr + ED_P0_CR, ED_CR_RD1 | ED_CR_STA); - - mb_offset = 0; - /* - * Transfer the mbuf chain to the NIC memory. - * The following code isn't too pretty. The problem is that we can only - * transfer words to the board, and if an mbuf has an odd number - * of bytes in it, this is a problem. It's not a simple matter of - * just removing a byte from the next mbuf (adjusting data++ and - * len--) because this will hose-over the mbuf chain which might - * be needed later for BPF. Instead, we maintain an offset - * (mb_offset) which let's us skip over the first byte in the - * following mbuf. - */ - while (m) { - if (m->m_len - mb_offset) { - if (sc->isa16bit) { - if ((m->m_len - mb_offset) > 1) - outsw(sc->asic_addr + ED_NOVELL_DATA, - mtod(m, caddr_t) + mb_offset, - (m->m_len - mb_offset) / 2); - - /* - * if odd number of bytes, get the odd byte from - * the next mbuf with data - */ - if ((m->m_len - mb_offset) & 1) { - /* first the last byte in current mbuf */ - residual[0] = *(mtod(m, caddr_t) - + m->m_len - 1); - - /* advance past any empty mbufs */ - while (m->m_next && (m->m_next->m_len == 0)) - m = m->m_next; - - if (m->m_next) { - /* remove first byte in next mbuf */ - residual[1] = *(mtod(m->m_next, caddr_t)); - mb_offset = 1; - } - - outw(sc->asic_addr + ED_NOVELL_DATA, - *((unsigned short *) residual)); - } else - mb_offset = 0; - } else - outsb(sc->asic_addr + ED_NOVELL_DATA, m->m_data, m->m_len); - - } - m = m->m_next; - } - - /* - * Wait for remote DMA complete. This is necessary because on the - * transmit side, data is handled internally by the NIC in bursts - * and we can't start another remote DMA until this one completes. - * Not waiting causes really bad things to happen - like the NIC - * irrecoverably jamming the ISA bus. - */ - while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait); - - if (!maxwait) { - log(LOG_WARNING, "ed%d: remote transmit DMA failed to complete\n", - sc->arpcom.ac_if.if_unit); - ed_reset(sc->arpcom.ac_if.if_unit); - } - - return(len); -} - -/* - * Given a source and destination address, copy 'amount' of a packet from - * the ring buffer into a linear destination buffer. Takes into account - * ring-wrap. - */ -static inline char * -ed_ring_copy(sc,src,dst,amount) - struct ed_softc *sc; - char *src; - char *dst; - u_short amount; -{ - u_short tmp_amount; - - /* does copy wrap to lower addr in ring buffer? */ - if (src + amount > sc->mem_end) { - tmp_amount = sc->mem_end - src; - - /* copy amount up to end of NIC memory */ - if (sc->mem_shared) - bcopy(src,dst,tmp_amount); - else - ed_pio_readmem(sc,src,dst,tmp_amount); - - amount -= tmp_amount; - src = sc->mem_ring; - dst += tmp_amount; - } - - if (sc->mem_shared) - bcopy(src, dst, amount); - else - ed_pio_readmem(sc, src, dst, amount); - - return(src + amount); -} - -/* - * Copy data from receive buffer to end of mbuf chain - * allocate additional mbufs as needed. return pointer - * to last mbuf in chain. - * sc = ed info (softc) - * src = pointer in ed ring buffer - * dst = pointer to last mbuf in mbuf chain to copy to - * amount = amount of data to copy - */ -struct mbuf * -ed_ring_to_mbuf(sc,src,dst,total_len) - struct ed_softc *sc; - char *src; - struct mbuf *dst; - u_short total_len; -{ - register struct mbuf *m = dst; - - while (total_len) { - register u_short amount = min(total_len, M_TRAILINGSPACE(m)); - - if (amount == 0) { /* no more data in this mbuf, alloc another */ - /* - * If there is enough data for an mbuf cluster, attempt - * to allocate one of those, otherwise, a regular - * mbuf will do. - * Note that a regular mbuf is always required, even if - * we get a cluster - getting a cluster does not - * allocate any mbufs, and one is needed to assign - * the cluster to. The mbuf that has a cluster - * extension can not be used to contain data - only - * the cluster can contain data. - */ - dst = m; - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return (0); - - if (total_len >= MINCLSIZE) - MCLGET(m, M_DONTWAIT); - - m->m_len = 0; - dst->m_next = m; - amount = min(total_len, M_TRAILINGSPACE(m)); - } - - src = ed_ring_copy(sc, src, mtod(m, caddr_t) + m->m_len, amount); - - m->m_len += amount; - total_len -= amount; - - } - return (m); -} -#endif diff --git a/sys/i386/isa/if_edreg.h b/sys/i386/isa/if_edreg.h deleted file mode 100644 index 9b7a43f..0000000 --- a/sys/i386/isa/if_edreg.h +++ /dev/null @@ -1,903 +0,0 @@ -/* - * National Semiconductor DS8390 NIC register definitions - * - * $Id: if_edreg.h,v 2.0 93/09/29 00:37:15 davidg Exp Locker: davidg $ - * - * Modification history - * - * $Log: if_edreg.h,v $ - * Revision 2.0 93/09/29 00:37:15 davidg - * changed double buffering flag to multi buffering - * made changes/additions for 3c503 multi-buffering - * ...companion to Rev. 2.0 of 'ed' driver. - * - * Revision 1.6 93/09/28 17:20:03 davidg - * first cut at PIO (e.g. NE1000/2000) support - * - * Revision 1.5 93/08/25 20:38:34 davidg - * added define for card type WD8013WC (10BaseT) - * - * Revision 1.4 93/08/14 20:07:55 davidg - * fix board type definition for 8013EP - * - * Revision 1.3 93/07/20 15:25:25 davidg - * added config flags for forcing 8/16bit mode and disabling double - * xmit buffers. - * - * Revision 1.2 93/06/23 03:03:05 davidg - * added some additional definitions for the 83C584 bus interface - * chip (SMC/WD boards) - * - * Revision 1.1 93/06/23 03:01:07 davidg - * Initial revision - * - */ - -/* - * Page 0 register offsets - */ -#define ED_P0_CR 0x00 /* Command Register */ - -#define ED_P0_CLDA0 0x01 /* Current Local DMA Addr low (read) */ -#define ED_P0_PSTART 0x01 /* Page Start register (write) */ - -#define ED_P0_CLDA1 0x02 /* Current Local DMA Addr high (read) */ -#define ED_P0_PSTOP 0x02 /* Page Stop register (write) */ - -#define ED_P0_BNRY 0x03 /* Boundary Pointer */ - -#define ED_P0_TSR 0x04 /* Transmit Status Register (read) */ -#define ED_P0_TPSR 0x04 /* Transmit Page Start (write) */ - -#define ED_P0_NCR 0x05 /* Number of Collisions Reg (read) */ -#define ED_P0_TBCR0 0x05 /* Transmit Byte count, low (write) */ - -#define ED_P0_FIFO 0x06 /* FIFO register (read) */ -#define ED_P0_TBCR1 0x06 /* Transmit Byte count, high (write) */ - -#define ED_P0_ISR 0x07 /* Interrupt Status Register */ - -#define ED_P0_CRDA0 0x08 /* Current Remote DMA Addr low (read) */ -#define ED_P0_RSAR0 0x08 /* Remote Start Address low (write) */ - -#define ED_P0_CRDA1 0x09 /* Current Remote DMA Addr high (read) */ -#define ED_P0_RSAR1 0x09 /* Remote Start Address high (write) */ - -#define ED_P0_RBCR0 0x0a /* Remote Byte Count low (write) */ - -#define ED_P0_RBCR1 0x0b /* Remote Byte Count high (write) */ - -#define ED_P0_RSR 0x0c /* Receive Status (read) */ -#define ED_P0_RCR 0x0c /* Receive Configuration Reg (write) */ - -#define ED_P0_CNTR0 0x0d /* frame alignment error counter (read) */ -#define ED_P0_TCR 0x0d /* Transmit Configuration Reg (write) */ - -#define ED_P0_CNTR1 0x0e /* CRC error counter (read) */ -#define ED_P0_DCR 0x0e /* Data Configuration Reg (write) */ - -#define ED_P0_CNTR2 0x0f /* missed packet counter (read) */ -#define ED_P0_IMR 0x0f /* Interrupt Mask Register (write) */ - -/* - * Page 1 register offsets - */ -#define ED_P1_CR 0x00 /* Command Register */ -#define ED_P1_PAR0 0x01 /* Physical Address Register 0 */ -#define ED_P1_PAR1 0x02 /* Physical Address Register 1 */ -#define ED_P1_PAR2 0x03 /* Physical Address Register 2 */ -#define ED_P1_PAR3 0x04 /* Physical Address Register 3 */ -#define ED_P1_PAR4 0x05 /* Physical Address Register 4 */ -#define ED_P1_PAR5 0x06 /* Physical Address Register 5 */ -#define ED_P1_CURR 0x07 /* Current RX ring-buffer page */ -#define ED_P1_MAR0 0x08 /* Multicast Address Register 0 */ -#define ED_P1_MAR1 0x09 /* Multicast Address Register 1 */ -#define ED_P1_MAR2 0x0a /* Multicast Address Register 2 */ -#define ED_P1_MAR3 0x0b /* Multicast Address Register 3 */ -#define ED_P1_MAR4 0x0c /* Multicast Address Register 4 */ -#define ED_P1_MAR5 0x0d /* Multicast Address Register 5 */ -#define ED_P1_MAR6 0x0e /* Multicast Address Register 6 */ -#define ED_P1_MAR7 0x0f /* Multicast Address Register 7 */ - -/* - * Page 2 register offsets - */ -#define ED_P2_CR 0x00 /* Command Register */ -#define ED_P2_PSTART 0x01 /* Page Start (read) */ -#define ED_P2_CLDA0 0x01 /* Current Local DMA Addr 0 (write) */ -#define ED_P2_PSTOP 0x02 /* Page Stop (read) */ -#define ED_P2_CLDA1 0x02 /* Current Local DMA Addr 1 (write) */ -#define ED_P2_RNPP 0x03 /* Remote Next Packet Pointer */ -#define ED_P2_TPSR 0x04 /* Transmit Page Start (read) */ -#define ED_P2_LNPP 0x05 /* Local Next Packet Pointer */ -#define ED_P2_ACU 0x06 /* Address Counter Upper */ -#define ED_P2_ACL 0x07 /* Address Counter Lower */ -#define ED_P2_RCR 0x0c /* Receive Configuration Register (read) */ -#define ED_P2_TCR 0x0d /* Transmit Configuration Register (read) */ -#define ED_P2_DCR 0x0e /* Data Configuration Register (read) */ -#define ED_P2_IMR 0x0f /* Interrupt Mask Register (read) */ - -/* - * Command Register (CR) definitions - */ - -/* - * STP: SToP. Software reset command. Takes the controller offline. No - * packets will be received or transmitted. Any reception or - * transmission in progress will continue to completion before - * entering reset state. To exit this state, the STP bit must - * reset and the STA bit must be set. The software reset has - * executed only when indicated by the RST bit in the ISR being - * set. - */ -#define ED_CR_STP 0x01 - -/* - * STA: STArt. This bit is used to activate the NIC after either power-up, - * or when the NIC has been put in reset mode by software command - * or error. - */ -#define ED_CR_STA 0x02 - -/* - * TXP: Transmit Packet. This bit must be set to indicate transmission of - * a packet. TXP is internally reset either after the transmission is - * completed or aborted. This bit should be set only after the Transmit - * Byte Count and Transmit Page Start register have been programmed. - */ -#define ED_CR_TXP 0x04 - -/* - * RD0, RD1, RD2: Remote DMA Command. These three bits control the operation - * of the remote DMA channel. RD2 can be set to abort any remote DMA - * command in progress. The Remote Byte Count registers should be cleared - * when a remote DMA has been aborted. The Remote Start Addresses are not - * restored to the starting address if the remote DMA is aborted. - * - * RD2 RD1 RD0 function - * 0 0 0 not allowed - * 0 0 1 remote read - * 0 1 0 remote write - * 0 1 1 send packet - * 1 X X abort - */ -#define ED_CR_RD0 0x08 -#define ED_CR_RD1 0x10 -#define ED_CR_RD2 0x20 - -/* - * PS0, PS1: Page Select. The two bits select which register set or 'page' to - * access. - * - * PS1 PS0 page - * 0 0 0 - * 0 1 1 - * 1 0 2 - * 1 1 reserved - */ -#define ED_CR_PS0 0x40 -#define ED_CR_PS1 0x80 -/* bit encoded aliases */ -#define ED_CR_PAGE_0 0x00 /* (for consistency) */ -#define ED_CR_PAGE_1 0x40 -#define ED_CR_PAGE_2 0x80 - -/* - * Interrupt Status Register (ISR) definitions - */ - -/* - * PRX: Packet Received. Indicates packet received with no errors. - */ -#define ED_ISR_PRX 0x01 - -/* - * PTX: Packet Transmitted. Indicates packet transmitted with no errors. - */ -#define ED_ISR_PTX 0x02 - -/* - * RXE: Receive Error. Indicates that a packet was received with one or more - * the following errors: CRC error, frame alignment error, FIFO overrun, - * missed packet. - */ -#define ED_ISR_RXE 0x04 - -/* - * TXE: Transmission Error. Indicates that an attempt to transmit a packet - * resulted in one or more of the following errors: excessive - * collisions, FIFO underrun. - */ -#define ED_ISR_TXE 0x08 - -/* - * OVW: OverWrite. Indicates a receive ring-buffer overrun. Incoming network - * would exceed (has exceeded?) the boundry pointer, resulting in data - * that was previously received and not yet read from the buffer to be - * overwritten. - */ -#define ED_ISR_OVW 0x10 - -/* - * CNT: Counter Overflow. Set when the MSB of one or more of the Network Talley - * Counters has been set. - */ -#define ED_ISR_CNT 0x20 - -/* - * RDC: Remote Data Complete. Indicates that a Remote DMA operation has completed. - */ -#define ED_ISR_RDC 0x40 - -/* - * RST: Reset status. Set when the NIC enters the reset state and cleared when a - * Start Command is issued to the CR. This bit is also set when a receive - * ring-buffer overrun (OverWrite) occurs and is cleared when one or more - * packets have been removed from the ring. This is a read-only bit. - */ -#define ED_ISR_RST 0x80 - -/* - * Interrupt Mask Register (IMR) definitions - */ - -/* - * PRXE: Packet Received interrupt Enable. If set, a received packet will cause - * an interrupt. - */ -#define ED_IMR_PRXE 0x01 - -/* - * PTXE: Packet Transmit interrupt Enable. If set, an interrupt is generated when - * a packet transmission completes. - */ -#define ED_IMR_PTXE 0x02 - -/* - * RXEE: Receive Error interrupt Enable. If set, an interrupt will occur whenever a - * packet is received with an error. - */ -#define ED_IMR_RXEE 0x04 - -/* - * TXEE: Transmit Error interrupt Enable. If set, an interrupt will occur whenever - * a transmission results in an error. - */ -#define ED_IMR_TXEE 0x08 - -/* - * OVWE: OverWrite error interrupt Enable. If set, an interrupt is generated whenever - * the receive ring-buffer is overrun. i.e. when the boundry pointer is exceeded. - */ -#define ED_IMR_OVWE 0x10 - -/* - * CNTE: Counter overflow interrupt Enable. If set, an interrupt is generated whenever - * the MSB of one or more of the Network Statistics counters has been set. - */ -#define ED_IMR_CNTE 0x20 - -/* - * RDCE: Remote DMA Complete interrupt Enable. If set, an interrupt is generated - * when a remote DMA transfer has completed. - */ -#define ED_IMR_RDCE 0x40 - -/* - * bit 7 is unused/reserved - */ - -/* - * Data Configuration Register (DCR) definitions - */ - -/* - * WTS: Word Transfer Select. WTS establishes byte or word transfers for - * both remote and local DMA transfers - */ -#define ED_DCR_WTS 0x01 - -/* - * BOS: Byte Order Select. BOS sets the byte order for the host. - * Should be 0 for 80x86, and 1 for 68000 series processors - */ -#define ED_DCR_BOS 0x02 - -/* - * LAS: Long Address Select. When LAS is 1, the contents of the remote - * DMA registers RSAR0 and RSAR1 are used to provide A16-A31 - */ -#define ED_DCR_LAS 0x04 - -/* - * LS: Loopback Select. When 0, loopback mode is selected. Bits D1 and D2 - * of the TCR must also be programmed for loopback operation. - * When 1, normal operation is selected. - */ -#define ED_DCR_LS 0x08 - -/* - * AR: Auto-initialize Remote. When 0, data must be removed from ring-buffer - * under program control. When 1, remote DMA is automatically initiated - * and the boundry pointer is automatically updated - */ -#define ED_DCR_AR 0x10 - -/* - * FT0, FT1: Fifo Threshold select. - * FT1 FT0 Word-width Byte-width - * 0 0 1 word 2 bytes - * 0 1 2 words 4 bytes - * 1 0 4 words 8 bytes - * 1 1 8 words 12 bytes - * - * During transmission, the FIFO threshold indicates the number of bytes - * or words that the FIFO has filled from the local DMA before BREQ is - * asserted. The transmission threshold is 16 bytes minus the receiver - * threshold. - */ -#define ED_DCR_FT0 0x20 -#define ED_DCR_FT1 0x40 - -/* - * bit 7 (0x80) is unused/reserved - */ - -/* - * Transmit Configuration Register (TCR) definitions - */ - -/* - * CRC: Inhibit CRC. If 0, CRC will be appended by the transmitter, if 0, CRC - * is not appended by the transmitter. - */ -#define ED_TCR_CRC 0x01 - -/* - * LB0, LB1: Loopback control. These two bits set the type of loopback that is - * to be performed. - * - * LB1 LB0 mode - * 0 0 0 - normal operation (DCR_LS = 0) - * 0 1 1 - internal loopback (DCR_LS = 0) - * 1 0 2 - external loopback (DCR_LS = 1) - * 1 1 3 - external loopback (DCR_LS = 0) - */ -#define ED_TCR_LB0 0x02 -#define ED_TCR_LB1 0x04 - -/* - * ATD: Auto Transmit Disable. Clear for normal operation. When set, allows - * another station to disable the NIC's transmitter by transmitting to - * a multicast address hashing to bit 62. Reception of a multicast address - * hashing to bit 63 enables the transmitter. - */ -#define ED_TCR_ATD 0x08 - -/* - * OFST: Collision Offset enable. This bit when set modifies the backoff - * algorithm to allow prioritization of nodes. - */ -#define ED_TCR_OFST 0x10 - -/* - * bits 5, 6, and 7 are unused/reserved - */ - -/* - * Transmit Status Register (TSR) definitions - */ - -/* - * PTX: Packet Transmitted. Indicates successful transmission of packet. - */ -#define ED_TSR_PTX 0x01 - -/* - * bit 1 (0x02) is unused/reserved - */ - -/* - * COL: Transmit Collided. Indicates that the transmission collided at least - * once with another station on the network. - */ -#define ED_TSR_COL 0x04 - -/* - * ABT: Transmit aborted. Indicates that the transmission was aborted due to - * excessive collisions. - */ -#define ED_TSR_ABT 0x08 - -/* - * CRS: Carrier Sense Lost. Indicates that carrier was lost during the - * transmission of the packet. (Transmission is not aborted because - * of a loss of carrier) - */ -#define ED_TSR_CRS 0x10 - -/* - * FU: FIFO Underrun. Indicates that the NIC wasn't able to access bus/ - * transmission memory before the FIFO emptied. Transmission of the - * packet was aborted. - */ -#define ED_TSR_FU 0x20 - -/* - * CDH: CD Heartbeat. Indicates that the collision detection circuitry - * isn't working correctly during a collision heartbeat test. - */ -#define ED_TSR_CDH 0x40 - -/* - * OWC: Out of Window Collision: Indicates that a collision occurred after - * a slot time (51.2us). The transmission is rescheduled just as in - * normal collisions. - */ -#define ED_TSR_OWC 0x80 - -/* - * Receiver Configuration Register (RCR) definitions - */ - -/* - * SEP: Save Errored Packets. If 0, error packets are discarded. If set to 1, - * packets with CRC and frame errors are not discarded. - */ -#define ED_RCR_SEP 0x01 - -/* - * AR: Accept Runt packet. If 0, packet with less than 64 byte are discarded. - * If set to 1, packets with less than 64 byte are not discarded. - */ -#define ED_RCR_AR 0x02 - -/* - * AB: Accept Broadcast. If set, packets sent to the broadcast address will be - * accepted. - */ -#define ED_RCR_AB 0x04 - -/* - * AM: Accept Multicast. If set, packets sent to a multicast address are checked - * for a match in the hashing array. If clear, multicast packets are ignored. - */ -#define ED_RCR_AM 0x08 - -/* - * PRO: Promiscuous Physical. If set, all packets with a physical addresses are - * accepted. If clear, a physical destination address must match this - * station's address. Note: for full promiscuous mode, RCR_AB and RCR_AM - * must also be set. In addition, the multicast hashing array must be set - * to all 1's so that all multicast addresses are accepted. - */ -#define ED_RCR_PRO 0x10 - -/* - * MON: Monitor Mode. If set, packets will be checked for good CRC and framing, - * but are not stored in the ring-buffer. If clear, packets are stored (normal - * operation). - */ -#define ED_RCR_MON 0x20 - -/* - * bits 6 and 7 are unused/reserved. - */ - -/* - * Receiver Status Register (RSR) definitions - */ - -/* - * PRX: Packet Received without error. - */ -#define ED_RSR_PRX 0x01 - -/* - * CRC: CRC error. Indicates that a packet has a CRC error. Also set for frame - * alignment errors. - */ -#define ED_RSR_CRC 0x02 - -/* - * FAE: Frame Alignment Error. Indicates that the incoming packet did not end on - * a byte boundry and the CRC did not match at the last byte boundry. - */ -#define ED_RSR_FAE 0x04 - -/* - * FO: FIFO Overrun. Indicates that the FIFO was not serviced (during local DMA) - * causing it to overrun. Reception of the packet is aborted. - */ -#define ED_RSR_FO 0x08 - -/* - * MPA: Missed Packet. Indicates that the received packet couldn't be stored in - * the ring-buffer because of insufficient buffer space (exceeding the - * boundry pointer), or because the transfer to the ring-buffer was inhibited - * by RCR_MON - monitor mode. - */ -#define ED_RSR_MPA 0x10 - -/* - * PHY: Physical address. If 0, the packet received was sent to a physical address. - * If 1, the packet was accepted because of a multicast/broadcast address - * match. - */ -#define ED_RSR_PHY 0x20 - -/* - * DIS: Receiver Disabled. Set to indicate that the receiver has enetered monitor - * mode. Cleared when the receiver exits monitor mode. - */ -#define ED_RSR_DIS 0x40 - -/* - * DFR: Deferring. Set to indicate a 'jabber' condition. The CRS and COL inputs - * are active, and the transceiver has set the CD line as a result of the - * jabber. - */ -#define ED_RSR_DFR 0x80 - -/* - * receive ring discriptor - * - * The National Semiconductor DS8390 Network interface controller uses - * the following receive ring headers. The way this works is that the - * memory on the interface card is chopped up into 256 bytes blocks. - * A contiguous portion of those blocks are marked for receive packets - * by setting start and end block #'s in the NIC. For each packet that - * is put into the receive ring, one of these headers (4 bytes each) is - * tacked onto the front. - */ -struct ed_ring { - struct edr_status { /* received packet status */ - u_char rs_prx:1, /* packet received intack */ - rs_crc:1, /* crc error */ - rs_fae:1, /* frame alignment error */ - rs_fo:1, /* fifo overrun */ - rs_mpa:1, /* packet received intack */ - rs_phy:1, /* packet received intack */ - rs_dis:1, /* packet received intack */ - rs_dfr:1; /* packet received intack */ - } ed_rcv_status; /* received packet status */ - u_char next_packet; /* pointer to next packet */ - u_short count; /* bytes in packet (length + 4) */ -}; - -/* - * Common constants - */ -#define ED_PAGE_SIZE 256 /* Size of RAM pages in bytes */ -#define ED_TXBUF_SIZE 6 /* Size of TX buffer in pages */ - -/* - * Vendor types - */ -#define ED_VENDOR_WD_SMC 0x00 /* Western Digital/SMC */ -#define ED_VENDOR_3COM 0x01 /* 3Com */ -#define ED_VENDOR_NOVELL 0x02 /* Novell */ - -/* - * Compile-time config flags - */ -/* - * this sets the default for enabling/disablng the tranceiver - */ -#define ED_FLAGS_DISABLE_TRANCEIVER 0x0001 - -/* - * This forces the board to be used in 8/16bit mode even if it - * autoconfigs differently - */ -#define ED_FLAGS_FORCE_8BIT_MODE 0x0002 -#define ED_FLAGS_FORCE_16BIT_MODE 0x0004 - -/* - * This disables the use of double transmit buffers. - */ -#define ED_FLAGS_NO_MULTI_BUFFERING 0x0008 - -/* - * This forces all operations with the NIC memory to use Programmed - * I/O (i.e. not via shared memory) - */ -#define ED_FLAGS_FORCE_PIO 0x0010 - -/* - * Definitions for Western digital/SMC WD80x3 series ASIC - */ -/* - * Memory Select Register (MSR) - */ -#define ED_WD_MSR 0 - -#define ED_WD_MSR_ADDR 0x3f /* Memory decode bits 18-13 */ -#define ED_WD_MSR_MENB 0x40 /* Memory enable */ -#define ED_WD_MSR_RST 0x80 /* Reset board */ - -/* - * Interface Configuration Register (ICR) - */ -#define ED_WD_ICR 1 - -#define ED_WD_ICR_16BIT 0x01 /* 16-bit interface */ -#define ED_WD_ICR_OAR 0x02 /* select register. 0=BIO 1=EAR */ -#define ED_WD_ICR_IR2 0x04 /* high order bit of encoded IRQ */ -#define ED_WD_ICR_MSZ 0x08 /* memory size (0=8k 1=32k) */ -#define ED_WD_ICR_RLA 0x10 /* recall LAN address */ -#define ED_WD_ICR_RX7 0x20 /* recall all but i/o and LAN address */ -#define ED_WD_ICR_RIO 0x40 /* recall i/o address */ -#define ED_WD_ICR_STO 0x80 /* store to non-volatile memory */ - -/* - * IO Address Register (IAR) - */ -#define ED_WD_IAR 2 - -/* - * EEROM Address Register - */ -#define ED_WD_EAR 3 - -/* - * Interrupt Request Register (IRR) - */ -#define ED_WD_IRR 4 - -#define ED_WD_IRR_0WS 0x01 /* use 0 wait-states on 8 bit bus */ -#define ED_WD_IRR_OUT1 0x02 /* WD83C584 pin 1 output */ -#define ED_WD_IRR_OUT2 0x04 /* WD83C584 pin 2 output */ -#define ED_WD_IRR_OUT3 0x08 /* WD83C584 pin 3 output */ -#define ED_WD_IRR_FLASH 0x10 /* Flash RAM is in the ROM socket */ - -/* - * The three bit of the encoded IRQ are decoded as follows: - * - * IR2 IR1 IR0 IRQ - * 0 0 0 2/9 - * 0 0 1 3 - * 0 1 0 5 - * 0 1 1 7 - * 1 0 0 10 - * 1 0 1 11 - * 1 1 0 15 - * 1 1 1 4 - */ -#define ED_WD_IRR_IR0 0x20 /* bit 0 of encoded IRQ */ -#define ED_WD_IRR_IR1 0x40 /* bit 1 of encoded IRQ */ -#define ED_WD_IRR_IEN 0x80 /* Interrupt enable */ - -/* - * LA Address Register (LAAR) - */ -#define ED_WD_LAAR 5 - -#define ED_WD_LAAR_ADDRHI 0x1f /* bits 23-19 of RAM address */ -#define ED_WD_LAAR_0WS16 0x20 /* enable 0 wait-states on 16 bit bus */ -#define ED_WD_LAAR_L16EN 0x40 /* enable 16-bit operation */ -#define ED_WD_LAAR_M16EN 0x80 /* enable 16-bit memory access */ - -/* i/o base offset to station address/card-ID PROM */ -#define ED_WD_PROM 8 - -/* i/o base offset to CARD ID */ -#define ED_WD_CARD_ID ED_WD_PROM+6 - -/* Board type codes in card ID */ -#define ED_TYPE_WD8003S 0x02 -#define ED_TYPE_WD8003E 0x03 -#define ED_TYPE_WD8013EBT 0x05 -#define ED_TYPE_WD8013EP 0x27 -#define ED_TYPE_WD8013WC 0x28 -#define ED_TYPE_WD8013EBP 0x2c -#define ED_TYPE_WD8013EPC 0x29 - -/* Bit definitions in card ID */ -#define ED_WD_REV_MASK 0x1f /* Revision mask */ -#define ED_WD_SOFTCONFIG 0x20 /* Soft config */ -#define ED_WD_LARGERAM 0x40 /* Large RAM */ -#define ED_MICROCHANEL 0x80 /* Microchannel bus (vs. isa) */ - -/* - * Checksum total. All 8 bytes in station address PROM will add up to this - */ -#define ED_WD_ROM_CHECKSUM_TOTAL 0xFF - -#define ED_WD_NIC_OFFSET 0x10 /* I/O base offset to NIC */ -#define ED_WD_ASIC_OFFSET 0 /* I/O base offset to ASIC */ -#define ED_WD_IO_PORTS 32 /* # of i/o addresses used */ - -#define ED_WD_PAGE_OFFSET 0 /* page offset for NIC access to mem */ - -/* - * Definitions for 3Com 3c503 - */ -#define ED_3COM_NIC_OFFSET 0 -#define ED_3COM_ASIC_OFFSET 0x400 /* offset to nic i/o regs */ - -/* - * XXX - The I/O address range is fragmented in the 3c503; this is the - * number of regs at iobase. - */ -#define ED_3COM_IO_PORTS 16 /* # of i/o addresses used */ - -/* tx memory starts in second bank on 8bit cards */ -#define ED_3COM_TX_PAGE_OFFSET_8BIT 0x20 - -/* tx memory starts in first bank on 16bit cards */ -#define ED_3COM_TX_PAGE_OFFSET_16BIT 0x0 - -/* ...and rx memory starts in second bank */ -#define ED_3COM_RX_PAGE_OFFSET_16BIT 0x20 - - -/* - * Page Start Register. Must match PSTART in NIC - */ -#define ED_3COM_PSTR 0 - -/* - * Page Stop Register. Must match PSTOP in NIC - */ -#define ED_3COM_PSPR 1 - -/* - * Drq Timer Register. Determines number of bytes to be transfered during - * a DMA burst. - */ -#define ED_3COM_DQTR 2 - -/* - * Base Configuration Register. Read-only register which contains the - * board-configured I/O base address of the adapter. Bit encoded. - */ -#define ED_3COM_BCFR 3 - -#define ED_3COM_BCFR_2E0 0x01 -#define ED_3COM_BCFR_2A0 0x02 -#define ED_3COM_BCFR_280 0x04 -#define ED_3COM_BCFR_250 0x08 -#define ED_3COM_BCFR_350 0x10 -#define ED_3COM_BCFR_330 0x20 -#define ED_3COM_BCFR_310 0x40 -#define ED_3COM_BCFR_300 0x80 - -/* - * EPROM Configuration Register. Read-only register which contains the - * board-configured memory base address. Bit encoded. - */ -#define ED_3COM_PCFR 4 - -#define ED_3COM_PCFR_C8000 0x10 -#define ED_3COM_PCFR_CC000 0x20 -#define ED_3COM_PCFR_D8000 0x40 -#define ED_3COM_PCFR_DC000 0x80 - -/* - * GA Configuration Register. Gate-Array Configuration Register. - */ -#define ED_3COM_GACFR 5 - -/* - * mbs2 mbs1 mbs0 start address - * 0 0 0 0x0000 - * 0 0 1 0x2000 - * 0 1 0 0x4000 - * 0 1 1 0x6000 - * - * Note that with adapters with only 8K, the setting for 0x2000 must - * always be used. - */ -#define ED_3COM_GACFR_MBS0 0x01 -#define ED_3COM_GACFR_MBS1 0x02 -#define ED_3COM_GACFR_MBS2 0x04 - -#define ED_3COM_GACFR_RSEL 0x08 /* enable shared memory */ -#define ED_3COM_GACFR_TEST 0x10 /* for GA testing */ -#define ED_3COM_GACFR_OWS 0x20 /* select 0WS access to GA */ -#define ED_3COM_GACFR_TCM 0x40 /* Mask DMA interrupts */ -#define ED_3COM_GACFR_NIM 0x80 /* Mask NIC interrupts */ - -/* - * Control Register. Miscellaneous control functions. - */ -#define ED_3COM_CR 6 - -#define ED_3COM_CR_RST 0x01 /* Reset GA and NIC */ -#define ED_3COM_CR_XSEL 0x02 /* Transceiver select. BNC=1(def) AUI=0 */ -#define ED_3COM_CR_EALO 0x04 /* window EA PROM 0-15 to I/O base */ -#define ED_3COM_CR_EAHI 0x08 /* window EA PROM 16-31 to I/O base */ -#define ED_3COM_CR_SHARE 0x10 /* select interrupt sharing option */ -#define ED_3COM_CR_DBSEL 0x20 /* Double buffer select */ -#define ED_3COM_CR_DDIR 0x40 /* DMA direction select */ -#define ED_3COM_CR_START 0x80 /* Start DMA controller */ - -/* - * Status Register. Miscellaneous status information. - */ -#define ED_3COM_STREG 7 - -#define ED_3COM_STREG_REV 0x07 /* GA revision */ -#define ED_3COM_STREG_DIP 0x08 /* DMA in progress */ -#define ED_3COM_STREG_DTC 0x10 /* DMA terminal count */ -#define ED_3COM_STREG_OFLW 0x20 /* Overflow */ -#define ED_3COM_STREG_UFLW 0x40 /* Underflow */ -#define ED_3COM_STREG_DPRDY 0x80 /* Data port ready */ - -/* - * Interrupt/DMA Configuration Register - */ -#define ED_3COM_IDCFR 8 - -#define ED_3COM_IDCFR_DRQ0 0x01 /* DMA request 1 select */ -#define ED_3COM_IDCFR_DRQ1 0x02 /* DMA request 2 select */ -#define ED_3COM_IDCFR_DRQ2 0x04 /* DMA request 3 select */ -#define ED_3COM_IDCFR_UNUSED 0x08 /* not used */ -#define ED_3COM_IDCFR_IRQ2 0x10 /* Interrupt request 2 select */ -#define ED_3COM_IDCFR_IRQ3 0x20 /* Interrupt request 3 select */ -#define ED_3COM_IDCFR_IRQ4 0x40 /* Interrupt request 4 select */ -#define ED_3COM_IDCFR_IRQ5 0x80 /* Interrupt request 5 select */ - -/* - * DMA Address Register MSB - */ -#define ED_3COM_DAMSB 9 - -/* - * DMA Address Register LSB - */ -#define ED_3COM_DALSB 0x0a - -/* - * Vector Pointer Register 2 - */ -#define ED_3COM_VPTR2 0x0b - -/* - * Vector Pointer Register 1 - */ -#define ED_3COM_VPTR1 0x0c - -/* - * Vector Pointer Register 0 - */ -#define ED_3COM_VPTR0 0x0d - -/* - * Register File Access MSB - */ -#define ED_3COM_RFMSB 0x0e - -/* - * Register File Access LSB - */ -#define ED_3COM_RFLSB 0x0f - -/* - * Definitions for Novell NE1000/2000 boards - */ - -/* - * Board type codes - */ -#define ED_TYPE_NE1000 0x01 -#define ED_TYPE_NE2000 0x02 - -/* - * Register offsets/total - */ -#define ED_NOVELL_NIC_OFFSET 0x00 -#define ED_NOVELL_ASIC_OFFSET 0x10 -#define ED_NOVELL_IO_PORTS 32 - -/* - * Remote DMA data register; for reading or writing to the NIC mem - * via programmed I/O (offset from ASIC base) - */ -#define ED_NOVELL_DATA 0x00 - -/* - * Reset register; reading from this register causes a board reset - */ -#define ED_NOVELL_RESET 0x0f diff --git a/sys/i386/isa/if_ie.c b/sys/i386/isa/if_ie.c deleted file mode 100644 index 2a68b1c..0000000 --- a/sys/i386/isa/if_ie.c +++ /dev/null @@ -1,1799 +0,0 @@ -/*- - * Copyright (c) 1992, 1993, University of Vermont and State - * Agricultural College. - * Copyright (c) 1992, 1993, Garrett A. Wollman. - * - * Portions: - * Copyright (c) 1990, 1991, William F. Jolitz - * Copyright (c) 1990, The Regents of the University of California - * - * All rights reserved. - * - * 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 University of - * Vermont and State Agricultural College and Garrett A. Wollman, - * by William F. Jolitz, by the University of California, - * Berkeley, by Larwence Berkeley Laboratory, and its contributors. - * 4. Neither the names of the Universities nor the names of the authors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * $Id$ - */ - -/* - * Intel 82586 Ethernet chip - * Register, bit, and structure definitions. - * - * Written by GAW with reference to the Clarkson Packet Driver code for this - * chip written by Russ Nelson and others. - * - * BPF support code stolen directly from hpdev/if_le.c, supplied with - * tcpdump. - */ - -/* - * The i82586 is a very versatile chip, found in many implementations. - * Programming this chip is mostly the same, but certain details differ - * from card to card. This driver is written so that different cards - * can be automatically detected at run-time. Currently, only the - * AT&T EN100/StarLAN 10 series are supported. - */ - -/* -Mode of operation: - -We run the 82586 in a standard Ethernet mode. We keep NFRAMES received -frame descriptors around for the receiver to use, and NBUFFS associated -receive buffer descriptors, both in a circular list. Whenever a frame is -received, we rotate both lists as necessary. (The 586 treats both lists -as a simple queue.) We also keep a transmit command around so that packets -can be sent off quickly. - -We configure the adapter in AL-LOC = 1 mode, which means that the -Ethernet/802.3 MAC header is placed at the beginning of the receive buffer -rather than being split off into various fields in the RFD. This also -means that we must include this header in the transmit buffer as well. - -By convention, all transmit commands, and only transmit commands, shall -have the I (IE_CMD_INTR) bit set in the command. This way, when an -interrupt arrives at ieintr(), it is immediately possible to tell -what precisely caused it. ANY OTHER command-sending routines should -run at splimp(), and should post an acknowledgement to every interrupt -they generate. - -The 82586 has a 24-bit address space internally, and the adaptor's -memory is located at the top of this region. However, the value we are -given in configuration is normally the *bottom* of the adaptor RAM. So, -we must go through a few gyrations to come up with a kernel virtual address -which represents the actual beginning of the 586 address space. First, -we autosize the RAM by running through several possible sizes and trying -to initialize the adapter under the assumption that the selected size -is correct. Then, knowing the correct RAM size, we set up our pointers -in ie_softc[unit]. `iomem' represents the computed base of the 586 -address space. `iomembot' represents the actual configured base -of adapter RAM. Finally, `iosize' represents the calculated size -of 586 RAM. Then, when laying out commands, we use the interval -[iomembot, iomembot + iosize); to make 24-pointers, we subtract -iomem, and to make 16-pointers, we subtract iomem and and with 0xffff. - -*/ - -#include "ie.h" -#if NIE > 0 - -#include "param.h" -#include "systm.h" -#include "mbuf.h" -#include "buf.h" -#include "protosw.h" -#include "socket.h" -#include "ioctl.h" -#include "errno.h" -#include "syslog.h" - -#include "net/if.h" -#include "net/if_types.h" -#include "net/if_dl.h" -#include "net/netisr.h" -#include "net/route.h" - -#include "bpfilter.h" - -#ifdef INET -#include "netinet/in.h" -#include "netinet/in_systm.h" -#include "netinet/in_var.h" -#include "netinet/ip.h" -#include "netinet/if_ether.h" -#endif - -#ifdef NS -#include "netns/ns.h" -#include "netns/ns_if.h" -#endif - -#include "i386/isa/isa.h" -/*#include "machine/cpufunc.h"*/ -#include "i386/isa/isa_device.h" -#include "i386/isa/ic/i82586.h" -#include "i386/isa/if_iereg.h" -#include "i386/isa/icu.h" - -#include "vm/vm.h" - -#if NBPFILTER > 0 -#include "net/bpf.h" -#include "net/bpfdesc.h" -#endif - -#if (NBPFILTER > 0) || defined(MULTICAST) -#define FILTER -static struct mbuf *last_not_for_us; -#endif - -#ifdef DEBUG -#define IED_RINT 1 -#define IED_TINT 2 -#define IED_RNR 4 -#define IED_CNA 8 -#define IED_READFRAME 16 -int ie_debug = IED_RNR; -#endif - -#ifndef ETHERMINLEN -#define ETHERMINLEN 60 -#endif - -#define IE_BUF_LEN 1512 /* length of transmit buffer */ - -/* Forward declaration */ -struct ie_softc; - -int ieprobe(struct isa_device *dvp); -int ieattach(struct isa_device *dvp); -int ieinit(int unit); -int ieioctl(struct ifnet *ifp, int command, void *data); -int iestart(struct ifnet *ifp); -static void sl_reset_586(int unit); -static void sl_chan_attn(int unit); -int iereset(int unit, int dummy); -static void ie_readframe(int unit, struct ie_softc *ie, int bufno); -static void ie_drop_packet_buffer(int unit, struct ie_softc *ie); -static void sl_read_ether(int unit, unsigned char addr[6]); -static void find_ie_mem_size(int unit); -static int command_and_wait(int unit, int command, void volatile *pcmd, int); -static int ierint(int unit, struct ie_softc *ie); -static int ietint(int unit, struct ie_softc *ie); -static int iernr(int unit, struct ie_softc *ie); -static void start_receiver(int unit); -static int ieget(int, struct ie_softc *, struct mbuf **, - struct ether_header *, int *); -static caddr_t setup_rfa(caddr_t ptr, struct ie_softc *ie); -static int mc_setup(int, caddr_t, volatile struct ie_sys_ctl_block *); -#ifdef MULTICAST -static void ie_mc_reset(int unit); -#endif - -#ifdef DEBUG -void print_rbd(volatile struct ie_recv_buf_desc *rbd); - -int in_ierint = 0; -int in_ietint = 0; -#endif - -/* - * This tells the autoconf code how to set us up. - */ -struct isa_driver iedriver = { - ieprobe, ieattach, "ie", -}; - -enum ie_hardware { - IE_STARLAN10, - IE_EN100, - IE_SLFIBER, - IE_UNKNOWN -}; - -const char *ie_hardware_names[] = { - "StarLAN 10", - "EN100", - "StarLAN Fiber", - "Unknown" -}; - -/* -sizeof(iscp) == 1+1+2+4 == 8 -sizeof(scb) == 2+2+2+2+2+2+2+2 == 16 -NFRAMES * sizeof(rfd) == NFRAMES*(2+2+2+2+6+6+2+2) == NFRAMES*24 == 384 -sizeof(xmit_cmd) == 2+2+2+2+6+2 == 18 -sizeof(transmit buffer) == 1512 -sizeof(transmit buffer desc) == 8 ------ -1946 - -NBUFFS * sizeof(rbd) == NBUFFS*(2+2+4+2+2) == NBUFFS*12 -NBUFFS * IE_RBUF_SIZE == NBUFFS*256 - -NBUFFS should be (16384 - 1946) / (256 + 12) == 14438 / 268 == 53 - -With NBUFFS == 48, this leaves us 1574 bytes for another command or -more buffers. Another transmit command would be 18+8+1512 == 1538 ----just barely fits! - -Obviously all these would have to be reduced for smaller memory sizes. -With a larger memory, it would be possible to roughly double the number of -both transmit and receive buffers. -*/ - -#define NFRAMES 16 /* number of frames to allow for receive */ -#define NBUFFS 48 /* number of buffers to allocate */ -#define IE_RBUF_SIZE 256 /* size of each buffer, MUST BE POWER OF TWO */ - -/* - * Ethernet status, per interface. - */ -struct ie_softc { - struct arpcom arpcom; - void (*ie_reset_586)(int); - void (*ie_chan_attn)(int); - enum ie_hardware hard_type; - int hard_vers; - - u_short port; - caddr_t iomem; - caddr_t iomembot; - unsigned iosize; - - int want_mcsetup; - int promisc; - volatile struct ie_int_sys_conf_ptr *iscp; - volatile struct ie_sys_ctl_block *scb; - volatile struct ie_recv_frame_desc *rframes[NFRAMES]; - volatile struct ie_recv_buf_desc *rbuffs[NBUFFS]; - volatile char *cbuffs[NBUFFS]; - int rfhead, rftail, rbhead, rbtail; - - volatile struct ie_xmit_cmd *xmit_cmds[2]; - volatile struct ie_xmit_buf *xmit_buffs[2]; - int xmit_count; - u_char *xmit_cbuffs[2]; - - struct ie_en_addr mcast_addrs[MAXMCAST + 1]; - int mcast_count; - -#if NBPFILTER > 0 - caddr_t ie_bpf; -#endif - -} ie_softc[NIE]; - -#define MK_24(base, ptr) ((caddr_t)((u_long)ptr - (u_long)base)) -#define MK_16(base, ptr) ((u_short)(u_long)MK_24(base, ptr)) - -#define PORT ie_softc[unit].port -#define MEM ie_softc[unit].iomem - - -int ieprobe(dvp) - struct isa_device *dvp; -{ - int unit = dvp->id_unit; - u_char c; - - ie_softc[unit].port = dvp->id_iobase; - ie_softc[unit].iomembot = dvp->id_maddr; - ie_softc[unit].iomem = 0; - - c = inb(PORT + IEATT_REVISION); - switch(SL_BOARD(c)) { - case SL10_BOARD: - ie_softc[unit].hard_type = IE_STARLAN10; - ie_softc[unit].ie_reset_586 = sl_reset_586; - ie_softc[unit].ie_chan_attn = sl_chan_attn; - break; - case EN100_BOARD: - ie_softc[unit].hard_type = IE_EN100; - ie_softc[unit].ie_reset_586 = sl_reset_586; - ie_softc[unit].ie_chan_attn = sl_chan_attn; - break; - case SLFIBER_BOARD: - ie_softc[unit].hard_type = IE_SLFIBER; - ie_softc[unit].ie_reset_586 = sl_reset_586; - ie_softc[unit].ie_chan_attn = sl_chan_attn; - break; - - /* - * Anything else is not recognized or cannot be used. - */ - default: - return 0; - } - - ie_softc[unit].hard_vers = SL_REV(c); - - /* - * Divine memory size on-board the card. Ususally 16k. - */ - find_ie_mem_size(unit); - - if(!ie_softc[unit].iosize) { - return 0; - } - - dvp->id_msize = ie_softc[unit].iosize; - - switch(ie_softc[unit].hard_type) { - case IE_EN100: - case IE_STARLAN10: - case IE_SLFIBER: - sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); - break; - - default: - printf("ie%d: unknown AT&T board type code %d\n", unit, - ie_softc[unit].hard_type); - return 0; - } - - return 1; -} - -/* - * Taken almost exactly from Bill's if_is.c, then modified beyond recognition. - */ -int -ieattach(dvp) - struct isa_device *dvp; -{ - int unit = dvp->id_unit; - struct ie_softc *ie = &ie_softc[unit]; - struct ifnet *ifp = &ie->arpcom.ac_if; - - ifp->if_unit = unit; - ifp->if_name = iedriver.name; - ifp->if_mtu = ETHERMTU; - printf("<%s R%d> ethernet address %s", - ie_hardware_names[ie_softc[unit].hard_type], - ie_softc[unit].hard_vers + 1, - ether_sprintf(ie->arpcom.ac_enaddr)); - - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS; -#ifdef MULTICAST - ifp->if_flags |= IFF_MULTICAST; -#endif /* MULTICAST */ - - ifp->if_init = ieinit; - ifp->if_output = ether_output; - ifp->if_start = iestart; - ifp->if_ioctl = ieioctl; - ifp->if_reset = iereset; - ifp->if_type = IFT_ETHER; - ifp->if_addrlen = 6; - ifp->if_hdrlen = 14; - -#if NBPFILTER > 0 - printf("\n"); - bpfattach(&ie_softc[unit].ie_bpf, ifp, DLT_EN10MB, - sizeof(struct ether_header)); -#endif - - if_attach(ifp); - { - struct ifaddr *ifa = ifp->if_addrlist; - struct sockaddr_dl *sdl; - while(ifa && ifa->ifa_addr && ifa->ifa_addr->sa_family != AF_LINK) - ifa = ifa->ifa_next; - - if(!ifa || !ifa->ifa_addr) return; - - /* Provide our ether address to the higher layers */ - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = 6; - sdl->sdl_slen = 0; - bcopy(ie->arpcom.ac_enaddr, LLADDR(sdl), 6); - } -} - -/* - * What to do upon receipt of an interrupt. - */ -int ieintr(unit) - int unit; -{ - register struct ie_softc *ie = &ie_softc[unit]; - register u_short status; - - status = ie->scb->ie_status; - -loop: - if(status & (IE_ST_RECV | IE_ST_RNR)) { -#ifdef DEBUG - in_ierint++; - if(ie_debug & IED_RINT) - printf("ie%d: rint\n", unit); -#endif - ierint(unit, ie); -#ifdef DEBUG - in_ierint--; -#endif - } - - if(status & IE_ST_DONE) { -#ifdef DEBUG - in_ietint++; - if(ie_debug & IED_TINT) - printf("ie%d: tint\n", unit); -#endif - ietint(unit, ie); -#ifdef DEBUG - in_ietint--; -#endif - } - - if(status & IE_ST_RNR) { -#ifdef DEBUG - if(ie_debug & IED_RNR) - printf("ie%d: rnr\n", unit); -#endif - iernr(unit, ie); - } - -#ifdef DEBUG - if((status & IE_ST_ALLDONE) - && (ie_debug & IED_CNA)) - printf("ie%d: cna\n", unit); -#endif - - /* Don't ack interrupts which we didn't receive */ - ie_ack(ie->scb, IE_ST_WHENCE & status, unit, ie->ie_chan_attn); - - if((status = ie->scb->ie_status) & IE_ST_WHENCE) - goto loop; - - return unit; -} - -/* - * Process a received-frame interrupt. - */ -static int ierint(unit, ie) - int unit; - struct ie_softc *ie; -{ - int i, status; - static int timesthru = 1024; - - i = ie->rfhead; - while(1) { - status = ie->rframes[i]->ie_fd_status; - - if((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) { - ie->arpcom.ac_if.if_ipackets++; - if(!--timesthru) { - ie->arpcom.ac_if.if_ierrors += ie->scb->ie_err_crc + ie->scb->ie_err_align + - ie->scb->ie_err_resource + ie->scb->ie_err_overrun; - ie->scb->ie_err_crc = 0; - ie->scb->ie_err_align = 0; - ie->scb->ie_err_resource = 0; - ie->scb->ie_err_overrun = 0; - timesthru = 1024; - } - ie_readframe(unit, ie, i); - } else { - if(status & IE_FD_RNR) { - if(!(ie->scb->ie_status & IE_RU_READY)) { - ie->rframes[0]->ie_fd_next = MK_16(MEM, ie->rbuffs[0]); - ie->scb->ie_recv_list = MK_16(MEM, ie->rframes[0]); - command_and_wait(unit, IE_RU_START, 0, 0); - } - } - break; - } - i = (i + 1) % NFRAMES; - } - return 0; -} - -/* - * Process a command-complete interrupt. These are only generated by - * the transmission of frames. This routine is deceptively simple, since - * most of the real work is done by iestart(). - */ -static int ietint(unit, ie) - int unit; - struct ie_softc *ie; -{ - int status; - int i; - - ie->arpcom.ac_if.if_timer = 0; - ie->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; - - for(i = 0; i < ie->xmit_count; i++) { - status = ie->xmit_cmds[i]->ie_xmit_status; - - if(status & IE_XS_LATECOLL) { - printf("ie%d: late collision\n", unit); - ie->arpcom.ac_if.if_collisions++; - ie->arpcom.ac_if.if_oerrors++; - } else if(status & IE_XS_NOCARRIER) { - printf("ie%d: no carrier\n", unit); - ie->arpcom.ac_if.if_oerrors++; - } else if(status & IE_XS_LOSTCTS) { - printf("ie%d: lost CTS\n", unit); - ie->arpcom.ac_if.if_oerrors++; - } else if(status & IE_XS_UNDERRUN) { - printf("ie%d: DMA underrun\n", unit); - ie->arpcom.ac_if.if_oerrors++; - } else if(status & IE_XS_EXCMAX) { - printf("ie%d: too many collisions\n", unit); - ie->arpcom.ac_if.if_collisions += 16; - ie->arpcom.ac_if.if_oerrors++; - } else { - ie->arpcom.ac_if.if_opackets++; - ie->arpcom.ac_if.if_collisions += status & IE_XS_MAXCOLL; - } - } - ie->xmit_count = 0; - - /* - * If multicast addresses were added or deleted while we were transmitting, - * ie_mc_reset() set the want_mcsetup flag indicating that we should do it. - */ - if(ie->want_mcsetup) { - mc_setup(unit, (caddr_t)ie->xmit_cbuffs[0], ie->scb); - ie->want_mcsetup = 0; - } - - /* Wish I knew why this seems to be necessary... */ - ie->xmit_cmds[0]->ie_xmit_status |= IE_STAT_COMPL; - - iestart(&ie->arpcom.ac_if); - return 0; /* shouldn't be necessary */ -} - -/* - * Process a receiver-not-ready interrupt. I believe that we get these - * when there aren't enough buffers to go around. For now (FIXME), we - * just restart the receiver, and hope everything's ok. - */ -static int iernr(unit, ie) - int unit; - struct ie_softc *ie; -{ -#ifdef doesnt_work - setup_rfa((caddr_t)ie->rframes[0], ie); - - ie->scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); - command_and_wait(unit, IE_RU_START, 0, 0); -#else - /* This doesn't work either, but it doesn't hang either. */ - command_and_wait(unit, IE_RU_DISABLE, 0, 0); /* just in case */ - setup_rfa((caddr_t)ie->rframes[0], ie); /* ignore cast-qual */ - - ie->scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); - command_and_wait(unit, IE_RU_START, 0, 0); /* was ENABLE */ - -#endif - ie_ack(ie->scb, IE_ST_WHENCE, unit, ie->ie_chan_attn); - - ie->arpcom.ac_if.if_ierrors++; - return 0; -} - -#ifdef FILTER -/* - * Compare two Ether/802 addresses for equality, inlined and - * unrolled for speed. I'd love to have an inline assembler - * version of this... - */ -static inline int ether_equal(u_char *one, u_char *two) { - if(one[0] != two[0]) return 0; - if(one[1] != two[1]) return 0; - if(one[2] != two[2]) return 0; - if(one[3] != two[3]) return 0; - if(one[4] != two[4]) return 0; - if(one[5] != two[5]) return 0; - return 1; -} - -/* - * Check for a valid address. to_bpf is filled in with one of the following: - * 0 -> BPF doesn't get this packet - * 1 -> BPF does get this packet - * 2 -> BPF does get this packet, but we don't - * Return value is true if the packet is for us, and false otherwise. - * - * This routine is a mess, but it's also critical that it be as fast - * as possible. It could be made cleaner if we can assume that the - * only client which will fiddle with IFF_PROMISC is BPF. This is - * probably a good assumption, but we do not make it here. (Yet.) - */ -static inline int check_eh(struct ie_softc *ie, - struct ether_header *eh, - int *to_bpf) { - int i; - - switch(ie->promisc) { - case IFF_ALLMULTI: - /* - * Receiving all multicasts, but no unicasts except those destined for us. - */ -#if NBPFILTER > 0 - *to_bpf = (ie->ie_bpf != 0); /* BPF gets this packet if anybody cares */ -#endif - if(eh->ether_dhost[0] & 1) { - return 1; - } - if(ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return 1; - return 0; - - case IFF_PROMISC: - /* - * Receiving all packets. These need to be passed on to BPF. - */ -#if NBPFILTER > 0 - *to_bpf = (ie->ie_bpf != 0); -#endif - /* If for us, accept and hand up to BPF */ - if(ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return 1; - -#if NBPFILTER > 0 - if(*to_bpf) *to_bpf = 2; /* we don't need to see it */ -#endif - -#ifdef MULTICAST - /* - * Not a multicast, so BPF wants to see it but we don't. - */ - if(!(eh->ether_dhost[0] & 1)) return 1; - - /* - * If it's one of our multicast groups, accept it and pass it - * up. - */ - for(i = 0; i < ie->mcast_count; i++) { - if(ether_equal(eh->ether_dhost, (u_char *)&ie->mcast_addrs[i])) { -#if NBPFILTER > 0 - if(*to_bpf) *to_bpf = 1; -#endif - return 1; - } - } -#endif /* MULTICAST */ - return 1; - - case IFF_ALLMULTI | IFF_PROMISC: - /* - * Acting as a multicast router, and BPF running at the same time. - * Whew! (Hope this is a fast machine...) - */ -#if NBPFILTER > 0 - *to_bpf = (ie->ie_bpf != 0); -#endif - /* We want to see multicasts. */ - if(eh->ether_dhost[0] & 1) return 1; - - /* We want to see our own packets */ - if(ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return 1; - - /* Anything else goes to BPF but nothing else. */ -#if NBPFILTER > 0 - if(*to_bpf) *to_bpf = 2; -#endif - return 1; - - default: - /* - * Only accept unicast packets destined for us, or multicasts - * for groups that we belong to. For now, we assume that the - * '586 will only return packets that we asked it for. This - * isn't strictly true (it uses hashing for the multicast filter), - * but it will do in this case, and we want to get out of here - * as quickly as possible. - */ -#if NBPFILTER > 0 - *to_bpf = (ie->ie_bpf != 0); -#endif - return 1; - } - return 0; -} -#endif /* FILTER */ - -/* - * We want to isolate the bits that have meaning... This assumes that - * IE_RBUF_SIZE is an even power of two. If somehow the act_len exceeds - * the size of the buffer, then we are screwed anyway. - */ -static inline int ie_buflen(struct ie_softc *ie, int head) { - return (ie->rbuffs[head]->ie_rbd_actual - & (IE_RBUF_SIZE | (IE_RBUF_SIZE - 1))); -} - -static inline int ie_packet_len(int unit, struct ie_softc *ie) { - int i; - int head = ie->rbhead; - int acc = 0; - - do { - if(!(ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_USED)) { -#ifdef DEBUG - print_rbd(ie->rbuffs[ie->rbhead]); -#endif - log(LOG_ERR, "ie%d: receive descriptors out of sync at %d\n", - unit, ie->rbhead); - iereset(unit, 0); - return -1; - } - - i = ie->rbuffs[head]->ie_rbd_actual & IE_RBD_LAST; - - acc += ie_buflen(ie, head); - head = (head + 1) % NBUFFS; - } while(!i); - - return acc; -} - -/* - * Read data off the interface, and turn it into an mbuf chain. - * - * This code is DRAMATICALLY different from the previous version; this - * version tries to allocate the entire mbuf chain up front, given the - * length of the data available. This enables us to allocate mbuf - * clusters in many situations where before we would have had a long - * chain of partially-full mbufs. This should help to speed up the - * operation considerably. (Provided that it works, of course.) - */ -static inline int ieget(unit, ie, mp, ehp, to_bpf) - int unit; - struct ie_softc *ie; - struct mbuf **mp; - struct ether_header *ehp; - int *to_bpf; -{ - struct mbuf *m, *top, **mymp; - int i; - int offset; - int totlen, resid; - int thismboff; - int head; - - totlen = ie_packet_len(unit, ie); - if(totlen <= 0) return -1; - - i = ie->rbhead; - - /* - * Snarf the Ethernet header. - */ - bcopy((caddr_t)ie->cbuffs[i], (caddr_t)ehp, sizeof *ehp); - /* ignore cast-qual warning here */ - - /* - * As quickly as possible, check if this packet is for us. - * If not, don't waste a single cycle copying the rest of the - * packet in. - * This is only a consideration when FILTER is defined; i.e., when - * we are either running BPF or doing multicasting. - */ -#ifdef FILTER - if(!check_eh(ie, ehp, to_bpf)) { - ie_drop_packet_buffer(unit, ie); - ie->arpcom.ac_if.if_ierrors--; /* just this case, it's not an error */ - return -1; - } -#endif - totlen -= (offset = sizeof *ehp); - - MGETHDR(*mp, M_DONTWAIT, MT_DATA); - if(!*mp) { - ie_drop_packet_buffer(unit, ie); - return -1; - } - - m = *mp; - m->m_pkthdr.rcvif = &ie->arpcom.ac_if; - m->m_len = MHLEN; - resid = m->m_pkthdr.len = totlen; - top = 0; - mymp = ⊤ - - /* - * This loop goes through and allocates mbufs for all the data we will - * be copying in. It does not actually do the copying yet. - */ - do { /* while(resid > 0) */ - /* - * Try to allocate an mbuf to hold the data that we have. If we - * already allocated one, just get another one and stick it on the - * end (eventually). If we don't already have one, try to allocate - * an mbuf cluster big enough to hold the whole packet, if we think it's - * reasonable, or a single mbuf which may or may not be big enough. - * Got that? - */ - if(top) { - MGET(m, M_DONTWAIT, MT_DATA); - if(!m) { - m_freem(top); - ie_drop_packet_buffer(unit, ie); - return -1; - } - m->m_len = MLEN; - } - - if(resid >= MINCLSIZE) { - MCLGET(m, M_DONTWAIT); - if(m->m_flags & M_EXT) - m->m_len = min(resid, MCLBYTES); - } else { - if(resid < m->m_len) { - if(!top && resid + max_linkhdr <= m->m_len) - m->m_data += max_linkhdr; - m->m_len = resid; - } - } - resid -= m->m_len; - *mymp = m; - mymp = &m->m_next; - } while(resid > 0); - - resid = totlen; - m = top; - thismboff = 0; - head = ie->rbhead; - - /* - * Now we take the mbuf chain (hopefully only one mbuf most of the - * time) and stuff the data into it. There are no possible failures - * at or after this point. - */ - while(resid > 0) { /* while there's stuff left */ - int thislen = ie_buflen(ie, head) - offset; - - /* - * If too much data for the current mbuf, then fill the current one - * up, go to the next one, and try again. - */ - if(thislen > m->m_len - thismboff) { - int newlen = m->m_len - thismboff; - bcopy((caddr_t)(ie->cbuffs[head] + offset), - mtod(m, caddr_t) + thismboff, (unsigned)newlen); - /* ignore cast-qual warning */ - m = m->m_next; - thismboff = 0; /* new mbuf, so no offset */ - offset += newlen; /* we are now this far into the packet */ - resid -= newlen; /* so there is this much left to get */ - continue; - } - - /* - * If there is more than enough space in the mbuf to hold the - * contents of this buffer, copy everything in, advance pointers, - * and so on. - */ - if(thislen < m->m_len - thismboff) { - bcopy((caddr_t)(ie->cbuffs[head] + offset), /* ignore warning */ - mtod(m, caddr_t) + thismboff, (unsigned)thislen); - thismboff += thislen; /* we are this far into the mbuf */ - resid -= thislen; /* and this much is left */ - goto nextbuf; - } - - /* - * Otherwise, there is exactly enough space to put this buffer's - * contents into the current mbuf. Do the combination of the above - * actions. - */ - bcopy((caddr_t)(ie->cbuffs[head] + offset), /* ignore warning */ - mtod(m, caddr_t) + thismboff, (unsigned)thislen); - m = m->m_next; - thismboff = 0; /* new mbuf, start at the beginning */ - resid -= thislen; /* and we are this far through */ - - /* - * Advance all the pointers. We can get here from either of the - * last two cases, but never the first. - */ -nextbuf: - offset = 0; - ie->rbuffs[head]->ie_rbd_actual = 0; - ie->rbuffs[head]->ie_rbd_length |= IE_RBD_LAST; - ie->rbhead = head = (head + 1) % NBUFFS; - ie->rbuffs[ie->rbtail]->ie_rbd_length &= ~IE_RBD_LAST; - ie->rbtail = (ie->rbtail + 1) % NBUFFS; - } - - /* - * Unless something changed strangely while we were doing the copy, - * we have now copied everything in from the shared memory. - * This means that we are done. - */ - return 0; -} - -/* - * Read frame NUM from unit UNIT (pre-cached as IE). - * - * This routine reads the RFD at NUM, and copies in the buffers from - * the list of RBD, then rotates the RBD and RFD lists so that the receiver - * doesn't start complaining. Trailers are DROPPED---there's no point - * in wasting time on confusing code to deal with them. Hopefully, - * this machine will never ARP for trailers anyway. - */ -static void ie_readframe(unit, ie, num) - int unit; - struct ie_softc *ie; - int num; /* frame number to read */ -{ - struct ie_recv_frame_desc rfd; - struct mbuf *m = 0; - struct ether_header eh; -#if NBPFILTER > 0 - int bpf_gets_it = 0; -#endif - - bcopy((caddr_t)(ie->rframes[num]), &rfd, sizeof(struct ie_recv_frame_desc)); - - /* Immediately advance the RFD list, since we we have copied ours now. */ - ie->rframes[num]->ie_fd_status = 0; - ie->rframes[num]->ie_fd_last |= IE_FD_LAST; - ie->rframes[ie->rftail]->ie_fd_last &= ~IE_FD_LAST; - ie->rftail = (ie->rftail + 1) % NFRAMES; - ie->rfhead = (ie->rfhead + 1) % NFRAMES; - - if(rfd.ie_fd_status & IE_FD_OK) { - if( -#if NBPFILTER > 0 - ieget(unit, ie, &m, &eh, &bpf_gets_it) -#else - ieget(unit, ie, &m, &eh, (int *)0) -#endif - ) { - ie->arpcom.ac_if.if_ierrors++; /* this counts as an error */ - return; - } - } - -#ifdef DEBUG - if(ie_debug & IED_READFRAME) { - printf("ie%d: frame from ether %s type %x\n", unit, - ether_sprintf(eh.ether_shost), (unsigned)eh.ether_type); - } - if(ntohs(eh.ether_type) > ETHERTYPE_TRAIL - && ntohs(eh.ether_type) < (ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER)) - printf("received trailer!\n"); -#endif - - if(!m) return; - -#ifdef FILTER - if(last_not_for_us) { - m_freem(last_not_for_us); - last_not_for_us = 0; - } - -#if NBPFILTER > 0 - /* - * Check for a BPF filter; if so, hand it up. - * Note that we have to stick an extra mbuf up front, because - * bpf_mtap expects to have the ether header at the front. - * It doesn't matter that this results in an ill-formatted mbuf chain, - * since BPF just looks at the data. (It doesn't try to free the mbuf, - * tho' it will make a copy for tcpdump.) - */ - if(bpf_gets_it) { - struct mbuf m0; - m0.m_len = sizeof eh; - m0.m_data = (caddr_t)&eh; - m0.m_next = m; - - /* Pass it up */ - bpf_mtap(ie->ie_bpf, &m0); - } - /* - * A signal passed up from the filtering code indicating that the - * packet is intended for BPF but not for the protocol machinery. - * We can save a few cycles by not handing it off to them. - */ - if(bpf_gets_it == 2) { - last_not_for_us = m; - return; - } -#endif /* NBPFILTER > 0 */ - /* - * In here there used to be code to check destination addresses upon - * receipt of a packet. We have deleted that code, and replaced it - * with code to check the address much earlier in the cycle, before - * copying the data in; this saves us valuable cycles when operating - * as a multicast router or when using BPF. - */ -#endif /* FILTER */ - - eh.ether_type = ntohs(eh.ether_type); - - /* - * Finally pass this packet up to higher layers. - */ - ether_input(&ie->arpcom.ac_if, &eh, m); -} - -static void ie_drop_packet_buffer(int unit, struct ie_softc *ie) { - int i; - - do { - /* - * This means we are somehow out of sync. So, we reset the - * adapter. - */ - if(!(ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_USED)) { -#ifdef DEBUG - print_rbd(ie->rbuffs[ie->rbhead]); -#endif - log(LOG_ERR, "ie%d: receive descriptors out of sync at %d\n", - unit, ie->rbhead); - iereset(unit, 0); - return; - } - - i = ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_LAST; - - ie->rbuffs[ie->rbhead]->ie_rbd_length |= IE_RBD_LAST; - ie->rbuffs[ie->rbhead]->ie_rbd_actual = 0; - ie->rbhead = (ie->rbhead + 1) % NBUFFS; - ie->rbuffs[ie->rbtail]->ie_rbd_length &= ~IE_RBD_LAST; - ie->rbtail = (ie->rbtail + 1) % NBUFFS; - } while(!i); -} - - -/* - * Start transmission on an interface. - */ -int iestart(ifp) - struct ifnet *ifp; -{ - struct ie_softc *ie = &ie_softc[ifp->if_unit]; - struct mbuf *m0, *m; - unsigned char *buffer; - u_short len; - /* This is not really volatile, in this routine, but it makes gcc happy. */ - volatile u_short *bptr = &ie->scb->ie_command_list; - - if(!(ifp->if_flags & IFF_RUNNING)) - return 0; - if(ifp->if_flags & IFF_OACTIVE) - return 0; - - do { - IF_DEQUEUE(&ie->arpcom.ac_if.if_snd, m); - if(!m) - break; - - buffer = ie->xmit_cbuffs[ie->xmit_count]; - len = 0; - - for(m0 = m; m && len < IE_BUF_LEN; m = m->m_next) { - bcopy(mtod(m, caddr_t), buffer, m->m_len); - buffer += m->m_len; - len += m->m_len; - } - - m_freem(m0); - len = MAX(len, ETHERMINLEN); - -#if NBPFILTER > 0 - /* - * See if bpf is listening on this interface, let it see the packet - * before we commit it to the wire. - */ - if(ie->ie_bpf) - bpf_tap(ie->ie_bpf, ie->xmit_cbuffs[ie->xmit_count], len); -#endif - - ie->xmit_buffs[ie->xmit_count]->ie_xmit_flags = IE_XMIT_LAST | len; - ie->xmit_buffs[ie->xmit_count]->ie_xmit_next = 0xffff; - ie->xmit_buffs[ie->xmit_count]->ie_xmit_buf = - MK_24(ie->iomem, ie->xmit_cbuffs[ie->xmit_count]); - - ie->xmit_cmds[ie->xmit_count]->com.ie_cmd_cmd = IE_CMD_XMIT; - ie->xmit_cmds[ie->xmit_count]->ie_xmit_status = 0; - ie->xmit_cmds[ie->xmit_count]->ie_xmit_desc = - MK_16(ie->iomem, ie->xmit_buffs[ie->xmit_count]); - - *bptr = MK_16(ie->iomem, ie->xmit_cmds[ie->xmit_count]); - bptr = &ie->xmit_cmds[ie->xmit_count]->com.ie_cmd_link; - ie->xmit_count++; - } while(ie->xmit_count < 2); - - /* - * If we queued up anything for transmission, send it. - */ - if(ie->xmit_count) { - ie->xmit_cmds[ie->xmit_count - 1]->com.ie_cmd_cmd |= - IE_CMD_LAST | IE_CMD_INTR; - - /* - * By passing the command pointer as a null, we tell - * command_and_wait() to pretend that this isn't an action - * command. I wish I understood what was happening here. - */ - command_and_wait(ifp->if_unit, IE_CU_START, 0, 0); - ifp->if_flags |= IFF_OACTIVE; - } - - return 0; -} - -/* - * Check to see if there's an 82586 out there. - */ -int check_ie_present(unit, where, size) - int unit; - caddr_t where; - unsigned size; -{ - volatile struct ie_sys_conf_ptr *scp; - volatile struct ie_int_sys_conf_ptr *iscp; - volatile struct ie_sys_ctl_block *scb; - u_long realbase; - int s; - - s = splimp(); - - realbase = (u_long)where + size - (1 << 24); - - scp = (volatile struct ie_sys_conf_ptr *)(realbase + IE_SCP_ADDR); - bzero((char *)scp, sizeof *scp); /* ignore cast-qual */ - - /* - * First we put the ISCP at the bottom of memory; this tests to make - * sure that our idea of the size of memory is the same as the controller's. - * This is NOT where the ISCP will be in normal operation. - */ - iscp = (volatile struct ie_int_sys_conf_ptr *)where; - bzero((char *)iscp, sizeof *iscp); /* ignore cast-qual */ - - scb = (volatile struct ie_sys_ctl_block *)where; - bzero((char *)scb, sizeof *scb); /* ignore cast-qual */ - - scp->ie_bus_use = 0; /* 16-bit */ - scp->ie_iscp_ptr = (caddr_t)((volatile caddr_t)iscp - /* ignore cast-qual */ - (volatile caddr_t)realbase); - - iscp->ie_busy = 1; - iscp->ie_scb_offset = MK_16(realbase, scb) + 256; - - (*ie_softc[unit].ie_reset_586)(unit); - (*ie_softc[unit].ie_chan_attn)(unit); - - DELAY(100); /* wait a while... */ - - if(iscp->ie_busy) { - splx(s); - return 0; - } - - /* - * Now relocate the ISCP to its real home, and reset the controller - * again. - */ - iscp = (void *)Align((caddr_t)(realbase + IE_SCP_ADDR - - sizeof(struct ie_int_sys_conf_ptr))); - bzero((char *)iscp, sizeof *iscp); /* ignore cast-qual */ - - scp->ie_iscp_ptr = (caddr_t)((caddr_t)iscp - (caddr_t)realbase); - /* ignore cast-qual */ - - iscp->ie_busy = 1; - iscp->ie_scb_offset = MK_16(realbase, scb); - - (*ie_softc[unit].ie_reset_586)(unit); - (*ie_softc[unit].ie_chan_attn)(unit); - - DELAY(100); - - if(iscp->ie_busy) { - splx(s); - return 0; - } - - ie_softc[unit].iosize = size; - ie_softc[unit].iomem = (caddr_t)realbase; - - ie_softc[unit].iscp = iscp; - ie_softc[unit].scb = scb; - - /* - * Acknowledge any interrupts we may have caused... - */ - ie_ack(scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); - splx(s); - - return 1; -} - -/* - * Divine the memory size of ie board UNIT. - * Better hope there's nothing important hiding just below the ie card... - */ -static void find_ie_mem_size(unit) - int unit; -{ - unsigned size; - - ie_softc[unit].iosize = 0; - - for(size = 65536; size >= 16384; size -= 16384) { - if(check_ie_present(unit, ie_softc[unit].iomembot, size)) { - return; - } - } - - return; -} - -void sl_reset_586(unit) - int unit; -{ - outb(PORT + IEATT_RESET, 0); -} - -void sl_chan_attn(unit) - int unit; -{ - outb(PORT + IEATT_ATTN, 0); -} - -void sl_read_ether(unit, addr) - int unit; - unsigned char addr[6]; -{ - int i; - - for(i = 0; i < 6; i++) - addr[i] = inb(PORT + i); -} - - -int iereset(unit, dummy) - int unit, dummy; -{ - int s = splimp(); - - if(unit >= NIE) { - splx(s); - return -1; - } - - printf("ie%d: reset\n", unit); - ie_softc[unit].arpcom.ac_if.if_flags &= ~IFF_UP; - ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0); - - /* - * Stop i82586 dead in its tracks. - */ - if(command_and_wait(unit, IE_RU_ABORT | IE_CU_ABORT, 0, 0)) - printf("ie%d: abort commands timed out\n", unit); - - if(command_and_wait(unit, IE_RU_DISABLE | IE_CU_STOP, 0, 0)) - printf("ie%d: disable commands timed out\n", unit); - -#ifdef notdef - if(!check_ie_present(unit, ie_softc[unit].iomembot, ie_softc[unit].iosize)) - panic("ie disappeared!\n"); -#endif - - ie_softc[unit].arpcom.ac_if.if_flags |= IFF_UP; - ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0); - - splx(s); - return 0; -} - -/* - * This is called if we time out. - */ -static int chan_attn_timeout(rock) - caddr_t rock; -{ - *(int *)rock = 1; - return 0; -} - -/* - * Send a command to the controller and wait for it to either - * complete or be accepted, depending on the command. If the - * command pointer is null, then pretend that the command is - * not an action command. If the command pointer is not null, - * and the command is an action command, wait for - * ((volatile struct ie_cmd_common *)pcmd)->ie_cmd_status & MASK - * to become true. - */ -static int command_and_wait(unit, cmd, pcmd, mask) - int unit; - int cmd; - volatile void *pcmd; - int mask; -{ - volatile struct ie_cmd_common *cc = pcmd; - volatile int timedout = 0; - extern int hz; - - ie_softc[unit].scb->ie_command = (u_short)cmd; - - if(IE_ACTION_COMMAND(cmd) && pcmd) { - (*ie_softc[unit].ie_chan_attn)(unit); - - /* - * According to the packet driver, the minimum timeout should be - * .369 seconds, which we round up to .37. - */ - timeout(chan_attn_timeout, (caddr_t)&timedout, 37 * hz / 100); - /* ignore cast-qual */ - - /* - * Now spin-lock waiting for status. This is not a very nice - * thing to do, but I haven't figured out how, or indeed if, we - * can put the process waiting for action to sleep. (We may - * be getting called through some other timeout running in the - * kernel.) - */ - while(1) { - if((cc->ie_cmd_status & mask) || timedout) - break; - } - - untimeout(chan_attn_timeout, (caddr_t)&timedout); - /* ignore cast-qual */ - - return timedout; - } else { - - /* - * Otherwise, just wait for the command to be accepted. - */ - (*ie_softc[unit].ie_chan_attn)(unit); - - while(ie_softc[unit].scb->ie_command) - ; /* spin lock */ - - return 0; - } -} - -/* - * Run the time-domain reflectometer... - */ -static void run_tdr(unit, cmd) - int unit; - struct ie_tdr_cmd *cmd; -{ - int result; - - cmd->com.ie_cmd_status = 0; - cmd->com.ie_cmd_cmd = IE_CMD_TDR | IE_CMD_LAST; - cmd->com.ie_cmd_link = 0xffff; - cmd->ie_tdr_time = 0; - - ie_softc[unit].scb->ie_command_list = MK_16(MEM, cmd); - cmd->ie_tdr_time = 0; - - if(command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL)) - result = 0x2000; - else - result = cmd->ie_tdr_time; - - ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, - ie_softc[unit].ie_chan_attn); - - if(result & IE_TDR_SUCCESS) - return; - - if(result & IE_TDR_XCVR) { - printf("ie%d: transceiver problem\n", unit); - } else if(result & IE_TDR_OPEN) { - printf("ie%d: TDR detected an open %d clocks away\n", unit, - result & IE_TDR_TIME); - } else if(result & IE_TDR_SHORT) { - printf("ie%d: TDR detected a short %d clocks away\n", unit, - result & IE_TDR_TIME); - } else { - printf("ie%d: TDR returned unknown status %x\n", result); - } -} - -static void start_receiver(unit) - int unit; -{ - int s = splimp(); - - ie_softc[unit].scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); - command_and_wait(unit, IE_RU_START, 0, 0); - - ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); - - splx(s); -} - -/* - * Here is a helper routine for iernr() and ieinit(). This sets up - * the RFA. - */ -static caddr_t setup_rfa(caddr_t ptr, struct ie_softc *ie) { - volatile struct ie_recv_frame_desc *rfd = (void *)ptr; - volatile struct ie_recv_buf_desc *rbd; - int i; - int unit = ie - &ie_softc[0]; - - /* First lay them out */ - for(i = 0; i < NFRAMES; i++) { - ie->rframes[i] = rfd; - bzero((char *)rfd, sizeof *rfd); /* ignore cast-qual */ - rfd++; - } - - ptr = (caddr_t)Align((caddr_t)rfd); /* ignore cast-qual */ - - /* Now link them together */ - for(i = 0; i < NFRAMES; i++) { - ie->rframes[i]->ie_fd_next = - MK_16(MEM, ie->rframes[(i + 1) % NFRAMES]); - } - - /* Finally, set the EOL bit on the last one. */ - ie->rframes[NFRAMES - 1]->ie_fd_last |= IE_FD_LAST; - - /* - * Now lay out some buffers for the incoming frames. Note that - * we set aside a bit of slop in each buffer, to make sure that - * we have enough space to hold a single frame in every buffer. - */ - rbd = (void *)ptr; - - for(i = 0; i < NBUFFS; i++) { - ie->rbuffs[i] = rbd; - bzero((char *)rbd, sizeof *rbd); /* ignore cast-qual */ - ptr = (caddr_t)Align(ptr + sizeof *rbd); - rbd->ie_rbd_length = IE_RBUF_SIZE; - rbd->ie_rbd_buffer = MK_24(MEM, ptr); - ie->cbuffs[i] = (void *)ptr; - ptr += IE_RBUF_SIZE; - rbd = (void *)ptr; - } - - /* Now link them together */ - for(i = 0; i < NBUFFS; i++) { - ie->rbuffs[i]->ie_rbd_next = MK_16(MEM, ie->rbuffs[(i + 1) % NBUFFS]); - } - - /* Tag EOF on the last one */ - ie->rbuffs[NBUFFS - 1]->ie_rbd_length |= IE_RBD_LAST; - - /* We use the head and tail pointers on receive to keep track of - * the order in which RFDs and RBDs are used. */ - ie->rfhead = 0; - ie->rftail = NFRAMES - 1; - ie->rbhead = 0; - ie->rbtail = NBUFFS - 1; - - ie->scb->ie_recv_list = MK_16(MEM, ie->rframes[0]); - ie->rframes[0]->ie_fd_buf_desc = MK_16(MEM, ie->rbuffs[0]); - - ptr = Align(ptr); - return ptr; -} - -/* - * Run the multicast setup command. - * Call at splimp(). - */ -static int mc_setup(int unit, caddr_t ptr, - volatile struct ie_sys_ctl_block *scb) { - struct ie_softc *ie = &ie_softc[unit]; - volatile struct ie_mcast_cmd *cmd = (void *)ptr; - - cmd->com.ie_cmd_status = 0; - cmd->com.ie_cmd_cmd = IE_CMD_MCAST | IE_CMD_LAST; - cmd->com.ie_cmd_link = 0xffff; - - /* ignore cast-qual */ - bcopy((caddr_t)ie->mcast_addrs, (caddr_t)cmd->ie_mcast_addrs, - ie->mcast_count * sizeof *ie->mcast_addrs); - - cmd->ie_mcast_bytes = ie->mcast_count * 6; /* grrr... */ - - scb->ie_command_list = MK_16(MEM, cmd); - if(command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) - || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { - printf("ie%d: multicast address setup command failed\n", unit); - return 0; - } - return 1; -} - -/* - * This routine takes the environment generated by check_ie_present() - * and adds to it all the other structures we need to operate the adapter. - * This includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands, - * starting the receiver unit, and clearing interrupts. - * - * THIS ROUTINE MUST BE CALLED AT splimp() OR HIGHER. - */ -int ieinit(unit) - int unit; -{ - struct ie_softc *ie = &ie_softc[unit]; - volatile struct ie_sys_ctl_block *scb = ie->scb; - caddr_t ptr; - - ptr = (caddr_t)Align((caddr_t)scb + sizeof *scb); /* ignore cast-qual */ - - /* - * Send the configure command first. - */ - { - volatile struct ie_config_cmd *cmd = (void *)ptr; - - ie_setup_config(cmd, ie->promisc, ie->hard_type == IE_STARLAN10); - cmd->com.ie_cmd_status = 0; - cmd->com.ie_cmd_cmd = IE_CMD_CONFIG | IE_CMD_LAST; - cmd->com.ie_cmd_link = 0xffff; - - scb->ie_command_list = MK_16(MEM, cmd); - - if(command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) - || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { - printf("ie%d: configure command failed\n", unit); - return 0; - } - } - /* - * Now send the Individual Address Setup command. - */ - { - volatile struct ie_iasetup_cmd *cmd = (void *)ptr; - - cmd->com.ie_cmd_status = 0; - cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST; - cmd->com.ie_cmd_link = 0xffff; - - bcopy((char *)ie_softc[unit].arpcom.ac_enaddr, (char *)&cmd->ie_address, - sizeof cmd->ie_address); /* ignore cast-qual */ - - scb->ie_command_list = MK_16(MEM, cmd); - if(command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) - || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { - printf("ie%d: individual address setup command failed\n", unit); - return 0; - } - } - - /* - * Now run the time-domain reflectometer. - */ - run_tdr(unit, (void *)ptr); - - /* - * Acknowledge any interrupts we have generated thus far. - */ - ie_ack(ie->scb, IE_ST_WHENCE, unit, ie->ie_chan_attn); - - /* - * Set up the RFA. - */ - ptr = setup_rfa(ptr, ie); - - /* - * Finally, the transmit command and buffer are the last little bit of work. - */ - ie->xmit_cmds[0] = (void *)ptr; - ptr += sizeof *ie->xmit_cmds[0]; - ptr = Align(ptr); - ie->xmit_buffs[0] = (void *)ptr; - ptr += sizeof *ie->xmit_buffs[0]; - ptr = Align(ptr); - - /* Second transmit command */ - ie->xmit_cmds[1] = (void *)ptr; - ptr += sizeof *ie->xmit_cmds[1]; - ptr = Align(ptr); - ie->xmit_buffs[1] = (void *)ptr; - ptr += sizeof *ie->xmit_buffs[1]; - ptr = Align(ptr); - - /* Both transmit buffers */ - ie->xmit_cbuffs[0] = (void *)ptr; - ptr += IE_BUF_LEN; - ptr = Align(ptr); - ie->xmit_cbuffs[1] = (void *)ptr; - - bzero((caddr_t)ie->xmit_cmds[0], sizeof *ie->xmit_cmds[0]); /* ignore */ - bzero((caddr_t)ie->xmit_buffs[0], sizeof *ie->xmit_buffs[0]); /* cast-qual */ - bzero((caddr_t)ie->xmit_cmds[1], sizeof *ie->xmit_cmds[0]); /* warnings */ - bzero((caddr_t)ie->xmit_buffs[1], sizeof *ie->xmit_buffs[0]); /* here */ - - /* - * This must be coordinated with iestart() and ietint(). - */ - ie->xmit_cmds[0]->ie_xmit_status = IE_STAT_COMPL; - - ie->arpcom.ac_if.if_flags |= IFF_RUNNING; /* tell higher levels that we are here */ - start_receiver(unit); - return 0; -} - -static void ie_stop(unit) - int unit; -{ - command_and_wait(unit, IE_RU_DISABLE, 0, 0); -} - -int ieioctl(ifp, command, data) - struct ifnet *ifp; - int command; - void *data; -{ - struct ifaddr *ifa = (struct ifaddr *)data; - struct ie_softc *ie = &ie_softc[ifp->if_unit]; - int s, error = 0; - - s = splimp(); - - switch(command) { - case SIOCSIFADDR: - ifp->if_flags |= IFF_UP; - - switch(ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - ieinit(ifp->if_unit); - ((struct arpcom *)ifp)->ac_ipaddr = - IA_SIN(ifa)->sin_addr; - arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); - break; -#endif /* INET */ - -#ifdef NS - /* This magic copied from if_is.c; I don't use XNS, so I have no - * way of telling if this actually works or not. - */ - case AF_NS: - { - struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); - - if(ns_nullhost(*ina)) { - ina->x_host = *(union ns_host *)(ie->arpcom.ac_enaddr); - } else { - ifp->if_flags &= ~IFF_RUNNING; - bcopy((caddr_t)ina->x_host.c_host, - (caddr_t)ie->arpcom.ac_enaddr, - sizeof ie->arpcom.ac_enaddr); - } - - ieinit(ifp->if_unit); - } - break; -#endif /* NS */ - - default: - ieinit(ifp->if_unit); - break; - } - break; - - case SIOCSIFFLAGS: - /* - * Note that this device doesn't have an "all multicast" mode, so we - * must turn on promiscuous mode and do the filtering manually. - */ - if((ifp->if_flags & IFF_UP) == 0 && - (ifp->if_flags & IFF_RUNNING)) { - ifp->if_flags &= ~IFF_RUNNING; - ie_stop(ifp->if_unit); - } else if((ifp->if_flags & IFF_UP) && - (ifp->if_flags & IFF_RUNNING) == 0) { - ie_softc[ifp->if_unit].promisc = - ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI); - ieinit(ifp->if_unit); - } else if(ie_softc[ifp->if_unit].promisc ^ - (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))) { - ie_softc[ifp->if_unit].promisc = - ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI); - ieinit(ifp->if_unit); - } - break; - -#ifdef MULTICAST - case SIOCADDMULTI: - case SIOCDELMULTI: - /* - * Update multicast listeners - */ - error = ((command == SIOCADDMULTI) - ? ether_addmulti((struct ifreq *)data, &ie->arpcom) - : ether_delmulti((struct ifreq *)data, &ie->arpcom)); - - if(error == ENETRESET) { - /* reset multicast filtering */ - ie_mc_reset(ifp->if_unit); - error = 0; - } - break; -#endif /* MULTICAST */ - - default: - error = EINVAL; - } - - splx(s); - return error; -} - -#ifdef MULTICAST -static void ie_mc_reset(int unit) { - struct ie_softc *ie = &ie_softc[unit]; - struct ether_multi *enm; - struct ether_multistep step; - - /* - * Step through the list of addresses. - */ - ie->mcast_count = 0; - ETHER_FIRST_MULTI(step, &ie->arpcom, enm); - while(enm) { - if(ie->mcast_count >= MAXMCAST - || bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) { - ie->arpcom.ac_if.if_flags |= IFF_ALLMULTI; - ieioctl(&ie->arpcom.ac_if, SIOCSIFFLAGS, (void *)0); - goto setflag; - } - - bcopy(enm->enm_addrlo, &(ie->mcast_addrs[ie->mcast_count]), 6); - ie->mcast_count++; - ETHER_NEXT_MULTI(step, enm); - } - -setflag: - ie->want_mcsetup = 1; -} - -#endif - -#ifdef DEBUG -void print_rbd(volatile struct ie_recv_buf_desc *rbd) { - printf("RBD at %08lx:\n" - "actual %04x, next %04x, buffer %08x\n" - "length %04x, mbz %04x\n", - (unsigned long)rbd, - rbd->ie_rbd_actual, rbd->ie_rbd_next, rbd->ie_rbd_buffer, - rbd->ie_rbd_length, rbd->mbz); -} -#endif /* DEBUG */ -#endif /* NIE > 0 */ - diff --git a/sys/i386/isa/if_iereg.h b/sys/i386/isa/if_iereg.h deleted file mode 100644 index 3588b84..0000000 --- a/sys/i386/isa/if_iereg.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * $Id$ - * definitions for AT&T StarLAN 10 etc... - */ - -#define IEATT_RESET 0 /* any write here resets the 586 */ -#define IEATT_ATTN 1 /* any write here sends a Chan attn */ -#define IEATT_REVISION 6 /* read here to figure out this board */ -#define IEATT_ATTRIB 7 /* more information about this board */ - -#define SL_BOARD(x) ((x) & 0x0f) -#define SL_REV(x) ((x) >> 4) - -#define SL1_BOARD 0 -#define SL10_BOARD 1 -#define EN100_BOARD 2 -#define SLFIBER_BOARD 3 - -#define SL_ATTR_WIDTH 0x04 /* bus width: clear -> 8-bit */ -#define SL_ATTR_SPEED 0x08 /* medium speed: clear -> 10 Mbps */ -#define SL_ATTR_CODING 0x10 /* encoding: clear -> Manchester */ -#define SL_ATTR_HBW 0x20 /* host bus width: clear -> 16-bit */ -#define SL_ATTR_TYPE 0x40 /* medium type: clear -> Ethernet */ -#define SL_ATTR_BOOTROM 0x80 /* set -> boot ROM present */ diff --git a/sys/i386/isa/if_is.c b/sys/i386/isa/if_is.c deleted file mode 100644 index ceb8401..0000000 --- a/sys/i386/isa/if_is.c +++ /dev/null @@ -1,1008 +0,0 @@ -/* - * Isolan AT 4141-0 Ethernet driver - * Isolink 4110 - * - * By Paul Richards - * - * Copyright (C) 1993, Paul Richards. This software may be used, modified, - * copied, distributed, and sold, in both source and binary form provided - * that the above copyright and these terms are retained. Under no - * circumstances is the author responsible for the proper functioning - * of this software, nor does the author assume any responsibility - * for damages incurred with its use. - * -*/ - -/* TODO - -1) Add working multicast support -2) Use better allocation of memory to card -3) Advertise for more packets until all transmit buffers are full -4) Add more of the timers/counters e.g. arpcom.opackets etc. -*/ - -#include "is.h" -#if NIS > 0 - -#include "bpfilter.h" - -#include "param.h" -#include "systm.h" -#include "errno.h" -#include "ioctl.h" -#include "mbuf.h" -#include "socket.h" -#include "syslog.h" - -#include "net/if.h" -#include "net/if_dl.h" -#include "net/if_types.h" -#include "net/netisr.h" - -#ifdef INET -#include "netinet/in.h" -#include "netinet/in_systm.h" -#include "netinet/in_var.h" -#include "netinet/ip.h" -#include "netinet/if_ether.h" -#endif - -#ifdef NS -#include "netns/ns.h" -#include "netns/ns_if.h" -#endif - -#if NBPFILTER > 0 -#include "net/bpf.h" -#include "net/bpfdesc.h" -#endif - -#include "i386/isa/isa_device.h" -#include "i386/isa/if_isreg.h" -#include "i386/isa/icu.h" - -#include "vm/vm.h" - - - -#define ETHER_MIN_LEN 64 -#define ETHER_MAX_LEN 1518 -#define ETHER_ADDR_LEN 6 - - -/* - * Ethernet software status per interface. - * - * Each interface is referenced by a network interface structure, - * arpcom.ac_if, which the routing code uses to locate the interface. - * This structure contains the output queue for the interface, its address, ... - */ -struct is_softc { - struct arpcom arpcom; /* Ethernet common part */ - int iobase; /* IO base address of card */ - void *lance_mem; /* Base of memory allocated to card */ - struct mds *rd; - struct mds *td; - unsigned char *rbuf; - unsigned char *tbuf; - int last_rd; - int last_td; - int no_td; - caddr_t bpf; /* BPF "magic cookie" */ - -} is_softc[NIS] ; - -struct init_block init_block[NIS]; - -/* Function prototypes */ -int is_probe(),is_attach(),is_watchdog(); -int is_ioctl(),is_init(),is_start(); - -static inline void is_rint(int unit); -static inline void isread(struct is_softc*, unsigned char*, int); - -struct mbuf *isget(); - -struct isa_driver isdriver = { - is_probe, - is_attach, - "is" -}; - -iswrcsr(unit,port,val) - int unit; - u_short port; - u_short val; -{ - int iobase; - - iobase = is_softc[unit].iobase; - outw(iobase+RAP,port); - outw(iobase+RDP,val); -} - -u_short isrdcsr(unit,port) - int unit; - u_short port; -{ - int iobase; - - iobase = is_softc[unit].iobase; - outw(iobase+RAP,port); - return(inw(iobase+RDP)); -} - -is_probe(isa_dev) - struct isa_device *isa_dev; -{ - int val,i,s; - int unit = isa_dev->id_unit ; - register struct is_softc *is = &is_softc[unit]; - - is->iobase = isa_dev->id_iobase; - - /* Stop the lance chip, put it known state */ - iswrcsr(unit,0,STOP); - DELAY(100); - - /* is there a lance? */ - iswrcsr(unit,3, 0xffff); - if (isrdcsr(unit,3) != 7) { - is->iobase = 0; - return (0); - } - iswrcsr(unit,3, 0); - - /* Extract board address */ - for(i=0;i<ETHER_ADDR_LEN;i++) - is->arpcom.ac_enaddr[i]=inb(is->iobase+(i*2)); - - return (1); -} - - - -/* - * Reset of interface. - */ -int -is_reset(int unit) -{ - int s; - struct is_softc *is = &is_softc[unit]; - - if (unit >= NIS) - return; - s = splnet(); - printf("is%d: reset\n", unit); - is_init(unit); - (void) splx(s); -} - -/* - * Interface exists: make available by filling in network interface - * record. System will initialize the interface when it is ready - * to accept packets. We get the ethernet address here. - */ -int -is_attach(isa_dev) - struct isa_device *isa_dev; -{ - int unit = isa_dev->id_unit; - struct is_softc *is = &is_softc[unit]; - struct ifnet *ifp = &is->arpcom.ac_if; - struct ifaddr *ifa; - struct sockaddr_dl *sdl; - - ifp->if_unit = unit; - ifp->if_name = isdriver.name ; - ifp->if_mtu = ETHERMTU; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS; - ifp->if_init = is_init; - ifp->if_output = ether_output; - ifp->if_start = is_start; - ifp->if_ioctl = is_ioctl; - ifp->if_reset = is_reset; - ifp->if_watchdog = is_watchdog; - - /* - * XXX - Set is->lance_mem to NULL so first pass - * through init_mem it won't try and free memory - * This is getting messy and needs redoing. - * Yes, I know NULL != 0 but it does what I want :-) - */ - - is->lance_mem = NULL; - - /* Set up DMA */ - isa_dmacascade(isa_dev->id_drq); - - if_attach(ifp); - - /* - * Search down the ifa address list looking - * for the AF_LINK type entry - */ - - ifa = ifp->if_addrlist; - while ((ifa != 0) && (ifa->ifa_addr != 0) && - (ifa->ifa_addr->sa_family != AF_LINK)) - ifa = ifa->ifa_next; - - /* - * If we find an AF_LINK type entry, we will fill - * in the hardware address for this interface. - */ - - if ((ifa != 0) && (ifa->ifa_addr != 0)) { - - /* - * Fill in the link level address for this interface - */ - - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = ETHER_ADDR_LEN; - sdl->sdl_slen = 0; - bcopy(is->arpcom.ac_enaddr, LLADDR(sdl), ETHER_ADDR_LEN); - } - - printf ("is%d: address %s\n", unit, - ether_sprintf(is->arpcom.ac_enaddr)) ; - -#if NBPFILTER > 0 - bpfattach(&is->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); -#endif -} - -int -is_watchdog(unit) - int unit; -{ - log(LOG_ERR, "is%d: device timeout\n", unit); - is_reset(unit); -} - - -/* Lance initialisation block set up */ -init_mem(unit) - int unit; -{ - int i; - u_long temp; - struct is_softc *is = &is_softc[unit]; - - /* Allocate memory */ - - /* - * XXX - hopefully have better way to get dma'able memory later, - * this code assumes that the physical memory address returned - * from malloc will be below 16Mb. The Lance's address registers - * are only 16 bits wide! - */ - -#define MAXMEM ((NRBUF+NTBUF)*(BUFSIZE) + (NRBUF+NTBUF)*sizeof(struct mds) + 8) - - /* - * XXX - If we've been here before then free - * the previously allocated memory - */ - if (is->lance_mem) - free(is->lance_mem,M_TEMP); - - is->lance_mem = malloc(MAXMEM,M_TEMP,M_NOWAIT); - if (!is->lance_mem) { - printf("is%d : Couldn't allocate memory for card\n",unit); - return; - } - temp = (u_long) is->lance_mem; - - /* Align message descriptors on quad word boundary - (this is essential) */ - - temp = (temp+8) - (temp%8); - is->rd = (struct mds *) temp; - is->td = (struct mds *) (temp + (NRBUF*sizeof(struct mds))); - temp += (NRBUF+NTBUF) * sizeof(struct mds); - - init_block[unit].mode = 0; - init_block[unit].rdra = kvtop(is->rd); - init_block[unit].rlen = ((kvtop(is->rd) >> 16) & 0xff) | (RLEN<<13); - init_block[unit].tdra = kvtop(is->td); - init_block[unit].tlen = ((kvtop(is->td) >> 16) & 0xff) | (TLEN<<13); - - /* Set up receive ring descriptors */ - - is->rbuf = (unsigned char *)temp; - for (i=0; i<NRBUF; i++) { - (is->rd+i)->addr = kvtop(temp); - (is->rd+i)->flags= ((kvtop(temp) >> 16) & 0xff) | OWN; - (is->rd+i)->bcnt = -BUFSIZE; - (is->rd+i)->mcnt = 0; - temp += BUFSIZE; - } - - /* Set up transmit ring descriptors */ - - is->tbuf = (unsigned char *)temp; - for (i=0; i<NTBUF; i++) { - (is->td+i)->addr = kvtop(temp); - (is->td+i)->flags= ((kvtop(temp) >> 16) & 0xff); - (is->td+i)->bcnt = 0; - (is->td+i)->mcnt = 0; - temp += BUFSIZE; - } - -} - -/* - * Initialization of interface; set up initialization block - * and transmit/receive descriptor rings. - */ -is_init(unit) - int unit; -{ - register struct is_softc *is = &is_softc[unit]; - struct ifnet *ifp = &is->arpcom.ac_if; - int s; - register i; - - /* Address not known */ - if (ifp->if_addrlist == (struct ifaddr *)0) return; - - s = splnet(); - is->last_rd = is->last_td = is->no_td = 0; - - /* Set up lance's memory area */ - init_mem(unit); - - /* Stop Lance to get access to other registers */ - iswrcsr(unit,0,STOP); - - /* Get ethernet address */ - for (i=0; i<ETHER_ADDR_LEN; i++) - init_block[unit].padr[i] = is->arpcom.ac_enaddr[i]; - -#if NBPFILTER > 0 - /* - * Initialize multicast address hashing registers to accept - * all multicasts (only used when in promiscuous mode) - */ - for (i = 0; i < 8; ++i) - init_block[unit].ladrf[i] = 0xff; -#endif - - - /* No byte swapping etc */ - iswrcsr(unit,3,0); - - /* Give lance the physical address of its memory area */ - iswrcsr(unit,1,kvtop(&init_block[unit])); - iswrcsr(unit,2,(kvtop(&init_block[unit]) >> 16) & 0xff); - - /* OK, let's try and initialise the Lance */ - iswrcsr(unit,0,INIT); - - /* Wait for initialisation to finish */ - for(i=0; i<1000; i++){ - if (isrdcsr(unit,0)&IDON) - break; - } - if (isrdcsr(unit,0)&IDON) { - /* Start lance */ - iswrcsr(unit,0,STRT|IDON|INEA); - ifp->if_flags |= IFF_RUNNING; - ifp->if_flags &= ~IFF_OACTIVE; - - is_start(ifp); - } - else - printf("is%d: card failed to initialise\n", unit); - - (void) splx(s); -} - -/* - * Setup output on interface. - * Get another datagram to send off of the interface queue, - * and map it to the interface before starting the output. - * called only at splimp or interrupt level. - */ -is_start(ifp) - struct ifnet *ifp; -{ - int unit = ifp->if_unit; - register struct is_softc *is = &is_softc[unit]; - struct mbuf *m0, *m; - unsigned char *buffer; - u_short len; - int i; - struct mds *cdm; - - - if ((is->arpcom.ac_if.if_flags & IFF_RUNNING) == 0) - return; - - do { - cdm = (is->td + is->last_td); - if (cdm->flags&OWN) - return; - - IF_DEQUEUE(&is->arpcom.ac_if.if_snd, m); - - if (m == 0) - return; - - /* - * Copy the mbuf chain into the transmit buffer - */ - - buffer = is->tbuf+(BUFSIZE*is->last_td); - len=0; - for (m0=m; m != 0; m=m->m_next) { - bcopy(mtod(m,caddr_t),buffer,m->m_len); - buffer += m->m_len; - len += m->m_len; - } -#if NBPFILTER > 0 - if (is->bpf) { - u_short etype; - int off, datasize, resid; - struct ether_header *eh; - struct trailer_header { - u_short ether_type; - u_short ether_residual; - } trailer_header; - char ether_packet[ETHER_MAX_LEN]; - char *ep; - - ep = ether_packet; - - /* - * We handle trailers below: - * Copy ether header first, then residual data, - * then data. Put all this in a temporary buffer - * 'ether_packet' and send off to bpf. Since the - * system has generated this packet, we assume - * that all of the offsets in the packet are - * correct; if they're not, the system will almost - * certainly crash in m_copydata. - * We make no assumptions about how the data is - * arranged in the mbuf chain (i.e. how much - * data is in each mbuf, if mbuf clusters are - * used, etc.), which is why we use m_copydata - * to get the ether header rather than assume - * that this is located in the first mbuf. - */ - /* copy ether header */ - m_copydata(m0, 0, sizeof(struct ether_header), ep); - eh = (struct ether_header *) ep; - ep += sizeof(struct ether_header); - etype = ntohs(eh->ether_type); - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - datasize = ((etype - ETHERTYPE_TRAIL) << 9); - off = datasize + sizeof(struct ether_header); - - /* copy trailer_header into a data structure */ - m_copydata(m0, off, sizeof(struct trailer_header), - &trailer_header.ether_type); - - /* copy residual data */ - resid = trailer_header.ether_residual - - sizeof(struct trailer_header); - resid = ntohs(resid); - m_copydata(m0, off+sizeof(struct trailer_header), - resid, ep); - ep += resid; - - /* copy data */ - m_copydata(m0, sizeof(struct ether_header), - datasize, ep); - ep += datasize; - - /* restore original ether packet type */ - eh->ether_type = trailer_header.ether_type; - - bpf_tap(is->bpf, ether_packet, ep - ether_packet); - } else - bpf_mtap(is->bpf, m0); - } -#endif - - - m_freem(m0); - len = MAX(len,ETHER_MIN_LEN); - - /* - * Init transmit registers, and set transmit start flag. - */ - - cdm->flags |= (OWN|STP|ENP); - cdm->bcnt = -len; - cdm->mcnt = 0; -#if ISDEBUG > 3 - xmit_print(unit,is->last_td); -#endif - - iswrcsr(unit,0,TDMD|INEA); - if (++is->last_td >= NTBUF) - is->last_td=0; - }while(++is->no_td < NTBUF); - is->no_td = NTBUF; - is->arpcom.ac_if.if_flags |= IFF_OACTIVE; -#if ISDEBUG >4 - printf("no_td = %x, last_td = %x\n",is->no_td, is->last_td); -#endif - return(0); -} - - -/* - * Controller interrupt. - */ -isintr(unit) -{ - register struct is_softc *is = &is_softc[unit]; - u_short isr; - - while((isr=isrdcsr(unit,0))&INTR) { - if (isr&ERR) { - if (isr&BABL){ - printf("is%d: BABL\n",unit); - is->arpcom.ac_if.if_oerrors++; - } - if (isr&CERR) { - printf("is%d: CERR\n",unit); - is->arpcom.ac_if.if_collisions++; - } - if (isr&MISS) { - printf("is%d: MISS\n",unit); - is->arpcom.ac_if.if_ierrors++; - } - if (isr&MERR) - printf("is%d: MERR\n",unit); - iswrcsr(unit,0,BABL|CERR|MISS|MERR|INEA); - } - if (!(isr&RXON)) { - printf("is%d: !(isr&RXON)\n", unit); - is->arpcom.ac_if.if_ierrors++; - is_reset(unit); - return(1); - } - if (!(isr&TXON)) { - printf("is%d: !(isr&TXON)\n", unit); - is->arpcom.ac_if.if_oerrors++; - is_reset(unit); - return(1); - } - - if (isr&RINT) { - /* reset watchdog timer */ - is->arpcom.ac_if.if_timer = 0; - is_rint(unit); - } - if (isr&TINT) { - /* reset watchdog timer */ - is->arpcom.ac_if.if_timer = 0; - iswrcsr(unit,0,TINT|INEA); - istint(unit); - } - } -} - -istint(unit) - int unit; -{ - struct is_softc *is = &is_softc[unit]; - register struct ifnet *ifp = &is->arpcom.ac_if; - int i,loopcount=0; - struct mds *cdm; - - is->arpcom.ac_if.if_opackets++; - do { - if ((i=is->last_td - is->no_td) < 0) - i+=NTBUF; - cdm = (is->td+i); -#if ISDEBUG >4 - printf("Trans cdm = %x\n",cdm); -#endif - if (cdm->flags&OWN) { - if (loopcount) - break; - return; - } - loopcount++; - is->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; - }while(--is->no_td > 0); - is_start(ifp); - -} - -#define NEXTRDS \ - if (++rmd == NRBUF) rmd=0, cdm=is->rd; else ++cdm - -/* only called from one place, so may as well integrate */ -static inline void is_rint(int unit) -{ - register struct is_softc *is=&is_softc[unit]; - register int rmd = is->last_rd; - struct mds *cdm = (is->rd + rmd); - - /* Out of sync with hardware, should never happen */ - - if (cdm->flags & OWN) { - printf("is%d: error: out of sync\n",unit); - iswrcsr(unit,0,RINT|INEA); - return; - } - - /* Process all buffers with valid data */ - while (!(cdm->flags&OWN)) { - /* Clear interrupt to avoid race condition */ - iswrcsr(unit,0,RINT|INEA); - if (cdm->flags&ERR) { - if (cdm->flags&FRAM) - printf("is%d: FRAM\n",unit); - if (cdm->flags&OFLO) - printf("is%d: OFLO\n",unit); - if (cdm->flags&CRC) - printf("is%d: CRC\n",unit); - if (cdm->flags&RBUFF) - printf("is%d: RBUFF\n",unit); - }else - if (cdm->flags&(STP|ENP) != (STP|ENP)) { - do { - iswrcsr(unit,0,RINT|INEA); - cdm->mcnt = 0; - cdm->flags |= OWN; - NEXTRDS; - }while (!(cdm->flags&(OWN|ERR|STP|ENP))); - is->last_rd = rmd; - printf("is%d: Chained buffer\n",unit); - if ((cdm->flags & (OWN|ERR|STP|ENP)) != ENP) { - is_reset(unit); - return; - } - }else - { -#if ISDEBUG >2 - recv_print(unit,is->last_rd); -#endif - isread(is,is->rbuf+(BUFSIZE*rmd),(int)cdm->mcnt); - is->arpcom.ac_if.if_ipackets++; - } - - cdm->flags |= OWN; - cdm->mcnt = 0; - NEXTRDS; -#if ISDEBUG >4 - printf("is->last_rd = %x, cdm = %x\n",is->last_rd,cdm); -#endif - } /* while */ - is->last_rd = rmd; -} /* is_rint */ - - -/* - * Pass a packet to the higher levels. - * We deal with the trailer protocol here. - */ -static inline void -isread(struct is_softc *is, unsigned char *buf, int len) -{ - register struct ether_header *eh; - struct mbuf *m; - int off, resid; - register struct ifqueue *inq; - - /* - * Deal with trailer protocol: if type is trailer type - * get true type from first 16-bit word past data. - * Remember that type was trailer by setting off. - */ - eh = (struct ether_header *)buf; - eh->ether_type = ntohs((u_short)eh->ether_type); - len = len - sizeof(struct ether_header) - 4; -#define nedataaddr(eh, off, type) ((type)(((caddr_t)((eh)+1)+(off)))) - if (eh->ether_type >= ETHERTYPE_TRAIL && - eh->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - off = (eh->ether_type - ETHERTYPE_TRAIL) * 512; - if (off >= ETHERMTU) return; /* sanity */ - eh->ether_type = ntohs(*nedataaddr(eh, off, u_short *)); - resid = ntohs(*(nedataaddr(eh, off+2, u_short *))); - if (off + resid > len) return; /* sanity */ - len = off + resid; - } else off = 0; - - if (len == 0) return; - - /* - * Pull packet off interface. Off is nonzero if packet - * has trailing header; neget will then force this header - * information to be at the front, but we still have to drop - * the type and length which are at the front of any trailer data. - */ - is->arpcom.ac_if.if_ipackets++; - m = isget(buf, len, off, &is->arpcom.ac_if); - if (m == 0) return; -#if NBPFILTER > 0 - /* - * Check if there's a BPF listener on this interface. - * If so, hand off the raw packet to bpf. - */ - if (is->bpf) { - bpf_mtap(is->bpf, m); - - /* - * Note that the interface cannot be in promiscuous mode if - * there are no BPF listeners. And if we are in promiscuous - * mode, we have to check if this packet is really ours. - * - * XXX This test does not support multicasts. - */ - if ((is->arpcom.ac_if.if_flags & IFF_PROMISC) && - bcmp(eh->ether_dhost, is->arpcom.ac_enaddr, - sizeof(eh->ether_dhost)) != 0 && - bcmp(eh->ether_dhost, etherbroadcastaddr, - sizeof(eh->ether_dhost)) != 0) { - - m_freem(m); - return; - } - } -#endif - - - ether_input(&is->arpcom.ac_if, eh, m); -} - -/* - * Supporting routines - */ - -/* - * Pull read data off a interface. - * Len is length of data, with local net header stripped. - * Off is non-zero if a trailer protocol was used, and - * gives the offset of the trailer information. - * We copy the trailer information and then all the normal - * data into mbufs. When full cluster sized units are present - * we copy into clusters. - */ -struct mbuf * -isget(buf, totlen, off0, ifp) - caddr_t buf; - int totlen, off0; - struct ifnet *ifp; -{ - struct mbuf *top, **mp, *m, *p; - int off = off0, len; - register caddr_t cp = buf; - char *epkt; - - buf += sizeof(struct ether_header); - cp = buf; - epkt = cp + totlen; - - - if (off) { - cp += off + 2 * sizeof(u_short); - totlen -= 2 * sizeof(u_short); - } - - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return (0); - m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = totlen; - m->m_len = MHLEN; - top = 0; - mp = ⊤ - while (totlen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return (0); - } - m->m_len = MLEN; - } - len = min(totlen, epkt - cp); - if (len >= MINCLSIZE) { - MCLGET(m, M_DONTWAIT); - if (m->m_flags & M_EXT) - m->m_len = len = min(len, MCLBYTES); - else - len = m->m_len; - } else { - /* - * Place initial small packet/header at end of mbuf. - */ - if (len < m->m_len) { - if (top == 0 && len + max_linkhdr <= m->m_len) - m->m_data += max_linkhdr; - m->m_len = len; - } else - len = m->m_len; - } - bcopy(cp, mtod(m, caddr_t), (unsigned)len); - cp += len; - *mp = m; - mp = &m->m_next; - totlen -= len; - if (cp == epkt) - cp = buf; - } - return (top); -} - - -/* - * Process an ioctl request. - */ -is_ioctl(ifp, cmd, data) - register struct ifnet *ifp; - int cmd; - caddr_t data; -{ - register struct ifaddr *ifa = (struct ifaddr *)data; - int unit = ifp->if_unit; - struct is_softc *is = &is_softc[unit]; - struct ifreq *ifr = (struct ifreq *)data; - int s, error = 0; - - s = splnet(); - - switch (cmd) { - - case SIOCSIFADDR: - ifp->if_flags |= IFF_UP; - - switch (ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - is_init(ifp->if_unit); /* before arpwhohas */ - /* - * See if another station has *our* IP address. - * i.e.: There is an address conflict! If a - * conflict exists, a message is sent to the - * console. - */ - ((struct arpcom *)ifp)->ac_ipaddr = - IA_SIN(ifa)->sin_addr; - arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); - break; -#endif -#ifdef NS - /* - * XXX - This code is probably wrong - */ - case AF_NS: - { - register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); - - if (ns_nullhost(*ina)) - ina->x_host = - *(union ns_host *)(is->arpcom.ac_enaddr); - else { - /* - * - */ - bcopy((caddr_t)ina->x_host.c_host, - (caddr_t)is->arpcom.ac_enaddr, - sizeof(is->arpcom.ac_enaddr)); - } - /* - * Set new address - */ - is_init(ifp->if_unit); - break; - } -#endif - default: - is_init(ifp->if_unit); - break; - } - break; - - case SIOCSIFFLAGS: - /* - * If interface is marked down and it is running, then stop it - */ - if ((ifp->if_flags & IFF_UP) == 0 && - ifp->if_flags & IFF_RUNNING) { - iswrcsr(unit,0,STOP); - ifp->if_flags &= ~IFF_RUNNING; - } else { - /* - * If interface is marked up and it is stopped, then start it - */ - if ((ifp->if_flags & IFF_UP) && - (ifp->if_flags & IFF_RUNNING) == 0) - is_init(ifp->if_unit); - } -#if NBPFILTER > 0 - if (ifp->if_flags & IFF_PROMISC) { - /* - * Set promiscuous mode on interface. - * XXX - for multicasts to work, we would need to - * write 1's in all bits of multicast - * hashing array. For now we assume that - * this was done in is_init(). - */ - init_block[unit].mode = PROM; - } else - /* - * XXX - for multicasts to work, we would need to - * rewrite the multicast hashing array with the - * proper hash (would have been destroyed above). - */ - { /* Don't know about this */}; -#endif - break; - -#ifdef notdef - case SIOCGHWADDR: - bcopy((caddr_t)is->arpcom.ac_enaddr, (caddr_t) &ifr->ifr_data, - sizeof(is->arpcom.ac_enaddr)); - break; -#endif - - default: - error = EINVAL; - } - (void) splx(s); - return (error); -} - -#ifdef ISDEBUG -recv_print(unit,no) - int unit,no; -{ - register struct is_softc *is=&is_softc[unit]; - struct mds *rmd; - int len,i,printed=0; - - rmd = (is->rd+no); - len = rmd->mcnt; - printf("is%d: Receive buffer %d, len = %d\n",unit,no,len); - printf("is%d: Status %x\n",unit,isrdcsr(unit,0)); - for (i=0; i<len; i++) { - if (!printed) { - printed=1; - printf("is%d: data: ", unit); - } - printf("%x ",*(is->rbuf+(BUFSIZE*no)+i)); - } - if (printed) - printf("\n"); -} - -xmit_print(unit,no) - int unit,no; -{ - register struct is_softc *is=&is_softc[unit]; - struct mds *rmd; - int i, printed=0; - u_short len; - - rmd = (is->td+no); - len = -(rmd->bcnt); - printf("is%d: Transmit buffer %d, len = %d\n",unit,no,len); - printf("is%d: Status %x\n",unit,isrdcsr(unit,0)); - printf("is%d: addr %x, flags %x, bcnt %x, mcnt %x\n", - unit,rmd->addr,rmd->flags,rmd->bcnt,rmd->mcnt); - for (i=0; i<len; i++) { - if (!printed) { - printed = 1; - printf("is%d: data: ", unit); - } - printf("%x ",*(is->tbuf+(BUFSIZE*no)+i)); - } - if (printed) - printf("\n"); -} -#endif /* ISDEBUG */ - -#endif /* NIS > 0 */ diff --git a/sys/i386/isa/if_isreg.h b/sys/i386/isa/if_isreg.h deleted file mode 100644 index 5e69064..0000000 --- a/sys/i386/isa/if_isreg.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Isolan AT 4141-0 Ethernet driver header file - * Isolink 4110 - * - * By Paul Richards - * - * Copyright (C) 1993, Paul Richards. This software may be used, modified, - * copied, distributed, and sold, in both source and binary form provided - * that the above copyright and these terms are retained. Under no - * circumstances is the author responsible for the proper functioning - * of this software, nor does the author assume any responsibility - * for damages incurred with its use. - * - * $Id$ - */ - -/* Declarations specific to this driver */ -#define NTBUF 2 -#define TLEN 1 -#define NRBUF 8 -#define RLEN 3 -#define BUFSIZE 1518 -#define RAP 0xe -#define RDP 0xc - -/* Control and status register 0 flags */ - -#define ERR 0x8000 -#define BABL 0x4000 -#define CERR 0x2000 -#define MISS 0x1000 -#define MERR 0x0800 -#define RINT 0x0400 -#define TINT 0x0200 -#define IDON 0x0100 -#define INTR 0x0080 -#define INEA 0x0040 -#define RXON 0x0020 -#define TXON 0x0010 -#define TDMD 0x0008 -#define STOP 0x0004 -#define STRT 0x0002 -#define INIT 0x0001 - -/* Coontrol and status register 3 flags */ - -#define BSWP 0x0004 -#define ACON 0x0002 -#define BCON 0x0001 - -/* Initialisation block (must be on word boundary) */ - -struct init_block { - u_short mode; /* Mode register */ - u_char padr[6]; /* Ethernet address */ - u_char ladrf[8]; /* Logical address filter (multicast) */ - u_short rdra; /* Low order pointer to receive ring */ - u_short rlen; /* High order pointer and no. rings */ - u_short tdra; /* Low order pointer to transmit ring */ - u_short tlen; /* High order pointer and no rings */ - }; - -/* Mode settings */ - -#define PROM 0x8000 /* Promiscuous */ -#define INTL 0x0040 /* Internal loopback */ -#define DRTY 0x0020 /* Disable retry */ -#define COLL 0x0010 /* Force collision */ -#define DTCR 0x0008 /* Disable transmit crc */ -#define LOOP 0x0004 /* Loop back */ -#define DTX 0x0002 /* Disable transmitter */ -#define DRX 0x0001 /* Disable receiver */ - -/* Message descriptor structure */ - -struct mds { - u_short addr; - u_short flags; - u_short bcnt; - u_short mcnt; - }; - -/* Receive ring status flags */ - -#define OWN 0x8000 /* Owner bit, 0=host, 1=Lance */ -#define MDERR 0x4000 /* Error */ -#define FRAM 0x2000 /* Framing error error */ -#define OFLO 0x1000 /* Silo overflow */ -#define CRC 0x0800 /* CRC error */ -#define RBUFF 0x0400 /* Buffer error */ -#define STP 0x0200 /* Start of packet */ -#define ENP 0x0100 /* End of packet */ - -/* Transmit ring flags */ - -#define MORE 0x1000 /* More than 1 retry */ -#define ONE 0x0800 /* One retry */ -#define DEF 0x0400 /* Deferred transmit */ - -/* Transmit errors */ - -#define TBUFF 0x8000 /* Buffer error */ -#define UFLO 0x4000 /* Silo underflow */ -#define LCOL 0x1000 /* Late collision */ -#define LCAR 0x0800 /* Loss of carrier */ -#define RTRY 0x0400 /* Tried 16 times */ diff --git a/sys/i386/isa/isa.c b/sys/i386/isa/isa.c deleted file mode 100644 index ec08312..0000000 --- a/sys/i386/isa/isa.c +++ /dev/null @@ -1,791 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)isa.c 7.2 (Berkeley) 5/13/91 - * $Id: isa.c,v 1.4 1993/10/13 15:59:28 rgrimes Exp $ - */ - -/* - * code to manage AT bus - * - * 92/08/18 Frank P. MacLachlan (fpm@crash.cts.com): - * Fixed uninitialized variable problem and added code to deal - * with DMA page boundaries in isa_dmarangecheck(). Fixed word - * mode DMA count compution and reorganized DMA setup code in - * isa_dmastart() - */ - -#include "param.h" -#include "systm.h" -#include "conf.h" -#include "file.h" -#include "buf.h" -#include "uio.h" -#include "syslog.h" -#include "malloc.h" -#include "rlist.h" -#include "machine/segments.h" -#include "vm/vm.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/isa.h" -#include "i386/isa/icu.h" -#include "i386/isa/ic/i8237.h" -#include "i386/isa/ic/i8042.h" - -/* -** Register definitions for DMA controller 1 (channels 0..3): -*/ -#define DMA1_CHN(c) (IO_DMA1 + 1*(2*(c))) /* addr reg for channel c */ -#define DMA1_SMSK (IO_DMA1 + 1*10) /* single mask register */ -#define DMA1_MODE (IO_DMA1 + 1*11) /* mode register */ -#define DMA1_FFC (IO_DMA1 + 1*12) /* clear first/last FF */ - -/* -** Register definitions for DMA controller 2 (channels 4..7): -*/ -#define DMA2_CHN(c) (IO_DMA2 + 2*(2*(c))) /* addr reg for channel c */ -#define DMA2_SMSK (IO_DMA2 + 2*10) /* single mask register */ -#define DMA2_MODE (IO_DMA2 + 2*11) /* mode register */ -#define DMA2_FFC (IO_DMA2 + 2*12) /* clear first/last FF */ - -int config_isadev __P((struct isa_device *, u_int *)); - -/* - * print a conflict message - */ -void -conflict(dvp, tmpdvp, item, reason, format) - struct isa_device *dvp, *tmpdvp; - int item; - char *reason; - char *format; -{ - printf("%s%d not probed due to %s conflict with %s%d at ", - dvp->id_driver->name, dvp->id_unit, reason, - tmpdvp->id_driver->name, tmpdvp->id_unit); - printf(format, item); - printf("\n"); -} - -/* - * Check to see if things are alread in use, like IRQ's, I/O addresses - * and Memory addresses. - */ -int -haveseen(dvp, tmpdvp) - struct isa_device *dvp, *tmpdvp; -{ - int status = 0; - - /* - * Only check against devices that have already been found - */ - if (tmpdvp->id_alive) { - /* - * Check for I/O address conflict. We can only check the - * starting address of the device against the range of the - * device that has already been probed since we do not - * know how many I/O addresses this device uses. - */ - if (tmpdvp->id_alive != -1) { - if ((dvp->id_iobase >= tmpdvp->id_iobase) && - (dvp->id_iobase <= - (tmpdvp->id_iobase + tmpdvp->id_alive - 1))) { - conflict(dvp, tmpdvp, dvp->id_iobase, - "I/O address", "0x%x"); - status = 1; - } - } - /* - * Check for Memory address conflict. We can check for - * range overlap, but it will not catch all cases since the - * driver may adjust the msize paramater during probe, for - * now we just check that the starting address does not - * fall within any allocated region. - * XXX could add a second check after the probe for overlap, - * since at that time we would know the full range. - * XXX KERNBASE is a hack, we should have vaddr in the table! - */ - if(tmpdvp->id_maddr) { - if((KERNBASE + dvp->id_maddr >= tmpdvp->id_maddr) && - (KERNBASE + dvp->id_maddr <= - (tmpdvp->id_maddr + tmpdvp->id_msize - 1))) { - conflict(dvp, tmpdvp, dvp->id_maddr, "maddr", - "0x%x"); - status = 1; - } - } - /* - * Check for IRQ conflicts. - */ - if(tmpdvp->id_irq) { - if (tmpdvp->id_irq == dvp->id_irq) { - conflict(dvp, tmpdvp, ffs(dvp->id_irq) - 1, - "irq", "%d"); - status = 1; - } - } - /* - * Check for DRQ conflicts. - */ - if(tmpdvp->id_drq != -1) { - if (tmpdvp->id_drq == dvp->id_drq) { - conflict(dvp, tmpdvp, dvp->id_drq, - "drq", "%d"); - status = 1; - } - } - } - return (status); -} - -/* - * Search through all the isa_devtab_* tables looking for anything that - * conflicts with the current device. - */ -int -haveseen_isadev(dvp) - struct isa_device *dvp; -{ - struct isa_device *tmpdvp; - int status = 0; - - for (tmpdvp = isa_devtab_tty; tmpdvp->id_driver; tmpdvp++) { - status |= haveseen(dvp, tmpdvp); - } - for (tmpdvp = isa_devtab_bio; tmpdvp->id_driver; tmpdvp++) { - status |= haveseen(dvp, tmpdvp); - } - for (tmpdvp = isa_devtab_net; tmpdvp->id_driver; tmpdvp++) { - status |= haveseen(dvp, tmpdvp); - } - for (tmpdvp = isa_devtab_null; tmpdvp->id_driver; tmpdvp++) { - status |= haveseen(dvp, tmpdvp); - } - return(status); -} - -/* - * Configure all ISA devices - */ -void -isa_configure() { - struct isa_device *dvp; - - enable_intr(); - splhigh(); - INTREN(IRQ_SLAVE); - printf("Probing for devices on the ISA bus:\n"); - for (dvp = isa_devtab_tty; dvp->id_driver; dvp++) { - if (!haveseen_isadev(dvp)) - config_isadev(dvp,&ttymask); - } - for (dvp = isa_devtab_bio; dvp->id_driver; dvp++) { - if (!haveseen_isadev(dvp)) - config_isadev(dvp,&biomask); - } - for (dvp = isa_devtab_net; dvp->id_driver; dvp++) { - if (!haveseen_isadev(dvp)) - config_isadev(dvp,&netmask); - } - for (dvp = isa_devtab_null; dvp->id_driver; dvp++) { - if (!haveseen_isadev(dvp)) - config_isadev(dvp,(u_int *) NULL); - } -/* - * XXX We should really add the tty device to netmask when the line is - * switched to SLIPDISC, and then remove it when it is switched away from - * SLIPDISC. No need to block out ALL ttys during a splnet when only one - * of them is running slip. - */ -#include "sl.h" -#if NSL > 0 - netmask |= ttymask; - ttymask |= netmask; -#endif - /* biomask |= ttymask ; can some tty devices use buffers? */ - printf("biomask %x ttymask %x netmask %x\n", biomask, ttymask, netmask); - splnone(); -} - -/* - * Configure an ISA device. - */ -config_isadev(isdp, mp) - struct isa_device *isdp; - u_int *mp; -{ - struct isa_driver *dp = isdp->id_driver; - - if (isdp->id_maddr) { - extern u_int atdevbase; - - isdp->id_maddr -= 0xa0000; /* XXX should be a define */ - isdp->id_maddr += atdevbase; - } - isdp->id_alive = (*dp->probe)(isdp); - if (isdp->id_alive) { - /* - * Only print the I/O address range if id_alive != -1 - * Right now this is a temporary fix just for the new - * NPX code so that if it finds a 486 that can use trap - * 16 it will not report I/O addresses. - * Rod Grimes 04/26/94 - */ - printf("%s%d", dp->name, isdp->id_unit); - if (isdp->id_alive != -1) { - printf(" at 0x%x", isdp->id_iobase); - if ((isdp->id_iobase + isdp->id_alive - 1) != - isdp->id_iobase) { - printf("-0x%x", - isdp->id_iobase + - isdp->id_alive - 1); - } - } - if(isdp->id_irq) - printf(" irq %d", ffs(isdp->id_irq) - 1); - if (isdp->id_drq != -1) - printf(" drq %d", isdp->id_drq); - if (isdp->id_maddr) - printf(" maddr 0x%x", kvtop(isdp->id_maddr)); - if (isdp->id_msize) - printf(" msize %d", isdp->id_msize); - if (isdp->id_flags) - printf(" flags 0x%x", isdp->id_flags); - if (isdp->id_iobase < 0x100) - printf(" on motherboard\n"); - else - printf(" on isa\n"); - - (*dp->attach)(isdp); - - if(isdp->id_irq) { - int intrno; - - intrno = ffs(isdp->id_irq)-1; - setidt(ICU_OFFSET+intrno, isdp->id_intr, - SDT_SYS386IGT, SEL_KPL); - if(mp) { - INTRMASK(*mp,isdp->id_irq); - } - INTREN(isdp->id_irq); - } - } else { - printf("%s%d not found", dp->name, isdp->id_unit); - if (isdp->id_iobase) { - printf(" at 0x%x", isdp->id_iobase); - } - printf("\n"); - } -} - -#define IDTVEC(name) __CONCAT(X,name) -/* default interrupt vector table entries */ -extern IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3), - IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7), - IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11), - IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15); - -static *defvec[16] = { - &IDTVEC(intr0), &IDTVEC(intr1), &IDTVEC(intr2), &IDTVEC(intr3), - &IDTVEC(intr4), &IDTVEC(intr5), &IDTVEC(intr6), &IDTVEC(intr7), - &IDTVEC(intr8), &IDTVEC(intr9), &IDTVEC(intr10), &IDTVEC(intr11), - &IDTVEC(intr12), &IDTVEC(intr13), &IDTVEC(intr14), &IDTVEC(intr15) }; - -/* out of range default interrupt vector gate entry */ -extern IDTVEC(intrdefault); - -/* - * Fill in default interrupt table (in case of spuruious interrupt - * during configuration of kernel, setup interrupt control unit - */ -isa_defaultirq() { - int i; - - /* icu vectors */ - for (i = NRSVIDT ; i < NRSVIDT+ICU_LEN ; i++) - setidt(i, defvec[i], SDT_SYS386IGT, SEL_KPL); - - /* out of range vectors */ - for (i = NRSVIDT; i < NIDT; i++) - setidt(i, &IDTVEC(intrdefault), SDT_SYS386IGT, SEL_KPL); - - /* initialize 8259's */ - outb(IO_ICU1, 0x11); /* reset; program device, four bytes */ - outb(IO_ICU1+1, NRSVIDT); /* starting at this vector index */ - outb(IO_ICU1+1, 1<<2); /* slave on line 2 */ -#ifdef AUTO_EOI_1 - outb(IO_ICU1+1, 2 | 1); /* auto EOI, 8086 mode */ -#else - outb(IO_ICU1+1, 1); /* 8086 mode */ -#endif - outb(IO_ICU1+1, 0xff); /* leave interrupts masked */ - outb(IO_ICU1, 0x0a); /* default to IRR on read */ - outb(IO_ICU1, 0xc0 | (3 - 1)); /* pri order 3-7, 0-2 (com2 first) */ - - outb(IO_ICU2, 0x11); /* reset; program device, four bytes */ - outb(IO_ICU2+1, NRSVIDT+8); /* staring at this vector index */ - outb(IO_ICU2+1,2); /* my slave id is 2 */ -#ifdef AUTO_EOI_2 - outb(IO_ICU2+1, 2 | 1); /* auto EOI, 8086 mode */ -#else - outb(IO_ICU2+1,1); /* 8086 mode */ -#endif - outb(IO_ICU2+1, 0xff); /* leave interrupts masked */ - outb(IO_ICU2, 0x0a); /* default to IRR on read */ -} - -/* region of physical memory known to be contiguous */ -vm_offset_t isaphysmem; -static caddr_t dma_bounce[8]; /* XXX */ -static char bounced[8]; /* XXX */ -#define MAXDMASZ 512 /* XXX */ - -/* high byte of address is stored in this port for i-th dma channel */ -static short dmapageport[8] = - { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; - -/* - * isa_dmacascade(): program 8237 DMA controller channel to accept - * external dma control by a board. - */ -void isa_dmacascade(unsigned chan) -{ - if (chan > 7) - panic("isa_dmacascade: impossible request"); - - /* set dma channel mode, and set dma channel mode */ - if ((chan & 4) == 0) { - outb(DMA1_MODE, DMA37MD_CASCADE | chan); - outb(DMA1_SMSK, chan); - } else { - outb(DMA2_MODE, DMA37MD_CASCADE | (chan & 3)); - outb(DMA2_SMSK, chan & 3); - } -} - -/* - * isa_dmastart(): program 8237 DMA controller channel, avoid page alignment - * problems by using a bounce buffer. - */ -void isa_dmastart(int flags, caddr_t addr, unsigned nbytes, unsigned chan) -{ vm_offset_t phys; - int waport; - caddr_t newaddr; - - if ( chan > 7 - || (chan < 4 && nbytes > (1<<16)) - || (chan >= 4 && (nbytes > (1<<17) || (u_int)addr & 1))) - panic("isa_dmastart: impossible request"); - - if (isa_dmarangecheck(addr, nbytes, chan)) { - if (dma_bounce[chan] == 0) - dma_bounce[chan] = - /*(caddr_t)malloc(MAXDMASZ, M_TEMP, M_WAITOK);*/ - (caddr_t) isaphysmem + NBPG*chan; - bounced[chan] = 1; - newaddr = dma_bounce[chan]; - *(int *) newaddr = 0; /* XXX */ - - /* copy bounce buffer on write */ - if (!(flags & B_READ)) - bcopy(addr, newaddr, nbytes); - addr = newaddr; - } - - /* translate to physical */ - phys = pmap_extract(pmap_kernel(), (vm_offset_t)addr); - - if ((chan & 4) == 0) { - /* - * Program one of DMA channels 0..3. These are - * byte mode channels. - */ - /* set dma channel mode, and reset address ff */ - if (flags & B_READ) - outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|chan); - else - outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_READ|chan); - outb(DMA1_FFC, 0); - - /* send start address */ - waport = DMA1_CHN(chan); - outb(waport, phys); - outb(waport, phys>>8); - outb(dmapageport[chan], phys>>16); - - /* send count */ - outb(waport + 1, --nbytes); - outb(waport + 1, nbytes>>8); - - /* unmask channel */ - outb(DMA1_SMSK, chan); - } else { - /* - * Program one of DMA channels 4..7. These are - * word mode channels. - */ - /* set dma channel mode, and reset address ff */ - if (flags & B_READ) - outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|(chan&3)); - else - outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_READ|(chan&3)); - outb(DMA2_FFC, 0); - - /* send start address */ - waport = DMA2_CHN(chan - 4); - outb(waport, phys>>1); - outb(waport, phys>>9); - outb(dmapageport[chan], phys>>16); - - /* send count */ - nbytes >>= 1; - outb(waport + 2, --nbytes); - outb(waport + 2, nbytes>>8); - - /* unmask channel */ - outb(DMA2_SMSK, chan & 3); - } -} - -void isa_dmadone(int flags, caddr_t addr, int nbytes, int chan) -{ - - /* copy bounce buffer on read */ - /*if ((flags & (B_PHYS|B_READ)) == (B_PHYS|B_READ))*/ - if (bounced[chan]) { - bcopy(dma_bounce[chan], addr, nbytes); - bounced[chan] = 0; - } -} - -/* - * Check for problems with the address range of a DMA transfer - * (non-contiguous physical pages, outside of bus address space, - * crossing DMA page boundaries). - * Return true if special handling needed. - */ - -isa_dmarangecheck(caddr_t va, unsigned length, unsigned chan) { - vm_offset_t phys, priorpage = 0, endva; - u_int dma_pgmsk = (chan & 4) ? ~(128*1024-1) : ~(64*1024-1); - - endva = (vm_offset_t)round_page(va + length); - for (; va < (caddr_t) endva ; va += NBPG) { - phys = trunc_page(pmap_extract(pmap_kernel(), (vm_offset_t)va)); -#define ISARAM_END RAM_END - if (phys == 0) - panic("isa_dmacheck: no physical page present"); - if (phys > ISARAM_END) - return (1); - if (priorpage) { - if (priorpage + NBPG != phys) - return (1); - /* check if crossing a DMA page boundary */ - if (((u_int)priorpage ^ (u_int)phys) & dma_pgmsk) - return (1); - } - priorpage = phys; - } - return (0); -} - -/* head of queue waiting for physmem to become available */ -struct buf isa_physmemq; - -/* blocked waiting for resource to become free for exclusive use */ -static isaphysmemflag; -/* if waited for and call requested when free (B_CALL) */ -static void (*isaphysmemunblock)(); /* needs to be a list */ - -/* - * Allocate contiguous physical memory for transfer, returning - * a *virtual* address to region. May block waiting for resource. - * (assumed to be called at splbio()) - */ -caddr_t -isa_allocphysmem(caddr_t va, unsigned length, void (*func)()) { - - isaphysmemunblock = func; - while (isaphysmemflag & B_BUSY) { - isaphysmemflag |= B_WANTED; - sleep(&isaphysmemflag, PRIBIO); - } - isaphysmemflag |= B_BUSY; - - return((caddr_t)isaphysmem); -} - -/* - * Free contiguous physical memory used for transfer. - * (assumed to be called at splbio()) - */ -void -isa_freephysmem(caddr_t va, unsigned length) { - - isaphysmemflag &= ~B_BUSY; - if (isaphysmemflag & B_WANTED) { - isaphysmemflag &= B_WANTED; - wakeup(&isaphysmemflag); - if (isaphysmemunblock) - (*isaphysmemunblock)(); - } -} - -/* - * Handle a NMI, possibly a machine check. - * return true to panic system, false to ignore. - */ -isa_nmi(cd) { - - log(LOG_CRIT, "\nNMI port 61 %x, port 70 %x\n", inb(0x61), inb(0x70)); - return(0); -} - -/* - * Caught a stray interrupt, notify - */ -isa_strayintr(d) { - - /* DON'T BOTHER FOR NOW! */ - /* for some reason, we get bursts of intr #7, even if not enabled! */ - /* - * Well the reason you got bursts of intr #7 is because someone - * raised an interrupt line and dropped it before the 8259 could - * prioritize it. This is documented in the intel data book. This - * means you have BAD hardware! I have changed this so that only - * the first 5 get logged, then it quits logging them, and puts - * out a special message. rgrimes 3/25/1993 - */ - extern u_long intrcnt_stray; - - intrcnt_stray++; - if (intrcnt_stray <= 5) - log(LOG_ERR,"ISA strayintr %x\n", d); - if (intrcnt_stray == 5) - log(LOG_CRIT,"Too many ISA strayintr not logging any more\n"); -} - -/* - * Wait "n" microseconds. - * Relies on timer 1 counting down from (TIMER_FREQ / hz) at - * (1 * TIMER_FREQ) Hz. - * Note: timer had better have been programmed before this is first used! - * (The standard programming causes the timer to generate a square wave and - * the counter is decremented twice every cycle.) - */ -#define CF (1 * TIMER_FREQ) -#define TIMER_FREQ 1193182 /* XXX - should be elsewhere */ - -extern int hz; /* XXX - should be elsewhere */ - -int DELAY(n) - int n; -{ - int counter_limit; - int prev_tick; - int tick; - int ticks_left; - int sec; - int usec; - -#ifdef DELAYDEBUG - int getit_calls = 1; - int n1; - static int state = 0; - - if (state == 0) { - state = 1; - for (n1 = 1; n1 <= 10000000; n1 *= 10) - DELAY(n1); - state = 2; - } - if (state == 1) - printf("DELAY(%d)...", n); -#endif - - /* - * Read the counter first, so that the rest of the setup overhead is - * counted. Guess the initial overhead is 20 usec (on most systems it - * takes about 1.5 usec for each of the i/o's in getit(). The loop - * takes about 6 usec on a 486/33 and 13 usec on a 386/20. The - * multiplications and divisions to scale the count take a while). - */ - prev_tick = getit(0, 0); - n -= 20; - - /* - * Calculate (n * (CF / 1e6)) without using floating point and without - * any avoidable overflows. - */ - sec = n / 1000000; - usec = n - sec * 1000000; - ticks_left = sec * CF - + usec * (CF / 1000000) - + usec * ((CF % 1000000) / 1000) / 1000 - + usec * (CF % 1000) / 1000000; - - counter_limit = TIMER_FREQ / hz; - while (ticks_left > 0) { - tick = getit(0, 0); -#ifdef DELAYDEBUG - ++getit_calls; -#endif - if (tick > prev_tick) - ticks_left -= prev_tick - (tick - counter_limit); - else - ticks_left -= prev_tick - tick; - prev_tick = tick; - } -#ifdef DELAYDEBUG - if (state == 1) - printf(" %d calls to getit() at %d usec each\n", - getit_calls, (n + 5) / getit_calls); -#endif -} - -getit(unit, timer) { - int high; - int low; - - /* - * XXX - isa.h defines bogus timers. There's no such timer as - * IO_TIMER_2 = 0x48. There's a timer in the CMOS RAM chip but - * its interface is quite different. Neither timer is an 8252. - * We actually only call this with unit = 0 and timer = 0. It - * could be static... - */ - /* - * Protect ourself against interrupts. - * XXX - sysbeep() and sysbeepstop() need protection. - */ - disable_intr(); - /* - * Latch the count for 'timer' (cc00xxxx, c = counter, x = any). - */ - outb(IO_TIMER1 + 3, timer << 6); - - low = inb(IO_TIMER1 + timer); - high = inb(IO_TIMER1 + timer); - enable_intr(); - return ((high << 8) | low); -} - -static beeping; -static -sysbeepstop(f) -{ - /* disable counter 2 */ - outb(0x61, inb(0x61) & 0xFC); - if (f) - timeout(sysbeepstop, 0, f); - else - beeping = 0; -} - -void sysbeep(int pitch, int period) -{ - - outb(0x61, inb(0x61) | 3); /* enable counter 2 */ - /* - * XXX - move timer stuff to clock.c. - * Program counter 2: - * ccaammmb, c counter, a = access, m = mode, b = BCD - * 1011x110, 11 for aa = LSB then MSB, x11 for mmm = square wave. - */ - outb(0x43, 0xb6); /* set command for counter 2, 2 byte write */ - - outb(0x42, pitch); - outb(0x42, (pitch>>8)); - - if (!beeping) { - beeping = period; - timeout(sysbeepstop, period/2, period); - } -} - -/* - * Pass command to keyboard controller (8042) - */ -unsigned kbc_8042cmd(val) { - - while (inb(KBSTATP)&KBS_IBF); - if (val) outb(KBCMDP, val); - while (inb(KBSTATP)&KBS_IBF); - return (inb(KBDATAP)); -} - -/* - * find an ISA device in a given isa_devtab_* table, given - * the table to search, the expected id_driver entry, and the unit number. - * - * this function is defined in isa_device.h, and this location is debatable; - * i put it there because it's useless w/o, and directly operates on - * the other stuff in that file. - * - */ - -struct isa_device *find_isadev(table, driverp, unit) - struct isa_device *table; - struct isa_driver *driverp; - int unit; -{ - if (driverp == NULL) /* sanity check */ - return NULL; - - while ((table->id_driver != driverp) || (table->id_unit != unit)) { - if (table->id_driver == 0) - return NULL; - - table++; - } - - return table; -} - -/* - * Return nonzero if a (masked) irq is pending for a given device. - */ -int -isa_irq_pending(dvp) - struct isa_device *dvp; -{ - unsigned id_irq; - - id_irq = (unsigned short) dvp->id_irq; /* XXX silly type in struct */ - if (id_irq & 0xff) - return (inb(IO_ICU1) & id_irq); - return (inb(IO_ICU2) & (id_irq >> 8)); -} diff --git a/sys/i386/isa/isa.h b/sys/i386/isa/isa.h deleted file mode 100644 index 24dc5cd..0000000 --- a/sys/i386/isa/isa.h +++ /dev/null @@ -1,180 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)isa.h 5.7 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * ISA Bus conventions - */ - -#ifndef LOCORE -#include <sys/cdefs.h> - -unsigned char rtcin __P((int)); -extern unsigned int atdevbase; /* offset in virtual memory of ISA io mem */ -void sysbeep __P((int, int)); -unsigned kbd_8042cmd __P((int)); -struct isa_device; -int isa_irq_pending __P((struct isa_device *dvp)); -#endif - - -/* - * Input / Output Port Assignments - */ - -#ifndef IO_BEGIN -#define IO_ISABEGIN 0x000 /* 0x000 - Beginning of I/O Registers */ - - /* CPU Board */ -#define IO_DMA1 0x000 /* 8237A DMA Controller #1 */ -#define IO_ICU1 0x020 /* 8259A Interrupt Controller #1 */ -#define IO_TIMER1 0x040 /* 8252 Timer #1 */ -#define IO_TIMER2 0x048 /* 8252 Timer #2 */ -#define IO_KBD 0x060 /* 8042 Keyboard */ -#define IO_RTC 0x070 /* RTC */ -#define IO_NMI IO_RTC /* NMI Control */ -#define IO_DMAPG 0x080 /* DMA Page Registers */ -#define IO_ICU2 0x0A0 /* 8259A Interrupt Controller #2 */ -#define IO_DMA2 0x0C0 /* 8237A DMA Controller #2 */ -#define IO_NPX 0x0F0 /* Numeric Coprocessor */ - - /* Cards */ - /* 0x100 - 0x16F Open */ - -#define IO_WD2 0x170 /* Secondary Fixed Disk Controller */ - - /* 0x178 - 0x1EF Open */ - -#define IO_WD1 0x1f0 /* Primary Fixed Disk Controller */ -#define IO_GAME 0x200 /* Game Controller */ - - /* 0x208 - 0x277 Open */ - -#define IO_LPT2 0x278 /* Parallel Port #2 */ - - /* 0x280 - 0x2E7 Open */ - -#define IO_COM4 0x2e8 /* COM4 i/o address */ - - /* 0x2F0 - 0x2F7 Open */ - -#define IO_COM2 0x2f8 /* COM2 i/o address */ - /* 0x300 - 0x32F Open */ - -#define IO_BT0 0x330 /* bustek 742a default addr. */ -#define IO_AHA0 0x330 /* adaptec 1542 default addr. */ -#define IO_UHA0 0x330 /* ultrastore 14f default addr. */ -#define IO_BT1 0x334 /* bustek 742a default addr. */ -#define IO_AHA1 0x334 /* adaptec 1542 default addr. */ - /* 0x338 - 0x36F Open */ - -#define IO_FD2 0x370 /* secondary base i/o address */ -#define IO_LPT1 0x378 /* Parallel Port #1 */ - - /* 0x380 - 0x3AF Open */ - -#define IO_MDA 0x3B0 /* Monochome Adapter */ -#define IO_LPT3 0x3BC /* Monochome Adapter Printer Port */ -#define IO_VGA 0x3C0 /* E/VGA Ports */ -#define IO_CGA 0x3D0 /* CGA Ports */ - - /* 0x3E0 - 0x3E7 Open */ - -#define IO_COM3 0x3e8 /* COM3 i/o address */ -#define IO_FD1 0x3f0 /* primary base i/o address */ -#define IO_COM1 0x3f8 /* COM1 i/o address */ - -#define IO_ISAEND 0x3FF /* - 0x3FF End of I/O Registers */ -#endif IO_ISABEGIN - -/* - * Input / Output Port Sizes - these are from several sources, and tend - * to be the larger of what was found, ie COM ports can be 4, but some - * boards do not fully decode the address, thus 8 ports are used. - */ - -#ifndef IO_ISASIZES -#define IO_ISASIZES - -#define IO_COMSIZE 8 /* 8250, 16X50 com controllers (4?) */ -#define IO_CGASIZE 16 /* CGA controllers */ -#define IO_DMASIZE 16 /* 8237 DMA controllers */ -#define IO_DPGSIZE 32 /* 74LS612 DMA page reisters */ -#define IO_FDCSIZE 8 /* Nec765 floppy controllers */ -#define IO_WDCSIZE 8 /* WD compatible disk controllers */ -#define IO_GAMSIZE 16 /* AT compatible game controllers */ -#define IO_ICUSIZE 16 /* 8259A interrupt controllers */ -#define IO_KBDSIZE 16 /* 8042 Keyboard controllers */ -#define IO_LPTSIZE 8 /* LPT controllers, some use only 4 */ -#define IO_MDASIZE 16 /* Monochrome display controllers */ -#define IO_RTCSIZE 16 /* CMOS real time clock, NMI control */ -#define IO_TMRSIZE 16 /* 8253 programmable timers */ -#define IO_NPXSIZE 16 /* 80387/80487 NPX registers */ -#define IO_VGASIZE 16 /* VGA controllers */ - -#endif /* IO_ISASIZES */ - -/* - * Input / Output Memory Physical Addresses - */ - -#ifndef IOM_BEGIN -#define IOM_BEGIN 0x0a0000 /* Start of I/O Memory "hole" */ -#define IOM_END 0x100000 /* End of I/O Memory "hole" */ -#define IOM_SIZE (IOM_END - IOM_BEGIN) -#endif IOM_BEGIN - -/* - * RAM Physical Address Space (ignoring the above mentioned "hole") - */ - -#ifndef RAM_BEGIN -#define RAM_BEGIN 0x0000000 /* Start of RAM Memory */ -#define RAM_END 0x1000000 /* End of RAM Memory */ -#define RAM_SIZE (RAM_END - RAM_BEGIN) -#endif RAM_BEGIN - -/* - * Oddball Physical Memory Addresses - */ -#ifndef COMPAQ_RAMRELOC -#define COMPAQ_RAMRELOC 0x80c00000 /* Compaq RAM relocation/diag */ -#define COMPAQ_RAMSETUP 0x80c00002 /* Compaq RAM setup */ -#define WEITEK_FPU 0xC0000000 /* WTL 2167 */ -#define CYRIX_EMC 0xC0000000 /* Cyrix EMC */ -#endif COMPAQ_RAMRELOC diff --git a/sys/i386/isa/isa_device.h b/sys/i386/isa/isa_device.h deleted file mode 100644 index 4405c70..0000000 --- a/sys/i386/isa/isa_device.h +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)isa_device.h 7.1 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * ISA Bus Autoconfiguration - */ - -/* - * Per device structure. - */ -struct isa_device { - struct isa_driver *id_driver; - short id_iobase; /* base i/o address */ - u_short id_irq; /* interrupt request */ - short id_drq; /* DMA request */ - caddr_t id_maddr; /* physical i/o memory address on bus (if any)*/ - int id_msize; /* size of i/o memory */ - int (*id_intr)(); /* interrupt interface routine */ - int id_unit; /* unit number */ - int id_flags; /* flags */ - int id_scsiid; /* scsi id if needed */ - int id_alive; /* device is present */ -}; - -/* - * Per-driver structure. - * - * Each device driver defines entries for a set of routines - * as well as an array of types which are acceptable to it. - * These are used at boot time by the configuration program. - */ -struct isa_driver { - int (*probe)(); /* test whether device is present */ - int (*attach)(); /* setup driver for a device */ - char *name; /* device name */ -}; - -extern struct isa_device isa_devtab_bio[], isa_devtab_tty[], isa_devtab_net[], - isa_devtab_null[]; - -extern struct isa_device *find_isadev(/* table, driver, unit*/); diff --git a/sys/i386/isa/iso8859.font b/sys/i386/isa/iso8859.font deleted file mode 100644 index 4c5e972..0000000 --- a/sys/i386/isa/iso8859.font +++ /dev/null @@ -1,1230 +0,0 @@ -/* - * ISO 8859-1 font file - * - * $Id$ - */ - -char font_8x8[256*8] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E, -0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, -0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, -0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, -0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x7C, 0x38, 0x7C, -0x10, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C, -0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, -0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, -0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, -0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, -0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, -0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, -0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, -0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, -0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, -0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, -0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, -0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, -0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, -0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, -0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0xCC, 0x78, -0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, -0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, -0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, -0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, -0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, -0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, -0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, -0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, -0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, -0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x30, 0x78, 0x78, 0x30, 0x30, 0x00, 0x30, 0x00, -0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, -0x30, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x30, 0x00, -0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, -0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, -0x60, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, -0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, -0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, -0x00, 0x30, 0x30, 0xFC, 0x30, 0x30, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x60, -0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, -0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, -0x7C, 0xC6, 0xCE, 0xDE, 0xF6, 0xE6, 0x7C, 0x00, -0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00, -0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00, -0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00, -0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00, -0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00, -0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00, -0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00, -0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00, -0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00, -0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00, -0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x60, -0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00, -0x00, 0x00, 0xFC, 0x00, 0x00, 0xFC, 0x00, 0x00, -0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00, -0x78, 0xCC, 0x0C, 0x18, 0x30, 0x00, 0x30, 0x00, -0x7C, 0xC6, 0xDE, 0xDE, 0xDE, 0xC0, 0x78, 0x00, -0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00, -0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00, -0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, -0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, -0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00, -0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00, -0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3E, 0x00, -0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00, -0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, -0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, -0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00, -0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, -0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, -0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, -0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, -0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, -0x78, 0xCC, 0xCC, 0xCC, 0xDC, 0x78, 0x1C, 0x00, -0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00, -0x78, 0xCC, 0xE0, 0x70, 0x1C, 0xCC, 0x78, 0x00, -0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, -0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, -0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, -0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00, -0xC6, 0xC6, 0x6C, 0x38, 0x38, 0x6C, 0xC6, 0x00, -0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00, -0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00, -0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, -0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, -0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, -0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00, -0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, -0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, -0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, -0x38, 0x6C, 0x60, 0xF0, 0x60, 0x60, 0xF0, 0x00, -0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, -0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, -0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, -0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, -0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00, -0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, -0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xC6, 0x00, -0x00, 0x00, 0xF8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, -0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, -0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0, -0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E, -0x00, 0x00, 0xDC, 0x76, 0x66, 0x60, 0xF0, 0x00, -0x00, 0x00, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x00, -0x10, 0x30, 0x7C, 0x30, 0x30, 0x34, 0x18, 0x00, -0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, -0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, -0x00, 0x00, 0xC6, 0xD6, 0xFE, 0xFE, 0x6C, 0x00, -0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, -0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, -0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, -0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00, -0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, -0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00, -0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x7E, 0xFF, 0x7E, 0x18, 0x00, -0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, -0x44, 0x44, 0x44, 0x44, 0x1F, 0x04, 0x04, 0x04, -0x7C, 0x40, 0x40, 0x40, 0x1F, 0x10, 0x10, 0x10, -0x38, 0x44, 0x44, 0x38, 0x1E, 0x11, 0x14, 0x13, -0x40, 0x40, 0x40, 0x7C, 0x1F, 0x10, 0x10, 0x10, -0x38, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, -0x44, 0x64, 0x4C, 0x44, 0x10, 0x10, 0x10, 0x1F, -0x44, 0x44, 0x28, 0x10, 0x1F, 0x04, 0x04, 0x04, -0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, -0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, -0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x00, 0x0C, 0x30, 0x60, 0x18, 0x0C, 0x7E, 0x00, -0x00, 0x30, 0x0C, 0x06, 0x18, 0x30, 0x7E, 0x00, -0x00, 0x00, 0x03, 0x3E, 0x36, 0x36, 0x6C, 0x00, -0x00, 0x00, 0x04, 0x7E, 0x10, 0x7E, 0x40, 0x00, -0x00, 0x1C, 0x30, 0x30, 0x30, 0x30, 0x7E, 0x00, -0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x30, 0x00, 0x30, 0x30, 0x78, 0x78, 0x30, 0x00, -0x00, 0x00, 0x10, 0x7C, 0xC0, 0xC0, 0x7C, 0x10, -0x00, 0x38, 0x60, 0x60, 0xF0, 0x60, 0xFC, 0x00, -0x00, 0xC3, 0x3C, 0x66, 0x66, 0x3C, 0xC3, 0x00, -0x00, 0xCC, 0xCC, 0x78, 0x30, 0xFC, 0x30, 0x00, -0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, -0x7E, 0xC0, 0x7C, 0xC6, 0x7C, 0x06, 0xFC, 0x00, -0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x7C, 0x82, 0xBA, 0xA2, 0xBA, 0x82, 0x7C, 0x00, -0x1C, 0x06, 0x1E, 0x22, 0x1F, 0x3F, 0x00, 0x00, -0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00, -0x00, 0xFE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x7C, 0x82, 0xBA, 0xB2, 0xAA, 0x82, 0x7C, 0x00, -0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x38, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x10, 0x7C, 0x10, 0x00, 0x7C, 0x00, 0x00, -0x1C, 0x36, 0x06, 0x18, 0x3E, 0x00, 0x00, 0x00, -0x1E, 0x02, 0x0E, 0x02, 0x1E, 0x00, 0x00, 0x00, -0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0xC0, -0x7E, 0xCA, 0xCA, 0x7E, 0x0A, 0x0A, 0x0A, 0x00, -0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, -0x06, 0x0E, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, -0x0E, 0x11, 0x11, 0x11, 0x0E, 0x1F, 0x00, 0x00, -0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, -0x60, 0xE0, 0x66, 0x6C, 0x33, 0x67, 0x0F, 0x03, -0x60, 0xE0, 0x66, 0x6C, 0x36, 0x6A, 0x04, 0x0E, -0xF0, 0x20, 0x96, 0x6C, 0x33, 0x67, 0x0F, 0x03, -0x30, 0x00, 0x30, 0x60, 0xC0, 0xCC, 0x78, 0x00, -0x18, 0x0C, 0x30, 0x78, 0xCC, 0xFC, 0xCC, 0x00, -0x60, 0xC0, 0x30, 0x78, 0xCC, 0xFC, 0xCC, 0x00, -0x78, 0x84, 0x30, 0x78, 0xCC, 0xFC, 0xCC, 0x00, -0x66, 0x98, 0x30, 0x78, 0xCC, 0xFC, 0xCC, 0x00, -0xCC, 0x00, 0x30, 0x78, 0xCC, 0xFC, 0xCC, 0x00, -0x30, 0x48, 0x30, 0x78, 0xCC, 0xFC, 0xCC, 0x00, -0x3E, 0x78, 0x98, 0x9C, 0xF8, 0x98, 0x9E, 0x00, -0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x1C, 0x30, -0x30, 0x18, 0xFE, 0x62, 0x78, 0x62, 0xFE, 0x00, -0x18, 0x30, 0xFE, 0x62, 0x78, 0x62, 0xFE, 0x00, -0x38, 0x44, 0xFE, 0x62, 0x78, 0x62, 0xFE, 0x00, -0x66, 0x00, 0xFE, 0x62, 0x78, 0x62, 0xFE, 0x00, -0x60, 0x30, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, -0x18, 0x30, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, -0x78, 0x84, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, -0xCC, 0x00, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, -0x78, 0x6C, 0x66, 0xF6, 0x66, 0x6C, 0x78, 0x00, -0x66, 0x98, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0x00, -0x30, 0x18, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, -0x18, 0x30, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, -0x38, 0x44, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, -0x66, 0x98, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, -0xC6, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, -0x00, 0xC6, 0x6C, 0x38, 0x38, 0x6C, 0xC6, 0x00, -0x06, 0x7C, 0xCE, 0x9A, 0xB2, 0xE6, 0x78, 0xC0, -0x60, 0x30, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, -0x18, 0x30, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, -0x78, 0x84, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, -0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, -0x18, 0x30, 0xCC, 0xCC, 0x78, 0x30, 0x78, 0x00, -0x60, 0x78, 0x6C, 0x78, 0x60, 0x60, 0x60, 0x00, -0x78, 0xCC, 0xC4, 0xDC, 0xC6, 0xC6, 0xDC, 0xC0, -0x30, 0x18, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0x18, 0x30, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0x78, 0x84, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0x66, 0x98, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0xCC, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0x30, 0x48, 0x38, 0x0C, 0x7C, 0xCC, 0x76, 0x00, -0x00, 0x00, 0xEC, 0x32, 0x7E, 0xB0, 0x6E, 0x00, -0x00, 0x00, 0x3C, 0x66, 0xC0, 0x66, 0x1C, 0x30, -0x30, 0x18, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, -0x18, 0x30, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, -0x78, 0x84, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, -0xCC, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, -0x60, 0x30, 0x00, 0x70, 0x30, 0x30, 0x78, 0x00, -0x18, 0x30, 0x00, 0x70, 0x30, 0x30, 0x78, 0x00, -0x70, 0x88, 0x00, 0x70, 0x30, 0x30, 0x78, 0x00, -0xCC, 0x00, 0x00, 0x70, 0x30, 0x30, 0x78, 0x00, -0x6C, 0x38, 0x6C, 0x0C, 0x6C, 0xCC, 0x78, 0x00, -0x66, 0x98, 0xF8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, -0x60, 0x30, 0x00, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, -0x18, 0x30, 0x00, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, -0x38, 0x44, 0x00, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, -0x66, 0x98, 0x00, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, -0xC6, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, -0x00, 0x00, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x00, -0x00, 0x00, 0x06, 0x7C, 0xDE, 0xF6, 0x7C, 0xC0, -0x60, 0x30, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, -0x18, 0x30, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, -0x30, 0x48, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, -0xCC, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, -0x18, 0x30, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, -0xE0, 0x78, 0x6C, 0x66, 0x6C, 0x78, 0xE0, 0x00, -0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8 -}; - -char font_8x14[256*14] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x7E, 0x81, 0xA5, 0x81, 0x81, 0xBD, 0x99, 0x81, -0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xFF, -0xDB, 0xFF, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x7F, 0x7F, -0x7F, 0x7F, 0x3E, 0x1C, 0x08, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, -0x1C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x3C, 0x3C, 0xE7, 0xE7, 0xE7, 0x18, 0x18, -0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, -0x7E, 0xFF, 0xFF, 0x7E, 0x18, 0x18, 0x3C, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, -0x3C, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, -0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x24, 0x42, 0x42, 0x24, 0x3C, -0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, -0xC3, 0xDB, 0xBD, 0xBD, 0xDB, 0xC3, 0xFF, 0xFF, -0xFF, 0xFF, 0x00, 0x00, 0x1F, 0x07, 0x0D, 0x19, -0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, -0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x0A, 0x09, 0x09, 0x09, 0x0A, 0x08, 0x38, -0x78, 0x78, 0x30, 0x00, 0x00, 0x00, 0x1F, 0x11, -0x1F, 0x11, 0x11, 0x11, 0x13, 0x37, 0x77, 0x72, -0x20, 0x00, 0x00, 0x00, 0x18, 0x18, 0xDB, 0x3C, -0xE7, 0x3C, 0xDB, 0x18, 0x18, 0x00, 0x00, 0x00, -0x00, 0x00, 0x40, 0x60, 0x70, 0x7C, 0x7F, 0x7C, -0x70, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, -0x01, 0x03, 0x07, 0x1F, 0x7F, 0x1F, 0x07, 0x03, -0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, -0x7E, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, -0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, -0x33, 0x33, 0x00, 0x33, 0x33, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7F, 0xDB, 0xDB, 0xDB, 0x7B, 0x1B, -0x1B, 0x1B, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x3E, -0x63, 0x30, 0x1C, 0x36, 0x63, 0x63, 0x36, 0x1C, -0x06, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, -0x18, 0x18, 0x7E, 0x3C, 0x18, 0x7E, 0x00, 0x00, -0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x06, 0x7F, 0x06, 0x0C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, -0x7F, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, -0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x24, 0x42, 0xFF, 0x42, 0x24, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, -0x18, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, -0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x7F, 0x36, -0x36, 0x36, 0x7F, 0x36, 0x36, 0x00, 0x00, 0x00, -0x08, 0x08, 0x3E, 0x63, 0x60, 0x60, 0x3E, 0x03, -0x03, 0x63, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00, -0x00, 0x61, 0x63, 0x06, 0x0C, 0x18, 0x30, 0x63, -0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x36, -0x36, 0x1C, 0x3B, 0x6E, 0x66, 0x66, 0x3B, 0x00, -0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, -0x30, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x18, -0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x66, 0x3C, 0x7E, 0x3C, 0x66, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, -0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, -0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x0C, -0x18, 0x30, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3E, 0x63, 0x67, 0x6F, 0x7B, 0x73, -0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x1C, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, -0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x63, -0x03, 0x06, 0x0C, 0x18, 0x30, 0x63, 0x7F, 0x00, -0x00, 0x00, 0x00, 0x00, 0x3E, 0x63, 0x03, 0x03, -0x1E, 0x03, 0x03, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x06, 0x0E, 0x1E, 0x36, 0x66, 0x7F, -0x06, 0x06, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x7E, 0x60, 0x60, 0x60, 0x7E, 0x03, 0x03, 0x63, -0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x30, -0x60, 0x60, 0x7E, 0x63, 0x63, 0x63, 0x3E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x7F, 0x63, 0x03, 0x06, -0x0C, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3E, 0x63, 0x63, 0x63, 0x3E, 0x63, -0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x3E, 0x63, 0x63, 0x63, 0x3F, 0x03, 0x03, 0x06, -0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, -0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, -0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x30, -0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x7E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, -0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00, -0x00, 0x00, 0x00, 0x00, 0x3E, 0x63, 0x63, 0x06, -0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3E, 0x63, 0x63, 0x6F, 0x6F, 0x6F, -0x6E, 0x60, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x08, 0x1C, 0x36, 0x63, 0x63, 0x7F, 0x63, 0x63, -0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x33, -0x33, 0x33, 0x3E, 0x33, 0x33, 0x33, 0x7E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x1E, 0x33, 0x60, 0x60, -0x60, 0x60, 0x60, 0x33, 0x1E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0x36, 0x33, 0x33, 0x33, 0x33, -0x33, 0x36, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x7F, 0x33, 0x30, 0x34, 0x3C, 0x34, 0x30, 0x33, -0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x33, -0x30, 0x34, 0x3C, 0x34, 0x30, 0x30, 0x78, 0x00, -0x00, 0x00, 0x00, 0x00, 0x1E, 0x33, 0x60, 0x60, -0x60, 0x6F, 0x63, 0x33, 0x1D, 0x00, 0x00, 0x00, -0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x7F, 0x63, -0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, -0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x06, -0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00, -0x00, 0x00, 0x00, 0x00, 0x73, 0x33, 0x36, 0x36, -0x3C, 0x36, 0x36, 0x33, 0x73, 0x00, 0x00, 0x00, -0x00, 0x00, 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, -0x30, 0x33, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63, 0x63, -0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x73, -0x7B, 0x7F, 0x6F, 0x67, 0x63, 0x63, 0x63, 0x00, -0x00, 0x00, 0x00, 0x00, 0x1C, 0x36, 0x63, 0x63, -0x63, 0x63, 0x63, 0x36, 0x1C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7E, 0x33, 0x33, 0x33, 0x3E, 0x30, -0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, -0x1C, 0x36, 0x63, 0x63, 0x63, 0x63, 0x6B, 0x3E, -0x1C, 0x06, 0x03, 0x00, 0x00, 0x00, 0x7E, 0x33, -0x33, 0x33, 0x3E, 0x36, 0x33, 0x33, 0x73, 0x00, -0x00, 0x00, 0x00, 0x00, 0x3E, 0x63, 0x63, 0x30, -0x1C, 0x06, 0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, -0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, -0x63, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x08, 0x00, -0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, -0x63, 0x6B, 0x6B, 0x7F, 0x36, 0x00, 0x00, 0x00, -0x00, 0x00, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x36, -0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, -0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, -0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x63, -0x06, 0x0C, 0x18, 0x30, 0x60, 0x63, 0x7F, 0x00, -0x00, 0x00, 0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, -0x30, 0x30, 0x30, 0x30, 0x3C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, -0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, -0x3C, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x36, 0x63, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x18, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, -0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x30, -0x30, 0x3E, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, -0x63, 0x60, 0x60, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0E, 0x06, 0x06, 0x3E, 0x66, 0x66, -0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x3E, 0x63, 0x7F, 0x60, 0x63, -0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x33, -0x30, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, -0x66, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C, 0x00, -0x00, 0x00, 0x70, 0x30, 0x30, 0x36, 0x3B, 0x33, -0x33, 0x33, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x0C, 0x00, 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, -0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, -0x00, 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0xCC, -0x78, 0x00, 0x00, 0x00, 0x70, 0x30, 0x30, 0x33, -0x36, 0x3C, 0x36, 0x33, 0x73, 0x00, 0x00, 0x00, -0x00, 0x00, 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, -0x0C, 0x0C, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x66, 0x7F, 0x6B, 0x6B, 0x6B, -0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x6E, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, -0x63, 0x63, 0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x6E, 0x33, 0x33, -0x33, 0x3E, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x3B, 0x66, 0x66, 0x66, 0x3E, -0x06, 0x06, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x6E, 0x33, 0x30, 0x30, 0x30, 0x78, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, -0x63, 0x38, 0x0E, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x08, 0x18, 0x7E, 0x18, 0x18, -0x18, 0x1B, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, -0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x08, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, -0x63, 0x6B, 0x6B, 0x7F, 0x36, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1C, -0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x63, 0x66, 0x66, 0x66, 0x3E, -0x06, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x7F, 0x66, 0x0C, 0x18, 0x33, 0x7F, 0x00, -0x00, 0x00, 0x00, 0x00, 0x0E, 0x18, 0x18, 0x18, -0x70, 0x18, 0x18, 0x18, 0x0E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x70, 0x18, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x18, -0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, 0x6E, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, -0x36, 0x63, 0x63, 0x7F, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x7E, 0x3C, -0x18, 0x00, 0x00, 0x00, 0x55, 0xAA, 0x55, 0xAA, -0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, -0x55, 0xAA, 0x00, 0x44, 0x44, 0x7C, 0x44, 0x44, -0x00, 0x1F, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, -0x00, 0x7C, 0x40, 0x78, 0x40, 0x40, 0x00, 0x1F, -0x10, 0x1E, 0x10, 0x10, 0x00, 0x00, 0x00, 0x38, -0x44, 0x40, 0x44, 0x38, 0x00, 0x1E, 0x11, 0x1E, -0x14, 0x13, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, -0x40, 0x7C, 0x00, 0x1F, 0x10, 0x1E, 0x10, 0x10, -0x00, 0x00, 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, -0x18, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x44, -0x64, 0x54, 0x4C, 0x44, 0x00, 0x10, 0x10, 0x10, -0x10, 0x1F, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, -0x28, 0x10, 0x00, 0x1F, 0x04, 0x04, 0x04, 0x04, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x0C, 0x18, -0x30, 0x60, 0x30, 0x18, 0x0C, 0x00, 0x7E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0C, 0x06, -0x0C, 0x18, 0x30, 0x00, 0x7E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x03, 0x3E, 0x76, 0x36, -0x36, 0x36, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x02, 0x04, 0x7E, 0x08, 0x10, 0x7E, 0x20, -0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x36, -0x30, 0x30, 0x7C, 0x30, 0x30, 0x73, 0x7E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x00, 0x18, 0x18, 0x3C, 0x3C, 0x3C, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, -0x08, 0x3E, 0x63, 0x60, 0x60, 0x63, 0x3E, 0x08, -0x08, 0x00, 0x00, 0x00, 0x1C, 0x36, 0x30, 0x30, -0x7C, 0x30, 0x30, 0x73, 0x7E, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x42, 0x3C, 0x66, 0x66, 0x66, -0x3C, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 0x7E, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, -0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, -0x00, 0x00, 0x00, 0x3E, 0x63, 0x30, 0x1C, 0x36, -0x63, 0x63, 0x36, 0x1C, 0x06, 0x63, 0x3E, 0x00, -0x00, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x3E, 0x41, 0x5D, 0x51, 0x51, 0x5D, 0x41, -0x3E, 0x00, 0x00, 0x00, 0x00, 0x38, 0x04, 0x3C, -0x44, 0x3C, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x36, -0x6C, 0x36, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x03, -0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, -0x41, 0x5D, 0x55, 0x59, 0x55, 0x41, 0x3E, 0x00, -0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, -0x7E, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6C, 0x18, -0x30, 0x64, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x7C, 0x0C, 0x38, 0x0C, 0x6C, -0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x06, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, -0x3B, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x7F, 0xDB, -0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x1B, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0C, 0x0C, 0x06, 0x1C, 0x00, 0x30, -0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, -0x44, 0x38, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x36, -0x1B, 0x36, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x60, 0xE0, 0x63, 0x66, 0x6C, 0x18, 0x33, -0x67, 0xCF, 0x1F, 0x03, 0x03, 0x00, 0x00, 0x60, -0xE0, 0x63, 0x66, 0x6C, 0x18, 0x30, 0x6E, 0xC3, -0x06, 0x0C, 0x1F, 0x00, 0x00, 0xF0, 0x30, 0x63, -0xF6, 0x6C, 0x18, 0x33, 0x67, 0xCF, 0x1F, 0x03, -0x03, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, -0x18, 0x30, 0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x60, 0x30, 0x18, 0x00, 0x1C, 0x36, 0x63, 0x63, -0x7F, 0x63, 0x63, 0x00, 0x00, 0x00, 0x03, 0x06, -0x0C, 0x00, 0x1C, 0x36, 0x63, 0x63, 0x7F, 0x63, -0x63, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x36, 0x00, -0x1C, 0x36, 0x63, 0x63, 0x7F, 0x63, 0x63, 0x00, -0x00, 0x00, 0x3B, 0x6E, 0x00, 0x08, 0x1C, 0x36, -0x63, 0x63, 0x7F, 0x63, 0x63, 0x00, 0x00, 0x00, -0x00, 0x63, 0x63, 0x08, 0x1C, 0x36, 0x63, 0x63, -0x7F, 0x63, 0x63, 0x00, 0x00, 0x00, 0x1C, 0x36, -0x1C, 0x00, 0x1C, 0x36, 0x63, 0x63, 0x7F, 0x63, -0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x36, -0x66, 0x66, 0x67, 0x7E, 0x66, 0x66, 0x67, 0x00, -0x00, 0x00, 0x00, 0x00, 0x1E, 0x33, 0x60, 0x60, -0x60, 0x60, 0x60, 0x33, 0x1E, 0x0C, 0x06, 0x1C, -0x60, 0x30, 0x18, 0x00, 0x7F, 0x33, 0x30, 0x3E, -0x30, 0x33, 0x7F, 0x00, 0x00, 0x00, 0x06, 0x0C, -0x18, 0x00, 0x7F, 0x33, 0x30, 0x3E, 0x30, 0x33, -0x7F, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x36, 0x00, -0x7F, 0x33, 0x30, 0x3E, 0x30, 0x33, 0x7F, 0x00, -0x00, 0x00, 0x00, 0x63, 0x63, 0x00, 0x7F, 0x33, -0x30, 0x3E, 0x30, 0x33, 0x7F, 0x00, 0x00, 0x00, -0x60, 0x30, 0x18, 0x00, 0x3C, 0x18, 0x18, 0x18, -0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x06, 0x0C, -0x18, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, -0x3C, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x66, 0x00, -0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, -0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x3C, 0x18, -0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x36, 0x33, 0x33, 0x7B, 0x33, -0x33, 0x36, 0x3C, 0x00, 0x00, 0x00, 0x3B, 0x6E, -0x00, 0x63, 0x73, 0x7B, 0x7F, 0x6F, 0x67, 0x63, -0x63, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, -0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00, -0x00, 0x00, 0x03, 0x06, 0x0C, 0x00, 0x1C, 0x36, -0x63, 0x63, 0x63, 0x36, 0x1C, 0x00, 0x00, 0x00, -0x08, 0x1C, 0x36, 0x00, 0x1C, 0x36, 0x63, 0x63, -0x63, 0x36, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x3B, -0x6E, 0x00, 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, -0x1C, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x00, -0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1C, -0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, -0x00, 0x03, 0x1E, 0x36, 0x67, 0x6F, 0x6B, 0x7B, -0x73, 0x36, 0x3C, 0x60, 0x00, 0x00, 0x60, 0x30, -0x18, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, -0x3E, 0x00, 0x00, 0x00, 0x03, 0x06, 0x0C, 0x00, -0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3E, 0x00, -0x00, 0x00, 0x08, 0x1C, 0x36, 0x00, 0x63, 0x63, -0x63, 0x63, 0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x63, 0x63, 0x00, 0x63, 0x63, 0x63, 0x63, -0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x06, 0x0C, -0x18, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, -0x3C, 0x00, 0x00, 0x00, 0x00, 0x78, 0x30, 0x3E, -0x33, 0x33, 0x3E, 0x30, 0x30, 0x30, 0x78, 0x00, -0x00, 0x00, 0x00, 0x00, 0x1C, 0x36, 0x63, 0x66, -0x6C, 0x67, 0x63, 0x6B, 0x6E, 0x60, 0x60, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0x3C, 0x06, 0x3E, -0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x06, -0x0C, 0x18, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, -0x3B, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x36, -0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00, -0x00, 0x00, 0x00, 0x00, 0x3B, 0x6E, 0x00, 0x3C, -0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, -0x00, 0x00, 0x66, 0x66, 0x00, 0x3C, 0x06, 0x3E, -0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x1C, -0x36, 0x1C, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x66, -0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x76, 0x0B, 0x3B, 0x6E, 0x68, 0x37, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, -0x63, 0x60, 0x60, 0x63, 0x3E, 0x0C, 0x06, 0x1C, -0x00, 0x30, 0x18, 0x0C, 0x00, 0x3E, 0x63, 0x7F, -0x60, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x03, -0x06, 0x0C, 0x00, 0x3E, 0x63, 0x7F, 0x60, 0x63, -0x3E, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1C, 0x36, -0x00, 0x3E, 0x63, 0x7F, 0x60, 0x63, 0x3E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x00, 0x3E, -0x63, 0x7F, 0x60, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, -0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x06, -0x0C, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, -0x3C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x66, -0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, -0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x38, -0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x36, 0x1C, 0x36, 0x06, 0x3E, 0x66, -0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x3B, 0x6E, 0x00, 0x6E, 0x33, 0x33, 0x33, 0x33, -0x33, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, -0x00, 0x3E, 0x63, 0x63, 0x63, 0x63, 0x3E, 0x00, -0x00, 0x00, 0x00, 0x06, 0x0C, 0x18, 0x00, 0x3E, -0x63, 0x63, 0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, -0x00, 0x08, 0x1C, 0x36, 0x00, 0x3E, 0x63, 0x63, -0x63, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x3B, 0x6E, 0x00, 0x3E, 0x63, 0x63, 0x63, 0x63, -0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, -0x00, 0x3E, 0x63, 0x63, 0x63, 0x63, 0x3E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, -0x7E, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x03, 0x3E, 0x67, 0x6F, -0x7B, 0x73, 0x3E, 0x60, 0x00, 0x00, 0x00, 0x60, -0x30, 0x18, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, -0x3B, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0C, 0x18, -0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3B, 0x00, -0x00, 0x00, 0x00, 0x18, 0x3C, 0x66, 0x00, 0x66, -0x66, 0x66, 0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, -0x00, 0x00, 0x66, 0x66, 0x00, 0x66, 0x66, 0x66, -0x66, 0x66, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x06, -0x0C, 0x18, 0x00, 0x63, 0x66, 0x66, 0x66, 0x3E, -0x06, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x78, -0x30, 0x3E, 0x33, 0x33, 0x33, 0x33, 0x3E, 0x30, -0x78, 0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x66, -0x66, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C, 0x00 -}; - -char font_8x16[256*16] = { -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7E, 0x81, 0xA5, 0x81, 0x81, 0xBD, -0x99, 0x81, 0x81, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7E, 0xFF, 0xDB, 0xFF, 0xFF, 0xC3, -0xE7, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x6C, 0xFE, 0xFE, 0xFE, -0xFE, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0xFE, -0x7C, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x18, 0x3C, 0x3C, 0xE7, 0xE7, -0xE7, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, -0x7E, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, -0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC3, -0xC3, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, -0x42, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0x99, 0xBD, -0xBD, 0x99, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -0x00, 0x00, 0x1E, 0x0E, 0x1A, 0x32, 0x78, 0xCC, -0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, -0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x30, -0x30, 0x70, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x63, -0x63, 0x67, 0xE7, 0xE6, 0xC0, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x18, 0x18, 0xDB, 0x3C, 0xE7, -0x3C, 0xDB, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFE, 0xF8, -0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x02, 0x06, 0x0E, 0x1E, 0x3E, 0xFE, 0x3E, -0x1E, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, -0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, -0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7F, 0xDB, 0xDB, 0xDB, 0x7B, 0x1B, -0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, 0x00, 0x00, -0x00, 0x7C, 0xC6, 0x60, 0x38, 0x6C, 0xC6, 0xC6, -0x6C, 0x38, 0x0C, 0xC6, 0x7C, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0xFE, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, -0x7E, 0x3C, 0x18, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0C, 0xFE, -0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xFE, -0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, -0xC0, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x66, 0xFF, -0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7C, -0x7C, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x7C, 0x7C, -0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x18, -0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x6C, 0x6C, 0xFE, 0x6C, 0x6C, -0x6C, 0xFE, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x7C, 0xC6, 0xC2, 0xC0, 0x7C, 0x06, -0x06, 0x86, 0xC6, 0x7C, 0x18, 0x18, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xC2, 0xC6, 0x0C, 0x18, -0x30, 0x60, 0xC6, 0x86, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x76, 0xDC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, -0x30, 0x30, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x0C, -0x0C, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3C, 0xFF, -0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, -0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0C, 0x18, -0x30, 0x60, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x66, 0xC3, 0xC3, 0xDB, 0xDB, -0xC3, 0xC3, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0x06, 0x0C, 0x18, 0x30, -0x60, 0xC0, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0x06, 0x06, 0x3C, 0x06, -0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0C, 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, -0x0C, 0x0C, 0x0C, 0x1E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFE, 0xC0, 0xC0, 0xC0, 0xFC, 0x06, -0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x38, 0x60, 0xC0, 0xC0, 0xFC, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFE, 0xC6, 0x06, 0x06, 0x0C, 0x18, -0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, -0x06, 0x06, 0x0C, 0x78, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, -0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, -0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, -0x30, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, -0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, -0x0C, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x0C, 0x18, 0x18, -0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xDE, 0xDE, -0xDE, 0xDC, 0xC0, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, -0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x66, -0x66, 0x66, 0x66, 0xFC, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xC0, -0xC0, 0xC2, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x66, -0x66, 0x66, 0x6C, 0xF8, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFE, 0x66, 0x62, 0x68, 0x78, 0x68, -0x60, 0x62, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFE, 0x66, 0x62, 0x68, 0x78, 0x68, -0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xDE, -0xC6, 0xC6, 0x66, 0x3A, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, -0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, -0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xE6, 0x66, 0x66, 0x6C, 0x78, 0x78, -0x6C, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xF0, 0x60, 0x60, 0x60, 0x60, 0x60, -0x60, 0x62, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC3, 0xE7, 0xFF, 0xFF, 0xDB, 0xC3, -0xC3, 0xC3, 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC6, 0xE6, 0xF6, 0xFE, 0xDE, 0xCE, -0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x60, -0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xD6, 0xDE, 0x7C, 0x0C, 0x0E, 0x00, 0x00, -0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x6C, -0x66, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x60, 0x38, 0x0C, -0x06, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFF, 0xDB, 0x99, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, -0xC3, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xDB, -0xDB, 0xFF, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC3, 0xC3, 0x66, 0x3C, 0x18, 0x18, -0x3C, 0x66, 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC3, 0xC3, 0xC3, 0x66, 0x3C, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xFF, 0xC3, 0x86, 0x0C, 0x18, 0x30, -0x60, 0xC1, 0xC3, 0xFF, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, -0x30, 0x30, 0x30, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x70, 0x38, -0x1C, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, -0x0C, 0x0C, 0x0C, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, -0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xE0, 0x60, 0x60, 0x78, 0x6C, 0x66, -0x66, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC0, -0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x1C, 0x0C, 0x0C, 0x3C, 0x6C, 0xCC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xFE, -0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, -0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xCC, 0x78, 0x00, -0x00, 0x00, 0xE0, 0x60, 0x60, 0x6C, 0x76, 0x66, -0x66, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x06, 0x06, 0x00, 0x0E, 0x06, 0x06, -0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00, -0x00, 0x00, 0xE0, 0x60, 0x60, 0x66, 0x6C, 0x78, -0x78, 0x6C, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0xFF, 0xDB, -0xDB, 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x66, 0x66, -0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x66, 0x66, -0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0x0C, 0x1E, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x76, 0x66, -0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0x60, -0x38, 0x0C, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x10, 0x30, 0x30, 0xFC, 0x30, 0x30, -0x30, 0x30, 0x36, 0x1C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xCC, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC3, 0xC3, -0xC3, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC3, 0xC3, -0xDB, 0xDB, 0xFF, 0x66, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x66, 0x3C, -0x18, 0x3C, 0x66, 0xC3, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x0C, 0xF8, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xCC, 0x18, -0x30, 0x60, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0E, 0x18, 0x18, 0x18, 0x70, 0x18, -0x18, 0x18, 0x18, 0x0E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0E, 0x18, -0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, -0xC6, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, -0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, -0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, -0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, -0x00, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x00, -0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, -0x00, 0xF8, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x00, -0x3E, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00, -0x00, 0x70, 0x88, 0x80, 0x80, 0x88, 0x70, 0x00, -0x3C, 0x22, 0x3C, 0x28, 0x24, 0x22, 0x00, 0x00, -0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, -0x3E, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x00, 0x00, -0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, -0x18, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, -0x00, 0x88, 0xC8, 0xA8, 0xA8, 0x98, 0x88, 0x00, -0x20, 0x20, 0x20, 0x20, 0x20, 0x3E, 0x00, 0x00, -0x00, 0x88, 0x88, 0x88, 0x88, 0x50, 0x20, 0x00, -0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -0x00, 0x00, 0x00, 0x0C, 0x18, 0x30, 0x60, 0x30, -0x18, 0x0C, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x30, 0x18, 0x0C, 0x06, 0x0C, -0x18, 0x30, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x02, 0x7E, 0xEC, 0x6C, 0x6C, -0x6C, 0x6C, 0x6C, 0xCC, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x06, 0x0C, 0x7E, 0x18, 0x18, -0x7E, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, 0x60, -0x60, 0x60, 0xE6, 0xFC, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, -0x3C, 0x3C, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x18, 0x7E, 0xC3, 0xC0, 0xC0, 0xC0, -0xC3, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, 0x60, -0x60, 0x60, 0xE6, 0xFC, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x82, 0xC6, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0x7C, 0xC6, 0x82, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC3, 0x66, 0x3C, 0x18, 0xFF, 0x18, -0xFF, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, -0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, -0x00, 0x7C, 0xC6, 0x60, 0x38, 0x6C, 0xC6, 0xC6, -0x6C, 0x38, 0x0C, 0xC6, 0x7C, 0x00, 0x00, 0x00, -0x00, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0x82, 0xBA, 0xA2, 0xA2, -0xBA, 0x82, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x70, 0x18, 0x78, 0xC8, 0x78, 0x00, 0xF8, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6C, 0xD8, -0x6C, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x06, -0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7C, 0xC6, 0x82, 0xBA, 0xAA, 0xB2, -0xAA, 0x82, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, -0x18, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, -0x00, 0x70, 0xD8, 0x30, 0x60, 0xC8, 0xF8, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0xF8, 0x18, 0x30, 0x18, 0xD8, 0x70, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, -0x66, 0x7E, 0x63, 0x60, 0xC0, 0x00, 0x00, 0x00, -0x00, 0x00, 0x7F, 0xDB, 0xDB, 0xDB, 0x7B, 0x1B, -0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, -0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x18, 0x0C, 0x06, 0x3C, 0x00, 0x00, -0x00, 0x60, 0xE0, 0x60, 0x60, 0x60, 0xF0, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x70, 0xD8, 0x88, 0xD8, 0x70, 0x00, 0xF8, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x6C, 0x36, -0x6C, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0xC0, 0xC0, 0xC2, 0xC6, 0xCC, 0x18, 0x30, -0x66, 0xCE, 0x96, 0x3E, 0x06, 0x06, 0x00, 0x00, -0x00, 0xC0, 0xC0, 0xC2, 0xC6, 0xCC, 0x18, 0x30, -0x60, 0xCE, 0x9B, 0x06, 0x0C, 0x1F, 0x00, 0x00, -0x00, 0xF0, 0x30, 0x72, 0x36, 0xEC, 0x18, 0x30, -0x66, 0xCE, 0x96, 0x3E, 0x06, 0x06, 0x00, 0x00, -0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, -0xC0, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x60, 0x30, 0x18, 0x00, 0x38, 0x6C, 0xC6, 0xC6, -0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x18, 0x30, 0x00, 0x38, 0x6C, 0xC6, 0xC6, -0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x10, 0x38, 0x6C, 0x00, 0x38, 0x6C, 0xC6, 0xC6, -0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x76, 0xDC, 0x00, 0x38, 0x6C, 0xC6, 0xC6, -0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0xC6, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, -0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x38, 0x6C, 0x38, 0x00, 0x38, 0x6C, 0xC6, 0xC6, -0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3E, 0x6C, 0xCC, 0xCC, 0xFE, 0xCC, -0xCC, 0xCC, 0xCC, 0xCE, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xC0, -0xC2, 0x66, 0x3C, 0x0C, 0x06, 0x7C, 0x00, 0x00, -0x30, 0x18, 0x0C, 0x00, 0xFE, 0x66, 0x60, 0x7C, -0x60, 0x60, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x18, 0x30, 0x60, 0x00, 0xFE, 0x66, 0x60, 0x7C, -0x60, 0x60, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x10, 0x38, 0x6C, 0x00, 0xFE, 0x66, 0x60, 0x7C, -0x60, 0x60, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x00, 0xC6, 0x00, 0xFE, 0x66, 0x60, 0x60, 0x7C, -0x60, 0x60, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00, -0x30, 0x18, 0x0C, 0x00, 0x3C, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x18, 0x30, 0x00, 0x3C, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x18, 0x3C, 0x66, 0x00, 0x3C, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x66, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x78, 0x6C, 0x66, 0x66, 0x66, 0xF6, -0x66, 0x66, 0x6C, 0x78, 0x00, 0x00, 0x00, 0x00, -0x76, 0xDC, 0x00, 0xC6, 0xE6, 0xF6, 0xFE, 0xDE, -0xCE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00, -0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x18, 0x30, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x76, 0xDC, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0xC6, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x10, -0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, -0x02, 0x06, 0x7C, 0xCE, 0xCE, 0xDE, 0xD6, 0xD6, -0xF6, 0xE6, 0xE6, 0x7C, 0xC0, 0x80, 0x00, 0x00, -0x60, 0x30, 0x18, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x18, 0x30, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x10, 0x38, 0x6C, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x0C, 0x18, 0x30, 0x00, 0xC3, 0xC3, 0x66, 0x3C, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0xF0, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, -0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x38, 0x6C, 0xC6, 0xCE, 0xDC, 0xD8, -0xCC, 0xC6, 0xD6, 0xDC, 0xC0, 0x80, 0x00, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x10, 0x38, 0x6C, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x76, 0xDC, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xCC, 0x00, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x38, 0x6C, 0x38, 0x00, 0x78, 0x0C, 0x7C, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x6E, 0x3B, 0x1B, -0x7E, 0xD8, 0xDC, 0x77, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x60, -0x66, 0x3C, 0x0C, 0x06, 0x3C, 0x00, 0x00, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xFE, -0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x0C, 0x18, 0x30, 0x00, 0x7C, 0xC6, 0xFE, -0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xFE, -0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC6, 0x00, 0x00, 0x7C, 0xC6, 0xFE, -0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x06, 0x0C, 0x18, 0x00, 0x38, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x3C, 0x66, 0x00, 0x38, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18, -0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x6C, 0x38, 0x38, 0x6C, 0x0C, 0x3C, 0x6C, -0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x76, 0xDC, 0x00, 0xDC, 0x66, 0x66, -0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x30, 0x60, 0x00, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x76, 0xDC, 0x00, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xC6, 0x00, 0x00, 0x7C, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7E, -0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x02, 0x06, 0x7C, 0xCE, 0xDE, -0xD6, 0xF6, 0xE6, 0x7C, 0xC0, 0x80, 0x00, 0x00, -0x00, 0x60, 0x30, 0x18, 0x00, 0xCC, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x30, 0x60, 0x00, 0xCC, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x30, 0x78, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0xCC, 0x00, 0x00, 0xCC, 0xCC, 0xCC, -0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00, -0x00, 0x18, 0x30, 0x60, 0x00, 0xC6, 0xC6, 0xC6, -0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x0C, 0xF8, 0x00, -0x00, 0x00, 0x00, 0xF0, 0x60, 0x7C, 0x66, 0x66, -0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, -0x00, 0x00, 0x66, 0x66, 0x00, 0xEE, 0x66, 0x66, -0x66, 0x66, 0x66, 0x3E, 0x06, 0x0C, 0x38, 0x00 -}; diff --git a/sys/i386/isa/kbd.h b/sys/i386/isa/kbd.h deleted file mode 100644 index 66e5224..0000000 --- a/sys/i386/isa/kbd.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Keyboard definitions - * from: unknown origin, 386BSD 0.1 - * $Id$ - */ - -/* Reference: IBM AT Technical Reference Manual, - * pp. 1-38 to 1-43, 4-3 to 4-22 - */ - -/* commands sent to KBCMDP */ - -#define KBC_CMDREAD 0x20 /* read kbd cntrl command byte */ -#define KBC_CMDWRITE 0x60 /* == LD_CMDBYTE in kd.h, write command */ -#define KBC_SELFTEST 0xAA /* perform self test, returns 55 when ok */ -#define KBC_IFTEST 0xAB /* perform interface test */ -#define KBC_DIAGDUMP 0xAC /* send 19 status bytes to system */ -#define KBC_DISKBD 0xAD /* disable keyboard */ -#define KBC_ENAKBD 0xAE /* enable keyboard */ -#define KBC_RDINP 0xC0 /* read input port */ -#define KBC_RDID 0xC4 /* read keyboard ID */ -#define KBC_RDOUTP 0xD0 /* read output port */ -#define KBC_WROUTP 0xD1 /* write output port */ -#define KBC_RDTINP 0xE0 /* read test inputs */ - -/* commands sent to KBDATAP */ -#define KBC_STSIND 0xED /* set keyboard status indicators */ -#define KBC_ECHO 0xEE /* reply with 0xEE */ -#define KBC_SETTPM 0xF3 /* Set typematic rate/delay */ -#define KBC_ENABLE 0xF4 /* Start scanning */ -#define KBC_SETDEFD 0xF5 /* =KBC_SETDEF, but disable scanning */ -#define KBC_SETDEF 0xF6 /* Set power on defaults */ -#define KBC_RESEND 0xFE /* system wants keyboard to resend last code */ -#define KBC_RESET 0xFF /* Reset the keyboard */ - -/* responses */ -#define KBR_OVERRUN 0x00 /* Keyboard flooded */ -#define KBR_STOK 0x55 /* Selftest ok response */ -#define KBR_IFOK 0x00 /* Interface test ok */ -#define KBR_IFCL_SA0 0x01 /* Clock Stuck-at-0 fault */ -#define KBR_IFCL_SA1 0x02 /* Clock Stuck-at-1 fault */ -#define KBR_IFDA_SA0 0x03 /* Data Stuck-at-0 fault */ -#define KBR_IFDA_SA1 0x04 /* Data Stuck-at-1 fault */ -#define KBR_RSTDONE 0xAA /* Keyboard reset (BAT) complete */ -#define KBR_E0 0xE0 /* Extended prefix */ -#define KBR_E1 0xE1 /* BREAK'S HIT :-( */ -#define KBR_ECHO 0xEE /* Echo response */ -#define KBR_F0 0xF0 /* Break code prefix */ -#define KBR_ACK 0xFA /* Keyboard did receive command */ -#define KBR_BATFAIL 0xFC /* BAT failed */ -#define KBR_DIAGFAIL 0xFD /* Diagnostic failed response */ -#define KBR_RESEND 0xFE /* Keyboard needs resend of command */ diff --git a/sys/i386/isa/kbdtables.h b/sys/i386/isa/kbdtables.h deleted file mode 100644 index 5acb9af..0000000 --- a/sys/i386/isa/kbdtables.h +++ /dev/null @@ -1,858 +0,0 @@ -/* - * Copyright (C) 1992, 1993 Søren Schmidt - * - * This program is free software; you may redistribute it and/or - * modify it, provided that it retain the above copyright notice - * and the following disclaimer. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Søren Schmidt Email: sos@kmd-ac.dk - * Tritonvej 36 UUCP: ...uunet!dkuug!kmd-ac!sos - * DK9210 Aalborg SO Phone: +45 9814 8076 - * - * $Id$ - */ - -#define META 0x80 /* eight bit for emacs META-key */ - -#ifdef DKKEYMAP -keymap_t key_map = { 0x69, /* DK iso8859 keymap */ -/* alt - * scan cntrl alt alt cntrl - * code base shift cntrl shift alt shift cntrl shift spcl flgs - * --------------------------------------------------------------------------- - */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, NOP, NOP, 0x1B, 0x1B, NOP, NOP, 0x33, 0x00, -/* sc=02 */ '1', '!', NOP, NOP, '1', '!', NOP, NOP, 0x33, 0x00, -/* sc=03 */ '2', '"', 0x00, 0x00, '@', '"', 0x00, 0x00, 0x00, 0x00, -/* sc=04 */ '3', '#', NOP, NOP, 0x9E, '#', NOP, NOP, 0x33, 0x00, -/* sc=05 */ '4', 0xA4, NOP, NOP, '$', 0xA4, NOP, NOP, 0x33, 0x00, -/* sc=06 */ '5', '%', NOP, NOP, '5', '%', NOP, NOP, 0x33, 0x00, -/* sc=07 */ '6', '&', NOP, NOP, '6', '&', NOP, NOP, 0x33, 0x00, -/* sc=08 */ '7', '/', NOP, NOP, '{', '/', NOP, NOP, 0x33, 0x00, -/* sc=09 */ '8', '(', 0x1B, 0x1B, '[', '(', 0x1B, 0x1B, 0x00, 0x00, -/* sc=0a */ '9', ')', 0x1D, 0x1D, ']', ')', 0x1D, 0x1D, 0x00, 0x00, -/* sc=0b */ '0', '=', NOP, NOP, '}', '=', NOP, NOP, 0x33, 0x00, -/* sc=0c */ '+', '?', NOP, NOP, '+', '?', NOP, NOP, 0x33, 0x00, -/* sc=0d */ '\'', '`', NOP, NOP, '|', '`', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, 0x08, 0x08, 0x00, 0x00, -/* sc=0f */ 0x09, 0x08, NOP, NOP, 0x09, 0x08, NOP, NOP, 0x33, 0x00, -/* sc=10 */ 'q', 'Q', 0x11, 0x11, 'q', 'Q', 0x11, 0x11, 0x00, 0x01, -/* sc=11 */ 'w', 'W', 0x17, 0x17, 'w', 'W', 0x17, 0x17, 0x00, 0x01, -/* sc=12 */ 'e', 'E', 0x05, 0x05, 'e', 'E', 0x05, 0x05, 0x00, 0x01, -/* sc=13 */ 'r', 'R', 0x12, 0x12, 'r', 'R', 0x12, 0x12, 0x00, 0x01, -/* sc=14 */ 't', 'T', 0x14, 0x14, 't', 'T', 0x14, 0x14, 0x00, 0x01, -/* sc=15 */ 'y', 'Y', 0x19, 0x19, 'y', 'Y', 0x19, 0x19, 0x00, 0x01, -/* sc=16 */ 'u', 'U', 0x15, 0x15, 'u', 'U', 0x15, 0x15, 0x00, 0x01, -/* sc=17 */ 'i', 'I', 0x09, 0x09, 'i', 'I', 0x09, 0x09, 0x00, 0x01, -/* sc=18 */ 'o', 'O', 0x0F, 0x0F, 'o', 'O', 0x0F, 0x0F, 0x00, 0x01, -/* sc=19 */ 'p', 'P', 0x10, 0x10, 'p', 'P', 0x10, 0x10, 0x00, 0x01, -/* sc=1a */ 0xE5, 0xC5, NOP, NOP, 0x86, 0x8F, NOP, NOP, 0x33, 0x01, -/* sc=1b */ '"', '^', 0x1E, 0x1E, '~', '^', 0x1E, 0x1E, 0x00, 0x00, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 'a', 'A', 0x01, 0x01, 'a', 'A', 0x01, 0x01, 0x00, 0x01, -/* sc=1f */ 's', 'S', 0x13, 0x13, 's', 'S', 0x13, 0x13, 0x00, 0x01, -/* sc=20 */ 'd', 'D', 0x04, 0x04, 'd', 'D', 0x04, 0x04, 0x00, 0x01, -/* sc=21 */ 'f', 'F', 0x06, 0x06, 'f', 'F', 0x06, 0x06, 0x00, 0x01, -/* sc=22 */ 'g', 'G', 0x07, 0x07, 'g', 'G', 0x07, 0x07, 0x00, 0x01, -/* sc=23 */ 'h', 'H', 0x08, 0x08, 'h', 'H', 0x08, 0x08, 0x00, 0x01, -/* sc=24 */ 'j', 'J', 0x0A, 0x0A, 'j', 'J', 0x0A, 0x0A, 0x00, 0x01, -/* sc=25 */ 'k', 'K', 0x0B, 0x0B, 'k', 'K', 0x0B, 0x0B, 0x00, 0x01, -/* sc=26 */ 'l', 'L', 0x0C, 0x0C, 'l', 'L', 0x0C, 0x0C, 0x00, 0x01, -/* sc=27 */ 0xE6, 0xC6, NOP, NOP, 0x91, 0x92, NOP, NOP, 0x33, 0x01, -/* sc=28 */ 0xF8, 0xD8, NOP, NOP, 0x9B, 0x9D, NOP, NOP, 0x33, 0x01, -/* sc=29 */ 0xBD, 0xA7, NOP, NOP, 0xBD, 0xA7, NOP, NOP, 0x33, 0x00, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '\'', '*', NOP, NOP, '\'', '*', NOP, NOP, 0x33, 0x00, -/* sc=2c */ 'z', 'Z', 0x1A, 0x1A, 'z', 'Z', 0x1A, 0x1A, 0x00, 0x01, -/* sc=2d */ 'x', 'X', 0x18, 0x18, 'x', 'X', 0x18, 0x18, 0x00, 0x01, -/* sc=2e */ 'c', 'C', 0x03, 0x03, 'c', 'C', 0x03, 0x03, 0x00, 0x01, -/* sc=2f */ 'v', 'V', 0x16, 0x16, 'v', 'V', 0x16, 0x16, 0x00, 0x01, -/* sc=30 */ 'b', 'B', 0x02, 0x02, 'b', 'B', 0x02, 0x02, 0x00, 0x01, -/* sc=31 */ 'n', 'N', 0x0E, 0x0E, 'n', 'N', 0x0E, 0x0E, 0x00, 0x01, -/* sc=32 */ 'm', 'M', 0x0D, 0x0D, 'm', 'M', 0x0D, 0x0D, 0x00, 0x01, -/* sc=33 */ ',', ';', NOP, NOP, ',', ';', NOP, NOP, 0x33, 0x00, -/* sc=34 */ '.', ':', NOP, NOP, '.', ':', NOP, NOP, 0x33, 0x00, -/* sc=35 */ '-', '_', 0x1F, 0x1F, '-', '_', 0x1F, 0x1F, 0x00, 0x00, -/* sc=36 */ RSH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', '*', '*', '*', '*', '*', '*', 0x33, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x00, 0x00, -/* sc=3a */ CLK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, NLK, NLK, NLK, NLK, NLK, NLK, 0xFF, 0x00, -/* sc=46 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -/* sc=47 */ F(49), '7', '7', '7', '7', '7', '7', '7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', '8', '8', '8', '8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', '9', '9', '9', '9', 0x80, 0x02, -/* sc=4a */ F(52), '-', '-', '-', '-', '-', '-', '-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', '4', '4', '4', '4', 0x80, 0x02, -/* sc=4c */ NOP, '5', '5', '5', '5', '5', '5', '5', 0x80, 0x02, -/* sc=4d */ F(55), '6', '6', '6', '6', '6', '6', '6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', '+', '+', '+', '+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', '1', '1', '1', '1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', '2', '2', '2', '2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', '3', '3', '3', '3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', '0', '0', '0', '0', 0x80, 0x02, -/* sc=53 */ 0x7F, '.', '.', '.', '.', '.', '.', '.', 0x00, 0x02, -/* sc=54 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ '<', '>', 0x1C, 0x1C, '\\', '>', 0x1C, 0x1C, 0x00, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x00, 0x02, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', '/', '/', '/', '/', '/', '/', 0x00, 0x00, -/* sc=5c */ '*', '*', '*', '*', '*', '*', '*', '*', 0x00, 0x00, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), F(54), F(54), F(54), F(54), F(54), F(54), 0xFF, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -}; -#endif - -#ifdef UKKEYMAP -keymap_t key_map = { 0x69, /* uk iso8859 keymap */ -/* alt - * scan cntrl alt alt cntrl - * code base shift cntrl shift alt shift cntrl shift spcl flgs - * --------------------------------------------------------------------------- - */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, -/* sc=02 */ '1', '!', NOP, NOP, '`', '`', NOP, NOP, 0x33, 0x00, -/* sc=03 */ '2', '"', 0x00, 0x00, '@', '@', 0x00, 0x00, 0x00, 0x00, -/* sc=04 */ '3', 0xA3, NOP, NOP, '#', '#', NOP, NOP, 0x33, 0x00, -/* sc=05 */ '4', '$', NOP, NOP, '4', '$', NOP, NOP, 0x33, 0x00, -/* sc=06 */ '5', '%', NOP, NOP, '5', '%', NOP, NOP, 0x33, 0x00, -/* sc=07 */ '6', '^', 0x1E, 0x1E, '^', '^', 0x1E, 0x1E, 0x00, 0x00, -/* sc=08 */ '7', '&', NOP, NOP, '[', '[', 0x1B, 0x1B, 0x30, 0x00, -/* sc=09 */ '8', '*', NOP, NOP, '8', '*', NOP, NOP, 0x33, 0x00, -/* sc=0a */ '9', '(', NOP, NOP, ']', ']', 0x1D, 0x1D, 0x30, 0x00, -/* sc=0b */ '0', ')', NOP, NOP, '{', '{', NOP, NOP, 0x33, 0x00, -/* sc=0c */ '-', '_', 0x1F, 0x1F, '|', '|', 0x1F, 0x1F, 0x00, 0x00, -/* sc=0d */ '=', '+', NOP, NOP, '}', '}', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x08, 0x08, 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, 0x00, 0x00, -/* sc=0f */ 0x09, 0x08, NOP, NOP, 0x09, 0x08, NOP, NOP, 0x77, 0x00, -/* sc=10 */ 'q', 'Q', 0x11, 0x11, 'q', 'Q', 0x11, 0x11, 0x00, 0x01, -/* sc=11 */ 'w', 'W', 0x17, 0x17, 'w', 'W', 0x17, 0x17, 0x00, 0x01, -/* sc=12 */ 'e', 'E', 0x05, 0x05, 'e', 'E', 0x05, 0x05, 0x00, 0x01, -/* sc=13 */ 'r', 'R', 0x12, 0x12, 'r', 'R', 0x12, 0x12, 0x00, 0x01, -/* sc=14 */ 't', 'T', 0x14, 0x14, 't', 'T', 0x14, 0x14, 0x00, 0x01, -/* sc=15 */ 'y', 'Y', 0x19, 0x19, 'y', 'Y', 0x19, 0x19, 0x00, 0x01, -/* sc=16 */ 'u', 'U', 0x15, 0x15, 'u', 'U', 0x15, 0x15, 0x00, 0x01, -/* sc=17 */ 'i', 'I', 0x09, 0x09, 'i', 'I', 0x09, 0x09, 0x00, 0x01, -/* sc=18 */ 'o', 'O', 0x0F, 0x0F, 'o', 'O', 0x0F, 0x0F, 0x00, 0x01, -/* sc=19 */ 'p', 'P', 0x10, 0x10, 'p', 'P', 0x10, 0x10, 0x00, 0x01, -/* sc=1a */ '[', '{', 0x1B, 0x1B, '[', '{', 0x1B, 0x1B, 0x00, 0x00, -/* sc=1b */ ']', '}', 0x1D, 0x1D, ']', '}', 0x1D, 0x1D, 0x00, 0x00, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 'a', 'A', 0x01, 0x01, 'a', 'A', 0x01, 0x01, 0x00, 0x01, -/* sc=1f */ 's', 'S', 0x13, 0x13, 's', 'S', 0x13, 0x13, 0x00, 0x01, -/* sc=20 */ 'd', 'D', 0x04, 0x04, 'd', 'D', 0x04, 0x04, 0x00, 0x01, -/* sc=21 */ 'f', 'F', 0x06, 0x06, 'f', 'F', 0x06, 0x06, 0x00, 0x01, -/* sc=22 */ 'g', 'G', 0x07, 0x07, 'g', 'G', 0x07, 0x07, 0x00, 0x01, -/* sc=23 */ 'h', 'H', 0x08, 0x08, 'h', 'H', 0x08, 0x08, 0x00, 0x01, -/* sc=24 */ 'j', 'J', 0x0A, 0x0A, 'j', 'J', 0x0A, 0x0A, 0x00, 0x01, -/* sc=25 */ 'k', 'K', 0x0B, 0x0B, 'k', 'K', 0x0B, 0x0B, 0x00, 0x01, -/* sc=26 */ 'l', 'L', 0x0C, 0x0C, 'l', 'L', 0x0C, 0x0C, 0x00, 0x01, -/* sc=27 */ ';', ':', NOP, NOP, ';', ':', NOP, NOP, 0x33, 0x00, -/* sc=28 */ '\'', '@', 0x00, 0x00, '\'', '@', 0x00, 0x00, 0x00, 0x00, -/* sc=29 */ '\\', '|', 0x1C, 0x1C, '\\', '\\', 0x1C, 0x1C, 0x00, 0x00, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '#', '~', NOP, NOP, '~', '~', NOP, NOP, 0x33, 0x00, -/* sc=2c */ 'z', 'Z', 0x1A, 0x1A, 'z', 'Z', 0x1A, 0x1A, 0x00, 0x01, -/* sc=2d */ 'x', 'X', 0x18, 0x18, 'x', 'X', 0x18, 0x18, 0x00, 0x01, -/* sc=2e */ 'c', 'C', 0x03, 0x03, 'c', 'C', 0x03, 0x03, 0x00, 0x01, -/* sc=2f */ 'v', 'V', 0x16, 0x16, 'v', 'V', 0x16, 0x16, 0x00, 0x01, -/* sc=30 */ 'b', 'B', 0x02, 0x02, 'b', 'B', 0x02, 0x02, 0x00, 0x01, -/* sc=31 */ 'n', 'N', 0x0E, 0x0E, 'n', 'N', 0x0E, 0x0E, 0x00, 0x01, -/* sc=32 */ 'm', 'M', 0x0D, 0x0D, 'm', 'M', 0x0D, 0x0D, 0x00, 0x01, -/* sc=33 */ ',', '<', NOP, NOP, ',', '<', NOP, NOP, 0x33, 0x00, -/* sc=34 */ '.', '>', NOP, NOP, '.', '>', NOP, NOP, 0x33, 0x00, -/* sc=35 */ '/', '?', NOP, NOP, '/', '?', NOP, NOP, 0x33, 0x00, -/* sc=36 */ RSH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', 0x0A, 0x0A, '*', '*', 0x0A, 0x0A, 0x33, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x00, 0x00, -/* sc=3a */ CLK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, 0x13, 0x13, NLK, NLK, 0x13, 0x13, 0xCC, 0x00, -/* sc=46 */ SLK, SLK, 0x7F, 0x7F, SLK, SLK, 0x7F, 0x7F, 0xCC, 0x00, -/* sc=47 */ F(49), '7', '7', '7', '7', '7', '7', '7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', '8', '8', '8', '8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', '9', '9', '9', '9', 0x80, 0x02, -/* sc=4a */ F(52), '-', 0x1F, 0x1F, '-', '-', '-', '-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', '4', '4', '4', '4', 0x80, 0x02, -/* sc=4c */ F(54), '5', '5', '5', '5', '5', '5', '5', 0x80, 0x02, -/* sc=4d */ F(55), '6', 0x1E, 0x1E, '6', '6', '6', '6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', '+', '+', '+', '+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', '1', '1', '1', '1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', '2', '2', '2', '2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', '3', '3', '3', '3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', '0', '0', '0', '0', 0x80, 0x02, -/* sc=53 */ 0x7F, '.', 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x00, 0x02, -/* sc=54 */ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ '\\', '|', 0x1C, 0x1C, '\\', '|', 0x1C, 0x1C, 0x00, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0xFF, 0x02, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', '/', '/', '/', '/', '/', '/', 0x00, 0x02, -/* sc=5c */ '*', '*', '*', '*', '*', '*', '*', '*', 0x00, 0x02, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), F(54), F(54), F(54), F(54), F(54), F(54), 0xFF, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -}; -#endif - -#ifdef GRKEYMAP -keymap_t key_map = { 0x69, /* german iso8859 keymap */ -/* alt - * scan cntrl alt alt cntrl - * code base shift cntrl shift alt shift cntrl shift spcl flgs - * --------------------------------------------------------------------------- - */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, -/* sc=02 */ '1', '!', NOP, NOP, '`', '`', NOP, NOP, 0x33, 0x00, -/* sc=03 */ '2', '"', 0x00, 0x00, '@', '@', 0x00, 0x00, 0x00, 0x00, -/* sc=04 */ '3', 0xA7, NOP, NOP, '#', '#', NOP, NOP, 0x33, 0x00, -/* sc=05 */ '4', '$', NOP, NOP, '4', '$', NOP, NOP, 0x33, 0x00, -/* sc=06 */ '5', '%', NOP, NOP, '5', '%', NOP, NOP, 0x33, 0x00, -/* sc=07 */ '6', '&', 0x1E, 0x1E, '^', '^', 0x1E, 0x1E, 0x00, 0x00, -/* sc=08 */ '7', '/', 0x1B, 0x1B, '[', '[', 0x1B, 0x1B, 0x00, 0x00, -/* sc=09 */ '8', '(', NOP, NOP, '8', '(', NOP, NOP, 0x33, 0x00, -/* sc=0a */ '9', ')', 0x1D, 0x1D, ']', ']', 0x1D, 0x1D, 0x00, 0x00, -/* sc=0b */ '0', '=', NOP, NOP, '{', '{', NOP, NOP, 0x33, 0x00, -/* sc=0c */ 0xDF, '?', NOP, NOP, '|', '|', NOP, NOP, 0x33, 0x00, -/* sc=0d */ 0x92, 0x93, NOP, NOP, '\'', '`', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x08, 0x08, 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, 0x00, 0x00, -/* sc=0f */ 0x09, 0x08, NOP, NOP, 0x09, 0x08, NOP, NOP, 0x77, 0x00, -/* sc=10 */ 'q', 'Q', 0x11, 0x11, 'q', 'Q', 0x11, 0x11, 0x00, 0x01, -/* sc=11 */ 'w', 'W', 0x17, 0x17, 'w', 'W', 0x17, 0x17, 0x00, 0x01, -/* sc=12 */ 'e', 'E', 0x05, 0x05, 'e', 'E', 0x05, 0x05, 0x00, 0x01, -/* sc=13 */ 'r', 'R', 0x12, 0x12, 'r', 'R', 0x12, 0x12, 0x00, 0x01, -/* sc=14 */ 't', 'T', 0x14, 0x14, 't', 'T', 0x14, 0x14, 0x00, 0x01, -/* sc=15 */ 'z', 'Z', 0x1A, 0x1A, 'z', 'Z', 0x1A, 0x1A, 0x00, 0x01, -/* sc=16 */ 'u', 'U', 0x15, 0x15, 'u', 'U', 0x15, 0x15, 0x00, 0x01, -/* sc=17 */ 'i', 'I', 0x09, 0x09, 'i', 'I', 0x09, 0x09, 0x00, 0x01, -/* sc=18 */ 'o', 'O', 0x0F, 0x0F, 'o', 'O', 0x0F, 0x0F, 0x00, 0x01, -/* sc=19 */ 'p', 'P', 0x10, 0x10, 'p', 'P', 0x10, 0x10, 0x00, 0x01, -/* sc=1a */ 0xFC, 0xDC, 0x1B, 0x1B, '[', '{', 0x1B, 0x1B, 0x00, 0x01, -/* sc=1b */ '+', '*', 0x1D, 0x1D, ']', '}', 0x1D, 0x1D, 0x00, 0x00, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 'a', 'A', 0x01, 0x01, 'a', 'A', 0x01, 0x01, 0x00, 0x01, -/* sc=1f */ 's', 'S', 0x13, 0x13, 's', 'S', 0x13, 0x13, 0x00, 0x01, -/* sc=20 */ 'd', 'D', 0x04, 0x04, 'd', 'D', 0x04, 0x04, 0x00, 0x01, -/* sc=21 */ 'f', 'F', 0x06, 0x06, 'f', 'F', 0x06, 0x06, 0x00, 0x01, -/* sc=22 */ 'g', 'G', 0x07, 0x07, 'g', 'G', 0x07, 0x07, 0x00, 0x01, -/* sc=23 */ 'h', 'H', 0x08, 0x08, 'h', 'H', 0x08, 0x08, 0x00, 0x01, -/* sc=24 */ 'j', 'J', 0x0A, 0x0A, 'j', 'J', 0x0A, 0x0A, 0x00, 0x01, -/* sc=25 */ 'k', 'K', 0x0B, 0x0B, 'k', 'K', 0x0B, 0x0B, 0x00, 0x01, -/* sc=26 */ 'l', 'L', 0x0C, 0x0C, 'l', 'L', 0x0C, 0x0C, 0x00, 0x01, -/* sc=27 */ 0xF6, 0xD6, NOP, NOP, 0xF6, 0xD6, NOP, NOP, 0x33, 0x01, -/* sc=28 */ 0xE4, 0xC4, NOP, NOP, 0xE4, 0xC4, NOP, NOP, 0x33, 0x01, -/* sc=29 */ '<', '>', 0x1C, 0x1C, '\\', '|', 0x1C, 0x1C, 0x00, 0x00, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '#', '^', 0x1E, 0x1E, '`', '~', 0x1E, 0x1E, 0x00, 0x00, -/* sc=2c */ 'y', 'Y', 0x19, 0x19, 'y', 'Y', 0x19, 0x19, 0x00, 0x01, -/* sc=2d */ 'x', 'X', 0x18, 0x18, 'x', 'X', 0x18, 0x18, 0x00, 0x01, -/* sc=2e */ 'c', 'C', 0x03, 0x03, 'c', 'C', 0x03, 0x03, 0x00, 0x01, -/* sc=2f */ 'v', 'V', 0x16, 0x16, 'v', 'V', 0x16, 0x16, 0x00, 0x01, -/* sc=30 */ 'b', 'B', 0x02, 0x02, 'b', 'B', 0x02, 0x02, 0x00, 0x01, -/* sc=31 */ 'n', 'N', 0x0E, 0x0E, 'n', 'N', 0x0E, 0x0E, 0x00, 0x01, -/* sc=32 */ 'm', 'M', 0x0D, 0x0D, 'm', 'M', 0x0D, 0x0D, 0x00, 0x01, -/* sc=33 */ ',', ';', NOP, NOP, ',', ';', NOP, NOP, 0x33, 0x00, -/* sc=34 */ '.', ':', NOP, NOP, '.', ':', NOP, NOP, 0x33, 0x00, -/* sc=35 */ '-', '_', 0x1F, 0x1F, '-', '_', 0x1F, 0x1F, 0x00, 0x00, -/* sc=36 */ RSH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', 0x0A, 0x0A, '*', '*', 0x0A, 0x0A, 0x33, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x00, 0x00, -/* sc=3a */ CLK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, 0x13, 0x13, NLK, NLK, 0x13, 0x13, 0xCC, 0x00, -/* sc=46 */ SLK, SLK, 0x7F, 0x7F, SLK, SLK, 0x7F, 0x7F, 0xCC, 0x00, -/* sc=47 */ F(49), '7', '7', '7', '7', '7', '7', '7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', '8', '8', '8', '8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', '9', '9', '9', '9', 0x80, 0x02, -/* sc=4a */ F(52), '-', 0x1F, 0x1F, '-', '-', '-', '-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', '4', '4', '4', '4', 0x80, 0x02, -/* sc=4c */ F(54), '5', '5', '5', '5', '5', '5', '5', 0x80, 0x02, -/* sc=4d */ F(55), '6', 0x1E, 0x1E, '6', '6', '6', '6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', '+', '+', '+', '+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', '1', '1', '1', '1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', '2', '2', '2', '2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', '3', '3', '3', '3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', '0', '0', '0', '0', 0x80, 0x02, -/* sc=53 */ 0x7F, '.', 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x00, 0x02, -/* sc=54 */ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0xFF, 0x02, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', '/', '/', '/', '/', '/', '/', 0x00, 0x02, -/* sc=5c */ '*', '*', '*', '*', '*', '*', '*', '*', 0x00, 0x02, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), F(54), F(54), F(54), F(54), F(54), F(54), 0xFF, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -}; -#endif - -#ifdef SWKEYMAP -keymap_t key_map = { 0x69, /* swedish iso8859 keymap */ -/* alt - * scan cntrl alt alt cntrl - * code base shift cntrl shift alt shift cntrl shift spcl flgs - * --------------------------------------------------------------------------- - */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, -/* sc=02 */ '1', '!', NOP, NOP, NOP, NOP, NOP, NOP, 0x3F, 0x00, -/* sc=03 */ '2', '"', NOP, NOP, NOP, '@', NOP, NOP, 0x3B, 0x00, -/* sc=04 */ '3', 0xA3, NOP, NOP, NOP, '#', NOP, NOP, 0x3B, 0x00, -/* sc=05 */ '4', '$', NOP, NOP, NOP, NOP, NOP, NOP, 0x3F, 0x00, -/* sc=06 */ '5', '%', NOP, NOP, NOP, NOP, NOP, NOP, 0x3F, 0x00, -/* sc=07 */ '6', '&', 0x1E, NOP, NOP, '^', 0x1E, NOP, 0x19, 0x00, -/* sc=08 */ '7', '/', NOP, NOP, NOP, '&', NOP, NOP, 0x3B, 0x00, -/* sc=09 */ '8', '(', NOP, NOP, NOP, '*', NOP, NOP, 0x3B, 0x00, -/* sc=0a */ '9', ')', NOP, NOP, NOP, '(', NOP, NOP, 0x3B, 0x00, -/* sc=0b */ '0', '=', NOP, NOP, NOP, ')', NOP, NOP, 0x3B, 0x00, -/* sc=0c */ '+', '?', 0x1F, 0x1F, '-', '_', 0x1F, 0x1F, 0x00, 0x00, -/* sc=0d */ 0xB4, '`', NOP, NOP, '=', '+', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x08, 0x08, 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, 0x00, 0x00, -/* sc=0f */ 0x09, 0x08, NOP, NOP, 0x09, 0x08, NOP, NOP, 0x77, 0x00, -/* sc=10 */ 'q', 'Q', 0x11, 0x11, 'q', 'Q', 0x11, 0x11, 0x00, 0x01, -/* sc=11 */ 'w', 'W', 0x17, 0x17, 'w', 'W', 0x17, 0x17, 0x00, 0x01, -/* sc=12 */ 'e', 'E', 0x05, 0x05, 'e', 'E', 0x05, 0x05, 0x00, 0x01, -/* sc=13 */ 'r', 'R', 0x12, 0x12, 'r', 'R', 0x12, 0x12, 0x00, 0x01, -/* sc=14 */ 't', 'T', 0x14, 0x14, 't', 'T', 0x14, 0x14, 0x00, 0x01, -/* sc=15 */ 'y', 'Y', 0x19, 0x19, 'y', 'Y', 0x19, 0x19, 0x00, 0x01, -/* sc=16 */ 'u', 'U', 0x15, 0x15, 'u', 'U', 0x15, 0x15, 0x00, 0x01, -/* sc=17 */ 'i', 'I', 0x09, 0x09, 'i', 'I', 0x09, 0x09, 0x00, 0x01, -/* sc=18 */ 'o', 'O', 0x0F, 0x0F, 'o', 'O', 0x0F, 0x0F, 0x00, 0x01, -/* sc=19 */ 'p', 'P', 0x10, 0x10, 'p', 'P', 0x10, 0x10, 0x00, 0x01, -/* sc=1a */ 0xE5, 0xC5, NOP, NOP, '[', '{', 0x1B, NOP, 0x31, 0x01, -/* sc=1b */ 0xA8, '^', NOP, NOP, ']', '}', 0x1D, NOP, 0x31, 0x00, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 'a', 'A', 0x01, 0x01, 'a', 'A', 0x01, 0x01, 0x00, 0x01, -/* sc=1f */ 's', 'S', 0x13, 0x13, 's', 'S', 0x13, 0x13, 0x00, 0x01, -/* sc=20 */ 'd', 'D', 0x04, 0x04, 'd', 'D', 0x04, 0x04, 0x00, 0x01, -/* sc=21 */ 'f', 'F', 0x06, 0x06, 'f', 'F', 0x06, 0x06, 0x00, 0x01, -/* sc=22 */ 'g', 'G', 0x07, 0x07, 'g', 'G', 0x07, 0x07, 0x00, 0x01, -/* sc=23 */ 'h', 'H', 0x08, 0x08, 'h', 'H', 0x08, 0x08, 0x00, 0x01, -/* sc=24 */ 'j', 'J', 0x0A, 0x0A, 'j', 'J', 0x0A, 0x0A, 0x00, 0x01, -/* sc=25 */ 'k', 'K', 0x0B, 0x0B, 'k', 'K', 0x0B, 0x0B, 0x00, 0x01, -/* sc=26 */ 'l', 'L', 0x0C, 0x0C, 'l', 'L', 0x0C, 0x0C, 0x00, 0x01, -/* sc=27 */ 0xF8, 0xD8, NOP, NOP, ';', ':', NOP, NOP, 0x33, 0x01, -/* sc=28 */ 0xE6, 0xC6, NOP, NOP, '\'', '"', NOP, NOP, 0x33, 0x01, -/* sc=29 */ '<', '>', NOP, NOP, '\\', '|', 0x1C, NOP, 0x31, 0x00, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '\'', '*', NOP, NOP, '`', '~', NOP, NOP, 0x33, 0x00, -/* sc=2c */ 'z', 'Z', 0x1A, 0x1A, 'z', 'Z', 0x1A, 0x1A, 0x00, 0x01, -/* sc=2d */ 'x', 'X', 0x18, 0x18, 'x', 'X', 0x18, 0x18, 0x00, 0x01, -/* sc=2e */ 'c', 'C', 0x03, 0x03, 'c', 'C', 0x03, 0x03, 0x00, 0x01, -/* sc=2f */ 'v', 'V', 0x16, 0x16, 'v', 'V', 0x16, 0x16, 0x00, 0x01, -/* sc=30 */ 'b', 'B', 0x02, 0x02, 'b', 'B', 0x02, 0x02, 0x00, 0x01, -/* sc=31 */ 'n', 'N', 0x0E, 0x0E, 'n', 'N', 0x0E, 0x0E, 0x00, 0x01, -/* sc=32 */ 'm', 'M', 0x0D, 0x0D, 'm', 'M', 0x0D, 0x0D, 0x00, 0x01, -/* sc=33 */ ',', ';', NOP, NOP, NOP, '<', NOP, NOP, 0x3B, 0x00, -/* sc=34 */ '.', ':', NOP, NOP, NOP, '>', NOP, NOP, 0x3B, 0x00, -/* sc=35 */ '-', '_', 0x1F, NOP, '/', '?', NOP, NOP, 0x13, 0x00, -/* sc=36 */ RSH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', 0x0A, 0x0A, '*', '*', 0x0A, 0x0A, 0x33, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x00, 0x00, -/* sc=3a */ CLK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, 0x13, 0x13, NLK, NLK, 0x13, 0x13, 0xCC, 0x00, -/* sc=46 */ SLK, SLK, 0x7F, 0x7F, SLK, SLK, 0x7F, 0x7F, 0xCC, 0x00, -/* sc=47 */ F(49), '7', '7', '7', '7', '7', '7', '7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', '8', '8', '8', '8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', '9', '9', '9', '9', 0x80, 0x02, -/* sc=4a */ F(52), '-', 0x1F, 0x1F, '-', '-', '-', '-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', '4', '4', '4', '4', 0x80, 0x02, -/* sc=4c */ F(54), '5', '5', '5', '5', '5', '5', '5', 0x80, 0x02, -/* sc=4d */ F(55), '6', 0x1E, 0x1E, '6', '6', '6', '6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', '+', '+', '+', '+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', '1', '1', '1', '1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', '2', '2', '2', '2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', '3', '3', '3', '3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', '0', '0', '0', '0', 0x80, 0x02, -/* sc=53 */ 0x7F, '.', 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x00, 0x02, -/* sc=54 */ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0xFF, 0x02, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', '/', '/', '/', '/', '/', '/', 0x00, 0x02, -/* sc=5c */ '*', '*', '*', '*', '*', '*', '*', '*', 0x00, 0x02, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), F(54), F(54), F(54), F(54), F(54), F(54), 0xFF, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -}; -#endif - -#ifdef RUKEYMAP -keymap_t key_map = { 0xe9, /* keys number */ -/* alt - * scan cntrl alt alt cntrl - * code base shift cntrl shift alt shift cntrl shift spcl flgs - * ------------------------------------------------------------------------------------------- - */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, NOP, NOP, META|0x1B, META|0x1B, NOP, NOP, 0x33, 0x00, -/* sc=02 */ '1', '!', NOP, NOP, META|'1', META|'!', NOP, NOP, 0x33, 0x00, -/* sc=03 */ '2', '@', 0x00, 0x00, META|'2', META|'@', META|0x00, META|0x00, 0x00, 0x00, -/* sc=04 */ '3', '#', NOP, NOP, META|'3', META|'#', NOP, NOP, 0x33, 0x00, -/* sc=05 */ '4', '$', NOP, NOP, META|'4', META|'$', NOP, NOP, 0x33, 0x00, -/* sc=06 */ '5', '%', NOP, NOP, META|'5', META|'%', NOP, NOP, 0x33, 0x00, -/* sc=07 */ '6', '^', 0x1E, 0x1E, META|'6', META|'^', META|0x1E, META|0x1E, 0x00, 0x00, -/* sc=08 */ '7', '&', NOP, NOP, META|'7', META|'&', NOP, NOP, 0x33, 0x00, -/* sc=09 */ '8', '*', NOP, NOP, META|'8', META|'*', NOP, NOP, 0x33, 0x00, -/* sc=0a */ '9', '(', NOP, NOP, META|'9', META|'(', NOP, NOP, 0x33, 0x00, -/* sc=0b */ '0', ')', NOP, NOP, META|'0', META|')', NOP, NOP, 0x33, 0x00, -/* sc=0c */ '-', '_', 0x1F, 0x1F, META|'-', META|'_', META|0x1F, META|0x1F, 0x00, 0x00, -/* sc=0d */ '=', '+', NOP, NOP, META|'=', META|'+', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x08, 0x08, 0x7F, 0x7F, META|0x08, META|0x08, META|0x7F, META|0x7F, 0x00, 0x00, -/* sc=0f */ 0x09, F(16), NOP, NOP, META|0x09, F(16), NOP, NOP, 0x77, 0x00, -/* sc=10 */ 'q', 'Q', 0x11, 0x11, META|'q', META|'Q', META|0x11, META|0x11, 0x00, 0x01, -/* sc=11 */ 'w', 'W', 0x17, 0x17, META|'w', META|'W', META|0x17, META|0x17, 0x00, 0x01, -/* sc=12 */ 'e', 'E', 0x05, 0x05, META|'e', META|'E', META|0x05, META|0x05, 0x00, 0x01, -/* sc=13 */ 'r', 'R', 0x12, 0x12, META|'r', META|'R', META|0x12, META|0x12, 0x00, 0x01, -/* sc=14 */ 't', 'T', 0x14, 0x14, META|'t', META|'T', META|0x14, META|0x14, 0x00, 0x01, -/* sc=15 */ 'y', 'Y', 0x19, 0x19, META|'y', META|'Y', META|0x19, META|0x19, 0x00, 0x01, -/* sc=16 */ 'u', 'U', 0x15, 0x15, META|'u', META|'U', META|0x15, META|0x15, 0x00, 0x01, -/* sc=17 */ 'i', 'I', 0x09, 0x09, META|'i', META|'I', META|0x09, META|0x09, 0x00, 0x01, -/* sc=18 */ 'o', 'O', 0x0F, 0x0F, META|'o', META|'O', META|0x0F, META|0x0F, 0x00, 0x01, -/* sc=19 */ 'p', 'P', 0x10, 0x10, META|'p', META|'P', META|0x10, META|0x10, 0x00, 0x01, -/* sc=1a */ '[', '{', 0x1B, 0x1B, META|'[', META|'{', META|0x1B, META|0x1B, 0x00, 0x00, -/* sc=1b */ ']', '}', 0x1D, 0x1D, META|']', META|'}', META|0x1D, META|0x1D, 0x00, 0x00, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, META|0x0D, META|0x0D, META|0x0A, META|0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 'a', 'A', 0x01, 0x01, META|'a', META|'A', META|0x01, META|0x01, 0x00, 0x01, -/* sc=1f */ 's', 'S', 0x13, 0x13, META|'s', META|'S', META|0x13, META|0x13, 0x00, 0x01, -/* sc=20 */ 'd', 'D', 0x04, 0x04, META|'d', META|'D', META|0x04, META|0x04, 0x00, 0x01, -/* sc=21 */ 'f', 'F', 0x06, 0x06, META|'f', META|'F', META|0x06, META|0x06, 0x00, 0x01, -/* sc=22 */ 'g', 'G', 0x07, 0x07, META|'g', META|'G', META|0x07, META|0x07, 0x00, 0x01, -/* sc=23 */ 'h', 'H', 0x08, 0x08, META|'h', META|'H', META|0x08, META|0x08, 0x00, 0x01, -/* sc=24 */ 'j', 'J', 0x0A, 0x0A, META|'j', META|'J', META|0x0A, META|0x0A, 0x00, 0x01, -/* sc=25 */ 'k', 'K', 0x0B, 0x0B, META|'k', META|'K', META|0x0B, META|0x0B, 0x00, 0x01, -/* sc=26 */ 'l', 'L', 0x0C, 0x0C, META|'l', META|'L', META|0x0C, META|0x0C, 0x00, 0x01, -/* sc=27 */ ';', ':', NOP, NOP, META|';', META|':', NOP, NOP, 0x33, 0x00, -/* sc=28 */ '\'', '"', NOP, NOP, META|'\'', META|'"', NOP, NOP, 0x33, 0x00, -/* sc=29 */ '`', '~', NOP, NOP, META|'`', META|'~', NOP, NOP, 0x33, 0x00, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '\\', '|', 0x1C, 0x1C, META|'\\', META|'|', META|0x1C, META|0x1C, 0x00, 0x00, -/* sc=2c */ 'z', 'Z', 0x1A, 0x1A, META|'z', META|'Z', META|0x1A, META|0x1A, 0x00, 0x01, -/* sc=2d */ 'x', 'X', 0x18, 0x18, META|'x', META|'X', META|0x18, META|0x18, 0x00, 0x01, -/* sc=2e */ 'c', 'C', 0x03, 0x03, META|'c', META|'C', META|0x03, META|0x03, 0x00, 0x01, -/* sc=2f */ 'v', 'V', 0x16, 0x16, META|'v', META|'V', META|0x16, META|0x16, 0x00, 0x01, -/* sc=30 */ 'b', 'B', 0x02, 0x02, META|'b', META|'B', META|0x02, META|0x02, 0x00, 0x01, -/* sc=31 */ 'n', 'N', 0x0E, 0x0E, META|'n', META|'N', META|0x0E, META|0x0E, 0x00, 0x01, -/* sc=32 */ 'm', 'M', 0x0D, 0x0D, META|'m', META|'M', META|0x0D, META|0x0D, 0x00, 0x01, -/* sc=33 */ ',', '<', NOP, NOP, META|',', META|'<', NOP, NOP, 0x33, 0x00, -/* sc=34 */ '.', '>', NOP, NOP, META|'.', META|'>', NOP, NOP, 0x33, 0x00, -/* sc=35 */ '/', '?', NOP, NOP, META|'/', META|'?', NOP, NOP, 0x33, 0x00, -/* sc=36 */ ASH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', 0x0A, 0x0A, META|'*', META|'*', META|0x0A, META|0x0A, 0x00, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', META|' ', META|' ', META|' ', META|' ', 0x00, 0x00, -/* sc=3a */ ALK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, NLK, NLK, NLK, NLK, NLK, NLK, 0xFF, 0x00, -/* sc=46 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -/* sc=47 */ F(49), '7', '7', '7', META|'7', META|'7', META|'7', META|'7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', META|'8', META|'8', META|'8', META|'8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', META|'9', META|'9', META|'9', META|'9', 0x80, 0x02, -/* sc=4a */ F(52), '-', '-', '-', META|'-', META|'-', META|'-', META|'-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', META|'4', META|'4', META|'4', META|'4', 0x80, 0x02, -/* sc=4c */ F(48), '5', '5', '5', META|'5', META|'5', META|'5', META|'5', 0x80, 0x02, -/* sc=4d */ F(55), '6', '6', '6', META|'6', META|'6', META|'6', META|'6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', META|'+', META|'+', META|'+', META|'+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', META|'1', META|'1', META|'1', META|'1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', META|'2', META|'2', META|'2', META|'2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', META|'3', META|'3', META|'3', META|'3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', META|'0', META|'0', META|'0', META|'0', 0x80, 0x02, -/* sc=53 */ F(54), '.', 0x7F, 0x7F, META|0x7F, META|0x7F, META|0x7F, META|0x7F, 0x80, 0x02, -/* sc=54 */ ALK, ALK, ALK, ALK, ALK, ALK, ALK, ALK, 0xFF, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0A, 0x0A, META|0x0D, META|0x0D, META|0x0A, META|0x0A, 0x00, 0x00, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', NOP, NOP, META|'/', META|'/', NOP, NOP, 0x33, 0x00, -/* sc=5c */ CLK, ALK, ALK, ALK, ALK, ALK, ALK, ALK, 0xFF, 0x00, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), 0x7F, 0x7F, META|0x7F, META|0x7F, META|0x7F, META|0x7F, 0xC0, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -/* sc=69 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=6a */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=6b */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=6c */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=6d */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=6e */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=6f */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=70 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=71 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=72 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=73 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=74 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=75 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=76 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=77 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=78 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=79 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=7a */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=7b */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=7c */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=7d */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=7e */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=7f */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* extended (ALTGR LOCK keys) */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, NOP, NOP, META|0x1B, META|0x1B, NOP, NOP, 0x33, 0x00, -/* sc=02 */ '!', '1', NOP, NOP, META|'1', META|'!', NOP, NOP, 0x33, 0x00, -/* sc=03 */ '"', '2', 0x00, 0x00, META|'2', META|'@', META|0x00, META|0x00, 0x00, 0x00, -/* sc=04 */ '\'', '3', NOP, NOP, META|'3', META|'#', NOP, NOP, 0x33, 0x00, -/* sc=05 */ ';', '4', NOP, NOP, META|'4', META|'$', NOP, NOP, 0x33, 0x00, -/* sc=06 */ ':', '5', NOP, NOP, META|'5', META|'%', NOP, NOP, 0x33, 0x00, -/* sc=07 */ ',', '6', 0x1E, 0x1E, META|'6', META|'^', META|0x1E, META|0x1E, 0x00, 0x00, -/* sc=08 */ '.', '7', NOP, NOP, META|'7', META|'&', NOP, NOP, 0x33, 0x00, -/* sc=09 */ '*', '8', NOP, NOP, META|'8', META|'*', NOP, NOP, 0x33, 0x00, -/* sc=0a */ '(', '9', NOP, NOP, META|'9', META|'(', NOP, NOP, 0x33, 0x00, -/* sc=0b */ ')', '0', NOP, NOP, META|'0', META|')', NOP, NOP, 0x33, 0x00, -/* sc=0c */ '_', '-', 0x1F, 0x1F, META|'-', META|'_', META|0x1F, META|0x1F, 0x00, 0x00, -/* sc=0d */ '+', '=', NOP, NOP, META|'=', META|'+', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x08, 0x08, 0x7F, 0x7F, META|0x08, META|0x08, META|0x7F, META|0x7F, 0x00, 0x00, -/* sc=0f */ 0x09, F(16), NOP, NOP, META|0x09, F(16), NOP, NOP, 0x77, 0x00, -/* sc=10 */ 0xca, 0xea, 0x11, 0x11, META|'q', META|'Q', META|0x11, META|0x11, 0x00, 0x01, -/* sc=11 */ 0xc3, 0xe3, 0x17, 0x17, META|'w', META|'W', META|0x17, META|0x17, 0x00, 0x01, -/* sc=12 */ 0xd5, 0xf5, 0x05, 0x05, META|'e', META|'E', META|0x05, META|0x05, 0x00, 0x01, -/* sc=13 */ 0xcb, 0xeb, 0x12, 0x12, META|'r', META|'R', META|0x12, META|0x12, 0x00, 0x01, -/* sc=14 */ 0xc5, 0xe5, 0x14, 0x14, META|'t', META|'T', META|0x14, META|0x14, 0x00, 0x01, -/* sc=15 */ 0xce, 0xee, 0x19, 0x19, META|'y', META|'Y', META|0x19, META|0x19, 0x00, 0x01, -/* sc=16 */ 0xc7, 0xe7, 0x15, 0x15, META|'u', META|'U', META|0x15, META|0x15, 0x00, 0x01, -/* sc=17 */ 0xdb, 0xfb, 0x09, 0x09, META|'i', META|'I', META|0x09, META|0x09, 0x00, 0x01, -/* sc=18 */ 0xdd, 0xfd, 0x0F, 0x0F, META|'o', META|'O', META|0x0F, META|0x0F, 0x00, 0x01, -/* sc=19 */ 0xda, 0xfa, 0x10, 0x10, META|'p', META|'P', META|0x10, META|0x10, 0x00, 0x01, -/* sc=1a */ 0xc8, 0xe8, 0x1B, 0x1B, META|'[', META|'{', META|0x1B, META|0x1B, 0x00, 0x01, -/* sc=1b */ 0xdf, 0xff, 0x1D, 0x1D, META|']', META|'}', META|0x1D, META|0x1D, 0x00, 0x01, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, META|0x0D, META|0x0D, META|0x0A, META|0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 0xc6, 0xe6, 0x01, 0x01, META|'a', META|'A', META|0x01, META|0x01, 0x00, 0x01, -/* sc=1f */ 0xd9, 0xf9, 0x13, 0x13, META|'s', META|'S', META|0x13, META|0x13, 0x00, 0x01, -/* sc=20 */ 0xd7, 0xf7, 0x04, 0x04, META|'d', META|'D', META|0x04, META|0x04, 0x00, 0x01, -/* sc=21 */ 0xc1, 0xe1, 0x06, 0x06, META|'f', META|'F', META|0x06, META|0x06, 0x00, 0x01, -/* sc=22 */ 0xd0, 0xf0, 0x07, 0x07, META|'g', META|'G', META|0x07, META|0x07, 0x00, 0x01, -/* sc=23 */ 0xd2, 0xf2, 0x08, 0x08, META|'h', META|'H', META|0x08, META|0x08, 0x00, 0x01, -/* sc=24 */ 0xcf, 0xef, 0x0A, 0x0A, META|'j', META|'J', META|0x0A, META|0x0A, 0x00, 0x01, -/* sc=25 */ 0xcc, 0xec, 0x0B, 0x0B, META|'k', META|'K', META|0x0B, META|0x0B, 0x00, 0x01, -/* sc=26 */ 0xc4, 0xe4, 0x0C, 0x0C, META|'l', META|'L', META|0x0C, META|0x0C, 0x00, 0x01, -/* sc=27 */ 0xd6, 0xf6, NOP, NOP, META|';', META|':', NOP, NOP, 0x33, 0x01, -/* sc=28 */ 0xdc, 0xfc, NOP, NOP, META|'\'', META|'"', NOP, NOP, 0x33, 0x01, -/* sc=29 */ 0xa3, 0xb3, NOP, NOP, META|'`', META|'~', NOP, NOP, 0x33, 0x01, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '\\', '|', 0x1C, 0x1C, META|'\\', META|'|', META|0x1C, META|0x1C, 0x00, 0x00, -/* sc=2c */ 0xd1, 0xf1, 0x1A, 0x1A, META|'z', META|'Z', META|0x1A, META|0x1A, 0x00, 0x01, -/* sc=2d */ 0xde, 0xfe, 0x18, 0x18, META|'x', META|'X', META|0x18, META|0x18, 0x00, 0x01, -/* sc=2e */ 0xd3, 0xf3, 0x03, 0x03, META|'c', META|'C', META|0x03, META|0x03, 0x00, 0x01, -/* sc=2f */ 0xcd, 0xed, 0x16, 0x16, META|'v', META|'V', META|0x16, META|0x16, 0x00, 0x01, -/* sc=30 */ 0xc9, 0xe9, 0x02, 0x02, META|'b', META|'B', META|0x02, META|0x02, 0x00, 0x01, -/* sc=31 */ 0xd4, 0xf4, 0x0E, 0x0E, META|'n', META|'N', META|0x0E, META|0x0E, 0x00, 0x01, -/* sc=32 */ 0xd8, 0xf8, 0x0D, 0x0D, META|'m', META|'M', META|0x0D, META|0x0D, 0x00, 0x01, -/* sc=33 */ 0xc2, 0xe2, NOP, NOP, META|',', META|'<', NOP, NOP, 0x33, 0x01, -/* sc=34 */ 0xc0, 0xe0, NOP, NOP, META|'.', META|'>', NOP, NOP, 0x33, 0x01, -/* sc=35 */ '/', '?', NOP, NOP, META|'/', META|'?', NOP, NOP, 0x33, 0x00, -/* sc=36 */ ASH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', 0x0A, 0x0A, META|'*', META|'*', META|0x0A, META|0x0A, 0x00, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', META|' ', META|' ', META|' ', META|' ', 0x00, 0x00, -/* sc=3a */ ALK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, NLK, NLK, NLK, NLK, NLK, NLK, 0xFF, 0x00, -/* sc=46 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -/* sc=47 */ F(49), '7', '7', '7', META|'7', META|'7', META|'7', META|'7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', META|'8', META|'8', META|'8', META|'8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', META|'9', META|'9', META|'9', META|'9', 0x80, 0x02, -/* sc=4a */ F(52), '-', '-', '-', META|'-', META|'-', META|'-', META|'-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', META|'4', META|'4', META|'4', META|'4', 0x80, 0x02, -/* sc=4c */ F(48), '5', '5', '5', META|'5', META|'5', META|'5', META|'5', 0x80, 0x02, -/* sc=4d */ F(55), '6', '6', '6', META|'6', META|'6', META|'6', META|'6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', META|'+', META|'+', META|'+', META|'+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', META|'1', META|'1', META|'1', META|'1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', META|'2', META|'2', META|'2', META|'2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', META|'3', META|'3', META|'3', META|'3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', META|'0', META|'0', META|'0', META|'0', 0x80, 0x02, -/* sc=53 */ F(54), '.', 0x7F, 0x7F, META|0x7F, META|0x7F, META|0x7F, META|0x7F, 0x80, 0x02, -/* sc=54 */ ALK, ALK, ALK, ALK, ALK, ALK, ALK, ALK, 0xFF, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0A, 0x0A, META|0x0D, META|0x0D, META|0x0A, META|0x0A, 0x00, 0x00, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', NOP, NOP, META|'/', META|'/', NOP, NOP, 0x33, 0x00, -/* sc=5c */ CLK, ALK, ALK, ALK, ALK, ALK, ALK, ALK, 0xFF, 0x00, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), 0x7F, 0x7F, META|0x7F, META|0x7F, META|0x7F, META|0x7F, 0xC0, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -}; - -#endif - -#if !defined(DKKEYMAP) && !defined(UKKEYMAP) && !defined(GRKEYMAP) && !defined(SWKEYMAP) && !defined(RUKEYMAP) -keymap_t key_map = { 0x69, /* US iso8859 keymap */ -/* alt - * scan cntrl alt alt cntrl - * code base shift cntrl shift alt shift cntrl shift spcl flgs - * --------------------------------------------------------------------------- - */ -/* sc=00 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=01 */ 0x1B, 0x1B, NOP, NOP, 0x1B, 0x1B, NOP, NOP, 0x33, 0x00, -/* sc=02 */ '1', '!', NOP, NOP, '1', '!', NOP, NOP, 0x33, 0x00, -/* sc=03 */ '2', '@', 0x00, 0x00, '2', '@', 0x00, 0x00, 0x00, 0x00, -/* sc=04 */ '3', '#', NOP, NOP, '3', '#', NOP, NOP, 0x33, 0x00, -/* sc=05 */ '4', '$', NOP, NOP, '4', '$', NOP, NOP, 0x33, 0x00, -/* sc=06 */ '5', '%', NOP, NOP, '5', '%', NOP, NOP, 0x33, 0x00, -/* sc=07 */ '6', '^', 0x1E, 0x1E, '6', '^', 0x1E, 0x1E, 0x00, 0x00, -/* sc=08 */ '7', '&', NOP, NOP, '7', '&', NOP, NOP, 0x33, 0x00, -/* sc=09 */ '8', '*', NOP, NOP, '8', '*', NOP, NOP, 0x33, 0x00, -/* sc=0a */ '9', '(', NOP, NOP, '9', '(', NOP, NOP, 0x33, 0x00, -/* sc=0b */ '0', ')', NOP, NOP, '0', ')', NOP, NOP, 0x33, 0x00, -/* sc=0c */ '-', '_', 0x1F, 0x1F, '-', '_', 0x1F, 0x1F, 0x00, 0x00, -/* sc=0d */ '=', '+', NOP, NOP, '=', '+', NOP, NOP, 0x33, 0x00, -/* sc=0e */ 0x08, 0x08, 0x7F, 0x7F, 0x08, 0x08, 0x7F, 0x7F, 0x00, 0x00, -/* sc=0f */ 0x09, 0x08, NOP, NOP, 0x09, 0x08, NOP, NOP, 0x33, 0x00, -/* sc=10 */ 'q', 'Q', 0x11, 0x11, 'q', 'Q', 0x11, 0x11, 0x00, 0x01, -/* sc=11 */ 'w', 'W', 0x17, 0x17, 'w', 'W', 0x17, 0x17, 0x00, 0x01, -/* sc=12 */ 'e', 'E', 0x05, 0x05, 'e', 'E', 0x05, 0x05, 0x00, 0x01, -/* sc=13 */ 'r', 'R', 0x12, 0x12, 'r', 'R', 0x12, 0x12, 0x00, 0x01, -/* sc=14 */ 't', 'T', 0x14, 0x14, 't', 'T', 0x14, 0x14, 0x00, 0x01, -/* sc=15 */ 'y', 'Y', 0x19, 0x19, 'y', 'Y', 0x19, 0x19, 0x00, 0x01, -/* sc=16 */ 'u', 'U', 0x15, 0x15, 'u', 'U', 0x15, 0x15, 0x00, 0x01, -/* sc=17 */ 'i', 'I', 0x09, 0x09, 'i', 'I', 0x09, 0x09, 0x00, 0x01, -/* sc=18 */ 'o', 'O', 0x0F, 0x0F, 'o', 'O', 0x0F, 0x0F, 0x00, 0x01, -/* sc=19 */ 'p', 'P', 0x10, 0x10, 'p', 'P', 0x10, 0x10, 0x00, 0x01, -/* sc=1a */ '[', '{', 0x1B, 0x1B, '[', '{', 0x1B, 0x1B, 0x00, 0x00, -/* sc=1b */ ']', '}', 0x1D, 0x1D, ']', '}', 0x1D, 0x1D, 0x00, 0x00, -/* sc=1c */ 0x0D, 0x0D, 0x0A, 0x0A, 0x0D, 0x0D, 0x0A, 0x0A, 0x00, 0x00, -/* sc=1d */ LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, LCTR, 0xFF, 0x00, -/* sc=1e */ 'a', 'A', 0x01, 0x01, 'a', 'A', 0x01, 0x01, 0x00, 0x01, -/* sc=1f */ 's', 'S', 0x13, 0x13, 's', 'S', 0x13, 0x13, 0x00, 0x01, -/* sc=20 */ 'd', 'D', 0x04, 0x04, 'd', 'D', 0x04, 0x04, 0x00, 0x01, -/* sc=21 */ 'f', 'F', 0x06, 0x06, 'f', 'F', 0x06, 0x06, 0x00, 0x01, -/* sc=22 */ 'g', 'G', 0x07, 0x07, 'g', 'G', 0x07, 0x07, 0x00, 0x01, -/* sc=23 */ 'h', 'H', 0x08, 0x08, 'h', 'H', 0x08, 0x08, 0x00, 0x01, -/* sc=24 */ 'j', 'J', 0x0A, 0x0A, 'j', 'J', 0x0A, 0x0A, 0x00, 0x01, -/* sc=25 */ 'k', 'K', 0x0B, 0x0B, 'k', 'K', 0x0B, 0x0B, 0x00, 0x01, -/* sc=26 */ 'l', 'L', 0x0C, 0x0C, 'l', 'L', 0x0C, 0x0C, 0x00, 0x01, -/* sc=27 */ ';', ':', NOP, NOP, ';', ':', NOP, NOP, 0x33, 0x00, -/* sc=28 */ '\'', '"', NOP, NOP, '\'', '"', NOP, NOP, 0x33, 0x00, -/* sc=29 */ '`', '~', NOP, NOP, '`', '~', NOP, NOP, 0x33, 0x00, -/* sc=2a */ LSH, LSH, LSH, LSH, LSH, LSH, LSH, LSH, 0xFF, 0x00, -/* sc=2b */ '\\', '|', 0x1C, 0x1C, '\\', '|', 0x1C, 0x1C, 0x00, 0x00, -/* sc=2c */ 'z', 'Z', 0x1A, 0x1A, 'z', 'Z', 0x1A, 0x1A, 0x00, 0x01, -/* sc=2d */ 'x', 'X', 0x18, 0x18, 'x', 'X', 0x18, 0x18, 0x00, 0x01, -/* sc=2e */ 'c', 'C', 0x03, 0x03, 'c', 'C', 0x03, 0x03, 0x00, 0x01, -/* sc=2f */ 'v', 'V', 0x16, 0x16, 'v', 'V', 0x16, 0x16, 0x00, 0x01, -/* sc=30 */ 'b', 'B', 0x02, 0x02, 'b', 'B', 0x02, 0x02, 0x00, 0x01, -/* sc=31 */ 'n', 'N', 0x0E, 0x0E, 'n', 'N', 0x0E, 0x0E, 0x00, 0x01, -/* sc=32 */ 'm', 'M', 0x0D, 0x0D, 'm', 'M', 0x0D, 0x0D, 0x00, 0x01, -/* sc=33 */ ',', '<', NOP, NOP, ',', '<', NOP, NOP, 0x33, 0x00, -/* sc=34 */ '.', '>', NOP, NOP, '.', '>', NOP, NOP, 0x33, 0x00, -/* sc=35 */ '/', '?', NOP, NOP, '/', '?', NOP, NOP, 0x33, 0x00, -/* sc=36 */ RSH, RSH, RSH, RSH, RSH, RSH, RSH, RSH, 0xFF, 0x00, -/* sc=37 */ '*', '*', 0x0A, 0x0A, '*', '*', 0x0A, 0x0A, 0x33, 0x00, -/* sc=38 */ LALT, LALT, LALT, LALT, LALT, LALT, LALT, LALT, 0xFF, 0x00, -/* sc=39 */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x00, 0x00, -/* sc=3a */ CLK, CLK, CLK, CLK, CLK, CLK, CLK, CLK, 0xFF, 0x00, -/* sc=3b */ F( 1), F(13), F(25), F(37), S( 1), S(11), S( 1), S(11), 0xFF, 0x00, -/* sc=3c */ F( 2), F(14), F(26), F(38), S( 2), S(12), S( 2), S(12), 0xFF, 0x00, -/* sc=3d */ F( 3), F(15), F(27), F(39), S( 3), S(13), S( 3), S(13), 0xFF, 0x00, -/* sc=3e */ F( 4), F(16), F(28), F(40), S( 4), S(14), S( 4), S(14), 0xFF, 0x00, -/* sc=3f */ F( 5), F(17), F(29), F(41), S( 5), S(15), S( 5), S(15), 0xFF, 0x00, -/* sc=40 */ F( 6), F(18), F(30), F(42), S( 6), S(16), S( 6), S(16), 0xFF, 0x00, -/* sc=41 */ F( 7), F(19), F(31), F(43), S( 7), S( 7), S( 7), S( 7), 0xFF, 0x00, -/* sc=42 */ F( 8), F(20), F(32), F(44), S( 8), S( 8), S( 8), S( 8), 0xFF, 0x00, -/* sc=43 */ F( 9), F(21), F(33), F(45), S( 9), S( 9), S( 9), S( 9), 0xFF, 0x00, -/* sc=44 */ F(10), F(22), F(34), F(46), S(10), S(10), S(10), S(10), 0xFF, 0x00, -/* sc=45 */ NLK, NLK, NLK, NLK, NLK, NLK, NLK, NLK, 0xFF, 0x00, -/* sc=46 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -/* sc=47 */ F(49), '7', '7', '7', '7', '7', '7', '7', 0x80, 0x02, -/* sc=48 */ F(50), '8', '8', '8', '8', '8', '8', '8', 0x80, 0x02, -/* sc=49 */ F(51), '9', '9', '9', '9', '9', '9', '9', 0x80, 0x02, -/* sc=4a */ F(52), '-', '-', '-', '-', '-', '-', '-', 0x80, 0x02, -/* sc=4b */ F(53), '4', '4', '4', '4', '4', '4', '4', 0x80, 0x02, -/* sc=4c */ NOP, '5', '5', '5', '5', '5', '5', '5', 0x80, 0x02, -/* sc=4d */ F(55), '6', '6', '6', '6', '6', '6', '6', 0x80, 0x02, -/* sc=4e */ F(56), '+', '+', '+', '+', '+', '+', '+', 0x80, 0x02, -/* sc=4f */ F(57), '1', '1', '1', '1', '1', '1', '1', 0x80, 0x02, -/* sc=50 */ F(58), '2', '2', '2', '2', '2', '2', '2', 0x80, 0x02, -/* sc=51 */ F(59), '3', '3', '3', '3', '3', '3', '3', 0x80, 0x02, -/* sc=52 */ F(60), '0', '0', '0', '0', '0', '0', '0', 0x80, 0x02, -/* sc=53 */ 0x7F, '.', 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x00, 0x02, -/* sc=54 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=55 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=56 */ NOP, NOP, NOP, NOP, NOP, NOP, NOP, NOP, 0xFF, 0x00, -/* sc=57 */ F(11), F(23), F(35), F(47), S(11), S(11), S(11), S(11), 0xFF, 0x00, -/* sc=58 */ F(12), F(24), F(36), F(48), S(12), S(12), S(12), S(12), 0xFF, 0x00, -/* sc=59 */ 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x00, 0x00, -/* sc=5a */ RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, RCTR, 0xFF, 0x00, -/* sc=5b */ '/', '/', '/', '/', '/', '/', '/', '/', 0x00, 0x00, -/* sc=5c */ '*', '*', '*', '*', '*', '*', '*', '*', 0x00, 0x00, -/* sc=5d */ RALT, RALT, RALT, RALT, RALT, RALT, RALT, RALT, 0xFF, 0x00, -/* sc=5e */ F(49), F(49), F(49), F(49), F(49), F(49), F(49), F(49), 0xFF, 0x00, -/* sc=5f */ F(50), F(50), F(50), F(50), F(50), F(50), F(50), F(50), 0xFF, 0x00, -/* sc=60 */ F(51), F(51), F(51), F(51), F(51), F(51), F(51), F(51), 0xFF, 0x00, -/* sc=61 */ F(53), F(53), F(53), F(53), F(53), F(53), F(53), F(53), 0xFF, 0x00, -/* sc=62 */ F(55), F(55), F(55), F(55), F(55), F(55), F(55), F(55), 0xFF, 0x00, -/* sc=63 */ F(57), F(57), F(57), F(57), F(57), F(57), F(57), F(57), 0xFF, 0x00, -/* sc=64 */ F(58), F(58), F(58), F(58), F(58), F(58), F(58), F(58), 0xFF, 0x00, -/* sc=65 */ F(59), F(59), F(59), F(59), F(59), F(59), F(59), F(59), 0xFF, 0x00, -/* sc=66 */ F(60), F(60), F(60), F(60), F(60), F(60), F(60), F(60), 0xFF, 0x00, -/* sc=67 */ F(54), F(54), F(54), F(54), F(54), F(54), F(54), F(54), 0xFF, 0x00, -/* sc=68 */ SLK, SLK, SLK, SLK, SLK, SLK, SLK, SLK, 0xFF, 0x00, -}; - -#endif - -fkeytab_t fkey_tab[60] = { -/* 00-03 */ {"\033[M", 3}, {"\033[N", 3}, {"\033[O", 3}, {"\033[P", 3}, -/* 04-07 */ {"\033[Q", 3}, {"\033[R", 3}, {"\033[S", 3}, {"\033[T", 3}, -/* 08-0B */ {"\033[U", 3}, {"\033[V", 3}, {"\033[W", 3}, {"\033[X", 3}, -/* 0C-0F */ {"\033[W", 3}, {"\033[X", 3}, {"\033[Y", 3}, {"\033[Z", 3}, -/* 10-13 */ {"\033[a", 3}, {"\033[b", 3}, {"\033[c", 3}, {"\033[d", 3}, -/* 14-17 */ {"\033[e", 3}, {"\033[f", 3}, {"\033[g", 3}, {"\033[h", 3}, -/* 18-1B */ {"\033[g", 3}, {"\033[h", 3}, {"\033[i", 3}, {"\033[j", 3}, -/* 1C-1F */ {"\033[k", 3}, {"\033[l", 3}, {"\033[m", 3}, {"\033[n", 3}, -/* 20-23 */ {"\033[o", 3}, {"\033[p", 3}, {"\033[q", 3}, {"\033[r", 3}, -/* 24-27 */ {"\033[g", 3}, {"\033[h", 3}, {"\033[i", 3}, {"\033[j", 3}, -/* 28-2B */ {"\033[k", 3}, {"\033[l", 3}, {"\033[m", 3}, {"\033[n", 3}, -/* 2C-2F */ {"\033[o", 3}, {"\033[p", 3}, {"\033[q", 3}, {"\033[r", 3}, -/* 30-33 */ {"\033[H", 3}, {"\033[A", 3}, {"\033[I", 3}, {"-" , 1}, -/* 34-37 */ {"\033[D", 3}, {"\177" , 1}, {"\033[C", 3}, {"+" , 1}, -/* 38-3B */ {"\033[F", 3}, {"\033[B", 3}, {"\033[G", 3}, {"\033[L", 3} -}; diff --git a/sys/i386/isa/lpt.c b/sys/i386/isa/lpt.c deleted file mode 100644 index 6d65d8a..0000000 --- a/sys/i386/isa/lpt.c +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright (c) 1990 William F. Jolitz, TeleMuse - * All rights reserved. - * - * 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 software is a component of "386BSD" developed by - * William F. Jolitz, TeleMuse. - * 4. Neither the name of the developer nor the name "386BSD" - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ - * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS - * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT. - * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT - * NOT MAKE USE OF THIS WORK. - * - * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED - * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN - * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES - * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING - * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND - * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE - * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS - * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: unknown origin, 386BSD 0.1 - * $Id$ - */ - -/* - * Device Driver for AT parallel printer port - * Written by William Jolitz 12/18/90 - */ - -#include "lpt.h" -#if NLPT > 0 - -#include "param.h" -#include "systm.h" -#include "proc.h" -#include "user.h" -#include "buf.h" -#include "kernel.h" -#include "ioctl.h" -#include "tty.h" -#include "uio.h" - -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/lptreg.h" - -#define LPINITRDY 4 /* wait up to 4 seconds for a ready */ -#define LPTOUTTIME 4 /* wait up to 4 seconds for a ready */ -#define LPPRI (PZERO+8) -#define BUFSIZE 1024 - -#ifndef DEBUG -#define lprintf -#else -#define lprintf if (lptflag) printf -int lptflag = 1; -#endif - -void lptout(); -#ifdef DEBUG -int lptflag = 1; -#endif - -int lptprobe(), lptattach(); -void lptintr(); - -struct isa_driver lptdriver = { - lptprobe, lptattach, "lpt" -}; - -#define LPTUNIT(s) (((s)>>6)&0x3) -#define LPTFLAGS(s) ((s)&0x3f) - -struct lpt_softc { - short sc_port; - short sc_state; - /* default case: negative prime, negative ack, handshake strobe, - prime once */ - u_char sc_control; - char sc_flags; -#define LP_POS_INIT 0x01 /* if we are a postive init signal */ -#define LP_POS_ACK 0x02 /* if we are a positive going ack */ -#define LP_NO_PRIME 0x04 /* don't prime the printer at all */ -#define LP_PRIMEOPEN 0x08 /* prime on every open */ -#define LP_AUTOLF 0x10 /* tell printer to do an automatic lf */ -#define LP_BYPASS 0x20 /* bypass printer ready checks */ - struct buf *sc_inbuf; - short sc_xfercnt ; - char sc_primed; - char *sc_cp ; -} lpt_sc[NLPT] ; - -/* bits for state */ -#define OPEN (1<<0) /* device is open */ -#define ASLP (1<<1) /* awaiting draining of printer */ -#define ERROR (1<<2) /* error was received from printer */ -#define OBUSY (1<<3) /* printer is busy doing output */ -#define LPTOUT (1<<4) /* timeout while not selected */ -#define TOUT (1<<5) /* timeout while not selected */ -#define INIT (1<<6) /* waiting to initialize for open */ - -/* - * Internal routine to lptprobe to do port tests of one byte value - */ -int -lpt_port_test(port, data, mask) - short port; - u_char data; - u_char mask; - { - int temp, timeout; - - data = data & mask; - outb(port, data); - timeout = 100; - do - temp = inb(port) & mask; - while (temp != data && --timeout); - lprintf("Port 0x%x\tout=%x\tin=%x\n", port, data, temp); - return (temp == data); - } - -/* - * New lptprobe routine written by Rodney W. Grimes, 3/25/1993 - * - * Logic: - * 1) You should be able to write to and read back the same value - * to the data port. Do an alternating zeros, alternating ones, - * walking zero, and walking one test to check for stuck bits. - * - * 2) You should be able to write to and read back the same value - * to the control port lower 5 bits, the upper 3 bits are reserved - * per the IBM PC technical reference manauls and different boards - * do different things with them. Do an alternating zeros, alternating - * ones, walking zero, and walking one test to check for stuck bits. - * - * Some printers drag the strobe line down when the are powered off - * so this bit has been masked out of the control port test. - * - * XXX Some printers may not like a fast pulse on init or strobe, I - * don't know at this point, if that becomes a problem these bits - * should be turned off in the mask byte for the control port test. - * - * 3) Set the data and control ports to a value of 0 - */ - -int -lptprobe(dvp) - struct isa_device *dvp; -{ - int status; - short port; - u_char data; - u_char mask; - int i; - - status = IO_LPTSIZE; - - port = dvp->id_iobase + lpt_data; - mask = 0xff; - while (mask != 0) - { - data = 0x55; /* Alternating zeros */ - if (!lpt_port_test(port, data, mask)) status = 0; - - data = 0xaa; /* Alternating ones */ - if (!lpt_port_test(port, data, mask)) status = 0; - - for (i = 0; i < 8; i++) /* Walking zero */ - { - data = ~(1 << i); - if (!lpt_port_test(port, data, mask)) status = 0; - } - - for (i = 0; i < 8; i++) /* Walking one */ - { - data = (1 << i); - if (!lpt_port_test(port, data, mask)) status = 0; - } - - if (port == dvp->id_iobase + lpt_data) - { - port = dvp->id_iobase + lpt_control; - mask = 0x1e; - } - else - mask = 0; - } - outb(dvp->id_iobase+lpt_data, 0); - outb(dvp->id_iobase+lpt_control, 0); - return (status); - } - -int -lptattach(isdp) - struct isa_device *isdp; -{ - struct lpt_softc *sc; - - sc = lpt_sc + isdp->id_unit; - sc->sc_port = isdp->id_iobase; - outb(sc->sc_port+lpt_control, LPC_NINIT); - return (1); -} - -/* - * lptopen -- reset the printer, then wait until it's selected and not busy. - */ - -int -lptopen(dev, flag) - dev_t dev; - int flag; -{ - struct lpt_softc *sc; - int s; - int trys, port; - u_int unit = LPTUNIT(minor(dev)); - - if (unit >= NLPT) - return (ENXIO); - sc = lpt_sc + unit; - - if (sc->sc_state) { -lprintf("lp: still open\n") ; -lprintf("still open %x\n", sc->sc_state); - return(EBUSY); - } else sc->sc_state |= INIT; - - s = spltty(); - sc->sc_flags = LPTFLAGS(minor(dev)); -lprintf("lp flags 0x%x\n", sc->sc_flags); - port = sc->sc_port; - - /* init printer */ - if((sc->sc_flags & LP_NO_PRIME) == 0) { - if((sc->sc_flags & LP_PRIMEOPEN) || sc->sc_primed == 0) { - outb(port+lpt_control, 0); - sc->sc_primed++; - DELAY(500); - } - } - outb(port+lpt_control, LPC_SEL|LPC_NINIT); - - /* wait till ready (printer running diagnostics) */ - trys = 0; - do { - /* ran out of waiting for the printer */ - if (trys++ >= LPINITRDY*4) { - splx(s); - sc->sc_state = 0; -lprintf ("status %x\n", inb(port+lpt_status) ); - return (EBUSY); - } - - /* wait 1/4 second, give up if we get a signal */ - if (tsleep (sc, LPPRI|PCATCH, "lptinit", hz/4) != EWOULDBLOCK) { - sc->sc_state = 0; - splx(s); - return (EBUSY); - } - - /* is printer online and ready for output */ - } while ((inb(port+lpt_status) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) != - (LPS_SEL|LPS_NBSY|LPS_NERR)); - - if(sc->sc_flags&LP_AUTOLF) { - outb(port+lpt_control, LPC_SEL|LPC_NINIT|LPC_ENA|LPC_AUTOL); - sc->sc_control = LPC_SEL|LPC_NINIT|LPC_ENA|LPC_AUTOL; - } else { - outb(port+lpt_control, LPC_SEL|LPC_NINIT|LPC_ENA); - sc->sc_control = LPC_SEL|LPC_NINIT|LPC_ENA; - } - - sc->sc_state = OPEN | TOUT; - sc->sc_inbuf = geteblk(BUFSIZE); - sc->sc_xfercnt = 0; - splx(s); - timeout (lptout, sc, hz/2); -lprintf("opened.\n"); - return(0); -} - -void -lptout (sc) - struct lpt_softc *sc; -{ int pl; - -lprintf ("T %x ", inb(sc->sc_port+lpt_status)); - if (sc->sc_state&OPEN) - timeout (lptout, sc, hz/2); - else sc->sc_state &= ~TOUT; - - if (sc->sc_state & ERROR) - sc->sc_state &= ~ERROR; - - /* - * Avoid possible hangs do to missed interrupts - */ - if (sc->sc_xfercnt) { - pl = spltty(); - lptintr(sc - lpt_sc); - splx(pl); - } else { - sc->sc_state &= ~OBUSY; - wakeup((caddr_t)sc); - } -} - -/* - * lptclose -- close the device, free the local line buffer. - */ - -int -lptclose(dev, flag) - dev_t dev; - int flag; -{ - struct lpt_softc *sc = lpt_sc + LPTUNIT(minor(dev)); - int port = sc->sc_port; - - sc->sc_state &= ~OPEN; - while ((inb(port+lpt_status) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) != - (LPS_SEL|LPS_NBSY|LPS_NERR) || sc->sc_xfercnt) - /* wait 1/4 second, give up if we get a signal */ - if (tsleep (sc, LPPRI|PCATCH, "lpclose", hz) != EWOULDBLOCK) - break; - - sc->sc_state = 0; - sc->sc_xfercnt = 0; - outb(sc->sc_port+lpt_control, LPC_NINIT); - brelse(sc->sc_inbuf); -lprintf("closed.\n"); - return(0); -} - -/* - * lptwrite --copy a line from user space to a local buffer, then call - * putc to get the chars moved to the output queue. - */ - -int -lptwrite(dev, uio) - dev_t dev; - struct uio *uio; -{ - register unsigned n; - int pl, err; - struct lpt_softc *sc = lpt_sc + LPTUNIT(minor(dev)); - - while (n = MIN(BUFSIZE, uio->uio_resid)) { - sc->sc_cp = sc->sc_inbuf->b_un.b_addr ; - uiomove(sc->sc_cp, n, uio); - sc->sc_xfercnt = n ; - while (sc->sc_xfercnt > 0) { - /* if the printer is ready for a char, give it one */ - if ((sc->sc_state & OBUSY) == 0){ -lprintf("\nC %d. ", sc->sc_xfercnt); - pl = spltty(); - lptintr(sc - lpt_sc); - (void) splx(pl); - } -lprintf("W "); - if (err = tsleep (sc, LPPRI|PCATCH, "lpwrite", 0)) - return(err); - } - } - return(0); -} - -/* - * lptintr -- handle printer interrupts which occur when the printer is - * ready to accept another char. - */ - -void -lptintr(unit) - int unit; -{ - struct lpt_softc *sc = lpt_sc + unit; - int port = sc->sc_port,sts; - - /* is printer online and ready for output */ - if (((sts=inb(port+lpt_status)) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR/*|LPS_NACK*/)) == - (LPS_SEL|LPS_NBSY|LPS_NERR)) { - /* is this a false interrupt ? */ - if ((sc->sc_state & OBUSY) - && (sts & LPS_NACK) == 0) return; - sc->sc_state |= OBUSY; sc->sc_state &= ~ERROR; - - if (sc->sc_xfercnt) { - /* send char */ -/*lprintf("%x ", *sc->sc_cp); */ - outb(port+lpt_data, *sc->sc_cp++) ; sc->sc_xfercnt-- ; - outb(port+lpt_control, sc->sc_control|LPC_STB); - /* DELAY(X) */ - outb(port+lpt_control, sc->sc_control); - } - - /* any more bytes for the printer? */ - if (sc->sc_xfercnt > 0) return; - - /* none, wake up the top half to get more */ - sc->sc_state &= ~OBUSY; - wakeup((caddr_t)sc); -lprintf("w "); -return; - } else sc->sc_state |= ERROR; -lprintf("sts %x ", sts); -} - -int -lptioctl(dev, cmd, data, flag) - dev_t dev; - int cmd; - caddr_t data; - int flag; -{ - int error; - - error = 0; - switch (cmd) { -#ifdef THISISASAMPLE - case XXX: - dothis; andthis; andthat; - error=x; - break; -#endif /* THISISASAMPLE */ - default: - error = ENODEV; - } - - return(error); -} - -#endif /* NLPT */ diff --git a/sys/i386/isa/lptreg.h b/sys/i386/isa/lptreg.h deleted file mode 100644 index 9e10ba9..0000000 --- a/sys/i386/isa/lptreg.h +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * form: @(#)lptreg.h 1.1 (Berkeley) 12/19/90 - * $Id$ - */ - -/* - * AT Parallel Port (for lineprinter) - * Interface port and bit definitions - * Written by William Jolitz 12/18/90 - * Copyright (C) William Jolitz 1990 - */ - -#define lpt_data 0 /* Data to/from printer (R/W) */ - -#define lpt_status 1 /* Status of printer (R) */ -#define LPS_NERR 0x08 /* printer no error */ -#define LPS_SEL 0x10 /* printer selected */ -#define LPS_OUT 0x20 /* printer out of paper */ -#define LPS_NACK 0x40 /* printer no ack of data */ -#define LPS_NBSY 0x80 /* printer no ack of data */ - -#define lpt_control 2 /* Control printer (R/W) */ -#define LPC_STB 0x01 /* strobe data to printer */ -#define LPC_AUTOL 0x02 /* automatic linefeed */ -#define LPC_NINIT 0x04 /* initialize printer */ -#define LPC_SEL 0x08 /* printer selected */ -#define LPC_ENA 0x10 /* printer out of paper */ diff --git a/sys/i386/isa/mcd.c b/sys/i386/isa/mcd.c deleted file mode 100644 index 3064d08..0000000 --- a/sys/i386/isa/mcd.c +++ /dev/null @@ -1,1260 +0,0 @@ -/* - * Copyright 1993 by Holger Veit (data part) - * Copyright 1993 by Brian Moore (audio part) - * All rights reserved. - * - * 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 software was developed by Holger Veit and Brian Moore - * for use with "386BSD" and similar operating systems. - * "Similar operating systems" includes mainly non-profit oriented - * systems for research and education, including but not restricted to - * "NetBSD", "FreeBSD", "Mach" (by CMU). - * 4. Neither the name of the developer(s) nor the name "386BSD" - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER(S) BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR 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. - * - * $Id: mcd.c,v 1.1 1993/10/12 06:08:29 rgrimes Exp $ - */ -static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; - -#include "mcd.h" -#if NMCD > 0 -#include "types.h" -#include "param.h" -#include "systm.h" -#include "conf.h" -#include "file.h" -#include "buf.h" -#include "stat.h" -#include "uio.h" -#include "ioctl.h" -#include "cdio.h" -#include "errno.h" -#include "dkbad.h" -#include "disklabel.h" -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "mcdreg.h" - -/* user definable options */ -/*#define MCD_TO_WARNING_ON*/ /* define to get timeout messages */ -/*#define MCDMINI*/ /* define for a mini configuration for boot kernel */ - - -#ifdef MCDMINI -#define MCD_TRACE(fmt,a,b,c,d) -#ifdef MCD_TO_WARNING_ON -#undef MCD_TO_WARNING_ON -#endif -#else -#define MCD_TRACE(fmt,a,b,c,d) {if (mcd_data[unit].debug) {printf("mcd%d st=%02x: ",unit,mcd_data[unit].status); printf(fmt,a,b,c,d);}} -#endif - -#define mcd_part(dev) ((minor(dev)) & 7) -#define mcd_unit(dev) (((minor(dev)) & 0x38) >> 3) -#define mcd_phys(dev) (((minor(dev)) & 0x40) >> 6) -#define RAW_PART 3 - -/* flags */ -#define MCDOPEN 0x0001 /* device opened */ -#define MCDVALID 0x0002 /* parameters loaded */ -#define MCDINIT 0x0004 /* device is init'd */ -#define MCDWAIT 0x0008 /* waiting for something */ -#define MCDLABEL 0x0010 /* label is read */ -#define MCDPROBING 0x0020 /* probing */ -#define MCDREADRAW 0x0040 /* read raw mode (2352 bytes) */ -#define MCDVOLINFO 0x0080 /* already read volinfo */ -#define MCDTOC 0x0100 /* already read toc */ -#define MCDMBXBSY 0x0200 /* local mbx is busy */ - -/* status */ -#define MCDAUDIOBSY MCD_ST_AUDIOBSY /* playing audio */ -#define MCDDSKCHNG MCD_ST_DSKCHNG /* sensed change of disk */ -#define MCDDSKIN MCD_ST_DSKIN /* sensed disk in drive */ -#define MCDDOOROPEN MCD_ST_DOOROPEN /* sensed door open */ - -/* toc */ -#define MCD_MAXTOCS 104 /* from the Linux driver */ -#define MCD_LASTPLUS1 170 /* special toc entry */ - -struct mcd_mbx { - short unit; - short port; - short retry; - short nblk; - int sz; - u_long skip; - struct buf *bp; - int p_offset; - short count; -}; - -struct mcd_data { - short config; - short flags; - short status; - int blksize; - u_long disksize; - int iobase; - struct disklabel dlabel; - int partflags[MAXPARTITIONS]; - int openflags; - struct mcd_volinfo volinfo; -#ifndef MCDMINI - struct mcd_qchninfo toc[MCD_MAXTOCS]; - short audio_status; - struct mcd_read2 lastpb; -#endif - short debug; - struct buf head; /* head of buf queue */ - struct mcd_mbx mbx; -} mcd_data[NMCD]; - -/* reader state machine */ -#define MCD_S_BEGIN 0 -#define MCD_S_BEGIN1 1 -#define MCD_S_WAITSTAT 2 -#define MCD_S_WAITMODE 3 -#define MCD_S_WAITREAD 4 - -/* prototypes */ -int mcdopen(dev_t dev); -int mcdclose(dev_t dev); -int mcdstrategy(struct buf *bp); -int mcdioctl(dev_t dev, int cmd, caddr_t addr, int flags); -int mcdsize(dev_t dev); -static void mcd_done(struct mcd_mbx *mbx); -static void mcd_start(int unit); -static int mcd_getdisklabel(int unit); -static void mcd_configure(struct mcd_data *cd); -static int mcd_get(int unit, char *buf, int nmax); -static void mcd_setflags(int unit,struct mcd_data *cd); -static int mcd_getstat(int unit,int sflg); -static int mcd_send(int unit, int cmd,int nretrys); -static int bcd2bin(bcd_t b); -static bcd_t bin2bcd(int b); -static void hsg2msf(int hsg, bcd_t *msf); -static int msf2hsg(bcd_t *msf); -static int mcd_volinfo(int unit); -static int mcd_waitrdy(int port,int dly); -static void mcd_doread(int state, struct mcd_mbx *mbxin); -#ifndef MCDMINI -static int mcd_setmode(int unit, int mode); -static int mcd_getqchan(int unit, struct mcd_qchninfo *q); -static int mcd_subchan(int unit, struct ioc_read_subchannel *sc); -static int mcd_toc_header(int unit, struct ioc_toc_header *th); -static int mcd_read_toc(int unit); -static int mcd_toc_entry(int unit, struct ioc_read_toc_entry *te); -static int mcd_stop(int unit); -static int mcd_playtracks(int unit, struct ioc_play_track *pt); -static int mcd_play(int unit, struct mcd_read2 *pb); -static int mcd_pause(int unit); -static int mcd_resume(int unit); -#endif - -extern int hz; -extern int mcd_probe(struct isa_device *dev); -extern int mcd_attach(struct isa_device *dev); -struct isa_driver mcddriver = { mcd_probe, mcd_attach, "mcd" }; - -#define mcd_put(port,byte) outb(port,byte) - -#define MCD_RETRYS 5 -#define MCD_RDRETRYS 8 - -#define MCDBLK 2048 /* for cooked mode */ -#define MCDRBLK 2352 /* for raw mode */ - -/* several delays */ -#define RDELAY_WAITSTAT 300 -#define RDELAY_WAITMODE 300 -#define RDELAY_WAITREAD 800 - -#define DELAY_STATUS 10000l /* 10000 * 1us */ -#define DELAY_GETREPLY 200000l /* 200000 * 2us */ -#define DELAY_SEEKREAD 20000l /* 20000 * 1us */ -#define mcd_delay DELAY - -int mcd_attach(struct isa_device *dev) -{ - struct mcd_data *cd = mcd_data + dev->id_unit; - int i; - - cd->iobase = dev->id_iobase; - cd->flags |= MCDINIT; - cd->openflags = 0; - for (i=0; i<MAXPARTITIONS; i++) cd->partflags[i] = 0; - -#ifdef NOTYET - /* wire controller for interrupts and dma */ - mcd_configure(cd); -#endif - - return 1; -} - -int mcdopen(dev_t dev) -{ - int unit,part,phys; - struct mcd_data *cd; - - unit = mcd_unit(dev); - if (unit >= NMCD) - return ENXIO; - - cd = mcd_data + unit; - part = mcd_part(dev); - phys = mcd_phys(dev); - - /* not initialized*/ - if (!(cd->flags & MCDINIT)) - return ENXIO; - - /* invalidated in the meantime? mark all open part's invalid */ - if (!(cd->flags & MCDVALID) && cd->openflags) - return ENXIO; - - if (mcd_getstat(unit,1) < 0) - return ENXIO; - - /* XXX get a default disklabel */ - mcd_getdisklabel(unit); - - if (mcdsize(dev) < 0) { - printf("mcd%d: failed to get disk size\n",unit); - return ENXIO; - } else - cd->flags |= MCDVALID; - -MCD_TRACE("open: partition=%d, disksize = %d, blksize=%d\n", - part,cd->disksize,cd->blksize,0); - - if (part == RAW_PART || - (part < cd->dlabel.d_npartitions && - cd->dlabel.d_partitions[part].p_fstype != FS_UNUSED)) { - cd->partflags[part] |= MCDOPEN; - cd->openflags |= (1<<part); - if (part == RAW_PART && phys != 0) - cd->partflags[part] |= MCDREADRAW; - return 0; - } - - return ENXIO; -} - -int mcdclose(dev_t dev) -{ - int unit,part,phys; - struct mcd_data *cd; - - unit = mcd_unit(dev); - if (unit >= NMCD) - return ENXIO; - - cd = mcd_data + unit; - part = mcd_part(dev); - phys = mcd_phys(dev); - - if (!(cd->flags & MCDINIT)) - return ENXIO; - - mcd_getstat(unit,1); /* get status */ - - /* close channel */ - cd->partflags[part] &= ~(MCDOPEN|MCDREADRAW); - cd->openflags &= ~(1<<part); - MCD_TRACE("close: partition=%d\n",part,0,0,0); - - return 0; -} - -int mcdstrategy(struct buf *bp) -{ - struct mcd_data *cd; - struct buf *qp; - int s; - - int unit = mcd_unit(bp->b_dev); - - cd = mcd_data + unit; - - /* test validity */ -/*MCD_TRACE("strategy: buf=0x%lx, unit=%ld, block#=%ld bcount=%ld\n", - bp,unit,bp->b_blkno,bp->b_bcount);*/ - if (unit >= NMCD || bp->b_blkno < 0) { - printf("mcdstrategy: unit = %d, blkno = %d, bcount = %d\n", - unit, bp->b_blkno, bp->b_bcount); - pg("mcd: mcdstratregy failure"); - bp->b_error = EINVAL; - bp->b_flags |= B_ERROR; - goto bad; - } - - /* if device invalidated (e.g. media change, door open), error */ - if (!(cd->flags & MCDVALID)) { -MCD_TRACE("strategy: drive not valid\n",0,0,0,0); - bp->b_error = EIO; - goto bad; - } - - /* read only */ - if (!(bp->b_flags & B_READ)) { - bp->b_error = EROFS; - goto bad; - } - - /* no data to read */ - if (bp->b_bcount == 0) - goto done; - - /* for non raw access, check partition limits */ - if (mcd_part(bp->b_dev) != RAW_PART) { - if (!(cd->flags & MCDLABEL)) { - bp->b_error = EIO; - goto bad; - } - /* adjust transfer if necessary */ - if (bounds_check_with_label(bp,&cd->dlabel,1) <= 0) { - goto done; - } - } - - /* queue it */ - qp = &cd->head; - s = splbio(); - disksort(qp,bp); - splx(s); - - /* now check whether we can perform processing */ - mcd_start(unit); - return; - -bad: - bp->b_flags |= B_ERROR; -done: - bp->b_resid = bp->b_bcount; - biodone(bp); - return; -} - -static void mcd_start(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - struct buf *bp, *qp = &cd->head; - struct partition *p; - int part; - register s = splbio(); - - if (cd->flags & MCDMBXBSY) - return; - - if ((bp = qp->b_actf) != 0) { - /* block found to process, dequeue */ - /*MCD_TRACE("mcd_start: found block bp=0x%x\n",bp,0,0,0);*/ - qp->b_actf = bp->av_forw; - splx(s); - } else { - /* nothing to do */ - splx(s); - return; - } - - /* changed media? */ - if (!(cd->flags & MCDVALID)) { - MCD_TRACE("mcd_start: drive not valid\n",0,0,0,0); - return; - } - - p = cd->dlabel.d_partitions + mcd_part(bp->b_dev); - - cd->flags |= MCDMBXBSY; - cd->mbx.unit = unit; - cd->mbx.port = cd->iobase; - cd->mbx.retry = MCD_RETRYS; - cd->mbx.bp = bp; - cd->mbx.p_offset = p->p_offset; - - /* calling the read routine */ - mcd_doread(MCD_S_BEGIN,&(cd->mbx)); - /* triggers mcd_start, when successful finished */ - return; -} - -int mcdioctl(dev_t dev, int cmd, caddr_t addr, int flags) -{ - struct mcd_data *cd; - int unit,part; - - unit = mcd_unit(dev); - part = mcd_part(dev); - cd = mcd_data + unit; - -#ifdef MCDMINI - return ENOTTY; -#else - if (!(cd->flags & MCDVALID)) - return EIO; -MCD_TRACE("ioctl called 0x%x\n",cmd,0,0,0); - - switch (cmd) { - case DIOCSBAD: - return EINVAL; - case DIOCGDINFO: - case DIOCGPART: - case DIOCWDINFO: - case DIOCSDINFO: - case DIOCWLABEL: - return ENOTTY; - case CDIOCPLAYTRACKS: - return mcd_playtracks(unit, (struct ioc_play_track *) addr); - case CDIOCPLAYBLOCKS: - return mcd_play(unit, (struct mcd_read2 *) addr); - case CDIOCREADSUBCHANNEL: - return mcd_subchan(unit, (struct ioc_read_subchannel *) addr); - case CDIOREADTOCHEADER: - return mcd_toc_header(unit, (struct ioc_toc_header *) addr); - case CDIOREADTOCENTRYS: - return mcd_toc_entry(unit, (struct ioc_read_toc_entry *) addr); - case CDIOCSETPATCH: - case CDIOCGETVOL: - case CDIOCSETVOL: - case CDIOCSETMONO: - case CDIOCSETSTERIO: - case CDIOCSETMUTE: - case CDIOCSETLEFT: - case CDIOCSETRIGHT: - return EINVAL; - case CDIOCRESUME: - return mcd_resume(unit); - case CDIOCPAUSE: - return mcd_pause(unit); - case CDIOCSTART: - return EINVAL; - case CDIOCSTOP: - return mcd_stop(unit); - case CDIOCEJECT: - return EINVAL; - case CDIOCSETDEBUG: - cd->debug = 1; - return 0; - case CDIOCCLRDEBUG: - cd->debug = 0; - return 0; - case CDIOCRESET: - return EINVAL; - default: - return ENOTTY; - } - /*NOTREACHED*/ -#endif /*!MCDMINI*/ -} - -/* this could have been taken from scsi/cd.c, but it is not clear - * whether the scsi cd driver is linked in - */ -static int mcd_getdisklabel(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - - if (cd->flags & MCDLABEL) - return -1; - - bzero(&cd->dlabel,sizeof(struct disklabel)); - strncpy(cd->dlabel.d_typename,"Mitsumi CD ROM ",16); - strncpy(cd->dlabel.d_packname,"unknown ",16); - cd->dlabel.d_secsize = cd->blksize; - cd->dlabel.d_nsectors = 100; - cd->dlabel.d_ntracks = 1; - cd->dlabel.d_ncylinders = (cd->disksize/100)+1; - cd->dlabel.d_secpercyl = 100; - cd->dlabel.d_secperunit = cd->disksize; - cd->dlabel.d_rpm = 300; - cd->dlabel.d_interleave = 1; - cd->dlabel.d_flags = D_REMOVABLE; - cd->dlabel.d_npartitions= 1; - cd->dlabel.d_partitions[0].p_offset = 0; - cd->dlabel.d_partitions[0].p_size = cd->disksize; - cd->dlabel.d_partitions[0].p_fstype = 9; - cd->dlabel.d_magic = DISKMAGIC; - cd->dlabel.d_magic2 = DISKMAGIC; - cd->dlabel.d_checksum = dkcksum(&cd->dlabel); - - cd->flags |= MCDLABEL; - return 0; -} - -int mcdsize(dev_t dev) -{ - int size; - int unit = mcd_unit(dev); - struct mcd_data *cd = mcd_data + unit; - - if (mcd_volinfo(unit) >= 0) { - cd->blksize = MCDBLK; - size = msf2hsg(cd->volinfo.vol_msf); - cd->disksize = size * (MCDBLK/DEV_BSIZE); - return 0; - } - return -1; -} - -/*************************************************************** - * lower level of driver starts here - **************************************************************/ - -#ifdef NOTDEF -static char irqs[] = { - 0x00,0x00,0x10,0x20,0x00,0x30,0x00,0x00, - 0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00 -}; - -static char drqs[] = { - 0x00,0x01,0x00,0x03,0x00,0x05,0x06,0x07, -}; -#endif - -static void mcd_configure(struct mcd_data *cd) -{ - outb(cd->iobase+mcd_config,cd->config); -} - -/* check if there is a cdrom */ -/* Heavly hacked by gclarkii@sugar.neosoft.com */ - -int mcd_probe(struct isa_device *dev) -{ - int port = dev->id_iobase; - int unit = dev->id_unit; - int i; - int st; - int check; - int junk; - - mcd_data[unit].flags = MCDPROBING; - -#ifdef NOTDEF - /* get irq/drq configuration word */ - mcd_data[unit].config = irqs[dev->id_irq]; /* | drqs[dev->id_drq];*/ -#else - mcd_data[unit].config = 0; -#endif - - /* send a reset */ - outb(port+MCD_FLAGS,0); - DELAY(100000); - /* get any pending status and throw away...*/ - for (i=10; i != 0; i--) { - inb(port+MCD_DATA); - } - DELAY(1000); - - outb(port+MCD_DATA,MCD_CMDGETSTAT); /* Send get status command */ - - /* Loop looking for avail of status */ - /* XXX May have to increase for fast machinces */ - for (i = 1000; i != 0; i--) { - if ((inb(port+MCD_FLAGS) & 0xF ) == STATUS_AVAIL) { - break; - } - DELAY(10); - } - /* get status */ - - if (i == 0) { -#ifdef DEBUG - printf ("Mitsumi drive NOT detected\n"); -#endif - return 0; - } - -/* - * The following code uses the 0xDC command, it returns a M from the - * second byte and a number in the third. Does anyone know what the - * number is for? Better yet, how about someone thats REAL good in - * i80x86 asm looking at the Dos driver... Most of this info came - * from a friend of mine spending a whole weekend..... - */ - - DELAY (2000); - outb(port+MCD_DATA,MCD_CMDCONTINFO); - for (i = 0; i < 100000; i++) { - if ((inb(port+MCD_FLAGS) & 0xF) == STATUS_AVAIL) - break; - } - if (i > 100000) { -#ifdef DEBUG - printf ("Mitsumi drive error\n"); -#endif - return 0; - } - DELAY (40000); - st = inb(port+MCD_DATA); - DELAY (500); - check = inb(port+MCD_DATA); - DELAY (500); - junk = inb(port+MCD_DATA); /* What is byte used for?!?!? */ - - if (check = 'M') { -#ifdef DEBUG - printf("Mitsumi drive detected\n"); -#endif - return 4; - } else { - printf("Mitsumi drive NOT detected\n"); - printf("Mitsumi drive error\n"); - return 0; - } -} - -static int mcd_waitrdy(int port,int dly) -{ - int i; - - /* wait until xfer port senses data ready */ - for (i=0; i<dly; i++) { - if ((inb(port+mcd_xfer) & MCD_ST_BUSY)==0) - return 0; - mcd_delay(1); - } - return -1; -} - -static int mcd_getreply(int unit,int dly) -{ - int i; - struct mcd_data *cd = mcd_data + unit; - int port = cd->iobase; - - /* wait data to become ready */ - if (mcd_waitrdy(port,dly)<0) { -#ifdef MCD_TO_WARNING_ON - printf("mcd%d: timeout getreply\n",unit); -#endif - return -1; - } - - /* get the data */ - return inb(port+mcd_status) & 0xFF; -} - -static int mcd_getstat(int unit,int sflg) -{ - int i; - struct mcd_data *cd = mcd_data + unit; - int port = cd->iobase; - - /* get the status */ - if (sflg) - outb(port+mcd_command, MCD_CMDGETSTAT); - i = mcd_getreply(unit,DELAY_GETREPLY); - if (i<0) return -1; - - cd->status = i; - - mcd_setflags(unit,cd); - return cd->status; -} - -static void mcd_setflags(int unit, struct mcd_data *cd) -{ - /* check flags */ - if (cd->status & (MCDDSKCHNG|MCDDOOROPEN)) { - MCD_TRACE("getstat: sensed DSKCHNG or DOOROPEN\n",0,0,0,0); - cd->flags &= ~MCDVALID; - } - -#ifndef MCDMINI - if (cd->status & MCDAUDIOBSY) - cd->audio_status = CD_AS_PLAY_IN_PROGRESS; - else if (cd->audio_status == CD_AS_PLAY_IN_PROGRESS) - cd->audio_status = CD_AS_PLAY_COMPLETED; -#endif -} - -static int mcd_get(int unit, char *buf, int nmax) -{ - int port = mcd_data[unit].iobase; - int i,k; - - for (i=0; i<nmax; i++) { - - /* wait for data */ - if ((k = mcd_getreply(unit,DELAY_GETREPLY)) < 0) { -#ifdef MCD_TO_WARNING_ON - printf("mcd%d: timeout mcd_get\n",unit); -#endif - return -1; - } - buf[i] = k; - } - return i; -} - -static int mcd_send(int unit, int cmd,int nretrys) -{ - int i,k; - int port = mcd_data[unit].iobase; - -/*MCD_TRACE("mcd_send: command = 0x%x\n",cmd,0,0,0);*/ - for (i=0; i<nretrys; i++) { - outb(port+mcd_command, cmd); - if ((k=mcd_getstat(unit,0)) != -1) - break; - } - if (i == nretrys) { - printf("mcd%d: mcd_send retry cnt exceeded\n",unit); - return -1; - } -/*MCD_TRACE("mcd_send: status = 0x%x\n",k,0,0,0);*/ - return 0; -} - -static int bcd2bin(bcd_t b) -{ - return (b >> 4) * 10 + (b & 15); -} - -static bcd_t bin2bcd(int b) -{ - return ((b / 10) << 4) | (b % 10); -} - -static void hsg2msf(int hsg, bcd_t *msf) -{ - hsg += 150; - M_msf(msf) = bin2bcd(hsg / 4500); - hsg %= 4500; - S_msf(msf) = bin2bcd(hsg / 75); - F_msf(msf) = bin2bcd(hsg % 75); -} - -static int msf2hsg(bcd_t *msf) -{ - return (bcd2bin(M_msf(msf)) * 60 + - bcd2bin(S_msf(msf))) * 75 + - bcd2bin(F_msf(msf)) - 150; -} - -static int mcd_volinfo(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - int i; - -/*MCD_TRACE("mcd_volinfo: enter\n",0,0,0,0);*/ - - /* Get the status, in case the disc has been changed */ - if (mcd_getstat(unit, 1) < 0) return EIO; - - /* Just return if we already have it */ - if (cd->flags & MCDVOLINFO) return 0; - - /* send volume info command */ - if (mcd_send(unit,MCD_CMDGETVOLINFO,MCD_RETRYS) < 0) - return -1; - - /* get data */ - if (mcd_get(unit,(char*) &cd->volinfo,sizeof(struct mcd_volinfo)) < 0) { - printf("mcd%d: mcd_volinfo: error read data\n",unit); - return -1; - } - - if (cd->volinfo.trk_low != 0 || cd->volinfo.trk_high != 0) { - cd->flags |= MCDVOLINFO; /* volinfo is OK */ - return 0; - } - - return -1; -} - -int mcdintr(unit) -{ - int port = mcd_data[unit].iobase; - u_int i; - - MCD_TRACE("stray interrupt xfer=0x%x\n",inb(port+mcd_xfer),0,0,0); - - /* just read out status and ignore the rest */ - if ((inb(port+mcd_xfer)&0xFF) != 0xFF) { - i = inb(port+mcd_status); - } -} - -/* state machine to process read requests - * initialize with MCD_S_BEGIN: calculate sizes, and read status - * MCD_S_WAITSTAT: wait for status reply, set mode - * MCD_S_WAITMODE: waits for status reply from set mode, set read command - * MCD_S_WAITREAD: wait for read ready, read data - */ -static struct mcd_mbx *mbxsave; - -static void mcd_doread(int state, struct mcd_mbx *mbxin) -{ - struct mcd_mbx *mbx = (state!=MCD_S_BEGIN) ? mbxsave : mbxin; - int unit = mbx->unit; - int port = mbx->port; - struct buf *bp = mbx->bp; - struct mcd_data *cd = mcd_data + unit; - - int rm,i,k; - struct mcd_read2 rbuf; - int blknum; - caddr_t addr; - -loop: - switch (state) { - case MCD_S_BEGIN: - mbx = mbxsave = mbxin; - - case MCD_S_BEGIN1: - /* get status */ - outb(port+mcd_command, MCD_CMDGETSTAT); - mbx->count = RDELAY_WAITSTAT; - timeout(mcd_doread,MCD_S_WAITSTAT,hz/100); - return; - case MCD_S_WAITSTAT: - untimeout(mcd_doread,MCD_S_WAITSTAT); - if (mbx->count-- >= 0) { - if (inb(port+mcd_xfer) & MCD_ST_BUSY) { - timeout(mcd_doread,MCD_S_WAITSTAT,hz/100); - return; - } - mcd_setflags(unit,cd); - MCD_TRACE("got WAITSTAT delay=%d\n",RDELAY_WAITSTAT-mbx->count,0,0,0); - /* reject, if audio active */ - if (cd->status & MCDAUDIOBSY) { - printf("mcd%d: audio is active\n",unit); - goto readerr; - } - - /* to check for raw/cooked mode */ - if (cd->flags & MCDREADRAW) { - rm = MCD_MD_RAW; - mbx->sz = MCDRBLK; - } else { - rm = MCD_MD_COOKED; - mbx->sz = cd->blksize; - } - - mbx->count = RDELAY_WAITMODE; - - mcd_put(port+mcd_command, MCD_CMDSETMODE); - mcd_put(port+mcd_command, rm); - timeout(mcd_doread,MCD_S_WAITMODE,hz/100); - return; - } else { -#ifdef MCD_TO_WARNING_ON - printf("mcd%d: timeout getstatus\n",unit); -#endif - goto readerr; - } - - case MCD_S_WAITMODE: - untimeout(mcd_doread,MCD_S_WAITMODE); - if (mbx->count-- < 0) { -#ifdef MCD_TO_WARNING_ON - printf("mcd%d: timeout set mode\n",unit); -#endif - goto readerr; - } - if (inb(port+mcd_xfer) & MCD_ST_BUSY) { - timeout(mcd_doread,MCD_S_WAITMODE,hz/100); - return; - } - mcd_setflags(unit,cd); - MCD_TRACE("got WAITMODE delay=%d\n",RDELAY_WAITMODE-mbx->count,0,0,0); - /* for first block */ - mbx->nblk = (bp->b_bcount + (mbx->sz-1)) / mbx->sz; - mbx->skip = 0; - -nextblock: - blknum = (bp->b_blkno / (mbx->sz/DEV_BSIZE)) - + mbx->p_offset + mbx->skip/mbx->sz; - - MCD_TRACE("mcd_doread: read blknum=%d for bp=0x%x\n",blknum,bp,0,0); - - /* build parameter block */ - hsg2msf(blknum,rbuf.start_msf); - - /* send the read command */ - mcd_put(port+mcd_command,MCD_CMDREAD2); - mcd_put(port+mcd_command,rbuf.start_msf[0]); - mcd_put(port+mcd_command,rbuf.start_msf[1]); - mcd_put(port+mcd_command,rbuf.start_msf[2]); - mcd_put(port+mcd_command,0); - mcd_put(port+mcd_command,0); - mcd_put(port+mcd_command,1); - mbx->count = RDELAY_WAITREAD; - timeout(mcd_doread,MCD_S_WAITREAD,hz/100); - return; - case MCD_S_WAITREAD: - untimeout(mcd_doread,MCD_S_WAITREAD); - if (mbx->count-- > 0) { - k = inb(port+mcd_xfer); - if ((k & 2)==0) { - MCD_TRACE("got data delay=%d\n",RDELAY_WAITREAD-mbx->count,0,0,0); - /* data is ready */ - addr = bp->b_un.b_addr + mbx->skip; - outb(port+mcd_ctl2,0x04); /* XXX */ - for (i=0; i<mbx->sz; i++) - *addr++ = inb(port+mcd_rdata); - outb(port+mcd_ctl2,0x0c); /* XXX */ - - if (--mbx->nblk > 0) { - mbx->skip += mbx->sz; - goto nextblock; - } - - /* return buffer */ - bp->b_resid = 0; - biodone(bp); - - cd->flags &= ~MCDMBXBSY; - mcd_start(mbx->unit); - return; - } - if ((k & 4)==0) - mcd_getstat(unit,0); - timeout(mcd_doread,MCD_S_WAITREAD,hz/100); - return; - } else { -#ifdef MCD_TO_WARNING_ON - printf("mcd%d: timeout read data\n",unit); -#endif - goto readerr; - } - } - -readerr: - if (mbx->retry-- > 0) { -#ifdef MCD_TO_WARNING_ON - printf("mcd%d: retrying\n",unit); -#endif - state = MCD_S_BEGIN1; - goto loop; - } - - /* invalidate the buffer */ - bp->b_flags |= B_ERROR; - bp->b_resid = bp->b_bcount; - biodone(bp); - mcd_start(mbx->unit); - return; - -#ifdef NOTDEF - printf("mcd%d: unit timeout, resetting\n",mbx->unit); - outb(mbx->port+mcd_reset,MCD_CMDRESET); - DELAY(300000); - (void)mcd_getstat(mbx->unit,1); - (void)mcd_getstat(mbx->unit,1); - /*cd->status &= ~MCDDSKCHNG; */ - cd->debug = 1; /* preventive set debug mode */ - -#endif - -} - -#ifndef MCDMINI -static int mcd_setmode(int unit, int mode) -{ - struct mcd_data *cd = mcd_data + unit; - int port = cd->iobase; - int retry; - - printf("mcd%d: setting mode to %d\n", unit, mode); - for(retry=0; retry<MCD_RETRYS; retry++) - { - outb(port+mcd_command, MCD_CMDSETMODE); - outb(port+mcd_command, mode); - if (mcd_getstat(unit, 0) != -1) return 0; - } - - return -1; -} - -static int mcd_toc_header(int unit, struct ioc_toc_header *th) -{ - struct mcd_data *cd = mcd_data + unit; - - if (mcd_volinfo(unit) < 0) - return ENXIO; - - th->len = msf2hsg(cd->volinfo.vol_msf); - th->starting_track = bcd2bin(cd->volinfo.trk_low); - th->ending_track = bcd2bin(cd->volinfo.trk_high); - - return 0; -} - -static int mcd_read_toc(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - struct ioc_toc_header th; - struct mcd_qchninfo q; - int rc, trk, idx, retry; - - /* Only read TOC if needed */ - if (cd->flags & MCDTOC) return 0; - - printf("mcd%d: reading toc header\n", unit); - if (mcd_toc_header(unit, &th) != 0) - return ENXIO; - - printf("mcd%d: stopping play\n", unit); - if ((rc=mcd_stop(unit)) != 0) - return rc; - - /* try setting the mode twice */ - if (mcd_setmode(unit, MCD_MD_TOC) != 0) - return EIO; - if (mcd_setmode(unit, MCD_MD_TOC) != 0) - return EIO; - - printf("mcd%d: get_toc reading qchannel info\n",unit); - for(trk=th.starting_track; trk<=th.ending_track; trk++) - cd->toc[trk].idx_no = 0; - trk = th.ending_track - th.starting_track + 1; - for(retry=0; retry<300 && trk>0; retry++) - { - if (mcd_getqchan(unit, &q) < 0) break; - idx = bcd2bin(q.idx_no); - if (idx>0 && idx < MCD_MAXTOCS && q.trk_no==0) - if (cd->toc[idx].idx_no == 0) - { - cd->toc[idx] = q; - trk--; - } - } - - if (mcd_setmode(unit, MCD_MD_COOKED) != 0) - return EIO; - - if (trk != 0) return ENXIO; - - /* add a fake last+1 */ - idx = th.ending_track + 1; - cd->toc[idx].ctrl_adr = cd->toc[idx-1].ctrl_adr; - cd->toc[idx].trk_no = 0; - cd->toc[idx].idx_no = 0xAA; - cd->toc[idx].hd_pos_msf[0] = cd->volinfo.vol_msf[0]; - cd->toc[idx].hd_pos_msf[1] = cd->volinfo.vol_msf[1]; - cd->toc[idx].hd_pos_msf[2] = cd->volinfo.vol_msf[2]; - - cd->flags |= MCDTOC; - - return 0; -} - -static int mcd_toc_entry(int unit, struct ioc_read_toc_entry *te) -{ - struct mcd_data *cd = mcd_data + unit; - struct ret_toc - { - struct ioc_toc_header th; - struct cd_toc_entry rt; - } ret_toc; - struct ioc_toc_header th; - int rc, i; - - /* Make sure we have a valid toc */ - if ((rc=mcd_read_toc(unit)) != 0) - return rc; - - /* find the toc to copy*/ - i = te->starting_track; - if (i == MCD_LASTPLUS1) - i = bcd2bin(cd->volinfo.trk_high) + 1; - - /* verify starting track */ - if (i < bcd2bin(cd->volinfo.trk_low) || - i > bcd2bin(cd->volinfo.trk_high)+1) - return EINVAL; - - /* do we have room */ - if (te->data_len < sizeof(struct ioc_toc_header) + - sizeof(struct cd_toc_entry)) return EINVAL; - - /* Copy the toc header */ - if (mcd_toc_header(unit, &th) < 0) return EIO; - ret_toc.th = th; - - /* copy the toc data */ - ret_toc.rt.control = cd->toc[i].ctrl_adr; - ret_toc.rt.addr_type = te->address_format; - ret_toc.rt.track = i; - if (te->address_format == CD_MSF_FORMAT) - { - ret_toc.rt.addr[1] = cd->toc[i].hd_pos_msf[0]; - ret_toc.rt.addr[2] = cd->toc[i].hd_pos_msf[1]; - ret_toc.rt.addr[3] = cd->toc[i].hd_pos_msf[2]; - } - - /* copy the data back */ - copyout(&ret_toc, te->data, sizeof(struct cd_toc_entry) - + sizeof(struct ioc_toc_header)); - - return 0; -} - -static int mcd_stop(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - - if (mcd_send(unit, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0) - return ENXIO; - cd->audio_status = CD_AS_PLAY_COMPLETED; - return 0; -} - -static int mcd_getqchan(int unit, struct mcd_qchninfo *q) -{ - struct mcd_data *cd = mcd_data + unit; - - if (mcd_send(unit, MCD_CMDGETQCHN, MCD_RETRYS) < 0) - return -1; - if (mcd_get(unit, (char *) q, sizeof(struct mcd_qchninfo)) < 0) - return -1; - if (cd->debug) - printf("mcd%d: qchannel ctl=%d, t=%d, i=%d, ttm=%d:%d.%d dtm=%d:%d.%d\n", - unit, - q->ctrl_adr, q->trk_no, q->idx_no, - q->trk_size_msf[0], q->trk_size_msf[1], q->trk_size_msf[2], - q->trk_size_msf[0], q->trk_size_msf[1], q->trk_size_msf[2]); - return 0; -} - -static int mcd_subchan(int unit, struct ioc_read_subchannel *sc) -{ - struct mcd_data *cd = mcd_data + unit; - struct mcd_qchninfo q; - struct cd_sub_channel_info data; - - printf("mcd%d: subchan af=%d, df=%d\n", unit, - sc->address_format, - sc->data_format); - if (sc->address_format != CD_MSF_FORMAT) return EIO; - if (sc->data_format != CD_CURRENT_POSITION) return EIO; - - if (mcd_getqchan(unit, &q) < 0) return EIO; - - data.header.audio_status = cd->audio_status; - data.what.position.data_format = CD_MSF_FORMAT; - data.what.position.track_number = bcd2bin(q.trk_no); - - if (copyout(&data, sc->data, sizeof(struct cd_sub_channel_info))!=0) - return EFAULT; - return 0; -} - -static int mcd_playtracks(int unit, struct ioc_play_track *pt) -{ - struct mcd_data *cd = mcd_data + unit; - struct mcd_read2 pb; - int a = pt->start_track; - int z = pt->end_track; - int rc; - - if ((rc = mcd_read_toc(unit)) != 0) return rc; - - printf("mcd%d: playtracks from %d:%d to %d:%d\n", unit, - a, pt->start_index, z, pt->end_index); - - if (a < cd->volinfo.trk_low || a > cd->volinfo.trk_high || a > z || - z < cd->volinfo.trk_low || z > cd->volinfo.trk_high) - return EINVAL; - - pb.start_msf[0] = cd->toc[a].hd_pos_msf[0]; - pb.start_msf[1] = cd->toc[a].hd_pos_msf[1]; - pb.start_msf[2] = cd->toc[a].hd_pos_msf[2]; - pb.end_msf[0] = cd->toc[z+1].hd_pos_msf[0]; - pb.end_msf[1] = cd->toc[z+1].hd_pos_msf[1]; - pb.end_msf[2] = cd->toc[z+1].hd_pos_msf[2]; - - return mcd_play(unit, &pb); -} - -static int mcd_play(int unit, struct mcd_read2 *pb) -{ - struct mcd_data *cd = mcd_data + unit; - int port = cd->iobase; - int retry, st; - - cd->lastpb = *pb; - for(retry=0; retry<MCD_RETRYS; retry++) - { - outb(port+mcd_command, MCD_CMDREAD2); - outb(port+mcd_command, pb->start_msf[0]); - outb(port+mcd_command, pb->start_msf[1]); - outb(port+mcd_command, pb->start_msf[2]); - outb(port+mcd_command, pb->end_msf[0]); - outb(port+mcd_command, pb->end_msf[1]); - outb(port+mcd_command, pb->end_msf[2]); - if ((st=mcd_getstat(unit, 0)) != -1) break; - } - - if (cd->debug) - printf("mcd%d: mcd_play retry=%d, status=%d\n", unit, retry, st); - if (st == -1) return ENXIO; - cd->audio_status = CD_AS_PLAY_IN_PROGRESS; - return 0; -} - -static int mcd_pause(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - struct mcd_qchninfo q; - int rc; - - /* Verify current status */ - if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS) - { - printf("mcd%d: pause attempted when not playing\n", unit); - return EINVAL; - } - - /* Get the current position */ - if (mcd_getqchan(unit, &q) < 0) return EIO; - - /* Copy it into lastpb */ - cd->lastpb.start_msf[0] = q.hd_pos_msf[0]; - cd->lastpb.start_msf[1] = q.hd_pos_msf[1]; - cd->lastpb.start_msf[2] = q.hd_pos_msf[2]; - - /* Stop playing */ - if ((rc=mcd_stop(unit)) != 0) return rc; - - /* Set the proper status and exit */ - cd->audio_status = CD_AS_PLAY_PAUSED; - return 0; -} - -static int mcd_resume(int unit) -{ - struct mcd_data *cd = mcd_data + unit; - - if (cd->audio_status != CD_AS_PLAY_PAUSED) return EINVAL; - return mcd_play(unit, &cd->lastpb); -} -#endif /*!MCDMINI*/ - -#endif /* NMCD > 0 */ diff --git a/sys/i386/isa/mcdreg.h b/sys/i386/isa/mcdreg.h deleted file mode 100644 index 83664a7..0000000 --- a/sys/i386/isa/mcdreg.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 1993 by Holger Veit (data part) - * Copyright 1993 by Brian Moore (audio part) - * All rights reserved. - * - * 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 software was developed by Holger Veit and Brian Moore - * for use with "386BSD" and similar operating systems. - * "Similar operating systems" includes mainly non-profit oriented - * systems for research and education, including but not restricted to - * "NetBSD", "FreeBSD", "Mach" (by CMU). - * 4. Neither the name of the developer(s) nor the name "386BSD" - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER(S) BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR 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. - * - * This file contains definitions for some cdrom control commands - * and status codes. This info was "inherited" from the DOS MTMCDE.SYS - * driver, and is thus not complete (and may even be wrong). Some day - * the manufacturer or anyone else might provide better documentation, - * so this file (and the driver) will then have a better quality. - * - * $Id$ - */ - -#ifndef MCD_H -#define MCD_H - -#ifdef __GNUC__ -#if __GNUC__ >= 2 -#pragma pack(1) -#endif -#endif - -typedef unsigned char bcd_t; -#define M_msf(msf) msf[0] -#define S_msf(msf) msf[1] -#define F_msf(msf) msf[2] - -/* io lines used */ -#define MCD_IO_BASE 0x300 - -#define mcd_command 0 -#define mcd_status 0 -#define mcd_rdata 0 - -#define mcd_reset 1 -#define mcd_xfer 1 -#define mcd_ctl2 2 /* XXX Is this right? */ - -#define mcd_config 3 -#define MCD_MASK_DMA 0x07 /* bits 2-0 = DMA channel */ -#define MCD_MASK_IRQ 0x70 /* bits 6-4 = INT number */ - /* 001 = int 2,9 */ - /* 010 = int 3 */ - /* 011 = int 5 */ - /* 100 = int 10 */ - /* 101 = int 11 */ -/* flags */ -#define STATUS_AVAIL 0xb -#define DATA_AVAIL 0xf - -/* ports */ -#define MCD_DATA 0 -#define MCD_FLAGS 1 -#define MCD_DONT_KNOW 2 /* What are these two ports for??? */ -#define CHANNEL 3 - -/* Status bits */ -#define MCD_ST_DOOROPEN 0x80 -#define MCD_ST_DSKIN 0x40 -#define MCD_ST_DSKCHNG 0x20 -#define MCD_ST_BUSY 0x04 -#define MCD_ST_AUDIOBSY 0x02 - -/* commands known by the controller */ -#define MCD_CMDRESET 0x00 -#define MCD_CMDGETVOLINFO 0x10 /* gets mcd_volinfo */ -#define MCD_CMDGETQCHN 0x20 /* gets mcd_qchninfo */ -#define MCD_CMDGETSTAT 0x40 /* gets a byte of status */ -#define MCD_CMDSETMODE 0x50 /* set transmission mode, needs byte */ -#define MCD_MD_RAW 0x60 -#define MCD_MD_COOKED 0x01 -#define MCD_MD_TOC 0x05 -#define MCD_CMDSTOPAUDIO 0x70 -#define MCD_CMDGETVOLUME 0x8E /* gets mcd_volume */ -#define MCD_CMDSETVOLUME 0xAE /* sets mcd_volume */ -#define MCD_CMDREAD1 0xB0 /* read n sectors */ -#define MCD_CMDREAD2 0xC0 /* read from-to */ -#define MCD_CMDCONTINFO 0xDC /* Get controller info */ -#define MCD_CMDEJECTDISK 0xF6 -#define MCD_CMDCLOSETRAY 0xF8 -#define MCD_CMDLOCKDRV 0xFE /* needs byte */ -#define MCD_LK_UNLOCK 0x00 -#define MCD_LK_LOCK 0x01 -#define MCD_LK_TEST 0x02 - -struct mcd_volinfo { - bcd_t trk_low; - bcd_t trk_high; - bcd_t vol_msf[3]; - bcd_t trk1_msf[3]; -}; - -struct mcd_qchninfo { - u_char ctrl_adr; - u_char trk_no; - u_char idx_no; - bcd_t trk_size_msf[3]; - u_char :8; - bcd_t hd_pos_msf[3]; -}; - -struct mcd_volume { - u_char v0l; - u_char v0rs; - u_char v0r; - u_char v0ls; -}; - -struct mcd_read1 { - bcd_t start_msf[3]; - u_char nsec[3]; -}; - -struct mcd_read2 { - bcd_t start_msf[3]; - bcd_t end_msf[3]; -}; -#endif /* MCD_H */ diff --git a/sys/i386/isa/mse.c b/sys/i386/isa/mse.c deleted file mode 100644 index 60621cc..0000000 --- a/sys/i386/isa/mse.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Copyright 1992 by the University of Guelph - * - * Permission to use, copy and modify this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting - * documentation. - * University of Guelph makes no representations about the suitability of - * this software for any purpose. It is provided "as is" - * without express or implied warranty. - */ -/* - * Driver for the Logitech and ATI Inport Bus mice for use with 386bsd and - * the X386 port, courtesy of - * Rick Macklem, rick@snowhite.cis.uoguelph.ca - * Caveats: The driver currently uses spltty(), but doesn't use any - * generic tty code. It could use splmse() (that only masks off the - * bus mouse interrupt, but that would require hacking in i386/isa/icu.s. - * (This may be worth the effort, since the Logitech generates 30/60 - * interrupts/sec continuously while it is open.) - * NB: The ATI has NOT been tested yet! - */ - -/* - * Modification history: - * - * Oct 19, 1992 -- E. Stark (stark@cs.sunysb.edu) - * fixes to make it work with Microsoft InPort busmouse - * - * Jan, 1993 -- E. Stark (stark@cs.sunysb.edu) - * added patches for new "select" interface - * - * May 4, 1993 -- E. Stark (stark@cs.sunysb.edu) - * changed position of some spl()'s in mseread - * - * October 8, 1993 -- E. Stark (stark@cs.sunysb.edu) - * limit maximum negative x/y value to -127 to work around XFree problem - * that causes spurious button pushes. - */ - -#include "mse.h" -#if NMSE > 0 -#include "param.h" -#include "proc.h" -#include "user.h" -#include "buf.h" -#include "systm.h" -#include "kernel.h" -#include "ioctl.h" -#include "tty.h" -#include "uio.h" - -#include "i386/isa/isa_device.h" -#include "i386/isa/icu.h" - -int mseprobe(), mseattach(), mseintr(); - -struct isa_driver msedriver = { - mseprobe, mseattach, "mse" -}; - -/* - * Software control structure for mouse. The sc_enablemouse(), - * sc_disablemouse() and sc_getmouse() routines must be called spl'd(). - */ -#define PROTOBYTES 5 -struct mse_softc { - int sc_flags; - int sc_mousetype; - pid_t sc_selp; - u_int sc_port; - void (*sc_enablemouse)(); - void (*sc_disablemouse)(); - void (*sc_getmouse)(); - int sc_deltax; - int sc_deltay; - int sc_obuttons; - int sc_buttons; - int sc_bytesread; - u_char sc_bytes[PROTOBYTES]; -} mse_sc[NMSE]; - -/* Flags */ -#define MSESC_OPEN 0x1 -#define MSESC_WANT 0x2 - -/* and Mouse Types */ -#define MSE_LOGITECH 0x1 -#define MSE_ATIINPORT 0x2 - -#define MSE_PORTA 0 -#define MSE_PORTB 1 -#define MSE_PORTC 2 -#define MSE_PORTD 3 - -#define MSE_UNIT(dev) (minor(dev) >> 1) -#define MSE_NBLOCKIO(dev) (minor(dev) & 0x1) - -/* - * Logitech bus mouse definitions - */ -#define MSE_SETUP 0x91 /* What does this mean? */ -#define MSE_HOLD 0x80 -#define MSE_RXLOW 0x00 -#define MSE_RXHIGH 0x20 -#define MSE_RYLOW 0x40 -#define MSE_RYHIGH 0x60 -#define MSE_DISINTR 0x10 -#define MSE_INTREN 0x00 - -static int mse_probelogi(); -static void mse_enablelogi(), mse_disablelogi(), mse_getlogi(); - -/* - * ATI Inport mouse definitions - */ -#define MSE_INPORT_RESET 0x80 -#define MSE_INPORT_STATUS 0x00 -#define MSE_INPORT_DX 0x01 -#define MSE_INPORT_DY 0x02 -#define MSE_INPORT_MODE 0x07 -#define MSE_INPORT_HOLD 0x20 -#define MSE_INPORT_INTREN 0x09 - -static int mse_probeati(); -static void mse_enableati(), mse_disableati(), mse_getati(); - -#define MSEPRI (PZERO + 3) - -/* - * Table of mouse types. - * Keep the Logitech last, since I haven't figured out how to probe it - * properly yet. (Someday I'll have the documentation.) - */ -struct mse_types { - int m_type; /* Type of bus mouse */ - int (*m_probe)(); /* Probe routine to test for it */ - void (*m_enable)(); /* Start routine */ - void (*m_disable)(); /* Disable interrupts routine */ - void (*m_get)(); /* and get mouse status */ -} mse_types[] = { - { MSE_ATIINPORT, mse_probeati, mse_enableati, mse_disableati, mse_getati }, - { MSE_LOGITECH, mse_probelogi, mse_enablelogi, mse_disablelogi, mse_getlogi }, - { 0, }, -}; - -mseprobe(idp) - register struct isa_device *idp; -{ - register struct mse_softc *sc = &mse_sc[idp->id_unit]; - register int i; - - /* - * Check for each mouse type in the table. - */ - i = 0; - while (mse_types[i].m_type) { - if ((*mse_types[i].m_probe)(idp)) { - sc->sc_mousetype = mse_types[i].m_type; - sc->sc_enablemouse = mse_types[i].m_enable; - sc->sc_disablemouse = mse_types[i].m_disable; - sc->sc_getmouse = mse_types[i].m_get; - return (1); - } - i++; - } - return (0); -} - -mseattach(idp) - struct isa_device *idp; -{ - struct mse_softc *sc = &mse_sc[idp->id_unit]; - - sc->sc_port = idp->id_iobase; - return (1); -} - -/* - * Exclusive open the mouse, initialize it and enable interrupts. - */ -mseopen(dev, flag) - dev_t dev; - int flag; -{ - register struct mse_softc *sc; - int s; - - if (MSE_UNIT(dev) >= NMSE) - return (ENXIO); - sc = &mse_sc[MSE_UNIT(dev)]; - if (sc->sc_flags & MSESC_OPEN) - return (EBUSY); - sc->sc_flags |= MSESC_OPEN; - sc->sc_obuttons = sc->sc_buttons = 0x7; - sc->sc_deltax = sc->sc_deltay = 0; - sc->sc_bytesread = PROTOBYTES; - - /* - * Initialize mouse interface and enable interrupts. - */ - s = spltty(); - (*sc->sc_enablemouse)(sc->sc_port); - splx(s); - return (0); -} - -/* - * mseclose: just turn off mouse innterrupts. - */ -mseclose(dev, flag) - int flag; -{ - struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; - int s; - - s = spltty(); - (*sc->sc_disablemouse)(sc->sc_port); - sc->sc_flags &= ~MSESC_OPEN; - splx(s); - return(0); -} - -/* - * mseread: return mouse info using the MSC serial protocol, but without - * using bytes 4 and 5. - * (Yes this is cheesy, but it makes the X386 server happy, so...) - */ -mseread(dev, uio) - dev_t dev; - struct uio *uio; -{ - register struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; - int xfer, s, error; - - /* - * If there are no protocol bytes to be read, set up a new protocol - * packet. - */ - s = spltty(); /* XXX Should be its own spl, but where is imlXX() */ - if (sc->sc_bytesread >= PROTOBYTES) { - while (sc->sc_deltax == 0 && sc->sc_deltay == 0 && - (sc->sc_obuttons ^ sc->sc_buttons) == 0) { - if (MSE_NBLOCKIO(dev)) { - splx(s); - return (0); - } - sc->sc_flags |= MSESC_WANT; - if (error = tsleep((caddr_t)sc, MSEPRI | PCATCH, - "mseread", 0)) { - splx(s); - return (error); - } - } - - /* - * Generate protocol bytes. - * For some reason X386 expects 5 bytes but never uses - * the fourth or fifth? - */ - sc->sc_bytes[0] = 0x80 | (sc->sc_buttons & ~0xf8); - if (sc->sc_deltax > 127) - sc->sc_deltax = 127; - if (sc->sc_deltax < -127) - sc->sc_deltax = -127; - sc->sc_deltay = -sc->sc_deltay; /* Otherwise mousey goes wrong way */ - if (sc->sc_deltay > 127) - sc->sc_deltay = 127; - if (sc->sc_deltay < -127) - sc->sc_deltay = -127; - sc->sc_bytes[1] = sc->sc_deltax; - sc->sc_bytes[2] = sc->sc_deltay; - sc->sc_bytes[3] = sc->sc_bytes[4] = 0; - sc->sc_obuttons = sc->sc_buttons; - sc->sc_deltax = sc->sc_deltay = 0; - sc->sc_bytesread = 0; - } - splx(s); - xfer = MIN(uio->uio_resid, PROTOBYTES - sc->sc_bytesread); - if (error = uiomove(&sc->sc_bytes[sc->sc_bytesread], xfer, uio)) - return (error); - sc->sc_bytesread += xfer; - return(0); -} - -/* - * mseselect: check for mouse input to be processed. - */ -mseselect(dev, rw, p) - dev_t dev; - int rw; - struct proc *p; -{ - register struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; - int s; - - s = spltty(); - if (sc->sc_bytesread != PROTOBYTES || sc->sc_deltax != 0 || - sc->sc_deltay != 0 || (sc->sc_obuttons ^ sc->sc_buttons) != 0) { - splx(s); - return (1); - } - - /* - * Since this is an exclusive open device, any previous proc. - * pointer is trash now, so we can just assign it. - */ - sc->sc_selp = p->p_pid; - splx(s); - return (0); -} - -/* - * mseintr: update mouse status. sc_deltax and sc_deltay are accumulative. - */ -mseintr(unit) - int unit; -{ - register struct mse_softc *sc = &mse_sc[unit]; - pid_t p; - -#ifdef DEBUG - static int mse_intrcnt = 0; - if((mse_intrcnt++ % 10000) == 0) - printf("mseintr\n"); -#endif /* DEBUG */ - if ((sc->sc_flags & MSESC_OPEN) == 0) - return; - - (*sc->sc_getmouse)(sc->sc_port, &sc->sc_deltax, &sc->sc_deltay, &sc->sc_buttons); - - /* - * If mouse state has changed, wake up anyone wanting to know. - */ - if (sc->sc_deltax != 0 || sc->sc_deltay != 0 || - (sc->sc_obuttons ^ sc->sc_buttons) != 0) { - if (sc->sc_flags & MSESC_WANT) { - sc->sc_flags &= ~MSESC_WANT; - wakeup((caddr_t)sc); - } - if (sc->sc_selp) { - p = sc->sc_selp; - sc->sc_selp = (pid_t)0; - selwakeup(p, 0); - } - } -} - -/* - * Routines for the Logitech mouse. - */ -/* - * Test for a Logitech bus mouse and return 1 if it is. - * (until I know how to use the signature port properly, just disable - * interrupts and return 1) - */ -static int -mse_probelogi(idp) - register struct isa_device *idp; -{ - - outb(idp->id_iobase + MSE_PORTB, 0x55); - if (inb(idp->id_iobase + MSE_PORTB) == 0x55) { - outb(idp->id_iobase + MSE_PORTB, 0xaa); - if (inb(idp->id_iobase + MSE_PORTB) == 0xaa) - return (1); - } - return (0); -} - -/* - * Initialize Logitech mouse and enable interrupts. - */ -static void -mse_enablelogi(port) - register u_int port; -{ - int dx, dy, but; - - outb(port + MSE_PORTD, MSE_SETUP); - mse_getlogi(port, &dx, &dy, &but); -} - -/* - * Disable interrupts for Logitech mouse. - */ -static void -mse_disablelogi(port) - register u_int port; -{ - - outb(port + MSE_PORTC, MSE_DISINTR); -} - -/* - * Get the current dx, dy and button up/down state. - */ -static void -mse_getlogi(port, dx, dy, but) - register u_int port; - int *dx; - int *dy; - int *but; -{ - register char x, y; - - outb(port + MSE_PORTC, MSE_HOLD | MSE_RXLOW); - x = inb(port + MSE_PORTA); - *but = (x >> 5) & 0x7; - x &= 0xf; - outb(port + MSE_PORTC, MSE_HOLD | MSE_RXHIGH); - x |= (inb(port + MSE_PORTA) << 4); - outb(port + MSE_PORTC, MSE_HOLD | MSE_RYLOW); - y = (inb(port + MSE_PORTA) & 0xf); - outb(port + MSE_PORTC, MSE_HOLD | MSE_RYHIGH); - y |= (inb(port + MSE_PORTA) << 4); - *dx += x; - *dy += y; - outb(port + MSE_PORTC, MSE_INTREN); -} - -/* - * Routines for the ATI Inport bus mouse. - */ -/* - * Test for a ATI Inport bus mouse and return 1 if it is. - * (do not enable interrupts) - */ -static int -mse_probeati(idp) - register struct isa_device *idp; -{ - int i; - - for (i = 0; i < 2; i++) - if (inb(idp->id_iobase + MSE_PORTC) == 0xde) - return (1); - return (0); -} - -/* - * Initialize ATI Inport mouse and enable interrupts. - */ -static void -mse_enableati(port) - register u_int port; -{ - - outb(port + MSE_PORTA, MSE_INPORT_RESET); - outb(port + MSE_PORTA, MSE_INPORT_MODE); - outb(port + MSE_PORTB, MSE_INPORT_INTREN); -} - -/* - * Disable interrupts for ATI Inport mouse. - */ -static void -mse_disableati(port) - register u_int port; -{ - - outb(port + MSE_PORTA, MSE_INPORT_MODE); - outb(port + MSE_PORTB, 0); -} - -/* - * Get current dx, dy and up/down button state. - */ -static void -mse_getati(port, dx, dy, but) - register u_int port; - int *dx; - int *dy; - int *but; -{ - register char byte; - - outb(port + MSE_PORTA, MSE_INPORT_MODE); - outb(port + MSE_PORTB, MSE_INPORT_HOLD); - outb(port + MSE_PORTA, MSE_INPORT_STATUS); - *but = ~(inb(port + MSE_PORTB) & 0x7); - outb(port + MSE_PORTA, MSE_INPORT_DX); - byte = inb(port + MSE_PORTB); - *dx += byte; - outb(port + MSE_PORTA, MSE_INPORT_DY); - byte = inb(port + MSE_PORTB); - *dy += byte; - outb(port + MSE_PORTA, MSE_INPORT_MODE); - outb(port + MSE_PORTB, MSE_INPORT_INTREN); -} -#endif /* NMSE */ diff --git a/sys/i386/isa/npx.c b/sys/i386/isa/npx.c deleted file mode 100644 index 08256a6..0000000 --- a/sys/i386/isa/npx.c +++ /dev/null @@ -1,554 +0,0 @@ -/*- - * Copyright (c) 1990 William Jolitz. - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)npx.c 7.2 (Berkeley) 5/12/91 - * $Id$ - */ - -#include "npx.h" -#if NNPX > 0 - -#include "param.h" -#include "systm.h" -#include "conf.h" -#include "file.h" -#include "proc.h" -#include "machine/cpu.h" -#include "machine/pcb.h" -#include "machine/trap.h" -#include "ioctl.h" -#include "machine/specialreg.h" -#include "i386/isa/icu.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/isa.h" - -/* - * 387 and 287 Numeric Coprocessor Extension (NPX) Driver. - */ - -#ifdef __GNUC__ - -#define disable_intr() __asm("cli") -#define enable_intr() __asm("sti") -#define fldcw(addr) __asm("fldcw %0" : : "m" (*addr)) -#define fnclex() __asm("fnclex") -#define fninit() __asm("fninit") -#define fnsave(addr) __asm("fnsave %0" : "=m" (*addr) : "0" (*addr)) -#define fnstcw(addr) __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr)) -#define fnstsw(addr) __asm("fnstsw %0" : "=m" (*addr) : "0" (*addr)) -#define fp_divide_by_0() __asm("fldz; fld1; fdiv %st,%st(1); fwait") -#define frstor(addr) __asm("frstor %0" : : "m" (*addr)) -#define fwait() __asm("fwait") -#define read_eflags() ({u_long ef; \ - __asm("pushf; popl %0" : "=a" (ef)); \ - ef; }) -#define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \ - : : "n" (CR0_TS) : "ax") -#define stop_emulating() __asm("clts") -#define write_eflags(ef) __asm("pushl %0; popf" : : "a" ((u_long) ef)) - -#else /* not __GNUC__ */ - -void disable_intr __P((void)); -void enable_intr __P((void)); -void fldcw __P((caddr_t addr)); -void fnclex __P((void)); -void fninit __P((void)); -void fnsave __P((caddr_t addr)); -void fnstcw __P((caddr_t addr)); -void fnstsw __P((caddr_t addr)); -void fp_divide_by_0 __P((void)); -void frstor __P((caddr_t addr)); -void fwait __P((void)); -u_long read_eflags __P((void)); -void start_emulating __P((void)); -void stop_emulating __P((void)); -void write_eflags __P((u_long ef)); - -#endif /* __GNUC__ */ - -typedef u_char bool_t; - -extern struct gate_descriptor idt[]; - -int npxdna __P((void)); -void npxexit __P((struct proc *p)); -void npxinit __P((u_int control)); -void npxintr __P((struct intrframe frame)); -void npxsave __P((struct save87 *addr)); -static int npxattach __P((struct isa_device *dvp)); -static int npxprobe __P((struct isa_device *dvp)); -static int npxprobe1 __P((struct isa_device *dvp)); - -struct isa_driver npxdriver = { - npxprobe, npxattach, "npx", -}; - -u_int npx0mask; -struct proc *npxproc; - -static bool_t npx_ex16; -static bool_t npx_exists; -static struct gate_descriptor npx_idt_probeintr; -static int npx_intrno; -static volatile u_int npx_intrs_while_probing; -static bool_t npx_irq13; -static volatile u_int npx_traps_while_probing; - -/* - * Special interrupt handlers. Someday intr0-intr15 will be used to count - * interrupts. We'll still need a special exception 16 handler. The busy - * latch stuff in probintr() can be moved to npxprobe(). - */ -void probeintr(void); -asm -(" - .text -_probeintr: - ss - incl _npx_intrs_while_probing - pushl %eax - movb $0x20,%al /* EOI (asm in strings loses cpp features) */ - outb %al,$0xa0 /* IO_ICU2 */ - outb %al,$0x20 /* IO_ICU1 */ - movb $0,%al - outb %al,$0xf0 /* clear BUSY# latch */ - popl %eax - iret -"); - -void probetrap(void); -asm -(" - .text -_probetrap: - ss - incl _npx_traps_while_probing - fnclex - iret -"); - -/* - * Probe routine. Initialize cr0 to give correct behaviour for [f]wait - * whether the device exists or not (XXX should be elsewhere). Set flags - * to tell npxattach() what to do. Modify device struct if npx doesn't - * need to use interrupts. Return 1 if device exists. - */ -static int -npxprobe(dvp) - struct isa_device *dvp; -{ - int result; - u_long save_eflags; - u_char save_icu1_mask; - u_char save_icu2_mask; - struct gate_descriptor save_idt_npxintr; - struct gate_descriptor save_idt_npxtrap; - /* - * This routine is now just a wrapper for npxprobe1(), to install - * special npx interrupt and trap handlers, to enable npx interrupts - * and to disable other interrupts. Someday isa_configure() will - * install suitable handlers and run with interrupts enabled so we - * won't need to do so much here. - */ - npx_intrno = NRSVIDT + ffs(dvp->id_irq) - 1; - save_eflags = read_eflags(); - disable_intr(); - save_icu1_mask = inb(IO_ICU1 + 1); - save_icu2_mask = inb(IO_ICU2 + 1); - save_idt_npxintr = idt[npx_intrno]; - save_idt_npxtrap = idt[16]; - outb(IO_ICU1 + 1, ~(IRQ_SLAVE | dvp->id_irq)); - outb(IO_ICU2 + 1, ~(dvp->id_irq >> 8)); - setidt(16, probetrap, SDT_SYS386TGT, SEL_KPL); - setidt(npx_intrno, probeintr, SDT_SYS386IGT, SEL_KPL); - npx_idt_probeintr = idt[npx_intrno]; - enable_intr(); - result = npxprobe1(dvp); - disable_intr(); - outb(IO_ICU1 + 1, save_icu1_mask); - outb(IO_ICU2 + 1, save_icu2_mask); - idt[npx_intrno] = save_idt_npxintr; - idt[16] = save_idt_npxtrap; - write_eflags(save_eflags); - return (result); -} - -static int -npxprobe1(dvp) - struct isa_device *dvp; -{ - int control; - int status; -#ifdef lint - npxintr(); -#endif - /* - * Partially reset the coprocessor, if any. Some BIOS's don't reset - * it after a warm boot. - */ - outb(0xf1, 0); /* full reset on some systems, NOP on others */ - outb(0xf0, 0); /* clear BUSY# latch */ - /* - * Prepare to trap all ESC (i.e., NPX) instructions and all WAIT - * instructions. We must set the CR0_MP bit and use the CR0_TS - * bit to control the trap, because setting the CR0_EM bit does - * not cause WAIT instructions to trap. It's important to trap - * WAIT instructions - otherwise the "wait" variants of no-wait - * control instructions would degenerate to the "no-wait" variants - * after FP context switches but work correctly otherwise. It's - * particularly important to trap WAITs when there is no NPX - - * otherwise the "wait" variants would always degenerate. - * - * Try setting CR0_NE to get correct error reporting on 486DX's. - * Setting it should fail or do nothing on lesser processors. - */ - load_cr0(rcr0() | CR0_MP | CR0_NE); - /* - * But don't trap while we're probing. - */ - stop_emulating(); - /* - * Finish resetting the coprocessor, if any. If there is an error - * pending, then we may get a bogus IRQ13, but probeintr() will handle - * it OK. Bogus halts have never been observed, but we enabled - * IRQ13 and cleared the BUSY# latch early to handle them anyway. - */ - fninit(); - DELAY(1000); /* wait for any IRQ13 (fwait might hang) */ -#ifdef DIAGNOSTIC - if (npx_intrs_while_probing != 0) - printf("fninit caused %u bogus npx interrupt(s)\n", - npx_intrs_while_probing); - if (npx_traps_while_probing != 0) - printf("fninit caused %u bogus npx trap(s)\n", - npx_traps_while_probing); -#endif - /* - * Check for a status of mostly zero. - */ - status = 0x5a5a; - fnstsw(&status); - if ((status & 0xb8ff) == 0) { - /* - * Good, now check for a proper control word. - */ - control = 0x5a5a; - fnstcw(&control); - if ((control & 0x1f3f) == 0x033f) { - npx_exists = 1; - /* - * We have an npx, now divide by 0 to see if exception - * 16 works. - */ - control &= ~(1 << 2); /* enable divide by 0 trap */ - fldcw(&control); - npx_traps_while_probing = npx_intrs_while_probing = 0; - fp_divide_by_0(); - if (npx_traps_while_probing != 0) { - /* - * Good, exception 16 works. - */ - npx_ex16 = 1; - dvp->id_irq = 0; /* zap the interrupt */ - /* - * special return value to flag that we do not - * actually use any I/O registers - */ - return (-1); - } - if (npx_intrs_while_probing != 0) { - /* - * Bad, we are stuck with IRQ13. - */ - npx_irq13 = 1; - npx0mask = dvp->id_irq; /* npxattach too late */ - return (IO_NPXSIZE); - } - /* - * Worse, even IRQ13 is broken. Use emulator. - */ - } - } - /* - * Probe failed, but we want to get to npxattach to initialize the - * emulator and say that it has been installed. XXX handle devices - * that aren't really devices better. - */ - dvp->id_irq = 0; - /* - * special return value to flag that we do not - * actually use any I/O registers - */ - return (-1); -} - -/* - * Attach routine - announce which it is, and wire into system - */ -int -npxattach(dvp) - struct isa_device *dvp; -{ - if (!npx_ex16 && !npx_irq13) { - if (npx_exists) - printf("npx%d: Error reporting broken, using 387 emulator\n",dvp->id_unit); - else - printf("npx%d: 387 Emulator\n",dvp->id_unit); - } - npxinit(__INITIAL_NPXCW__); - return (1); /* XXX unused */ -} - -/* - * Initialize floating point unit. - */ -void -npxinit(control) - u_int control; -{ - struct save87 dummy; - - if (!npx_exists) - return; - /* - * fninit has the same h/w bugs as fnsave. Use the detoxified - * fnsave to throw away any junk in the fpu. fnsave initializes - * the fpu and sets npxproc = NULL as important side effects. - */ - npxsave(&dummy); - stop_emulating(); - fldcw(&control); - if (curpcb != NULL) - fnsave(&curpcb->pcb_savefpu); - start_emulating(); -} - -/* - * Free coprocessor (if we have it). - */ -void -npxexit(p) - struct proc *p; -{ - - if (p == npxproc) { - start_emulating(); - npxproc = NULL; - } -} - -/* - * Record the FPU state and reinitialize it all except for the control word. - * Then generate a SIGFPE. - * - * Reinitializing the state allows naive SIGFPE handlers to longjmp without - * doing any fixups. - * - * XXX there is currently no way to pass the full error state to signal - * handlers, and if this is a nested interrupt there is no way to pass even - * a status code! So there is no way to have a non-naive SIGFPE handler. At - * best a handler could do an fninit followed by an fldcw of a static value. - * fnclex would be of little use because it would leave junk on the FPU stack. - * Returning from the handler would be even less safe than usual because - * IRQ13 exception handling makes exceptions even less precise than usual. - */ -void -npxintr(frame) - struct intrframe frame; -{ - int code; - - if (npxproc == NULL || !npx_exists) { - /* XXX no %p in stand/printf.c. Cast to quiet gcc -Wall. */ - printf("npxintr: npxproc = %lx, curproc = %lx, npx_exists = %d\n", - (u_long) npxproc, (u_long) curproc, npx_exists); - panic("npxintr from nowhere"); - } - if (npxproc != curproc) { - printf("npxintr: npxproc = %lx, curproc = %lx, npx_exists = %d\n", - (u_long) npxproc, (u_long) curproc, npx_exists); - panic("npxintr from non-current process"); - } - /* - * Save state. This does an implied fninit. It had better not halt - * the cpu or we'll hang. - */ - outb(0xf0, 0); - fnsave(&curpcb->pcb_savefpu); - fwait(); - /* - * Restore control word (was clobbered by fnsave). - */ - fldcw(&curpcb->pcb_savefpu.sv_env.en_cw); - fwait(); - /* - * Remember the exception status word and tag word. The current - * (almost fninit'ed) fpu state is in the fpu and the exception - * state just saved will soon be junk. However, the implied fninit - * doesn't change the error pointers or register contents, and we - * preserved the control word and will copy the status and tag - * words, so the complete exception state can be recovered. - */ - curpcb->pcb_savefpu.sv_ex_sw = curpcb->pcb_savefpu.sv_env.en_sw; - curpcb->pcb_savefpu.sv_ex_tw = curpcb->pcb_savefpu.sv_env.en_tw; - - /* - * Pass exception to process. - */ - if (ISPL(frame.if_cs) == SEL_UPL) { - /* - * Interrupt is essentially a trap, so we can afford to call - * the SIGFPE handler (if any) as soon as the interrupt - * returns. - * - * XXX little or nothing is gained from this, and plenty is - * lost - the interrupt frame has to contain the trap frame - * (this is otherwise only necessary for the rescheduling trap - * in doreti, and the frame for that could easily be set up - * just before it is used). - */ - curproc->p_regs = (int *)&frame.if_es; - curpcb->pcb_flags |= FM_TRAP; /* used by sendsig */ -#ifdef notyet - /* - * Encode the appropriate code for detailed information on - * this exception. - */ - code = XXX_ENCODE(curpcb->pcb_savefpu.sv_ex_sw); -#else - code = 0; /* XXX */ -#endif - trapsignal(curproc, SIGFPE, code); - curpcb->pcb_flags &= ~FM_TRAP; - } else { - /* - * Nested interrupt. These losers occur when: - * o an IRQ13 is bogusly generated at a bogus time, e.g.: - * o immediately after an fnsave or frstor of an - * error state. - * o a couple of 386 instructions after - * "fstpl _memvar" causes a stack overflow. - * These are especially nasty when combined with a - * trace trap. - * o an IRQ13 occurs at the same time as another higher- - * priority interrupt. - * - * Treat them like a true async interrupt. - */ - psignal(npxproc, SIGFPE); - } -} - -/* - * Implement device not available (DNA) exception - * - * It would be better to switch FP context here (only). This would require - * saving the state in the proc table instead of in the pcb. - */ -int -npxdna() -{ - if (!npx_exists) - return (0); - if (npxproc != NULL) { - printf("npxdna: npxproc = %lx, curproc = %lx\n", - (u_long) npxproc, (u_long) curproc); - panic("npxdna"); - } - stop_emulating(); - /* - * Record new context early in case frstor causes an IRQ13. - */ - npxproc = curproc; - /* - * The following frstor may cause an IRQ13 when the state being - * restored has a pending error. The error will appear to have been - * triggered by the current (npx) user instruction even when that - * instruction is a no-wait instruction that should not trigger an - * error (e.g., fnclex). On at least one 486 system all of the - * no-wait instructions are broken the same as frstor, so our - * treatment does not amplify the breakage. On at least one - * 386/Cyrix 387 system, fnclex works correctly while frstor and - * fnsave are broken, so our treatment breaks fnclex if it is the - * first FPU instruction after a context switch. - */ - frstor(&curpcb->pcb_savefpu); - - return (1); -} - -/* - * Wrapper for fnsave instruction to handle h/w bugs. If there is an error - * pending, then fnsave generates a bogus IRQ13 on some systems. Force - * any IRQ13 to be handled immediately, and then ignore it. This routine is - * often called at splhigh so it must not use many system services. In - * particular, it's much easier to install a special handler than to - * guarantee that it's safe to use npxintr() and its supporting code. - */ -void -npxsave(addr) - struct save87 *addr; -{ - u_char icu1_mask; - u_char icu2_mask; - u_char old_icu1_mask; - u_char old_icu2_mask; - struct gate_descriptor save_idt_npxintr; - - disable_intr(); - old_icu1_mask = inb(IO_ICU1 + 1); - old_icu2_mask = inb(IO_ICU2 + 1); - save_idt_npxintr = idt[npx_intrno]; - outb(IO_ICU1 + 1, old_icu1_mask & ~(IRQ_SLAVE | npx0mask)); - outb(IO_ICU2 + 1, old_icu2_mask & ~(npx0mask >> 8)); - idt[npx_intrno] = npx_idt_probeintr; - enable_intr(); - stop_emulating(); - fnsave(addr); - fwait(); - start_emulating(); - npxproc = NULL; - disable_intr(); - icu1_mask = inb(IO_ICU1 + 1); /* masks may have changed */ - icu2_mask = inb(IO_ICU2 + 1); - outb(IO_ICU1 + 1, - (icu1_mask & ~npx0mask) | (old_icu1_mask & npx0mask)); - outb(IO_ICU2 + 1, - (icu2_mask & ~(npx0mask >> 8)) - | (old_icu2_mask & (npx0mask >> 8))); - idt[npx_intrno] = save_idt_npxintr; - enable_intr(); /* back to usual state */ -} - -#endif /* NNPX > 0 */ diff --git a/sys/i386/isa/rtc.h b/sys/i386/isa/rtc.h deleted file mode 100644 index 3f7b4c2..0000000 --- a/sys/i386/isa/rtc.h +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)rtc.h 7.1 (Berkeley) 5/12/91 - * $Id$ - */ - -/* - * RTC Register locations - */ - -#define RTC_SEC 0x00 /* seconds */ -#define RTC_SECALRM 0x01 /* seconds alarm */ -#define RTC_MIN 0x02 /* minutes */ -#define RTC_MINALRM 0x03 /* minutes alarm */ -#define RTC_HRS 0x04 /* hours */ -#define RTC_HRSALRM 0x05 /* hours alarm */ -#define RTC_WDAY 0x06 /* week day */ -#define RTC_DAY 0x07 /* day of month */ -#define RTC_MONTH 0x08 /* month of year */ -#define RTC_YEAR 0x09 /* month of year */ -#define RTC_STATUSA 0x0a /* status register A */ -#define RTCSA_TUP 0x80 /* time update, don't look now */ - -#define RTC_STATUSB 0x0b /* status register B */ - -#define RTC_INTR 0x0c /* status register C (R) interrupt source */ -#define RTCIR_UPDATE 0x10 /* update intr */ -#define RTCIR_ALARM 0x20 /* alarm intr */ -#define RTCIR_PERIOD 0x40 /* periodic intr */ -#define RTCIR_INT 0x80 /* interrupt output signal */ - -#define RTC_STATUSD 0x0d /* status register D (R) Lost Power */ -#define RTCSD_PWR 0x80 /* clock lost power */ - -#define RTC_DIAG 0x0e /* status register E - bios diagnostic */ -#define RTCDG_BITS "\020\010clock_battery\007ROM_cksum\006config_unit\005memory_size\004fixed_disk\003invalid_time" - -#define RTC_RESET 0x0f /* status register F - reset code byte */ -#define RTCRS_RST 0x00 /* normal reset */ -#define RTCRS_LOAD 0x04 /* load system */ - -#define RTC_FDISKETTE 0x10 /* diskette drive type in upper/lower nibble */ -#define RTCFDT_NONE 0 /* none present */ -#define RTCFDT_360K 0x10 /* 360K */ -#define RTCFDT_12M 0x20 /* 1.2M */ -#define RTCFDT_144M 0x40 /* 1.44M */ - -#define RTC_BASELO 0x15 /* low byte of basemem size */ -#define RTC_BASEHI 0x16 /* high byte of basemem size */ -#define RTC_EXTLO 0x17 /* low byte of extended mem size */ -#define RTC_EXTHI 0x18 /* low byte of extended mem size */ - -#define RTC_CENTURY 0x32 /* current century - please increment in Dec99*/ diff --git a/sys/i386/isa/sio.c b/sys/i386/isa/sio.c deleted file mode 100644 index 055a5e8..0000000 --- a/sys/i386/isa/sio.c +++ /dev/null @@ -1,1740 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)com.c 7.5 (Berkeley) 5/16/91 - * $Id$ - */ - -#include "sio.h" -#if NSIO > 0 -/* - * COM driver, based on HP dca driver. - * Mostly rewritten to use pseudo-DMA. - * Works for National Semiconductor NS8250-NS16550AF UARTs. - */ -#include "param.h" -#include "systm.h" -#include "ioctl.h" -#include "tty.h" -#include "proc.h" -#include "user.h" -#include "conf.h" -#include "file.h" -#include "uio.h" -#include "kernel.h" -#include "syslog.h" - -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/comreg.h" -#include "i386/isa/ic/ns16550.h" - -#undef CRTS_IFLOW -#define CRTS_IFLOW CRTSCTS /* XXX, CCTS_OFLOW = CRTSCTS already */ -#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */ -#define RB_I_HIGH_WATER (RBSZ - 2 * RS_IBUFSIZE) -#define RB_I_LOW_WATER ((RBSZ - 2 * RS_IBUFSIZE) * 7 / 8) -#define RS_IBUFSIZE 256 -#define TS_RTSBLOCK TS_TBLOCK /* XXX */ -#define TTY_BI TTY_FE /* XXX */ -#define TTY_OE TTY_PE /* XXX */ -#ifndef COM_BIDIR -#define UNIT(x) (minor(x)) /* XXX */ -#else /* COM_BIDIR */ -#define COM_UNITMASK 0x7f -#define COM_CALLOUTMASK 0x80 - -#define UNIT(x) (minor(x) & COM_UNITMASK) -#define CALLOUT(x) (minor(x) & COM_CALLOUTMASK) -#endif /* COM_BIDIR */ - -#ifdef COM_MULTIPORT -/* checks in flags for multiport and which is multiport "master chip" - * for a given card - */ -#define COM_ISMULTIPORT(dev) ((dev)->id_flags & 0x01) -#define COM_MPMASTER(dev) (((dev)->id_flags >> 8) & 0x0ff) -#endif /* COM_MULTIPORT */ - -#define com_scr 7 /* scratch register for 16450-16550 (R/W) */ -#define schedsoftcom() (ipending |= 1 << 4) /* XXX */ - -/* - * Input buffer watermarks. - * The external device is asked to stop sending when the buffer exactly reaches - * high water, or when the high level requests it. - * The high level is notified immediately (rather than at a later clock tick) - * when this watermark is reached. - * The buffer size is chosen so the watermark should almost never be reached. - * The low watermark is invisibly 0 since the buffer is always emptied all at - * once. - */ -#define RS_IHIGHWATER (3 * RS_IBUFSIZE / 4) - -/* - * com state bits. - * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher - * than the other bits so that they can be tested as a group without masking - * off the low bits. - * - * The following com and tty flags correspond closely: - * TS_BUSY = CS_BUSY (maintained by comstart() and comflush()) - * CS_TTGO = ~TS_TTSTOP (maintained by comstart() and siostop()) - * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam()) - * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam()) - * TS_FLUSH is not used. - * Bug: I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON. - */ -#define CS_BUSY 0x80 /* output in progress */ -#define CS_TTGO 0x40 /* output not stopped by XOFF */ -#define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */ -#define CS_CHECKMSR 1 /* check of MSR scheduled */ -#define CS_CTS_OFLOW 2 /* use CTS output flow control */ -#define CS_ODONE 4 /* output completed */ -#define CS_RTS_IFLOW 8 /* use RTS input flow control */ - -static char *error_desc[] = { -#define CE_OVERRUN 0 - "silo overflow", -#define CE_INTERRUPT_BUF_OVERFLOW 1 - "interrupt-level buffer overflow", -#define CE_TTY_BUF_OVERFLOW 2 - "tty-level buffer overflow", -}; - -#define CE_NTYPES 3 -#define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum]) - -/* types. XXX - should be elsewhere */ -typedef u_int Port_t; /* hardware port */ -typedef int Bool_t; /* promoted boolean */ -typedef u_char bool_t; /* boolean */ - -/* com device structure */ -struct com_s { - u_char state; /* miscellaneous flag bits */ - u_char cfcr_image; /* copy of value written to CFCR */ - bool_t hasfifo; /* nonzero for 16550 UARTs */ - u_char mcr_image; /* copy of value written to MCR */ - bool_t softDCD; /* nonzero for faked carrier detect */ -#ifdef COM_BIDIR - bool_t bidir; /* is this unit bidirectional? */ - bool_t active; /* is the port active _at all_? */ - bool_t active_in; /* is the incoming port in use? */ - bool_t active_out; /* is the outgoing port in use? */ -#endif /* COM_BIDIR */ -#ifdef COM_MULTIPORT - bool_t multiport; /* is this unit part of a multiport device? */ -#endif /* COM_MULTIPORT */ - - /* - * The high level of the driver never reads status registers directly - * because there would be too many side effects to handle conveniently. - * Instead, it reads copies of the registers stored here by the - * interrupt handler. - */ - u_char last_modem_status; /* last MSR read by intr handler */ - u_char prev_modem_status; /* last MSR handled by high level */ - - u_char *ibuf; /* start of input buffer */ - u_char *ibufend; /* end of input buffer */ - u_char *ihighwater; /* threshold in input buffer */ - u_char *iptr; /* next free spot in input buffer */ - - u_char *obufend; /* end of output buffer */ - int ocount; /* original count for current output */ - u_char *optr; /* next char to output */ - - Port_t data_port; /* i/o ports */ - Port_t int_id_port; - Port_t iobase; - Port_t modem_ctl_port; - Port_t line_status_port; - Port_t modem_status_port; - - struct tty *tp; /* cross reference */ - - u_long bytes_in; /* statistics */ - u_long bytes_out; - u_int delta_error_counts[CE_NTYPES]; - u_int error_counts[CE_NTYPES]; - - /* - * Ping-pong input buffers. The extra factor of 2 in the sizes is - * to allow for an error byte for each input byte. - */ -#define CE_INPUT_OFFSET RS_IBUFSIZE - u_char ibuf1[2 * RS_IBUFSIZE]; - u_char ibuf2[2 * RS_IBUFSIZE]; -}; - - -/* - * These functions in the com module ought to be declared (with a prototype) - * in a com-driver system header. The void ones may need to be int to match - * ancient devswitch declarations, but they don't actually return anything. - */ -#define Dev_t int /* promoted dev_t */ -struct consdev; - -int sioclose __P((Dev_t dev, int fflag, int devtype, - struct proc *p)); -void siointr __P((int unit)); -#ifdef COM_MULTIPORT -bool_t comintr1 __P((struct com_s *com)); -#endif /* COM_MULTIPORT */ -int sioioctl __P((Dev_t dev, int cmd, caddr_t data, - int fflag, struct proc *p)); -int siocngetc __P((Dev_t dev)); -void siocninit __P((struct consdev *cp)); -void siocnprobe __P((struct consdev *cp)); -void siocnputc __P((Dev_t dev, int c)); -int sioopen __P((Dev_t dev, int oflags, int devtype, - struct proc *p)); -/* - * sioopen gets compared to the d_open entry in struct cdevsw. d_open and - * other functions are declared in <sys/conf.h> with short types like dev_t - * in the prototype. Such declarations are broken because they vary with - * __P (significantly in theory - the compiler is allowed to push a short - * arg if it has seen the prototype; insignificantly in practice - gcc - * doesn't push short args and it would be slower on 386's to do so). - * - * Also, most of the device switch functions are still declared old-style - * so they take a Dev_t arg and shorten it to a dev_t. It would be simpler - * and faster if dev_t's were always promoted (to ints or whatever) as - * early as possible. - * - * Until <sys/conf.h> is fixed, we cast sioopen to the following `wrong' type - * when comparing it to the d_open entry just to avoid compiler warnings. - */ -typedef int (*bogus_open_t) __P((dev_t dev, int oflags, int devtype, - struct proc *p)); -int sioread __P((Dev_t dev, struct uio *uio, int ioflag)); -void siostop __P((struct tty *tp, int rw)); -int siowrite __P((Dev_t dev, struct uio *uio, int ioflag)); -void softsio0 __P((void)); -void softsio1 __P((void)); -void softsio2 __P((void)); -void softsio3 __P((void)); -void softsio4 __P((void)); -void softsio5 __P((void)); -void softsio6 __P((void)); -void softsio7 __P((void)); -void softsio8 __P((void)); - -static int sioattach __P((struct isa_device *dev)); -static void comflush __P((struct com_s *com)); -static void comhardclose __P((struct com_s *com)); -static void cominit __P((int unit, int rate)); -static int commctl __P((struct com_s *com, int bits, int how)); -static int comparam __P((struct tty *tp, struct termios *t)); -static int sioprobe __P((struct isa_device *dev)); -static void compoll __P((void)); -static int comstart __P((struct tty *tp)); -static void comwakeup __P((void)); -static int tiocm2mcr __P((int)); - -/* table and macro for fast conversion from a unit number to its com struct */ -static struct com_s *p_com_addr[NSIO]; -#define com_addr(unit) (p_com_addr[unit]) - -static struct com_s com_structs[NSIO]; - -struct isa_driver siodriver = { - sioprobe, sioattach, "sio" -}; - -#ifdef COMCONSOLE -static int comconsole = COMCONSOLE; -#else -static int comconsole = -1; -#endif -static bool_t comconsinit; -static speed_t comdefaultrate = TTYDEF_SPEED; -static u_int com_events; /* input chars + weighted output completions */ -static int commajor; -struct tty sio_tty[NSIO]; -extern struct tty *constty; -extern u_int ipending; /* XXX */ -extern int tk_nin; /* XXX */ -extern int tk_rawcc; /* XXX */ - -#ifdef KGDB -#include "machine/remote-sl.h" - -extern int kgdb_dev; -extern int kgdb_rate; -extern int kgdb_debug_init; -#endif - -static struct speedtab comspeedtab[] = { - 0, 0, - 50, COMBRD(50), - 75, COMBRD(75), - 110, COMBRD(110), - 134, COMBRD(134), - 150, COMBRD(150), - 200, COMBRD(200), - 300, COMBRD(300), - 600, COMBRD(600), - 1200, COMBRD(1200), - 1800, COMBRD(1800), - 2400, COMBRD(2400), - 4800, COMBRD(4800), - 9600, COMBRD(9600), - 19200, COMBRD(19200), - 38400, COMBRD(38400), - 57600, COMBRD(57600), - 115200, COMBRD(115200), - -1, -1 -}; - -/* XXX - configure this list */ -static Port_t likely_com_ports[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, }; - -static int -sioprobe(dev) - struct isa_device *dev; -{ - static bool_t already_init; - Port_t *com_ptr; - Port_t iobase; - int result; - - if (!already_init) { - /* - * Turn off MCR_IENABLE for all likely serial ports. An unused - * port with its MCR_IENABLE gate open will inhibit interrupts - * from any used port that shares the interrupt vector. - */ - for (com_ptr = likely_com_ports; - com_ptr < &likely_com_ports[sizeof likely_com_ports - / sizeof likely_com_ports[0]]; - ++com_ptr) - outb(*com_ptr + com_mcr, 0); - already_init = TRUE; - } - iobase = dev->id_iobase; - result = IO_COMSIZE; - - /* - * We don't want to get actual interrupts, just masked ones. - * Interrupts from this line should already be masked in the ICU, - * but mask them in the processor as well in case there are some - * (misconfigured) shared interrupts. - */ - disable_intr(); - - /* - * Enable output interrupts (only) and check the following: - * o the CFCR, IER and MCR in UART hold the values written to them - * (the values happen to be all distinct - this is good for - * avoiding false positive tests from bus echoes). - * o an output interrupt is generated and its vector is correct. - * o the interrupt goes away when the IIR in the UART is read. - */ - outb(iobase + com_cfcr, CFCR_8BITS); /* ensure IER is addressed */ - outb(iobase + com_mcr, MCR_IENABLE); /* open gate early */ - outb(iobase + com_ier, 0); /* ensure edge on next intr */ - outb(iobase + com_ier, IER_ETXRDY); /* generate interrupt */ - if ( inb(iobase + com_cfcr) != CFCR_8BITS - || inb(iobase + com_ier) != IER_ETXRDY - || inb(iobase + com_mcr) != MCR_IENABLE - || (inb(iobase + com_iir) & IIR_IMASK) != IIR_TXRDY - || isa_irq_pending(dev) - || (inb(iobase + com_iir) & IIR_IMASK) != IIR_NOPEND) - result = 0; - - /* - * Turn off all device interrupts and check that they go off properly. - * Leave MCR_IENABLE set. It gates the OUT2 output of the UART to - * the ICU input. Closing the gate would give a floating ICU input - * (unless there is another device driving at) and spurious interrupts. - * (On the system that this was first tested on, the input floats high - * and gives a (masked) interrupt as soon as the gate is closed.) - */ - outb(iobase + com_ier, 0); - outb(iobase + com_mcr, MCR_IENABLE); /* dummy to avoid bus echo */ - if ( inb(iobase + com_ier) != 0 - || isa_irq_pending(dev) - || (inb(iobase + com_iir) & IIR_IMASK) != IIR_NOPEND) - result = 0; - - enable_intr(); - - return (result); -} - -static int /* XXX - should be void */ -sioattach(isdp) - struct isa_device *isdp; -{ - struct com_s *com; - static bool_t comwakeup_started = FALSE; - Port_t iobase; - int s; - u_char scr; - u_char scr1; - u_char scr2; - int unit; - - iobase = isdp->id_iobase; - unit = isdp->id_unit; - if (unit == comconsole) - DELAY(1000); /* XXX */ - s = spltty(); - - /* - * sioprobe() has initialized the device registers as follows: - * o cfcr = CFCR_8BITS. - * It is most important that CFCR_DLAB is off, so that the - * data port is not hidden when we enable interrupts. - * o ier = 0. - * Interrupts are only enabled when the line is open. - * o mcr = MCR_IENABLE. - * Keeping MCR_DTR and MCR_RTS off might stop the external - * device from sending before we are ready. - */ - - com = &com_structs[unit]; - com->cfcr_image = CFCR_8BITS; - com->mcr_image = MCR_IENABLE; -#if 0 - com->softDCD = TRUE; -#endif - com->iptr = com->ibuf = com->ibuf1; - com->ibufend = com->ibuf1 + RS_IBUFSIZE; - com->ihighwater = com->ibuf1 + RS_IHIGHWATER; - com->iobase = iobase; - com->data_port = iobase + com_data; - com->int_id_port = iobase + com_iir; - com->modem_ctl_port = iobase + com_mcr; - com->line_status_port = iobase + com_lsr; - com->modem_status_port = iobase + com_msr; - com->tp = &sio_tty[unit]; -#ifdef COM_BIDIR - /* - * if bidirectional ports possible, clear the bidir port info; - */ - com->bidir = FALSE; - com->active = FALSE; - com->active_in = com->active_out = FALSE; -#endif /* COM_BIDIR */ - - /* attempt to determine UART type */ - scr = inb(iobase + com_scr); - outb(iobase + com_scr, 0xa5); - scr1 = inb(iobase + com_scr); - outb(iobase + com_scr, 0x5a); - scr2 = inb(iobase + com_scr); - outb(iobase + com_scr, scr); - printf("sio%d: type", unit); -#ifdef COM_MULTIPORT - if (0); -#else - if (scr1 != 0xa5 || scr2 != 0x5a) - printf(" <8250>"); -#endif - else { - outb(iobase + com_fifo, FIFO_ENABLE | FIFO_TRIGGER_14); - DELAY(100); - switch (inb(iobase + com_iir) & IIR_FIFO_MASK) { - case FIFO_TRIGGER_1: - printf(" <16450>"); - break; - case FIFO_TRIGGER_4: - printf(" <16450?>"); - break; - case FIFO_TRIGGER_8: - printf(" <16550?>"); - break; - case FIFO_TRIGGER_14: - com->hasfifo = TRUE; - printf(" <16550A>"); - break; - } - outb(iobase + com_fifo, 0); - } -#ifdef COM_MULTIPORT - if (COM_ISMULTIPORT(isdp)) { - struct isa_device *masterdev; - - com->multiport = TRUE; - printf(" (multiport)"); - - /* set the master's common-interrupt-enable reg., - * as appropriate. YYY See your manual - */ - /* enable only common interrupt for port */ - outb(iobase + com_mcr, 0); - - masterdev = find_isadev(isa_devtab_tty, &siodriver, - COM_MPMASTER(isdp)); - outb(masterdev->id_iobase+com_scr, 0x80); - } - else - com->multiport = FALSE; -#endif /* COM_MULTIPORT */ - printf("\n"); - -#ifdef KGDB - if (kgdb_dev == makedev(commajor, unit)) { - if (comconsole == unit) - kgdb_dev = -1; /* can't debug over console port */ - else { - cominit(unit, kgdb_rate); - if (kgdb_debug_init) { - /* - * Print prefix of device name, - * let kgdb_connect print the rest. - */ - printf("com%d: ", unit); - kgdb_connect(1); - } - else - printf("com%d: kgdb enabled\n", unit); - } - } -#endif - - /* - * Need to reset baud rate, etc. of next print so reset comconsinit. - * Also make sure console is always "hardwired" - */ - if (unit == comconsole) { - comconsinit = FALSE; - com->softDCD = TRUE; - } - - com_addr(unit) = com; - - splx(s); - - if (!comwakeup_started) { - comwakeup(); - comwakeup_started = TRUE; - } - - return (1); -} - -/* ARGSUSED */ -int -sioopen(dev, flag, mode, p) - dev_t dev; - int flag; - int mode; - struct proc *p; -{ - struct com_s *com; - int error = 0; - Port_t iobase; - int s; - struct tty *tp; - int unit = UNIT(dev); -#ifdef COM_BIDIR - bool_t callout = CALLOUT(dev); -#endif /* COM_BIDIR */ - if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL) - return (ENXIO); -#ifdef COM_BIDIR - /* if it's a callout device, and bidir not possible on that dev, die */ - if (callout && !(com->bidir)) - return (ENXIO); -#endif /* COM_BIDIR */ - - tp = com->tp; - s = spltty(); - -#ifdef COM_BIDIR - -bidir_open_top: - /* if it's bidirectional, we've gotta deal with it... */ - if (com->bidir) { - if (callout) { - if (com->active_in) { - /* it's busy. die */ - splx(s); - return (EBUSY); - } else { - /* it's ours. lock it down, and set it up */ - com->active_out = TRUE; - com->softDCD = TRUE; - } - } else { - if (com->active_out) { - /* it's busy, outgoing. wait, if possible */ - if (flag & O_NONBLOCK) { - /* can't wait; bail */ - splx(s); - return (EBUSY); - } else { - /* wait for it... */ - error = tsleep(&com->active_out, - TTIPRI|PCATCH, - "comoth", - 0); - /* if there was an error, take off. */ - if (error != 0) { - splx(s); - return (error); - } - /* else take it from the top */ - goto bidir_open_top; - } - } else if (com->last_modem_status & MSR_DCD) { - /* there's a carrier on the line; we win */ - com->active_in = TRUE; - com->softDCD = FALSE; - } else { - /* there is no carrier on the line */ - if (flag & O_NONBLOCK) { - /* can't wait; let it open */ - com->active_in = TRUE; - com->softDCD = FALSE; - } else { - /* put DTR & RTS up */ - /* NOTE: cgd'sdriver used the ier register - * to enable/disable interrupts. This one - * uses both ier and IENABLE in the mcr. - */ - (void) commctl(com, MCR_DTR | MCR_RTS, DMSET); - outb(com->iobase + com_ier, IER_EMSC); - /* wait for it... */ - error = tsleep(&com->active_in, - TTIPRI|PCATCH, - "comdcd", - 0); - - /* if not active, turn DTR & RTS off */ - if (!com->active) - (void) commctl(com, MCR_DTR, DMBIC); - - /* if there was an error, take off. */ - if (error != 0) { - splx(s); - return (error); - } - /* else take it from the top */ - goto bidir_open_top; - } - } - } - } - - com->active = TRUE; -#endif /* COM_BIDIR */ - - tp->t_oproc = comstart; - tp->t_param = comparam; - tp->t_dev = dev; - if (!(tp->t_state & TS_ISOPEN)) { - tp->t_state |= TS_WOPEN; - ttychars(tp); - if (tp->t_ispeed == 0) { - /* - * We no longer use the flags from <sys/ttydefaults.h> - * since those are only relevant for logins. It's - * important to have echo off initially so that the - * line doesn't start blathering before the echo flag - * can be turned off. - */ - tp->t_iflag = 0; - tp->t_oflag = 0; - tp->t_cflag = CREAD | CS8 | HUPCL; - tp->t_lflag = 0; - tp->t_ispeed = tp->t_ospeed = comdefaultrate; - } - (void) commctl(com, MCR_DTR | MCR_RTS, DMSET); - error = comparam(tp, &tp->t_termios); - if (error != 0) - goto out; - ttsetwater(tp); - iobase = com->iobase; - disable_intr(); - if (com->hasfifo) - /* (re)enable and drain FIFO */ - outb(iobase + com_fifo, FIFO_ENABLE | FIFO_TRIGGER_14 - | FIFO_RCV_RST | FIFO_XMT_RST); - (void) inb(com->line_status_port); - (void) inb(com->data_port); - com->last_modem_status = - com->prev_modem_status = inb(com->modem_status_port); - outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS - | IER_EMSC); - enable_intr(); - if (com->softDCD || com->prev_modem_status & MSR_DCD) - tp->t_state |= TS_CARR_ON; - } - else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) { - splx(s); - return (EBUSY); - } - while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) -#ifdef COM_BIDIR - /* We went through a lot of trouble to open it, - * but it's certain we have a carrier now, so - * don't spend any time on it now. - */ - && !(com->bidir) -#endif /* COM_BIDIR */ - && !(tp->t_state & TS_CARR_ON)) { - tp->t_state |= TS_WOPEN; - error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, - ttopen, 0); - if (error != 0) - break; - } -out: - splx(s); - if (error == 0) - error = (*linesw[tp->t_line].l_open)(dev, tp); - -#ifdef COM_BIDIR - /* wakeup sleepers */ - wakeup((caddr_t) &com->active_in); -#endif /* COM_BIDIR */ - - /* - * XXX - the next step was once not done, so interrupts, DTR and RTS - * remainded hot if the process was killed while it was sleeping - * waiting for carrier. Now there is the opposite problem. If several - * processes are sleeping waiting for carrier on the same line and one - * is killed, interrupts are turned off so the other processes will - * never see the carrier rise. - */ - if (error != 0 && !(tp->t_state & TS_ISOPEN)) -{ - comhardclose(com); -} - tp->t_state &= ~TS_WOPEN; - - return (error); -} - -/*ARGSUSED*/ -int -sioclose(dev, flag, mode, p) - dev_t dev; - int flag; - int mode; - struct proc *p; -{ - struct com_s *com; - struct tty *tp; - - com = com_addr(UNIT(dev)); - tp = com->tp; - (*linesw[tp->t_line].l_close)(tp, flag); - comhardclose(com); - ttyclose(tp); - return (0); -} - -void -comhardclose(com) - struct com_s *com; -{ - Port_t iobase; - int s; - struct tty *tp; - - s = spltty(); - iobase = com->iobase; - outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); -#ifdef KGDB - /* do not disable interrupts if debugging */ - if (kgdb_dev != makedev(commajor, com - &com_structs[0])) -#endif - outb(iobase + com_ier, 0); - tp = com->tp; - if (tp->t_cflag & HUPCL || tp->t_state & TS_WOPEN - || !(tp->t_state & TS_ISOPEN)) - (void) commctl(com, MCR_RTS, DMSET); -#ifdef COM_BIDIR - com->active = com->active_in = com->active_out = FALSE; - com->softDCD = FALSE; - - /* wakeup sleepers who are waiting for out to finish */ - wakeup((caddr_t) &com->active_out); -#endif /* COM_BIDIR */ - - splx(s); -} - -int -sioread(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; -{ - struct tty *tp = com_addr(UNIT(dev))->tp; - - return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); -} - -int -siowrite(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; -{ - int unit = UNIT(dev); - struct tty *tp = com_addr(unit)->tp; - - /* - * (XXX) We disallow virtual consoles if the physical console is - * a serial port. This is in case there is a display attached that - * is not the console. In that situation we don't need/want the X - * server taking over the console. - */ - if (constty && unit == comconsole) - constty = NULL; - return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); -} - -void -siointr(unit) - int unit; -{ - struct com_s *com; -#ifndef COM_MULTIPORT - u_char line_status; - u_char modem_status; - u_char *ioptr; - u_char recv_data; - - com = com_addr(unit); -#else /* COM_MULTIPORT */ - int i; - bool_t donesomething; - - do { - donesomething = FALSE; - for(i=0;i<NSIO;i++) { - com=com_addr(i); - if(com != NULL) { - /* XXX When siointr is called - * to start output, maybe - * it should be changed to a - * call to comintr1. Doesn't - * seem a good idea: interrupts - * are disabled all the time. - */ -enable_intr(); -disable_intr(); - donesomething = comintr1(com); - } - } - } while (donesomething); - return; -} - -bool_t -comintr1(struct com_s *com) -{ - u_char line_status; - u_char modem_status; - u_char *ioptr; - u_char recv_data; - bool_t donesomething; - - donesomething = FALSE; -#endif /* COM_MULTIPORT */ - - while (TRUE) { - line_status = inb(com->line_status_port); - - /* input event? (check first to help avoid overruns) */ - while (line_status & LSR_RCV_MASK) { - /* break/unnattached error bits or real input? */ -#ifdef COM_MULTIPORT - donesomething = TRUE; -#endif /* COM_MULTIPORT */ - if (!(line_status & LSR_RXRDY)) - recv_data = 0; - else - recv_data = inb(com->data_port); - ++com->bytes_in; -#ifdef KGDB - /* trap into kgdb? (XXX - needs testing and optim) */ - if (recv_data == FRAME_END - && !(com->tp->t_state & TS_ISOPEN) - && kgdb_dev == makedev(commajor, unit)) { - kgdb_connect(0); - continue; - } -#endif /* KGDB */ - ioptr = com->iptr; - if (ioptr >= com->ibufend) - CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW); - else { - ++com_events; - ioptr[0] = recv_data; - ioptr[CE_INPUT_OFFSET] = line_status; - com->iptr = ++ioptr; - if (ioptr == com->ihighwater - && com->state & CS_RTS_IFLOW) - outb(com->modem_ctl_port, - com->mcr_image &= ~MCR_RTS); - } - - /* - * "& 0x7F" is to avoid the gcc-1.40 generating a slow - * jump from the top of the loop to here - */ - line_status = inb(com->line_status_port) & 0x7F; - } - - /* modem status change? (always check before doing output) */ - modem_status = inb(com->modem_status_port); - if (modem_status != com->last_modem_status) { - /* - * Schedule high level to handle DCD changes. Note - * that we don't use the delta bits anywhere. Some - * UARTs mess them up, and it's easy to remember the - * previous bits and calculate the delta. - */ -#ifdef COM_MULTIPORT - donesomething = TRUE; -#endif /* COM_MULTIPORT */ - com->last_modem_status = modem_status; - if (!(com->state & CS_CHECKMSR)) { - com_events += LOTS_OF_EVENTS; - com->state |= CS_CHECKMSR; - schedsoftcom(); - } - - /* handle CTS change immediately for crisp flow ctl */ - if (com->state & CS_CTS_OFLOW) { - if (modem_status & MSR_CTS) - com->state |= CS_ODEVREADY; - else - com->state &= ~CS_ODEVREADY; - } - } - - /* output queued and everything ready? */ - if (line_status & LSR_TXRDY - && com->state >= (CS_ODEVREADY | CS_BUSY | CS_TTGO)) { -#ifdef COM_MULTIPORT - donesomething = TRUE; -#endif /* COM_MULTIPORT */ - ioptr = com->optr; - outb(com->data_port, *ioptr); - ++com->bytes_out; - com->optr = ++ioptr; - if (ioptr >= com->obufend) { - /* output just completed */ - com_events += LOTS_OF_EVENTS; - com->state ^= (CS_ODONE | CS_BUSY); - schedsoftcom(); /* handle at high level ASAP */ - } - } - - /* finished? */ - if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND) -#ifdef COM_MULTIPORT - return (donesomething); -#else - return; -#endif /* COM_MULTIPORT */ - } -} - -static int -tiocm2mcr(data) - int data; -{ - register m = 0; - if (data & TIOCM_DTR) m |= MCR_DTR; - if (data & TIOCM_RTS) m |= MCR_RTS; - return m; -} -int -sioioctl(dev, cmd, data, flag, p) - dev_t dev; - int cmd; - caddr_t data; - int flag; - struct proc *p; -{ - struct com_s *com; - int error; - Port_t iobase; - int s; - struct tty *tp; - - com = com_addr(UNIT(dev)); - tp = com->tp; - error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); - if (error >= 0) - return (error); - error = ttioctl(tp, cmd, data, flag); - if (error >= 0) - return (error); - - iobase = com->iobase; - s = spltty(); - switch (cmd) { - case TIOCSBRK: - outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK); - break; - case TIOCCBRK: - outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); - break; - case TIOCSDTR: - (void) commctl(com, MCR_DTR, DMBIS); - break; - case TIOCCDTR: - (void) commctl(com, MCR_DTR, DMBIC); - break; - case TIOCMSET: - (void) commctl(com, tiocm2mcr(*(int *)data), DMSET); - break; - case TIOCMBIS: - (void) commctl(com, tiocm2mcr(*(int *)data), DMBIS); - break; - case TIOCMBIC: - (void) commctl(com, tiocm2mcr(*(int *)data), DMBIC); - break; - case TIOCMGET: - { - register int bits = 0, mode; - - mode = commctl(com, 0, DMGET); - if (inb(com->iobase+com_ier)) bits |= TIOCM_LE; /* XXX */ - if (mode & MSR_DCD) bits |= TIOCM_CD; - if (mode & MSR_CTS) bits |= TIOCM_CTS; - if (mode & MSR_DSR) bits |= TIOCM_DSR; - if (mode & (MCR_DTR<<8)) bits |= TIOCM_DTR; - if (mode & (MCR_RTS<<8)) bits |= TIOCM_RTS; - if (mode & (MSR_RI|MSR_TERI)) bits |= TIOCM_RI; - *(int *)data = bits; - } - break; -#ifdef COM_BIDIR - case TIOCMSBIDIR: - /* must be root to set bidir. capability */ - if (p->p_ucred->cr_uid != 0) - return(EPERM); - - /* if it's the console, can't do it */ - if (UNIT(dev) == comconsole) - return(ENOTTY); - - /* can't do the next, for obvious reasons... - * but there are problems to be looked at... - */ - - /* if the port is active, don't do it */ - /* if (com->active) - return(EBUSY); */ - - com->bidir = *(int *)data; - break; - case TIOCMGBIDIR: - *(int *)data = com->bidir; - break; -#endif /* COM_BIDIR */ - default: - splx(s); - return (ENOTTY); - } - splx(s); - return (0); -} - -/* cancel pending output */ -static void -comflush(com) - struct com_s *com; -{ - struct ringb *rbp; - - disable_intr(); - if (com->state & CS_ODONE) - com_events -= LOTS_OF_EVENTS; - com->state &= ~(CS_ODONE | CS_BUSY); - enable_intr(); - rbp = &com->tp->t_out; - rbp->rb_hd += com->ocount; - rbp->rb_hd = RB_ROLLOVER(rbp, rbp->rb_hd); - com->ocount = 0; - com->tp->t_state &= ~TS_BUSY; -} - -static void -compoll() -{ - static bool_t awake = FALSE; - struct com_s *com; - int s; - int unit; - - if (com_events == 0) - return; - disable_intr(); - if (awake) { - enable_intr(); - return; - } - awake = TRUE; - enable_intr(); - s = spltty(); -repeat: - for (unit = 0; unit < NSIO; ++unit) { - u_char *buf; - u_char *ibuf; - int incc; - struct tty *tp; - - com = com_addr(unit); - if (com == NULL) - continue; - tp = com->tp; - - /* switch the role of the low-level input buffers */ - if (com->iptr == (ibuf = com->ibuf)) - incc = 0; - else { - buf = ibuf; - disable_intr(); - incc = com->iptr - buf; - com_events -= incc; - if (ibuf == com->ibuf1) - ibuf = com->ibuf2; - else - ibuf = com->ibuf1; - com->ibufend = ibuf + RS_IBUFSIZE; - com->ihighwater = ibuf + RS_IHIGHWATER; - com->iptr = ibuf; - - /* - * There is now room for another low-level buffer full - * of input, so enable RTS if it is now disabled and - * there is room in the high-level buffer. - */ - if (!(com->mcr_image & MCR_RTS) - && !(tp->t_state & TS_RTSBLOCK)) - outb(com->modem_ctl_port, - com->mcr_image |= MCR_RTS); - enable_intr(); - com->ibuf = ibuf; - } - - if (com->state & CS_CHECKMSR) { - u_char delta_modem_status; - - disable_intr(); - delta_modem_status = com->last_modem_status - ^ com->prev_modem_status; - com->prev_modem_status = com->last_modem_status; - com_events -= LOTS_OF_EVENTS; - com->state &= ~CS_CHECKMSR; - enable_intr(); - if (delta_modem_status & MSR_DCD && - unit != comconsole) { -#ifdef COM_BIDIR - if (com->prev_modem_status & MSR_DCD) { - (*linesw[tp->t_line].l_modem)(tp, 1); - com->softDCD = FALSE; - wakeup((caddr_t) &com->active_in); - } -#else - if (com->prev_modem_status & MSR_DCD) - (*linesw[tp->t_line].l_modem)(tp, 1); -#endif /* COM_BIDIR */ - else if ((*linesw[tp->t_line].l_modem)(tp, 0) - == 0) { - disable_intr(); - outb(com->modem_ctl_port, - com->mcr_image - &= ~MCR_DTR); - enable_intr(); - } - } - } - - /* XXX */ - if (TRUE) { - u_int delta; - u_int delta_error_counts[CE_NTYPES]; - int errnum; - u_long total; - - disable_intr(); - bcopy(com->delta_error_counts, delta_error_counts, - sizeof delta_error_counts); - bzero(com->delta_error_counts, - sizeof delta_error_counts); - enable_intr(); - for (errnum = 0; errnum < CE_NTYPES; ++errnum) { - delta = delta_error_counts[errnum]; - if (delta != 0) { - total = - com->error_counts[errnum] += delta; - log(LOG_WARNING, - "com%d: %u more %s%s (total %lu)\n", - unit, delta, error_desc[errnum], - delta == 1 ? "" : "s", total); - } - } - } - if (com->state & CS_ODONE) { - comflush(com); - /* XXX - why isn't the table used for t_line == 0? */ - if (tp->t_line != 0) - (*linesw[tp->t_line].l_start)(tp); - else - comstart(tp); - } - if (incc <= 0 || !(tp->t_state & TS_ISOPEN)) - continue; - if (com->state & CS_RTS_IFLOW - && RB_LEN(&tp->t_raw) + incc >= RB_I_HIGH_WATER - && !(tp->t_state & TS_RTSBLOCK) - /* - * XXX - need RTS flow control for all line disciplines. - * Only have it in standard one now. - */ - && linesw[tp->t_line].l_rint == ttyinput) { - tp->t_state |= TS_RTSBLOCK; - ttstart(tp); - } - /* - * Avoid the grotesquely inefficient lineswitch routine - * (ttyinput) in "raw" mode. It usually takes about 450 - * instructions (that's without canonical processing or echo!). - * slinput is reasonably fast (usually 40 instructions plus - * call overhead). - */ - if (!(tp->t_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP - | IXOFF | IXON)) - && !(tp->t_lflag & (ECHO | ECHONL | ICANON | IEXTEN | ISIG - | PENDIN)) - && !(tp->t_state & (TS_CNTTB | TS_LNCH)) - && linesw[tp->t_line].l_rint == ttyinput) { - tk_nin += incc; - tk_rawcc += incc; - tp->t_rawcc += incc; - com->delta_error_counts[CE_TTY_BUF_OVERFLOW] - += incc - rb_write(&tp->t_raw, (char *) buf, - incc); - ttwakeup(tp); - if (tp->t_state & TS_TTSTOP - && (tp->t_iflag & IXANY - || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) { - tp->t_state &= ~TS_TTSTOP; - tp->t_lflag &= ~FLUSHO; - ttstart(tp); - } - } - else { - do { - u_char line_status; - int recv_data; - - line_status = (u_char) buf[CE_INPUT_OFFSET]; - recv_data = (u_char) *buf++; - if (line_status - & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) { - if (line_status & LSR_BI) - recv_data |= TTY_BI; - if (line_status & LSR_FE) - recv_data |= TTY_FE; - if (line_status & LSR_OE) - recv_data |= TTY_OE; - if (line_status & LSR_PE) - recv_data |= TTY_PE; - } - (*linesw[tp->t_line].l_rint)(recv_data, tp); - } while (--incc > 0); - } - if (com_events == 0) - break; - } - if (com_events >= LOTS_OF_EVENTS) - goto repeat; - splx(s); - awake = FALSE; -} - -static int -comparam(tp, t) - struct tty *tp; - struct termios *t; -{ - u_int cfcr; - int cflag; - struct com_s *com; - int divisor; - int error; - Port_t iobase; - int s; - int unit; - - /* check requested parameters */ - divisor = ttspeedtab(t->c_ospeed, comspeedtab); - if (divisor < 0 || t->c_ispeed != 0 && t->c_ispeed != t->c_ospeed) - return (EINVAL); - - /* parameters are OK, convert them to the com struct and the device */ - unit = UNIT(tp->t_dev); - com = com_addr(unit); - iobase = com->iobase; - s = spltty(); - if (divisor == 0) { - (void) commctl(com, MCR_RTS, DMSET); /* hang up line */ - splx(s); - return (0); - } - cflag = t->c_cflag; - switch (cflag & CSIZE) { - case CS5: - cfcr = CFCR_5BITS; - break; - case CS6: - cfcr = CFCR_6BITS; - break; - case CS7: - cfcr = CFCR_7BITS; - break; - default: - cfcr = CFCR_8BITS; - break; - } - if (cflag & PARENB) { - cfcr |= CFCR_PENAB; - if (!(cflag & PARODD)) - cfcr |= CFCR_PEVEN; - } - if (cflag & CSTOPB) - cfcr |= CFCR_STOPB; - - /* - * Some UARTs lock up if the divisor latch registers are selected - * while the UART is doing output (they refuse to transmit anything - * more until given a hard reset). Fix this by stopping filling - * the device buffers and waiting for them to drain. Reading the - * line status port outside of siointr() might lose some receiver - * error bits, but that is acceptable here. - */ - disable_intr(); - com->state &= ~CS_TTGO; - enable_intr(); - while ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY)) - != (LSR_TSRE | LSR_TXRDY)) { - error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, - "comparam", 1); - if (error != 0 && error != EAGAIN) { - if (!(tp->t_state & TS_TTSTOP)) { - disable_intr(); - com->state |= CS_TTGO; - enable_intr(); - } - splx(s); - return (error); - } - } - - disable_intr(); /* very important while com_data is hidden */ - outb(iobase + com_cfcr, cfcr | CFCR_DLAB); - outb(iobase + com_dlbl, divisor & 0xFF); - outb(iobase + com_dlbh, (u_int) divisor >> 8); - outb(iobase + com_cfcr, com->cfcr_image = cfcr); - if (!(tp->t_state & TS_TTSTOP)) - com->state |= CS_TTGO; - if (cflag & CRTS_IFLOW) - com->state |= CS_RTS_IFLOW; /* XXX - secondary changes? */ - else - com->state &= ~CS_RTS_IFLOW; - - /* - * Set up state to handle output flow control. - * XXX - worth handling MDMBUF (DCD) flow control at the lowest level? - * Now has 16+ msec latency, while CTS flow has 50- usec latency. - * Note that DCD flow control stupidly uses the same state flag - * (TS_TTSTOP) as XON/XOFF flow control. - */ - com->state &= ~CS_CTS_OFLOW; - com->state |= CS_ODEVREADY; - if (cflag & CCTS_OFLOW) { - com->state |= CS_CTS_OFLOW; - if (!(com->prev_modem_status & MSR_CTS)) - com->state &= ~CS_ODEVREADY; - } - - enable_intr(); - siointr(unit); /* recover from fiddling with CS_TTGO */ - splx(s); - return (0); -} - -static int /* XXX - should be void */ -comstart(tp) - struct tty *tp; -{ - struct com_s *com; - int s; - int unit; - - unit = UNIT(tp->t_dev); - com = com_addr(unit); - s = spltty(); - disable_intr(); - if (tp->t_state & TS_TTSTOP) - com->state &= ~CS_TTGO; - else - com->state |= CS_TTGO; - if (tp->t_state & TS_RTSBLOCK) { - if (com->mcr_image & MCR_RTS && com->state & CS_RTS_IFLOW) - outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS); - } - else { - if (!(com->mcr_image & MCR_RTS) && com->iptr < com->ihighwater) { - tp->t_state &= ~TS_RTSBLOCK; - outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); - } - } - enable_intr(); - if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) - goto out; - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { - if (tp->t_state & TS_ASLEEP) { - tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); - } - if (tp->t_wsel) { - selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); - tp->t_wsel = 0; - tp->t_state &= ~TS_WCOLL; - } - } - if (com->ocount != 0) { - disable_intr(); - siointr(unit); - enable_intr(); - } - else if (RB_LEN(&tp->t_out) != 0) { - tp->t_state |= TS_BUSY; - com->ocount = RB_CONTIGGET(&tp->t_out); - disable_intr(); - com->obufend = (com->optr = (u_char *) tp->t_out.rb_hd) - + com->ocount; - com->state |= CS_BUSY; - siointr(unit); /* fake interrupt to start output */ - enable_intr(); - } -out: - splx(s); - return (1); -} - -void -siostop(tp, rw) - struct tty *tp; - int rw; -{ - struct com_s *com; - - com = com_addr(UNIT(tp->t_dev)); - if (rw & FWRITE) - comflush(com); - disable_intr(); - if (tp->t_state & TS_TTSTOP) - com->state &= ~CS_TTGO; - else - com->state |= CS_TTGO; - enable_intr(); -} - -static int -commctl(com, bits, how) - struct com_s *com; - int bits; - int how; -{ - disable_intr(); - switch (how) { - case DMSET: -#ifdef COM_MULTIPORT - /* YYY maybe your card doesn't want IENABLE to be reset? */ - if(com->multiport) - outb(com->modem_ctl_port, - com->mcr_image = bits); - else -#endif /* COM_MULTIPORT */ - outb(com->modem_ctl_port, - com->mcr_image = bits | MCR_IENABLE); - break; - case DMBIS: - outb(com->modem_ctl_port, com->mcr_image |= bits); - break; - case DMBIC: -#ifdef COM_MULTIPORT - /* YYY maybe your card doesn't want IENABLE to be reset? */ - if(com->multiport) - outb(com->modem_ctl_port, - com->mcr_image &= ~(bits)); - else -#endif /* COM_MULTIPORT */ - outb(com->modem_ctl_port, - com->mcr_image &= ~(bits & ~MCR_IENABLE)); - break; - case DMGET: - bits = com->prev_modem_status | (com->mcr_image << 8); - break; - } - enable_intr(); - return (bits); -} - -static void -comwakeup() -{ - struct com_s *com; - int unit; - - timeout((timeout_func_t) comwakeup, (caddr_t) NULL, 1); - if (com_events != 0) - /* schedule compoll() to run when the cpl allows */ - schedsoftcom(); - - /* recover from lost output interrupts */ - for (unit = 0; unit < NSIO; ++unit) { - com = com_addr(unit); - if (com != NULL && com->state >= (CS_BUSY | CS_TTGO)) { - disable_intr(); - siointr(unit); - enable_intr(); - } - } -} - -void -softsio0() { compoll(); } - -void -softsio1() { compoll(); } - -void -softsio2() { compoll(); } - -void -softsio3() { compoll(); } - -void -softsio4() { compoll(); } - -void -softsio5() { compoll(); } - -void -softsio6() { compoll(); } - -void -softsio7() { compoll(); } - -void -softsio8() { compoll(); } - -/* - * Following are all routines needed for COM to act as console - * XXX - not tested in this version - * XXX - check that the corresponding serial interrupts are never enabled - */ -#include "i386/i386/cons.h" - -void -siocnprobe(cp) - struct consdev *cp; -{ - int unit; - - /* locate the major number */ - for (commajor = 0; commajor < nchrdev; commajor++) - if (cdevsw[commajor].d_open == (bogus_open_t) sioopen) - break; - - /* XXX: ick */ - unit = CONUNIT; - com_addr(unit) = &com_structs[unit]; - com_addr(unit)->iobase = CONADDR; - - /* make sure hardware exists? XXX */ - - /* initialize required fields */ - cp->cn_dev = makedev(commajor, unit); - cp->cn_tp = &sio_tty[unit]; -#ifdef COMCONSOLE - cp->cn_pri = CN_REMOTE; /* Force a serial port console */ -#else - cp->cn_pri = CN_NORMAL; -#endif -} - -void -siocninit(cp) - struct consdev *cp; -{ - int unit; - - unit = UNIT(cp->cn_dev); - cominit(unit, comdefaultrate); - comconsole = unit; - comconsinit = TRUE; -} - -static void -cominit(unit, rate) - int unit; - int rate; -{ - Port_t iobase; - int s; - - iobase = com_addr(unit)->iobase; - s = splhigh(); - outb(iobase + com_cfcr, CFCR_DLAB); - rate = ttspeedtab(comdefaultrate, comspeedtab); - outb(iobase + com_data, rate & 0xFF); - outb(iobase + com_ier, rate >> 8); - outb(iobase + com_cfcr, CFCR_8BITS); - - /* - * XXX - fishy to enable interrupts and then poll. - * It shouldn't be necessary to ready the iir. - */ - outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); - outb(iobase + com_fifo, - FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14); - (void) inb(iobase + com_iir); - splx(s); -} - -int -siocngetc(dev) - dev_t dev; -{ - int c; - Port_t iobase; - int s; - - iobase = com_addr(UNIT(dev))->iobase; - s = splhigh(); - while (!(inb(iobase + com_lsr) & LSR_RXRDY)) - ; - c = inb(iobase + com_data); - (void) inb(iobase + com_iir); - splx(s); - return (c); -} - -void -siocnputc(dev, c) - dev_t dev; - int c; -{ - Port_t iobase; - int s; - int timo; - - iobase = com_addr(UNIT(dev))->iobase; - s = splhigh(); -#ifdef KGDB - if (dev != kgdb_dev) -#endif - if (!comconsinit) { - (void) cominit(UNIT(dev), comdefaultrate); - comconsinit = TRUE; - } - /* wait for any pending transmission to finish */ - timo = 50000; - while (!(inb(iobase + com_lsr) & LSR_TXRDY) && --timo) - ; - outb(iobase + com_data, c); - /* wait for this transmission to complete */ - timo = 1500000; - while (!(inb(iobase + com_lsr) & LSR_TXRDY) && --timo) - ; - /* clear any interrupts generated by this transmission */ - (void) inb(iobase + com_iir); - splx(s); -} - -/* - * 10 Feb 93 Jordan K. Hubbard Added select code - * 27 May 93 Rodney W. Grimes Stole the select code from com.c.pl5 - */ - -int -sioselect(dev, rw, p) - dev_t dev; - int rw; - struct proc *p; -{ - register struct tty *tp = &sio_tty[UNIT(dev)]; - int nread; - int s = spltty(); - struct proc *selp; - - switch (rw) { - - case FREAD: - nread = ttnread(tp); - if (nread > 0 || - ((tp->t_cflag&CLOCAL) == 0 && (tp->t_state&TS_CARR_ON) == 0)) - goto win; - if (tp->t_rsel && (selp = pfind(tp->t_rsel)) && selp->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_RCOLL; - else - tp->t_rsel = p->p_pid; - break; - - case FWRITE: - if (RB_LEN(&tp->t_out) <= tp->t_lowat) - goto win; - if (tp->t_wsel && (selp = pfind(tp->t_wsel)) && selp->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_WCOLL; - else - tp->t_wsel = p->p_pid; - break; - } - splx(s); - return (0); - win: - splx(s); - return (1); -} - -#endif /* NSIO > 0 */ diff --git a/sys/i386/isa/sioreg.h b/sys/i386/isa/sioreg.h deleted file mode 100644 index 4b0f1b6..0000000 --- a/sys/i386/isa/sioreg.h +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)comreg.h 7.2 (Berkeley) 5/9/91 - * $Id$ - */ - - -/* 16 bit baud rate divisor (lower byte in dca_data, upper in dca_ier) */ -#define COMBRD(x) (1843200 / (16*(x))) - -/* interrupt enable register */ -#define IER_ERXRDY 0x1 -#define IER_ETXRDY 0x2 -#define IER_ERLS 0x4 -#define IER_EMSC 0x8 - -/* interrupt identification register */ -#define IIR_IMASK 0xf -#define IIR_RXTOUT 0xc -#define IIR_RLS 0x6 -#define IIR_RXRDY 0x4 -#define IIR_TXRDY 0x2 -#define IIR_NOPEND 0x1 -#define IIR_MLSC 0x0 -#define IIR_FIFO_MASK 0xc0 /* set if FIFOs are enabled */ - -/* fifo control register */ -#define FIFO_ENABLE 0x01 -#define FIFO_RCV_RST 0x02 -#define FIFO_XMT_RST 0x04 -#define FIFO_DMA_MODE 0x08 -#define FIFO_TRIGGER_1 0x00 -#define FIFO_TRIGGER_4 0x40 -#define FIFO_TRIGGER_8 0x80 -#define FIFO_TRIGGER_14 0xc0 - -/* character format control register */ -#define CFCR_DLAB 0x80 -#define CFCR_SBREAK 0x40 -#define CFCR_PZERO 0x30 -#define CFCR_PONE 0x20 -#define CFCR_PEVEN 0x10 -#define CFCR_PODD 0x00 -#define CFCR_PENAB 0x08 -#define CFCR_STOPB 0x04 -#define CFCR_8BITS 0x03 -#define CFCR_7BITS 0x02 -#define CFCR_6BITS 0x01 -#define CFCR_5BITS 0x00 - -/* modem control register */ -#define MCR_LOOPBACK 0x10 -#define MCR_IENABLE 0x08 -#define MCR_DRS 0x04 -#define MCR_RTS 0x02 -#define MCR_DTR 0x01 - -/* line status register */ -#define LSR_RCV_FIFO 0x80 -#define LSR_TSRE 0x40 -#define LSR_TXRDY 0x20 -#define LSR_BI 0x10 -#define LSR_FE 0x08 -#define LSR_PE 0x04 -#define LSR_OE 0x02 -#define LSR_RXRDY 0x01 -#define LSR_RCV_MASK 0x1f - -/* modem status register */ -#define MSR_DCD 0x80 -#define MSR_RI 0x40 -#define MSR_DSR 0x20 -#define MSR_CTS 0x10 -#define MSR_DDCD 0x08 -#define MSR_TERI 0x04 -#define MSR_DDSR 0x02 -#define MSR_DCTS 0x01 - -/* - * WARNING: Serial console is assumed to be at COM1 address - * and CONUNIT must be 0. - */ -#define CONADDR (0x3f8) -#define CONUNIT (0) diff --git a/sys/i386/isa/sound/CHANGELOG b/sys/i386/isa/sound/CHANGELOG new file mode 100644 index 0000000..78168dd --- /dev/null +++ b/sys/i386/isa/sound/CHANGELOG @@ -0,0 +1,55 @@ +Changelog for version 2.4 +------------------------- + +Since 2.3b +- Fixed bug which made it impossible to make long recordings to disk. + Recording was not restarted after a buffer overflow situation. +- Limited mixer support for GUS. +- Numerous improvements to the GUS driver by Andrew Robinson. Including + some click removal etc. + +Since 2.3 +- Fixed some minor bugs in the SB16 driver. + +Since 2.2b +- Full SB16 DSP support. 8/16 bit, mono/stereo +- The SCO and FreeBSD versions should be in sync now. There are some + problems with SB16 and GUS in the freebsd versions. + The DMA buffer allocation of the SCO version has been polished but + there could still be some problems. At least it hogs memory. + The DMA channel + configuration method used in the sco/System is a hack. +- Support for the MPU emulation of the SB16. +- Some big arrays are now allocated boot time. This makes the bss segment + smaller which makes it possible to use the full driver with + NetBSD. These arrays are not allocated if no suitable soundcard is available. +- Fixed a bug in the compute_and_set_volume in gus_wave.c +- Fixed the too fast mono playback problem of SB Pro and PAS16. + +Since 2.2 +- Stereo recording for SB Pro. Somehow it was missing and nobody + had noticed it earlier. +- Minor polishing. +- Interpreting of boot time arguments (sound=) for Linux. +- Breakup of sb_dsp.c. Parts of the code has been moved to + sb_mixer.c and sb_midi.c + +Since 2.1 +- Preliminary support for SB16. + - The SB16 mixer is supported in it's native mode. + - Digitized voice capability up to 44.1 kHz/8 bit/mono + (16 bit and stereo support coming in the next release). +- Fixed some bugs in the digitized voice driver for PAS16. +- Proper initialization of the SB emulation of latest PAS16 models. + +- Significantly improved /dev/dsp and /dev/audio support. + - Now supports half duplex mode. It's now possible to record and + playback without closing and reopening the device. + - It's possible to use smaller buffers than earlier. There is a new + ioctl(fd, SNDCTL_DSP_SUBDIVIDE, &n) where n should be 1, 2 or 4. + This call instructs the driver to use smaller buffers. The default + buffer size (0.5 to 1.0 seconds) is divided by n. Should be called + immediately after opening the device. + +Since 2.0 +Just cosmetic changes. diff --git a/sys/i386/isa/sound/HOWTO_MIDI b/sys/i386/isa/sound/HOWTO_MIDI deleted file mode 100644 index f0601e5..0000000 --- a/sys/i386/isa/sound/HOWTO_MIDI +++ /dev/null @@ -1,51 +0,0 @@ -The following file describes the procedure for adding modules to MIDI -Please READ the main documentation files for the driver first!!! - - - Example: We have a sound card with a MIDI chip & port on it - and, we call it the 'MYBLASTER' card: - - ************************************************************************** - - 0: Run 'configure'. Select the MIDI on CHIP support option. - - 1: Write a midi driver module; 'blast_midi.c' - (with functions for open,close,read,write,attach.) - - 1a: Write all functions except the 'attach' the way you want. - - For the 'attach' function, look at a model in the 'pro_midi.c' - file. Just dup it in the same fashion. For the 'generic_midi_operations' - structure which is required, see file 'dev_table.h'. - - 2: We called the 'attach' function: 'blast_attach'. - - Go to the file 'dev_table.h' and add your driver name and the function - pointer ( which is 'blast_attach' ) to the 'midi_supported' table. - - 3: You are almost set. Go and make a reference - to an 'exclude constant'; say EXLCUDE_BLAST_MIDI in your module - (refer to the 'pro_midi.c' file for model). Also make sure to - add the constant to the file 'sound_config.h' (for example, look - where the constant EXCLUDE_PRO_MIDI is in the file.) - - 4: Add the line - - #define ALL_EXTERNAL_TO_ME - - as the 1st line of your 'blast_midi.c' file. This happily, makes - you ignorant of everything else specific to the driver! :). - - 4a: And of course, don't forget to make a device :). Note that your - minor number should be = ( 15 + position of your driver in the - 'midi_supported' table in the 'dev_table.h' file ). - - Eg: Your driver is the second one in the table. viz midi_supported[1]. - Your device minor number should be ( 15 + 1 = 16 ). Then, make the - reference to your device as, say CMIDI_DEV_BLAST in the file - 'sound_config.h'. Also add this in 'soundcard.c' for the open, read, - write and close routines. See files for example using CMIDI_DEV_PRO - (which is the ProAudioSpectrum on chip MIDI). - - 5: You are all set. If ever you have problems, follow the same model - as the file 'pro_midi.c', except for substituting your own functions! diff --git a/sys/i386/isa/sound/RELNOTES b/sys/i386/isa/sound/RELNOTES deleted file mode 100644 index 03d492d..0000000 --- a/sys/i386/isa/sound/RELNOTES +++ /dev/null @@ -1,38 +0,0 @@ -Welcome to use the Linux sound driver for FreeBSD. This -driver supports the SoundBlaster, SB Pro, Pro Audio Spectrum 16, -AdLib and Gravis UltraSound sound cards. - -In addition there is rather limited support for MPU-401 -(and compatible) midi cards. Also, the OPL-3 synthesizer -of the SB Pro and PAS16 cards is now supported in the 4 OP -modes. - -Most of the features of the /dev/sequencer device file are -available just for GUS owners. - -The SoundBlaster 16 and SB 16 ASP cards are not supported, -though they may work in mono mode with speeds < 22 kHz. -The OPL-3 chicp of the SB 16 should work (without problems?). -Is there anybody willing to implement the SB 16 support -(have the SB 16 and the SDK for it)? - -Since this driver is a sound driver, it does not contain support -for SCSI/CD-ROM/Joystick -devices. - -Known bugs ----------- - -- It's not possible to open /dev/dsp (or /dev/audio) while the - /dev/sequencer is open for output and GUS is the only soundcard - installed. It's possible if /dev/dsp is opened before /dev/sequencer - but at this time the GUS is not available for access via /dev/sequencer. - This is a limitation of the driver. -- MPU-401 driver hangs the computer on boot if there is no MPU-401 installed. - It uses by default the I/O port 0x330, which is also used by the - Adaptec 1542 SCSI adapter. -- The /dev/sequencer playback to GUS sounds sometimes rather weird. Hitting - ^C and playing again should solve this problem. This is probably caused by - incompatibilities between the GUS and certain VLB motherboards. Try to avoid - switching between VTs while patches are being loaded to the GUS. -- There is a skeleton of the patch manager support. It doesn't work in - this version. diff --git a/sys/i386/isa/sound/RELNOTES.Linux b/sys/i386/isa/sound/RELNOTES.Linux deleted file mode 100644 index 4082f4e..0000000 --- a/sys/i386/isa/sound/RELNOTES.Linux +++ /dev/null @@ -1,191 +0,0 @@ -Release notes for the Linux Sound Driver 1.99.9 ------------------------------------------------ - -******** THIS IS A BETA TEST RELEASE ******** -which means that there can be some untested things. In theory -there is a risk that this driver causes some trouble to your system. -You should not use this driver before backing up your disks. - - - - -Welcome to use the Gravis UltraSound driver for Linux. This -driver still supports the same cards than version 1.0c -(SoundBlaster, SB Pro, Pro Audio Spectrum 16 and AdLib). -In addition there is rather limited support for MPU-401 -(and compatible) midi cards. Also the OPL-3 synthesizer -of the SB Pro and PAS16 cards is now supported in the 4 OP -modes. -Most of the features of the /dev/sequencer device file are -available just for GUS owners. - -The SoundBlaster 16 and SB 16 ASP cards are not supported. -They could work in mono mode with speeds < 22 kHz. -The OPL-3 chicp of the SB 16 should work (without problems?). -Is there anybody willing to implement the SB 16 support -(have the SB 16 and the SDK for it)? - - -This is the first version of the driver which has almost -all of the features which I have planned to include into -version 2.0. Some features are still missing and some ones -doesn't work. - -NOTE! There are separate driver for CD-ROMS supported by - some soundcards. The driver for CDU31A (Fusion 16) is - called cdu31a-0.6.diff.z. It will be contained in the - Linux version 0.99.12. The driver for the CD-ROM of SB Pro - is sbpcd0.4.tar.gz (these were the latest versions when I wrote - this). These files should be at least at sunsite.unc.edu. - As far as I know, there is no driver for the SCSI interface of PAS16 - (yet). - - There is also a driver for joystick. Look for file joystick-0.5.tar.gz - (sunsite). - - Since this driver is a sound driver, it will not contain support - for SCSI/CD-ROM/Joystick -devices. - -Compatibility with the earlier versions ---------------------------------------- - -This is just like the version 1.99.7/1.99.8. There is just some minor -enhancements. Most of them are portability fixes. If you are porting -this driver to any OS, please look at the 386bsd/os.h. There is some -new macros and some macros have more parameters. In addition this file -contains some usefull comments. - -**** There is some ISC and 386bsd stuff in this driver. Please stay away **** -This stuff is here just because I want to be in sync with the porters. These -ports don't work yet. - -The ioctl() interface has changed completely since version 1.0c. All -programs using this driver must be at least recompiled. -The snd-util-1.99.6 package contains some utilities for this version. - -The version 1.0c and earlier used a 'nonportable' ioctl calling scheme -where the input argument was passed by value and the output value was -returned as the functional return. For example setting the speed of -/dev/dsp were done as the following: - - int actual_speed; - actual_speed = ioctl(fd, SOUND_PCM_WRITE_RATE, 44100); - -After version 1.99.0 this must be done as the following: - - int actual_speed = 44100; - ioctl(fd, SOUND_PCM_WRITE_RATE, &actual_speed); - -If you have an application written for the version 1.0, you should search -for the strings SNDCTL_ and SOUND_ and to check the parameters. - -Since the this version will support more than one synthesizer devices -at the same time, the ioctl(SNDCTL_FM_LOAD_INSTR) is obsolete. In addition -there is some new fields which must be initialized. Look at the sbiset.c in -the snd-util-1.99.6 package for further info. - -The GUS patch format has changed since the version 1.99.3. You have to -use latest versions of the programs in the sound/gustest directory. In -addition the version 0.4g of the Adagio package supports this format. - -New features ------------- - -There is also some changes which make this version more usable than -the version 1.0c. - -- /dev/dsp and /dev/audio - -The DMA buffering is now little bit more intelligent than earlier. The -buffer size is selected run-time so that a buffer holds data for 0.5 to -1.0 seconds of recording or playback. This makes recording more comfortable -than with version 1.0. With the previous version there was sometimes more -than 10 seconds of delay before the driver returned the first input byte. - -There is also support for more than one digitized voice devices. The device -files /dev/dsp1 and /dev/audio1 (minor 19 and 20) are available with PAS16. -The /dev/dsp (/dev/audio) is connected to the PCM circuit of the PAS16 itself -and the /dev/dsp1 (/dev/audio1) to the SB emulation of PAS16 card. Two -dsp/audio devices are available also if you have combination of SB and GUS. -With GUS and PAS16 you will have even three dsp/audio devices. These devices -can be used independently and can be active at the same time (3 channels -at the same time propably don't work). - -The dsp/audio support of PAS16 should be much cleaner now since the -constant clicking sound between the DMA blocks (about once per second) has -been eliminated. - -The stereo playback of GUS doesn't work perfectly. There is lot of -clicking in the output. - -- /dev/mixer - -No changes. - -There is no mixer for the GUS yet. - -- /dev/sequencer - -This part has the most changes. Mostly to support the rich -features of the Gravis UltraSound. There is also the support -for the OPL-3 synthesizer chip. - -- /dev/sndstat - -This is a new devicefile for debugging purposes. A better place for -it is in the /proc -directory but I was just too lazy to implement it -properly. The /dev/sndstat (major 14, minor 6) is a file which returns -info about the current configuration (see the example below). If you -send me a error/problem report, please include a printout from this -device to your message (cat /dev/sndstat). - ------- cut here --- cat /dev/sndstat example -------- -Sound Driver:1.99.7 (Fri Jul 9 17:01:47 GMT 1993 root@lucifer.savolai.fi) -Config options: 0x00000d4b - -Major number: 14 -HW config: -Type 4: Gravis Ultrasound at 0x210 irq 15 drq 6 -Type 3: ProAudioSpectrum at 0x388 irq 10 drq 3 -Type 2: SoundBlaster at 0x220 irq 7 drq 1 -Type 1: AdLib at 0x388 irq 0 drq 0 - -PCM devices: -00: Gravis UltraSound -01: Pro Audio Spectrum -02: SoundBlaster 2.0 - -Synth devices: -00: Gravis UltraSound -01: Yamaha OPL-3 - -Midi devices: -00: Gravis UltraSound -01: Pro Audio Spectrum - -Mixer(s) installed ------- cut here ---- End of Example ----------- - - -Known bugs ----------- - -- There was clicking during stereo playback to /dev/dsp with GUS. - * Fixed in 1.99.9 * -- It's not possible to open /dev/dsp (or /dev/audio) while the - /dev/sequencer is open for output and GUS is the only soundcard - installed. It's possible if /dev/dsp is opened before /dev/sequencer - but at this time the GUS is not available for access via /dev/sequencer. - This is a limitation of the driver. -- MPU-401 driver hangs the computer on boot if there is no MPU-401 installed. - It uses by default the I/O port 0x330 whic is used by Adaptec 1542 SCSI - adapter. -- The /dev/sequencer playback to GUS sounds sometimes rather weird. Hitting - ^C and playing again should solve this problem. This is propably caused by - incompatibilities between GUS and certain VLB motherboards. Try to avoid - switching between VTs while patches are being loaded to the GUS. -- There was some problems with GUS and Mitsumi CD in version 1.99.8. Fixed - in 1.99.9. -- /dev/audio sounded like stereo with GUS. Fixed in 1.99.9. -- There is a skeleton of the patch manager support. It don't work in - this version. diff --git a/sys/i386/isa/sound/gus_linearvol.h b/sys/i386/isa/sound/gus_linearvol.h new file mode 100644 index 0000000..7ad0c30 --- /dev/null +++ b/sys/i386/isa/sound/gus_linearvol.h @@ -0,0 +1,18 @@ +static unsigned short gus_linearvol[128] = { + 0x0000, 0x08ff, 0x09ff, 0x0a80, 0x0aff, 0x0b40, 0x0b80, 0x0bc0, + 0x0bff, 0x0c20, 0x0c40, 0x0c60, 0x0c80, 0x0ca0, 0x0cc0, 0x0ce0, + 0x0cff, 0x0d10, 0x0d20, 0x0d30, 0x0d40, 0x0d50, 0x0d60, 0x0d70, + 0x0d80, 0x0d90, 0x0da0, 0x0db0, 0x0dc0, 0x0dd0, 0x0de0, 0x0df0, + 0x0dff, 0x0e08, 0x0e10, 0x0e18, 0x0e20, 0x0e28, 0x0e30, 0x0e38, + 0x0e40, 0x0e48, 0x0e50, 0x0e58, 0x0e60, 0x0e68, 0x0e70, 0x0e78, + 0x0e80, 0x0e88, 0x0e90, 0x0e98, 0x0ea0, 0x0ea8, 0x0eb0, 0x0eb8, + 0x0ec0, 0x0ec8, 0x0ed0, 0x0ed8, 0x0ee0, 0x0ee8, 0x0ef0, 0x0ef8, + 0x0eff, 0x0f04, 0x0f08, 0x0f0c, 0x0f10, 0x0f14, 0x0f18, 0x0f1c, + 0x0f20, 0x0f24, 0x0f28, 0x0f2c, 0x0f30, 0x0f34, 0x0f38, 0x0f3c, + 0x0f40, 0x0f44, 0x0f48, 0x0f4c, 0x0f50, 0x0f54, 0x0f58, 0x0f5c, + 0x0f60, 0x0f64, 0x0f68, 0x0f6c, 0x0f70, 0x0f74, 0x0f78, 0x0f7c, + 0x0f80, 0x0f84, 0x0f88, 0x0f8c, 0x0f90, 0x0f94, 0x0f98, 0x0f9c, + 0x0fa0, 0x0fa4, 0x0fa8, 0x0fac, 0x0fb0, 0x0fb4, 0x0fb8, 0x0fbc, + 0x0fc0, 0x0fc4, 0x0fc8, 0x0fcc, 0x0fd0, 0x0fd4, 0x0fd8, 0x0fdc, + 0x0fe0, 0x0fe4, 0x0fe8, 0x0fec, 0x0ff0, 0x0ff4, 0x0ff8, 0x0ffc +}; diff --git a/sys/i386/isa/sound/gustest/Makefile b/sys/i386/isa/sound/gustest/Makefile deleted file mode 100644 index d161e5b..0000000 --- a/sys/i386/isa/sound/gustest/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -all: gustest gusload gmod midithru - -gustest: gustest.c - $(CC) -o gustest gustest.c -lm - -gusload: gusload.c - $(CC) -o gusload gusload.c - -gmod: gmod.c - $(CC) -o gmod gmod.c - -midithru: midithru.c - $(CC) -o midithru midithru.c - -clean: - rm -f gusload gustest gmod midithru *.o diff --git a/sys/i386/isa/sound/gustest/Readme b/sys/i386/isa/sound/gustest/Readme deleted file mode 100644 index 7640bf8..0000000 --- a/sys/i386/isa/sound/gustest/Readme +++ /dev/null @@ -1,67 +0,0 @@ -The programs in this directory are more or less incompletely implemented. -I have used them for debugging purposes while developing the driver. - -Files in this directory: - - -../ultrasound.h (sys/ultrasound.h) - This file contains some macros which are similar than - the procedures provided by GUSUNIT.PAS. See gustest.c - for more information. - INSTALL THIS FILE TO YOUR /usr/include/sys !!!!!!!!!!!! - -gusload.c This program can be used to load patches (samples) to - the DRAM of GUS. It understands the format used in the - .pat files shipped with GUS. - - Usage: gusload pgm# patchfile. - or gusload reset #Removes all patches from memory. - - You should load just the patches you will need to play - a Midi file, since the memory capacity of GUS is rather - limited (256k-1M). - - Example: - - gusload 0 acpiano.pat - gusload 1 britepno.pat - gusload 19 church.pat - - This program is not required if the adagio package is - used. It can do the patch uploading itself. - -gmod.c This is a simple module player which demonstrates - programming with GUS. It doesn't try to interpret - most of the effect commands. In fact this program - may interpret the modules incorrectly since I am - not a module player expert. - This version plays .MOD, .STM and .669 modules. - -midithru.c This program reads messages from the Midi interface - and plays the notes with an internal synthesizer - (FM or GUS). The program accepts one argument, the - synthesizer device number. In addition to the note on - and note off messages it interprets also program changes - and channel pressure messages. - If you need an example on programming the /dev/sequencer, - this is a good one. The voice allocation algorithm is - not good so don't look at it. - - NOTE! This program is useful with gmod. Jus load - a module with gmod. Wait until the module has - finished or hit ^C. Now you can play the samples - with the midithru program. - - NOTE2! You need a Midi keyboard to use this program. In - addition the Midi interface of GUS is not supported - yet which means you need also PAS16 or MPU-401. - -pmtest.c -gpatinfo.c ******* For information only ******* - These programs demonstrate the patch manager interface - which will be included to some later driver version. - This interface is not complete in version 1.99.9. - Using pmtest will hang your system sooner or later. - -Hannu Savolainen -hsavolai@cs.helsinki.fi diff --git a/sys/i386/isa/sound/gustest/gmidi.h b/sys/i386/isa/sound/gustest/gmidi.h deleted file mode 100644 index ab951e7..0000000 --- a/sys/i386/isa/sound/gustest/gmidi.h +++ /dev/null @@ -1,131 +0,0 @@ - char patch_names[][9] = - { - /* 0 */ "acpiano", - /* 1 */ "britepno", - /* 2 */ "synpiano", - /* 3 */ "honktonk", - /* 4 */ "epiano1", - /* 5 */ "epiano2", - /* 6 */ "hrpschrd", - /* 7 */ "clavinet", - /* 8 */ "celeste", - /* 9 */ "glocken", - /* 10 */ "musicbox", - /* 11 */ "vibes", - /* 12 */ "marimba", - /* 13 */ "xylophon", - /* 14 */ "tubebell", - /* 15 */ "santur", - /* 16 */ "homeorg", - /* 17 */ "percorg", - /* 18 */ "rockorg", - /* 19 */ "church", - /* 20 */ "reedorg", - /* 21 */ "accordn", - /* 22 */ "harmonca", - /* 23 */ "concrtna", - /* 24 */ "nyguitar", - /* 25 */ "acguitar", - /* 26 */ "jazzgtr", - /* 27 */ "cleangtr", - /* 28 */ "mutegtr", - /* 29 */ "odguitar", - /* 30 */ "distgtr", - /* 31 */ "gtrharm", - /* 32 */ "acbass", - /* 33 */ "fngrbass", - /* 34 */ "pickbass", - /* 35 */ "fretless", - /* 36 */ "slapbas1", - /* 37 */ "slapbas2", - /* 38 */ "synbass1", - /* 39 */ "synbass2", - /* 40 */ "violin", - /* 41 */ "viola", - /* 42 */ "cello", - /* 43 */ "contraba", - /* 44 */ "marcato", - /* 45 */ "pizzcato", - /* 46 */ "harp", - /* 47 */ "timpani", - /* 48 */ "marcato", - /* 49 */ "slowstr", - /* 50 */ "synstr1", - /* 51 */ "synstr2", - /* 52 */ "choir", - /* 53 */ "doo", - /* 54 */ "voices", - /* 55 */ "orchhit", - /* 56 */ "trumpet", - /* 57 */ "trombone", - /* 58 */ "tuba", - /* 59 */ "mutetrum", - /* 60 */ "frenchrn", - /* 61 */ "hitbrass", - /* 62 */ "synbras1", - /* 63 */ "synbras2", - /* 64 */ "sprnosax", - /* 65 */ "altosax", - /* 66 */ "tenorsax", - /* 67 */ "barisax", - /* 68 */ "oboe", - /* 69 */ "englhorn", - /* 70 */ "bassoon", - /* 71 */ "clarinet", - /* 72 */ "piccolo", - /* 73 */ "flute", - /* 74 */ "recorder", - /* 75 */ "woodflut", - /* 76 */ "bottle", - /* 77 */ "shakazul", - /* 78 */ "whistle", - /* 79 */ "ocarina", - /* 80 */ "sqrwave", - /* 81 */ "sawwave", - /* 82 */ "calliope", - /* 83 */ "chiflead", - /* 84 */ "voxlead", - /* 85 */ "voxlead", - /* 86 */ "lead5th", - /* 87 */ "basslead", - /* 88 */ "fantasia", - /* 89 */ "warmpad", - /* 90 */ "polysyn", - /* 91 */ "ghostie", - /* 92 */ "bowglass", - /* 93 */ "metalpad", - /* 94 */ "halopad", - /* 95 */ "sweeper", - /* 96 */ "aurora", - /* 97 */ "soundtrk", - /* 98 */ "crystal", - /* 99 */ "atmosphr", - /* 100 */ "freshair", - /* 101 */ "unicorn", - /* 102 */ "sweeper", - /* 103 */ "startrak", - /* 104 */ "sitar", - /* 105 */ "banjo", - /* 106 */ "shamisen", - /* 107 */ "koto", - /* 108 */ "kalimba", - /* 109 */ "bagpipes", - /* 110 */ "fiddle", - /* 111 */ "Shannai", - /* 112 */ "carillon", - /* 113 */ "agogo", - /* 114 */ "steeldrm", - /* 115 */ "woodblk", - /* 116 */ "taiko", - /* 117 */ "toms", - /* 118 */ "syntom", - /* 119 */ "revcym", - /* 120 */ "fx-fret", - /* 121 */ "fx-blow", - /* 122 */ "seashore", - /* 123 */ "jungle", - /* 124 */ "telephon", - /* 125 */ "helicptr", - /* 126 */ "applause", - /* 127 */ "ringwhsl" - }; diff --git a/sys/i386/isa/sound/gustest/gmod.c b/sys/i386/isa/sound/gustest/gmod.c deleted file mode 100644 index d730e26..0000000 --- a/sys/i386/isa/sound/gustest/gmod.c +++ /dev/null @@ -1,1589 +0,0 @@ -/* - * gmod.c - Module player for GUS and Linux. - * (C) Hannu Savolainen, 1993 - * - * NOTE! This program doesn't try to be a complete module player. - * It's just a too I used while developing the driver. In - * addition it can be used as an example on programming - * the LInux Sound Driver with GUS. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/ultrasound.h> -#include <sys/ioctl.h> -#include <fcntl.h> -#include <math.h> -#include <string.h> - -#define CMD_ARPEG 0x00 -#define CMD_SLIDEUP 0x01 -#define CMD_SLIDEDOWN 0x02 -#define CMD_SLIDETO 0x03 -#define SLIDE_SIZE 8 -#define CMD_VOLSLIDE 0x0a -#define CMD_JUMP 0x0b -#define CMD_VOLUME 0x0c -#define CMD_BREAK 0x0d -#define CMD_SPEED 0x0f -#define CMD_NOP 0xfe -#define CMD_NONOTE 0xff - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -#define MAX_TRACK 8 -#define MAX_PATTERN 128 -#define MAX_POSITION 128 - -struct note_info - { - unsigned char note; - unsigned char vol; - unsigned char sample; - unsigned char command; - short parm1, parm2; - }; - -struct voice_info - { - int sample; - int note; - int volume; - int pitchbender; - - /* Pitch sliding */ - - int slide_pitch; - int slide_goal; - int slide_rate; - - int volslide; - }; - -typedef struct note_info pattern[MAX_TRACK][64]; -int pattern_len[MAX_POSITION]; -int pattern_tempo[MAX_POSITION]; -pattern *pattern_table[MAX_PATTERN]; - -struct voice_info voices[MAX_TRACK]; - -int nr_channels, nr_patterns, songlength; -int tune[MAX_POSITION]; -double tick_duration; - -int period_table[] = -{ - 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453, - 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226, - 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113 -}; - -SEQ_DEFINEBUF (2048); - -int seqfd; -int sample_ok[128], sample_vol[128]; -int tmp, gus_dev; -double this_time, next_time; -int ticks_per_division; -double clock_rate; /* HZ */ - -/* - * The function seqbuf_dump() must always be provided - */ - -void play_module (char *name); -int load_module (char *name); -int play_note (int channel, struct note_info *pat); -void lets_play_voice (int channel, struct voice_info *v); - -void -seqbuf_dump () -{ - if (_seqbufptr) - if (write (seqfd, _seqbuf, _seqbufptr) == -1) - { - perror ("write /dev/sequencer"); - exit (-1); - } - _seqbufptr = 0; -} - -void -init_voices () -{ - int i; - - for (i = 0; i < MAX_TRACK; i++) - { - voices[i].sample = 0; - voices[i].note = 0; - voices[i].volume = 64; - - voices[i].slide_pitch = 0; - voices[i].slide_goal = 0; - voices[i].slide_rate = 0; - voices[i].pitchbender = 0; - - voices[i].volslide = 0; - } -} - -int -main (int argc, char *argv[]) -{ - int i, n, j; - struct synth_info info; - - if ((seqfd = open ("/dev/sequencer", O_WRONLY, 0)) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - if (ioctl (seqfd, SNDCTL_SEQ_NRSYNTHS, &n) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - for (i = 0; i < n; i++) - { - info.device = i; - - if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - if (info.synth_type == SYNTH_TYPE_SAMPLE - && info.synth_subtype == SAMPLE_TYPE_GUS) - gus_dev = i; - } - - if (gus_dev == -1) - { - fprintf (stderr, "Gravis Ultrasound not detected\n"); - exit (-1); - } - - GUS_NUMVOICES (gus_dev, 14); - - for (i = 1; i < argc; i++) - { - for (j = 0; j < MAX_PATTERN; j++) - pattern_table[j] = NULL; - - if (load_module (argv[i])) - { - tick_duration = 100.0 / clock_rate; - play_module (argv[i]); - } - - } - - SEQ_DUMPBUF (); - close (seqfd); - - exit (0); -} - -unsigned short -intelize (unsigned short v) -{ - return ((v & 0xff) << 8) | ((v >> 8) & 0xff); -} - -unsigned long -intelize4 (unsigned long v) -{ - return - (((v >> 16) & 0xff) << 8) | (((v >> 16) >> 8) & 0xff) | - (((v & 0xff) << 8) | ((v >> 8) & 0xff) << 16); -} - -int -load_stm_module (int mod_fd, char *name) -{ - - struct sample_header - { - char name[12]; - unsigned char instr_disk; - unsigned short reserved1; - unsigned short length; /* In bytes */ - unsigned short loop_start; - unsigned short loop_end; - unsigned char volume; - unsigned char reserved2; - unsigned short C2_speed; - unsigned short reserved3; - - }; - - int i, total_mem; - int sample_ptr; - - int position; - - unsigned char *tune_ptr; /* array 0-127 */ - - char header[1105], sname[21]; - - int nr_samples; /* 16 or 32 samples (or 64 or ???) */ - int slen, npat; - - fprintf (stderr, "Loading .STM module: %s\n", name); - - if (read (mod_fd, header, sizeof (header)) != sizeof (header)) - { - fprintf (stderr, "%s: Short file (header)\n", name); - close (mod_fd); - return 0; - } - - strncpy (sname, header, 20); - - fprintf (stderr, "\nModule: %s - ", sname); - - if (header[28] != 0x1a) - { - fprintf (stderr, "Not a STM module\n"); - close (mod_fd); - return 0; - } - - npat = header[33]; - slen = 0; - tune_ptr = &header[48 + (31 * 32)]; - - for (i = 0; i < 64; i++) - { - tune[i] = tune_ptr[i]; - if (tune[i] < npat) - slen = i; - } - - fprintf (stderr, "Song lenght %d, %d patterns.\n", slen, npat); - - nr_samples = 31; - - sample_ptr = 48 + (31 * 32) + 64 + (npat * 1024); /* Location where the - * first sample is - * stored */ - total_mem = 0; - - for (i = 0; i < 32; i++) - sample_ok[i] = 0; - - for (i = 0; i < nr_samples; i++) - { - int len, loop_start, loop_end, base_freq; - unsigned short loop_flags = 0; - - struct sample_header *sample; - - struct patch_info *patch; - - sample = (struct sample_header *) &header[48 + (i * 32)]; - - len = sample->length; - loop_start = sample->loop_start; - loop_end = sample->loop_end; - base_freq = sample->C2_speed; - - if (strlen (sample->name) > 21) - { - fprintf (stderr, "\nInvalid name for sample #%d\n", i); - close (mod_fd); - return 0; - } - - if (len > 0) - { - int x; - - if (loop_end > len) - loop_end = 1; - else if (loop_end < loop_start) - { - loop_start = 0; - loop_end = 0; - } - else - loop_flags = WAVE_LOOPING; - - total_mem += len; - patch = (struct patch_info *) malloc (sizeof (*patch) + len); - - patch->key = GUS_PATCH; - patch->device_no = gus_dev; - patch->instr_no = i; - patch->mode = loop_flags; - patch->len = len; - patch->loop_start = loop_start; - patch->loop_end = loop_end; - patch->base_freq = base_freq; - patch->base_note = 261630; /* Mid C */ - patch->low_note = 0; - patch->high_note = 0x7fffffff; - patch->volume = 120; - - if (lseek (mod_fd, sample_ptr, 0) == -1) - { - perror (name); - close (mod_fd); - free (patch); - return 0; - } - - sample_ptr += len; - - if ((x = read (mod_fd, patch->data, len)) != len) - { - fprintf (stderr, "Short file (sample at %d (%d!=%d)\n", sample_ptr, x, len); - close (mod_fd); - free (patch); - return 0; - } - - fprintf (stderr, "Sample %02d: %05d, %05d, %05d, %07d %s\n", - i, - len, - loop_start, - loop_end, - base_freq, - sample->name); - - if (write (seqfd, patch, sizeof (*patch) + len) == -1) - { - perror ("ioctl /dev/sequencer"); - exit (-1); - } - else - sample_ok[i] = 1; - - free (patch); - } - } - - nr_patterns = slen; - songlength = slen; - nr_channels = 4; - - for (position = 0; position < npat; position++) - { - unsigned char patterns[64][4][4]; - int pat, channel, x; - - int pp = 1104 + (position * 1024); - - if ((pattern_table[position] = (pattern *) malloc (sizeof (struct note_info) * 64 * nr_channels)) == NULL) - { - fprintf (stderr, "Can't allocate memory for a pattern\n"); - return 0; - } - - if (lseek (mod_fd, pp, 0) == -1) - { - perror (name); - close (mod_fd); - return 0; - } - - if ((x = read (mod_fd, patterns, 1024)) != 1024) - { - fprintf (stderr, "Short file (pattern at %d), %d!=%d\n", pp, x, 1024); - close (mod_fd); - return 0; - } - - for (pat = 0; pat < 64; pat++) - { - - for (channel = 0; channel < 4; channel++) - { - unsigned char *p; - - unsigned vol, note, octave, sample, effect, params; - - p = &patterns[pat][channel][0]; - - if (p[0] < 251) - { - note = p[0] & 15; - octave = p[0] / 16; - - note = 48 + octave * 12 + note; - - sample = p[1] / 8; - vol = (p[1] & 7) + (p[2] / 2); - effect = p[2] & 0xF; - params = p[3]; - } - else - { - note = 0; - octave = 0; - - sample = 0; - vol = 0; - effect = CMD_NONOTE; - params = 0; - } - - (*pattern_table[position])[channel][pat].note = note; - (*pattern_table[position])[channel][pat].sample = sample; - (*pattern_table[position])[channel][pat].command = effect; - (*pattern_table[position])[channel][pat].parm1 = params; - (*pattern_table[position])[channel][pat].parm2 = 0; - (*pattern_table[position])[channel][pat].vol = vol; - } - - } - - } - - close (mod_fd); - return 1; -} - -int -load_669_module (int mod_fd, char *name) -{ - struct sample_header - { - char name[13]; - unsigned long length; /* In bytes */ - unsigned long loop_start; - unsigned long loop_end; - }; - - int i, total_mem; - int sample_ptr; - - int position; - - unsigned char *tune_ptr, *len_ptr, *tempo_ptr; /* array 0-127 */ - - char header[1084]; - char msg[110]; - - int nr_samples; /* 16 or 32 samples */ - int slen, npat; - - clock_rate = 25.0; - - fprintf (stderr, "Loading .669 module: %s\n", name); - - if (read (mod_fd, header, sizeof (header)) != sizeof (header)) - { - fprintf (stderr, "%s: Short file (header)\n", name); - close (mod_fd); - return 0; - } - - if (*(unsigned short *) &header[0] != 0x6669) - { - fprintf (stderr, "Not a 669 file\n"); - close (mod_fd); - return 0; - } - - strncpy (msg, &header[2], 108); - - for (i = 0; i < strlen (msg); i++) - if ((msg[i] >= ' ' && msg[i] <= 'z') || msg[i] == '\n') - printf ("%c", msg[i]); - printf ("\n"); - - npat = header[0x6f]; - - tune_ptr = &header[0x71]; - - for (slen = 0; slen < 128 && tune_ptr[slen] != 0xff; slen++); - slen--; - - for (i = 0; i < slen; i++) - tune[i] = tune_ptr[i]; - - len_ptr = &header[0x171]; - for (i = 0; i < slen; i++) - pattern_len[i] = len_ptr[i] - 1; - - tempo_ptr = &header[0xf1]; - for (i = 0; i < slen; i++) - pattern_tempo[i] = tempo_ptr[i]; - - nr_samples = header[0x6e]; - - fprintf (stderr, "Song lenght %d, %d patterns, %d samples.\n", slen, npat, nr_samples); - - sample_ptr = 0x1f1 + (nr_samples * 0x19) + (npat * 0x600); /* Location where the - * first sample is - * stored */ - total_mem = 0; - - for (i = 0; i < 64; i++) - sample_ok[i] = 0; - - for (i = 0; i < nr_samples; i++) - { - int len, loop_start, loop_end; - unsigned short loop_flags = 0; - - struct sample_header *sample; - char sname[14]; - - struct patch_info *patch; - - sample = (struct sample_header *) &header[0x1f1 + (i * 0x19)]; - - len = *(unsigned long *) &sample->name[13]; - loop_start = *(unsigned long *) &sample->name[17]; - loop_end = *(unsigned long *) &sample->name[21]; - if (loop_end > len) - loop_end = 1; - else if (loop_end == len) - loop_end--; - - if (loop_end < loop_start) - { - loop_start = 0; - loop_end = 0; - } - - strncpy (sname, sample->name, 13); - - if (len > 0 && len < 200000) - { - total_mem += len; - - fprintf (stderr, "Sample %02d: %05d, %05d, %05d %s\n", - i, - len, - loop_start, - loop_end, - sname); - - patch = (struct patch_info *) malloc (sizeof (*patch) + len); - - if (loop_end == 0) - loop_end = 1; - if (loop_end >= len) - loop_end = 1; - - if (loop_end > 1) loop_flags = WAVE_LOOPING; - - patch->key = GUS_PATCH; - patch->device_no = gus_dev; - patch->instr_no = i; - patch->mode = WAVE_UNSIGNED | loop_flags; - patch->len = len; - patch->loop_start = loop_start; - patch->loop_end = loop_end; - patch->base_freq = 8448; - patch->base_note = 261630; - patch->low_note = 1000; - patch->high_note = 0x7fffffff; - patch->volume = 120; - - if (lseek (mod_fd, sample_ptr, 0) == -1) - { - fprintf (stderr, "Seek failed\n"); - perror (name); - close (mod_fd); - free (patch); - return 0; - } - - sample_ptr += len; - - if (read (mod_fd, patch->data, len) != len) - { - fprintf (stderr, "Short file (sample at %d)\n", sample_ptr); - close (mod_fd); - free (patch); - return 0; - } - - if (write (seqfd, patch, sizeof (*patch) + len) == -1) - { - perror ("ioctl /dev/sequencer"); - /* exit (-1); */ - } - else - sample_ok[i] = 1; - - free (patch); - } - } - - nr_patterns = slen; - songlength = slen; - nr_channels = 8; - - for (position = 0; position < npat; position++) - { - unsigned char patterns[0x600]; - int pat, channel, x; - - int pp = 0x1f1 + (nr_samples * 0x19) + (position * 0x600); - - if ((pattern_table[position] = (pattern *) malloc (sizeof (struct note_info) * 64 * nr_channels)) == NULL) - { - fprintf (stderr, "Can't allocate memory for a pattern\n"); - return 0; - } - - - if (lseek (mod_fd, pp, 0) == -1) - { - perror (name); - close (mod_fd); - return 0; - } - - if ((x = read (mod_fd, patterns, 1024)) != 1024) - { - fprintf (stderr, "Short file (pattern at %d) %d!=1024\n", pp, x); - close (mod_fd); - return 0; - } - - for (pat = 0; pat < 64; pat++) - { - - for (channel = 0; channel < 8; channel++) - { - unsigned char *p; - - unsigned vol, period, sample, effect, params; - - p = &patterns[pat * 24 + channel * 3]; - - if (p[0] >= 0xfe || - (p[0] == 0xff && p[1] == 0xff && p[2] == 0xff) || - (p[0] == 0 && p[1] == 0 && p[2] == 0) || - *(int *) p == -1) - { - period = 0; - effect = CMD_NONOTE; - sample = 0; - vol = 0; - params = 0; - - if (p[0] == 0) - { - effect = CMD_BREAK; - params = -2; - } - } - else - { - period = (p[0] >> 2) + 48; - effect = (p[2] >> 4); - params = p[2] & 0x0f; - vol = p[1] & 0x0f; - - if (p[2] == 0xfe) - { - effect = CMD_VOLUME; - params = vol; - } - else if (p[2] == 0xff) - { - effect = CMD_NOP; - } - else - switch (effect) - { - case 0: /* a - Portamento up */ - effect = CMD_SLIDEUP; - break; - - case 1: /* b - Portamento down */ - effect = CMD_SLIDEDOWN; - break; - - case 2: /* c - Port to note */ - effect = CMD_SLIDETO; - break; - - case 3: /* d - Frequency adjust */ - effect = CMD_NOP; /* To be implemented */ - break; - - case 4: /* e - Frequency vibrato */ - effect = CMD_NOP; /* To be implemented */ - break; - - case 5: /* f - Set tempo */ - effect = CMD_SPEED; - break; - - default: - effect = CMD_NOP; - } - - sample = (((p[0] << 4) & 0x30) | ((p[1] >> 4) & 0x0f)) + 1; - } - - (*pattern_table[position])[channel][pat].note = period; - (*pattern_table[position])[channel][pat].sample = sample; - (*pattern_table[position])[channel][pat].command = effect; - (*pattern_table[position])[channel][pat].parm1 = params; - (*pattern_table[position])[channel][pat].parm2 = 0; - (*pattern_table[position])[channel][pat].vol = vol; - } - - } - - } - - close (mod_fd); - return 1; -} - -int -load_mmd0_module (int mod_fd, char *name) -{ - - struct sample_header - { - unsigned short loop_start; - unsigned short loop_end; - unsigned char midich; - unsigned char midipreset; - unsigned char volume; - unsigned char strans; - }; - - int i, total_mem; - int sample_ptr; - - int position; - - unsigned char *tune_ptr; /* array 0-127 */ - - char header[1105]; - - int nr_samples; /* 16 or 32 samples (or 64 or ???) */ - int slen, npat; - - fprintf (stderr, "Loading .MED module: %s\n", name); - - if (read (mod_fd, header, sizeof (header)) != sizeof (header)) - { - fprintf (stderr, "%s: Short file (header)\n", name); - close (mod_fd); - return 0; - } - - if (strncmp (header, "MMD0", 4)) - { - fprintf (stderr, "Not a MED module\n"); - close (mod_fd); - return 0; - } - - printf ("Module len %d\n", intelize4 (*(long *) &header[4])); - printf ("Song info %d\n", intelize4 (*(long *) &header[8])); - printf ("Song len %d\n", intelize4 (*(long *) &header[12])); - printf ("Blockarr %x\n", intelize4 (*(long *) &header[16])); - printf ("Blockarr len %d\n", intelize4 (*(long *) &header[20])); - printf ("Sample array %x\n", intelize4 (*(long *) &header[24])); - printf ("Sample array len %d\n", intelize4 (*(long *) &header[28])); - printf ("Exp data %x\n", intelize4 (*(long *) &header[32])); - printf ("Exp size %d\n", intelize4 (*(long *) &header[36])); - printf ("Pstate %d\n", intelize (*(long *) &header[40])); - printf ("Pblock %d\n", intelize (*(long *) &header[42])); - - return 0; - - npat = header[33]; - slen = 0; - tune_ptr = &header[48 + (31 * 32)]; - - for (i = 0; i < 64; i++) - { - tune[i] = tune_ptr[i]; - if (tune[i] < npat) - slen = i; - } - - fprintf (stderr, "Song lenght %d, %d patterns.\n", slen, npat); - - nr_samples = 31; - - sample_ptr = 48 + (31 * 32) + 64 + (npat * 1024); /* Location where the - * first sample is - * stored */ - total_mem = 0; - - for (i = 0; i < 32; i++) - sample_ok[i] = 0; - - for (i = 0; i < nr_samples; i++) - { - int len, loop_start, loop_end, base_freq; - unsigned short loop_flags = 0; - - struct sample_header *sample; - - struct patch_info *patch; - - sample = (struct sample_header *) &header[48 + (i * 32)]; - - /* - * len = sample->length; loop_start = sample->loop_start; loop_end = - * sample->loop_end; base_freq = sample->C2_speed; - * - * if (strlen (sample->name) > 21) { fprintf (stderr, "\nInvalid name for - * sample #%d\n", i); close (mod_fd); return 0; } - */ - if (len > 0) - { - int x; - - if (loop_end > len) - loop_end = 1; - - if (loop_end < loop_start) - { - loop_start = 0; - loop_end = 0; - } - - if (loop_end > 2) loop_flags = WAVE_LOOPING; - - total_mem += len; - patch = (struct patch_info *) malloc (sizeof (*patch) + len); - - patch->key = GUS_PATCH; - patch->device_no = gus_dev; - patch->instr_no = i; - patch->mode = loop_flags; - patch->len = len; - patch->loop_start = loop_start; - patch->loop_end = loop_end; - patch->base_freq = base_freq; - patch->base_note = 261630; /* Mid C */ - patch->low_note = 0; - patch->high_note = 0x7fffffff; - patch->volume = 120; - - if (lseek (mod_fd, sample_ptr, 0) == -1) - { - perror (name); - close (mod_fd); - free (patch); - return 0; - } - - sample_ptr += len; - - if ((x = read (mod_fd, patch->data, len)) != len) - { - fprintf (stderr, "Short file (sample at %d (%d!=%d)\n", sample_ptr, x, len); - close (mod_fd); - free (patch); - return 0; - } - /* - * fprintf (stderr, "Sample %02d: %05d, %05d, %05d, %07d %s\n", i, - * len, loop_start, loop_end, base_freq, sample->name); - */ - if (write (seqfd, patch, sizeof (*patch) + len) == -1) - { - perror ("ioctl /dev/sequencer"); - exit (-1); - } - else - sample_ok[i] = 1; - - free (patch); - } - } - - nr_patterns = slen; - songlength = slen; - nr_channels = 4; - - for (position = 0; position < npat; position++) - { - unsigned char patterns[64][4][4]; - int pat, channel, x; - - int pp = 1104 + (position * 1024); - - if ((pattern_table[position] = (pattern *) malloc (sizeof (struct note_info) * 64 * nr_channels)) == NULL) - { - fprintf (stderr, "Can't allocate memory for a pattern\n"); - return 0; - } - - if (lseek (mod_fd, pp, 0) == -1) - { - perror (name); - close (mod_fd); - return 0; - } - - if ((x = read (mod_fd, patterns, 1024)) != 1024) - { - fprintf (stderr, "Short file (pattern at %d), %d!=%d\n", pp, x, 1024); - close (mod_fd); - return 0; - } - - for (pat = 0; pat < 64; pat++) - { - - for (channel = 0; channel < 4; channel++) - { - unsigned char *p; - - unsigned vol, note, octave, sample, effect, params; - - p = &patterns[pat][channel][0]; - - if (p[0] < 251) - { - note = p[0] & 15; - octave = p[0] / 16; - - note = 48 + octave * 12 + note; - - sample = p[1] / 8; - vol = (p[1] & 7) + (p[2] / 2); - effect = p[2] & 0xF; - params = p[3]; - } - else - { - note = 0; - octave = 0; - - sample = 0; - vol = 0; - effect = CMD_NONOTE; - params = 0; - } - - (*pattern_table[position])[channel][pat].note = note; - (*pattern_table[position])[channel][pat].sample = sample; - (*pattern_table[position])[channel][pat].command = effect; - (*pattern_table[position])[channel][pat].parm1 = params; - (*pattern_table[position])[channel][pat].parm2 = 0; - (*pattern_table[position])[channel][pat].vol = vol; - } - - } - - } - - close (mod_fd); - return 1; -} - -int -load_module (char *name) -{ - - struct sample_header - { - char name[22]; - unsigned short length; /* In words */ - - unsigned char finetune; - unsigned char volume; - - unsigned short repeat_point; /* In words */ - unsigned short repeat_length; /* In words */ - }; - - int i, mod_fd, total_mem; - int sample_ptr, pattern_loc; - - int position; - - unsigned char *tune_ptr; /* array 0-127 */ - - char header[1084]; - - int nr_samples; /* 16 or 32 samples */ - int slen, npat; - char mname[23]; - - ioctl (seqfd, SNDCTL_SEQ_SYNC, 0); - ioctl (seqfd, SNDCTL_SEQ_RESETSAMPLES, &gus_dev); - - clock_rate = 50.0; - - for (i = 0; i < MAX_POSITION; i++) - pattern_len[i] = 64; - - for (i = 0; i < MAX_POSITION; i++) - pattern_tempo[i] = 0; - - if ((mod_fd = open (name, O_RDONLY, 0)) == -1) - { - perror (name); - return 0; - } - - if (read (mod_fd, header, sizeof (header)) != sizeof (header)) - { - fprintf (stderr, "%s: Short file (header)\n", name); - close (mod_fd); - return 0; - } - - if (lseek (mod_fd, 0, 0) == -1) - { - perror (name); - close (mod_fd); - return 0; - } - - if (header[28] == 0x1a) - return load_stm_module (mod_fd, name); - - if (*(unsigned short *) &header[0] == 0x6669) - return load_669_module (mod_fd, name); - - if (!strncmp (header, "MMD0", 4)) - return load_mmd0_module (mod_fd, name); - - fprintf (stderr, "Loading .MOD module: %s\n", name); - - strncpy (mname, header, 22); - fprintf (stderr, "\nModule: %s - ", mname); - - if (!strncmp (&header[1080], "M.K.", 4) || !strncmp (&header[1080], "FLT8", 4)) - { - fprintf (stderr, "31 samples\n"); - nr_samples = 31; - } - else - { - fprintf (stderr, "15 samples\n"); - nr_samples = 15; - } - - if (nr_samples == 31) - { - sample_ptr = pattern_loc = 1084; - slen = header[950]; - tune_ptr = (unsigned char *) &header[952]; - } - else - { - sample_ptr = pattern_loc = 600; - slen = header[470]; - tune_ptr = (unsigned char *) &header[472]; - } - - npat = 0; - for (i = 0; i < 128; i++) - { - tune[i] = tune_ptr[i]; - - if (tune_ptr[i] > npat) - npat = tune_ptr[i]; - } - npat++; - - fprintf (stderr, "Song lenght %d, %d patterns.\n", slen, npat); - - sample_ptr += (npat * 1024); /* Location where the first sample is stored */ - total_mem = 0; - - for (i = 0; i < 32; i++) - sample_ok[i] = 0; - - for (i = 0; i < nr_samples; i++) - { - int len, loop_start, loop_end; - unsigned short loop_flags = 0; - char pname[22]; - - struct sample_header *sample; - - struct patch_info *patch; - - sample = (struct sample_header *) &header[20 + (i * 30)]; - - len = intelize (sample->length) * 2; - loop_start = intelize (sample->repeat_point) * 2; - loop_end = loop_start + (intelize (sample->repeat_length) * 2); - - if (loop_start > len) - loop_start = 0; - if (loop_end > len) - loop_end = len; - - if (loop_end <= loop_start) - loop_end = loop_start + 1; - - if (loop_end > 2 && loop_end > loop_start) - loop_flags = WAVE_LOOPING; - - strncpy (pname, sample->name, 20); - - if (len > 0) - { - fprintf (stderr, "Sample %02d: L%05d, S%05d, E%05d V%02d %s\n", - i, - len, - loop_start, - loop_end, - sample->volume, - pname); - - total_mem += len; - - patch = (struct patch_info *) malloc (sizeof (*patch) + len); - - patch->key = GUS_PATCH; - patch->device_no = gus_dev; - patch->instr_no = i; - patch->mode = loop_flags; - patch->len = len; - patch->loop_start = loop_start; - patch->loop_end = loop_end; - patch->base_note = 261630; /* Middle C */ - patch->base_freq = 8448; - patch->low_note = 0; - patch->high_note = 20000000; - patch->volume = 120; - patch->panning = 0; - - if (lseek (mod_fd, sample_ptr, 0) == -1) - { - perror (name); - close (mod_fd); - free (patch); - return 0; - } - - sample_ptr += len; - - if (read (mod_fd, patch->data, len) != len) - { - fprintf (stderr, "Short file (sample) %d\n", sample_ptr); - close (mod_fd); - free (patch); - return 0; - } - - SEQ_WRPATCH (patch, sizeof (*patch) + len); - - sample_ok[i] = 1; - if (sample->volume == 0) sample->volume = 64; - sample_vol[i] = sample->volume; - - free (patch); - } - } - - nr_patterns = npat; - songlength = slen; - nr_channels = 4; - - for (position = 0; position < npat; position++) - { - unsigned char patterns[64][4][4]; - int pat, channel; - - int pp = pattern_loc + (position * 1024); - - if (lseek (mod_fd, pp, 0) == -1) - { - perror (name); - close (mod_fd); - return 0; - } - - if (read (mod_fd, patterns, 1024) != 1024) - { - fprintf (stderr, "Short file (pattern %d) %d\n", tune[position], pp); - close (mod_fd); - return 0; - } - - if ((pattern_table[position] = (pattern *) malloc (sizeof (struct note_info) * 64 * nr_channels)) == NULL) - { - fprintf (stderr, "Can't allocate memory for a pattern\n"); - return 0; - } - - for (pat = 0; pat < 64; pat++) - { - for (channel = 0; channel < 4; channel++) - { - unsigned short tmp; - unsigned char *p; - - unsigned period, sample, effect, params, note, vol; - - p = &patterns[pat][channel][0]; - - tmp = (p[0] << 8) | p[1]; - sample = (tmp >> 8) & 0x10; - period = - MIN (tmp & 0xFFF, 1023); - tmp = (p[2] << 8) | p[3]; - sample |= tmp >> 12; - effect = (tmp >> 8) & 0xF; - params = tmp & 0xFF; - - note = 0; - - if (period) - { - /* - * Convert period to a Midi note number - */ - - for (note = 0; note < 37 && period != period_table[note]; note++); - if (note >= 37) - note = 0; - - note += 48; - } - - vol = 64; - - if (sample) - if (effect == 0xc) - { - vol = params; - } - else - vol = sample_vol[sample - 1]; - - vol *= 2; - if (vol>64)vol--; - - (*pattern_table[position])[channel][pat].note = note; - (*pattern_table[position])[channel][pat].sample = sample; - (*pattern_table[position])[channel][pat].command = effect; - (*pattern_table[position])[channel][pat].parm1 = params; - (*pattern_table[position])[channel][pat].parm2 = 0; - (*pattern_table[position])[channel][pat].vol = vol; - } - } - } - - close (mod_fd); - return 1; -} - -int -panning (int ch) -{ - static int panning_tab[] = - {-110, 110, 110, -110}; - - return panning_tab[ch % 4]; -} - -void -set_speed (int parm) -{ - if (!parm) - parm = 1; - - if (parm < 32) - { - ticks_per_division = parm; - } - else - { - tick_duration = (60.0 / parm) * 10.0; - } - -} - -void -play_module (char *name) -{ - int i, position, jump_to_pos; - - init_voices (); - - SEQ_START_TIMER (); -#if 1 - for (i=0;i<32;i++) - { - SEQ_EXPRESSION(gus_dev, i, 127); - SEQ_MAIN_VOLUME(gus_dev, i, 100); - } -#endif - next_time = 0.0; - - set_speed (6); - - for (position = 0; position < songlength; position++) - { - int tick, pattern, channel, pos, go_to; - - pos = tune[position]; - if (pattern_tempo[position]) - set_speed (pattern_tempo[position]); - - jump_to_pos = -1; - for (pattern = 0; pattern < pattern_len[position] && jump_to_pos == -1; pattern++) - { - this_time = 0.0; - - for (channel = 0; channel < nr_channels; channel++) - { - if ((go_to = play_note (channel, &(*pattern_table[pos])[channel][pattern])) != -1) - jump_to_pos = go_to; - - } - - next_time += tick_duration; - - for (tick = 1; tick < ticks_per_division; tick++) - { - for (channel = 0; channel < nr_channels; channel++) - lets_play_voice (channel, &voices[channel]); - next_time += tick_duration; - } - - } - - if (jump_to_pos >= 0) - position = jump_to_pos; - } - - SEQ_WAIT_TIME ((int) next_time + 200); /* Wait extra 2 secs */ - - for (i = 0; i < nr_channels; i++) - SEQ_STOP_NOTE (gus_dev, i, 0, 127); - SEQ_DUMPBUF (); - - for (i = 0; i < nr_patterns; i++) - free (pattern_table[i]); -} - -void -sync_time () -{ - if (next_time > this_time) - { - SEQ_WAIT_TIME ((long) next_time); - this_time = next_time; - } -} - -void -set_volslide (int channel, struct note_info *pat) -{ - int n; - - voices[channel].volslide = 0; - - if ((n = (pat->parm1 & 0xf0) >> 4)) - voices[channel].volslide = n; - else - voices[channel].volslide = pat->parm1 & 0xf; -} - -void -set_slideto (int channel, struct note_info *pat) -{ - int size, rate, dir, range = 200; - - rate = pat->parm1; - size = voices[channel].note - pat->note; - if (!size) - return; - - if (size < 0) - { - size *= -1; - dir = -1; - } - else - dir = 1; - - if (size > 2) - { - range = size * 100; - rate = rate * size / 200; - } - - rate = pat->parm1 * dir / 30; - if (!rate) - rate = 1; - - voices[channel].slide_pitch = 1; - voices[channel].slide_goal = (dir * 8192 * 200 * 2 / size) / range; - voices[channel].pitchbender = 0; - voices[channel].slide_rate = rate; - SEQ_BENDER_RANGE (gus_dev, channel, range); -} - -int -play_note (int channel, struct note_info *pat) -{ - int jump = -1; - int sample; - - if (pat->sample == 0x3f) - pat->sample = 0; - - if (pat->command == CMD_NONOTE) - return -1; /* Undefined */ - - sample = pat->sample; - - if (sample && !pat->note) - { - pat->note = voices[channel].note; - } - - if (sample) - voices[channel].sample = sample; - else - sample = voices[channel].sample; - - sample--; - - if (pat->note && pat->command != 3) /* Have a note -> play */ - { - if (sample < 0) - sample = voices[channel].sample - 1; - - if (!sample_ok[sample]) - sample = voices[channel].sample - 1; - - if (sample < 0) - sample = 0; - - if (sample_ok[sample]) - { - sync_time (); - - if (pat->vol > 127) pat->vol=127; - SEQ_SET_PATCH (gus_dev, channel, sample); - SEQ_PANNING (gus_dev, channel, panning (channel)); - SEQ_PITCHBEND (gus_dev, channel, 0); - SEQ_START_NOTE (gus_dev, channel, pat->note, pat->vol); - - voices[channel].volume = pat->vol; - voices[channel].note = pat->note; - voices[channel].slide_pitch = 0; - } - else - SEQ_STOP_NOTE (gus_dev, channel, pat->note, pat->vol); - } - - switch (pat->command) - { - - case CMD_NOP:; - break; - - case CMD_JUMP: - jump = pat->parm1; - break; - - case CMD_BREAK: - jump = -2; - break; - - case CMD_SPEED: - set_speed (pat->parm1); - break; - - case CMD_SLIDEUP: - voices[channel].slide_pitch = 1; - voices[channel].slide_goal = 8191; - voices[channel].pitchbender = 0; - voices[channel].slide_rate = pat->parm1 * SLIDE_SIZE; - SEQ_BENDER_RANGE (gus_dev, channel, 200); - break; - - case CMD_SLIDEDOWN: - voices[channel].slide_pitch = 1; - voices[channel].slide_goal = -8192; - voices[channel].pitchbender = 0; - voices[channel].slide_rate = -pat->parm1 * SLIDE_SIZE; - SEQ_BENDER_RANGE (gus_dev, channel, 200); - break; - - case CMD_SLIDETO: - set_slideto (channel, pat); - break; - - case CMD_VOLUME: - { - int vol = pat->parm1*2; - if (vol>127) vol=127; - if (pat->note && pat->command != 3) - break; - SEQ_START_NOTE (gus_dev, channel, 255, vol); - } - break; - - case CMD_ARPEG: - break; - - case 0x0e: - /* printf ("Cmd 0xE%02x\n", pat->parm1); */ - break; - - case CMD_VOLSLIDE: - set_slideto (channel, pat); - break; - - default: - /* printf ("Command %x %02x\n", pat->command, pat->parm1); */ - } - - return jump; -} - -void -lets_play_voice (int channel, struct voice_info *v) -{ - if (v->slide_pitch) - { - v->pitchbender += v->slide_rate; - if (v->slide_goal < 0) - { - if (v->pitchbender <= v->slide_goal) - { - v->pitchbender = v->slide_goal; - v->slide_pitch = 0; /* Stop */ - } - } - else - { - if (v->pitchbender >= v->slide_goal) - { - v->pitchbender = v->slide_goal; - v->slide_pitch = 0; /* Stop */ - } - } - - sync_time (); - SEQ_PITCHBEND (gus_dev, channel, v->pitchbender); - } - - if (v->volslide) - { - v->volume += v->volslide; - sync_time (); - - if (v->volume > 127) v->volume = 127; - SEQ_START_NOTE (gus_dev, channel, 255, v->volume); - } -} diff --git a/sys/i386/isa/sound/gustest/gpatinfo.c b/sys/i386/isa/sound/gustest/gpatinfo.c deleted file mode 100644 index 3e21fc5..0000000 --- a/sys/i386/isa/sound/gustest/gpatinfo.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * gpatinfo.c: This program demonstrates the patch management - * interface of the GUS driver. - * - * NOTE! The patch manager interface is highly device dependent, - * currently incompletely implemented prototype and - * will change before final implementation. - * - */ - -#include <stdio.h> -#include <sys/ultrasound.h> -#include <sys/ioctl.h> -#include <stdlib.h> -#include <strings.h> -#include <unistd.h> -#include <fcntl.h> -#include "gmidi.h" - -#define GUS_DEV gus_dev - -#define patch_access(cmd, rec) \ - rec.command = cmd;\ - rec.device = gus_dev;\ - if (ioctl(seqfd, SNDCTL_PMGR_IFACE, &rec)==-1)\ - {\ - perror("/dev/sequencer(SNDCTL_PMGR_IFACE/" #cmd ")");\ - exit(-1);\ - } - -SEQ_DEFINEBUF (2048); - -int seqfd; - -int gus_dev = -1; - -/* - * The function seqbuf_dump() must always be provided - */ - -void -seqbuf_dump () -{ - if (_seqbufptr) - if (write (seqfd, _seqbuf, _seqbufptr) == -1) - { - perror ("write /dev/sequencer"); - exit (-1); - } - _seqbufptr = 0; -} - -int -main (int argc, char *argv[]) -{ - int i, j, n; - struct synth_info info; - struct patch_info *patch; - struct patmgr_info mgr, mgr2, mgr3; - - if ((seqfd = open ("/dev/sequencer", O_WRONLY, 0)) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - if (ioctl (seqfd, SNDCTL_SEQ_NRSYNTHS, &n) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - -/* - * First locate the GUS device - */ - - for (i = 0; i < n; i++) - { - info.device = i; - - if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - if (info.synth_type == SYNTH_TYPE_SAMPLE - && info.synth_subtype == SAMPLE_TYPE_GUS) - gus_dev = i; - } - - if (gus_dev == -1) - { - fprintf (stderr, "Error: Gravis Ultrasound not detected\n"); - exit (-1); - } - - printf("Gravis UltraSound device = %d\n", gus_dev); - - /* - * Get type of the Patch Manager interface of the GUS device - */ - - patch_access(PM_GET_DEVTYPE, mgr); - printf("Patch manager type: %d\n", mgr.parm1); - - if (mgr.parm1 != PMTYPE_WAVE) - { - fprintf(stderr, "Hups, this program seems to be obsolete\n"); - exit(-1); - } - - /* - * The GUS driver supports up to 256 different midi program numbers but - * this limit can be changed before compiling the driver. The following - * call returns the value compiled to the driver. - */ - - patch_access(PM_GET_PGMMAP, mgr); - printf("Device supports %d midi programs.\n", mgr.parm1); - - /* - * Each program can be undefined or it may have one or more patches. - * A patch consists of header and the waveform data. If there is more - * than one patch in a program, the right one is selected by checking the - * note number when the program is played. - * - * The following call reads an array indexed by program number. Each - * element defines the number of patches defined for the corresponding - * program. - */ - printf("Loaded programs:\n"); - - for (i=0;i<mgr.parm1;i++) - if (mgr.data.data8[i]) - { - printf("%03d: %2d patches\n", i, mgr.data.data8[i]); - - /* - * Next get the magic keys of the patches associated with this program. - * This key can be used to access the patc data. - */ - mgr2.parm1=i; - patch_access(PM_GET_PGM_PATCHES, mgr2); - for (j = 0;j<mgr2.parm1;j++) - { - printf("\tPatch %d: %3d ", j, mgr2.data.data32[j]); - - /* - * The last step is to read the patch header (without wave data). - * The header is returned in the mgr3.data. The field parm1 returns - * address of the wave data in tge GUS DRAM. Parm2 returns - * size of the struct patch_info in the kernel. - * - * There is also the PM_SET_PATCH call which allows modification of the - * header data. The only limitation is that the sample len cannot be - * increased. - */ - mgr3.parm1 = mgr2.data.data32[j]; - patch_access(PM_GET_PATCH, mgr3); - patch = (struct patch_info *)&mgr3.data; /* Pointer to the patch hdr */ - - printf("DRAM ptr = %7d, sample len =%6d bytes.\n", - mgr3.parm1, patch->len); - - } - } - - i = gus_dev; - - if (ioctl(seqfd, SNDCTL_SYNTH_MEMAVL, &i)==-1) exit(-1); - printf("%d bytes of DRAM available for wave data\n", i); - - - exit(0); -} diff --git a/sys/i386/isa/sound/gustest/gusload.c b/sys/i386/isa/sound/gustest/gusload.c deleted file mode 100644 index 216150a..0000000 --- a/sys/i386/isa/sound/gustest/gusload.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * patutil.c - A sample program which loads patches to the Gravis - * Ultrasound - * - */ - -#ifndef PATCH_PATH -#define PATCH_PATH "/D/ultrasnd/midi" -#endif - -#include <stdio.h> -#include <sys/ultrasound.h> -#include <sys/ioctl.h> -#include <stdlib.h> -#include <strings.h> -#include <unistd.h> -#include <fcntl.h> -#include "gmidi.h" - -struct pat_header - { - char magic[12]; - char version[10]; - char description[60]; - unsigned char instruments; - char voices; - char channels; - unsigned short nr_waveforms; - unsigned short master_volume; - unsigned long data_size; - }; - -struct sample_header - { - char name[7]; - unsigned char fractions; - long len; - long loop_start; - long loop_end; - unsigned short base_freq; - long low_note; - long high_note; - long base_note; - short detune; - unsigned char panning; - - unsigned char envelope_rate[6]; - unsigned char envelope_offset[6]; - - unsigned char tremolo_sweep; - unsigned char tremolo_rate; - unsigned char tremolo_depth; - - unsigned char vibrato_sweep; - unsigned char vibrato_rate; - unsigned char vibrato_depth; - - char modes; - - short scale_frequency; - unsigned short scale_factor; - }; - -#define GUS_DEV gus_dev - -SEQ_DEFINEBUF (2048); - -int seqfd; - -int gus_dev = -1; - -struct patch_info *patch; - -/* - * The function seqbuf_dump() must always be provided - */ - -void -seqbuf_dump () -{ - if (_seqbufptr) - if (write (seqfd, _seqbuf, _seqbufptr) == -1) - { - perror ("write /dev/sequencer"); - exit (-1); - } - _seqbufptr = 0; -} - -int -main (int argc, char *argv[]) -{ - int i, n, patfd, pgm, print_only = 0; - struct synth_info info; - struct pat_header header; - struct sample_header sample; - char buf[256]; - char name[256]; - long offset; - - if ((seqfd = open ("/dev/sequencer", O_WRONLY, 0)) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - if (ioctl (seqfd, SNDCTL_SEQ_NRSYNTHS, &n) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - - for (i = 0; i < n; i++) - { - info.device = i; - - if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1) - { - perror ("/dev/sequencer"); - exit (-1); - } - - if (info.synth_type == SYNTH_TYPE_SAMPLE - && info.synth_subtype == SAMPLE_TYPE_GUS) - gus_dev = i; - } - - if (gus_dev == -1) - { - fprintf (stderr, "Error: Gravis Ultrasound not detected\n"); - exit (-1); - } - - if (argc == 2) - { - if (!strcmp (argv[1], "reset")) - if (ioctl (seqfd, SNDCTL_SEQ_RESETSAMPLES, &gus_dev) == -1) - perror ("Sample reset"); - exit (0); - } - - if (argc != 3) - { - fprintf (stderr, "Usage: %s pgm# patchfile\n", argv[0]); - fprintf (stderr, " or : %s pgm# GM\n", argv[0]); - fprintf (stderr, " or : %s pgm# -l\n", argv[0]); - fprintf (stderr, " or : %s reset\n", argv[0]); - fprintf (stderr, " or : %s -l patchfile\n", argv[0]); - exit (-1); - } - - pgm = atoi (argv[1]); - strcpy (name, argv[2]); - - if (strcmp (name, "GM") == 0 || strcmp(name, "-l")==0) - { - if (strcmp (name, "-l") == 0) print_only = 1; - if (pgm < 0 || pgm > 127) - { - fprintf (stderr, "pgm# must be between 0 and 127\n"); - exit (-1); - } - - sprintf (name, PATCH_PATH "/%s.pat", patch_names[pgm]); - - if (!print_only) - fprintf (stderr, "Loading program %d from %s\n", pgm, name); - } - else if (strcmp (argv[1], "-l") == 0) - print_only = 1; - - if ((patfd = open (name, O_RDONLY, 0)) == -1) - { - perror (name); - exit (-1); - } - - if (read (patfd, buf, 0xef) != 0xef) - { - fprintf (stderr, "%s: Short file\n", name); - exit (-1); - } - - memcpy ((char *) &header, buf, sizeof (header)); - - if (strncmp (header.magic, "GF1PATCH110", 12)) - { - fprintf (stderr, "%s: Not a patch file\n", name); - exit (-1); - } - - if (strncmp (header.version, "ID#000002", 10)) - { - fprintf (stderr, "%s: Incompatible patch file version\n", name); - exit (-1); - } - - header.nr_waveforms = *(unsigned short *) &buf[85]; - header.master_volume = *(unsigned short *) &buf[87]; - - if (print_only) - { - printf ("Patch file: %s contains %d samples\n\n", name, header.nr_waveforms); - printf ("Master volume: %d\n", header.master_volume); - } - - offset = 0xef; - - for (i = 0; i < header.nr_waveforms; i++) - { - if (lseek (patfd, offset, 0) == -1) - { - perror (name); - exit (-1); - } - - if (read (patfd, &buf, sizeof (sample)) != sizeof (sample)) - { - fprintf (stderr, "%s: Short file\n", name); - exit (-1); - } - - memcpy ((char *) &sample, buf, sizeof (sample)); - - /* - * Since some fields of the patch record are not 32bit aligned, we must - * handle them specially. - */ - sample.low_note = *(long *) &buf[22]; - sample.high_note = *(long *) &buf[26]; - sample.base_note = *(long *) &buf[30]; - sample.detune = *(short *) &buf[34]; - sample.panning = (unsigned char) buf[36]; - - memcpy (sample.envelope_rate, &buf[37], 6); - memcpy (sample.envelope_offset, &buf[43], 6); - - sample.tremolo_sweep = (unsigned char) buf[49]; - sample.tremolo_rate = (unsigned char) buf[50]; - sample.tremolo_depth = (unsigned char) buf[51]; - - sample.vibrato_sweep = (unsigned char) buf[52]; - sample.vibrato_rate = (unsigned char) buf[53]; - sample.vibrato_depth = (unsigned char) buf[54]; - sample.modes = (unsigned char) buf[55]; - sample.scale_frequency = *(short *) &buf[56]; - sample.scale_factor = *(unsigned short *) &buf[58]; - - if (print_only) - { - printf("\nSample: %03d / %s\n", i, sample.name); - printf ("Len: %d, Loop start: %d, Loop end: %d\n", sample.len, sample.loop_start, sample.loop_end); - printf ("Flags: "); - if (sample.modes & WAVE_16_BITS) - printf ("16 bit "); - if (sample.modes & WAVE_UNSIGNED) - printf ("unsigned "); - if (sample.modes & WAVE_LOOP_BACK) - printf("reverse "); - if (sample.modes & WAVE_BIDIR_LOOP) - printf("bidir "); - if (sample.modes & WAVE_LOOPING) - printf ("looping "); else printf("one_shot" ); - if (sample.modes & WAVE_SUSTAIN_ON) - printf ("sustain "); - if (sample.modes & WAVE_ENVELOPES) - printf ("enveloped "); - printf ("\n"); - - if (sample.modes & WAVE_ENVELOPES) - { - int i; - - printf ("Envelope info: "); - for (i = 0; i < 6; i++) - { - printf ("%d/%d ", sample.envelope_rate[i], - sample.envelope_offset[i]); - } - printf ("\n"); - } - - printf("Tremolo: sweep=%d, rate=%d, depth=%d\n", - sample.tremolo_sweep, - sample.tremolo_rate, - sample.tremolo_depth); - - printf("Vibrato: sweep=%d, rate=%d, depth=%d\n", - sample.vibrato_sweep, - sample.vibrato_rate, - sample.vibrato_depth); - } - - offset = offset + 96; - patch = (struct patch_info *) malloc (sizeof (*patch) + sample.len); - - patch->key = GUS_PATCH; - patch->device_no = GUS_DEV; - patch->instr_no = pgm; - patch->mode = sample.modes | WAVE_TREMOLO | - WAVE_VIBRATO | WAVE_SCALE; - patch->len = sample.len; - patch->loop_start = sample.loop_start; - patch->loop_end = sample.loop_end; - patch->base_note = sample.base_note; - patch->high_note = sample.high_note; - patch->low_note = sample.low_note; - patch->base_freq = sample.base_freq; - patch->detuning = sample.detune; - patch->panning = (sample.panning - 7) * 16; - - memcpy (patch->env_rate, sample.envelope_rate, 6); - memcpy (patch->env_offset, sample.envelope_offset, 6); - - patch->tremolo_sweep = sample.tremolo_sweep; - patch->tremolo_rate = sample.tremolo_rate; - patch->tremolo_depth = sample.tremolo_depth; - - patch->vibrato_sweep = sample.vibrato_sweep; - patch->vibrato_rate = sample.vibrato_rate; - patch->vibrato_depth = sample.vibrato_depth; - - patch->scale_frequency = sample.scale_frequency; - patch->scale_factor = sample.scale_factor; - - patch->volume = header.master_volume; - - if (lseek (patfd, offset, 0) == -1) - { - perror (name); - exit (-1); - } - - if (!print_only) - { - if (read (patfd, patch->data, sample.len) != sample.len) - { - fprintf (stderr, "%s: Short file\n", name); - exit (-1); - } - - SEQ_WRPATCH (patch, sizeof (*patch) + sample.len); - } - - offset = offset + sample.len; - } - - exit (0); -} diff --git a/sys/i386/isa/sound/gustest/midithru.c b/sys/i386/isa/sound/gustest/midithru.c deleted file mode 100644 index 36e1e07..0000000 --- a/sys/i386/isa/sound/gustest/midithru.c +++ /dev/null @@ -1,325 +0,0 @@ -#include <stdio.h> -#include <sys/soundcard.h> -#include <unistd.h> -#include <fcntl.h> -#include <stdlib.h> -#include <sys/errno.h> - -SEQ_DEFINEBUF (2048); -SEQ_PM_DEFINES; - -int seqfd, dev = 0; -unsigned char buf[100]; -int bufp; - -/* LRU list for free operators */ - -unsigned char free_list[256]; -int fhead=0, ftail=0, flen=0; - -/* LRU list for still playing notes */ - -unsigned char note_list[256]; -int nhead=0, ntail=0, nlen=0; -unsigned char oper_note[32]; - -int pgm = 0; -int num_voices; -int bender = 0; /* Initially off */ - -void -seqbuf_dump () -{ - if (_seqbufptr) - if (write (seqfd, _seqbuf, _seqbufptr) == -1) - { - perror ("write /dev/sequencer"); - exit (-1); - } - _seqbufptr = 0; -} - -void -stop_note(int note, int velocity) -{ - int i, op; - - op=255; - - for (i=0;i<num_voices && op==255;i++) - { - if (oper_note[i]== note) op=i; - } - - if (op==255) - { - fprintf(stderr, "Note %d off, note not started\n", note); - fprintf(stderr, "%d, %d\n", flen, nlen); - return; /* Has already been killed ??? */ - } - - SEQ_STOP_NOTE(dev, op, note, velocity); - SEQ_DUMPBUF(); - - oper_note[op] = 255; - - free_list[ftail]=op; - flen++; - ftail = (ftail+1) % num_voices; - - for (i=0;i<16;i++) - if (note_list[i] == op) note_list[i] = 255; - - while (nlen && note_list[nhead] == 255) - { - nlen--; - /* printf("Remove from note queue %d, len %d\n", nhead, nlen); */ - nhead = (nhead+1) % 256; - } -} - -void -kill_one_note() -{ - int oldest; - - if (!nlen) {fprintf(stderr, "Free list empty but no notes playing\n");return;} /* No notes playing */ - - oldest = note_list[nhead]; - nlen--; - nhead = (nhead+1) % 256; - - fprintf(stderr, "Killing oper %d, note %d\n", oldest, oper_note[oldest]); - - if (oldest== 255) return; /* Was already stopped. Why? */ - - stop_note(oper_note[oldest], 127); -} - -void -start_note(int note, int velocity) -{ - int free; - - if (!flen) kill_one_note(); - - if (!flen) {printf("** no free voices\n");return;} /* Panic??? */ - - free = free_list[fhead]; - flen--; - fhead = (fhead+1) % num_voices; - - note_list[ntail] = free; - - if (nlen>255) - { -#if 0 - fprintf(stderr, "Note list overflow %d, %d, %d\n", - nlen, nhead, ntail); -#endif - nlen=0; /* Overflow -> hard reset */ - } - nlen++; - ntail = (ntail+1) % 256; - - oper_note[free] = note; - - SEQ_SET_PATCH(dev, free, pgm); - SEQ_PITCHBEND(dev, free, bender); - SEQ_START_NOTE(dev, free, note, velocity); - SEQ_DUMPBUF(); -} - -void -channel_pressure(int ch, int pressure) -{ - int i; - - for (i=0;i<num_voices;i++) - { - if (oper_note[i] != 255) - { -#if 1 - SEQ_CHN_PRESSURE(dev, i, pressure); -#else - SEQ_EXPRESSION(dev, i, pressure); -#endif - SEQ_DUMPBUF(); - } - } -} - -void -pitch_bender(int ch, int value) -{ - int i; - - value -= 8192; - - bender = value; - - for (i=0;i<num_voices;i++) - { - if (oper_note[i] != 255) - { - bender = value; - SEQ_PITCHBEND(dev, i, value); - SEQ_DUMPBUF(); - } - } -} - -void -do_buf() -{ - int ch = buf[0] & 0x0f; - int value; - - switch (buf[0] & 0xf0) - { - case 0x90: /* Note on */ - if (bufp < 3) break; - /* printf("Note on %d %d %d\n", ch, buf[1], buf[2]); */ - if (buf[2]) - start_note(buf[1], buf[2]); - else - stop_note(buf[1], buf[2]); - bufp=1; - break; - - case 0xb0: /* Control change */ - if (bufp < 3) break; - /* printf("Control change %d %d %d\n", ch, buf[1], buf[2]); */ - bufp=1; - break; - - case 0x80: /* Note off */ - if (bufp < 3) break; - /* printf("Note off %d %d %d\n", ch, buf[1], buf[2]); */ - stop_note(buf[1], buf[2]); - bufp=1; - break; - - case 0xe0: /* Pitch bender */ - if (bufp < 3) break; - value = ((buf[2] & 0x7f) << 7) | (buf[1] & 0x7f); - /* printf("Pitch bender %d %d\n", ch, value >> 7); */ - pitch_bender(ch, value); - bufp=1; - break; - - case 0xc0: /* Pgm change */ - if (bufp < 2) break; - /* printf("Pgm change %d %d\n", ch, buf[1]); */ - pgm = buf[1]; - if (PM_LOAD_PATCH(dev, 0, pgm) < 0) - if (errno != ESRCH) /* No such process */ - perror("PM_LOAD_PATCH"); - bufp=0; - break; - - case 0xd0: /* Channel pressure */ - if (bufp < 2) break; - /* printf("Channel pressure %d %d\n", ch, buf[1]); */ - channel_pressure(ch, buf[1]); - bufp=1; - break; - - default: - bufp=0; - } -} - -int -main (int argc, char *argv[]) -{ - int i, n, max_voice = 999; - - struct synth_info info; - - unsigned char ev[4], *p; - - if (argc >= 2) dev = atoi(argv[1]); - - for (i=0;i<16;i++) oper_note[i] = 255; - - if ((seqfd = open ("/dev/sequencer", O_RDWR, 0)) == -1) - { - perror ("open /dev/sequencer"); - exit (-1); - } - - if (argc >= 3) - { - int d = dev; - ioctl(seqfd, SNDCTL_FM_4OP_ENABLE, &d); - } - - info.device = dev; - - if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &info)==-1) - { - perror ("info /dev/sequencer"); - exit (-1); - } - - num_voices = info.nr_voices; - if (num_voices>max_voice)num_voices = max_voice; - fprintf(stderr, "Output to synth device %d (%s)\n", dev, info.name); - fprintf(stderr, "%d voices available\n", num_voices); - - for (i=0;i<num_voices;i++) - { - flen++; - free_list[fhead] = i; - fhead = (fhead+1) % num_voices; - } - - bufp = 0; - if (PM_LOAD_PATCH(dev, 0, 0) < 0) /* Load the default instrument */ - if (errno != ESRCH) /* No such process */ - perror("PM_LOAD_PATCH"); - - while (1) - { - if ((n = read (seqfd, ev, sizeof (ev))) == -1) - { - perror ("read /dev/sequencer"); - exit (-1); - } - - for (i = 0; i <= (n / 4); i++) - { - p = &ev[i * 4]; - - if (p[0] == SEQ_MIDIPUTC && p[2] == 0 /* Midi if# == 0 */) - { -/* printf("%02x ", p[1]);fflush(stdout); */ - if (p[1] & 0x80) /* Status */ - { - if (bufp) - do_buf (); - buf[0] = p[1]; - bufp = 1; - } - else if (bufp) - { - buf[bufp++] = p[1]; - if ((buf[0] & 0xf0) == 0x90 || (buf[0] & 0xf0) == 0x80 || (buf[0] & 0xf0) == 0xb0 || - (buf[0] & 0xf0) == 0xe0) - { - if (bufp == 3) - do_buf (); - } - else - if ((buf[0] & 0xf0) == 0xc0 || (buf[0] & 0xf0) == 0xd0) - { - if (bufp == 2) do_buf(); - } - } - } - } - } - - exit (0); -} diff --git a/sys/i386/isa/sound/gustest/pmtest.c b/sys/i386/isa/sound/gustest/pmtest.c deleted file mode 100644 index 3b6b1d5..0000000 --- a/sys/i386/isa/sound/gustest/pmtest.c +++ /dev/null @@ -1,411 +0,0 @@ -/* - * CAUTION! This program is just an incompletely implemented version - * of the patch manager daemon for GUS. Using this program - * with the driver version 1.99.9 will hang your system - * completely (sooner or later). - * - * This program is for information only. The final - * implementation of the patch manager will not be - * compatible with this one. - */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <sys/soundcard.h> -#include <sys/ultrasound.h> -#include <strings.h> -#include <sys/errno.h> -#include "gmidi.h" - -#ifndef PATCH_PATH -#define PATCH_PATH "/D/ultrasnd/midi" -#endif - -char loadmap[256] = -{0}; /* 1 if the patch is already loaded */ - -struct pat_header - { - char magic[12]; - char version[10]; - char description[60]; - unsigned char instruments; - char voices; - char channels; - unsigned short nr_waveforms; - unsigned short master_volume; - unsigned long data_size; - }; - -struct sample_header - { - char name[7]; - unsigned char fractions; - long len; - long loop_start; - long loop_end; - unsigned short base_freq; - long low_note; - long high_note; - long base_note; - short detune; - unsigned char panning; - - unsigned char envelope_rate[6]; - unsigned char envelope_offset[6]; - - unsigned char tremolo_sweep; - unsigned char tremolo_rate; - unsigned char tremolo_depth; - - unsigned char vibrato_sweep; - unsigned char vibrato_rate; - unsigned char vibrato_depth; - - char modes; - - short scale_frequency; - unsigned short scale_factor; - }; -int seqfd = 0, gus_dev = -1; - -struct patch_info *patch; - -int -do_load_patch (struct patmgr_info *rec) -{ - int i, patfd, pgm, print_only = 0; - struct pat_header header; - struct sample_header sample; - char buf[256]; - char name[256]; - long offset; - - pgm = rec->data.data8[0]; - - if (loadmap[pgm]) - return 0; /* Already loaded */ - - sprintf (name, PATCH_PATH "/%s.pat", patch_names[pgm]); - - if ((patfd = open (name, O_RDONLY, 0)) == -1) - { - perror (name); - return errno; - } - - if (read (patfd, buf, 0xef) != 0xef) - { - fprintf (stderr, "%s: Short file\n", name); - return EIO; - } - - memcpy ((char *) &header, buf, sizeof (header)); - - if (strncmp (header.magic, "GF1PATCH110", 12)) - { - fprintf (stderr, "%s: Not a patch file\n", name); - return EINVAL; - } - - if (strncmp (header.version, "ID#000002", 10)) - { - fprintf (stderr, "%s: Incompatible patch file version\n", name); - return EINVAL; - } - - header.nr_waveforms = *(unsigned short *) &buf[85]; - header.master_volume = *(unsigned short *) &buf[87]; - - printf ("GUS: Loading: %s\n", name); - - offset = 0xef; - - for (i = 0; i < header.nr_waveforms; i++) - { - if (lseek (patfd, offset, 0) == -1) - { - perror (name); - return errno; - } - - if (read (patfd, &buf, sizeof (sample)) != sizeof (sample)) - { - fprintf (stderr, "%s: Short file\n", name); - return EIO; - } - - memcpy ((char *) &sample, buf, sizeof (sample)); - - /* - * Since some fields of the patch record are not 32bit aligned, we must - * handle them specially. - */ - sample.low_note = *(long *) &buf[22]; - sample.high_note = *(long *) &buf[26]; - sample.base_note = *(long *) &buf[30]; - sample.detune = *(short *) &buf[34]; - sample.panning = (unsigned char) buf[36]; - - memcpy (sample.envelope_rate, &buf[37], 6); - memcpy (sample.envelope_offset, &buf[43], 6); - - sample.tremolo_sweep = (unsigned char) buf[49]; - sample.tremolo_rate = (unsigned char) buf[50]; - sample.tremolo_depth = (unsigned char) buf[51]; - - sample.vibrato_sweep = (unsigned char) buf[52]; - sample.vibrato_rate = (unsigned char) buf[53]; - sample.vibrato_depth = (unsigned char) buf[54]; - sample.modes = (unsigned char) buf[55]; - sample.scale_frequency = *(short *) &buf[56]; - sample.scale_factor = *(unsigned short *) &buf[58]; - - if (print_only) - { - printf ("\nSample: %03d / %s\n", i, sample.name); - printf ("Len: %d, Loop start: %d, Loop end: %d\n", sample.len, sample.loop_start, sample.loop_end); - printf ("Flags: "); - if (sample.modes & WAVE_16_BITS) - printf ("16 bit "); - if (sample.modes & WAVE_UNSIGNED) - printf ("unsigned "); - if (sample.modes & WAVE_LOOP_BACK) - printf ("reverse "); - if (sample.modes & WAVE_BIDIR_LOOP) - printf ("bidir "); - if (sample.modes & WAVE_LOOPING) - printf ("looping "); - else - printf ("one_shot"); - if (sample.modes & WAVE_SUSTAIN_ON) - printf ("sustain "); - if (sample.modes & WAVE_ENVELOPES) - printf ("enveloped "); - printf ("\n"); - - if (sample.modes & WAVE_ENVELOPES) - { - int i; - - printf ("Envelope info: "); - for (i = 0; i < 6; i++) - { - printf ("%d/%d ", sample.envelope_rate[i], - sample.envelope_offset[i]); - } - printf ("\n"); - } - - printf ("Tremolo: sweep=%d, rate=%d, depth=%d\n", - sample.tremolo_sweep, - sample.tremolo_rate, - sample.tremolo_depth); - - printf ("Vibrato: sweep=%d, rate=%d, depth=%d\n", - sample.vibrato_sweep, - sample.vibrato_rate, - sample.vibrato_depth); - } - - offset = offset + 96; - patch = (struct patch_info *) malloc (sizeof (*patch) + sample.len); - - patch->key = GUS_PATCH; - patch->device_no = gus_dev; - patch->instr_no = pgm; - patch->mode = sample.modes | WAVE_TREMOLO | - WAVE_VIBRATO | WAVE_SCALE; - patch->len = sample.len; - patch->loop_start = sample.loop_start; - patch->loop_end = sample.loop_end; - patch->base_note = sample.base_note; - patch->high_note = sample.high_note; - patch->low_note = sample.low_note; - patch->base_freq = sample.base_freq; - patch->detuning = sample.detune; - patch->panning = (sample.panning - 7) * 16; - - memcpy (patch->env_rate, sample.envelope_rate, 6); - memcpy (patch->env_offset, sample.envelope_offset, 6); - - patch->tremolo_sweep = sample.tremolo_sweep; - patch->tremolo_rate = sample.tremolo_rate; - patch->tremolo_depth = sample.tremolo_depth; - - patch->vibrato_sweep = sample.vibrato_sweep; - patch->vibrato_rate = sample.vibrato_rate; - patch->vibrato_depth = sample.vibrato_depth; - - patch->scale_frequency = sample.scale_frequency; - patch->scale_factor = sample.scale_factor; - - patch->volume = header.master_volume; - - if (lseek (patfd, offset, 0) == -1) - { - perror (name); - return errno; - } - - if (!print_only) - { - if (read (patfd, patch->data, sample.len) != sample.len) - { - fprintf (stderr, "%s: Short file\n", name); - return EIO; - } - - if (write (seqfd, patch, sizeof (*patch) + sample.len) == -1) - { - perror ("/dev/pmgr0"); - return errno; - } - } - - offset = offset + sample.len; - } - - loadmap[pgm] = 1; - return 0; -} - -int -main (int argc, char *argv[]) -{ - struct patmgr_info inf; - int err, i, n; - struct synth_info info; - - if ((seqfd = open ("/dev/patmgr0", O_RDWR, 0)) == -1) - { - fprintf (stderr, "Cannot open\n"); - perror ("/dev/patmgr0"); - exit (-1); - } - - if (ioctl (seqfd, SNDCTL_SEQ_NRSYNTHS, &n) == -1) - { - perror ("NRSYNTH: /dev/patmgr0"); - exit (-1); - } - - for (i = 0; i < n; i++) - { - info.device = i; - - if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1) - { - perror ("SYNTH_INFO: /dev/patmgr0"); - exit (-1); - } - - if (info.synth_type == SYNTH_TYPE_SAMPLE - && info.synth_subtype == SAMPLE_TYPE_GUS) - gus_dev = i; - } - - if (gus_dev == -1) - { - fprintf (stderr, "Error: Gravis Ultrasound not detected\n"); - exit (-1); - } - - if (ioctl (seqfd, SNDCTL_SEQ_RESETSAMPLES, &gus_dev) == -1) - perror ("Sample reset"); - - for (i = 0; i < 256; i++) - loadmap[i] = 0; - - while (1) - { - if (read (seqfd, (char *) &inf, sizeof (inf)) != sizeof (inf)) - { - perror ("Read"); - exit (-1); - } - - if (inf.key == PM_K_EVENT) - switch (inf.command) - { - case PM_E_OPENED: - printf ("Opened\n"); - break; - - case PM_E_CLOSED: - printf ("Closed\n"); - if (ioctl (seqfd, SNDCTL_SEQ_RESETSAMPLES, &gus_dev) == -1) - perror ("Sample reset"); - for (i = 0; i < 256; i++) - loadmap[i] = 0; - break; - - case PM_E_PATCH_RESET: - printf ("Patch reset called\n"); - for (i = 0; i < 256; i++) - loadmap[i] = 0; - break; - - case PM_E_PATCH_LOADED: - printf ("Patch loaded by client\n"); - break; - - default: - printf ("Unknown event %d\n", inf.command); - inf.key = PM_ERROR; - inf.parm1 = EINVAL; - } - else if (inf.key == PM_K_COMMAND) - switch (inf.command) - { - case _PM_LOAD_PATCH: - if ((err = do_load_patch (&inf))) - if (err == ENOSPC) - { - if (ioctl (seqfd, SNDCTL_SEQ_RESETSAMPLES, &gus_dev) == -1) - { - perror ("Sample reset"); - return errno; - } - - for (i = 0; i < 256; i++) - loadmap[i] = 0; - err = do_load_patch (&inf); - } - - if (err) - { - inf.key = PM_ERROR; - inf.parm1 = err; - printf("Error = %d\n", err); - } - else - { - inf.key = PM_K_COMMAND; - inf.parm1 = 0; - } - break; - - default: - printf ("Unknown command %d\n", inf.command); - inf.key = PM_ERROR; - inf.parm1 = EINVAL; - } - else - { - printf ("Unknown event %d/%d\n", inf.key, inf.command); - inf.key = PM_ERROR; - inf.parm1 = EINVAL; - } - - if (write (seqfd, (char *) &inf, sizeof (inf)) != sizeof (inf)) - { - perror ("write"); - exit (-1); - } - } - - exit (0); -} diff --git a/sys/i386/isa/sound/ics2101.c b/sys/i386/isa/sound/ics2101.c new file mode 100644 index 0000000..619b635 --- /dev/null +++ b/sys/i386/isa/sound/ics2101.c @@ -0,0 +1,261 @@ +/* + * sound/ics2101.c + * + * Driver for the ICS2101 mixer of GUS v3.7. + * + * Copyright by Hannu Savolainen 1994 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ + +#include "sound_config.h" +#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_GUS) + +#include "ultrasound.h" +#include "gus_hw.h" + +#define MIX_DEVS (SOUND_MASK_MIC|SOUND_MASK_LINE| \ + SOUND_MASK_SYNTH| \ + SOUND_MASK_CD | SOUND_MASK_VOLUME) + +extern int gus_base; +static int volumes[ICS_MIXDEVS]; +static int left_fix[ICS_MIXDEVS] = +{1, 1, 1, 2, 1, 2}; +static int right_fix[ICS_MIXDEVS] = +{2, 2, 2, 1, 2, 1}; + +static int +scale_vol(int vol) +{ +#if 1 +/* + * Experimental volume scaling by Risto Kankkunen. + * This should give smoother volume response than just + * a plain multiplication. + */ + int e; + + if (vol < 0) + vol = 0; + if (vol > 100) + vol = 100; + vol = (31 * vol + 50) / 100; + e = 0; + if (vol) { + while (vol < 16) { + vol <<= 1; + e--; + } + vol -= 16; + e += 7; + } + return ((e << 4) + vol); +#else + return ((vol*127)+50)/100; +#endif +} + +static void +write_mix (int dev, int chn, int vol) +{ + int *selector; + unsigned long flags; + int ctrl_addr = dev << 3; + int attn_addr = dev << 3; + + vol=scale_vol(vol); + + if (chn == CHN_LEFT) + { + selector = left_fix; + ctrl_addr |= 0x00; + attn_addr |= 0x02; + } + else + { + selector = right_fix; + ctrl_addr |= 0x01; + attn_addr |= 0x03; + } + + DISABLE_INTR (flags); + OUTB (ctrl_addr, u_MixSelect); + OUTB (selector[dev], u_MixData); + OUTB (attn_addr, u_MixSelect); + OUTB ((unsigned char) vol, u_MixData); + RESTORE_INTR (flags); +} + +static int +set_volumes (int dev, int vol) +{ + int left = vol & 0x00ff; + int right = (vol >> 8) & 0x00ff; + + if (left < 0) + left = 0; + if (left > 100) + left = 100; + if (right < 0) + right = 0; + if (right > 100) + right = 100; + + write_mix (dev, CHN_LEFT, left); + write_mix (dev, CHN_RIGHT, right); + + vol = left + (right << 8); + volumes[dev] = vol; + return vol; +} + +static int +ics2101_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg) +{ + if (((cmd >> 8) & 0xff) == 'M') + { + if (cmd & IOC_IN) + switch (cmd & 0xff) + { + case SOUND_MIXER_RECSRC: + return gus_default_mixer_ioctl (dev, cmd, arg); + break; + + case SOUND_MIXER_MIC: + return IOCTL_OUT (arg, set_volumes (DEV_MIC, IOCTL_IN (arg))); + break; + + case SOUND_MIXER_CD: + return IOCTL_OUT (arg, set_volumes (DEV_CD, IOCTL_IN (arg))); + break; + + case SOUND_MIXER_LINE: + return IOCTL_OUT (arg, set_volumes (DEV_LINE, IOCTL_IN (arg))); + break; + + case SOUND_MIXER_SYNTH: + return IOCTL_OUT (arg, set_volumes (DEV_GF1, IOCTL_IN (arg))); + break; + + case SOUND_MIXER_VOLUME: + return IOCTL_OUT (arg, set_volumes (DEV_VOL, IOCTL_IN (arg))); + break; + + default: + return RET_ERROR (EINVAL); + } + else + switch (cmd & 0xff) /* + * Return parameters + */ + { + + case SOUND_MIXER_RECSRC: + return gus_default_mixer_ioctl (dev, cmd, arg); + break; + + case SOUND_MIXER_DEVMASK: + return IOCTL_OUT (arg, MIX_DEVS); + break; + + case SOUND_MIXER_STEREODEVS: + return IOCTL_OUT (arg, SOUND_MASK_LINE | SOUND_MASK_CD | + SOUND_MASK_SYNTH | SOUND_MASK_VOLUME| + SOUND_MASK_MIC); + break; + + case SOUND_MIXER_RECMASK: + return IOCTL_OUT (arg, SOUND_MASK_MIC | SOUND_MASK_LINE); + break; + + case SOUND_MIXER_CAPS: + return IOCTL_OUT (arg, 0); + break; + + case SOUND_MIXER_MIC: + return IOCTL_OUT (arg, volumes[DEV_MIC]); + break; + + case SOUND_MIXER_LINE: + return IOCTL_OUT (arg, volumes[DEV_LINE]); + break; + + case SOUND_MIXER_CD: + return IOCTL_OUT (arg, volumes[DEV_CD]); + break; + + case SOUND_MIXER_VOLUME: + return IOCTL_OUT (arg, volumes[DEV_VOL]); + break; + + case SOUND_MIXER_SYNTH: + return IOCTL_OUT (arg, volumes[DEV_GF1]); + break; + + default: + return RET_ERROR (EINVAL); + } + } + + return RET_ERROR (EINVAL); +} + +static struct mixer_operations ics2101_mixer_operations = +{ + ics2101_mixer_ioctl +}; + +long +ics2101_mixer_init (long mem_start) +{ + int i; + + if (num_mixers < MAX_MIXER_DEV) + { + mixer_devs[num_mixers++] = &ics2101_mixer_operations; + + /* + * Some GUS v3.7 cards had some channels flipped. Disable + * the flipping feature if the model id is other than 5. + */ + + if (INB (u_MixSelect) != 5) + { + for (i = 0; i < ICS_MIXDEVS; i++) + left_fix[i] = 1; + for (i = 0; i < ICS_MIXDEVS; i++) + right_fix[i] = 2; + } + + set_volumes (DEV_GF1, 0x5a5a); + set_volumes (DEV_CD, 0x5a5a); + set_volumes (DEV_MIC, 0x0000); + set_volumes (DEV_LINE, 0x5a5a); + set_volumes (DEV_VOL, 0x5a5a); + set_volumes (DEV_UNUSED, 0x0000); + } + + return mem_start; +} + +#endif diff --git a/sys/i386/isa/sound/midi.c b/sys/i386/isa/sound/midi.c deleted file mode 100644 index 83088d2..0000000 --- a/sys/i386/isa/sound/midi.c +++ /dev/null @@ -1,176 +0,0 @@ -/* UWM - comments to soft-eng@cs.uwm.edu */ -#define _MIDI_TABLE_C_ -#include "sound_config.h" - -#ifdef CONFIGURE_SOUNDCARD - -#ifndef EXCLUDE_CHIP_MIDI - - -static int generic_midi_busy[MAX_MIDI_DEV]; - -long CMIDI_init (long mem_start) -{ - - int i; - int n = num_midi_drivers; - /* int n = sizeof (midi_supported) / sizeof( struct generic_midi_info ); - */ - for (i = 0; i < n; i++) - { - if ( midi_supported[i].attach (mem_start) ) - { - printk("MIDI: Successfully attached %s\n",midi_supported[i].name); - } - - } - return (mem_start); -} - - -int -CMIDI_open (int dev, struct fileinfo *file) -{ - - int mode, err, retval; - - dev = dev >> 4; - - mode = file->mode & O_ACCMODE; - - - if (generic_midi_busy[dev]) - return (RET_ERROR(EBUSY)); - - - if (dev >= num_generic_midis) - { - printk(" MIDI device %d not installed.\n", dev); - return (ENXIO); - } - - if (!generic_midi_devs[dev]) - { - printk(" MIDI device %d not initialized\n",dev); - return (ENXIO); - } - - /* If all good and healthy, go ahead and issue call! */ - - - retval = generic_midi_devs[dev]->open (dev, mode) ; - - /* If everything ok, set device as busy */ - - if ( retval >= 0 ) - generic_midi_busy[dev] = 1; - - return ( retval ); - -} - -int -CMIDI_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count) -{ - - int retval; - - dev = dev >> 4; - - if (dev >= num_generic_midis) - { - printk(" MIDI device %d not installed.\n", dev); - return (ENXIO); - } - - /* Make double sure of healthiness -- doubt - * Need we check this again?? - * - */ - - if (!generic_midi_devs[dev]) - { - printk(" MIDI device %d not initialized\n",dev); - return (ENXIO); - } - - /* If all good and healthy, go ahead and issue call! */ - - - retval = generic_midi_devs[dev]->write (dev, buf); - - return ( retval ); - -} - -int -CMIDI_read (int dev, struct fileinfo *file, snd_rw_buf *buf, int count) -{ - int retval; - - dev = dev >> 4; - - if (dev >= num_generic_midis) - { - printk(" MIDI device %d not installed.\n", dev); - return (ENXIO); - } - - /* Make double sure of healthiness -- doubt - * Need we check this again?? - * - */ - - if (!generic_midi_devs[dev]) - { - printk(" MIDI device %d not initialized\n",dev); - return (ENXIO); - } - - /* If all good and healthy, go ahead and issue call! */ - - - retval = generic_midi_devs[dev]->read(dev,buf); - - return (retval); - -} - -int -CMIDI_close (int dev, struct fileinfo *file) -{ - - int retval; - dev = dev >> 4; - - if (dev >= num_generic_midis) - { - printk(" MIDI device %d not installed.\n", dev); - return (ENXIO); - } - - /* Make double sure of healthiness -- doubt - * Need we check this again?? - * - */ - - if (!generic_midi_devs[dev]) - { - printk(" MIDI device %d not initialized\n",dev); - return (ENXIO); - } - - /* If all good and healthy, go ahead and issue call! */ - - - generic_midi_devs[dev]->close(dev); - - generic_midi_busy[dev] = 0; /* Free the device */ - - return (0) ; - -} - -#endif - -#endif diff --git a/sys/i386/isa/sound/pas.h b/sys/i386/isa/sound/pas.h deleted file mode 100644 index 4dadea3..0000000 --- a/sys/i386/isa/sound/pas.h +++ /dev/null @@ -1,249 +0,0 @@ -/* */ -/* Port addresses and bit fields for the Media Vision Pro AudioSpectrum second generation sound cards. */ -/* */ -/* Feel free to use this header file in any application you create that has support for the Media Vision */ -/* Pro AudioSpectrum second generation sound cards. Other uses prohibited without prior permission. */ -/* */ -/* - cmetz@thor.tjhsst.edu */ -/* */ -/* Notes: */ -/* */ -/* * All of these ports go into the MVD101 multimedia controller chip, which then signals the other chips to do */ -/* the actual work. Many ports like the FM ones functionally attach directly to the destination chip though */ -/* they don't actually have a direct connection. */ -/* */ -/* * The PAS2 series cards have an MVD101 multimedia controller chip, the original PAS cards don't. The original */ -/* PAS cards are pretty defunct now, so no attempt is made here to support them. */ -/* */ -/* * The PAS2 series cards are all really different at the hardware level, though the MVD101 hides some of the */ -/* incompatibilities, there still are differences that need to be accounted for. */ -/* */ -/* Card CD-ROM interface PCM chip Mixer chip FM chip */ -/* PAS Plus Sony proprietary (Crystal?) 8-bit DAC National OPL3 */ -/* PAS 16 Zilog SCSI MVA416 16-bit Codec MVA508 OPL3 */ -/* CDPC Sony proprietary Sony 16-bit Codec National OPL3 */ -/* Fusion CD 16 Sony proprietary MVA416 16-bit Codec MVA508 OPL3 */ -/* Fusion CD Sony proprietary (Crystal?) 8-bit DAC National OPL3 */ -/* */ -#define PAS_DEFAULT_BASE 0x388 - -/* Symbolic Name Value R W Subsystem Description */ -#define SPEAKER_CONTROL 0x61 /* W PC speaker Control register */ -#define SPEAKER_CONTROL_GHOST 0x738B /* R W PC speaker Control ghost register */ -#define SPEAKER_TIMER_CONTROL 0x43 /* W PC speaker Timer control register */ -#define SPEAKER_TIMER_CONTROL_GHOST 0x778B /* R W PC speaker Timer control register ghost */ -#define SPEAKER_TIMER_DATA 0x42 /* W PC speaker Timer data register */ -#define SPEAKER_TIMER_DATA_GHOST 0x138A /* R W PC speaker Timer data register ghost */ - -#define WARM_BOOT 0x41 /* W Control Used to detect system warm boot */ -#define WARM_BOOT_GHOST 0x7789 /* ? W Control Use to get the card to fake warm boot */ -#define MASTER_DECODE 0x9A01 /* W Control Address >> 2 of card base address */ -#define PRESCALE_DIVIDER 0xBF8A /* R W PCM Ration between Codec clock and master clock */ -#define WAIT_STATE 0xBF88 /* R W Control Four-bit bus wait-state count (~140ns ea.) */ -#define BOARD_REV_ID 0x2789 /* R Control Extended Board Revision ID */ - -#define SYSTEM_CONFIGURATION_1 0x8388 /* R W Control */ - #define S_C_1_PCS_ENABLE 0x01 /* R W PC speaker 1=enable, 0=disable PC speaker emulation */ - #define S_C_1_PCM_CLOCK_SELECT 0x02 /* R W PCM 1=14.31818Mhz/12, 0=28.224Mhz master clock */ - #define S_C_1_FM_EMULATE_CLOCK 0x04 /* R W FM 1=use 28.224Mhz/2, 0=use 14.31818Mhz clock */ - #define S_C_1_PCS_STEREO 0x10 /* R W PC speaker 1=enable PC speaker stereo effect, 0=disable */ - #define S_C_1_PCS_REALSOUND 0x20 /* R W PC speaker 1=enable RealSound enhancement, 0=disable */ - #define S_C_1_FORCE_EXT_RESET 0x40 /* R W Control Force external reset */ - #define S_C_1_FORCE_INT_RESET 0x80 /* R W Control Force internal reset */ -#define SYSTEM_CONFIGURATION_2 0x8389 /* R W Control */ - #define S_C_2_PCM_OVERSAMPLING 0x03 /* R W PCM 00=0x, 01=2x, 10=4x, 11=reserved */ - #define S_C_2_PCM_16_BIT 0x04 /* R W PCM 1=16-bit, 0=8-bit samples */ -#define SYSTEM_CONFIGURATION_3 0x838A /* R W Control */ - #define S_C_3_PCM_CLOCK_SELECT 0x02 /* R W PCM 1=use 1.008Mhz clock for PCM, 0=don't */ -#define SYSTEM_CONFIGURATION_4 0x838B /* R W Control CD-ROM interface controls */ - -#define IO_CONFIGURATION_1 0xF388 /* R W Control */ - #define I_C_1_BOOT_RESET_ENABLE 0x80 /* R W Control 1=reset board on warm boot, 0=don't */ -#define IO_CONFIGURATION_2 0xF389 /* R W Control */ - #define I_C_2_PCM_DMA_DISABLED 0x00 /* R W PCM PCM DMA disabled */ -#define IO_CONFIGURATION_3 0xF38A /* R W Control */ - #define I_C_3_PCM_IRQ_DISABLED 0x00 /* R W PCM PCM IRQ disabled */ - -#define COMPATIBILITY_ENABLE 0xF788 /* R W Control */ - #define C_E_MPU401_ENABLE 0x01 /* R W MIDI 1=enable, 0=disable MPU401 MIDI emulation */ - #define C_E_SB_ENABLE 0x02 /* R W PCM 1=enable, 0=disable Sound Blaster emulation */ - #define C_E_SB_ACTIVE 0x04 /* R PCM "Sound Blaster Interrupt active" */ - #define C_E_MPU401_ACTIVE 0x08 /* R MIDI "MPU UART mode active" */ - #define C_E_PCM_COMPRESSION 0x10 /* R W PCM 1=enable, 0=disabled compression */ -#define EMULATION_ADDRESS 0xF789 /* R W Control */ - #define E_A_SB_BASE 0x0f /* R W PCM bits A4-A7 for SB base port */ - #define E_A_MPU401_BASE 0xf0 /* R W MIDI bits A4-A7 for MPU401 base port */ -#define EMULATION_CONFIGURATION 0xFB8A /* R W ***** Only valid on newer PAS2 cards (?) ***** */ - #define E_C_MPU401_IRQ 0x07 /* R W MIDI MPU401 emulation IRQ */ - #define E_C_SB_IRQ 0x38 /* R W PCM SB emulation IRQ */ - #define E_C_SB_DMA 0xC0 /* R W PCM SB emulation DMA */ - -#define OPERATION_MODE_1 0xEF8B /* R Control */ - #define O_M_1_CDROM_TYPE 0x03 /* R CD-ROM 3=SCSI, 2=Sony, 0=no CD-ROM interface */ - #define O_M_1_FM_TYPE 0x04 /* R FM 1=sterero, 0=mono FM chip */ - #define O_M_1_PCM_TYPE 0x08 /* R PCM 1=16-bit Codec, 0=8-bit DAC */ -#define OPERATION_MODE_2 0xFF8B /* R Control */ - #define O_M_2_PCS_ENABLED 0x02 /* R PC speaker PC speaker emulation 1=enabled, 0=disabled */ - #define O_M_2_BUS_TIMING 0x10 /* R Control 1=AT bus timing, 0=XT bus timing */ - #define O_M_2_BOARD_REVISION 0xe0 /* R Control Board revision */ - -#define INTERRUPT_MASK 0x0B8B /* R W Control */ - #define I_M_FM_LEFT_IRQ_ENABLE 0x01 /* R W FM Enable FM left interrupt */ - #define I_M_FM_RIGHT_IRQ_ENABLE 0x02 /* R W FM Enable FM right interrupt */ - #define I_M_PCM_RATE_IRQ_ENABLE 0x04 /* R W PCM Enable Sample Rate interrupt */ - #define I_M_PCM_BUFFER_IRQ_ENABLE 0x08 /* R W PCM Enable Sample Buffer interrupt */ - #define I_M_MIDI_IRQ_ENABLE 0x10 /* R W MIDI Enable MIDI interrupt */ - #define I_M_BOARD_REV 0xE0 /* R Control Board revision */ - -#define INTERRUPT_STATUS 0x0B89 /* R W Control */ - #define I_S_FM_LEFT_IRQ 0x01 /* R W FM Left FM Interrupt Pending */ - #define I_S_FM_RIGHT_IRQ 0x02 /* R W FM Right FM Interrupt Pending */ - #define I_S_PCM_SAMPLE_RATE_IRQ 0x04 /* R W PCM Sample Rate Interrupt Pending */ - #define I_S_PCM_SAMPLE_BUFFER_IRQ 0x08 /* R W PCM Sample Buffer Interrupt Pending */ - #define I_S_MIDI_IRQ 0x10 /* R W MIDI MIDI Interrupt Pending */ - #define I_S_PCM_CHANNEL 0x20 /* R W PCM 1=right, 0=left */ - #define I_S_RESET_ACTIVE 0x40 /* R W Control Reset is active (Timed pulse not finished) */ - #define I_S_PCM_CLIPPING 0x80 /* R W PCM Clipping has occurred */ - -#define FILTER_FREQUENCY 0x0B8A /* R W Control */ - #define F_F_FILTER_DISABLED 0x00 /* R W Mixer No filter */ -#if 0 - struct { /* R W Mixer Filter translation */ - unsigned int freq:24; - unsigned int value:8; - } F_F_FILTER_translate[] = - { { 73500, 0x01 }, /* 73500Hz - divide by 16 */ - { 65333, 0x02 }, /* 65333Hz - divide by 18 */ - { 49000, 0x09 }, /* 49000Hz - divide by 24 */ - { 36750, 0x11 }, /* 36750Hz - divide by 32 */ - { 24500, 0x19 }, /* 24500Hz - divide by 48 */ - { 18375, 0x07 }, /* 18375Hz - divide by 64 */ - { 12783, 0x0f }, /* 12783Hz - divide by 92 */ - { 12250, 0x04 }, /* 12250Hz - divide by 96 */ - { 9188, 0x17 }, /* 9188Hz - divide by 128 */ - { 6125, 0x1f }, /* 6125Hz - divide by 192 */ - }; -#endif - #define F_F_MIXER_UNMUTE 0x20 /* R W Mixer 1=disable, 0=enable board mute */ - #define F_F_PCM_RATE_COUNTER 0x40 /* R W PCM 1=enable, 0=disable sample rate counter */ - #define F_F_PCM_BUFFER_COUNTER 0x80 /* R W PCM 1=enable, 0=disable sample buffer counter */ - -#define PAS_NONE 0 -#define PAS_PLUS 1 -#define PAS_CDPC 2 -#define PAS_16 3 - -#ifdef DEFINE_TRANSLATIONS - char I_C_2_PCM_DMA_translate[] = /* R W PCM PCM DMA channel value translations */ - { 4, 1, 2, 3, 0, 5, 6, 7 }; - char I_C_3_PCM_IRQ_translate[] = /* R W PCM PCM IRQ level value translation */ - { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 }; - char E_C_MPU401_IRQ_translate[] = /* R W MIDI MPU401 emulation IRQ value translation */ - { 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x05, 0x06, 0x07 }; - char E_C_SB_IRQ_translate[] = /* R W PCM SB emulation IRQ translate */ - { 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20, 0x00, 0x00, 0x28, 0x30, 0x38 }; - char E_C_SB_DMA_translate[] = /* R W PCM SB emulation DMA translate */ - { 0x00, 0x40, 0x80, 0xC0 }; - char O_M_1_to_card[] = /* R W Control Translate (OM1 & 0x0f) to card type */ - { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 3, 0, 2, 3 }; -#else - extern char I_C_2_PCM_DMA_translate[]; /* R W PCM PCM DMA channel value translations */ - extern char I_C_3_PCM_IRQ_translate[]; /* R W PCM PCM IRQ level value translation */ - extern char E_C_MPU401_IRQ_translate[]; /* R W MIDI MPU401 emulation IRQ value translation */ - extern char E_C_SB_IRQ_translate[]; /* R W PCM SB emulation IRQ translate */ - extern char E_C_SB_DMA_translate[]; /* R W PCM SB emulation DMA translate */ - extern char O_M_1_to_card[]; /* R W Control Translate (OM1 & 0x0f) to card type */ -#endif - -#define PARALLEL_MIXER 0x078B /* W Mixer Documented for MVD101 as FM Mono Right decode?? */ - #define P_M_MV508_ADDRESS 0x80 /* W Mixer MVD508 Address/mixer select */ - #define P_M_MV508_DATA 0x00 - #define P_M_MV508_LEFT 0x20 /* W Mixer MVD508 Left channel select */ - #define P_M_MV508_RIGHT 0x40 /* W Mixer MVD508 Right channel select */ - #define P_M_MV508_BOTH 0x00 /* W Mixer MVD508 Both channel select */ - #define P_M_MV508_MIXER 0x10 /* W Mixer MVD508 Select a mixer (rather than a volume) */ - #define P_M_MV508_VOLUME 0x00 - - #define P_M_MV508_INPUTMIX 0x20 /* W Mixer MVD508 Select mixer A */ - #define P_M_MV508_OUTPUTMIX 0x00 /* W Mixer MVD508 Select mixer B */ - - #define P_M_MV508_MASTER_A 0x01 /* W Mixer MVD508 Master volume control A (output) */ - #define P_M_MV508_MASTER_B 0x02 /* W Mixer MVD508 Master volume control B (DSP input) */ - #define P_M_MV508_BASS 0x03 /* W Mixer MVD508 Bass control */ - #define P_M_MV508_TREBLE 0x04 /* W Mixer MVD508 Treble control */ - #define P_M_MV508_MODE 0x05 /* W Mixer MVD508 Master mode control */ - - #define P_M_MV508_LOUDNESS 0x04 /* W Mixer MVD508 Mode control - Loudness filter */ - #define P_M_MV508_ENHANCE_BITS 0x03 - #define P_M_MV508_ENHANCE_NONE 0x00 /* W Mixer MVD508 Mode control - No stereo enhancement */ - #define P_M_MV508_ENHANCE_40 0x01 /* W Mixer MVD508 Mode control - 40% stereo enhancement */ - #define P_M_MV508_ENHANCE_60 0x02 /* W Mixer MVD508 Mode control - 60% stereo enhancement */ - #define P_M_MV508_ENHANCE_80 0x03 /* W Mixer MVD508 Mode control - 80% stereo enhancement */ - - #define P_M_MV508_FM 0x00 /* W Mixer MVD508 Channel 0 - FM */ - #define P_M_MV508_IMIXER 0x01 /* W Mixer MVD508 Channel 1 - Input mixer (rec monitor) */ - #define P_M_MV508_LINE 0x02 /* W Mixer MVD508 Channel 2 - Line in */ - #define P_M_MV508_CDROM 0x03 /* W Mixer MVD508 Channel 3 - CD-ROM */ - #define P_M_MV508_MIC 0x04 /* W Mixer MVD508 Channel 4 - Microphone */ - #define P_M_MV508_PCM 0x05 /* W Mixer MVD508 Channel 5 - PCM */ - #define P_M_MV508_SPEAKER 0x06 /* W Mixer MVD508 Channel 6 - PC Speaker */ - #define P_M_MV508_SB 0x07 /* W Mixer MVD508 Channel 7 - SB DSP */ - -#define SERIAL_MIXER 0xB88 /* R W Control Serial mixer control (used other ways) */ - #define S_M_PCM_RESET 0x01 /* R W PCM Codec/DSP reset */ - #define S_M_FM_RESET 0x02 /* R W FM FM chip reset */ - #define S_M_SB_RESET 0x04 /* R W PCM SB emulation chip reset */ - #define S_M_MIXER_RESET 0x10 /* R W Mixer Mixer chip reset */ - #define S_M_INTEGRATOR_ENABLE 0x40 /* R W Speaker Enable PC speaker integrator (FORCE RealSound) */ - #define S_M_OPL3_DUAL_MONO 0x80 /* R W FM Set the OPL-3 to dual mono mode */ - -#define PCM_CONTROL 0xF8A /* R W PCM PCM Control Register */ - #define P_C_MIXER_CROSS_FIELD 0x0f - #define P_C_MIXER_CROSS_R_TO_R 0x01 /* R W Mixer Connect Right to Right */ - #define P_C_MIXER_CROSS_L_TO_R 0x02 /* R W Mixer Connect Left to Right */ - #define P_C_MIXER_CROSS_R_TO_L 0x04 /* R W Mixer Connect Right to Left */ - #define P_C_MIXER_CROSS_L_TO_L 0x08 /* R W Mixer Connect Left to Left */ - #define P_C_PCM_DAC_MODE 0x10 /* R W PCM Playback (DAC) mode */ - #define P_C_PCM_ADC_MODE 0x00 /* R W PCM Record (ADC) mode */ - #define P_C_PCM_MONO 0x20 /* R W PCM Mono mode */ - #define P_C_PCM_STEREO 0x00 /* R W PCM Stereo mode */ - #define P_C_PCM_ENABLE 0x40 /* R W PCM Enable PCM engine */ - #define P_C_PCM_DMA_ENABLE 0x80 /* R W PCM Enable DRQ */ - -#define SAMPLE_COUNTER_CONTROL 0x138B /* R W PCM Sample counter control register */ - #define S_C_C_SQUARE_WAVE 0x04 /* R W PCM Square wave generator (use for sample rate) */ - #define S_C_C_RATE 0x06 /* R W PCM Rate generator (use for sample buffer count) */ - #define S_C_C_LSB_THEN_MSB 0x30 /* R W PCM Change all 16 bits, LSB first, then MSB */ - - /* MVD101 and SDK documentations have S_C_C_SAMPLE_RATE and S_C_C_SAMPLE_BUFFER transposed. Only one works :-) */ - #define S_C_C_SAMPLE_RATE 0x00 /* R W PCM Select sample rate timer */ - #define S_C_C_SAMPLE_BUFFER 0x40 /* R W PCM Select sample buffer counter */ - - #define S_C_C_PC_SPEAKER 0x80 /* R W PCM Select PC speaker counter */ - -#define SAMPLE_RATE_TIMER 0x1388 /* W PCM Sample rate timer register (PCM wait interval) */ -#define SAMPLE_BUFFER_COUNTER 0x1389 /* R W PCM Sample buffer counter (DMA buffer size) */ - -#define MIDI_CONTROL 0x178b /* R W MIDI Midi control register */ - #define M_C_ENA_TSTAMP_IRQ 0x01 /* R W MIDI Enable Time Stamp Interrupts */ - #define M_C_ENA_TME_COMP_IRQ 0x02 /* R W MIDI Enable time compare interrupts */ - #define M_C_ENA_INPUT_IRQ 0x04 /* R W MIDI Enable input FIFO interrupts */ - #define M_C_ENA_OUTPUT_IRQ 0x08 /* R W MIDI Enable output FIFO interrupts */ - #define M_C_ENA_OUTPUT_HALF_IRQ 0x10 /* R W MIDI Enable output FIFO half full interrupts */ - #define M_C_RESET_INPUT_FIFO 0x20 /* R W MIDI Reset input FIFO pointer */ - #define M_C_RESET_OUTPUT_FIFO 0x40 /* R W MIDI Reset output FIFO pointer */ - #define M_C_ENA_THRU_MODE 0x80 /* R W MIDI Echo input to output (THRU) */ - -#define MIDI_STATUS 0x1B88 /* R W MIDI Midi (interrupt) status register */ - #define M_S_TIMESTAMP 0x01 /* R W MIDI Midi time stamp interrupt occurred */ - #define M_S_COMPARE 0x02 /* R W MIDI Midi compare time interrupt occurred */ - #define M_S_INPUT_AVAIL 0x04 /* R W MIDI Midi input data available interrupt occurred */ - #define M_S_OUTPUT_EMPTY 0x08 /* R W MIDI Midi output FIFO empty interrupt occurred */ - #define M_S_OUTPUT_HALF_EMPTY 0x10 /* R W MIDI Midi output FIFO half empty interrupt occurred */ - #define M_S_INPUT_OVERRUN 0x20 /* R W MIDI Midi input overrun error occurred */ - #define M_S_OUTPUT_OVERRUN 0x40 /* R W MIDI Midi output overrun error occurred */ - #define M_S_FRAMING_ERROR 0x80 /* R W MIDI Midi input framing error occurred */ - -#define MIDI_FIFO_STATUS 0x1B89 /* R W MIDI Midi fifo status */ -#define MIDI_DATA 0x178A /* R W MIDI Midi data register */ -#define MIDI_INPUT_AVAILABLE 0x0f /* RW MIDI */ diff --git a/sys/i386/isa/sound/pro_midi.c b/sys/i386/isa/sound/pro_midi.c deleted file mode 100644 index b7f6b9a..0000000 --- a/sys/i386/isa/sound/pro_midi.c +++ /dev/null @@ -1,155 +0,0 @@ -/* UWM -- comments to soft-eng@cs.uwm.edu */ -#define ALL_EXTERNAL_TO_ME -#include "sound_config.h" - -#ifdef CONFIGURE_SOUNDCARD - -#include "pas.h" -#define ESUCCESS 0 - -#if !defined(EXCLUDE_PRO_MIDI) && !defined(EXCLUDE_CHIP_MIDI) - - -/** Structure for handling operations **/ - - -static struct generic_midi_operations pro_midi_operations = { - - {"Pro_Audio_Spectrum 16 MV101", 0}, - pro_midi_open, - pro_midi_close, - pro_midi_write, - pro_midi_read -}; - -/* - * Note! Note! Note! - * Follow the same model for any other attach function you - * may write - */ - -long pro_midi_attach( long mem_start) -{ - pro_midi_dev = num_generic_midis; - generic_midi_devs[num_generic_midis++] = &pro_midi_operations; - return mem_start; -} - -int pro_midi_open(int dev, int mode) -{ - - int intr_mask, s; - - - s = splhigh(); - - - /* Reset the input and output FIFO pointers */ - - - outb(MIDI_CONTROL,M_C_RESET_INPUT_FIFO | M_C_RESET_OUTPUT_FIFO); - - /* Get the interrupt status */ - - intr_mask = inb(INTERRUPT_MASK); - - - /* Enable MIDI IRQ */ - - intr_mask |= I_M_MIDI_IRQ_ENABLE; - outb(INTERRUPT_MASK, intr_mask); - - - /* Enable READ/WRITE on MIDI port. This part is quite unsure though */ - - outb(MIDI_CONTROL,M_C_ENA_OUTPUT_IRQ | M_C_ENA_INPUT_IRQ); - - /* Acknowledge pending interrupts */ - - outb(MIDI_STATUS,0xff); - - - splx(s); - - return(ESUCCESS); - - -} - - -void pro_midi_close(int dev) -{ - - int intr_mask; - - /* Clean up */ - - outb(MIDI_CONTROL,M_C_RESET_INPUT_FIFO | M_C_RESET_OUTPUT_FIFO); - intr_mask = inb(INTERRUPT_MASK); - intr_mask &= ~I_M_MIDI_IRQ_ENABLE; - outb(INTERRUPT_MASK,intr_mask); - - return; -} - -int pro_midi_write(int dev, struct uio *uio) -{ - - int s; - unsigned char data; - - /* printf("midi: Going to do write routine..\n"); */ - while(uio->uio_resid) { - - if ( uiomove(&data,1,uio) ) return(ENOTTY); - - s = splhigh(); - - DELAY(30); - outb(MIDI_DATA,data); - DELAY(70); /* Ze best pause.. find a better one if - * you can :) - */ - splx(s); - } - - return(ESUCCESS); - -} - - -int pro_midi_read(int dev, struct uio *uio) -{ - - int s; - unsigned char data; - - s = splhigh(); - - /* For each uio_iov[] entry .... */ - - while (uio->uio_resid) { - - if((( inb(MIDI_STATUS) & M_S_INPUT_AVAIL) == 0 ) && - ((inb(MIDI_FIFO_STATUS) & MIDI_INPUT_AVAILABLE) == 0 ) ) - - data = 0xfe; - else - data = inb(MIDI_DATA); - - if ( uiomove(&data, 1 , uio)) { - - printf("midi: Bad copyout()!\n"); - return(ENOTTY); - - } - - } - splx(s); - return(ESUCCESS); - -} - -#endif - -#endif diff --git a/sys/i386/isa/sound/sb16_dsp.c b/sys/i386/isa/sound/sb16_dsp.c new file mode 100644 index 0000000..8787b27 --- /dev/null +++ b/sys/i386/isa/sound/sb16_dsp.c @@ -0,0 +1,641 @@ +/* + * sound/sb16_dsp.c + * + * The low level driver for the SoundBlaster DSP chip. + * + * (C) 1993 J. Schubert (jsb@sth.ruhr-uni-bochum.de) + * + * based on SB-driver by (C) Hannu Savolainen + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ + +#define DEB(x) +#define DEB1(x) +/* + #define DEB_DMARES + */ +#include "sound_config.h" +#include "sb.h" +#include "sb_mixer.h" + +#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SB) && !defined(EXCLUDE_AUDIO) && !defined(EXCLUDE_SBPRO) + +extern int sbc_base; + +static int sb16_dsp_ok = 0; /* Set to 1 after successful initialization */ +static int dsp_16bit = 0; +static int dsp_stereo = 0; +static int dsp_current_speed = 8000; /*DSP_DEFAULT_SPEED; */ +static int dsp_busy = 0; +static int dma16, dma8; +static unsigned long dsp_count = 0; + +static int irq_mode = IMODE_NONE; /* IMODE_INPUT, IMODE_OUTPUT or + + IMODE_NONE */ +static int my_dev = 0; + +static volatile int intr_active = 0; + +static int sb16_dsp_open (int dev, int mode); +static void sb16_dsp_close (int dev); +static void sb16_dsp_output_block (int dev, unsigned long buf, int count, int intrflag, int dma_restart); +static void sb16_dsp_start_input (int dev, unsigned long buf, int count, int intrflag, int dma_restart); +static int sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg, int local); +static int sb16_dsp_prepare_for_input (int dev, int bsize, int bcount); +static int sb16_dsp_prepare_for_output (int dev, int bsize, int bcount); +static void sb16_dsp_reset (int dev); +static void sb16_dsp_halt (int dev); +static int dsp_set_speed (int); +static int dsp_set_stereo (int); +static void dsp_cleanup (void); +int sb_reset_dsp (void); + +static struct audio_operations sb16_dsp_operations = +{ + "SoundBlaster 16", + sb16_dsp_open, + sb16_dsp_close, + sb16_dsp_output_block, + sb16_dsp_start_input, + sb16_dsp_ioctl, + sb16_dsp_prepare_for_input, + sb16_dsp_prepare_for_output, + sb16_dsp_reset, + sb16_dsp_halt, + NULL, + NULL +}; + +static int +sb_dsp_command01 (unsigned char val) +{ + int i = 1 << 16; + + while (--i & (!INB (DSP_STATUS) & 0x80)); + if (!i) + printk ("SB16 sb_dsp_command01 Timeout\n"); + return sb_dsp_command (val); +} + +static int +wait_data_avail (int t) +{ + int loopc = 5000000; + + t += GET_TIME (); + do + { + if (INB (DSP_DATA_AVAIL) & 0x80) + return 1; + } + while (--loopc && GET_TIME () < t); + printk ("!data_avail l=%d\n", loopc); + return 0; +} + +static int +read_dsp (int t) +{ + if (!wait_data_avail (t)) + return -1; + else + return INB (DSP_READ); +} + +static int +dsp_ini2 (void) +{ +#if 0 + /* sb_setmixer(0x83, sb_getmixer(0x83) | 0x03); */ + sb_dsp_command (0xe2); + sb_dsp_command (0x76); /* E0 ??? */ + sb_dsp_command (0xe2); + sb_dsp_command (0x30); /* A0 ??? */ + sb_dsp_command (0xe4); + sb_dsp_command (0xaa); + sb_dsp_command (0xe8); + if (read_dsp (100) != 0xaa) + printk ("Error dsp_ini2\n"); +#endif + return 0; +} +/* + static char *dsp_getmessage(unsigned char command,int maxn) + { + static char buff[100]; + int n=0; + + sb_dsp_command(command); + while(n<maxn && wait_data_avail(2)) { + buff[++n]=INB(DSP_READ); + if(!buff[n]) + break; + } + buff[0]=n; + return buff; + } + + static void dsp_showmessage(unsigned char command,int len) + { + int n; + unsigned char *c; + c=dsp_getmessage(command,len); + printk("DSP C=%x l=%d,lr=%d b=",command,len,c[0]); + for(n=1;n<=c[0];n++) + if(c[n]>=' ' & c[n]<='z') + printk("%c",c[n]); + else + printk("|%x|",c[n]); + printk("\n"); + } + */ +static int +dsp_set_speed (int mode) +{ + DEB (printk ("dsp_set_speed(%d)\n", mode)); + if (mode) + { + if (mode < 5000) + mode = 5000; + if (mode > 44100) + mode = 44100; + dsp_current_speed = mode; + } + return mode; +} + +static int +dsp_set_stereo (int mode) +{ + DEB (printk ("dsp_set_stereo(%d)\n", mode)); + + dsp_stereo = mode; + + return mode; +} + +static int +dsp_set_bits (int arg) +{ + DEB (printk ("dsp_set_bits(%d)\n", arg)); + + if (arg) + switch (arg) + { + case 8: + dsp_16bit = 0; + break; + case 16: + dsp_16bit = 1; + break; + default: + return RET_ERROR (EINVAL); + } + return dsp_16bit ? 16 : 8; +} + +static int +sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg, int local) +{ + switch (cmd) + { + case SOUND_PCM_WRITE_RATE: + if (local) + return dsp_set_speed (arg); + return IOCTL_OUT (arg, dsp_set_speed (IOCTL_IN (arg))); + + case SOUND_PCM_READ_RATE: + if (local) + return dsp_current_speed; + return IOCTL_OUT (arg, dsp_current_speed); + + case SNDCTL_DSP_STEREO: + if (local) + return dsp_set_stereo (arg); + return IOCTL_OUT (arg, dsp_set_stereo (IOCTL_IN (arg))); + + case SOUND_PCM_WRITE_CHANNELS: + if (local) + return dsp_set_stereo (arg - 1) + 1; + return IOCTL_OUT (arg, dsp_set_stereo (IOCTL_IN (arg) - 1) + 1); + + case SOUND_PCM_READ_CHANNELS: + if (local) + return dsp_stereo + 1; + return IOCTL_OUT (arg, dsp_stereo + 1); + + case SNDCTL_DSP_SAMPLESIZE: + if (local) + return dsp_set_bits (arg); + return IOCTL_OUT (arg, dsp_set_bits (IOCTL_IN (arg))); + + case SOUND_PCM_READ_BITS: + if (local) + return dsp_16bit ? 16 : 8; + return IOCTL_OUT (arg, dsp_16bit ? 16 : 8); + + case SOUND_PCM_WRITE_FILTER: /* NOT YET IMPLEMENTED */ + if (IOCTL_IN (arg) > 1) + return IOCTL_OUT (arg, RET_ERROR (EINVAL)); + default: + return RET_ERROR (EINVAL); + } + + return RET_ERROR (EINVAL); +} + +static int +sb16_dsp_open (int dev, int mode) +{ + int retval; + + DEB (printk ("sb16_dsp_open()\n")); + if (!sb16_dsp_ok) + { + printk ("SB16 Error: SoundBlaster board not installed\n"); + return RET_ERROR (ENXIO); + } + + if (intr_active) + return RET_ERROR (EBUSY); + + retval = sb_get_irq (); + if (retval < 0) + return retval; + + if (ALLOC_DMA_CHN (dma8)) + { + printk ("SB16: Unable to grab DMA%d\n", dma8); + sb_free_irq (); + return RET_ERROR (EBUSY); + } + + if (dma16 != dma8) + if (ALLOC_DMA_CHN (dma16)) + { + printk ("SB16: Unable to grab DMA%d\n", dma16); + sb_free_irq (); + RELEASE_DMA_CHN (dma8); + return RET_ERROR (EBUSY); + } + + dsp_ini2 (); + + irq_mode = IMODE_NONE; + dsp_busy = 1; + + return 0; +} + +static void +sb16_dsp_close (int dev) +{ + unsigned long flags; + + DEB (printk ("sb16_dsp_close()\n")); + sb_dsp_command01 (0xd9); + sb_dsp_command01 (0xd5); + + DISABLE_INTR (flags); + RELEASE_DMA_CHN (dma8); + + if (dma16 != dma8) + RELEASE_DMA_CHN (dma16); + sb_free_irq (); + dsp_cleanup (); + dsp_busy = 0; + RESTORE_INTR (flags); +} + +static void +sb16_dsp_output_block (int dev, unsigned long buf, int count, int intrflag, int dma_restart) +{ + unsigned long flags, cnt; + + cnt = count; + if (dsp_16bit) + cnt >>= 1; + cnt--; + +#ifdef DEB_DMARES + printk ("output_block: %x %d %d\n", buf, count, intrflag); + if (intrflag) + { + int pos, chan = sound_dsp_dmachan[dev]; + + DISABLE_INTR (flags); + clear_dma_ff (chan); + disable_dma (chan); + pos = get_dma_residue (chan); + enable_dma (chan); + RESTORE_INTR (flags); + printk ("dmapos=%d %x\n", pos, pos); + } +#endif + if (sound_dma_automode[dev] && + intrflag && + cnt == dsp_count) + { + irq_mode = IMODE_OUTPUT; + intr_active = 1; + return; /* Auto mode on. No need to react */ + } + DISABLE_INTR (flags); + + if (dma_restart) + { + sb16_dsp_halt (dev); + DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); + } + sb_dsp_command (0x41); + sb_dsp_command ((unsigned char) ((dsp_current_speed >> 8) & 0xff)); + sb_dsp_command ((unsigned char) (dsp_current_speed & 0xff)); + sb_dsp_command ((unsigned char) (dsp_16bit ? 0xb6 : 0xc6)); + sb_dsp_command ((unsigned char) ((dsp_stereo ? 0x20 : 0) + + (dsp_16bit ? 0x10 : 0))); + sb_dsp_command01 ((unsigned char) (cnt & 0xff)); + sb_dsp_command ((unsigned char) (cnt >> 8)); + /* sb_dsp_command (0); + sb_dsp_command (0); */ + + RESTORE_INTR (flags); + dsp_count = cnt; + irq_mode = IMODE_OUTPUT; + intr_active = 1; +} + +static void +sb16_dsp_start_input (int dev, unsigned long buf, int count, int intrflag, int dma_restart) +{ + unsigned long flags, cnt; + + cnt = count; + if (dsp_16bit) + cnt >>= 1; + cnt--; + +#ifdef DEB_DMARES + printk ("start_input: %x %d %d\n", buf, count, intrflag); + if (intrflag) + { + int pos, chan = sound_dsp_dmachan[dev]; + + DISABLE_INTR (flags); + clear_dma_ff (chan); + disable_dma (chan); + pos = get_dma_residue (chan); + enable_dma (chan); + RESTORE_INTR (flags); + printk ("dmapos=%d %x\n", pos, pos); + } +#endif + if (sound_dma_automode[dev] && + intrflag && + cnt == dsp_count) + { + irq_mode = IMODE_INPUT; + intr_active = 1; + return; /* Auto mode on. No need to react */ + } + DISABLE_INTR (flags); + + if (dma_restart) + { + sb16_dsp_halt (dev); + DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); + } + + sb_dsp_command (0x42); + sb_dsp_command ((unsigned char) ((dsp_current_speed >> 8) & 0xff)); + sb_dsp_command ((unsigned char) (dsp_current_speed & 0xff)); + sb_dsp_command ((unsigned char) (dsp_16bit ? 0xbe : 0xce)); + sb_dsp_command ((unsigned char) ((dsp_stereo ? 0x20 : 0) + + (dsp_16bit ? 0x10 : 0))); + sb_dsp_command01 ((unsigned char) (cnt & 0xff)); + sb_dsp_command ((unsigned char) (cnt >> 8)); + + /* sb_dsp_command (0); + sb_dsp_command (0); */ + RESTORE_INTR (flags); + dsp_count = cnt; + irq_mode = IMODE_INPUT; + intr_active = 1; +} + +static int +sb16_dsp_prepare_for_input (int dev, int bsize, int bcount) +{ + sound_dsp_dmachan[my_dev] = dsp_16bit ? dma16 : dma8; + dsp_count = 0; + dsp_cleanup (); + return 0; +} + +static int +sb16_dsp_prepare_for_output (int dev, int bsize, int bcount) +{ + sound_dsp_dmachan[my_dev] = dsp_16bit ? dma16 : dma8; + dsp_count = 0; + dsp_cleanup (); + return 0; +} + +static void +dsp_cleanup (void) +{ + irq_mode = IMODE_NONE; + intr_active = 0; +} + +static void +sb16_dsp_reset (int dev) +{ + unsigned long flags; + + DISABLE_INTR (flags); + + sb_reset_dsp (); + dsp_cleanup (); + + RESTORE_INTR (flags); +} + +static void +sb16_dsp_halt (int dev) +{ + if (dsp_16bit) + { + sb_dsp_command01 (0xd9); + sb_dsp_command01 (0xd5); + } + else + { + sb_dsp_command01 (0xda); + sb_dsp_command01 (0xd0); + } +} + +static void +set_irq_hw (int level) +{ + int ival; + + switch (level) + { + case 5: + ival = 2; + break; + case 7: + ival = 4; + break; + case 10: + ival = 8; + break; + default: + printk ("SB16_IRQ_LEVEL %d does not exist\n", level); + return; + } + sb_setmixer (IRQ_NR, ival); +} + +long +sb16_dsp_init (long mem_start, struct address_info *hw_config) +{ + int i, major, minor; + + major = minor = 0; + sb_dsp_command (0xe1); /* Get version */ + + for (i = 1000; i; i--) + { + if (INB (DSP_DATA_AVAIL) & 0x80) + { /* wait for Data Ready */ + if (major == 0) + major = INB (DSP_READ); + else + { + minor = INB (DSP_READ); + break; + } + } + } + +#ifndef SCO + sprintf (sb16_dsp_operations.name, "SoundBlaster 16 %d.%d", major, minor); +#endif + + printk ("snd6: <%s>", sb16_dsp_operations.name); + + if (num_dspdevs < MAX_DSP_DEV) + { + dsp_devs[my_dev = num_dspdevs++] = &sb16_dsp_operations; + sound_dsp_dmachan[my_dev] = hw_config->dma; + sound_buffcounts[my_dev] = 1; + sound_buffsizes[my_dev] = DSP_BUFFSIZE; + sound_dma_automode[my_dev] = 1; + } + else + printk ("SB: Too many DSP devices available\n"); + sb16_dsp_ok = 1; + return mem_start; +} + +int +sb16_dsp_detect (struct address_info *hw_config) +{ + struct address_info *sb_config; + + if (sb16_dsp_ok) + return 1; /* Already initialized */ + + if (!(sb_config = sound_getconf (SNDCARD_SB))) + { + printk ("SB16 Error: Plain SB not configured\n"); + return 0; + } + + if (sbc_base != hw_config->io_base) + printk ("Warning! SB16 I/O != SB I/O\n"); + + /* sb_setmixer(OPSW,0xf); + if(sb_getmixer(OPSW)!=0xf) + return 0; */ + + if (!sb_reset_dsp ()) + return 0; + + if (hw_config->irq != sb_config->irq) + { + printk ("SB16 Error: Invalid IRQ number %d/%d\n", + sb_config->irq, hw_config->irq); + return 0; + } + + if (hw_config->dma < 4) + if (hw_config->dma != sb_config->dma) + { + printk ("SB16 Error: Invalid DMA channel %d/%d\n", + sb_config->dma, hw_config->dma); + return 0; + } + + dma16 = hw_config->dma; + dma8 = sb_config->dma; + set_irq_hw (hw_config->irq); + sb_setmixer (DMA_NR, (1 << hw_config->dma) | (1 << sb_config->dma)); + + DEB (printk ("SoundBlaster 16: IRQ %d DMA %d OK\n", hw_config->irq, hw_config->dma)); + +/* + dsp_showmessage(0xe3,99); + */ + sb16_dsp_ok = 1; + return 1; +} + +void +sb16_dsp_interrupt (int unused) +{ + int data; + + data = INB (DSP_DATA_AVL16); /* Interrupt acknowledge */ + + if (intr_active) + switch (irq_mode) + { + case IMODE_OUTPUT: + intr_active = 0; + DMAbuf_outputintr (my_dev, 1); + break; + + case IMODE_INPUT: + intr_active = 0; + DMAbuf_inputintr (my_dev); + break; + + default: + printk ("SoundBlaster: Unexpected interrupt\n"); + } +} +#endif diff --git a/sys/i386/isa/sound/sb16_midi.c b/sys/i386/isa/sound/sb16_midi.c new file mode 100644 index 0000000..f7a61a6 --- /dev/null +++ b/sys/i386/isa/sound/sb16_midi.c @@ -0,0 +1,314 @@ +/* + * sound/sb16_midi.c + * + * The low level driver for the MPU-401 UART emulation of the SB16. + * + * Copyright by Hannu Savolainen 1993 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ + +#include "sound_config.h" + +#ifdef CONFIGURE_SOUNDCARD + +#if !defined(EXCLUDE_SB) && !defined(EXCLUDE_SB16) && !defined(EXCLUDE_MIDI) + +#define DATAPORT (sb16midi_base) /* MPU-401 Data I/O Port on IBM */ +#define COMDPORT (sb16midi_base+1) /* MPU-401 Command Port on IBM */ +#define STATPORT (sb16midi_base+1) /* MPU-401 Status Port on IBM */ + +#define sb16midi_status() INB(STATPORT) +#define input_avail() (!(sb16midi_status()&INPUT_AVAIL)) +#define output_ready() (!(sb16midi_status()&OUTPUT_READY)) +#define sb16midi_cmd(cmd) OUTB(cmd, COMDPORT) +#define sb16midi_read() INB(DATAPORT) +#define sb16midi_write(byte) OUTB(byte, DATAPORT) + +#define OUTPUT_READY 0x40 /* Mask for Data Read Redy Bit */ +#define INPUT_AVAIL 0x80 /* Mask for Data Send Ready Bit */ +#define MPU_ACK 0xFE /* MPU-401 Acknowledge Response */ +#define MPU_RESET 0xFF /* MPU-401 Total Reset Command */ +#define UART_MODE_ON 0x3F /* MPU-401 "Dumb UART Mode" */ + +static int sb16midi_opened = 0; +static int sb16midi_base = 0x330; +static int sb16midi_detected = 0; +static int my_dev; + +static int reset_sb16midi (void); +static void (*midi_input_intr) (int dev, unsigned char data); + +static void +sb16midi_input_loop (void) +{ + int count; + + count = 10; + + while (count) /* Not timed out */ + if (input_avail ()) + { + unsigned char c = sb16midi_read (); + + count = 100; + + if (sb16midi_opened & OPEN_READ) + midi_input_intr (my_dev, c); + } + else + while (!input_avail () && count) + count--; +} + +void +sb16midiintr (int unit) +{ + if (input_avail ()) + sb16midi_input_loop (); +} + +/* + * It looks like there is no input interrupts in the UART mode. Let's try + * polling. + */ + +static void +poll_sb16midi (unsigned long dummy) +{ + unsigned long flags; + + DEFINE_TIMER (sb16midi_timer, poll_sb16midi); + + if (!(sb16midi_opened & OPEN_READ)) + return; /* No longer required */ + + DISABLE_INTR (flags); + + if (input_avail ()) + sb16midi_input_loop (); + + ACTIVATE_TIMER (sb16midi_timer, poll_sb16midi, 1); /* Come back later */ + + RESTORE_INTR (flags); +} + +static int +sb16midi_open (int dev, int mode, + void (*input) (int dev, unsigned char data), + void (*output) (int dev) +) +{ + if (sb16midi_opened) + { + return RET_ERROR (EBUSY); + } + + sb16midi_input_loop (); + + midi_input_intr = input; + sb16midi_opened = mode; + poll_sb16midi (0); /* Enable input polling */ + + return 0; +} + +static void +sb16midi_close (int dev) +{ + sb16midi_opened = 0; +} + +static int +sb16midi_out (int dev, unsigned char midi_byte) +{ + int timeout; + unsigned long flags; + + /* + * Test for input since pending input seems to block the output. + */ + + DISABLE_INTR (flags); + + if (input_avail ()) + sb16midi_input_loop (); + + RESTORE_INTR (flags); + + /* + * Sometimes it takes about 13000 loops before the output becomes ready + * (After reset). Normally it takes just about 10 loops. + */ + + for (timeout = 30000; timeout > 0 && !output_ready (); timeout--); /* Wait */ + + if (!output_ready ()) + { + printk ("MPU-401: Timeout\n"); + return 0; + } + + sb16midi_write (midi_byte); + return 1; +} + +static int +sb16midi_command (int dev, unsigned char midi_byte) +{ + return 1; +} + +static int +sb16midi_start_read (int dev) +{ + return 0; +} + +static int +sb16midi_end_read (int dev) +{ + return 0; +} + +static int +sb16midi_ioctl (int dev, unsigned cmd, unsigned arg) +{ + return RET_ERROR (EINVAL); +} + +static void +sb16midi_kick (int dev) +{ +} + +static int +sb16midi_buffer_status (int dev) +{ + return 0; /* No data in buffers */ +} + +static struct midi_operations sb16midi_operations = +{ + {"SoundBlaster MPU-401", 0, 0, SNDCARD_SB16MIDI}, + sb16midi_open, + sb16midi_close, + sb16midi_ioctl, + sb16midi_out, + sb16midi_start_read, + sb16midi_end_read, + sb16midi_kick, + sb16midi_command, + sb16midi_buffer_status +}; + + +long +attach_sb16midi (long mem_start, struct address_info *hw_config) +{ + int ok, timeout; + unsigned long flags; + + sb16midi_base = hw_config->io_base; + + if (!sb16midi_detected) + return RET_ERROR (EIO); + + DISABLE_INTR (flags); + for (timeout = 30000; timeout < 0 && !output_ready (); timeout--); /* Wait */ + sb16midi_cmd (UART_MODE_ON); + + ok = 0; + for (timeout = 50000; timeout > 0 && !ok; timeout--) + if (input_avail ()) + if (sb16midi_read () == MPU_ACK) + ok = 1; + + RESTORE_INTR (flags); + + printk ("snd7: <SoundBlaster MPU-401>"); + + my_dev = num_midis; + midi_devs[num_midis++] = &sb16midi_operations; + return mem_start; +} + +static int +reset_sb16midi (void) +{ + unsigned long flags; + int ok, timeout, n; + + /* + * Send the RESET command. Try again if no success at the first time. + */ + + ok = 0; + + DISABLE_INTR (flags); + + for (n = 0; n < 2 && !ok; n++) + { + for (timeout = 30000; timeout < 0 && !output_ready (); timeout--); /* Wait */ + sb16midi_cmd (MPU_RESET); /* Send MPU-401 RESET Command */ + + /* + * Wait at least 25 msec. This method is not accurate so let's make the + * loop bit longer. Cannot sleep since this is called during boot. + */ + + for (timeout = 50000; timeout > 0 && !ok; timeout--) + if (input_avail ()) + if (sb16midi_read () == MPU_ACK) + ok = 1; + + } + + sb16midi_opened = 0; + if (ok) + sb16midi_input_loop (); /* Flush input before enabling interrupts */ + + RESTORE_INTR (flags); + + return ok; +} + + +int +probe_sb16midi (struct address_info *hw_config) +{ + int ok = 0; + + sb16midi_base = hw_config->io_base; + + if (sb_get_irq () < 0) + return 0; + + ok = reset_sb16midi (); + + sb16midi_detected = ok; + return ok; +} + +#endif + +#endif diff --git a/sys/i386/isa/sound/sb_midi.c b/sys/i386/isa/sound/sb_midi.c new file mode 100644 index 0000000..2b0ab52 --- /dev/null +++ b/sys/i386/isa/sound/sb_midi.c @@ -0,0 +1,198 @@ +/* + * sound/sb_dsp.c + * + * The low level driver for the SoundBlaster DS chips. + * + * Copyright by Hannu Savolainen 1993 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ + +#include "sound_config.h" + +#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SB) && !defined(EXCLUDE_MIDI) + +#include "sb.h" +#undef SB_TEST_IRQ + +/* + * The DSP channel can be used either for input or output. Variable + * 'sb_irq_mode' will be set when the program calls read or write first time + * after open. Current version doesn't support mode changes without closing + * and reopening the device. Support for this feature may be implemented in a + * future version of this driver. + */ + +extern int sb_dsp_ok; /* Set to 1 after successful initialization */ + +extern int sb_midi_mode; +extern int sb_midi_busy; /* 1 if the process has output to MIDI */ +extern int sb_dsp_busy; +extern int sb_dsp_highspeed; + +extern volatile int sb_irq_mode; /* IMODE_INPUT, IMODE_OUTPUT + + * or IMODE_NONE */ +extern int sb_dsp_model; /* 1=SB, 2=SB Pro */ +extern int sb_duplex_midi; +extern int sb_intr_active; + +static int +sb_midi_open (int dev, int mode, + void (*input) (int dev, unsigned char data), + void (*output) (int dev) +) +{ + int ret; + + if (!sb_dsp_ok) + { + printk ("SB Error: MIDI hardware not installed\n"); + return RET_ERROR (ENXIO); + } + + if (mode != OPEN_WRITE && !sb_duplex_midi) + { + if (num_midis == 1) + printk ("SoundBlaster: Midi input not currently supported\n"); + return RET_ERROR (EPERM); + } + + sb_midi_mode = NORMAL_MIDI; + if (mode != OPEN_WRITE) + { + if (sb_dsp_busy || sb_intr_active) + return RET_ERROR (EBUSY); + sb_midi_mode = UART_MIDI; + } + + if (sb_dsp_highspeed) + { + printk ("SB Error: Midi output not possible during stereo or high speed audio\n"); + return RET_ERROR (EBUSY); + } + + if (sb_midi_mode == UART_MIDI) + { + sb_irq_mode = IMODE_MIDI; + + sb_reset_dsp (); + + if (!sb_dsp_command (0x35)) + return RET_ERROR (EIO); /* Enter the UART mode */ + sb_intr_active = 1; + + if ((ret = sb_get_irq ()) < 0) + { + sb_reset_dsp (); + return 0; /* IRQ not free */ + } + } + + sb_midi_busy = 1; + + return 0; +} + +static void +sb_midi_close (int dev) +{ + if (sb_midi_mode == UART_MIDI) + { + sb_reset_dsp (); /* The only way to kill the UART mode */ + sb_free_irq (); + } + sb_intr_active = 0; + sb_midi_busy = 0; +} + +static int +sb_midi_out (int dev, unsigned char midi_byte) +{ + unsigned long flags; + + sb_midi_busy = 1; /* Kill all notes after close */ + + if (sb_midi_mode == NORMAL_MIDI) + { + DISABLE_INTR (flags); + if (sb_dsp_command (0x38)) + sb_dsp_command (midi_byte); + else + printk ("SB Error: Unable to send a MIDI byte\n"); + RESTORE_INTR (flags); + } + else + sb_dsp_command (midi_byte); /* UART write */ + + return 1; +} + +static int +sb_midi_start_read (int dev) +{ + if (sb_midi_mode != UART_MIDI) + { + printk ("SoundBlaster: MIDI input not implemented.\n"); + return RET_ERROR (EPERM); + } + return 0; +} + +static int +sb_midi_end_read (int dev) +{ + if (sb_midi_mode == UART_MIDI) + { + sb_reset_dsp (); + sb_intr_active = 0; + } + return 0; +} + +static int +sb_midi_ioctl (int dev, unsigned cmd, unsigned arg) +{ + return RET_ERROR (EPERM); +} + +static struct midi_operations sb_midi_operations = +{ + {"SoundBlaster", 0, 0, SNDCARD_SB}, + sb_midi_open, + sb_midi_close, + sb_midi_ioctl, + sb_midi_out, + sb_midi_start_read, + sb_midi_end_read, + NULL, /* Kick */ + NULL, /* command */ + NULL /* buffer_status */ +}; + +void +sb_midi_init (int model) +{ + midi_devs[num_midis++] = &sb_midi_operations; +} + +#endif diff --git a/sys/i386/isa/sound/sb_mixer.c b/sys/i386/isa/sound/sb_mixer.c new file mode 100644 index 0000000..089a2af --- /dev/null +++ b/sys/i386/isa/sound/sb_mixer.c @@ -0,0 +1,359 @@ + +/* + * sound/sb_mixer.c + * + * The low level mixer driver for the SoundBlaster Pro and SB16 cards. + * + * Copyright by Hannu Savolainen 1993 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ + +#include "sound_config.h" + +#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SB) && !defined(EXCLUDE_SBPRO) +#define __SB_MIXER_C__ + +#include "sb.h" +#include "sb_mixer.h" +#undef SB_TEST_IRQ + +extern int sbc_base; + +static int mixer_initialized = 0; + +static int supported_rec_devices; +static int supported_devices; +static int recmask = 0; +static int mixer_model; +static int mixer_caps; +static mixer_tab *iomap; + +void +sb_setmixer (unsigned int port, unsigned int value) +{ + unsigned long flags; + + DISABLE_INTR (flags); + OUTB ((unsigned char) (port & 0xff), MIXER_ADDR); /* Select register */ + tenmicrosec (); + OUTB ((unsigned char) (value & 0xff), MIXER_DATA); + tenmicrosec (); + RESTORE_INTR (flags); +} + +int +sb_getmixer (unsigned int port) +{ + int val; + unsigned long flags; + + DISABLE_INTR (flags); + OUTB ((unsigned char) (port & 0xff), MIXER_ADDR); /* Select register */ + tenmicrosec (); + val = INB (MIXER_DATA); + tenmicrosec (); + RESTORE_INTR (flags); + + return val; +} + +void +sb_mixer_set_stereo (int mode) +{ + if (!mixer_initialized) + return; + + sb_setmixer (OUT_FILTER, ((sb_getmixer (OUT_FILTER) & ~STEREO_DAC) + | (mode ? STEREO_DAC : MONO_DAC))); +} + +static int +detect_mixer (void) +{ + /* + * Detect the mixer by changing parameters of two volume channels. If the + * values read back match with the values written, the mixer is there (is + * it?) + */ + sb_setmixer (FM_VOL, 0xff); + sb_setmixer (VOC_VOL, 0x33); + + if (sb_getmixer (FM_VOL) != 0xff) + return 0; /* No match */ + if (sb_getmixer (VOC_VOL) != 0x33) + return 0; + + return 1; +} + +static void +change_bits (unsigned char *regval, int dev, int chn, int newval) +{ + unsigned char mask; + int shift; + + mask = (1 << (*iomap)[dev][chn].nbits) - 1; + newval = ((newval * mask) + 50) / 100; /* Scale it */ + + shift = (*iomap)[dev][chn].bitoffs - (*iomap)[dev][LEFT_CHN].nbits + 1; + + *regval &= ~(mask << shift); /* Filter out the previous value */ + *regval |= (newval & mask) << shift; /* Set the new value */ +} + +static int +sb_mixer_get (int dev) +{ + if (!((1 << dev) & supported_devices)) + return RET_ERROR (EINVAL); + + return levels[dev]; +} + +static int +sb_mixer_set (int dev, int value) +{ + int left = value & 0x000000ff; + int right = (value & 0x0000ff00) >> 8; + + int regoffs; + unsigned char val; + + if (left > 100) + left = 100; + if (right > 100) + right = 100; + + if (dev > 31) + return RET_ERROR (EINVAL); + + if (!(supported_devices & (1 << dev))) /* Not supported */ + return RET_ERROR (EINVAL); + + regoffs = (*iomap)[dev][LEFT_CHN].regno; + + if (regoffs == 0) + return RET_ERROR (EINVAL); + + val = sb_getmixer (regoffs); + change_bits (&val, dev, LEFT_CHN, left); + + levels[dev] = left | (left << 8); + + if ((*iomap)[dev][RIGHT_CHN].regno != regoffs) /* Change register */ + { + sb_setmixer (regoffs, val); /* Save the old one */ + regoffs = (*iomap)[dev][RIGHT_CHN].regno; + + if (regoffs == 0) + return left | (left << 8); /* Just left channel present */ + + val = sb_getmixer (regoffs); /* Read the new one */ + } + + change_bits (&val, dev, RIGHT_CHN, right); + sb_setmixer (regoffs, val); + + levels[dev] = left | (right << 8); + return left | (right << 8); +} + +static void +set_recsrc (int src) +{ + sb_setmixer (RECORD_SRC, (sb_getmixer (RECORD_SRC) & ~7) | (src & 0x7)); +} + +static int +set_recmask (int mask) +{ + int devmask, i; + unsigned char regimageL, regimageR; + + devmask = mask & supported_rec_devices; + + switch (mixer_model) + { + case 3: + + if (devmask != SOUND_MASK_MIC && + devmask != SOUND_MASK_LINE && + devmask != SOUND_MASK_CD) + { /* More than one devices selected. Drop the + * previous selection */ + devmask &= ~recmask; + } + + if (devmask != SOUND_MASK_MIC && + devmask != SOUND_MASK_LINE && + devmask != SOUND_MASK_CD) + { /* More than one devices selected. Default to + * mic */ + devmask = SOUND_MASK_MIC; + } + + + if (devmask ^ recmask) /* Input source changed */ + { + switch (devmask) + { + + case SOUND_MASK_MIC: + set_recsrc (SRC_MIC); + break; + + case SOUND_MASK_LINE: + set_recsrc (SRC_LINE); + break; + + case SOUND_MASK_CD: + set_recsrc (SRC_CD); + break; + + default: + set_recsrc (SRC_MIC); + } + } + + break; + + case 4: + if (!devmask) + devmask = SOUND_MASK_MIC; + + regimageL = regimageR = 0; + for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) + if ((1 << i) & devmask) + { + regimageL |= sb16_recmasks_L[i]; + regimageR |= sb16_recmasks_R[i]; + } + sb_setmixer (SB16_IMASK_L, regimageL); + sb_setmixer (SB16_IMASK_R, regimageR); + break; + } + + recmask = devmask; + return recmask; +} + +static int +sb_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg) +{ + if (((cmd >> 8) & 0xff) == 'M') + { + if (cmd & IOC_IN) + switch (cmd & 0xff) + { + case SOUND_MIXER_RECSRC: + return IOCTL_OUT (arg, set_recmask (IOCTL_IN (arg))); + break; + + default: + return IOCTL_OUT (arg, sb_mixer_set (cmd & 0xff, IOCTL_IN (arg))); + } + else + switch (cmd & 0xff) /* Return parameters */ + { + + case SOUND_MIXER_RECSRC: + return IOCTL_OUT (arg, recmask); + break; + + case SOUND_MIXER_DEVMASK: + return IOCTL_OUT (arg, supported_devices); + break; + + case SOUND_MIXER_STEREODEVS: + return IOCTL_OUT (arg, supported_devices & + ~(SOUND_MASK_MIC | SOUND_MASK_SPEAKER)); + break; + + case SOUND_MIXER_RECMASK: + return IOCTL_OUT (arg, supported_rec_devices); + break; + + case SOUND_MIXER_CAPS: + return IOCTL_OUT (arg, mixer_caps); + break; + + default: + return IOCTL_OUT (arg, sb_mixer_get (cmd & 0xff)); + } + } + else + return RET_ERROR (EINVAL); +} + +static struct mixer_operations sb_mixer_operations = +{ + sb_mixer_ioctl +}; + +static void +sb_mixer_reset (void) +{ + int i; + + for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) + sb_mixer_set (i, levels[i]); + set_recmask (SOUND_MASK_MIC); +} + +void +sb_mixer_init (int major_model) +{ + sb_setmixer (0x00, 0); /* Reset mixer */ + + if (!detect_mixer ()) + return; /* No mixer. Why? */ + + mixer_initialized = 1; + mixer_model = major_model; + + switch (major_model) + { + case 3: + mixer_caps = SOUND_CAP_EXCL_INPUT; + supported_devices = SBPRO_MIXER_DEVICES; + supported_rec_devices = SBPRO_RECORDING_DEVICES; + iomap = &sbpro_mix; + break; + + case 4: + mixer_caps = 0; + supported_devices = SB16_MIXER_DEVICES; + supported_rec_devices = SB16_RECORDING_DEVICES; + iomap = &sb16_mix; + break; + + default: + printk ("SB Warning: Unsupported mixer type\n"); + return; + } + + mixer_devs[num_mixers++] = &sb_mixer_operations; + sb_mixer_reset (); +} + +#endif diff --git a/sys/i386/isa/sound/sb_mixer.h b/sys/i386/isa/sound/sb_mixer.h new file mode 100644 index 0000000..304af642 --- /dev/null +++ b/sys/i386/isa/sound/sb_mixer.h @@ -0,0 +1,172 @@ +/* + * sound/sb_mixer.h + * + * Definitions for the SB Pro and SB16 mixers + * + * Copyright by Hannu Savolainen 1993 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ +#define SBPRO_RECORDING_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD) + +#define SBPRO_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE | SOUND_MASK_MIC | \ + SOUND_MASK_CD | SOUND_MASK_VOLUME) + +#define SB16_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | SOUND_MASK_MIC | \ + SOUND_MASK_CD) + +#define SB16_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \ + SOUND_MASK_CD | SOUND_MASK_RECLEV | \ + SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE) + +/* + * Mixer registers + * + * NOTE! RECORD_SRC == IN_FILTER + */ + +/* + * Mixer registers of SB Pro + */ +#define VOC_VOL 0x04 +#define MIC_VOL 0x0A +#define MIC_MIX 0x0A +#define RECORD_SRC 0x0C +#define IN_FILTER 0x0C +#define OUT_FILTER 0x0E +#define MASTER_VOL 0x22 +#define FM_VOL 0x26 +#define CD_VOL 0x28 +#define LINE_VOL 0x2E +#define IRQ_NR 0x80 +#define DMA_NR 0x81 +#define IRQ_STAT 0x82 +#define OPSW 0x3c + +#define FREQ_HI (1 << 3)/* Use High-frequency ANFI filters */ +#define FREQ_LOW 0 /* Use Low-frequency ANFI filters */ +#define FILT_ON 0 /* Yes, 0 to turn it on, 1 for off */ +#define FILT_OFF (1 << 5) + +#define MONO_DAC 0x00 +#define STEREO_DAC 0x02 + +/* + * Mixer registers of SB16 + */ +#define SB16_IMASK_L 0x3d +#define SB16_IMASK_R 0x3e + +#define LEFT_CHN 0 +#define RIGHT_CHN 1 + +struct mixer_def { + unsigned int regno: 8; + unsigned int bitoffs:4; + unsigned int nbits:4; +}; + + +typedef struct mixer_def mixer_tab[32][2]; +typedef struct mixer_def mixer_ent; + +#define MIX_ENT(name, reg_l, bit_l, len_l, reg_r, bit_r, len_r) \ + {{reg_l, bit_l, len_l}, {reg_r, bit_r, len_r}} + +#ifdef __SB_MIXER_C__ +mixer_tab sbpro_mix = { +MIX_ENT(SOUND_MIXER_VOLUME, 0x22, 7, 4, 0x22, 3, 4), +MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_SYNTH, 0x26, 7, 4, 0x26, 3, 4), +MIX_ENT(SOUND_MIXER_PCM, 0x04, 7, 4, 0x04, 3, 4), +MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_LINE, 0x2e, 7, 4, 0x2e, 3, 4), +MIX_ENT(SOUND_MIXER_MIC, 0x0a, 2, 3, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_CD, 0x28, 7, 4, 0x28, 3, 4), +MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0) +}; + +mixer_tab sb16_mix = { +MIX_ENT(SOUND_MIXER_VOLUME, 0x30, 7, 5, 0x31, 7, 5), +MIX_ENT(SOUND_MIXER_BASS, 0x46, 7, 4, 0x47, 7, 4), +MIX_ENT(SOUND_MIXER_TREBLE, 0x44, 7, 4, 0x45, 7, 4), +MIX_ENT(SOUND_MIXER_SYNTH, 0x34, 7, 5, 0x35, 7, 5), +MIX_ENT(SOUND_MIXER_PCM, 0x32, 7, 5, 0x33, 7, 5), +MIX_ENT(SOUND_MIXER_SPEAKER, 0x3b, 7, 2, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_LINE, 0x38, 7, 5, 0x39, 7, 5), +MIX_ENT(SOUND_MIXER_MIC, 0x3a, 7, 5, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_CD, 0x36, 7, 5, 0x37, 7, 5), +MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0), +MIX_ENT(SOUND_MIXER_RECLEV, 0x3f, 7, 2, 0x40, 7, 2) +}; + +static unsigned short levels[SOUND_MIXER_NRDEVICES] = +{ + 0x5a5a, /* Master Volume */ + 0x3232, /* Bass */ + 0x3232, /* Treble */ + 0x4b4b, /* FM */ + 0x4b4b, /* PCM */ + 0x4b4b, /* PC Speaker */ + 0x4b4b, /* Ext Line */ + 0x0000, /* Mic */ + 0x4b4b, /* CD */ + 0x4b4b, /* Recording monitor */ + 0x4b4b, /* SB PCM */ + 0x4b4b}; /* Recording level */ + +static unsigned char sb16_recmasks_L[SOUND_MIXER_NRDEVICES] = +{ + 0x00, /* SOUND_MIXER_VOLUME */ + 0x00, /* SOUND_MIXER_BASS */ + 0x00, /* SOUND_MIXER_TREBLE */ + 0x40, /* SOUND_MIXER_SYNTH */ + 0x00, /* SOUND_MIXER_PCM */ + 0x00, /* SOUND_MIXER_SPEAKER */ + 0x10, /* SOUND_MIXER_LINE */ + 0x01, /* SOUND_MIXER_MIC */ + 0x04, /* SOUND_MIXER_CD */ + 0x00, /* SOUND_MIXER_IMIX */ + 0x00, /* SOUND_MIXER_ALTPCM */ + 0x00 /* SOUND_MIXER_RECLEV */ +}; + +static unsigned char sb16_recmasks_R[SOUND_MIXER_NRDEVICES] = +{ + 0x00, /* SOUND_MIXER_VOLUME */ + 0x00, /* SOUND_MIXER_BASS */ + 0x00, /* SOUND_MIXER_TREBLE */ + 0x20, /* SOUND_MIXER_SYNTH */ + 0x00, /* SOUND_MIXER_PCM */ + 0x00, /* SOUND_MIXER_SPEAKER */ + 0x08, /* SOUND_MIXER_LINE */ + 0x01, /* SOUND_MIXER_MIC */ + 0x02, /* SOUND_MIXER_CD */ + 0x00, /* SOUND_MIXER_IMIX */ + 0x00, /* SOUND_MIXER_ALTPCM */ + 0x00 /* SOUND_MIXER_RECLEV */ +}; +#endif diff --git a/sys/i386/isa/sound/sound_switch.c b/sys/i386/isa/sound/sound_switch.c new file mode 100644 index 0000000..52120d5 --- /dev/null +++ b/sys/i386/isa/sound/sound_switch.c @@ -0,0 +1,444 @@ +/* + * sound/sound_switch.c + * + * The system call switch + * + * Copyright by Hannu Savolainen 1993 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. + * + */ + +#include "sound_config.h" + +#ifdef CONFIGURE_SOUNDCARD + +struct sbc_device + { + int usecount; + }; + +static struct sbc_device sbc_devices[SND_NDEVS] = +{ + {0}}; + +static int in_use = 0; /* Total # of open device files (excluding + + * minor 0) */ + +/* + * /dev/sndstatus -device + */ +static char *status_buf = NULL; +static int status_len, status_ptr; +static int status_busy = 0; + +static int +put_status (char *s) +{ + int l; + + for (l = 0; l < 256, s[l]; l++); /* l=strlen(s); */ + + if (status_len + l >= 4000) + return 0; + + memcpy (&status_buf[status_len], s, l); + status_len += l; + + return 1; +} + +static int +put_status_int (unsigned int val, int radix) +{ + int l, v; + + static char hx[] = "0123456789abcdef"; + char buf[11]; + + if (!val) + return put_status ("0"); + + l = 0; + buf[10] = 0; + + while (val) + { + v = val % radix; + val = val / radix; + + buf[9 - l] = hx[v]; + l++; + } + + if (status_len + l >= 4000) + return 0; + + memcpy (&status_buf[status_len], &buf[10 - l], l); + status_len += l; + + return 1; +} + +static void +init_status (void) +{ + /* + * Write the status information to the status_buf and update status_len. + * There is a limit of 4000 bytes for the data. + */ + + int i; + + status_ptr = 0; + + put_status ("Sound Driver:" SOUND_VERSION_STRING + " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY "@" + SOUND_CONFIG_HOST "." SOUND_CONFIG_DOMAIN ")" + "\n"); + + if (!put_status ("Config options: ")) + return; + if (!put_status_int (SELECTED_SOUND_OPTIONS, 16)) + return; + + if (!put_status ("\n\nHW config: \n")) + return; + + for (i = 0; i < (num_sound_drivers - 1); i++) + { + if (!supported_drivers[i].enabled) + if (!put_status ("(")) + return; + + if (!put_status ("Type ")) + return; + if (!put_status_int (supported_drivers[i].card_type, 10)) + return; + if (!put_status (": ")) + return; + if (!put_status (supported_drivers[i].name)) + return; + if (!put_status (" at 0x")) + return; + if (!put_status_int (supported_drivers[i].config.io_base, 16)) + return; + if (!put_status (" irq ")) + return; + if (!put_status_int (supported_drivers[i].config.irq, 10)) + return; + if (!put_status (" drq ")) + return; + if (!put_status_int (supported_drivers[i].config.dma, 10)) + return; + + if (!supported_drivers[i].enabled) + if (!put_status (")")) + return; + + if (!put_status ("\n")) + return; + } + + if (!put_status ("\nPCM devices:\n")) + return; + + for (i = 0; i < num_dspdevs; i++) + { + if (!put_status_int (i, 10)) + return; + if (!put_status (": ")) + return; + if (!put_status (dsp_devs[i]->name)) + return; + if (!put_status ("\n")) + return; + } + + if (!put_status ("\nSynth devices:\n")) + return; + + for (i = 0; i < num_synths; i++) + { + if (!put_status_int (i, 10)) + return; + if (!put_status (": ")) + return; + if (!put_status (synth_devs[i]->info->name)) + return; + if (!put_status ("\n")) + return; + } + + if (!put_status ("\nMidi devices:\n")) + return; + + for (i = 0; i < num_midis; i++) + { + if (!put_status_int (i, 10)) + return; + if (!put_status (": ")) + return; + if (!put_status (midi_devs[i]->info.name)) + return; + if (!put_status ("\n")) + return; + } + + if (num_mixers) + { + if (!put_status ("\nMixer(s) installed\n")) + return; + } + else + { + if (!put_status ("\nNo mixers installed\n")) + return; + } +} + +static int +read_status (snd_rw_buf * buf, int count) +{ + /* + * Return at most 'count' bytes from the status_buf. + */ + int l, c; + + l = count; + c = status_len - status_ptr; + + if (l > c) + l = c; + if (l <= 0) + return 0; + + COPY_TO_USER (buf, 0, &status_buf[status_ptr], l); + status_ptr += l; + + return l; +} + +int +sound_read_sw (int dev, struct fileinfo *file, snd_rw_buf * buf, int count) +{ + DEB (printk ("sound_read_sw(dev=%d, count=%d)\n", dev, count)); + + switch (dev & 0x0f) + { + case SND_DEV_STATUS: + return read_status (buf, count); + break; + + case SND_DEV_DSP: + case SND_DEV_DSP16: + case SND_DEV_AUDIO: + return audio_read (dev, file, buf, count); + break; + + case SND_DEV_SEQ: + return sequencer_read (dev, file, buf, count); + break; + +#ifndef EXCLUDE_MPU401 + case SND_DEV_MIDIN: + return MIDIbuf_read (dev, file, buf, count); +#endif + + default: + printk ("Sound: Undefined minor device %d\n", dev); + } + + return RET_ERROR (EPERM); +} + +int +sound_write_sw (int dev, struct fileinfo *file, snd_rw_buf * buf, int count) +{ + + DEB (printk ("sound_write_sw(dev=%d, count=%d)\n", dev, count)); + + switch (dev & 0x0f) + { + + case SND_DEV_SEQ: + return sequencer_write (dev, file, buf, count); + break; + + case SND_DEV_DSP: + case SND_DEV_DSP16: + case SND_DEV_AUDIO: + return audio_write (dev, file, buf, count); + break; + + default: + return RET_ERROR (EPERM); + } + + return count; +} + +int +sound_open_sw (int dev, struct fileinfo *file) +{ + int retval; + + DEB (printk ("sound_open_sw(dev=%d) : usecount=%d\n", dev, sbc_devices[dev].usecount)); + + if ((dev >= SND_NDEVS) || (dev < 0)) + { + printk ("Invalid minor device %d\n", dev); + return RET_ERROR (ENXIO); + } + + switch (dev & 0x0f) + { + case SND_DEV_STATUS: + if (status_busy) + return RET_ERROR (EBUSY); + status_busy = 1; + if ((status_buf = (char *) KERNEL_MALLOC (4000)) == NULL) + return RET_ERROR (EIO); + status_len = status_ptr = 0; + init_status (); + break; + + case SND_DEV_CTL: + return 0; + break; + + case SND_DEV_SEQ: + if ((retval = sequencer_open (dev, file)) < 0) + return retval; + break; + +#ifndef EXCLUDE_MPU401 + case SND_DEV_MIDIN: + if ((retval = MIDIbuf_open (dev, file)) < 0) + return retval; + break; +#endif + + case SND_DEV_DSP: + case SND_DEV_DSP16: + case SND_DEV_AUDIO: + if ((retval = audio_open (dev, file)) < 0) + return retval; + break; + + default: + printk ("Invalid minor device %d\n", dev); + return RET_ERROR (ENXIO); + } + + sbc_devices[dev].usecount++; + in_use++; + + return 0; +} + +void +sound_release_sw (int dev, struct fileinfo *file) +{ + + DEB (printk ("sound_release_sw(dev=%d)\n", dev)); + + switch (dev & 0x0f) + { + case SND_DEV_STATUS: + if (status_buf) + KERNEL_FREE (status_buf); + status_buf = NULL; + status_busy = 0; + break; + + case SND_DEV_CTL: + break; + + case SND_DEV_SEQ: + sequencer_release (dev, file); + break; + +#ifndef EXCLUDE_MPU401 + case SND_DEV_MIDIN: + MIDIbuf_release (dev, file); + break; +#endif + + case SND_DEV_DSP: + case SND_DEV_DSP16: + case SND_DEV_AUDIO: + audio_release (dev, file); + break; + + default: + printk ("Sound error: Releasing unknown device 0x%02x\n", dev); + } + + sbc_devices[dev].usecount--; + in_use--; +} + +int +sound_ioctl_sw (int dev, struct fileinfo *file, + unsigned int cmd, unsigned long arg) +{ + DEB (printk ("sound_ioctl_sw(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg)); + + switch (dev & 0x0f) + { + + case SND_DEV_CTL: + + if (!num_mixers) + return RET_ERROR (ENXIO); + + if ((dev >> 4) >= num_mixers) + return RET_ERROR (ENXIO); + + return mixer_devs[dev >> 4]->ioctl (dev >> 4, cmd, arg); + break; + + case SND_DEV_SEQ: + return sequencer_ioctl (dev, file, cmd, arg); + break; + + case SND_DEV_DSP: + case SND_DEV_DSP16: + case SND_DEV_AUDIO: + return audio_ioctl (dev, file, cmd, arg); + break; + +#ifndef EXCLUDE_MPU401 + case SND_DEV_MIDIN: + return MIDIbuf_ioctl (dev, file, cmd, arg); + break; +#endif + + default: + return RET_ERROR (EPERM); + break; + } + + return RET_ERROR (EPERM); +} +#endif diff --git a/sys/i386/isa/spkr.c b/sys/i386/isa/spkr.c deleted file mode 100644 index 7b82f16..0000000 --- a/sys/i386/isa/spkr.c +++ /dev/null @@ -1,523 +0,0 @@ -/* - * spkr.c -- device driver for console speaker on 80386 - * - * v1.1 by Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990 - * modified for 386bsd by Andrew A. Chernov <ache@astral.msk.su> - * 386bsd only clean version, all SYSV stuff removed - * use hz value from param.c - * - * $Id$ - */ - -#include "speaker.h" - -#if NSPEAKER > 0 - -#include "param.h" -#include "systm.h" -#include "kernel.h" -#include "errno.h" -#include "buf.h" -#include "uio.h" -#include "spkr.h" - -/**************** MACHINE DEPENDENT PART STARTS HERE ************************* - * - * This section defines a function tone() which causes a tone of given - * frequency and duration from the 80x86's console speaker. - * Another function endtone() is defined to force sound off, and there is - * also a rest() entry point to do pauses. - * - * Audible sound is generated using the Programmable Interval Timer (PIT) and - * Programmable Peripheral Interface (PPI) attached to the 80x86's speaker. The - * PPI controls whether sound is passed through at all; the PIT's channel 2 is - * used to generate clicks (a square wave) of whatever frequency is desired. - */ - -/* - * PIT and PPI port addresses and control values - * - * Most of the magic is hidden in the TIMER_PREP value, which selects PIT - * channel 2, frequency LSB first, square-wave mode and binary encoding. - * The encoding is as follows: - * - * +----------+----------+---------------+-----+ - * | 1 0 | 1 1 | 0 1 1 | 0 | - * | SC1 SC0 | RW1 RW0 | M2 M1 M0 | BCD | - * +----------+----------+---------------+-----+ - * Counter Write Mode 3 Binary - * Channel 2 LSB first, (Square Wave) Encoding - * MSB second - */ -#define PPI 0x61 /* port of Programmable Peripheral Interface */ -#define PPI_SPKR 0x03 /* turn these PPI bits on to pass sound */ -#define PIT_CTRL 0x43 /* PIT control address */ -#define PIT_COUNT 0x42 /* PIT count address */ -#define PIT_MODE 0xB6 /* set timer mode for sound generation */ - -/* - * Magic numbers for timer control. - */ -#define TIMER_CLK 1193180L /* corresponds to 18.2 MHz tick rate */ - -static int endtone() -/* turn off the speaker, ending current tone */ -{ - wakeup((caddr_t)endtone); - outb(PPI, inb(PPI) & ~PPI_SPKR); -} - -static void tone(hz, ticks) -/* emit tone of frequency hz for given number of ticks */ -unsigned int hz, ticks; -{ - unsigned int divisor = TIMER_CLK / hz; - int sps; - -#ifdef DEBUG - printf("tone: hz=%d ticks=%d\n", hz, ticks); -#endif /* DEBUG */ - - /* set timer to generate clicks at given frequency in Hertz */ - sps = spltty(); - outb(PIT_CTRL, PIT_MODE); /* prepare timer */ - outb(PIT_COUNT, (unsigned char) divisor); /* send lo byte */ - outb(PIT_COUNT, (divisor >> 8)); /* send hi byte */ - splx(sps); - - /* turn the speaker on */ - outb(PPI, inb(PPI) | PPI_SPKR); - - /* - * Set timeout to endtone function, then give up the timeslice. - * This is so other processes can execute while the tone is being - * emitted. - */ - timeout((caddr_t)endtone, (caddr_t)NULL, ticks); - sleep((caddr_t)endtone, PZERO - 1); -} - -static int endrest() -/* end a rest */ -{ - wakeup((caddr_t)endrest); -} - -static void rest(ticks) -/* rest for given number of ticks */ -int ticks; -{ - /* - * Set timeout to endrest function, then give up the timeslice. - * This is so other processes can execute while the rest is being - * waited out. - */ -#ifdef DEBUG - printf("rest: %d\n", ticks); -#endif /* DEBUG */ - timeout((caddr_t)endrest, (caddr_t)NULL, ticks); - sleep((caddr_t)endrest, PZERO - 1); -} - -/**************** PLAY STRING INTERPRETER BEGINS HERE ********************** - * - * Play string interpretation is modelled on IBM BASIC 2.0's PLAY statement; - * M[LNS] are missing and the ~ synonym and octave-tracking facility is added. - * Requires tone(), rest(), and endtone(). String play is not interruptible - * except possibly at physical block boundaries. - */ - -typedef int bool; -#define TRUE 1 -#define FALSE 0 - -#define toupper(c) ((c) - ' ' * (((c) >= 'a') && ((c) <= 'z'))) -#define isdigit(c) (((c) >= '0') && ((c) <= '9')) -#define dtoi(c) ((c) - '0') - -static int octave; /* currently selected octave */ -static int whole; /* whole-note time at current tempo, in ticks */ -static int value; /* whole divisor for note time, quarter note = 1 */ -static int fill; /* controls spacing of notes */ -static bool octtrack; /* octave-tracking on? */ -static bool octprefix; /* override current octave-tracking state? */ - -/* - * Magic number avoidance... - */ -#define SECS_PER_MIN 60 /* seconds per minute */ -#define WHOLE_NOTE 4 /* quarter notes per whole note */ -#define MIN_VALUE 64 /* the most we can divide a note by */ -#define DFLT_VALUE 4 /* default value (quarter-note) */ -#define FILLTIME 8 /* for articulation, break note in parts */ -#define STACCATO 6 /* 6/8 = 3/4 of note is filled */ -#define NORMAL 7 /* 7/8ths of note interval is filled */ -#define LEGATO 8 /* all of note interval is filled */ -#define DFLT_OCTAVE 4 /* default octave */ -#define MIN_TEMPO 32 /* minimum tempo */ -#define DFLT_TEMPO 120 /* default tempo */ -#define MAX_TEMPO 255 /* max tempo */ -#define NUM_MULT 3 /* numerator of dot multiplier */ -#define DENOM_MULT 2 /* denominator of dot multiplier */ - -/* letter to half-tone: A B C D E F G */ -static int notetab[8] = {9, 11, 0, 2, 4, 5, 7}; - -/* - * This is the American Standard A440 Equal-Tempered scale with frequencies - * rounded to nearest integer. Thank Goddess for the good ol' CRC Handbook... - * our octave 0 is standard octave 2. - */ -#define OCTAVE_NOTES 12 /* semitones per octave */ -static int pitchtab[] = -{ -/* C C# D D# E F F# G G# A A# B*/ -/* 0 */ 65, 69, 73, 78, 82, 87, 93, 98, 103, 110, 117, 123, -/* 1 */ 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, -/* 2 */ 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, -/* 3 */ 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, -/* 4 */ 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1975, -/* 5 */ 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, -/* 6 */ 4186, 4435, 4698, 4978, 5274, 5588, 5920, 6272, 6644, 7040, 7459, 7902, -}; - -static void playinit() -{ - octave = DFLT_OCTAVE; - whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO; - fill = NORMAL; - value = DFLT_VALUE; - octtrack = FALSE; - octprefix = TRUE; /* act as though there was an initial O(n) */ -} - -static void playtone(pitch, value, sustain) -/* play tone of proper duration for current rhythm signature */ -int pitch, value, sustain; -{ - register int sound, silence, snum = 1, sdenom = 1; - - /* this weirdness avoids floating-point arithmetic */ - for (; sustain; sustain--) - { - snum *= NUM_MULT; - sdenom *= DENOM_MULT; - } - - if (pitch == -1) - rest(whole * snum / (value * sdenom)); - else - { - sound = (whole * snum) / (value * sdenom) - - (whole * (FILLTIME - fill)) / (value * FILLTIME); - silence = whole * (FILLTIME-fill) * snum / (FILLTIME * value * sdenom); - -#ifdef DEBUG - printf("playtone: pitch %d for %d ticks, rest for %d ticks\n", - pitch, sound, silence); -#endif /* DEBUG */ - - tone(pitchtab[pitch], sound); - if (fill != LEGATO) - rest(silence); - } -} - -static int abs(n) -int n; -{ - if (n < 0) - return(-n); - else - return(n); -} - -static void playstring(cp, slen) -/* interpret and play an item from a notation string */ -char *cp; -size_t slen; -{ - int pitch, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE; - -#define GETNUM(cp, v) for(v=0; isdigit(cp[1]) && slen > 0; ) \ - {v = v * 10 + (*++cp - '0'); slen--;} - for (; slen--; cp++) - { - int sustain, timeval, tempo; - register char c = toupper(*cp); - -#ifdef DEBUG - printf("playstring: %c (%x)\n", c, c); -#endif /* DEBUG */ - - switch (c) - { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': - - /* compute pitch */ - pitch = notetab[c - 'A'] + octave * OCTAVE_NOTES; - - /* this may be followed by an accidental sign */ - if (cp[1] == '#' || cp[1] == '+') - { - ++pitch; - ++cp; - slen--; - } - else if (cp[1] == '-') - { - --pitch; - ++cp; - slen--; - } - - /* - * If octave-tracking mode is on, and there has been no octave- - * setting prefix, find the version of the current letter note - * closest to the last regardless of octave. - */ - if (octtrack && !octprefix) - { - if (abs(pitch-lastpitch) > abs(pitch+OCTAVE_NOTES-lastpitch)) - { - ++octave; - pitch += OCTAVE_NOTES; - } - - if (abs(pitch-lastpitch) > abs((pitch-OCTAVE_NOTES)-lastpitch)) - { - --octave; - pitch -= OCTAVE_NOTES; - } - } - octprefix = FALSE; - lastpitch = pitch; - - /* ...which may in turn be followed by an override time value */ - GETNUM(cp, timeval); - if (timeval <= 0 || timeval > MIN_VALUE) - timeval = value; - - /* ...and/or sustain dots */ - for (sustain = 0; cp[1] == '.'; cp++) - { - slen--; - sustain++; - } - - /* time to emit the actual tone */ - playtone(pitch, timeval, sustain); - break; - - case 'O': - if (cp[1] == 'N' || cp[1] == 'n') - { - octprefix = octtrack = FALSE; - ++cp; - slen--; - } - else if (cp[1] == 'L' || cp[1] == 'l') - { - octtrack = TRUE; - ++cp; - slen--; - } - else - { - GETNUM(cp, octave); - if (octave >= sizeof(pitchtab) / OCTAVE_NOTES) - octave = DFLT_OCTAVE; - octprefix = TRUE; - } - break; - - case '>': - if (octave < sizeof(pitchtab) / OCTAVE_NOTES - 1) - octave++; - octprefix = TRUE; - break; - - case '<': - if (octave > 0) - octave--; - octprefix = TRUE; - break; - - case 'N': - GETNUM(cp, pitch); - for (sustain = 0; cp[1] == '.'; cp++) - { - slen--; - sustain++; - } - playtone(pitch - 1, value, sustain); - break; - - case 'L': - GETNUM(cp, value); - if (value <= 0 || value > MIN_VALUE) - value = DFLT_VALUE; - break; - - case 'P': - case '~': - /* this may be followed by an override time value */ - GETNUM(cp, timeval); - if (timeval <= 0 || timeval > MIN_VALUE) - timeval = value; - for (sustain = 0; cp[1] == '.'; cp++) - { - slen--; - sustain++; - } - playtone(-1, timeval, sustain); - break; - - case 'T': - GETNUM(cp, tempo); - if (tempo < MIN_TEMPO || tempo > MAX_TEMPO) - tempo = DFLT_TEMPO; - whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo; - break; - - case 'M': - if (cp[1] == 'N' || cp[1] == 'n') - { - fill = NORMAL; - ++cp; - slen--; - } - else if (cp[1] == 'L' || cp[1] == 'l') - { - fill = LEGATO; - ++cp; - slen--; - } - else if (cp[1] == 'S' || cp[1] == 's') - { - fill = STACCATO; - ++cp; - slen--; - } - break; - } - } -} - -/******************* UNIX DRIVER HOOKS BEGIN HERE ************************** - * - * This section implements driver hooks to run playstring() and the tone(), - * endtone(), and rest() functions defined above. - */ - -static int spkr_active; /* exclusion flag */ -static struct buf *spkr_inbuf; /* incoming buf */ - -int spkropen(dev) -dev_t dev; -{ -#ifdef DEBUG - printf("spkropen: entering with dev = %x\n", dev); -#endif /* DEBUG */ - - if (minor(dev) != 0) - return(ENXIO); - else if (spkr_active) - return(EBUSY); - else - { - playinit(); - spkr_inbuf = geteblk(DEV_BSIZE); - spkr_active = 1; - } - return(0); -} - -int spkrwrite(dev, uio) -dev_t dev; -struct uio *uio; -{ - register unsigned n; - char *cp; - int error; -#ifdef DEBUG - printf("spkrwrite: entering with dev = %x, count = %d\n", - dev, uio->uio_resid); -#endif /* DEBUG */ - - if (minor(dev) != 0) - return(ENXIO); - else - { - n = MIN(DEV_BSIZE, uio->uio_resid); - cp = spkr_inbuf->b_un.b_addr; - error = uiomove(cp, n, uio); - if (!error) - playstring(cp, n); - return(error); - } -} - -int spkrclose(dev) -dev_t dev; -{ -#ifdef DEBUG - printf("spkrclose: entering with dev = %x\n", dev); -#endif /* DEBUG */ - - if (minor(dev) != 0) - return(ENXIO); - else - { - endtone(); - brelse(spkr_inbuf); - spkr_active = 0; - } - return(0); -} - -int spkrioctl(dev, cmd, cmdarg) -dev_t dev; -int cmd; -caddr_t cmdarg; -{ -#ifdef DEBUG - printf("spkrioctl: entering with dev = %x, cmd = %x\n", dev, cmd); -#endif /* DEBUG */ - - if (minor(dev) != 0) - return(ENXIO); - else if (cmd == SPKRTONE) - { - tone_t *tp = (tone_t *)cmdarg; - - if (tp->frequency == 0) - rest(tp->duration); - else - tone(tp->frequency, tp->duration); - } - else if (cmd == SPKRTUNE) - { - tone_t *tp = (tone_t *)(*(caddr_t *)cmdarg); - tone_t ttp; - int error; - - for (; ; tp++) { - error = copyin(tp, &ttp, sizeof(tone_t)); - if (error) - return(error); - if (ttp.duration == 0) - break; - if (ttp.frequency == 0) - rest(ttp.duration); - else - tone(ttp.frequency, ttp.duration); - } - } - else - return(EINVAL); - return(0); -} - -#endif /* NSPEAKER > 0 */ -/* spkr.c ends here */ diff --git a/sys/i386/isa/syscons.c b/sys/i386/isa/syscons.c deleted file mode 100644 index e639252..0000000 --- a/sys/i386/isa/syscons.c +++ /dev/null @@ -1,2415 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz and Don Ahn. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)pccons.c 5.11 (Berkeley) 5/21/91 - * from: @(#)syscons.c 1.0 930928 - * $Id: syscons.c,v 1.13 1993/10/16 13:46:23 rgrimes Exp $ - * - * Heavily modified by Søren Schmidt (sos@login.dkuug.dk) to provide: - * - * virtual consoles, SYSV ioctl's, ANSI emulation - */ - -#define STAR_SAVER -/* #define FAT_CURSOR /* This breaks on some CGA displays */ - -#include "param.h" -#include "conf.h" -#include "ioctl.h" -#include "proc.h" -#include "user.h" -#include "tty.h" -#include "uio.h" -#include "callout.h" -#include "systm.h" -#include "kernel.h" -#include "syslog.h" -#include "errno.h" -#include "machine/console.h" -#include "malloc.h" -#include "i386/isa/icu.h" -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "machine/pc/display.h" -#include "i386/i386/cons.h" -#include "machine/psl.h" -#include "machine/frame.h" -#include "sc.h" -#include "ddb.h" -#include "iso8859.font" -#include "kbdtables.h" - -#if NSC > 0 -#ifndef NCONS -#define NCONS 12 -#endif - -/* status flags */ -#define LOCK_KEY_MASK 0x0000F -#define LED_MASK 0x00007 -#define UNKNOWN_MODE 0x00010 -#define KBD_RAW_MODE 0x00020 -#define SWITCH_WAIT_REL 0x00040 -#define SWITCH_WAIT_ACQ 0x00080 - -/* virtual video memory addresses */ -#define MONO_BUF (KERNBASE + 0xB0000) -#define CGA_BUF (KERNBASE + 0xB8000) -#define VGA_BUF (KERNBASE + 0xA0000) -#define VIDEOMEM 0x000A0000 -#define MEMSIZE 0x00020000 - -/* misc defines */ -#define MAX_ESC_PAR 3 -#define TEXT80x25 1 -#define TEXT80x50 2 -#define COL 80 -#define ROW 25 -#ifndef XTALSPEED -#define XTALSPEED 1193182 /* should be in isa.h */ -#endif - -/* defines related to hardware addresses */ -#define MONO_BASE 0x3B4 /* crt controller base mono */ -#define COLOR_BASE 0x3D4 /* crt controller base color */ -#define ATC IO_VGA+0x00 /* attribute controller */ -#define TSIDX IO_VGA+0x04 /* timing sequencer idx */ -#define TSREG IO_VGA+0x05 /* timing sequencer data */ -#define PIXMASK IO_VGA+0x06 /* pixel write mask */ -#define PALRADR IO_VGA+0x07 /* palette read address */ -#define PALWADR IO_VGA+0x08 /* palette write address */ -#define PALDATA IO_VGA+0x09 /* palette data register */ -#define GDCIDX IO_VGA+0x0E /* graph data controller idx */ -#define GDCREG IO_VGA+0x0F /* graph data controller data */ - -typedef struct term_stat { - int esc; /* processing escape sequence */ - int n_par; /* # of parameters to ESC */ - int last_par; /* last parameter # */ - int par[MAX_ESC_PAR]; /* contains ESC parameters */ - int attr; /* current attributes */ - int std_attr; /* normal attributes */ - int rev_attr; /* reverse attributes */ -} term_stat; - -typedef struct scr_stat { - u_short *crt_base; /* address of screen memory */ - u_short *scr; /* buffer when off screen */ - u_short *crtat; /* cursor address */ - int posx; /* current X position */ - int posy; /* current Y position */ - int max_posx; /* X size */ - int max_posy; /* X size */ - term_stat term; /* terminal emulation stuff */ - char cursor_start; /* cursor start line # */ - char cursor_end; /* cursor start end # */ - u_char border; /* border color */ - u_short bell_duration; - u_short bell_pitch; - u_short status; /* status (bitfield) */ - u_short mode; /* mode */ - pid_t pid; /* pid of controlling proc */ - struct proc *proc; /* proc* of controlling proc */ - struct vt_mode smode; /* switch mode */ -} scr_stat; - -typedef struct default_attr { - int std_attr; /* normal attributes */ - int rev_attr; /* reverse attributes */ -} default_attr; - -static default_attr user_default = { - (FG_LIGHTGREY | BG_BLACK) << 8, - (FG_BLACK | BG_LIGHTGREY) << 8 -}; - -static default_attr kernel_default = { - (FG_WHITE | BG_BLACK) << 8, - (FG_BLACK | BG_LIGHTGREY) << 8 -}; - -static default_attr *current_default; - -static scr_stat cons_scr_stat[NCONS]; -static scr_stat *cur_scr_stat = &cons_scr_stat[0]; -static scr_stat *new_scp, *old_scp; -static term_stat kernel_console; -static int switch_in_progress = 0; - -u_short *Crtat = (u_short *)MONO_BUF; -static u_short *crtat = 0; -static u_int crtc_addr = MONO_BASE; -static char crtc_vga = 0; -static u_char shfts = 0, ctls = 0, alts = 0, agrs = 0; -static u_char nlkcnt = 0, clkcnt = 0, slkcnt = 0, alkcnt = 0; -static char palette[3*256]; -static const u_int n_fkey_tab = sizeof(fkey_tab) / sizeof(*fkey_tab); -static int cur_cursor_pos = -1; -static char in_putc, nx_scr; -static char saved_console = -1; /* saved console number */ -static long scrn_blank_time = 0; /* screen saver timout value */ -static int scrn_blanked = 0; /* screen saver active flag */ -static long scrn_time_stamp; -static u_char scr_map[256]; - -struct tty pccons[NCONS]; -struct tty *cur_pccons = &pccons[0]; -struct tty *new_pccons; - -extern int hz; -extern struct timeval time; - -#define CSF_ACTIVE 0x1 /* timeout active */ -#define CSF_POLLING 0x2 /* polling for input */ - -struct pcconsoftc { - char cs_flags; - char cs_lastc; /* last char sent */ - int cs_timo; /* timeouts since interrupt */ - u_long cs_wedgecnt; /* times restarted */ -} pcconsoftc = {0, 0, 0, 0}; - - -/* special characters */ -#define bs 8 -#define lf 10 -#define cr 13 -#define cntlc 3 -#define del 0177 -#define cntld 4 - -/* function prototypes */ -int pcprobe(struct isa_device *dev); -int pcattach(struct isa_device *dev); -int pcopen(dev_t dev, int flag, int mode, struct proc *p); -int pcclose(dev_t dev, int flag, int mode, struct proc *p); -int pcread(dev_t dev, struct uio *uio, int flag); -int pcwrite(dev_t dev, struct uio *uio, int flag); -int pcparam(struct tty *tp, struct termios *t); -int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p); -int pcxint(dev_t dev); -int pcstart(struct tty *tp); -int pccnprobe(struct consdev *cp); -int pccninit(struct consdev *cp); -int pccnputc(dev_t dev, char c); -int pccngetc(dev_t dev); -int scintr(dev_t dev, int irq, int cpl); -void scrn_saver(int test); -static struct tty *get_pccons(dev_t dev); -static scr_stat *get_scr_stat(dev_t dev); -static int get_scr_num(scr_stat *scp); -static void cursor_shape(int start, int end); -static void get_cursor_shape(int *start, int *end); -static void cursor_pos(void); -static void clear_screen(scr_stat *scp); -static switch_scr(u_int next_scr); -static void exchange_scr(void); -static void move_crsr(scr_stat *scp, int x, int y); -static void move_up(u_short *s, u_short *d, u_int len); -static void move_down(u_short *s, u_short *d, u_int len); -static void scan_esc(scr_stat *scp, u_char c); -static void ansi_put(scr_stat *scp, u_char c); -void consinit(void); -static void sput(u_char c); -static u_char *get_fstr(u_int c, u_int *len); -static update_leds(int which); -void reset_cpu(void); -u_int sgetc(int noblock); -int pcmmap(dev_t dev, int offset, int nprot); -int getchar(void); -static void kbd_wait(void); -static void kbd_cmd(u_char command); -static void set_mode(scr_stat *scp); -static void set_border(int color); -static load_font(int segment, int size, char* font); -static void save_palette(void); -static void load_palette(void); -static change_winsize(struct tty *tp, int x, int y); - -struct isa_driver scdriver = { - pcprobe, pcattach, "sc", -}; - - -int pcprobe(struct isa_device *dev) -{ - u_char c; - int again = 0; - - /* Enable interrupts and keyboard controller */ - kbd_wait(); - outb(KB_STAT, KB_WRITE); - kbd_cmd(0x4D); - - /* Start keyboard stuff RESET */ - kbd_cmd(KB_RESET); - while ((c=inb(KB_DATA)) != KB_ACK) { - if ((c == 0xFE) || (c == 0xFF)) { - if (!again) - printf("KEYBOARD disconnected: RECONNECT \n"); - kbd_cmd(KB_RESET); - again = 1; - } - } - kbd_wait(); - return (IO_KBDSIZE); -} - - -int pcattach(struct isa_device *dev) -{ - scr_stat *scp; - int start = -1, end = -1, i; - - if (crtc_vga) - if (crtc_addr == MONO_BASE) - printf("VGA mono"); - else - printf("VGA color"); - else - if (crtc_addr == MONO_BASE) - printf("MDA/hercules"); - else - printf("CGA/EGA"); - - if (NCONS > 1) - printf(" <%d virtual consoles>\n", NCONS); - else - printf("\n"); -#ifdef FAT_CURSOR - start = 0; - end = 18; -#endif - if (crtc_vga) { -#ifndef FAT_CURSOR - get_cursor_shape(&start, &end); -#endif - save_palette(); - load_font(0, 16, font_8x16); - load_font(1, 8, font_8x8); - load_font(2, 14, font_8x14); - } - current_default = &user_default; - for (i = 0; i < NCONS; i++) { - scp = &cons_scr_stat[i]; - scp->scr = (u_short *)malloc(COL * ROW * 2, M_DEVBUF, M_NOWAIT); - scp->mode = TEXT80x25; - scp->term.esc = 0; - scp->term.std_attr = current_default->std_attr; - scp->term.rev_attr = current_default->rev_attr; - scp->term.attr = scp->term.std_attr; - scp->border = BG_BLACK; - scp->cursor_start = start; - scp->cursor_end = end; - scp->max_posx = COL; - scp->max_posy = ROW; - scp->bell_pitch = 800; - scp->bell_duration = 10; - scp->status = 0; - scp->pid = 0; - scp->proc = NULL; - scp->smode.mode = VT_AUTO; - if (i > 0) { - scp->crt_base = scp->crtat = scp->scr; - fillw(scp->term.attr|scr_map[0x20], scp->scr, COL*ROW); - } - } - /* get cursor going */ -#ifdef FAT_CURSOR - cursor_shape(cons_scr_stat[0].cursor_start, - cons_scr_stat[0].cursor_end); -#endif - cursor_pos(); -} - - -static struct tty *get_pccons(dev_t dev) -{ - int i = minor(dev); - - if (i >= NCONS) - return(NULL); - return(&pccons[i]); -} - - -static scr_stat *get_scr_stat(dev_t dev) -{ - int i = minor(dev); - - if (i >= NCONS) - return(NULL); - return(&cons_scr_stat[i]); -} - - -static int get_scr_num(scr_stat *scp) /* allways call with legal scp !! */ -{ - int i = 0; - - while ((i < NCONS) && (cur_scr_stat != &cons_scr_stat[i])) i++; - return i; -} - -pcopen(dev_t dev, int flag, int mode, struct proc *p) -{ - struct tty *tp = get_pccons(dev); - - if (!tp) - return(ENXIO); - tp->t_oproc = pcstart; - tp->t_param = pcparam; - tp->t_dev = dev; - if ((tp->t_state & TS_ISOPEN) == 0) { - tp->t_state |= TS_WOPEN; - ttychars(tp); - tp->t_iflag = TTYDEF_IFLAG; - tp->t_oflag = TTYDEF_OFLAG; - tp->t_cflag = TTYDEF_CFLAG; - tp->t_lflag = TTYDEF_LFLAG; - tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; - pcparam(tp, &tp->t_termios); - ttsetwater(tp); - } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0) - return(EBUSY); - tp->t_state |= TS_CARR_ON; - return((*linesw[tp->t_line].l_open)(dev, tp)); -} - - -pcclose(dev_t dev, int flag, int mode, struct proc *p) -{ - struct tty *tp = get_pccons(dev); - struct scr_stat *scp; - - if (!tp) - return(ENXIO); - scp = get_scr_stat(tp->t_dev); - scp->pid = 0; - scp->proc = NULL; - scp->smode.mode = VT_AUTO; - (*linesw[tp->t_line].l_close)(tp, flag); - ttyclose(tp); - return(0); -} - - -pcread(dev_t dev, struct uio *uio, int flag) -{ - struct tty *tp = get_pccons(dev); - - if (!tp) - return(ENXIO); - return((*linesw[tp->t_line].l_read)(tp, uio, flag)); -} - - -pcwrite(dev_t dev, struct uio *uio, int flag) -{ - struct tty *tp = get_pccons(dev); - - if (!tp) - return(ENXIO); - return((*linesw[tp->t_line].l_write)(tp, uio, flag)); -} - - -/* - * Got a console interrupt, keyboard action ! - * Catch the character, and see who it goes to. - */ -scintr(dev_t dev, int irq, int cpl) -{ - int c, len; - u_char *cp; - - /* make screensaver happy */ - scrn_time_stamp = time.tv_sec; - if (scrn_blanked) - scrn_saver(0); - c = sgetc(1); - if (c & 0x100) - return; - if ((cur_pccons->t_state & TS_ISOPEN) == 0) - return; - if (pcconsoftc.cs_flags & CSF_POLLING) - return; - if (c < 0x100) - (*linesw[cur_pccons->t_line].l_rint)(c & 0xFF, cur_pccons); - else if (cp = get_fstr((u_int)c, (u_int *)&len)) { - while (len-- > 0) - (*linesw[cur_pccons->t_line].l_rint) - (*cp++ & 0xFF, cur_pccons); - } -} - - -/* - * Set line parameters - */ -pcparam(struct tty *tp, struct termios *t) -{ - int cflag = t->c_cflag; - - /* and copy to tty */ - tp->t_ispeed = t->c_ispeed; - tp->t_ospeed = t->c_ospeed; - tp->t_cflag = cflag; - return(0); -} - - -pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) -{ - int i, error; - struct tty *tp; - struct syscframe *fp; - scr_stat *scp; - - tp = get_pccons(dev); - if (!tp) - return ENXIO; - scp = get_scr_stat(tp->t_dev); - - switch (cmd) { /* process console hardware related ioctl's */ - - case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */ - scrn_blank_time = *(int*)data; - return 0; - - case CONS_80x25TEXT: /* set 80x25 text mode */ - if (!crtc_vga) - return ENXIO; - scp->mode = TEXT80x25; - scp->max_posy = 25; - free(scp->scr, M_DEVBUF); - scp->scr = (u_short *)malloc(scp->max_posx*scp->max_posy*2, - M_DEVBUF, M_NOWAIT); - if (scp != cur_scr_stat) - scp->crt_base = scp->scr; - set_mode(scp); - clear_screen(scp); - change_winsize(tp, scp->max_posx, scp->max_posy); - return 0; - - case CONS_80x50TEXT: /* set 80x50 text mode */ - if (!crtc_vga) - return ENXIO; - scp->mode = TEXT80x50; - scp->max_posy = 50; - free(scp->scr, M_DEVBUF); - scp->scr = (u_short *)malloc(scp->max_posx*scp->max_posy*2, - M_DEVBUF, M_NOWAIT); - if (scp != cur_scr_stat) - scp->crt_base = scp->scr; - set_mode(scp); - clear_screen(scp); - change_winsize(tp, scp->max_posx, scp->max_posy); - return 0; - - case CONS_GETVERS: /* get version number */ - *(int*)data = 0x100; /* version 1.0 */ - return 0; - - case CONS_GETINFO: /* get current (virtual) console info */ - if (*data == sizeof(struct vid_info)) { - vid_info_t *ptr = (vid_info_t*)data; - ptr->m_num = get_scr_num(scp); - ptr->mv_col = scp->posx; - ptr->mv_row = scp->posy; - ptr->mv_csz = scp->max_posx; - ptr->mv_rsz = scp->max_posy; - ptr->mv_norm.fore = (scp->term.std_attr & 0x0f00)>>8; - ptr->mv_norm.back = (scp->term.std_attr & 0xf000)>>12; - ptr->mv_rev.fore = (scp->term.rev_attr & 0x0f00)>>8; - ptr->mv_rev.back = (scp->term.rev_attr & 0xf000)>>12; - ptr->mv_grfc.fore = 0; /* not supported */ - ptr->mv_grfc.back = 0; /* not supported */ - ptr->mv_ovscan = scp->border; - ptr->mk_keylock = scp->status & LOCK_KEY_MASK; - return 0; - } - return EINVAL; - - case VT_SETMODE: /* set screen switcher mode */ - bcopy(data, &scp->smode, sizeof(struct vt_mode)); - if (scp->smode.mode == VT_PROCESS) { - scp->proc = p; - scp->pid = scp->proc->p_pid; - } - return 0; - - case VT_GETMODE: /* get screen switcher mode */ - bcopy(&scp->smode, data, sizeof(struct vt_mode)); - return 0; - - case VT_RELDISP: /* screen switcher ioctl */ - switch(*data) { - case VT_FALSE: /* user refuses to release screen, abort */ - if (scp == old_scp && (scp->status & SWITCH_WAIT_REL)) { - old_scp->status &= ~SWITCH_WAIT_REL; - switch_in_progress = 0; - return 0; - } - return EINVAL; - - case VT_TRUE: /* user has released screen, go on */ - if (scp == old_scp && (scp->status & SWITCH_WAIT_REL)) { - scp->status &= ~SWITCH_WAIT_REL; - exchange_scr(); - if (new_scp->smode.mode == VT_PROCESS) { - new_scp->status |= SWITCH_WAIT_ACQ; - psignal(new_scp->proc, - new_scp->smode.acqsig); - } - else - switch_in_progress = 0; - return 0; - } - return EINVAL; - - case VT_ACKACQ: /* acquire acknowledged, switch completed */ - if (scp == new_scp && (scp->status & SWITCH_WAIT_ACQ)) { - scp->status &= ~SWITCH_WAIT_ACQ; - switch_in_progress = 0; - return 0; - } - return EINVAL; - - default: - return EINVAL; - } - /* NOT REACHED */ - - case VT_OPENQRY: /* return free virtual console */ - for (i = 0; i < NCONS; i++) - if (!(pccons[i].t_state & TS_ISOPEN)) { - *data = i + 1; - return 0; - } - return EINVAL; - /* NOT REACHED */ - - case VT_GETACTIVE: /* return number of active virtual console */ - *data = get_scr_num(scp) + 1; - return 0; - - case VT_ACTIVATE: /* switch to screen *data */ - return switch_scr((*data) - 1); - - case VT_WAITACTIVE: /* wait for switch to occur */ - if (*data > NCONS) - return EINVAL; - if (minor(dev) == (*data) - 1) - return 0; - if (*data == 0) { - if (scp == cur_scr_stat) - return 0; - while ((error=tsleep(&scp->smode, - PZERO|PCATCH, "waitvt", 0)) - == ERESTART) ; - } - else - while ((error=tsleep(&cons_scr_stat[*data].smode, - PZERO|PCATCH, "waitvt", 0)) - == ERESTART) ; - return error; - - case KDENABIO: /* allow io operations */ - fp = (struct syscframe *)p->p_regs; - fp->sf_eflags |= PSL_IOPL; - return 0; - - case KDDISABIO: /* disallow io operations (default) */ - fp = (struct syscframe *)p->p_regs; - fp->sf_eflags &= ~PSL_IOPL; - return 0; - - case KDSETMODE: /* set current mode of this (virtual) console */ - switch (*data) { - case KD_TEXT: /* switch to TEXT (known) mode */ - /* restore fonts & palette ! */ - if (crtc_vga) { - load_font(0, 16, font_8x16); - load_font(1, 8, font_8x8); - load_font(2, 14, font_8x14); - load_palette(); - } - /* FALL THROUGH */ - - case KD_TEXT1: /* switch to TEXT (known) mode */ - /* no restore fonts & palette */ - scp->status &= ~UNKNOWN_MODE; - set_mode(scp); - clear_screen(scp); - return 0; - - case KD_GRAPHICS:/* switch to GRAPHICS (unknown) mode */ - scp->status |= UNKNOWN_MODE; - return 0; - default: - return EINVAL; - } - /* NOT REACHED */ - - case KDGETMODE: /* get current mode of this (virtual) console */ - *data = (scp->status & UNKNOWN_MODE) ? KD_GRAPHICS : KD_TEXT; - return 0; - - case KDSBORDER: /* set border color of this (virtual) console */ - if (!crtc_vga) - return ENXIO; - scp->border = *data; - if (scp == cur_scr_stat) - set_border(scp->border); - return 0; - - case KDSKBSTATE: /* set keyboard state (locks) */ - if (*data >= 0 && *data <= LOCK_KEY_MASK) { - scp->status &= ~LOCK_KEY_MASK; - scp->status |= *data; - if (scp == cur_scr_stat) - update_leds(scp->status & LED_MASK); - return 0; - } - return EINVAL; - - case KDGKBSTATE: /* get keyboard state (locks) */ - *data = scp->status & LOCK_KEY_MASK; - return 0; - - case KDSETRAD: /* set keyboard repeat & delay rates */ - if (*(u_char*)data < 0x80) { - kbd_cmd(KB_SETRAD); - kbd_cmd(*data & 0x7f); - return 0; - } - return EINVAL; - - case KDSKBMODE: /* set keyboard mode */ - switch (*data) { - case K_RAW: /* switch to RAW scancode mode */ - scp->status |= KBD_RAW_MODE; - return 0; - - case K_XLATE: /* switch to XLT ascii mode */ - scp->status &= ~KBD_RAW_MODE; - return 0; - default: - return EINVAL; - } - /* NOT REACHED */ - - case KDGKBMODE: /* get keyboard mode */ - *data = (scp->status & KBD_RAW_MODE) ? K_RAW : K_XLATE; - return 0; - - case KDMKTONE: /* sound the bell */ - if (scp == cur_scr_stat) - sysbeep(scp->bell_pitch, scp->bell_duration); - return 0; - - case KIOCSOUND: /* make tone (*data) hz */ - if (scp == cur_scr_stat) { - if (*(int*)data) { - int pitch = XTALSPEED/(*(int*)data); - /* enable counter 2 */ - outb(0x61, inb(0x61) | 3); - /* set command for counter 2, 2 byte write */ - outb(0x43, 0xb6); - /* set pitch */ - outb(0x42, pitch); - outb(0x42, (pitch>>8)); - } - else { - /* disable counter 2 */ - outb(0x61, inb(0x61) & 0xFC); - } - } - return 0; - - case KDGKBTYPE: /* get keyboard type */ - *data = 0; /* type not known (yet) */ - return 0; - - case KDSETLED: /* set keyboard LED status */ - if (*data >= 0 && *data <= LED_MASK) { - scp->status &= ~LED_MASK; - scp->status |= *data; - if (scp == cur_scr_stat) - update_leds(scp->status & LED_MASK); - return 0; - } - return EINVAL; - - case KDGETLED: /* get keyboard LED status */ - *data = scp->status & LED_MASK; - return 0; - - case GETFKEY: /* get functionkey string */ - if (*(u_short*)data < n_fkey_tab) { - fkeyarg_t *ptr = (fkeyarg_t*)data; - bcopy(&fkey_tab[ptr->keynum].str, - ptr->keydef, - fkey_tab[ptr->keynum].len); - ptr->flen = fkey_tab[ptr->keynum].len; - return 0; - } - else - return EINVAL; - - case SETFKEY: /* set functionkey string */ - if (*(u_short*)data < n_fkey_tab) { - fkeyarg_t *ptr = (fkeyarg_t*)data; - bcopy(ptr->keydef, - &fkey_tab[ptr->keynum].str, - min(ptr->flen, MAXFK)); - fkey_tab[ptr->keynum].len = min(ptr->flen, MAXFK); - return 0; - } - else - return EINVAL; - - case GIO_SCRNMAP: /* get output translation table */ - bcopy(&scr_map, data, sizeof(scr_map)); - return 0; - - case PIO_SCRNMAP: /* set output translation table */ - bcopy(data, &scr_map, sizeof(scr_map)); - return 0; - - case GIO_KEYMAP: /* get keyboard translation table */ - bcopy(&key_map, data, sizeof(key_map)); - return 0; - - case PIO_KEYMAP: /* set keyboard translation table */ - bcopy(data, &key_map, sizeof(key_map)); - return 0; - - case PIO_FONT8x8: /* set 8x8 dot font */ - if (!crtc_vga) - return ENXIO; - bcopy(data, &font_8x8, sizeof(font_8x8)); - load_font(1, 8, font_8x8); - return 0; - - case GIO_FONT8x8: /* get 8x8 dot font */ - if (!crtc_vga) - return ENXIO; - bcopy(&font_8x8, data, sizeof(font_8x8)); - return 0; - - case PIO_FONT8x14: /* set 8x14 dot font */ - if (!crtc_vga) - return ENXIO; - bcopy(data, &font_8x14, sizeof(font_8x14)); - load_font(2, 14, font_8x14); - return 0; - - case GIO_FONT8x14: /* get 8x14 dot font */ - if (!crtc_vga) - return ENXIO; - bcopy(&font_8x14, data, sizeof(font_8x14)); - return 0; - - case PIO_FONT8x16: /* set 8x16 dot font */ - if (!crtc_vga) - return ENXIO; - bcopy(data, &font_8x16, sizeof(font_8x16)); - load_font(0, 16, font_8x16); - return 0; - - case GIO_FONT8x16: /* get 8x16 dot font */ - if (!crtc_vga) - return ENXIO; - bcopy(&font_8x16, data, sizeof(font_8x16)); - return 0; - - case CONSOLE_X_MODE_ON: /* just to be compatible */ - if (saved_console < 0) { - saved_console = get_scr_num(cur_scr_stat); - switch_scr(minor(dev)); - fp = (struct syscframe *)p->p_regs; - fp->sf_eflags |= PSL_IOPL; - scp->status |= UNKNOWN_MODE; - scp->status |= KBD_RAW_MODE; - return 0; - } - return EAGAIN; - - case CONSOLE_X_MODE_OFF:/* just to be compatible */ - fp = (struct syscframe *)p->p_regs; - fp->sf_eflags &= ~PSL_IOPL; - if (crtc_vga) { - load_font(0, 16, font_8x16); - load_font(1, 8, font_8x8); - load_font(2, 14, font_8x14); - load_palette(); - } - scp->status &= ~UNKNOWN_MODE; - set_mode(scp); - clear_screen(scp); - scp->status &= ~KBD_RAW_MODE; - switch_scr(saved_console); - saved_console = -1; - return 0; - - case CONSOLE_X_BELL: /* more compatibility */ - /* - * if set, data is a pointer to a length 2 array of - * integers. data[0] is the pitch in Hz and data[1] - * is the duration in msec. - */ - if (data) - sysbeep(XTALSPEED/((int*)data)[0], ((int*)data)[1]*hz/3000); - else - sysbeep(0x31b, hz/4); - return 0; - - default: - break; - } - - error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); - if (error >= 0) - return(error); - error = ttioctl(tp, cmd, data, flag); - if (error >= 0) - return(error); - return(ENOTTY); -} - - -pcxint(dev_t dev) -{ - pccons[minor(dev)].t_state &= ~TS_BUSY; - pcconsoftc.cs_timo = 0; - if (pccons[minor(dev)].t_line) - (*linesw[pccons[minor(dev)].t_line].l_start) - (&pccons[minor(dev)]); - else - pcstart(&pccons[minor(dev)]); -} - - -pcstart(struct tty *tp) -{ - int c, s; - scr_stat *scp = get_scr_stat(tp->t_dev); - - s = spltty(); - if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) - for (;;) { - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { - if (tp->t_state & TS_ASLEEP) { - tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); - } - if (tp->t_wsel) { - selwakeup(tp->t_wsel, - tp->t_state & TS_WCOLL); - tp->t_wsel = 0; - tp->t_state &= ~TS_WCOLL; - } - } - if (RB_LEN(&tp->t_out) == 0) - break; - if (scp->status & SLKED) - break; - c = getc(&tp->t_out); - tp->t_state |= TS_BUSY; - splx(s); - ansi_put(scp, c); - s = spltty(); - tp->t_state &= ~TS_BUSY; - } - splx(s); -} - - -pccnprobe(struct consdev *cp) -{ - int maj; - - /* locate the major number */ - for (maj = 0; maj < nchrdev; maj++) - if (cdevsw[maj].d_open == pcopen) - break; - - /* initialize required fields */ - cp->cn_dev = makedev(maj, 0); - cp->cn_tp = &pccons[0]; - cp->cn_pri = CN_INTERNAL; -} - - -pccninit(struct consdev *cp) -{ -} - - -pccnputc(dev_t dev, char c) -{ - int pos; - - if (cur_scr_stat->status & UNKNOWN_MODE) - return; - if (c == '\n') - sput('\r'); - sput(c); - pos = cur_scr_stat->crtat - cur_scr_stat->crt_base; - if (pos != cur_cursor_pos) { - cur_cursor_pos = pos; - outb(crtc_addr,14); - outb(crtc_addr+1,pos >> 8); - outb(crtc_addr,15); - outb(crtc_addr+1,pos&0xff); - } -} - - -pccngetc(dev_t dev) -{ - int c, s; - - s = spltty(); /* block scintr while we poll */ - c = sgetc(0); - splx(s); - if (c == '\r') c = '\n'; - return(c); -} - -#if !defined(STAR_SAVER) && !defined(SNAKE_SAVER) - -void scrn_saver(int test) -{ - u_char val; - - if (test) { - scrn_blanked = 1; - outb(TSIDX, 0x01); val = inb(TSREG); - outb(TSIDX, 0x01); outb(TSREG, val | 0x20); - } - else { - scrn_blanked = 0; - outb(TSIDX, 0x01); val = inb(TSREG); - outb(TSIDX, 0x01); outb(TSREG, val & 0xDF); - } -} -#endif -#if defined(STAR_SAVER) || defined(SNAKE_SAVER) - -static u_long rand_next = 1; - -static rand() -{ - return ((rand_next = rand_next * 1103515245 + 12345) & 0x7FFFFFFF); -} -#endif -#ifdef STAR_SAVER -/* - * Alternate saver that got its inspiration from a well known utility - * package for an unfamous OS. - */ - -#define NUM_STARS 50 - -void scrn_saver(int test) -{ - scr_stat *scp = cur_scr_stat; - int cell, i; - char pattern[] = {"...........++++*** "}; - char colors[] = {FG_DARKGREY, FG_LIGHTGREY, - FG_WHITE, FG_LIGHTCYAN}; - static u_short stars[NUM_STARS][2]; - - if (test) { - if (!scrn_blanked) { - bcopy(Crtat, scp->scr, - scp->max_posx * scp->max_posy * 2); - fillw((FG_LIGHTGREY|BG_BLACK)<<8 | scr_map[0x20], Crtat, - scp->max_posx * scp->max_posy); - set_border(0); - i = scp->max_posy * scp->max_posx + 5; - outb(crtc_addr, 14); - outb(crtc_addr+1, i >> 8); - outb(crtc_addr, 15); - outb(crtc_addr+1, i & 0xff); - scrn_blanked = 1; - for(i=0; i<NUM_STARS; i++) { - stars[i][0] = - rand() % (scp->max_posx*scp->max_posy); - stars[i][1] = 0; - } - } - cell = rand() % NUM_STARS; - *((u_short*)(Crtat + stars[cell][0])) = - scr_map[pattern[stars[cell][1]]] | - colors[rand()%sizeof(colors)] << 8; - if ((stars[cell][1]+=(rand()%4)) >= sizeof(pattern)-1) { - stars[cell][0] = rand() % (scp->max_posx*scp->max_posy); - stars[cell][1] = 0; - } - } - else { - if (scrn_blanked) { - bcopy(scp->scr, Crtat, scp->max_posx*scp->max_posy*2); - cur_cursor_pos = -1; - set_border(scp->border); - scrn_blanked = 0; - } - } -} -#endif -#ifdef SNAKE_SAVER -/* - * alternative screen saver for cards that do not like blanking - */ - -void scrn_saver(int test) -{ - const char saves[] = {"FreeBSD"}; - static u_char *savs[sizeof(saves)-1]; - static int dirx, diry; - int f; - scr_stat *scp = cur_scr_stat; - - if (test) { - if (!scrn_blanked) { - bcopy(Crtat, scp->scr, - scp->max_posx * scp->max_posy * 2); - fillw((FG_LIGHTGREY|BG_BLACK)<<8 | scr_map[0x20], Crtat, - scp->max_posx * scp->max_posy); - set_border(0); - dirx = (scp->posx ? 1 : -1); - diry = (scp->posy ? - scp->max_posx : -scp->max_posx); - for (f=0; f< sizeof(saves)-1; f++) - savs[f] = (u_char *)Crtat + 2 * - (scp->posx+scp->posy*scp->max_posx); - *(savs[0]) = scr_map[*saves]; - f = scp->max_posy * scp->max_posx + 5; - outb(crtc_addr, 14); - outb(crtc_addr+1, f >> 8); - outb(crtc_addr, 15); - outb(crtc_addr+1, f & 0xff); - scrn_blanked = 1; - } - if (scrn_blanked++ < 4) - return; - scrn_blanked = 1; - *(savs[sizeof(saves)-2]) = scr_map[0x20]; - for (f=sizeof(saves)-2; f > 0; f--) - savs[f] = savs[f-1]; - f = (savs[0] - (u_char *)Crtat) / 2; - if ((f % scp->max_posx) == 0 || - (f % scp->max_posx) == scp->max_posx - 1 || - (rand() % 50) == 0) - dirx = -dirx; - if ((f / scp->max_posx) == 0 || - (f / scp->max_posx) == scp->max_posy - 1 || - (rand() % 20) == 0) - diry = -diry; - savs[0] += 2*dirx + 2*diry; - for (f=sizeof(saves)-2; f>=0; f--) - *(savs[f]) = scr_map[saves[f]]; - } - else { - if (scrn_blanked) { - bcopy(scp->scr, Crtat, - scp->max_posx * scp->max_posy * 2); - cur_cursor_pos = -1; - set_border(scp->border); - scrn_blanked = 0; - } - } -} -#endif - -static void cursor_shape(int start, int end) -{ - outb(crtc_addr, 10); - outb(crtc_addr+1, start & 0xFF); - outb(crtc_addr, 11); - outb(crtc_addr+1, end & 0xFF); -} - - -static void get_cursor_shape(int *start, int *end) -{ - outb(crtc_addr, 10); - *start = inb(crtc_addr+1) & 0x1F; - outb(crtc_addr, 11); - *end = inb(crtc_addr+1) & 0x1F; -} - - -static void cursor_pos(void) -{ - int pos; - - if (cur_scr_stat->status & UNKNOWN_MODE) - return; - if (scrn_blank_time && (time.tv_sec > scrn_time_stamp+scrn_blank_time)) - scrn_saver(1); - pos = cur_scr_stat->crtat - cur_scr_stat->crt_base; - if (!scrn_blanked && pos != cur_cursor_pos) { - cur_cursor_pos = pos; - outb(crtc_addr, 14); - outb(crtc_addr+1, pos>>8); - outb(crtc_addr, 15); - outb(crtc_addr+1, pos&0xff); - } - timeout(cursor_pos, 0, hz/20); -} - - -static void clear_screen(scr_stat *scp) -{ - move_crsr(scp, 0, 0); - fillw(scp->term.attr | scr_map[0x20], scp->crt_base, - scp->max_posx * scp->max_posy); -} - - -static switch_scr(u_int next_scr) -{ - if (in_putc) { /* don't switch if in putc */ - nx_scr = next_scr+1; - return 0; - } - if (switch_in_progress && - (cur_scr_stat->proc != pfind(cur_scr_stat->pid))) - switch_in_progress = 0; - if (next_scr >= NCONS || switch_in_progress) { - sysbeep(800, hz/4); - return -1; - } - switch_in_progress = 1; - old_scp = cur_scr_stat; - new_scp = &cons_scr_stat[next_scr]; - wakeup(&new_scp->smode); - if (new_scp == old_scp) { - switch_in_progress = 0; - return 0; - } - new_pccons = &pccons[next_scr]; - - /* has controlling process died? */ - if (old_scp->proc && (old_scp->proc != pfind(old_scp->pid))) - old_scp->smode.mode = VT_AUTO; - if (new_scp->proc && (new_scp->proc != pfind(new_scp->pid))) - new_scp->smode.mode = VT_AUTO; - - /* check the modes and switch approbiatly */ - if (old_scp->smode.mode == VT_PROCESS) { - old_scp->status |= SWITCH_WAIT_REL; - psignal(old_scp->proc, old_scp->smode.relsig); - } - else { - exchange_scr(); - if (new_scp->smode.mode == VT_PROCESS) { - new_scp->status |= SWITCH_WAIT_ACQ; - psignal(new_scp->proc, new_scp->smode.acqsig); - } - else - switch_in_progress = 0; - } - return 0; -} - - -static void exchange_scr(void) -{ - bcopy(Crtat, old_scp->scr, old_scp->max_posx * old_scp->max_posy * 2); - old_scp->crt_base = old_scp->scr; - move_crsr(old_scp, old_scp->posx, old_scp->posy); - cur_scr_stat = new_scp; - cur_pccons = new_pccons; - if (old_scp->status & KBD_RAW_MODE || new_scp->status & KBD_RAW_MODE) - shfts = ctls = alts = 0; - update_leds(new_scp->status & LED_MASK); - set_mode(new_scp); - new_scp->crt_base = Crtat; - move_crsr(new_scp, new_scp->posx, new_scp->posy); - bcopy(new_scp->scr, Crtat, new_scp->max_posx * new_scp->max_posy * 2); - nx_scr = 0; -} - - -static void move_crsr(scr_stat *scp, int x, int y) -{ - if (x < 0 || y < 0 || x >= scp->max_posx || y >= scp->max_posy) - return; - scp->posx = x; - scp->posy = y; - scp->crtat = scp->crt_base + scp->posy * scp->max_posx + scp->posx; -} - - -static void move_up(u_short *s, u_short *d, u_int len) -{ - s += len; - d += len; - while (len-- > 0) - *--d = *--s; -} - - -static void move_down(u_short *s, u_short *d, u_int len) -{ - while (len-- > 0) - *d++ = *s++; -} - - -static void scan_esc(scr_stat *scp, u_char c) -{ - static u_char ansi_col[16] = - {0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15}; - int i, n; - u_short *src, *dst, count; - - if (scp->term.esc == 1) { - switch (c) { - - case '[': /* Start ESC [ sequence */ - scp->term.esc = 2; - scp->term.last_par = -1; - for (i = scp->term.n_par; i < MAX_ESC_PAR; i++) - scp->term.par[i] = 1; - scp->term.n_par = 0; - return; - - case 'M': /* Move cursor up 1 line, scroll if at top */ - if (scp->posy > 0) - move_crsr(scp, scp->posx, scp->posy - 1); - else { - move_up(scp->crt_base, - scp->crt_base + scp->max_posx, - (scp->max_posy - 1) * scp->max_posx); - fillw(scp->term.attr | scr_map[0x20], - scp->crt_base, scp->max_posx); - } - break; -#if notyet - case 'Q': - scp->term.esc = 4; - break; -#endif - case 'c': /* Clear screen & home */ - clear_screen(scp); - break; - } - } - else if (scp->term.esc == 2) { - if (c >= '0' && c <= '9') { - if (scp->term.n_par < MAX_ESC_PAR) { - if (scp->term.last_par != scp->term.n_par) { - scp->term.last_par = scp->term.n_par; - scp->term.par[scp->term.n_par] = 0; - } - else - scp->term.par[scp->term.n_par] *= 10; - scp->term.par[scp->term.n_par] += c - '0'; - return; - } - } - scp->term.n_par = scp->term.last_par + 1; - switch (c) { - - case ';': - if (scp->term.n_par < MAX_ESC_PAR) - return; - break; - - case '=': - scp->term.esc = 3; - scp->term.last_par = -1; - for (i = scp->term.n_par; i < MAX_ESC_PAR; i++) - scp->term.par[i] = 1; - scp->term.n_par = 0; - return; - - case 'A': /* up n rows */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx, scp->posy - n); - break; - - case 'B': /* down n rows */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx, scp->posy + n); - break; - - case 'C': /* right n columns */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx + n, scp->posy); - break; - - case 'D': /* left n columns */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx - n, scp->posy); - break; - - case 'E': /* cursor to start of line n lines down */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, 0, scp->posy + n); - break; - - case 'F': /* cursor to start of line n lines up */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, 0, scp->posy - n); - break; - - case 'f': /* System V consoles .. */ - case 'H': /* Cursor move */ - if (scp->term.n_par == 0) - move_crsr(scp, 0, 0); - else if (scp->term.n_par == 2) - move_crsr(scp, scp->term.par[1] - 1, - scp->term.par[0] - 1); - break; - - case 'J': /* Clear all or part of display */ - if (scp->term.n_par == 0) - n = 0; - else - n = scp->term.par[0]; - switch (n) { - case 0: /* clear form cursor to end of display */ - fillw(scp->term.attr | scr_map[0x20], - scp->crtat, scp->crt_base + - scp->max_posx * scp->max_posy - - scp->crtat); - break; - case 1: /* clear from beginning of display to cursor */ - fillw(scp->term.attr | scr_map[0x20], - scp->crt_base, - scp->crtat - scp->crt_base); - break; - case 2: /* clear entire display */ - clear_screen(scp); - break; - } - break; - - case 'K': /* Clear all or part of line */ - if (scp->term.n_par == 0) - n = 0; - else - n = scp->term.par[0]; - switch (n) { - case 0: /* clear form cursor to end of line */ - fillw(scp->term.attr | scr_map[0x20], - scp->crtat, scp->max_posx - scp->posx); - break; - case 1: /* clear from beginning of line to cursor */ - fillw(scp->term.attr|scr_map[0x20], - scp->crtat - (scp->max_posx - scp->posx), - (scp->max_posx - scp->posx) + 1); - break; - case 2: /* clear entire line */ - fillw(scp->term.attr|scr_map[0x20], - scp->crtat - (scp->max_posx - scp->posx), - scp->max_posx); - break; - } - break; - - case 'L': /* Insert n lines */ - n = scp->term.par[0]; if (n < 1) n = 1; - if (n > scp->max_posy - scp->posy) - n = scp->max_posy - scp->posy; - src = scp->crt_base + scp->posy * scp->max_posx; - dst = src + n * scp->max_posx; - count = scp->max_posy - (scp->posy + n); - move_up(src, dst, count * scp->max_posx); - fillw(scp->term.attr | scr_map[0x20], src, - n * scp->max_posx); - break; - - case 'M': /* Delete n lines */ - n = scp->term.par[0]; if (n < 1) n = 1; - if (n > scp->max_posy - scp->posy) - n = scp->max_posy - scp->posy; - dst = scp->crt_base + scp->posy * scp->max_posx; - src = dst + n * scp->max_posx; - count = scp->max_posy - (scp->posy + n); - move_down(src, dst, count * scp->max_posx); - src = dst + count * scp->max_posx; - fillw(scp->term.attr | scr_map[0x20], src, - n * scp->max_posx); - break; - - case 'P': /* Delete n chars */ - n = scp->term.par[0]; if (n < 1) n = 1; - if (n > scp->max_posx - scp->posx) - n = scp->max_posx - scp->posx; - dst = scp->crtat; - src = dst + n; - count = scp->max_posx - (scp->posx + n); - move_down(src, dst, count); - src = dst + count; - fillw(scp->term.attr | scr_map[0x20], src, n); - break; - - case '@': /* Insert n chars */ - n = scp->term.par[0]; if (n < 1) n = 1; - if (n > scp->max_posx - scp->posx) - n = scp->max_posx - scp->posx; - src = scp->crtat; - dst = src + n; - count = scp->max_posx - (scp->posx + n); - move_up(src, dst, count); - fillw(scp->term.attr | scr_map[0x20], src, n); - break; - - case 'S': /* scroll up n lines */ - n = scp->term.par[0]; if (n < 1) n = 1; - bcopy(scp->crt_base + (scp->max_posx * n), - scp->crt_base, - scp->max_posx * (scp->max_posy - n) * - sizeof(u_short)); - fillw(scp->term.attr | scr_map[0x20], - scp->crt_base + scp->max_posx * - (scp->max_posy - 1), - scp->max_posx); - break; - - case 'T': /* scroll down n lines */ - n = scp->term.par[0]; if (n < 1) n = 1; - bcopy(scp->crt_base, - scp->crt_base + (scp->max_posx * n), - scp->max_posx * (scp->max_posy - n) * - sizeof(u_short)); - fillw(scp->term.attr | scr_map[0x20], scp->crt_base, - scp->max_posx); - break; - - case 'X': /* delete n characters in line */ - n = scp->term.par[0]; if (n < 1) n = 1; - fillw(scp->term.attr | scr_map[0x20], - scp->crt_base + scp->posx + - ((scp->max_posx*scp->posy) * sizeof(u_short)), n); - break; - - case 'Z': /* move n tabs backwards */ - n = scp->term.par[0]; if (n < 1) n = 1; - if ((i = scp->posx & 0xf8) == scp->posx) - i -= 8*n; - else - i -= 8*(n-1); - if (i < 0) - i = 0; - move_crsr(scp, i, scp->posy); - break; - - case '`': /* move cursor to column n */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, n, scp->posy); - break; - - case 'a': /* move cursor n columns to the right */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx + n, scp->posy); - break; - - case 'd': /* move cursor to row n */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx, n); - break; - - case 'e': /* move cursor n rows down */ - n = scp->term.par[0]; if (n < 1) n = 1; - move_crsr(scp, scp->posx, scp->posy + n); - break; - - case 'm': /* change attribute */ - if (scp->term.n_par == 0) - n = 0; - else - n = scp->term.par[0]; - switch (n) { - case 0: /* back to normal */ - scp->term.attr = scp->term.std_attr; - break; - case 1: /* highlight (bold) */ - scp->term.attr &= 0xFF00; - scp->term.attr |= 0x0800; - break; - case 4: /* highlight (underline) */ - scp->term.attr &= 0x0F00; - scp->term.attr |= 0x0800; - break; - case 5: /* blink */ - scp->term.attr &= 0xFF00; - scp->term.attr |= 0x8000; - break; - case 7: /* reverse video */ - scp->term.attr = scp->term.rev_attr; - break; - case 30: case 31: case 32: case 33: /* set fg color */ - case 34: case 35: case 36: case 37: - scp->term.attr = (scp->term.attr & 0xF0FF) - | (ansi_col[(n - 30) & 7] << 8); - break; - case 40: case 41: case 42: case 43: /* set bg color */ - case 44: case 45: case 46: case 47: - scp->term.attr = (scp->term.attr & 0x0FFF) - | (ansi_col[(n - 40) & 7] << 12); - break; - } - break; - - case 'x': - if (scp->term.n_par == 0) - n = 0; - else - n = scp->term.par[0]; - switch (n) { - case 0: /* reset attributes */ - scp->term.attr = scp->term.std_attr = - current_default->std_attr; - scp->term.rev_attr = current_default->rev_attr; - break; - case 1: /* set ansi background */ - scp->term.attr = scp->term.std_attr = - (scp->term.std_attr & 0x0F00) | - (ansi_col[(scp->term.par[1])&0x0F]<<12); - break; - case 2: /* set ansi foreground */ - scp->term.attr = scp->term.std_attr = - (scp->term.std_attr & 0xF000) | - (ansi_col[(scp->term.par[1])&0x0F]<<8); - break; - case 3: /* set ansi attribute directly */ - scp->term.attr = scp->term.std_attr = - (scp->term.par[1]&0xFF)<<8; - break; - case 5: /* set ansi reverse video background */ - scp->term.rev_attr = - (scp->term.rev_attr & 0x0F00) | - (ansi_col[(scp->term.par[1])&0x0F]<<12); - break; - case 6: /* set ansi reverse video foreground */ - scp->term.rev_attr = - (scp->term.rev_attr & 0xF000) | - (ansi_col[(scp->term.par[1])&0x0F]<<8); - break; - case 7: /* set ansi reverse video directly */ - scp->term.rev_attr = (scp->term.par[1]&0xFF)<<8; - break; - } - break; - - case 'z': /* switch to (virtual) console n */ - if (scp->term.n_par == 1) - switch_scr(scp->term.par[0]); - break; - } - } - else if (scp->term.esc == 3) { - if (c >= '0' && c <= '9') { - if (scp->term.n_par < MAX_ESC_PAR) { - if (scp->term.last_par != scp->term.n_par) { - scp->term.last_par = scp->term.n_par; - scp->term.par[scp->term.n_par] = 0; - } - else - scp->term.par[scp->term.n_par] *= 10; - scp->term.par[scp->term.n_par] += c - '0'; - return; - } - } - scp->term.n_par = scp->term.last_par + 1; - switch (c) { - - case ';': - if (scp->term.n_par < MAX_ESC_PAR) - return; - break; - - case 'A': /* set display border color */ - if (scp->term.n_par == 1) - scp->border=scp->term.par[0] & 0xff; - if (scp == cur_scr_stat) - set_border(scp->border); - break; - - case 'B': /* set bell pitch and duration */ - if (scp->term.n_par == 2) { - scp->bell_pitch = scp->term.par[0]; - scp->bell_duration = scp->term.par[1]*10; - } - break; - - case 'C': /* set cursor shape (start & end line) */ - if (scp->term.n_par == 2) { - scp->cursor_start = scp->term.par[0] & 0x1F; - scp->cursor_end = scp->term.par[1] & 0x1F; - if (scp == cur_scr_stat) - cursor_shape(scp->cursor_start, - scp->cursor_end); - } - break; - - case 'F': /* set ansi foreground */ - if (scp->term.n_par == 1) - scp->term.attr = scp->term.std_attr = - (scp->term.std_attr & 0xF000) - | ((scp->term.par[0] & 0x0F) << 8); - break; - - case 'G': /* set ansi background */ - if (scp->term.n_par == 1) - scp->term.attr = scp->term.std_attr = - (scp->term.std_attr & 0x0F00) - | ((scp->term.par[0] & 0x0F) << 12); - break; - - case 'H': /* set ansi reverse video foreground */ - if (scp->term.n_par == 1) - scp->term.rev_attr = - (scp->term.rev_attr & 0xF000) - | ((scp->term.par[0] & 0x0F) << 8); - break; - - case 'I': /* set ansi reverse video background */ - if (scp->term.n_par == 1) - scp->term.rev_attr = - (scp->term.rev_attr & 0x0F00) - | ((scp->term.par[0] & 0x0F) << 12); - break; - } - } - scp->term.esc = 0; -} - - -static void ansi_put(scr_stat *scp, u_char c) -{ - if (scp->status & UNKNOWN_MODE) - return; - - /* make screensaver happy */ - if (scp == cur_scr_stat) { - scrn_time_stamp = time.tv_sec; - if (scrn_blanked) - scrn_saver(0); - } - in_putc++; - if (scp->term.esc) - scan_esc(scp, c); - else switch(c) { - case 0x1B: /* start escape sequence */ - scp->term.esc = 1; - scp->term.n_par = 0; - break; - case 0x07: - if (scp == cur_scr_stat) - sysbeep(scp->bell_pitch, scp->bell_duration); - break; - case '\t': /* non-destructive tab */ - scp->crtat += (8 - scp->posx % 8); - scp->posx += (8 - scp->posx % 8); - break; - case '\b': /* non-destructive backspace */ - if (scp->crtat > scp->crt_base) { - scp->crtat--; - if (scp->posx > 0) - scp->posx--; - else { - scp->posx += scp->max_posx - 1; - scp->posy--; - } - } - break; - case '\r': /* return to pos 0 */ - move_crsr(scp, 0, scp->posy); - break; - case '\n': /* newline, same pos */ - scp->crtat += scp->max_posx; - scp->posy++; - break; - case '\f': /* form feed, clears screen */ - clear_screen(scp); - break; - default: - /* Print only printables */ - *scp->crtat = (scp->term.attr | scr_map[c]); - scp->crtat++; - if (++scp->posx >= scp->max_posx) { - scp->posx = 0; - scp->posy++; - } - break; - } - if (scp->crtat >= scp->crt_base + scp->max_posy * scp->max_posx) { - bcopy(scp->crt_base + scp->max_posx, scp->crt_base, - scp->max_posx * (scp->max_posy - 1) * sizeof(u_short)); - fillw(scp->term.attr | scr_map[0x20], - scp->crt_base + scp->max_posx * (scp->max_posy - 1), - scp->max_posx); - scp->crtat -= scp->max_posx; - scp->posy--; - } - in_putc--; - if (nx_scr) - switch_scr(nx_scr - 1); -} - - -void consinit(void) -{ - u_short volatile *cp = Crtat + (CGA_BUF-MONO_BUF)/sizeof(u_short), was; - unsigned cursorat; - int i; - - /* - * catch that once in a blue moon occurence when consinit is called - * TWICE, adding the CGA_BUF offset again -> poooff - */ - if (crtat != 0) - return; - /* - * Crtat initialized to point to MONO buffer, if not present change - * to CGA_BUF offset. ONLY ADD the difference since locore.s adds - * in the remapped offset at the right time - */ - was = *cp; - *cp = (u_short) 0xA55A; - if (*cp != 0xA55A) { - crtc_addr = MONO_BASE; - } else { - *cp = was; - crtc_addr = COLOR_BASE; - Crtat = Crtat + (CGA_BUF-MONO_BUF)/sizeof(u_short); - } - - /* Extract cursor location */ - outb(crtc_addr,14); - cursorat = inb(crtc_addr+1)<<8 ; - outb(crtc_addr,15); - cursorat |= inb(crtc_addr+1); - crtat = Crtat + cursorat; - - /* is this a VGA or higher ? */ - outb(crtc_addr, 7); - if (inb(crtc_addr) == 7) - crtc_vga = 1; - - current_default = &user_default; - cons_scr_stat[0].crtat = crtat; - cons_scr_stat[0].crt_base = Crtat; - cons_scr_stat[0].term.esc = 0; - cons_scr_stat[0].term.std_attr = current_default->std_attr; - cons_scr_stat[0].term.rev_attr = current_default->rev_attr; - cons_scr_stat[0].term.attr = current_default->std_attr; - cons_scr_stat[0].posx = cursorat % COL; - cons_scr_stat[0].posy = cursorat / COL; - cons_scr_stat[0].border = BG_BLACK;; - cons_scr_stat[0].max_posx = COL; - cons_scr_stat[0].max_posy = ROW; - cons_scr_stat[0].status = 0; - cons_scr_stat[0].pid = 0; - cons_scr_stat[0].proc = NULL; - cons_scr_stat[0].smode.mode = VT_AUTO; - cons_scr_stat[0].bell_pitch = 800; - cons_scr_stat[0].bell_duration = 10; - kernel_console.esc = 0; - kernel_console.std_attr = kernel_default.std_attr; - kernel_console.rev_attr = kernel_default.rev_attr; - kernel_console.attr = kernel_default.std_attr; - /* initialize mapscrn array to */ - for (i=0; i<sizeof(scr_map); i++) - scr_map[i] = i; - clear_screen(&cons_scr_stat[0]); -} - - -static void sput(u_char c) -{ - scr_stat *scp = &cons_scr_stat[0]; - term_stat save; - - if (crtat == 0) - consinit(); - save = scp->term; - scp->term = kernel_console; - current_default = &kernel_default; - ansi_put(scp, c); - kernel_console = scp->term; - current_default = &user_default; - scp->term = save; -} - - -static u_char *get_fstr(u_int c, u_int *len) -{ - u_int i; - - if (!(c & FKEY)) - return(NULL); - i = (c & 0xFF) - F_FN; - if (i > n_fkey_tab) - return(NULL); - *len = fkey_tab[i].len; - return(fkey_tab[i].str); -} - - -static update_leds(int which) -{ - u_char xlate_leds[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; - - kbd_cmd(KB_SETLEDS); /* LED Command */ - kbd_cmd(xlate_leds[which & LED_MASK]); - kbd_wait(); -} - - -volatile void reset_cpu(void) -{ - while (1) { - kbd_cmd(KB_RESET_CPU); /* Reset Command */ - DELAY(4000000); - kbd_cmd(KB_RESET); /* Keyboard Reset Command */ - } -} - - -/* - * sgetc(noblock) : get a character from the keyboard. - * If noblock = 0 wait until a key is gotten. Otherwise return a 0x100. - */ -u_int sgetc(int noblock) -{ - u_char val, code, release; - u_int state, action; - struct key_t *key; - static u_char esc_flag = 0, compose = 0; - static u_int chr = 0; - -next_code: - kbd_wait(); - /* First see if there is something in the keyboard port */ - if (inb(KB_STAT) & KB_BUF_FULL) - val = inb(KB_DATA); - else if (noblock) - return(0x100); - else - goto next_code; - - if (cur_scr_stat->status & KBD_RAW_MODE) - return val; - - code = val & 0x7F; - release = val & 0x80; - - /* Check for cntl-alt-del */ - if ((code == 83) && ctls && alts) - cpu_reset(); -#if NDDB > 0 - /* Check for cntl-alt-esc */ - if ((val == 1) && ctls && alts) { - /* if debugger called, try to switch to console 0 */ - if (cur_scr_stat->smode.mode == VT_AUTO && - cons_scr_stat[0].smode.mode == VT_AUTO) - switch_scr(0); - Debugger(); - return(0x100); - } -#endif - switch (esc_flag) { - case 0x00: /* normal scancode */ - switch(code) { - case 0x38: /* left alt (compose key) */ - if (release && compose) { - compose = 0; - if (chr > 255) { - sysbeep(500, hz/4); - chr = 0; - } - } - else { - if (!compose) { - compose = 1; - chr = 0; - } - } - break; - case 0x60: - case 0x61: - esc_flag = code; - goto next_code; - } - break; - case 0x60: /* 0xE0 prefix */ - esc_flag = 0; - switch (code) { - case 0x1c: /* right enter key */ - code = 0x59; - break; - case 0x1d: /* right ctrl key */ - code = 0x5a; - break; - case 0x35: /* keypad divide key */ - code = 0x5b; - break; - case 0x37: /* print scrn key */ - code = 0x5c; - break; - case 0x38: /* right alt key (alt gr) */ - code = 0x5d; - break; - case 0x47: /* grey home key */ - code = 0x5e; - break; - case 0x48: /* grey up arrow key */ - code = 0x5f; - break; - case 0x49: /* grey page up key */ - code = 0x60; - break; - case 0x4b: /* grey left arrow key */ - code = 0x61; - break; - case 0x4d: /* grey right arrow key */ - code = 0x62; - break; - case 0x4f: /* grey end key */ - code = 0x63; - break; - case 0x50: /* grey down arrow key */ - code = 0x64; - break; - case 0x51: /* grey page down key */ - code = 0x65; - break; - case 0x52: /* grey insert key */ - code = 0x66; - break; - case 0x53: /* grey delete key */ - code = 0x67; - break; - default: /* ignore everything else */ - goto next_code; - } - break; - case 0x61: /* 0xE1 prefix */ - esc_flag = 0; - if (code == 0x1D) - esc_flag = 0x1D; - goto next_code; - /* NOT REACHED */ - case 0x1D: /* pause / break */ - esc_flag = 0; - if (code != 0x45) - goto next_code; - code = 0x68; - break; - } - - if (compose) { - switch (code) { - case 0x47: - case 0x48: /* keypad 7,8,9 */ - case 0x49: - if (!release) - chr = (code - 0x40) + chr*10; - goto next_code; - case 0x4b: - case 0x4c: /* keypad 4,5,6 */ - case 0x4d: - if (!release) - chr = (code - 0x47) + chr*10; - goto next_code; - case 0x4f: - case 0x50: /* keypad 1,2,3 */ - case 0x51: - if (!release) - chr = (code - 0x4e) + chr*10; - goto next_code; - case 0x52: /* keypad 0 */ - if (!release) - chr *= 10; - goto next_code; - case 0x38: /* left alt key */ - break; - default: - if (chr) { - compose = chr = 0; - sysbeep(500, hz/4); - goto next_code; - } - break; - } - } - - state = (shfts ? 1 : 0 ) | (2 * (ctls ? 1 : 0)) | (4 * (alts ? 1 : 0)); - if ((!agrs && (cur_scr_stat->status & ALKED)) - || (agrs && !(cur_scr_stat->status & ALKED))) - code += ALTGR_OFFSET; - key = &key_map.key[code]; - if ( ((key->flgs & FLAG_LOCK_C) && (cur_scr_stat->status & CLKED)) - || ((key->flgs & FLAG_LOCK_N) && (cur_scr_stat->status & NLKED)) ) - state ^= 1; - - /* Check for make/break */ - action = key->map[state]; - if (release) { /* key released */ - if (key->spcl & 0x80) { - switch (action) { - case LSH: - shfts &= ~1; - break; - case RSH: - shfts &= ~2; - break; - case LCTR: - ctls &= ~1; - break; - case RCTR: - ctls &= ~2; - break; - case LALT: - alts &= ~1; - break; - case RALT: - alts &= ~2; - break; - case NLK: - nlkcnt = 0; - break; - case CLK: - clkcnt = 0; - break; - case SLK: - slkcnt = 0; - break; - case ASH: - agrs = 0; - break; - case ALK: - alkcnt = 0; - break; - } - } - if (chr && !compose) { - action = chr; - chr = 0; - return (action); - } - } else { - /* key pressed */ - if (key->spcl & (0x80>>state)) { - switch (action) { - /* LOCKING KEYS */ - case NLK: - if (!nlkcnt) { - nlkcnt++; - if (cur_scr_stat->status & NLKED) - cur_scr_stat->status &= ~NLKED; - else - cur_scr_stat->status |= NLKED; - update_leds(cur_scr_stat->status & LED_MASK); - } - break; - case CLK: - if (!clkcnt) { - clkcnt++; - if (cur_scr_stat->status & CLKED) - cur_scr_stat->status &= ~CLKED; - else - cur_scr_stat->status |= CLKED; - update_leds(cur_scr_stat->status & LED_MASK); - } - break; - case SLK: - if (!slkcnt) { - slkcnt++; - if (cur_scr_stat->status & SLKED) { - cur_scr_stat->status &= ~SLKED; - pcstart(&pccons[get_scr_num(cur_scr_stat)]); - } - else - cur_scr_stat->status |= SLKED; - update_leds(cur_scr_stat->status & LED_MASK); - } - break; - case ALK: - if (!alkcnt) { - alkcnt++; - if (cur_scr_stat->status & ALKED) - cur_scr_stat->status &= ~ALKED; - else - cur_scr_stat->status |= ALKED; - } - break; - - /* NON-LOCKING KEYS */ - case LSH: - shfts |= 1; - break; - case RSH: - shfts |= 2; - break; - case LCTR: - ctls |= 1; - break; - case RCTR: - ctls |= 2; - break; - case LALT: - alts |= 1; - break; - case RALT: - alts |= 2; - break; - case ASH: - agrs = 1; - break; - case NOP: - break; - default: - if (action >= F_SCR && action <= L_SCR) { - switch_scr(action - F_SCR); - break; - } - if (action >= F_FN && action <= L_FN) { - return(action | FKEY); - } - return(action); - } - } - else return(action); - } - goto next_code; -} - -/* July '93, jkh. Added in for init_main.c */ -void cons_highlight() -{ - cons_scr_stat[0].term.attr &= 0xFF00; - cons_scr_stat[0].term.attr |= 0x0800; -} - -void cons_normal() -{ - cons_scr_stat[0].term.attr = cons_scr_stat[0].term.std_attr; -} - -int getchar(void) -{ - char thechar; - int s; - - pcconsoftc.cs_flags |= CSF_POLLING; - s = splhigh(); - sput('>'); - thechar = (char) sgetc(0); - pcconsoftc.cs_flags &= ~CSF_POLLING; - splx(s); - switch (thechar) { - default: - if (thechar >= scr_map[0x20]) - sput(thechar); - return(thechar); - case cr: - case lf: - sput(cr); sput(lf); - return(lf); - case bs: - case del: - sput(bs); sput(scr_map[0x20]); sput(bs); - return(thechar); - case cntld: - sput('^'); sput('D'); sput('\r'); sput('\n'); - return(0); - } -} - - -int pcmmap(dev_t dev, int offset, int nprot) -{ - if (offset > 0x20000) - return EINVAL; - return i386_btop((VIDEOMEM + offset)); -} - - -static void kbd_wait(void) -{ - int i; - for (i=0; i<10000; i++) - if ((inb(KB_STAT) & KB_READY) == 0) - break; -} - - -static void kbd_cmd(u_char command) -{ - kbd_wait(); - outb(KB_DATA, command); -} - - -static void set_mode(scr_stat *scp) -{ - u_char byte; - int s; - - if (scp != cur_scr_stat) - return; - - /* (re)activate cursor */ - untimeout(cursor_pos, 0); - cursor_pos(); - - /* change cursor type if set */ - if (scp->cursor_start != -1 && scp->cursor_end != -1) - cursor_shape(scp->cursor_start, scp->cursor_end); - - /* mode change only on VGA's */ - if (!crtc_vga) - return; - - /* setup video hardware for the given mode */ - s = splhigh(); - switch(scp->mode) { - case TEXT80x25: - outb(crtc_addr, 9); byte = inb(crtc_addr+1); - outb(crtc_addr, 9); outb(crtc_addr+1, byte | 0x0F); - outb(TSIDX, 0x03); outb(TSREG, 0x00); /* select font 0 */ - break; - case TEXT80x50: - outb(crtc_addr, 9); byte = inb(crtc_addr+1); - outb(crtc_addr, 9); outb(crtc_addr+1, (byte & 0xF0) | 0x07); - outb(TSIDX, 0x03); outb(TSREG, 0x05); /* select font 1 */ - break; - default: - return; - } - splx(s); - - /* set border color for this (virtual) console */ - set_border(scp->border); - return; -} - - -static void set_border(int color) -{ - inb(crtc_addr+6); /* reset flip-flop */ - outb(ATC, 0x11); outb(ATC, color); - inb(crtc_addr+6); /* reset flip-flop */ - outb(ATC, 0x20); /* enable Palette */ -} - -static load_font(int segment, int size, char* font) -{ - int ch, line, s; - u_char val; - - outb(TSIDX, 0x01); val = inb(TSREG); /* blank screen */ - outb(TSIDX, 0x01); outb(TSREG, val | 0x20); - - /* setup vga for loading fonts (graphics plane mode) */ - s = splhigh(); - inb(crtc_addr+6); /* reset flip/flop */ - outb(ATC, 0x30); outb(ATC, 0x01); - outb(TSIDX, 0x02); outb(TSREG, 0x04); - outb(TSIDX, 0x04); outb(TSREG, 0x06); - outb(GDCIDX, 0x04); outb(GDCREG, 0x02); - outb(GDCIDX, 0x05); outb(GDCREG, 0x00); - outb(GDCIDX, 0x06); outb(GDCREG, 0x05); /* addr = a0000, 64kb */ - splx(s); - for (ch=0; ch < 256; ch++) - for (line=0; line < size; line++) - *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) = - font[(ch*size)+line]; - /* setup vga for text mode again */ - s = splhigh(); - inb(crtc_addr+6); /* reset flip/flop */ - outb(ATC, 0x30); outb(ATC, 0x0C); - outb(TSIDX, 0x02); outb(TSREG, 0x03); - outb(TSIDX, 0x04); outb(TSREG, 0x02); - outb(GDCIDX, 0x04); outb(GDCREG, 0x00); - outb(GDCIDX, 0x05); outb(GDCREG, 0x10); - if (crtc_addr == MONO_BASE) { - outb(GDCIDX, 0x06); outb(GDCREG, 0x0A); /* addr = b0000, 32kb */ - } - else { - outb(GDCIDX, 0x06); outb(GDCREG, 0x0E); /* addr = b8000, 32kb */ - } - splx(s); - outb(TSIDX, 0x01); val = inb(TSREG); /* unblank screen */ - outb(TSIDX, 0x01); outb(TSREG, val & 0xDF); -} - - -static void load_palette(void) -{ - int i; - - outb(PIXMASK, 0xFF); /* no pixelmask */ - outb(PALWADR, 0x00); - for (i=0x00; i<0x300; i++) - outb(PALDATA, palette[i]); - inb(crtc_addr+6); /* reset flip/flop */ - outb(ATC, 0x20); /* enable palette */ -} - -static void save_palette(void) -{ - int i; - - outb(PALRADR, 0x00); - for (i=0x00; i<0x300; i++) - palette[i] = inb(PALDATA); - inb(crtc_addr+6); /* reset flip/flop */ -} - - -static change_winsize(struct tty *tp, int x, int y) -{ - if (tp->t_winsize.ws_col != x || tp->t_winsize.ws_row != y) { - tp->t_winsize.ws_col = x; - tp->t_winsize.ws_row = y; - pgsignal(tp->t_pgrp, SIGWINCH, 1); - } -} - -#endif /* NSC */ diff --git a/sys/i386/isa/timerreg.h b/sys/i386/isa/timerreg.h deleted file mode 100644 index 5742f66..0000000 --- a/sys/i386/isa/timerreg.h +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * Copyright (c) 1993 The Regents of the University of California. - * All rights reserved. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: Header: timerreg.h,v 1.2 93/02/28 15:08:58 mccanne Exp - * $Id$ - */ - -/* - * - * Register definitions for the Intel 8253 Programmable Interval Timer. - * - * This chip has three independent 16-bit down counters that can be - * read on the fly. There are three mode registers and three countdown - * registers. The countdown registers are addressed directly, via the - * first three I/O ports. The three mode registers are accessed via - * the fourth I/O port, with two bits in the mode byte indicating the - * register. (Why are hardware interfaces always so braindead?). - * - * To write a value into the countdown register, the mode register - * is first programmed with a command indicating the which byte of - * the two byte register is to be modified. The three possibilities - * are load msb (TMR_MR_MSB), load lsb (TMR_MR_LSB), or load lsb then - * msb (TMR_MR_BOTH). - * - * To read the current value ("on the fly") from the countdown register, - * you write a "latch" command into the mode register, then read the stable - * value from the corresponding I/O port. For example, you write - * TMR_MR_LATCH into the corresponding mode register. Presumably, - * after doing this, a write operation to the I/O port would result - * in undefined behavior (but hopefully not fry the chip). - * Reading in this manner has no side effects. - * - * The outputs of the three timers are connected as follows: - * - * timer 0 -> irq 0 - * timer 1 -> dma chan 0 (for dram refresh) - * timer 2 -> speaker (via keyboard controller) - * - * Timer 0 is used to call hardclock. - * Timer 2 is used to generate console beeps. - */ - -/* - * Macros for specifying values to be written into a mode register. - */ -#define TIMER_CNTR0 (IO_TIMER1 + 0) /* timer 0 counter port */ -#define TIMER_CNTR1 (IO_TIMER1 + 1) /* timer 1 counter port */ -#define TIMER_CNTR2 (IO_TIMER1 + 2) /* timer 2 counter port */ -#define TIMER_MODE (IO_TIMER1 + 3) /* timer mode port */ -#define TIMER_SEL0 0x00 /* select counter 0 */ -#define TIMER_SEL1 0x40 /* select counter 1 */ -#define TIMER_SEL2 0x80 /* select counter 2 */ -#define TIMER_INTTC 0x00 /* mode 0, intr on terminal cnt */ -#define TIMER_ONESHOT 0x02 /* mode 1, one shot */ -#define TIMER_RATEGEN 0x04 /* mode 2, rate generator */ -#define TIMER_SQWAVE 0x06 /* mode 3, square wave */ -#define TIMER_SWSTROBE 0x08 /* mode 4, s/w triggered strobe */ -#define TIMER_HWSTROBE 0x0a /* mode 5, h/w triggered strobe */ -#define TIMER_LATCH 0x00 /* latch counter for reading */ -#define TIMER_LSB 0x10 /* r/w counter LSB */ -#define TIMER_MSB 0x20 /* r/w counter MSB */ -#define TIMER_16BIT 0x30 /* r/w counter 16 bits, LSB first */ -#define TIMER_BCD 0x01 /* count in BCD */ - diff --git a/sys/i386/isa/ultra14f.c b/sys/i386/isa/ultra14f.c deleted file mode 100644 index 9566258..0000000 --- a/sys/i386/isa/ultra14f.c +++ /dev/null @@ -1,1209 +0,0 @@ -/* - * Ported for use with the UltraStor 14f by Gary Close (gclose@wvnvms.wvnet.edu) - * Thanks to Julian Elischer for advice and help with this port. - * - * Written by Julian Elischer (julian@tfs.com) - * for TRW Financial Systems for use under the MACH(2.5) operating system. - * - * TRW Financial Systems, in accordance with their agreement with Carnegie - * Mellon University, makes this software available to CMU to distribute - * or use in any manner that they see fit as long as this message is kept with - * the software. For this reason TFS also grants any other persons or - * organisations permission to use or modify this software. - * - * TFS supplies this software to be publicly redistributed - * on the understanding that TFS is not responsible for the correct - * functioning of this software in any circumstances. - * - * commenced: Sun Sep 27 18:14:01 PDT 1992 - * slight mod to make work with 34F as well: Wed Jun 2 18:05:48 WST 1993 - * - * $Id: ultra14f.c,v 1.9 1993/10/12 07:15:38 rgrimes Exp $ - */ - -#include <sys/types.h> -#include <uha.h> - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/errno.h> -#include <sys/ioctl.h> -#include <sys/buf.h> -#include <sys/proc.h> -#include <sys/user.h> - -#ifdef MACH /* EITHER CMU OR OSF */ -#include <i386/ipl.h> -#include <i386at/scsi.h> -#include <i386at/scsiconf.h> - -#ifdef OSF /* OSF ONLY */ -#include <sys/table.h> -#include <i386/handler.h> -#include <i386/dispatcher.h> -#include <i386/AT386/atbus.h> - -#else OSF /* CMU ONLY */ -#include <i386at/atbus.h> -#include <i386/pio.h> -#endif OSF -#endif MACH /* end of MACH specific */ - -#ifdef __386BSD__ /* 386BSD specific */ -#define isa_dev isa_device -#define dev_unit id_unit -#define dev_addr id_iobase - -#include <i386/include/pio.h> -#include <i386/isa/isa_device.h> -#include <scsi/scsi_all.h> -#include <scsi/scsiconf.h> -#endif __386BSD__ - -/**/ - -#ifdef __386BSD__ -#include "ddb.h" -#if NDDB > 0 -int Debugger(); -#else NDDB -#define Debugger() panic("should call debugger here") -#endif NDDB -#endif __386BSD__ - -#ifdef MACH -int Debugger(); -#endif MACH - -typedef struct {unsigned char addr[4]; } physaddr; -typedef struct {unsigned char len[4]; } physlen; - - -#ifdef MACH -extern physaddr kvtophys(); -#define PHYSTOKV(x) phystokv(x) -#define KVTOPHYS(x) kvtophys(x) -#endif MACH - -#ifdef __386BSD__ -#define KVTOPHYS(x) vtophys(x) -#endif __386BSD__ - -extern int hz; -extern int delaycount; /* from clock setup code */ -#define NUM_CONCURRENT 16 /* number of concurrent ops per board */ -#define UHA_NSEG 33 /* number of dma segments supported */ -#define FUDGE(X) (X>>1) /* our loops are slower than spinwait() */ -/**/ -/************************** board definitions *******************************/ -/* - * I/O Port Interface -*/ - #define UHA_LMASK (0x000) /* local doorbell mask reg */ - #define UHA_LINT (0x001) /* local doorbell int/stat reg */ - #define UHA_SMASK (0x002) /* system doorbell mask reg */ - #define UHA_SINT (0x003) /* system doorbell int/stat reg */ - #define UHA_ID0 (0x004) /* product id reg 0 */ - #define UHA_ID1 (0x005) /* product id reg 1 */ - #define UHA_CONF1 (0x006) /* config reg 1 */ - #define UHA_CONF2 (0x007) /* config reg 2 */ - #define UHA_OGM0 (0x008) /* outgoing mail ptr 0 least sig */ - #define UHA_OGM1 (0x009) /* outgoing mail ptr 1 least mid */ - #define UHA_OGM2 (0x00a) /* outgoing mail ptr 2 most mid */ - #define UHA_OGM3 (0x00b) /* outgoing mail ptr 3 most sig */ - #define UHA_ICM0 (0x00c) /* incoming mail ptr 0 */ - #define UHA_ICM1 (0x00d) /* incoming mail ptr 1 */ - #define UHA_ICM2 (0x00e) /* incoming mail ptr 2 */ - #define UHA_ICM3 (0x00f) /* incoming mail ptr 3 */ - - /* -* UHA_LMASK bits (read only) -*/ - -#define UHA_LDIE 0x80 /* local doorbell int enabled */ -#define UHA_SRSTE 0x40 /* soft reset enabled */ -#define UHA_ABORTEN 0x10 /* abort MSCP enabled */ -#define UHA_OGMINTEN 0x01 /* outgoing mail interrupt enabled */ - -/* -* UHA_LINT bits (read) -*/ - -#define UHA_LDIP 0x80 /* local doorbell int pending */ - -/* -* UHA_LINT bits (write) -*/ - -#define UHA_ADRST 0x40 /* adapter soft reset */ -#define UHA_SBRST 0x20 /* scsi bus reset */ -#define UHA_ASRST 0x60 /* adapter and scsi reset */ -#define UHA_ABORT 0x10 /* abort MSCP */ -#define UHA_OGMINT 0x01 /* tell adapter to get mail */ - -/* -* UHA_SMASK bits (read) -*/ - -#define UHA_SINTEN 0x80 /* system doorbell interupt Enabled */ -#define UHA_ABORT_COMPLETE_EN 0x10 /* abort MSCP command complete int Enabled */ -#define UHA_ICM_ENABLED 0x01 /* ICM interrupt enabled - -/* -* UHA_SMASK bits (write) -*/ - -#define UHA_ENSINT 0x80 /* enable system doorbell interrupt */ -#define UHA_EN_ABORT_COMPLETE 0x10 /* enable abort MSCP complete int */ -#define UHA_ENICM 0x01 /* enable ICM interrupt */ - -/* -* UHA_SINT bits (read) -*/ - -#define UHA_SINTP 0x80 /* system doorbell int pending */ -#define UHA_ABORT_SUCC 0x10 /* abort MSCP successful */ -#define UHA_ABORT_FAIL 0x18 /* abort MSCP failed */ - -/* -* UHA_SINT bits (write) -*/ - -#define UHA_ABORT_ACK 0x18 /* acknowledge status and clear */ -#define UHA_ICM_ACK 0x01 /* acknowledge ICM and clear */ - -/* -* UHA_CONF1 bits (read only) -*/ - -#define UHA_DMA_CH5 0x00 /* DMA channel 5 */ -#define UHA_DMA_CH6 0x40 /* 6 */ -#define UHA_DMA_CH7 0x80 /* 7 */ -#define UHA_IRQ15 0x00 /* IRQ 15 */ -#define UHA_IRQ14 0x10 /* 14 */ -#define UHA_IRQ11 0x20 /* 11 */ -#define UHA_IRQ10 0x30 /* 10 */ - -/*********************************** -* ha_status error codes -\***********************************/ - -#define UHA_NO_ERR 0x00 /* No error supposedly */ -#define UHA_SBUS_ABORT_ERR 0x84 /* scsi bus abort error */ -#define UHA_SBUS_TIMEOUT 0x91 /* scsi bus selection timeout */ -#define UHA_SBUS_OVER_UNDER 0x92 /* scsi bus over/underrun */ -#define UHA_BAD_SCSI_CMD 0x96 /* illegal scsi command */ -#define UHA_AUTO_SENSE_ERR 0x9b /* auto request sense err */ -#define UHA_SBUS_RES_ERR 0xa3 /* scsi bus reset error */ -#define UHA_BAD_SG_LIST 0xff /* invalid scatter gath list */ - -/**/ - -struct uha_dma_seg -{ - physaddr addr; - physlen len; -}; -/**/ - -struct mscp -{ - unsigned char opcode:3; - #define U14_HAC 0x01 /*host adapter command*/ - #define U14_TSP 0x02 /*target scsi pass through command*/ - #define U14_SDR 0x04 /*scsi device reset*/ - unsigned char xdir:2; /*xfer direction*/ - #define U14_SDET 0x00 /*determined by scsi command*/ - #define U14_SDIN 0x01 /*scsi data in*/ - #define U14_SDOUT 0x02 /*scsi data out*/ - #define U14_NODATA 0x03 /*no data xfer*/ - unsigned char dcn:1; /*disable disconnect for this command*/ - unsigned char ca:1; /*Cache control*/ - unsigned char sgth:1; /*scatter gather flag*/ - unsigned char target:3; - unsigned char chan:2; /*scsi channel (always 0 for 14f)*/ - unsigned char lun:3; - physaddr data; - physlen datalen; - physaddr link; - unsigned char link_id; - unsigned char sg_num; /*number of scat gath segs */ - /*in s-g list if sg flag is*/ - /*set. starts at 1, 8bytes per*/ - unsigned char senselen; - unsigned char cdblen; - unsigned char cdb[12]; - unsigned char ha_status; - unsigned char targ_status; - physaddr sense; /* if 0 no auto sense */ - /*-----------------end of hardware supported fields----------------*/ - struct mscp *next; /* in free list */ - struct scsi_xfer *xs; /* the scsi_xfer for this cmd */ - int flags; -#define MSCP_FREE 0 -#define MSCP_ACTIVE 1 -#define MSCP_ABORTED 2 - struct uha_dma_seg uha_dma[UHA_NSEG]; - struct scsi_sense_data mscp_sense; -}; - -/**/ - -struct uha_data -{ - int flags; -#define UHA_INIT 0x01; - int baseport; - struct mscp mscps[NUM_CONCURRENT]; - struct mscp *free_mscp; - int our_id; /* our scsi id */ - int vect; - int dma; -} uha_data[NUHA]; - -int uhaprobe(); -int uha_attach(); -int uhaintr(); -int uha_scsi_cmd(); -int uha_timeout(); -int uha_abort(); -struct mscp *cheat; -void uhaminphys(); -long int uha_adapter_info(); - -unsigned long int scratch; - -#ifdef MACH -struct isa_driver uhadriver = { uhaprobe, 0, uha_attach, "uha", 0, 0, 0}; -int (*uhaintrs[])() = {uhaintr, 0}; -#endif MACH - -#ifdef __386BSD__ -struct isa_driver uhadriver = { uhaprobe, uha_attach, "uha"}; -#endif __386BSD__ - -static uha_unit = 0; -#ifdef UHADEBUG -int uha_debug = 0; -#endif /*UHADEBUG*/ -#define UHA_SHOWMSCPS 0x01 -#define UHA_SHOWINTS 0x02 -#define UHA_SHOWCMDS 0x04 -#define UHA_SHOWMISC 0x08 -#define FAIL 1 -#define SUCCESS 0 -#define PAGESIZ 4096 - -struct scsi_switch uha_switch = -{ - uha_scsi_cmd, - uhaminphys, - 0, - 0, - uha_adapter_info, - "uha", - 0,0 -}; - -/**/ -/***********************************************************************\ -* Function to send a command out through a mailbox * -\***********************************************************************/ -uha_send_mbox( int unit - ,struct mscp *mscp) -{ - int port = uha_data[unit].baseport; - int spincount = FUDGE(delaycount) * 1000; /* 1s should be enough */ - int s = splbio(); - - while( ((inb(port + UHA_LINT) & (UHA_LDIP)) - != (0)) - && (spincount--)); - if(spincount == -1) - { - printf("uha%d: uha_send_mbox, board not responding\n",unit); - Debugger(); - } - - outl(port + UHA_OGM0,KVTOPHYS(mscp)); - outb(port + UHA_LINT, (UHA_OGMINT)); - splx(s); -} - -/***********************************************************************\ -* Function to send abort to 14f * -\***********************************************************************/ - -uha_abort( int unit - ,struct mscp *mscp) -{ - int port = uha_data[unit].baseport; - int spincount = FUDGE(delaycount) * 1; - int abortcount = FUDGE(delaycount) * 2000; - int s = splbio(); - - while(((inb(port + UHA_LINT) & (UHA_LDIP)) - != (0)) - && (spincount--)); - if(spincount == -1); - { - printf("uha%d: uha_abort, board not responding\n",unit); - Debugger(); - } - - outl(port + UHA_OGM0,KVTOPHYS(mscp)); - outb(port + UHA_LINT,UHA_ABORT); - - while((abortcount--) && (!(inb(port + UHA_SINT) & UHA_ABORT_FAIL))); - if(abortcount == -1) - { - printf("uha%d: uha_abort, board not responding\n",unit); - Debugger(); - } - if((inb(port + UHA_SINT) & 0x10) != 0) - { - outb(port + UHA_SINT,UHA_ABORT_ACK); - return(1); - } - else - { - outb(port + UHA_SINT,UHA_ABORT_ACK); - return(0); - } -} - -/***********************************************************************\ -* Function to poll for command completion when in poll mode * -\***********************************************************************/ -uha_poll(int unit ,int wait) /* in msec */ -{ - int port = uha_data[unit].baseport; - int spincount = FUDGE(delaycount) * wait; /* in msec */ - int stport = port + UHA_SINT; - int start = spincount; - -retry: - while( (spincount--) && (!(inb(stport) & UHA_SINTP))); - if(spincount == -1) - { - printf("uha%d: uha_poll, board not responding\n",unit); - return(EIO); - } -if ((int)cheat != PHYSTOKV(inl(port + UHA_ICM0))) -{ - printf("uha%d: discarding %x\n",unit,inl(port + UHA_ICM0)); - outb(port + UHA_SINT, UHA_ICM_ACK); - spinwait(50); - goto retry; -}/* don't know this will work */ - uhaintr(unit); - return(0); -} - -/*******************************************************\ -* Check if the device can be found at the port given * -* and if so, set it up ready for further work * -* as an argument, takes the isa_dev structure from * -* autoconf.c * -\*******************************************************/ -uhaprobe(dev) -struct isa_dev *dev; -{ - int unit = uha_unit; - dev->dev_unit = unit; - uha_data[unit].baseport = dev->dev_addr; - if(unit >= NUHA) - { - printf("uha%d: unit number too high\n",unit); - return(0); - } - - /*try and initialize unit at this location*/ - if (uha_init(unit) != 0) - { - return(0); - } - - /* if its there put in it's interrupt and DRQ vectors */ - - dev->id_irq = (1 << uha_data[unit].vect); - dev->id_drq = uha_data[unit].dma; - - - uha_unit ++; -return(1); -} - -/***********************************************\ -* Attach all the sub-devices we can find * -\***********************************************/ -uha_attach(dev) -struct isa_dev *dev; -{ - int unit = dev->dev_unit; - - - /***********************************************\ - * ask the adapter what subunits are present * - \***********************************************/ - scsi_attachdevs( unit, uha_data[unit].our_id, &uha_switch); - -#if defined(OSF) - uha_attached[unit]=1; -#endif /* defined(OSF) */ - return; -} - -/***********************************************\ -* Return some information to the caller about * -* the adapter and it's capabilities * -\***********************************************/ -long int uha_adapter_info(unit) -int unit; -{ - return(2); /* 2 outstanding requests at a time per device */ -} - -/***********************************************\ -* Catch an interrupt from the adaptor * -\***********************************************/ -uhaintr(unit) -{ - struct mscp *mscp; - u_char uhastat; - unsigned long int mboxval; - - int port = uha_data[unit].baseport; - - -#ifdef UHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("uhaintr "); -#endif /*UHADEBUG*/ - -#if defined(OSF) - if (!uha_attached[unit]) - { - return(1); - } -#endif /* defined(OSF) */ - while(inb(port + UHA_SINT) & UHA_SINTP) - { - /***********************************************\ - * First get all the information and then * - * acknowlege the interrupt * - \***********************************************/ - uhastat = inb(port + UHA_SINT); - mboxval = inl(port + UHA_ICM0); - outb(port + UHA_SINT,UHA_ICM_ACK); - -#ifdef UHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("status = 0x%x ",uhastat); -#endif /*UHADEBUG*/ - /***********************************************\ - * Process the completed operation * - \***********************************************/ - - mscp = (struct mscp *)(PHYSTOKV(mboxval)); - -#ifdef UHADEBUG - if(uha_debug & UHA_SHOWCMDS ) - { - uha_show_scsi_cmd(mscp->xs); - } - if((uha_debug & UHA_SHOWMSCPS) && mscp) - printf("<int mscp(%x)>",mscp); -#endif /*UHADEBUG*/ - untimeout(uha_timeout,mscp); - - uha_done(unit,mscp); - } - return(1); -} - -/***********************************************\ -* We have a mscp which has been processed by the * -* adaptor, now we look to see how the operation * -* went. * -\***********************************************/ - -uha_done(unit,mscp) -int unit; -struct mscp *mscp; -{ - struct scsi_sense_data *s1,*s2; - struct scsi_xfer *xs = mscp->xs; - -#ifdef UHADEBUG - if(scsi_debug & (PRINTROUTINES | TRACEINTERRUPTS)) - printf("uha_done "); -#endif /*UHADEBUG*/ - /***********************************************\ - * Otherwise, put the results of the operation * - * into the xfer and call whoever started it * - \***********************************************/ - if ( (mscp->ha_status == UHA_NO_ERR) || (xs->flags & SCSI_ERR_OK)) - { /* All went correctly OR errors expected */ - xs->resid = 0; - xs->error = 0; - } - else - { - - s1 = &(mscp->mscp_sense); - s2 = &(xs->sense); - - if(mscp->ha_status != UHA_NO_ERR) - { - switch(mscp->ha_status) - { - case UHA_SBUS_TIMEOUT: /* No response */ -#ifdef UHADEBUG - if (uha_debug & UHA_SHOWMISC) - { - printf("timeout reported back\n"); - } -#endif /*UHADEBUG*/ - xs->error = XS_TIMEOUT; - break; - case UHA_SBUS_OVER_UNDER: -#ifdef UHADEBUG - if (uha_debug & UHA_SHOWMISC) - { - printf("scsi bus xfer over/underrun\n"); - } -#endif /*UHADEBUG*/ - xs->error = XS_DRIVER_STUFFUP; - break; - case UHA_BAD_SG_LIST: -#ifdef UHADEBUG - if (uha_debug & UHA_SHOWMISC) - { - printf("bad sg list reported back\n"); - } -#endif /*UHADEBUG*/ - xs->error = XS_DRIVER_STUFFUP; - break; - default: /* Other scsi protocol messes */ - xs->error = XS_DRIVER_STUFFUP; -#ifdef UHADEBUG - if (uha_debug & UHA_SHOWMISC) - { - printf("unexpected ha_status: %x\n", - mscp->ha_status); - } -#endif /*UHADEBUG*/ - } - - } - else - { - - if (mscp->targ_status != 0) -/**************************************************************************\ -* I have no information for any possible value of target status field * -* other than 0 means no error!! So I guess any error is unexpected in that * -* event!! * -\**************************************************************************/ - - { -#ifdef UHADEBUG - if (uha_debug & UHA_SHOWMISC) - { - printf("unexpected targ_status: %x\n", - mscp->targ_status); - } -#endif /*UHADEBUG*/ - xs->error = XS_DRIVER_STUFFUP; - } - } - } -done: xs->flags |= ITSDONE; - uha_free_mscp(unit,mscp, xs->flags); - if(xs->when_done) - (*(xs->when_done))(xs->done_arg,xs->done_arg2); -} - -/***********************************************\ -* A mscp (and hence a mbx-out is put onto the * -* free list. * -\***********************************************/ -uha_free_mscp(unit,mscp, flags) -struct mscp *mscp; -{ - unsigned int opri; - -#ifdef UHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("mscp%d(0x%x)> ",unit,flags); -#endif /*UHADEBUG*/ - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - - mscp->next = uha_data[unit].free_mscp; - uha_data[unit].free_mscp = mscp; - mscp->flags = MSCP_FREE; - /***********************************************\ - * If there were none, wake abybody waiting for * - * one to come free, starting with queued entries* - \***********************************************/ - if (!mscp->next) { - wakeup(&uha_data[unit].free_mscp); - } - if (!(flags & SCSI_NOMASK)) - splx(opri); -} - -/***********************************************\ -* Get a free mscp (and hence mbox-out entry) * -\***********************************************/ -struct mscp * -uha_get_mscp(unit,flags) -{ - unsigned opri; - struct mscp *rc; - -#ifdef UHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("<mscp%d(0x%x) ",unit,flags); -#endif /*UHADEBUG*/ - if (!(flags & SCSI_NOMASK)) - opri = splbio(); - /***********************************************\ - * If we can and have to, sleep waiting for one * - * to come free * - \***********************************************/ - while ((!(rc = uha_data[unit].free_mscp)) && (!(flags & SCSI_NOSLEEP))) - { - sleep(&uha_data[unit].free_mscp, PRIBIO); - } - if (rc) - { - uha_data[unit].free_mscp = rc->next; - rc->flags = MSCP_ACTIVE; - } - if (!(flags & SCSI_NOMASK)) - splx(opri); - return(rc); -} - - - -/***********************************************\ -* Start the board, ready for normal operation * -\***********************************************/ - -uha_init(unit) -int unit; -{ - unsigned char ad[4]; - volatile unsigned char model; - volatile unsigned char submodel; - unsigned char config_reg1; - unsigned char config_reg2; - unsigned char dma_ch; - unsigned char irq_ch; - unsigned char uha_id; - int port = uha_data[unit].baseport; - int i; - int resetcount = FUDGE(delaycount) * 4000; - - model = inb(port + UHA_ID0); - submodel = inb(port + UHA_ID1); - if ((model != 0x56) & (submodel != 0x40)) { -#ifdef UHADEBUG - printf("uha%d: uha_init, board not responding\n",unit); -#endif /*UHADEBUG*/ - return(ENXIO); - } - - printf("uha%d: reading board settings, ",unit); - - config_reg1 = inb(port + UHA_CONF1); - config_reg2 = inb(port + UHA_CONF2); - dma_ch = (config_reg1 & 0xc0); - irq_ch = (config_reg1 & 0x30); - uha_id = (config_reg2 & 0x07); - - switch(dma_ch) - { - case UHA_DMA_CH5: - uha_data[unit].dma = 5; - printf("dma=5 "); - break; - case UHA_DMA_CH6: - uha_data[unit].dma = 6; - printf("dma=6 "); - break; - case UHA_DMA_CH7: - uha_data[unit].dma = 7; - printf("dma=7 "); - break; - default: - printf("illegal dma jumper setting\n"); - return(EIO); - } - switch(irq_ch) - { - case UHA_IRQ10: - uha_data[unit].vect = 10; - printf("int=10 "); - break; - case UHA_IRQ11: - uha_data[unit].vect = 11; - printf("int=11 "); - break; - case UHA_IRQ14: - uha_data[unit].vect = 14; - printf("int=14 "); - break; - case UHA_IRQ15: - uha_data[unit].vect = 15; - printf("int=15 "); - break; - default: - printf("illegal int jumper setting\n"); - return(EIO); - } - /* who are we on the scsi bus */ - printf("id=%x\n",uha_id); - uha_data[unit].our_id = uha_id; - - - /***********************************************\ - * link up all our MSCPs into a free list * - \***********************************************/ - for (i=0; i < NUM_CONCURRENT; i++) - { - uha_data[unit].mscps[i].next = uha_data[unit].free_mscp; - uha_data[unit].free_mscp = &uha_data[unit].mscps[i]; - uha_data[unit].free_mscp->flags = MSCP_FREE; - } - - /***********************************************\ - * Note that we are going and return (to probe) * - \***********************************************/ - outb(port + UHA_LINT, UHA_ASRST); - while( (resetcount--) && (!(inb(port + UHA_LINT)))); - if(resetcount == -1) - { - printf("uha%d: board timed out during reset\n",unit); - return(ENXIO); - } - - outb(port + UHA_SMASK, 0x81); /* make sure interrupts are enabled */ - uha_data[unit].flags |= UHA_INIT; - return(0); -} - - - -#ifndef min -#define min(x,y) (x < y ? x : y) -#endif min - - -void uhaminphys(bp) -struct buf *bp; -{ -#ifdef MACH -#if !defined(OSF) - bp->b_flags |= B_NPAGES; /* can support scat/gather */ -#endif /* defined(OSF) */ -#endif MACH - if(bp->b_bcount > ((UHA_NSEG-1) * PAGESIZ)) - { - bp->b_bcount = ((UHA_NSEG-1) * PAGESIZ); - } -} - -/***********************************************\ -* start a scsi operation given the command and * -* the data address. Also needs the unit, target * -* and lu * -\***********************************************/ -int uha_scsi_cmd(xs) -struct scsi_xfer *xs; -{ - struct scsi_sense_data *s1,*s2; - struct mscp *mscp; - struct uha_dma_seg *sg; - int seg; /* scatter gather seg being worked on */ - int i = 0; - int rc = 0; - int thiskv; - unsigned long int thisphys,nextphys; - int unit =xs->adapter; - int bytes_this_seg,bytes_this_page,datalen,flags; - struct iovec *iovp; - int s; - unsigned int stat; - int port = uha_data[unit].baseport; - unsigned long int templen; - - -#ifdef UHADEBUG - if(scsi_debug & PRINTROUTINES) - printf("uha_scsi_cmd "); -#endif /*UHADEBUG*/ - /***********************************************\ - * get a mscp (mbox-out) to use. If the transfer * - * is from a buf (possibly from interrupt time) * - * then we can't allow it to sleep * - \***********************************************/ - flags = xs->flags; - if(xs->bp) flags |= (SCSI_NOSLEEP); /* just to be sure */ - if(flags & ITSDONE) - { - printf("uha%d: Already done?",unit); - xs->flags &= ~ITSDONE; - } - if(!(flags & INUSE)) - { - printf("uha%d: Not in use?",unit); - xs->flags |= INUSE; - } - if (!(mscp = uha_get_mscp(unit,flags))) - { - xs->error = XS_DRIVER_STUFFUP; - return(TRY_AGAIN_LATER); - } - -cheat = mscp; -#ifdef UHADEBUG - if(uha_debug & UHA_SHOWMSCPS) - printf("<start mscp(%x)>",mscp); - if(scsi_debug & SHOWCOMMANDS) - { - uha_show_scsi_cmd(xs); - } -#endif /*UHADEBUG*/ - mscp->xs = xs; - /***********************************************\ - * Put all the arguments for the xfer in the mscp * - \***********************************************/ - - if (flags & SCSI_RESET) - { - mscp->opcode = 0x04; - mscp->ca = 0x01; - } - else - { - mscp->opcode = 0x02; - mscp->ca = 0x01; - } - - if (flags & SCSI_DATA_IN) - { - mscp->xdir = 0x01; - } - if (flags & SCSI_DATA_OUT) - { - mscp->xdir = 0x02; - } - - if (xs->lu != 0) - { - xs->error = XS_DRIVER_STUFFUP; - uha_free_mscp(unit,mscp,flags); - return(HAD_ERROR); - } - - mscp->dcn = 0x00; - mscp->chan = 0x00; - mscp->target = xs->targ; - mscp->lun = xs->lu; - mscp->link.addr[0] = 0x00; - mscp->link.addr[1] = 0x00; - mscp->link.addr[2] = 0x00; - mscp->link.addr[3] = 0x00; - mscp->link_id = 0x00; - mscp->cdblen = xs->cmdlen; - scratch = KVTOPHYS(&(mscp->mscp_sense)); - mscp->sense.addr[0] = (scratch & 0xff); - mscp->sense.addr[1] = ((scratch >> 8) & 0xff); - mscp->sense.addr[2] = ((scratch >> 16) & 0xff); - mscp->sense.addr[3] = ((scratch >> 24) & 0xff); - mscp->senselen = sizeof(mscp->mscp_sense); - mscp->ha_status = 0x00; - mscp->targ_status = 0x00; - - if(xs->datalen) - { /* should use S/G only if not zero length */ - scratch = KVTOPHYS(mscp->uha_dma); - mscp->data.addr[0] = (scratch & 0xff); - mscp->data.addr[1] = ((scratch >> 8) & 0xff); - mscp->data.addr[2] = ((scratch >> 16) & 0xff); - mscp->data.addr[3] = ((scratch >> 24) & 0xff); - sg = mscp->uha_dma ; - seg = 0; - mscp->sgth = 0x01; - - if(flags & SCSI_DATA_UIO) - { - iovp = ((struct uio *)xs->data)->uio_iov; - datalen = ((struct uio *)xs->data)->uio_iovcnt; - xs->datalen = 0; - while ((datalen) && (seg < UHA_NSEG)) - { - scratch = (unsigned long)iovp->iov_base; - sg->addr.addr[0] = (scratch & 0xff); - sg->addr.addr[1] = ((scratch >> 8) & 0xff); - sg->addr.addr[2] = ((scratch >> 16) & 0xff); - sg->addr.addr[3] = ((scratch >> 24) & 0xff); - xs->datalen += *(unsigned long *)sg->len.len = iovp->iov_len; -#ifdef UHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x@0x%x)" - ,iovp->iov_len - ,iovp->iov_base); -#endif /*UHADEBUG*/ - sg++; - iovp++; - seg++; - datalen--; - } - } - else - { - /***********************************************\ - * Set up the scatter gather block * - \***********************************************/ - -#ifdef UHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("%d @0x%x:- ",xs->datalen,xs->data); -#endif /*UHADEBUG*/ - datalen = xs->datalen; - thiskv = (int)xs->data; - thisphys = KVTOPHYS(thiskv); - templen = 0; - - while ((datalen) && (seg < UHA_NSEG)) - { - bytes_this_seg = 0; - - /* put in the base address */ - sg->addr.addr[0] = (thisphys & 0xff); - sg->addr.addr[1] = ((thisphys >> 8) & 0xff); - sg->addr.addr[2] = ((thisphys >> 16) & 0xff); - sg->addr.addr[3] = ((thisphys >> 24) & 0xff); - -#ifdef UHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("0x%x",thisphys); -#endif /*UHADEBUG*/ - - /* do it at least once */ - nextphys = thisphys; - while ((datalen) && (thisphys == nextphys)) - /*********************************************\ - * This page is contiguous (physically) with * - * the the last, just extend the length * - \*********************************************/ - { - /* how far to the end of the page */ - nextphys = (thisphys & (~(PAGESIZ - 1))) - + PAGESIZ; - bytes_this_page = nextphys - thisphys; - /**** or the data ****/ - bytes_this_page = min(bytes_this_page - ,datalen); - bytes_this_seg += bytes_this_page; - datalen -= bytes_this_page; - - /* get more ready for the next page */ - thiskv = (thiskv & (~(PAGESIZ - 1))) - + PAGESIZ; - if(datalen) - thisphys = KVTOPHYS(thiskv); - } - /********************************************\ - * next page isn't contiguous, finish the seg * - \********************************************/ -#ifdef UHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("(0x%x)",bytes_this_seg); -#endif /*UHADEBUG*/ - sg->len.len[0] = (bytes_this_seg & 0xff); - sg->len.len[1] = ((bytes_this_seg >> 8) & 0xff); - sg->len.len[2] = ((bytes_this_seg >> 16) & 0xff); - sg->len.len[3] = ((bytes_this_seg >> 24) & 0xff); - templen += bytes_this_seg; - sg++; - seg++; - } - } /*end of iov/kv decision */ - mscp->datalen.len[0] = (templen & 0xff); - mscp->datalen.len[1] = ((templen >> 8) & 0xff); - mscp->datalen.len[2] = ((templen >> 16) & 0xff); - mscp->datalen.len[3] = ((templen >> 24) & 0xff); - mscp->sg_num = seg; - -#ifdef UHADEBUG - if(scsi_debug & SHOWSCATGATH) - printf("\n"); -#endif /*UHADEBUG*/ - if (datalen) - { /* there's still data, must have run out of segs! */ - printf("uha%d: uha_scsi_cmd, more than %d DMA segs\n", - unit,UHA_NSEG); - xs->error = XS_DRIVER_STUFFUP; - uha_free_mscp(unit,mscp,flags); - return(HAD_ERROR); - } - - } - else - { /* No data xfer, use non S/G values */ - mscp->data.addr[0] = 0x00; - mscp->data.addr[1] = 0x00; - mscp->data.addr[2] = 0x00; - mscp->data.addr[3] = 0x00; - mscp->datalen.len[0] = 0x00; - mscp->datalen.len[1] = 0x00; - mscp->datalen.len[2] = 0x00; - mscp->datalen.len[3] = 0x00; - mscp->xdir = 0x03; - mscp->sgth = 0x00; - mscp->sg_num = 0x00; - } - - /***********************************************\ - * Put the scsi command in the mscp and start it * - \***********************************************/ - bcopy(xs->cmd, mscp->cdb, xs->cmdlen); - - /***********************************************\ - * Usually return SUCCESSFULLY QUEUED * - \***********************************************/ - if (!(flags & SCSI_NOMASK)) - { - s = splbio(); - uha_send_mbox(unit,mscp); - timeout(uha_timeout,mscp,(xs->timeout * hz) / 1000); - splx(s); -#ifdef UHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("cmd_sent "); -#endif /*UHADEBUG*/ - return(SUCCESSFULLY_QUEUED); - } - /***********************************************\ - * If we can't use interrupts, poll on completion* - \***********************************************/ - uha_send_mbox(unit,mscp); -#ifdef UHADEBUG - if(scsi_debug & TRACEINTERRUPTS) - printf("cmd_wait "); -#endif /*UHADEBUG*/ - do - { - if(uha_poll(unit,xs->timeout)) - { - if (!(xs->flags & SCSI_SILENT)) - printf("uha%d: cmd fail\n",unit); - if(!(uha_abort(unit,mscp))) - { - printf("uha%d: abort failed in wait\n",unit); - uha_free_mscp(unit,mscp,flags); - } - xs->error = XS_DRIVER_STUFFUP; - return(HAD_ERROR); - } - } while (!(xs->flags & ITSDONE));/* something (?) else finished */ - if(xs->error) - { - return(HAD_ERROR); - } - return(COMPLETE); -} - - -uha_timeout(struct mscp *mscp) -{ - int unit; - int s = splbio(); - int port = uha_data[unit].baseport; - - unit = mscp->xs->adapter; - printf("uha%d:%d device timed out\n",unit - ,mscp->xs->targ); -#ifdef UHADEBUG - if(uha_debug & UHA_SHOWMSCPS) - uha_print_active_mscp(unit); -#endif /*UHADEBUG*/ - - if((uha_abort(unit,mscp) !=1) || (mscp->flags = MSCP_ABORTED)) - { - printf("AGAIN"); - mscp->xs->retries = 0; /* I MEAN IT ! */ - uha_done(unit,mscp,FAIL); - } - else /* abort the operation that has timed out */ - { - printf("\n"); - timeout(uha_timeout,mscp,2 * hz); - mscp->flags = MSCP_ABORTED; - } - splx(s); -} - -uha_show_scsi_cmd(struct scsi_xfer *xs) -{ - u_char *b = (u_char *)xs->cmd; - int i = 0; - if(!(xs->flags & SCSI_RESET)) - { - printf("uha%d:%d:%d-" - ,xs->adapter - ,xs->targ - ,xs->lu); - while(i < xs->cmdlen ) - { - if(i) printf(","); - printf("%x",b[i++]); - } - printf("-\n"); - } - else - { - printf("uha%d:%d:%d-RESET-\n" - ,xs->adapter - ,xs->targ - ,xs->lu - ); - } -} -uha_print_mscp(mscp) -struct mscp *mscp; -{ - printf("mscp:%x op:%x cmdlen:%d senlen:%d\n" - ,mscp - ,mscp->opcode - ,mscp->cdblen - ,mscp->senselen); - printf(" sg:%d sgnum:%x datlen:%d hstat:%x tstat:%x flags:%x\n" - ,mscp->sgth - ,mscp->sg_num - ,mscp->datalen - ,mscp->ha_status - ,mscp->targ_status - ,mscp->flags); - uha_show_scsi_cmd(mscp->xs); -} - -uha_print_active_mscp(int unit) -{ - struct mscp *mscp = uha_data[unit].mscps; - int i = NUHA; - - while(i--) - { - if(mscp->flags != MSCP_FREE) - uha_print_mscp(mscp); - mscp++; - } -} diff --git a/sys/i386/isa/vector.s b/sys/i386/isa/vector.s deleted file mode 100644 index aa40fd5..0000000 --- a/sys/i386/isa/vector.s +++ /dev/null @@ -1,368 +0,0 @@ -/* - * from: vector.s, 386BSD 0.1 unknown origin - * $Id$ - */ - -#include "i386/isa/icu.h" -#include "i386/isa/isa.h" -#include "vector.h" - -#define ICU_EOI 0x20 /* XXX - define elsewhere */ - -#define IRQ_BIT(irq_num) (1 << ((irq_num) % 8)) -#define IRQ_BYTE(irq_num) ((irq_num) / 8) - -#define ENABLE_ICU1 \ - movb $ICU_EOI,%al ; /* as soon as possible send EOI ... */ \ - FASTER_NOP ; /* ... ASAP ... */ \ - outb %al,$IO_ICU1 /* ... to clear in service bit */ -#ifdef AUTO_EOI_1 -#undef ENABLE_ICU1 /* we now use auto-EOI to reduce i/o */ -#define ENABLE_ICU1 -#endif - -#define ENABLE_ICU1_AND_2 \ - movb $ICU_EOI,%al ; /* as above */ \ - FASTER_NOP ; \ - outb %al,$IO_ICU2 ; /* but do second icu first */ \ - FASTER_NOP ; \ - outb %al,$IO_ICU1 /* then first icu */ -#ifdef AUTO_EOI_2 -#undef ENABLE_ICU1_AND_2 /* data sheet says no auto-EOI on slave ... */ -#define ENABLE_ICU1_AND_2 /* ... but it works */ -#endif - -/* - * Macros for interrupt interrupt entry, call to handler, and exit. - * - * XXX - the interrupt frame is set up to look like a trap frame. This is - * usually a waste of time. The only interrupt handlers that want a frame - * are the clock handler (it wants a clock frame), the npx handler (it's - * easier to do right all in assembler). The interrupt return routine - * needs a trap frame for rare AST's (it could easily convert the frame). - * The direct costs of setting up a trap frame are two pushl's (error - * code and trap number), an addl to get rid of these, and pushing and - * popping the call-saved regs %esi, %edi and %ebp twice, The indirect - * costs are making the driver interface nonuniform so unpending of - * interrupts is more complicated and slower (call_driver(unit) would - * be easier than ensuring an interrupt frame for all handlers. Finally, - * there are some struct copies in the npx handler and maybe in the clock - * handler that could be avoided by working more with pointers to frames - * instead of frames. - * - * XXX - should we do a cld on every system entry to avoid the requirement - * for scattered cld's? - * - * Coding notes for *.s: - * - * If possible, avoid operations that involve an operand size override. - * Word-sized operations might be smaller, but the operand size override - * makes them slower on on 486's and no faster on 386's unless perhaps - * the instruction pipeline is depleted. E.g., - * - * Use movl to seg regs instead of the equivalent but more descriptive - * movw - gas generates an irelevant (slower) operand size override. - * - * Use movl to ordinary regs in preference to movw and especially - * in preference to movz[bw]l. Use unsigned (long) variables with the - * top bits clear instead of unsigned short variables to provide more - * opportunities for movl. - * - * If possible, use byte-sized operations. They are smaller and no slower. - * - * Use (%reg) instead of 0(%reg) - gas generates larger code for the latter. - * - * If the interrupt frame is made more flexible, INTR can push %eax first - * and decide the ipending case with less overhead, e.g., by avoiding - * loading segregs. - */ - -#define FAST_INTR(unit, irq_num, id_num, handler, enable_icus) \ - pushl %eax ; /* save only call-used registers */ \ - pushl %ecx ; \ - pushl %edx ; \ - pushl %ds ; \ - /* pushl %es ; know compiler doesn't do string insns */ \ - movl $KDSEL,%eax ; \ - movl %ax,%ds ; \ - /* movl %ax,%es ; */ \ - SHOW_CLI ; /* although it interferes with "ASAP" */ \ - pushl $unit ; \ - call handler ; /* do the work ASAP */ \ - enable_icus ; /* (re)enable ASAP (helps edge trigger?) */ \ - addl $4,%esp ; \ - incl _cnt+V_INTR ; /* book-keeping can wait */ \ - COUNT_EVENT(_intrcnt_actv, id_num) ; \ - SHOW_STI ; \ - /* popl %es ; */ \ - popl %ds ; \ - popl %edx; \ - popl %ecx; \ - popl %eax; \ - iret - -#define INTR(unit, irq_num, id_num, mask, handler, icu, enable_icus, reg, stray) \ - pushl $0 ; /* dummy error code */ \ - pushl $T_ASTFLT ; \ - pushal ; \ - pushl %ds ; /* save our data and extra segments ... */ \ - pushl %es ; \ - movl $KDSEL,%eax ; /* ... and reload with kernel's own ... */ \ - movl %ax,%ds ; /* ... early in case SHOW_A_LOT is on */ \ - movl %ax,%es ; \ - SHOW_CLI ; /* interrupt did an implicit cli */ \ - movb _imen + IRQ_BYTE(irq_num),%al ; \ - orb $IRQ_BIT(irq_num),%al ; \ - movb %al,_imen + IRQ_BYTE(irq_num) ; \ - SHOW_IMEN ; \ - FASTER_NOP ; \ - outb %al,$icu+1 ; \ - enable_icus ; \ - incl _cnt+V_INTR ; /* tally interrupts */ \ - movl _cpl,%eax ; \ - testb $IRQ_BIT(irq_num),%reg ; \ - jne 2f ; \ -1: ; \ - COUNT_EVENT(_intrcnt_actv, id_num) ; \ - movl _cpl,%eax ; \ - pushl %eax ; \ - pushl $unit ; \ - orl mask,%eax ; \ - movl %eax,_cpl ; \ - SHOW_CPL ; \ - SHOW_STI ; \ - sti ; \ - call handler ; \ - movb _imen + IRQ_BYTE(irq_num),%al ; \ - andb $~IRQ_BIT(irq_num),%al ; \ - movb %al,_imen + IRQ_BYTE(irq_num) ; \ - SHOW_IMEN ; \ - FASTER_NOP ; \ - outb %al,$icu+1 ; \ - jmp doreti ; \ -; \ - ALIGN_TEXT ; \ -2: ; \ - COUNT_EVENT(_intrcnt_pend, id_num) ; \ - movl $1b,%eax ; /* register resume address */ \ - /* XXX - someday do it at attach time */ \ - movl %eax,Vresume + (irq_num) * 4 ; \ - orb $IRQ_BIT(irq_num),_ipending + IRQ_BYTE(irq_num) ; \ - SHOW_IPENDING ; \ - popl %es ; \ - popl %ds ; \ - popal ; \ - addl $4+4,%esp ; \ - iret - -/* - * vector.h has defined a macro 'BUILD_VECTORS' containing a big list of info - * about vectors, including a submacro 'BUILD_VECTOR' that operates on the - * info about each vector. We redefine 'BUILD_VECTOR' to expand the info - * in different ways. Here we expand it to a list of interrupt handlers. - * This order is of course unimportant. Elsewhere we expand it to inline - * linear search code for which the order is a little more important and - * concatenating the code with no holes is very important. - * - * XXX - now there is BUILD_FAST_VECTOR as well as BUILD_VECTOR. - * - * The info consists of the following items for each vector: - * - * name (identifier): name of the vector; used to build labels - * unit (expression): unit number to call the device driver with - * irq_num (number): number of the IRQ to handled (0-15) - * id_num (number): uniq numeric id for handler (assigned by config) - * mask (blank-ident): priority mask used - * handler (blank-ident): interrupt handler to call - * icu_num (number): (1 + irq_num / 8) converted for label building - * icu_enables (number): 1 for icu_num == 1, 1_AND_2 for icu_num == 2 - * reg (blank-ident): al for icu_num == 1, ah for icu_num == 2 - * - * 'irq_num' is converted in several ways at config time to get around - * limitations in cpp. The macros have blanks after commas iff they would - * not mess up identifiers and numbers. - */ - -#undef BUILD_FAST_VECTOR -#define BUILD_FAST_VECTOR(name, unit, irq_num, id_num, mask, handler, \ - icu_num, icu_enables, reg) \ - .globl handler ; \ - .text ; \ - .globl _V/**/name ; \ - SUPERALIGN_TEXT ; \ -_V/**/name: ; \ - FAST_INTR(unit, irq_num, id_num, handler, ENABLE_ICU/**/icu_enables) - -#undef BUILD_VECTOR -#define BUILD_VECTOR(name, unit, irq_num, id_num, mask, handler, \ - icu_num, icu_enables, reg) \ - .globl handler ; \ - .text ; \ - .globl _V/**/name ; \ - SUPERALIGN_TEXT ; \ -_V/**/name: ; \ - INTR(unit,irq_num,id_num, mask, handler, IO_ICU/**/icu_num, \ - ENABLE_ICU/**/icu_enables, reg,) - - BUILD_VECTORS - - /* hardware interrupt catcher (IDT 32 - 47) */ - .globl _isa_strayintr - -#define STRAYINTR(irq_num, icu_num, icu_enables, reg) \ -IDTVEC(intr/**/irq_num) ; \ - INTR(irq_num,irq_num,irq_num, _highmask, _isa_strayintr, \ - IO_ICU/**/icu_num, ENABLE_ICU/**/icu_enables, reg,stray) - -/* - * XXX - the mask (1 << 2) == IRQ_SLAVE will be generated for IRQ 2, instead - * of the mask IRQ2 (defined as IRQ9 == (1 << 9)). But IRQ 2 "can't happen". - * In fact, all stray interrupts "can't happen" except for bugs. The - * "stray" IRQ 7 is documented behaviour of the 8259. It happens when there - * is a glitch on any of its interrupt inputs. Does it really interrupt when - * IRQ 7 is masked? - * - * XXX - unpend doesn't work for these, it sends them to the real handler. - * - * XXX - the race bug during initialization may be because I changed the - * order of switching from the stray to the real interrupt handler to before - * enabling interrupts. The old order looked unsafe but maybe it is OK with - * the stray interrupt handler installed. But these handlers only reduce - * the window of vulnerability - it is still open at the end of - * isa_configure(). - * - * XXX - many comments are stale. - */ - - STRAYINTR(0,1,1, al) - STRAYINTR(1,1,1, al) - STRAYINTR(2,1,1, al) - STRAYINTR(3,1,1, al) - STRAYINTR(4,1,1, al) - STRAYINTR(5,1,1, al) - STRAYINTR(6,1,1, al) - STRAYINTR(8,2,1_AND_2, ah) - STRAYINTR(9,2,1_AND_2, ah) - STRAYINTR(10,2,1_AND_2, ah) - STRAYINTR(11,2,1_AND_2, ah) - STRAYINTR(12,2,1_AND_2, ah) - STRAYINTR(13,2,1_AND_2, ah) - STRAYINTR(14,2,1_AND_2, ah) - STRAYINTR(15,2,1_AND_2, ah) -IDTVEC(intrdefault) - STRAYINTR(7,1,1, al) /* XXX */ -#if 0 - INTRSTRAY(255, _highmask, 255) ; call _isa_strayintr ; INTREXIT2 -#endif -/* - * These are the interrupt counters, I moved them here from icu.s so that - * they are with the name table. rgrimes - * - * There are now lots of counters, this has been redone to work with - * Bruce Evans intr-0.1 code, which I modified some more to make it all - * work with vmstat. - */ - .data -Vresume: .space 16 * 4 /* where to resume intr handler after unpend */ - .globl _intrcnt -_intrcnt: /* used by vmstat to calc size of table */ - .globl _intrcnt_bad7 -_intrcnt_bad7: .space 4 /* glitches on irq 7 */ - .globl _intrcnt_bad15 -_intrcnt_bad15: .space 4 /* glitches on irq 15 */ - .globl _intrcnt_stray -_intrcnt_stray: .space 4 /* total count of stray interrupts */ - .globl _intrcnt_actv -_intrcnt_actv: .space NR_REAL_INT_HANDLERS * 4 /* active interrupts */ - .globl _intrcnt_pend -_intrcnt_pend: .space NR_REAL_INT_HANDLERS * 4 /* pending interrupts */ - .globl _eintrcnt -_eintrcnt: /* used by vmstat to calc size of table */ - .globl _intrcnt_spl -_intrcnt_spl: .space 32 * 4 /* XXX 32 should not be hard coded ? */ - .globl _intrcnt_show -_intrcnt_show: .space 8 * 4 /* XXX 16 should not be hard coded ? */ - -/* - * Build the interrupt name table for vmstat - */ - -#undef BUILD_FAST_VECTOR -#define BUILD_FAST_VECTOR BUILD_VECTOR - -#undef BUILD_VECTOR -#define BUILD_VECTOR(name, unit, irq_num, id_num, mask, handler, \ - icu_num, icu_enables, reg) \ - .ascii "name irq" ; \ - .asciz "irq_num" -/* - * XXX - use the STRING and CONCAT macros from <sys/cdefs.h> to stringize - * and concatenate names above and elsewhere. - */ - - .text - .globl _intrnames, _eintrnames -_intrnames: - BUILD_VECTOR(bad,,7,,,,,,) - BUILD_VECTOR(bad,,15,,,,,,) - BUILD_VECTOR(stray,,,,,,,,) - BUILD_VECTORS - -#undef BUILD_FAST_VECTOR -#define BUILD_FAST_VECTOR BUILD_VECTOR - -#undef BUILD_VECTOR -#define BUILD_VECTOR(name, unit, irq_num, id_num, mask, handler, \ - icu_num, icu_enables, reg) \ - .asciz "name pend" - - BUILD_VECTORS -_eintrnames: - -/* - * now the spl names - */ - .asciz "unpend_v" - .asciz "doreti" - .asciz "p0!ni" - .asciz "!p0!ni" - .asciz "p0ni" - .asciz "netisr_raw" - .asciz "netisr_ip" - .asciz "netisr_imp" - .asciz "netisr_ns" - .asciz "netisr_iso" - .asciz "softclock" /* 10 */ - .asciz "trap" - .asciz "doreti_exit2" - .asciz "splbio" - .asciz "splclock" - .asciz "splhigh" - .asciz "splimp" - .asciz "splnet" - .asciz "splsoftclock" - .asciz "spltty" - .asciz "spl0" /* 20 */ - .asciz "netisr_raw2" - .asciz "netisr_ip2" - .asciz "netisr_imp2" - .asciz "netisr_ns2" - .asciz "netisr_iso2" - .asciz "splx" - .asciz "splx!0" - .asciz "unpend_V" - .asciz "spl29" /* spl29-spl31 are spares */ - .asciz "spl30" - .asciz "spl31" -/* - * now the mask names - */ - .asciz "cli" - .asciz "cpl" - .asciz "imen" - .asciz "ipending" - .asciz "sti" - .asciz "mask5" /* mask5-mask7 are spares */ - .asciz "mask6" - .asciz "mask7" - diff --git a/sys/i386/isa/wd.c b/sys/i386/isa/wd.c deleted file mode 100644 index 02b53e4..0000000 --- a/sys/i386/isa/wd.c +++ /dev/null @@ -1,1341 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)wd.c 7.2 (Berkeley) 5/9/91 - * $Id$ - */ - -/* TODO:peel out buffer at low ipl, speed improvement */ - - -#include "wd.h" -#if NWD > 0 - -#include "param.h" -#include "dkbad.h" -#include "systm.h" -#include "conf.h" -#include "file.h" -#include "stat.h" -#include "ioctl.h" -#include "disklabel.h" -#include "buf.h" -#include "uio.h" -#include "malloc.h" -#include "machine/cpu.h" -#include "i386/isa/isa.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/icu.h" -#include "i386/isa/wdreg.h" -#include "syslog.h" -#include "vm/vm.h" - -#define _NWD (NWD - 1) /* One is for the controller XXX 31 Jul 92*/ - -#ifndef WDCTIMEOUT -#define WDCTIMEOUT 10000000 /* arbitrary timeout for drive ready waits */ -#endif - -#define RETRIES 5 /* number of retries before giving up */ -#define MAXTRANSFER 32 /* max size of transfer in page clusters */ - -#define wdnoreloc(dev) (minor(dev) & 0x80) /* ignore partition table */ -#define wddospart(dev) (minor(dev) & 0x40) /* use dos partitions */ -#define wdunit(dev) ((minor(dev) & 0x38) >> 3) -#define wdpart(dev) (minor(dev) & 0x7) -#define makewddev(maj, unit, part) (makedev(maj,((unit<<3)+part))) -#define WDRAW 3 /* 'd' partition isn't a partition! */ - -#define b_cylin b_resid /* cylinder number for doing IO to */ - /* shares an entry in the buf struct */ - -/* - * Drive states. Used to initialize drive. - */ - -#define CLOSED 0 /* disk is closed. */ -#define WANTOPEN 1 /* open requested, not started */ -#define RECAL 2 /* doing restore */ -#define OPEN 3 /* done with open */ - -/* - * The structure of a disk drive. - */ -struct disk { - long dk_bc; /* byte count left */ - short dk_skip; /* blocks already transferred */ - char dk_unit; /* physical unit number */ - char dk_state; /* control state */ - u_char dk_status; /* copy of status reg. */ - u_char dk_error; /* copy of error reg. */ - short dk_port; /* i/o port base */ - - u_long dk_copenpart; /* character units open on this drive */ - u_long dk_bopenpart; /* block units open on this drive */ - u_long dk_openpart; /* all units open on this drive */ - short dk_wlabel; /* label writable? */ - short dk_flags; /* drive characteistics found */ -#define DKFL_DOSPART 0x00001 /* has DOS partition table */ -#define DKFL_QUIET 0x00002 /* report errors back, but don't complain */ -#define DKFL_SINGLE 0x00004 /* sector at a time mode */ -#define DKFL_ERROR 0x00008 /* processing a disk error */ -#define DKFL_BSDLABEL 0x00010 /* has a BSD disk label */ -#define DKFL_BADSECT 0x00020 /* has a bad144 badsector table */ -#define DKFL_WRITEPROT 0x00040 /* manual unit write protect */ - struct wdparams dk_params; /* ESDI/IDE drive/controller parameters */ - struct disklabel dk_dd; /* device configuration data */ - struct dos_partition - dk_dospartitions[NDOSPART]; /* DOS view of disk */ - struct dkbad dk_bad; /* bad sector table */ -}; - -struct disk *wddrives[_NWD]; /* table of units */ -struct buf wdtab; -struct buf wdutab[_NWD]; /* head of queue per drive */ -struct buf rwdbuf[_NWD]; /* buffers for raw IO */ -long wdxfer[_NWD]; /* count of transfers */ -#ifdef WDDEBUG -int wddebug; -#endif - -struct isa_driver wddriver = { - wdprobe, wdattach, "wd", -}; - -static void wdustart(struct disk *); -static void wdstart(); -static int wdcommand(struct disk *, int); -static int wdcontrol(struct buf *); -static int wdsetctlr(dev_t, struct disk *); -static int wdgetctlr(int, struct disk *); - -/* - * Probe for controller. - */ -int -wdprobe(struct isa_device *dvp) -{ - int unit = dvp->id_unit; - struct disk *du; - int wdc; - - if (unit >= _NWD) /* 31 Jul 92*/ - return(0); - - if ((du = wddrives[unit]) == 0) { - du = wddrives[unit] = (struct disk *) - malloc (sizeof(struct disk), M_TEMP, M_NOWAIT); - bzero (du, sizeof(struct disk)); /* 31 Jul 92*/ - du->dk_unit = unit; - } - - wdc = du->dk_port = dvp->id_iobase; - - /* check if we have registers that work */ - outb(wdc+wd_cyl_lo, 0xa5) ; /* wd_cyl_lo is read/write */ - if(inb(wdc+wd_cyl_lo) != 0xa5) - goto nodevice; - - /* reset the device */ - outb(wdc+wd_ctlr, (WDCTL_RST|WDCTL_IDS)); - DELAY(1000); - outb(wdc+wd_ctlr, WDCTL_IDS); - DELAY(1000); - - /* execute a controller only command */ - if (wdcommand(du, WDCC_DIAGNOSE) < 0) - goto nodevice; - - (void) inb(wdc+wd_error); /* XXX! */ - outb(wdc+wd_ctlr, WDCTL_4BIT); - return (IO_WDCSIZE); - -nodevice: - free(du, M_TEMP); - wddrives[unit] = 0; - return (0); -} - -/* - * Attach each drive if possible. - */ -int -wdattach(struct isa_device *dvp) -{ - int unit; -/* int unit = dvp->id_unit;*/ - - for (unit=0; unit< _NWD; unit++) { - struct disk *du; - if ((du = wddrives[unit]) == 0) { - du = wddrives[unit] = (struct disk *) - malloc (sizeof(struct disk), M_TEMP, M_NOWAIT); - bzero (du, sizeof(struct disk)); - du->dk_unit = unit; - du->dk_port = dvp->id_iobase; - } - - /* print out description of drive, suppressing multiple blanks*/ - if(wdgetctlr(unit, du) == 0) { - int i, blank; - char c; - printf("wd%d: unit %d type ", unit, unit); - for (i = blank = 0 ; i < sizeof(du->dk_params.wdp_model); i++) { - char c = du->dk_params.wdp_model[i]; - - if (blank && c == ' ') continue; - if (blank && c != ' ') { - printf(" %c", c); - blank = 0; - continue; - } - if (c == ' ') - blank = 1; - else - printf("%c", c); - } - printf("\n"); - du->dk_unit = unit; - } - } - return(1); -} - -/* Read/write routine for a buffer. Finds the proper unit, range checks - * arguments, and schedules the transfer. Does not wait for the transfer - * to complete. Multi-page transfers are supported. All I/O requests must - * be a multiple of a sector in length. - */ -int -wdstrategy(register struct buf *bp) -{ - register struct buf *dp; - struct disklabel *lp; - register struct partition *p; - struct disk *du; /* Disk unit to do the IO. */ - long maxsz, sz; - int unit = wdunit(bp->b_dev); - int s; - - /* valid unit, controller, and request? */ - if (unit >= _NWD || bp->b_blkno < 0 || (du = wddrives[unit]) == 0) { - - bp->b_error = EINVAL; - bp->b_flags |= B_ERROR; - goto done; - } - - /* "soft" write protect check */ - if ((du->dk_flags & DKFL_WRITEPROT) && (bp->b_flags & B_READ) == 0) { - bp->b_error = EROFS; - bp->b_flags |= B_ERROR; - goto done; - } - - /* have partitions and want to use them? */ - if ((du->dk_flags & DKFL_BSDLABEL) != 0 && wdpart(bp->b_dev) != WDRAW) { - - /* - * do bounds checking, adjust transfer. if error, process. - * if end of partition, just return - */ - if (bounds_check_with_label(bp, &du->dk_dd, du->dk_wlabel) <= 0) - goto done; - /* otherwise, process transfer request */ - } - -q: - /* queue transfer on drive, activate drive and controller if idle */ - dp = &wdutab[unit]; - s = splbio(); - disksort(dp, bp); - if (dp->b_active == 0) - wdustart(du); /* start drive */ - if (wdtab.b_active == 0) - wdstart(s); /* start controller */ - splx(s); - return; - -done: - /* toss transfer, we're done early */ - biodone(bp); -} - -/* - * Routine to queue a command to the controller. The unit's - * request is linked into the active list for the controller. - * If the controller is idle, the transfer is started. - */ -static void -wdustart(register struct disk *du) -{ - register struct buf *bp, *dp = &wdutab[du->dk_unit]; - - /* unit already active? */ - if (dp->b_active) - return; - - /* anything to start? */ - bp = dp->b_actf; - if (bp == NULL) - return; - - /* link onto controller queue */ - dp->b_forw = NULL; - if (wdtab.b_actf == NULL) - wdtab.b_actf = dp; - else - wdtab.b_actl->b_forw = dp; - wdtab.b_actl = dp; - - /* mark the drive unit as busy */ - dp->b_active = 1; -} - -/* - * Controller startup routine. This does the calculation, and starts - * a single-sector read or write operation. Called to start a transfer, - * or from the interrupt routine to continue a multi-sector transfer. - * RESTRICTIONS: - * 1. The transfer length must be an exact multiple of the sector size. - */ - -static void -wdstart() -{ - register struct disk *du; /* disk unit for IO */ - register struct buf *bp; - struct disklabel *lp; - struct buf *dp; - register struct bt_bad *bt_ptr; - long blknum, pagcnt, cylin, head, sector; - long secpertrk, secpercyl, addr, i, timeout; - int unit, s, wdc; - -loop: - /* is there a drive for the controller to do a transfer with? */ - dp = wdtab.b_actf; - if (dp == NULL) - return; - - /* is there a transfer to this drive ? if so, link it on - the controller's queue */ - bp = dp->b_actf; - if (bp == NULL) { - wdtab.b_actf = dp->b_forw; - goto loop; - } - - /* obtain controller and drive information */ - unit = wdunit(bp->b_dev); - du = wddrives[unit]; - - /* if not really a transfer, do control operations specially */ - if (du->dk_state < OPEN) { - (void) wdcontrol(bp); - return; - } - - /* calculate transfer details */ - blknum = bp->b_blkno + du->dk_skip; -/*if(wddebug)printf("bn%d ", blknum);*/ -#ifdef WDDEBUG - if (du->dk_skip == 0) - printf("\nwdstart %d: %s %d@%d; map ", unit, - (bp->b_flags & B_READ) ? "read" : "write", - bp->b_bcount, blknum); - else - printf(" %d)%x", du->dk_skip, inb(wdc+wd_altsts)); -#endif - addr = (int) bp->b_un.b_addr; - if (du->dk_skip == 0) - du->dk_bc = bp->b_bcount; - - lp = &du->dk_dd; - secpertrk = lp->d_nsectors; - secpercyl = lp->d_secpercyl; - if ((du->dk_flags & DKFL_BSDLABEL) != 0 && wdpart(bp->b_dev) != WDRAW) - blknum += lp->d_partitions[wdpart(bp->b_dev)].p_offset; - cylin = blknum / secpercyl; - head = (blknum % secpercyl) / secpertrk; - sector = blknum % secpertrk; - - /* - * See if the current block is in the bad block list. - * (If we have one, and not formatting.) - */ - if ((du->dk_flags & (DKFL_SINGLE|DKFL_BADSECT)) /* 19 Aug 92*/ - == (DKFL_SINGLE|DKFL_BADSECT)) - /* XXX - * BAD144END was done to clean up some old bad code that was - * attempting to compare a u_short to -1. This makes the compilers - * happy and clearly shows what is going on. - * rgrimes 93/06/17 - */ -#define BAD144END (u_short)(-1) - for (bt_ptr = du->dk_bad.bt_bad; bt_ptr->bt_cyl != BAD144END; bt_ptr++) { - if (bt_ptr->bt_cyl > cylin) - /* Sorted list, and we passed our cylinder. quit. */ - break; - if (bt_ptr->bt_cyl == cylin && - bt_ptr->bt_trksec == (head << 8) + sector) { - /* - * Found bad block. Calculate new block addr. - * This starts at the end of the disk (skip the - * last track which is used for the bad block list), - * and works backwards to the front of the disk. - */ -#ifdef WDDEBUG - printf("--- badblock code -> Old = %d; ", - blknum); -#endif - blknum = lp->d_secperunit - lp->d_nsectors - - (bt_ptr - du->dk_bad.bt_bad) - 1; - cylin = blknum / secpercyl; - head = (blknum % secpercyl) / secpertrk; - sector = blknum % secpertrk; -#ifdef WDDEBUG - printf("new = %d\n", blknum); -#endif - break; - } - } -/*if(wddebug)pg("c%d h%d s%d ", cylin, head, sector);*/ - sector += 1; /* sectors begin with 1, not 0 */ - - wdtab.b_active = 1; /* mark controller active */ - wdc = du->dk_port; - -RETRY: - /* if starting a multisector transfer, or doing single transfers */ - if (du->dk_skip == 0 || (du->dk_flags & DKFL_SINGLE)) { - if (wdtab.b_errcnt && (bp->b_flags & B_READ) == 0) - du->dk_bc += DEV_BSIZE; - - /* controller idle? */ - timeout = 0; - while (inb(wdc+wd_status) & WDCS_BUSY) - { - if (++timeout > WDCTIMEOUT) - { - printf("wd.c: Controller busy too long!\n"); - /* reset the device */ - outb(wdc+wd_ctlr, (WDCTL_RST|WDCTL_IDS)); - DELAY(1000); - outb(wdc+wd_ctlr, WDCTL_IDS); - DELAY(1000); - (void) inb(wdc+wd_error); /* XXX! */ - outb(wdc+wd_ctlr, WDCTL_4BIT); - break; - } - } - - /* stuff the task file */ - outb(wdc+wd_precomp, lp->d_precompcyl / 4); -#ifdef B_FORMAT - if (bp->b_flags & B_FORMAT) { - outb(wdc+wd_sector, lp->d_gap3); - outb(wdc+wd_seccnt, lp->d_nsectors); - } else { -#endif - if (du->dk_flags & DKFL_SINGLE) - outb(wdc+wd_seccnt, 1); - else - outb(wdc+wd_seccnt, howmany(du->dk_bc, DEV_BSIZE)); - outb(wdc+wd_sector, sector); - -#ifdef B_FORMAT - } -#endif - - outb(wdc+wd_cyl_lo, cylin); - outb(wdc+wd_cyl_hi, cylin >> 8); - - /* set up the SDH register (select drive) */ - outb(wdc+wd_sdh, WDSD_IBM | (unit<<4) | (head & 0xf)); - - /* wait for drive to become ready */ - timeout = 0; - while ((inb(wdc+wd_status) & WDCS_READY) == 0) - { - if (++timeout > WDCTIMEOUT) - { - printf("wd.c: Drive busy too long!\n"); - /* reset the device */ - outb(wdc+wd_ctlr, (WDCTL_RST|WDCTL_IDS)); - DELAY(1000); - outb(wdc+wd_ctlr, WDCTL_IDS); - DELAY(1000); - (void) inb(wdc+wd_error); /* XXX! */ - outb(wdc+wd_ctlr, WDCTL_4BIT); - goto RETRY; - } - } - - /* initiate command! */ -#ifdef B_FORMAT - if (bp->b_flags & B_FORMAT) - outb(wdc+wd_command, WDCC_FORMAT); - else -#endif - outb(wdc+wd_command, - (bp->b_flags & B_READ)? WDCC_READ : WDCC_WRITE); -#ifdef WDDEBUG - printf("sector %d cylin %d head %d addr %x sts %x\n", - sector, cylin, head, addr, inb(wdc+wd_altsts)); -#endif - } - - /* if this is a read operation, just go away until it's done. */ - if (bp->b_flags & B_READ) return; - - /* ready to send data? */ - timeout = 0; - while ((inb(wdc+wd_status) & WDCS_DRQ) == 0) - { - if (++timeout > WDCTIMEOUT) - { - printf("wd.c: Drive not ready for too long!\n"); - /* reset the device */ - outb(wdc+wd_ctlr, (WDCTL_RST|WDCTL_IDS)); - DELAY(1000); - outb(wdc+wd_ctlr, WDCTL_IDS); - DELAY(1000); - (void) inb(wdc+wd_error); /* XXX! */ - outb(wdc+wd_ctlr, WDCTL_4BIT); - goto RETRY; - } - } - - /* then send it! */ - outsw (wdc+wd_data, addr+du->dk_skip * DEV_BSIZE, - DEV_BSIZE/sizeof(short)); - du->dk_bc -= DEV_BSIZE; -} - -/* Interrupt routine for the controller. Acknowledge the interrupt, check for - * errors on the current operation, mark it done if necessary, and start - * the next request. Also check for a partially done transfer, and - * continue with the next chunk if so. - */ -void -wdintr(struct intrframe wdif) -{ - register struct disk *du; - register struct buf *bp, *dp; - int status, wdc; - char partch ; - - if (!wdtab.b_active) { -#ifdef nyet - printf("wd: extra interrupt\n"); -#endif - return; - } - - dp = wdtab.b_actf; - bp = dp->b_actf; - du = wddrives[wdunit(bp->b_dev)]; - wdc = du->dk_port; - -#ifdef WDDEBUG - printf("I "); -#endif - - while ((status = inb(wdc+wd_status)) & WDCS_BUSY) ; - - /* is it not a transfer, but a control operation? */ - if (du->dk_state < OPEN) { - if (wdcontrol(bp)) - wdstart(); - return; - } - - /* have we an error? */ - if (status & (WDCS_ERR | WDCS_ECCCOR)) { - - du->dk_status = status; - du->dk_error = inb(wdc + wd_error); -#ifdef WDDEBUG - printf("status %x error %x\n", status, du->dk_error); -#endif - if((du->dk_flags & DKFL_SINGLE) == 0) { - du->dk_flags |= DKFL_ERROR; - goto outt; - } -#ifdef B_FORMAT - if (bp->b_flags & B_FORMAT) { - bp->b_error = EIO; /* 17 Sep 92*/ - bp->b_flags |= B_ERROR; - goto done; - } -#endif - - /* error or error correction? */ - if (status & WDCS_ERR) { - if (++wdtab.b_errcnt < RETRIES) { - wdtab.b_active = 0; - } else { - diskerr(bp, "wd", "hard error", LOG_PRINTF, - du->dk_skip, &du->dk_dd); -#ifdef WDDEBUG - printf( "status %b error %b\n", - status, WDCS_BITS, - inb(wdc+wd_error), WDERR_BITS); -#endif - bp->b_error = EIO; /* 17 Sep 92*/ - bp->b_flags |= B_ERROR; /* flag the error */ - } - } else { - diskerr(bp, "wd", "soft ecc", 0, - du->dk_skip, &du->dk_dd); - } - } -outt: - - /* - * If this was a successful read operation, fetch the data. - */ - if (((bp->b_flags & (B_READ | B_ERROR)) == B_READ) && wdtab.b_active) { - int chk, dummy; - - chk = min(DEV_BSIZE / sizeof(short), du->dk_bc / sizeof(short)); - - /* ready to receive data? */ - while ((inb(wdc+wd_status) & WDCS_DRQ) == 0) - ; - - /* suck in data */ - insw (wdc+wd_data, - (int)bp->b_un.b_addr + du->dk_skip * DEV_BSIZE, chk); - du->dk_bc -= chk * sizeof(short); - - /* for obselete fractional sector reads */ - while (chk++ < 256) insw (wdc+wd_data, &dummy, 1); - } - - wdxfer[du->dk_unit]++; - if (wdtab.b_active) { - if ((bp->b_flags & B_ERROR) == 0) { - du->dk_skip++; /* Add to successful sectors. */ - if (wdtab.b_errcnt) - diskerr(bp, "wd", "soft error", 0, - du->dk_skip, &du->dk_dd); - wdtab.b_errcnt = 0; - - /* see if more to transfer */ - if (du->dk_bc > 0 && (du->dk_flags & DKFL_ERROR) == 0) { - wdstart(); - return; /* next chunk is started */ - } else if ((du->dk_flags & (DKFL_SINGLE|DKFL_ERROR)) - == DKFL_ERROR) { - du->dk_skip = 0; - du->dk_flags &= ~DKFL_ERROR; - du->dk_flags |= DKFL_SINGLE; - wdstart(); - return; /* redo xfer sector by sector */ - } - } - -done: - /* done with this transfer, with or without error */ - du->dk_flags &= ~DKFL_SINGLE; - wdtab.b_actf = dp->b_forw; - wdtab.b_errcnt = 0; - du->dk_skip = 0; - dp->b_active = 0; - dp->b_actf = bp->av_forw; - dp->b_errcnt = 0; - bp->b_resid = 0; - biodone(bp); - } - - /* controller idle */ - wdtab.b_active = 0; - - /* anything more on drive queue? */ - if (dp->b_actf) - wdustart(du); - /* anything more for controller to do? */ - if (wdtab.b_actf) - wdstart(); -} - -/* - * Initialize a drive. - */ -int -wdopen(dev_t dev, int flags, int fmt, struct proc *p) -{ - register unsigned int unit; - register struct disk *du; - int part = wdpart(dev), mask = 1 << part; - struct partition *pp; - struct dkbad *db; - int i, error = 0; - char *msg; - - unit = wdunit(dev); - if (unit >= _NWD) return (ENXIO) ; - - du = wddrives[unit]; - if (du == 0) return (ENXIO) ; - - if ((du->dk_flags & DKFL_BSDLABEL) == 0) { - du->dk_flags |= DKFL_WRITEPROT; - wdutab[unit].b_actf = NULL; - - /* - * Use the default sizes until we've read the label, - * or longer if there isn't one there. - */ - bzero(&du->dk_dd, sizeof(du->dk_dd)); -#undef d_type /* fix goddamn segments.h! XXX */ - du->dk_dd.d_type = DTYPE_ST506; - du->dk_dd.d_ncylinders = 1024; - du->dk_dd.d_secsize = DEV_BSIZE; - du->dk_dd.d_ntracks = 8; - du->dk_dd.d_nsectors = 17; - du->dk_dd.d_secpercyl = 17*8; - du->dk_state = WANTOPEN; - du->dk_unit = unit; - - /* read label using "c" partition */ - if (msg = readdisklabel(makewddev(major(dev), wdunit(dev), WDRAW), - wdstrategy, &du->dk_dd, du->dk_dospartitions, - &du->dk_bad, 0)) { - log(LOG_WARNING, "wd%d: cannot find label (%s)\n", - unit, msg); - if (part != WDRAW) - error = EINVAL; /* XXX needs translation */ - goto done; - } else { - - wdsetctlr(dev, du); - du->dk_flags |= DKFL_BSDLABEL; - du->dk_flags &= ~DKFL_WRITEPROT; - if (du->dk_dd.d_flags & D_BADSECT) - du->dk_flags |= DKFL_BADSECT; - } - -done: - if (error) - return(error); - - } - /* - * Warn if a partion is opened - * that overlaps another partition which is open - * unless one is the "raw" partition (whole disk). - */ - if ((du->dk_openpart & mask) == 0 /*&& part != RAWPART*/ && part != WDRAW) { - int start, end; - - pp = &du->dk_dd.d_partitions[part]; - start = pp->p_offset; - end = pp->p_offset + pp->p_size; - for (pp = du->dk_dd.d_partitions; - pp < &du->dk_dd.d_partitions[du->dk_dd.d_npartitions]; - pp++) { - if (pp->p_offset + pp->p_size <= start || - pp->p_offset >= end) - continue; - /*if (pp - du->dk_dd.d_partitions == RAWPART) - continue; */ - if (pp - du->dk_dd.d_partitions == WDRAW) - continue; - if (du->dk_openpart & (1 << (pp - - du->dk_dd.d_partitions))) - log(LOG_WARNING, - "wd%d%c: overlaps open partition (%c)\n", - unit, part + 'a', - pp - du->dk_dd.d_partitions + 'a'); - } - } - if (part >= du->dk_dd.d_npartitions && part != WDRAW) - return (ENXIO); - - /* insure only one open at a time */ - du->dk_openpart |= mask; - switch (fmt) { - case S_IFCHR: - du->dk_copenpart |= mask; - break; - case S_IFBLK: - du->dk_bopenpart |= mask; - break; - } - return (0); -} - -/* - * Implement operations other than read/write. - * Called from wdstart or wdintr during opens and formats. - * Uses finite-state-machine to track progress of operation in progress. - * Returns 0 if operation still in progress, 1 if completed. - */ -static int -wdcontrol(register struct buf *bp) -{ - register struct disk *du; - register unit; - unsigned char stat; - int s, cnt; - extern int bootdev; - int cyl, trk, sec, i, wdc; - struct wdparams foo; - - du = wddrives[wdunit(bp->b_dev)]; - unit = du->dk_unit; - wdc = du->dk_port; - - switch (du->dk_state) { - - tryagainrecal: - case WANTOPEN: /* set SDH, step rate, do restore */ -#ifdef WDDEBUG - printf("wd%d: recal ", unit); -#endif - s = splbio(); /* not called from intr level ... */ - wdgetctlr(unit, du); - - outb(wdc+wd_sdh, WDSD_IBM | (unit << 4)); - wdtab.b_active = 1; - - /* wait for drive and controller to become ready */ - for (i = WDCTIMEOUT; (inb(wdc+wd_status) & (WDCS_READY|WDCS_BUSY)) - != WDCS_READY && i-- != 0; ) - ; - outb(wdc+wd_command, WDCC_RESTORE | WD_STEP); - du->dk_state++; - splx(s); - return(0); - - case RECAL: - if ((stat = inb(wdc+wd_status)) & WDCS_ERR) { - printf("wd%d: recal", du->dk_unit); - printf(": status %b error %b\n", stat, WDCS_BITS, - inb(wdc+wd_error), WDERR_BITS); - if (++wdtab.b_errcnt < RETRIES) { - du->dk_state = WANTOPEN; - goto tryagainrecal; - } - bp->b_error = ENXIO; /* XXX needs translation */ - goto badopen; - } - - /* some controllers require this ... */ - wdsetctlr(bp->b_dev, du); - - wdtab.b_errcnt = 0; - du->dk_state = OPEN; - /* - * The rest of the initialization can be done - * by normal means. - */ - return(1); - - default: - panic("wdcontrol"); - } - /* NOTREACHED */ - -badopen: - printf(": status %b error %b\n", stat, WDCS_BITS, - inb(wdc + wd_error), WDERR_BITS); - bp->b_flags |= B_ERROR; - return(1); -} - -/* - * send a command and wait uninterruptibly until controller is finished. - * return -1 if controller busy for too long, otherwise - * return status. intended for brief controller commands at critical points. - * assumes interrupts are blocked. - */ -static int -wdcommand(struct disk *du, int cmd) { - int timeout = WDCTIMEOUT, stat, wdc; - - /* controller ready for command? */ - wdc = du->dk_port; - while (((stat = inb(wdc + wd_status)) & WDCS_BUSY) && timeout > 0) - timeout--; - if (timeout <= 0) - return(-1); - - /* send command, await results */ - outb(wdc+wd_command, cmd); - while (((stat = inb(wdc+wd_status)) & WDCS_BUSY) && timeout > 0) - timeout--; - if (timeout <= 0) - return(-1); - if (cmd != WDCC_READP) - return (stat); - - /* is controller ready to return data? */ - while (((stat = inb(wdc+wd_status)) & (WDCS_ERR|WDCS_DRQ)) == 0 && - timeout > 0) - timeout--; - if (timeout <= 0) - return(-1); - - return (stat); -} - -/* - * issue IDC to drive to tell it just what geometry it is to be. - */ -static int -wdsetctlr(dev_t dev, struct disk *du) { - int stat, x, wdc; - -/*printf("C%dH%dS%d ", du->dk_dd.d_ncylinders, du->dk_dd.d_ntracks, - du->dk_dd.d_nsectors);*/ - - x = splbio(); - wdc = du->dk_port; - outb(wdc+wd_cyl_lo, du->dk_dd.d_ncylinders+1); - outb(wdc+wd_cyl_hi, (du->dk_dd.d_ncylinders+1)>>8); - outb(wdc+wd_sdh, WDSD_IBM | (wdunit(dev) << 4) + du->dk_dd.d_ntracks-1); - outb(wdc+wd_seccnt, du->dk_dd.d_nsectors); - stat = wdcommand(du, WDCC_IDC); - - if (stat < 0) { - splx(x); - return(stat); - } - if (stat & WDCS_ERR) - printf("wdsetctlr: status %b error %b\n", - stat, WDCS_BITS, inb(wdc+wd_error), WDERR_BITS); - splx(x); - return(stat); -} - -/* - * issue READP to drive to ask it what it is. - */ -static int -wdgetctlr(int u, struct disk *du) { - int stat, x, i, wdc; - char tb[DEV_BSIZE]; - struct wdparams *wp; - - x = splbio(); /* not called from intr level ... */ - wdc = du->dk_port; - outb(wdc+wd_sdh, WDSD_IBM | (u << 4)); - stat = wdcommand(du, WDCC_READP); - - if (stat < 0) { - splx(x); - return(stat); - } - /* - * If WDCC_READP fails then we might have an old ST506 type drive - * so we try a seek to 0; if that passes then the - * drive is there but it's OLD AND KRUSTY - */ - if (stat & WDCS_ERR) { - stat = wdcommand(du, WDCC_RESTORE | WD_STEP); - if (stat & WDCS_ERR) { - stat = inb(wdc+wd_error); - splx(x); - return(stat); - } - - strncpy(du->dk_dd.d_typename, "ST506", - sizeof du->dk_dd.d_typename); - strncpy(du->dk_params.wdp_model, "Unknown Type", - sizeof du->dk_params.wdp_model); - du->dk_dd.d_type = DTYPE_ST506; - splx(x); - return(0); - } - - /* obtain parameters */ - wp = &du->dk_params; - insw(wdc+wd_data, tb, sizeof(tb)/sizeof(short)); - bcopy(tb, wp, sizeof(struct wdparams)); - - /* shuffle string byte order */ - for (i=0; i < sizeof(wp->wdp_model) ;i+=2) { - u_short *p; - p = (u_short *) (wp->wdp_model + i); - *p = ntohs(*p); - } -/*printf("gc %x cyl %d trk %d sec %d type %d sz %d model %s\n", wp->wdp_config, -wp->wdp_fixedcyl+wp->wdp_removcyl, wp->wdp_heads, wp->wdp_sectors, -wp->wdp_cntype, wp->wdp_cnsbsz, wp->wdp_model);*/ - - /* update disklabel given drive information */ - du->dk_dd.d_ncylinders = wp->wdp_fixedcyl + wp->wdp_removcyl /*+- 1*/; - du->dk_dd.d_ntracks = wp->wdp_heads; - du->dk_dd.d_nsectors = wp->wdp_sectors; - du->dk_dd.d_secpercyl = du->dk_dd.d_ntracks * du->dk_dd.d_nsectors; - du->dk_dd.d_partitions[1].p_size = du->dk_dd.d_secpercyl * - wp->wdp_sectors; - du->dk_dd.d_partitions[1].p_offset = 0; - /* dubious ... */ - bcopy("ESDI/IDE", du->dk_dd.d_typename, 9); - bcopy(wp->wdp_model+20, du->dk_dd.d_packname, 14-1); - /* better ... */ - du->dk_dd.d_type = DTYPE_ESDI; - du->dk_dd.d_subtype |= DSTYPE_GEOMETRY; - - /* XXX sometimes possibly needed */ - (void) inb(wdc+wd_status); - return (0); -} - - -/* ARGSUSED */ -int -wdclose(dev_t dev, int flags, int fmt) -{ - register struct disk *du; - int part = wdpart(dev), mask = 1 << part; - - du = wddrives[wdunit(dev)]; - - /* insure only one open at a time */ - du->dk_openpart &= ~mask; - switch (fmt) { - case S_IFCHR: - du->dk_copenpart &= ~mask; - break; - case S_IFBLK: - du->dk_bopenpart &= ~mask; - break; - } - return(0); -} - -int -wdioctl(dev_t dev, int cmd, caddr_t addr, int flag) -{ - int unit = wdunit(dev); - register struct disk *du; - int error = 0; - struct uio auio; - struct iovec aiov; - - du = wddrives[unit]; - - switch (cmd) { - - case DIOCSBAD: - if ((flag & FWRITE) == 0) - error = EBADF; - else - du->dk_bad = *(struct dkbad *)addr; - break; - - case DIOCGDINFO: - *(struct disklabel *)addr = du->dk_dd; - break; - - case DIOCGPART: - ((struct partinfo *)addr)->disklab = &du->dk_dd; - ((struct partinfo *)addr)->part = - &du->dk_dd.d_partitions[wdpart(dev)]; - break; - - case DIOCSDINFO: - if ((flag & FWRITE) == 0) - error = EBADF; - else - error = setdisklabel(&du->dk_dd, - (struct disklabel *)addr, - /*(du->dk_flags & DKFL_BSDLABEL) ? du->dk_openpart : */0, - du->dk_dospartitions); - if (error == 0) { - du->dk_flags |= DKFL_BSDLABEL; - wdsetctlr(dev, du); - } - break; - - case DIOCWLABEL: - du->dk_flags &= ~DKFL_WRITEPROT; - if ((flag & FWRITE) == 0) - error = EBADF; - else - du->dk_wlabel = *(int *)addr; - break; - - case DIOCWDINFO: - du->dk_flags &= ~DKFL_WRITEPROT; - if ((flag & FWRITE) == 0) - error = EBADF; - else if ((error = setdisklabel(&du->dk_dd, (struct disklabel *)addr, - /*(du->dk_flags & DKFL_BSDLABEL) ? du->dk_openpart :*/ 0, - du->dk_dospartitions)) == 0) { - int wlab; - - du->dk_flags |= DKFL_BSDLABEL; - wdsetctlr(dev, du); - - /* simulate opening partition 0 so write succeeds */ - du->dk_openpart |= (1 << 0); /* XXX */ - wlab = du->dk_wlabel; - du->dk_wlabel = 1; - error = writedisklabel(dev, wdstrategy, - &du->dk_dd, du->dk_dospartitions); - du->dk_openpart = du->dk_copenpart | du->dk_bopenpart; - du->dk_wlabel = wlab; - } - break; - -#ifdef notyet - case DIOCGDINFOP: - *(struct disklabel **)addr = &(du->dk_dd); - break; - - case DIOCWFORMAT: - if ((flag & FWRITE) == 0) - error = EBADF; - else { - register struct format_op *fop; - - fop = (struct format_op *)addr; - aiov.iov_base = fop->df_buf; - aiov.iov_len = fop->df_count; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_resid = fop->df_count; - auio.uio_segflg = 0; - auio.uio_offset = - fop->df_startblk * du->dk_dd.d_secsize; - error = physio(wdformat, &rwdbuf[unit], dev, B_WRITE, - minphys, &auio); - fop->df_count -= auio.uio_resid; - fop->df_reg[0] = du->dk_status; - fop->df_reg[1] = du->dk_error; - } - break; -#endif - - default: - error = ENOTTY; - break; - } - return (error); -} - -#ifdef B_FORMAT -int -wdformat(struct buf *bp) -{ - - bp->b_flags |= B_FORMAT; - return (wdstrategy(bp)); -} -#endif - -int -wdsize(dev_t dev) -{ - int unit = wdunit(dev), part = wdpart(dev), val = 0; - struct disk *du; - - if (unit >= _NWD) /* 31 Jul 92*/ - return(-1); - - du = wddrives[unit]; - if (du == 0 || du->dk_state == 0) - val = wdopen (makewddev(major(dev), unit, WDRAW), FREAD, S_IFBLK, 0); - if (du == 0 || val != 0 || du->dk_flags & DKFL_WRITEPROT) - return (-1); - - return((int)du->dk_dd.d_partitions[part].p_size); -} - -extern char *vmmap; /* poor name! */ - -int -wddump(dev_t dev) /* dump core after a system crash */ -{ - register struct disk *du; /* disk unit to do the IO */ - register struct bt_bad *bt_ptr; - long num; /* number of sectors to write */ - int unit, part, wdc; - long blkoff, blknum, blkcnt; - long cylin, head, sector, stat; - long secpertrk, secpercyl, nblocks, i; - char *addr; - extern int Maxmem; - static wddoingadump = 0 ; - extern caddr_t CADDR1; - - addr = (char *) 0; /* starting address */ - - /* toss any characters present prior to dump */ - while (sgetc(1)) - ; - - /* size of memory to dump */ - num = Maxmem; - unit = wdunit(dev); /* eventually support floppies? */ - part = wdpart(dev); /* file system */ - /* check for acceptable drive number */ - if (unit >= _NWD) return(ENXIO); /* 31 Jul 92*/ - - du = wddrives[unit]; - if (du == 0) return(ENXIO); - /* was it ever initialized ? */ - if (du->dk_state < OPEN) return (ENXIO) ; - if (du->dk_flags & DKFL_WRITEPROT) return(ENXIO); - wdc = du->dk_port; - - /* Convert to disk sectors */ - num = (u_long) num * NBPG / du->dk_dd.d_secsize; - - /* check if controller active */ - /*if (wdtab.b_active) return(EFAULT); */ - if (wddoingadump) return(EFAULT); - - secpertrk = du->dk_dd.d_nsectors; - secpercyl = du->dk_dd.d_secpercyl; - nblocks = du->dk_dd.d_partitions[part].p_size; - blkoff = du->dk_dd.d_partitions[part].p_offset; - -/*pg("xunit %x, nblocks %d, dumplo %d num %d\n", part,nblocks,dumplo,num);*/ - /* check transfer bounds against partition size */ - if ((dumplo < 0) || ((dumplo + num) > nblocks)) - return(EINVAL); - - /*wdtab.b_active = 1; /* mark controller active for if we - panic during the dump */ - wddoingadump = 1 ; i = 100000 ; - while ((inb(wdc+wd_status) & WDCS_BUSY) && (i-- > 0)) ; - outb(wdc+wd_sdh, WDSD_IBM | (unit << 4)); - outb(wdc+wd_command, WDCC_RESTORE | WD_STEP); - while (inb(wdc+wd_status) & WDCS_BUSY) ; - - /* some compaq controllers require this ... */ - wdsetctlr(dev, du); - - blknum = dumplo + blkoff; - while (num > 0) { -#ifdef notdef - if (blkcnt > MAXTRANSFER) blkcnt = MAXTRANSFER; - if ((blknum + blkcnt - 1) / secpercyl != blknum / secpercyl) - blkcnt = secpercyl - (blknum % secpercyl); - /* keep transfer within current cylinder */ -#endif - pmap_enter(kernel_pmap, CADDR1, trunc_page(addr), VM_PROT_READ, TRUE); - - /* compute disk address */ - cylin = blknum / secpercyl; - head = (blknum % secpercyl) / secpertrk; - sector = blknum % secpertrk; - -#ifdef notyet - /* - * See if the current block is in the bad block list. - * (If we have one.) - */ - for (bt_ptr = du->dk_bad.bt_bad; - bt_ptr->bt_cyl != -1; bt_ptr++) { - if (bt_ptr->bt_cyl > cylin) - /* Sorted list, and we passed our cylinder. - quit. */ - break; - if (bt_ptr->bt_cyl == cylin && - bt_ptr->bt_trksec == (head << 8) + sector) { - /* - * Found bad block. Calculate new block addr. - * This starts at the end of the disk (skip the - * last track which is used for the bad block list), - * and works backwards to the front of the disk. - */ - blknum = (du->dk_dd.d_secperunit) - - du->dk_dd.d_nsectors - - (bt_ptr - du->dk_bad.bt_bad) - 1; - cylin = blknum / secpercyl; - head = (blknum % secpercyl) / secpertrk; - sector = blknum % secpertrk; - break; - } - -#endif - sector++; /* origin 1 */ - - /* select drive. */ - outb(wdc+wd_sdh, WDSD_IBM | (unit<<4) | (head & 0xf)); - while ((inb(wdc+wd_status) & WDCS_READY) == 0) ; - - /* transfer some blocks */ - outb(wdc+wd_sector, sector); - outb(wdc+wd_seccnt,1); - outb(wdc+wd_cyl_lo, cylin); - outb(wdc+wd_cyl_hi, cylin >> 8); -#ifdef notdef - /* lets just talk about this first...*/ - pg ("sdh 0%o sector %d cyl %d addr 0x%x", - inb(wdc+wd_sdh), inb(wdc+wd_sector), - inb(wdc+wd_cyl_hi)*256+inb(wdc+wd_cyl_lo), addr) ; -#endif - outb(wdc+wd_command, WDCC_WRITE); - - /* Ready to send data? */ - while ((inb(wdc+wd_status) & WDCS_DRQ) == 0) ; - if (inb(wdc+wd_status) & WDCS_ERR) return(EIO) ; - - outsw (wdc+wd_data, CADDR1+((int)addr&(NBPG-1)), 256); - - if (inb(wdc+wd_status) & WDCS_ERR) return(EIO) ; - /* Check data request (should be done). */ - if (inb(wdc+wd_status) & WDCS_DRQ) return(EIO) ; - - /* wait for completion */ - for ( i = WDCTIMEOUT ; inb(wdc+wd_status) & WDCS_BUSY ; i--) { - if (i < 0) return (EIO) ; - } - /* error check the xfer */ - if (inb(wdc+wd_status) & WDCS_ERR) return(EIO) ; - - if ((unsigned)addr % (1024*1024) == 0) printf("%d ", num/2048) ; - /* update block count */ - num--; - blknum++ ; - (int) addr += 512; - - /* operator aborting dump? */ - if (sgetc(1)) - return(EINTR); - } - return(0); -} -#endif diff --git a/sys/i386/isa/wdreg.h b/sys/i386/isa/wdreg.h deleted file mode 100644 index 5feabf5..0000000 --- a/sys/i386/isa/wdreg.h +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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. - * - * from: @(#)wdreg.h 7.1 (Berkeley) 5/9/91 - * $Id$ - */ - -/* - * Disk Controller register definitions. - */ -#define wd_data 0x0 /* data register (R/W - 16 bits) */ -#define wd_error 0x1 /* error register (R) */ -#define wd_precomp wd_error /* write precompensation (W) */ -#define wd_seccnt 0x2 /* sector count (R/W) */ -#define wd_sector 0x3 /* first sector number (R/W) */ -#define wd_cyl_lo 0x4 /* cylinder address, low byte (R/W) */ -#define wd_cyl_hi 0x5 /* cylinder address, high byte (R/W)*/ -#define wd_sdh 0x6 /* sector size/drive/head (R/W)*/ -#define wd_command 0x7 /* command register (W) */ -#define wd_status wd_command /* immediate status (R) */ - -#define wd_altsts 0x206 /*alternate fixed disk status(via 1015) (R)*/ -#define wd_ctlr 0x206 /*fixed disk controller control(via 1015) (W)*/ -#define WDCTL_4BIT 0x8 /* use four head bits (wd1003) */ -#define WDCTL_RST 0x4 /* reset the controller */ -#define WDCTL_IDS 0x2 /* disable controller interrupts */ -#define wd_digin 0x207 /* disk controller input(via 1015) (R)*/ - -/* - * Status Bits. - */ -#define WDCS_BUSY 0x80 /* Controller busy bit. */ -#define WDCS_READY 0x40 /* Selected drive is ready */ -#define WDCS_WRTFLT 0x20 /* Write fault */ -#define WDCS_SEEKCMPLT 0x10 /* Seek complete */ -#define WDCS_DRQ 0x08 /* Data request bit. */ -#define WDCS_ECCCOR 0x04 /* ECC correction made in data */ -#define WDCS_INDEX 0x02 /* Index pulse from selected drive */ -#define WDCS_ERR 0x01 /* Error detect bit. */ - -#define WDCS_BITS "\020\010busy\006rdy\006wrtflt\005seekdone\004drq\003ecc_cor\002index\001err" - -#define WDERR_BITS "\020\010badblk\007uncorr\006id_crc\005no_id\003abort\002tr000\001no_dam" - -/* - * Commands for Disk Controller. - */ -#define WDCC_RESTORE 0x10 /* disk restore code -- resets cntlr */ - -#define WDCC_READ 0x20 /* disk read code */ -#define WDCC_WRITE 0x30 /* disk write code */ -#define WDCC__LONG 0x02 /* modifier -- access ecc bytes */ -#define WDCC__NORETRY 0x01 /* modifier -- no retrys */ - -#define WDCC_FORMAT 0x50 /* disk format code */ -#define WDCC_DIAGNOSE 0x90 /* controller diagnostic */ -#define WDCC_IDC 0x91 /* initialize drive command */ - -#define WDCC_EXTDCMD 0xE0 /* send extended command */ -#define WDCC_READP 0xEC /* read parameters from controller */ -#define WDCC_CACHEC 0xEF /* cache control */ - -#define WD_STEP 0 /* winchester- default 35us step */ - -#define WDSD_IBM 0xa0 /* forced to 512 byte sector, ecc */ - - -#ifdef KERNEL -/* - * read parameters command returns this: - */ -struct wdparams { - /* drive info */ - short wdp_config; /* general configuration */ - short wdp_fixedcyl; /* number of non-removable cylinders */ - short wdp_removcyl; /* number of removable cylinders */ - short wdp_heads; /* number of heads */ - short wdp_unfbytespertrk; /* number of unformatted bytes/track */ - short wdp_unfbytes; /* number of unformatted bytes/sector */ - short wdp_sectors; /* number of sectors */ - short wdp_minisg; /* minimum bytes in inter-sector gap*/ - short wdp_minplo; /* minimum bytes in postamble */ - short wdp_vendstat; /* number of words of vendor status */ - /* controller info */ - char wdp_cnsn[20]; /* controller serial number */ - short wdp_cntype; /* controller type */ -#define WDTYPE_SINGLEPORTSECTOR 1 /* single port, single sector buffer */ -#define WDTYPE_DUALPORTMULTI 2 /* dual port, multiple sector buffer */ -#define WDTYPE_DUALPORTMULTICACHE 3 /* above plus track cache */ - short wdp_cnsbsz; /* sector buffer size, in sectors */ - short wdp_necc; /* ecc bytes appended */ - char wdp_rev[8]; /* firmware revision */ - char wdp_model[40]; /* model name */ - short wdp_nsecperint; /* sectors per interrupt */ - short wdp_usedmovsd; /* can use double word read/write? */ -}; - -/* - * wd driver entry points - */ -int wdprobe(struct isa_device *); -int wdattach(struct isa_device *); -int wdstrategy(struct buf *); -void wdintr(struct intrframe); -int wdopen(dev_t, int, int, struct proc *); -int wdclose(dev_t dev, int flags, int fmt); -int wdioctl(dev_t, int, caddr_t, int); -/* int wdformat(struct buf *bp); */ -int wdsize(dev_t); -int wddump(dev_t); - -#endif KERNEL diff --git a/sys/i386/isa/wt.c b/sys/i386/isa/wt.c deleted file mode 100644 index 7ae351f..0000000 --- a/sys/i386/isa/wt.c +++ /dev/null @@ -1,821 +0,0 @@ -/* - * Streamer tape driver for 386bsd and FreeBSD. - * Supports Archive QIC-02 and Wangtek QIC-02/QIC-36 boards. - * - * Copyright (C) 1993 by: - * Sergey Ryzhkov <sir@kiae.su> - * Serge Vakulenko <vak@zebub.msk.su> - * - * Placed in the public domain with NO WARRANTIES, not even the implied - * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Authors grant any other persons or organisations permission to use - * or modify this software as long as this message is kept with the software, - * all derivative works or modified versions. - * - * This driver is derived from the old 386bsd Wangtek streamer tape driver, - * made by Robert Baron at CMU, based on Intel sources. - * Authors thank Robert Baron, CMU and Intel and retain here - * the original CMU copyright notice. - * - * from: Version 1.1, Fri Sep 24 02:14:31 MSD 1993 - * $Id$ - */ - -/* - * Copyright (c) 1989 Carnegie-Mellon University. - * All rights reserved. - * - * Authors: Robert Baron - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -#include "wt.h" -#if NWT > 0 - -#include "sys/param.h" -#include "sys/buf.h" -#include "sys/fcntl.h" -#include "sys/malloc.h" -#include "sys/ioctl.h" -#include "sys/mtio.h" -#include "vm/vm_param.h" -#include "i386/include/pio.h" -#include "i386/isa/isa_device.h" -#include "i386/isa/wtreg.h" - -#define WTPRI (PZERO+10) /* sleep priority */ -#define BLKSIZE 512 /* streamer tape block size */ - -/* - * Wangtek controller ports - */ -#define WT_CTLPORT(base) ((base)+0) /* control, write only */ -#define WT_STATPORT(base) ((base)+0) /* status, read only */ -#define WT_CMDPORT(base) ((base)+1) /* command, write only */ -#define WT_DATAPORT(base) ((base)+1) /* data, read only */ -#define WT_NPORT 2 /* 2 i/o ports */ - -/* status port bits */ -#define WT_BUSY 0x01 /* not ready bit define */ -#define WT_NOEXCEP 0x02 /* no exception bit define */ -#define WT_RESETMASK 0x07 /* to check after reset */ -#define WT_RESETVAL 0x05 /* state after reset */ - -/* control port bits */ -#define WT_ONLINE 0x01 /* device selected */ -#define WT_RESET 0x02 /* reset command */ -#define WT_REQUEST 0x04 /* request command */ -#define WT_IEN(chan) ((chan)>2 ? 0x10 : 0x8) /* enable intr */ - -/* - * Archive controller ports - */ -#define AV_DATAPORT(base) ((base)+0) /* data, read only */ -#define AV_CMDPORT(base) ((base)+0) /* command, write only */ -#define AV_STATPORT(base) ((base)+1) /* status, read only */ -#define AV_CTLPORT(base) ((base)+1) /* control, write only */ -#define AV_SDMAPORT(base) ((base)+2) /* start dma */ -#define AV_RDMAPORT(base) ((base)+3) /* reset dma */ -#define AV_NPORT 4 /* 4 i/o ports */ - -/* status port bits */ -#define AV_BUSY 0x40 /* not ready bit define */ -#define AV_NOEXCEP 0x20 /* no exception bit define */ -#define AV_RESETMASK 0xf8 /* to check after reset */ -#define AV_RESETVAL 0x50 /* state after reset */ - -/* control port bits */ -#define AV_RESET 0x80 /* reset command */ -#define AV_REQUEST 0x40 /* request command */ -#define AV_IEN 0x20 /* enable interrupts */ - -#define DMA_STATUSREG 0x8 -#define DMA_DONE(chan) (1 << (chan)) - -typedef struct { - unsigned short err; /* code for error encountered */ - unsigned short ercnt; /* number of error blocks */ - unsigned short urcnt; /* number of underruns */ -} wtstatus_t; - -typedef struct { - unsigned unit; /* unit number */ - unsigned port; /* base i/o port */ - unsigned chan; /* dma channel number, 1..3 */ - unsigned flags; /* state of tape drive */ - unsigned dens; /* tape density */ - void *buf; /* internal i/o buffer */ - - void *dmavaddr; /* virtual address of dma i/o buffer */ - unsigned dmatotal; /* size of i/o buffer */ - unsigned dmaflags; /* i/o direction, B_READ or B_WRITE */ - unsigned dmacount; /* resulting length of dma i/o */ - - wtstatus_t error; /* status of controller */ - - unsigned short DATAPORT, CMDPORT, STATPORT, CTLPORT, SDMAPORT, RDMAPORT; - unsigned char BUSY, NOEXCEP, RESETMASK, RESETVAL; - unsigned char ONLINE, RESET, REQUEST, IEN; -} wtinfo_t; - -wtinfo_t wttab[NWT]; /* tape info by unit number */ - -extern int hz; /* number of ticks per second */ - -static int wtwait (wtinfo_t *t, int catch, char *msg); -static int wtcmd (wtinfo_t *t, int cmd); -static int wtstart (wtinfo_t *t, unsigned mode, void *vaddr, unsigned len); -static void wtdma (wtinfo_t *t); -static void wtimer (wtinfo_t *t); -static void wtclock (wtinfo_t *t); -static int wtreset (wtinfo_t *t); -static int wtsense (wtinfo_t *t, int ignor); -static int wtstatus (wtinfo_t *t); -static void wtrewind (wtinfo_t *t); -static int wtreadfm (wtinfo_t *t); -static int wtwritefm (wtinfo_t *t); -static int wtpoll (wtinfo_t *t); - -extern void DELAY (int usec); -extern void bcopy (void *from, void *to, unsigned len); -extern void isa_dmastart (int flags, void *addr, unsigned len, unsigned chan); -extern void isa_dmadone (int flags, void *addr, unsigned len, int chan); -extern void printf (char *str, ...); -extern int splbio (void); -extern int splx (int level); -extern void timeout (void (*func) (), void *arg, int timo); -extern int tsleep (void *chan, int priority, char *msg, int timo); -extern void wakeup (void *chan); - -/* - * Probe for the presence of the device. - */ -int wtprobe (struct isa_device *id) -{ - wtinfo_t *t = wttab + id->id_unit; - - t->unit = id->id_unit; - t->chan = id->id_drq; - t->port = 0; /* Mark it as not configured. */ - if (t->chan<1 || t->chan>3) { - printf ("wt%d: Bad drq=%d, should be 1..3\n", t->unit, t->chan); - return (0); - } - t->port = id->id_iobase; - - /* Try Wangtek. */ - t->CTLPORT = WT_CTLPORT (t->port); t->STATPORT = WT_STATPORT (t->port); - t->CMDPORT = WT_CMDPORT (t->port); t->DATAPORT = WT_DATAPORT (t->port); - t->SDMAPORT = 0; t->RDMAPORT = 0; - t->BUSY = WT_BUSY; t->NOEXCEP = WT_NOEXCEP; - t->RESETMASK = WT_RESETMASK; t->RESETVAL = WT_RESETVAL; - t->ONLINE = WT_ONLINE; t->RESET = WT_RESET; - t->REQUEST = WT_REQUEST; t->IEN = WT_IEN (t->chan); - if (wtreset (t)) - return (WT_NPORT); - - /* Try Archive. */ - t->CTLPORT = AV_CTLPORT (t->port); t->STATPORT = AV_STATPORT (t->port); - t->CMDPORT = AV_CMDPORT (t->port); t->DATAPORT = AV_DATAPORT (t->port); - t->SDMAPORT = AV_SDMAPORT (t->port); t->RDMAPORT = AV_RDMAPORT (t->port); - t->BUSY = AV_BUSY; t->NOEXCEP = AV_NOEXCEP; - t->RESETMASK = AV_RESETMASK; t->RESETVAL = AV_RESETVAL; - t->ONLINE = 0; t->RESET = AV_RESET; - t->REQUEST = AV_REQUEST; t->IEN = AV_IEN; - if (wtreset (t)) - return (AV_NPORT); - - /* Tape controller not found. */ - t->port = 0; - return (0); -} - -/* - * Device is found, configure it. - */ -int wtattach (struct isa_device *id) -{ - wtinfo_t *t = wttab + id->id_unit; - - if (t->RDMAPORT) { - printf ("wt%d: type <Archive>\n", t->unit); - outb (t->RDMAPORT, 0); /* reset dma */ - } else - printf ("wt%d: type <Wangtek>\n", t->unit); - t->flags = TPSTART; /* tape is rewound */ - t->dens = -1; /* unknown density */ - t->buf = malloc (BLKSIZE, M_TEMP, M_NOWAIT); - return (1); -} - -struct isa_driver wtdriver = { wtprobe, wtattach, "wt", }; - -int wtdump (int dev) -{ - /* Not implemented */ - return (EINVAL); -} - -int wtsize (int dev) -{ - /* Not implemented */ - return (-1); -} - -/* - * Open routine, called on every device open. - */ -int wtopen (int dev, int flag) -{ - int u = minor (dev) & T_UNIT; - wtinfo_t *t = wttab + u; - int error; - - if (u >= NWT || !t->port) - return (ENXIO); - - /* Check that device is not in use */ - if (t->flags & TPINUSE) - return (EBUSY); - - /* If the tape is in rewound state, check the status and set density. */ - if (t->flags & TPSTART) { - /* If rewind is going on, wait */ - error = wtwait (t, PCATCH, "wtrew"); - if (error) - return (error); - - if (! wtsense (t, (flag & FWRITE) ? 0 : TP_WRP)) { - /* Bad status. Reset the controller. */ - if (! wtreset (t)) - return (ENXIO); - if (! wtsense (t, (flag & FWRITE) ? 0 : TP_WRP)) - return (ENXIO); - } - - /* Set up tape density. */ - if (t->dens != (minor (dev) & T_DENSEL)) { - int d; - - switch (minor (dev) & T_DENSEL) { - default: - case T_800BPI: d = QIC_FMT150; break; /* minor 000 */ - case T_1600BPI: d = QIC_FMT120; break; /* minor 010 */ - case T_6250BPI: d = QIC_FMT24; break; /* minor 020 */ - case T_BADBPI: d = QIC_FMT11; break; /* minor 030 */ - } - if (! wtcmd (t, d)) - return (ENXIO); - - /* Check the status of the controller. */ - if (! wtsense (t, (flag & FWRITE) ? 0 : TP_WRP)) - return (ENXIO); - - t->dens = minor (dev) & T_DENSEL; - } - t->flags &= ~TPSTART; - } else if (t->dens != (minor (dev) & T_DENSEL)) - return (ENXIO); - - t->flags = TPINUSE; - if (flag & FREAD) - t->flags |= TPREAD; - if (flag & FWRITE) - t->flags |= TPWRITE; - return (0); -} - -/* - * Close routine, called on last device close. - */ -int wtclose (int dev) -{ - int u = minor (dev) & T_UNIT; - wtinfo_t *t = wttab + u; - - if (u >= NWT || !t->port) - return (ENXIO); - - /* If rewind is pending, do nothing */ - if (t->flags & TPREW) - goto done; - - /* If seek forward is pending and no rewind on close, do nothing */ - if ((t->flags & TPRMARK) && (minor (dev) & T_NOREWIND)) - goto done; - - /* If file mark read is going on, wait */ - wtwait (t, 0, "wtrfm"); - - if (t->flags & TPWANY) - /* Tape was written. Write file mark. */ - wtwritefm (t); - - if (! (minor (dev) & T_NOREWIND)) { - /* Rewind tape to beginning of tape. */ - /* Don't wait until rewind, though. */ - wtrewind (t); - goto done; - } - if ((t->flags & TPRANY) && ! (t->flags & (TPVOL | TPWANY))) - /* Space forward to after next file mark if no writing done. */ - /* Don't wait for completion. */ - wtreadfm (t); -done: - t->flags &= TPREW | TPRMARK | TPSTART | TPTIMER; - return (0); -} - -/* - * Ioctl routine. Compatible with BSD ioctls. - * Direct QIC-02 commands ERASE and RETENSION added. - * There are three possible ioctls: - * ioctl (int fd, MTIOCGET, struct mtget *buf) -- get status - * ioctl (int fd, MTIOCTOP, struct mtop *buf) -- do BSD-like op - * ioctl (int fd, WTQICMD, int qicop) -- do QIC op - */ -int wtioctl (int dev, int cmd, void *arg, int mode) -{ - int u = minor (dev) & T_UNIT; - wtinfo_t *t = wttab + u; - int error, count, op; - - if (u >= NWT || !t->port) - return (ENXIO); - - switch (cmd) { - default: - return (EINVAL); - case WTQICMD: /* direct QIC command */ - op = (int) *(void**)arg; - switch (op) { - default: - return (EINVAL); - case QIC_ERASE: /* erase the whole tape */ - if (! (t->flags & TPWRITE) || (t->flags & TPWP)) - return (EACCES); - if (error = wtwait (t, PCATCH, "wterase")) - return (error); - break; - case QIC_RETENS: /* retension the tape */ - if (error = wtwait (t, PCATCH, "wtretens")) - return (error); - break; - } - /* Both ERASE and RETENS operations work like REWIND. */ - /* Simulate the rewind operation here. */ - t->flags &= ~(TPRO | TPWO | TPVOL); - if (! wtcmd (t, op)) - return (EIO); - t->flags |= TPSTART | TPREW; - if (op == QIC_ERASE) - t->flags |= TPWANY; - wtclock (t); - return (0); - case MTIOCIEOT: /* ignore EOT errors */ - case MTIOCEEOT: /* enable EOT errors */ - return (0); - case MTIOCGET: - ((struct mtget*)arg)->mt_type = t->RDMAPORT ? MT_ISVIPER1 : 0x11; - ((struct mtget*)arg)->mt_dsreg = t->flags; /* status */ - ((struct mtget*)arg)->mt_erreg = t->error.err; /* errors */ - ((struct mtget*)arg)->mt_resid = 0; - ((struct mtget*)arg)->mt_fileno = 0; /* file */ - ((struct mtget*)arg)->mt_blkno = 0; /* block */ - return (0); - case MTIOCTOP: - break; - } - switch ((short) ((struct mtop*)arg)->mt_op) { - default: - case MTFSR: /* forward space record */ - case MTBSR: /* backward space record */ - case MTBSF: /* backward space file */ - break; - case MTNOP: /* no operation, sets status only */ - case MTCACHE: /* enable controller cache */ - case MTNOCACHE: /* disable controller cache */ - return (0); - case MTREW: /* rewind */ - case MTOFFL: /* rewind and put the drive offline */ - if (t->flags & TPREW) /* rewind is running */ - return (0); - if (error = wtwait (t, PCATCH, "wtorew")) - return (error); - wtrewind (t); - return (0); - case MTFSF: /* forward space file */ - for (count=((struct mtop*)arg)->mt_count; count>0; --count) { - if (error = wtwait (t, PCATCH, "wtorfm")) - return (error); - if (error = wtreadfm (t)) - return (error); - } - return (0); - case MTWEOF: /* write an end-of-file record */ - if (! (t->flags & TPWRITE) || (t->flags & TPWP)) - return (EACCES); - if (error = wtwait (t, PCATCH, "wtowfm")) - return (error); - if (error = wtwritefm (t)) - return (error); - return (0); - } - return (EINVAL); -} - -/* - * Strategy routine. - */ -void wtstrategy (struct buf *bp) -{ - int u = minor (bp->b_dev) & T_UNIT; - wtinfo_t *t = wttab + u; - int s; - - bp->b_resid = bp->b_bcount; - if (u >= NWT || !t->port) - goto errxit; - - /* at file marks and end of tape, we just return '0 bytes available' */ - if (t->flags & TPVOL) - goto xit; - - if (bp->b_flags & B_READ) { - /* Check read access and no previous write to this tape. */ - if (! (t->flags & TPREAD) || (t->flags & TPWANY)) - goto errxit; - - /* For now, we assume that all data will be copied out */ - /* If read command outstanding, just skip down */ - if (! (t->flags & TPRO)) { - if (! wtsense (t, TP_WRP)) /* clear status */ - goto errxit; - if (! wtcmd (t, QIC_RDDATA)) { /* sed read mode */ - wtsense (t, TP_WRP); - goto errxit; - } - t->flags |= TPRO | TPRANY; - } - } else { - /* Check write access and write protection. */ - /* No previous read from this tape allowed. */ - if (! (t->flags & TPWRITE) || (t->flags & (TPWP | TPRANY))) - goto errxit; - - /* If write command outstanding, just skip down */ - if (! (t->flags & TPWO)) { - if (! wtsense (t, 0)) /* clear status */ - goto errxit; - if (! wtcmd (t, QIC_WRTDATA)) { /* set write mode */ - wtsense (t, 0); - goto errxit; - } - t->flags |= TPWO | TPWANY; - } - } - - if (! bp->b_bcount) - goto xit; - - t->flags &= ~TPEXCEP; - s = splbio (); - if (wtstart (t, bp->b_flags, bp->b_un.b_addr, bp->b_bcount)) { - wtwait (t, 0, (bp->b_flags & B_READ) ? "wtread" : "wtwrite"); - bp->b_resid -= t->dmacount; - } - splx (s); - - if (t->flags & TPEXCEP) { -errxit: bp->b_flags |= B_ERROR; - bp->b_error = EIO; - } -xit: biodone (bp); - return; -} - -/* - * Interrupt routine. - */ -void wtintr (int u) -{ - wtinfo_t *t = wttab + u; - unsigned char s; - - if (u >= NWT || !t->port) - return; - - s = inb (t->STATPORT); /* get status */ - if ((s & (t->BUSY | t->NOEXCEP)) == (t->BUSY | t->NOEXCEP)) - return; /* device is busy */ - outb (t->CTLPORT, t->ONLINE); /* stop controller */ - - /* - * Check if rewind finished. - */ - if (t->flags & TPREW) { - t->flags &= ~TPREW; /* Rewind finished. */ - wtsense (t, TP_WRP); - wakeup (t); - return; - } - - /* - * Check if writing/reading of file mark finished. - */ - if (t->flags & (TPRMARK | TPWMARK)) { - if (! (s & t->NOEXCEP)) /* Operation failed. */ - wtsense (t, (t->flags & TPRMARK) ? TP_WRP : 0); - t->flags &= ~(TPRMARK | TPWMARK); /* Operation finished. */ - wakeup (t); - return; - } - - /* - * Do we started any i/o? If no, just return. - */ - if (! (t->flags & TPACTIVE)) - return; - t->flags &= ~TPACTIVE; - - if (inb (DMA_STATUSREG) & DMA_DONE (t->chan)) /* if dma finished */ - t->dmacount += BLKSIZE; /* increment counter */ - - /* - * Clean up dma. - */ - if ((t->dmaflags & B_READ) && (t->dmatotal - t->dmacount) < BLKSIZE) { - /* If the address crosses 64-k boundary, or reading short block, - * copy the internal buffer to the user memory. */ - isa_dmadone (t->dmaflags, t->buf, BLKSIZE, t->chan); - bcopy (t->buf, t->dmavaddr, t->dmatotal - t->dmacount); - } else - isa_dmadone (t->dmaflags, t->dmavaddr, BLKSIZE, t->chan); - - /* - * On exception, check for end of file and end of volume. - */ - if (! (s & t->NOEXCEP)) { - wtsense (t, (t->dmaflags & B_READ) ? TP_WRP : 0); - if (t->error.err & (TP_EOM | TP_FIL)) - t->flags |= TPVOL; /* end of file */ - else - t->flags |= TPEXCEP; /* i/o error */ - wakeup (t); - return; - } - - if (t->dmacount < t->dmatotal) { /* continue i/o */ - t->dmavaddr += BLKSIZE; - wtdma (t); - return; - } - if (t->dmacount > t->dmatotal) /* short last block */ - t->dmacount = t->dmatotal; - wakeup (t); /* wake up user level */ -} - -/* start the rewind operation */ -static void wtrewind (wtinfo_t *t) -{ - t->flags &= ~(TPRO | TPWO | TPVOL); - if (! wtcmd (t, QIC_REWIND)) - return; - t->flags |= TPSTART | TPREW; - wtclock (t); -} - -/* start the `read marker' operation */ -static int wtreadfm (wtinfo_t *t) -{ - t->flags &= ~(TPRO | TPWO | TPVOL); - if (! wtcmd (t, QIC_READFM)) { - wtsense (t, TP_WRP); - return (EIO); - } - t->flags |= TPRMARK | TPRANY; - wtclock (t); - /* Don't wait for completion here. */ - return (0); -} - -/* write marker to the tape */ -static int wtwritefm (wtinfo_t *t) -{ - tsleep (wtwritefm, WTPRI, "wtwfm", hz); /* timeout: 1 second */ - t->flags &= ~(TPRO | TPWO); - if (! wtcmd (t, QIC_WRITEFM)) { - wtsense (t, 0); - return (EIO); - } - t->flags |= TPWMARK | TPWANY; - wtclock (t); - return (wtwait (t, 0, "wtwfm")); -} - -/* wait for controller ready or exception */ -static int wtpoll (wtinfo_t *t) -{ - int s, NOTREADY = t->BUSY | t->NOEXCEP; - - /* Poll status port, waiting for ready or exception. */ - do s = inb (t->STATPORT); - while ((s & NOTREADY) == NOTREADY); - return (s); -} - -/* execute QIC command */ -static int wtcmd (wtinfo_t *t, int cmd) -{ - if (! (wtpoll (t) & t->NOEXCEP)) /* wait for ready */ - return (0); /* error */ - - outb (t->CMDPORT, cmd); /* output the command */ - - outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */ - while (inb (t->STATPORT) & t->BUSY) /* wait for ready */ - continue; - outb (t->CTLPORT, t->IEN | t->ONLINE); /* reset request */ - while (! (inb (t->STATPORT) & t->BUSY)) /* wait for not ready */ - continue; - - return (1); -} - -/* wait for the end of i/o, seeking marker or rewind operation */ -static int wtwait (wtinfo_t *t, int catch, char *msg) -{ - int error; - - while (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)) - if (error = tsleep (t, WTPRI | catch, msg, 0)) - return (error); - return (0); -} - -/* initialize dma for the i/o operation */ -static void wtdma (wtinfo_t *t) -{ - t->flags |= TPACTIVE; - wtclock (t); - - if (t->SDMAPORT) - outb (t->SDMAPORT, 0); /* set dma */ - - if ((t->dmaflags & B_READ) && (t->dmatotal - t->dmacount) < BLKSIZE) - /* Reading short block. Do it through the internal buffer. */ - isa_dmastart (t->dmaflags, t->buf, BLKSIZE, t->chan); - else - isa_dmastart (t->dmaflags, t->dmavaddr, BLKSIZE, t->chan); - - outb (t->CTLPORT, t->IEN | t->ONLINE); -} - -/* start i/o operation */ -static int wtstart (wtinfo_t *t, unsigned flags, void *vaddr, unsigned len) -{ - if (! (wtpoll (t) & t->NOEXCEP)) { /* wait for ready or error */ - t->flags |= TPEXCEP; /* error */ - return (0); - } - t->flags &= ~TPEXCEP; /* clear exception flag */ - t->dmavaddr = vaddr; - t->dmatotal = len; - t->dmacount = 0; - t->dmaflags = flags; - wtdma (t); - return (1); -} - -/* start timer */ -static void wtclock (wtinfo_t *t) -{ - if (! (t->flags & TPTIMER)) { - t->flags |= TPTIMER; - timeout (wtimer, t, hz); - } -} - -/* - * Simulate an interrupt periodically while i/o is going. - * This is necessary in case interrupts get eaten due to - * multiple devices on a single IRQ line. - */ -static void wtimer (wtinfo_t *t) -{ - int s; - - t->flags &= ~TPTIMER; - if (! (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK))) - return; - - /* If i/o going, simulate interrupt. */ - s = splbio (); - wtintr (t->unit); - splx (s); - - /* Restart timer if i/o pending. */ - if (t->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)) - wtclock (t); -} - -/* reset the controller */ -static int wtreset (wtinfo_t *t) -{ - outb (t->CTLPORT, t->RESET); /* send reset */ - DELAY (25); - outb (t->CTLPORT, 0); /* turn off reset */ - if ((inb (t->STATPORT) & t->RESETMASK) != t->RESETVAL) - return (0); - return (1); -} - -/* get controller status information */ -/* return 0 if user i/o request should receive an i/o error code */ -static int wtsense (wtinfo_t *t, int ignor) -{ - char *msg = 0; - int err; - - t->flags &= ~(TPRO | TPWO); - if (! wtstatus (t)) - return (0); - if (! (t->error.err & TP_ST0)) - t->error.err &= ~TP_ST0MASK; - if (! (t->error.err & TP_ST1)) - t->error.err &= ~TP_ST1MASK; - t->error.err &= ~ignor; /* ignore certain errors */ - err = t->error.err & (TP_FIL | TP_BNL | TP_UDA | TP_EOM | TP_WRP | - TP_USL | TP_CNI | TP_MBD | TP_NDT | TP_ILL); - if (! err) - return (1); - - /* lifted from tdriver.c from Wangtek */ - if (err & TP_USL) msg = "Drive not online"; - else if (err & TP_CNI) msg = "No cartridge"; - else if ((err & TP_WRP) && !(t->flags & TPWP)) { - msg = "Tape is write protected"; - t->flags |= TPWP; - } - else if (err & TP_FIL) msg = 0 /*"Filemark detected"*/; - else if (err & TP_EOM) msg = 0 /*"End of tape"*/; - else if (err & TP_BNL) msg = "Block not located"; - else if (err & TP_UDA) msg = "Unrecoverable data error"; - else if (err & TP_NDT) msg = "No data detected"; - else if (err & TP_ILL) msg = "Illegal command"; - if (msg) - printf ("wt%d: %s\n", t->unit, msg); - return (0); -} - -/* get controller status information */ -static int wtstatus (wtinfo_t *t) -{ - char *p; - - wtpoll (t); /* wait for ready or exception */ - outb (t->CMDPORT, QIC_RDSTAT); /* send `read status' command */ - - outb (t->CTLPORT, t->REQUEST | t->ONLINE); /* set request */ - while (inb (t->STATPORT) & t->BUSY) /* wait for ready */ - continue; - outb (t->CTLPORT, t->ONLINE); /* reset request */ - while (! (inb (t->STATPORT) & t->BUSY)) /* wait for not ready */ - continue; - - p = (char*) &t->error; - while (p < (char*)&t->error + 6) { - if (! (wtpoll (t) & t->NOEXCEP)) /* wait for ready */ - return (0); /* error */ - - *p++ = inb (t->DATAPORT); /* read status byte */ - - outb (t->CTLPORT, t->REQUEST); /* set request */ - while (! (inb (t->STATPORT) & t->BUSY)) /* wait for not ready */ - continue; - /* DELAY (50); */ /* wait 50 usec */ - outb (t->CTLPORT, 0); /* unset request */ - } - return (1); -} -#endif /* NWT */ diff --git a/sys/i386/isa/wtreg.h b/sys/i386/isa/wtreg.h deleted file mode 100644 index d7658f3..0000000 --- a/sys/i386/isa/wtreg.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Streamer tape driver for 386bsd and FreeBSD. - * Supports Archive QIC-02 and Wangtek QIC-02/QIC-36 boards. - * - * Copyright (C) 1993 by: - * Sergey Ryzhkov <sir@kiae.su> - * Serge Vakulenko <vak@zebub.msk.su> - * - * Placed in the public domain with NO WARRANTIES, not even the implied - * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Authors grant any other persons or organisations permission to use - * or modify this software as long as this message is kept with the software, - * all derivative works or modified versions. - * - * This driver is derived from the old 386bsd Wangtek streamer tape driver, - * made by Robert Baron at CMU, based on Intel sources. - * Authors thank Robert Baron, CMU and Intel and retain here - * the original CMU copyright notice. - * - * from: Version 1.1, Fri Sep 24 02:14:42 MSD 1993 - * $Id$ - */ - -/* - * Copyright (c) 1989 Carnegie-Mellon University. - * All rights reserved. - * - * Authors: Robert Baron - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* ioctl for direct QIC commands */ -#define WTQICMD _IO('W', 0) - -/* QIC-02 commands allowed for WTQICMD */ -#define QIC_ERASE 0x22 -#define QIC_RETENS 0x24 - -/* internal QIC-02 commands */ -#define QIC_RDDATA 0x80 /* read data */ -#define QIC_READFM 0xa0 /* read file mark */ -#define QIC_WRTDATA 0x40 /* write data */ -#define QIC_WRITEFM 0x60 /* write file mark */ -#define QIC_RDSTAT 0xc0 /* read status command */ -#define QIC_REWIND 0x21 /* rewind command (position+bot) */ -#define QIC_FMT11 0x26 /* set format QIC-11 */ -#define QIC_FMT24 0x27 /* set format QIC-24 */ -#define QIC_FMT120 0x28 /* set format QIC-120 */ -#define QIC_FMT150 0x29 /* set format QIC-150 */ - -/* tape driver flags */ -#define TPINUSE 0x0001 /* tape is already open */ -#define TPREAD 0x0002 /* tape is only open for reading */ -#define TPWRITE 0x0004 /* tape is only open for writing */ -#define TPSTART 0x0008 /* tape must be rewound and reset */ -#define TPRMARK 0x0010 /* read file mark command outstanding */ -#define TPWMARK 0x0020 /* write file mark command outstanding */ -#define TPREW 0x0040 /* rewind command outstanding */ -#define TPEXCEP 0x0080 /* i/o exception flag */ -#define TPVOL 0x0100 /* read file mark or hit end of tape */ -#define TPWO 0x0200 /* write command outstanding */ -#define TPRO 0x0400 /* read command outstanding */ -#define TPWANY 0x0800 /* write command requested */ -#define TPRANY 0x1000 /* read command requested */ -#define TPWP 0x2000 /* write protect error seen */ -#define TPTIMER 0x4000 /* timer() is active */ -#define TPACTIVE 0x8000 /* dma i/o active */ - -/* controller error register bits */ -#define TP_FIL 0x0001 /* File mark detected */ -#define TP_BNL 0x0002 /* Block not located */ -#define TP_UDA 0x0004 /* Unrecoverable data error */ -#define TP_EOM 0x0008 /* End of media */ -#define TP_WRP 0x0010 /* Write protected cartridge */ -#define TP_USL 0x0020 /* Unselected drive */ -#define TP_CNI 0x0040 /* Cartridge not in place */ -#define TP_ST0 0x0080 /* Status byte 0 bits */ -#define TP_ST0MASK 0x00ff /* Status byte 0 mask */ -#define TP_POR 0x0100 /* Power on/reset occurred */ -#define TP_RES1 0x0200 /* Reserved for end of media */ -#define TP_RES2 0x0400 /* Reserved for bus parity */ -#define TP_BOM 0x0800 /* Beginning of media */ -#define TP_MBD 0x1000 /* Marginal block detected */ -#define TP_NDT 0x2000 /* No data detected */ -#define TP_ILL 0x4000 /* Illegal command - should not happen! */ -#define TP_ST1 0x8000 /* Status byte 1 bits */ -#define TP_ST1MASK 0xff00 /* Status byte 1 mask */ - -/* formats for printing flags and error values */ -#define WTDS_BITS "\20\1inuse\2read\3write\4start\5rmark\6wmark\7rew\10excep\11vol\12wo\13ro\14wany\15rany\16wp\17timer\20active" -#define WTER_BITS "\20\1eof\2bnl\3uda\4eom\5wrp\6usl\7cni\11por\12res1\13res2\14bom\15mbd\16ndt\17ill" |