1*e5fbc36aSthorpej /* $NetBSD: plb.c,v 1.25 2023/12/20 15:29:06 thorpej Exp $ */
26bf1aaf8Ssimonb
36bf1aaf8Ssimonb /*
46bf1aaf8Ssimonb * Copyright 2001 Wasabi Systems, Inc.
56bf1aaf8Ssimonb * All rights reserved.
66bf1aaf8Ssimonb *
76bf1aaf8Ssimonb * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
86bf1aaf8Ssimonb *
96bf1aaf8Ssimonb * Redistribution and use in source and binary forms, with or without
106bf1aaf8Ssimonb * modification, are permitted provided that the following conditions
116bf1aaf8Ssimonb * are met:
126bf1aaf8Ssimonb * 1. Redistributions of source code must retain the above copyright
136bf1aaf8Ssimonb * notice, this list of conditions and the following disclaimer.
146bf1aaf8Ssimonb * 2. Redistributions in binary form must reproduce the above copyright
156bf1aaf8Ssimonb * notice, this list of conditions and the following disclaimer in the
166bf1aaf8Ssimonb * documentation and/or other materials provided with the distribution.
176bf1aaf8Ssimonb * 3. All advertising materials mentioning features or use of this software
186bf1aaf8Ssimonb * must display the following acknowledgement:
196bf1aaf8Ssimonb * This product includes software developed for the NetBSD Project by
206bf1aaf8Ssimonb * Wasabi Systems, Inc.
216bf1aaf8Ssimonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse
226bf1aaf8Ssimonb * or promote products derived from this software without specific prior
236bf1aaf8Ssimonb * written permission.
246bf1aaf8Ssimonb *
256bf1aaf8Ssimonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
266bf1aaf8Ssimonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
276bf1aaf8Ssimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
286bf1aaf8Ssimonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
296bf1aaf8Ssimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
306bf1aaf8Ssimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
316bf1aaf8Ssimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
326bf1aaf8Ssimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
336bf1aaf8Ssimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
346bf1aaf8Ssimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
356bf1aaf8Ssimonb * POSSIBILITY OF SUCH DAMAGE.
366bf1aaf8Ssimonb */
376bf1aaf8Ssimonb
386bf1aaf8Ssimonb /*
396bf1aaf8Ssimonb * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
406bf1aaf8Ssimonb *
416bf1aaf8Ssimonb * Redistribution and use in source and binary forms, with or without
426bf1aaf8Ssimonb * modification, are permitted provided that the following conditions
436bf1aaf8Ssimonb * are met:
446bf1aaf8Ssimonb * 1. Redistributions of source code must retain the above copyright
456bf1aaf8Ssimonb * notice, this list of conditions and the following disclaimer.
466bf1aaf8Ssimonb * 2. Redistributions in binary form must reproduce the above copyright
476bf1aaf8Ssimonb * notice, this list of conditions and the following disclaimer in the
486bf1aaf8Ssimonb * documentation and/or other materials provided with the distribution.
496bf1aaf8Ssimonb * 3. All advertising materials mentioning features or use of this software
506bf1aaf8Ssimonb * must display the following acknowledgement:
516bf1aaf8Ssimonb * This product includes software developed by Christopher G. Demetriou
526bf1aaf8Ssimonb * for the NetBSD Project.
536bf1aaf8Ssimonb * 4. The name of the author may not be used to endorse or promote products
546bf1aaf8Ssimonb * derived from this software without specific prior written permission
556bf1aaf8Ssimonb *
566bf1aaf8Ssimonb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
576bf1aaf8Ssimonb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
586bf1aaf8Ssimonb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
596bf1aaf8Ssimonb * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
606bf1aaf8Ssimonb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
616bf1aaf8Ssimonb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
626bf1aaf8Ssimonb * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
636bf1aaf8Ssimonb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
646bf1aaf8Ssimonb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
656bf1aaf8Ssimonb * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
666bf1aaf8Ssimonb */
676bf1aaf8Ssimonb
68ed517291Slukem #include <sys/cdefs.h>
69*e5fbc36aSthorpej __KERNEL_RCSID(0, "$NetBSD: plb.c,v 1.25 2023/12/20 15:29:06 thorpej Exp $");
70ed517291Slukem
712692e2e2Skiyohara #include "emac.h"
7216031f7dSrin #include "locators.h"
736bf1aaf8Ssimonb
741fd2c684Smatt #define _POWERPC_BUS_DMA_PRIVATE
751fd2c684Smatt
766bf1aaf8Ssimonb #include <sys/param.h>
776bf1aaf8Ssimonb #include <sys/systm.h>
786bf1aaf8Ssimonb #include <sys/device.h>
796bf1aaf8Ssimonb #include <sys/extent.h>
801fd2c684Smatt #include <sys/bus.h>
811fd2c684Smatt #include <sys/cpu.h>
826bf1aaf8Ssimonb
831fd2c684Smatt #include <powerpc/ibm4xx/cpu.h>
841fd2c684Smatt #include <powerpc/ibm4xx/spr.h>
852692e2e2Skiyohara #include <powerpc/ibm4xx/dev/malvar.h>
866bf1aaf8Ssimonb #include <powerpc/ibm4xx/dev/plbvar.h>
876bf1aaf8Ssimonb
886bf1aaf8Ssimonb /*
89d20841bbSwiz * The devices that attach to the processor local bus on the 405GP CPU.
906bf1aaf8Ssimonb */
916bf1aaf8Ssimonb const struct plb_dev plb_devs [] = {
922692e2e2Skiyohara /* IBM 405GP */
932692e2e2Skiyohara { IBM405GP, "cpu", },
942692e2e2Skiyohara { IBM405GP, "ecc", },
952692e2e2Skiyohara { IBM405GP, "opb", },
962692e2e2Skiyohara { IBM405GP, "pchb", },
972692e2e2Skiyohara
982692e2e2Skiyohara /* IBM 405GPr */
992692e2e2Skiyohara { IBM405GPR, "cpu", },
1002692e2e2Skiyohara { IBM405GPR, "ecc", },
1012692e2e2Skiyohara { IBM405GPR, "opb", },
1022692e2e2Skiyohara { IBM405GPR, "pchb", },
1037e4dfb0fSuebayasi { IBM405GPR, "exb", },
1042692e2e2Skiyohara
1052692e2e2Skiyohara /* AMCC 405EX / EXR */
1062692e2e2Skiyohara { AMCC405EX, "cpu", },
1072692e2e2Skiyohara { AMCC405EX, "ecc", },
1082692e2e2Skiyohara { AMCC405EX, "opb", },
109964b567aSkiyohara { AMCC405EX, "dwctwo", },
1102692e2e2Skiyohara
1112692e2e2Skiyohara { 0, NULL }
1126bf1aaf8Ssimonb };
1136bf1aaf8Ssimonb
114ec1797c1Smatt static int plb_match(device_t, cfdata_t, void *);
115ec1797c1Smatt static void plb_attach(device_t, device_t, void *);
1166bf1aaf8Ssimonb static int plb_print(void *, const char *);
1176bf1aaf8Ssimonb
118ec1797c1Smatt CFATTACH_DECL_NEW(plb, 0, plb_match, plb_attach, NULL, NULL);
1196bf1aaf8Ssimonb
1206bf1aaf8Ssimonb /*
121728102e6Sscw * "generic" DMA struct, nothing special.
122728102e6Sscw */
123728102e6Sscw struct powerpc_bus_dma_tag ibm4xx_default_bus_dma_tag = {
124728102e6Sscw 0, /* _bounce_thresh */
125728102e6Sscw _bus_dmamap_create,
126728102e6Sscw _bus_dmamap_destroy,
127728102e6Sscw _bus_dmamap_load,
128728102e6Sscw _bus_dmamap_load_mbuf,
129728102e6Sscw _bus_dmamap_load_uio,
130728102e6Sscw _bus_dmamap_load_raw,
131728102e6Sscw _bus_dmamap_unload,
132728102e6Sscw _bus_dmamap_sync,
133728102e6Sscw _bus_dmamem_alloc,
134728102e6Sscw _bus_dmamem_free,
135728102e6Sscw _bus_dmamem_map,
136728102e6Sscw _bus_dmamem_unmap,
137728102e6Sscw _bus_dmamem_mmap,
138728102e6Sscw _bus_dma_phys_to_bus_mem_generic,
139728102e6Sscw _bus_dma_bus_mem_to_phys_generic,
140728102e6Sscw };
141728102e6Sscw
142728102e6Sscw /*
1436bf1aaf8Ssimonb * Probe for the plb; always succeeds.
1446bf1aaf8Ssimonb */
1456bf1aaf8Ssimonb static int
plb_match(device_t parent,cfdata_t cf,void * aux)146ec1797c1Smatt plb_match(device_t parent, cfdata_t cf, void *aux)
1476bf1aaf8Ssimonb {
1486bf1aaf8Ssimonb
1492692e2e2Skiyohara return 1;
1506bf1aaf8Ssimonb }
1516bf1aaf8Ssimonb
1526bf1aaf8Ssimonb /*
1536bf1aaf8Ssimonb * Attach the processor local bus.
1546bf1aaf8Ssimonb */
1556bf1aaf8Ssimonb static void
plb_attach(device_t parent,device_t self,void * aux)156ec1797c1Smatt plb_attach(device_t parent, device_t self, void *aux)
1576bf1aaf8Ssimonb {
1586bf1aaf8Ssimonb struct plb_attach_args paa;
1596bf1aaf8Ssimonb struct plb_dev *local_plb_devs = aux;
1602692e2e2Skiyohara int pvr, i;
1616bf1aaf8Ssimonb
1622692e2e2Skiyohara aprint_naive("\n");
1632692e2e2Skiyohara aprint_normal("\n");
1642692e2e2Skiyohara
1652692e2e2Skiyohara pvr = mfpvr() >> 16;
1662692e2e2Skiyohara
1672692e2e2Skiyohara #if NEMAC > 0
1682692e2e2Skiyohara mal_attach(pvr);
1692692e2e2Skiyohara #endif
1706bf1aaf8Ssimonb
1716bf1aaf8Ssimonb for (i = 0; plb_devs[i].plb_name != NULL; i++) {
1722692e2e2Skiyohara if (plb_devs[i].plb_pvr != pvr)
1732692e2e2Skiyohara continue;
1742692e2e2Skiyohara
1756bf1aaf8Ssimonb paa.plb_name = plb_devs[i].plb_name;
176964b567aSkiyohara paa.plb_addr = PLBCF_ADDR_DEFAULT;
177f0302072Ssimonb paa.plb_dmat = &ibm4xx_default_bus_dma_tag;
1785b79fdfaSscw paa.plb_irq = PLBCF_IRQ_DEFAULT;
1796bf1aaf8Ssimonb
180c7fb772bSthorpej config_found(self, &paa, plb_print, CFARGS_NONE);
1816bf1aaf8Ssimonb }
1826bf1aaf8Ssimonb
1836bf1aaf8Ssimonb while (local_plb_devs && local_plb_devs->plb_name != NULL) {
1845d76b58fSkiyohara if (local_plb_devs->plb_pvr != pvr)
1852692e2e2Skiyohara continue;
1862692e2e2Skiyohara
1876bf1aaf8Ssimonb paa.plb_name = local_plb_devs->plb_name;
188964b567aSkiyohara paa.plb_addr = PLBCF_ADDR_DEFAULT;
189f0302072Ssimonb paa.plb_dmat = &ibm4xx_default_bus_dma_tag;
1905b79fdfaSscw paa.plb_irq = PLBCF_IRQ_DEFAULT;
1916bf1aaf8Ssimonb
192c7fb772bSthorpej config_found(self, &paa, plb_print, CFARGS_NONE);
1936bf1aaf8Ssimonb local_plb_devs++;
1946bf1aaf8Ssimonb }
1956bf1aaf8Ssimonb }
1966bf1aaf8Ssimonb
1976bf1aaf8Ssimonb static int
plb_print(void * aux,const char * pnp)1986bf1aaf8Ssimonb plb_print(void *aux, const char *pnp)
1996bf1aaf8Ssimonb {
2006bf1aaf8Ssimonb struct plb_attach_args *paa = aux;
2016bf1aaf8Ssimonb
2026bf1aaf8Ssimonb if (pnp)
20395fa2e14Sthorpej aprint_normal("%s at %s", paa->plb_name, pnp);
204964b567aSkiyohara if (paa->plb_addr != PLBCF_ADDR_DEFAULT)
205964b567aSkiyohara aprint_normal(" address 0x%08x", paa->plb_addr);
2065b79fdfaSscw if (paa->plb_irq != PLBCF_IRQ_DEFAULT)
20795fa2e14Sthorpej aprint_normal(" irq %d", paa->plb_irq);
2086bf1aaf8Ssimonb
2092692e2e2Skiyohara return UNCONF;
2106bf1aaf8Ssimonb }
211