Path: blob/main/sys/arm/annapurna/alpine/alpine_nb_service.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_NB_ACF_MISC_OFFSET 0xD041#define AL_NB_ACF_MISC_READ_BYPASS (1 << 30)4243static struct resource_spec nb_service_spec[] = {44{ SYS_RES_MEMORY, 0, RF_ACTIVE },45{ -1, 0 }46};4748struct nb_service_softc {49struct resource *res;50};5152static int nb_service_probe(device_t dev);53static int nb_service_attach(device_t dev);54static int nb_service_detach(device_t dev);5556static device_method_t nb_service_methods[] = {57DEVMETHOD(device_probe, nb_service_probe),58DEVMETHOD(device_attach, nb_service_attach),59DEVMETHOD(device_detach, nb_service_detach),60{ 0, 0 }61};6263static driver_t nb_service_driver = {64"nb_service",65nb_service_methods,66sizeof(struct nb_service_softc)67};6869EARLY_DRIVER_MODULE(nb_service, simplebus, nb_service_driver, 0, 0,70BUS_PASS_CPU + BUS_PASS_ORDER_MIDDLE);71EARLY_DRIVER_MODULE(nb_service, ofwbus, nb_service_driver, 0, 0,72BUS_PASS_CPU + BUS_PASS_ORDER_MIDDLE);7374static int75nb_service_probe(device_t dev)76{7778if (!ofw_bus_status_okay(dev))79return (ENXIO);8081if (!ofw_bus_is_compatible(dev, "annapurna-labs,al-nb-service"))82return (ENXIO);8384device_set_desc(dev, "Alpine North Bridge Service");8586return (BUS_PROBE_DEFAULT);87}8889static int90nb_service_attach(device_t dev)91{92struct nb_service_softc *sc;93uint32_t val;94int err;9596sc = device_get_softc(dev);9798err = bus_alloc_resources(dev, nb_service_spec, &sc->res);99if (err != 0) {100device_printf(dev, "could not allocate resources\n");101return (err);102}103104/* Do not allow reads to bypass writes to different addresses */105val = bus_read_4(sc->res, AL_NB_ACF_MISC_OFFSET);106val &= ~AL_NB_ACF_MISC_READ_BYPASS;107bus_write_4(sc->res, AL_NB_ACF_MISC_OFFSET, val);108109return (0);110}111112static int113nb_service_detach(device_t dev)114{115struct nb_service_softc *sc;116117sc = device_get_softc(dev);118119bus_release_resources(dev, nb_service_spec, &sc->res);120121return (0);122}123124125