Home | History | Annotate | Line # | Download | only in pci
pci_hades.c revision 1.1
      1  1.1  leo /*	$NetBSD: pci_hades.c,v 1.1 2001/05/15 14:14:49 leo Exp $	*/
      2  1.1  leo 
      3  1.1  leo /*
      4  1.1  leo  * Copyright (c) 1996 Leo Weppelman.  All rights reserved.
      5  1.1  leo  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      6  1.1  leo  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
      7  1.1  leo  *
      8  1.1  leo  * Redistribution and use in source and binary forms, with or without
      9  1.1  leo  * modification, are permitted provided that the following conditions
     10  1.1  leo  * are met:
     11  1.1  leo  * 1. Redistributions of source code must retain the above copyright
     12  1.1  leo  *    notice, this list of conditions and the following disclaimer.
     13  1.1  leo  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  leo  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  leo  *    documentation and/or other materials provided with the distribution.
     16  1.1  leo  * 3. All advertising materials mentioning features or use of this software
     17  1.1  leo  *    must display the following acknowledgement:
     18  1.1  leo  *	This product includes software developed by Charles M. Hannum.
     19  1.1  leo  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  leo  *    derived from this software without specific prior written permission.
     21  1.1  leo  *
     22  1.1  leo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  leo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  leo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  leo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  leo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  leo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  leo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  leo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  leo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  leo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  leo  */
     33  1.1  leo 
     34  1.1  leo #include <sys/types.h>
     35  1.1  leo #include <sys/param.h>
     36  1.1  leo #include <sys/systm.h>
     37  1.1  leo #include <sys/device.h>
     38  1.1  leo 
     39  1.1  leo #include <machine/bus.h>
     40  1.1  leo 
     41  1.1  leo #include <dev/pci/pcivar.h>
     42  1.1  leo #include <dev/pci/pcireg.h>
     43  1.1  leo 
     44  1.1  leo #include <machine/cpu.h>
     45  1.1  leo #include <machine/iomap.h>
     46  1.1  leo #include <machine/mfp.h>
     47  1.1  leo #include <machine/bswap.h>
     48  1.1  leo 
     49  1.1  leo #include <atari/atari/device.h>
     50  1.1  leo #include <atari/pci/pci_vga.h>
     51  1.1  leo 
     52  1.1  leo int
     53  1.1  leo pci_bus_maxdevs(pc, busno)
     54  1.1  leo 	pci_chipset_tag_t pc;
     55  1.1  leo 	int busno;
     56  1.1  leo {
     57  1.1  leo 	return (4);
     58  1.1  leo }
     59  1.1  leo 
     60  1.1  leo static int pci_config_offset __P((pcitag_t));
     61  1.1  leo 
     62  1.1  leo /*
     63  1.1  leo  * Atari_init.c maps the config areas NBPG bytes apart....
     64  1.1  leo  */
     65  1.1  leo static int pci_config_offset(tag)
     66  1.1  leo pcitag_t	tag;
     67  1.1  leo {
     68  1.1  leo 	int	device;
     69  1.1  leo 
     70  1.1  leo 	device = (tag >> 11) & 0x1f;
     71  1.1  leo 	return(device * NBPG);
     72  1.1  leo }
     73  1.1  leo 
     74  1.1  leo pcireg_t
     75  1.1  leo pci_conf_read(pc, tag, reg)
     76  1.1  leo 	pci_chipset_tag_t pc;
     77  1.1  leo 	pcitag_t tag;
     78  1.1  leo 	int reg;
     79  1.1  leo {
     80  1.1  leo 	u_long	data;
     81  1.1  leo 
     82  1.1  leo 	data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
     83  1.1  leo 	return (bswap32(data));
     84  1.1  leo }
     85  1.1  leo 
     86  1.1  leo void
     87  1.1  leo pci_conf_write(pc, tag, reg, data)
     88  1.1  leo 	pci_chipset_tag_t pc;
     89  1.1  leo 	pcitag_t tag;
     90  1.1  leo 	int reg;
     91  1.1  leo 	pcireg_t data;
     92  1.1  leo {
     93  1.1  leo 	*((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg))
     94  1.1  leo 		= bswap32(data);
     95  1.1  leo }
     96  1.1  leo 
     97  1.1  leo /*
     98  1.1  leo  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
     99  1.1  leo  * for a slot are wired together and connected to IO 0,1,2 or 5 (slots:
    100  1.1  leo  * (0-3) on the TT-MFP. The Pci-config code initializes the irq. number
    101  1.1  leo  * to the slot position.
    102  1.1  leo  */
    103  1.1  leo static pci_intr_info_t iinfo[4] = { { -1 }, { -1 }, { -1 }, { -1 } };
    104  1.1  leo 
    105  1.1  leo static int	iifun __P((int, int));
    106  1.1  leo 
    107  1.1  leo static int
    108  1.1  leo iifun(slot, sr)
    109  1.1  leo int	slot;
    110  1.1  leo int	sr;
    111  1.1  leo {
    112  1.1  leo 	pci_intr_info_t *iinfo_p;
    113  1.1  leo 	int		s;
    114  1.1  leo 
    115  1.1  leo 	iinfo_p = &iinfo[slot];
    116  1.1  leo 
    117  1.1  leo 	/*
    118  1.1  leo 	 * Disable the interrupts
    119  1.1  leo 	 */
    120  1.1  leo 	MFP2->mf_imrb  &= ~iinfo_p->imask;
    121  1.1  leo 
    122  1.1  leo 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
    123  1.1  leo 		/*
    124  1.1  leo 		 * We're running at a too high priority now.
    125  1.1  leo 		 */
    126  1.1  leo 		add_sicallback((si_farg)iifun, (void*)slot, 0);
    127  1.1  leo 	}
    128  1.1  leo 	else {
    129  1.1  leo 		s = splx(iinfo_p->ipl);
    130  1.1  leo 		(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    131  1.1  leo 		splx(s);
    132  1.1  leo 
    133  1.1  leo 		/*
    134  1.1  leo 		 * Re-enable interrupts after handling
    135  1.1  leo 		 */
    136  1.1  leo 		MFP2->mf_imrb |= iinfo_p->imask;
    137  1.1  leo 	}
    138  1.1  leo 	return 1;
    139  1.1  leo }
    140  1.1  leo 
    141  1.1  leo void *
    142  1.1  leo pci_intr_establish(pc, ih, level, ih_fun, ih_arg)
    143  1.1  leo 	pci_chipset_tag_t	pc;
    144  1.1  leo 	pci_intr_handle_t	ih;
    145  1.1  leo 	int			level;
    146  1.1  leo 	int			(*ih_fun) __P((void *));
    147  1.1  leo 	void			*ih_arg;
    148  1.1  leo {
    149  1.1  leo 	pci_intr_info_t *iinfo_p;
    150  1.1  leo 	struct intrhand	*ihand;
    151  1.1  leo 	int		slot;
    152  1.1  leo 
    153  1.1  leo 	slot    = ih;
    154  1.1  leo 	iinfo_p = &iinfo[slot];
    155  1.1  leo 
    156  1.1  leo 	if (iinfo_p->ipl > 0)
    157  1.1  leo 	    panic("pci_intr_establish: interrupt was already established\n");
    158  1.1  leo 
    159  1.1  leo 	ihand = intr_establish((slot == 3) ? 23 : 16 + slot, USER_VEC, 0,
    160  1.1  leo 				(hw_ifun_t)iifun, (void *)slot);
    161  1.1  leo 	if (ihand != NULL) {
    162  1.1  leo 		iinfo_p->ipl   = level;
    163  1.1  leo 		iinfo_p->imask = (slot == 3) ? 0x80 : (0x01 << slot);
    164  1.1  leo 		iinfo_p->ifunc = ih_fun;
    165  1.1  leo 		iinfo_p->iarg  = ih_arg;
    166  1.1  leo 		iinfo_p->ihand = ihand;
    167  1.1  leo 
    168  1.1  leo 		/*
    169  1.1  leo 		 * Enable (unmask) the interrupt
    170  1.1  leo 		 */
    171  1.1  leo 		MFP2->mf_imrb |= iinfo_p->imask;
    172  1.1  leo 		MFP2->mf_ierb |= iinfo_p->imask;
    173  1.1  leo 		return(iinfo_p);
    174  1.1  leo 	}
    175  1.1  leo 	return NULL;
    176  1.1  leo }
    177  1.1  leo 
    178  1.1  leo void
    179  1.1  leo pci_intr_disestablish(pc, cookie)
    180  1.1  leo 	pci_chipset_tag_t pc;
    181  1.1  leo 	void *cookie;
    182  1.1  leo {
    183  1.1  leo 	pci_intr_info_t *iinfo_p = (pci_intr_info_t *)cookie;
    184  1.1  leo 
    185  1.1  leo 	if (iinfo->ipl < 0)
    186  1.1  leo 	    panic("pci_intr_disestablish: interrupt was not established\n");
    187  1.1  leo 
    188  1.1  leo 	MFP2->mf_imrb &= ~iinfo->imask;
    189  1.1  leo 	MFP2->mf_ierb &= ~iinfo->imask;
    190  1.1  leo 	(void) intr_disestablish(iinfo_p->ihand);
    191  1.1  leo 	iinfo_p->ipl = -1;
    192  1.1  leo }
    193