1 /* $NetBSD: pci_machdep_common.c,v 1.3 2007/12/15 00:39:23 perry Exp $ */ 2 3 /*- 4 * Copyright (c) 2007 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Tim Rightnour 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Generic PowerPC functions for dealing with a PCI bridge. For most cases, 41 * these functions will work just fine, however, some machines may need 42 * specialized code, so those ports are free to write thier own functions 43 * and call those instead where appropriate. 44 */ 45 46 #include <sys/cdefs.h> 47 __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.3 2007/12/15 00:39:23 perry Exp $"); 48 49 #include <sys/types.h> 50 #include <sys/param.h> 51 #include <sys/time.h> 52 #include <sys/systm.h> 53 #include <sys/errno.h> 54 #include <sys/extent.h> 55 #include <sys/device.h> 56 #include <sys/malloc.h> 57 58 #include <uvm/uvm_extern.h> 59 60 #define _POWERPC_BUS_DMA_PRIVATE 61 #include <machine/bus.h> 62 #include <machine/intr.h> 63 64 #include <dev/pci/pcivar.h> 65 #include <dev/pci/pcireg.h> 66 #include <dev/pci/pcidevs.h> 67 #include <dev/pci/pciconf.h> 68 69 /* 70 * PCI doesn't have any special needs; just use the generic versions 71 * of these functions. 72 */ 73 /* 74 * XXX for now macppc needs its own pci_bus_dma_tag 75 * this will go away once we use the common bus_space stuff 76 */ 77 #ifndef macppc 78 struct powerpc_bus_dma_tag pci_bus_dma_tag = { 79 0, /* _bounce_thresh */ 80 _bus_dmamap_create, 81 _bus_dmamap_destroy, 82 _bus_dmamap_load, 83 _bus_dmamap_load_mbuf, 84 _bus_dmamap_load_uio, 85 _bus_dmamap_load_raw, 86 _bus_dmamap_unload, 87 NULL, /* _dmamap_sync */ 88 _bus_dmamem_alloc, 89 _bus_dmamem_free, 90 _bus_dmamem_map, 91 _bus_dmamem_unmap, 92 _bus_dmamem_mmap, 93 }; 94 #endif 95 int 96 genppc_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 97 { 98 return 32; 99 } 100 101 const char * 102 genppc_pci_intr_string(void *v, pci_intr_handle_t ih) 103 { 104 static char irqstr[8]; /* 4 + 2 + NULL + sanity */ 105 106 if (ih == 0 || ih >= ICU_LEN 107 /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */ 108 #ifdef IRQ_SLAVE 109 || ih == IRQ_SLAVE 110 #endif 111 ) 112 panic("pci_intr_string: bogus handle 0x%x", ih); 113 114 sprintf(irqstr, "irq %d", ih); 115 return (irqstr); 116 117 } 118 119 const struct evcnt * 120 genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih) 121 { 122 123 /* XXX for now, no evcnt parent reported */ 124 return NULL; 125 } 126 127 void * 128 genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level, 129 int (*func)(void *), void *arg) 130 { 131 132 if (ih == 0 || ih >= ICU_LEN 133 #ifdef IRQ_SLAVE 134 || ih == IRQ_SLAVE 135 #endif 136 ) 137 panic("pci_intr_establish: bogus handle 0x%x", ih); 138 139 return intr_establish(ih, IST_LEVEL, level, func, arg); 140 } 141 142 void 143 genppc_pci_intr_disestablish(void *v, void *cookie) 144 { 145 146 intr_disestablish(cookie); 147 } 148 149 void 150 genppc_pci_conf_interrupt(pci_chipset_tag_t pct, int bus, int dev, int pin, 151 int swiz, int *iline) 152 { 153 /* do nothing */ 154 } 155 156 int 157 genppc_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func, 158 pcireg_t id) 159 { 160 return (PCI_CONF_DEFAULT); 161 } 162 163 int 164 genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) 165 { 166 int pin = pa->pa_intrpin; 167 int line = pa->pa_intrline; 168 169 #if DEBUG 170 printf("%s: pin: %d, line: %d\n", __func__, pin, line); 171 #endif 172 173 if (pin == 0) { 174 /* No IRQ used. */ 175 aprint_error("pci_intr_map: interrupt pin %d\n", pin); 176 goto bad; 177 } 178 179 if (pin > 4) { 180 aprint_error("pci_intr_map: bad interrupt pin %d\n", pin); 181 goto bad; 182 } 183 184 /* 185 * Section 6.2.4, `Miscellaneous Functions', says that 255 means 186 * `unknown' or `no connection' on a PC. We assume that a device with 187 * `no connection' either doesn't have an interrupt (in which case the 188 * pin number should be 0, and would have been noticed above), or 189 * wasn't configured by the BIOS (in which case we punt, since there's 190 * no real way we can know how the interrupt lines are mapped in the 191 * hardware). 192 * 193 * XXX 194 * Since IRQ 0 is only used by the clock, and we can't actually be sure 195 * that the BIOS did its job, we also recognize that as meaning that 196 * the BIOS has not configured the device. 197 */ 198 if (line == 0 || line == 255) { 199 aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin); 200 goto bad; 201 } else { 202 if (line >= ICU_LEN) { 203 aprint_error("pci_intr_map: bad interrupt line %d\n", line); 204 goto bad; 205 } 206 } 207 208 *ihp = line; 209 return 0; 210 211 bad: 212 *ihp = -1; 213 return 1; 214 } 215 216