Path: blob/main/sys/powerpc/mpc85xx/mpc85xx_cache.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2018 Justin Hibbits4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/bus.h>30#include <sys/kernel.h>31#include <sys/module.h>3233#include <machine/bus.h>3435#include <dev/ofw/ofw_bus.h>36#include <dev/ofw/ofw_bus_subr.h>3738/*39* From the P1022 manual, sequence for writing to L2CTL is:40* - mbar41* - isync42* - write43* - read44* - mbar45*/46#define L2_CTL 0x047#define L2CTL_L2E 0x8000000048#define L2CTL_L2I 0x4000000049struct mpc85xx_cache_softc {50struct resource *sc_mem;51};5253static struct ofw_compat_data compats[] = {54{"fsl,8540-l2-cache-controller", 1},55{"fsl,8541-l2-cache-controller", 1},56{"fsl,8544-l2-cache-controller", 1},57{"fsl,8548-l2-cache-controller", 1},58{"fsl,8555-l2-cache-controller", 1},59{"fsl,8568-l2-cache-controller", 1},60{"fsl,b4420-l2-cache-controller", 1},61{"fsl,b4860-l2-cache-controller", 1},62{"fsl,bsc9131-l2-cache-controller", 1},63{"fsl,bsc9132-l2-cache-controller", 1},64{"fsl,c293-l2-cache-controller", 1},65{"fsl,mpc8536-l2-cache-controller", 1},66{"fsl,mpc8540-l2-cache-controller", 1},67{"fsl,mpc8541-l2-cache-controller", 1},68{"fsl,mpc8544-l2-cache-controller", 1},69{"fsl,mpc8548-l2-cache-controller", 1},70{"fsl,mpc8555-l2-cache-controller", 1},71{"fsl,mpc8560-l2-cache-controller", 1},72{"fsl,mpc8568-l2-cache-controller", 1},73{"fsl,mpc8569-l2-cache-controller", 1},74{"fsl,mpc8572-l2-cache-controller", 1},75{"fsl,p1010-l2-cache-controller", 1},76{"fsl,p1011-l2-cache-controller", 1},77{"fsl,p1012-l2-cache-controller", 1},78{"fsl,p1013-l2-cache-controller", 1},79{"fsl,p1014-l2-cache-controller", 1},80{"fsl,p1015-l2-cache-controller", 1},81{"fsl,p1016-l2-cache-controller", 1},82{"fsl,p1020-l2-cache-controller", 1},83{"fsl,p1021-l2-cache-controller", 1},84{"fsl,p1022-l2-cache-controller", 1},85{"fsl,p1023-l2-cache-controller", 1},86{"fsl,p1024-l2-cache-controller", 1},87{"fsl,p1025-l2-cache-controller", 1},88{"fsl,p2010-l2-cache-controller", 1},89{"fsl,p2020-l2-cache-controller", 1},90{"fsl,t2080-l2-cache-controller", 1},91{"fsl,t4240-l2-cache-controller", 1},92{0, 0}93};9495static int96mpc85xx_cache_probe(device_t dev)97{9899if (ofw_bus_search_compatible(dev, compats)->ocd_str == NULL)100return (ENXIO);101102device_set_desc(dev, "MPC85xx L2 cache");103return (0);104}105106static int107mpc85xx_cache_attach(device_t dev)108{109struct mpc85xx_cache_softc *sc = device_get_softc(dev);110int rid;111int cache_line_size, cache_size;112113/* Map registers. */114rid = 0;115sc->sc_mem = bus_alloc_resource_any(dev,116SYS_RES_MEMORY, &rid, RF_ACTIVE);117if (sc->sc_mem == NULL)118return (ENOMEM);119120/* Enable cache and flash invalidate. */121__asm __volatile ("mbar; isync" ::: "memory");122bus_write_4(sc->sc_mem, L2_CTL, L2CTL_L2E | L2CTL_L2I);123bus_read_4(sc->sc_mem, L2_CTL);124__asm __volatile ("mbar" ::: "memory");125126cache_line_size = 0;127cache_size = 0;128OF_getencprop(ofw_bus_get_node(dev), "cache-size", &cache_size,129sizeof(cache_size));130OF_getencprop(ofw_bus_get_node(dev), "cache-line-size",131&cache_line_size, sizeof(cache_line_size));132133if (cache_line_size != 0 && cache_size != 0)134device_printf(dev,135"L2 cache size: %dKB, cache line size: %d bytes\n",136cache_size / 1024, cache_line_size);137138return (0);139}140141static device_method_t mpc85xx_cache_methods[] = {142/* device methods */143DEVMETHOD(device_probe, mpc85xx_cache_probe),144DEVMETHOD(device_attach, mpc85xx_cache_attach),145146DEVMETHOD_END147};148149static driver_t mpc85xx_cache_driver = {150"cache",151mpc85xx_cache_methods,152sizeof(struct mpc85xx_cache_softc),153};154155EARLY_DRIVER_MODULE(mpc85xx_cache, simplebus, mpc85xx_cache_driver, NULL, NULL,156BUS_PASS_RESOURCE + BUS_PASS_ORDER_MIDDLE);157158159