ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ia64 / sn / fakeprom / main.c
1 /* 
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 2000-2003 Silicon Graphics, Inc.  All rights reserved.
8  */
9
10
11
12 #include <linux/config.h>
13 #include <linux/types.h>
14 #include <asm/bitops.h>
15
16 extern void klgraph_init(void);
17 void bedrock_init(int);
18 void synergy_init(int, int);
19 void sys_fw_init (const char *args, int arglen, int bsp);
20
21 volatile int    bootmaster=0;           /* Used to pick bootmaster */
22 volatile int    nasidmaster[128]={0};   /* Used to pick node/synergy masters */
23 int             init_done=0;
24 extern int      bsp_lid;
25
26 #define get_bit(b,p)    (((*p)>>(b))&1)
27
28 int
29 fmain(int lid, int bsp) {
30         int     syn, nasid, cpu;
31
32         /*
33          * First lets figure out who we are. This is done from the
34          * LID passed to us.
35          */
36         nasid = (lid>>16)&0xfff;
37         cpu = (lid>>28)&3;
38         syn = 0;
39         
40         /*
41          * Now pick a nasid master to initialize Bedrock registers.
42          */
43         if (test_and_set_bit(8, &nasidmaster[nasid]) == 0) {
44                 bedrock_init(nasid);
45                 test_and_set_bit(9, &nasidmaster[nasid]);
46         } else
47                 while (get_bit(9, &nasidmaster[nasid]) == 0);
48         
49
50         /*
51          * Now pick a BSP & finish init.
52          */
53         if (test_and_set_bit(0, &bootmaster) == 0) {
54                 sys_fw_init(0, 0, bsp);
55                 test_and_set_bit(1, &bootmaster);
56         } else
57                 while (get_bit(1, &bootmaster) == 0);
58
59         return (lid == bsp_lid);
60 }
61
62
63 void
64 bedrock_init(int nasid)
65 {
66         nasid = nasid;          /* to quiet gcc */
67 #if 0
68         /*
69          * Undef if you need fprom to generate a 1 node klgraph
70          * information .. only works for 1 node for nasid 0.
71          */
72         klgraph_init();
73 #endif
74 }
75
76
77 void
78 synergy_init(int nasid, int syn)
79 {
80         long    *base;
81         long    off;
82
83         /*
84          * Enable all FSB flashed interrupts.
85          * I'd really like defines for this......
86          */
87         base = (long*)0x80000e0000000000LL;             /* base of synergy regs */
88         for (off = 0x2a0; off < 0x2e0; off+=8)          /* offset for VEC_MASK_{0-3}_A/B */
89                 *(base+off/8) = -1LL;
90
91         /*
92          * Set the NASID in the FSB_CONFIG register.
93          */
94         base = (long*)0x80000e0000000450LL;
95         *base = (long)((nasid<<16)|(syn<<9));
96 }
97
98
99 /* Why isnt there a bcopy/memcpy in lib64.a */
100
101 void* 
102 memcpy(void * dest, const void *src, size_t count)
103 {
104         char *s, *se, *d;
105
106         for(d=dest, s=(char*)src, se=s+count; s<se; s++, d++)
107                 *d = *s;
108         return dest;
109 }