1 /* $NetBSD: cpu.c,v 1.3 1999/06/28 01:20:44 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 #include <stand.h> 38 #include "boot.h" 39 40 /* 41 * Return the ordinal of the CPU on which the code runs (0/1) 42 */ 43 44 #define CPU1_HRESET 0x20000000 45 46 int 47 whichCPU() 48 { 49 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF3F0; 50 51 if (*CPU_control & 0x02000000) { 52 return (1); 53 } else { 54 return (0); 55 } 56 } 57 58 /* 59 * Force CPU #1 into Hard RESET state 60 */ 61 62 void 63 resetCPU1() 64 { 65 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF4F0; 66 67 *CPU_control = CPU1_HRESET; 68 } 69 70 /* 71 * Return state of CPU RESET register 72 */ 73 unsigned long 74 cpuState() 75 { 76 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF4F0; 77 78 return (*CPU_control); 79 } 80 81 /* 82 * Start CPU #1 83 */ 84 void 85 runCPU1(entry) 86 void *entry; 87 { 88 volatile unsigned long *CPU_control = (unsigned long *)0x7FFFF4F0; 89 long *PEF_vector = (long *)0x3000; 90 long *PEF_vector2 = (long *)0x3018; 91 92 PEF_vector[0] = 0; 93 PEF_vector[1] = 0; 94 PEF_vector[2] = 0; 95 PEF_vector[3] = 0; 96 PEF_vector[0] = 0; 97 PEF_vector2[0] = 0; 98 *CPU_control = 0x80000000 | CPU1_HRESET; 99 /* Give the other CPU a chance to find the zero value */ 100 delay(1000); 101 PEF_vector[0] = (long)entry; 102 PEF_vector[1] = (long)entry; 103 PEF_vector[2] = (long)entry; 104 PEF_vector[3] = (long)entry; 105 PEF_vector[0] = (long)entry; 106 PEF_vector2[0] = (long)entry; 107 } 108 109 /* 110 * CPU #1 runs here 111 */ 112 volatile int cpu_ctr = 0; 113 114 void 115 cpu1() 116 { 117 while (1) 118 cpu_ctr++; 119 } 120 121 volatile int CPU1_alive = 0; 122 123 void 124 start_CPU1() 125 { 126 volatile long *key = (volatile long *)0x0080; 127 128 CPU1_alive++; 129 *key = 0; 130 /* Wait for a kernel to load up a vector of where we should jump */ 131 while (*key == 0) 132 delay(10); 133 134 run(NULL, NULL, NULL, NULL, (void *)*key); 135 } 136 137 void 138 wait_for(ptr) 139 volatile int *ptr; 140 { 141 int i; 142 for (i = 0; i < 10; i++) { 143 if (*ptr) 144 return; 145 delay(10); 146 } 147 printf("CPU #1 didn't start!\n"); 148 } 149