1 /* $NetBSD: pci_machdep.c,v 1.7 1997/04/10 23:12:20 cgd Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Leo Weppelman. All rights reserved. 5 * Copyright (c) 1996, 1997 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 *, struct cfdata *, 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, cfp, auxp) 74 struct device *pdp; 75 struct cfdata *cfp; 76 void *auxp; 77 { 78 if(atari_realconfig == 0) 79 return (0); 80 if (strcmp((char *)auxp, "pcibus") || cfp->cf_unit != 0) 81 return(0); 82 return(machineid & ATARI_HADES ? 1 : 0); 83 } 84 85 void 86 pcibusattach(pdp, dp, auxp) 87 struct device *pdp, *dp; 88 void *auxp; 89 { 90 struct pcibus_attach_args pba; 91 92 pba.pba_busname = "pci"; 93 pba.pba_pc = NULL; 94 pba.pba_bus = 0; 95 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; 96 97 printf("\n"); 98 99 config_found(dp, &pba, pcibusprint); 100 } 101 102 int 103 pcibusprint(auxp, name) 104 void *auxp; 105 const char *name; 106 { 107 if(name == NULL) 108 return(UNCONF); 109 return(QUIET); 110 } 111 112 void 113 pci_attach_hook(parent, self, pba) 114 struct device *parent, *self; 115 struct pcibus_attach_args *pba; 116 { 117 } 118 119 /* 120 * Atari_init.c maps the config areas NBPG bytes apart.... 121 */ 122 static int pci_config_offset(tag) 123 pcitag_t tag; 124 { 125 int device; 126 127 device = (tag >> 11) & 0x1f; 128 return(device * NBPG); 129 } 130 131 int 132 pci_bus_maxdevs(pc, busno) 133 pci_chipset_tag_t pc; 134 int busno; 135 { 136 return (4); 137 } 138 139 pcitag_t 140 pci_make_tag(pc, bus, device, function) 141 pci_chipset_tag_t pc; 142 int bus, device, function; 143 { 144 return ((bus << 16) | (device << 11) | (function << 8)); 145 } 146 147 pcireg_t 148 pci_conf_read(pc, tag, reg) 149 pci_chipset_tag_t pc; 150 pcitag_t tag; 151 int reg; 152 { 153 u_long data; 154 155 data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg); 156 swapl(data); 157 return(data); 158 } 159 160 void 161 pci_conf_write(pc, tag, reg, data) 162 pci_chipset_tag_t pc; 163 pcitag_t tag; 164 int reg; 165 pcireg_t data; 166 { 167 swapl(data); 168 *((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg)) = data; 169 } 170 171 /* 172 * XXX: All pci_intr_*() functions are no-op's for now... 173 */ 174 int 175 pci_intr_map(pc, intrtag, pin, line, ihp) 176 pci_chipset_tag_t pc; 177 pcitag_t intrtag; 178 int pin, line; 179 pci_intr_handle_t *ihp; 180 { 181 /* XXXXXXXXX */ 182 *ihp = -1; 183 return 1; 184 } 185 186 const char * 187 pci_intr_string(pc, ih) 188 pci_chipset_tag_t pc; 189 pci_intr_handle_t ih; 190 { 191 static char irqstr[8]; /* 4 + 2 + NULL + sanity */ 192 193 if (ih == 0) 194 panic("pci_intr_string: bogus handle 0x%x\n", ih); 195 196 sprintf(irqstr, "irq %d", ih); 197 return (irqstr); 198 199 } 200 201 void * 202 pci_intr_establish(pc, ih, level, func, arg) 203 pci_chipset_tag_t pc; 204 pci_intr_handle_t ih; 205 int level, (*func) __P((void *)); 206 void *arg; 207 { 208 /* XXXX */ 209 return NULL; 210 } 211 212 void 213 pci_intr_disestablish(pc, cookie) 214 pci_chipset_tag_t pc; 215 void *cookie; 216 { 217 /* XXXX */ 218 } 219