Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/arm/mv/armada38x/pmsu.c
39536 views
1
/*-
2
* Copyright (c) 2015 Semihalf.
3
* Copyright (c) 2015 Stormshield.
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*/
27
28
#include <sys/param.h>
29
#include <sys/bus.h>
30
#include <sys/conf.h>
31
#include <sys/rman.h>
32
#include <sys/types.h>
33
#include <sys/kernel.h>
34
#include <sys/module.h>
35
#include <sys/resource.h>
36
#include <sys/systm.h>
37
38
#include <vm/vm.h>
39
#include <vm/pmap.h>
40
41
#include <machine/cpu.h>
42
#include <machine/fdt.h>
43
#include <machine/smp.h>
44
45
#include <dev/ofw/ofw_bus_subr.h>
46
47
#include <arm/mv/mvreg.h>
48
49
#include "pmsu.h"
50
51
static struct resource_spec pmsu_spec[] = {
52
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
53
{ -1, 0 }
54
};
55
56
struct pmsu_softc {
57
device_t dev;
58
struct resource *res;
59
};
60
61
static int pmsu_probe(device_t dev);
62
static int pmsu_attach(device_t dev);
63
static int pmsu_detach(device_t dev);
64
65
static device_method_t pmsu_methods[] = {
66
DEVMETHOD(device_probe, pmsu_probe),
67
DEVMETHOD(device_attach, pmsu_attach),
68
DEVMETHOD(device_detach, pmsu_detach),
69
{ 0, 0 }
70
};
71
72
static driver_t pmsu_driver = {
73
"pmsu",
74
pmsu_methods,
75
sizeof(struct pmsu_softc)
76
};
77
78
DRIVER_MODULE(pmsu, simplebus, pmsu_driver, 0, 0);
79
DRIVER_MODULE(pmsu, ofwbus, pmsu_driver, 0, 0);
80
81
static int
82
pmsu_probe(device_t dev)
83
{
84
85
if (!ofw_bus_status_okay(dev))
86
return (ENXIO);
87
88
if (!ofw_bus_is_compatible(dev, "marvell,armada-380-pmsu"))
89
return (ENXIO);
90
91
device_set_desc(dev, "Power Management Service Unit");
92
93
return (BUS_PROBE_DEFAULT);
94
}
95
96
static int
97
pmsu_attach(device_t dev)
98
{
99
struct pmsu_softc *sc;
100
int err;
101
102
sc = device_get_softc(dev);
103
sc->dev = dev;
104
105
err = bus_alloc_resources(dev, pmsu_spec, &sc->res);
106
if (err != 0) {
107
device_printf(dev, "could not allocate resources\n");
108
return (ENXIO);
109
}
110
111
return (0);
112
}
113
114
static int
115
pmsu_detach(device_t dev)
116
{
117
struct pmsu_softc *sc;
118
119
sc = device_get_softc(dev);
120
121
bus_release_resources(dev, pmsu_spec, &sc->res);
122
123
return (0);
124
}
125
126
#ifdef SMP
127
int
128
pmsu_boot_secondary_cpu(void)
129
{
130
bus_space_handle_t vaddr;
131
int rv;
132
133
rv = bus_space_map(fdtbus_bs_tag, (bus_addr_t)MV_PMSU_BASE, MV_PMSU_REGS_LEN,
134
0, &vaddr);
135
if (rv != 0)
136
return (rv);
137
138
/* Boot cpu1 */
139
bus_space_write_4(fdtbus_bs_tag, vaddr, PMSU_BOOT_ADDR_REDIRECT_OFFSET(1),
140
pmap_kextract((vm_offset_t)mpentry));
141
142
dcache_wbinv_poc_all();
143
dsb();
144
sev();
145
146
bus_space_unmap(fdtbus_bs_tag, vaddr, MV_PMSU_REGS_LEN);
147
148
return (0);
149
}
150
#endif
151
152