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