OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [arch/] [or32/] [kernel/] [setup-new.c] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 xianfeng
/*
2
 *  linux/arch/or32/kernel/setup.c
3
 *
4
 *  or32 version
5
 *    author(s): Matjaz Breskvar (phoenix@bsemi.com)
6
 *
7
 *  derived from cris, i386, m68k, ppc, sh ports.
8
 *
9
 *  changes:
10
 *  18. 11. 2003: Matjaz Breskvar (phoenix@bsemi.com)
11
 *    initial port to or32 architecture
12
 *
13
 */
14
 
15
/*
16
 * This file handles the architecture-dependent parts of initialization
17
 */
18
 
19
#include <linux/errno.h>
20
#include <linux/sched.h>
21
#include <linux/kernel.h>
22
#include <linux/mm.h>
23
#include <linux/stddef.h>
24
#include <linux/unistd.h>
25
#include <linux/ptrace.h>
26
#include <linux/slab.h>
27
#include <linux/user.h>
28
#include <linux/a.out.h>
29
#include <linux/tty.h>
30
#include <linux/ioport.h>
31
#include <linux/delay.h>
32
#include <linux/config.h>
33
#include <linux/init.h>
34
#include <linux/bootmem.h>
35
#include <linux/seq_file.h>
36
#include <linux/console.h>
37
 
38
#include <asm/segment.h>
39
#include <asm/system.h>
40
#include <asm/smp.h>
41
#include <asm/pgtable.h>
42
#include <asm/types.h>
43
 
44
/*
45
 * Setup options
46
 */
47
 
48
extern int root_mountflags;
49
extern char _etext, _edata, _end;
50
 
51
#ifdef CONFIG_BLK_DEV_INITRD
52
extern unsigned long initrd_start, initrd_end;
53
extern char _initrd_start, _initrd_end;
54
#endif
55
 
56
#define COMMAND_LINE_SIZE 256
57
 
58
#include <asm/machdep.h>
59
 
60
extern void config_BSP(char *command, int len);
61
 
62
void (*mach_tick)(void) = NULL;
63
int (*mach_set_clock_mmss) (unsigned long) = NULL;
64
void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *)) = NULL;
65
unsigned long (*mach_gettimeoffset)(void) = NULL;
66
void (*mach_gettod)(int *year, int *mon, int *day, int *hour, int *min, int *sec) = NULL;
67
int (*mach_hwclk)(int, struct hwclk_time*) = NULL;
68
void (*mach_mksound)( unsigned int count, unsigned int ticks) = NULL;
69
void (*mach_reset)( void ) = NULL;
70
void (*mach_debug_init)(void) = NULL;
71
 
72
 
73
static char command_line[COMMAND_LINE_SIZE] = "root=/dev/ram";
74
char saved_command_line[COMMAND_LINE_SIZE];
75
extern const unsigned long text_start, edata; /* set by the linker script */
76
 
77
extern kdev_t or32_console_device(struct console *c);
78
extern int or32_console_setup(struct console *co, char *options);
79
extern void or32_console_write(struct console *co, const char *buf, unsigned int len);
80
 
81
static struct console or32_console = {
82
        name:   "ttyS",
83
        write:  or32_console_write,
84
        device: or32_console_device,
85
        setup:  or32_console_setup,
86
        flags:  CON_PRINTBUFFER,
87
        index:  -1,
88
};
89
 
90
void or32_console_init(void)
91
{
92
        register_console(&or32_console);
93
}
94
 
95
static unsigned long __init setup_memory(void)
96
{
97
        unsigned long bootmap_size, start_pfn, max_low_pfn;
98
 
99
 
100
#define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
101
#define PFN_DOWN(x)     ((x) >> PAGE_SHIFT)
102
#define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
103
 
104
        /* min_low_pfn points to the start of DRAM, start_pfn points
105
         * to the first DRAM pages after the kernel, and max_low_pfn
106
         * to the end of DRAM. Partial pages are not useful, so round it
107
         * down.
108
         */
109
        start_pfn   = PFN_UP(__pa(&_end));
110
        max_low_pfn = PFN_DOWN(CONFIG_OR32_MEMORY_SIZE);
111
        min_low_pfn = PAGE_OFFSET >> PAGE_SHIFT;
112
 
113
        /*
114
         * Initialize the boot-time allocator (with low memory only)
115
         */
116
        bootmap_size = init_bootmem(start_pfn, max_low_pfn);
117
        free_bootmem(PFN_PHYS(start_pfn), PFN_PHYS(max_low_pfn - start_pfn));
118
        reserve_bootmem(PFN_PHYS(start_pfn), bootmap_size);
119
 
120
        return(max_low_pfn);
121
}
122
 
