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