]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bhnd/bhnd_nexus.c
Update llvm, clang, lld and lldb to release_39 branch r288513.
[FreeBSD/FreeBSD.git] / sys / dev / bhnd / bhnd_nexus.c
1 /*-
2  * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org>
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  * $FreeBSD$
30  */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35
36 /*
37  * bhnd(4) driver mix-in providing shared common methods for
38  * bhnd bus devices attached via a root nexus.
39  */
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/bus.h>
44 #include <sys/kernel.h>
45 #include <sys/module.h>
46 #include <sys/rman.h>
47 #include <sys/malloc.h>
48
49 #include <machine/bus.h>
50
51 #include <dev/bhnd/bhnd_ids.h>
52 #include <dev/bhnd/cores/chipc/chipcreg.h>
53
54 #include "bhnd_nexusvar.h"
55
56 static const struct resource_spec bhnd_nexus_res_spec[] = {
57         { SYS_RES_MEMORY,       0,      RF_ACTIVE },    /* chipc registers */
58         { -1,                   0,      0 }
59 };
60
61 /**
62  * Map ChipCommon's register block and read the chip identifier data.
63  * 
64  * @param dev A bhnd_nexus device.
65  * @param chipid On success, will be populated with the chip identifier.
66  * @retval 0 success
67  * @retval non-zero An error occurred reading the chip identifier..
68  */
69 int
70 bhnd_nexus_read_chipid(device_t dev, struct bhnd_chipid *chipid)
71 {
72         struct resource_spec    rspec[nitems(bhnd_nexus_res_spec)];
73         int                     error;
74
75         memcpy(rspec, bhnd_nexus_res_spec, sizeof(rspec));
76         error = bhnd_read_chipid(dev, rspec, 0, chipid);
77         if (error)
78                 device_printf(dev, "error %d reading chip ID\n", error);
79
80         return (error);
81 }
82
83 static bool
84 bhnd_nexus_is_hw_disabled(device_t dev, device_t child)
85 {
86         return (false);
87 }
88
89 static bhnd_attach_type
90 bhnd_nexus_get_attach_type(device_t dev, device_t child)
91 {
92         return (BHND_ATTACH_NATIVE);
93 }
94
95 static int
96 bhnd_nexus_activate_resource(device_t dev, device_t child, int type, int rid,
97     struct bhnd_resource *r)
98 {
99         int error;
100
101         /* Always direct */
102         if ((error = bus_activate_resource(child, type, rid, r->res)))
103                 return (error);
104
105         r->direct = true;
106         return (0);
107 }
108
109 static int
110 bhnd_nexus_deactivate_resource(device_t dev, device_t child,
111     int type, int rid, struct bhnd_resource *r)
112 {
113         int error;
114
115         /* Always direct */
116         KASSERT(r->direct, ("indirect resource delegated to bhnd_nexus\n"));
117
118         if ((error = bus_deactivate_resource(child, type, rid, r->res)))
119                 return (error);
120
121         r->direct = false;
122         return (0);
123 }
124
125 static int
126 bhnd_nexus_get_intr_count(device_t dev, device_t child)
127 {
128         // TODO: arch-specific interrupt handling.
129         return (0);
130 }
131
132 static device_method_t bhnd_nexus_methods[] = {
133         /* bhnd interface */
134         DEVMETHOD(bhnd_bus_activate_resource,   bhnd_nexus_activate_resource),
135         DEVMETHOD(bhnd_bus_deactivate_resource, bhnd_nexus_deactivate_resource),
136         DEVMETHOD(bhnd_bus_is_hw_disabled,      bhnd_nexus_is_hw_disabled),
137         DEVMETHOD(bhnd_bus_get_attach_type,     bhnd_nexus_get_attach_type),
138
139         DEVMETHOD(bhnd_bus_get_intr_count,      bhnd_nexus_get_intr_count),
140
141         DEVMETHOD_END
142 };
143
144 DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods,
145     sizeof(struct bhnd_softc));