123
static inline unsigned long extract_value_bits(unsigned long reg,
124
                                               short bit_nr, short width)
125
{
126
        return((reg >> bit_nr) & (0 << width));
127
}
128
 
129
static inline unsigned long extract_value(unsigned long reg,
130
                                          unsigned long mask)
131
{
132
        while (!(mask & 0x1)) {
133
                reg  = reg  >> 1;
134
                mask = mask >> 1;
135
        }
136
        return(mask & reg);
137
}
138
 
139
void __init detect_timer(void)
140
{
141
        unsigned long cfg;
142
 
143
        cfg = mfspr(SPR_TTMR);
144
        printk("period 0x%x\n", SPR_TTMR & SPR_TTMR_PERIOD);
145
}
146
 
147
void __init detect_unit_config(unsigned long upr, unsigned long mask,
148
                               char *text, void (*func)(void))
149
{
150
        if (text != NULL)
151
                printk("%s", text);
152
 
153
        if ( upr & mask ) {
154
                if (func != NULL)
155
                        func();
156
                else
157
                        printk("present\n");
158
        }
159
        else
160
                printk("N/A\n");
161
}
162
 
163
 
164
void __init detect_soc_generic(unsigned long upr)
165
{
166
        detect_unit_config(upr, SPR_UPR_DCP,  "  dCACHE: ", NULL);
167
        detect_unit_config(upr, SPR_UPR_ICP,  "  iCACHE: ", NULL);
168
        detect_unit_config(upr, SPR_UPR_DMP,  "  dMMU\t: ", NULL);
169
        detect_unit_config(upr, SPR_UPR_IMP,  "  iMMU\t: ", NULL);
170
        detect_unit_config(upr, SPR_UPR_DUP,  "  debug : ", NULL);
171
        detect_unit_config(upr, SPR_UPR_PCUP, "  PerfC : ", NULL);
172
        detect_unit_config(upr, SPR_UPR_PMP,  "  PM    : ", NULL);
173
        detect_unit_config(upr, SPR_UPR_PICP, "  PIC   : ", NULL);
174
        detect_unit_config(upr, SPR_UPR_TTP,  "  TIMER : ", detect_timer);
175
        detect_unit_config(upr, SPR_UPR_CUST, "  CUs   : ", NULL);
176
 
177
/* add amount configured memory
178
 */
179
}
180
 
181
void __init detect_soc_rev_0(unsigned long upr)
182
{
183
 
184
        printk("  WARNING, using default values !\n"
185
               "           (some early revision 0 processors don't have unit present register\n"
186
               "            populated with all avaliable units)\n");
187
 
188
        printk("  dCACHE: assumed %4d Kb size, %2d bytes/line, %d way(s)",
189
               CONFIG_OR32_DC_SIZE, CONFIG_OR32_DC_LINE, 1);
190
        detect_unit_config(upr, SPR_UPR_DCP,  ", detected: ", NULL);
191
 
192
        printk("  iCACHE: assumed %4d Kb size, %2d bytes/line, %d way(s)",
193
               CONFIG_OR32_IC_SIZE, CONFIG_OR32_IC_LINE, 1);
194
        detect_unit_config(upr, SPR_UPR_ICP,  ", detected: ", NULL);
195
 
196
        printk("  dMMU\t: assumed %4d entries, %d way(s)",
197
               CONFIG_OR32_DTLB_ENTRIES, 1);
198
        detect_unit_config(upr, SPR_UPR_DMP,  ", detected: ", NULL);
199
 
200
        printk("  iMMU\t: assumed %4d entries, %d way(s)",
201
               CONFIG_OR32_ITLB_ENTRIES, 1);
202
        detect_unit_config(upr, SPR_UPR_IMP,  ", detected: ", NULL);
203
        detect_unit_config(upr, SPR_UPR_DUP,  "  debug : unknown (guess yes), detected: ", NULL);
204
        detect_unit_config(upr, SPR_UPR_PCUP, "  PerfC : unknown (guess no ), detected: ", NULL);
205
        detect_unit_config(upr, SPR_UPR_PMP,  "  PM    : unknown (guess yes), detected: ", NULL);
206
        detect_unit_config(upr, SPR_UPR_PICP, "  PIC   : unknown (guess yes), detected: ", NULL);
207
        detect_unit_config(upr, SPR_UPR_TTP,  "  TIMER : unknown (guess yes), detected: ", NULL);
208
        detect_unit_config(upr, SPR_UPR_CUST, "  CUs   : unknown (guess no ), detected: ", NULL);
209
 
210
/* add amount configured memory
211
 */
212
}
213
 
