1 1.5 thorpej /* $NetBSD: pci_machdep.c,v 1.5 2023/12/20 00:40:42 thorpej Exp $ */ 2 1.1 rkujawa 3 1.1 rkujawa /*- 4 1.1 rkujawa * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 1.1 rkujawa * All rights reserved. 6 1.1 rkujawa * 7 1.1 rkujawa * This code is derived from software contributed to The NetBSD Foundation 8 1.1 rkujawa * by Radoslaw Kujawa. 9 1.1 rkujawa * 10 1.1 rkujawa * Redistribution and use in source and binary forms, with or without 11 1.1 rkujawa * modification, are permitted provided that the following conditions 12 1.1 rkujawa * are met: 13 1.1 rkujawa * 1. Redistributions of source code must retain the above copyright 14 1.1 rkujawa * notice, this list of conditions and the following disclaimer. 15 1.1 rkujawa * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 rkujawa * notice, this list of conditions and the following disclaimer in the 17 1.1 rkujawa * documentation and/or other materials provided with the distribution. 18 1.1 rkujawa * 19 1.1 rkujawa * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 rkujawa * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 rkujawa * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 rkujawa * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 rkujawa * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 rkujawa * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 rkujawa * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 rkujawa * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 rkujawa * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 rkujawa * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 rkujawa * POSSIBILITY OF SUCH DAMAGE. 30 1.1 rkujawa */ 31 1.1 rkujawa 32 1.1 rkujawa /* Amiga-specific PCI MD stuff. */ 33 1.1 rkujawa 34 1.1 rkujawa #include <sys/types.h> 35 1.1 rkujawa #include <sys/param.h> 36 1.1 rkujawa #include <sys/time.h> 37 1.1 rkujawa #include <sys/systm.h> 38 1.1 rkujawa #include <sys/errno.h> 39 1.1 rkujawa #include <sys/device.h> 40 1.1 rkujawa #include <sys/kmem.h> 41 1.1 rkujawa 42 1.1 rkujawa #include <uvm/uvm_extern.h> 43 1.1 rkujawa 44 1.1 rkujawa #include <machine/bus.h> 45 1.1 rkujawa #include <machine/cpu.h> 46 1.1 rkujawa 47 1.1 rkujawa #include <m68k/bus_dma.h> 48 1.1 rkujawa #include <amiga/dev/zbusvar.h> 49 1.1 rkujawa #include <amiga/pci/mppbreg.h> 50 1.1 rkujawa 51 1.1 rkujawa #include <dev/pci/pcivar.h> 52 1.1 rkujawa #include <dev/pci/pcireg.h> 53 1.1 rkujawa #include <dev/pci/pcidevs.h> 54 1.1 rkujawa #include <dev/pci/pciconf.h> 55 1.1 rkujawa 56 1.1 rkujawa pcitag_t 57 1.1 rkujawa amiga_pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) 58 1.1 rkujawa { 59 1.1 rkujawa return (bus << 16) | (device << 11) | (function << 8); 60 1.1 rkujawa } 61 1.1 rkujawa 62 1.1 rkujawa void 63 1.1 rkujawa amiga_pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, 64 1.1 rkujawa int *dp, int *fp) 65 1.1 rkujawa { 66 1.1 rkujawa if (bp != NULL) 67 1.1 rkujawa *bp = (tag >> 16) & 0xff; 68 1.1 rkujawa if (dp != NULL) 69 1.1 rkujawa *dp = (tag >> 11) & 0x1f; 70 1.1 rkujawa if (fp != NULL) 71 1.1 rkujawa *fp = (tag >> 8) & 0x07; 72 1.1 rkujawa } 73 1.1 rkujawa 74 1.1 rkujawa void * 75 1.1 rkujawa amiga_pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, 76 1.1 rkujawa int (*ih_fun)(void *), void *ih_arg) 77 1.1 rkujawa { 78 1.1 rkujawa struct isr* pci_isr; 79 1.1 rkujawa pci_isr = kmem_zalloc(sizeof(struct isr), KM_SLEEP); 80 1.1 rkujawa 81 1.1 rkujawa /* TODO: check for bogus handle */ 82 1.1 rkujawa 83 1.1 rkujawa pci_isr->isr_intr = ih_fun; 84 1.1 rkujawa pci_isr->isr_arg = ih_arg; 85 1.1 rkujawa pci_isr->isr_ipl = 2; /* XXX: true for all current drivers */ 86 1.1 rkujawa add_isr(pci_isr); 87 1.1 rkujawa return pci_isr; 88 1.1 rkujawa } 89 1.1 rkujawa 90 1.1 rkujawa void 91 1.1 rkujawa amiga_pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie) 92 1.1 rkujawa { 93 1.1 rkujawa remove_isr(cookie); 94 1.1 rkujawa kmem_free(cookie, sizeof(struct isr)); 95 1.1 rkujawa } 96 1.1 rkujawa 97 1.1 rkujawa const char * 98 1.3 christos amiga_pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, 99 1.3 christos size_t len) 100 1.1 rkujawa { 101 1.1 rkujawa 102 1.3 christos snprintf(buf, len, "INT%d", (int) ih); 103 1.3 christos return buf; 104 1.1 rkujawa } 105 1.1 rkujawa 106 1.1 rkujawa int 107 1.1 rkujawa amiga_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func, 108 1.1 rkujawa pcireg_t id) 109 1.1 rkujawa { 110 1.1 rkujawa return PCI_CONF_DEFAULT; 111 1.1 rkujawa } 112 1.1 rkujawa 113 1.1 rkujawa void 114 1.1 rkujawa amiga_pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int func, 115 1.1 rkujawa int swiz, int *iline) 116 1.1 rkujawa { 117 1.1 rkujawa } 118 1.1 rkujawa 119