Home | History | Annotate | Line # | Download | only in isa
isa.c revision 1.28.2.22
      1        1.1      cgd /*-
      2   1.28.2.7  mycroft  * Copyright (c) 1993 Charles Hannum.
      3        1.1      cgd  * Copyright (c) 1991 The Regents of the University of California.
      4        1.1      cgd  * All rights reserved.
      5        1.1      cgd  *
      6        1.1      cgd  * This code is derived from software contributed to Berkeley by
      7        1.1      cgd  * William Jolitz.
      8        1.1      cgd  *
      9        1.1      cgd  * Redistribution and use in source and binary forms, with or without
     10        1.1      cgd  * modification, are permitted provided that the following conditions
     11        1.1      cgd  * are met:
     12        1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     13        1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     14        1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     15        1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     16        1.1      cgd  *    documentation and/or other materials provided with the distribution.
     17        1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     18        1.1      cgd  *    must display the following acknowledgement:
     19        1.1      cgd  *	This product includes software developed by the University of
     20        1.1      cgd  *	California, Berkeley and its contributors.
     21        1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     22        1.1      cgd  *    may be used to endorse or promote products derived from this software
     23        1.1      cgd  *    without specific prior written permission.
     24        1.1      cgd  *
     25        1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26        1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27        1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28        1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29        1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30        1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31        1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32        1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33        1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34        1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35        1.1      cgd  * SUCH DAMAGE.
     36        1.1      cgd  *
     37       1.13      cgd  *	from: @(#)isa.c	7.2 (Berkeley) 5/13/91
     38  1.28.2.22  mycroft  *	$Id: isa.c,v 1.28.2.22 1993/12/01 00:55:47 mycroft Exp $
     39        1.1      cgd  */
     40        1.1      cgd 
     41        1.1      cgd /*
     42        1.1      cgd  * code to manage AT bus
     43        1.1      cgd  */
     44        1.1      cgd 
     45  1.28.2.15  mycroft #include <sys/param.h>
     46  1.28.2.15  mycroft #include <sys/systm.h>
     47  1.28.2.15  mycroft #include <sys/conf.h>
     48  1.28.2.15  mycroft #include <sys/file.h>
     49  1.28.2.15  mycroft #include <sys/device.h>
     50  1.28.2.15  mycroft 
     51  1.28.2.15  mycroft #include <machine/cpu.h>
     52  1.28.2.15  mycroft #include <machine/pio.h>
     53  1.28.2.15  mycroft 
     54  1.28.2.15  mycroft #include <i386/isa/isa.h>
     55  1.28.2.15  mycroft #include <i386/isa/isavar.h>
     56  1.28.2.15  mycroft #include <i386/isa/icu.h>
     57  1.28.2.15  mycroft #include <i386/isa/timerreg.h>
     58  1.28.2.15  mycroft #include <i386/isa/spkr_reg.h>
     59       1.14  deraadt 
     60   1.28.2.1  mycroft isa_type isa_bustype;				/* type of bus */
     61        1.1      cgd 
     62   1.28.2.1  mycroft static int isaprobe __P((struct device *, struct cfdata *, void *));
     63   1.28.2.2  mycroft static void isaattach __P((struct device *, struct device *, void *));
     64   1.28.2.2  mycroft static int isasubmatch __P((struct device *, struct cfdata *, void *));
     65   1.28.2.1  mycroft 
     66   1.28.2.1  mycroft struct cfdriver isacd =
     67   1.28.2.2  mycroft     { NULL, "isa", isaprobe, isaattach, DV_DULL, sizeof(struct isa_softc) };
     68   1.28.2.1  mycroft 
     69   1.28.2.2  mycroft static int isaprint __P((void *, char *));
     70  1.28.2.17  mycroft void isa_defaultirq __P((void));
     71  1.28.2.17  mycroft void isa_flushintrs __P((void));
     72  1.28.2.17  mycroft void isa_intrmaskwickedness __P((void));
     73   1.28.2.2  mycroft 
     74   1.28.2.2  mycroft /*
     75   1.28.2.2  mycroft  * We think there might be an ISA bus here.  Check it out.
     76   1.28.2.2  mycroft  */
     77   1.28.2.2  mycroft static int
     78   1.28.2.1  mycroft isaprobe(parent, cf, aux)
     79   1.28.2.1  mycroft 	struct device *parent;
     80   1.28.2.1  mycroft 	struct cfdata *cf;
     81   1.28.2.1  mycroft 	void *aux;
     82   1.28.2.1  mycroft {
     83   1.28.2.1  mycroft 
     84   1.28.2.1  mycroft 	/* XXX should do a real probe */
     85   1.28.2.1  mycroft 	isa_bustype = BUS_ISA;
     86   1.28.2.1  mycroft 	return 1;
     87   1.28.2.1  mycroft }
     88   1.28.2.1  mycroft 
     89   1.28.2.2  mycroft /*
     90   1.28.2.2  mycroft  * Probe succeeded, someone called config_attach.  Now we have to
     91   1.28.2.2  mycroft  * probe the ISA bus itself in our turn.
     92   1.28.2.2  mycroft  */
     93   1.28.2.2  mycroft static void
     94   1.28.2.2  mycroft isaattach(parent, self, aux)
     95   1.28.2.2  mycroft 	struct device *parent, *self;
     96   1.28.2.2  mycroft 	void *aux;
     97   1.28.2.2  mycroft {
     98   1.28.2.2  mycroft 
     99   1.28.2.7  mycroft 	/* XXX should print ISA/EISA & bus clock frequency and anything else
    100   1.28.2.2  mycroft 	   we can figure out? */
    101   1.28.2.2  mycroft 	printf("\n");
    102   1.28.2.2  mycroft 
    103   1.28.2.2  mycroft 	isa_defaultirq();
    104   1.28.2.2  mycroft 
    105   1.28.2.2  mycroft 	/* Iterate ``isasubmatch'' over all devices configured here. */
    106   1.28.2.2  mycroft 	(void)config_search(isasubmatch, self, (void *)NULL);
    107   1.28.2.2  mycroft 
    108  1.28.2.12  mycroft 	isa_intrmaskwickedness();
    109   1.28.2.9  mycroft 	isa_flushintrs();
    110   1.28.2.2  mycroft }
    111   1.28.2.2  mycroft 
    112   1.28.2.2  mycroft /*
    113   1.28.2.2  mycroft  * isaattach (above) iterates this function over all the sub-devices that
    114   1.28.2.2  mycroft  * were configured at the ``isa'' device.  Our job is to provide defaults
    115   1.28.2.2  mycroft  * and do some internal/external representation conversion (some of which
    116   1.28.2.2  mycroft  * is scheduled to get cleaned up later), then call the device's probe
    117   1.28.2.2  mycroft  * function.  If this says the device is there, we try to reserve ISA
    118   1.28.2.2  mycroft  * bus memory and ports for the device, and attach it.
    119   1.28.2.2  mycroft  *
    120   1.28.2.2  mycroft  * Note that we always return 0, but our ultimate caller (isaattach)
    121   1.28.2.2  mycroft  * does not care that we never `match' anything.  (In fact, our return
    122   1.28.2.2  mycroft  * value is entirely irrelevant; this function is run entirely for its
    123   1.28.2.2  mycroft  * side effects.)
    124   1.28.2.2  mycroft  */
    125   1.28.2.1  mycroft static int
    126   1.28.2.2  mycroft isasubmatch(isa, cf, aux)
    127   1.28.2.2  mycroft 	struct device *isa;
    128   1.28.2.1  mycroft 	struct cfdata *cf;
    129   1.28.2.1  mycroft 	void *aux;
    130   1.28.2.1  mycroft {
    131   1.28.2.2  mycroft 	struct isa_attach_args ia;
    132   1.28.2.1  mycroft 
    133   1.28.2.1  mycroft #ifdef DIAGNOSTIC
    134   1.28.2.2  mycroft 	if (cf->cf_driver->cd_match == NULL) {
    135  1.28.2.21  mycroft 		panic("isasubmatch: no match function for `%s' device\n",
    136  1.28.2.21  mycroft 		      cf->cf_driver->cd_name);
    137   1.28.2.1  mycroft 	}
    138   1.28.2.1  mycroft #endif
    139   1.28.2.1  mycroft 
    140  1.28.2.12  mycroft 	/* Init the info needed in the device probe and attach routines. */
    141   1.28.2.2  mycroft 	ia.ia_iobase = cf->cf_iobase;
    142   1.28.2.2  mycroft 	ia.ia_iosize = cf->cf_iosize;
    143   1.28.2.2  mycroft 	if (cf->cf_irq == -1)
    144   1.28.2.2  mycroft 		ia.ia_irq = IRQUNK;
    145   1.28.2.2  mycroft 	else
    146   1.28.2.2  mycroft 		ia.ia_irq = 1 << cf->cf_irq;
    147   1.28.2.2  mycroft 	ia.ia_drq = cf->cf_drq;
    148   1.28.2.2  mycroft 	ia.ia_maddr = (caddr_t)cf->cf_maddr;
    149   1.28.2.2  mycroft 	ia.ia_msize = cf->cf_msize;
    150   1.28.2.1  mycroft 
    151   1.28.2.2  mycroft 	/* If driver says it's not there, believe it. */
    152   1.28.2.2  mycroft 	if (!cf->cf_driver->cd_match(isa, cf, &ia))
    153   1.28.2.1  mycroft 		return 0;
    154   1.28.2.1  mycroft 
    155  1.28.2.12  mycroft 	/* Check for port or shared memory conflicts. */
    156  1.28.2.12  mycroft 	if (ia.ia_iosize && !isa_portcheck(ia.ia_iobase, ia.ia_iosize))
    157  1.28.2.12  mycroft 		return 0;
    158  1.28.2.12  mycroft 	if (ia.ia_msize && !isa_memcheck(ia.ia_maddr, ia.ia_msize))
    159  1.28.2.12  mycroft 		return 0;
    160  1.28.2.12  mycroft 
    161  1.28.2.12  mycroft 	/* Reserve I/O ports and/or shared memory. */
    162  1.28.2.12  mycroft 	if (ia.ia_iosize)
    163  1.28.2.11  mycroft 		isa_portalloc(ia.ia_iobase, ia.ia_iosize);
    164  1.28.2.12  mycroft 	if (ia.ia_msize)
    165  1.28.2.12  mycroft 		isa_memalloc(ia.ia_maddr, ia.ia_msize);
    166  1.28.2.12  mycroft 
    167  1.28.2.12  mycroft 	/* Configure device. */
    168  1.28.2.12  mycroft 	config_attach(isa, cf, &ia, isaprint);
    169   1.28.2.1  mycroft 
    170   1.28.2.2  mycroft 	return 0;
    171  1.28.2.14  mycroft }
    172  1.28.2.14  mycroft 
    173  1.28.2.14  mycroft /*
    174  1.28.2.14  mycroft  * XXX It's not clear to me why this is useful.
    175  1.28.2.14  mycroft  */
    176  1.28.2.14  mycroft void
    177  1.28.2.14  mycroft isa_establish(id, dv)
    178  1.28.2.14  mycroft 	struct isadev *id;
    179  1.28.2.14  mycroft 	struct device *dv;
    180  1.28.2.14  mycroft {
    181  1.28.2.14  mycroft 	struct isa_softc *idv = (struct isa_softc *)dv->dv_parent;
    182  1.28.2.14  mycroft 	id->id_dev = dv;
    183  1.28.2.14  mycroft 	id->id_bchain = idv->sc_isadev;
    184  1.28.2.14  mycroft 	idv->sc_isadev = id;
    185   1.28.2.1  mycroft }
    186   1.28.2.1  mycroft 
    187   1.28.2.2  mycroft /*
    188   1.28.2.2  mycroft  * Called indirectly via config_attach (see above).  Config has already
    189   1.28.2.2  mycroft  * printed, e.g., "wdc0 at isa0".  We can ignore our ``isaname'' arg
    190   1.28.2.2  mycroft  * (it is always NULL, by definition) and just extend the line with
    191   1.28.2.2  mycroft  * the standard info (port(s), irq, drq, and iomem).
    192   1.28.2.2  mycroft  */
    193   1.28.2.2  mycroft static int
    194   1.28.2.1  mycroft isaprint(aux, isaname)
    195   1.28.2.1  mycroft 	void *aux;
    196   1.28.2.1  mycroft 	char *isaname;
    197   1.28.2.1  mycroft {
    198   1.28.2.1  mycroft 	struct isa_attach_args *ia = aux;
    199   1.28.2.1  mycroft 
    200   1.28.2.1  mycroft 	if (ia->ia_iosize)
    201   1.28.2.1  mycroft 		printf(" port 0x%x", ia->ia_iobase);
    202   1.28.2.1  mycroft 	if (ia->ia_iosize > 1)
    203   1.28.2.1  mycroft 		printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
    204  1.28.2.12  mycroft 	if (ia->ia_msize)
    205  1.28.2.12  mycroft 		printf(" iomem 0x%x", ia->ia_maddr);
    206  1.28.2.12  mycroft 	if (ia->ia_msize > 1)
    207  1.28.2.12  mycroft 		printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
    208   1.28.2.3  mycroft #ifdef DIAGNOSTIC
    209   1.28.2.3  mycroft 	if (ia->ia_irq == IRQUNK)
    210   1.28.2.4  mycroft 		printf(" THIS IS A BUG ->");
    211   1.28.2.3  mycroft #endif
    212   1.28.2.3  mycroft 	if (ia->ia_irq != IRQNONE)
    213   1.28.2.1  mycroft 		printf(" irq %d", ffs(ia->ia_irq) - 1);
    214   1.28.2.1  mycroft 	if (ia->ia_drq != DRQUNK)
    215   1.28.2.1  mycroft 		printf(" drq %d", ia->ia_drq);
    216   1.28.2.7  mycroft 	/* XXXX print flags */
    217   1.28.2.2  mycroft 	return QUIET;	/* actually, our return value is irrelevant. */
    218        1.1      cgd }
    219        1.1      cgd 
    220  1.28.2.13  mycroft /*
    221  1.28.2.12  mycroft int isa_portcheck __P((u_int, u_int));
    222  1.28.2.12  mycroft int isa_memcheck __P((u_int, u_int));
    223  1.28.2.12  mycroft void isa_portalloc __P((u_int, u_int));
    224  1.28.2.12  mycroft void isa_memalloc __P((u_int, u_int));
    225  1.28.2.13  mycroft */
    226        1.1      cgd 
    227   1.28.2.7  mycroft static int beeping;
    228   1.28.2.7  mycroft 
    229       1.21   andrew static void
    230  1.28.2.22  mycroft sysbeepstop(arg)
    231  1.28.2.22  mycroft 	caddr_t arg;
    232        1.1      cgd {
    233       1.16  mycroft 
    234        1.1      cgd 	/* disable counter 2 */
    235       1.16  mycroft 	disable_intr();
    236       1.28   brezak 	outb(PITAUX_PORT, inb(PITAUX_PORT) & ~PIT_SPKR);
    237       1.16  mycroft 	enable_intr();
    238  1.28.2.22  mycroft 	beeping = 0;
    239        1.1      cgd }
    240        1.1      cgd 
    241       1.21   andrew void
    242       1.21   andrew sysbeep(int pitch, int period)
    243        1.1      cgd {
    244       1.16  mycroft 	static int last_pitch, last_period;
    245        1.1      cgd 
    246  1.28.2.22  mycroft 	if (beeping)
    247  1.28.2.22  mycroft 		untimeout(sysbeepstop, (caddr_t)0);
    248       1.16  mycroft 	if (!beeping || last_pitch != pitch) {
    249       1.16  mycroft 		/*
    250   1.28.2.7  mycroft 		 * XXX - move timer stuff to clock.c.
    251   1.28.2.7  mycroft 		 */
    252       1.16  mycroft 		disable_intr();
    253       1.16  mycroft 		outb(TIMER_MODE, TIMER_SEL2|TIMER_16BIT|TIMER_SQWAVE);
    254   1.28.2.7  mycroft 		outb(TIMER_CNTR2, TIMER_DIV(pitch));
    255   1.28.2.7  mycroft 		outb(TIMER_CNTR2, TIMER_DIV(pitch)>>8);
    256       1.28   brezak 		outb(PITAUX_PORT, inb(PITAUX_PORT) | PIT_SPKR);	/* enable counter 2 */
    257       1.16  mycroft 		enable_intr();
    258       1.16  mycroft 	}
    259       1.16  mycroft 	last_pitch = pitch;
    260       1.16  mycroft 	beeping = last_period = period;
    261  1.28.2.22  mycroft 	timeout(sysbeepstop, (caddr_t)0, period);
    262        1.1      cgd }
    263