214
void __init detect_soc(void)
215
{
216
        unsigned long upr, cfg, version, revision;
217
 
218
        upr = mfspr(SPR_UPR);
219
        if (upr &  SPR_UPR_UP)
220
                printk("Detecting Processor units:\n");
221
        else {
222
                printk("Unit Present Register not avaliable\n");
223
                return;
224
        }
225
 
226
        cfg = mfspr(SPR_VR);
227
        printk("  CPU\t: or32/OpenRISC-%x, revision %x, @%d MHz, %s\n",
228
               version=extract_value(cfg, SPR_VR_VER),
229
               revision=extract_value(cfg, SPR_VR_REV),
230
               CONFIG_OR32_SYS_CLK,
231
               (upr & (unsigned long)SPR_UPR_SRP) ?
232
               "with shadow registers" : "with no shadow registers");
233
 
234
        if ((version == 0x1200) & (revision == 0)) {
235
                detect_soc_rev_0(upr);
236
        } else {
237
                detect_soc_generic(upr);
238
        }
239
}
240
 
241
 
242
 
243
void __init setup_arch(char **cmdline_p)
244
{
245
        unsigned long max_low_pfn;
246
 
247
        config_BSP(&command_line[0], COMMAND_LINE_SIZE);
248
 
249
        /* register an initial console printing routine for printk's */
250
        or32_console_init();
251
 
252
        /* detect System on Chip parameters */
253
        detect_soc();
254
 
255
        /* process 1's initial memory region is the kernel code/data */
256
        init_mm.start_code = (unsigned long) &text_start;
257
        init_mm.end_code =   (unsigned long) &_etext;
258
        init_mm.end_data =   (unsigned long) &_edata;
259
        init_mm.brk =        (unsigned long) &_end;
260
 
261
#ifdef CONFIG_BLK_DEV_INITRD
262
        initrd_start = (unsigned long)&_initrd_start;
263
        initrd_end = (unsigned long)&_initrd_end;
264
#endif
265
 
266
        /* setup bootmem allocator */
267
        max_low_pfn = setup_memory();
268
 
269
        /* paging_init() sets up the MMU and marks all pages as reserved */
270
        paging_init();
271
 
272
        *cmdline_p = command_line;
273
 
274
        /* Save command line copy for /proc/cmdline */
275
        memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
276
        saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
277
 
278
        printk("Linux/or32 port 2003 OpenCores\n");
279
}
280
 
281
static int show_cpuinfo(struct seq_file *m, void *v)
282
{
283
        return seq_printf(m,
284
                          "cpu\t\t: or32\n"
285
                          "cpu revision\t: %lu\n"
286
                          "cpu model\t: %s\n"
287
                          "cache size\t: %d kB\n"
288
                          "fpu\t\t: %s\n"
289
                          "mmu\t\t: %s\n"
290
                          "ethernet\t: %s Mbps\n"
291
                          "token ring\t: %s\n"
292
                          "scsi\t\t: %s\n"
293
                          "ata\t\t: %s\n"
294
                          "usb\t\t: %s\n"
295
                          "bogomips\t: %lu.%02lu\n",
296
 
297
                          1UL,
298
                          "Marvin",
299
                          4,
300
                          "no",
301
                          "yes",
302
                          "10",
303
                          "no",
304
                          "no",
305
                          "no",
306
                          "no",
307
                          (loops_per_jiffy * HZ) / 500000,
308
                          ((loops_per_jiffy * HZ) / 5000) % 100);
309
}
310
 
311
static void *c_start(struct seq_file *m, loff_t *pos)
312
{
313
        /* We only got one CPU... */
314
        return *pos < 1 ? (void *)1 : NULL;
315
}
316
 
317
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
318
{
319
        ++*pos;
320
        return NULL;
321
}
322
 
323
static void c_stop(struct seq_file *m, void *v)
324
{
325
}
326
 
327
struct seq_operations cpuinfo_op = {
328
        start:  c_start,
329
        next:   c_next,
330
        stop:   c_stop,
331
        show:   show_cpuinfo,
332
};
333
 
334
void arch_gettod(int *year, int *mon, int *day, int *hour,
335
                                  int *min, int *sec)
336
{
337
 
338
        if (mach_gettod)
339
                mach_gettod(year, mon, day, hour, min, sec);
340
        else
341
                *year = *mon = *day = *hour = *min = *sec = 0;
342
}
343
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.