pci_machdep_common.c revision 1.14
1/* $NetBSD: pci_machdep_common.c,v 1.14 2011/08/17 18:52:01 matt 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/* 33 * Generic PowerPC functions for dealing with a PCI bridge. For most cases, 34 * these functions will work just fine, however, some machines may need 35 * specialized code, so those ports are free to write thier own functions 36 * and call those instead where appropriate. 37 */ 38 39#include <sys/cdefs.h> 40__KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.14 2011/08/17 18:52:01 matt Exp $"); 41 42#define _POWERPC_BUS_DMA_PRIVATE 43 44#include <sys/param.h> 45#include <sys/bus.h> 46#include <sys/device.h> 47#include <sys/errno.h> 48#include <sys/extent.h> 49#include <sys/intr.h> 50#include <sys/malloc.h> 51#include <sys/systm.h> 52#include <sys/time.h> 53 54#include <uvm/uvm_extern.h> 55 56#include <dev/pci/pcivar.h> 57#include <dev/pci/pcireg.h> 58#include <dev/pci/pcidevs.h> 59#include <dev/pci/pciconf.h> 60#include <dev/pci/pciidereg.h> 61 62/* 63 * PCI doesn't have any special needs; just use the generic versions 64 * of these functions. 65 */ 66struct powerpc_bus_dma_tag pci_bus_dma_tag = { 67 0, /* _bounce_thresh */ 68 _bus_dmamap_create, 69 _bus_dmamap_destroy, 70 _bus_dmamap_load, 71 _bus_dmamap_load_mbuf, 72 _bus_dmamap_load_uio, 73 _bus_dmamap_load_raw, 74 _bus_dmamap_unload, 75 NULL, /* _dmamap_sync */ 76 _bus_dmamem_alloc, 77 _bus_dmamem_free, 78 _bus_dmamem_map, 79 _bus_dmamem_unmap, 80 _bus_dmamem_mmap, 81}; 82 83int 84genppc_pci_bus_maxdevs(void *v, int busno) 85{ 86 return 32; 87} 88 89const char * 90genppc_pci_intr_string(void *v, pci_intr_handle_t ih) 91{ 92 static char irqstr[8]; /* 4 + 2 + NULL + sanity */ 93 94#ifdef ICU_LEN 95 if (ih == 0 || ih >= ICU_LEN 96/* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */ 97#ifdef IRQ_SLAVE 98 || ih == IRQ_SLAVE 99#endif 100 ) 101 panic("pci_intr_string: bogus handle 0x%x", ih); 102#endif 103 104 sprintf(irqstr, "irq %d", ih); 105 return (irqstr); 106 107} 108 109const struct evcnt * 110genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih) 111{ 112 113 /* XXX for now, no evcnt parent reported */ 114 return NULL; 115} 116 117void * 118genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level, 119 int (*func)(void *), void *arg) 120{ 121 122#ifdef ICU_LEN 123 if (ih == 0 || ih >= ICU_LEN 124#ifdef IRQ_SLAVE 125 || ih == IRQ_SLAVE 126#endif 127 ) 128 panic("pci_intr_establish: bogus handle 0x%x", ih); 129#endif 130 131 return intr_establish(ih, IST_LEVEL, level, func, arg); 132} 133 134void 135genppc_pci_intr_disestablish(void *v, void *cookie) 136{ 137 138 intr_disestablish(cookie); 139} 140 141int 142genppc_pci_intr_setattr(void *v, pci_intr_handle_t *ihp, int attr, 143 uint64_t data) 144{ 145 146 return ENODEV; 147} 148 149void 150genppc_pci_conf_interrupt(void *v, int bus, int dev, int pin, 151 int swiz, int *iline) 152{ 153 /* do nothing */ 154} 155 156int 157genppc_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id) 158{ 159 return (PCI_CONF_DEFAULT); 160} 161 162int 163genppc_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 164{ 165 int pin = pa->pa_intrpin; 166 int line = pa->pa_intrline; 167 168#ifdef DEBUG 169 printf("%s: pin: %d, line: %d\n", __func__, pin, line); 170#endif 171 172 if (pin == 0) { 173 /* No IRQ used. */ 174 aprint_error("pci_intr_map: interrupt pin %d\n", pin); 175 goto bad; 176 } 177 178 if (pin > 4) { 179 aprint_error("pci_intr_map: bad interrupt pin %d\n", pin); 180 goto bad; 181 } 182 183 /* 184 * Section 6.2.4, `Miscellaneous Functions', says that 255 means 185 * `unknown' or `no connection' on a PC. We assume that a device with 186 * `no connection' either doesn't have an interrupt (in which case the 187 * pin number should be 0, and would have been noticed above), or 188 * wasn't configured by the BIOS (in which case we punt, since there's 189 * no real way we can know how the interrupt lines are mapped in the 190 * hardware). 191 * 192 * XXX 193 * Since IRQ 0 is only used by the clock, and we can't actually be sure 194 * that the BIOS did its job, we also recognize that as meaning that 195 * the BIOS has not configured the device. 196 */ 197 if (line == 0 || line == 255) { 198 aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin); 199 goto bad; 200#ifdef ICU_LEN 201 } else { 202 if (line >= ICU_LEN) { 203 aprint_error("pci_intr_map: bad interrupt line %d\n", line); 204 goto bad; 205 } 206#endif 207 } 208 209 *ihp = line; 210 return 0; 211 212bad: 213 *ihp = -1; 214 return 1; 215} 216 217int 218genppc_pci_msi_request(const struct pci_attach_args *pa, 219 pci_msi_handle_t *msihp, size_t nmsirq, int ipl, int capid) 220{ 221 return EOPNOTSUPP; 222} 223 224int 225genppc_pci_msi_type(void *v, pci_msi_handle_t msih) 226{ 227 panic("%s", __func__); 228} 229 230size_t 231genppc_pci_msi_available(void *v, pci_msi_handle_t msih) 232{ 233 panic("%s", __func__); 234} 235 236const char * 237genppc_pci_msi_string(void *v, pci_msi_handle_t msih, size_t msirq) 238{ 239 panic("%s", __func__); 240} 241 242const struct evcnt * 243genppc_pci_msi_evcnt(void *v, pci_msi_handle_t msih, size_t msirq) 244{ 245 panic("%s", __func__); 246} 247 248void * 249genppc_pci_msi_establish(void *v, pci_msi_handle_t msih, size_t msirq, 250 int ipl, int (*func)(void *), void *arg) 251{ 252 panic("%s", __func__); 253} 254 255void * 256genppc_pci_msix_establish(void *v, pci_msi_handle_t msih, size_t vec, 257 size_t msirq, int ipl, int (*func)(void *), void *arg) 258{ 259 panic("%s", __func__); 260} 261 262void 263genppc_pci_msi_disestablish(void *v, void *ih) 264{ 265 panic("%s", __func__); 266} 267 268void 269genppc_pci_msi_free(void *v, pci_msi_handle_t msih, size_t msirq) 270{ 271 panic("%s", __func__); 272} 273 274void 275genppc_pci_msi_release(void *v, pci_msi_handle_t msih) 276{ 277 panic("%s", __func__); 278} 279 280void 281genppc_pci_chipset_msi_init(pci_chipset_tag_t pc) 282{ 283 pc->pc_msi_request = genppc_pci_msi_request; 284 pc->pc_msi_type = genppc_pci_msi_type; 285 pc->pc_msi_available = genppc_pci_msi_available; 286 pc->pc_msi_evcnt = genppc_pci_msi_evcnt; 287 pc->pc_msi_string = genppc_pci_msi_string; 288 pc->pc_msi_establish = genppc_pci_msi_establish; 289 pc->pc_msix_establish = genppc_pci_msix_establish; 290 pc->pc_msi_disestablish = genppc_pci_msi_disestablish; 291 pc->pc_msi_free = genppc_pci_msi_free; 292 pc->pc_msi_release = genppc_pci_msi_release; 293} 294 295#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH 296#include <machine/isa_machdep.h> 297#include "isa.h" 298 299void *genppc_pciide_machdep_compat_intr_establish(device_t, 300 struct pci_attach_args *, int, int (*)(void *), void *); 301 302void * 303genppc_pciide_machdep_compat_intr_establish(device_t dev, 304 struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg) 305{ 306#if NISA > 0 307 int irq; 308 void *cookie; 309 310 irq = PCIIDE_COMPAT_IRQ(chan); 311 cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg); 312 if (cookie == NULL) 313 return (NULL); 314 aprint_normal_dev(dev, "%s channel interrupting at irq %d\n", 315 PCIIDE_CHANNEL_NAME(chan), irq); 316 return (cookie); 317#else 318 panic("pciide_machdep_compat_intr_establish() called"); 319#endif 320} 321#endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */ 322