Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.4
      1 /*	$NetBSD: pci_machdep.c,v 1.4 1996/11/08 14:18:20 leo Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Leo Weppelman.  All rights reserved.
      5  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      6  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by Charles Hannum.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/types.h>
     35 #include <sys/param.h>
     36 #include <sys/time.h>
     37 #include <sys/systm.h>
     38 #include <sys/errno.h>
     39 #include <sys/device.h>
     40 
     41 #include <vm/vm.h>
     42 #include <vm/vm_kern.h>
     43 
     44 #include <dev/pci/pcivar.h>
     45 #include <dev/pci/pcireg.h>
     46 
     47 #include <machine/cpu.h>
     48 #include <machine/iomap.h>
     49 #include <atari/atari/device.h>
     50 
     51 int	pcibusprint __P((void *auxp, const char *));
     52 int	pcibusmatch __P((struct device *, void *, void *));
     53 void	pcibusattach __P((struct device *, struct device *, void *));
     54 
     55 static int pci_config_offset __P((pcitag_t));
     56 
     57 /*
     58  * Swap a long (abcd -> dcba). The pci-config area has the wrong
     59  * endianess....
     60  */
     61 #define swapl(x)	\
     62 	{ asm volatile ("rorw #8,%0\nswap %0\nrorw #8,%0" : : "r" (x)); }
     63 
     64 struct cfattach pcibus_ca = {
     65 	sizeof(struct device), pcibusmatch, pcibusattach
     66 };
     67 
     68 struct cfdriver pcibus_cd = {
     69 	NULL, "pcibus", DV_DULL
     70 };
     71 
     72 int
     73 pcibusmatch(pdp, match, auxp)
     74 struct device	*pdp;
     75 void		*match, *auxp;
     76 {
     77 	struct cfdata *cfp = match;
     78 
     79 	if(atari_realconfig == 0)
     80 		return (0);
     81 	if (strcmp((char *)auxp, "pcibus") || cfp->cf_unit != 0)
     82 		return(0);
     83 	return(machineid & ATARI_HADES ? 1 : 0);
     84 }
     85 
     86 void
     87 pcibusattach(pdp, dp, auxp)
     88 struct device	*pdp, *dp;
     89 void		*auxp;
     90 {
     91 	struct pcibus_attach_args	pba;
     92 
     93 	pba.pba_busname = "pci";
     94 	pba.pba_pc      = NULL;
     95 	pba.pba_bus     = 0;
     96 
     97 	config_found(dp, &pba, pcibusprint);
     98 }
     99 
    100 int
    101 pcibusprint(auxp, name)
    102 void		*auxp;
    103 const char	*name;
    104 {
    105 	if(name == NULL)
    106 		return(UNCONF);
    107 	return(QUIET);
    108 }
    109 
    110 void
    111 pci_attach_hook(parent, self, pba)
    112 	struct device *parent, *self;
    113 	struct pcibus_attach_args *pba;
    114 {
    115 }
    116 
    117 /*
    118  * Atari_init.c maps the config areas NBPG bytes apart....
    119  */
    120 static int pci_config_offset(tag)
    121 pcitag_t	tag;
    122 {
    123 	int	device;
    124 
    125 	device = (tag >> 11) & 0x1f;
    126 	return(device * NBPG);
    127 }
    128 
    129 int
    130 pci_bus_maxdevs(pc, busno)
    131 	pci_chipset_tag_t pc;
    132 	int busno;
    133 {
    134 	return (4);
    135 }
    136 
    137 pcitag_t
    138 pci_make_tag(pc, bus, device, function)
    139 	pci_chipset_tag_t pc;
    140 	int bus, device, function;
    141 {
    142 	return ((bus << 16) | (device << 11) | (function << 8));
    143 }
    144 
    145 pcireg_t
    146 pci_conf_read(pc, tag, reg)
    147 	pci_chipset_tag_t pc;
    148 	pcitag_t tag;
    149 	int reg;
    150 {
    151 	u_long	data;
    152 
    153 	data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
    154 	swapl(data);
    155 	return(data);
    156 }
    157 
    158 void
    159 pci_conf_write(pc, tag, reg, data)
    160 	pci_chipset_tag_t pc;
    161 	pcitag_t tag;
    162 	int reg;
    163 	pcireg_t data;
    164 {
    165 	swapl(data);
    166 	*((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg)) = data;
    167 }
    168 
    169 /*
    170  * XXX: All pci_intr_*() functions are no-op's for now...
    171  */
    172 int
    173 pci_intr_map(pc, intrtag, pin, line, ihp)
    174 	pci_chipset_tag_t pc;
    175 	pcitag_t intrtag;
    176 	int pin, line;
    177 	pci_intr_handle_t *ihp;
    178 {
    179 	/* XXXXXXXXX */
    180 	*ihp = -1;
    181 	return 1;
    182 }
    183 
    184 const char *
    185 pci_intr_string(pc, ih)
    186 	pci_chipset_tag_t pc;
    187 	pci_intr_handle_t ih;
    188 {
    189 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    190 
    191 	if (ih == 0)
    192 		panic("pci_intr_string: bogus handle 0x%x\n", ih);
    193 
    194 	sprintf(irqstr, "irq %d", ih);
    195 	return (irqstr);
    196 
    197 }
    198 
    199 void *
    200 pci_intr_establish(pc, ih, level, func, arg)
    201 	pci_chipset_tag_t pc;
    202 	pci_intr_handle_t ih;
    203 	int level, (*func) __P((void *));
    204 	void *arg;
    205 {
    206 	/* XXXX */
    207 	return NULL;
    208 }
    209 
    210 void
    211 pci_intr_disestablish(pc, cookie)
    212 	pci_chipset_tag_t pc;
    213 	void *cookie;
    214 {
    215 	/* XXXX */
    216 }
    217