cpunode.c revision 1.4.2.2 1 1.4.2.2 rmind /* $NetBSD: cpunode.c,v 1.4.2.2 2011/03/05 20:51:34 rmind Exp $ */
2 1.4.2.2 rmind /*-
3 1.4.2.2 rmind * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4 1.4.2.2 rmind * All rights reserved.
5 1.4.2.2 rmind *
6 1.4.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
7 1.4.2.2 rmind * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8 1.4.2.2 rmind * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9 1.4.2.2 rmind *
10 1.4.2.2 rmind * This material is based upon work supported by the Defense Advanced Research
11 1.4.2.2 rmind * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12 1.4.2.2 rmind * Contract No. N66001-09-C-2073.
13 1.4.2.2 rmind * Approved for Public Release, Distribution Unlimited
14 1.4.2.2 rmind *
15 1.4.2.2 rmind * Redistribution and use in source and binary forms, with or without
16 1.4.2.2 rmind * modification, are permitted provided that the following conditions
17 1.4.2.2 rmind * are met:
18 1.4.2.2 rmind * 1. Redistributions of source code must retain the above copyright
19 1.4.2.2 rmind * notice, this list of conditions and the following disclaimer.
20 1.4.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
21 1.4.2.2 rmind * notice, this list of conditions and the following disclaimer in the
22 1.4.2.2 rmind * documentation and/or other materials provided with the distribution.
23 1.4.2.2 rmind *
24 1.4.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 1.4.2.2 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.4.2.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 1.4.2.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 1.4.2.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 1.4.2.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 1.4.2.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 1.4.2.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 1.4.2.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 1.4.2.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 1.4.2.2 rmind * POSSIBILITY OF SUCH DAMAGE.
35 1.4.2.2 rmind */
36 1.4.2.2 rmind
37 1.4.2.2 rmind #include <sys/cdefs.h>
38 1.4.2.2 rmind
39 1.4.2.2 rmind __KERNEL_RCSID(0, "$NetBSD: cpunode.c,v 1.4.2.2 2011/03/05 20:51:34 rmind Exp $");
40 1.4.2.2 rmind
41 1.4.2.2 rmind #include <sys/param.h>
42 1.4.2.2 rmind #include <sys/device.h>
43 1.4.2.2 rmind #include <sys/cpu.h>
44 1.4.2.2 rmind
45 1.4.2.2 rmind #include "ioconf.h"
46 1.4.2.2 rmind
47 1.4.2.2 rmind #include <powerpc/booke/cpuvar.h>
48 1.4.2.2 rmind
49 1.4.2.2 rmind static int cpunode_match(device_t, cfdata_t, void *);
50 1.4.2.2 rmind static void cpunode_attach(device_t, device_t, void *);
51 1.4.2.2 rmind
52 1.4.2.2 rmind CFATTACH_DECL_NEW(cpunode, sizeof(struct cpunode_softc),
53 1.4.2.2 rmind cpunode_match, cpunode_attach, NULL, NULL);
54 1.4.2.2 rmind
55 1.4.2.2 rmind static u_int nodes;
56 1.4.2.2 rmind
57 1.4.2.2 rmind static int
58 1.4.2.2 rmind cpunode_match(device_t parent, cfdata_t cf, void *aux)
59 1.4.2.2 rmind {
60 1.4.2.2 rmind struct mainbus_attach_args * const ma = aux;
61 1.4.2.2 rmind if (strcmp(ma->ma_name, cpunode_cd.cd_name) != 0)
62 1.4.2.2 rmind return 0;
63 1.4.2.2 rmind
64 1.4.2.2 rmind if (ma->ma_node > 8 || (nodes & (1 << ma->ma_node)))
65 1.4.2.2 rmind return 0;
66 1.4.2.2 rmind
67 1.4.2.2 rmind return 1;
68 1.4.2.2 rmind }
69 1.4.2.2 rmind
70 1.4.2.2 rmind static int
71 1.4.2.2 rmind cpunode_print(void *aux, const char *pnp)
72 1.4.2.2 rmind {
73 1.4.2.2 rmind struct cpunode_attach_args *cna = aux;
74 1.4.2.2 rmind
75 1.4.2.2 rmind if (pnp)
76 1.4.2.2 rmind #if 0
77 1.4.2.2 rmind return QUIET;
78 1.4.2.2 rmind #else
79 1.4.2.2 rmind aprint_normal("%s at %s", cna->cna_locs.cnl_name, pnp);
80 1.4.2.2 rmind #endif
81 1.4.2.2 rmind
82 1.4.2.2 rmind if (cna->cna_locs.cnl_instance != 0)
83 1.4.2.2 rmind aprint_normal(" instance %d", cna->cna_locs.cnl_instance);
84 1.4.2.2 rmind
85 1.4.2.2 rmind return UNCONF;
86 1.4.2.2 rmind }
87 1.4.2.2 rmind
88 1.4.2.2 rmind static void
89 1.4.2.2 rmind cpunode_attach(device_t parent, device_t self, void *aux)
90 1.4.2.2 rmind {
91 1.4.2.2 rmind const struct cpunode_locators *cnl = cpu_md_ops.md_cpunode_locs;
92 1.4.2.2 rmind struct cpunode_softc * const sc = device_private(self);
93 1.4.2.2 rmind struct mainbus_attach_args * const ma = aux;
94 1.4.2.2 rmind struct cpunode_attach_args cna;
95 1.4.2.2 rmind
96 1.4.2.2 rmind sc->sc_dev = self;
97 1.4.2.2 rmind
98 1.4.2.2 rmind aprint_normal("\n");
99 1.4.2.2 rmind aprint_normal_dev(self,
100 1.4.2.2 rmind "%"PRIu64"KB/%"PRIu64"B %"PRIu64"-banked %"PRIu64"-way unified L2 cache\n",
101 1.4.2.2 rmind board_info_get_number("l2-cache-size") / 1024,
102 1.4.2.2 rmind board_info_get_number("l2-cache-line-size"),
103 1.4.2.2 rmind board_info_get_number("l2-cache-banks"),
104 1.4.2.2 rmind board_info_get_number("l2-cache-ways"));
105 1.4.2.2 rmind
106 1.4.2.2 rmind nodes |= 1 << ma->ma_node;
107 1.4.2.2 rmind
108 1.4.2.2 rmind const uint16_t my_id = board_info_get_number("my-id");
109 1.4.2.2 rmind
110 1.4.2.2 rmind for (u_int childmask = 1; cnl->cnl_name != NULL; cnl++) {
111 1.4.2.2 rmind bool inclusive = true;
112 1.4.2.2 rmind bool found = (cnl->cnl_ids[0] == 0);
113 1.4.2.2 rmind for (u_int i = 0;
114 1.4.2.2 rmind !found
115 1.4.2.2 rmind && i < __arraycount(cnl->cnl_ids)
116 1.4.2.2 rmind && cnl->cnl_ids[i] != 0;
117 1.4.2.2 rmind i++) {
118 1.4.2.2 rmind if (cnl->cnl_ids[i] == 0xffff) {
119 1.4.2.2 rmind inclusive = false;
120 1.4.2.2 rmind continue;
121 1.4.2.2 rmind }
122 1.4.2.2 rmind found = (cnl->cnl_ids[i] == my_id);
123 1.4.2.2 rmind }
124 1.4.2.2 rmind /*
125 1.4.2.2 rmind * found & inclusive == match
126 1.4.2.2 rmind * !found & !inclusive == match
127 1.4.2.2 rmind * found & !inclusive == no match
128 1.4.2.2 rmind * !found & inclusive == no match
129 1.4.2.2 rmind * therefore
130 1.4.2.2 rmind * found ^ inclusive = no match
131 1.4.2.2 rmind * so
132 1.4.2.2 rmind * !(found ^ inclusive) = match
133 1.4.2.2 rmind */
134 1.4.2.2 rmind if (found ^ inclusive)
135 1.4.2.2 rmind continue;
136 1.4.2.2 rmind
137 1.4.2.2 rmind cna.cna_busname = "cpunode";
138 1.4.2.2 rmind cna.cna_memt = ma->ma_memt;
139 1.4.2.2 rmind cna.cna_le_memt = ma->ma_le_memt;
140 1.4.2.2 rmind cna.cna_dmat = ma->ma_dmat;
141 1.4.2.2 rmind cna.cna_childmask = childmask;
142 1.4.2.2 rmind cna.cna_locs = *cnl;
143 1.4.2.2 rmind
144 1.4.2.2 rmind #if DEBUG > 1
145 1.4.2.2 rmind aprint_normal_dev(self, "dev=%s[%u], addr=%x@%x",
146 1.4.2.2 rmind cnl->cnl_name, cnl->cnl_instance, cnl->cnl_size,
147 1.4.2.2 rmind cnl->cnl_addr);
148 1.4.2.2 rmind if (cnl->cnl_nintr > 0) {
149 1.4.2.2 rmind aprint_normal(", intrs=%u", cnl->cnl_intrs[0]);
150 1.4.2.2 rmind for (u_int i = 1; i < cnl->cnl_nintr; i++)
151 1.4.2.2 rmind aprint_normal(",%u", cnl->cnl_intrs[i]);
152 1.4.2.2 rmind }
153 1.4.2.2 rmind aprint_normal("\n");
154 1.4.2.2 rmind #endif
155 1.4.2.2 rmind (void)config_found_sm_loc(self, "cpunode", NULL, &cna,
156 1.4.2.2 rmind cpunode_print, NULL);
157 1.4.2.2 rmind childmask <<= 1;
158 1.4.2.2 rmind }
159 1.4.2.2 rmind /*
160 1.4.2.2 rmind * Anything MD left to do?
161 1.4.2.2 rmind */
162 1.4.2.2 rmind if (cpu_md_ops.md_cpunode_attach != NULL)
163 1.4.2.2 rmind (*cpu_md_ops.md_cpunode_attach)(parent, self, aux);
164 1.4.2.2 rmind }
165 1.4.2.2 rmind
166 1.4.2.2 rmind static int cpu_match(device_t, cfdata_t, void *);
167 1.4.2.2 rmind static void cpu_attach(device_t, device_t, void *);
168 1.4.2.2 rmind
169 1.4.2.2 rmind CFATTACH_DECL_NEW(cpu, 0,
170 1.4.2.2 rmind cpu_match, cpu_attach, NULL, NULL);
171 1.4.2.2 rmind
172 1.4.2.2 rmind static int
173 1.4.2.2 rmind cpu_match(device_t parent, cfdata_t cf, void *aux)
174 1.4.2.2 rmind {
175 1.4.2.2 rmind struct cpunode_softc * const psc = device_private(parent);
176 1.4.2.2 rmind struct cpunode_attach_args * const cna = aux;
177 1.4.2.2 rmind
178 1.4.2.2 rmind if (strcmp(cna->cna_locs.cnl_name, cpu_cd.cd_name) != 0)
179 1.4.2.2 rmind return 0;
180 1.4.2.2 rmind
181 1.4.2.2 rmind if (psc->sc_children & cna->cna_childmask)
182 1.4.2.2 rmind return 0;
183 1.4.2.2 rmind
184 1.4.2.2 rmind return 1;
185 1.4.2.2 rmind }
186 1.4.2.2 rmind
187 1.4.2.2 rmind static void
188 1.4.2.2 rmind cpu_attach(device_t parent, device_t self, void *aux)
189 1.4.2.2 rmind {
190 1.4.2.2 rmind struct cpunode_softc * const psc = device_private(parent);
191 1.4.2.2 rmind struct cpunode_attach_args * const cna = aux;
192 1.4.2.2 rmind
193 1.4.2.2 rmind psc->sc_children |= cna->cna_childmask;
194 1.4.2.2 rmind
195 1.4.2.2 rmind aprint_normal("\n");
196 1.4.2.2 rmind
197 1.4.2.2 rmind (*cpu_md_ops.md_cpu_attach)(self, cna->cna_locs.cnl_instance);
198 1.4.2.2 rmind }
199