bcm_mipscore.c revision 301698
1/*- 2 * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 */ 29 30#include <sys/cdefs.h> 31__FBSDID("$FreeBSD: head/sys/mips/broadcom/bcm_mipscore.c 301698 2016-06-08 21:38:51Z landonf $"); 32 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/bus.h> 36#include <sys/module.h> 37#include <sys/systm.h> 38#include <sys/errno.h> 39#include <sys/rman.h> 40#include <sys/stddef.h> 41 42#include <machine/bus.h> 43#include <machine/resource.h> 44 45#include <dev/bhnd/bhnd.h> 46#include <dev/bhnd/bhndvar.h> 47#include <dev/bhnd/bhnd_ids.h> 48 49#include "bcm_mipscore.h" 50 51static const struct resource_spec mipscore_rspec[MIPSCORE_MAX_RSPEC] = { 52 { SYS_RES_MEMORY, 0, RF_ACTIVE }, 53 { -1, -1, 0 } 54}; 55 56#define MIPSCORE_DEV(_vendor, _core) \ 57 BHND_DEVICE(_vendor, _core, NULL, NULL, BHND_DF_SOC) 58 59struct bhnd_device mipscore_match[] = { 60 MIPSCORE_DEV(BCM, MIPS), 61 MIPSCORE_DEV(BCM, MIPS33), 62 MIPSCORE_DEV(MIPS, MIPS74K), 63 BHND_DEVICE_END 64}; 65 66static int 67mipscore_probe(device_t dev) 68{ 69 const struct bhnd_device *id; 70 71 id = bhnd_device_lookup(dev, mipscore_match, sizeof(mipscore_match[0])); 72 if (id == NULL) 73 return (ENXIO); 74 75 bhnd_set_default_core_desc(dev); 76 return (BUS_PROBE_DEFAULT); 77} 78 79static int 80mipscore_attach(device_t dev) 81{ 82 struct mipscore_softc *sc; 83 struct resource *res; 84 uint32_t intmask; 85 uint16_t devid; 86 int error; 87 88 sc = device_get_softc(dev); 89 devid = bhnd_get_device(dev); 90 91 sc->devid = devid; 92 sc->dev = dev; 93 94 /* Allocate bus resources */ 95 memcpy(sc->rspec, mipscore_rspec, sizeof(sc->rspec)); 96 error = bhnd_alloc_resources(dev, sc->rspec, sc->res); 97 if (error) 98 return (error); 99 100 res = sc->res[0]->res; 101 if (res == NULL) 102 return (ENXIO); 103 104 if (devid == BHND_COREID_MIPS74K) { 105 intmask = (1 << 31); 106 /* Use intmask5 register to route the timer interrupt */ 107 bus_write_4(res, offsetof(struct mipscore_regs, intmask[5]), 108 intmask); 109 } 110 111 return (0); 112} 113 114static device_method_t mipscore_methods[] = { 115 DEVMETHOD(device_probe, mipscore_probe), 116 DEVMETHOD(device_attach, mipscore_attach), 117 DEVMETHOD_END 118}; 119 120devclass_t bhnd_mipscore_devclass; 121 122DEFINE_CLASS_0(bhnd_mips, mipscore_driver, mipscore_methods, 123 sizeof(struct mipscore_softc)); 124EARLY_DRIVER_MODULE(bhnd_mips, bhnd, mipscore_driver, 125 bhnd_mipscore_devclass, 0, 0, BUS_PASS_CPU + BUS_PASS_ORDER_EARLY); 126MODULE_VERSION(bhnd_mips, 1); 127