Path: blob/master/arch/mips/powertv/powertv_setup.c
10818 views
/*1* Carsten Langgaard, [email protected]2* Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.3* Portions copyright (C) 2009 Cisco Systems, Inc.4*5* This program is free software; you can distribute it and/or modify it6* under the terms of the GNU General Public License (Version 2) as7* published by the Free Software Foundation.8*9* This program is distributed in the hope it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* for more details.13*14* You should have received a copy of the GNU General Public License along15* with this program; if not, write to the Free Software Foundation, Inc.,16* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.17*/18#include <linux/init.h>19#include <linux/sched.h>20#include <linux/ioport.h>21#include <linux/pci.h>22#include <linux/screen_info.h>23#include <linux/notifier.h>24#include <linux/etherdevice.h>25#include <linux/if_ether.h>26#include <linux/ctype.h>27#include <linux/cpu.h>28#include <linux/time.h>2930#include <asm/bootinfo.h>31#include <asm/irq.h>32#include <asm/mips-boards/generic.h>33#include <asm/mips-boards/prom.h>34#include <asm/dma.h>35#include <asm/asm.h>36#include <asm/traps.h>37#include <asm/asm-offsets.h>38#include "reset.h"3940#define VAL(n) STR(n)4142/*43* Macros for loading addresses and storing registers:44* LONG_L_ Stringified version of LONG_L for use in asm() statement45* LONG_S_ Stringified version of LONG_S for use in asm() statement46* PTR_LA_ Stringified version of PTR_LA for use in asm() statement47* REG_SIZE Number of 8-bit bytes in a full width register48*/49#define LONG_L_ VAL(LONG_L) " "50#define LONG_S_ VAL(LONG_S) " "51#define PTR_LA_ VAL(PTR_LA) " "5253#ifdef CONFIG_64BIT54#warning TODO: 64-bit code needs to be verified55#define REG_SIZE "8" /* In bytes */56#endif5758#ifdef CONFIG_32BIT59#define REG_SIZE "4" /* In bytes */60#endif6162static void register_panic_notifier(void);63static int panic_handler(struct notifier_block *notifier_block,64unsigned long event, void *cause_string);6566const char *get_system_type(void)67{68return "PowerTV";69}7071void __init plat_mem_setup(void)72{73panic_on_oops = 1;74register_panic_notifier();7576#if 077mips_pcibios_init();78#endif79mips_reboot_setup();80}8182/*83* Install a panic notifier for platform-specific diagnostics84*/85static void register_panic_notifier()86{87static struct notifier_block panic_notifier = {88.notifier_call = panic_handler,89.next = NULL,90.priority = INT_MAX91};92atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier);93}9495static int panic_handler(struct notifier_block *notifier_block,96unsigned long event, void *cause_string)97{98struct pt_regs my_regs;99100/* Save all of the registers */101{102unsigned long at, v0, v1; /* Must be on the stack */103104/* Start by saving $at and v0 on the stack. We use $at105* ourselves, but it looks like the compiler may use v0 or v1106* to load the address of the pt_regs structure. We'll come107* back later to store the registers in the pt_regs108* structure. */109__asm__ __volatile__ (110".set noat\n"111LONG_S_ "$at, %[at]\n"112LONG_S_ "$2, %[v0]\n"113LONG_S_ "$3, %[v1]\n"114:115[at] "=m" (at),116[v0] "=m" (v0),117[v1] "=m" (v1)118:119: "at"120);121122__asm__ __volatile__ (123".set noat\n"124"move $at, %[pt_regs]\n"125126/* Argument registers */127LONG_S_ "$4, " VAL(PT_R4) "($at)\n"128LONG_S_ "$5, " VAL(PT_R5) "($at)\n"129LONG_S_ "$6, " VAL(PT_R6) "($at)\n"130LONG_S_ "$7, " VAL(PT_R7) "($at)\n"131132/* Temporary regs */133LONG_S_ "$8, " VAL(PT_R8) "($at)\n"134LONG_S_ "$9, " VAL(PT_R9) "($at)\n"135LONG_S_ "$10, " VAL(PT_R10) "($at)\n"136LONG_S_ "$11, " VAL(PT_R11) "($at)\n"137LONG_S_ "$12, " VAL(PT_R12) "($at)\n"138LONG_S_ "$13, " VAL(PT_R13) "($at)\n"139LONG_S_ "$14, " VAL(PT_R14) "($at)\n"140LONG_S_ "$15, " VAL(PT_R15) "($at)\n"141142/* "Saved" registers */143LONG_S_ "$16, " VAL(PT_R16) "($at)\n"144LONG_S_ "$17, " VAL(PT_R17) "($at)\n"145LONG_S_ "$18, " VAL(PT_R18) "($at)\n"146LONG_S_ "$19, " VAL(PT_R19) "($at)\n"147LONG_S_ "$20, " VAL(PT_R20) "($at)\n"148LONG_S_ "$21, " VAL(PT_R21) "($at)\n"149LONG_S_ "$22, " VAL(PT_R22) "($at)\n"150LONG_S_ "$23, " VAL(PT_R23) "($at)\n"151152/* Add'l temp regs */153LONG_S_ "$24, " VAL(PT_R24) "($at)\n"154LONG_S_ "$25, " VAL(PT_R25) "($at)\n"155156/* Kernel temp regs */157LONG_S_ "$26, " VAL(PT_R26) "($at)\n"158LONG_S_ "$27, " VAL(PT_R27) "($at)\n"159160/* Global pointer, stack pointer, frame pointer and161* return address */162LONG_S_ "$gp, " VAL(PT_R28) "($at)\n"163LONG_S_ "$sp, " VAL(PT_R29) "($at)\n"164LONG_S_ "$fp, " VAL(PT_R30) "($at)\n"165LONG_S_ "$ra, " VAL(PT_R31) "($at)\n"166167/* Now we can get the $at and v0 registers back and168* store them */169LONG_L_ "$8, %[at]\n"170LONG_S_ "$8, " VAL(PT_R1) "($at)\n"171LONG_L_ "$8, %[v0]\n"172LONG_S_ "$8, " VAL(PT_R2) "($at)\n"173LONG_L_ "$8, %[v1]\n"174LONG_S_ "$8, " VAL(PT_R3) "($at)\n"175:176:177[at] "m" (at),178[v0] "m" (v0),179[v1] "m" (v1),180[pt_regs] "r" (&my_regs)181: "at", "t0"182);183184/* Set the current EPC value to be the current location in this185* function */186__asm__ __volatile__ (187".set noat\n"188"1:\n"189PTR_LA_ "$at, 1b\n"190LONG_S_ "$at, %[cp0_epc]\n"191:192[cp0_epc] "=m" (my_regs.cp0_epc)193:194: "at"195);196197my_regs.cp0_cause = read_c0_cause();198my_regs.cp0_status = read_c0_status();199}200201pr_crit("I'm feeling a bit sleepy. hmmmmm... perhaps a nap would... "202"zzzz... \n");203204return NOTIFY_DONE;205}206207/* Information about the RF MAC address, if one was supplied on the208* command line. */209static bool have_rfmac;210static u8 rfmac[ETH_ALEN];211212static int rfmac_param(char *p)213{214u8 *q;215bool is_high_nibble;216int c;217218/* Skip a leading "0x", if present */219if (*p == '0' && *(p+1) == 'x')220p += 2;221222q = rfmac;223is_high_nibble = true;224225for (c = (unsigned char) *p++;226isxdigit(c) && q - rfmac < ETH_ALEN;227c = (unsigned char) *p++) {228int nibble;229230nibble = (isdigit(c) ? (c - '0') :231(isupper(c) ? c - 'A' + 10 : c - 'a' + 10));232233if (is_high_nibble)234*q = nibble << 4;235else236*q++ |= nibble;237238is_high_nibble = !is_high_nibble;239}240241/* If we parsed all the way to the end of the parameter value and242* parsed all ETH_ALEN bytes, we have a usable RF MAC address */243have_rfmac = (c == '\0' && q - rfmac == ETH_ALEN);244245return 0;246}247248early_param("rfmac", rfmac_param);249250/*251* Generate an Ethernet MAC address that has a good chance of being unique.252* @addr: Pointer to six-byte array containing the Ethernet address253* Generates an Ethernet MAC address that is highly likely to be unique for254* this particular system on a network with other systems of the same type.255*256* The problem we are solving is that, when random_ether_addr() is used to257* generate MAC addresses at startup, there isn't much entropy for the random258* number generator to use and the addresses it produces are fairly likely to259* be the same as those of other identical systems on the same local network.260* This is true even for relatively small numbers of systems (for the reason261* why, see the Wikipedia entry for "Birthday problem" at:262* http://en.wikipedia.org/wiki/Birthday_problem263*264* The good news is that we already have a MAC address known to be unique, the265* RF MAC address. The bad news is that this address is already in use on the266* RF interface. Worse, the obvious trick, taking the RF MAC address and267* turning on the locally managed bit, has already been used for other devices.268* Still, this does give us something to work with.269*270* The approach we take is:271* 1. If we can't get the RF MAC Address, just call random_ether_addr.272* 2. Use the 24-bit NIC-specific bits of the RF MAC address as the last 24273* bits of the new address. This is very likely to be unique, except for274* the current box.275* 3. To avoid using addresses already on the current box, we set the top276* six bits of the address with a value different from any currently277* registered Scientific Atlanta organizationally unique identifyer278* (OUI). This avoids duplication with any addresses on the system that279* were generated from valid Scientific Atlanta-registered address by280* simply flipping the locally managed bit.281* 4. We aren't generating a multicast address, so we leave the multicast282* bit off. Since we aren't using a registered address, we have to set283* the locally managed bit.284* 5. We then randomly generate the remaining 16-bits. This does two285* things:286* a. It allows us to call this function for more than one device287* in this system288* b. It ensures that things will probably still work even if289* some device on the device network has a locally managed290* address that matches the top six bits from step 2.291*/292void platform_random_ether_addr(u8 addr[ETH_ALEN])293{294const int num_random_bytes = 2;295const unsigned char non_sciatl_oui_bits = 0xc0u;296const unsigned char mac_addr_locally_managed = (1 << 1);297298if (!have_rfmac) {299pr_warning("rfmac not available on command line; "300"generating random MAC address\n");301random_ether_addr(addr);302}303304else {305int i;306307/* Set the first byte to something that won't match a Scientific308* Atlanta OUI, is locally managed, and isn't a multicast309* address */310addr[0] = non_sciatl_oui_bits | mac_addr_locally_managed;311312/* Get some bytes of random address information */313get_random_bytes(&addr[1], num_random_bytes);314315/* Copy over the NIC-specific bits of the RF MAC address */316for (i = 1 + num_random_bytes; i < ETH_ALEN; i++)317addr[i] = rfmac[i];318}319}320321322