xref: /netbsd-src/sys/arch/powerpc/booke/e500_autoconf.c (revision b8ea2c8cad98dc73c67d62f5856235879ca7e5f0)
1*b8ea2c8cSmatt /*	$NetBSD: e500_autoconf.c,v 1.2 2011/01/18 01:02:52 matt Exp $	*/
2*b8ea2c8cSmatt 
3*b8ea2c8cSmatt /*-
4*b8ea2c8cSmatt  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
5*b8ea2c8cSmatt  * All rights reserved.
6*b8ea2c8cSmatt  *
7*b8ea2c8cSmatt  * This code is derived from software contributed to The NetBSD Foundation
8*b8ea2c8cSmatt  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
9*b8ea2c8cSmatt  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
10*b8ea2c8cSmatt  *
11*b8ea2c8cSmatt  * This material is based upon work supported by the Defense Advanced Research
12*b8ea2c8cSmatt  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
13*b8ea2c8cSmatt  * Contract No. N66001-09-C-2073.
14*b8ea2c8cSmatt  * Approved for Public Release, Distribution Unlimited
15*b8ea2c8cSmatt  *
16*b8ea2c8cSmatt  * Redistribution and use in source and binary forms, with or without
17*b8ea2c8cSmatt  * modification, are permitted provided that the following conditions
18*b8ea2c8cSmatt  * are met:
19*b8ea2c8cSmatt  * 1. Redistributions of source code must retain the above copyright
20*b8ea2c8cSmatt  *    notice, this list of conditions and the following disclaimer.
21*b8ea2c8cSmatt  * 2. Redistributions in binary form must reproduce the above copyright
22*b8ea2c8cSmatt  *    notice, this list of conditions and the following disclaimer in the
23*b8ea2c8cSmatt  *    documentation and/or other materials provided with the distribution.
24*b8ea2c8cSmatt  *
25*b8ea2c8cSmatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26*b8ea2c8cSmatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27*b8ea2c8cSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28*b8ea2c8cSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29*b8ea2c8cSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30*b8ea2c8cSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31*b8ea2c8cSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32*b8ea2c8cSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33*b8ea2c8cSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34*b8ea2c8cSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35*b8ea2c8cSmatt  * POSSIBILITY OF SUCH DAMAGE.
36*b8ea2c8cSmatt  */
37*b8ea2c8cSmatt 
38*b8ea2c8cSmatt #include <sys/cdefs.h>
39*b8ea2c8cSmatt __KERNEL_RCSID(0, "$NetBSD: e500_autoconf.c,v 1.2 2011/01/18 01:02:52 matt Exp $");
40*b8ea2c8cSmatt 
41*b8ea2c8cSmatt #include <sys/param.h>
42*b8ea2c8cSmatt #include <sys/cpu.h>
43*b8ea2c8cSmatt #include <sys/conf.h>
44*b8ea2c8cSmatt #include <sys/device.h>
45*b8ea2c8cSmatt #include <sys/systm.h>
46*b8ea2c8cSmatt 
47*b8ea2c8cSmatt #include <net/if.h>
48*b8ea2c8cSmatt #include <net/if_ether.h>
49*b8ea2c8cSmatt 
50*b8ea2c8cSmatt #define	GLOBAL_PRIVATE
51*b8ea2c8cSmatt 
52*b8ea2c8cSmatt #include <powerpc/spr.h>
53*b8ea2c8cSmatt #include <powerpc/booke/spr.h>
54*b8ea2c8cSmatt 
55*b8ea2c8cSmatt #include <powerpc/booke/cpuvar.h>
56*b8ea2c8cSmatt #include <powerpc/booke/e500var.h>
57*b8ea2c8cSmatt #include <powerpc/booke/e500reg.h>
58*b8ea2c8cSmatt 
59*b8ea2c8cSmatt void
e500_device_register(device_t dev,void * aux)60*b8ea2c8cSmatt e500_device_register(device_t dev, void *aux)
61*b8ea2c8cSmatt {
62*b8ea2c8cSmatt }
63*b8ea2c8cSmatt 
64*b8ea2c8cSmatt /*
65*b8ea2c8cSmatt  * Let's see if the DEVDISR bit encoded in the low 6 bits of cnl_flags is
66*b8ea2c8cSmatt  * set.  If it is, the device is disabled.
67*b8ea2c8cSmatt  */
68*b8ea2c8cSmatt bool
e500_device_disabled_p(uint32_t flags)69*b8ea2c8cSmatt e500_device_disabled_p(uint32_t flags)
70*b8ea2c8cSmatt {
71*b8ea2c8cSmatt 	if ((flags-- & 63) == 0)
72*b8ea2c8cSmatt 		return false;
73*b8ea2c8cSmatt 
74*b8ea2c8cSmatt 	const uint32_t v = cpu_read_4(GLOBAL_BASE + DEVDISR);
75*b8ea2c8cSmatt 	return (v & (1 << (flags & 31))) != 0;
76*b8ea2c8cSmatt }
77*b8ea2c8cSmatt 
78*b8ea2c8cSmatt uint16_t
e500_get_svr(void)79*b8ea2c8cSmatt e500_get_svr(void)
80*b8ea2c8cSmatt {
81*b8ea2c8cSmatt 	uint32_t svr = (mfspr(SPR_SVR) >> 16) & ~8;
82*b8ea2c8cSmatt 
83*b8ea2c8cSmatt 	switch (svr) {
84*b8ea2c8cSmatt 	case SVR_MPC8543v1 >> 16:
85*b8ea2c8cSmatt 		return SVR_MPC8548v1 >> 16;
86*b8ea2c8cSmatt 	case SVR_MPC8541v1 >> 16:
87*b8ea2c8cSmatt 		return SVR_MPC8555v1 >> 16;
88*b8ea2c8cSmatt 	default:
89*b8ea2c8cSmatt 		return svr;
90*b8ea2c8cSmatt 	}
91*b8ea2c8cSmatt }
92*b8ea2c8cSmatt 
93*b8ea2c8cSmatt u_int
e500_truth_decode(u_int instance,uint32_t data,const struct e500_truthtab * tab,size_t ntab,u_int default_value)94*b8ea2c8cSmatt e500_truth_decode(u_int instance, uint32_t data,
95*b8ea2c8cSmatt 	const struct e500_truthtab *tab, size_t ntab, u_int default_value)
96*b8ea2c8cSmatt {
97*b8ea2c8cSmatt 	const uint16_t svr = e500_get_svr();
98*b8ea2c8cSmatt 
99*b8ea2c8cSmatt 	for (u_int i = ntab; i-- > 0; tab++) {
100*b8ea2c8cSmatt #if 0
101*b8ea2c8cSmatt 		printf("%s: [%u] = %x/%x %u/%u (%#x & %#x) = %#x (%#x)\n",
102*b8ea2c8cSmatt 		    __func__, i, tab->tt_svrhi, svr,
103*b8ea2c8cSmatt 		    tab->tt_instance, instance,
104*b8ea2c8cSmatt 		    data, tab->tt_mask, data & tab->tt_mask, tab->tt_value);
105*b8ea2c8cSmatt #endif
106*b8ea2c8cSmatt 		if (tab->tt_svrhi == svr
107*b8ea2c8cSmatt 		    && tab->tt_instance == instance
108*b8ea2c8cSmatt 		    && (data & tab->tt_mask) == tab->tt_value)
109*b8ea2c8cSmatt 			return tab->tt_result;
110*b8ea2c8cSmatt 	}
111*b8ea2c8cSmatt 	return default_value;
112*b8ea2c8cSmatt }
113*b8ea2c8cSmatt 
114*b8ea2c8cSmatt int
e500_cpunode_submatch(device_t parent,cfdata_t cf,const char * name,void * aux)115*b8ea2c8cSmatt e500_cpunode_submatch(device_t parent, cfdata_t cf, const char *name, void *aux)
116*b8ea2c8cSmatt {
117*b8ea2c8cSmatt 	struct cpunode_softc * const psc = device_private(parent);
118*b8ea2c8cSmatt 	struct cpunode_attach_args * const cna = aux;
119*b8ea2c8cSmatt 	struct cpunode_locators * const cnl = &cna->cna_locs;
120*b8ea2c8cSmatt 
121*b8ea2c8cSmatt 	if (!board_info_get_bool("pq3")
122*b8ea2c8cSmatt 	    || strcmp(cnl->cnl_name, name) != 0
123*b8ea2c8cSmatt 	    || e500_device_disabled_p(cnl->cnl_flags)
124*b8ea2c8cSmatt 	    || (cna->cna_childmask & psc->sc_children)
125*b8ea2c8cSmatt 	    || (cf->cf_loc[CPUNODECF_INSTANCE] != CPUNODECF_INSTANCE_DEFAULT
126*b8ea2c8cSmatt 		&& cf->cf_loc[CPUNODECF_INSTANCE] != cnl->cnl_instance))
127*b8ea2c8cSmatt 		return 0;
128*b8ea2c8cSmatt 
129*b8ea2c8cSmatt 	return 1;
130*b8ea2c8cSmatt }
131