Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.5.2.1
      1  1.5.2.1   thorpej /*	$NetBSD: pci_machdep.c,v 1.5.2.1 1997/01/30 05:37:01 thorpej 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 Christopher G. Demetriou.  All rights reserved.
      6      1.1       leo  * Copyright (c) 1994 Charles 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 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/time.h>
     37      1.1       leo #include <sys/systm.h>
     38      1.1       leo #include <sys/errno.h>
     39      1.1       leo #include <sys/device.h>
     40      1.1       leo 
     41      1.1       leo #include <vm/vm.h>
     42      1.1       leo #include <vm/vm_kern.h>
     43      1.1       leo 
     44      1.1       leo #include <dev/pci/pcivar.h>
     45      1.1       leo #include <dev/pci/pcireg.h>
     46      1.1       leo 
     47      1.1       leo #include <machine/cpu.h>
     48      1.1       leo #include <machine/iomap.h>
     49      1.1       leo #include <atari/atari/device.h>
     50      1.1       leo 
     51      1.1       leo int	pcibusprint __P((void *auxp, const char *));
     52      1.5       leo int	pcibusmatch __P((struct device *, struct cfdata *, void *));
     53      1.1       leo void	pcibusattach __P((struct device *, struct device *, void *));
     54      1.1       leo 
     55      1.1       leo static int pci_config_offset __P((pcitag_t));
     56      1.1       leo 
     57      1.1       leo /*
     58      1.1       leo  * Swap a long (abcd -> dcba). The pci-config area has the wrong
     59      1.1       leo  * endianess....
     60      1.1       leo  */
     61      1.1       leo #define swapl(x)	\
     62      1.1       leo 	{ asm volatile ("rorw #8,%0\nswap %0\nrorw #8,%0" : : "r" (x)); }
     63      1.1       leo 
     64      1.1       leo struct cfattach pcibus_ca = {
     65      1.1       leo 	sizeof(struct device), pcibusmatch, pcibusattach
     66      1.1       leo };
     67      1.1       leo 
     68      1.1       leo struct cfdriver pcibus_cd = {
     69      1.1       leo 	NULL, "pcibus", DV_DULL
     70      1.1       leo };
     71      1.1       leo 
     72      1.1       leo int
     73      1.5       leo pcibusmatch(pdp, cfp, auxp)
     74      1.1       leo struct device	*pdp;
     75      1.5       leo struct cfdata	*cfp;
     76      1.5       leo void		*auxp;
     77      1.1       leo {
     78      1.1       leo 	if(atari_realconfig == 0)
     79      1.1       leo 		return (0);
     80      1.1       leo 	if (strcmp((char *)auxp, "pcibus") || cfp->cf_unit != 0)
     81      1.1       leo 		return(0);
     82      1.1       leo 	return(machineid & ATARI_HADES ? 1 : 0);
     83      1.1       leo }
     84      1.1       leo 
     85      1.1       leo void
     86      1.1       leo pcibusattach(pdp, dp, auxp)
     87      1.1       leo struct device	*pdp, *dp;
     88      1.1       leo void		*auxp;
     89      1.1       leo {
     90      1.1       leo 	struct pcibus_attach_args	pba;
     91      1.1       leo 
     92      1.1       leo 	pba.pba_busname = "pci";
     93      1.4       leo 	pba.pba_pc      = NULL;
     94      1.1       leo 	pba.pba_bus     = 0;
     95  1.5.2.1   thorpej 
     96  1.5.2.1   thorpej 	printf("\n");
     97      1.1       leo 
     98      1.1       leo 	config_found(dp, &pba, pcibusprint);
     99      1.1       leo }
    100      1.1       leo 
    101      1.1       leo int
    102      1.1       leo pcibusprint(auxp, name)
    103      1.1       leo void		*auxp;
    104      1.1       leo const char	*name;
    105      1.1       leo {
    106      1.1       leo 	if(name == NULL)
    107      1.1       leo 		return(UNCONF);
    108      1.1       leo 	return(QUIET);
    109      1.1       leo }
    110      1.1       leo 
    111      1.1       leo void
    112      1.1       leo pci_attach_hook(parent, self, pba)
    113      1.1       leo 	struct device *parent, *self;
    114      1.1       leo 	struct pcibus_attach_args *pba;
    115      1.1       leo {
    116      1.1       leo }
    117      1.1       leo 
    118      1.1       leo /*
    119      1.1       leo  * Atari_init.c maps the config areas NBPG bytes apart....
    120      1.1       leo  */
    121      1.1       leo static int pci_config_offset(tag)
    122      1.1       leo pcitag_t	tag;
    123      1.1       leo {
    124      1.1       leo 	int	device;
    125      1.1       leo 
    126      1.1       leo 	device = (tag >> 11) & 0x1f;
    127      1.1       leo 	return(device * NBPG);
    128      1.1       leo }
    129      1.1       leo 
    130      1.1       leo int
    131      1.1       leo pci_bus_maxdevs(pc, busno)
    132      1.1       leo 	pci_chipset_tag_t pc;
    133      1.1       leo 	int busno;
    134      1.1       leo {
    135      1.1       leo 	return (4);
    136      1.1       leo }
    137      1.1       leo 
    138      1.1       leo pcitag_t
    139      1.1       leo pci_make_tag(pc, bus, device, function)
    140      1.1       leo 	pci_chipset_tag_t pc;
    141      1.1       leo 	int bus, device, function;
    142      1.1       leo {
    143      1.1       leo 	return ((bus << 16) | (device << 11) | (function << 8));
    144      1.1       leo }
    145      1.1       leo 
    146      1.1       leo pcireg_t
    147      1.1       leo pci_conf_read(pc, tag, reg)
    148      1.1       leo 	pci_chipset_tag_t pc;
    149      1.1       leo 	pcitag_t tag;
    150      1.1       leo 	int reg;
    151      1.1       leo {
    152      1.1       leo 	u_long	data;
    153      1.1       leo 
    154      1.1       leo 	data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
    155      1.1       leo 	swapl(data);
    156      1.1       leo 	return(data);
    157      1.1       leo }
    158      1.1       leo 
    159      1.1       leo void
    160      1.1       leo pci_conf_write(pc, tag, reg, data)
    161      1.1       leo 	pci_chipset_tag_t pc;
    162      1.1       leo 	pcitag_t tag;
    163      1.1       leo 	int reg;
    164      1.1       leo 	pcireg_t data;
    165      1.1       leo {
    166      1.1       leo 	swapl(data);
    167      1.1       leo 	*((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg)) = data;
    168      1.1       leo }
    169      1.1       leo 
    170      1.1       leo /*
    171      1.1       leo  * XXX: All pci_intr_*() functions are no-op's for now...
    172      1.1       leo  */
    173      1.1       leo int
    174      1.1       leo pci_intr_map(pc, intrtag, pin, line, ihp)
    175      1.1       leo 	pci_chipset_tag_t pc;
    176      1.1       leo 	pcitag_t intrtag;
    177      1.1       leo 	int pin, line;
    178      1.1       leo 	pci_intr_handle_t *ihp;
    179      1.1       leo {
    180      1.1       leo 	/* XXXXXXXXX */
    181      1.1       leo 	*ihp = -1;
    182      1.1       leo 	return 1;
    183      1.1       leo }
    184      1.1       leo 
    185      1.1       leo const char *
    186      1.1       leo pci_intr_string(pc, ih)
    187      1.1       leo 	pci_chipset_tag_t pc;
    188      1.1       leo 	pci_intr_handle_t ih;
    189      1.1       leo {
    190      1.1       leo 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    191      1.1       leo 
    192      1.1       leo 	if (ih == 0)
    193      1.1       leo 		panic("pci_intr_string: bogus handle 0x%x\n", ih);
    194      1.1       leo 
    195      1.3  christos 	sprintf(irqstr, "irq %d", ih);
    196      1.1       leo 	return (irqstr);
    197      1.1       leo 
    198      1.1       leo }
    199      1.1       leo 
    200      1.1       leo void *
    201      1.1       leo pci_intr_establish(pc, ih, level, func, arg)
    202      1.1       leo 	pci_chipset_tag_t pc;
    203      1.1       leo 	pci_intr_handle_t ih;
    204      1.1       leo 	int level, (*func) __P((void *));
    205      1.1       leo 	void *arg;
    206      1.1       leo {
    207      1.1       leo 	/* XXXX */
    208      1.1       leo 	return NULL;
    209      1.1       leo }
    210      1.1       leo 
    211      1.1       leo void
    212      1.1       leo pci_intr_disestablish(pc, cookie)
    213      1.1       leo 	pci_chipset_tag_t pc;
    214      1.1       leo 	void *cookie;
    215      1.1       leo {
    216      1.1       leo 	/* XXXX */
    217      1.1       leo }
    218