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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [or32/] [kernel/] [setup.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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