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