Path: blob/main/sys/arm/annapurna/alpine/alpine_ccu.c
39536 views
/*-1* Copyright (c) 2015,2016 Annapurna Labs Ltd. and affiliates2* All rights reserved.3*4* Developed by Semihalf.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/conf.h>31#include <sys/rman.h>32#include <sys/kernel.h>33#include <sys/module.h>34#include <sys/resource.h>35#include <sys/systm.h>3637#include <machine/bus.h>38#include <dev/ofw/ofw_bus_subr.h>3940#define AL_CCU_SNOOP_CONTROL_IOFAB_0_OFFSET 0x400041#define AL_CCU_SNOOP_CONTROL_IOFAB_1_OFFSET 0x500042#define AL_CCU_SPECULATION_CONTROL_OFFSET 0x44344static struct resource_spec al_ccu_spec[] = {45{ SYS_RES_MEMORY, 0, RF_ACTIVE },46{ -1, 0 }47};4849struct al_ccu_softc {50struct resource *res;51};5253static int al_ccu_probe(device_t dev);54static int al_ccu_attach(device_t dev);55static int al_ccu_detach(device_t dev);5657static device_method_t al_ccu_methods[] = {58DEVMETHOD(device_probe, al_ccu_probe),59DEVMETHOD(device_attach, al_ccu_attach),60DEVMETHOD(device_detach, al_ccu_detach),61{ 0, 0 }62};6364static driver_t al_ccu_driver = {65"ccu",66al_ccu_methods,67sizeof(struct al_ccu_softc)68};6970EARLY_DRIVER_MODULE(al_ccu, simplebus, al_ccu_driver, 0, 0,71BUS_PASS_CPU + BUS_PASS_ORDER_MIDDLE);72EARLY_DRIVER_MODULE(al_ccu, ofwbus, al_ccu_driver, 0, 0,73BUS_PASS_CPU + BUS_PASS_ORDER_MIDDLE);7475static int76al_ccu_probe(device_t dev)77{7879if (!ofw_bus_status_okay(dev))80return (ENXIO);8182if (!ofw_bus_is_compatible(dev, "annapurna-labs,al-ccu"))83return (ENXIO);8485device_set_desc(dev, "Alpine CCU");8687return (BUS_PROBE_DEFAULT);88}8990static int91al_ccu_attach(device_t dev)92{93struct al_ccu_softc *sc;94int err;9596sc = device_get_softc(dev);9798err = bus_alloc_resources(dev, al_ccu_spec, &sc->res);99if (err != 0) {100device_printf(dev, "could not allocate resources\n");101return (err);102}103104/* Enable cache snoop */105bus_write_4(sc->res, AL_CCU_SNOOP_CONTROL_IOFAB_0_OFFSET, 1);106bus_write_4(sc->res, AL_CCU_SNOOP_CONTROL_IOFAB_1_OFFSET, 1);107108/* Disable speculative fetches from masters */109bus_write_4(sc->res, AL_CCU_SPECULATION_CONTROL_OFFSET, 7);110111return (0);112}113114static int115al_ccu_detach(device_t dev)116{117struct al_ccu_softc *sc;118119sc = device_get_softc(dev);120121bus_release_resources(dev, al_ccu_spec, &sc->res);122123return (0);124}125126127