ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ppc / boot / simple / misc-prep.c
1 /*
2  * arch/ppc/boot/simple/misc-prep.c
3  *
4  * Maintainer: Tom Rini <trini@kernel.crashing.org>
5  *
6  * In the past: Gary Thomas, Cort Dougan <cort@cs.nmt.edu>
7  */
8
9 #include <linux/config.h>
10 #include <linux/pci_ids.h>
11 #include <linux/types.h>
12 #include <asm/residual.h>
13 #include <asm/string.h>
14 #include <asm/byteorder.h>
15 #include "mpc10x.h"
16 #include "of1275.h"
17 #include "nonstdio.h"
18
19 extern int keyb_present;        /* keyboard controller is present by default */
20 RESIDUAL hold_resid_buf;
21 RESIDUAL *hold_residual = &hold_resid_buf;
22 static void *OFW_interface;     /* Pointer to OF, if available. */
23
24 #ifdef CONFIG_VGA_CONSOLE
25 char *vidmem = (char *)0xC00B8000;
26 int lines = 25, cols = 80;
27 int orig_x, orig_y = 24;
28 #endif /* CONFIG_VGA_CONSOLE */
29
30 extern int CRT_tstc(void);
31 extern int vga_init(unsigned char *ISA_mem);
32 extern void gunzip(void *, int, unsigned char *, int *);
33 extern unsigned long serial_init(int chan, void *ignored);
34 extern void serial_fixups(void);
35 extern struct bi_record *decompress_kernel(unsigned long load_addr,
36                 int num_words, unsigned long cksum);
37 extern void disable_6xx_mmu(void);
38 extern unsigned long mpc10x_get_mem_size(void);
39
40 static void
41 writel(unsigned int val, unsigned int address)
42 {
43         /* Ensure I/O operations complete */
44         __asm__ volatile("eieio");
45         *(unsigned int *)address = cpu_to_le32(val);
46 }
47
48 #define PCI_CFG_ADDR(dev,off)   ((0x80<<24) | (dev<<8) | (off&0xfc))
49 #define PCI_CFG_DATA(off)       (MPC10X_MAPA_CNFG_DATA+(off&3))
50
51 static void
52 pci_read_config_32(unsigned char devfn,
53                 unsigned char offset,
54                 unsigned int *val)
55 {
56         /* Ensure I/O operations complete */
57         __asm__ volatile("eieio");
58         *(unsigned int *)PCI_CFG_ADDR(devfn,offset) =
59                 cpu_to_le32(MPC10X_MAPA_CNFG_ADDR);
60         /* Ensure I/O operations complete */
61         __asm__ volatile("eieio");
62         *val = le32_to_cpu(*(unsigned int *)PCI_CFG_DATA(offset));
63         return;
64 }
65
66 #ifdef CONFIG_VGA_CONSOLE
67 void
68 scroll(void)
69 {
70         int i;
71
72         memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
73         for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
74                 vidmem[i] = ' ';
75 }
76 #endif /* CONFIG_VGA_CONSOLE */
77
78 unsigned long
79 load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
80                   RESIDUAL *residual, void *OFW)
81 {
82         int start_multi = 0;
83         unsigned int pci_viddid, pci_did, tulip_pci_base, tulip_base;
84
85         /* If we have Open Firmware, initialise it immediately */
86         if (OFW) {
87                 OFW_interface = OFW;
88                 ofinit(OFW_interface);
89         }
90
91 #if defined(CONFIG_VGA_CONSOLE)
92         vga_init((unsigned char *)0xC0000000);
93 #endif /* CONFIG_VGA_CONSOLE */
94
95         if (residual) {
96                 /* Is this Motorola PPCBug? */
97                 if ((1 & residual->VitalProductData.FirmwareSupports) &&
98                     (1 == residual->VitalProductData.FirmwareSupplier)) {
99                         unsigned char base_mod;
100                         unsigned char board_type = inb(0x801) & 0xF0;
101
102                         /*
103                          * Reset the onboard 21x4x Ethernet
104                          * Motorola Ethernet is at IDSEL 14 (devfn 0x70)
105                          */
106                         pci_read_config_32(0x70, 0x00, &pci_viddid);
107                         pci_did = (pci_viddid & 0xffff0000) >> 16;
108                         /* Be sure we've really found a 21x4x chip */
109                         if (((pci_viddid & 0xffff) == PCI_VENDOR_ID_DEC) &&
110                                 ((pci_did == PCI_DEVICE_ID_DEC_TULIP_FAST) ||
111                                 (pci_did == PCI_DEVICE_ID_DEC_TULIP) ||
112                                 (pci_did == PCI_DEVICE_ID_DEC_TULIP_PLUS) ||
113                                 (pci_did == PCI_DEVICE_ID_DEC_21142))) {
114                                 pci_read_config_32(0x70,
115                                                 0x10,
116                                                 &tulip_pci_base);
117                                 /* Get the physical base address */
118                                 tulip_base =
119                                         (tulip_pci_base & ~0x03UL) + 0x80000000;
120                                 /* Strobe the 21x4x reset bit in CSR0 */
121                                 writel(0x1, tulip_base);
122                         }
123
124                         /* If this is genesis 2 board then check for no
125                          * keyboard controller and more than one processor.
126                          */
127                         if (board_type == 0xe0) {
128                                 base_mod = inb(0x803);
129                                 /* if a MVME2300/2400 or a Sitka then no keyboard */
130                                 if((base_mod == 0xFA) || (base_mod == 0xF9) ||
131                                    (base_mod == 0xE1)) {
132                                         keyb_present = 0;       /* no keyboard */
133                                 }
134                         }
135                         /* If this is a multiprocessor system then
136                          * park the other processor so that the
137                          * kernel knows where to find them.
138                          */
139                         if (residual->MaxNumCpus > 1)
140                                 start_multi = 1;
141                 }
142                 memcpy(hold_residual,residual,sizeof(RESIDUAL));
143         }
144
145         /* Call decompress_kernel */
146         decompress_kernel(load_addr, num_words, cksum);
147
148         if (start_multi) {
149                 residual->VitalProductData.SmpIar = (unsigned long)0xc0;
150                 residual->Cpus[1].CpuState = CPU_GOOD;
151                 hold_residual->VitalProductData.Reserved5 = 0xdeadbeef;
152         }
153
154         /* Now go and clear out the BATs and ensure that our MSR is
155          * correct .*/
156         disable_6xx_mmu();
157
158         /* Make r3 be a pointer to the residual data. */
159         return (unsigned long)hold_residual;
160 }
161
162 unsigned long
163 get_mem_size(void)
164 {
165         unsigned int pci_viddid, pci_did;
166
167         /* First, figure out what kind of host bridge we are on.  If it's
168          * an MPC10x, we can ask it directly how much memory it has.
169          * Otherwise, see if the residual data has anything.  This isn't
170          * the best way, but it can be the only way.  If there's nothing,
171          * assume 32MB. -- Tom.
172          */
173         /* See what our host bridge is. */
174         pci_read_config_32(0x00, 0x00, &pci_viddid);
175         pci_did = (pci_viddid & 0xffff0000) >> 16;
176         /* See if we are on an MPC10x. */
177         if (((pci_viddid & 0xffff) == PCI_VENDOR_ID_MOTOROLA)
178                         && ((pci_did == PCI_DEVICE_ID_MOTOROLA_MPC105)
179                                 || (pci_did == PCI_DEVICE_ID_MOTOROLA_MPC106)
180                                 || (pci_did == PCI_DEVICE_ID_MOTOROLA_MPC107)))
181                 return mpc10x_get_mem_size();
182         /* If it's not, see if we have anything in the residual data. */
183         else if (hold_residual && hold_residual->TotalMemory)
184                 return hold_residual->TotalMemory;
185         else if (OFW_interface) {
186                 /*
187                  * This is a 'best guess' check.  We want to make sure
188                  * we don't try this on a PReP box without OF
189                  *     -- Cort
190                  */
191                 while (OFW_interface)
192                 {
193                         phandle dev_handle;
194                         int mem_info[2];
195
196                         /* get handle to memory description */
197                         if (!(dev_handle = finddevice("/memory@0")))
198                                 break;
199
200                         /* get the info */
201                         if (getprop(dev_handle, "reg", mem_info,
202                                                 sizeof(mem_info)) != 8)
203                                 break;
204
205                         return mem_info[1];
206                 }
207         }
208
209         /* Fall back to hard-coding 32MB. */
210         return 32*1024*1024;
211 }