1 /* $NetBSD: plb.c,v 1.28 2026/09/28 20:41:01 rkujawa Exp $ */ 2 3 /* 4 * Copyright 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /* 39 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the above copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. All advertising materials mentioning features or use of this software 50 * must display the following acknowledgement: 51 * This product includes software developed by Christopher G. Demetriou 52 * for the NetBSD Project. 53 * 4. The name of the author may not be used to endorse or promote products 54 * derived from this software without specific prior written permission 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 65 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 */ 67 68 #include <sys/cdefs.h> 69 __KERNEL_RCSID(0, "$NetBSD: plb.c,v 1.28 2026/09/28 20:41:01 rkujawa Exp $"); 70 71 #include "emac.h" 72 #include "locators.h" 73 74 #define _POWERPC_BUS_DMA_PRIVATE 75 76 #include <sys/param.h> 77 #include <sys/systm.h> 78 #include <sys/device.h> 79 #include <sys/extent.h> 80 #include <sys/bus.h> 81 #include <sys/cpu.h> 82 83 #include <powerpc/ibm4xx/cpu.h> 84 #include <powerpc/ibm4xx/spr.h> 85 #include <powerpc/ibm4xx/dev/malvar.h> 86 #include <powerpc/ibm4xx/dev/plbvar.h> 87 88 /* 89 * The devices that attach to the processor local bus on the 405GP CPU. 90 */ 91 const struct plb_dev plb_devs [] = { 92 /* IBM 405GP */ 93 { IBM405GP, "cpu", }, 94 { IBM405GP, "ecc", }, 95 { IBM405GP, "opb", }, 96 { IBM405GP, "pchb", }, 97 98 /* IBM 405GPr */ 99 { IBM405GPR, "cpu", }, 100 { IBM405GPR, "ecc", }, 101 { IBM405GPR, "opb", }, 102 { IBM405GPR, "pchb", }, 103 { IBM405GPR, "exb", }, 104 105 /* AMCC 405EX / EXR */ 106 { AMCC405EX, "cpu", }, 107 { AMCC405EX, "ecc", }, 108 { AMCC405EX, "opb", }, 109 { AMCC405EX, "dwctwo", }, 110 111 /* AMCC 460EX */ 112 { AMCC460EX, "cpu", }, 113 { AMCC460EX, "opb", }, 114 { AMCC460EX, "ebc", }, 115 { AMCC460EX, "pcix", }, 116 { AMCC460EX, "pciex", }, /* PCIE0 */ 117 { AMCC460EX, "pciex", }, /* PCIE1 */ 118 { AMCC460EX, "ohci", }, 119 { AMCC460EX, "ehci", }, 120 { AMCC460EX, "dwcsata", }, 121 122 { 0, NULL } 123 }; 124 125 static int plb_match(device_t, cfdata_t, void *); 126 static void plb_attach(device_t, device_t, void *); 127 static int plb_print(void *, const char *); 128 129 CFATTACH_DECL_NEW(plb, 0, plb_match, plb_attach, NULL, NULL); 130 131 /* 132 * "generic" DMA struct, nothing special. 133 */ 134 struct powerpc_bus_dma_tag ibm4xx_default_bus_dma_tag = { 135 0, 0, /* _bounce_thresh_min/max */ 136 _bus_dmamap_create, 137 _bus_dmamap_destroy, 138 _bus_dmamap_load, 139 _bus_dmamap_load_mbuf, 140 _bus_dmamap_load_uio, 141 _bus_dmamap_load_raw, 142 _bus_dmamap_unload, 143 _bus_dmamap_sync, 144 _bus_dmamem_alloc, 145 _bus_dmamem_free, 146 _bus_dmamem_map, 147 _bus_dmamem_unmap, 148 _bus_dmamem_mmap, 149 _bus_dma_phys_to_bus_mem_generic, 150 _bus_dma_bus_mem_to_phys_generic, 151 }; 152 153 /* 154 * Probe for the plb; always succeeds. 155 */ 156 static int 157 plb_match(device_t parent, cfdata_t cf, void *aux) 158 { 159 160 return 1; 161 } 162 163 /* 164 * Attach the processor local bus. 165 */ 166 static void 167 plb_attach(device_t parent, device_t self, void *aux) 168 { 169 struct plb_attach_args paa; 170 struct plb_dev *local_plb_devs = aux; 171 int pvr, i; 172 173 aprint_naive("\n"); 174 aprint_normal("\n"); 175 176 pvr = mfpvr() >> 16; 177 178 #if NEMAC > 0 179 mal_attach(pvr); 180 #endif 181 182 for (i = 0; plb_devs[i].plb_name != NULL; i++) { 183 if (plb_devs[i].plb_pvr != pvr) 184 continue; 185 186 paa.plb_name = plb_devs[i].plb_name; 187 paa.plb_addr = PLBCF_ADDR_DEFAULT; 188 paa.plb_dmat = &ibm4xx_default_bus_dma_tag; 189 paa.plb_irq = PLBCF_IRQ_DEFAULT; 190 191 config_found(self, &paa, plb_print, CFARGS_NONE); 192 } 193 194 while (local_plb_devs && local_plb_devs->plb_name != NULL) { 195 if (local_plb_devs->plb_pvr != pvr) 196 continue; 197 198 paa.plb_name = local_plb_devs->plb_name; 199 paa.plb_addr = PLBCF_ADDR_DEFAULT; 200 paa.plb_dmat = &ibm4xx_default_bus_dma_tag; 201 paa.plb_irq = PLBCF_IRQ_DEFAULT; 202 203 config_found(self, &paa, plb_print, CFARGS_NONE); 204 local_plb_devs++; 205 } 206 } 207 208 static int 209 plb_print(void *aux, const char *pnp) 210 { 211 struct plb_attach_args *paa = aux; 212 213 if (pnp) 214 aprint_normal("%s at %s", paa->plb_name, pnp); 215 if (paa->plb_addr != PLBCF_ADDR_DEFAULT) 216 aprint_normal(" address 0x%08x", paa->plb_addr); 217 if (paa->plb_irq != PLBCF_IRQ_DEFAULT) 218 aprint_normal(" irq %d", paa->plb_irq); 219 220 return UNCONF; 221 } 222