]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/broadcom/bcm_mipscore.c
Update to ELF Tool Chain r3475
[FreeBSD/FreeBSD.git] / sys / mips / broadcom / bcm_mipscore.c
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$");
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
51 static const struct resource_spec mipscore_rspec[MIPSCORE_MAX_RSPEC] = {
52         { SYS_RES_MEMORY,       0,      RF_ACTIVE },
53         { -1, -1, 0 }
54 };
55
56 struct bhnd_device mipscore_match[] = {
57         BHND_MIPS_DEVICE(MIPS,          "BHND MIPS processor",          NULL),
58         BHND_MIPS_DEVICE(MIPS33,        "BHND MIPS3302 processor",      NULL),
59         BHND_MIPS_DEVICE(MIPS74K,       "BHND MIPS74K processor",       NULL),
60         BHND_DEVICE_END
61 };
62
63 static int
64 mipscore_probe(device_t dev)
65 {
66         const struct bhnd_device *id;
67
68         id = bhnd_device_lookup(dev, mipscore_match, sizeof(mipscore_match[0]));
69         if (id == NULL)
70                 return (ENXIO);
71
72         bhnd_set_default_core_desc(dev);
73         return (BUS_PROBE_DEFAULT);
74 }
75
76 static int
77 mipscore_attach(device_t dev)
78 {
79         struct mipscore_softc   *sc;
80         struct resource         *res;
81         uint32_t                 intmask;
82         uint16_t                 devid;
83         int                      error;
84
85         sc = device_get_softc(dev);
86         devid = bhnd_get_device(dev);
87
88         sc->devid = devid;
89         sc->dev = dev;
90
91         /* Allocate bus resources */
92         memcpy(sc->rspec, mipscore_rspec, sizeof(sc->rspec));
93         error = bhnd_alloc_resources(dev, sc->rspec, sc->res);
94         if (error)
95                 return (error);
96
97         res = sc->res[0]->res;
98         if (res == NULL)
99                 return (ENXIO);
100
101         if (devid == BHND_COREID_MIPS74K) {
102                 intmask = (1 << 31);
103                 /* Use intmask5 register to route the timer interrupt */
104                 bus_write_4(res, offsetof(struct mipscore_regs, intmask[5]),
105                                 intmask);
106         }
107
108         return (0);
109 }
110
111 static device_method_t mipscore_methods[] = {
112                 DEVMETHOD(device_probe,         mipscore_probe),
113                 DEVMETHOD(device_attach,        mipscore_attach),
114                 DEVMETHOD_END
115 };
116
117 devclass_t bhnd_mipscore_devclass;
118
119 DEFINE_CLASS_0(bhnd_mipscore, mipscore_driver, mipscore_methods,
120                 sizeof(struct mipscore_softc));
121 DRIVER_MODULE(bhnd_mipscore, bhnd, mipscore_driver, bhnd_mipscore_devclass,
122                 0, 0);
123 MODULE_VERSION(bhnd_mipscore, 1);