1 /* $Id: cpu.c,v 1.1 1998/01/16 04:17:42 sakamoto Exp $ */ 2 3 /* 4 * This file contains information proprietary to Be Inc. 5 */ 6 7 /*- 8 * Copyright (C) 1995-1997 Gary Thomas (gdt@linuxppc.org) 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by Gary Thomas. 22 * 4. The name of the author may not be used to endorse or promote products 23 * derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37 /* 38 * Return the ordinal of the CPU on which the code runs (0/1) 39 */ 40 41 #define CPU1_HRESET 0x20000000 42 43 int 44 whichCPU() 45 { 46 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF3F0; 47 if (*CPU_control & 0x02000000) 48 { 49 return (1); 50 } else 51 { 52 return (0); 53 } 54 } 55 56 /* 57 * Force CPU #1 into Hard RESET state 58 */ 59 60 void 61 resetCPU1() 62 { 63 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF4F0; 64 *CPU_control = CPU1_HRESET; 65 } 66 67 /* 68 * Return state of CPU RESET register 69 */ 70 unsigned long 71 cpuState() 72 { 73 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF4F0; 74 return (*CPU_control); 75 } 76 77 /* 78 * Start CPU #1 79 */ 80 void 81 runCPU1(entry) 82 long entry; 83 { 84 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF4F0; 85 long *PEF_vector = (long *)0x3000; 86 long *PEF_vector2 = (long *)0x3018; 87 int i; 88 PEF_vector[0] = 0; 89 PEF_vector[1] = 0; 90 PEF_vector[2] = 0; 91 PEF_vector[3] = 0; 92 PEF_vector[0] = 0; 93 PEF_vector2[0] = 0; 94 *CPU_control = 0x80000000 | CPU1_HRESET; 95 /* Give the other CPU a chance to find the zero value */ 96 delay(1000); 97 PEF_vector[0] = entry; 98 PEF_vector[1] = entry; 99 PEF_vector[2] = entry; 100 PEF_vector[3] = entry; 101 PEF_vector[0] = entry; 102 PEF_vector2[0] = entry; 103 } 104 105 /* 106 * CPU #1 runs here 107 */ 108 volatile int cpu_ctr = 0; 109 110 cpu1() 111 { 112 while(1) cpu_ctr++; 113 } 114 115 volatile int CPU1_alive = 0; 116 117 void 118 start_CPU1() 119 { 120 volatile long *key = (volatile long *)0x0080; 121 122 CPU1_alive++; 123 *key = 0; 124 /* Wait for a kernel to load up a vector of where we should jump */ 125 while (*key == 0) { 126 delay(10); 127 } 128 run(*key); 129 } 130 131 void 132 wait_for(ptr) 133 volatile long *ptr; 134 { 135 int i; 136 for (i = 0; i < 10; i++) { 137 if (*ptr) 138 return; 139 delay(10); 140 } 141 printf("CPU #1 didn't start!\n"); 142 } 143