2 * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
40 #include <sys/stddef.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
45 #include <dev/bhnd/bhnd.h>
46 #include <dev/bhnd/bhndvar.h>
47 #include <dev/bhnd/bhnd_ids.h>
49 #include "bcm_mipscore.h"
51 static const struct resource_spec mipscore_rspec[MIPSCORE_MAX_RSPEC] = {
52 { SYS_RES_MEMORY, 0, RF_ACTIVE },
56 #define MIPSCORE_DEV(_vendor, _core) \
57 BHND_DEVICE(_vendor, _core, NULL, NULL, BHND_DF_SOC)
59 struct bhnd_device mipscore_match[] = {
60 MIPSCORE_DEV(BCM, MIPS),
61 MIPSCORE_DEV(BCM, MIPS33),
62 MIPSCORE_DEV(MIPS, MIPS74K),
67 mipscore_probe(device_t dev)
69 const struct bhnd_device *id;
71 id = bhnd_device_lookup(dev, mipscore_match, sizeof(mipscore_match[0]));
75 bhnd_set_default_core_desc(dev);
76 return (BUS_PROBE_DEFAULT);
80 mipscore_attach(device_t dev)
82 struct mipscore_softc *sc;
88 sc = device_get_softc(dev);
89 devid = bhnd_get_device(dev);
94 /* Allocate bus resources */
95 memcpy(sc->rspec, mipscore_rspec, sizeof(sc->rspec));
96 error = bhnd_alloc_resources(dev, sc->rspec, sc->res);
100 res = sc->res[0]->res;
104 if (devid == BHND_COREID_MIPS74K) {
106 /* Use intmask5 register to route the timer interrupt */
107 bus_write_4(res, offsetof(struct mipscore_regs, intmask[5]),
114 static device_method_t mipscore_methods[] = {
115 DEVMETHOD(device_probe, mipscore_probe),
116 DEVMETHOD(device_attach, mipscore_attach),
120 devclass_t bhnd_mipscore_devclass;
122 DEFINE_CLASS_0(bhnd_mips, mipscore_driver, mipscore_methods,
123 sizeof(struct mipscore_softc));
124 EARLY_DRIVER_MODULE(bhnd_mips, bhnd, mipscore_driver,
125 bhnd_mipscore_devclass, 0, 0, BUS_PASS_CPU + BUS_PASS_ORDER_EARLY);
126 MODULE_VERSION(bhnd_mips, 1);