1 /* $NetBSD: shpcic_machdep.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 5 * Copyright (c) 1994 Charles M. Hannum. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Charles M. Hannum. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Machine-specific functions for PCI autoconfiguration. 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: shpcic_machdep.c,v 1.1 2006/09/01 21:26:18 uwe Exp $"); 39 40 #include <sys/types.h> 41 #include <sys/param.h> 42 #include <sys/time.h> 43 #include <sys/systm.h> 44 #include <sys/errno.h> 45 #include <sys/extent.h> 46 #include <sys/device.h> 47 48 #include <uvm/uvm_extern.h> 49 50 #include <dev/pci/pcivar.h> 51 #include <dev/pci/pcireg.h> 52 #include <dev/pci/pcidevs.h> 53 #include <dev/pci/pciconf.h> 54 55 #include <machine/bus.h> 56 #include <machine/intr.h> 57 #include <machine/pci_machdep.h> 58 59 bus_space_tag_t 60 shpcic_get_bus_io_tag(void) 61 { 62 extern struct _bus_space landisk_pci_bus_io; 63 64 return &landisk_pci_bus_io; 65 } 66 67 bus_space_tag_t 68 shpcic_get_bus_mem_tag(void) 69 { 70 extern struct _bus_space landisk_pci_bus_mem; 71 72 return &landisk_pci_bus_mem; 73 } 74 75 bus_dma_tag_t 76 shpcic_get_bus_dma_tag(void) 77 { 78 extern struct _bus_dma_tag landisk_bus_dma; 79 80 return &landisk_bus_dma; 81 } 82 83 void 84 landisk_pci_attach_hook(struct device *parent, struct device *self, 85 struct pcibus_attach_args *pba) 86 { 87 88 /* Nothing to do */ 89 } 90 91 int 92 landisk_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) 93 { 94 int pin = pa->pa_intrpin; 95 int line = pa->pa_intrline; 96 97 if (pin == 0) { 98 /* No IRQ used. */ 99 goto bad; 100 } 101 102 if (pin > 4) { 103 printf("pci_intr_map: bad interrupt pin %d\n", pin); 104 goto bad; 105 } 106 107 if (line == 0 || line == 255) { 108 printf("pci_intr_map: no mapping for pin %c\n", '@' + pin); 109 goto bad; 110 } 111 112 *ihp = line; 113 return 0; 114 115 bad: 116 *ihp = -1; 117 return 1; 118 } 119 120 const char * 121 landisk_pci_intr_string(void *v, pci_intr_handle_t ih) 122 { 123 static char irqstr[8]; /* 4 + 2 + NULL + sanity */ 124 125 if (ih == 0) 126 panic("pci_intr_string: bogus handle 0x%x", ih); 127 128 sprintf(irqstr, "irq %d", ih); 129 130 return (irqstr); 131 } 132 133 const struct evcnt * 134 landisk_pci_intr_evcnt(void *v, pci_intr_handle_t ih) 135 { 136 137 /* XXX for now, no evcnt parent reported */ 138 return (NULL); 139 } 140 141 void * 142 landisk_pci_intr_establish(void *v, pci_intr_handle_t ih, int level, 143 int (*ih_fun)(void *), void *ih_arg) 144 { 145 146 if (ih == 0) 147 panic("pci_intr_establish: bogus handle 0x%x", ih); 148 149 return extintr_establish(ih, level, ih_fun, ih_arg); 150 } 151 152 void 153 landisk_pci_intr_disestablish(void *v, void *cookie) 154 { 155 156 extintr_disestablish(cookie); 157 } 158 159 void 160 landisk_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz, 161 int *iline) 162 { 163 static const int irq[4] = { 5, 6, 7, 8 }; 164 165 *iline = -1; 166 if ((dev >= 0 && dev <= 3) && (pin >= 1 && pin <= 4)) { 167 *iline = irq[(dev + pin - 1) & 3]; 168 } 169 } 170 171 int 172 landisk_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id) 173 { 174 175 return (PCI_CONF_ALL & ~PCI_CONF_MAP_ROM); 176 } 177 178 /* 179 * shpcic bus space 180 */ 181 struct _bus_space landisk_pci_bus_io = 182 { 183 .bs_cookie = NULL, 184 185 .bs_map = shpcic_iomem_map, 186 .bs_unmap = shpcic_iomem_unmap, 187 .bs_subregion = shpcic_iomem_subregion, 188 189 .bs_alloc = shpcic_iomem_alloc, 190 .bs_free = shpcic_iomem_free, 191 192 .bs_r_1 = shpcic_io_read_1, 193 .bs_r_2 = shpcic_io_read_2, 194 .bs_r_4 = shpcic_io_read_4, 195 196 .bs_rm_1 = shpcic_io_read_multi_1, 197 .bs_rm_2 = shpcic_io_read_multi_2, 198 .bs_rm_4 = shpcic_io_read_multi_4, 199 200 .bs_rr_1 = shpcic_io_read_region_1, 201 .bs_rr_2 = shpcic_io_read_region_2, 202 .bs_rr_4 = shpcic_io_read_region_4, 203 204 .bs_w_1 = shpcic_io_write_1, 205 .bs_w_2 = shpcic_io_write_2, 206 .bs_w_4 = shpcic_io_write_4, 207 208 .bs_wm_1 = shpcic_io_write_multi_1, 209 .bs_wm_2 = shpcic_io_write_multi_2, 210 .bs_wm_4 = shpcic_io_write_multi_4, 211 212 .bs_wr_1 = shpcic_io_write_region_1, 213 .bs_wr_2 = shpcic_io_write_region_2, 214 .bs_wr_4 = shpcic_io_write_region_4, 215 216 .bs_sm_1 = shpcic_io_set_multi_1, 217 .bs_sm_2 = shpcic_io_set_multi_2, 218 .bs_sm_4 = shpcic_io_set_multi_4, 219 220 .bs_sr_1 = shpcic_io_set_region_1, 221 .bs_sr_2 = shpcic_io_set_region_2, 222 .bs_sr_4 = shpcic_io_set_region_4, 223 224 .bs_c_1 = shpcic_io_copy_region_1, 225 .bs_c_2 = shpcic_io_copy_region_2, 226 .bs_c_4 = shpcic_io_copy_region_4, 227 }; 228 229 struct _bus_space landisk_pci_bus_mem = 230 { 231 .bs_cookie = NULL, 232 233 .bs_map = shpcic_iomem_map, 234 .bs_unmap = shpcic_iomem_unmap, 235 .bs_subregion = shpcic_iomem_subregion, 236 237 .bs_alloc = shpcic_iomem_alloc, 238 .bs_free = shpcic_iomem_free, 239 240 .bs_r_1 = shpcic_mem_read_1, 241 .bs_r_2 = shpcic_mem_read_2, 242 .bs_r_4 = shpcic_mem_read_4, 243 244 .bs_rm_1 = shpcic_mem_read_multi_1, 245 .bs_rm_2 = shpcic_mem_read_multi_2, 246 .bs_rm_4 = shpcic_mem_read_multi_4, 247 248 .bs_rr_1 = shpcic_mem_read_region_1, 249 .bs_rr_2 = shpcic_mem_read_region_2, 250 .bs_rr_4 = shpcic_mem_read_region_4, 251 252 .bs_w_1 = shpcic_mem_write_1, 253 .bs_w_2 = shpcic_mem_write_2, 254 .bs_w_4 = shpcic_mem_write_4, 255 256 .bs_wm_1 = shpcic_mem_write_multi_1, 257 .bs_wm_2 = shpcic_mem_write_multi_2, 258 .bs_wm_4 = shpcic_mem_write_multi_4, 259 260 .bs_wr_1 = shpcic_mem_write_region_1, 261 .bs_wr_2 = shpcic_mem_write_region_2, 262 .bs_wr_4 = shpcic_mem_write_region_4, 263 264 .bs_sm_1 = shpcic_mem_set_multi_1, 265 .bs_sm_2 = shpcic_mem_set_multi_2, 266 .bs_sm_4 = shpcic_mem_set_multi_4, 267 268 .bs_sr_1 = shpcic_mem_set_region_1, 269 .bs_sr_2 = shpcic_mem_set_region_2, 270 .bs_sr_4 = shpcic_mem_set_region_4, 271 272 .bs_c_1 = shpcic_mem_copy_region_1, 273 .bs_c_2 = shpcic_mem_copy_region_2, 274 .bs_c_4 = shpcic_mem_copy_region_4, 275 }; 276